Skip to contentSkip to conversation

pc: memhp: enforce minimal 128Mb alignment for pc-dimm

PATCH Superseded Igor Mammedov 3 participants 7 messages Oct 26, 2015 – Oct 27, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: memhp: enforce minimal 128Mb alignment for pc-dimm

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!
...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +5 -0
index 3d958ba..cd68169 100644
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */
+
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
@@ -1624,6 +1626,9 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
 
     if (memory_region_get_alignment(mr) && pcms->enforce_aligned_dimm) {
         align = memory_region_get_alignment(mr);
+        if (pcmc->inter_dimm_gap && (align < MIN_DIMM_ALIGNMENT)) {
+            align = MIN_DIMM_ALIGNMENT;
+        }
     }
 
     if (!pcms->acpi_dev) {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!

This is in portable code. Does this imply anyone implementing inter dimm gaps will need the same value?
Shouldn't this go into portable code then?

Quoted 17 lines

...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

Quoted 1 line

Thanks for the fix. Pls see comments below.

Quoted 9 lines
---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1614

Quoted 5 lines
hw/i386/pc.c +2 -0
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */
+

Pls prefix with PC_ and pls add a comment explaining where does this value come from.

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1629

Quoted 8 lines
hw/i386/pc.c +1 -0
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
@@ -1624,6 +1626,9 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
 
     if (memory_region_get_alignment(mr) && pcms->enforce_aligned_dimm) {
         align = memory_region_get_alignment(mr);
+        if (pcmc->inter_dimm_gap && (align < MIN_DIMM_ALIGNMENT)) {

() not required around math.

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1631

Quoted 2 lines
hw/i386/pc.c +2 -0
+            align = MIN_DIMM_ALIGNMENT;
+        }

This seems wrong. Why is alignment only required when inter_dimm_gap is set? Does this have to do with compatibility somehow? Pls add a comment.

Quoted 5 lines
hw/i386/pc.c +0 -0
     }
 
     if (!pcms->acpi_dev) {
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 10 lines · On Mon, 26 Oct 2015 11:02:10 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!

This is in portable code. Does this imply anyone implementing inter dimm gaps will need the same value?
Shouldn't this go into portable code then?

yep, but PAGE_SECTION_MASK => secstion size is not portable (i.e. it's per target define)

Quoted 35 lines
Quoted 18 lines

...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

Quoted 1 line

Thanks for the fix. Pls see comments below.

Quoted 12 lines
---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
Quoted 5 lines

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1614

Quoted 2 lines
hw/i386/pc.c +2 -0
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */
+

Pls prefix with PC_ and pls add a comment explaining where does this value come from.

sure

Quoted 12 lines

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1629

Quoted 9 lines
hw/i386/pc.c +1 -0
 static void pc_dimm_plug(HotplugHandler *hotplug_dev,
                          DeviceState *dev, Error **errp)
 {
@@ -1624,6 +1626,9 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
 
     if (memory_region_get_alignment(mr) && pcms->enforce_aligned_dimm) {
         align = memory_region_get_alignment(mr);
+        if (pcmc->inter_dimm_gap && (align < MIN_DIMM_ALIGNMENT)) {

() not required around math.

Quoted 5 lines

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1631

Quoted 2 lines
hw/i386/pc.c +2 -0
+            align = MIN_DIMM_ALIGNMENT;
+        }

This seems wrong. Why is alignment only required when inter_dimm_gap is set? Does this have to do with compatibility somehow? Pls add a comment.

indeed, it's keyed on inter_dimm_gap for compatibility reasons.
and since inter_dimm_gap introduced layout change it should be ok
to make fix also depend on inter_dimm_gap and not to touch previous machine types.

I'll respin v2.

Quoted 6 lines
Quoted 6 lines
hw/i386/pc.c +0 -0
     }
 
     if (!pcms->acpi_dev) {
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Igor Mammedov
Quoted 32 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!
...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1613

Quoted 4 lines
hw/i386/pc.c +1 -0
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */

If you send a new version, could you include the explanation for the 128MB value as a comment above the macro definition?

Signature · 1 line
Eduardo
#4 lore raw
Quoted 36 lines · Eduardo Habkost
Quoted 35 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!
...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
Quoted 4 lines

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1613

Quoted 1 line
hw/i386/pc.c +1 -0
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */

If you send a new version, could you include the explanation for the 128MB value as a comment above the macro definition?

The issue is that there's no good explanation yet. It's just something that seems to work for current linux. Why does linux do it, and what basis does it have in hardware, IIUC we don't know.

Quoted 2 lines
Signature · 1 line
Eduardo
#5 lore raw
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Eduardo Habkost
Quoted 35 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!
...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
Quoted 8 lines
Quoted 4 lines

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1613

Quoted 1 line
hw/i386/pc.c +1 -0
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */

If you send a new version, could you include the explanation for the 128MB value as a comment above the macro definition?

The issue is that there's no good explanation yet. It's just something that seems to work for current linux. Why does linux do it, and what basis does it have in hardware, IIUC we don't know.

We just need an explanation to why we chose that value, even if we don't know yet why it works. Even "this is the only value we ever tested and it seems to work, good luck figuring out why" would be better than no explanation, IMO.

Signature · 1 line
Eduardo
#6 lore raw
Quoted 43 lines · Eduardo Habkost
Quoted 42 lines · Michael S. Tsirkin
Quoted 40 lines · Eduardo Habkost
Quoted 32 lines · Igor Mammedov

commit aa8580cd "pc: memhp: force gaps between DIMM's GPA" regressed memory hot-unplug for linux guests triggering following BUGON
=====
kernel BUG at mm/memory_hotplug.c:703!
...

 [<ffffffff81385fa7>] acpi_memory_device_remove+0x79/0xa5
 [<ffffffff81357818>] acpi_bus_trim+0x5a/0x8d
 [<ffffffff81359026>] acpi_device_hotplug+0x1b7/0x418
 ===
    BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK);
 ===

reson for it is that x86-64 linux guest supports memory hotplug in chunks of 128Mb and memory section also should be 128Mb aligned.
However gaps forced between 128Mb DIMMs with backend's natural alignment of 2Mb make the 2nd and following DIMMs not being aligned on 128Mb boundary as it was originally. To fix regression enforce minimal 128Mb alignment like it was done for PPC.

---
 hw/i386/pc.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc.c +0 -0
index 3d958ba..cd68169 100644

hw/i386/pc.c void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) · line 1613

Quoted 4 lines
hw/i386/pc.c +1 -0
@@ -1610,6 +1610,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
     }
 }
 
+#define MIN_DIMM_ALIGNMENT (1ULL << 27) /* 128Mb */

If you send a new version, could you include the explanation for the 128MB value as a comment above the macro definition?

Quoted 8 lines
Quoted 3 lines

The issue is that there's no good explanation yet. It's just something that seems to work for current linux. Why does linux do it, and what basis does it have in hardware, IIUC we don't know.

We just need an explanation to why we chose that value, even if we don't know yet why it works. Even "this is the only value we ever tested and it seems to work, good luck figuring out why" would be better than no explanation, IMO.

Not by much though :)

Quoted 2 lines
Signature · 1 line
Eduardo