Skip to contentSkip to conversation

trace: Remove and forbid newline characters in event format

PATCH Applied Philippe Mathieu-Daudé 5 participants 15 messages Jun 6, 2024 – Jun 10, 2024

lore
Share & tools
lore
#0 lore raw

cover trace: Remove and forbid newline characters in event format

Trace events aren't designed to be multi-lines.
Few format use the newline character: remove it
and forbid further uses.

Philippe Mathieu-Daudé (5):
backends/tpm: Remove newline character in trace event hw/sh4: Remove newline character in trace events hw/usb: Remove newline character in trace events hw/vfio: Remove newline character in trace events
tracetool: Forbid newline character in event format

 backends/tpm/tpm_util.c       | 5 +++--
 backends/tpm/trace-events     | 3 ++-
 hw/sh4/trace-events           | 4 ++--
 hw/usb/trace-events           | 6 +++---
 hw/vfio/trace-events          | 4 ++--
 scripts/tracetool/__init__.py | 2 ++
 6 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/5 backends/tpm: Remove newline character in trace event

Split the 'tpm_util_show_buffer' event in two to avoid using a newline character.

---
 backends/tpm/tpm_util.c   | 5 +++--
 backends/tpm/trace-events | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
backends/tpm/tpm_util.c +3 -2
index 1856589c3b..cf138551df 100644
@@ -339,10 +339,11 @@ void tpm_util_show_buffer(const unsigned char *buffer,
     size_t len, i;
     char *line_buffer, *p;
 
-    if (!trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) {
+    if (!trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER_CONTENT)) {
         return;
     }
     len = MIN(tpm_cmd_get_size(buffer), buffer_size);
+    trace_tpm_util_show_buffer_header(string, len);
 
     /*
      * allocate enough room for 3 chars per buffer entry plus a
@@ -356,7 +357,7 @@ void tpm_util_show_buffer(const unsigned char *buffer,
         }
         p += sprintf(p, "%.2X ", buffer[i]);
     }
-    trace_tpm_util_show_buffer(string, len, line_buffer);
+    trace_tpm_util_show_buffer_content(line_buffer);
 
     g_free(line_buffer);
 }
backends/tpm/trace-events +2 -1
index 1ecef42a07..cb5cfa6510 100644
@@ -10,7 +10,8 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u,
 tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu"
 tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu"
 tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu"
-tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s"
+tpm_util_show_buffer_header(const char *direction, size_t len) "direction: %s len: %zu"
+tpm_util_show_buffer_content(const char *buf) "%s"
 
 # tpm_emulator.c
 tpm_emulator_set_locality(uint8_t locty) "setting locality to %d"
Signature · 1 line
2.41.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] backends/tpm: Remove newline character in trace event

Quoted 8 lines · Philippe Mathieu-Daudé

Split the 'tpm_util_show_buffer' event in two to avoid using a newline character.

---
 backends/tpm/tpm_util.c   | 5 +++--
 backends/tpm/trace-events | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

With 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 :|
Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] backends/tpm: Remove newline character in trace event

In reply to Philippe Mathieu-Daudé
Quoted 40 lines · Philippe Mathieu-Daudé

Split the 'tpm_util_show_buffer' event in two to avoid using a newline character.

---
  backends/tpm/tpm_util.c   | 5 +++--
  backends/tpm/trace-events | 3 ++-
  2 files changed, 5 insertions(+), 3 deletions(-)
backends/tpm/tpm_util.c +3 -2
index 1856589c3b..cf138551df 100644
@@ -339,10 +339,11 @@ void tpm_util_show_buffer(const unsigned char *buffer,
      size_t len, i;
      char *line_buffer, *p;
 
-    if (!trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER)) {
+    if (!trace_event_get_state_backends(TRACE_TPM_UTIL_SHOW_BUFFER_CONTENT)) {
          return;
      }
      len = MIN(tpm_cmd_get_size(buffer), buffer_size);
+    trace_tpm_util_show_buffer_header(string, len);
 
      /*
       * allocate enough room for 3 chars per buffer entry plus a
@@ -356,7 +357,7 @@ void tpm_util_show_buffer(const unsigned char *buffer,
          }
          p += sprintf(p, "%.2X ", buffer[i]);
      }
-    trace_tpm_util_show_buffer(string, len, line_buffer);
+    trace_tpm_util_show_buffer_content(line_buffer);
 
      g_free(line_buffer);
  }
backends/tpm/trace-events +0 -0
index 1ecef42a07..cb5cfa6510 100644

backends/tpm/trace-events tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, · line 17

Quoted 9 lines
backends/tpm/trace-events +2 -1
@@ -10,7 +10,8 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u,
  tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu"
  tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu"
  tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu"
-tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s"
+tpm_util_show_buffer_header(const char *direction, size_t len) "direction: %s len: %zu"
+tpm_util_show_buffer_content(const char *buf) "%s"
 
  # tpm_emulator.c
  tpm_emulator_set_locality(uint8_t locty) "setting locality to %d"
#4 lore raw

PATCH 2/5 hw/sh4: Remove newline character in trace events

In reply to Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines. Remove the newline character which doesn't bring much value.

---
 hw/sh4/trace-events | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/sh4/trace-events +2 -2
index 4b61cd56c8..6bfd7eebc4 100644
@@ -1,3 +1,3 @@
 # sh7750.c
-sh7750_porta(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "porta changed from 0x%04x to 0x%04x\npdtra=0x%04x, pctra=0x%08x"
-sh7750_portb(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "portb changed from 0x%04x to 0x%04x\npdtrb=0x%04x, pctrb=0x%08x"
+sh7750_porta(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "porta changed from 0x%04x to 0x%04x (pdtra=0x%04x, pctra=0x%08x)"
+sh7750_portb(uint16_t prev, uint16_t cur, uint16_t pdtr, uint16_t pctr) "portb changed from 0x%04x to 0x%04x (pdtrb=0x%04x, pctrb=0x%08x)"
Signature · 1 line
2.41.0
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] hw/sh4: Remove newline character in trace events

Quoted 7 lines · Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines. Remove the newline character which doesn't bring much value.

---
 hw/sh4/trace-events | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

With 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 :|
#6 lore raw

PATCH 3/5 hw/usb: Remove newline character in trace events

In reply to Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Remove the newline characters.

---
 hw/usb/trace-events | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/usb/trace-events +3 -3
index fd7b90d70c..46732717a9 100644
@@ -15,7 +15,7 @@ usb_ohci_exit(const char *s) "%s"
 
 # hcd-ohci.c
 usb_ohci_iso_td_read_failed(uint32_t addr) "ISO_TD read error at 0x%x"
-usb_ohci_iso_td_head(uint32_t head, uint32_t tail, uint32_t flags, uint32_t bp, uint32_t next, uint32_t be, uint32_t framenum, uint32_t startframe, uint32_t framecount, int rel_frame_num) "ISO_TD ED head 0x%.8x tailp 0x%.8x\n0x%.8x 0x%.8x 0x%.8x 0x%.8x\nframe_number 0x%.8x starting_frame 0x%.8x\nframe_count  0x%.8x relative %d"
+usb_ohci_iso_td_head(uint32_t head, uint32_t tail, uint32_t flags, uint32_t bp, uint32_t next, uint32_t be, uint32_t framenum, uint32_t startframe, uint32_t framecount, int rel_frame_num) "ISO_TD ED head 0x%.8x tailp 0x%.8x, flags 0x%.8x bp 0x%.8x next 0x%.8x be 0x%.8x, frame_number 0x%.8x starting_frame 0x%.8x, frame_count 0x%.8x relative %d"
 usb_ohci_iso_td_head_offset(uint32_t o0, uint32_t o1, uint32_t o2, uint32_t o3, uint32_t o4, uint32_t o5, uint32_t o6, uint32_t o7) "0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x"
 usb_ohci_iso_td_relative_frame_number_neg(int rel) "ISO_TD R=%d < 0"
 usb_ohci_iso_td_relative_frame_number_big(int rel, int count) "ISO_TD R=%d > FC=%d"
@@ -23,7 +23,7 @@ usb_ohci_iso_td_bad_direction(int dir) "Bad direction %d"
 usb_ohci_iso_td_bad_bp_be(uint32_t bp, uint32_t be) "ISO_TD bp 0x%.8x be 0x%.8x"
 usb_ohci_iso_td_bad_cc_not_accessed(uint32_t start, uint32_t next) "ISO_TD cc != not accessed 0x%.8x 0x%.8x"
 usb_ohci_iso_td_bad_cc_overrun(uint32_t start, uint32_t next) "ISO_TD start_offset=0x%.8x > next_offset=0x%.8x"
-usb_ohci_iso_td_so(uint32_t so, uint32_t eo, uint32_t s, uint32_t e, const char *str, ssize_t len, int ret) "0x%.8x eo 0x%.8x\nsa 0x%.8x ea 0x%.8x\ndir %s len %zu ret %d"
+usb_ohci_iso_td_so(uint32_t so, uint32_t eo, uint32_t s, uint32_t e, const char *str, ssize_t len, int ret) "0x%.8x eo 0x%.8x sa 0x%.8x ea 0x%.8x dir %s len %zu ret %d"
 usb_ohci_iso_td_data_overrun(int ret, ssize_t len) "DataOverrun %d > %zu"
 usb_ohci_iso_td_data_underrun(int ret) "DataUnderrun %d"
 usb_ohci_iso_td_nak(int ret) "got NAK/STALL %d"
@@ -55,7 +55,7 @@ usb_ohci_td_pkt_full(const char *dir, const char *buf) "%s data: %s"
 usb_ohci_td_too_many_pending(int ep) "ep=%d"
 usb_ohci_td_packet_status(int status) "status=%d"
 usb_ohci_ed_read_error(uint32_t addr) "ED read error at 0x%x"
-usb_ohci_ed_pkt(uint32_t cur, int h, int c, uint32_t head, uint32_t tail, uint32_t next) "ED @ 0x%.8x h=%u c=%u\n  head=0x%.8x tailp=0x%.8x next=0x%.8x"
+usb_ohci_ed_pkt(uint32_t cur, int h, int c, uint32_t head, uint32_t tail, uint32_t next) "ED @ 0x%.8x h=%u c=%u head=0x%.8x tailp=0x%.8x next=0x%.8x"
 usb_ohci_ed_pkt_flags(uint32_t fa, uint32_t en, uint32_t d, int s, int k, int f, uint32_t mps) "fa=%u en=%u d=%u s=%u k=%u f=%u mps=%u"
 usb_ohci_hcca_read_error(uint32_t addr) "HCCA read error at 0x%x"
 usb_ohci_mem_read(uint32_t size, const char *name, uint32_t addr, uint32_t offs, uint32_t val) "%d %s 0x%x %d -> 0x%x"
Signature · 1 line
2.41.0
Reviewed-by on v1 3/5
#7 lore raw

Re: [PATCH 3/5] hw/usb: Remove newline character in trace events

Quoted 7 lines · Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Remove the newline characters.

---
 hw/usb/trace-events | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

With 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 :|
#8 lore raw

PATCH 4/5 hw/vfio: Remove newline character in trace events

In reply to Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Remove the newline characters.

---
 hw/vfio/trace-events | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/trace-events +2 -2
index 64161bf6f4..e16179b507 100644
@@ -19,7 +19,7 @@ vfio_msix_fixup(const char *name, int bar, uint64_t start, uint64_t end) " (%s)
 vfio_msix_relo(const char *name, int bar, uint64_t offset) " (%s) BAR %d offset 0x%"PRIx64""
 vfio_msi_enable(const char *name, int nr_vectors) " (%s) Enabled %d MSI vectors"
 vfio_msi_disable(const char *name) " (%s)"
-vfio_pci_load_rom(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s ROM:\n  size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
+vfio_pci_load_rom(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device '%s' ROM: size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
 vfio_rom_read(const char *name, uint64_t addr, int size, uint64_t data) " (%s, 0x%"PRIx64", 0x%x) = 0x%"PRIx64
 vfio_pci_size_rom(const char *name, int size) "%s ROM size 0x%x"
 vfio_vga_write(uint64_t addr, uint64_t data, int size) " (0x%"PRIx64", 0x%"PRIx64", %d)"
@@ -35,7 +35,7 @@ vfio_pci_hot_reset(const char *name, const char *type) " (%s) %s"
 vfio_pci_hot_reset_has_dep_devices(const char *name) "%s: hot reset dependent devices:"
 vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int group_id) "\t%04x:%02x:%02x.%x group %d"
 vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s"
-vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s config:\n  size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
+vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device '%s' config: size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
 vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_IRQ_INFO failure: %s"
 vfio_attach_device(const char *name, int group_id) " (%s) group %d"
 vfio_detach_device(const char *name, int group_id) " (%s) group %d"
Signature · 1 line
2.41.0
Reviewed-by on v1 4/5
#9 lore raw

Re: [PATCH 4/5] hw/vfio: Remove newline character in trace events

Quoted 7 lines · Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Remove the newline characters.

---
 hw/vfio/trace-events | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

With 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 :|
#10 lore raw

PATCH 5/5 tracetool: Forbid newline character in event format

In reply to Philippe Mathieu-Daudé

Events aren't designed to be multi-lines. Multiple events can be used instead. Prevent that format using multi-lines by forbidding the newline character.

---
 scripts/tracetool/__init__.py | 2 ++
 1 file changed, 2 insertions(+)
scripts/tracetool/__init__.py +2 -0
index 7237abe0e8..bc03238c0f 100644
@@ -301,6 +301,8 @@ def build(line_str, lineno, filename):
         if fmt.endswith(r'\n"'):
             raise ValueError("Event format must not end with a newline "
                              "character")
+        if '\\n' in fmt:
+            raise ValueError("Event format must not use new line character")
 
         if len(fmt_trans) > 0:
             fmt = [fmt_trans, fmt]
Signature · 1 line
2.41.0
Reviewed-by on v1 5/5
#11 lore raw

Re: [PATCH 5/5] tracetool: Forbid newline character in event format

Quoted 8 lines · Philippe Mathieu-Daudé

Events aren't designed to be multi-lines. Multiple events can be used instead. Prevent that format using multi-lines by forbidding the newline character.

---
 scripts/tracetool/__init__.py | 2 ++
 1 file changed, 2 insertions(+)

With 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 :|
Acked-by on the v1 series
#12 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 12 lines

Trace events aren't designed to be multi-lines. Few format use the newline character: remove it and forbid further uses.

Philippe Mathieu-Daudé (5):
backends/tpm: Remove newline character in trace event hw/sh4: Remove newline character in trace events hw/usb: Remove newline character in trace events hw/vfio: Remove newline character in trace events
tracetool: Forbid newline character in event format

Quoted 11 lines
backends/tpm/tpm_util.c       | 5 +++--
backends/tpm/trace-events     | 3 ++-
hw/sh4/trace-events           | 4 ++--
hw/usb/trace-events           | 6 +++---
hw/vfio/trace-events          | 4 ++--
scripts/tracetool/__init__.py | 2 ++
6 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.41.0
#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Few format use the newline character: remove it
and forbid further uses.

Philippe Mathieu-Daudé (5):
backends/tpm: Remove newline character in trace event hw/sh4: Remove newline character in trace events hw/usb: Remove newline character in trace events hw/vfio: Remove newline character in trace events
tracetool: Forbid newline character in event format

Quoted 11 lines
 backends/tpm/tpm_util.c       | 5 +++--
 backends/tpm/trace-events     | 3 ++-
 hw/sh4/trace-events           | 4 ++--
 hw/usb/trace-events           | 6 +++---
 hw/vfio/trace-events          | 4 ++--
 scripts/tracetool/__init__.py | 2 ++
 6 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.41.0

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

Stefan

#14 lore raw
Quoted 13 lines · Stefan Hajnoczi
Quoted 10 lines · Philippe Mathieu-Daudé

Trace events aren't designed to be multi-lines.
Few format use the newline character: remove it
and forbid further uses.

Philippe Mathieu-Daudé (5):
backends/tpm: Remove newline character in trace event hw/sh4: Remove newline character in trace events hw/usb: Remove newline character in trace events hw/vfio: Remove newline character in trace events
tracetool: Forbid newline character in event format

Quoted 2 lines

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

Thanks!