Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions third-party/zen-pmu-workaround/zen_workaround.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@
#include <linux/module.h>
#include <linux/tracepoint.h>
#include <linux/suspend.h>
#include <linux/version.h>
#include <asm/msr.h>

#define MODULE_NAME "zen_workaround"

#define SPECLOCKMAP_DISABLE BIT_64(54)

u64 set_speclockmap_disable(u64 msr) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,16,0)
#define wrmsrq_safe wrmsrl_safe
#define rdmsrq_safe rdmsrl_safe
#define native_wrmsrq native_wrmsrl
#endif


static u64 set_speclockmap_disable(u64 msr) {
return msr | SPECLOCKMAP_DISABLE;
}

u64 unset_speclockmap_disable(u64 msr) {
static u64 unset_speclockmap_disable(u64 msr) {
return msr & ~SPECLOCKMAP_DISABLE;
}

Expand All @@ -26,10 +35,10 @@ static void edit_ls_cfg_on_cpu(void *info)
int cpu = get_cpu();
u64 value = 0;

if (!rdmsrl_safe(MSR_AMD64_LS_CFG, &value)) {
if (!rdmsrq_safe(MSR_AMD64_LS_CFG, &value)) {
edit_msr_func_t edit_msr = (edit_msr_func_t) info;
u64 new_value = edit_msr(value);
if (!wrmsrl_safe(MSR_AMD64_LS_CFG, new_value)) {
if (!wrmsrq_safe(MSR_AMD64_LS_CFG, new_value)) {
pr_info("MSR_AMD64_LS_CFG for cpu %d was 0x%llx, setting to 0x%llx\n",
cpu, value, new_value);
} else {
Expand All @@ -50,7 +59,7 @@ static void do_zen_workaround(edit_msr_func_t edit_msr)
void on_write_msr(void *data, unsigned int msr, u64 val, int failed)
{
if (msr == MSR_AMD64_LS_CFG && !(val & SPECLOCKMAP_DISABLE)) {
native_wrmsrl(MSR_AMD64_LS_CFG, set_speclockmap_disable(val));
native_wrmsrq(MSR_AMD64_LS_CFG, set_speclockmap_disable(val));
}
}

Expand Down