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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D5C1C433EF for ; Mon, 22 Nov 2021 09:18:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D03EE6B0071; Mon, 22 Nov 2021 04:17:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8C596B0072; Mon, 22 Nov 2021 04:17:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2D426B0073; Mon, 22 Nov 2021 04:17:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 9E5ED6B0071 for ; Mon, 22 Nov 2021 04:17:58 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6307A180BA55A for ; Mon, 22 Nov 2021 09:17:48 +0000 (UTC) X-FDA: 78836013816.31.76E5107 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf22.hostedemail.com (Postfix) with ESMTP id 607CB191F for ; Mon, 22 Nov 2021 09:17:47 +0000 (UTC) Received: by mail-qt1-f175.google.com with SMTP id o17so15953726qtk.1 for ; Mon, 22 Nov 2021 01:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PNk9AvIUG3nSldGQQKqTpubI/KNmMnFk9sAVMdVoa/g=; b=lny072LuhQ0Lkgl+X0xJam5iiuyvUM5fb+hKco7V8b8WemAcrO32LeZd5jJPHrQP73 PEnDr3Q3kx0qK6NdlxwmMKcRCOOBKh9koGjnRF+Q3W8E1hvtI2TJC75XBOQGulWhPjb3 suBQWbYzhsqfTVZvn+fvkzGfYAnLkHn7ECUUn3NrCY8US66BPsuZ3kWFiRuBmxUcnSBp fooQzewalQDnSglrr4isIDwUzfvFjXilDaGIjfBHCslXtqNAzhM9Ugjgmy0MhqZgIASt 0QomSYAFEe37njcGMlki0iTqtprIMKXoS8Dl38DcjHWpP0+5w86owbsuOThX0UZX0Jn3 +CwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PNk9AvIUG3nSldGQQKqTpubI/KNmMnFk9sAVMdVoa/g=; b=r+bc8GRiqxinc3HrFPyCy7Ts1sMtRwAlRFZKwpktN/HFjHB9nFCiC2vhlRXBxrOarD xBy4X+lzO343dZYRA6h+E8MtAY3wcn5V1uCafuFIAKwdmMTW+TRVXGsAtO2ULUuIqHoD v3Fzy9i0uN7QwApehKXv6uGjXWa94i/Amft0nF+Bse2Xq0tisxWfDIGcViQqsBKpbNRT ycf3Gtw1UUJA/bvqcnMTCQ3pU4+A/U2/KOyAGPk6oKFnFPB/lErDpKXdKBSsXrfEfBYv 7tIsHCxdzTsrEZ9HhvgVB+Ey2O322UcwqXPf75Zc7Vf7DNEAeLwRS6fSorCodVES3pyD UX1g== X-Gm-Message-State: AOAM530cFkdu/P1i9oiGE24b51BVCLBekTtYAZekQMp8uL2PHx2dWZXH sshpmRqMqtNmSqh8vy7Bh+WchF2fl8S7H3qXDQc= X-Google-Smtp-Source: ABdhPJy4nFBt+/aRd/2RXSe4ZodQ8MrQBuebeoTeJJkcdLrDSnkb9qdxCUqIcl0SdpS1c8E5VVbRiOLQ6lhAICFTlRA= X-Received: by 2002:a05:622a:587:: with SMTP id c7mr29051151qtb.354.1637572667206; Mon, 22 Nov 2021 01:17:47 -0800 (PST) MIME-Version: 1.0 References: <1637558929-22971-1-git-send-email-huangzhaoyang@gmail.com> In-Reply-To: From: Zhaoyang Huang Date: Mon, 22 Nov 2021 17:17:26 +0800 Message-ID: Subject: Re: [RFC PATCH] arch: arm64: introduce RODATA_FULL_USE_PTE_CONT To: Ard Biesheuvel Cc: Catalin Marinas , Will Deacon , Anshuman Khandual , Andrew Morton , Nicholas Piggin , Mike Rapoport , Pavel Tatashin , Christophe Leroy , Jonathan Marek , Zhaoyang Huang , Linux Memory Management List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 607CB191F X-Stat-Signature: ijd458jjifrgcjo8sqo17dpbxnqk5ogh Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lny072Lu; spf=pass (imf22.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1637572667-477795 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 22, 2021 at 5:04 PM Ard Biesheuvel wrote: > > On Mon, 22 Nov 2021 at 10:00, Zhaoyang Huang wrote: > > > > On Mon, Nov 22, 2021 at 4:52 PM Ard Biesheuvel wrote: > > > > > > On Mon, 22 Nov 2021 at 06:29, Huangzhaoyang wrote: > > > > > > > > From: Zhaoyang Huang > > > > > > > > Kernel linear mapping will be split to the smallest granularity when > > > > RODATA_FULL applied, which could lead to TLB pressure. Introduce a method > > > > to apply PTE_CONT on pte. > > > > > > > > Signed-off-by: Zhaoyang Huang > > > > > > How would this lead to TLB pressure, and how does the use of > > > contiguous mappings mitigate that? The linear mapping of the kernel is > > > rarely used, as all normal accesses to it go via the vmalloc region, > > > so in which case would TLB entries be allocated for this region in a > > > way that could cause a measurable performance impact? > > In fact, the patch is about to use PTE_CONT *OUT OF* the range of > > kernel text. > > OK, I had missed that, apologies. > > > Would you please have a look at the code. It apply > > PTE_CONT during map_mem and then clear it when load_module change the > > corresponding linear mapping to the area it use in vmalloc area. > > You cannot change the PTE_CONT attribute on live mappings. Is it an inner constraint from ASIC perspective? PTE_CONT is different to other attributes? > > > > > > > > > > > --- > > > > arch/arm64/Kconfig | 9 +++++++++ > > > > arch/arm64/mm/mmu.c | 10 ++++++++-- > > > > arch/arm64/mm/pageattr.c | 9 +++++++++ > > > > 3 files changed, 26 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > > > > index fee914c..3f8fbf0 100644 > > > > --- a/arch/arm64/Kconfig > > > > +++ b/arch/arm64/Kconfig > > > > @@ -1198,6 +1198,15 @@ config RODATA_FULL_DEFAULT_ENABLED > > > > This requires the linear region to be mapped down to pages, > > > > which may adversely affect performance in some cases. > > > > > > > > +config RODATA_FULL_USE_PTE_CONT > > > > + bool "Apply PTE_CONT when RODATA_FULL_DEFAULT_ENABLED enabled" > > > > + depends on RODATA_FULL_DEFAULT_ENABLED > > > > + default y > > > > + help > > > > + Apply PTE_CONT on linear mapping as much as we can when > > > > + RODATA_FULL_DEFAULT_ENABLED enabled which could decrease the > > > > + impaction on performance by small pte granularity. > > > > + > > > > config ARM64_SW_TTBR0_PAN > > > > bool "Emulate Privileged Access Never using TTBR0_EL1 switching" > > > > help > > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > > > index cfd9deb..8017b17 100644 > > > > --- a/arch/arm64/mm/mmu.c > > > > +++ b/arch/arm64/mm/mmu.c > > > > @@ -124,15 +124,21 @@ static bool pgattr_change_is_safe(u64 old, u64 new) > > > > * The following mapping attributes may be updated in live > > > > * kernel mappings without the need for break-before-make. > > > > */ > > > > +#ifndef CONFIG_RODATA_FULL_USE_PTE_CONT > > > > pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG; > > > > +#else > > > > + pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG | PTE_CONT; > > > > +#endif > > What justifies this change? Why is it ok in certain cases to update > the PTE_CONT attribute without BBM? BBM? I am not sure if it is ok here, but I just find nobody else change PTE_CONT so far other than this commit. > > > > > > > > > /* creating or taking down mappings is always safe */ > > > > if (old == 0 || new == 0) > > > > return true; > > > > > > > > /* live contiguous mappings may not be manipulated at all */ > > > > - if ((old | new) & PTE_CONT) > > > > +#ifndef CONFIG_RODATA_FULL_USE_PTE_CONT > > > > + if ((old | new) & PTE_CONT) > > > > return false; > > > > +#endif > > > > > > > > /* Transitioning from Non-Global to Global is unsafe */ > > > > if (old & ~new & PTE_NG) > > > > @@ -206,7 +212,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, > > > > > > > > /* use a contiguous mapping if the range is suitably aligned */ > > > > if ((((addr | next | phys) & ~CONT_PTE_MASK) == 0) && > > > > - (flags & NO_CONT_MAPPINGS) == 0) > > > > + (IS_ENABLED(CONFIG_RODATA_FULL_USE_PTE_CONT) || (flags & NO_CONT_MAPPINGS) == 0)) > > > > __prot = __pgprot(pgprot_val(prot) | PTE_CONT); > > > > > > > > init_pte(pmdp, addr, next, phys, __prot); > > > > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c > > > > index a3bacd7..88a87eb 100644 > > > > --- a/arch/arm64/mm/pageattr.c > > > > +++ b/arch/arm64/mm/pageattr.c > > > > @@ -99,6 +99,15 @@ static int change_memory_common(unsigned long addr, int numpages, > > > > if (rodata_full && (pgprot_val(set_mask) == PTE_RDONLY || > > > > pgprot_val(clear_mask) == PTE_RDONLY)) { > > > > for (i = 0; i < area->nr_pages; i++) { > > > > +#ifdef CONFIG_RODATA_FULL_USE_PTE_CONT > > > > + unsigned long cont_pte_low_bound; > > > > + unsigned long addr; > > > > + > > > > + addr = (u64)page_address(area->pages[i]); > > > > + cont_pte_low_bound = addr & CONT_PTE_MASK; > > > > + __change_memory_common(cont_pte_low_bound, > > > > + (~CONT_PTE_MASK + 1), __pgprot(0) , __pgprot(PTE_CONT)); > > > > +#endif > > > > __change_memory_common((u64)page_address(area->pages[i]), > > > > PAGE_SIZE, set_mask, clear_mask); > > > > } > > > > -- > > > > 1.9.1 > > > >