[Devel] [PATCH vz8 v2 2/2] x86: don't enable cpuid faults if /proc/vz/cpuid_override unused

Kirill Tkhai ktkhai at virtuozzo.com
Tue Nov 3 15:00:22 MSK 2020


On 02.11.2020 20:13, Andrey Ryabinin wrote:
> 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>

> ---
> 
> Changes since v1:
>  - git add include/linux/cpuid_override.h 
>  
>  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(-)
>  create mode 100644 include/linux/cpuid_override.h
> 
> 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 aad8ce69ca1f..0d4d0ab70369 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