[PATCH V8 17/44] mm/pkeys: Introduce pks_mk_noaccess()

ira.weiny
2022-01-27T17:55:31Z

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

After a valid access for a PKS protected page Users will need to change
the protections back to No Access for their Pkey

Define pks_mk_noaccess() to update the specified Pkey

Add documentation.

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

---
Changes for V8
Make the call inline
Split this patch out from 'Add PKS kernel API'
Include documentation in this patch
---
Documentation/core-api/protection-keys.rst | 2 +-
include/linux/pkeys.h | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Documentation/core-api/protection-keys.rst b/Documentation/core-api/protection-keys.rst
index e4a27b93f3d4..115afc67153f 100644
--- a/Documentation/core-api/protection-keys.rst
+++ b/Documentation/core-api/protection-keys.rst
@@ -145,7 +145,7 @@ Changing permissions of individual keys
---------------------------------------

.. kernel-doc:: include/linux/pks-keys.h
- :identifiers: pks_mk_readwrite
+ :identifiers: pks_mk_readwrite pks_mk_noaccess

MSR details
-----------
diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h
index 73b554b99123..5f4965f5449b 100644
--- a/include/linux/pkeys.h
+++ b/include/linux/pkeys.h
@@ -57,6 +57,18 @@ static inline bool arch_pkeys_enabled(void)

void pks_update_protection(int pkey, u32 protection);

+/**
+ * pks_mk_noaccess() - Disable all access to the domain
+ * @pkey: the pkey for which the access should change.
+ *
+ * Disable all access to the domain specified by pkey. This is not a global
+ * update and only affects the current running thread.
+ */
+static inline void pks_mk_noaccess(int pkey)
+{
+ pks_update_protection(pkey, PKEY_DISABLE_ACCESS);
+}
+
/**
* pks_mk_readwrite() - Make the domain Read/Write
* @pkey: the pkey for which the access should change.
@@ -71,6 +83,7 @@ static inline void pks_mk_readwrite(int pkey)

#else /* !CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS */

+static inline void pks_mk_noaccess(int pkey) {}
static inline void pks_mk_readwrite(int pkey) {}

#endif /* CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS */
--
2.31.1