All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Patrick Daly <pdaly@codeaurora.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Will Deacon <will@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory
Date: Fri, 5 Mar 2021 11:19:09 +0000	[thread overview]
Message-ID: <20210305111908.GA23855@arm.com> (raw)
In-Reply-To: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org>

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@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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-03-05 11:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  4:21 [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory Patrick Daly
2021-03-05 11:19 ` Catalin Marinas [this message]
2021-03-05 15:43   ` Catalin Marinas
2021-03-05 15:43     ` Catalin Marinas
2021-03-05 15:55     ` David Hildenbrand
2021-03-05 15:55       ` David Hildenbrand
2021-03-05 17:44       ` Catalin Marinas
2021-03-05 17:44         ` Catalin Marinas
2021-03-08 11:00         ` David Hildenbrand
2021-03-08 11:00           ` David Hildenbrand
2021-03-08 11:18           ` Catalin Marinas
2021-03-08 11:18             ` Catalin Marinas
2021-03-08 23:44             ` Patrick Daly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210305111908.GA23855@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=pdaly@codeaurora.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.