From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 48405309F00 for ; Thu, 16 Jul 2026 00:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784162742; cv=none; b=fTrPndtWpVQBQ2qOFJQn21cnllPeEEufeLnzTiZ7QODFfhR4GqQzekXA09T7UWDFrVQ5sgOZvbKL4irvSYAhP0KFE/Tq6tgbdna0h/XBsc2XP5wdgy5HynbXl7XNgVXzU8gYkA60KtaVV/Cws4Y67Rn3NUbrpQ3B+Ys9Bir/BVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784162742; c=relaxed/simple; bh=45N8Tw0nbFR/tUcRrbcencZ0MXmIl52x5c713vTbZqU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T6xgEigsejAEo8b0NaadVOvgWqJsRsHHFNk8fTXFSMIZxZL4OTOdEcK7ZeQemNuE95BUpcUfo5DHnEgF6Pq/m1aUto4WE1hT0ybiwk9bFGOWTkStC5RPaUXtH68Do7H//3Y/iRJ7gddlpsp7LaGwkuYdvrysSoQqc0Zu9RzhRuM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jRs7WOuO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jRs7WOuO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F37C01F000E9; Thu, 16 Jul 2026 00:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784162741; bh=vFBYIn8JjXDFeh03QvQBuEg35l79xVLBqEMTfqo+BhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jRs7WOuO+rewZ87f1FwL/ix8vePSY+k0BCCApd6tTnpuGg2fi2wY8aiJup4mL5B11 qopYIJQznvrUBCPostqMnrRl4sC6XdOj4NQL7ZqNZlJ2bitcIq9r5Jwd3ZblfergAC oyWk23n9vYv3oLtbK4PEvLQiZEJfGvFo/t7ELZzR1TACvfsG3y7KJmEJVPg+QEO9KY 6SKm/L600isLjfRTC54l/U3Wf9REYsSBwCgsw25wPyQomhKSS4BuMLXZ2m7qpNCJVo 7kP7IdZUhDlP0Gh72/x82WrstjuJ74E6JK9L1+vlNGPhw59UvRTLEnJRa86GQrdgp5 rfpwDCW86SlFQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BDFCACE0569; Wed, 15 Jul 2026 17:45:40 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Chuyi Zhou , Ulf Hansson , Muchun Song , Joel Fernandes , Marco Crivellari , "Rafael J. Wysocki" , "Paul E . McKenney" Subject: [PATCH 1/2] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug Date: Wed, 15 Jul 2026 17:45:38 -0700 Message-Id: <20260716004539.13983-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <01070aaf-540c-403b-b589-5185f62eb29a@paulmck-laptop> References: <01070aaf-540c-403b-b589-5185f62eb29a@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chuyi Zhou 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 Reviewed-by: Paul E. McKenney Acked-by: Muchun Song Signed-off-by: Paul E. McKenney --- 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