From patchwork Mon Jan 20 02:40:09 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: 13944705 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 14C08C02187 for ; Mon, 20 Jan 2025 02:42:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E9F06B008C; Sun, 19 Jan 2025 21:42:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E58836B0093; Sun, 19 Jan 2025 21:42:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C9FF280005; Sun, 19 Jan 2025 21:42:30 -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 66CD26B0088 for ; Sun, 19 Jan 2025 21:42:30 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 08B4F8266F for ; Mon, 20 Jan 2025 02:42:30 +0000 (UTC) X-FDA: 83026281660.13.98E0BE7 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf19.hostedemail.com (Postfix) with ESMTP id 737A71A0010 for ; Mon, 20 Jan 2025 02:42:28 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737340948; 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=E6KbmwyeKyUW6AotLMtbEieNGrBDHNjr7VxrE8YFvTC4ZYck0y+3cDmafh7jyIWGa9c/Ab bKo3/5HUJsQ0Cqol2q5H2Osh3pHfGq3m8gKYhbWjUY9yta+Fn/m1IcyBV5G7e1WIk4fOKM bWC7za8ZK0qTVYQXXZj4MyCWkTlT+Zw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737340948; a=rsa-sha256; cv=none; b=wUSDnDMLBamjczG2OBzedunGalLIKDMcaubEWv6FQ6VP5i7Qfz+bZBpwR2C0497UdiWdX7 nc8OmXQ3hhL2ADb4qDBnpURY6+/iBMVy8iJTDUI+AZ3CCqP79zQxq+REqnUOZFOZs6Cuwo VzF+uozNPcXn7VwoBIG9MSVsS9rMIec= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none 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 1tZhis-000000002w5-0gJU; Sun, 19 Jan 2025 21:41:06 -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 v6 01/12] x86/mm: make MMU_GATHER_RCU_TABLE_FREE unconditional Date: Sun, 19 Jan 2025 21:40:09 -0500 Message-ID: <20250120024104.1924753-2-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120024104.1924753-1-riel@surriel.com> References: <20250120024104.1924753-1-riel@surriel.com> MIME-Version: 1.0 X-Stat-Signature: uqgahiy7sfb9pgdoqzkuyiktmebutf6g X-Rspamd-Queue-Id: 737A71A0010 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1737340948-801679 X-HE-Meta: U2FsdGVkX18LHen7hTZ0nagr0dNm6+fXKUaC/jLEFXDpV9bUS7wgv4yKH2/suXkg9S1EbPiSJ5mrmemp23x4xNxtUWMkuRJUDrhT3BOpWYmSA5jONvLull9FtboFHhyLbnOfLG+p1umTDFIHMUZTQtUije6TeeXPnc+f5EMnxx+xUAEIX4DjF4ONnR00T93eQYiIV9ugxq3lZ5bUKnZeXvkvDZzdH6ZDLzKBgy0chOwRtymBAS83eFBPfOQ03HdNdldbTTodGlhK1YgSw5IWwTRATRO2I+YuHQju2ywlYo7v0Bm3zwIXKMXI0kwtMusFP8XOVHGD4O2G4gnF44JcSdvt5WdNLrA33wJAs47aZYkRwxu2ZDToA7mpWvrEBqgBjrC+D1nLYRCFk2OIpK3lGoMxsgJ55LISR27udIXnoWnuoyxsgin+X3fqIFkeLuZ9GDGeVAoR3Ppz2WOATm8VHALVYnTxJEc0p96jKc7b24QEcO1fNFW82jyO4zydhjQ5yka05MbtG1o4q9DrwJp7unF808QkwWlrrZRJ23fTR9k7kPKPUoNGLtqpbzYjuiVrBeMPYozu5dqT75RfDzHmDKns+gl1DIOv/k+6c0HJzv1ltluDYj/8lk1yCyQc9lFvJAZyrrf8iVKsOwAAF0pBSZoDu7h5haXJFcl4E+d6DVFGhT9YFXiD/uswl8nKZ5uTeZ3WIkbGUv7Hcam7QuCUvtxk3I6wgyDrmnKuywfE76TC6B+e9/Pr9DMuO1uAaTkfwtiSBtYmlhQfCrtnEZC/4GuZInB+H6Im8S273Ms79pZL7m/aCWBJFRBDNkt7V0BqlY7bA5gBCwHPOlJGH/PHoIVTEfKL/OFON+dlHarAikJZVrO+4Tbr++5nZMnhgSM/XA5T6ZrfTNkvXSxeixesOAPbS/P4jnpy+pggtDt8N1YUyY2HAe6cxEw51Dwp9bi3PRhcFzcxKkRnctkJ5iG fsLr9ZIy PnBBZdXS2UFc5pUGdoaEdmBGbjHSh295/anfKd+kQFcAqAOWN8rLp7+YMwO0AyjQIDJag1imzsGFCvYppSCg/eyyomekj/DYNvhOwv0V5bJOrXcsOi80/GJSzraUHaHwVaQJL6EVsDRCXyB9nCbAu1ddgfEbqN5EpHYVFgs3R/GxO9w+F5oAGvMF3DitddNsxpwxKmyc9BcJcsJmACsBGGkJDGQoC8dkg+LMVL1sOFFFEAOOv9l7cH0DurFYshQnps1KGlH88lVIupuMaSgC9EZddUTgabII0Xqok9d1Sn0235NqxFxbKzkCsvZH6DRoXnIWMXF8GGzhEVt3+4A+op11zFxZA6KtYYIvJX8FOXtsiKCBYWG/mjcU0EOzu9IDWZ3Tm3jo3/41Kn9+rd8EIE420CxsKcSySbllijKB3eAOR4Ntegr4IFSReUgkxVeBpu6JH0x+nWewGkLbUXO9kHRNLJ84U/UkxfEpDfHS3GFGvkOexyHqTW3SYGA== 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,