From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 099F7176FB1 for ; Fri, 17 Jul 2026 15:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784301784; cv=none; b=QReHh8PRRmk467T3wZwejIpZ0H4/0Vlxic8PR362HcpZEmtHqlYFuGWbDuYkhhdL5l9kQCkZuTfOy3+Zovrmfs3o3WgaiUDYfTa6IfNyMIw17XBe8TTuKH9W9VHKdW8EwkRjoDooMvcBZjZlLM72RMqbpl3YcLY9Z18IOG7A/F8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784301784; c=relaxed/simple; bh=ldjiXEKTQB7Gnt4Gp/QNlr4hMf+izOX8e/wBRi+CE1s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BQqRPlljtz6SIR/KJHvlc1QxefI3NT79h/cJ7Fii+r1MvsgY5vh1h1tfnX9gSnQ8hx23Ffz63GI1g0mPC4VF6/4ttllB/FiI6dR0Xb1Tt+E7eZEqfSnM1HeJ6ENhC/vpjXKeBubKutucZjO8mp3n+jltZdOFxVoHU3gQp2fwj64= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=V8JHsU7G; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="V8JHsU7G" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-47f59f25ec4so626806f8f.2 for ; Fri, 17 Jul 2026 08:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784301781; x=1784906581; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=xXzFJhhAu0paPqZvnx7kZReavfriCzThkXWJX/+JEuw=; b=V8JHsU7GenMwtIeikSU8WBBNxJz45Y7gQHGvUDLyyp+cQ1sO+7vBQPUYnTyB5f1/yg SNKILmkQyRVhcsymMxC9fBAqxWflK2fvfPkzjaoV9iDspLkbVHl0lp6h9sOQ4aPRYcGe juF8IHNRJyLI/5cOpYP7dA+c4irD75gcWY+fpG5AgzI2pzwgJ6lsQrFJ2uYB8kr7u3aU 0OY+Em0pbFDIkjj5gcMBJibkRoazD9cZRHTIf/Ac0vEBDxOaFJVJywYsAkrVVDIZ50v1 GuankfZFg7yRti3rnf2gR0BPBlKH963UO6V6d64MqNTFF2EUlp3UCkvl42+BYT30DCwy qqJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784301781; x=1784906581; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xXzFJhhAu0paPqZvnx7kZReavfriCzThkXWJX/+JEuw=; b=SkjES7XEwMD2EtYEqFtauEWA4yRI9/JL1/nxz7zw/bLrUV/kssRzHHjZ4S2zR94/lg /bFvwMyTWsv74lX1r4l+YaauCuHHs9h9fMHQ1dGYtiuESggAMx5JHQJT1zBTP0uFtaif 01jEnu16JTKOlb7rIBfNTixhkxeoIge4S0MH273YDeRQkkxkaY7PODE6WgZnnlaAkZnd k9QXRDLqVAkqdWoc1tr6Zbj2U7ImD8OMWeHh2B5uk/chJDdQFW3Tpabmk/mnHdRLx4yy 0JvNH8Y0UF60Q3I6sNUjCNPEX47+6STWsxtyQ9SJR5qQqWxTJZTbZDBxrAYEOWOCmOtC sHow== X-Forwarded-Encrypted: i=1; AHgh+RoxSFP7nBRZ1G6gU14b4jszzqlcZtgUZOotJlIEdNwsDDsDKcLcnmvroMlrq5bTitcL3/l82yhGIiCFgBs=@vger.kernel.org X-Gm-Message-State: AOJu0YzTdXYfYcvuZ+Mu0ChPGpuWtQLA3oOrQ36LsHUZY6n+eOLGAcmZ eQ0H9gg+6L1Kl0DgRt/WnynjG0YDy90xseKx0e/RvlDExck2d2/5lyTS0NoQ+hWnwyI= X-Gm-Gg: AfdE7cnaHye4u2FelXlMYh2OH7/0MN67A95tSv3SJpxteNnXr9Qr2Z3o3mwZGSEOO3h B1oJ1OJ1fXwOirIEhtZfk+kdateodClsdDbY/FjvC/BxkxfaROKVaE8e8XzX5Y4fxjVzUnFxNKq 2z61LSJqzUerZ7U0N4O4TAHXe8K+oxbR81iSEpKyM1pSxImuRTb+hVCdf58XQ8kPpkA/OlRA2Mv YMtRnahCpPV9hRym0LK78o97ZRYanvalmy9J2E/DpwaP4nRKGTRxucu2Pi11gYMG9MLEND+ZBlo 5o3qgGv9sIHaoCDWCa5DzJF5i8bEWr7hIrWfmGF4GkVzHIotlRk9FxFfRg87CFFOAXJBYNyOvIZ 3qg5RK/9PSjobOL0puis4a6Qk7dMtoqB+wokoujFK56zcRlOZ2My+3lSmM7lmc/vCpuUwvLfOVy XebD9Jklo8ihBxOzc= X-Received: by 2002:a05:6000:40cd:b0:47f:5378:b6e1 with SMTP id ffacd0b85a97d-47f62318bacmr4030157f8f.30.1784301781221; Fri, 17 Jul 2026 08:23:01 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f63e52aa4sm4897943f8f.10.2026.07.17.08.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 08:23:01 -0700 (PDT) Date: Fri, 17 Jul 2026 17:22:59 +0200 From: Petr Mladek To: Bradley Morgan Cc: akpm@linux-foundation.org, feng.tang@linux.alibaba.com, sashiko-bot@kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/3] panic: fix redirect CPU race in panic_try_force_cpu() Message-ID: References: <20260714173103.11585-1-include@grrlz.net> <20260714173103.11585-2-include@grrlz.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260714173103.11585-2-include@grrlz.net> On Tue 2026-07-14 17:31:00, Bradley Morgan wrote: > The cmpxchg() in panic_try_force_cpu() makes sure that only one CPU > tries to redirect panic() to the requested CPU. It is similar to the > cmpxchg() in panic_try_start() which makes sure that only one CPU does > the panic(). In both situations, only the winner of cmpxchg() should > proceed further. Other CPUs should go offline. > > There is a bug because the cmpxchg loser returns false and falls through > into vpanic(). Two non-target CPUs A and B panic, the requested CPU is C: > > cpu A cpu B > ---------- ---------- > panic() panic() > vpanic() vpanic() > panic_try_force_cpu() panic_try_force_cpu() > cmpxchg wins cmpxchg fails > redirect = A old_cpu = A > IPI -> C return false <- BUG > return true panic_try_start() wins > panic_smp_self_stop() __crash_kexec() on B > (A stops) (target C bypassed) > > The loser must stop, not fall through. It cannot just return true, > though. A CPU that already won the redirect cmpxchg can reenter > panic_try_force_cpu() on the same CPU, for example a nested NMI during > the message formatting, before the IPI is sent: > > cpu A (1st) cpu A (nested) > ---------- ---------- > panic() > vpanic() > panic_try_force_cpu() > cmpxchg wins (redirect = A) > vsnprintf(msg) ... > <-- NMI, nested panic --> > panic() > vpanic() > panic_try_force_cpu() > cmpxchg fails > old_cpu == A (this CPU) > return true <- would halt > panic_smp_self_stop() > (IPI never sent, panic abandoned) > > Check old_cpu against this_cpu so a second call from the same CPU > returns false and falls through to panic_try_start() instead. > > Also fix the panic_in_progress() check. We must not redirect when > panic_cpu is already assigned. Return true to stop when the panic is on > another CPU, false to proceed when it is this one. > > Reported-by: Sashiko > Closes: https://sashiko.dev/#/patchset/20260705164123.18746-1-include@grrlz.net > Closes: https://sashiko.dev/#/patchset/20260707172252.4842-1-include@grrlz.net > Cc: stable@vger.kernel.org > Signed-off-by: Bradley Morgan > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -396,16 +396,20 @@ static bool panic_try_force_cpu(const char *fmt, va_list args) > return false; > } > > - /* Another panic already in progress */ > + /* > + * Don't redirect when a panic is already in progress. Stop this > + * CPU when it's another one, proceed when it's this one. > + */ > if (panic_in_progress()) > - return false; > + return !panic_on_this_cpu(); Nit: I would use return panic_on_other_cpu(); It is more straightforward. The negative logic just added an extra step for understanding the code. Otherwise, it looks good to me. With the proposed change: Reviewed-by: Petr Mladek Best Regards, Petr