NUMA: Validate CPU configuration
v3 cover NUMA: Validate CPU configuration
This adds extra checks to the NUMA code to make sure the CPU configuration is consistent. This needs to be applied on top of the following series:
Message-Id: <[email protected]>
Subject: [Qemu-devel] [PATCH 0/7] NUMA code cleanup
From: Eduardo Habkost <[email protected]>
Date: Sun, 8 Feb 2015 16:51:15 -0200
Git tree: https://github.com/ehabkost/qemu.git numa-next
Changes v1 -> v2:
* (none, v1 was tagged by accident and never sent to qemu-devel)
Changes v2 -> v3:
* Fix off-by-one error on CPU index check
* Use GString and error_report() instead of calling fprintf() directly
* Simplify logic of the CPUs-not-present check
Eduardo Habkost (4):
numa: Fix off-by-one error at MAX_CPUMASK_BITS check
numa: Reject CPU indexes > max_cpus
numa: Reject configuration if CPU appears on multiple nodes
numa: Print warning if no node is assigned to a CPU
numa.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
PATCH v3 1/4 numa: Fix off-by-one error at MAX_CPUMASK_BITS check
Fix the CPU index check to ensure we don't go beyond the size of the node_cpu bitmap.
CPU index is always less than MAX_CPUMASK_BITS, as documented at sysemu.h:
Quoted 2 lines
The following shall be true for all CPUs:
cpu->cpu_index<max_cpus<=MAX_CPUMASK_BITS
--- numa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
numa.c +2 -2
@@ -76,9 +76,9 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) { -if (cpus->value >MAX_CPUMASK_BITS ) { +if (cpus->value >=MAX_CPUMASK_BITS ) {error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS ); + cpus->value,MAX_CPUMASK_BITS -1 );return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v3 1/4] numa: Fix off-by-one error at MAX_CPUMASK_BITS check
Quoted 10 lines · On Thu, 12 Feb 2015 15:50:32 -0200 Eduardo Habkost <[email protected]> wrote:
Fix the CPU index check to ensure we don't go beyond the size of the
node_cpubitmap.CPU index is always less than
MAX_CPUMASK_BITS, as documented atsysemu.h:Quoted 2 lines
The following shall be true for all CPUs:
cpu->cpu_index<max_cpus<=MAX_CPUMASK_BITSSigned-off-by Eduardo Habkost <[email protected]>
Quoted 20 lines
--- numa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)numa.c +2
-2@@ -76,9 +76,9 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) { -if (cpus->value >MAX_CPUMASK_BITS ) { +if (cpus->value >=MAX_CPUMASK_BITS ) {error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS ); + cpus->value,MAX_CPUMASK_BITS -1 );return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
PATCH v3 2/4 numa: Reject CPU indexes > max_cpus
In reply to Eduardo HabkostCPU index is always less than max_cpus, as documented at sysemu.h:
Quoted 2 lines
The following shall be true for all CPUs:
cpu->cpu_index<max_cpus<=MAX_CPUMASK_BITS
Reject configuration which uses invalid CPU indexes.
---
v1 -> v2: (no changes)
v2 -> v3:
* Check for (cpu >= max_cpus) instead of (cpu > max_cpus)
* Reword error message as we are not checking for "bigger than maxcpus" CPU indexes
--- numa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
numa.c +5 -3
@@ -76,9 +76,11 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) { -if (cpus->value >=MAX_CPUMASK_BITS ) { -error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS -1 ); +if (cpus->value >= max_cpus) { +error_setg (errp, +"CPU index (%" PRIu16")" \ +" should be smaller than maxcpus (%d)" , + cpus->value, max_cpus);return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v3 2/4] numa: Reject CPU indexes > max_cpus
Quoted 8 lines · On Thu, 12 Feb 2015 15:50:33 -0200 Eduardo Habkost <[email protected]> wrote:
CPU index is always less than
max_cpus, as documented atsysemu.h:Quoted 2 lines
The following shall be true for all CPUs:
cpu->cpu_index<max_cpus<=MAX_CPUMASK_BITSReject configuration which uses invalid CPU indexes.
Signed-off-by Eduardo Habkost <[email protected]>
Excluding nitpicking below
Quoted 16 lines
---
v1 -> v2: (no changes)v2 -> v3:
* Check for (cpu >=max_cpus) instead of (cpu >max_cpus)
* Reword error message as we are not checking for "bigger than maxcpus" CPU indexes--- numa.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)numa.c +0
-0
numa.c static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) · line 81
Quoted 9 lines
numa.c +3
-3@@ -76,9 +76,11 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp) }for (cpus = node->cpus; cpus; cpus = cpus->next) { -if (cpus->value >=MAX_CPUMASK_BITS ) { -error_setg (errp,"CPU number %" PRIu16" is bigger than %d" , - cpus->value,MAX_CPUMASK_BITS -1 ); +if (cpus->value >= max_cpus) { +error_setg (errp, + "CPU index (%" PRIu16 ")" \
'\' is not really necessary here
Quoted 5 lines
numa.c +2
-0+" should be smaller than maxcpus (%d)" , + cpus->value, max_cpus);return ; }bitmap_set (numa_info[nodenr].node_cpu, cpus->value,1 );
PATCH v3 3/4 numa: Reject configuration if CPU appears on multiple nodes
In reply to Eduardo HabkostEach CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
---
v1 -> v2: (no changes)
v2 -> v3:
* Rename present_cpus to seen_cpus, to make it less confusing
* Use GString and error_report() instead of multiple fprintf() calls
--- numa.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
numa.c +37 -0
@@ -168,6 +168,41 @@ error:return -1 ; } +static char *enumerate_cpus (unsigned long *cpus,int max_cpus) +{ +int cpu; +bool first = true; +GString *s =g_string_new (NULL ); + +for (cpu =find_first_bit (cpus, max_cpus); + cpu < max_cpus; + cpu =find_next_bit (cpus, max_cpus, cpu +1 )) { +g_string_append_printf (s,"%s%d" , first ?"" :" " , cpu); + first = false; + } +return g_string_free (s, FALSE); +} + +static void validate_numa_cpus (void ) +{ +int i; +DECLARE_BITMAP (seen_cpus,MAX_CPUMASK_BITS ); + +bitmap_zero (seen_cpus,MAX_CPUMASK_BITS ); +for (i =0 ; i < nb_numa_nodes; i++) { +if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, +MAX_CPUMASK_BITS )) { +bitmap_and (seen_cpus, seen_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); +error_report ("CPU(s) present in multiple NUMA nodes: %s" , +enumerate_cpus (seen_cpus, max_cpus));; +exit (1 ); + } +bitmap_or (seen_cpus, seen_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + } +} +void parse_numa_opts (void ) {int i;
@@ -245,6 +280,8 @@ void parse_numa_opts(void)set_bit (i, numa_info[i % nb_numa_nodes].node_cpu); } } + +validate_numa_cpus (); } }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v3 3/4] numa: Reject configuration if CPU appears on multiple nodes
Quoted 10 lines · On Thu, 12 Feb 2015 15:50:34 -0200 Eduardo Habkost <[email protected]> wrote:
Each CPU can appear in only one NUMA node on the NUMA config. Reject configuration if a CPU appears in multiple nodes.
Signed-off-by Eduardo Habkost <[email protected]>---
v1 -> v2: (no changes)v2 -> v3:
* Renamepresent_cpustoseen_cpus, to make it less confusing
* Use GString anderror_report()instead of multiplefprintf()calls
With comment below fixed:
Quoted 31 lines
--- numa.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)numa.c +19
-0@@ -168,6 +168,41 @@ error:return -1 ; } +static char *enumerate_cpus (unsigned long *cpus,int max_cpus) +{ +int cpu; +bool first = true; +GString *s =g_string_new (NULL ); + +for (cpu =find_first_bit (cpus, max_cpus); + cpu < max_cpus; + cpu =find_next_bit (cpus, max_cpus, cpu +1 )) { +g_string_append_printf (s,"%s%d" , first ?"" :" " , cpu); + first = false; + } +return g_string_free (s, FALSE); +} + +static void validate_numa_cpus (void ) +{ +int i; +DECLARE_BITMAP (seen_cpus,MAX_CPUMASK_BITS );
numa.c error: · line 199
Quoted 10 lines
numa.c +10
-0+ +bitmap_zero (seen_cpus,MAX_CPUMASK_BITS ); +for (i =0 ; i < nb_numa_nodes; i++) { +if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, +MAX_CPUMASK_BITS )) { +bitmap_and (seen_cpus, seen_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); +error_report ("CPU(s) present in multiple NUMA nodes: %s" , +enumerate_cpus (seen_cpus, max_cpus));; +exit (1 );
s/1/EXIT_FAILURE/
Quoted 18 lines
numa.c +8
-0+ } +bitmap_or (seen_cpus, seen_cpus, + numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + } +} +void parse_numa_opts (void ) {int i;@@ -245,6 +280,8 @@ void parse_numa_opts(void)set_bit (i, numa_info[i % nb_numa_nodes].node_cpu); } } + +validate_numa_cpus (); } }
PATCH v3 4/4 numa: Print warning if no node is assigned to a CPU
In reply to Eduardo HabkostInstead of silently assigning CPU to node 0 when it is omitted from the command-line, check if all CPUs up to max_cpus are present in the NUMA configuration.
I am making this a warning and not a fatal error, to allow management software to be updated if necessary.
---
v1 -> v2: (no changes)
v2 -> v3:
* Use enumerate_cpus() and error_report() for error message
* Simplify logic using bitmap_full()
--- numa.c | 8 ++++++++ 1 file changed, 8 insertions(+)
numa.c +8 -0
@@ -201,6 +201,14 @@ static void validate_numa_cpus(void)bitmap_or (seen_cpus, seen_cpus, numa_info[i].node_cpu,MAX_CPUMASK_BITS ); } + +if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg); +g_free (msg); + } }void parse_numa_opts (void )
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v3 4/4] numa: Print warning if no node is assigned to a CPU
numa.c static void validate_numa_cpus(void) · line 211
Quoted 8 lines · Eduardo Habkost
numa.c +8
-0+ +if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg); +g_free (msg); + }
What happens if you have a single node (useful to give it a memdev via -numa node,memdev=...)? It would be nice in this case to avoid the warning and assign all CPUs to node 0.
Paolo
Re: [Qemu-devel] [PATCH v3 4/4] numa: Print warning if no node is assigned to a CPU
Quoted 10 lines · Paolo Bonzini
numa.c static void validate_numa_cpus(void) · line 211
Quoted 8 lines · Eduardo Habkost
numa.c +8
-0+ +if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg); +g_free (msg); + }
Quoted 3 lines
What happens if you have a single node (useful to give it a memdev via -numa node,memdev=...)? It would be nice in this case to avoid the warning and assign all CPUs to node 0.
The existing code at set_numa_nodes()/parse_numa_opts() should already do what you suggest when we have only one node:
for (i = 0; i < nb_numa_nodes; i++) {
if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) {
break;
}
}
/* assigning the VCPUs round-robin is easier to implement, guest OSes
* must cope with this anyway, because there are BIOSes out there in
* real machines which also use this scheme.
*/
if (i == nb_numa_nodes) {
for (i = 0; i < max_cpus; i++) {
set_bit(i, numa_info[i % nb_numa_nodes].node_cpu);
}
}I don't like how it ignores socket topology, but it is good enough for the one-node case, at least.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 4/4] numa: Print warning if no node is assigned to a CPU
In reply to Eduardo HabkostQuoted 3 lines · On Thu, 12 Feb 2015 15:50:35 -0200 Eduardo Habkost <[email protected]> wrote:
Instead of silently assigning CPU to node 0 when it is omitted from the command-line, check if all CPUs up to
max_cpusare present in the NUMA configuration.
That would also trigger warning for possible (i.e. to be hotplugged) CPUs as well.
Quoted 20 lines
I am making this a warning and not a fatal error, to allow management software to be updated if necessary.
Signed-off-by Eduardo Habkost <[email protected]>---
v1 -> v2: (no changes)v2 -> v3:
* Useenumerate_cpus()anderror_report()for error message
* Simplify logic usingbitmap_full()--- numa.c | 8 ++++++++ 1 file changed, 8 insertions(+)numa.c +0
-0
numa.c static void validate_numa_cpus(void) · line 209
Quoted 9 lines
numa.c +6
-0@@ -201,6 +201,14 @@ static void validate_numa_cpus(void)bitmap_or (seen_cpus, seen_cpus, numa_info[i].node_cpu,MAX_CPUMASK_BITS ); } + +if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg);
Maybe add to this that all CPUs up to maxcpus must be described in numa config?
Quoted 5 lines
numa.c +2
-0+g_free (msg); + } }void parse_numa_opts (void )
Re: [Qemu-devel] [PATCH v3 4/4] numa: Print warning if no node is assigned to a CPU
Quoted 8 lines · Igor Mammedov
Quoted 3 lines · On Thu, 12 Feb 2015 15:50:35 -0200 Eduardo Habkost <[email protected]> wrote:
Instead of silently assigning CPU to node 0 when it is omitted from the command-line, check if all CPUs up to
max_cpusare present in the NUMA configuration.That would also trigger warning for possible (i.e. to be hotplugged) CPUs as well.
And that's correct, right? As far as I can see, there's no _PXM method in our Processor objects, so we need to know the NUMA node for all possible VCPUs in the moment the SRAT is generated. Or am I missing something?
[...]
Quoted 6 lines
numa.c static void validate_numa_cpus(void) · line 209
Quoted 5 lines
numa.c +5
-0+if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg);Maybe add to this that all CPUs up to maxcpus must be described in numa config?
I will update it. Thanks!
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 4/4] numa: Print warning if no node is assigned to a CPU
Quoted 7 lines · On Tue, 24 Feb 2015 15:19:28 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Thu, 12 Feb 2015 15:50:35 -0200 Eduardo Habkost <[email protected]> wrote:
Instead of silently assigning CPU to node 0 when it is omitted from the command-line, check if all CPUs up to
max_cpusare present in the NUMA configuration.
Quoted 7 lines
Quoted 2 lines
That would also trigger warning for possible (i.e. to be hotplugged) CPUs as well.
And that's correct, right? As far as I can see, there's no
_PXMmethod in our Processor objects, so we need to know the NUMA node for all possible VCPUs in the moment the SRAT is generated. Or am I missing something?
Yep, that's how it's now. And probably it should stay so. Just define topology at startup and there won't be warnings.
Quoted 12 lines
[...]
Quoted 6 lines
numa.c static void validate_numa_cpus(void) · line 209
Quoted 5 lines
numa.c +5
-0+if (!bitmap_full (seen_cpus, max_cpus)) { +char *msg; +bitmap_complement (seen_cpus, seen_cpus, max_cpus); + msg =enumerate_cpus (seen_cpus, max_cpus); +error_report ("warning: CPU(s) not present in any NUMA nodes: %s" , msg);Maybe add to this that all CPUs up to maxcpus must be described in numa config?
I will update it. Thanks!
Ping? Can somebody help review this?
Quoted 30 lines · Eduardo Habkost
This adds extra checks to the NUMA code to make sure the CPU configuration is consistent. This needs to be applied on top of the following series:
Message-Id: <[email protected]>
Subject: [Qemu-devel] [PATCH 0/7] NUMA code cleanup
From: Eduardo Habkost <[email protected]>
Date: Sun, 8 Feb 2015 16:51:15 -0200
Git tree: https://github.com/ehabkost/qemu.git numa-nextChanges v1 -> v2:
* (none, v1 was tagged by accident and never sent to qemu-devel)Changes v2 -> v3:
* Fix off-by-one error on CPU index check
* Use GString anderror_report()instead of callingfprintf()directly
* Simplify logic of the CPUs-not-present checkEduardo Habkost (4):
numa: Fix off-by-one error atMAX_CPUMASK_BITScheck
numa: Reject CPU indexes >max_cpus
numa: Reject configuration if CPU appears on multiple nodes
numa: Print warning if no node is assigned to a CPUnuma.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-)Signature · 1 line
2.1.0
Signature · 1 line
Eduardo