From: Dave Hansen <dave.hansen@linux.intel.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
Dave Hansen <dave.hansen@linux.intel.com>,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
x86@kernel.org, luto@kernel.org
Subject: [RFC][PATCH 4/8] x86/fpu: remove PKRU from FPU user state clearing
Date: Tue, 22 Jun 2021 15:25:02 -0700 [thread overview]
Message-ID: <20210622222502.EA11BE12@viggo.jf.intel.com> (raw)
In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com>
From: Dave Hansen <dave.hansen@linux.intel.com>
The signal code has a few points where it initializes user FPU state.
Remove PKRU from the set of features which are initialized in the FPU
code. Use write_pkru() to explicitly initialize PKRU instead of using
the fpstate/XSAVE infrastructure.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
---
b/arch/x86/kernel/fpu/core.c | 8 +++++---
b/arch/x86/kernel/fpu/signal.c | 5 ++++-
b/arch/x86/kernel/signal.c | 1 +
3 files changed, 10 insertions(+), 4 deletions(-)
diff -puN arch/x86/kernel/fpu/core.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/fpu/core.c
--- a/arch/x86/kernel/fpu/core.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.026051754 -0700
+++ b/arch/x86/kernel/fpu/core.c 2021-06-22 14:49:10.039051754 -0700
@@ -209,7 +209,8 @@ static inline void fpstate_init_xstate(s
* XRSTORS requires these bits set in xcomp_bv, or it will
* trigger #GP:
*/
- xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xfeatures_mask_all;
+ xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
+ xfeatures_mask_fpstate();
}
static inline void fpstate_init_fxstate(struct fxregs_state *fx)
@@ -389,8 +390,9 @@ void fpu__clear_user_states(struct fpu *
os_xrstor(&fpu->state.xsave, xfeatures_mask_supervisor());
}
- /* Reset user states in registers. */
- load_fpregs_from_init_fpstate(xfeatures_mask_restore_user());
+ /* Reset user registers maintained in fpstate. */
+ load_fpregs_from_init_fpstate(xfeatures_mask_fpstate() &
+ xfeatures_mask_restore_user());
/*
* Now all FPU registers have their desired values. Inform the FPU
diff -puN arch/x86/kernel/fpu/signal.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/fpu/signal.c
--- a/arch/x86/kernel/fpu/signal.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.031051754 -0700
+++ b/arch/x86/kernel/fpu/signal.c 2021-06-22 14:49:10.040051754 -0700
@@ -437,6 +437,7 @@ int fpu__restore_sig(void __user *buf, i
int ret;
if (unlikely(!buf)) {
+ write_pkru(pkru_get_init_value());
fpu__clear_user_states(¤t->thread.fpu);
return 0;
}
@@ -468,8 +469,10 @@ int fpu__restore_sig(void __user *buf, i
ret = __fpu_restore_sig(buf, buf_fx, ia32_fxstate);
out:
- if (unlikely(ret))
+ if (unlikely(ret)) {
+ write_pkru(pkru_get_init_value());
fpu__clear_user_states(¤t->thread.fpu);
+ }
return ret;
}
diff -puN arch/x86/kernel/signal.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/signal.c
--- a/arch/x86/kernel/signal.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.033051754 -0700
+++ b/arch/x86/kernel/signal.c 2021-06-22 14:49:10.043051754 -0700
@@ -835,6 +835,7 @@ handle_signal(struct ksignal *ksig, stru
/*
* Ensure the signal handler starts with the new fpu state.
*/
+ write_pkru(pkru_get_init_value());
fpu__clear_user_states(fpu);
}
signal_setup_done(failed, ksig, stepping);
_
next prev parent reply other threads:[~2021-06-22 22:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 22:24 [RFC][PATCH 0/8] x86/pkeys: remove PKRU from kernel XSAVE buffer Dave Hansen
2021-06-22 22:24 ` [RFC][PATCH 1/8] x86/pkeys: add PKRU storage outside of task " Dave Hansen
2021-06-22 22:24 ` [RFC][PATCH 2/8] x86/fpu: hook up PKRU into signal user ABIs Dave Hansen
2021-06-22 22:25 ` [RFC][PATCH 3/8] x86/fpu: separate the setup of xfeatures not in fpstate Dave Hansen
2021-06-22 22:25 ` Dave Hansen [this message]
2021-06-22 22:25 ` [RFC][PATCH 5/8] x86/fpu: XSAVE buffer access routine rename Dave Hansen
2021-06-22 22:25 ` [RFC][PATCH 6/8] x86/fpu: update xstate size calculations for non-XSAVE-managed features Dave Hansen
2021-06-22 22:25 ` [RFC][PATCH 7/8] x86/fpu: actually stop using XSAVE on PKRU Dave Hansen
2021-06-22 22:25 ` [RFC][PATCH 8/8] x86/pkeys: remove init_pkru_value variable Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210622222502.EA11BE12@viggo.jf.intel.com \
--to=dave.hansen@linux.intel.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).