[PATCH V9 06/45] mm/pkeys: Add Kconfig options for PKS

From: ira . weiny
Date: Thu Mar 10 2022 - 12:20:46 EST


From: Ira Weiny <ira.weiny@xxxxxxxxx>

Consumers wishing to implement additional protections on memory pages
can use PKS. However, PKS is only available on some architectures.

For this reason PKS code, both in the core and in the consumers, is dead
code without PKS being both available and used.

Add Kconfig options to allow for the elimination of unneeded code by
detecting architecture PKS support (ARCH_HAS_SUPERVISOR_PKEYS) and
requiring an indication of consumer need (ARCH_ENABLE_SUPERVISOR_PKEYS).

In this patch ARCH_ENABLE_SUPERVISOR_PKEYS remains off until the first
kernel consumer sets it.

Cc: "Moger, Babu" <Babu.Moger@xxxxxxx>
Signed-off-by: Ira Weiny <ira.weiny@xxxxxxxxx>

---
Changes for V9
Dave Hansen
Don't exclude AMD, cpu supported bits will properly turn
the feature off.
Clarify commit message
Depend on CPU_SUP_INTEL

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 9f5bd41bf660..459948622a73 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1868,6 +1868,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.35.1