From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from confino.investici.org (confino.investici.org [93.190.126.19]) (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 08715371CE3 for ; Tue, 7 Jul 2026 18:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.190.126.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783449178; cv=none; b=ssSmxDyvACoswY1bFgkA1mRgH2FdDgnzV08Uq0krbO0LvUhzqwgLjqTdVcJwrldE0z8BaLbLk/A8onx67BcS0BcnlLj+mV5vyvim6bd5XzYCMA4Kdd4RpAwK7GtR1ZiFdcmeUQB2hYpsjcG/n7OSPS0iPgSlwKZINT0bg8mQfPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783449178; c=relaxed/simple; bh=Tr0VRfxk5bfB0LlDV/FKctiC37okDT5FhhiTkGXjxDY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lyuhvbnXu6+NsP8bWkjhLR/bZinwCvdj4ZzMIAgDHdnh8F0qIWQAis9t9gLN6iZhmAjp2tjPSvttkRL7CwtPcEeYO/3bNDAGu2RYDQMYg7GI3LQ/6JjAQWeEhRfUA6OFvFYZpqMfEqDpWEedChMlvENi25GZlz6fk58+wdvbv9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net; spf=pass smtp.mailfrom=grrlz.net; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b=RyYFPgvv; arc=none smtp.client-ip=93.190.126.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grrlz.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b="RyYFPgvv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grrlz.net; s=stigmate; t=1783449174; bh=Lv/Ry2tg9N2mi5mjgeGx3EhV3JSaCLbMgMvUHfxkgOc=; h=From:To:Cc:Subject:Date:From; b=RyYFPgvvTSveBB1iNW2ifkHHojrH/ujC0fE4ZNLIzgPE6AIjKnZlw8lUBaZ4MHQhu g/gBMInfarSf1AB/XA3X4q2ra8MNi3w9gohXkGAHe45UB3E1thE4VBnolvNmrMkKPj W+MeNjuVHFCirHjZ3THugnt26LadfiWSpRaVWb9Q= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4gvqbV0ZGdz10yj; Tue, 07 Jul 2026 18:32:54 +0000 (UTC) Received: by mx1.investici.org (Postfix) id 4gvqbS4WXgz10sW; Tue, 07 Jul 2026 18:32:52 +0000 (UTC) From: Bradley Morgan To: akpm@linux-foundation.org Cc: pmladek@suse.com, feng.tang@linux.alibaba.com, linux-kernel@vger.kernel.org, include@grrlz.net Subject: [PATCH v2] panic: stop CPUs that lose the panic_redirect_cpu race Date: Tue, 7 Jul 2026 18:32:53 +0000 Message-ID: <20260707183253.9793-1-include@grrlz.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Loser of the redirect cmpxchg must stop, not fall through to panic_try_start(). This issue was found by sashiko [1]. [1] https://sashiko.dev/#/patchset/20260705164123.18746-1-include%40grrlz.net Signed-off-by: Bradley Morgan --- kernel/panic.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) Changes since v1: a nested panic on the CPU that already holds panic_redirect_cpu would fail its own cmpxchg and, with v1's unconditional return true, halt itself and abandon the panic. Check old_cpu == this_cpu so the winner of a nested reentry falls through to panic_try_start() instead. diff --git a/kernel/panic.c b/kernel/panic.c index 03f1eef07b17..e46c37b39c40 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -400,12 +400,9 @@ static bool panic_try_force_cpu(const char *fmt, va_list args) if (panic_in_progress()) return false; - /* - * Only one CPU can do the redirect. Use atomic cmpxchg to ensure - * we don't race with another CPU also trying to redirect. - */ + /* Which CPU won the race? */ if (!atomic_try_cmpxchg(&panic_redirect_cpu, &old_cpu, this_cpu)) - return false; + return old_cpu != this_cpu; /* * Use dynamically allocated buffer if available, otherwise -- 2.53.0