From nobody Sat Feb 7 21:14:44 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C4D71A2C11 for ; Mon, 29 Dec 2025 14:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017597; cv=none; b=GttuCNOLj9ftEhXSRZ+bzQ6gwsT2xUWVygxjl0kADD6mJoUtc6GV6g6RtaB0PckLTsDJCnd9jhsRgEjlsgyd5t4oxg9kij1oMrqvKmpoVhgGPk5lB+osBkLARi4AT9FoDFOZtL9a6++JAKlD/lNBB8uCMmlr4VLa+RQ44M+4WVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017597; c=relaxed/simple; bh=lC6GEfxIGK/35lvrPF2qw5D86rHWEQ6C/lNcw05H+jI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EU6jJ6y71K01LetsD6GLx0NHBRDSg+OtK8U8gRM4sAmr5ikKvYn5YGHUGWcHixnVaAf3Luo5wNeayfmd7xB2xABe68+qSmkvN4/9MBAoU0UpSuwdDffKjJGma6yYTY55qYr3p1Vc7FDeQbEMkiiO1pzivSA8uCCvFjPFvsteJzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7f0da2dfeaeso9724034b3a.1 for ; Mon, 29 Dec 2025 06:13:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767017594; x=1767622394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=foHDr6tTVVg2N+oq2ubI3TwM6NJy7Osy+6nFP/DCYQ8=; b=Vpct6HKmyS36p3dgHrEwiwNXRw0mddMhIBYiHVCMEqXzkPYWI/UcL2CgcRyg2RH2KT q9s2nTLhLROHCcMJH3pJd6CTXHMVPGmSOAW75lqhmAtF44plAOg/ysiJFEAJ9pvUfsxB XZzNeLVFwqEdGbuX/3ai+R34amtpjBDe7Nfh7KBs9Fomn2lmRzg442hxeMgjhGTE61c7 bdgCw3MI0MKvXvYZjGtelIU+iNPp0bSfHz/LW3JrKBkCK94KQ5ieHl+59NIYEvBqS+Ju GL0QDOAPTpTAsJmJ8wqjI/W3TPpbFYtgCTh5mka8M3o2CJonPCobx4GdXST5Xj1gH8oN kuRA== X-Forwarded-Encrypted: i=1; AJvYcCXy2Z1WL1yQMbzRFhDNcwJiCVbGLTCoRK5URL7gw8CfbcQ4pqTY6DMaz+6s9mLHd1D32783BHv0DRgqmCo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2Ov+dwH3NtWnl5GlkCgZEBja4xsuvHGCqsKgUsjYhxpWgNO/O JKADoDfnbnNWqOjhfr4/qmsDIUU/IktKe50j5mYe623vHMuWA2nkEcEl X-Gm-Gg: AY/fxX5P9Be+lrzoTYu1dLNd5EEiXT2pxTG+GsUY0cyVQaQmYPONHxEt+zL6H2WLunV nD3xntu1CLIN7zt/e+eiOX00MLjW80oBcwZCMcf35C6vdGS/tQ59GO3n5mqNNCXTAomKDLxg5g6 lflvdu4H9yIaMmd8+DSyt+p0DlZubYFKbpyavvxDgy/ofYxiJ85iPQ8sanpK2mIgIOwTHxJah1M k2QPm8Wyxyd2ntOCHRtSgrA1pHLHeGX/HZchf2aKRbgi4WO1MJXFHLluaLgteOT0ZgZ5TNmWZ6p 9qyuB5TDwRkhKWHjoEo1X3OPXzMXNM6D4y9QtKzXh5xoroewXVJtfBJdWE6qa7iZhEafNNDxZSM dNi/KDLbRnxAOp8FW5Aummk31TevOKNNWrHoOavQGs444OIg3zXpY+MRZLuC0yrmnWAj/MXVCGq iztaled4ShLw4zZZAd3PMh X-Google-Smtp-Source: AGHT+IHjQ5rl02KKPHQhO2WlxDrubU3tUX+Dp23WgXVCA057aOMTV2/+jAKILyQh7BNfdVe+rKUfAQ== X-Received: by 2002:a05:6a21:328a:b0:366:14ac:e1dd with SMTP id adf61e73a8af0-376aaff9943mr29756512637.67.1767017594482; Mon, 29 Dec 2025 06:13:14 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7a93ab3csm29472636b3a.7.2025.12.29.06.13.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:13:14 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, ioworker0@gmail.com, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v1 1/3] mm/tlb: allow architectures to skip redundant TLB sync IPIs Date: Mon, 29 Dec 2025 22:12:43 +0800 Message-ID: <20251229141246.63435-2-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229141246.63435-1-lance.yang@linux.dev> References: <20251229141246.63435-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lance Yang When unsharing hugetlb PMD page tables, we currently send two IPIs: one for TLB invalidation, and another to synchronize with concurrent GUP-fast walkers. However, if the TLB flush already reaches all CPUs, the second IPI is redundant. GUP-fast runs with IRQs disabled, so when the TLB flush IPI completes, any concurrent GUP-fast must have finished. Add tlb_table_flush_implies_ipi_broadcast() to let architectures indicate their TLB flush provides full synchronization, enabling the redundant IPI to be skipped. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- include/asm-generic/tlb.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 4d679d2a206b..e8d99b5e831f 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -261,6 +261,20 @@ static inline void tlb_remove_table_sync_one(void) { } =20 #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ =20 +/* + * Architectures can override if their TLB flush already broadcasts IPIs t= o all + * CPUs when freeing or unsharing page tables. + * + * Return true only when the flush guarantees: + * - IPIs reach all CPUs with potentially stale paging-structure cache ent= ries + * - Synchronization with IRQ-disabled code like GUP-fast + */ +#ifndef tlb_table_flush_implies_ipi_broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ + return false; +} +#endif =20 #ifndef CONFIG_MMU_GATHER_NO_GATHER /* --=20 2.49.0 From nobody Sat Feb 7 21:14:44 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42DDF31A541 for ; Mon, 29 Dec 2025 14:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017606; cv=none; b=mzJvmJWb7G9PZrRH5c0nyB4lJNFGWZQg+ou8CiQ81xOXtFUiNmEBiizaiuwxbo0Rj/iAwCBHoDq397ojxBVrZmPuMbr5aD2+xob6OOEDAEWxgfTVhBjccrf2fV71DwwdpO5bhHPEPBtDO0eYWoLHz7dQBYn0sjhaPkK3vUENRD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017606; c=relaxed/simple; bh=m4iHj+AwFx2PCF5x5k1miVOJkb/O+RupWNG1Z8Fowrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KXAKotRkCh8+TnQYjiRcBAss88V1pN09sieoNpQ6r5+YTEdBYxpoNEbXxSdzvc+ILK5sgvN8q80EByBhj7Rh6SrCkLG0PdDT6z/lDT6/3Gh8ufe5BFsLriJitDd2WBLkkBxTamfzIdqQ7QgeVOAnueWaBqvknp4Zjm30vysyzfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7bb710d1d1dso12719612b3a.1 for ; Mon, 29 Dec 2025 06:13:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767017603; x=1767622403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZldRDJqtH1ig79a3NbAjYulmXt3x4GlRPqkLpWEwBdc=; b=AmbQNT1yMRYE6M8+zYFTzfpIDPWF55suk3d8m7nhLrGQ+kD3D0HGVLoutK1bFJ07fV 4k4QWDsF4Ra5yg9ugPK8HAWwiNuDyWSKMzH1vvw/5LWWU3VEglrvQ6RBxE0tuaGUX/Fd xdguwWHPulccIXP9mRfUTjir9u4woVPX+t7ZSE9FOcnKDEW4+/AV43p4XyIZ3tLsOy4G mM5nJ99eib+kocA+P0iuG1BXI9r1s6HwSsyB6ktOpvsCkmy/WEwUo9Ek/WRJOkNOIn0X pljzeu2JgDhiaOXTfvhydoF23Pyw94GhZaXzyGf7SZB5y4n6U+GFbLNFV9iMIu1jNEQF nXDg== X-Forwarded-Encrypted: i=1; AJvYcCXq97pNDIrPRoX4IvyFitOcAPE2RtEzcO6n8j9eH/wFs49GKJ+44cZ4hCUPVfnHtiyXXwKxwdIvqNP4/0I=@vger.kernel.org X-Gm-Message-State: AOJu0YzoIVi8bDyIxFQfBz1GWB/kV9Tj5mb6aASWR1ZMByNi4u30I18D N/196Bs8UyM1OcRQmkbFLyPVvt1ejs1/bBGqXMrYx5DyagjuQee0hvmw X-Gm-Gg: AY/fxX4MCZHvry4bMa898v2XE8ssP6/ZW+lnLDoZ2mwNc9JZnGWDIR2W88tbOBvybKi re+vkRvUhOArB12sorBLw4+nLbO23Mgc+Xmc/r7CZubWW4fCPvJ+hhhs6CQn+Ak9t+M4TFbW3C0 xSjMiNsfchnfyzFzsg7yAuDOIx8iG9VYMBBMw1H203ZIC2QXpnsucDKrjdvvJGtCF1R+9wvkTqd 3yfHbTJr0Ad65JR5aHFNlGWganzwWxiN1LPVPDttbMwNjxQCmgM0SLlZGKgI0ApP6Qc8zgdsOHz 8KCV7C95W1LIfw5nedYBxTHlFbC6A8WTZz1LxuEoOWQrelM59Y021GzJCvukyi7Mde6wmI6/YG4 Qwiui1DzLuJFcZwO4dj8CQ+svHkp4gYA2JfOI+gG7HDz6ol7uL04C9vrmV/z+sB2pFzUVdMX5Qx QfcKF5mIAZPIzwJtC7UWGr X-Google-Smtp-Source: AGHT+IH9QXaO3feBvaLzy/ByuIkfJ3Ao5dwL4ovexpjF/alBrOC14CnwS3t1wGYhjPm1oFgU/egDBQ== X-Received: by 2002:a05:6a00:8014:b0:7aa:e5f2:617d with SMTP id d2e1a72fcca58-7ff651c3519mr29469977b3a.30.1767017603556; Mon, 29 Dec 2025 06:13:23 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7a93ab3csm29472636b3a.7.2025.12.29.06.13.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:13:23 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, ioworker0@gmail.com, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v1 2/3] x86/mm: implement redundant IPI elimination for page table operations Date: Mon, 29 Dec 2025 22:12:44 +0800 Message-ID: <20251229141246.63435-3-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229141246.63435-1-lance.yang@linux.dev> References: <20251229141246.63435-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lance Yang Add a callback function flush_tlb_multi_implies_ipi_broadcast to pv_mmu_ops to explicitly track whether flush_tlb_multi IPIs provide sufficient synchronization for GUP-fast when freeing or unsharing page tables. Pass both freed_tables and unshared_tables to flush_tlb_mm_range() to ensure lazy-TLB CPUs receive IPIs and flush their paging-structure caches: flush_tlb_mm_range(..., freed_tables || unshared_tables); Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- arch/x86/include/asm/paravirt_types.h | 6 ++++++ arch/x86/include/asm/tlb.h | 19 ++++++++++++++++++- arch/x86/kernel/paravirt.c | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/p= aravirt_types.h index 3502939415ad..a5bd0983da1f 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -133,6 +133,12 @@ struct pv_mmu_ops { void (*flush_tlb_multi)(const struct cpumask *cpus, const struct flush_tlb_info *info); =20 + /* + * Indicates whether flush_tlb_multi IPIs provide sufficient + * synchronization for GUP-fast when freeing or unsharing page tables. + */ + bool (*flush_tlb_multi_implies_ipi_broadcast)(void); + /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); void (*notify_page_enc_status_changed)(unsigned long pfn, int npages, boo= l enc); diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..3a7cdfdcea8e 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -5,10 +5,26 @@ #define tlb_flush tlb_flush static inline void tlb_flush(struct mmu_gather *tlb); =20 +#define tlb_table_flush_implies_ipi_broadcast tlb_table_flush_implies_ipi_= broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void); + #include #include #include #include +#include + +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ +#ifdef CONFIG_PARAVIRT + if (pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast) + return pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast(); + + return false; +#else + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +#endif +} =20 static inline void tlb_flush(struct mmu_gather *tlb) { @@ -20,7 +36,8 @@ static inline void tlb_flush(struct mmu_gather *tlb) end =3D tlb->end; } =20 - flush_tlb_mm_range(tlb->mm, start, end, stride_shift, tlb->freed_tables); + flush_tlb_mm_range(tlb->mm, start, end, stride_shift, + tlb->freed_tables || tlb->unshared_tables); } =20 static inline void invlpg(unsigned long addr) diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ab3e172dcc69..4eaa44800b39 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -60,6 +60,15 @@ void __init native_pv_lock_init(void) static_branch_enable(&virt_spin_lock_key); } =20 +static bool native_flush_tlb_multi_implies_ipi_broadcast(void) +{ + /* Paravirt may use hypercalls that don't send real IPIs. */ + if (pv_ops.mmu.flush_tlb_multi !=3D native_flush_tlb_multi) + return false; + + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +} + struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; =20 @@ -173,6 +182,7 @@ struct paravirt_patch_template pv_ops =3D { .mmu.flush_tlb_kernel =3D native_flush_tlb_global, .mmu.flush_tlb_one_user =3D native_flush_tlb_one_user, .mmu.flush_tlb_multi =3D native_flush_tlb_multi, + .mmu.flush_tlb_multi_implies_ipi_broadcast =3D native_flush_tlb_multi_imp= lies_ipi_broadcast, =20 .mmu.exit_mmap =3D paravirt_nop, .mmu.notify_page_enc_status_changed =3D paravirt_nop, --=20 2.49.0 From nobody Sat Feb 7 21:14:44 2026 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98E6721ADC7 for ; Mon, 29 Dec 2025 14:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017615; cv=none; b=fDeGliD0CW9DbtU4IdvIuwLSuo7W0H+wAL2cNrVnM5zkpy/FyvRCweZlwwQ6qZ0NLW0EIfWMDU7tM/xj0oqFJ+Jp0ycEjYT4CvEVHNphEs5dlvuKJK2Ikd7+aaaE5beMCd4PtDdfh01r2atbkaR651unyiLUw1h5LR/fg9M2ClM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017615; c=relaxed/simple; bh=QELGmcYo0okd7XeZ+8OIMQ2Ox7GoXMWa9Ttw3qK5W4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RXSuDU468iCx3+QNvrs3qIHSTC0SdCa7oG2eUFzM+ap4Mfq2vpoY/v4Wm0LYFpaV/yigIi9hhl56Y6eN0sxHC1pXvMF32f5svMUukdQrnb9hvNNer5i21W0LNCeJR+X09AO2+ErGp2gxSeRLHnc9rRMhkDGC0/SczBYbiJ1QDpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b80fed1505so9168901b3a.3 for ; Mon, 29 Dec 2025 06:13:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767017613; x=1767622413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=K2pBV4vyT2c4GBUcrUp/G3rP2JcNWZOiRH8LtGLdyis=; b=Fc8hYQlyOVgOVCY1ROcGSwzo5rkj00pBuJasheaSZDEof61gi93n6Rkks/xOr0FB14 LODHonWWvZ6AebpKGfe+chDuBUS2+sLMyQ88J7crKG3GGAL8Jz2MioUngp66MlS+iIbl JjkNH9h6pnyhACfdob1aUwLTn6I7v1D6d1piA5q9a2/ljtyODgX55E6S2d8uJD9ovFsP R6KphjKEreV8nBMcWShWQz9KaWQxlk15ZdmD0zC9k0Bh38CXameCjc5efQyO10ZOFjVa evteiwAWxqI7zILOoZaMnxmkYC/3gvIfEk8wb9Xmuo1ROORvAlXybG5CcCA3x1UUtIrG ovdw== X-Forwarded-Encrypted: i=1; AJvYcCVuQIlw1v2BsQ1bpLIuhlmjlcTpTINngIIS9s6c9Zu/21uw3EnPrcPqbwamMzEa5rI+HFpQA/mb6JI9yNE=@vger.kernel.org X-Gm-Message-State: AOJu0YxBRyRL4uWQPPSqmUHg9pNqr/6rK93PXm+LxKlfRnM/NrYfCVcp kbnOklNr+8hmObntRB11ftST6hkqoY5yuojwKnJuq+ACMciSpxvBVi7r X-Gm-Gg: AY/fxX72C/j2VzpfF5c42reyYMGUOwwXb17NVWbhzOI2CCHJ/8LaAmBb8Dxh4rzoW2r YdBXCdOrqIkBa4w37Z2VP07kwkwA8nTU6qZZoNT2aJtlvlWtWJ6v4QJjdGM+2kqwlwdDISlhCZd PslLYJCj3tJcEQ2NF9boCcN++T4JDf2UHXzLv1hyT3prEUNVU2sBm0AlSncjEg6OYOoJZPnvgcy us71DfAPGHvQGRky86b+zoOLixNoHYyuhOp6J4mEpS8+KKR8XCKJT+jxFU4RuabXheJ3WM7QFi0 FG22BEmuxVhx1mvuJNUmU54UbndWkyNZetVgVcmkPfgmGq2ljH8VtjXkqN5rWRWY6Y20+CNYhFM eJtzkT/JmcYdg34WDWuHpiDeTAHpXGnfmMpRACYqP5YXMDX1mYqVwcif5USr9pFhxgYux3EUxFz +thG6E4vPWKlg1nhg9PpGI X-Google-Smtp-Source: AGHT+IEQcka9ib1s/U4Ml1PaEUtFGR87vhYFW2tWQf/4rd0WuelWAoKlS5mhRUJT7d3+jGEwNTk6bw== X-Received: by 2002:a05:6a00:450c:b0:7e8:4398:b373 with SMTP id d2e1a72fcca58-7ff66d5f557mr25343417b3a.70.1767017612759; Mon, 29 Dec 2025 06:13:32 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7a93ab3csm29472636b3a.7.2025.12.29.06.13.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:13:32 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, david@kernel.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, ioworker0@gmail.com, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v1 3/3] mm: embed TLB flush IPI check in tlb_remove_table_sync_one() Date: Mon, 29 Dec 2025 22:12:45 +0800 Message-ID: <20251229141246.63435-4-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229141246.63435-1-lance.yang@linux.dev> References: <20251229141246.63435-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lance Yang Embed the tlb_table_flush_implies_ipi_broadcast() check directly inside tlb_remove_table_sync_one() instead of requiring every caller to check it explicitly. This relies on callers to do the right thing: flush with freed_tables=3Dtrue or unshared_tables=3Dtrue beforehand. All existing callers satisfy this requirement: 1. mm/khugepaged.c:1188 (collapse_huge_page): pmdp_collapse_flush(vma, address, pmd) -> flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE) -> flush_tlb_mm_range(mm, ..., freed_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) So freed_tables=3Dtrue before calling tlb_remove_table_sync_one(). 2. include/asm-generic/tlb.h:861 (tlb_flush_unshared_tables): tlb_flush_mmu_tlbonly(tlb) -> tlb_flush(tlb) -> flush_tlb_mm_range(mm, ..., unshared_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) unshared_tables=3Dtrue (equivalent to freed_tables for sending IPIs). 3. mm/mmu_gather.c:341 (__tlb_remove_table_one): When we can't allocate a batch page in tlb_remove_table(), we do: tlb_table_invalidate(tlb) -> tlb_flush_mmu_tlbonly(tlb) -> flush_tlb_mm_range(mm, ..., freed_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) Then: tlb_remove_table_one(table) -> __tlb_remove_table_one(table) // if !CONFIG_PT_RECLAIM -> tlb_remove_table_sync_one() freed_tables=3Dtrue, and this should work too. Why is tlb->freed_tables guaranteed? Because callers like pte_free_tlb() (via free_pte_range) set freed_tables=3Dtrue before calling __pte_free_tlb(), which then calls tlb_remove_table(). We cannot free page tables without freed_tables=3Dtrue. Note that tlb_remove_table_sync_one() was a NOP on bare metal x86 (CONFIG_MMU_GATHER_RCU_TABLE_FREE=3Dn) before commit a37259732a7d ("x86/mm: Make MMU_GATHER_RCU_TABLE_FREE unconditional"). 4-5. mm/khugepaged.c:1683,1819 (pmdp_get_lockless_sync macro): Same as #1. These also use pmdp_collapse_flush() beforehand. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- mm/mmu_gather.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 7468ec388455..7b588643cbae 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -276,6 +276,10 @@ static void tlb_remove_table_smp_sync(void *arg) =20 void tlb_remove_table_sync_one(void) { + /* Skip the IPI if the TLB flush already synchronized with other CPUs. */ + if (tlb_table_flush_implies_ipi_broadcast()) + return; + /* * This isn't an RCU grace period and hence the page-tables cannot be * assumed to be actually RCU-freed. --=20 2.49.0