xen/arm: vpl011: reserve the virq before setting up the backend
PATCH 1/1 xen/arm: vpl011: reserve the virq before setting up the backend
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.
---
CC: Julien Grall <[email protected]>,
CC: Bertrand Marquis <[email protected]>,
CC: Michal Orzel <[email protected]>,
CC: Volodymyr Babchuk <[email protected]>
xen/arch/arm/vpl011.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
xen/arch/arm/vpl011.c +10 -14
@@ -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; }
Signature · 1 line
2.47.3
Quoted 8 lines · Stefano Stabellini
domain_vpl011_init()allocates the backend event channel before it reserves the virq and records it invpl011->virq. A notification sent on that port in between runsvpl011_update_interrupt_status()withvpl011->virqstill 0. WithCONFIG_NEW_VGICthis callsvgic_inject_irq(d, NULL, 0, ...), andvgic_get_irq()dereferences the NULL vcpu to look up the private interrupt 0. The same notification also takesvpl011->lockand updatesvpl011->uartfrbefore 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.
Quoted 9 lines
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 <[email protected]>
~Michal