From patchwork Thu Jan 23 04:23:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13947930 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 9AE5EC02182 for ; Thu, 23 Jan 2025 04:27:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 364116B008A; Wed, 22 Jan 2025 23:27:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECA26B0093; Wed, 22 Jan 2025 23:27:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18DAC280002; Wed, 22 Jan 2025 23:27:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EAE7E6B008A for ; Wed, 22 Jan 2025 23:27:44 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 81FBD1C7EA1 for ; Thu, 23 Jan 2025 04:27:44 +0000 (UTC) X-FDA: 83037433248.22.7EEAEE6 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf29.hostedemail.com (Postfix) with ESMTP id F3262120008 for ; Thu, 23 Jan 2025 04:27:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737606463; h=from:from:sender: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=oq4XWnrfEGNzde2AdVIgZ/kCkzfSi4nq7uDv8bgjwV0=; b=EOkATDb/AYRWT4DEAlPALk5aTx6pUBZMkUZxwsHKIO2Q0h2FkQ9STZRVMrCRRbqxXauadA GoezamK8nsw48VHinaxl2S4xvObDDWjVD5/y0hLgcMmma0Dp6P9SDa4aCswnRYwcdt8l3I tF+fDTBQKapfI6fYhoJ/9da+wLoN1uM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737606463; a=rsa-sha256; cv=none; b=QgXKLi1vp3ve9sewHXasc1+m07gYmhS7DnTc0Nb9xj2BfkfyrTmBBUMoxBfq+t6grA4hti DdOGytjBaFEaYxVFnbkaGIx6ujEk6VoIqojcIDgJYnXsK2qVEb3I5xAnjyj9B+5ueZ5GSh 4mMpURJrIdo2cxN5/pBoOC+QC66gjys= Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1taols-000000005uH-2VQQ; Wed, 22 Jan 2025 23:24:48 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com, Rik van Riel Subject: [PATCH v7 01/12] x86/mm: make MMU_GATHER_RCU_TABLE_FREE unconditional Date: Wed, 22 Jan 2025 23:23:20 -0500 Message-ID: <20250123042447.2259648-2-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123042447.2259648-1-riel@surriel.com> References: <20250123042447.2259648-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F3262120008 X-Stat-Signature: cmn6edjuc84g5qmddqr4tq8cwhhntyqj X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737606462-581854 X-HE-Meta: U2FsdGVkX1975Nz33HGT3gUFRKSsG6N06ish/fCzLyy9JEkCiHTj5ntNCqEO1LxMS7/R9cdhooVTRLwJF5XNpR9N9jaMGsVjOYKuzqOKt0DJKxil+2IHSyUFgYPgsGME++WGa++ofzwbpGpBPCN6uWRFvVKXg1kt15vAMdKrsegM9qfRFDV8+E4EkS8G6AXSqqkS0mW8olmXTxpP0BGsFFte2YQjcjuVa/JscBrlye50htXO+aGfj+airU+mSWvdPKyeWeGeEBdz+cMrtor7bhmtDNy+yPKBAUiJenkBex5VkU3nGJZlJcuAYlYj4ZxHiOeJyTdmYzc1skWB7oir8PTG0si2cf12HBDuYfwNG+D2XUaicAMtyZhqJxSJmHIGrtBLNxBW9EBLxJBkvyYSOfyt2ntq0B1vMCX5D0VYrmy1x38j5HgnwawILrIiBjM+ta9FeYRfEZVqD1PFxZAtcS6ww407Bpx7Bc48buUy489Z3j30NDObndV1AObTTTKhr6+ZytVi0OxlcucjgWUAOKCgRJpTh+XFPfDlER3v84VHVe7af5lfMMoIJmxvx4X9AbfSApXcSaX67kI4H/E1iQO8Ad0p4d9EP9u0OCLOOyrOX13j/+KUblWdQNYeDNj7YABidwM7KiWfDJoQjGe4cgMfTQgtURckXnHSSFcAz0GjzlkhNwJw6fWzwO4XovozSo7ovzmo49LIHldDu3GJGtw4ox+frG4GSE2rVz+AbqREvf4EkzjN8Ky7Im5YR9G0QfuZkXaY/QyAvYMyKjGfj+ny9acalkxy94jAYqNaeOTJZUF6xhAAtnVXPDmYfTtwEweIaRP6HnO5W1bczXayTrcyF6gUTnu8mKIM617GrlzX0xzaKgKvEn/OO4l3TpWOJNIhoLQUSq94GfM8JMpb45R5iBw/P2NLG7xn9tlmwX/aWtJNKu8HdIduo5t3mAvZDdGfsoPciKkfEymdDfz gP9t/u6e wBdCO1K1pnuD5CIma70v13ziZDhTjmpIXCqr5Ak06J3PSYhWwr5QD9V3P7hpOR9/9KxPeyRWsLcm2AwEceKGeZ3BSa89MkVA3gfbiH5Zfsx8HCcA8X7bbxTWrIuo/NNsYa6daGdKxOJAALvy5w9AFkaU/MHwLbjuUcFz/d2zS4uTOVv0vZEf0MMm/YeQ75K3TbSEioHm6AZPtxHMhuf+bnM2sZl4VfQL/fnsX4IDPVSQ4wv0L5S3uknS+PPIHgwwjlJXuMlMoCTvFcbuu3vB59yECU1eMGSD74qbFRpEeU0o6e3jmTEVQRaxpBrJSML55G8FAHabSqCPS5iB9STNtBqi+T08g09WukQ7Sb0pelJKx9D3lRZDGKN4bJJsof12BKxFbKp4NLpOXOVve6zQUiZA3OQyQekPdCpHf65jswyPzm3gSOJWRNvoPKDAU/sq+B+3srzGHjtS4LoSG9SAGcIFzLx3I/01XSTjoWmWSlsDxFVE= 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: Currently x86 uses CONFIG_MMU_GATHER_TABLE_FREE when using paravirt, and not when running on bare metal. There is no real good reason to do things differently for each setup. Make them all the same. Currently get_user_pages_fast synchronizes against page table freeing in two different ways: - on bare metal, by blocking IRQs, which block TLB flush IPIs - on paravirt, with MMU_GATHER_RCU_TABLE_FREE This is done because some paravirt TLB flush implementations handle the TLB flush in the hypervisor, and will do the flush even when the target CPU has interrupts disabled. Always handle page table freeing with MMU_GATHER_RCU_TABLE_FREE. Using RCU synchronization between page table freeing and get_user_pages_fast() allows bare metal to also do TLB flushing while interrupts are disabled. Various places in the mm do still block IRQs or disable preemption as an implicit way to block RCU frees. That makes it safe to use INVLPGB on AMD CPUs. Signed-off-by: Rik van Riel Suggested-by: Peter Zijlstra --- arch/x86/Kconfig | 2 +- arch/x86/kernel/paravirt.c | 7 +------ arch/x86/mm/pgtable.c | 16 ++++------------ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 9d7bd0ae48c4..e8743f8c9fd0 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -274,7 +274,7 @@ config X86 select HAVE_PCI select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP - select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT + select MMU_GATHER_RCU_TABLE_FREE select MMU_GATHER_MERGE_VMAS select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index fec381533555..2b78a6b466ed 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -59,11 +59,6 @@ void __init native_pv_lock_init(void) static_branch_enable(&virt_spin_lock_key); } -static void native_tlb_remove_table(struct mmu_gather *tlb, void *table) -{ - tlb_remove_page(tlb, table); -} - struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; @@ -191,7 +186,7 @@ struct paravirt_patch_template pv_ops = { .mmu.flush_tlb_kernel = native_flush_tlb_global, .mmu.flush_tlb_one_user = native_flush_tlb_one_user, .mmu.flush_tlb_multi = native_flush_tlb_multi, - .mmu.tlb_remove_table = native_tlb_remove_table, + .mmu.tlb_remove_table = tlb_remove_table, .mmu.exit_mmap = paravirt_nop, .mmu.notify_page_enc_status_changed = paravirt_nop, diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 5745a354a241..3dc4af1f7868 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -18,14 +18,6 @@ EXPORT_SYMBOL(physical_mask); #define PGTABLE_HIGHMEM 0 #endif -#ifndef CONFIG_PARAVIRT -static inline -void paravirt_tlb_remove_table(struct mmu_gather *tlb, void *table) -{ - tlb_remove_page(tlb, table); -} -#endif - gfp_t __userpte_alloc_gfp = GFP_PGTABLE_USER | PGTABLE_HIGHMEM; pgtable_t pte_alloc_one(struct mm_struct *mm) @@ -54,7 +46,7 @@ void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte) { pagetable_pte_dtor(page_ptdesc(pte)); paravirt_release_pte(page_to_pfn(pte)); - paravirt_tlb_remove_table(tlb, pte); + tlb_remove_table(tlb, pte); } #if CONFIG_PGTABLE_LEVELS > 2 @@ -70,7 +62,7 @@ void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd) tlb->need_flush_all = 1; #endif pagetable_pmd_dtor(ptdesc); - paravirt_tlb_remove_table(tlb, ptdesc_page(ptdesc)); + tlb_remove_table(tlb, ptdesc_page(ptdesc)); } #if CONFIG_PGTABLE_LEVELS > 3 @@ -80,14 +72,14 @@ void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud) pagetable_pud_dtor(ptdesc); paravirt_release_pud(__pa(pud) >> PAGE_SHIFT); - paravirt_tlb_remove_table(tlb, virt_to_page(pud)); + tlb_remove_table(tlb, virt_to_page(pud)); } #if CONFIG_PGTABLE_LEVELS > 4 void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d) { paravirt_release_p4d(__pa(p4d) >> PAGE_SHIFT); - paravirt_tlb_remove_table(tlb, virt_to_page(p4d)); + tlb_remove_table(tlb, virt_to_page(p4d)); } #endif /* CONFIG_PGTABLE_LEVELS > 4 */ #endif /* CONFIG_PGTABLE_LEVELS > 3 */