Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp89080lqp; Thu, 4 Apr 2024 07:49:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNMa/9g8ZaraI4iy244xVvGhGaAEsIlK4VkHhlXV+bFqjI/MLu/IL3RQn6nuqcTsZdMVpq3j1IMaet9OTynMG8hCqp3Yva2a3zcSuJ3A== X-Google-Smtp-Source: AGHT+IFFSlpm/iS/H67/uw1JdmVuJbD8hyfrzZhIV2mjLgEhAaYsxnCaC8YX9CVMFmP7PhAAbzz/ X-Received: by 2002:a05:6358:260b:b0:17f:8815:ef23 with SMTP id l11-20020a056358260b00b0017f8815ef23mr2568862rwc.10.1712242190863; Thu, 04 Apr 2024 07:49:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712242190; cv=pass; d=google.com; s=arc-20160816; b=yOMZ6dK2+djbLxHS5Li6Ca9jnt7LBIHSjZMQqnf0FRhl8mJ4kFfQETqwgNHXBkPe8f MbKcm7hci6ZKlAJoSTqpfTCv7AO+9+PKesiBcNdVYXgbd6osNnx3Hj/0ula4XAA4zUTw xh9dh+MUKdg5Qi8NMd7pbEksXLMkBdt5PDZ+p3eXdADiygOMnxAfkdMQPBrZ3MBtqfVE +icxLI/ofcZ+72Kcy0Qn0cP/4p4dY3vmc1pDc2eF/zeDdAQ5ZJPzQo1bELhwoSpsGIhU thJNgwatkNhJehsIixKoUyrhN1sAX8sbf6ykI9Tz8qe85OLigrOqzchYgMFxKHWLD0U0 zGcg== 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=Iq+yD1aHdmd8v1xpn17PV3+F/WqhJYmUtsxSiKYgL3A=; fh=v/ZIPGFTxC8d1MMVbwyojvDvopPRKsRhmXNzvjHdZnQ=; b=b/2ODAJixnfDEMklLZgsrwOfy9hnPXzm07lnR6RyyUFl4lah5gAzlUrLtT0vjirOg7 kxPfSy1J3dvgXuQ9+Op3b3UKOSf3L8ei816O8rJHBj/+tn4no7yN9rdxu/S0frA/AgKY 8+ORW1omGvThd0SDu0MYhytjWkQoLZcBz8NsEBsKh2p12hLRV9n27esYDeWxnGFnaktl CXMvgAhbxrQ1w9YdX+gn8nataywi3oRvR2yutLAQHHtxtNc1knaZuCcw81GRneJzkjQi wXUaWpKwxvtECLYG3W/B1jzTgYHV99OesyERhHwcSANnrT4UPUk/gQJlYox/m0IoHOFJ qsQA==; 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-131623-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131623-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u11-20020a655c0b000000b005dc3614f97csi15462605pgr.571.2024.04.04.07.49.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131623-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-131623-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131623-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4EA93B2770F for ; Thu, 4 Apr 2024 14:33:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E3131D555; Thu, 4 Apr 2024 14:33:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 690AE1B964 for ; Thu, 4 Apr 2024 14:33: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=1712241204; cv=none; b=ccdPs2rHiGLQr24/jLmWR7TSC50KAaynoflYh0poPJpW0qLjj1Gm+YeHhQ2FTx3amhIHPnphZav2Z9oEWZln1o0ytC1XHwIU+q7GSJ+wtqNG1Q3AHKjY6/VIhlDlvKkCQnRm4jkRkfbRojG0t5zbq+eAmCyLYuIiwiI1pHtTUBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712241204; c=relaxed/simple; bh=SYO4oFNDFkL0s+N/cJYfdC8JBBGNx9XmnIIAMpjkrAQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lF4UFIHerTdbQfQaPGlx/WoOg3Rn7l/pZ7tv02GaF2oBQREvKifFcG1ZTaB7vUaY+DbdTsCvUCD2ZKky9lygbdDBsXOPGWdNL60fLUQu+gBXEm7ztkC7YT3UzalGL6nr5AwMyP86LpNj9TWueIwUNpm/z7hBjGRV/UE15vswonk= 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 B87C1150C; Thu, 4 Apr 2024 07:33:52 -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 94D6A3F64C; Thu, 4 Apr 2024 07:33: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 v2 2/4] arm64: mm: Batch dsb and isb when populating pgtables Date: Thu, 4 Apr 2024 15:33:06 +0100 Message-Id: <20240404143308.2224141-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240404143308.2224141-1-ryan.roberts@arm.com> References: <20240404143308.2224141-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 | 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(); } static pmd_t *init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, -- 2.25.1