qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v5 0/3] hw/acpi-build: Fix ACPI SRAT Memory Affinity building
@ 2017-08-31 12:04 Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Dou Liyang @ 2017-08-31 12:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, imammedo, mst, rth, Dou Liyang

v4 --> v5:
  - Replace the original way with Eduardo's method.
  - rewrite the testcase.
  - Drop the SLIT date
  - 2.11 develop tree is opened, So, Add the third patch for re-posting it. 

v3 --> v4:
  -add a new testcase.

This patchset fixs an ACPI building bug which caused by no RAM
in the first NUAM node. and also add a new testcase for the bug.

Dou Liyang (2):
  ACPI/unit-test: Add a new testcase for RAM allocation in numa node
  NUMA: Replace MAX_NODES with nb_numa_nodes in for loop

Eduardo Habkost (1):
  hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM

 hw/i386/acpi-build.c                  |  30 +++++++++++++++++++++++-------
 numa.c                                |   2 +-
 tests/acpi-test-data/pc/DSDT.numamem  | Bin 0 -> 5104 bytes
 tests/acpi-test-data/pc/SRAT.numamem  | Bin 0 -> 224 bytes
 tests/acpi-test-data/q35/DSDT.numamem | Bin 0 -> 7788 bytes
 tests/acpi-test-data/q35/SRAT.numamem | Bin 0 -> 224 bytes
 tests/bios-tables-test.c              |  24 ++++++++++++++++++++++++
 7 files changed, 48 insertions(+), 8 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/DSDT.numamem
 create mode 100644 tests/acpi-test-data/pc/SRAT.numamem
 create mode 100644 tests/acpi-test-data/q35/DSDT.numamem
 create mode 100644 tests/acpi-test-data/q35/SRAT.numamem

-- 
2.5.5

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

* [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-08-31 12:04 [Qemu-devel] [PATCH v5 0/3] hw/acpi-build: Fix ACPI SRAT Memory Affinity building Dou Liyang
@ 2017-08-31 12:04 ` Dou Liyang
  2017-08-31 21:36   ` Eduardo Habkost
  2017-09-04  9:39   ` Igor Mammedov
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 2/3] ACPI/unit-test: Add a new testcase for RAM allocation in numa node Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 3/3] NUMA: Replace MAX_NODES with nb_numa_nodes in for loop Dou Liyang
  2 siblings, 2 replies; 10+ messages in thread
From: Dou Liyang @ 2017-08-31 12:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, imammedo, mst, rth, Dou Liyang

From: Eduardo Habkost <ehabkost@redhat.com>

Currently, Using the fisrt node without memory on the machine makes
QEMU unhappy. With this example command line:
  ... \
  -m 1024M,slots=4,maxmem=32G \
  -numa node,nodeid=0 \
  -numa node,mem=1024M,nodeid=1 \
  -numa node,nodeid=2 \
  -numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is
wrong.

This is because when QEMU builds ACPI SRAT, it regards node 0 as the
default node to deal with the memory hole(640K-1M). this means the
node0 must have some memory(>1M), but, actually it can have no
memory.

Fix this problem by  cut out the 640K hole in the same way the PCI
4G hole does. Also do some cleanup.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
---
 hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 98dd424..48525a1 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
                  (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
 }
 
+#define HOLE_640K_START  (640 * 1024)
+#define HOLE_640K_END   (1024 * 1024)
+
 static void
 build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
 {
@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     next_base = 0;
     numa_start = table_data->len;
 
-    numamem = acpi_data_push(table_data, sizeof *numamem);
-    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
-    next_base = 1024 * 1024;
     for (i = 1; i < pcms->numa_nodes + 1; ++i) {
         mem_base = next_base;
         mem_len = pcms->node_mem[i - 1];
-        if (i == 1) {
-            mem_len -= 1024 * 1024;
-        }
         next_base = mem_base + mem_len;
 
+        /* Cut out the 640K hole */
+        if (mem_base <= HOLE_640K_START &&
+            next_base > HOLE_640K_START) {
+            mem_len -= next_base - HOLE_640K_START;
+            if (mem_len > 0) {
+                numamem = acpi_data_push(table_data, sizeof *numamem);
+                build_srat_memory(numamem, mem_base, mem_len, i - 1,
+                                  MEM_AFFINITY_ENABLED);
+            }
+
+            /* Check for the rare case: 640K < RAM < 1M */
+            if (next_base <= HOLE_640K_END) {
+                next_base = HOLE_640K_END;
+                continue;
+            }
+            mem_base = HOLE_640K_END;
+            mem_len = next_base - HOLE_640K_END;
+        }
+
         /* Cut out the ACPI_PCI hole */
         if (mem_base <= pcms->below_4g_mem_size &&
             next_base > pcms->below_4g_mem_size) {
@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
             }
             mem_base = 1ULL << 32;
             mem_len = next_base - pcms->below_4g_mem_size;
-            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
+            next_base = mem_base + mem_len;
         }
         numamem = acpi_data_push(table_data, sizeof *numamem);
         build_srat_memory(numamem, mem_base, mem_len, i - 1,
-- 
2.5.5

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

* [Qemu-devel] [PATCH v5 2/3] ACPI/unit-test: Add a new testcase for RAM allocation in numa node
  2017-08-31 12:04 [Qemu-devel] [PATCH v5 0/3] hw/acpi-build: Fix ACPI SRAT Memory Affinity building Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
@ 2017-08-31 12:04 ` Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 3/3] NUMA: Replace MAX_NODES with nb_numa_nodes in for loop Dou Liyang
  2 siblings, 0 replies; 10+ messages in thread
