* [PATCH] xen/arm: vpl011: reserve the virq before setting up the backend
@ 2026-11-19 21:37 Stefano Stabellini
2026-11-23 8:32 ` Orzel, Michal
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Stabellini @ 2026-11-19 21:37 UTC (permalink / raw)
To: xen-devel
Cc: stefano.stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
Volodymyr Babchuk
domain_vpl011_init() allocates the backend event channel before it
reserves the virq and records it in vpl011->virq. A notification sent
on that port in between runs vpl011_update_interrupt_status() with
vpl011->virq still 0. With CONFIG_NEW_VGIC this calls
vgic_inject_irq(d, NULL, 0, ...), and vgic_get_irq() dereferences the
NULL vcpu to look up the private interrupt 0. The same notification
also takes vpl011->lock and updates vpl011->uartfr before either is
initialised, and both are then reset under it.
Reserve and record the virq, set the initial flags and initialise the
lock first, before any backend is set up, so that they are valid by the
time the event channel exists. All the failures after the reservation
now go through domain_vpl011_deinit(), which releases the virq.
Fixes: ca0637a147af ("xen/arm: vpl011: Add SBSA UART emulation in Xen")
Fixes: 85da01b71312 ("xen/arm: vpl011: record the virq only once it is reserved")
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
CC: Julien Grall <julien@xen.org>,
CC: Bertrand Marquis <bertrand.marquis@arm.com>,
CC: Michal Orzel <michal.orzel@amd.com>,
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
xen/arch/arm/vpl011.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c
index a37e88a8b4..b1d286e1d1 100644
--- a/xen/arch/arm/vpl011.c
+++ b/xen/arch/arm/vpl011.c
@@ -689,6 +689,14 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)
virq = GUEST_VPL011_SPI;
}
+ if ( !vgic_reserve_virq(d, virq) )
+ return -EINVAL;
+ vpl011->virq = virq;
+
+ vpl011->uartfr = TXFE | RXFE;
+
+ spin_lock_init(&vpl011->lock);
+
/*
* info is NULL when the backend is in Xen.
* info is != NULL when the backend is in a domain.
@@ -708,7 +716,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)
rc = alloc_unbound_xen_event_channel(d, 0, info->console_domid,
vpl011_notification);
if ( rc < 0 )
- goto out1;
+ goto out;
vpl011->evtchn = info->evtchn = rc;
}
@@ -725,26 +733,14 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)
}
}
- if ( !vgic_reserve_virq(d, virq) )
- {
- rc = -EINVAL;
- goto out1;
- }
- vpl011->virq = virq;
-
- vpl011->uartfr = TXFE | RXFE;
-
- spin_lock_init(&vpl011->lock);
-
register_mmio_handler(d, &vpl011_mmio_handler,
vpl011->base_addr, GUEST_PL011_SIZE, NULL);
return 0;
-out1:
+out:
domain_vpl011_deinit(d);
-out:
return rc;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xen/arm: vpl011: reserve the virq before setting up the backend
2026-11-19 21:37 [PATCH] xen/arm: vpl011: reserve the virq before setting up the backend Stefano Stabellini
@ 2026-11-23 8:32 ` Orzel, Michal
0 siblings, 0 replies; 2+ messages in thread
From: Orzel, Michal @ 2026-11-23 8:32 UTC (permalink / raw)
To: Stefano Stabellini, xen-devel
Cc: Julien Grall, Bertrand Marquis, Volodymyr Babchuk
On 19-Nov-26 22:37, Stefano Stabellini wrote:
> domain_vpl011_init() allocates the backend event channel before it
> reserves the virq and records it in vpl011->virq. A notification sent
> on that port in between runs vpl011_update_interrupt_status() with
> vpl011->virq still 0. With CONFIG_NEW_VGIC this calls
> vgic_inject_irq(d, NULL, 0, ...), and vgic_get_irq() dereferences the
> NULL vcpu to look up the private interrupt 0. The same notification
> also takes vpl011->lock and updates vpl011->uartfr before either is
> initialised, and both are then reset under it.
I struggle to understand how this could work in practice (in theory, yes). The
evtchn port is returned by the hypercall which at this point has not yet
returned to the caller. So the caller (console domain) would need to predicate
the port that Xen is going to return and send something on that port via a
different pCPU. xenconsoled never does that which is worth saying in the commit msg.
>
> Reserve and record the virq, set the initial flags and initialise the
> lock first, before any backend is set up, so that they are valid by the
> time the event channel exists. All the failures after the reservation
> now go through domain_vpl011_deinit(), which releases the virq.
>
> Fixes: ca0637a147af ("xen/arm: vpl011: Add SBSA UART emulation in Xen")
> Fixes: 85da01b71312 ("xen/arm: vpl011: record the virq only once it is reserved")
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
~Michal
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 21:37 [PATCH] xen/arm: vpl011: reserve the virq before setting up the backend Stefano Stabellini
2026-11-23 8:32 ` Orzel, Michal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.