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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2C65CD1296 for ; Wed, 10 Apr 2024 10:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=mT0chrFGSE8gcKNGz+QE2HM7eR/j23Eo3i5xUBfmVko=; b=oNnA3LHCqt4L9g lmQ3Yi52Cz9Xf4yNbN2v8NWJ+U6u1eT1Mv5IOfA9HUwwqDAyQOY6EgSRaCh1It3hdrWqJQMG/G1oz N/xXElqU4cLb3XttowjJt3bh41YDBKcgObP9P0khnREbnqzyNNgRu0T2XW5xUdSCHBYl9yMC/LvWs kcq/eQf5PHgl8fRHjgsKzE4snKD4VtisILqmASk1XTE42myzrQwUtf2L58Vl5Zy51JnJVEhVKKGh4 bKmNkUYHfnVPCEHGz5y9Sxj4p/wihLsBdpbonW5Xqt7PW/MfI0P/xIFxb6YAw7gVDA9scS7Zmc5j0 pvZpLL6tYKDTAacXuULw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruUqx-00000006Ir3-3XPC; Wed, 10 Apr 2024 10:06:51 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruUqq-00000006Ilw-3miy for linux-arm-kernel@lists.infradead.org; Wed, 10 Apr 2024 10:06:50 +0000 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 DE1CA139F; Wed, 10 Apr 2024 03:07:13 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.17.100]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 374D63F6C4; Wed, 10 Apr 2024 03:06:42 -0700 (PDT) Date: Wed, 10 Apr 2024 11:06:39 +0100 From: Mark Rutland To: Ryan Roberts Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , David Hildenbrand , Donald Dutile , Eric Chanudet , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Itaru Kitayama Subject: Re: [PATCH v2 2/4] arm64: mm: Batch dsb and isb when populating pgtables Message-ID: References: <20240404143308.2224141-1-ryan.roberts@arm.com> <20240404143308.2224141-3-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240404143308.2224141-3-ryan.roberts@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240410_030645_774774_91D2A107 X-CRM114-Status: GOOD ( 23.98 ) 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 On Thu, Apr 04, 2024 at 03:33:06PM +0100, Ryan Roberts wrote: > After removing uneccessary TLBIs, the next bottleneck when creating the > page tables for the linear map is DSB and ISB, which were previously > issued per-pte in __set_pte(). Since we are writing multiple ptes in a > given pte table, we can elide these barriers and insert them once we > have finished writing to the table. > > Execution time of map_mem(), which creates the kernel linear map page > tables, was measured on different machines with different RAM configs: > > | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra > | VM, 16G | VM, 64G | VM, 256G | Metal, 512G > ---------------|-------------|-------------|-------------|------------- > | ms (%) | ms (%) | ms (%) | ms (%) > ---------------|-------------|-------------|-------------|------------- > before | 77 (0%) | 431 (0%) | 1727 (0%) | 3796 (0%) > after | 13 (-84%) | 162 (-62%) | 655 (-62%) | 1656 (-56%) > > Signed-off-by: Ryan Roberts > Tested-by: Itaru Kitayama > Tested-by: Eric Chanudet > --- > arch/arm64/include/asm/pgtable.h | 7 ++++++- > arch/arm64/mm/mmu.c | 13 ++++++++++++- > 2 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index afdd56d26ad7..105a95a8845c 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -271,9 +271,14 @@ static inline pte_t pte_mkdevmap(pte_t pte) > return set_pte_bit(pte, __pgprot(PTE_DEVMAP | PTE_SPECIAL)); > } > > -static inline void __set_pte(pte_t *ptep, pte_t pte) > +static inline void __set_pte_nosync(pte_t *ptep, pte_t pte) > { > WRITE_ONCE(*ptep, pte); > +} > + > +static inline void __set_pte(pte_t *ptep, pte_t pte) > +{ > + __set_pte_nosync(ptep, pte); > > /* > * Only if the new pte is valid and kernel, otherwise TLB maintenance > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index fd91b5bdb514..dc86dceb0efe 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -178,7 +178,11 @@ static pte_t *init_pte(pte_t *ptep, unsigned long addr, unsigned long end, > do { > pte_t old_pte = __ptep_get(ptep); > > - __set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot)); > + /* > + * Required barriers to make this visible to the table walker > + * are deferred to the end of alloc_init_cont_pte(). > + */ > + __set_pte_nosync(ptep, pfn_pte(__phys_to_pfn(phys), prot)); > > /* > * After the PTE entry has been populated once, we > @@ -234,6 +238,13 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, > } while (addr = next, addr != end); > > pte_clear_fixmap(); > + > + /* > + * Ensure all previous pgtable writes are visible to the table walker. > + * See init_pte(). > + */ > + dsb(ishst); > + isb(); Hmm... currently the call to pte_clear_fixmap() alone should be sufficient, since that needs to update the PTE for the fixmap slot, then do maintenance for that. So we could avoid the addition of the dsb+isb here, and have a comment: /* * Note: barriers and maintenance necessary to clear the fixmap slot * ensure that all previous pgtable writes are visible to the table * walker. */ pte_clear_fixmap(); ... which'd be fine as long as we keep this fixmap clearing rather than trying to do that lazily as in patch 4. Mark. > } > > static pmd_t *init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel