[v7,07/26] x86/fpu/xstate: Warn if kernel dynamic xfeatures detected in normal fpstate

Message ID 20231124055330.138870-8-weijiang.yang@intel.com
State New
Headers
Series Enable CET Virtualization |

Commit Message

Yang, Weijiang Nov. 24, 2023, 5:53 a.m. UTC
  Kernel dynamic xfeatures now are __ONLY__ enabled for guest fpstate, i.e.,
none for normal kernel fpstate. The bits are added when guest FPU config
is initialized. Guest fpstate is allocated with fpstate->is_guest set to
%true.

For normal fpstate, the bits should have been removed when initializes
kernel FPU config settings, WARN_ONCE() if kernel detects normal fpstate
xfeatures contains kernel dynamic xfeatures before executes xsaves.

Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
 arch/x86/kernel/fpu/xstate.h | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Edgecombe, Rick P Nov. 28, 2023, 3:25 p.m. UTC | #1
On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote:
> Kernel dynamic xfeatures now are __ONLY__ enabled for guest fpstate,
> i.e.,
> none for normal kernel fpstate. The bits are added when guest FPU
  ^never?
> config
> is initialized. Guest fpstate is allocated with fpstate->is_guest set
> to
> %true.
> 
> For normal fpstate, the bits should have been removed when
> initializes
> kernel FPU config settings, WARN_ONCE() if kernel detects normal
> fpstate
> xfeatures contains kernel dynamic xfeatures before executes xsaves.
> 
> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>

Otherwise...

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
  
Yang, Weijiang Nov. 29, 2023, 2:18 p.m. UTC | #2
On 11/28/2023 11:25 PM, Edgecombe, Rick P wrote:
> On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote:
>> Kernel dynamic xfeatures now are __ONLY__ enabled for guest fpstate,
>> i.e.,
>> none for normal kernel fpstate. The bits are added when guest FPU
>    ^never?

Sure, will change it, thank you!

>> config
>> is initialized. Guest fpstate is allocated with fpstate->is_guest set
>> to
>> %true.
>>
>> For normal fpstate, the bits should have been removed when
>> initializes
>> kernel FPU config settings, WARN_ONCE() if kernel detects normal
>> fpstate
>> xfeatures contains kernel dynamic xfeatures before executes xsaves.
>>
>> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
> Otherwise...
>
> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
  

Patch

diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h
index c032acb56306..d45f3e570e69 100644
--- a/arch/x86/kernel/fpu/xstate.h
+++ b/arch/x86/kernel/fpu/xstate.h
@@ -186,6 +186,9 @@  static inline void os_xsave(struct fpstate *fpstate)
 	WARN_ON_FPU(!alternatives_patched);
 	xfd_validate_state(fpstate, mask, false);
 
+	WARN_ON_FPU(!fpstate->is_guest &&
+		    (mask & XFEATURE_MASK_KERNEL_DYNAMIC));
+
 	XSTATE_XSAVE(&fpstate->regs.xsave, lmask, hmask, err);
 
 	/* We should never fault when copying to a kernel buffer: */