From nobody Sun May 24 19:34:44 2026 Received: from va-1-115.ptr.blmpb.com (va-1-115.ptr.blmpb.com [209.127.230.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60AF31E5B88 for ; Sat, 23 May 2026 04:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779510459; cv=none; b=aUW0Pam+F9BCV9bEvRPpC5SUQvmwcjwsT0FJ7sTt4rVTnxdP4NYDFCLem9VrXJPr4dNDIizxpBalHPF4SUjN4lop06e6iN0W+BXSIFMr3dnhl0+d9V9ezSb9xDCxC9jlGQhMLxiy9sxunW6s1+eWQcmQAp2bilt9rfGTry7TjoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779510459; c=relaxed/simple; bh=WuPcq9q1JRE05RWLoOoV/hxHVSK24CqTiUQ7EMlAelI=; h=To:From:Mime-Version:Content-Type:Cc:Subject:Date:Message-Id; b=PUMHSeNE/2JRM6GWNTKvS/PLMGrFdXLZnTskhj6tRd4LxoroddbUc7bbJyeS+f4hVIOzAnc6dFR9VNeajVsWmRymttMOfmTM5zpGF4NdIeTZzCQzZCRH9T2YM8E2kqq11Px3x/L5k+9kajvIRKZOxzI7hvfE2o+YnCvW+yh0g0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=GD/m7oC6; arc=none smtp.client-ip=209.127.230.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="GD/m7oC6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1779510452; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=hf+AyvviZG+jq5DO40kB/Vt+3Y9M0R9kpcLEqFWfc5w=; b=GD/m7oC62sFJEh3NNLF82nyycbRRX0cuWOYxRqN9K9PKR0bgyCNCzhkbT0/MQEO/ag7sxL 9SueBJg8F7tbk4MzX5DeM8Smck9jObnu9NZtSKoBxlWtFpkDgiz3m3NUcgDDRj5PRKSIte 7zX2KK5jxxhYVs+uxzfTHvVhKraddUNH7P/As7i0faVu4nvq+VwmjXgFPqlpjPk31GnI0F soUgmAv7tuLZWg+aXTCyquduQC2e7bFOD5hf7aJkFdxbGBaI2MCSywX6FFlO4BMcalhfTZ 6+XnWqv9QKULH28IckLiQIbQ85gx+9IphamUlfWIELKS0rIwt0RjnDXg2fsprA== X-Original-From: Chuyi Zhou To: , , , , , , , From: "Chuyi Zhou" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable Cc: , "Chuyi Zhou" Subject: [RESEND PATCH] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug Date: Sat, 23 May 2026 12:27:03 +0800 Message-Id: <20260523042703.862592-1-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 Content-Type: text/plain; charset="utf-8" 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 diag= nostics") Signed-off-by: Chuyi Zhou Reviewed-by: Paul E. McKenney Acked-by: Muchun Song --- kernel/smp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/smp.c b/kernel/smp.c index a0bb56bd8dda..dc6582bb35d0 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); } --=20 2.20.1