From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A07DDC433E6 for ; Fri, 5 Mar 2021 11:21:01 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13E8A64E6B for ; Fri, 5 Mar 2021 11:21:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13E8A64E6B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yd8URbv7OUOv/wjtiKYlw8H+YOJFzhB63ZA9hpdQ8rM=; b=CKSeQQCefjuInV7U995q+JTbu dQwvgbFO+gnJ1CWo1SUd9itx9m7danNCcc/lGHFjimGjInG/umwh5L9iBH2HXlUWOKN8wdmLhJD0j 9zbebDAVwF/UeXAxNvT0+aQ/A9MBn9YDaaNHk/x6m93zlICawP/Mhj3CHStAa9O0NSj4NkpfZAlHP XumSbTnxdEr2bfCFZtPgm0aCi52Dq1m+ha4DtEEh+gzQ4joK/uHBinXnNOHRfSZRh/4viV5rLLCKM NDoP8RWdEfBZQT0y/nefq6unLwk4eTjcKVh7eTy15BUkudJQh3noJILFuWWQUojpnvrbvCeVwljGT 7OaaKnT2g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lI8UN-00EjHN-Mr; Fri, 05 Mar 2021 11:19:23 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lI8UG-00EjG3-Pw for linux-arm-kernel@lists.infradead.org; Fri, 05 Mar 2021 11:19:19 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 47D9664E6B; Fri, 5 Mar 2021 11:19:12 +0000 (UTC) Date: Fri, 5 Mar 2021 11:19:09 +0000 From: Catalin Marinas To: Patrick Daly Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Vincenzo Frascino , Anshuman Khandual , linux-mm@kvack.org Subject: Re: [PATCH] arm64: mte: Use PAGE_KERNEL_TAGGED in arch_add_memory Message-ID: <20210305111908.GA23855@arm.com> References: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1614745263-27827-1-git-send-email-pdaly@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210305_111917_547396_B786CB82 X-CRM114-Status: GOOD ( 24.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 > --- > 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