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>
===================================================================
@@ -45,6 +45,7 @@
#include <linux/smp.h>
#include <linux/syscore_ops.h>
#include <linux/rcupdate.h>
+#include <linux/sched/isolation.h>
#include <asm/cacheinfo.h>
#include <asm/cpufeature.h>
@@ -226,7 +227,7 @@ int mtrr_add_page(unsigned long base, un
unsigned int type, bool increment)
{
unsigned long lbase, lsize;
- int i, replace, error;
+ int i, replace, error, idx;
mtrr_type ltype;
if (!mtrr_enabled())
@@ -261,6 +262,13 @@ int mtrr_add_page(unsigned long base, un
error = -EINVAL;
replace = -1;
+ idx = block_interf_srcu_read_lock();
+
+ if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) {
+ block_interf_srcu_read_unlock(idx);
+ return -EPERM;
+ }
+
/* No CPU hotplug when we change MTRR entries */
cpus_read_lock();
@@ -325,6 +333,7 @@ int mtrr_add_page(unsigned long base, un
out:
mutex_unlock(&mtrr_mutex);
cpus_read_unlock();
+ block_interf_srcu_read_unlock(idx);
return error;
}
@@ -405,11 +414,17 @@ int mtrr_del_page(int reg, unsigned long
mtrr_type ltype;
unsigned long lbase, lsize;
int error = -EINVAL;
+ int idx;
if (!mtrr_enabled())
return -ENODEV;
max = num_var_ranges;
+ idx = block_interf_srcu_read_lock();
+ if (cpumask_intersects(block_interf_cpumask, cpu_online_mask)) {
+ block_interf_srcu_read_unlock(idx);
+ return -EPERM;
+ }
/* No CPU hotplug when we change MTRR entries */
cpus_read_lock();
mutex_lock(&mtrr_mutex);
@@ -446,6 +461,7 @@ int mtrr_del_page(int reg, unsigned long
out:
mutex_unlock(&mtrr_mutex);
cpus_read_unlock();
+ block_interf_srcu_read_unlock(idx);
return error;
}