From nobody Mon Feb 9 12:07:58 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9ACA6283C90 for ; Tue, 4 Mar 2025 15:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741100710; cv=none; b=UFYRj50Kh2rHZng619GAOaKnNBEGqvu97YzDyanAxe6ZZA3lSKEJAZ1yQxRzCdxJrEfh/cJz9E7EZQzc56DvyktyTsG2DE0ChxCZybQtAZ4KfPlOZnl4Ws9l4WEBGK2qnj05d/3RKC9Zk8U4uxvY2WwjIwkjDDd6mNDvHP3XO2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741100710; c=relaxed/simple; bh=aYAYZ8yX3+DzCiiENiVNFGzYXz3TId8FNdWwH4AVEdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4njRR8KMNyZNngQpxoTNu2WQlOPi4q6p0eA3WnOq8/nQTgD7M6NjcW+ckYuq+J6Gwz+EzfAUlfrMtptyuIKTfM6nhYeEOQqhHCYZMaW9buHwc5wRL561xG2C7MWCPWvFBjPCNlYJKr2fpTec/X1GY6kPKk5UZVhw8pibGGTmAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 9595EFEC; Tue, 4 Mar 2025 07:05:21 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0F7FE3F66E; Tue, 4 Mar 2025 07:05:05 -0800 (PST) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Pasha Tatashin , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , David Hildenbrand , "Matthew Wilcox (Oracle)" , Mark Rutland , Anshuman Khandual , Alexandre Ghiti , Kevin Brodsky Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 06/11] arm64/mm: Hoist barriers out of set_ptes_anysz() loop Date: Tue, 4 Mar 2025 15:04:36 +0000 Message-ID: <20250304150444.3788920-7-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304150444.3788920-1-ryan.roberts@arm.com> References: <20250304150444.3788920-1-ryan.roberts@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" set_ptes_anysz() previously called __set_pte() for each PTE in the range, which would conditionally issue a DSB and ISB to make the new PTE value immediately visible to the table walker if the new PTE was valid and for kernel space. We can do better than this; let's hoist those barriers out of the loop so that they are only issued once at the end of the loop. We then reduce the cost by the number of PTEs in the range. Signed-off-by: Ryan Roberts Reviewed-by: Anshuman Khandual Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/pgtable.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index e255a36380dc..1898c3069c43 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -317,13 +317,11 @@ static inline void __set_pte_nosync(pte_t *ptep, pte_= t pte) WRITE_ONCE(*ptep, pte); } =20 -static inline void __set_pte(pte_t *ptep, pte_t pte) +static inline void __set_pte_complete(pte_t pte) { - __set_pte_nosync(ptep, pte); - /* * Only if the new pte is valid and kernel, otherwise TLB maintenance - * or update_mmu_cache() have the necessary barriers. + * has the necessary barriers. */ if (pte_valid_not_user(pte)) { dsb(ishst); @@ -331,6 +329,12 @@ static inline void __set_pte(pte_t *ptep, pte_t pte) } } =20 +static inline void __set_pte(pte_t *ptep, pte_t pte) +{ + __set_pte_nosync(ptep, pte); + __set_pte_complete(pte); +} + static inline pte_t __ptep_get(pte_t *ptep) { return READ_ONCE(*ptep); @@ -647,12 +651,14 @@ static inline void set_ptes_anysz(struct mm_struct *m= m, pte_t *ptep, pte_t pte, =20 for (;;) { __check_safe_pte_update(mm, ptep, pte); - __set_pte(ptep, pte); + __set_pte_nosync(ptep, pte); if (--nr =3D=3D 0) break; ptep++; pte =3D pte_advance_pfn(pte, stride); } + + __set_pte_complete(pte); } =20 static inline void __set_ptes(struct mm_struct *mm, --=20 2.43.0