[PATCH v6] arch/x86: Update config and kernel doc for MPK feature on AMD

From: Babu Moger
Date: Thu May 28 2020 - 12:08:35 EST


AMD's next generation of EPYC processors support the MPK (Memory
Protection Keys) feature. Update the dependency and documentation.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
Reviewed-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
---
v6:
- Removed X86_MEMORY_PROTECTION_KEYS. Just keeping the dependency
and doc update.

v5:
https://lore.kernel.org/lkml/158940940570.47998.17107695356894054769.stgit@xxxxxxxxxxxxxxxxxxx/
- Just submiting the first config update patch. Paulo said he already queued
patch 2 & 3.
- This patch addresses the few text changes suggested by Dave Hansen.

v4:
https://lore.kernel.org/lkml/158932780954.44260.4292038705292213548.stgit@xxxxxxxxxxxxxxxxxxx/
- Removed all the source changes related to config parameter.
Just kept the doc cahnges and add new config parameter
X86_MEMORY_PROTECTION_KEYS which shadows X86_INTEL_MEMORY_PROTECTION_KEYS.
- Minor change in feature detection in kvm/cpuid.c

v3:
https://lore.kernel.org/lkml/158923982830.20128.14580309786525588408.stgit@xxxxxxxxxxxxxxxxxxx/#r
- Fixed the problem Jim Mattson pointed out which can cause pkru
resources to get corrupted during host and guest switches.
- Moved the PKU feature detection code from VMX.c to common code.

v2:
https://lore.kernel.org/lkml/158897190718.22378.3974700869904223395.stgit@xxxxxxxxxxxxxxxxxxx/
- Introduced intermediate config option X86_MEMORY_PROTECTION_KEYS to
avoid user propmpts. Kept X86_INTEL_MEMORY_PROTECTION_KEYS as is.
Eventually, we will be moving to X86_MEMORY_PROTECTION_KEYS after
couple of kernel revisions.
- Moved pkru data structures to kvm_vcpu_arch. Moved save/restore pkru
to kvm_load_host_xsave_state/kvm_load_guest_xsave_state.

v1:
https://lore.kernel.org/lkml/158880240546.11615.2219410169137148044.stgit@xxxxxxxxxxxxxxxxxxx/

Documentation/core-api/protection-keys.rst | 5 +++--
arch/x86/Kconfig | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Documentation/core-api/protection-keys.rst b/Documentation/core-api/protection-keys.rst
index 49d9833af871..ec575e72d0b2 100644
--- a/Documentation/core-api/protection-keys.rst
+++ b/Documentation/core-api/protection-keys.rst
@@ -5,8 +5,9 @@ Memory Protection Keys
======================

Memory Protection Keys for Userspace (PKU aka PKEYs) is a feature
-which is found on Intel's Skylake "Scalable Processor" Server CPUs.
-It will be avalable in future non-server parts.
+which is found on Intel's Skylake (and later) "Scalable Processor"
+Server CPUs. It will be available in future non-server Intel parts
+and future AMD processors.

For anyone wishing to test or use this feature, it is available in
Amazon's EC2 C5 instances and is known to work there using an Ubuntu
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1197b5596d5a..db248baa829a 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1887,10 +1887,10 @@ config X86_UMIP
results are dummy.

config X86_INTEL_MEMORY_PROTECTION_KEYS
- prompt "Intel Memory Protection Keys"
+ prompt "Memory Protection Keys"
def_bool y
# Note: only available in 64-bit mode
- depends on CPU_SUP_INTEL && X86_64
+ depends on X86_64 && (CPU_SUP_INTEL || CPU_SUP_AMD)
select ARCH_USES_HIGH_VMA_FLAGS
select ARCH_HAS_PKEYS
---help---