Skip to contentSkip to conversation

x86/vlapic: accept a logical destination of all ones as a broadcast

PATCH Superseded Stefano Stabellini 2 participants 3 messages Nov 17

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/vlapic: accept a logical destination of all ones as a broadcast

In logical destination mode, a destination of all ones is a broadcast accepted by every local APIC: 0xff in xAPIC mode, in both the flat and the cluster model (AMD APM vol. 2, 16.6.1), and 0xffffffff in x2APIC mode (AMD APM vol. 2 Rev 3.39, 16.14).

vlapic_match_logical_addr() treated these as ordinary logical destinations, so a broadcast reached only the vLAPICs whose logical ID happened to match it. In particular, a vLAPIC whose logical ID is 0 received no logical broadcast at all.

Match the broadcast in each model. A destination format register naming neither model still matches nothing.

---
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 | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vlapic.c +13 -4
index 6698779e22..ed745a810c 100644
@@ -209,9 +209,16 @@ static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda)
     bool result = false;
     uint32_t logical_id = vlapic_get_reg(vlapic, APIC_LDR);
 
+    /*
+     * A destination of all ones is a broadcast in logical destination mode
+     * too, accepted by every local APIC: 0xffffffff in x2APIC mode (AMD APM
+     * vol. 2 Rev 3.39, 16.14), and 0xff in both the flat and the cluster
+     * model in xAPIC mode (AMD APM vol. 2, 16.6.1).
+     */
     if ( vlapic_x2apic_mode(vlapic) )
-        return ((logical_id >> 16) == (mda >> 16)) &&
-               (uint16_t)(logical_id & mda);
+        return (mda == 0xffffffffU) ||
+               (((logical_id >> 16) == (mda >> 16)) &&
+                (uint16_t)(logical_id & mda));
 
     logical_id = GET_xAPIC_LOGICAL_ID(logical_id);
     mda = (uint8_t)mda;
@@ -219,11 +226,13 @@ static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda)
     switch ( vlapic_get_reg(vlapic, APIC_DFR) )
     {
     case APIC_DFR_FLAT:
-        if ( logical_id & mda )
+        if ( (mda == 0xff) || (logical_id & mda) )
             result = true;
         break;
     case APIC_DFR_CLUSTER:
-        if ( ((logical_id >> 4) == (mda >> 0x4)) && (logical_id & mda & 0xf) )
+        if ( (mda == 0xff) ||
+             (((logical_id >> 4) == (mda >> 0x4)) &&
+              (logical_id & mda & 0xf)) )
             result = true;
         break;
     default:
Signature · 1 line
2.47.3
#1 lore raw
Quoted 4 lines · Stefano Stabellini

In logical destination mode, a destination of all ones is a broadcast accepted by every local APIC: 0xff in xAPIC mode, in both the flat and the cluster model (AMD APM vol. 2, 16.6.1), and 0xffffffff in x2APIC mode (AMD APM vol. 2 Rev 3.39, 16.14).

While revision number plus section number properly disambiguate things, this still isn't very practical: Readers may not have that revision to hand. Therefore we (much) prefer section titles; amending them by rev+ secno is okay.

Quoted 7 lines

vlapic_match_logical_addr() treated these as ordinary logical destinations, so a broadcast reached only the vLAPICs whose logical ID happened to match it. In particular, a vLAPIC whose logical ID is 0 received no logical broadcast at all.

Match the broadcast in each model. A destination format register naming neither model still matches nothing.

Along the lines of what you say here, why not a simpler change in the sole caller of vlapic_match_logical_addr(), with this as a result (sans comment for now):

    case APIC_DEST_NOSHORT:
        if ( dest == _VLAPIC_ID(target, 0xffffffffU) )
            return true;
        if ( dest_mode )
            return vlapic_match_logical_addr(target, dest);
        return dest == VLAPIC_ID(target);

? Otherwise I'd be inclined to ask for simplification of ...

Quoted 7 lines
xen/arch/x86/hvm/vlapic.c +1 -0
@@ -209,9 +209,16 @@ static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda)
     bool result = false;
     uint32_t logical_id = vlapic_get_reg(vlapic, APIC_LDR);
 
+    /*

xen/arch/x86/hvm/vlapic.c static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda) · line 220

Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +7 -2
+     * A destination of all ones is a broadcast in logical destination mode
+     * too, accepted by every local APIC: 0xffffffff in x2APIC mode (AMD APM
+     * vol. 2 Rev 3.39, 16.14), and 0xff in both the flat and the cluster
+     * model in xAPIC mode (AMD APM vol. 2, 16.6.1).
+     */
     if ( vlapic_x2apic_mode(vlapic) )
-        return ((logical_id >> 16) == (mda >> 16)) &&
-               (uint16_t)(logical_id & mda);
+        return (mda == 0xffffffffU) ||
+               (((logical_id >> 16) == (mda >> 16)) &&

... this and ...

Quoted 6 lines
xen/arch/x86/hvm/vlapic.c +1 -0
+                (uint16_t)(logical_id & mda));
 
     logical_id = GET_xAPIC_LOGICAL_ID(logical_id);
     mda = (uint8_t)mda;
@@ -219,11 +226,13 @@ static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda)
     switch ( vlapic_get_reg(vlapic, APIC_DFR) )

xen/arch/x86/hvm/vlapic.c static bool vlapic_match_logical_addr(const struct vlapic *vlapic, uint32_t mda) · line 234

Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +3 -2
     {
     case APIC_DFR_FLAT:
-        if ( logical_id & mda )
+        if ( (mda == 0xff) || (logical_id & mda) )
             result = true;
         break;
     case APIC_DFR_CLUSTER:
-        if ( ((logical_id >> 4) == (mda >> 0x4)) && (logical_id & mda & 0xf) )
+        if ( (mda == 0xff) ||
+             (((logical_id >> 4) == (mda >> 0x4)) &&

... this while touching this code anyway.

Jan

Quoted 4 lines
xen/arch/x86/hvm/vlapic.c +1 -0
+              (logical_id & mda & 0xf)) )
             result = true;
         break;
     default:
#2 lore raw
In reply to Stefano Stabellini
Quoted 10 lines · Stefano Stabellini

In logical destination mode, a destination of all ones is a broadcast accepted by every local APIC: 0xff in xAPIC mode, in both the flat and the cluster model (AMD APM vol. 2, 16.6.1), and 0xffffffff in x2APIC mode (AMD APM vol. 2 Rev 3.39, 16.14).

vlapic_match_logical_addr() treated these as ordinary logical destinations, so a broadcast reached only the vLAPICs whose logical ID happened to match it. In particular, a vLAPIC whose logical ID is 0 received no logical broadcast at all.

Quoted 4 lines

Match the broadcast in each model. A destination format register naming neither model still matches nothing.

Oh, and - a Fixes: tag is going to be wanted here (at the risk of it being one of the bitkeeper ones with meaningless subjects).

Jan