qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks
@ 2016-11-18 11:02 Igor Mammedov
  2016-11-22  5:39 ` Alexey Kardashevskiy
  2016-12-28 17:08 ` Eduardo Habkost
  0 siblings, 2 replies; 4+ messages in thread
From: Igor Mammedov @ 2016-11-18 11:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexey Kardashevskiy, Greg Kurz, David Gibson, Eduardo Habkost,
	Paolo Bonzini

so it won't impose an additional limits on max_cpus limits
supported by different targets.

It removes global MAX_CPUMASK_BITS constant and need to
bump it up whenever max_cpus is being increased for
a target above MAX_CPUMASK_BITS value.

Use runtime max_cpus value instead to allocate sufficiently
sized node_cpu bitmasks in numa parser.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v1:
  - replace bitmap_free() with g_free()
  - drop bitmap_zero() as bitmap_new() returns already zerroed out one

CC: Alexey Kardashevskiy <aik@ozlabs.ru>
CC: Greg Kurz <gkurz@linux.vnet.ibm.com>
CC: David Gibson <david@gibson.dropbear.id.au>
CC: Eduardo Habkost <ehabkost@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
 include/sysemu/numa.h   |  2 +-
 include/sysemu/sysemu.h |  7 -------
 numa.c                  | 18 +++++++++++-------
 vl.c                    |  5 -----
 4 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h
index 4da808a..8f09dcf 100644
--- a/include/sysemu/numa.h
+++ b/include/sysemu/numa.h
@@ -17,7 +17,7 @@ struct numa_addr_range {
 
 typedef struct node_info {
     uint64_t node_mem;
-    DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+    unsigned long *node_cpu;
     struct HostMemoryBackend *node_memdev;
     bool present;
     QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 66c6f15..cccde56 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -168,13 +168,6 @@ extern int mem_prealloc;
 #define MAX_NODES 128
 #define NUMA_NODE_UNASSIGNED MAX_NODES
 
-/* The following shall be true for all CPUs:
- *   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
- *
- * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS.
- */
-#define MAX_CPUMASK_BITS 288
-
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
     const char *name;
diff --git a/numa.c b/numa.c
index 9c09e45..1b6fa78 100644
--- a/numa.c
+++ b/numa.c
@@ -266,20 +266,19 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus)
 static void validate_numa_cpus(void)
 {
     int i;
-    DECLARE_BITMAP(seen_cpus, MAX_CPUMASK_BITS);
+    unsigned long *seen_cpus = bitmap_new(max_cpus);
 
-    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)) {
+        if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) {
             bitmap_and(seen_cpus, seen_cpus,
-                       numa_info[i].node_cpu, MAX_CPUMASK_BITS);
+                       numa_info[i].node_cpu, max_cpus);
             error_report("CPU(s) present in multiple NUMA nodes: %s",
                          enumerate_cpus(seen_cpus, max_cpus));
+            g_free(seen_cpus);
             exit(EXIT_FAILURE);
         }
         bitmap_or(seen_cpus, seen_cpus,
-                  numa_info[i].node_cpu, MAX_CPUMASK_BITS);
+                  numa_info[i].node_cpu, max_cpus);
     }
 
     if (!bitmap_full(seen_cpus, max_cpus)) {
@@ -291,12 +290,17 @@ static void validate_numa_cpus(void)
                      "in NUMA config");
         g_free(msg);
     }
+    g_free(seen_cpus);
 }
 
 void parse_numa_opts(MachineClass *mc)
 {
     int i;
 
+    for (i = 0; i < MAX_NODES; i++) {
+        numa_info[i].node_cpu = bitmap_new(max_cpus);
+    }
+
     if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, NULL, NULL)) {
         exit(1);
     }
@@ -362,7 +366,7 @@ void parse_numa_opts(MachineClass *mc)
         numa_set_mem_ranges();
 
         for (i = 0; i < nb_numa_nodes; i++) {
-            if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) {
+            if (!bitmap_empty(numa_info[i].node_cpu, max_cpus)) {
                 break;
             }
         }
diff --git a/vl.c b/vl.c
index d77dd86..37790e5 100644
--- a/vl.c
+++ b/vl.c
@@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts)
 
         max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
 