From: Dou Liyang @ 2017-08-31 12:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, imammedo, mst, rth, Dou Liyang

As QEMU supports the memory-less node, it is possible that there is
no RAM in the first numa node(also be called as node0). eg:
  ... \
  -m 128,slots=3,maxmem=1G \
  -numa node -numa node,mem=128M \

But, this makes it hard for QEMU to build a known-to-work ACPI SRAT
table. Only fixing it is not enough.

Add a testcase for this situation to make sure the ACPI table is
correct for guest.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
---
 tests/acpi-test-data/pc/DSDT.numamem  | Bin 0 -> 5104 bytes
 tests/acpi-test-data/pc/SRAT.numamem  | Bin 0 -> 224 bytes
 tests/acpi-test-data/q35/DSDT.numamem | Bin 0 -> 7788 bytes
 tests/acpi-test-data/q35/SRAT.numamem | Bin 0 -> 224 bytes
 tests/bios-tables-test.c              |  24 ++++++++++++++++++++++++
 5 files changed, 24 insertions(+)
 create mode 100644 tests/acpi-test-data/pc/DSDT.numamem
 create mode 100644 tests/acpi-test-data/pc/SRAT.numamem
 create mode 100644 tests/acpi-test-data/q35/DSDT.numamem
 create mode 100644 tests/acpi-test-data/q35/SRAT.numamem

