[Devel] [PATCH RHEL8 COMMIT] x86: don't enable cpuid faults if /proc/vz/cpuid_override unused #PSBM-121823
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Nov 6 17:11:44 MSK 2020
The commit is pushed to "work" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.16
------>
commit b82cdbd9074b894fd5f0f6f098c017e5c5a64ba8
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date: Fri Nov 6 17:11:44 2020 +0300
x86: don't enable cpuid faults if /proc/vz/cpuid_override unused #PSBM-121823
We don't need to enable cpuid faults if /proc/vz/cpuid_override
was never used. If task was attached to ve before a write to
'cpuid_override' it will not get cpuid faults now. It shouldn't
be a problem since the proper use of 'cpuid_override' requires
stopping all containers.
https://jira.sw.ru/browse/PSBM-121823
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
arch/x86/kernel/cpuid_fault.c | 21 ++-------------------
include/linux/cpuid_override.h | 30 ++++++++++++++++++++++++++++++
kernel/ve/ve.c | 5 ++++-
3 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/cpuid_fault.c b/arch/x86/kernel/cpuid_fault.c
index 1e8ffacc4412..cb6c2216fa8a 100644
--- a/arch/x86/kernel/cpuid_fault.c
+++ b/arch/x86/kernel/cpuid_fault.c
@@ -1,3 +1,4 @@
+#include <linux/cpuid_override.h>
#include <linux/gfp.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -9,25 +10,7 @@
#include <linux/veowner.h>
#include <linux/uaccess.h>
-struct cpuid_override_entry {
- unsigned int op;
- unsigned int count;
- bool has_count;
- unsigned int eax;
- unsigned int ebx;
- unsigned int ecx;
- unsigned int edx;
-};
-
-#define MAX_CPUID_OVERRIDE_ENTRIES 16
-
-struct cpuid_override_table {
- struct rcu_head rcu_head;
- int size;
- struct cpuid_override_entry entries[MAX_CPUID_OVERRIDE_ENTRIES];
-};
-
-static struct cpuid_override_table __rcu *cpuid_override __read_mostly;
+struct cpuid_override_table __rcu *cpuid_override __read_mostly;
static DEFINE_SPINLOCK(cpuid_override_lock);
static void cpuid_override_update(struct cpuid_override_table *new_table)
diff --git a/include/linux/cpuid_override.h b/include/linux/cpuid_override.h
new file mode 100644
index 000000000000..ea0fa7af3d3c
--- /dev/null
+++ b/include/linux/cpuid_override.h
@@ -0,0 +1,30 @@
+#ifndef __CPUID_OVERRIDE_H
+#define __CPUID_OVERRIDE_H
+
+#include <linux/rcupdate.h>
+
+struct cpuid_override_entry {
+ unsigned int op;
+ unsigned int count;
+ bool has_count;
+ unsigned int eax;
+ unsigned int ebx;
+ unsigned int ecx;
+ unsigned int edx;
+};
+
+#define MAX_CPUID_OVERRIDE_ENTRIES 16
+
+struct cpuid_override_table {
+ struct rcu_head rcu_head;
+ int size;
+ struct cpuid_override_entry entries[MAX_CPUID_OVERRIDE_ENTRIES];
+};
+
+extern struct cpuid_override_table __rcu *cpuid_override;
+
+static inline bool cpuid_override_on(void)
+{
+ return rcu_access_pointer(cpuid_override);
+}
+#endif
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index a6e3a145d51d..a9afefc5b9de 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -9,6 +9,7 @@
* 've.c' helper file performing VE sub-system initialization
*/
+#include <linux/cpuid_override.h>
#include <linux/ctype.h>
#include <linux/init.h>
#include <linux/kernel.h>
@@ -801,6 +802,7 @@ static void ve_attach(struct cgroup_taskset *tset)
{
struct cgroup_subsys_state *css;
struct task_struct *task;
+ extern struct cpuid_override_table __rcu *cpuid_override;
cgroup_taskset_for_each(task, css, tset) {
struct ve_struct *ve = css_to_ve(css);
@@ -816,7 +818,8 @@ static void ve_attach(struct cgroup_taskset *tset)
/* Leave parent exec domain */
task->parent_exec_id--;
- set_tsk_thread_flag(task, TIF_CPUID_OVERRIDE);
+ if (cpuid_override_on())
+ set_tsk_thread_flag(task, TIF_CPUID_OVERRIDE);
task->task_ve = ve;
}
}
More information about the Devel
mailing list