Skip to contentSkip to conversation

acpi: Fix PCI hole handling on SRAT table

PATCH Applied Eduardo Habkost 5 participants 9 messages Jan 9, 2014 – Jan 26, 2014

lore
Share & tools
lore
#0 lore raw

cover acpi: Fix PCI hole handling on SRAT table

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Example Linux guest dmesg output when the bug is present (using -m 4G and 4 1GB NUMA nodes):

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xffffffff]
NUMA: nodes only cover 3583MB of your 4095MB e820 RAM. Not used.
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Output after the series is applied:

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xdfffffff]
SRAT: Node 3 PXM 3 [mem 0x100000000-0x11fffffff]
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi-build: Fix PCI hole handling on build_srat()

 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 1/2 pc: Save size of RAM below 4GB

The ram_below_4g value will be useful in other places, such as the ACPI table code, and other code that currently requires passing below_4g_mem_size around in function arguments.

---
 hw/i386/pc.c         | 1 +
 include/hw/i386/pc.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/i386/pc.c +1 -0
index 3cd8f38..a2efc99 100644
@@ -1068,6 +1068,7 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     PcGuestInfo *guest_info = &guest_info_state->info;
     int i, j;
 
+    guest_info->ram_size_below_4g = below_4g_mem_size;
     guest_info->ram_size = below_4g_mem_size + above_4g_mem_size;
     guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
     guest_info->apic_xrupt_override = kvm_allows_irq0_override();
include/hw/i386/pc.h +1 -1
index 24eb3de..8cb637b 100644
@@ -35,7 +35,7 @@ typedef struct PcPciInfo {
 struct PcGuestInfo {
     bool has_pci_info;
     bool isapc_ram_fw;
-    hwaddr ram_size;
+    hwaddr ram_size, ram_size_below_4g;
     unsigned apic_id_limit;
     bool apic_xrupt_override;
     uint64_t numa_nodes;
Signature · 1 line
1.8.4.2
#2 lore raw

PATCH 2/2 acpi: Fix PCI hole handling on build_srat()

In reply to Eduardo Habkost

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

Change build_srat() to use ram_size_below_4g instead of ram_size, to restore the original behavior from SeaBIOS.

---
 hw/i386/acpi-build.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/i386/acpi-build.c +5 -5
index 48312f5..b58cc1a 100644
@@ -867,16 +867,16 @@ build_srat(GArray *table_data, GArray *linker,
         next_base = mem_base + mem_len;
 
         /* Cut out the ACPI_PCI hole */
-        if (mem_base <= guest_info->ram_size &&
-            next_base > guest_info->ram_size) {
-            mem_len -= next_base - guest_info->ram_size;
+        if (mem_base <= guest_info->ram_size_below_4g &&
+            next_base > guest_info->ram_size_below_4g) {
+            mem_len -= next_base - guest_info->ram_size_below_4g;
             if (mem_len > 0) {
                 numamem = acpi_data_push(table_data, sizeof *numamem);
                 acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1);
             }
             mem_base = 1ULL << 32;
-            mem_len = next_base - guest_info->ram_size;
-            next_base += (1ULL << 32) - guest_info->ram_size;
+            mem_len = next_base - guest_info->ram_size_below_4g;
+            next_base += (1ULL << 32) - guest_info->ram_size_below_4g;
         }
         numamem = acpi_data_push(table_data, sizeof *numamem);
         acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1, 1);
Signature · 1 line
1.8.4.2
Reviewed-by on the v1 series
#3 lore raw
In reply to Eduardo Habkost
Quoted 28 lines · Eduardo Habkost

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Example Linux guest dmesg output when the bug is present (using -m 4G and 4 1GB NUMA nodes):

SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xffffffff]
NUMA: nodes only cover 3583MB of your 4095MB e820 RAM. Not used.

Output after the series is applied:

SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xdfffffff]
SRAT: Node 3 PXM 3 [mem 0x100000000-0x11fffffff]

Quoted 9 lines

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi-build: Fix PCI hole handling on build_srat()

 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

It looks sane to me (which might not mean much of course).

series

