]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
xentrace: handle sparse cpu ids correctly in xen trace buffer handling
authorJuergen Gross <jgross@suse.com>
Thu, 4 Oct 2018 11:47:24 +0000 (12:47 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Thu, 4 Oct 2018 11:47:24 +0000 (12:47 +0100)
The per-cpu buffers for Xentrace are addressed by cpu-id, but the info
array for the buffers is sized only by number of online cpus. This
might lead to crashes when using Xentrace with smt=0.

The t_info structure has to be sized based on nr_cpu_ids.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
tools/xentrace/xentrace.c
xen/common/trace.c

index a9cb4b15a9f1be5c2283f7a35c8b1009d3a29be5..4b50b8a53e05803b0baa9d5349c4383180736dd5 100644 (file)
@@ -600,7 +600,7 @@ static unsigned int get_num_cpus(void)
         exit(EXIT_FAILURE);
     }
 
-    return physinfo.nr_cpus;
+    return physinfo.max_cpu_id + 1;
 }
 
 /**
index 8cdc17b7315d1917e230b444b18aa8665a0d8677..cc294fc38473ebceb1f00908ed8f7c6dba0ca90a 100644 (file)
@@ -113,7 +113,7 @@ static int calculate_tbuf_size(unsigned int pages, uint16_t t_info_first_offset)
     struct t_info dummy_pages;
     typeof(dummy_pages.tbuf_size) max_pages;
     typeof(dummy_pages.mfn_offset[0]) max_mfn_offset;
-    unsigned int max_cpus = num_online_cpus();
+    unsigned int max_cpus = nr_cpu_ids;
     unsigned int t_info_words;
 
     /* force maximum value for an unsigned type */
@@ -149,13 +149,13 @@ static int calculate_tbuf_size(unsigned int pages, uint16_t t_info_first_offset)
 
     /* 
      * NB this calculation is correct, because t_info_first_offset is
-     * in words, not bytes, not bytes
+     * in words, not bytes
      */
-    t_info_words = num_online_cpus() * pages + t_info_first_offset;
+    t_info_words = nr_cpu_ids * pages + t_info_first_offset;
     t_info_pages = PFN_UP(t_info_words * sizeof(uint32_t));
     printk(XENLOG_INFO "xentrace: requesting %u t_info pages "
            "for %u trace pages on %u cpus\n",
-           t_info_pages, pages, num_online_cpus());
+           t_info_pages, pages, nr_cpu_ids);
     return pages;
 }