⬢ DragonFlyBSD Kernel Audit
DF-5160 / approbe.c
← back to finding ↓ download raw
/*
 * DF-5160 non-fatal probe (approbe.ko): prints the CPUID.06H gate state
 * and the rdmsr_safe() result for MSR_APERF/MSR_MPERF, WITHOUT the raw
 * read. Used on the '-cpu host' guest to document KVM's masking policy
 * for leaf 6 ECX bit 0 before deciding the driver-level vs trigger path.
 */
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <machine/cpufunc.h>

#define MSR_MPERF	0xE7
#define MSR_APERF	0xE8

static int
approbe_modevent(module_t mod, int type, void *arg)
{
	uint64_t v;
	uint32_t regs[4], maxleaf[4];
	int err;

	switch (type) {
	case MOD_LOAD:
		do_cpuid(0x00000000, maxleaf);
		do_cpuid(0x00000006, regs);
		kprintf("approbe: max basic leaf = 0x%08x\n", maxleaf[0]);
		kprintf("approbe: CPUID.06H EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n",
		    regs[0], regs[1], regs[2], regs[3]);
		kprintf("approbe: aperf identify gate ECX bit0 (aperf.c:89) = %d\n",
		    (regs[2] & 1) != 0);
		err = rdmsr_safe(MSR_APERF, &v);
		kprintf("approbe: rdmsr_safe(MSR_APERF 0xE8) = %d val=%#llx\n",
		    err, err ? 0ULL : (unsigned long long)v);
		err = rdmsr_safe(MSR_MPERF, &v);
		kprintf("approbe: rdmsr_safe(MSR_MPERF 0xE7) = %d val=%#llx\n",
		    err, err ? 0ULL : (unsigned long long)v);
		return 0;
	default:
		return EOPNOTSUPP;
	}
}

static moduledata_t approbe_mod = {
	"approbe",
	approbe_modevent,
	NULL
};
DECLARE_MODULE(approbe, approbe_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);