#4 lore raw
In reply to Eduardo Habkost
Quoted 69 lines · On Thu, 9 Jan 2014 17:12:41 -0200 Eduardo Habkost <[email protected]> wrote:

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Example Linux guest dmesg output when the bug is present (using -m 4G and 4 1GB NUMA nodes):

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xffffffff]
NUMA: nodes only cover 3583MB of your 4095MB e820 RAM. Not used.
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Output after the series is applied:

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xdfffffff]
SRAT: Node 3 PXM 3 [mem 0x100000000-0x11fffffff]
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Quoted 9 lines

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi-build: Fix PCI hole handling on build_srat()

 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

since purpose of the the block you are touching is to exclude PCI hole from SRAT could you use acpi_get_pci_info() instead?

#5 lore raw
Quoted 10 lines · Igor Mammedov
Quoted 7 lines · On Thu, 9 Jan 2014 17:12:41 -0200 Eduardo Habkost <[email protected]> wrote:

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

[...]

Quoted 5 lines
Quoted 5 lines

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi-build: Fix PCI hole handling on build_srat()

Quoted 8 lines
Quoted 5 lines
 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

since purpose of the the block you are touching is to exclude PCI hole from SRAT could you use acpi_get_pci_info() instead?

That would make sense, but as that was not the original behavior from SeaBIOS, I prefer to first fix this obvious and simple translation mistake, and then make the code able to use acpi_get_pci_info() (which won't be as trivial to write/review as this fix).

(I didn't even review the existing PCI hole exclusion logic myself. I simply made sure that the code matches what's inside SeaBIOS today and is known to work.)

Signature · 1 line
Eduardo
Reviewed-by on the v1 series
#6 lore raw
In reply to Eduardo Habkost
Quoted 8 lines · Eduardo Habkost

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the
build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Looks good to me.

cheers,
Gerd

#7 lore raw
In reply to Eduardo Habkost
Quoted 6 lines · Eduardo Habkost

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Michael, can you pull this into your tree?

Signature · 1 line
Eduardo
#8 lore raw
In reply to Eduardo Habkost
Quoted 59 lines · Eduardo Habkost

The original SeaBIOS code used the RamSize variable, that was used by SeaBIOS for the size of RAM below 4GB, not for all RAM. When copied to QEMU, the code was changed to use the full RAM size, and this broke the build_srat() code that handles the PCI hole.

This series fixes the problem by restoring the original behavior from SeaBIOS.

Example Linux guest dmesg output when the bug is present (using -m 4G and 4 1GB NUMA nodes):

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xffffffff]
NUMA: nodes only cover 3583MB of your 4095MB e820 RAM. Not used.
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Output after the series is applied:

e820: BIOS-provided physical RAM map:
BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
BIOS-e820: [mem 0x0000000000100000-0x00000000dfffdfff] usable
BIOS-e820: [mem 0x00000000dfffe000-0x00000000dfffffff] reserved
BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
BIOS-e820: [mem 0x0000000100000000-0x000000011fffffff] usable
e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
e820: remove [mem 0x000a0000-0x000fffff] usable
e820: last_pfn = 0x120000 max_arch_pfn = 0x400000000
e820: last_pfn = 0xdfffe max_arch_pfn = 0x400000000
ACPI: SRAT 00000000dffffc0e 00160 (v01 BOCHS BXPCSRAT 00000001 BXPC 00000001)
SRAT: PXM 0 -> APIC 0x00 -> Node 0
SRAT: PXM 1 -> APIC 0x01 -> Node 1
SRAT: PXM 2 -> APIC 0x02 -> Node 2
SRAT: PXM 3 -> APIC 0x03 -> Node 3
SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]

Quoted 9 lines

SRAT: Node 0 PXM 0 [mem 0x00100000-0x3fffffff]
SRAT: Node 1 PXM 1 [mem 0x40000000-0x7fffffff]
SRAT: Node 2 PXM 2 [mem 0x80000000-0xbfffffff]
SRAT: Node 3 PXM 3 [mem 0xc0000000-0xdfffffff]
SRAT: Node 3 PXM 3 [mem 0x100000000-0x11fffffff]
e820: [mem 0xe0000000-0xfeffbfff] available for PCI devices
e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
e820: reserve RAM buffer [mem 0xdfffe000-0xdfffffff]

Thanks, applied.

Quoted 11 lines

Eduardo Habkost (2):
pc: Save size of RAM below 4GB
acpi-build: Fix PCI hole handling on build_srat()

 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  1 +
 include/hw/i386/pc.h |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.4.2