ACPI: NUMA: Fix ACPI SRAT Memory Affinity building
v6 cover ACPI: NUMA: Fix ACPI SRAT Memory Affinity building
v5 --> v6:
- Split the unrelated code into a separate patch [2/4]
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 (3):
hw/acpi-build: Make assignment statement of next_base easy to read 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
Signature · 1 line
2.5.5
PATCH v6 1/4 hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
From: Eduardo Habkost <[email protected]>
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.
--- hw/i386/acpi-build.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
hw/i386/acpi-build.c +22 -6
@@ -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) {
Signature · 1 line
2.5.5
PATCH v6 2/4 hw/acpi-build: Make assignment statement of next_base easy to read
In reply to Dou LiyangIt may be hard to read the assignment statement of "next_base", so
S/next_base += (1ULL << 32) - pcms->below_4g_mem_size;
/next_base = mem_base + mem_len;
... for readability.
No functionality change.
--- hw/i386/acpi-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/acpi-build.c +1 -1
@@ -2411,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,
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH v6 2/4] hw/acpi-build: Make assignment statement of next_base easy to read
Quoted 10 lines · Dou Liyang
It may be hard to read the assignment statement of "
next_base", soS/next_base += (1ULL << 32) -
pcms->below_4g_mem_size;
/next_base =mem_base+mem_len;... for readability.
No functionality change.
Signed-off-by Dou Liyang <[email protected]>
This or the new test case at patch 3/4 seem to have caused build failures under some circumstances:
https://www.mail-archive.com/[email protected]/msg486368.html
I couldn't reproduce the failure yet, but I'm removing this and patch 3/4 from the queue until this is investigated.
Quoted 23 lines
--- hw/i386/acpi-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/acpi-build.c +1
-1@@ -2411,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,Signature · 1 line
2.5.5
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v6 2/4] hw/acpi-build: Make assignment statement of next_base easy to read
Hi Eduardo,
Quoted 12 lines · Eduardo Habkost
Quoted 10 lines · Dou Liyang
It may be hard to read the assignment statement of "
next_base", soS/next_base += (1ULL << 32) -
pcms->below_4g_mem_size;
/next_base =mem_base+mem_len;... for readability.
No functionality change.
Signed-off-by Dou Liyang <[email protected]>
Quoted 7 lines
This or the new test case at patch 3/4 seem to have caused build failures under some circumstances:
https://www.mail-archive.com/[email protected]/msg486368.html
I couldn't reproduce the failure yet, but I'm removing this and patch 3/4 from the queue until this is investigated.
Hmm, I see, I will do it.
Thanks,
dou.
Quoted 25 lines
Quoted 24 lines
--- hw/i386/acpi-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/acpi-build.c +1
-2@@ -2411,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
PATCH v6 3/4 ACPI/unit-test: Add a new testcase for RAM allocation in numa node
In reply to Dou LiyangAs 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.
--- 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
tests/acpi-test-data/pc/DSDT.numamem new file binary +0 -0
tests/acpi-test-data/pc/SRAT.numamem new file binary +0 -0
tests/acpi-test-data/q35/DSDT.numamem new file binary +0 -0
tests/acpi-test-data/q35/SRAT.numamem new file binary +0 -0
tests/bios-tables-test.c +24 -0
@@ -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);
Signature · 1 line
2.5.5
PATCH v6 4/4 NUMA: Replace MAX_NODES with nb_numa_nodes in for loop
In reply to Dou LiyangIn 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.
--- numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
numa.c +1 -1
@@ -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) {
Signature · 1 line
2.5.5