All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/x86: On x2APIC mode, derive LDR from APIC_ID
@ 2023-11-13 16:50 Alejandro Vallejo
  2023-11-13 17:53 ` Roger Pau Monné
  0 siblings, 1 reply; 12+ messages in thread
From: Alejandro Vallejo @ 2023-11-13 16:50 UTC (permalink / raw)
  To: Xen-devel
  Cc: Alejandro Vallejo, Jan Beulich, Andrew Cooper,
	Roger Pau Monné, Wei Liu

Both Intel and AMD manuals agree that on x2APIC mode, the APIC LDR and ID
registers are derivable from each other through a fixed formula.

Xen uses that formula, but applies it to vCPU IDs (which are sequential)
rather than x2APIC_IDs (which are not, at the moment). As I understand it,
this is an attempt to tightly pack vCPUs into clusters so each cluster has
16 vCPUs rather than 8, but this is problematic for OSs that might read the
x2APIC_ID and internally derive LDR (or the other way around)

This patch fixes the implementation so we follow the rules in the x2APIC
spec(s).

While in the neighborhood, replace the u32 type with the standard uint32_t

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
 xen/arch/x86/hvm/vlapic.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c
index c7ce82d064..5a74e84445 100644
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -1063,10 +1063,10 @@ static const struct hvm_mmio_ops vlapic_mmio_ops = {
 
 static void set_x2apic_id(struct vlapic *vlapic)
 {
-    u32 id = vlapic_vcpu(vlapic)->vcpu_id;
-    u32 ldr = ((id & ~0xf) << 12) | (1 << (id & 0xf));
+    uint32_t id = vlapic_vcpu(vlapic)->vcpu_id * 2;
+    uint32_t ldr = ((id & ~0xf) << 12) | (1 << (id & 0xf));
 
-    vlapic_set_reg(vlapic, APIC_ID, id * 2);
+    vlapic_set_reg(vlapic, APIC_ID, id);
     vlapic_set_reg(vlapic, APIC_LDR, ldr);
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-11-14 15:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-13 16:50 [PATCH] xen/x86: On x2APIC mode, derive LDR from APIC_ID Alejandro Vallejo
2023-11-13 17:53 ` Roger Pau Monné
2023-11-14 10:14   ` Jan Beulich
2023-11-14 11:45     ` Andrew Cooper
2023-11-14 12:18     ` Alejandro Vallejo
2023-11-14 12:32       ` Jan Beulich
2023-11-14 12:55         ` Andrew Cooper
2023-11-14 14:11           ` Roger Pau Monné
2023-11-14 14:22             ` Alejandro Vallejo
2023-11-14 14:44             ` Andrew Cooper
2023-11-14 15:06               ` Roger Pau Monné
2023-11-14 12:09   ` Alejandro Vallejo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.