[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210527235111.11857E30@viggo.jf.intel.com>
Date: Thu, 27 May 2021 16:51:11 -0700
From: Dave Hansen <dave.hansen@...ux.intel.com>
To: linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org,
Dave Hansen <dave.hansen@...ux.intel.com>, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, x86@...nel.org, luto@...nel.org,
shuah@...nel.org, babu.moger@....com, dave.kleikamp@...cle.com,
linuxram@...ibm.com, bauerman@...ux.ibm.com, bigeasy@...utronix.de
Subject: [PATCH 1/5] x86/pkeys: move read_pkru() and write_pkru()
From: Dave Hansen <dave.hansen@...ux.intel.com>
write_pkru() was originally used just to write to the PKRU register. It
was mercifully short and sweet and was not out of place in pgtable.h with
some other pkey-related code.
But, later work included a requirement to also modify the task XSAVE
buffer when updating the register. This really is more related to the
XSAVE architecture than to paging.
Move the read/write_pkru() to asm/fpu/xstate.h. pgtable.h won't miss them.
Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Borislav Petkov <bp@...en8.de>
Cc: x86@...nel.org
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Shuah Khan <shuah@...nel.org>
Cc: Babu Moger <babu.moger@....com>
Cc: Dave Kleikamp <dave.kleikamp@...cle.com>
Cc: Ram Pai <linuxram@...ibm.com>
Cc: Thiago Jung Bauermann <bauerman@...ux.ibm.com>
Cc: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
---
b/arch/x86/include/asm/fpu/xstate.h | 29 +++++++++++++++++++++++++++++
b/arch/x86/include/asm/pgtable.h | 29 -----------------------------
b/arch/x86/kernel/process_64.c | 1 +
b/arch/x86/kvm/svm/sev.c | 1 +
b/arch/x86/kvm/x86.c | 1 +
b/arch/x86/mm/pkeys.c | 1 +
6 files changed, 33 insertions(+), 29 deletions(-)
diff -puN arch/x86/include/asm/fpu/xstate.h~move-write_pkru arch/x86/include/asm/fpu/xstate.h
--- a/arch/x86/include/asm/fpu/xstate.h~move-write_pkru 2021-05-27 16:40:23.110705472 -0700
+++ b/arch/x86/include/asm/fpu/xstate.h 2021-05-27 16:40:23.132705472 -0700
@@ -6,6 +6,7 @@
#include <linux/types.h>
#include <asm/processor.h>
+#include <asm/fpu/api.h>
#include <asm/user.h>
/* Bit 63 of XCR0 is reserved for future expansion */
@@ -116,4 +117,32 @@ void copy_kernel_to_dynamic_supervisor(s
/* Validate an xstate header supplied by userspace (ptrace or sigreturn) */
int validate_user_xstate_header(const struct xstate_header *hdr);
+static inline u32 read_pkru(void)
+{
+ if (boot_cpu_has(X86_FEATURE_OSPKE))
+ return rdpkru();
+ return 0;
+}
+
+static inline void write_pkru(u32 pkru)
+{
+ struct pkru_state *pk;
+
+ if (!boot_cpu_has(X86_FEATURE_OSPKE))
+ return;
+
+ pk = get_xsave_addr(¤t->thread.fpu.state.xsave, XFEATURE_PKRU);
+
+ /*
+ * The PKRU value in xstate needs to be in sync with the value that is
+ * written to the CPU. The FPU restore on return to userland would
+ * otherwise load the previous value again.
+ */
+ fpregs_lock();
+ if (pk)
+ pk->pkru = pkru;
+ __write_pkru(pkru);
+ fpregs_unlock();
+}
+
#endif
diff -puN arch/x86/include/asm/pgtable.h~move-write_pkru arch/x86/include/asm/pgtable.h
--- a/arch/x86/include/asm/pgtable.h~move-write_pkru 2021-05-27 16:40:23.114705472 -0700
+++ b/arch/x86/include/asm/pgtable.h 2021-05-27 16:40:23.135705472 -0700
@@ -126,35 +126,6 @@ static inline int pte_dirty(pte_t pte)
return pte_flags(pte) & _PAGE_DIRTY;
}
-
-static inline u32 read_pkru(void)
-{
- if (boot_cpu_has(X86_FEATURE_OSPKE))
- return rdpkru();
- return 0;
-}
-
-static inline void write_pkru(u32 pkru)
-{
- struct pkru_state *pk;
-
- if (!boot_cpu_has(X86_FEATURE_OSPKE))
- return;
-
- pk = get_xsave_addr(¤t->thread.fpu.state.xsave, XFEATURE_PKRU);
-
- /*
- * The PKRU value in xstate needs to be in sync with the value that is
- * written to the CPU. The FPU restore on return to userland would
- * otherwise load the previous value again.
- */
- fpregs_lock();
- if (pk)
- pk->pkru = pkru;
- __write_pkru(pkru);
- fpregs_unlock();
-}
-
static inline int pte_young(pte_t pte)
{
return pte_flags(pte) & _PAGE_ACCESSED;
diff -puN arch/x86/kernel/process_64.c~move-write_pkru arch/x86/kernel/process_64.c
--- a/arch/x86/kernel/process_64.c~move-write_pkru 2021-05-27 16:40:23.117705472 -0700
+++ b/arch/x86/kernel/process_64.c 2021-05-27 16:40:23.138705472 -0700
@@ -41,6 +41,7 @@
#include <linux/syscalls.h>
#include <asm/processor.h>
+#include <asm/fpu/xstate.h>
#include <asm/fpu/internal.h>
#include <asm/mmu_context.h>
#include <asm/prctl.h>
diff -puN arch/x86/kvm/svm/sev.c~move-write_pkru arch/x86/kvm/svm/sev.c
--- a/arch/x86/kvm/svm/sev.c~move-write_pkru 2021-05-27 16:40:23.121705472 -0700
+++ b/arch/x86/kvm/svm/sev.c 2021-05-27 16:40:23.142705472 -0700
@@ -16,6 +16,7 @@
#include <linux/swap.h>
#include <linux/processor.h>
#include <linux/trace_events.h>
+#include <asm/fpu/xstate.h>
#include <asm/fpu/internal.h>
#include <asm/trapnr.h>
diff -puN arch/x86/kvm/x86.c~move-write_pkru arch/x86/kvm/x86.c
--- a/arch/x86/kvm/x86.c~move-write_pkru 2021-05-27 16:40:23.125705472 -0700
+++ b/arch/x86/kvm/x86.c 2021-05-27 16:40:23.150705472 -0700
@@ -66,6 +66,7 @@
#include <asm/desc.h>
#include <asm/mce.h>
#include <linux/kernel_stat.h>
+#include <asm/fpu/xstate.h>
#include <asm/fpu/internal.h> /* Ugh! */
#include <asm/pvclock.h>
#include <asm/div64.h>
diff -puN arch/x86/mm/pkeys.c~move-write_pkru arch/x86/mm/pkeys.c
--- a/arch/x86/mm/pkeys.c~move-write_pkru 2021-05-27 16:40:23.128705472 -0700
+++ b/arch/x86/mm/pkeys.c 2021-05-27 16:40:23.151705472 -0700
@@ -10,6 +10,7 @@
#include <asm/cpufeature.h> /* boot_cpu_has, ... */
#include <asm/mmu_context.h> /* vma_pkey() */
+#include <asm/fpu/xstate.h> /* read/write_pkru() */
#include <asm/fpu/internal.h> /* init_fpstate */
int __execute_only_pkey(struct mm_struct *mm)
_
Powered by blists - more mailing lists