From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Romain Caritey <Romain.Caritey@microchip.com>,
Baptiste Le Duc <baptiste.le-duc@vates.tech>,
Alistair Francis <alistair.francis@wdc.com>,
Connor Davis <connojdavis@gmail.com>,
"Daniel P. Smith" <dpsmith@apertussolutions.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v6 18/23] xen/riscv: implement IRQ routing for device passthrough
Date: Wed, 29 Jul 2026 13:59:04 +0200 [thread overview]
Message-ID: <6cebc63c-2f21-4ef8-ab10-e2ec62f887b7@gmail.com> (raw)
In-Reply-To: <c64fc958-73bb-44ed-a3b2-dc368ce675ac@suse.com>
On 7/23/26 3:30 PM, Jan Beulich wrote:
> On 20.07.2026 17:59, Oleksii Kurochko wrote:
>> +/* Route an IRQ to a specific guest */
>> +int route_irq_to_guest(struct domain *d, unsigned int virq,
>> + unsigned int irq, const char *devname)
>> +{
>> + struct irqaction *action;
>> + struct irq_guest *info;
>> + struct irq_desc *desc;
>> + unsigned long flags;
>> + int retval = 0;
>> +
>> + if ( d->is_dying )
>> + return -EINVAL;
>> +
>> + desc = irq_to_desc(irq);
>> +
>> + /*
>> + * release_irq() frees this action via xvfree(), relying on action
>> + * being the first member of struct irq_guest so that &info->action
>> + * coincides with info itself. Guard the layout so a future field
>> + * reorder can't silently turn that into a free() of a mid-allocation
>> + * pointer.
>> + */
>> + BUILD_BUG_ON(offsetof(struct irq_guest, action) != 0);
>
> Can't release_irq() simply use container_of()? One way or another it feels
> like you're painting yourself into a particular corner ...
If it isn't the best option then it is needed to follow they way we had
before:
-/*
- * Describe an IRQ assigned to a guest.
- *
- * The irqaction is embedded here (rather than allocated separately with
- * its dev_id pointing at a standalone struct irq_guest) so that freeing
- * the action in release_irq() also frees this whole structure in one go.
- * That avoids the alternative of release_irq()'s caller having to free
- * dev_id itself (something like in Arm release_guest_irq()).
- */
+/* Describe an IRQ assigned to a guest */
struct irq_guest
{
- struct irqaction action;
struct domain *d;
unsigned int virq;
};
@@ -263,7 +254,6 @@ static struct irq_guest *irq_get_guest_info(struct
irq_desc *desc)
return desc->action->dev_id;
}
-
void release_irq(unsigned int irq, const void *dev_id)
{
struct irq_desc *desc;
@@ -361,6 +351,7 @@ int release_guest_irq(struct domain *d, unsigned int
virq)
spin_unlock_irqrestore(&desc->lock, flags);
release_irq(desc->irq, info);
+ xvfree(info);
return 0;
@@ -384,23 +375,20 @@ int route_irq_to_guest(struct domain *d, unsigned
int virq,
desc = irq_to_desc(irq);
- /*
- * release_irq() frees this action via xvfree(), relying on action
- * being the first member of struct irq_guest so that &info->action
- * coincides with info itself. Guard the layout so a future field
- * reorder can't silently turn that into a free() of a mid-allocation
- * pointer.
- */
- BUILD_BUG_ON(offsetof(struct irq_guest, action) != 0);
+ action = xvmalloc(struct irqaction);
+ if ( !action )
+ return -ENOMEM;
info = xvmalloc(struct irq_guest);
if ( !info )
+ {
+ xvfree(action);
return -ENOMEM;
+ }
info->d = d;
info->virq = virq;
- action = &info->action;
action->dev_id = info;
action->name = devname;
action->free_on_release = true;
@@ -454,13 +442,15 @@ int route_irq_to_guest(struct domain *d, unsigned
int virq,
if ( retval )
{
release_irq(desc->irq, info);
- return retval;
+ goto free_info;
}
return 0;
out:
spin_unlock_irqrestore(&desc->lock, flags);
+ xvfree(action);
+ free_info:
xvfree(info);
return retval;
I see an an item in changelog which meniotned that:
```
Drop xfree(info) from release_guest_irq() to avoid a potential
dangling-pointer issue with the ->dev_id field. Now that
struct irqaction action;' is embedded into 'struct irq_guest',
'info' will be freed as part of release_irq() at the end.
```
But it seems I don't see now why it will be dangled-pointer here as
info is referenced by exactly one pointer, action->dev_id, and nothing
caches it: the only reader, irq_get_guest_info(), dereferences
desc->action->dev_id under desc->lock and doesn't outlive the critical
section. xvfree(info) only ever runs after release_irq() has unlinked
the action from desc->action under the lock and waited for
_IRQ_INPROGRESS to clear, so by then no CPU can reach ->dev_id. A
concurrent release_guest_irq() for the same IRQ is excluded by clearing
_IRQ_GUEST under desc->lock, and live unrouting of a running domain is
rejected with -EBUSY. In the error paths, out: frees an action
_setup_irq() never installed, and the intc_route_irq_to_guest() failure
path calls release_irq() before freeing info.
So it seems like it is safe to use what we had in v4.
Any concerns?
~ Oleksii
next prev parent reply other threads:[~2026-07-29 11:59 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 15:59 [PATCH v6 00/23] Introduce enablemenant of dom0less Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 01/23] xen: introduce CONFIG_HAS_SHARED_INFO for archs without a shared page Oleksii Kurochko
2026-07-21 14:50 ` Jan Beulich
2026-07-28 15:29 ` Oleksii Kurochko
2026-07-28 15:40 ` Jan Beulich
2026-07-20 15:59 ` [PATCH v6 02/23] xen/dom0less: turn max_init_domid into a common variable Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 03/23] xen: arm: update p2m_set_allocation() prototype Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 04/23] xen/riscv: Implement ARCH_PAGING_MEMPOOL Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 05/23] xen/riscv: Implement construct_domain() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 06/23] xen/riscv: introduce guest riscv,isa string Oleksii Kurochko
2026-07-22 7:25 ` Jan Beulich
2026-07-28 15:47 ` Oleksii Kurochko
2026-07-28 15:53 ` Jan Beulich
2026-07-20 15:59 ` [PATCH v6 07/23] xen/riscv: implement make_cpus_node() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 08/23] xen/riscv: implement make_timer_node() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 09/23] xen/riscv: implement make_arch_nodes() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 10/23] xen/riscv: introduce init interrupt controller operations Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 11/23] xen/riscv: implement make_intc_domU_node() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 12/23] xen/riscv: introduce aia_init() and aia_usable() Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 13/23] xen/riscv: introduce per-vCPU IMSIC state Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 14/23] xen/riscv: introduce minimal virtual APLIC (vAPLIC) infrastructure Oleksii Kurochko
2026-07-22 7:40 ` Jan Beulich
2026-07-29 10:41 ` Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 15/23] xen/riscv: introduce (de)initialization helpers for vINTC Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 16/23] xen/riscv: generate IMSIC DT node for guest domains Oleksii Kurochko
2026-07-22 7:43 ` Jan Beulich
2026-07-20 15:59 ` [PATCH v6 17/23] xen/riscv: create APLIC " Oleksii Kurochko
2026-07-23 13:08 ` Jan Beulich
2026-07-29 11:02 ` Oleksii Kurochko
2026-07-20 15:59 ` [PATCH v6 18/23] xen/riscv: implement IRQ routing for device passthrough Oleksii Kurochko
2026-07-23 13:30 ` Jan Beulich
2026-07-29 11:59 ` Oleksii Kurochko [this message]
2026-07-29 14:15 ` Jan Beulich
2026-07-29 15:02 ` Oleksii Kurochko
2026-07-29 15:23 ` Oleksii Kurochko
2026-07-30 7:18 ` Jan Beulich
2026-07-30 11:31 ` Oleksii Kurochko
2026-07-20 16:00 ` [PATCH v6 19/23] xen/riscv: implement init_intc_phandle() Oleksii Kurochko
2026-07-20 16:00 ` [PATCH v6 20/23] xen/riscv: initialize RCU, scheduler, and system domains in start_xen() Oleksii Kurochko
2026-07-20 16:00 ` [PATCH v6 21/23] xen/riscv: provide init_vuart() Oleksii Kurochko
2026-07-20 16:00 ` [PATCH v6 22/23] xen/riscv: add initial dom0less infrastructure support Oleksii Kurochko
2026-07-21 7:27 ` Jan Beulich
2026-07-20 16:00 ` [PATCH v6 23/23] xen/riscv: do a 4th linking pass if necessary Oleksii Kurochko
2026-07-21 7:29 ` Jan Beulich
2026-07-21 7:34 ` Oleksii Kurochko
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=6cebc63c-2f21-4ef8-ab10-e2ec62f887b7@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=Romain.Caritey@microchip.com \
--cc=alistair.francis@wdc.com \
--cc=baptiste.le-duc@vates.tech \
--cc=connojdavis@gmail.com \
--cc=dpsmith@apertussolutions.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xenproject.org \
/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