-        if (max_cpus > MAX_CPUMASK_BITS) {
-            error_report("unsupported number of maxcpus");
-            exit(1);
-        }
-
         if (max_cpus < cpus) {
             error_report("maxcpus must be equal to or greater than smp");
             exit(1);
-- 
2.7.4

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

* Re: [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks
  2016-11-18 11:02 [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks Igor Mammedov
@ 2016-11-22  5:39 ` Alexey Kardashevskiy
  2016-12-28 17:08 ` Eduardo Habkost
  1 sibling, 0 replies; 4+ messages in thread
From: Alexey Kardashevskiy @ 2016-11-22  5:39 UTC (permalink / raw)
  To: Igor Mammedov, qemu-devel
  Cc: Greg Kurz, David Gibson, Eduardo Habkost, Paolo Bonzini

On 18/11/16 22:02, Igor Mammedov wrote:
> so it won't impose an additional limits on max_cpus limits
> supported by different targets.
> 
> It removes global MAX_CPUMASK_BITS constant and need to
> bump it up whenever max_cpus is being increased for
> a target above MAX_CPUMASK_BITS value.
> 
> Use runtime max_cpus value instead to allocate sufficiently
> sized node_cpu bitmasks in numa parser.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v1:
>   - replace bitmap_free() with g_free()
>   - drop bitmap_zero() as bitmap_new() returns already zerroed out one
> 
> CC: Alexey Kardashevskiy <aik@ozlabs.ru>




Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>


> CC: Greg Kurz <gkurz@linux.vnet.ibm.com>
> CC: David Gibson <david@gibson.dropbear.id.au>
> CC: Eduardo Habkost <ehabkost@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/sysemu/numa.h   |  2 +-
>  include/sysemu/sysemu.h |  7 -------
>  numa.c                  | 18 +++++++++++-------
>  vl.c                    |  5 -----
>  4 files changed, 12 insertions(+), 20 deletions(-)
> 
> diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h
> index 4da808a..8f09dcf 100644
> --- a/include/sysemu/numa.h
> +++ b/include/sysemu/numa.h
> @@ -17,7 +17,7 @@ struct numa_addr_range {
>  
>  typedef struct node_info {
>      uint64_t node_mem;
> -    DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
> +    unsigned long *node_cpu;
>      struct HostMemoryBackend *node_memdev;
>      bool present;
>      QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 66c6f15..cccde56 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -168,13 +168,6 @@ extern int mem_prealloc;
>  #define MAX_NODES 128
>  #define NUMA_NODE_UNASSIGNED MAX_NODES
>  
> -/* The following shall be true for all CPUs:
> - *   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
> - *
> - * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS.
> - */
> -#define MAX_CPUMASK_BITS 288
> -
>  #define MAX_OPTION_ROMS 16
>  typedef struct QEMUOptionRom {
>      const char *name;
> diff --git a/numa.c b/numa.c
> index 9c09e45..1b6fa78 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -266,20 +266,19 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus)
>  static void validate_numa_cpus(void)
>  {
>      int i;
> -    DECLARE_BITMAP(seen_cpus, MAX_CPUMASK_BITS);
> +    unsigned long *seen_cpus = bitmap_new(max_cpus);
>  
> -    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)) {
> +        if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) {
>              bitmap_and(seen_cpus, seen_cpus,
> -                       numa_info[i].node_cpu, MAX_CPUMASK_BITS);
> +                       numa_info[i].node_cpu, max_cpus);
>              error_report("CPU(s) present in multiple NUMA nodes: %s",
>                           enumerate_cpus(seen_cpus, max_cpus));
> +            g_free(seen_cpus);
>              exit(EXIT_FAILURE);
>          }
>          bitmap_or(seen_cpus, seen_cpus,
> -                  numa_info[i].node_cpu, MAX_CPUMASK_BITS);
> +                  numa_info[i].node_cpu, max_cpus);
>      }
>  
>      if (!bitmap_full(seen_cpus, max_cpus)) {
> @@ -291,12 +290,17 @@ static void validate_numa_cpus(void)
>                       "in NUMA config");
>          g_free(msg);
>      }
> +    g_free(seen_cpus);
>  }
>  
>  void parse_numa_opts(MachineClass *mc)
>  {
>      int i;
>  
> +    for (i = 0; i < MAX_NODES; i++) {
> +        numa_info[i].node_cpu = bitmap_new(max_cpus);
> +    }
> +
>      if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, NULL, NULL)) {
>          exit(1);
>      }
> @@ -362,7 +366,7 @@ void parse_numa_opts(MachineClass *mc)
>          numa_set_mem_ranges();
>  
>          for (i = 0; i < nb_numa_nodes; i++) {
> -            if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) {
> +            if (!bitmap_empty(numa_info[i].node_cpu, max_cpus)) {
>                  break;
>              }
>          }
> diff --git a/vl.c b/vl.c
> index d77dd86..37790e5 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts)
>  
>          max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
>  
> -        if (max_cpus > MAX_CPUMASK_BITS) {
> -            error_report("unsupported number of maxcpus");
> -            exit(1);
> -        }
> -
>          if (max_cpus < cpus) {
>              error_report("maxcpus must be equal to or greater than smp");
>              exit(1);
> 


-- 
Alexey

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

* Re: [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks
  2016-11-18 11:02 [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks Igor Mammedov
  2016-11-22  5:39 ` Alexey Kardashevskiy
@ 2016-12-28 17:08 ` Eduardo Habkost
  2016-12-29  8:39   ` Igor Mammedov
  1 sibling, 1 reply; 4+ messages in thread
From: Eduardo Habkost @ 2016-12-28 17:08 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel, Alexey Kardashevskiy, Paolo Bonzini, David Gibson,
	Greg Kurz

On Fri, Nov 18, 2016 at 12:02:54PM +0100, Igor Mammedov wrote:
> so it won't impose an additional limits on max_cpus limits
> supported by different targets.
> 
> It removes global MAX_CPUMASK_BITS constant and need to
> bump it up whenever max_cpus is being increased for
> a target above MAX_CPUMASK_BITS value.
> 
> Use runtime max_cpus value instead to allocate sufficiently
> sized node_cpu bitmasks in numa parser.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

As the cpu_index assignment code isn't obviously safe against
setting cpu_index > max_cpus, I would like to squash this into
the patch. Is that OK for you?

diff --git a/numa.c b/numa.c
index 1b6fa78..33f2fd4 100644
--- a/numa.c
+++ b/numa.c
@@ -401,6 +401,7 @@ void numa_post_machine_init(void)
 
     CPU_FOREACH(cpu) {
         for (i = 0; i < nb_numa_nodes; i++) {
+            assert(cpu->cpu_index < max_cpus);
             if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
                 cpu->numa_node = i;
             }
@@ -559,6 +560,8 @@ int numa_get_node_for_cpu(int idx)
 {
     int i;
 
+    assert(idx < max_cpus);
+
     for (i = 0; i < nb_numa_nodes; i++) {
         if (test_bit(idx, numa_info[i].node_cpu)) {
             break;

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks
  2016-12-28 17:08 ` Eduardo Habkost
@ 2016-12-29  8:39   ` Igor Mammedov
  0 siblings, 0 replies; 4+ messages in thread
From: Igor Mammedov @ 2016-12-29  8:39 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, Alexey Kardashevskiy, Paolo Bonzini, David Gibson,
	Greg Kurz

On Wed, 28 Dec 2016 15:08:42 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Fri, Nov 18, 2016 at 12:02:54PM +0100, Igor Mammedov wrote:
> > so it won't impose an additional limits on max_cpus limits
> > supported by different targets.
> > 
> > It removes global MAX_CPUMASK_BITS constant and need to
> > bump it up whenever max_cpus is being increased for
> > a target above MAX_CPUMASK_BITS value.
> > 
> > Use runtime max_cpus value instead to allocate sufficiently
> > sized node_cpu bitmasks in numa parser.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>  
> 
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> 
> As the cpu_index assignment code isn't obviously safe against
> setting cpu_index > max_cpus, I would like to squash this into
> the patch. Is that OK for you?
Go ahead, change looks good to me.

> 
> diff --git a/numa.c b/numa.c
> index 1b6fa78..33f2fd4 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -401,6 +401,7 @@ void numa_post_machine_init(void)
>  
>      CPU_FOREACH(cpu) {
>          for (i = 0; i < nb_numa_nodes; i++) {
> +            assert(cpu->cpu_index < max_cpus);
>              if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
>                  cpu->numa_node = i;
>              }
> @@ -559,6 +560,8 @@ int numa_get_node_for_cpu(int idx)
>  {
>      int i;
>  
> +    assert(idx < max_cpus);
> +
>      for (i = 0; i < nb_numa_nodes; i++) {
>          if (test_bit(idx, numa_info[i].node_cpu)) {
>              break;
> 

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

end of thread, other threads:[~2016-12-29  8:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-18 11:02 [Qemu-devel] [PATCH for-2.9] numa: make -numa parser dynamically allocate CPUs masks Igor Mammedov
2016-11-22  5:39 ` Alexey Kardashevskiy
2016-12-28 17:08 ` Eduardo Habkost
2016-12-29  8:39   ` Igor Mammedov

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).