Skip to contentSkip to conversation

tracetool: fix log-stap format

PATCH Applied Laurent Vivier 4 participants 9 messages Jan 5, 2021 – Jan 13, 2021

lore
Share & tools
lore
#0 lore raw

cover tracetool: fix log-stap format

The first patch fixes a problem I have introduced in vhost-vdpa traces by adding an unsupported format ("%llu").

The second patch fixes a problem I've seen while I was checking the result of the first patch: %PRI formats are not decoded correctly and we can end with things like "0x%u" because the used format is always the one of the first format of the string.

Laurent Vivier (2):
vhost-vdpa: fix "unsigned long long" error with stap
tracetool: fix "PRI" macro decoding

 hw/virtio/trace-events               | 2 +-
 hw/virtio/vhost-vdpa.c               | 4 ++--
 scripts/tracetool/format/log_stap.py | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/2 vhost-vdpa: fix "unsigned long long" error with stap

The "%llu" format type is not understood by stap:

$ sudo stap -e 'probe begin{printf ("BEGIN")}'  -I .

parse error: invalid or missing conversion specifier

          saw: operator ',' at ./qemu-system-x86_64-log.stp:15118:101
       source:     printf("%d@%d vhost_vdpa_set_log_base dev: %p base: 0x%x size: %llu refcnt: %d fd: %d log: %p\n", pid(), gettimeofday_ns(), dev, base, size, refcnt, fd, log)
                                                                                                                 ^

1 parse error.
WARNING: tapset "./qemu-system-x86_64-log.stp" has errors, and will be skipped

commit 35e28cb0f210 ("scripts/tracetool: silence SystemTap dtrace(1) long long warnings") has already fixed the problem for the dtrace format by dynamically replacing "unsigned long long" by "uint64_t", but as it seems the problem can happen with any format and this is the only occurrence of this type, simply replace it directly by "uint64_t" in the trace-events file.

Fixes 778e67de4cd8 ("vhost-vdpa: add trace-events")
---
 hw/virtio/trace-events | 2 +-
 hw/virtio/vhost-vdpa.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/virtio/trace-events +1 -1
index 2060a144a2f4..6074bafeb147 100644
@@ -42,7 +42,7 @@ vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s"
 vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, uint32_t flags) "dev: %p offset: %"PRIu32" size: %"PRIu32" flags: 0x%"PRIx32
 vhost_vdpa_get_config(void *dev, void *config, uint32_t config_len) "dev: %p config: %p config_len: %"PRIu32
 vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d"
-vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcnt: %d fd: %d log: %p"
+vhost_vdpa_set_log_base(void *dev, uint64_t base, uint64_t size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %"PRIu64" refcnt: %d fd: %d log: %p"
 vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64
 vhost_vdpa_set_vring_num(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u"
 vhost_vdpa_set_vring_base(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u"
hw/virtio/vhost-vdpa.c +2 -2
index 01d2101d0976..436aa20d3f09 100644
@@ -493,8 +493,8 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base,
                                      struct vhost_log *log)
 {
-    trace_vhost_vdpa_set_log_base(dev, base, log->size, log->refcnt, log->fd,
-                                  log->log);
+    trace_vhost_vdpa_set_log_base(dev, base, (uint64_t)log->size, log->refcnt,
+                                  log->fd, log->log);
     return vhost_vdpa_call(dev, VHOST_SET_LOG_BASE, &base);
 }
 
Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH 1/2] vhost-vdpa: fix "unsigned long long" error with stap

Quoted 19 lines · Laurent Vivier

The "%llu" format type is not understood by stap:

$ sudo stap -e 'probe begin{printf ("BEGIN")}'  -I .

parse error: invalid or missing conversion specifier

          saw: operator ',' at ./qemu-system-x86_64-log.stp:15118:101
       source:     printf("%d@%d vhost_vdpa_set_log_base dev: %p base: 0x%x size: %llu refcnt: %d fd: %d log: %p\n", pid(), gettimeofday_ns(), dev, base, size, refcnt, fd, log)
                                                                                                                 ^

1 parse error.
WARNING: tapset "./qemu-system-x86_64-log.stp" has errors, and will be skipped

commit 35e28cb0f210 ("scripts/tracetool: silence SystemTap dtrace(1) long long warnings") has already fixed the problem for the dtrace format by dynamically replacing "unsigned long long" by "uint64_t", but as it seems the problem can happen with any format and this is the only occurrence of this type, simply replace it directly by "uint64_t" in the trace-events file.

Quoted 6 lines
Fixes 778e67de4cd8 ("vhost-vdpa: add trace-events")
---
 hw/virtio/trace-events | 2 +-
 hw/virtio/vhost-vdpa.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Ignore this patch, Daniel has proposed a better fix.

Thanks,
Laurent

#3 lore raw

PATCH 2/2 tracetool: fix "PRI" macro decoding

In reply to Laurent Vivier

macro is not reset after use, so the format decoded is always the one of the first "PRI" in the format string.

For instance:

  vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, \
                        uint32_t flags) "dev: %p offset: %"PRIu32" \
                        size: %"PRIu32" flags: 0x%"PRIx32

