x86/irq: further gate PIRQ usage for HVM domains
PATCH 1/1 x86/irq: further gate PIRQ usage for HVM domains
Further restrict PIRQ usage for HVM domains not having the ability to route device interrupts over event channels.
It's still possible for HVM domains without PIRQ support to exercise the vector == 0 path in hvm_inject_msi(), which is intended to be used only when the guest has PIRQ support. Taking the PIRQ path in hvm_inject_msi() inhibits the local APIC from raising an ESR error when the MSI vector is 0, since an MSI with vector == 0 is always processed as a PIRQ. Introduce a has_pirq() check in hvm_inject_msi().
EVTCHNOP_bind_pirq is also not outright blocked for HVM domains without PIRQ support, so guests could attempt to bind device interrupts to event channels. Short-circuit evtchn_bind_pirq() early if the domain has no PIRQ support.
Additionally introduce an assert in map_domain_emuirq_pirq() to ensure it's never called from HVM domains without PIRQ support.
Finally add an extra check in hvm_domain_use_pirq() so it returns false unconditionally if the domain has no PIRQ support. Also convert the is_hvm_domain() check into an ASSERT(); this helper is never called against a PV domain.
--- xen/arch/x86/hvm/irq.c | 5 +++-- xen/arch/x86/irq.c | 2 ++ xen/common/event_channel.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/irq.c +3 -2
@@ -19,7 +19,8 @@bool hvm_domain_use_pirq (const struct domain *d,const struct pirq *pirq) { -return is_hvm_domain (d) && pirq && pirq->arch.hvm.emuirq !=IRQ_UNBOUND ; +ASSERT (is_hvm_domain (d)); +return has_pirq (d) && pirq && pirq->arch.hvm.emuirq !=IRQ_UNBOUND ; }/* Must be called with hvm_domain->irq_lock hold */
@@ -382,7 +383,7 @@ int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data) >> MSI_DATA_TRIGGER_SHIFT;uint8_t vector = data &MSI_DATA_VECTOR_MASK ; -if ( !vector ) +if (has_pirq (d) && !vector ) {unsigned int pirq = ((addr >>32 ) &0xffffff00U ) | dest;
xen/arch/x86/irq.c +2 -0
@@ -2814,6 +2814,8 @@ int map_domain_emuirq_pirq(struct domain *d, int pirq, int emuirq)if ( !is_hvm_domain (d) )return -EINVAL ; +ASSERT (has_pirq (d)); +if ( pirq <0 || pirq >= d->nr_pirqs || emuirq ==IRQ_UNBOUND || emuirq >= (int ) nr_irqs ) {
xen/common/event_channel.c +3 -0
@@ -681,6 +681,9 @@ static int evtchn_bind_pirq(evtchn_bind_pirq_t *bind)int port =0 , rc;unsigned int pirq = bind->pirq; +if (is_hvm_domain (d) && !has_pirq (d) ) +return -EOPNOTSUPP ; +if ( pirq >= d->nr_pirqs )return -EINVAL ;
Signature · 1 line
2.55.0
Quoted 18 lines · Roger Pau Monne
Further restrict PIRQ usage for HVM domains not having the ability to route device interrupts over event channels.
It's still possible for HVM domains without PIRQ support to exercise the vector == 0 path in
hvm_inject_msi(), which is intended to be used only when the guest has PIRQ support. Taking the PIRQ path inhvm_inject_msi()inhibits the local APIC from raising an ESR error when the MSI vector is 0, since an MSI with vector == 0 is always processed as a PIRQ. Introduce ahas_pirq()check inhvm_inject_msi().
EVTCHNOP_bind_pirqis also not outright blocked for HVM domains without PIRQ support, so guests could attempt to bind device interrupts to event channels. Short-circuitevtchn_bind_pirq()early if the domain has no PIRQ support.Additionally introduce an assert in
map_domain_emuirq_pirq()to ensure it's never called from HVM domains without PIRQ support.
Quoted 7 lines
Finally add an extra check in
hvm_domain_use_pirq()so it returns false unconditionally if the domain has no PIRQ support. Also convert theis_hvm_domain()check into anASSERT(); this helper is never called against a PV domain.Fixes b96b50004804 ("x86: remove XENFEAT_hvm_pirqs for PVHv2 guests")Signed-off-by Roger Pau Monné <[email protected]>