|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] x86/vLAPIC: only accept interrupts on enabled LAPICs
In hardware-disabled mode the APIC behaves as if absent altogether. In
software-disabled mode it only accepts INIT, NMI, SMI, and SIPI.
Integrate the enabled checking into vlapic_match_dest(), requiring the
delivery mode to be passed in. This way (for vlapic_lowest_prio() and
vioapic_deliver()) the cheaper check also is done first.
Modernize a few involved types at the same time.
Fixes: 7429bfd50dd7 ("This patch provide local APIC support for vmx guest")
Fixes: e03ad58f0b8c ("x86 hvm: Clean up vlapic/vioapic/vmsi delivery")
Fixes: d75c52c50c4b ("iommu: Fix pirq conflict issue when guest adopts per-cpu
vector")
Fixes: 023e3bc72dc3 ("x86: Make assigned devices' interrupts delivery to right
vcpu")
Fixes: 7242e0dc2c6c ("hvm: Improve APIC INIT/SIPI emulation, fixing it for call
paths other than x86_emulate()")
Fixes: 35a1caf8b6b5 ("pass-through: update IRTE according to guest interrupt
config changes")
Reported-by: Roger Pau Monné <roger.pau@xxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
--- a/xen/arch/x86/hvm/vioapic.c
+++ b/xen/arch/x86/hvm/vioapic.c
@@ -438,9 +438,8 @@ static void vioapic_deliver(struct hvm_v
/* Force to pick vCPU 0 if part of the destination list */
if ( (irq == hvm_isa_irq_to_gsi(0)) && pt_active(&d->arch.vpit.pt0) &&
- vlapic_match_dest(lapic0, NULL, 0, dest, dest_mode) &&
- /* Mimic the vlapic_enabled check found in vlapic_lowest_prio. */
- vlapic_enabled(lapic0) )
+ vlapic_match_dest(lapic0, NULL, 0, dest, dest_mode,
+ APIC_DM_LOWEST) )
target = lapic0;
else
#endif
@@ -463,8 +462,8 @@ static void vioapic_deliver(struct hvm_v
{
struct vlapic *vlapic = vcpu_vlapic(v);
- if ( vlapic_enabled(vlapic) &&
- vlapic_match_dest(vlapic, NULL, 0, dest, dest_mode) )
+ if ( vlapic_match_dest(vlapic, NULL, 0, dest, dest_mode,
+ APIC_DM_FIXED) )
ioapic_inj_irq(vioapic, vlapic, vector, trig_mode,
delivery_mode);
}
@@ -473,8 +472,8 @@ static void vioapic_deliver(struct hvm_v
case dest_NMI:
{
for_each_vcpu ( d, v )
- if ( vlapic_match_dest(vcpu_vlapic(v), NULL,
- 0, dest, dest_mode) &&
+ if ( vlapic_match_dest(vcpu_vlapic(v), NULL, 0, dest, dest_mode,
+ APIC_DM_NMI) &&
!test_and_set_bool(v->arch.nmi_state.pending) )
vcpu_kick(v);
break;
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -238,12 +238,28 @@ static bool vlapic_match_logical_addr(co
bool vlapic_match_dest(
const struct vlapic *target, const struct vlapic *source,
- int short_hand, uint32_t dest, bool dest_mode)
+ unsigned int short_hand, uint32_t dest, bool dest_mode, unsigned int dm)
{
HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "target %p, source %p, dest %#x, "
"dest_mode %#x, short_hand %#x",
target, source, dest, dest_mode, short_hand);
+ switch ( dm )
+ {
+ default:
+ if ( !vlapic_enabled(target) )
+ return false;
+
+ case APIC_DM_SMI:
+ case APIC_DM_REMRD:
+ case APIC_DM_NMI:
+ case APIC_DM_INIT:
+ case APIC_DM_STARTUP:
+ if ( vlapic_hw_disabled(target) )
+ return false;
+ break;
+ }
+
switch ( short_hand )
{
case APIC_DEST_NOSHORT:
@@ -317,7 +333,8 @@ static void cf_check vlapic_init_sipi_ac
struct vcpu *origin = data;
uint32_t icr = vcpu_vlapic(origin)->init_sipi.icr;
uint32_t dest = vcpu_vlapic(origin)->init_sipi.dest;
- uint32_t short_hand = icr & APIC_SHORT_MASK;
+ unsigned int short_hand = icr & APIC_SHORT_MASK;
+ unsigned int dm = icr & APIC_DM_MASK;
bool dest_mode = icr & APIC_DEST_MASK;
struct vcpu *v;
@@ -327,7 +344,7 @@ static void cf_check vlapic_init_sipi_ac
for_each_vcpu ( origin->domain, v )
{
if ( vlapic_match_dest(vcpu_vlapic(v), vcpu_vlapic(origin),
- short_hand, dest, dest_mode) )
+ short_hand, dest, dest_mode, dm) )
vlapic_init_sipi_one(v, icr);
}
@@ -399,8 +416,8 @@ struct vlapic *vlapic_lowest_prio(
do {
v = v->next_in_list ? : d->vcpu[0];
vlapic = vcpu_vlapic(v);
- if ( vlapic_match_dest(vlapic, source, short_hand, dest, dest_mode) &&
- vlapic_enabled(vlapic) &&
+ if ( vlapic_match_dest(vlapic, source, short_hand, dest, dest_mode,
+ APIC_DM_LOWEST) &&
((ppr = vlapic_get_ppr(vlapic)) < target_ppr) )
{
target = vlapic;
@@ -498,13 +515,14 @@ void vlapic_ipi(
{
unsigned int dest;
unsigned int short_hand = icr_low & APIC_SHORT_MASK;
+ unsigned int dm = icr_low & APIC_DM_MASK;
bool dest_mode = icr_low & APIC_DEST_MASK;
HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "icr = 0x%08x:%08x", icr_high, icr_low);
dest = _VLAPIC_ID(vlapic, icr_high);
- switch ( icr_low & APIC_DM_MASK )
+ switch ( dm )
{
case APIC_DM_INIT:
case APIC_DM_STARTUP:
@@ -546,7 +564,7 @@ void vlapic_ipi(
for_each_vcpu ( vlapic_domain(vlapic), v )
{
if ( vlapic_match_dest(vcpu_vlapic(v), vlapic,
- short_hand, dest, dest_mode) )
+ short_hand, dest, dest_mode, dm) )
vlapic_accept_irq(v, icr_low);
}
if ( batch )
--- a/xen/arch/x86/hvm/vmsi.c
+++ b/xen/arch/x86/hvm/vmsi.c
@@ -89,8 +89,8 @@ int vmsi_deliver(
for_each_vcpu ( d, v )
{
target = vcpu_vlapic(v);
- if ( vlapic_enabled(target) &&
- vlapic_match_dest(target, NULL, 0, dest, dest_mode) )
+ if ( vlapic_match_dest(target, NULL, 0, dest, dest_mode,
+ MASK_INSR(delivery_mode, APIC_DM_MASK)) )
vmsi_inj_irq(target, vector, trig_mode, delivery_mode);
}
break;
@@ -125,7 +125,8 @@ void vmsi_deliver_pirq(struct domain *d,
}
/* Return value, -1 : multi-dests, non-negative value: dest_vcpu_id */
-int hvm_girq_dest_2_vcpu_id(struct domain *d, uint8_t dest, uint8_t dest_mode)
+int hvm_girq_dest_2_vcpu_id(struct domain *d, unsigned int dest, bool
dest_mode,
+ unsigned int delivery_mode)
{
int dest_vcpu_id = -1, w = 0;
struct vcpu *v;
@@ -135,7 +136,8 @@ int hvm_girq_dest_2_vcpu_id(struct domai
for_each_vcpu ( d, v )
{
- if ( vlapic_match_dest(vcpu_vlapic(v), NULL, 0, dest, dest_mode) )
+ if ( vlapic_match_dest(vcpu_vlapic(v), NULL, 0, dest, dest_mode,
+ MASK_INSR(delivery_mode, APIC_DM_MASK)) )
{
w++;
dest_vcpu_id = v->vcpu_id;
--- a/xen/arch/x86/include/asm/hvm/hvm.h
+++ b/xen/arch/x86/include/asm/hvm/hvm.h
@@ -299,7 +299,8 @@ int vmsi_deliver(
uint8_t delivery_mode, uint8_t trig_mode);
struct hvm_pirq_dpci;
void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci
*pirq_dpci);
-int hvm_girq_dest_2_vcpu_id(struct domain *d, uint8_t dest, uint8_t dest_mode);
+int hvm_girq_dest_2_vcpu_id(struct domain *d, unsigned int dest, bool
dest_mode,
+ unsigned int delivery_mode);
enum hvm_intblk
hvm_interrupt_blocked(struct vcpu *v, struct hvm_intack intack);
--- a/xen/arch/x86/include/asm/hvm/vlapic.h
+++ b/xen/arch/x86/include/asm/hvm/vlapic.h
@@ -136,6 +136,6 @@ struct vlapic *vlapic_lowest_prio(
bool vlapic_match_dest(
const struct vlapic *target, const struct vlapic *source,
- int short_hand, uint32_t dest, bool dest_mode);
+ unsigned int short_hand, uint32_t dest, bool dest_mode, unsigned int dm);
#endif /* __ASM_X86_HVM_VLAPIC_H__ */
--- a/xen/drivers/passthrough/x86/hvm.c
+++ b/xen/drivers/passthrough/x86/hvm.c
@@ -191,7 +191,7 @@ static struct vcpu *vector_hashing_dest(
for_each_vcpu ( d, v )
{
if ( !vlapic_match_dest(vcpu_vlapic(v), NULL, APIC_DEST_NOSHORT,
- dest_id, dest_mode) )
+ dest_id, dest_mode, APIC_DM_LOWEST) )
continue;
__set_bit(v->vcpu_id, dest_vcpu_bitmap);
@@ -371,7 +371,8 @@ int pt_irq_create_bind(
delivery_mode = MASK_EXTR(pirq_dpci->gmsi.gflags,
XEN_DOMCTL_VMSI_X86_DELIV_MASK);
- dest_vcpu_id = hvm_girq_dest_2_vcpu_id(d, dest, dest_mode);
+ dest_vcpu_id = hvm_girq_dest_2_vcpu_id(d, dest, dest_mode,
+ delivery_mode);
pirq_dpci->gmsi.dest_vcpu_id = dest_vcpu_id;
pirq_dpci->gmsi.posted = false;
@@ -819,9 +820,11 @@ static int cf_check _hvm_dpci_msi_eoi(
unsigned int dest = MASK_EXTR(pirq_dpci->gmsi.gflags,
XEN_DOMCTL_VMSI_X86_DEST_ID_MASK);
bool dest_mode = pirq_dpci->gmsi.gflags & XEN_DOMCTL_VMSI_X86_DM_MASK;
+ unsigned int dm = MASK_EXTR(pirq_dpci->gmsi.gflags,
+ XEN_DOMCTL_VMSI_X86_DELIV_MASK);
if ( vlapic_match_dest(vcpu_vlapic(current), NULL, 0, dest,
- dest_mode) )
+ dest_mode, MASK_INSR(dm, APIC_DM_MASK)) )
{
__msi_pirq_eoi(pirq_dpci);
return 1;
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |