mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@kernel.org>,
	Chuyi Zhou <zhouchuyi@bytedance.com>,
	Ulf Hansson <ulfh@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Marco Crivellari <marco.crivellari@suse.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH 1/2] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug
Date: Wed, 15 Jul 2026 17:45:38 -0700	[thread overview]
Message-ID: <20260716004539.13983-1-paulmck@kernel.org> (raw)
In-Reply-To: <01070aaf-540c-403b-b589-5185f62eb29a@paulmck-laptop>

From: Chuyi Zhou <zhouchuyi@bytedance.com>

Commit b0473dcd4b1d ("smp: Improve smp_call_function_single()
CSD-lock diagnostics") made smp_call_function_single() use the destination
CPU's csd_data when CSD lock debugging is enabled. That lets the debug code
associate a stuck CSD lock with the target CPU, but it also means the CPU
argument is used in per_cpu_ptr() before generic_exec_single() has a chance
to validate it.

This becomes unsafe when smp_call_function_any() cannot find an online CPU
in the supplied mask. In that case the selected CPU can be nr_cpu_ids, and
the !wait path calls get_single_csd_data(cpu) before generic_exec_single()
returns -ENXIO. With csdlock_debug_enabled set, that indexes the per-CPU
offset array with an invalid CPU number.

Use the destination CPU's csd_data only when the CPU number is within
nr_cpu_ids. For invalid CPU numbers, fall back to the local CPU's csd_data
and let generic_exec_single() perform the existing validation and return
-ENXIO.

Fixes: b0473dcd4b1d ("smp: Improve smp_call_function_single() CSD-lock diagnostics")
Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Acked-by: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/smp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index a0bb56bd8ddadb..dc6582bb35d084 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -380,7 +380,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data);
 #ifdef CONFIG_CSD_LOCK_WAIT_DEBUG
 static call_single_data_t *get_single_csd_data(int cpu)
 {
-	if (static_branch_unlikely(&csdlock_debug_enabled))
+	if (static_branch_unlikely(&csdlock_debug_enabled) &&
+	    (unsigned int)cpu < nr_cpu_ids)
 		return per_cpu_ptr(&csd_data, cpu);
 	return this_cpu_ptr(&csd_data);
 }
-- 
2.40.1


  reply	other threads:[~2026-07-16  0:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  0:44 [PATCH 0/2] CSD-lock updates for v7.3 Paul E. McKenney
2026-07-16  0:45 ` Paul E. McKenney [this message]
2026-07-22 18:58   ` [tip: smp/urgent] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug tip-bot2 for Chuyi Zhou
2026-07-16  0:45 ` [PATCH 2/2] smp: Make CSD lock acquisition atomic for debug mode Paul E. McKenney
2026-07-22 18:58   ` [tip: smp/urgent] " tip-bot2 for Chuyi Zhou
  -- strict thread matches above, loose matches on Subject: below --
2026-06-08 11:23 [PATCH 0/2] smp: Fix CSD lock debug regressions Chuyi Zhou
2026-06-08 11:23 ` [PATCH 1/2] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug 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=20260716004539.13983-1-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@kernel.org \
    --cc=ulfh@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®