xen/arm: vpl011: record the virq only once it is reserved
PATCH 1/1 xen/arm: vpl011: record the virq only once it is reserved
domain_vpl011_init() sets vpl011->virq before vgic_reserve_virq() claims it, and both a refused reservation and a failed alloc_unbound_xen_event_channel() take the out1 error path into domain_vpl011_deinit(), which frees vpl011->virq. That clears the allocation bit of an interrupt the vPL011 never reserved, so an interrupt held by another user can be handed out a second time.
Record the virq only after the reservation succeeds.
---
CC: Stefano Stabellini <[email protected]>,
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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/arm/vpl011.c +5 -4
@@ -640,6 +640,7 @@ static void vpl011_notification(struct vcpu *v, unsigned int port)int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info) {int rc; +unsigned int virq;struct vpl011 *vpl011 = &d->arch.vpl011;if ( vpl011->backend.dom.ring_buf )
@@ -659,7 +660,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)if ( (uart !=NULL ) && (vpl011_irq >0 ) ) { vpl011->base_addr = uart->base_addr; - vpl011->virq = vpl011_irq; + virq = vpl011_irq; }else {
@@ -685,7 +686,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)else { vpl011->base_addr =GUEST_PL011_BASE ; - vpl011->virq =GUEST_VPL011_SPI ; + virq =GUEST_VPL011_SPI ; }/*
@@ -724,12 +725,12 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) } } - rc =vgic_reserve_virq (d, vpl011->virq); -if ( !rc ) +if ( !vgic_reserve_virq (d, virq) ) { rc = -EINVAL ; goto out1; } + vpl011->virq = virq; vpl011->uartfr =TXFE |RXFE ;
Signature · 1 line
2.47.3
Quoted 6 lines · Stefano Stabellini
domain_vpl011_init()setsvpl011->virqbeforevgic_reserve_virq()claims it, and both a refused reservation and a failedalloc_unbound_xen_event_channel()take the out1 error path intodomain_vpl011_deinit(), which freesvpl011->virq. That clears the allocation bit of an interrupt the vPL011 never reserved, so an interrupt held by another user can be handed out a second time.
Who is the other user here? The virq is either GUEST_VPL011_SPI or the Xen UART IRQ. libxl rejects a passthrough IRQ that matches the vpl011 SPI, dom0less reserves the vpl011 virq before passthrough and panics on failure, and the Xen UART cannot be assigned. AFAICT there is no issue as of today and this should be explained in the commit msg.
Quoted 4 lines
Record the virq only after the reservation succeeds.
Fixes 08bbc1c02d38 ("xen/arm: vpl011: Fix domain_vpl011_init error path")
The SHA is wrong - unknown revision. That said, I think this should be 1ee1e4b0d1ff instead.
~Michal
Quoted 6 lines · Stefano Stabellini
domain_vpl011_init()setsvpl011->virqbeforevgic_reserve_virq()claims it, and both a refused reservation and a failedalloc_unbound_xen_event_channel()take the out1 error path intodomain_vpl011_deinit(), which freesvpl011->virq. That clears the allocation bit of an interrupt the vPL011 never reserved, so an interrupt held by another user can be handed out a second time.
Who is the other user here? The virq is either GUEST_VPL011_SPI or the Xen UART IRQ. libxl rejects a passthrough IRQ that matches the vpl011 SPI, dom0less reserves the vpl011 virq before passthrough and panics on failure, and the Xen UART cannot be assigned. AFAICT there is no issue as of today and this should be explained in the commit msg.
Quoted 4 lines
Record the virq only after the reservation succeeds.
Fixes 08bbc1c02d38 ("xen/arm: vpl011: Fix domain_vpl011_init error path")
The SHA is wrong - unknown revision. That said, I think this should be 1ee1e4b0d1ff instead.
~Michal
Quoted 7 lines · Michal
Quoted 6 lines · Stefano Stabellini
domain_vpl011_init()setsvpl011->virqbeforevgic_reserve_virq()claims it, and both a refused reservation and a failedalloc_unbound_xen_event_channel()take the out1 error path intodomain_vpl011_deinit(), which freesvpl011->virq. That clears the allocation bit of an interrupt the vPL011 never reserved, so an interrupt held by another user can be handed out a second time.
Quoted 5 lines
Who is the other user here? The virq is either
GUEST_VPL011_SPIor the Xen UART IRQ. libxl rejects a passthrough IRQ that matches the vpl011 SPI, dom0less reserves the vpl011 virq before passthrough and panics on failure, and the Xen UART cannot be assigned. AFAICT there is no issue as of today and this should be explained in the commit msg.
Yes, I can explain this in the commit message.
Just one note though: Xen itself doesn't enforce it. XEN_DOMCTL_bind_pt_irq accepts GUEST_VPL011_SPI. A toolstack that binds a passthrough IRQ there before XEN_DOMCTL_vuart_op would see the vpl011 error path free that passthrough virq. I'll explain this in the commit message.
Quoted 5 lines
Quoted 3 lines
Record the virq only after the reservation succeeds.
Fixes 08bbc1c02d38 ("xen/arm: vpl011: Fix domain_vpl011_init error path")The SHA is wrong - unknown revision. That said, I think this should be
1ee1e4b0d1ffinstead.
Thanks! I can use that
---
xen/arm: vpl011: record the virq only once it is reserved
domain_vpl011_init() sets vpl011->virq before reserving it. If the reservation or the event channel allocation fails, the error path frees vpl011->virq, which the vPL011 never reserved.
libxl and dom0less never hit this with a virq held by someone else, but Xen does not enforce it: XEN_DOMCTL_bind_pt_irq accepts GUEST_VPL011_SPI, so a passthrough IRQ bound there before XEN_DOMCTL_vuart_op would lose its reservation.
Record the virq only after the reservation succeeds.
---
Changes in v2:
- explain in the commit message why libxl and dom0less never hit this, and that Xen itself does not enforce it
- Fixes: tag now points to 1ee1e4b0d1ff
xen/arch/arm/vpl011.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/arm/vpl011.c +5 -4
@@ -640,6 +640,7 @@ static void vpl011_notification(struct vcpu *v, unsigned int port)int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info) {int rc; +unsigned int virq;struct vpl011 *vpl011 = &d->arch.vpl011;if ( vpl011->backend.dom.ring_buf )
@@ -659,7 +660,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)if ( (uart !=NULL ) && (vpl011_irq >0 ) ) { vpl011->base_addr = uart->base_addr; - vpl011->virq = vpl011_irq; + virq = vpl011_irq; }else {
@@ -685,7 +686,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)else { vpl011->base_addr =GUEST_PL011_BASE ; - vpl011->virq =GUEST_VPL011_SPI ; + virq =GUEST_VPL011_SPI ; }/*
@@ -724,12 +725,12 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) } } - rc =vgic_reserve_virq (d, vpl011->virq); -if ( !rc ) +if ( !vgic_reserve_virq (d, virq) ) { rc = -EINVAL ; goto out1; } + vpl011->virq = virq; vpl011->uartfr =TXFE |RXFE ;
Signature · 1 line
2.47.3
Orzel, Michal
Reviewed-byQuoted 44 lines · Stefano Stabellini
Quoted 7 lines · Michal
Quoted 6 lines · Stefano Stabellini
domain_vpl011_init()setsvpl011->virqbeforevgic_reserve_virq()claims it, and both a refused reservation and a failedalloc_unbound_xen_event_channel()take the out1 error path intodomain_vpl011_deinit(), which freesvpl011->virq. That clears the allocation bit of an interrupt the vPL011 never reserved, so an interrupt held by another user can be handed out a second time.Quoted 5 lines
Who is the other user here? The virq is either
GUEST_VPL011_SPIor the Xen UART IRQ. libxl rejects a passthrough IRQ that matches the vpl011 SPI, dom0less reserves the vpl011 virq before passthrough and panics on failure, and the Xen UART cannot be assigned. AFAICT there is no issue as of today and this should be explained in the commit msg.Yes, I can explain this in the commit message.
Just one note though: Xen itself doesn't enforce it.
XEN_DOMCTL_bind_pt_irqacceptsGUEST_VPL011_SPI. A toolstack that binds a passthrough IRQ there beforeXEN_DOMCTL_vuart_opwould see the vpl011 error path free that passthrough virq. I'll explain this in the commit message.Quoted 5 lines
Quoted 3 lines
Record the virq only after the reservation succeeds.
Fixes 08bbc1c02d38 ("xen/arm: vpl011: Fix domain_vpl011_init error path")The SHA is wrong - unknown revision. That said, I think this should be
1ee1e4b0d1ffinstead.Thanks! I can use that
---
xen/arm: vpl011: record the virq only once it is reserved
domain_vpl011_init()setsvpl011->virqbefore reserving it. If the reservation or the event channel allocation fails, the error path freesvpl011->virq, which the vPL011 never reserved.libxl and dom0less never hit this with a virq held by someone else, but Xen does not enforce it:
XEN_DOMCTL_bind_pt_irqacceptsGUEST_VPL011_SPI, so a passthrough IRQ bound there beforeXEN_DOMCTL_vuart_opwould lose its reservation.
Quoted 4 lines
Record the virq only after the reservation succeeds.
Fixes 1ee1e4b0d1ff ("xen/arm: Allow vpl011 to be used by DomU")Signed-off-by Stefano Stabellini <[email protected]>
~Michal