From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 588933DB337 for ; Tue, 25 Aug 2026 08:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787646432; cv=none; b=erPR89AhKSvHgi8EeoRVKXL2siIg5FSjBKLFxnMT0vHu25eW1u3AmIim2aLb9598SOMIWUsEosRurWVkV+g3zbXvxfs8XsMwRllrNS5Cms4PQok2IUlCtISNncaAmTEtovggekNjaE/ucwb68ayEbhfFNJBaFZqqAcS8e1yEtqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787646432; c=relaxed/simple; bh=dyVQW9gRLSLRud2A56oCasKJYXjEIo8Bbt+OQMWXYzA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dPxl7jSql5n3E2HnuA6ELZdFkyAYbKBwiKqB4CGn0UFpo47cr7GGKMyM9HBZ9nrE60bZLELeWRqvaV9U/+N38Tj1vqJjdszD61eNZQK7ZExjKFtTi3PZeuFg2W6V4+voVu14jkiUO9DqfsiB//3fnfuFFLRKbTPCdacbcZ05oxU= 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=EvPB3AGd; arc=none smtp.client-ip=209.85.208.45 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="EvPB3AGd" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-6a0a4aa99bdso7533605a12.1 for ; Tue, 25 Aug 2026 01:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787646429; x=1788251229; 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=WlBe2tCB1TNQh/yTFepa09hxWsDbL5hbhAFU88+P9Z8=; b=EvPB3AGd8zU0bVWoGqAKtmeoAyZUCO/AVVdiJcDCiIwtqJMqanoTn1B0GiBzZl8fJc mMYPPDWPi5fGGaeqCHgxDJT02ChpNpFxc3r5wl1t1oMigXNK4Uu9ohDFiKetCoDNaWwv YUIae+SSzeUwMtnVsWJWi5CPq5QZ4o41tNhYb7BhSV4l0UNvN/Vp4IRWeNxzllI2MD1R 6R1dDkLQp01HbjFL6Q3hzmFXM4iXzf4MSFZM+hoRVFnpWvo1+34KWwOKSw34dCIzomcE 6uHtgQFoux8ZcnS30t1+WKd8EXnLQp+5H/N3h9wAqWU8gmsNcxXiA2h6xPtLOHLVCucK opqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787646429; x=1788251229; 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=WlBe2tCB1TNQh/yTFepa09hxWsDbL5hbhAFU88+P9Z8=; b=tX6fn9dXFq6jhtbjWBSYmXHLP18E/A7wZLu5/KaFASyJVNB1pYG+PmYWScezf9Z4hv 0HAzm70QRWQ7oKYwQxs87P6PU7K1tA/015R82wijLLhzht4lWE4lUvfLhSsv8xdwK73t dni+ZTkP1PXMX4HEhvT+2IJ5rHXePFP/ibXXbWJx9fCnsEQBczD0QjNgvnns5fbWo0TZ LiR+Z+Bc3DpRZ4Nv3gHMgwk6/dniJhuYC8A0MdbUq61O1bBz4XGCfGtvz3lnvtjIOkaM JjGjbSThUHXw8IPt5E2xtQLNM/jgwlxr/79SxOdMosbTywsE+tiC2iWNGdEGGUNXhET2 9Hsg== X-Forwarded-Encrypted: i=1; AHgh+RrGHCr9JLzLSJEIwwHhGWYdZi2Ds8aGLa/bgVrzUXp58xqCJwDTO3JcB6vaOheJ+TGETGEKSt0KLKNTFPk=@vger.kernel.org X-Gm-Message-State: AFuF++m4Ib5hgr9XnVWPtnssJXAWmxPB3k2hDuQqNDZ/0MnX+JftdYoT Vk5Y1Nw+yQNb9inlqen3Tu2jkUbRluCFHZiB+GzjVBtktruenFi6DyvBGUZ5mHwHLEI= X-Gm-Gg: AR+sD13FWDk72Asv/7nSe0nKf5thFwgvI+4ZUzb92GjaSXEgc/F4NigCQ9vrZLcIB6X zyXMB02PjSb8H66YDxE4CWu84tGYbi8EOImgIurMBXxfXe7fujNdf+nFShnmc3g91fOAls0Iola hJWq0JzPVU3+gy+kYZLuaP7TyAycfRS4lW49/Cfg5WegpqrEM2CU/StzwoN4Hp8rB3Q/I6yJ1jC wtCv6cpVw0EgEHIBLN/H/cjRtNF5S302VWIVieRK+iBSKuOd3SIrcwiG3PBotFzzZyR0ck3WQWU EX50DNPa1ogeay3Jyb7rcAxS01tkd36reuYjX/VMZRt+gOek0yk+CNu73OCfNJbshdvaFEWvNKe RPMZ48bPe/glDELyeW8klOsofH/L/mgwxi7N3yCFBDtntsG5DDrkn56iGVoX4/MDnwo51IKZDMd bif2ShS7ZcPMcN2dy1XdgUIviIeWuszty62jWmt6b7FsmDVyCQBDrOPt//zBNUzg== X-Received: by 2002:a05:6402:21d4:b0:69a:928:9405 with SMTP id 4fb4d7f45d1cf-6a582af8853mr24585036a12.1.1787646429584; Tue, 25 Aug 2026 01:27:09 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a59e00108asm18987959a12.2.2026.08.25.01.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 01:27:09 -0700 (PDT) Date: Tue, 25 Aug 2026 10:27:06 +0200 From: Petr Mladek To: Bradley Morgan Cc: Andrew Morton , Jinchao Wang , Feng Tang , Rio , Pnina Feder , Petr Pavlu , Sergey Senozhatsky , linux-kernel@vger.kernel.org, Sashiko , stable@vger.kernel.org Subject: Re: [PATCH v6 1/6] panic: fix redirect CPU race in panic_try_force_cpu() Message-ID: References: <20260818163806.17460-1-include@grrlz.net> <20260818163806.17460-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: <20260818163806.17460-2-include@grrlz.net> On Tue 2026-08-18 16:38:01, 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. > > Update the panic_try_force_cpu() doc comment for the new return value > semantics. > > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -396,16 +397,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_other_cpu(); > > /* > - * Only one CPU can do the redirect. Use atomic cmpxchg to ensure > - * we don't race with another CPU also trying to redirect. > + * Only one CPU can do the redirection. Others should go offline. > + * Continue with panic() when we already tried the redirection > + * from this CPU before, for example via nmi_panic(). > */ > 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 Just for completeness. Sashiko AI points out that the vsnprintf() in panic_try_force_cpu() uses the "args" and they might later be used again when the redirection fails, see https://sashiko.dev/#/patchset/20260818163806.17460-1-include%40grrlz.net This problem is fixed in by the 3rd patch in this patchset, see https://lore.kernel.org/all/20260818163806.17460-4-include@grrlz.net/ So, we are on the safe side. Best Regards, Petr