From nobody Sat Apr 4 07:50:49 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F171A2D73A1 for ; Fri, 20 Mar 2026 10:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774003539; cv=none; b=G+Z8l8V8qk97ZH0eWzFjl0we+J7INWZq8nO8y7O6HaupvGfmg/fmhA0NbcEZVgRkFGtWaSK/XuT1RBqHX2kVj3DLsmfUfqXjyG6XZJ6KINgb9vLuBr2SbhtZdTYI6vooKeEMas5kcLmc75RRO1Wi7p6tGv91z/RAms2CeyMecjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774003539; c=relaxed/simple; bh=bBk6T7GnUtho6Ef3CoSHDVRjC4rhed6RGz3DdEr6fpI=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=R+V9MoEXIGtHNdi98gR/5WnBgeN8+Qg3HpnuSpQUMBKJoKGuYBt5ntkzH6NJCUUP+ynWrcEbIVULAQbNEQUID1TayGKR4xzr0+XOVGQ+pguphEAKdAqmbjvxqUntThvRZBIkIDiHIhARkxgCHFR1Me/Er8yj7Lv6v7oJdc2A9Jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XHl0e+9f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XHl0e+9f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F81C4CEF7; Fri, 20 Mar 2026 10:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774003538; bh=bBk6T7GnUtho6Ef3CoSHDVRjC4rhed6RGz3DdEr6fpI=; h=Date:From:To:Cc:Subject:Reply-To:From; b=XHl0e+9f7K/nO3yFDYZPni7j1p03F46K66Eme7RT0nw65AodiZKmBeW0HpLtCarMB CIjfXpojN4voXQqBIkK99CWxQtTpxOPRy7qW4RBU8hM/een0FLlnvFYcqncJqEyUgz YMyYaXP+8GRI78rgcx4lmm6zfR8PKdzUZBrCdIHPaQ5ApVl9sm5K4ZvaVlpwDXhmIk C9w7rf5vx7qTo2MTwCexEHFAfPTZhwIK4SGdSfNW9xALnLAmY02I9xZD4NjXJqyPxr SCTRYUMfbrQ4A6N9/1cxBWR2o9e5VOIbB91zGdWb/czbgTS4S63+pSex/YtZT2RjHr kM909wAO4AxgQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 9C709CE0CAC; Fri, 20 Mar 2026 03:45:36 -0700 (PDT) Date: Fri, 20 Mar 2026 03:45:36 -0700 From: "Paul E. McKenney" To: Thomas Gleixner , Rik van Riel , "Rafael J. Wysocki" , Ulf Hansson , Joel Fernandes , Roman Kisel Cc: linux-kernel@vger.kernel.org Subject: [PATCH] kernel/smp: Improve smp_call_function_single() CSD-lock diagnostics Message-ID: <25c2eb97-77c8-49a5-80ac-efe78dea272c@paulmck-laptop> Reply-To: paulmck@kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both smp_call_function() and smp_call_function_single() use per-CPU call_single_data_t variable to hold the infamous CSD lock. However, while smp_call_function() acquires the destination CPU's CSD lock, smp_call_function_single() instead uses the source CPU's CSD lock. (These are two separate sets of CSD locks, cfd_data and csd_data, respectively.) This otherwise inexplicable pair of choices is explained by their respective queueing properties. If smp_call_function() where to use the sending CPU's CSD lock, that would serialize the destination CPUs' IPI handlers and result in long smp_call_function() latencies, especially on systems with large numbers of CPUs. For its part, if smp_call_function_single() were to use the (single) destination CPU's CSD lock, this would similarly serialize in the case where many CPUs are sending IPIs to a single "victim" CPU. Plus it would result in higher levels of memory contention. Except that if you don't have NMI-based stack tracing and you are working with a weakly ordered system where remote unsynchronized stack traces are especially unreliable, the improved debugging beats the improved queueing. Keep in mind that this improved queueing only matters if a bunch of CPUs are calling smp_call_function_single() concurrently for a single "victim" CPU, which is not the common case. Therefore, make smp_call_function_single() use the destination CPU's csd_data instance in kernels built with CONFIG_CSD_LOCK_WAIT_DEBUG=3Dy where csdlock_debug_enabled is also set. Otherwise, continue to use the source CPU's csd_data. Signed-off-by: Paul E. McKenney diff --git a/kernel/smp.c b/kernel/smp.c index f349960f79cad..09521cb38a55c 100644 Reviewed-by: Ulf Hansson --- a/kernel/smp.c +++ b/kernel/smp.c @@ -377,6 +377,20 @@ static __always_inline void csd_unlock(call_single_dat= a_t *csd) =20 static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data); =20 +#ifdef CONFIG_CSD_LOCK_WAIT_DEBUG +static call_single_data_t *get_single_csd_data(int cpu) +{ + if (static_branch_unlikely(&csdlock_debug_enabled)) + return per_cpu_ptr(&csd_data, cpu); + return this_cpu_ptr(&csd_data); +} +#else +static call_single_data_t *get_single_csd_data(int cpu) +{ + return this_cpu_ptr(&csd_data); +} +#endif + void __smp_call_single_queue(int cpu, struct llist_node *node) { /* @@ -670,7 +684,7 @@ int smp_call_function_single(int cpu, smp_call_func_t f= unc, void *info, =20 csd =3D &csd_stack; if (!wait) { - csd =3D this_cpu_ptr(&csd_data); + csd =3D get_single_csd_data(cpu); csd_lock(csd); }