Skip to contentSkip to conversation

pc: fix 64-bit PCI window clashing with memory hotplug region

PATCH In review Igor Mammedov 3 participants 7 messages Sep 7, 2015 – Sep 10, 2015

lore
Share & tools
lore
#0 lore raw

cover pc: fix 64-bit PCI window clashing with memory hotplug region

Igor Mammedov (2):
pc: memhotplug: fix incorrectly set reserved-memory-end
pc: memhotplug: keep reserved-memory-end broken on 2.4 and earlier
machines

 hw/i386/pc.c         | 8 +++++++-
 hw/i386/pc_piix.c    | 2 ++
 hw/i386/pc_q35.c     | 2 ++
 include/hw/i386/pc.h | 1 +
 4 files changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 pc: memhotplug: fix incorrectly set reserved-memory-end

reserved-memory-end tells firmware address from which it could start treating memory as PCI address space and map PCI BARs after it to avoid collisions with RAM.
Currently it is incorrectly pointing to address where hotplugged memory range starts which could redirect hotplugged RAM accesses to PCI BARs when firmware maps them over RAM or viceverse.
Fix this by pointing reserved-memory-end to the end of memory hotplug area.

---
 hw/i386/pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/pc.c +3 -1
index 9f2924e..354e1b3 100644
@@ -1412,7 +1412,9 @@ FWCfgState *pc_memory_init(PCMachineState *pcms,
 
     if (guest_info->has_reserved_memory && pcms->hotplug_memory.base) {
         uint64_t *val = g_malloc(sizeof(*val));
-        *val = cpu_to_le64(ROUND_UP(pcms->hotplug_memory.base, 0x1ULL << 30));
+        uint64_t res_mem_end = pcms->hotplug_memory.base +
+                               memory_region_size(&pcms->hotplug_memory.mr);
+        *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
         fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
     }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc: memhotplug: fix incorrectly set reserved-memory-end

Quoted 11 lines · Igor Mammedov

reserved-memory-end tells firmware address from which it could start treating memory as PCI address space and map PCI BARs after it to avoid collisions with RAM.
Currently it is incorrectly pointing to address where hotplugged memory range starts which could redirect hotplugged RAM accesses to PCI BARs when firmware maps them over RAM or viceverse.
Fix this by pointing reserved-memory-end to the end of memory hotplug area.

Quoted 1 line

But I would like to see this squashed into patch 2/2 (or the rebased version of patch 2/2) to keep bisectability.

Signature · 1 line
Eduardo
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc: memhotplug: fix incorrectly set reserved-memory-end

Quoted 12 lines · On Wed, 9 Sep 2015 17:03:56 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 11 lines · Igor Mammedov

reserved-memory-end tells firmware address from which it could start treating memory as PCI address space and map PCI BARs after it to avoid collisions with RAM.
Currently it is incorrectly pointing to address where hotplugged memory range starts which could redirect hotplugged RAM accesses to PCI BARs when firmware maps them over RAM or viceverse.
Fix this by pointing reserved-memory-end to the end of memory hotplug area.

Quoted 6 lines
Quoted 1 line

But I would like to see this squashed into patch 2/2 (or the rebased version of patch 2/2) to keep bisectability.

Eduardo, thanks for review.
It's ok squash 2/2, could you handle it and take it through your tree?

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] pc: memhotplug: fix incorrectly set reserved-memory-end

Quoted 17 lines · Igor Mammedov
Quoted 14 lines · On Wed, 9 Sep 2015 17:03:56 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 12 lines · Igor Mammedov

reserved-memory-end tells firmware address from which it could start treating memory as PCI address space and map PCI BARs after it to avoid collisions with RAM.
Currently it is incorrectly pointing to address where hotplugged memory range starts which could redirect hotplugged RAM accesses to PCI BARs when firmware maps them over RAM or viceverse.
Fix this by pointing reserved-memory-end to the end of memory hotplug area.

Quoted 7 lines
Quoted 4 lines

But I would like to see this squashed into patch 2/2 (or the rebased version of patch 2/2) to keep bisectability.

Eduardo, thanks for review.
It's ok squash 2/2, could you handle it and take it through your tree?

I merged them separately already:
I'm not too concerned about breaking cross version migration being slightly racy when doing bisect.

Signature · 1 line
MST
#5 lore raw

PATCH 2/2 pc: memhotplug: keep reserved-memory-end broken on 2.4 and earlier machines

