Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp622404rdh; Wed, 23 Aug 2023 09:49:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqbDLdPktrnFWpxP9AHIgGFxJicQSa0aoIXXRVK2E6EBeEuw4jijntLl0y7xf7PDaojvHX X-Received: by 2002:a17:906:7691:b0:99b:f66a:3189 with SMTP id o17-20020a170906769100b0099bf66a3189mr10373950ejm.8.1692809368628; Wed, 23 Aug 2023 09:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692809368; cv=none; d=google.com; s=arc-20160816; b=c0KPws6WuhBAZ07Qpz2mvLS3p/ZOkweXIoQJgZVxwx6CHOF3PoA7dYygKOGE6zuslX DomlL9JluPS2TWMJepKTID3qlEeBd7QfHPMYtBPqP0yIerPeu6zk5OFfx8da/BlHsY23 DjXwhWsJaO79cNfycg+0arOKdnvptxJr5/E1DNC3WjZDdSEYBFoYiVi9OUgq6OaRG7RI 04EFieNLve38G+fk/DX/FG5UNm7yVxf7ylJh5hY03zzV36UX2GMtyyeDsoRFjZiFIPT6 PLeRXiYC/RS1tRmsBYZTGqhhMH/XQlsROWAqAyDrlpG3QwWgLbmBd8m4UNDdqH28JRj8 26ig== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Kvvr3fnXbq2HHvMhlDHS/wJAJ6ZRdrhcIm2Sezd7beA=; fh=imQ/NyNBnYYmfGk25mVbc8KayF+owEio9SAkc/cwCHU=; b=UG8eXluOaeR3S+nmKOMdXWgJd6Xkj9pwHPl/uui+wOvdfWo9nWQytJjAE7uapwRKtL 6X7LvGJLNUhtaA7oSeO8zJOX438jdVPFu7fkQWAVQsBjXev1dKc93CuaE6mQjT4KIdB6 hU18YbL3+sMKjQL8vVAxxpw1zplY/VST18y+PoPnSH+cr5WTjw+ZwiCqTzfszCHwAma1 RdsLi14Jp+CmWG1VvdcQMqcWTuiRJoNxBk47J4EHRVEaZWkl0IRzSQYzfpEortBdxIsZ 80AeZ3BkQ/SpcItOKP1wa7xTlaPFQd2LbJ6o83SlyoOeVYgpeuRLMdJ/X5PCbnmOcDGL bRfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a170906234600b00992e21b04aasi8629018eja.720.2023.08.23.09.49.03; Wed, 23 Aug 2023 09:49:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235723AbjHWNRx (ORCPT + 99 others); Wed, 23 Aug 2023 09:17:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235397AbjHWNRr (ORCPT ); Wed, 23 Aug 2023 09:17:47 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17DE8E6A; Wed, 23 Aug 2023 06:17:21 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 740FB16F8; Wed, 23 Aug 2023 06:17:57 -0700 (PDT) Received: from e121798.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1BF5A3F740; Wed, 23 Aug 2023 06:17:10 -0700 (PDT) From: Alexandru Elisei To: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com Cc: pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH RFC 29/37] mm: arm64: Define the PAGE_METADATA_NONE page protection Date: Wed, 23 Aug 2023 14:13:42 +0100 Message-Id: <20230823131350.114942-30-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823131350.114942-1-alexandru.elisei@arm.com> References: <20230823131350.114942-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define the PAGE_METADATA_NONE page protection to be used when a page with metadata doesn't have metadata storage reserved. For arm64, this is accomplished by adding a new page table entry software bit PTE_METADATA_NONE. Linux doesn't set any of the PBHA bits in entries from the last level of the translation table and it doesn't use the TCR_ELx.HWUxx bits. This makes it safe to define PTE_METADATA_NONE as bit 59. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/pgtable-prot.h | 2 ++ arch/arm64/include/asm/pgtable.h | 16 ++++++++++++++-- include/linux/pgtable.h | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index eed814b00a38..ed2a98ec4e95 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -19,6 +19,7 @@ #define PTE_SPECIAL (_AT(pteval_t, 1) << 56) #define PTE_DEVMAP (_AT(pteval_t, 1) << 57) #define PTE_PROT_NONE (_AT(pteval_t, 1) << 58) /* only when !PTE_VALID */ +#define PTE_METADATA_NONE (_AT(pteval_t, 1) << 59) /* only when PTE_PROT_NONE */ /* * This bit indicates that the entry is present i.e. pmd_page() @@ -98,6 +99,7 @@ extern bool arm64_use_ng_mappings; }) #define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN) +#define PAGE_METADATA_NONE __pgprot((_PAGE_DEFAULT & ~PTE_VALID) | PTE_PROT_NONE | PTE_METADATA_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN) /* shared+writable pages are clean by default, hence PTE_RDONLY|PTE_WRITE */ #define PAGE_SHARED __pgprot(_PAGE_SHARED) #define PAGE_SHARED_EXEC __pgprot(_PAGE_SHARED_EXEC) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 944860d7090e..2e42f7713425 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -451,6 +451,18 @@ static inline int pmd_protnone(pmd_t pmd) } #endif +#ifdef CONFIG_MEMORY_METADATA +static inline bool pte_metadata_none(pte_t pte) +{ + return (((pte_val(pte) & (PTE_VALID | PTE_PROT_NONE)) == PTE_PROT_NONE) + && (pte_val(pte) & PTE_METADATA_NONE)); +} +static inline bool pmd_metadata_none(pmd_t pmd) +{ + return pte_metadata_none(pmd_pte(pmd)); +} +#endif + #define pmd_present_invalid(pmd) (!!(pmd_val(pmd) & PMD_PRESENT_INVALID)) static inline int pmd_present(pmd_t pmd) @@ -809,8 +821,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) * in MAIR_EL1. The mask below has to include PTE_ATTRINDX_MASK. */ const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY | - PTE_PROT_NONE | PTE_VALID | PTE_WRITE | PTE_GP | - PTE_ATTRINDX_MASK; + PTE_PROT_NONE | PTE_METADATA_NONE | PTE_VALID | + PTE_WRITE | PTE_GP | PTE_ATTRINDX_MASK; /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) pte = pte_mkdirty(pte); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 5063b482e34f..0119ffa2c0ab 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1340,6 +1340,18 @@ static inline int pmd_protnone(pmd_t pmd) } #endif /* CONFIG_NUMA_BALANCING */ +#ifndef CONFIG_MEMORY_METADATA +static inline bool pte_metadata_none(pte_t pte) +{ + return false; +} + +static inline bool pmd_metadata_none(pmd_t pmd) +{ + return false; +} +#endif /* CONFIG_MEMORY_METADATA */ + #endif /* CONFIG_MMU */ #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -- 2.41.0