generates:

  printf("%d@%d vhost_vdpa_set_config dev: %p offset: %u size: %u \
          flags: 0x%u\n", pid(), gettimeofday_ns(), dev, offset, \
          size, flags)

for the "flags" parameter, we can see a "0x%u" rather than a "0x%x" because the first macro was "PRIu32" (for offset).

In the loop, macro becomes "PRIu32PRIu32PRIx32", and c_macro_to_format() returns always macro[3] ('u' in this case). This patch resets macro after the format has been decoded.

---
 scripts/tracetool/format/log_stap.py | 1 +
 1 file changed, 1 insertion(+)
scripts/tracetool/format/log_stap.py +1 -0
index b486beb67239..3e1186ae9cc2 100644
@@ -54,6 +54,7 @@ def c_fmt_to_stap(fmt):
             else:
                 if state == STATE_MACRO:
                     bits.append(c_macro_to_format(macro))
+                    macro = ""
                 state = STATE_LITERAL
         elif fmt[i] == ' ' or fmt[i] == '\t':
             if state == STATE_MACRO:
Signature · 1 line
2.29.2
#4 lore raw

Re: [PATCH 2/2] tracetool: fix "PRI" macro decoding

Quoted 32 lines · Laurent Vivier

macro is not reset after use, so the format decoded is always the one of the first "PRI" in the format string.

For instance:

  vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, \
                        uint32_t flags) "dev: %p offset: %"PRIu32" \
                        size: %"PRIu32" flags: 0x%"PRIx32

generates:

  printf("%d@%d vhost_vdpa_set_config dev: %p offset: %u size: %u \
          flags: 0x%u\n", pid(), gettimeofday_ns(), dev, offset, \
          size, flags)

for the "flags" parameter, we can see a "0x%u" rather than a "0x%x" because the first macro was "PRIu32" (for offset).

In the loop, macro becomes "PRIu32PRIu32PRIx32", and c_macro_to_format() returns always macro[3] ('u' in this case). This patch resets macro after the format has been decoded.

---
 scripts/tracetool/format/log_stap.py | 1 +
 1 file changed, 1 insertion(+)
scripts/tracetool/format/log_stap.py +0 -0
index b486beb67239..3e1186ae9cc2 100644

scripts/tracetool/format/log_stap.py def c_fmt_to_stap(fmt): · line 60

Quoted 7 lines
scripts/tracetool/format/log_stap.py +1 -0
@@ -54,6 +54,7 @@ def c_fmt_to_stap(fmt):
             else:
                 if state == STATE_MACRO:
                     bits.append(c_macro_to_format(macro))
+                    macro = ""
                 state = STATE_LITERAL
         elif fmt[i] == ' ' or fmt[i] == '\t':
             if state == STATE_MACRO:

What about the 'else' case?

#5 lore raw

Re: [PATCH 2/2] tracetool: fix "PRI" macro decoding

Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 27 lines · Laurent Vivier

macro is not reset after use, so the format decoded is always the one of the first "PRI" in the format string.

For instance:

  vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, \
                        uint32_t flags) "dev: %p offset: %"PRIu32" \
                        size: %"PRIu32" flags: 0x%"PRIx32

generates:

  printf("%d@%d vhost_vdpa_set_config dev: %p offset: %u size: %u \
          flags: 0x%u\n", pid(), gettimeofday_ns(), dev, offset, \
          size, flags)

for the "flags" parameter, we can see a "0x%u" rather than a "0x%x" because the first macro was "PRIu32" (for offset).

