From nobody Fri Jul 24 21:53:25 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A15043A81D; Thu, 23 Jul 2026 10:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784802089; cv=none; b=Y9t2/ruqSfsQWSgCHmqe5QhcVZAOemwm7PMKxXy9lG90RNpwrdlacjek9j6KzEMfuRK9LrRd1zW+MVQaK6Esf9YjID81nXaJxa5kjY8NCGPdEqAgDwEK0woydGXPDJvft3qFcVjtS7Q1V24UulEkgrdKpCVY+bBPkn5LViBgn+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784802089; c=relaxed/simple; bh=uzjM5oRMLNmRYz++95163OIfgA5EGrESUIzsgrhpopo=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=fCXFiEJBO5BZxlXIVQRkC7F+hbWfCmwG4+yuqndb3mrAiQfuypcyKZCbnrgB0AdPAQ6MXoOKbjqfm2qRsrOceGyGjNk5QjLWVh2miTr1znnXq8OMshRrItXuNqR05gDDo3NsCphVo5cKXHw3n9g3T5g6ZukyzHWpRd3kN7z5Fjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZEYV24B8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yttBEOx4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZEYV24B8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yttBEOx4" Date: Thu, 23 Jul 2026 10:21:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1784802085; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZYMTp2L2JWVr+0lProcXXIBiPVhEqfE3OJlXm16NwXI=; b=ZEYV24B8MbWYwxN6Mx/ixJiWmr3BKVAu/xYRK7ZUTdfnHisdsBOOaGpD+NVjypLGBitjau pHYbUX4jupkRsOAmlcWPiHJcvH7wiB/PUfdjpWDZDETeKPkKVPcKydQZbJuAxFiGjnS9j8 AV2yO//djrppQ0me2vQeCKT0X0IkmXRPCmWfdkZbe27yuNWeSnjCIurWN9gb+mdtGAAaXg wh3RPSY+5Q00b4oe8EN9xYvyVbhx7XcJxqjJFZj5S+wMT9+W/oek2JmSVnYWcPPUVuhJEy wwaHGo1YatxJpEhGZI5n3f80TeYXnY/gr8m+D2HlUMB4I0azvrHT8k6LgBxL2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1784802085; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZYMTp2L2JWVr+0lProcXXIBiPVhEqfE3OJlXm16NwXI=; b=yttBEOx4vUgfwkBZGNjqPn2OzxWtD2ulFSRt8vah1+HvpTikpdoxZPljKafaOvntZw+Uf7 LsckZzEAW0owi8Dw== From: "tip-bot2 for Chuyi Zhou" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: smp/core] smp: Refactor remote CPU selection in smp_call_function_any() Cc: Chuyi Zhou , Thomas Gleixner , "Paul E. McKenney" , Sebastian Andrzej Siewior , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260709122933.4021501-4-zhouchuyi@bytedance.com> References: <20260709122933.4021501-4-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178480208382.2943223.13110473336208942716.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the smp/core branch of tip: Commit-ID: 0485235b6e0dcb8c70e5c947faa2b5031febd736 Gitweb: https://git.kernel.org/tip/0485235b6e0dcb8c70e5c947faa2b5031= febd736 Author: Chuyi Zhou AuthorDate: Thu, 09 Jul 2026 20:29:22 +08:00 Committer: Thomas Gleixner CommitterDate: Thu, 16 Jul 2026 09:24:55 +02:00 smp: Refactor remote CPU selection in smp_call_function_any() smp_call_function_any() disables preemption across the entire operation: selecting a target CPU, enqueueing the IPI, and synchronously waiting for the remote CPU. smp_call_function_single() already re-enables preemption before the synchronous csd_lock_wait(), so callers of smp_call_function_any() should benefit from the same shorter preemption-disabled section. Simply removing get_cpu() and put_cpu() from smp_call_function_any() would leave the preemption disablement entirely to smp_call_function_single(). That opens a preemption window between selecting the remote CPU, for example via sched_numa_find_nth_cpu(), and dispatching the IPI in smp_call_function_single(). If the selected CPU is fully offlined in that window, smp_call_function_single() fails its cpu_online() check and returns -ENXIO to the caller, violating the guarantee that smp_call_function_any() executes on any online CPU in the mask. Move the remote CPU selection into a common __smp_call_function_single() helper. Keep the target CPU selection and IPI dispatch within the same preemption-disabled region, while still allowing the wait path to use the shorter preemption-disabled section provided by smp_call_function_single(). Signed-off-by: Chuyi Zhou Signed-off-by: Thomas Gleixner Tested-by: Paul E. McKenney Reviewed-by: Sebastian Andrzej Siewior Link: https://patch.msgid.link/20260709122933.4021501-4-zhouchuyi@bytedance= .com --- include/linux/smp.h | 3 +-- kernel/smp.c | 56 +++++++++++++++++++++++--------------------- kernel/up.c | 3 +-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/linux/smp.h b/include/linux/smp.h index 6925d15..11e36c7 100644 --- a/include/linux/smp.h +++ b/include/linux/smp.h @@ -47,8 +47,7 @@ extern void __smp_call_single_queue(int cpu, struct llist= _node *node); /* total number of cpus in this system (may exceed NR_CPUS) */ extern unsigned int total_cpus; =20 -int smp_call_function_single(int cpuid, smp_call_func_t func, void *info, - int wait); +int smp_call_function_single(int cpuid, smp_call_func_t func, void *info, = bool wait); =20 void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func, void *info, bool wait, const struct cpumask *mask); diff --git a/kernel/smp.c b/kernel/smp.c index 31cdb06..5c05029 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -653,17 +653,9 @@ void flush_smp_call_function_queue(void) local_irq_restore(flags); } =20 -/** - * smp_call_function_single - Run a function on a specific CPU - * @cpu: Specific target CPU for this function. - * @func: The function to run. This must be fast and non-blocking. - * @info: An arbitrary pointer to pass to the function. - * @wait: If true, wait until function has completed on other CPUs. - * - * Returns: %0 on success, else a negative status code. - */ -int smp_call_function_single(int cpu, smp_call_func_t func, void *info, - int wait) +static int __smp_call_function_single(int cpu, smp_call_func_t func, + void *info, const struct cpumask *mask, + bool wait) { call_single_data_t *csd; call_single_data_t csd_stack =3D { @@ -680,6 +672,14 @@ int smp_call_function_single(int cpu, smp_call_func_t = func, void *info, */ this_cpu =3D get_cpu(); =20 + if (mask) { + /* Try for same CPU (cheapest) */ + if (!cpumask_test_cpu(this_cpu, mask)) + cpu =3D sched_numa_find_nth_cpu(mask, 0, cpu_to_node(this_cpu)); + else + cpu =3D this_cpu; + } + /* * Can deadlock when called with interrupts disabled. * We allow cpu's that are not yet online though, as no one else can @@ -724,6 +724,20 @@ int smp_call_function_single(int cpu, smp_call_func_t = func, void *info, =20 return err; } + +/** + * smp_call_function_single - Run a function on a specific CPU + * @cpu: Specific target CPU for this function. + * @func: The function to run. This must be fast and non-blocking. + * @info: An arbitrary pointer to pass to the function. + * @wait: If true, wait until function has completed on other CPUs. + * + * Returns: %0 on success, else a negative status code. + */ +int smp_call_function_single(int cpu, smp_call_func_t func, void *info, bo= ol wait) +{ + return __smp_call_function_single(cpu, func, info, NULL, wait); +} EXPORT_SYMBOL(smp_call_function_single); =20 /** @@ -774,10 +788,10 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async); =20 /** * smp_call_function_any - Run a function on any of the given cpus - * @mask: The mask of cpus it can run on. - * @func: The function to run. This must be fast and non-blocking. - * @info: An arbitrary pointer to pass to the function. - * @wait: If true, wait until function has completed. + * @mask: The mask of cpus it can run on. + * @func: The function to run. This must be fast and non-blocking. + * @info: An arbitrary pointer to pass to the function. + * @wait: If true, wait until function has completed. * * Selection preference: * 1) current cpu if in @mask @@ -788,17 +802,7 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async); int smp_call_function_any(const struct cpumask *mask, smp_call_func_t func, void *info, int wait) { - unsigned int cpu; - int ret; - - /* Try for same CPU (cheapest) */ - cpu =3D get_cpu(); - if (!cpumask_test_cpu(cpu, mask)) - cpu =3D sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); - - ret =3D smp_call_function_single(cpu, func, info, wait); - put_cpu(); - return ret; + return __smp_call_function_single(-1, func, info, mask, wait); } EXPORT_SYMBOL_GPL(smp_call_function_any); =20 diff --git a/kernel/up.c b/kernel/up.c index df50828..6d4ac95 100644 --- a/kernel/up.c +++ b/kernel/up.c @@ -9,8 +9,7 @@ #include #include =20 -int smp_call_function_single(int cpu, void (*func) (void *info), void *inf= o, - int wait) +int smp_call_function_single(int cpu, void (*func)(void *info), void *info= , bool wait) { unsigned long flags; =20