Skip to contentSkip to conversation

xentrace: fix xentrace for smt=0

PATCH In review Juergen Gross 2 participants 6 messages Oct 4, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover xentrace: fix xentrace for smt=0

When hyperthreads are disabled via smt=0 Xen boot parameter xentrace is no longer working, but crashing the system.

Patch 1 makes the xentrace user tool work on systems when not all possible cpu ids have an associated trace buffer allocated.

Patch 2 corrects xentrace handling by sizing the control structures according to the physical cpus instead of taking online cpus into account only.

Juergen Gross (2):
xentrace: allow sparse cpu list
xentrace: handle sparse cpu ids correctly in xen trace buffer handling

 tools/xentrace/xentrace.c | 18 ++++++++++++------
 xen/common/trace.c        |  6 +++---
 2 files changed, 15 insertions(+), 9 deletions(-)
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/2 xentrace: allow sparse cpu list

Modify the xentrace utility to allow sparse cpu list resulting in not all possible cpus having a trace buffer allocated.

---
 tools/xentrace/xentrace.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
tools/xentrace/xentrace.c +11 -5
index 364a6fdad5..590a91e091 100644
@@ -500,12 +500,14 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
 
     for(i=0; i<num; i++)
     {
-        
-        const uint32_t *mfn_list = (const uint32_t *)tbufs.t_info
-                                   + tbufs.t_info->mfn_offset[i];
+        const uint32_t *mfn_list;
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
 
+        if ( !tbufs.t_info->mfn_offset[i] )
+            continue;
+
+        mfn_list = (const uint32_t *)tbufs.t_info + tbufs.t_info->mfn_offset[i];
         for ( j=0; j<tbufs.t_info->tbuf_size; j++)
             pfn_list[j] = (xen_pfn_t)mfn_list[j];
 
@@ -702,7 +704,8 @@ static int monitor_tbufs(void)
 
     if ( opts.discard )
         for ( i = 0; i < num; i++ )
-            meta[i]->cons = meta[i]->prod;
+            if ( meta[i] )
+                meta[i]->cons = meta[i]->prod;
 
     /* now, scan buffers for events */
     while ( 1 )
@@ -710,7 +713,10 @@ static int monitor_tbufs(void)
         for ( i = 0; i < num; i++ )
         {
             unsigned long start_offset, end_offset, window_size, cons, prod;
-                
+
+            if ( !meta[i] )
+                continue;
+
             /* Read window information only once. */
             cons = meta[i]->cons;
             prod = meta[i]->prod;
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xentrace: allow sparse cpu list

Quoted 4 lines · Juergen Gross

Modify the xentrace utility to allow sparse cpu list resulting in not all possible cpus having a trace buffer allocated.

This looks good:

Would you mind if I fold in the attached comment when committing?

-George

Quoted 39 lines
---
 tools/xentrace/xentrace.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
tools/xentrace/xentrace.c +7 -4
index 364a6fdad5..590a91e091 100644
@@ -500,12 +500,14 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
 
     for(i=0; i<num; i++)
     {
-        
-        const uint32_t *mfn_list = (const uint32_t *)tbufs.t_info
-                                   + tbufs.t_info->mfn_offset[i];
+        const uint32_t *mfn_list;
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
 
+        if ( !tbufs.t_info->mfn_offset[i] )
+            continue;
+
+        mfn_list = (const uint32_t *)tbufs.t_info + tbufs.t_info->mfn_offset[i];
         for ( j=0; j<tbufs.t_info->tbuf_size; j++)
             pfn_list[j] = (xen_pfn_t)mfn_list[j];
 
@@ -702,7 +704,8 @@ static int monitor_tbufs(void)
 
     if ( opts.discard )
         for ( i = 0; i < num; i++ )
-            meta[i]->cons = meta[i]->prod;
+            if ( meta[i] )
+                meta[i]->cons = meta[i]->prod;
 
     /* now, scan buffers for events */
     while ( 1 )
@@ -710,7 +713,10 @@ static int monitor_tbufs(void)
         for ( i = 0; i < num; i++ )

tools/xentrace/xentrace.c static int monitor_tbufs(void) · line 722

Quoted 10 lines
tools/xentrace/xentrace.c +4 -1
         {
             unsigned long start_offset, end_offset, window_size, cons, prod;
-                
+
+            if ( !meta[i] )
+                continue;
+
             /* Read window information only once. */
             cons = meta[i]->cons;
             prod = meta[i]->prod;
tools/xentrace/xentrace.c +5 -1
index 590a91e091..a897223592 100644
@@ -489,7 +489,11 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
         exit(EXIT_FAILURE);
     }
 
-    /* Map per-cpu buffers */
+    /* 
+     * Map per-cpu buffers.  NB that if a cpus is offline, it may have
+     * no trace buffers.  In this case, the the respective mfn_offset
+     * will be 0, and the index should be ignored.
+     */
     tbufs.meta = (struct t_buf **)calloc(num, sizeof(struct t_buf *));
     tbufs.data = (unsigned char **)calloc(num, sizeof(unsigned char *));
     if ( tbufs.meta == NULL || tbufs.data == NULL )

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [PATCH v2 1/2] xentrace: allow sparse cpu list

Quoted 11 lines · George Dunlap
Quoted 4 lines · Juergen Gross

Modify the xentrace utility to allow sparse cpu list resulting in not all possible cpus having a trace buffer allocated.

This looks good:

Would you mind if I fold in the attached comment when committing?

With some adaptions, please:

- /* Map per-cpu buffers */
+ /*
+ * Map per-cpu buffers. NB that if a cpus is offline, it may have

s/ cpus / cpu /

+ * no trace buffers. In this case, the the respective mfn_offset

s/the the/the/

+ * will be 0, and the index should be ignored.
+ */

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

PATCH v2 2/2 xentrace: handle sparse cpu ids correctly in xen trace buffer handling

In reply to Juergen Gross

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.

---
 tools/xentrace/xentrace.c | 2 +-
 xen/common/trace.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/xentrace/xentrace.c +1 -1
index 590a91e091..12497a16b4 100644
@@ -596,7 +596,7 @@ static unsigned int get_num_cpus(void)
         exit(EXIT_FAILURE);
     }
 
-    return physinfo.nr_cpus;
+    return physinfo.max_cpu_id + 1;
 }
 
 /**
xen/common/trace.c +3 -3
index 8cdc17b731..c079454c6a 100644
@@ -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 */
@@ -151,11 +151,11 @@ 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
      */
-    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;
 }
 
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] xentrace: handle sparse cpu ids correctly in xen trace buffer handling

Quoted 39 lines · Juergen Gross

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.

---
 tools/xentrace/xentrace.c | 2 +-
 xen/common/trace.c        | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/xentrace/xentrace.c +1 -1
index 590a91e091..12497a16b4 100644
@@ -596,7 +596,7 @@ static unsigned int get_num_cpus(void)
         exit(EXIT_FAILURE);
     }
 
-    return physinfo.nr_cpus;
+    return physinfo.max_cpu_id + 1;
 }
 
 /**
xen/common/trace.c +1 -1
index 8cdc17b731..c079454c6a 100644
@@ -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 */

xen/common/trace.c static int calculate_tbuf_size(unsigned int pages, uint16_t t_info_first_offset) · line 153

Quoted 3 lines
xen/common/trace.c +0 -0
@@ -151,11 +151,11 @@ 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
      */

This sounds a bit like song lyrics.

But that's not your fault, not your fault:

I'll fix the comment on check-in.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel