From: "tip-bot2 for Chuyi Zhou" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Chuyi Zhou <zhouchuyi@bytedance.com>,
Thomas Gleixner <tglx@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/mm] x86/mm: Re-enable preemption before flush_tlb_multi()
Date: Thu, 23 Jul 2026 10:32:21 -0000 [thread overview]
Message-ID: <178480274158.2943223.9063459835821318530.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260709122933.4021501-15-zhouchuyi@bytedance.com>
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: a5a162fe1ae130e3d2ceefef3f43afe3773c1d56
Gitweb: https://git.kernel.org/tip/a5a162fe1ae130e3d2ceefef3f43afe3773c1d56
Author: Chuyi Zhou <zhouchuyi@bytedance.com>
AuthorDate: Thu, 09 Jul 2026 20:29:33 +08:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Thu, 23 Jul 2026 12:30:31 +02:00
x86/mm: Re-enable preemption before flush_tlb_multi()
flush_tlb_mm_range() and arch_tlbbatch_flush() pin the current CPU while
they decide whether the flush can be handled locally or must be sent to
remote CPUs. The CPU pinning is needed for the current CPU number and for
the local TLB flush path, which reads per-CPU TLB state.
The caller does not need to remain pinned while waiting for a remote TLB
flush to complete. After the remote-flush path has been selected,
flush_tlb_info is caller-private stack storage, so the caller no longer
has to stay on the same CPU to protect a shared per-CPU flush_tlb_info
object.
flush_tlb_multi() may also route through x86 PV backends. Those backends
must protect their own CPU-local scratch state instead of relying on the
caller to stay pinned. Hyper-V already does this by disabling interrupts
while using hyperv_pcpu_input_arg, and Xen's multicall path brackets its
per-CPU multicall buffer with xen_mc_batch() and xen_mc_issue().
kvm_flush_tlb_multi() also disables preemption while using __pv_cpu_mask.
Remote TLB flushes may synchronously wait for many CPUs, and the wait can
take tens of milliseconds when remote CPUs have interrupts disabled or
when many CPUs are involved. Keeping preemption disabled for that whole
wait unnecessarily increases scheduling latency on the initiating CPU.
Drop the CPU pinning before calling flush_tlb_multi() in the remote paths
of flush_tlb_mm_range() and arch_tlbbatch_flush(). Keep the local paths
inside the pinned section because they still access this CPU's TLB state.
Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Tested-by: Paul E. McKenney <paulmck@kernel.org>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20260709122933.4021501-15-zhouchuyi@bytedance.com
---
arch/x86/mm/tlb.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index b464a73..e5a0c6e 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1403,6 +1403,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
bool freed_tables)
{
struct flush_tlb_info info;
+ bool remote_flush = false;
int cpu = get_cpu();
u64 new_tlb_gen;
@@ -1419,9 +1420,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
if (mm_global_asid(mm)) {
broadcast_tlb_flush(&info);
} else if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids) {
- info.trim_cpumask = should_trim_cpumask(mm);
- flush_tlb_multi(mm_cpumask(mm), &info);
- consider_global_asid(mm);
+ remote_flush = true;
} else if (mm == this_cpu_read(cpu_tlbstate.loaded_mm)) {
lockdep_assert_irqs_enabled();
local_irq_disable();
@@ -1430,6 +1429,13 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
}
put_cpu();
+
+ if (remote_flush) {
+ info.trim_cpumask = should_trim_cpumask(mm);
+ flush_tlb_multi(mm_cpumask(mm), &info);
+ consider_global_asid(mm);
+ }
+
mmu_notifier_arch_invalidate_secondary_tlbs(mm, start, end);
}
@@ -1676,7 +1682,7 @@ EXPORT_SYMBOL_FOR_KVM(__flush_tlb_all);
void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
{
struct flush_tlb_info info;
-
+ bool remote_flush = false;
int cpu = get_cpu();
init_flush_tlb_info(&info, NULL, 0, TLB_FLUSH_ALL, 0, false,
@@ -1690,7 +1696,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
invlpgb_flush_all_nonglobals();
batch->unmapped_pages = false;
} else if (cpumask_any_but(&batch->cpumask, cpu) < nr_cpu_ids) {
- flush_tlb_multi(&batch->cpumask, &info);
+ remote_flush = true;
} else if (cpumask_test_cpu(cpu, &batch->cpumask)) {
lockdep_assert_irqs_enabled();
local_irq_disable();
@@ -1698,9 +1704,12 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
local_irq_enable();
}
- cpumask_clear(&batch->cpumask);
-
put_cpu();
+
+ if (remote_flush)
+ flush_tlb_multi(&batch->cpumask, &info);
+
+ cpumask_clear(&batch->cpumask);
}
/*
next prev parent reply other threads:[~2026-07-23 10:32 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 12:29 [PATCH v10 00/14] Allow preemption during IPI completion waiting to improve real-time performance Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 01/14] smp: Disable preemption explicitly in __csd_lock_wait() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 02/14] smp: Enable preemption early in smp_call_function_single() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 03/14] smp: Refactor remote CPU selection in smp_call_function_any() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 04/14] smp: Use task-local IPI cpumask in smp_call_function_many_cond() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 05/14] smp: Alloc percpu csd data in smpcfd_prepare_cpu() only once Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 06/14] smp: Enable preemption early in smp_call_function_many_cond() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 07/14] smp: Remove preempt_disable() from smp_call_function() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 08/14] smp: Remove preempt_disable() from on_each_cpu_cond_mask() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 09/14] scftorture: Remove preempt_disable() in scftorture_invoke_one() Chuyi Zhou
2026-07-23 10:21 ` [tip: smp/core] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 10/14] x86/mm: Factor out flush_tlb_info initialization Chuyi Zhou
2026-07-23 10:32 ` [tip: x86/mm] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 11/14] x86/mm: Cap flush_tlb_info alignment at 64 bytes Chuyi Zhou
2026-07-23 10:32 ` [tip: x86/mm] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 12/14] x86/mm: Move flush_tlb_info back to the stack Chuyi Zhou
2026-07-23 10:32 ` [tip: x86/mm] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 13/14] x86/kvm: Disable preemption in kvm_flush_tlb_multi() Chuyi Zhou
2026-07-23 10:32 ` [tip: x86/mm] " tip-bot2 for Chuyi Zhou
2026-07-09 12:29 ` [PATCH v10 14/14] x86/mm: Re-enable preemption before flush_tlb_multi() Chuyi Zhou
2026-07-23 10:32 ` tip-bot2 for Chuyi Zhou [this message]
2026-07-16 14:14 ` [PATCH v10 00/14] Allow preemption during IPI completion waiting to improve real-time performance Chuyi Zhou
2026-07-16 21:18 ` Thomas Gleixner
2026-07-23 19:26 ` Borislav Petkov
2026-07-24 3:08 ` Chuyi Zhou
2026-08-11 21:22 ` Borislav Petkov
2026-08-12 3:56 ` Chuyi Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178480274158.2943223.9063459835821318530.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=zhouchuyi@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®