summaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/pkru.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/include/asm/pkru.h')
-rw-r--r--arch/x86/include/asm/pkru.h17
1 files changed, 4 insertions, 13 deletions
diff --git a/arch/x86/include/asm/pkru.h b/arch/x86/include/asm/pkru.h
index 7e4550911c51..ccc539faa5bb 100644
--- a/arch/x86/include/asm/pkru.h
+++ b/arch/x86/include/asm/pkru.h
@@ -41,23 +41,14 @@ static inline u32 read_pkru(void)
static inline void write_pkru(u32 pkru)
{
- struct pkru_state *pk;
-
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
return;
-
- pk = get_xsave_addr(&current->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.
+ * WRPKRU is relatively expensive compared to RDPKRU.
+ * Avoid WRPKRU when it would not change the value.
*/
- fpregs_lock();
- if (pk)
- pk->pkru = pkru;
- __write_pkru(pkru);
- fpregs_unlock();
+ if (pkru != rdpkru())
+ wrpkru(pkru);
}
static inline void pkru_write_default(void)