Skip to contentSkip to conversation

x86/hvmloader: fix order of PCI vs MTRR initialization

PATCH In review Roger Pau Monne 3 participants 3 messages May 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvmloader: fix order of PCI vs MTRR initialization

After some recent change the order of MTRR vs PCI initialization is inverted. MTRR will get initialization ahead of PCI scanning and sizing of MMIO regions. As a result when setting up MTRRs the MMIO window below 4GB will always have the same size, and there will be no window above 4GB. This results in malformed and incomplete MTRRs being setup.

Fix by making sure PCI is initialized ahead of MTRR, also add a comment to notice the ordering dependency.

Fixes 2c3dffbaa324 ('tools/hvmloader: Replace LAPIC_ID() with cpu_to_apicid[]')
---
 tools/firmware/hvmloader/hvmloader.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/hvmloader.c +7 -1
index 4e330fc1e241..6d23150fc9fd 100644
@@ -341,10 +341,16 @@ int main(void)
 
     printf("CPU speed is %u MHz\n", get_cpu_mhz());
 
+    /*
+     * PCI setup must be done before SMP initialization, as the later also does
+     * the MTRR setup and so the size of the PCI MMIO windows must be known at
+     * that point.
+     */
+    pci_setup();
+
     smp_initialise();
 
     apic_setup();
-    pci_setup();
 
     perform_tests();
 
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Roger Pau Monne

After some recent change the order of MTRR vs PCI initialization is inverted. MTRR will get initialization ahead of PCI scanning and sizing of MMIO regions. As a result when setting up MTRRs the MMIO window below 4GB will always have the same size, and there will be no window above 4GB. This results in malformed and incomplete MTRRs being setup.

Fix by making sure PCI is initialized ahead of MTRR, also add a comment to notice the ordering dependency.

Fixes 2c3dffbaa324 ('tools/hvmloader: Replace LAPIC_ID() with cpu_to_apicid[]')
Reviewed-by on v1 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 11 lines · Roger Pau Monne

After some recent change the order of MTRR vs PCI initialization is inverted. MTRR will get initialization ahead of PCI scanning and sizing of MMIO regions. As a result when setting up MTRRs the MMIO window below 4GB will always have the same size, and there will be no window above 4GB. This results in malformed and incomplete MTRRs being setup.

Fix by making sure PCI is initialized ahead of MTRR, also add a comment to notice the ordering dependency.

Fixes 2c3dffbaa324 ('tools/hvmloader: Replace LAPIC_ID() with cpu_to_apicid[]')