[PATCH V8 06/44] mm/pkeys: Add Kconfig options for PKS

ira.weiny
2022-01-27T17:56:14Z

From: Ira Weiny <ira.weiny@intel.com>

Protection Key Supervisor, PKS, is a feature used by kernel code only.
As such if no kernel users are configured the PKS code is unnecessary
overhead.

Define a Kconfig structure which allows kernel code to detect PKS
support by an architecture and then subsequently enable that support
within the architecture.

ARCH_HAS_SUPERVISOR_PKEYS indicates to kernel consumers that an
architecture supports pkeys. PKS users can then select
ARCH_ENABLE_SUPERVISOR_PKEYS to turn on the support within the
architecture.

If ARCH_ENABLE_SUPERVISOR_PKEYS is not selected architectures avoid the
PKS overhead.

ARCH_ENABLE_SUPERVISOR_PKEYS remains off until the first kernel use case
sets it.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>

---
Changes for V8
Split this out to a single change patch
---
arch/x86/Kconfig | 1 +
mm/Kconfig | 4 ++++
2 files changed, 5 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ebe8fc76949a..a30fe85e27ac 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1867,6 +1867,7 @@ config X86_INTEL_MEMORY_PROTECTION_KEYS
depends on X86_64 && (CPU_SUP_INTEL || CPU_SUP_AMD)
select ARCH_USES_HIGH_VMA_FLAGS
select ARCH_HAS_PKEYS
+ select ARCH_HAS_SUPERVISOR_PKEYS
help
Memory Protection Keys provides a mechanism for enforcing
page-based protections, but without requiring modification of the
diff --git a/mm/Kconfig b/mm/Kconfig
index 3326ee3903f3..46f2bb15aa4e 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -804,6 +804,10 @@ config ARCH_USES_HIGH_VMA_FLAGS
bool
config ARCH_HAS_PKEYS
bool
+config ARCH_HAS_SUPERVISOR_PKEYS
+ bool
+config ARCH_ENABLE_SUPERVISOR_PKEYS
+ bool

config PERCPU_STATS
bool "Collect percpu memory statistics"
--
2.31.1