[PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory
Catalin Marinas
catalin.marinas at arm.com
Fri Mar 5 11:19:09 GMT 2021
Hi Patrick,
Thanks for this. Adding a few more people and linux-mm.
On Tue, Mar 02, 2021 at 08:21:03PM -0800, Patrick Daly wrote:
> In a system which supports MTE, the linear kernel region must allow
> reading/writing allocation tags. For memory present at boot this
> is already being done in map_mem(). Add the same in arch_add_memory().
>
> Signed-off-by: Patrick Daly <pdaly at codeaurora.org>
> ---
> arch/arm64/mm/mmu.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 9b25d60b..0fcfe90 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -1463,6 +1463,7 @@ int arch_add_memory(int nid, u64 start, u64 size,
> struct mhp_params *params)
> {
> int ret, flags = 0;
> + pgprot_t pgprot;
>
> if (!inside_linear_region(start, size)) {
> pr_err("[%llx %llx] is outside linear mapping region\n", start, start + size);
> @@ -1477,8 +1478,17 @@ int arch_add_memory(int nid, u64 start, u64 size,
> IS_ENABLED(CONFIG_KFENCE))
> flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
>
> + /*
> + * The linear map must allow allocation tags reading/writing
> + * if MTE is present. Otherwise, it has the same attributes as
> + * PAGE_KERNEL.
> + */
> + pgprot = params->pgprot;
> + if (pgprot_val(pgprot) == pgprot_val(PAGE_KERNEL))
> + pgprot = PAGE_KERNEL_TAGGED;
> +
> __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start),
> - size, params->pgprot, __pgd_pgtable_alloc,
> + size, pgprot, __pgd_pgtable_alloc,
> flags);
We'll need a similar pattern for vmalloc() once we have the khwasan
support in place. So we could add a pgprot_tagged() function (similar to
pgprot_writecombine() etc.) which does the above check and returns
PAGE_KERNEL_TAGGED, maybe only checking the PTE_ATTRINDX_MASK bits
rather than the whole prot bits.
However, the bigger problem is that arch_add_memory() is also called for
ZONE_DEVICE mappings and we can't always guarantee that such range
supports tagging (most likely it doesn't, e.g. persistent memory),
leading to potential external aborts.
One option is to expand mhp_params to pass additional information so
that the arch code can make the right decision. Another option is to
make PAGE_KERNEL_TAGGED global which is just PAGE_KERNEL for all the
other architectures and use it in the core code.
Yet another option which we haven't fully explored with MTE is to have
PAGE_KERNEL always tagged but add a new PAGE_KERNEL_DEVICE (or
_UNTAGGED) for specific cases like ZONE_DEVICE. We need to make sure
that PAGE_KERNEL doesn't end up in places where the backing memory does
not support tags.
I'll give the last option a quick try and see if it falls apart (just
changing PAGE_KERNEL to tagged). In terms of tag cache usage, it
probably won't have much of an impact since the whole of the linear map
is tagged already.
--
Catalin
More information about the linux-arm-kernel
mailing list