From patchwork Thu Jan 16 02:30:24 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: 13941163 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 9E470C02185 for ; Thu, 16 Jan 2025 02:33:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FF306B0092; Wed, 15 Jan 2025 21:32:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AF486B0093; Wed, 15 Jan 2025 21:32:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1E57280001; Wed, 15 Jan 2025 21:32:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BF4826B0092 for ; Wed, 15 Jan 2025 21:32:49 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 70B821C70BA for ; Thu, 16 Jan 2025 02:32:49 +0000 (UTC) X-FDA: 83011742058.02.F4CDE13 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf23.hostedemail.com (Postfix) with ESMTP id E9B0B14000A for ; Thu, 16 Jan 2025 02:32:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.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=1736994768; a=rsa-sha256; cv=none; b=qVWatv3iQ80WGkhBAF6lkJOgtlm4ozxXU64pb/w7TRr0lgbeWOGhaK/Ab4v2Xi2mAxZcEu Arfnton/K8RSEehtsq6JPbaMNOPH5omPypkTXvruTbZQrj8esMuYZB9eKD9gbxUBHHIohY +7BxlEC7OQ3aMTsZlvMCIvcJWAuGEjg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.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=1736994768; 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=fGSmCRe0+cRBeDTp5bUo5pBeMMwXGS2kevdWEnm8DLs=; b=uqBvs48zm+4u3tfCb6HcOEeL8PCaxXZUQVk603BD45aVNg2xeCLaShv6F2CVq0VIoLheXE 1yrLDVBwdBljbviMCe4EKNB9tgCrw0UH87ZCdg0oj2YiNt01L3fDl1sQekwr1mDKqKkenh 5Z3AZuwlJZ9+JLbBRC7gk7iWbo+YiNM= 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 1tYFfO-000000003nd-2zJv; Wed, 15 Jan 2025 21:31:30 -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 v5 01/12] x86/mm: make MMU_GATHER_RCU_TABLE_FREE unconditional Date: Wed, 15 Jan 2025 21:30:24 -0500 Message-ID: <20250116023127.1531583-2-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250116023127.1531583-1-riel@surriel.com> References: <20250116023127.1531583-1-riel@surriel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E9B0B14000A X-Stat-Signature: tyif8zj69j3kjg3wm48bj819utpcqo45 X-HE-Tag: 1736994767-903783 X-HE-Meta: U2FsdGVkX1/ZE4jMkEH5aI7iZR9DVgMFJz7SIvosIRGuchwTHBeWqAXkPJD4xUdJjW7A5JGxAGS7VDyibfy5yltK4uJ5WZmQM4wf/j16LBJoRVBjC1Ga0EOLXlBMKcqSaVEL/OrrjWnUw5TS3eprW04yWh5KiV1YmaBdGM+S6vF5rlp48JYBR/NC+V0Ln5+xm3LrRho2qx+oHjbZmSeA7ZHaGwpUBh+I6nJ1TVg9UPN7ih5eDBQ0nwttiJaLJrcx51DoULBh6wmOZylx6eS20/dwm1LIwrjZX5t8wiMl4sUUqZpOeaV58lYmvbDit/DgV9RiUjwmgZTqAoJfCRqFVtiVfr0eR3ZRsZPo5kHKsIqbGgGEYFVX2QEp2dz7pBn/L3bK/OXZLFTna3azbK0f9dtQw7lUS8Ju+wAW/gv6/IvW71obucprmZRSeeE/fSKoistmY09QsPnRu15mIDc96HmuXa8u2qPmYVkAN0D7GwIQP+o9aY/oMEL1Mq8RYwif3UGDSGcJ1Zw/yMquLW45sEaAHJw2QkVU6gh2iN7BdJfLbQoKyByASxNtElK/kKW5/7bkrKPNAIMQaB0FpDXEsT0uBv4JPwIgpV/fegMAMCQYclxggsne8WFSdNVsaREMrHERJSiyWC0/F4BrJsAq4L69WCtn6dwN88YnSuUqzFwQmQhVITxkO9wTt1dMLm1VgHd07tCjUC+C5Lce482sSqhWGQvyGFLZ7EyMGZz76LbZ/sanqmXreFSjAhMdmpYEvjN6UzqxOlIT5aQyu6GQXX55D8FHjoEFejvFy/Xpb0wPUN4IMxdkBjiTl5riC7mKmoBgksHVZGgrwv07Cjmkw4cIuaSqC/eZ3tHuVRBVMmkzUe55z7aoebfBQLWF8uTONhUlbZGI8g92hfaibqq84j1Vg8c0UyO5TJYR/aqPuGbmlXB8JFE21SH795yMvC7x2f19MEW7DQuT4cWEzfR Mv1El42s 6FgkE3DHdIX/R2dXO1t1hInNJuAuenAsp0mGjTxOPPqbuahPRGdpOJDywyhQ1AW0NQ3CVs7PXCSDKVSvHXvP//09GZbE/fKBLSc/c/KA9f5WkgQjAoxkIhhJ0GGxJ6zL0vHkcwEhFLJ4fitlnOHa6Sd9zJujptSYrkpQZPz21/2jyEQMEA+lQEymFHZSiyWY9DfesfaDR0N4AZmA2za36mranW+Sn2WEZH6Xh0Pzxxyu5AJ0fZH8Y/nkOE/3trWeWu/Rp3821lZbUjp4/CpffvT3yQFiP5IG64ncV7+XW6oWo1OWpoWf/Ey+qaqyptVLcDLarSIhbfpsrT+c9u6YCKEMBNIb4N5ogUXd8mM4v3B64Hd0W93trKVKcRx9wAPOvxG8k07WTtCElrtXUM2XKuDNPNJWRiQTJ7Ts9mJ84Vvg+ibzXZHpkBlK2CLeLZoqc0UcnU4KoOKDCncufQ+5kmSKuIL6iKp9AedFfSCRCTYmdNcrLvRDDQUKx4A== 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. 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 +------ 2 files changed, 2 insertions(+), 7 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,