new file mode 100644
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_HRESET_H
+
+void reset_hardware_history_hetero(void);
+
+#endif /* _ASM_X86_HRESET_H */
@@ -57,6 +57,7 @@
#include <asm/mce.h>
#include <asm/msr.h>
#include <asm/cacheinfo.h>
+#include <asm/hreset.h>
#include <asm/memtype.h>
#include <asm/microcode.h>
#include <asm/intel-family.h>
@@ -403,6 +404,7 @@ static const unsigned long cr4_pinned_mask = X86_CR4_SMEP | X86_CR4_SMAP | X86_C
X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED;
static DEFINE_STATIC_KEY_FALSE_RO(cr_pinning);
static unsigned long cr4_pinned_bits __ro_after_init;
+static DEFINE_STATIC_KEY_FALSE_RO(hardware_history_features);
void native_write_cr0(unsigned long val)
{
@@ -481,6 +483,12 @@ void cr4_init(void)
this_cpu_write(cpu_tlbstate.cr4, cr4);
}
+static void __init setup_hreset(struct cpuinfo_x86 *c)
+{
+ if (cpu_feature_enabled(X86_FEATURE_AMD_WORKLOAD_CLASS))
+ static_key_enable_cpuslocked(&hardware_history_features.key);
+}
+
/*
* Once CPU feature detection is finished (and boot params have been
* parsed), record any of the sensitive CR bits that are set, and
@@ -1951,6 +1959,7 @@ static __init void identify_boot_cpu(void)
tsx_init();
tdx_init();
lkgs_init();
+ setup_hreset(&boot_cpu_data);
}
void identify_secondary_cpu(struct cpuinfo_x86 *c)
@@ -2410,3 +2419,9 @@ void __init arch_cpu_finalize_init(void)
*/
mem_encrypt_init();
}
+
+__always_inline void reset_hardware_history_hetero(void)
+{
+ if (static_branch_unlikely(&hardware_history_features))
+ wrmsrl(AMD_WORKLOAD_HRST, 0x1);
+}
@@ -52,6 +52,7 @@
#include <asm/switch_to.h>
#include <asm/vm86.h>
#include <asm/resctrl.h>
+#include <asm/hreset.h>
#include <asm/proto.h>
#include "process.h"
@@ -213,6 +214,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/* Load the Intel cache allocation PQR MSR. */
resctrl_sched_in(next_p);
+ reset_hardware_history_hetero();
+
return prev_p;
}
@@ -54,6 +54,7 @@
#include <asm/xen/hypervisor.h>
#include <asm/vdso.h>
#include <asm/resctrl.h>
+#include <asm/hreset.h>
#include <asm/unistd.h>
#include <asm/fsgsbase.h>
#include <asm/fred.h>
@@ -709,6 +710,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
/* Load the Intel cache allocation PQR MSR. */
resctrl_sched_in(next_p);
+ reset_hardware_history_hetero();
+
return prev_p;
}