x86/vlapic: size the all-ones broadcast by the sender's mode
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.
---
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
@@ -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
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.
---
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
@@ -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
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 checkvlapic_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 asvioapic_deliver()already mimics where it usesvlapic_match_dest()on its own.Fixes 35a1caf8b6b5 ("pass-through: update IRTE according to guest interrupt config changes")Signed-off-by Stefano Stabellini <[email protected]>
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);
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
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
0xffis uniformly "broadcast" there. (Or alternatively0xffcannot 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_IDafaics.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;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
0xffis uniformly "broadcast" there. (Or alternatively0xffcannot 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_IDafaics.
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
0xffbroadcast 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
0xffis uniformly a broadcast for IO-APIC/MSI, the alternative is to accept a physical0xfffrom 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