[RFC PATCH 7/7] mtrr_add_page/mtrr_del_page: check for block interference CPUs

Marcelo Tosatti posted 7 patches 3 years, 6 months ago
There is a newer version of this series
[RFC PATCH 7/7] mtrr_add_page/mtrr_del_page: check for block interference CPUs
Posted by Marcelo Tosatti 3 years, 6 months ago
Check if any online CPU in the system is tagged as
a block interference CPU, and if so return an error
to mtrr_add_page/mtrr_del_page. 

This can avoid interference to such CPUs (while allowing
userspace to handle the failures).

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>


Index: linux-2.6/arch/x86/kernel/cpu/mtrr/mtrr.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/mtrr.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/mtrr.c
@@ -45,6 +45,7 @@
 #include <linux/smp.h>
 #include <linux/syscore_ops.h>
 #include <linux/rcupdate.h>
+#include <linux/sched/isolation.h>
 
 #include <asm/cpufeature.h>
 #include <asm/e820/api.h>
@@ -335,6 +336,13 @@ int mtrr_add_page(unsigned long base, un
 	error = -EINVAL;
 	replace = -1;
 
+	block_interf_read_lock();
+
+	if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) {
+		block_interf_read_unlock();
+		return -EPERM;
+	}
+
 	/* No CPU hotplug when we change MTRR entries */
 	cpus_read_lock();
 
@@ -399,6 +407,7 @@ int mtrr_add_page(unsigned long base, un
  out:
 	mutex_unlock(&mtrr_mutex);
 	cpus_read_unlock();
+	block_interf_read_unlock();
 	return error;
 }
 
@@ -484,6 +493,11 @@ int mtrr_del_page(int reg, unsigned long
 		return -ENODEV;
 
 	max = num_var_ranges;
+	block_interf_read_lock();
+	if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) {
+		block_interf_read_unlock();
+		return -EPERM;
+	}
 	/* No CPU hotplug when we change MTRR entries */
 	cpus_read_lock();
 	mutex_lock(&mtrr_mutex);
@@ -521,6 +535,7 @@ int mtrr_del_page(int reg, unsigned long
  out:
 	mutex_unlock(&mtrr_mutex);
 	cpus_read_unlock();
+	block_interf_read_unlock();
 	return error;
 }