From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 782D731F9BA for ; Wed, 8 Jul 2026 04:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783484896; cv=none; b=eIT5EyDqoMezEQPsFbaGWRcIFfx4rK/LewFOtPp9sV8SxIkxS7sJQ34DgbGKyBCUYWY5VQtoC4VITIkVP1KwK8nmtpOeuXIy+RcRoYQtQL5PUoCb2O2K9supbYxjJVs3GhiKf0iKLXPSVtEFuKL94SQnTckgE82vvj+NavAXifI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783484896; c=relaxed/simple; bh=yJzd42/gqzZwyMJjvTXBgOd+qc5ozykoK35Dv1iljvk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uA1nnjz0n1TlBtS9794BZmp9HR2k8mET+8z0x6f/OF7K5ecvULr27tAb5ta9HQP+4pQBmt/gJLe/ORY+VpMo0E5BdNEVrEvbG3b6rxg9sue3jhDbylVq2JPfbVMqHBgPAYGxSeGGO2zBPSOb9GvjmWdEjW4mWWK0THZXse3U42o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=U6t1eSDW; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="U6t1eSDW" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 667MmcAm920904; Wed, 8 Jul 2026 04:27:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=uGUGL/ POIVv0M3ZtnYCAYH4seGHdEF7PBlI+l8AKKrc=; b=U6t1eSDWFIyvBMY4WzKlMj 2oSG2JoA12HXwp6I9T4NLXikELXHaF4fpQlX0cucQdit+Nh7Bv8ftRslcvs/xGSp nZBusyOIrRLTBdRXfY4/T0zBpVp2+7se2f3OISfRYfmeiXuZuS9t0pR/Z3ZBczPd npIFSW27xBmpCWJUbRzMHTp9bkqdXrFICDMnNYMKxzd8j7H3K11fNOqZxNMGJE4J zS1hlNf04FtsuY3uZgHR5zPF5C5xsC/bCp+t+3vsoArd7mDSxAwy9hLKkgXJLAaR T75lYURSEMgY/qPF2yr25ahnzJcMoI8PKp5C4LaRVyh/itmhS0XlLlRaKlqeZQ+Q == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4f6sp3tmc7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2026 04:27:53 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6684JenT013074; Wed, 8 Jul 2026 04:27:52 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4f7f6y5k4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2026 04:27:52 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6684RmvR60424526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Jul 2026 04:27:48 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FF3D2004B; Wed, 8 Jul 2026 04:27:48 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E70C20040; Wed, 8 Jul 2026 04:27:46 +0000 (GMT) Received: from [9.39.26.208] (unknown [9.39.26.208]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Jul 2026 04:27:45 +0000 (GMT) Message-ID: <880eba74-6427-4fa3-941d-b67bbf98f3a4@linux.ibm.com> Date: Wed, 8 Jul 2026 09:57:44 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] powerpc/970: fix nap return address corruption on async interrupt exit To: "Mukesh Kumar Chaurasiya (IBM)" , maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, mchauras@linux.ibm.com, ruanjinjie@huawei.com, thuth@redhat.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Andreas Schwab References: <20260707172430.790040-1-mkchauras@gmail.com> From: Shrikanth Hegde Content-Language: en-US In-Reply-To: <20260707172430.790040-1-mkchauras@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF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lJ3X10kY1 fcq5tDWdz0Mnv7GYVoQ== X-Proofpoint-ORIG-GUID: LHpkbLgZtJzIDFZpAeZME05uGlBh69b2 X-Proofpoint-GUID: tqt656R1iEPo82XJFwvErZEAAfG5ek_o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-07_06,2026-07-06_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607080038 Hi Mukesh. On 7/7/26 10:54 PM, 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) > --- > arch/powerpc/include/asm/entry-common.h | 15 +++++++-------- > arch/powerpc/include/asm/interrupt.h | 1 + > 2 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h > index fc636c42e89a..c5adb5006361 100644 > --- a/arch/powerpc/include/asm/entry-common.h > +++ b/arch/powerpc/include/asm/entry-common.h > @@ -66,6 +66,13 @@ static inline void srr_regs_clobbered(void) > static inline void nap_adjust_return(struct pt_regs *regs) > { > #ifdef CONFIG_PPC_970_NAP > + /* > + * Adjust the nap return address before irq_exit_rcu(). irq_exit_rcu() > + * may invoke softirqs with interrupts re-enabled, allowing a nested > + * async interrupt to arrive. If _TLF_NAPPING is still set at that > + * point, the nested interrupt would erroneously redirect its own > + * return address to power4_idle_nap_return, corrupting the stack. > + */ > if (unlikely(test_thread_local_flags(_TLF_NAPPING))) { > /* Can avoid a test-and-clear because NMIs do not call this */ > clear_thread_local_flags(_TLF_NAPPING); > @@ -286,14 +293,6 @@ static inline void arch_interrupt_async_enter_prepare(struct pt_regs *regs) > > static inline void arch_interrupt_async_exit_prepare(struct pt_regs *regs) > { > - /* > - * Adjust at exit so the main handler sees the true NIA. This must > - * come before irq_exit() because irq_exit can enable interrupts, and > - * if another interrupt is taken before nap_adjust_return has run > - * here, then that interrupt would return directly to idle nap return. > - */ > - nap_adjust_return(regs); > - > arch_interrupt_exit_prepare(regs); > } This makes arch_interrupt_async_exit_prepare same as arch_interrupt_exit_prepare. Maybe remove arch_interrupt_async_exit_prepare? > > diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h > index fb42a664ae54..1b45a49e9bed 100644 > --- a/arch/powerpc/include/asm/interrupt.h > +++ b/arch/powerpc/include/asm/interrupt.h > @@ -246,6 +246,7 @@ interrupt_handler void func(struct pt_regs *regs) \ > instrumentation_begin(); \ > irq_enter_rcu(); \ > ____##func (regs); \ > + nap_adjust_return(regs); \ > irq_exit_rcu(); \ > instrumentation_end(); \ > arch_interrupt_async_exit_prepare(regs); \