In reply to Igor Mammedov

it will prevent guests on old machines from seeing inconsistent memory mapping in firmware/ACPI views.

---
PS: this patch probably clashes with Eduardo's
pc_compat refactoring, so I've split it from
main fix, if applied via Eduardo's it could
be squashed in main fix after merging on top
of his patches or as is if goes in first.

---
 hw/i386/pc.c         | 8 ++++++--
 hw/i386/pc_piix.c    | 2 ++
 hw/i386/pc_q35.c     | 2 ++
 include/hw/i386/pc.h | 1 +
 4 files changed, 11 insertions(+), 2 deletions(-)
hw/i386/pc.c +6 -2
index 354e1b3..b5107f7 100644
@@ -1412,8 +1412,12 @@ FWCfgState *pc_memory_init(PCMachineState *pcms,
 
     if (guest_info->has_reserved_memory && pcms->hotplug_memory.base) {
         uint64_t *val = g_malloc(sizeof(*val));
-        uint64_t res_mem_end = pcms->hotplug_memory.base +
-                               memory_region_size(&pcms->hotplug_memory.mr);
+        PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
+        uint64_t res_mem_end = pcms->hotplug_memory.base;
+
+        if (!pcmc->broken_reserved_end) {
+            res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+        }
         *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
         fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
     }
hw/i386/pc_piix.c +2 -0
index b82921d..589f530 100644
@@ -451,7 +451,9 @@ static void pc_i440fx_machine_options(MachineClass *m)
 
 static void pc_i440fx_2_4_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_machine_options(m);
+    pcmc->broken_reserved_end = true;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
     m->alias = "pc";
hw/i386/pc_q35.c +2 -0
index 7217cbf..839d3b9 100644
@@ -370,7 +370,9 @@ static void pc_q35_machine_options(MachineClass *m)
 
 static void pc_q35_2_4_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_machine_options(m);
+    pcmc->broken_reserved_end = true;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
     m->no_floppy = 1;
include/hw/i386/pc.h +1 -0
index d0cad87..ff0b48b 100644
@@ -59,6 +59,7 @@ struct PCMachineClass {
     MachineClass parent_class;
 
     /*< public >*/
+    bool broken_reserved_end;
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
 };
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/2
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] pc: memhotplug: keep reserved-memory-end broken on 2.4 and earlier machines

Quoted 10 lines · Igor Mammedov

it will prevent guests on old machines from seeing inconsistent memory mapping in firmware/ACPI views.

---
PS: this patch probably clashes with Eduardo's
pc_compat refactoring, so I've split it from
main fix, if applied via Eduardo's it could
be squashed in main fix after merging on top
of his patches or as is if goes in first.

It conflicts with my "pc: Initialization and compat function cleanup" series, but my series needs to be rebased because of smbios changes anyway. I can rebase my series after your fix gets in.

[...]

hw/i386/pc.c FWCfgState *pc_memory_init(PCMachineState *pcms, · line 1415

Quoted 11 lines
hw/i386/pc.c +1 -2
index 354e1b3..b5107f7 100644
@@ -1412,8 +1412,12 @@ FWCfgState *pc_memory_init(PCMachineState *pcms,
 
     if (guest_info->has_reserved_memory && pcms->hotplug_memory.base) {
         uint64_t *val = g_malloc(sizeof(*val));
-        uint64_t res_mem_end = pcms->hotplug_memory.base +
-                               memory_region_size(&pcms->hotplug_memory.mr);
+        PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);

Style suggestion: move pcmc to the beginning of the function, because other blocks inside the function are likely to look at PCMachineClass fields in the future.

Quoted 8 lines
hw/i386/pc.c +5 -0
+        uint64_t res_mem_end = pcms->hotplug_memory.base;
+
+        if (!pcmc->broken_reserved_end) {
+            res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+        }
         *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
         fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
     }

[...]

include/hw/i386/pc.h struct PCMachineClass { · line 62

Quoted 9 lines
include/hw/i386/pc.h +1 -0
index d0cad87..ff0b48b 100644
@@ -59,6 +59,7 @@ struct PCMachineClass {
     MachineClass parent_class;
 
     /*< public >*/
+    bool broken_reserved_end;

A comment describing what exactly the new field does would be welcome.

I don't think my suggestions should block the patch, so:

Signature · 1 line
Eduardo