Commit 499c8bb4 authored by Kohei Tarumizu's avatar Kohei Tarumizu Committed by Dave Hansen

x86/resctrl: Fix to restore to original value when re-enabling hardware prefetch register

The current pseudo_lock.c code overwrites the value of the
MSR_MISC_FEATURE_CONTROL to 0 even if the original value is not 0.
Therefore, modify it to save and restore the original values.

Fixes: 018961ae ("x86/intel_rdt: Pseudo-lock region creation/removal core")
Fixes: 443810fe ("x86/intel_rdt: Create debugfs files for pseudo-locking testing")
Fixes: 8a2fc0e1 ("x86/intel_rdt: More precise L2 hit/miss measurements")
Signed-off-by: default avatarKohei Tarumizu <tarumizu.kohei@fujitsu.com>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Acked-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Link: https://lkml.kernel.org/r/eb660f3c2010b79a792c573c02d01e8e841206ad.1661358182.git.reinette.chatre@intel.com
parent b90cb105
...@@ -420,6 +420,7 @@ static int pseudo_lock_fn(void *_rdtgrp) ...@@ -420,6 +420,7 @@ static int pseudo_lock_fn(void *_rdtgrp)
struct pseudo_lock_region *plr = rdtgrp->plr; struct pseudo_lock_region *plr = rdtgrp->plr;
u32 rmid_p, closid_p; u32 rmid_p, closid_p;
unsigned long i; unsigned long i;
u64 saved_msr;
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
/* /*
* The registers used for local register variables are also used * The registers used for local register variables are also used
...@@ -463,6 +464,7 @@ static int pseudo_lock_fn(void *_rdtgrp) ...@@ -463,6 +464,7 @@ static int pseudo_lock_fn(void *_rdtgrp)
* the buffer and evict pseudo-locked memory read earlier from the * the buffer and evict pseudo-locked memory read earlier from the
* cache. * cache.
*/ */
saved_msr = __rdmsr(MSR_MISC_FEATURE_CONTROL);
__wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
closid_p = this_cpu_read(pqr_state.cur_closid); closid_p = this_cpu_read(pqr_state.cur_closid);
rmid_p = this_cpu_read(pqr_state.cur_rmid); rmid_p = this_cpu_read(pqr_state.cur_rmid);
...@@ -514,7 +516,7 @@ static int pseudo_lock_fn(void *_rdtgrp) ...@@ -514,7 +516,7 @@ static int pseudo_lock_fn(void *_rdtgrp)
__wrmsr(IA32_PQR_ASSOC, rmid_p, closid_p); __wrmsr(IA32_PQR_ASSOC, rmid_p, closid_p);
/* Re-enable the hardware prefetcher(s) */ /* Re-enable the hardware prefetcher(s) */
wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0); wrmsrl(MSR_MISC_FEATURE_CONTROL, saved_msr);
local_irq_enable(); local_irq_enable();
plr->thread_done = 1; plr->thread_done = 1;
...@@ -871,6 +873,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d) ...@@ -871,6 +873,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
static int measure_cycles_lat_fn(void *_plr) static int measure_cycles_lat_fn(void *_plr)
{ {
struct pseudo_lock_region *plr = _plr; struct pseudo_lock_region *plr = _plr;
u32 saved_low, saved_high;
unsigned long i; unsigned long i;
u64 start, end; u64 start, end;
void *mem_r; void *mem_r;
...@@ -879,6 +882,7 @@ static int measure_cycles_lat_fn(void *_plr) ...@@ -879,6 +882,7 @@ static int measure_cycles_lat_fn(void *_plr)
/* /*
* Disable hardware prefetchers. * Disable hardware prefetchers.
*/ */
rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
mem_r = READ_ONCE(plr->kmem); mem_r = READ_ONCE(plr->kmem);
/* /*
...@@ -895,7 +899,7 @@ static int measure_cycles_lat_fn(void *_plr) ...@@ -895,7 +899,7 @@ static int measure_cycles_lat_fn(void *_plr)
end = rdtsc_ordered(); end = rdtsc_ordered();
trace_pseudo_lock_mem_latency((u32)(end - start)); trace_pseudo_lock_mem_latency((u32)(end - start));
} }
wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0); wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
local_irq_enable(); local_irq_enable();
plr->thread_done = 1; plr->thread_done = 1;
wake_up_interruptible(&plr->lock_thread_wq); wake_up_interruptible(&plr->lock_thread_wq);
...@@ -940,6 +944,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr, ...@@ -940,6 +944,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0; u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
struct perf_event *miss_event, *hit_event; struct perf_event *miss_event, *hit_event;
int hit_pmcnum, miss_pmcnum; int hit_pmcnum, miss_pmcnum;
u32 saved_low, saved_high;
unsigned int line_size; unsigned int line_size;
unsigned int size; unsigned int size;
unsigned long i; unsigned long i;
...@@ -973,6 +978,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr, ...@@ -973,6 +978,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
/* /*
* Disable hardware prefetchers. * Disable hardware prefetchers.
*/ */
rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
/* Initialize rest of local variables */ /* Initialize rest of local variables */
...@@ -1031,7 +1037,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr, ...@@ -1031,7 +1037,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
*/ */
rmb(); rmb();
/* Re-enable hardware prefetchers */ /* Re-enable hardware prefetchers */
wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0); wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
local_irq_enable(); local_irq_enable();
out_hit: out_hit:
perf_event_release_kernel(hit_event); perf_event_release_kernel(hit_event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment