diff mbox series

[v3,06/10] x86/fpu/xstate: Initialize guest perm with fpu_guest_cfg

Message ID 20250307164123.1613414-7-chao.gao@intel.com (mailing list archive)
State New
Headers show
Series Introduce CET supervisor state support | expand

Commit Message

Chao Gao March 7, 2025, 4:41 p.m. UTC
From: Yang Weijiang <weijiang.yang@intel.com>

Use the new fpu_guest_cfg to initialize guest permissions.

Note fpu_guest_cfg and fpu_kernel_cfg remain the same for now. So there
is no functional change.

Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
[Gao Chao: Extrace this from the previous patch ]
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
 arch/x86/kernel/fpu/core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Dave Hansen March 7, 2025, 6:14 p.m. UTC | #1
On 3/7/25 08:41, Chao Gao wrote:
> From: Yang Weijiang <weijiang.yang@intel.com>
> 
> Use the new fpu_guest_cfg to initialize guest permissions.

Background, please.

What are the guest permissions currently set to? Why does it need to change?

> Note fpu_guest_cfg and fpu_kernel_cfg remain the same for now. So there
> is no functional change.
> 
> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
> [Gao Chao: Extrace this from the previous patch ]
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
>  arch/x86/kernel/fpu/core.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index b0c1ef40d105..d7ae684adbad 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -534,8 +534,15 @@ void fpstate_reset(struct fpu *fpu)
>  	fpu->perm.__state_perm		= fpu_kernel_cfg.default_features;
>  	fpu->perm.__state_size		= fpu_kernel_cfg.default_size;
>  	fpu->perm.__user_state_size	= fpu_user_cfg.default_size;
> -	/* Same defaults for guests */
> -	fpu->guest_perm = fpu->perm;
> +
> +	/* Guest permission settings */
> +	fpu->guest_perm.__state_perm	= fpu_guest_cfg.default_features;
> +	fpu->guest_perm.__state_size	= fpu_guest_cfg.default_size;
> +	/*
> +	 * Set guest's __user_state_size to fpu_user_cfg.default_size so that
> +	 * existing uAPIs can still work.
> +	 */

I suspect that readers here will understand that this line:

> +	fpu->guest_perm.__user_state_size = fpu_user_cfg.default_size;
>  }

means "Set guest's __user_state_size to fpu_user_cfg.default_size". The
comment basically just literally restates what the code does. That part
of the comment doesn't add value.
Chao Gao March 8, 2025, 3:14 a.m. UTC | #2
On Fri, Mar 07, 2025 at 10:14:19AM -0800, Dave Hansen wrote:
>On 3/7/25 08:41, Chao Gao wrote:
>> From: Yang Weijiang <weijiang.yang@intel.com>
>> 
>> Use the new fpu_guest_cfg to initialize guest permissions.
>
>Background, please.
>
>What are the guest permissions currently set to? Why does it need to change?

Ok. Will add:

Currently, fpu->guest_perm is copied from fpu->perm, which is derived from
fpu_kernel_cfg. To separate the guest FPU from the kernel FPU, switch to use
the new fpu_guest_cfg to initialize guest permissions. This ensures that any
future changes to fpu_guest_cfg will automatically update the guest permissions

The __user_state_size is tied to existing uAPIs, so it remains unchanged.

>
>> Note fpu_guest_cfg and fpu_kernel_cfg remain the same for now. So there
>> is no functional change.
>> 
>> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
>> [Gao Chao: Extrace this from the previous patch ]
>> Signed-off-by: Chao Gao <chao.gao@intel.com>
>> ---
>>  arch/x86/kernel/fpu/core.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>> 
>> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
>> index b0c1ef40d105..d7ae684adbad 100644
>> --- a/arch/x86/kernel/fpu/core.c
>> +++ b/arch/x86/kernel/fpu/core.c
>> @@ -534,8 +534,15 @@ void fpstate_reset(struct fpu *fpu)
>>  	fpu->perm.__state_perm		= fpu_kernel_cfg.default_features;
>>  	fpu->perm.__state_size		= fpu_kernel_cfg.default_size;
>>  	fpu->perm.__user_state_size	= fpu_user_cfg.default_size;
>> -	/* Same defaults for guests */
>> -	fpu->guest_perm = fpu->perm;
>> +
>> +	/* Guest permission settings */
>> +	fpu->guest_perm.__state_perm	= fpu_guest_cfg.default_features;
>> +	fpu->guest_perm.__state_size	= fpu_guest_cfg.default_size;
>> +	/*
>> +	 * Set guest's __user_state_size to fpu_user_cfg.default_size so that
>> +	 * existing uAPIs can still work.
>> +	 */
>
>I suspect that readers here will understand that this line:
>
>> +	fpu->guest_perm.__user_state_size = fpu_user_cfg.default_size;
>>  }
>
>means "Set guest's __user_state_size to fpu_user_cfg.default_size". The
>comment basically just literally restates what the code does. That part
>of the comment doesn't add value.

Will drop this useless comment.
diff mbox series

Patch

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index b0c1ef40d105..d7ae684adbad 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -534,8 +534,15 @@  void fpstate_reset(struct fpu *fpu)
 	fpu->perm.__state_perm		= fpu_kernel_cfg.default_features;
 	fpu->perm.__state_size		= fpu_kernel_cfg.default_size;
 	fpu->perm.__user_state_size	= fpu_user_cfg.default_size;
-	/* Same defaults for guests */
-	fpu->guest_perm = fpu->perm;
+
+	/* Guest permission settings */
+	fpu->guest_perm.__state_perm	= fpu_guest_cfg.default_features;
+	fpu->guest_perm.__state_size	= fpu_guest_cfg.default_size;
+	/*
+	 * Set guest's __user_state_size to fpu_user_cfg.default_size so that
+	 * existing uAPIs can still work.
+	 */
+	fpu->guest_perm.__user_state_size = fpu_user_cfg.default_size;
 }
 
 static inline void fpu_inherit_perms(struct fpu *dst_fpu)