[PATCH RFC v9 05/25] arm64: Implement asm/kpkeys.h using POE
Linu Cherian
linu.cherian at arm.com
Tue Sep 1 07:48:37 PDT 2026
Kevin,
On Tue, Aug 18, 2026 at 03:08:47PM +0100, Kevin Brodsky wrote:
> Implement the kpkeys interface if CONFIG_ARM64_POE is enabled.
> The permissions for pkey 0 are set to RWX as this pkey is also used
> for code mappings. POR_EL1 is left untouched if we have already
> entered the requested context.
>
> To allow <asm/kpkeys.h> to be included from assembly, also add
> appropriate #ifdef's to <asm/por.h>.
>
> Signed-off-by: Kevin Brodsky <kevin.brodsky at arm.com>
> ---
> arch/arm64/include/asm/kpkeys.h | 67 +++++++++++++++++++++++++++++++++++
> arch/arm64/include/asm/kpkeys_types.h | 15 ++++++++
> arch/arm64/include/asm/por.h | 4 +++
> 3 files changed, 86 insertions(+)
>
> diff --git a/arch/arm64/include/asm/kpkeys.h b/arch/arm64/include/asm/kpkeys.h
> new file mode 100644
> index 000000000000..09fd5a849cb0
> --- /dev/null
> +++ b/arch/arm64/include/asm/kpkeys.h
> @@ -0,0 +1,67 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __ASM_KPKEYS_H
> +#define __ASM_KPKEYS_H
> +
> +#include <linux/kpkeys_types.h>
> +
> +#include <asm/barrier.h>
> +#include <asm/cpufeature.h>
> +#include <asm/por.h>
> +
> +/*
> + * Equivalent to por_set_kpkeys_context(0, KPKEYS_CTX_DEFAULT), but can also be
> + * used in assembly.
> + */
> +#define POR_EL1_INIT POR_ELx_PERM_PREP(0, POE_RWX)
IMHO, moving this macro defintion to "arm64: Enable kpkeys" , would be better as
this patch is about implementing arch helpers.
> +
> +#ifndef __ASSEMBLY__
> +
> +static inline bool arch_supports_kpkeys(void)
> +{
> + return system_supports_poe();
> +}
> +
> +#ifdef CONFIG_ARM64_POE
> +
> +static inline u64 por_set_kpkeys_context(u64 por, enum kpkeys_ctx ctx)
> +{
> + por = por_elx_set_pkey_perms(por, 0, POE_RWX);
Guess, we would want to set the pkey index 0 only when,
ctx == KPKEYS_CTX_DEFAULT and it need to be set only once.
IIUC, we wouldnt want to deal with that every time we set a new
context. ie. update only what is relevant.
--
Linu Cherian
More information about the linux-arm-kernel
mailing list