From: "Cédric Le Goater" <clg@kaod.org>
To: Shrikanth Hegde <sshegde@linux.ibm.com>,
Gou Hao <gouhao@uniontech.com>,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
chleroy@kernel.org, namcao@linutronix.de, peterz@infradead.org,
kees@kernel.org, lgs201920130244@gmail.com, srikar@linux.ibm.com,
ynorov@nvidia.com, nilay@linux.ibm.com, benh@kernel.crashing.org,
miltonm@bga.com, mkchauras@gmail.com, akpm@linux-foundation.org
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
gouhaojake@163.com, kernel@uniontech.com
Subject: Re: [PATCH v3 1/5] powerpc/xive: make xive IPI allocation NULL-safe
Date: Thu, 30 Jul 2026 16:06:02 +0200 [thread overview]
Message-ID: <5dd79d09-d064-4bbe-9a97-215968252b83@kaod.org> (raw)
In-Reply-To: <ff80d246-1bc6-4092-861c-9169d0fc599b@linux.ibm.com>
On 7/30/26 15:53, Shrikanth Hegde wrote:
>
>
> On 7/27/26 4:12 PM, Gou Hao wrote:
>> __GFP_NOFAIL should not be used in new code [1]. xive_init_ipis()
>> allocates the xive_ipis array with __GFP_NOFAIL, which makes the
>> subsequent NULL check unreachable dead code.
>>
>> Remove __GFP_NOFAIL so the allocation can fail, and make all xive_ipis
>> access paths NULL-safe:
>>
>> - Return XIVE_BAD_IRQ from xive_ipi_cpu_to_irq() when xive_ipis is NULL.
>> - Set xive_ipis to NULL after kfree() in the error path to prevent
>> use-after-free.
>> - Guard xive_setup_cpu_ipi() and xive_cleanup_cpu_ipi() against
>> xive_ipi_irq == XIVE_BAD_IRQ to avoid dereferencing an uninitialized
>> or already-freed xive_ipis array.
>
> I would rather prefer a BUG_ON if the allocation fails. That keeps the earlier
> semantic.
>
> - If xive fails, then who will send the interrupts?. It is better to crash instead
> of leaving the system in weird state.
Then do like XICS, which has BUG_ON(). I don't know why we took this
direction when XIVE was first introduced.
C.
>>
>> No functional change when allocation succeeds.
>
> Please don't put a statement like this.
> It should be either no functional changes or function changes.
>
>>
>> Link: https://lore.kernel.org/all/20260725202632.dcb325658896a470df91cf57@linux-foundation.org/ [1]
>> Fixes: 7dcc37b3eff9 ("powerpc/xive: Map one IPI interrupt per node")
>> Signed-off-by: Gou Hao <gouhao@uniontech.com>
>> Reviewed-by: Wentao Guan <guanwentao@uniontech.com>
>> Reviewed-by: jiazhenyuan <jiazhenyuan@uniontech.com>
>> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
>> Suggested-by: Cédric Le Goater <clg@kaod.org>
>> Suggested-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
>> Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
>> Reviewed-by: Cédric Le Goater <clg@kaod.org>
>> Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
>> ---
>> arch/powerpc/sysdev/xive/common.c | 12 ++++++++++--
>> 1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
>> index dadd1f46ec93..86c78af1f68e 100644
>> --- a/arch/powerpc/sysdev/xive/common.c
>> +++ b/arch/powerpc/sysdev/xive/common.c
>> @@ -74,6 +74,8 @@ static struct xive_ipi_desc {
>> */
>> static unsigned int xive_ipi_cpu_to_irq(unsigned int cpu)
>> {
>> + if (!xive_ipis)
>> + return XIVE_BAD_IRQ;
>> return xive_ipis[early_cpu_to_node(cpu)].irq;
>> }
>> #endif
>> @@ -1132,8 +1134,7 @@ static int __init xive_init_ipis(void)
>> if (!ipi_domain)
>> goto out_free_fwnode;
>> - xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids,
>> - GFP_KERNEL | __GFP_NOFAIL);
>> + xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids, GFP_KERNEL);
>> if (!xive_ipis)
>> goto out_free_domain;
>> @@ -1158,6 +1159,7 @@ static int __init xive_init_ipis(void)
>> out_free_xive_ipis:
>> kfree(xive_ipis);
>> + xive_ipis = NULL;
>> out_free_domain:
>> irq_domain_remove(ipi_domain);
>> out_free_fwnode:
>> @@ -1190,6 +1192,9 @@ static int xive_setup_cpu_ipi(unsigned int cpu)
>> pr_debug("Setting up IPI for CPU %d\n", cpu);
>> + if (xive_ipi_irq == XIVE_BAD_IRQ)
>> + return -EIO;
>> +
>> xc = per_cpu(xive_cpu, cpu);
>> /* Check if we are already setup */
>> @@ -1234,6 +1239,9 @@ noinstr static void xive_cleanup_cpu_ipi(unsigned int cpu, struct xive_cpu *xc)
>> /* Disable the IPI and free the IRQ data */
>> + if (xive_ipi_irq == XIVE_BAD_IRQ)
>> + return;
>> +
>> /* Already cleaned up ? */
>> if (xc->hw_ipi == XIVE_BAD_IRQ)
>> return;
>
next prev parent reply other threads:[~2026-07-30 14:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 10:42 [PATCH v3 0/5] powerpc/xive: remove __GFP_NOFAIL and fix IPI error handling Gou Hao
2026-07-27 10:42 ` [PATCH v3 1/5] powerpc/xive: make xive IPI allocation NULL-safe Gou Hao
2026-07-30 13:53 ` Shrikanth Hegde
2026-07-30 14:06 ` Cédric Le Goater [this message]
2026-07-30 17:50 ` Shrikanth Hegde
2026-07-27 10:42 ` [PATCH v3 2/5] powerpc/xive: add error return value to xive_smp_probe() Gou Hao
2026-07-29 17:33 ` Cédric Le Goater
2026-07-27 10:42 ` [PATCH v3 3/5] powerpc/xive: propagate IPI init errors to prevent use-after-free Gou Hao
2026-07-28 2:47 ` Srikar Dronamraju
2026-07-28 10:26 ` Gou Hao
2026-07-29 17:37 ` Cédric Le Goater
2026-07-29 17:34 ` Cédric Le Goater
2026-07-27 10:42 ` [PATCH v3 4/5] powerpc/xive: defer setting cause_ipi until IPI init succeeds Gou Hao
2026-07-29 17:34 ` Cédric Le Goater
2026-07-27 10:42 ` [PATCH v3 5/5] powerpc/smp: add NULL guard for cause_ipi in smp_muxed_ipi_message_pass Gou Hao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5dd79d09-d064-4bbe-9a97-215968252b83@kaod.org \
--to=clg@kaod.org \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=chleroy@kernel.org \
--cc=gouhao@uniontech.com \
--cc=gouhaojake@163.com \
--cc=kees@kernel.org \
--cc=kernel@uniontech.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=miltonm@bga.com \
--cc=mkchauras@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=namcao@linutronix.de \
--cc=nilay@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=srikar@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
--cc=ynorov@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox