DF-5155 / pbfix.c
/* * DF-5155 fix-path replica — implements perfbias_set_handler() exactly as * after fix.diff (wrmsr_safe/rdmsr_safe + error propagation). Loading this * on the patched kernel demonstrates the post-fix instruction sequence on * the same platform where the baseline raw wrmsr took Fatal trap 9: * expected "wrmsr_safe -> error 14" and NO trap. */ #include <sys/param.h> #include <sys/module.h> #include <sys/kernel.h> #include <sys/systm.h> #include <machine/cpufunc.h> #define INTEL_MSR_PERF_BIAS 0x1b0 static int pbfix_modevent(module_t mod, int type, void *data) { uint64_t val = 0; int error; switch (type) { case MOD_LOAD: /* the patched perfbias_set_handler body, verbatim shape */ error = wrmsr_safe(INTEL_MSR_PERF_BIAS, 7); if (error == 0) { val = rdmsr(INTEL_MSR_PERF_BIAS); kprintf("pbfix: hint now %#llx\n", (unsigned long long)(val & 0xf)); } kprintf("pbfix: patched handler returns error %d " "(sysctl writer gets EIO, no trap)\n", error); return 0; case MOD_UNLOAD: return 0; } return EOPNOTSUPP; } static moduledata_t pbfix_mod = { "pbfix", pbfix_modevent, NULL }; DECLARE_MODULE(pbfix, pbfix_mod, SI_SUB_DRIVERS, SI_ORDER_ANY); |