lkml.org 
[lkml]   [2021]   [Jun]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH v5 14/28] x86/fpu/xstate: Prevent unauthorised use of dynamic user state
Date
On Jun 29, 2021, at 10:54, Hansen, Dave <dave.hansen@intel.com> wrote:
> How about we pay this 26-cycle cost, but only when XFD is in use? We
> could either look at the shadowed value of the XFD MSR, or flip a global
> variable the first time XFD gets used.

How about something like this:

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 777cccab0b47..9752ebe6be79 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -99,6 +99,23 @@ EXPORT_SYMBOL(irq_fpu_usable);
void save_fpregs_to_fpstate(struct fpu *fpu)
{
if (likely(use_xsave())) {
+ /*
+ * MSR IA32_XFD write follows after this XSAVE(S). So if a
+ * state component is in use, XFD should not be armed for
+ * current. But, for potential changes in the future,
+ * cross-check XINUSE and XFD values. If a XINUSE state
+ * is XFD-armed, the following XSAVE(S) does not save the
+ * state.
+ *
+ * Reference the shadow XFD value instead of reading the
+ * MSR.
+ */
+ if (xfd_capable() && boot_cpu_has(X86_FEATURE_XGETBV1)) {
+ u64 current_xfd = (fpu->state_mask & xfd_capable()) ^ xfd_capable();
+
+ WARN_ON_FPU(xgetbv(1) & current_xfd);
+ }
+
os_xsave(&fpu->state->xsave, fpu->state_mask);

Thanks,
Chang
\
 
 \ /
  Last update: 2021-06-29 20:36    [W:0.097 / U:0.664 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site