From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (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 1DCDC1A8F97 for ; Mon, 8 Jun 2026 11:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780917917; cv=none; b=gSGBKoLJbxoP8PyEt7tHFxQdfeeP68DqUafp3kgXjVmClyqrevQmqHYoPV+4hpdzKo0KVNdUBsbBjQxGQBG5KulkP9KVrBnznvg+23/84HYFUI7kMSJ3qeMayQrKtve63dt5wCA5D6fkgpc8XNXRljwfo0M2NIuKaI9yMb0FCRs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780917917; c=relaxed/simple; bh=/xHvIW7FFltaIBo3a2H4VLbW7akKFqJI/9e2980Ua/k=; h=Cc:From:Date:Message-Id:To:Subject:In-Reply-To:References: Mime-Version:Content-Type; b=nSQOCis60lMcP8PuhwgzKx8LqXUYSeIjcCLY+sPNtRajvvoQU3JlBOTbaqBLF5OLnjZ8yboB4c4a2G2uQicsb2BIlPe56UJ873W6IdwP7CGOJbcn+Ckmz91RIwUDbtV37dZyt1Iedfo0kB2q/Ct3yZamLAidpmcPl55FJbZ5hTM= 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=VO5InFLg; arc=none smtp.client-ip=209.127.230.111 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="VO5InFLg" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780917905; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=IPtaVrzKM+ewoB3wkBduXNiC3EZPHQcOkti8Q6Xs/t0=; b=VO5InFLg2UqBydUQlxnsgco4hIKWHmDgekTYwqtuJ+sNS8MnB6JmkpMUeh4hXmLNhjr/aV 7X7St7XWgQ1BB18tg/bYpJInsoBhd2Z+XS+l+FmQVRvTKW2SGHa8oVg+ZUAPhLZ3i0sLwP yHlNIIXvYJowEaOSTHgMWe2UzalA/TTqYHxeKm7q6xdnwU9FcBQDHu3+7Llc1qs7xQtyCU WU4690ysyBx3raJ/htUxL5JaG5eO8GVLzVTDXZ1fQB30CW1Ti8hCsdbkA/B03AIYbJ0Poa FOwHwtpyBPUrUB/UBcXVO11zVwAkveoFb0dAMmepHM0shfwciv2DbcM5vVfI4w== Cc: , "Chuyi Zhou" From: "Chuyi Zhou" Date: Mon, 8 Jun 2026 19:23:48 +0800 Message-Id: <20260608112349.3955175-2-zhouchuyi@bytedance.com> X-Lms-Return-Path: To: , , , , , Subject: [PATCH 1/2] smp: Avoid invalid per-CPU CSD lookup with CSD lock debug In-Reply-To: <20260608112349.3955175-1-zhouchuyi@bytedance.com> References: <20260608112349.3955175-1-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou Content-Transfer-Encoding: 7bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 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 diagnostics") 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); } -- 2.20.1