diff --git a/tests/acpi-test-data/pc/DSDT.numamem b/tests/acpi-test-data/pc/DSDT.numamem
new file mode 100644
index 0000000000000000000000000000000000000000..bc703d77ee48720af1b801c518b43511c95c852d
GIT binary patch
literal 5104
zcmb7IZExE~5}qX~n_5aXWizjC8^L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cN)JPMzd}SMZ7%*!jG(iRPVrb8bpu=roRRH0M+WyFu*pP`XJP
z3PAtU@$$LdYs-HzmqQ2cm8u(<5II6mc&x|t7*#{P<ZlLjP4#iG`b8`;7>4F#GT1}X
z4-mKeu9F=KxZV;N$d<LRi=;tL4DvK^yYD#JJNTlrQ5*h%!B=E3=7MyiK8p;HnxHwN
zB`97KXbPd&u0}uwYfM06QP8|##S0>2or;7C)@cEqj)LA0tk`~stZF1wu*L;69tFKA
zSh;}mNT^`N#0wqJqM)|~YeGO1kx;>!6wqW8^tND~5zv`Ps9?ngF!Xgc3VKJd>H?}q
zLIrC|KvPlB_XX>mfX+oi1?#+k&PPEDf)z7A49kdw3f40MdL{~56s%_j^lT(lu$~jp
zb5T%Ju$~vt^N~=&dO<)hL_saVdQm_xMnVPaf`BeWK}&-54FP>45-M2V6wo)Lpv!{w
zEdhNi5-M0P3FxKMphkJYx?gKZy~J)C@6tW0b&mo;M**u@D5Oacnk5vlB88d`38YEx
zwl%zn_Z%!MLrEfOq*GAB;xN>at(zkq8N(w!)RDDYBORH;gF4iaz1yUl-ECua#am?0
z!2>5`yhl(z*5hrm=it#1dTbU@KGy3b;~^0GbRZw=mq^BR7Wz&gAM1mNF)@W6FOxmT
z9Me<Om|`P6#chr0DRNAfkv>iGn0^Um-1d>aLo(`(OVoJae}w3#J#8W0bsKCru(<pS
DEH%hI

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/pc/SRAT.numamem b/tests/acpi-test-data/pc/SRAT.numamem
new file mode 100644
index 0000000000000000000000000000000000000000..dbc595d9cb85d3fcb5a4243153f42bb431c9de8f
GIT binary patch
literal 224
zcmWFzatwLEz`(%x#mV2<BUr&HBEUHqD8>jB1F=Cg2*ZH@DxXmUE`z~9*2k!U%mXRq
Yf~!ZCL8t>-1O^}2VG2>z!9?-X08OU~0RR91

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/q35/DSDT.numamem b/tests/acpi-test-data/q35/DSDT.numamem
new file mode 100644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
zcY}I1MD^+3OIufMwH`noY3xTwgY9H9iVZ|OJinjZL8BkIvvKd`u{~?62XWBMkfYNT
zvXWh)hl%|M^_j2}t~)2$u;On^x&0U`8Sy|QJH-qSYxbBSJ`$L&Bps7)4aP<W_P~mt
zuG+);cvpNpCwJwh$NK^ueN8snoDMfSUGF5L6OY%}VBvUhcY?2hn@YA4_5EZcreNae
zdY`V^bXwsG!v|+5PA%tvPB5H=%~H3Ja~*;I^Yo+_<oa}m(@7zM87u^LbL32H-+dp~
z>)TBcT)-J!YgPJ{;x!yIUag|Dn+~)e&>p@HN9TF*bu46h@*0qfkF<PMo^t>6MP8)v
z-x{AI`oeP5p?Bz64%#gb>lZ@&fZd1QG0tQ0MTq}?j+=tqPtTJ_NAx^NpOoM|{Im-A
z?C9vbA9;s(_9iV`g*JvJ7eDi@^;WTjp~?FMwQDyBEI@WkZcauP-yoK=%UKI+U;fXw
zAn9E1&t+{3g|Pivf6lSpl#8VrpkLA+D(e5{h2`GftJPbfygBDLE6tlY64!{GsN!e*
z4BdwOb$g4~pQ^T8cg%H)MJ%|{3T<!i=bhrOB*5%g0*TRCiLm5G8`spvb>7If!u78B
EKkzjyY5)KL

literal 0
HcmV?d00001

diff --git a/tests/acpi-test-data/q35/SRAT.numamem b/tests/acpi-test-data/q35/SRAT.numamem
new file mode 100644
index 0000000000000000000000000000000000000000..dbc595d9cb85d3fcb5a4243153f42bb431c9de8f
GIT binary patch
literal 224
zcmWFzatwLEz`(%x#mV2<BUr&HBEUHqD8>jB1F=Cg2*ZH@DxXmUE`z~9*2k!U%mXRq
Yf~!ZCL8t>-1O^}2VG2>z!9?-X08OU~0RR91

literal 0
HcmV?d00001

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 564da45..f092315 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -808,6 +808,28 @@ static void test_acpi_piix4_tcg_memhp(void)
     free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_numamem(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".numamem";
+    test_acpi_one(" -numa node -numa node,mem=128", &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_piix4_tcg_numamem(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".numamem";
+    test_acpi_one(" -numa node -numa node,mem=128", &data);
+    free_test_data(&data);
+}
+
 int main(int argc, char *argv[])
 {
     const char *arch = qtest_get_arch();
@@ -830,6 +852,8 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/cpuhp", test_acpi_q35_tcg_cphp);
         qtest_add_func("acpi/piix4/memhp", test_acpi_piix4_tcg_memhp);
         qtest_add_func("acpi/q35/memhp", test_acpi_q35_tcg_memhp);
+        qtest_add_func("acpi/piix4/numamem", test_acpi_piix4_tcg_numamem);
+        qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
     }
     ret = g_test_run();
     boot_sector_cleanup(disk);
-- 
2.5.5

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

* [Qemu-devel] [PATCH v5 3/3] NUMA: Replace MAX_NODES with nb_numa_nodes in for loop
  2017-08-31 12:04 [Qemu-devel] [PATCH v5 0/3] hw/acpi-build: Fix ACPI SRAT Memory Affinity building Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 2/3] ACPI/unit-test: Add a new testcase for RAM allocation in numa node Dou Liyang
@ 2017-08-31 12:04 ` Dou Liyang
  2 siblings, 0 replies; 10+ messages in thread
From: Dou Liyang @ 2017-08-31 12:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: ehabkost, imammedo, mst, rth, Dou Liyang

In QEMU, the number of the NUMA nodes is determined by parse_numa_opts().
Then, QEMU uses it for iteration, for example:
  for (i = 0; i < nb_numa_nodes; i++)

However, in memory_region_allocate_system_memory(), it uses MAX_NODES
not nb_numa_nodes.

So, replace MAX_NODES with nb_numa_nodes to keep code consistency and
reduce the loop times.

Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/numa.c b/numa.c
index e32af04..5f2916d 100644
--- a/numa.c
+++ b/numa.c
@@ -567,7 +567,7 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
     }
 
     memory_region_init(mr, owner, name, ram_size);
-    for (i = 0; i < MAX_NODES; i++) {
+    for (i = 0; i < nb_numa_nodes; i++) {
         uint64_t size = numa_info[i].node_mem;
         HostMemoryBackend *backend = numa_info[i].node_memdev;
         if (!backend) {
-- 
2.5.5

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
@ 2017-08-31 21:36   ` Eduardo Habkost
  2017-09-01  1:29     ` Dou Liyang
  2017-09-04  9:39   ` Igor Mammedov
  1 sibling, 1 reply; 10+ messages in thread
From: Eduardo Habkost @ 2017-08-31 21:36 UTC (permalink / raw)
  To: Dou Liyang; +Cc: qemu-devel, imammedo, mst, rth

On Thu, Aug 31, 2017 at 08:04:26PM +0800, Dou Liyang wrote:
> From: Eduardo Habkost <ehabkost@redhat.com>
> 
> Currently, Using the fisrt node without memory on the machine makes
> QEMU unhappy. With this example command line:
>   ... \
>   -m 1024M,slots=4,maxmem=32G \
>   -numa node,nodeid=0 \
>   -numa node,mem=1024M,nodeid=1 \
>   -numa node,nodeid=2 \
>   -numa node,nodeid=3 \
> Guest reports "No NUMA configuration found" and the NUMA topology is
> wrong.
> 
> This is because when QEMU builds ACPI SRAT, it regards node 0 as the
> default node to deal with the memory hole(640K-1M). this means the
> node0 must have some memory(>1M), but, actually it can have no
> memory.
> 
> Fix this problem by  cut out the 640K hole in the same way the PCI
> 4G hole does. Also do some cleanup.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
> ---
>  hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 98dd424..48525a1 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
>                   (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
>  }
>  
> +#define HOLE_640K_START  (640 * 1024)
> +#define HOLE_640K_END   (1024 * 1024)
> +
>  static void
>  build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>  {
> @@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>      next_base = 0;
>      numa_start = table_data->len;
>  
> -    numamem = acpi_data_push(table_data, sizeof *numamem);
> -    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
> -    next_base = 1024 * 1024;
>      for (i = 1; i < pcms->numa_nodes + 1; ++i) {
>          mem_base = next_base;
>          mem_len = pcms->node_mem[i - 1];
> -        if (i == 1) {
> -            mem_len -= 1024 * 1024;
> -        }
>          next_base = mem_base + mem_len;
>  
> +        /* Cut out the 640K hole */
> +        if (mem_base <= HOLE_640K_START &&
> +            next_base > HOLE_640K_START) {
> +            mem_len -= next_base - HOLE_640K_START;
> +            if (mem_len > 0) {
> +                numamem = acpi_data_push(table_data, sizeof *numamem);
> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
> +                                  MEM_AFFINITY_ENABLED);
> +            }
> +
> +            /* Check for the rare case: 640K < RAM < 1M */
> +            if (next_base <= HOLE_640K_END) {
> +                next_base = HOLE_640K_END;
> +                continue;
> +            }
> +            mem_base = HOLE_640K_END;
> +            mem_len = next_base - HOLE_640K_END;
> +        }
> +
>          /* Cut out the ACPI_PCI hole */
>          if (mem_base <= pcms->below_4g_mem_size &&
>              next_base > pcms->below_4g_mem_size) {
> @@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>              }
>              mem_base = 1ULL << 32;
>              mem_len = next_base - pcms->below_4g_mem_size;
> -            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
> +            next_base = mem_base + mem_len;

Is this extra change intentional?

I find the code more readable with it, but it should go in a
separate patch because it is unrelated to the bug fix.

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-08-31 21:36   ` Eduardo Habkost
@ 2017-09-01  1:29     ` Dou Liyang
  0 siblings, 0 replies; 10+ messages in thread
From: Dou Liyang @ 2017-09-01  1:29 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, imammedo, mst, rth

Hi, Eduardo

At 09/01/2017 05:36 AM, Eduardo Habkost wrote:
> On Thu, Aug 31, 2017 at 08:04:26PM +0800, Dou Liyang wrote:
>> From: Eduardo Habkost <ehabkost@redhat.com>
>>
>> Currently, Using the fisrt node without memory on the machine makes
>> QEMU unhappy. With this example command line:
>>   ... \
>>   -m 1024M,slots=4,maxmem=32G \
>>   -numa node,nodeid=0 \
>>   -numa node,mem=1024M,nodeid=1 \
>>   -numa node,nodeid=2 \
>>   -numa node,nodeid=3 \
>> Guest reports "No NUMA configuration found" and the NUMA topology is
>> wrong.
>>
>> This is because when QEMU builds ACPI SRAT, it regards node 0 as the
>> default node to deal with the memory hole(640K-1M). this means the
>> node0 must have some memory(>1M), but, actually it can have no
>> memory.
>>
>> Fix this problem by  cut out the 640K hole in the same way the PCI
>> 4G hole does. Also do some cleanup.
>>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
>> ---
>>  hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
>>  1 file changed, 23 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>> index 98dd424..48525a1 100644
>> --- a/hw/i386/acpi-build.c
>> +++ b/hw/i386/acpi-build.c
>> @@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
>>                   (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
>>  }
>>
>> +#define HOLE_640K_START  (640 * 1024)
>> +#define HOLE_640K_END   (1024 * 1024)
>> +
>>  static void
>>  build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>  {
>> @@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>      next_base = 0;
>>      numa_start = table_data->len;
>>
>> -    numamem = acpi_data_push(table_data, sizeof *numamem);
>> -    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
>> -    next_base = 1024 * 1024;
>>      for (i = 1; i < pcms->numa_nodes + 1; ++i) {
>>          mem_base = next_base;
>>          mem_len = pcms->node_mem[i - 1];
>> -        if (i == 1) {
>> -            mem_len -= 1024 * 1024;
>> -        }
>>          next_base = mem_base + mem_len;
>>
>> +        /* Cut out the 640K hole */
>> +        if (mem_base <= HOLE_640K_START &&
>> +            next_base > HOLE_640K_START) {
>> +            mem_len -= next_base - HOLE_640K_START;
>> +            if (mem_len > 0) {
>> +                numamem = acpi_data_push(table_data, sizeof *numamem);
>> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
>> +                                  MEM_AFFINITY_ENABLED);
>> +            }
>> +
>> +            /* Check for the rare case: 640K < RAM < 1M */
>> +            if (next_base <= HOLE_640K_END) {
>> +                next_base = HOLE_640K_END;
>> +                continue;
>> +            }
>> +            mem_base = HOLE_640K_END;
>> +            mem_len = next_base - HOLE_640K_END;
>> +        }
>> +
>>          /* Cut out the ACPI_PCI hole */
>>          if (mem_base <= pcms->below_4g_mem_size &&
>>              next_base > pcms->below_4g_mem_size) {
>> @@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>              }
>>              mem_base = 1ULL << 32;
>>              mem_len = next_base - pcms->below_4g_mem_size;
>> -            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
>> +            next_base = mem_base + mem_len;
>
> Is this extra change intentional?
>

Yes, it is, Just for readability. :-)

> I find the code more readable with it, but it should go in a
> separate patch because it is unrelated to the bug fix.
>

Indeed, I will split it out.

Thanks,
	dou.

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
  2017-08-31 21:36   ` Eduardo Habkost
@ 2017-09-04  9:39   ` Igor Mammedov
  2017-09-04 10:16     ` Dou Liyang
  1 sibling, 1 reply; 10+ messages in thread
From: Igor Mammedov @ 2017-09-04  9:39 UTC (permalink / raw)
  To: Dou Liyang; +Cc: qemu-devel, ehabkost, mst, rth

On Thu, 31 Aug 2017 20:04:26 +0800
Dou Liyang <douly.fnst@cn.fujitsu.com> wrote:

> From: Eduardo Habkost <ehabkost@redhat.com>
> 
> Currently, Using the fisrt node without memory on the machine makes
> QEMU unhappy. With this example command line:
>   ... \
>   -m 1024M,slots=4,maxmem=32G \
>   -numa node,nodeid=0 \
>   -numa node,mem=1024M,nodeid=1 \
>   -numa node,nodeid=2 \
>   -numa node,nodeid=3 \
> Guest reports "No NUMA configuration found" and the NUMA topology is
> wrong.
> 
> This is because when QEMU builds ACPI SRAT, it regards node 0 as the
> default node to deal with the memory hole(640K-1M). this means the
> node0 must have some memory(>1M), but, actually it can have no
> memory.
> 
> Fix this problem by  cut out the 640K hole in the same way the PCI
> 4G hole does. Also do some cleanup.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
> ---
>  hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 98dd424..48525a1 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
>                   (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
>  }
>  
> +#define HOLE_640K_START  (640 * 1024)
> +#define HOLE_640K_END   (1024 * 1024)
> +
>  static void
>  build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>  {
> @@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>      next_base = 0;
>      numa_start = table_data->len;
>  
> -    numamem = acpi_data_push(table_data, sizeof *numamem);
> -    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
> -    next_base = 1024 * 1024;
>      for (i = 1; i < pcms->numa_nodes + 1; ++i) {
>          mem_base = next_base;
>          mem_len = pcms->node_mem[i - 1];
> -        if (i == 1) {
> -            mem_len -= 1024 * 1024;
> -        }
>          next_base = mem_base + mem_len;
>  
> +        /* Cut out the 640K hole */
> +        if (mem_base <= HOLE_640K_START &&
> +            next_base > HOLE_640K_START) {
> +            mem_len -= next_base - HOLE_640K_START;
> +            if (mem_len > 0) {
> +                numamem = acpi_data_push(table_data, sizeof *numamem);
> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
> +                                  MEM_AFFINITY_ENABLED);
> +            }
> +
> +            /* Check for the rare case: 640K < RAM < 1M */
> +            if (next_base <= HOLE_640K_END) {
> +                next_base = HOLE_640K_END;
Is this assignment really necessary?

it seems that next_base will be set at the start of the loop.

> +                continue;
> +            }
> +            mem_base = HOLE_640K_END;
> +            mem_len = next_base - HOLE_640K_END;
> +        }
> +
>          /* Cut out the ACPI_PCI hole */
>          if (mem_base <= pcms->below_4g_mem_size &&
>              next_base > pcms->below_4g_mem_size) {
> @@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>              }
>              mem_base = 1ULL << 32;
>              mem_len = next_base - pcms->below_4g_mem_size;
> -            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
> +            next_base = mem_base + mem_len;
>          }
>          numamem = acpi_data_push(table_data, sizeof *numamem);
>          build_srat_memory(numamem, mem_base, mem_len, i - 1,

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-09-04  9:39   ` Igor Mammedov
@ 2017-09-04 10:16     ` Dou Liyang
  2017-09-04 11:11       ` Igor Mammedov
  0 siblings, 1 reply; 10+ messages in thread
From: Dou Liyang @ 2017-09-04 10:16 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, ehabkost, mst, rth



At 09/04/2017 05:39 PM, Igor Mammedov wrote:
> On Thu, 31 Aug 2017 20:04:26 +0800
> Dou Liyang <douly.fnst@cn.fujitsu.com> wrote:
>
>> From: Eduardo Habkost <ehabkost@redhat.com>
>>
>> Currently, Using the fisrt node without memory on the machine makes
>> QEMU unhappy. With this example command line:
>>   ... \
>>   -m 1024M,slots=4,maxmem=32G \
>>   -numa node,nodeid=0 \
>>   -numa node,mem=1024M,nodeid=1 \
>>   -numa node,nodeid=2 \
>>   -numa node,nodeid=3 \
>> Guest reports "No NUMA configuration found" and the NUMA topology is
>> wrong.
>>
>> This is because when QEMU builds ACPI SRAT, it regards node 0 as the
>> default node to deal with the memory hole(640K-1M). this means the
>> node0 must have some memory(>1M), but, actually it can have no
>> memory.
>>
>> Fix this problem by  cut out the 640K hole in the same way the PCI
>> 4G hole does. Also do some cleanup.
>>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
>> ---
>>  hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
>>  1 file changed, 23 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>> index 98dd424..48525a1 100644
>> --- a/hw/i386/acpi-build.c
>> +++ b/hw/i386/acpi-build.c
>> @@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
>>                   (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
>>  }
>>
>> +#define HOLE_640K_START  (640 * 1024)
>> +#define HOLE_640K_END   (1024 * 1024)
>> +
>>  static void
>>  build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>  {
>> @@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>      next_base = 0;
>>      numa_start = table_data->len;
>>
>> -    numamem = acpi_data_push(table_data, sizeof *numamem);
>> -    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
>> -    next_base = 1024 * 1024;
>>      for (i = 1; i < pcms->numa_nodes + 1; ++i) {
>>          mem_base = next_base;
>>          mem_len = pcms->node_mem[i - 1];
>> -        if (i == 1) {
>> -            mem_len -= 1024 * 1024;
>> -        }
>>          next_base = mem_base + mem_len;
>>
>> +        /* Cut out the 640K hole */
>> +        if (mem_base <= HOLE_640K_START &&
>> +            next_base > HOLE_640K_START) {
>> +            mem_len -= next_base - HOLE_640K_START;
>> +            if (mem_len > 0) {
>> +                numamem = acpi_data_push(table_data, sizeof *numamem);
>> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
>> +                                  MEM_AFFINITY_ENABLED);
>> +            }
>> +
>> +            /* Check for the rare case: 640K < RAM < 1M */
>> +            if (next_base <= HOLE_640K_END) {
>> +                next_base = HOLE_640K_END;
> Is this assignment really necessary?
>

It is necessary, because we set mem_base to next_base before setting
next_base;

But, I can refine it:

                                    MEM_AFFINITY_ENABLED);
              }

+            mem_base = HOLE_640K_END;
              /* Check for the rare case: 640K < RAM < 1M */
              if (next_base <= HOLE_640K_END) {
-                next_base = HOLE_640K_END;
                  continue;
              }
-            mem_base = HOLE_640K_END;
              mem_len = next_base - HOLE_640K_END;
          }

Is it?

Thanks,
	dou.

> it seems that next_base will be set at the start of the loop.
>


>> +                continue;
>> +            }
>> +            mem_base = HOLE_640K_END;
>> +            mem_len = next_base - HOLE_640K_END;
>> +        }
>> +
>>          /* Cut out the ACPI_PCI hole */
>>          if (mem_base <= pcms->below_4g_mem_size &&
>>              next_base > pcms->below_4g_mem_size) {
>> @@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
>>              }
>>              mem_base = 1ULL << 32;
>>              mem_len = next_base - pcms->below_4g_mem_size;
>> -            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
>> +            next_base = mem_base + mem_len;
>>          }
>>          numamem = acpi_data_push(table_data, sizeof *numamem);
>>          build_srat_memory(numamem, mem_base, mem_len, i - 1,
>
>
>
>

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-09-04 10:16     ` Dou Liyang
@ 2017-09-04 11:11       ` Igor Mammedov
  2017-09-05  0:59         ` Dou Liyang
  0 siblings, 1 reply; 10+ messages in thread
From: Igor Mammedov @ 2017-09-04 11:11 UTC (permalink / raw)
  To: Dou Liyang; +Cc: qemu-devel, ehabkost, mst, rth

On Mon, 4 Sep 2017 18:16:31 +0800
Dou Liyang <douly.fnst@cn.fujitsu.com> wrote:

> At 09/04/2017 05:39 PM, Igor Mammedov wrote:
> > On Thu, 31 Aug 2017 20:04:26 +0800
> > Dou Liyang <douly.fnst@cn.fujitsu.com> wrote:
> >  
> >> From: Eduardo Habkost <ehabkost@redhat.com>
> >>
> >> Currently, Using the fisrt node without memory on the machine makes
> >> QEMU unhappy. With this example command line:
> >>   ... \
> >>   -m 1024M,slots=4,maxmem=32G \
> >>   -numa node,nodeid=0 \
> >>   -numa node,mem=1024M,nodeid=1 \
> >>   -numa node,nodeid=2 \
> >>   -numa node,nodeid=3 \
> >> Guest reports "No NUMA configuration found" and the NUMA topology is
> >> wrong.
> >>
> >> This is because when QEMU builds ACPI SRAT, it regards node 0 as the
> >> default node to deal with the memory hole(640K-1M). this means the
> >> node0 must have some memory(>1M), but, actually it can have no
> >> memory.
> >>
> >> Fix this problem by  cut out the 640K hole in the same way the PCI
> >> 4G hole does. Also do some cleanup.
> >>
> >> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >> Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
> >> ---
> >>  hw/i386/acpi-build.c | 30 +++++++++++++++++++++++-------
> >>  1 file changed, 23 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> >> index 98dd424..48525a1 100644
> >> --- a/hw/i386/acpi-build.c
> >> +++ b/hw/i386/acpi-build.c
> >> @@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker)
> >>                   (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
> >>  }
> >>
> >> +#define HOLE_640K_START  (640 * 1024)
> >> +#define HOLE_640K_END   (1024 * 1024)
> >> +
> >>  static void
> >>  build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> >>  {
> >> @@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> >>      next_base = 0;
> >>      numa_start = table_data->len;
> >>
> >> -    numamem = acpi_data_push(table_data, sizeof *numamem);
> >> -    build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);
> >> -    next_base = 1024 * 1024;
> >>      for (i = 1; i < pcms->numa_nodes + 1; ++i) {
> >>          mem_base = next_base;
> >>          mem_len = pcms->node_mem[i - 1];
> >> -        if (i == 1) {
> >> -            mem_len -= 1024 * 1024;
> >> -        }
> >>          next_base = mem_base + mem_len;
> >>
> >> +        /* Cut out the 640K hole */
> >> +        if (mem_base <= HOLE_640K_START &&
> >> +            next_base > HOLE_640K_START) {
> >> +            mem_len -= next_base - HOLE_640K_START;
> >> +            if (mem_len > 0) {
> >> +                numamem = acpi_data_push(table_data, sizeof *numamem);
> >> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
> >> +                                  MEM_AFFINITY_ENABLED);
> >> +            }
> >> +
> >> +            /* Check for the rare case: 640K < RAM < 1M */
> >> +            if (next_base <= HOLE_640K_END) {
> >> +                next_base = HOLE_640K_END;  
> > Is this assignment really necessary?
> >  
> 
> It is necessary, because we set mem_base to next_base before setting
> next_base;
> 
> But, I can refine it:
> 
>                                     MEM_AFFINITY_ENABLED);
>               }
> 
> +            mem_base = HOLE_640K_END;
>               /* Check for the rare case: 640K < RAM < 1M */
>               if (next_base <= HOLE_640K_END) {
> -                next_base = HOLE_640K_END;
>                   continue;
>               }
> -            mem_base = HOLE_640K_END;
>               mem_len = next_base - HOLE_640K_END;
>           }
> 
> Is it?
I was wrong, so just leave it as it is now.

> 
> Thanks,
> 	dou.
> 
> > it seems that next_base will be set at the start of the loop.
> >  
> 
> 
> >> +                continue;
> >> +            }
> >> +            mem_base = HOLE_640K_END;
> >> +            mem_len = next_base - HOLE_640K_END;
> >> +        }
> >> +
> >>          /* Cut out the ACPI_PCI hole */
> >>          if (mem_base <= pcms->below_4g_mem_size &&
> >>              next_base > pcms->below_4g_mem_size) {
> >> @@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> >>              }
> >>              mem_base = 1ULL << 32;
> >>              mem_len = next_base - pcms->below_4g_mem_size;
> >> -            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
> >> +            next_base = mem_base + mem_len;
> >>          }
> >>          numamem = acpi_data_push(table_data, sizeof *numamem);
> >>          build_srat_memory(numamem, mem_base, mem_len, i - 1,  
> >
> >
> >
> >  
> 
> 

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

* Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
  2017-09-04 11:11       ` Igor Mammedov
@ 2017-09-05  0:59         ` Dou Liyang
  0 siblings, 0 replies; 10+ messages in thread
From: Dou Liyang @ 2017-09-05  0:59 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, ehabkost, mst, rth

Hi Igor,

At 09/04/2017 07:11 PM, Igor Mammedov wrote:
[...]
>>>> +        if (mem_base <= HOLE_640K_START &&
>>>> +            next_base > HOLE_640K_START) {
>>>> +            mem_len -= next_base - HOLE_640K_START;
>>>> +            if (mem_len > 0) {
>>>> +                numamem = acpi_data_push(table_data, sizeof *numamem);
>>>> +                build_srat_memory(numamem, mem_base, mem_len, i - 1,
>>>> +                                  MEM_AFFINITY_ENABLED);
>>>> +            }
>>>> +
>>>> +            /* Check for the rare case: 640K < RAM < 1M */
>>>> +            if (next_base <= HOLE_640K_END) {
>>>> +                next_base = HOLE_640K_END;
>>> Is this assignment really necessary?
>>>
>>
>> It is necessary, because we set mem_base to next_base before setting
>> next_base;
>>
>> But, I can refine it:
>>
>>                                     MEM_AFFINITY_ENABLED);
>>               }
>>
>> +            mem_base = HOLE_640K_END;
>>               /* Check for the rare case: 640K < RAM < 1M */
>>               if (next_base <= HOLE_640K_END) {
>> -                next_base = HOLE_640K_END;
>>                   continue;
>>               }
>> -            mem_base = HOLE_640K_END;
>>               mem_len = next_base - HOLE_640K_END;
>>           }
>>
>> Is it?
> I was wrong, so just leave it as it is now.
>

OK, I see.

Thanks,
	dou.

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

end of thread, other threads:[~2017-09-05  0:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 12:04 [Qemu-devel] [PATCH v5 0/3] hw/acpi-build: Fix ACPI SRAT Memory Affinity building Dou Liyang
2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM Dou Liyang
2017-08-31 21:36   ` Eduardo Habkost
2017-09-01  1:29     ` Dou Liyang
2017-09-04  9:39   ` Igor Mammedov
2017-09-04 10:16     ` Dou Liyang
2017-09-04 11:11       ` Igor Mammedov
2017-09-05  0:59         ` Dou Liyang
2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 2/3] ACPI/unit-test: Add a new testcase for RAM allocation in numa node Dou Liyang
2017-08-31 12:04 ` [Qemu-devel] [PATCH v5 3/3] NUMA: Replace MAX_NODES with nb_numa_nodes in for loop Dou Liyang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).