In the loop, macro becomes "PRIu32PRIu32PRIx32", and c_macro_to_format() returns always macro[3] ('u' in this case). This patch resets macro after the format has been decoded.

---
 scripts/tracetool/format/log_stap.py | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

scripts/tracetool/format/log_stap.py def c_fmt_to_stap(fmt): · line 60

Quoted 12 lines
scripts/tracetool/format/log_stap.py +1 -0
index b486beb67239..3e1186ae9cc2 100644
@@ -54,6 +54,7 @@ def c_fmt_to_stap(fmt):
             else:
                 if state == STATE_MACRO:
                     bits.append(c_macro_to_format(macro))
+                    macro = ""
                 state = STATE_LITERAL
         elif fmt[i] == ' ' or fmt[i] == '\t':
             if state == STATE_MACRO:

What about the 'else' case?

It already has the 'macro = ""', so no need to fix it.

Thanks,
Laurent

Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] tracetool: fix "PRI" macro decoding

In reply to Laurent Vivier
Quoted 32 lines · Laurent Vivier

macro is not reset after use, so the format decoded is always the one of the first "PRI" in the format string.

For instance:

  vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, \
                        uint32_t flags) "dev: %p offset: %"PRIu32" \
                        size: %"PRIu32" flags: 0x%"PRIx32

generates:

  printf("%d@%d vhost_vdpa_set_config dev: %p offset: %u size: %u \
          flags: 0x%u\n", pid(), gettimeofday_ns(), dev, offset, \
          size, flags)

for the "flags" parameter, we can see a "0x%u" rather than a "0x%x" because the first macro was "PRIu32" (for offset).

In the loop, macro becomes "PRIu32PRIu32PRIx32", and c_macro_to_format() returns always macro[3] ('u' in this case). This patch resets macro after the format has been decoded.

---
 scripts/tracetool/format/log_stap.py | 1 +
 1 file changed, 1 insertion(+)
scripts/tracetool/format/log_stap.py +0 -0
index b486beb67239..3e1186ae9cc2 100644

scripts/tracetool/format/log_stap.py def c_fmt_to_stap(fmt): · line 60

Quoted 7 lines
scripts/tracetool/format/log_stap.py +1 -0
@@ -54,6 +54,7 @@ def c_fmt_to_stap(fmt):
             else:
                 if state == STATE_MACRO:
                     bits.append(c_macro_to_format(macro))
+                    macro = ""
                 state = STATE_LITERAL
         elif fmt[i] == ' ' or fmt[i] == '\t':
             if state == STATE_MACRO:

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH 2/2] tracetool: fix "PRI" macro decoding

In reply to Laurent Vivier
Quoted 18 lines · Laurent Vivier

macro is not reset after use, so the format decoded is always the one of the first "PRI" in the format string.

For instance:

  vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, \
                        uint32_t flags) "dev: %p offset: %"PRIu32" \
                        size: %"PRIu32" flags: 0x%"PRIx32

generates:

  printf("%d@%d vhost_vdpa_set_config dev: %p offset: %u size: %u \
          flags: 0x%u\n", pid(), gettimeofday_ns(), dev, offset, \
          size, flags)

for the "flags" parameter, we can see a "0x%u" rather than a "0x%x" because the first macro was "PRIu32" (for offset).

Quoted 8 lines

In the loop, macro becomes "PRIu32PRIu32PRIx32", and c_macro_to_format() returns always macro[3] ('u' in this case). This patch resets macro after the format has been decoded.

---
 scripts/tracetool/format/log_stap.py | 1 +
 1 file changed, 1 insertion(+)

Thanks, applied to my tracing tree:
https://gitlab.com/stefanha/qemu/commits/tracing

Stefan

Reviewed-by on the v1 series
#8 lore raw
In reply to Laurent Vivier
Quoted 8 lines · Laurent Vivier

The first patch fixes a problem I have introduced in vhost-vdpa traces by adding an unsupported format ("%llu").

The second patch fixes a problem I've seen while I was checking the result of the first patch: %PRI formats are not decoded correctly and we can end with things like "0x%u" because the used format is always the one of the first format of the string.

Quoted 8 lines

Laurent Vivier (2):
vhost-vdpa: fix "unsigned long long" error with stap
tracetool: fix "PRI" macro decoding

 hw/virtio/trace-events               | 2 +-
 hw/virtio/vhost-vdpa.c               | 4 ++--
 scripts/tracetool/format/log_stap.py | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)