From nobody Mon Feb 9 04:29:34 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 690242D5C91 for ; Mon, 29 Dec 2025 14:54:47 +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=1767020089; cv=none; b=lfVcMHT/LtUpw1boTLZlb36RFNWNp5OBDpQ3fFEc8a5XG+N57c9Um43eRQ91CttVwLEL9EZRVSmX08phdMlcSKTnpVIur4+y4aCmFjWhT+2Jz3nLKfyTKnbP3oo4QzSM+6PJQ3usWKplxWFUwirsEOEmVvzcqipsL9/bQpR/8uU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767020089; c=relaxed/simple; bh=lC6GEfxIGK/35lvrPF2qw5D86rHWEQ6C/lNcw05H+jI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dXG6GXQjK6ZAz9nDZjNUHfqpwuBGMyUz4IxHSh/dD/ew0JW3zIZE9dLZBVTkKLY95E4gGR0Vn3iHgel1UeaKSUEcI5DheREAAvUngsKaJ85RGGGbiMYLqzxPrhLzzmJHZLowSOFvv+GPMUDoqIrCHTQ+6i3JQDs3/iakL9YjZto= 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-7b9c17dd591so7847011b3a.3 for ; Mon, 29 Dec 2025 06:54:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767020087; x=1767624887; 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=ajf8UQ5hX9i96tajGa1CZkFL48h5CQSlBjtS/KXfDuU+9SZOjnZvXKFf43pVDdx+28 vgazkY7g5r0/4eKS/msVWtH0nWgViALFbsSCYEH+R1YNbLHWAwtebGzntKKeo6fwof3h 6P4rCm6Yf+9JnTl518H/HYtjuib0bPaPUbF+DyXgT4Z+tybTB6onmJOZWyan0AJO4bMg 3krMqfv+wk8HRq+D42bw4vT+UGnL0DhZDqHTFcyg8twu8SUShW1+DZ4a5WSseOQpjIeb Girlli3/uRXJr5RLvrCrm+FCYqvugNMTNrwNRCAr41pH2YL3LugypqFvcu40lpRwzmDb Crqg== X-Forwarded-Encrypted: i=1; AJvYcCVFYpGxOxPBR6vl9icFGKm2XPj9aBH0lCpJq1t5lRsXYukECTX+S/qsjQ0Xc/z+/b/DFpfh/wj8tsYXRbE=@vger.kernel.org X-Gm-Message-State: AOJu0YyGcGq25gw+yrzJlT0Uw+r+zTzkpNyjZcPIJeLbw97wngw2LiNI 00osxA1HsT7O8ZjLFjyngE6om/N9boOalp1aM3eCCEVKYMz3wnSZ2o4c X-Gm-Gg: AY/fxX5+jZx8XFYaP43uPzZc8gkY9h22XdolbJcC1a5Kqgdyhj3xItX8nXD8OJd10Op 5n1EPtAE7VMKdtooFDFu/2jLI4XOkB2vI9+ZDCGPIjVKnrOF//tcjSwMUNL1CwSaov5Y8Ge0Pt0 F0nKm6RrA0Jl7ULIHBbm6eb3JZcjyVX2HWyxk+c3yoo2OfjQZOwI+plzkwX4xawzRl9/VW/MKWj uKZNMPQfyHz4cDJofsuEHYOefNauPxyOJJjcQbkvpynQ4/PUomzJ47p90lWokJaM5RMhHAPYn9f qd9Nzu11ZHPEuWYvCk++RqezN/or21k5JMkL+ZXuuaZVsimvrEcBQZuPryB7V0WnyJQskR7C91j QZJjB4ZAM9Qg9VIp9kFMlx5lg1fP8O2WoBo25ZLiwKxsWGY6irKT5e8Y0o1JC6oxCxu7BF+0yPM EqOogTVe5laAKwSRnV6ofgOthGWH0RJyE= X-Google-Smtp-Source: AGHT+IGKVZznmIqdsFJZx8tzz7DJSoz4ei3n/x9I/qNdC+q4k/iJfPtD5Rz6uSZJWfuK81E5v5oz3Q== X-Received: by 2002:a05:6a21:6da6:b0:35b:9ba2:8cd5 with SMTP id adf61e73a8af0-376a9ccbb8emr26989418637.56.1767020086734; Mon, 29 Dec 2025 06:54:46 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34e70dbcb6esm31557603a91.9.2025.12.29.06.54.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:54:46 -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 v2 1/3] mm/tlb: allow architectures to skip redundant TLB sync IPIs Date: Mon, 29 Dec 2025 22:52:43 +0800 Message-ID: <20251229145245.85452-2-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229145245.85452-1-lance.yang@linux.dev> References: <20251229145245.85452-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 Suggested-by: Dave Hansen Suggested-by: David Hildenbrand --- 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 Mon Feb 9 04:29:34 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 3EB26329E78 for ; Mon, 29 Dec 2025 14:54:57 +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=1767020099; cv=none; b=IqFiVmGuC6LDHBlXjc59h93JJDri4Dw2jP1ct8J9U0vq0IUjOyKFwwrlcypqHKWpA8LHPgl2R4i0z9wr7fAbk9ANuhKAwQWwf1Ft/1DdM3siYIIemO1RCPpf4/UlVRYUmWAxc5lyh1MOEGrcrFSgF0HcCH9E+o8nkPdNwR8rKF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767020099; c=relaxed/simple; bh=m4iHj+AwFx2PCF5x5k1miVOJkb/O+RupWNG1Z8Fowrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIln4mx0CM21Z9aD8JJf3ixV+5eBE4XtE5yPG6M+R0fesd18nGf52ZoZstcUGIVPD4TtEerzYAHBoC0S9Ftfy52iZFqK4Q+WsunDsW5AVOuS2BZnXUlwl6kroa7JahgGGawCXd0mggVbYsMmDx9cIEbBz/hANZ2yU+GWOnz6yfs= 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-7f0db5700b2so7996632b3a.0 for ; Mon, 29 Dec 2025 06:54:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767020096; x=1767624896; 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=Sc4JfLEFDfwkcHdiYLIRpErgGopChW1gkFFoZbVv9/pHwDXvhR6AazBjA0bdsXCvp0 aENizf1ybYk5fO6snzkArzcBdVKJyuVi0qWO4z/IiEAeRWRQtnpUMv0oGUW4MxHnWxL0 FFzxM46bUmkMnOlSHXUtb1+NLZT4Y6a2ZumKbPcs99kZ6UzzhkT6nBs0q5a5o/GzLH4W wHnvvNp7VoXanemfxAqGQ3bjgCO7KLMVXxnssU+PWiSxwn7niKGz2uf9rRs+89l2DWqt FC9krCFTv2x+6uKPMhS53pS+m+NaIirfF/kgxb3dCMD9dmOg2VZbqLGXvo0qK1lz6rCe aEXA== X-Forwarded-Encrypted: i=1; AJvYcCWe4JjywovX8WWR0kC1WvLppoMT8sPevW7G4Fo9OeGnPIviudsP8cf7+PkOw0jvK7Nc6JfwvidKgG5bB4M=@vger.kernel.org X-Gm-Message-State: AOJu0YyDGd4JY6Sb7qRIxhUDxy4ZcAjnsgAOu1wi21WDxQzsEVSZE12M vCq+0DuNvlAoFVMXvNZEzmnJPK2pT5Z94S4T2NDE0YdGZPro89mGwHdc X-Gm-Gg: AY/fxX65x+zxPH2LgmcmiFqPRVXx+VXZSdMqBgiZJhWEtBGw7UeMuj63fXDvN/W22Vr vwRdO7yYndhHZa3K6NMIM0c3qhP2SdG3hJAuMrb1lurwU7OtGatD6DtxjsrEmPX/I18tqueNXFk vkrr3lV6Gop7e1N3EOwWTWMViTvqsI+sDnWkE/6Uo2cDkB79bFYhAzV0UASj78FtW+MjArcfINO qdzedXuackDQowfqmRYjx4BwXfU5G2m9FWtxobBEan12oQMdRhsVj9lCgPG07fnMkcfHzO3vRWf L6Vt6+weGU2IyBysL6RRhgmABXqrKPt1t95EqQTVYCppJslTsaIPlQ2RQE7JJGWHZWTU791IoJn C7jMkj97BC7vunVAW1xC6gVP6w2sa1KxD/RXO1R4Dz2psOxoJgcCMt9iZDb8cDI0LKJJfOK8EdY l5ABhrPZs0rYs8DBQqmOTF X-Google-Smtp-Source: AGHT+IEgAkno5Gh1oJSDww9XUzjPOXWz4twHLH5pNZW8aq25hrJps84zND6cTLDC5XmLsL+UKP9xOw== X-Received: by 2002:a05:6a20:2588:b0:366:14af:9bbf with SMTP id adf61e73a8af0-376ab2e77c7mr30792916637.73.1767020095708; Mon, 29 Dec 2025 06:54:55 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34e70dbcb6esm31557603a91.9.2025.12.29.06.54.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:54:55 -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 v2 2/3] x86/mm: implement redundant IPI elimination for page table operations Date: Mon, 29 Dec 2025 22:52:44 +0800 Message-ID: <20251229145245.85452-3-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229145245.85452-1-lance.yang@linux.dev> References: <20251229145245.85452-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 Suggested-by: Dave Hansen Suggested-by: David Hildenbrand --- 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 Mon Feb 9 04:29:34 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 8A63E329E78 for ; Mon, 29 Dec 2025 14:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767020107; cv=none; b=M5eG2hArnk3yQTrjGzI9xs+Jci2NNpZRqnOcpgIHIoPO1lsyvCeVLag7k4fJqs6pU2qf4pZtrSa9kV4BoOhsO88sX/Ip6qjDHcbTlke++tJr5ujaJExAh/tClOuxJh5wWIl5VvvWkEY2Mem51kErReu1Ux5/zNAoLMOpCIY1iFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767020107; c=relaxed/simple; bh=QELGmcYo0okd7XeZ+8OIMQ2Ox7GoXMWa9Ttw3qK5W4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dMZN0upJO6sH7wgvfw1h8WXC4TMA2BbjLij9iNOMmUekJTnwbNXYJIbs0Rwic7WmEon4gt0VwTuNotUbrXDL4V6ILcb7ChoAuboExKn5QsLODhjGNQO2fcPDwITYQZHAgro74ZJqued+WMdgl2scFXnsmw6RsWwYbctIgyiMyBk= 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.216.43 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-pj1-f43.google.com with SMTP id 98e67ed59e1d1-34ccb7ad166so8452637a91.2 for ; Mon, 29 Dec 2025 06:55:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767020104; x=1767624904; 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=RYRxysVreRoddeYf468idnbP61t6xt3AkIHhYdA1K4NyeIrlE+6kmXaoAeL1n3EuAd 6SE0Cr1QAqu6XhM9yGM7/21f+cZ3A92ysrnDR7tkz+WlY0PVdXAX93j3FSsbemlY+z5X FOU1kHBYXIaoPWD/mNcjLUiMGWVx10e8lEExyVyvgOuLuNuKt97uUbcf1OTm1oGKWOVc rVRw2R8K42TSrYVpTaOlfDPzY4Nru/X4J9VxcRhoRkvBohNs/5imbU47VBeT8iuuqHA3 MrJxOPn23yM2V3dSZ1GRY9q/Coj+hQhAgISwuROdCP/PoMHFbQgGHzg9kCPQbzuWjDxX jW1A== X-Forwarded-Encrypted: i=1; AJvYcCVXlmd/7uABwhU/kujBLfUjFuh1cKDoOmPtyJ9hT+mTXiDsVxo4hzs4DRkTEv+IeLoLFLvuqAo3WPHpxd0=@vger.kernel.org X-Gm-Message-State: AOJu0YxxmEiZVaobCSjlcj71L7fA7qhbgT5Ttf5wjqdRUdNECjm2tikj 9CQghe+GGVY8plZg4+6aI0n24I4eTmW13oF8QEGu6e4s2I7RxdoocdgC X-Gm-Gg: AY/fxX4bariLl92MiYi57TblCWuCP5FqhaApizhqBjxKoN55vqxahlp95h8JDSnz46u IK4dHeUh9Qs6e6oYtyZqcLsBSKf7l5ZA+Slbx39krWITmf+snAp2Zz1upYZ9W4ridW6RimgNXKv i9Hpzy0hXD06+PNqaFLkb5gLK4MY335AkipM27d6xWrum+Fz3EK2oJEVl+ZwHsN1PZ9gtIIilkj zFN1As8F2RW/b8aPkWJM3LSu0LtDDAe++xQKMKi2m/w1QH3kHt160L6QX/XUQI2q9G/Cxd7A4+Z C3FkI/o58jgB9zFYRjhyvfgm9WaAXpxzPEV/fKJn1T8oDAk8nd2viBvfrZOyZ8O9YNEE3WiLg1n kwt7BnqbYDA5OBY+xwD/N/96WrK5YmI17TZq7XU0xzFXR01h6Up/wQza3XDTLFJCNJpbSdqBlcX dqZ/g3JqQad1NyZ1fD1DLX X-Google-Smtp-Source: AGHT+IEf9Iv5nOPUSm+mp/HKv1O5w/lt7w1F73FenhI+IdA1+6z3gDDv4Fw3i4Tf4eeD+0sQQsI38w== X-Received: by 2002:a17:90b:560c:b0:32d:e780:e9d5 with SMTP id 98e67ed59e1d1-34e921c3003mr21256159a91.22.1767020103739; Mon, 29 Dec 2025 06:55:03 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34e70dbcb6esm31557603a91.9.2025.12.29.06.54.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:55:03 -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 v2 3/3] mm: embed TLB flush IPI check in tlb_remove_table_sync_one() Date: Mon, 29 Dec 2025 22:52:45 +0800 Message-ID: <20251229145245.85452-4-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229145245.85452-1-lance.yang@linux.dev> References: <20251229145245.85452-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 Suggested-by: Dave Hansen Suggested-by: David Hildenbrand --- 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