From patchwork Mon Mar 15 13:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 400460 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3461596jai; Mon, 15 Mar 2021 07:16:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJfN930Okb6Vs4TLKfzmXk3hYxLMNSw4OAJShB57EpefT5n+z9U6mCX3GlIzc0E0QRheci X-Received: by 2002:a05:6402:1cc1:: with SMTP id ds1mr29684162edb.135.1615817666866; Mon, 15 Mar 2021 07:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817666; cv=none; d=google.com; s=arc-20160816; b=Q8U8bFuOVqiPRpLhevh6YJs7b0nOY6KIvh6di+zBqkvRF+1oA7fUS0iMBVtv+o8qYY svGtqnL0Pv101GBEZ4U0b5BW3jZKUTcATj5H3rz016dt2Hiq+Oq5apEvsJNwySSTYp99 E3kMOmV+iP8yPcpvbTrazQREanErawScWYujUvUgtiPrIHWKwrtAn+xvsGcx/1C04BJc vK3RthXnUmbRvUEvu7JjUpaJZCzl2M0LS6k/xJWfqAY+3tWSatiaRERl6mriwUQ+K5+g fPE81/b1lk6toFg1s5Hzn6ijPhZqKCa0D7RhDpyS/Ya4p+f8YOObVknGZGcf1H+HJHbb 1MDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7ZITF6Q1OqL72uPE9Z6RqQF0DPIvOgwgSUhx+F9EUy4=; b=DDKgV28oOqovQIz0kyMJ2FNWcZpZeoKlVUmt2z8whgi7qyOaukd/UGrvIXLWxN93W8 aer0tOhcNW0nmMJkWM2K5tivdvCBSlPEKPP2T/QvKET0rbpxvKTB65u7YFmMVTZIxSHr sxjMjgR+YKcSaMn0O7zWpz2rnCDvMs1AAPCgWhjTnenSfu3T8RLqBCzEcknteD4ZhGRy lZwOJfnYC6IAprf0CQzig4lFJzq1SG4ozThdiwlgAJsLBJsFFZWT6xSEETL8biEpq79W glqudLsENbQFZGZ6jdZQs14oMob3IekoNGKuutQ/8Y9IgHcA1LsOI/TtwJYaQrzgmSTf vDWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hxjuoRYh; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si993553ede.37.2021.03.15.07.14.26; Mon, 15 Mar 2021 07:14:26 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hxjuoRYh; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235043AbhCOOHC (ORCPT + 12 others); Mon, 15 Mar 2021 10:07:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233533AbhCOOB6 (ORCPT ); Mon, 15 Mar 2021 10:01:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A1DF364F5C; Mon, 15 Mar 2021 14:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816918; bh=DPLZ20FHEm6buiAlNMc6sF4N3Wh4qxUvn6HmEX26kFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hxjuoRYhdaBFcGosLDD3RW9EhpK3Ui9sqbSl+dsXaU4qG994T1fBdvvPxwIfomV8W gEjckyaTuy/5V4N89LmjnrmxYLHI9gR2lRyq+nhkoIDZ0l2UyLRb5iQb1eoiKuVKey HHEOHPFOhwz5YzRuODFew81AY4xxpUqewxaFyobQ= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Patrick Daly , Will Deacon , Andrew Morton , Vincenzo Frascino , David Hildenbrand , Anshuman Khandual Subject: [PATCH 5.10 187/290] arm64: mte: Map hotplugged memory as Normal Tagged Date: Mon, 15 Mar 2021 14:54:40 +0100 Message-Id: <20210315135548.230965788@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Greg Kroah-Hartman From: Catalin Marinas commit d15dfd31384ba3cb93150e5f87661a76fa419f74 upstream. In a system supporting MTE, the linear map must allow reading/writing allocation tags by setting the memory type as Normal Tagged. Currently, this is only handled for memory present at boot. Hotplugged memory uses Normal non-Tagged memory. Introduce pgprot_mhp() for hotplugged memory and use it in add_memory_resource(). The arm64 code maps pgprot_mhp() to pgprot_tagged(). Note that ZONE_DEVICE memory should not be mapped as Tagged and therefore setting the memory type in arch_add_memory() is not feasible. Signed-off-by: Catalin Marinas Fixes: 0178dc761368 ("arm64: mte: Use Normal Tagged attributes for the linear map") Reported-by: Patrick Daly Tested-by: Patrick Daly Link: https://lore.kernel.org/r/1614745263-27827-1-git-send-email-pdaly@codeaurora.org Cc: # 5.10.x Cc: Will Deacon Cc: Andrew Morton Cc: Vincenzo Frascino Cc: David Hildenbrand Reviewed-by: David Hildenbrand Reviewed-by: Vincenzo Frascino Reviewed-by: Anshuman Khandual Link: https://lore.kernel.org/r/20210309122601.5543-1-catalin.marinas@arm.com Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/pgtable-prot.h | 1 - arch/arm64/include/asm/pgtable.h | 3 +++ arch/arm64/mm/mmu.c | 3 ++- include/linux/pgtable.h | 4 ++++ mm/memory_hotplug.c | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -66,7 +66,6 @@ extern bool arm64_use_ng_mappings; #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) #define PAGE_KERNEL __pgprot(PROT_NORMAL) -#define PAGE_KERNEL_TAGGED __pgprot(PROT_NORMAL_TAGGED) #define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY) #define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY) #define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN) --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -484,6 +484,9 @@ static inline pmd_t pmd_mkdevmap(pmd_t p __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN) #define pgprot_device(prot) \ __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_DEVICE_nGnRE) | PTE_PXN | PTE_UXN) +#define pgprot_tagged(prot) \ + __pgprot_modify(prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_TAGGED)) +#define pgprot_mhp pgprot_tagged /* * DMA allocations for non-coherent devices use what the Arm architecture calls * "Normal non-cacheable" memory, which permits speculation, unaligned accesses --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -502,7 +502,8 @@ static void __init map_mem(pgd_t *pgdp) * if MTE is present. Otherwise, it has the same attributes as * PAGE_KERNEL. */ - __map_memblock(pgdp, start, end, PAGE_KERNEL_TAGGED, flags); + __map_memblock(pgdp, start, end, pgprot_tagged(PAGE_KERNEL), + flags); } /* --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -857,6 +857,10 @@ static inline void ptep_modify_prot_comm #define pgprot_device pgprot_noncached #endif +#ifndef pgprot_mhp +#define pgprot_mhp(prot) (prot) +#endif + #ifdef CONFIG_MMU #ifndef pgprot_modify #define pgprot_modify pgprot_modify --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1020,7 +1020,7 @@ static int online_memory_block(struct me */ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) { - struct mhp_params params = { .pgprot = PAGE_KERNEL }; + struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) }; u64 start, size; bool new_node = false; int ret;