From patchwork Mon Feb 17 14:08:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13977915 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 2B651C021A9 for ; Mon, 17 Feb 2025 14:08:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A99196B00B4; Mon, 17 Feb 2025 09:08:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A48D86B00B7; Mon, 17 Feb 2025 09:08:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E84D6B00B6; Mon, 17 Feb 2025 09:08:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 675C86B00B2 for ; Mon, 17 Feb 2025 09:08:48 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2DF09477DA for ; Mon, 17 Feb 2025 14:08:48 +0000 (UTC) X-FDA: 83129617536.04.B1C2456 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 604F480005 for ; Mon, 17 Feb 2025 14:08:46 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739801326; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YcimCt12M3537/OZTbdudhpXR/S8bHCeIQvJ781xMdc=; b=H5BJQ2q2YW4xZvQ622xKPqrLKtGtQHq1FdqVfwHVWZlTSTIiokhZYJv4snx7SGWoHDQPcL RSySlh/FB+q+sH+5b8XnoRpxh6/b0uDTkiS/tt5l13Q2ZlIwMLlLeiyHIJUTGtsh+u54k0 XMz0zaFndTBoXaWxuSAuRDx1eKxZM6s= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739801326; a=rsa-sha256; cv=none; b=Gic9YAIQr01z9SQA8fnNol5czZFHIe09KOUUkcJKnzLRThZEgsYaKBQ/nitBeQ1guHgUAg Ah+lefb1m57udFi703rLflk8a9wqPTEHdOMLvb3d0erUPmyTY1BCdbUmId95yvXMFx0MrY A2nnHg4WcQNvKDcGpAnuwg3rzud/eTE= 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 F17D81A2D; Mon, 17 Feb 2025 06:09:04 -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 83BC73F6A8; Mon, 17 Feb 2025 06:08:43 -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 v2 10/14] arm64/mm: Support huge pte-mapped pages in vmap Date: Mon, 17 Feb 2025 14:08:02 +0000 Message-ID: <20250217140809.1702789-11-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217140809.1702789-1-ryan.roberts@arm.com> References: <20250217140809.1702789-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 604F480005 X-Stat-Signature: okiwcq8cntjxdrns89xicryzbpj8ucdu X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1739801326-435769 X-HE-Meta: U2FsdGVkX1+L+Jk+UmIwc8dwimrwxTle1Ufmz5/1YB2LSWpqyVxJcAj67qSHg67X1NOOHoV8w558WKLlau9WEGZCRwzs0zaYOnq8p0rWYCI51VS9uwhZzaYR4Bhycb4AyGhbXmPQb6KBkD7PU8uVc5LywoOCYC1yUAo5dkPmbE0PGmnYBfUz5u6qZn5WCtk7DCTWzZsDwebgsu5AlNt5BBMw1LvI9O2IKJJ4N71AoPJzcZCONpiCee4WfOJTdQMAkO0IKZOclj5GTi65W1yTsQ278HINP1HlTB2Yh7J60m6hNziDCyQP80v+vuBjnWt+LaCoNqA+fFS9cKROcy8Z/vZOXGLy1t/IwCJ1A2MMi1tQj+wjCTfgEm5sm7lJtPgeL0w799TWZ+X93yab3aCzax2TcQ+OL/1hScqW0jbo7eiBv0RP/3gAXX4xJT4UNKJ8UnMKubpUtJm3hGeClhJdm8YA6m0UEpKDY6xmoqabyrFcTmlyOmTNiY5ObDGD+p7T5Tuxw13RBB02v7aQg08TERSmzIgB2JX3yKa/sCd59raxZ+VYzt9UgVv5/hU6bCdrU3omC6cShqwOTZitwHy6t5JfVzaaMc5pHIYnMNCo10kqT8jCF6+XHlL0ZLbF8g7DV4XD6dC7TF1vey3RyfuiYyWfTAs464c2KVaYd9a6K8ZHr/n6sDUlynueuX+yq4yd8ebV1bPz/6W+VKJn6xXXuNyo0ascOZbZqkuQ+zdy1aQC/p6LK0HL6M9X1z2dLzcKEullGLMIdN3igSikoF2rfFDKv35yJQHoHWTZ2aIN8URjpm9avAiop/bqDTYKwYW/Wez1P5oGculiplkv0R0V/ZNPTKxos9Bj+Z0IX45OV1VamdtVhdV1pDcgdBnijWrHYdcPG2Vu+LOt30rPBjbqHQ5esJb/rSDUZbh961WSfIyz/hgDEznnFE3XOHhgtI4dd7c3Klc+84Ap4wfwKEb IpyOCs+f KYNy/j7z9aRLwCXVY9Xmj5LCR9qrCgvloTYY6GVWDVBfIwvvCOmkDJuBGJq58Lr1LJmrq7a536XxN7X66HNcE5kizBX0vyEibx333UcONvT+5CQ7q7ikqftPqnDOl9xOQMZvzqIFZ5iRBp+fioKMZmztGZQ== 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: List-Subscribe: List-Unsubscribe: Implement the required arch functions to enable use of contpte in the vmap when VM_ALLOW_HUGE_VMAP is specified. This speeds up vmap operations due to only having to issue a DSB and ISB per contpte block instead of per pte. But it also means that the TLB pressure reduces due to only needing a single TLB entry for the whole contpte block. Since vmap uses set_huge_pte_at() to set the contpte, that API is now used for kernel mappings for the first time. Although in the vmap case we never expect it to be called to modify a valid mapping so clear_flush() should never be called, it's still wise to make it robust for the kernel case, so amend the tlb flush function if the mm is for kernel space. Tested with vmalloc performance selftests: # kself/mm/test_vmalloc.sh \ run_test_mask=1 test_repeat_count=5 nr_pages=256 test_loop_count=100000 use_huge=1 Duration reduced from 1274243 usec to 1083553 usec on Apple M2 for 15% reduction in time taken. Reviewed-by: Anshuman Khandual Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/vmalloc.h | 46 ++++++++++++++++++++++++++++++++ arch/arm64/mm/hugetlbpage.c | 5 +++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/vmalloc.h b/arch/arm64/include/asm/vmalloc.h index 38fafffe699f..40ebc664190b 100644 --- a/arch/arm64/include/asm/vmalloc.h +++ b/arch/arm64/include/asm/vmalloc.h @@ -23,6 +23,52 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot) return !IS_ENABLED(CONFIG_PTDUMP_DEBUGFS); } +#define arch_vmap_pte_range_map_size arch_vmap_pte_range_map_size +static inline unsigned long arch_vmap_pte_range_map_size(unsigned long addr, + unsigned long end, u64 pfn, + unsigned int max_page_shift) +{ + /* + * If the block is at least CONT_PTE_SIZE in size, and is naturally + * aligned in both virtual and physical space, then we can pte-map the + * block using the PTE_CONT bit for more efficient use of the TLB. + */ + + if (max_page_shift < CONT_PTE_SHIFT) + return PAGE_SIZE; + + if (end - addr < CONT_PTE_SIZE) + return PAGE_SIZE; + + if (!IS_ALIGNED(addr, CONT_PTE_SIZE)) + return PAGE_SIZE; + + if (!IS_ALIGNED(PFN_PHYS(pfn), CONT_PTE_SIZE)) + return PAGE_SIZE; + + return CONT_PTE_SIZE; +} + +#define arch_vmap_pte_range_unmap_size arch_vmap_pte_range_unmap_size +static inline unsigned long arch_vmap_pte_range_unmap_size(unsigned long addr, + pte_t *ptep) +{ + /* + * The caller handles alignment so it's sufficient just to check + * PTE_CONT. + */ + return pte_valid_cont(__ptep_get(ptep)) ? CONT_PTE_SIZE : PAGE_SIZE; +} + +#define arch_vmap_pte_supported_shift arch_vmap_pte_supported_shift +static inline int arch_vmap_pte_supported_shift(unsigned long size) +{ + if (size >= CONT_PTE_SIZE) + return CONT_PTE_SHIFT; + + return PAGE_SHIFT; +} + #endif #define arch_vmap_pgprot_tagged arch_vmap_pgprot_tagged diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 8ac86cd180b3..a29f347fea54 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -217,7 +217,10 @@ static void clear_flush(struct mm_struct *mm, for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) ptep_get_and_clear_anysz(mm, ptep, pgsize); - __flush_hugetlb_tlb_range(&vma, saddr, addr, pgsize, true); + if (mm == &init_mm) + flush_tlb_kernel_range(saddr, addr); + else + __flush_hugetlb_tlb_range(&vma, saddr, addr, pgsize, true); } void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,