Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp140924lql; Fri, 12 Apr 2024 06:20:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUf7E74qCsQ3Ws8ygu6p1khH/7Ozq6AK2KO0OAeQwW97f6tWN1ZstEochtsrYKcBbZBuS70THH/g4gABak5xBQCvhcluQphZazEK0B79A== X-Google-Smtp-Source: AGHT+IHirWy4DSZFhLEidt7xD9EP6KBx2cBJnuKEazfa+F0w0+ywyRHCUZ+csealCE75NWrntgxf X-Received: by 2002:a17:903:2405:b0:1e5:5041:b18a with SMTP id e5-20020a170903240500b001e55041b18amr3134582plo.40.1712928040860; Fri, 12 Apr 2024 06:20:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712928040; cv=pass; d=google.com; s=arc-20160816; b=Z1gdCACd0uZcyDcHRfr2g8hCwLH4NIAx+3lMabANlAgnkZn2y2abxzJlz2901JbLT6 4Q4+I6u0CWsRe6mHkfCVfPfzMqsdR+3H032U9C/Gtp+m6a1edHfLUR/SzcKmVGuyIMwB 96KY/1mies/rtpczEKhP2KlctBMm8YeYHaAvU2WAz2qwsLIny5qr4l13VrtbXI5F4e1R MERd2n2vtWvDOGv1CfcDOLvl+GYCXAfXF3GMII/F88mQmfvOvdntKjr2ZoycZSBwJlVL /QoPiiOnG8rzbjZzYX2Xzs1SqBrSdVCVpSEUU2VpMwxx4HuBwWA0KhPzDtVj0W5lz4Ik IUzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=R6mLOECUZoUb89mers+CjzDS3KqMEcvQAwnwaBfOCRs=; fh=v/ZIPGFTxC8d1MMVbwyojvDvopPRKsRhmXNzvjHdZnQ=; b=yEThEIlbLAejXRu9Cbsg+rVQhf8Rv6r2HXgQ3binA/8x6V/UGWG5GTQEjSJJ8y7GPA WJx1Ay8O+wFSR5QrEnA5+JFRZHvuXH3vrEb76F5HEmIwI5sMhMo4rj7XQ+fRWEJ9Nxaw 4ueupcjp8+mH8S8ruJPsx/awbfAShpKLnRAtbH6wG54TkEqdYtVkiOep7IJXu+O3i2JD WyYuRxyr5A/ORVjGRzkCo9wNEu0dPCeNMbdvpVGGKKQah/8FljSb6cga6V5vvYyTsLDx fezzok/H/C/p8qzQbHV8wYJvygrEYONGx8+ZevoGFzLmJ98oxr3g6vow/bhHfR/lIf6U lbJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ay1-20020a1709028b8100b001e43e672bb4si3114340plb.544.2024.04.12.06.20.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142714-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 082D5282181 for ; Fri, 12 Apr 2024 13:20:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A76C82D86; Fri, 12 Apr 2024 13:19:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67A7C824A3 for ; Fri, 12 Apr 2024 13:19:22 +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=1712927964; cv=none; b=K3C311ImXdhtEmMphDz1Fa5MeGIHPkMl25H51ww8Wj//4wTJcSjlGfLh2mum3mjYyz7HeLo0SEPAmS37BEGBYcb/xufiOEFaqrpa+DN9xlYdVWXCfBGHOzj2NjkBppSEskacurZrVRL+XPR4EA23I+OG2al+q2m635fR1g8cmDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712927964; c=relaxed/simple; bh=rTIiiTX/0GDPQFzvBo0C+aUzO0YBV2V1wPty4ExbMiM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zjn1tYl5M8ik9Y+6DEKfY4VlNnK+QPMxXQVNoqgEXCdQ2JWZtosGr7ep6IqGlwaLu2t/kwl/a0AHZjIYnAIF1FmjVt3mlYq9jAJ25a1RbxlqQ8pdIEgIkjFPVi8I4shX5kLr4QXL9z4kxbNCcKehxwuD3/dytJ19VrnB5B5RR/M= 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 F2A111474; Fri, 12 Apr 2024 06:19:50 -0700 (PDT) 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 602A43F766; Fri, 12 Apr 2024 06:19:20 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , David Hildenbrand , Donald Dutile , Eric Chanudet Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Itaru Kitayama Subject: [PATCH v3 2/3] arm64: mm: Batch dsb and isb when populating pgtables Date: Fri, 12 Apr 2024 14:19:07 +0100 Message-Id: <20240412131908.433043-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240412131908.433043-1-ryan.roberts@arm.com> References: <20240412131908.433043-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: 8bit 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 | 78 (0%) | 435 (0%) | 1723 (0%) | 3779 (0%) after | 11 (-86%) | 161 (-63%) | 656 (-62%) | 1654 (-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 | 11 ++++++++++- 2 files changed, 16 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 9f1d69b7b494..ac88b89770a6 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -178,7 +178,11 @@ static void 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 @@ -232,6 +236,11 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, phys += next - addr; } while (addr = next, addr != end); + /* + * 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(); } -- 2.25.1