Skip to contentSkip to conversation

x86/vlapic: size the all-ones broadcast by the sender's mode

PATCH In review Stefano Stabellini 3 participants 6 messages Nov 19 – Nov 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/vlapic: size the all-ones broadcast by the sender's mode

vlapic_match_dest() detects a broadcast by comparing the destination with all ones in the target's mode, but an IPI's destination has the width of the sender's mode.

Use the sender's mode when there is one, as is_multicast_dest() does:
whether a destination is a broadcast is decided by the sender. vIO-APIC and MSI destinations have no sender and are still compared in the target's mode.

Fixes 82d29b97d013 ("x86/vlapic: accept a logical destination of all ones as a broadcast")

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

 xen/arch/x86/hvm/vlapic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vlapic.c +6 -2
index 50b515d254..b7861bd2ba 100644
@@ -247,8 +247,12 @@ bool vlapic_match_dest(
     switch ( short_hand )
     {
     case APIC_DEST_NOSHORT:
-        /* All ones is a broadcast in either destination mode. */
-        if ( dest == _VLAPIC_ID(target, 0xffffffffU) )
+        /*
+         * All ones is a broadcast in either destination mode.  An IPI's
+         * destination has the width of its sender's mode; IO-APIC and MSI
+         * destinations are compared in the target's.
+         */
+        if ( dest == _VLAPIC_ID(source ?: target, 0xffffffffU) )
             return true;
         if ( dest_mode )
             return vlapic_match_logical_addr(target, dest);
Signature · 1 line
2.47.3
#1 lore raw

PATCH 2/2 x86/passthrough: skip disabled vLAPICs in vector_hashing_dest()

Unlike vlapic_lowest_prio(), vector_hashing_dest() does not check vlapic_enabled(), so a lowest-priority MSI can be posted to a vCPU whose LAPIC is disabled, e.g. an AP not yet started, and the interrupt is left pending in that vCPU's PIR instead of being delivered.

Skip such vCPUs, as vlapic_lowest_prio() does, and as vioapic_deliver() already mimics where it uses vlapic_match_dest() on its own.

Fixes 35a1caf8b6b5 ("pass-through: update IRTE according to guest interrupt config changes")

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

 xen/drivers/passthrough/x86/hvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/x86/hvm.c +2 -1
index 9f8e6c8cd5..7971acadbc 100644
@@ -191,7 +191,8 @@ static struct vcpu *vector_hashing_dest(const struct domain *d,
     for_each_vcpu ( d, v )
     {
         if ( !vlapic_match_dest(vcpu_vlapic(v), NULL, APIC_DEST_NOSHORT,
-                                dest_id, dest_mode) )
+                                dest_id, dest_mode) ||
+             !vlapic_enabled(vcpu_vlapic(v)) )
             continue;
 
         __set_bit(v->vcpu_id, dest_vcpu_bitmap);
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 2/2] x86/passthrough: skip disabled vLAPICs in vector_hashing_dest()

Quoted 10 lines · Stefano Stabellini

Unlike vlapic_lowest_prio(), vector_hashing_dest() does not check vlapic_enabled(), so a lowest-priority MSI can be posted to a vCPU whose LAPIC is disabled, e.g. an AP not yet started, and the interrupt is left pending in that vCPU's PIR instead of being delivered.

Skip such vCPUs, as vlapic_lowest_prio() does, and as vioapic_deliver() already mimics where it uses vlapic_match_dest() on its own.

Fixes 35a1caf8b6b5 ("pass-through: update IRTE according to guest interrupt config changes")

Please see https://lists.xen.org/archives/html/xen-devel/2026-11/msg01815.html
for a more extensive fix.

Jan

Quoted 12 lines
xen/drivers/passthrough/x86/hvm.c +2 -1
@@ -191,7 +191,8 @@ static struct vcpu *vector_hashing_dest(const struct domain *d,
     for_each_vcpu ( d, v )
     {
         if ( !vlapic_match_dest(vcpu_vlapic(v), NULL, APIC_DEST_NOSHORT,
-                                dest_id, dest_mode) )
+                                dest_id, dest_mode) ||
+             !vlapic_enabled(vcpu_vlapic(v)) )
             continue;
 
         __set_bit(v->vcpu_id, dest_vcpu_bitmap);
#3 lore raw
In reply to Stefano Stabellini
Quoted 8 lines · Stefano Stabellini

vlapic_match_dest() detects a broadcast by comparing the destination with all ones in the target's mode, but an IPI's destination has the width of the sender's mode.

Use the sender's mode when there is one, as is_multicast_dest() does:
whether a destination is a broadcast is decided by the sender. vIO-APIC and MSI destinations have no sender and are still compared in the target's mode.

But that isn't right: Those simply cannot express wide target IDs. Aiui 0xff is uniformly "broadcast" there. (Or alternatively 0xff cannot validly be used in x2APIC mode, or even at all. I fear different sources say different things as to the validity of this.)

The situation is perhaps yet more fuzzy there with the 15-bit ID extension, for which patches are floating around. All we've got in the tree so far is XEN_HVM_CPUID_EXT_DEST_ID afaics.

Overall with no sender it may be best to simply skip the broadcast check.

Jan

#4 lore raw
Quoted 15 lines · Jan Beulich
Quoted 8 lines · Stefano Stabellini

vlapic_match_dest() detects a broadcast by comparing the destination with all ones in the target's mode, but an IPI's destination has the width of the sender's mode.

Use the sender's mode when there is one, as is_multicast_dest() does:
whether a destination is a broadcast is decided by the sender. vIO-APIC and MSI destinations have no sender and are still compared in the target's mode.

But that isn't right: Those simply cannot express wide target IDs. Aiui 0xff is uniformly "broadcast" there. (Or alternatively 0xff cannot validly be used in x2APIC mode, or even at all. I fear different sources say different things as to the validity of this.)

Quoted 5 lines

The situation is perhaps yet more fuzzy there with the 15-bit ID extension, for which patches are floating around. All we've got in the tree so far is XEN_HVM_CPUID_EXT_DEST_ID afaics.

Overall with no sender it may be best to simply skip the broadcast check.

Is this what you are thinking?

if ( source && dest == _VLAPIC_ID(source, 0xffffffffU) )

    return true;

Note that this also drops the physical 0xff broadcast from IO-APIC/MSI to xAPIC-mode vLAPICs.

If 0xff is uniformly a broadcast for IO-APIC/MSI, the alternative is to accept a physical 0xff from them for every vLAPIC, independent of the target's mode:

case APIC_DEST_NOSHORT:

    if ( source ? dest == _VLAPIC_ID(source, 0xffffffffU)
                : !dest_mode && dest == 0xff )
        return true;
#5 lore raw
Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Jan Beulich
Quoted 8 lines · Stefano Stabellini

vlapic_match_dest() detects a broadcast by comparing the destination with all ones in the target's mode, but an IPI's destination has the width of the sender's mode.

Use the sender's mode when there is one, as is_multicast_dest() does:
whether a destination is a broadcast is decided by the sender. vIO-APIC and MSI destinations have no sender and are still compared in the target's mode.

But that isn't right: Those simply cannot express wide target IDs. Aiui 0xff is uniformly "broadcast" there. (Or alternatively 0xff cannot validly be used in x2APIC mode, or even at all. I fear different sources say different things as to the validity of this.)

The situation is perhaps yet more fuzzy there with the 15-bit ID extension, for which patches are floating around. All we've got in the tree so far is XEN_HVM_CPUID_EXT_DEST_ID afaics.

Quoted 6 lines
Quoted 1 line

Overall with no sender it may be best to simply skip the broadcast check.

Is this what you are thinking?

if ( source && dest == _VLAPIC_ID(source, 0xffffffffU) )

    return true;

Yes and ...

Quoted 2 lines

Note that this also drops the physical 0xff broadcast from IO-APIC/MSI to xAPIC-mode vLAPICs.

... yes. As said, I don't think I can establish, from the source I found, whether the above, ...

Quoted 8 lines

If 0xff is uniformly a broadcast for IO-APIC/MSI, the alternative is to accept a physical 0xff from them for every vLAPIC, independent of the target's mode:

case APIC_DEST_NOSHORT:

    if ( source ? dest == _VLAPIC_ID(source, 0xffffffffU)
                : !dest_mode && dest == 0xff )
        return true;

... this, or yet something else is how hardware behaves (or at least is supposed to behave). You may be in a better position to find out than I am.

Jan