From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 453CF36F8F1 for ; Thu, 16 Jul 2026 16:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784219664; cv=none; b=MHVgEoB/zqEdZFlWcasF3k1ILJLOE28Lu/Bv2oaD8y8+plW1Kh2lhSR5z8nPjB4cLJ13xV3EsS7yVZ7IDKdwLS2M0rj2eLdeX5FToHM4oPDHTQ6Z6PiSVr7JZDX5hAqpP0dsj0mNqCyi+7LNpNd2OnwI8DGdpyOpW067li2P6lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784219664; c=relaxed/simple; bh=BskcRHxjvBDwQ+eHUbSALgQqTBN5lr7S7C5nRZjfGnw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=UsTCd2JI7jSnHEC6sPVvAhHFRP4uPQkEuL3Hq2N+oe7qqGKaMr6S/yIDOu7uphQ2X6hYStR1S2EcPZ0rVcuewvvgWXuSEPDQa8daWJTmB8MG5MEQcql4Jk+naht4AeeYpbkknzoqWDX1yoW5TIVD7V83svTCs06RMFpaVcp+3ys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=T9Gua9OZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ag72+Rsg; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="T9Gua9OZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ag72+Rsg" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1784219654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hRIlkUFNXSnVjl7nU+5tayy/Q9Hmh7cE9CUYAHl6yoU=; b=T9Gua9OZZYS3jIf2+UWaoK9o0KgnknLUNYZjXTizXrKaJ1WlBGIvL1pro3nTM2BH1H4pvJ eqnUq1BFMgoUssbmK5Y6szfQ67xK2PPrvv+UBhzSXOaGqGsl2rSw7KVo0AeqH5P/fRLc5E 0ctxEpKQd4F1+fOKZWe3s+eeaGJDUO6Ooqp4RdK1rkHZC5Je96URx7QHPKqH35wK9O07sI Cz61oTrL71Jw17vEQJwa37H/W/RW5FR7vedKNn80XcS1Dop9Rgcns4yTw/5PNc9XtKkZyo qcEUZLUxnoAhVPMK1yQk7f2bftEllybJ5uNLY0EOdMSlugUFUmp+SdW7SedOWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1784219654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hRIlkUFNXSnVjl7nU+5tayy/Q9Hmh7cE9CUYAHl6yoU=; b=ag72+Rsg+CTxnC0Xc6VdHmqDhZS8KPz3VORx9pohNemeldpQz8j3jZCDorYby2oXR/Ojqp SIhDRpwP7BELVwAQ== To: "Mukesh Kumar Chaurasiya (IBM)" , maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, sshegde@linux.ibm.com, mchauras@linux.ibm.com, mkchauras@gmail.com, ruanjinjie@huawei.com, thuth@redhat.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Andreas Schwab Subject: Re: [PATCH] powerpc/970: fix nap return address corruption on async interrupt exit In-Reply-To: <20260707172430.790040-1-mkchauras@gmail.com> References: <20260707172430.790040-1-mkchauras@gmail.com> Date: Thu, 16 Jul 2026 18:40:13 +0206 Message-ID: <87fr1iq4fu.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2026-07-07, "Mukesh Kumar Chaurasiya (IBM)" wrote: > On PowerMac G5 (PPC970, CONFIG_PPC_970_NAP) the system panics shortly > after boot with symptoms including instruction fetch faults, kernel data > access faults, and stack corruption, predominantly on SMP and always > somewhere inside softirq processing. > > The PPC970 idle path works by setting _TLF_NAPPING in the current > thread's local flags before entering the MSR_POW nap loop. When any > async interrupt wakes the CPU, nap_adjust_return() is expected to detect > _TLF_NAPPING, clear it, and rewrite regs->NIP to power4_idle_nap_return > so that the interrupt returns cleanly to the caller of power4_idle_nap() > rather than back into the nap spin loop. > > DEFINE_INTERRUPT_HANDLER_ASYNC generates the following sequence: > > irq_enter_rcu(); > ____func(regs); /* timer_interrupt / do_IRQ body */ > irq_exit_rcu(); /* softirqs run here, irqs re-enabled */ > arch_interrupt_async_exit_prepare(regs); /* nap_adjust_return was here */ > irqentry_exit(regs, state); > > irq_exit_rcu() calls invoke_softirq() -> do_softirq_own_stack(), which > runs softirqs with hardware interrupts re-enabled. A nested async > interrupt can therefore arrive while _TLF_NAPPING is still set. That > nested interrupt reaches nap_adjust_return() in its own > arch_interrupt_async_exit_prepare() call, finds _TLF_NAPPING set, and > redirects *its own* regs->NIP to power4_idle_nap_return. Returning via > that blr with an unrelated LR on the softirq stack jumps to a garbage > address, causing the observed crashes. > > The comment that previously lived in arch_interrupt_async_exit_prepare() > even described this exact hazard ("must come before irq_exit()"), but > nap_adjust_return() was placed after irq_exit_rcu() in the macro, so > the protection was never effective. > > Fix this by calling nap_adjust_return() inside DEFINE_INTERRUPT_HANDLER_ASYNC > immediately before irq_exit_rcu(), ensuring _TLF_NAPPING is cleared and > regs->NIP is adjusted before any code that can re-enable interrupts or > invoke softirqs runs. Move the explanatory comment into > nap_adjust_return() itself and remove it from arch_interrupt_async_exit_prepare(). > > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature") > Closes: https://lore.kernel.org/all/87wlvazrdy.fsf@igel.home/ > Reported-by: Andreas Schwab > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) Tested-by: John Ogness Would be nice to see this in 7.2-rc4