Skip to contentSkip to conversation

Add dtrace support on macOS

PATCH Applied Roman Bolshakov 5 participants 21 messages Jul 17, 2020 – Aug 7, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Add dtrace support on macOS

Hi,

This is a small series that enables dtrace tracing backend on macOS. Whether or not it should go to 5.1 is up to discretion of tracing maintainers.

Thanks,
Roman

Changes since v1:
- Fixed a typo ANSI C to C99, wrt to _Bool in the first patch.
- Prevented a few [-Wpointer-sign] warnings by converting int8_t * to signed char * in static probe definitions.
- Moved COLO packet dump under #ifdef DEBUG_COLO_PACKETS (Daniel).
- Separated tracepoints in net/filter-rewriter.c to use matching is-enabled probe (Daniel).

Roman Bolshakov (4):
scripts/tracetool: Fix dtrace generation for macOS scripts/tracetool: Use void pointer for vcpu
build: Don't make object files for dtrace on macOS net/colo: Match is-enabled probe to tracepoint

 Makefile.objs                 |  2 ++
 net/colo-compare.c            | 42 ++++++++++++++++++-----------------
 net/filter-rewriter.c         | 10 +++++++--
 net/trace-events              |  2 --
 scripts/tracetool/format/d.py | 15 ++++++++++++-
 scripts/tracetool/vcpu.py     |  2 +-
 6 files changed, 47 insertions(+), 26 deletions(-)
Signature · 1 line
2.26.1
#1 lore raw

PATCH v2 1/4 scripts/tracetool: Fix dtrace generation for macOS

dtrace USDT is fully supported since OS X 10.6. There are a few peculiarities compared to other dtrace flavors.

1. It doesn't accept empty files.
2. It doesn't recognize bool type but accepts C99 _Bool.
3. It converts int8_t * in probe points to char * in header files and introduces [-Wpointer-sign] warning.

Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/format/d.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
scripts/tracetool/format/d.py +14 -1
index 0afb5f3f47..353722f89c 100644
@@ -13,6 +13,7 @@ __email__      = "[email protected]"
 
 
 from tracetool import out
+from sys import platform
 
 
 # Reserved keywords from
@@ -34,7 +35,8 @@ def generate(events, backend, group):
 
     # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
     # with an empty file.  Avoid the warning.
-    if not events:
+    # But dtrace on macOS can't deal with empty files.
+    if not events and platform != "darwin":
         return
 
     out('/* This file is autogenerated by tracetool, do not edit. */'
@@ -44,6 +46,17 @@ def generate(events, backend, group):
     for e in events:
         args = []
         for type_, name in e.args:
+            if platform == "darwin":
+                # macOS dtrace accepts only C99 _Bool
+                if type_ == 'bool':
+                    type_ = '_Bool'
+                if type_ == 'bool *':
+                    type_ = '_Bool *'
+                # It converts int8_t * in probe points to char * in header
+                # files and introduces [-Wpointer-sign] warning.
+                # Avoid it by changing probe type to signed char * beforehand.
+                if type_ == 'int8_t *':
+                    type_ = 'signed char *'
             if name in RESERVED_WORDS:
                 name += '_'
             args.append(type_ + ' ' + name)
Signature · 1 line
2.26.1
#2 lore raw

Re: [PATCH v2 1/4] scripts/tracetool: Fix dtrace generation for macOS

Quoted 27 lines · Roman Bolshakov

dtrace USDT is fully supported since OS X 10.6. There are a few peculiarities compared to other dtrace flavors.

1. It doesn't accept empty files.
2. It doesn't recognize bool type but accepts C99 _Bool.
3. It converts int8_t * in probe points to char * in header files and introduces [-Wpointer-sign] warning.

Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/format/d.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
scripts/tracetool/format/d.py +1 -0
index 0afb5f3f47..353722f89c 100644
@@ -13,6 +13,7 @@ __email__      = "[email protected]"
 
 
 from tracetool import out
+from sys import platform
 
 
 # Reserved keywords from

scripts/tracetool/format/d.py def generate(events, backend, group): · line 39

Quoted 6 lines
scripts/tracetool/format/d.py +2 -1
@@ -34,7 +35,8 @@ def generate(events, backend, group):
 
     # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
     # with an empty file.  Avoid the warning.
-    if not events:
+    # But dtrace on macOS can't deal with empty files.
+    if not events and platform != "darwin":

or?

scripts/tracetool/format/d.py def generate(events, backend, group): · line 50

Quoted 9 lines
scripts/tracetool/format/d.py +2 -0
         return
 
     out('/* This file is autogenerated by tracetool, do not edit. */'
@@ -44,6 +46,17 @@ def generate(events, backend, group):
     for e in events:
         args = []
         for type_, name in e.args:
+            if platform == "darwin":
+                # macOS dtrace accepts only C99 _Bool

Why not do that for all platforms?

Quoted 13 lines
scripts/tracetool/format/d.py +9 -0
+                if type_ == 'bool':
+                    type_ = '_Bool'
+                if type_ == 'bool *':
+                    type_ = '_Bool *'
+                # It converts int8_t * in probe points to char * in header
+                # files and introduces [-Wpointer-sign] warning.
+                # Avoid it by changing probe type to signed char * beforehand.
+                if type_ == 'int8_t *':
+                    type_ = 'signed char *'
             if name in RESERVED_WORDS:
                 name += '_'
             args.append(type_ + ' ' + name)
#3 lore raw

Re: [PATCH v2 1/4] scripts/tracetool: Fix dtrace generation for macOS

Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Roman Bolshakov

dtrace USDT is fully supported since OS X 10.6. There are a few peculiarities compared to other dtrace flavors.

1. It doesn't accept empty files.
2. It doesn't recognize bool type but accepts C99 _Bool.
3. It converts int8_t * in probe points to char * in header files and introduces [-Wpointer-sign] warning.

Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/format/d.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
scripts/tracetool/format/d.py +1 -0
index 0afb5f3f47..353722f89c 100644
@@ -13,6 +13,7 @@ __email__      = "[email protected]"
 
 
 from tracetool import out
+from sys import platform
 
 
 # Reserved keywords from
@@ -34,7 +35,8 @@ def generate(events, backend, group):
 
Quoted 7 lines

scripts/tracetool/format/d.py def generate(events, backend, group): · line 39

Quoted 5 lines
scripts/tracetool/format/d.py +2 -1
     # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
     # with an empty file.  Avoid the warning.
-    if not events:
+    # But dtrace on macOS can't deal with empty files.
+    if not events and platform != "darwin":

or?

no, the event list is empty for some files where all events are disabled (e.g. hppa/trace-events), so it should have an "and" here. This limits early exit only on macOS. The precendence looks correct:

https://docs.python.org/3/reference/expressions.html#operator-precedence

Quoted 13 lines

scripts/tracetool/format/d.py def generate(events, backend, group): · line 50

Quoted 10 lines
scripts/tracetool/format/d.py +2 -0
         return
 
     out('/* This file is autogenerated by tracetool, do not edit. */'
@@ -44,6 +46,17 @@ def generate(events, backend, group):
     for e in events:
         args = []
         for type_, name in e.args:
+            if platform == "darwin":
+                # macOS dtrace accepts only C99 _Bool

Why not do that for all platforms?

Because I can only test the changes on darwin :)
I don't know how other dtrace flavors behave and whether it is an issue for dtrace on Linux/Solaris/FreeBSD/etc.

Thanks,
Roman

Quoted 14 lines
Quoted 13 lines
scripts/tracetool/format/d.py +9 -0
+                if type_ == 'bool':
+                    type_ = '_Bool'
+                if type_ == 'bool *':
+                    type_ = '_Bool *'
+                # It converts int8_t * in probe points to char * in header
+                # files and introduces [-Wpointer-sign] warning.
+                # Avoid it by changing probe type to signed char * beforehand.
+                if type_ == 'int8_t *':
+                    type_ = 'signed char *'
             if name in RESERVED_WORDS:
                 name += '_'
             args.append(type_ + ' ' + name)
#4 lore raw

Re: [PATCH v2 1/4] scripts/tracetool: Fix dtrace generation for macOS

Quoted 38 lines · Roman Bolshakov
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Roman Bolshakov

dtrace USDT is fully supported since OS X 10.6. There are a few peculiarities compared to other dtrace flavors.

1. It doesn't accept empty files.
2. It doesn't recognize bool type but accepts C99 _Bool.
3. It converts int8_t * in probe points to char * in header files and introduces [-Wpointer-sign] warning.

Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/format/d.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
scripts/tracetool/format/d.py +1 -0
index 0afb5f3f47..353722f89c 100644
@@ -13,6 +13,7 @@ __email__      = "[email protected]"
 
 
 from tracetool import out
+from sys import platform
 
 
 # Reserved keywords from
@@ -34,7 +35,8 @@ def generate(events, backend, group):
 
Quoted 7 lines

scripts/tracetool/format/d.py def generate(events, backend, group): · line 39

Quoted 5 lines
scripts/tracetool/format/d.py +2 -1
     # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
     # with an empty file.  Avoid the warning.
-    if not events:
+    # But dtrace on macOS can't deal with empty files.
+    if not events and platform != "darwin":

or?

Quoted 3 lines

no, the event list is empty for some files where all events are disabled (e.g. hppa/trace-events), so it should have an "and" here. This limits early exit only on macOS.

Ah yes you are right, I misread it.

Quoted 40 lines

The precendence looks correct:

https://docs.python.org/3/reference/expressions.html#operator-precedence

Quoted 13 lines

scripts/tracetool/format/d.py def generate(events, backend, group): · line 50

Quoted 10 lines
scripts/tracetool/format/d.py +2 -0
         return
 
     out('/* This file is autogenerated by tracetool, do not edit. */'
@@ -44,6 +46,17 @@ def generate(events, backend, group):
     for e in events:
         args = []
         for type_, name in e.args:
+            if platform == "darwin":
+                # macOS dtrace accepts only C99 _Bool

Why not do that for all platforms?

Because I can only test the changes on darwin :)
I don't know how other dtrace flavors behave and whether it is an issue for dtrace on Linux/Solaris/FreeBSD/etc.

Thanks,
Roman

Quoted 14 lines
Quoted 13 lines
scripts/tracetool/format/d.py +9 -0
+                if type_ == 'bool':
+                    type_ = '_Bool'
+                if type_ == 'bool *':
+                    type_ = '_Bool *'
+                # It converts int8_t * in probe points to char * in header
+                # files and introduces [-Wpointer-sign] warning.
+                # Avoid it by changing probe type to signed char * beforehand.
+                if type_ == 'int8_t *':
+                    type_ = 'signed char *'
             if name in RESERVED_WORDS:
                 name += '_'
             args.append(type_ + ' ' + name)
Reviewed-by on v2 1/4
#5 lore raw

Re: [PATCH v2 1/4] scripts/tracetool: Fix dtrace generation for macOS

In reply to Roman Bolshakov
Quoted 8 lines · Roman Bolshakov

dtrace USDT is fully supported since OS X 10.6. There are a few peculiarities compared to other dtrace flavors.

1. It doesn't accept empty files.
2. It doesn't recognize bool type but accepts C99 _Bool.
3. It converts int8_t * in probe points to char * in header files and introduces [-Wpointer-sign] warning.

Quoted 5 lines
Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/format/d.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
#6 lore raw

PATCH v2 2/4 scripts/tracetool: Use void pointer for vcpu

In reply to Roman Bolshakov

dtrace on macOS complains that CPUState * is used for a few probes:

dtrace: failed to compile script trace-dtrace-root.dtrace: line 130: syntax error near "CPUState"

A comment in scripts/tracetool/__init__.py mentions that:

We only want to allow standard C types or fixed sized integer types. We don't want QEMU specific types as we can't assume trace backends can resolve all the typedefs

Fixes 3d211d9f4dbee ("trace: Add 'vcpu' event property to trace guest vCPU")
Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/vcpu.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tracetool/vcpu.py +1 -1
index b54e4f4e7a..868b4cb04c 100644
@@ -24,7 +24,7 @@ def transform_event(event):
         assert "tcg-trans" not in event.properties
         assert "tcg-exec" not in event.properties
 
-        event.args = Arguments([("CPUState *", "__cpu"), event.args])
+        event.args = Arguments([("void *", "__cpu"), event.args])
         if "tcg" in event.properties:
             fmt = "\"cpu=%p \""
             event.fmt = [fmt + event.fmt[0],
Signature · 1 line
2.26.1
Reviewed-by on v2 2/4
#7 lore raw

Re: [PATCH v2 2/4] scripts/tracetool: Use void pointer for vcpu

Quoted 11 lines · Roman Bolshakov

dtrace on macOS complains that CPUState * is used for a few probes:

dtrace: failed to compile script trace-dtrace-root.dtrace: line 130: syntax error near "CPUState"

A comment in scripts/tracetool/__init__.py mentions that:

We only want to allow standard C types or fixed sized integer types. We don't want QEMU specific types as we can't assume trace backends can resolve all the typedefs

Quoted 7 lines
Fixes 3d211d9f4dbee ("trace: Add 'vcpu' event property to trace guest vCPU")
Cc Cameron Esfahani <[email protected]>
---
 scripts/tracetool/vcpu.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#8 lore raw

PATCH v2 3/4 build: Don't make object files for dtrace on macOS

In reply to Roman Bolshakov

dtrace on macOS uses unresolved symbols with a special prefix to define probes [1], only headers should be generated for USDT (dtrace(1)). But it doesn't support backwards compatible no-op -G flag [2] and implicit build rules fail.

1. https://markmail.org/message/6grq2ygr5nwdwsnb
2. https://markmail.org/message/5xrxt2w5m42nojkz

---
 Makefile.objs | 2 ++
 1 file changed, 2 insertions(+)
Makefile.objs +2 -0
index d22b3b45d7..982f15ba30 100644
@@ -211,5 +211,7 @@ trace-events-files = $(SRC_PATH)/trace-events $(trace-events-subdirs:%=$(SRC_PAT
 trace-obj-y = trace-root.o
 trace-obj-y += $(trace-events-subdirs:%=%/trace.o)
 trace-obj-$(CONFIG_TRACE_UST) += trace-ust-all.o
+ifneq ($(CONFIG_DARWIN),y)
 trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace-root.o
 trace-obj-$(CONFIG_TRACE_DTRACE) += $(trace-events-subdirs:%=%/trace-dtrace.o)
+endif
Signature · 1 line
2.26.1
Reviewed-by on v2 3/4
#9 lore raw

Re: [PATCH v2 3/4] build: Don't make object files for dtrace on macOS

Quoted 8 lines · Roman Bolshakov

dtrace on macOS uses unresolved symbols with a special prefix to define probes [1], only headers should be generated for USDT (dtrace(1)). But it doesn't support backwards compatible no-op -G flag [2] and implicit build rules fail.

1. https://markmail.org/message/6grq2ygr5nwdwsnb
2. https://markmail.org/message/5xrxt2w5m42nojkz

Quoted 6 lines
---
 Makefile.objs | 2 ++
 1 file changed, 2 insertions(+)
#10 lore raw

Re: [PATCH v2 3/4] build: Don't make object files for dtrace on macOS

In reply to Roman Bolshakov
Quoted 30 lines · Roman Bolshakov

dtrace on macOS uses unresolved symbols with a special prefix to define probes [1], only headers should be generated for USDT (dtrace(1)). But it doesn't support backwards compatible no-op -G flag [2] and implicit build rules fail.

1. https://markmail.org/message/6grq2ygr5nwdwsnb
2. https://markmail.org/message/5xrxt2w5m42nojkz

---
 Makefile.objs | 2 ++
 1 file changed, 2 insertions(+)
Makefile.objs +2 -0
index d22b3b45d7..982f15ba30 100644
@@ -211,5 +211,7 @@ trace-events-files = $(SRC_PATH)/trace-events $(trace-events-subdirs:%=$(SRC_PAT
 trace-obj-y = trace-root.o
 trace-obj-y += $(trace-events-subdirs:%=%/trace.o)
 trace-obj-$(CONFIG_TRACE_UST) += trace-ust-all.o
+ifneq ($(CONFIG_DARWIN),y)
 trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace-root.o
 trace-obj-$(CONFIG_TRACE_DTRACE) += $(trace-events-subdirs:%=%/trace-dtrace.o)
+endif
Signature · 1 line
2.26.1

An article about DTrace [1] mentions that FreeBSD also doesn't need that:
"On FreeBSD/Mac OS X, you do not have to generate a separate probe object file for linking. This makes the compilation process much more straightforward [...]"

I don't know for sure but perhaps "-G" makes dummy object files there.

1. https://www.ibm.com/developerworks/aix/library/au-dtraceprobes.html

Thanks,
Roman

#11 lore raw

PATCH v2 4/4 net/colo: Match is-enabled probe to tracepoint

In reply to Roman Bolshakov

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile-time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)
net/colo-compare.c +22 -20
index 398b7546ff..e0be98e494 100644
@@ -54,6 +54,8 @@ static NotifierList colo_compare_notifiers =
 #define REGULAR_PACKET_CHECK_MS 3000
 #define DEFAULT_TIME_OUT_MS 3000
 
+/* #define DEBUG_COLO_PACKETS */
+
 static QemuMutex colo_compare_mutex;
 static bool colo_compare_active;
 static QemuMutex event_mtx;
@@ -327,7 +329,7 @@ static int colo_compare_packet_payload(Packet *ppkt,
                                        uint16_t len)
 
 {
-    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO)) {
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
 
         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src));
@@ -492,12 +494,12 @@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);
 
-        if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size);
+#endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
-        if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif
         return -1;
     } else {
         return 0;
@@ -576,12 +578,12 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
                                            ppkt->size);
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
-        if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif
         return -1;
     } else {
         return 0;
@@ -597,7 +599,7 @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
     uint16_t offset = ppkt->vnet_hdr_len;
 
     trace_colo_compare_main("compare other");
-    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO)) {
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
 
         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src));
net/filter-rewriter.c +8 -2
index 1aaad101b6..576b019d09 100644
@@ -76,11 +76,14 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
     struct tcp_hdr *tcp_pkt;
 
     tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
-    if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
+    if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_PKT_INFO)) {
         trace_colo_filter_rewriter_pkt_info(__func__,
                     inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
+    }
+    if (trace_event_get_state_backends(
+          TRACE_COLO_FILTER_REWRITER_CONN_OFFSET)) {
         trace_colo_filter_rewriter_conn_offset(conn->offset);
     }
 
@@ -180,11 +183,14 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
 
     tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
 
-    if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
+    if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_PKT_INFO)) {
         trace_colo_filter_rewriter_pkt_info(__func__,
                     inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
+    }
+    if (trace_event_get_state_backends(
+          TRACE_COLO_FILTER_REWRITER_CONN_OFFSET)) {
         trace_colo_filter_rewriter_conn_offset(conn->offset);
     }
 
net/trace-events +0 -2
index fa49c71533..bfaff7891d 100644
@@ -17,10 +17,8 @@ colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d"
 colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
 colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
 colo_old_packet_check_found(int64_t old_time) "%" PRId64
-colo_compare_miscompare(void) ""
 colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int hdlen, int pdlen, int offset, int flags) "%s: seq/ack= %u/%u hdlen= %d pdlen= %d offset= %d flags=%d"
 
 # filter-rewriter.c
-colo_filter_rewriter_debug(void) ""
 colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u  flags=0x%x"
 colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u"
Signature · 1 line
2.26.1
#12 lore raw

RE: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 100 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)
net/colo-compare.c index renamed from net/colo-compare.c +0 -0

398b7546ff..e0be98e494 100644

net/colo-compare.c +0 -0
@@ -54,6 +54,8 @@ static NotifierList colo_compare_notifiers =  #define

REGULAR_PACKET_CHECK_MS 3000 #define DEFAULT_TIME_OUT_MS 3000

net/colo-compare.c +3 -1
+/* #define DEBUG_COLO_PACKETS */
+
 static QemuMutex colo_compare_mutex;
 static bool colo_compare_active;
 static QemuMutex event_mtx;
@@ -327,7 +329,7 @@ static int colo_compare_packet_payload(Packet
 *ppkt,
                                        uint16_t len)
 
 {
-    if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
+    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))
{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -492,12 +494,12
@@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if
(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {

net/colo-compare.c +5 -7
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, · line 543

Quoted 10 lines
net/colo-compare.c +6 -4
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

Hi Roman,

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

Thanks
Zhang Chen

Quoted 110 lines
         return -1;
     } else {
         return 0;
net/colo-compare.c +6 -6
@@ -576,12 +578,12 @@ static int colo_packet_compare_icmp(Packet *spkt,
 Packet *ppkt)
                                            ppkt->size);
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif
         return -1;
     } else {
         return 0;
net/colo-compare.c +1 -1
@@ -597,7 +599,7 @@ static int colo_packet_compare_other(Packet *spkt,
 Packet *ppkt)
     uint16_t offset = ppkt->vnet_hdr_len;
 
     trace_colo_compare_main("compare other");
-    if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
+    if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))
{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); diff --git a/net/filter-

rewriter.c b/net/filter-rewriter.c index 1aaad101b6..576b019d09 100644

net/filter-rewriter.c +0 -1
@@ -76,11 +76,14 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
     struct tcp_hdr *tcp_pkt;
 
     tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
-    if

(trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG )) {

net/filter-rewriter.c +2 -0
+    if
+

(trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_PKT_IN FO))

+ {
         trace_colo_filter_rewriter_pkt_info(__func__,
                     inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
net/filter-rewriter.c +3 -1
+    }
+    if (trace_event_get_state_backends(
+          TRACE_COLO_FILTER_REWRITER_CONN_OFFSET)) {
         trace_colo_filter_rewriter_conn_offset(conn->offset);
     }
@@ -180,11 +183,14 @@ static int handle_secondary_tcp_pkt(RewriterState
 *rf,
 
     tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
 
-    if

(trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG )) {

net/filter-rewriter.c +2 -0
+    if
+

(trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_PKT_IN FO))

+ {
         trace_colo_filter_rewriter_pkt_info(__func__,
                     inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
net/filter-rewriter.c +3 -0
+    }
+    if (trace_event_get_state_backends(
+          TRACE_COLO_FILTER_REWRITER_CONN_OFFSET)) {
         trace_colo_filter_rewriter_conn_offset(conn->offset);
     }
net/trace-events index renamed from net/trace-events +0 -0

fa49c71533..bfaff7891d 100644

net/trace-events +0 -0
@@ -17,10 +17,8 @@ colo_compare_udp_miscompare(const char *sta, int

size) ": %s = %d"
colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize,
const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
colo_old_packet_check_found(int64_t old_time) "%" PRId64
-colo_compare_miscompare(void) ""
colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int
hdlen, int pdlen, int offset, int flags) "%s: seq/ack= %u/%u hdlen= %d pdlen= %d offset= %d flags=%d"

 # filter-rewriter.c
-colo_filter_rewriter_debug(void) ""
 colo_filter_rewriter_pkt_info(const char *func, const char *src, const char
*dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p:
seq/ack=%u/%u  flags=0x%x"
 colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u"
--
2.26.1
#13 lore raw

Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 18 lines · Chen
Quoted 18 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM

net/colo-compare.c +1 -6
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
Quoted 9 lines

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) · line 543

Quoted 5 lines
net/colo-compare.c +5 -0
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

Hi Chen,

Do you mean to use another is-enabled probe?
e.g. change from
"if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))" to
"if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MAIN))"

Thanks,
Roman

#14 lore raw

Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

In reply to Zhang, Chen
Quoted 96 lines · Chen
Quoted 83 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))

{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -492,12 +494,12
@@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if
(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {

net/colo-compare.c +5 -7
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, · line 543

Quoted 10 lines
net/colo-compare.c +6 -4
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

Hi Roman,

Quoted 3 lines

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

That may workaround the immediate bug, but this is still a misuse of the tracing code. Use of any trace point should only trigger actions in the trace infrastructure.

If I'm using dtrace backend to monitor events I don't want to see QEMU dumping stuff to stderr. Anything written to stderr is going to trigger disk I/O writing to the VM's logfile, and is also liable to trigger rate limiting which can impact the guest performance.

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

Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 101 lines · Daniel P. Berrangé
Quoted 96 lines · Chen
Quoted 83 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))

{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -492,12 +494,12
@@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if
(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {

net/colo-compare.c +5 -7
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, · line 543

Quoted 10 lines
net/colo-compare.c +6 -4
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

Hi Roman,

Quoted 3 lines

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

Quoted 9 lines

That may workaround the immediate bug, but this is still a misuse of the tracing code. Use of any trace point should only trigger actions in the trace infrastructure.

If I'm using dtrace backend to monitor events I don't want to see QEMU dumping stuff to stderr. Anything written to stderr is going to trigger disk I/O writing to the VM's logfile, and is also liable to trigger rate limiting which can impact the guest performance.

Hi Daniel, Chen, Stefan,

So, what do we want to do about the series? Do we have an agreement? Is the patch okay or I should make a change?

BTW. I've found that Apple added trace probes to Hypervisor.framework in Big Sur and there're fbt probes in AppleHV.kext. Addition of dtrace on macOS helps to find performance or functional issues. (I'm using the series in my private branches for debugging).

Thanks,
Roman

#16 lore raw

Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 112 lines · Roman Bolshakov
Quoted 101 lines · Daniel P. Berrangé
Quoted 96 lines · Chen
Quoted 83 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))

{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -492,12 +494,12
@@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if
(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {

net/colo-compare.c +5 -7
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, · line 543

Quoted 10 lines
net/colo-compare.c +6 -4
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

Hi Roman,

Quoted 3 lines

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

Quoted 9 lines

That may workaround the immediate bug, but this is still a misuse of the tracing code. Use of any trace point should only trigger actions in the trace infrastructure.

If I'm using dtrace backend to monitor events I don't want to see QEMU dumping stuff to stderr. Anything written to stderr is going to trigger disk I/O writing to the VM's logfile, and is also liable to trigger rate limiting which can impact the guest performance.

Quoted 4 lines

Hi Daniel, Chen, Stefan,

So, what do we want to do about the series? Do we have an agreement? Is the patch okay or I should make a change?

I think your current patch here should be merged as is, as it is removing the mis-use of the trace infrastructure.

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

Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 113 lines · Daniel P. Berrangé
Quoted 112 lines · Roman Bolshakov
Quoted 110 lines · Daniel P. Berrangé
Quoted 96 lines · Chen
Quoted 83 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm not sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not used explicitly. Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet comparison")
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++--------------------
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
+ if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))

{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@ -492,12 +494,12
@@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if
(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {

net/colo-compare.c +5 -7
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
 
         colo_compare_inconsistency_notify(s);
     }
@@ -533,12 +535,12 @@ static int colo_packet_compare_udp(Packet *spkt,
 Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt-
 >size);
-        if
 (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE))
 {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, · line 543

Quoted 10 lines
net/colo-compare.c +6 -4
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+                     spkt->size);
+#endif

Hi Roman,

Quoted 3 lines

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice here. It will keep the original code logic and avoid the problem here.

That may workaround the immediate bug, but this is still a misuse of the tracing code. Use of any trace point should only trigger actions in the trace infrastructure.

If I'm using dtrace backend to monitor events I don't want to see QEMU dumping stuff to stderr. Anything written to stderr is going to trigger disk I/O writing to the VM's logfile, and is also liable to trigger rate limiting which can impact the guest performance.

Quoted 7 lines
Quoted 4 lines

Hi Daniel, Chen, Stefan,

So, what do we want to do about the series? Do we have an agreement? Is the patch okay or I should make a change?

I think your current patch here should be merged as is, as it is removing the mis-use of the trace infrastructure.

Hi Zhang Chen,
Do you agree?

Thanks,
Stefan

Reviewed-by
#18 lore raw

RE: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 150 lines

-----Original Message-----
From: Stefan Hajnoczi <[email protected]>
Sent: Wednesday, August 5, 2020 6:53 PM
To: Zhang, Chen <[email protected]>
Cc: Roman Bolshakov <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- [email protected]; Cameron Esfahani <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Daniel Berrange <[email protected]>
Subject: Re: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Quoted 20 lines · Daniel P. Berrangé
Quoted 19 lines · Roman Bolshakov
Quoted 18 lines · Daniel P. Berrangé
Quoted 17 lines · Chen
Quoted 17 lines

-----Original Message-----
From: Roman Bolshakov <[email protected]>
Sent: Friday, July 17, 2020 5:35 PM
To: [email protected]
Cc: Daniel P. Berrangé <[email protected]>; Stefan Hajnoczi <[email protected]>; Cameron Esfahani <[email protected]>; Roman Bolshakov <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH v2 4/4] net/colo: Match is-enabled probe to tracepoint

Build of QEMU with dtrace fails on macOS:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

LINK x86_64-softmmu/qemu-system-x86_64
error: probe colo_compare_miscompare doesn't exist
error: Could not register probes
ld: error creating dtrace DOF section for architecture x86_64

The reason of the error is explained by Adam Leventhal [1]:

Note that is-enabled probes don't have the stability magic so I'm

not

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

sure how things would work if only is-enabled probes were used.

net/colo code uses is-enabled probes to determine if other probes should be used but colo_compare_miscompare itself is not

used explicitly.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Linker doesn't include the symbol and build fails.

The issue can be resolved if is-enabled probe matches the actual trace point that is used inside the test. Packet dump toggle is replaced with a compile- time conditional definition.

1. http://markmail.org/message/6grq2ygr5nwdwsnb

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Fixes f4b618360e ("colo-compare: add TCP, UDP, ICMP packet

comparison")

Cc Philippe Mathieu-Daudé <[email protected]>
Cc Cameron Esfahani <[email protected]>
---
 net/colo-compare.c    | 42 ++++++++++++++++++++++---------------

-----

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
 net/filter-rewriter.c | 10 ++++++++--
 net/trace-events      |  2 --
 3 files changed, 30 insertions(+), 24 deletions(-)

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines

)
{

(quoted diff) +2 -0
+    if
+

(trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO))

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
{
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20],

sec_ip_dst[20];

         strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src)); @@
-492,12 +494,12 @@ sec:
         g_queue_push_head(&conn->primary_list, ppkt);
         g_queue_push_head(&conn->secondary_list, spkt);

- if

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

)
{

net/colo-compare.c +5 -5
-            qemu_hexdump((char *)ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr,
+                     "colo-compare ppkt", ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr,
+                     "colo-compare spkt", spkt->size); #endif
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review static int · line 537

Quoted 6 lines
         colo_compare_inconsistency_notify(s);
     }
(quoted diff) +0 -0
@@ -533,12 +535,12 @@ static int
 colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
                                     ppkt->size - offset)) {
         trace_colo_compare_udp_miscompare("primary pkt size",

ppkt->size);

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
         trace_colo_compare_udp_miscompare("Secondary pkt

size", spkt-

Quoted 1 line

size);

- if

(trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

)
{
- qemu_hexdump((char *)ppkt->data, stderr, "colo-compare

pri pkt",

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -2
-                         ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare

sec pkt",

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

net/colo-compare.c static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)

Quoted 4 lines
net/colo-compare.c +2 -2
-                         spkt->size);
-        }
+#ifdef DEBUG_COLO_PACKETS
+        qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri

pkt",

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                     ppkt->size);
+        qemu_hexdump((char *)spkt->data, stderr, "colo-compare

sec pkt",

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+ spkt->size); #endif

Hi Roman,

I think change the " trace_event_get_state_backends()" to "trace_colo_compare_main("Dump packet hex: ")" is a better choice

here.

Quoted 14 lines
Quoted 14 lines
Quoted 11 lines
Quoted 1 line

It will keep the original code logic and avoid the problem here.

That may workaround the immediate bug, but this is still a misuse of the tracing code. Use of any trace point should only trigger actions in the trace infrastructure.

If I'm using dtrace backend to monitor events I don't want to see QEMU dumping stuff to stderr. Anything written to stderr is going to trigger disk I/O writing to the VM's logfile, and is also liable to trigger rate limiting which can impact the guest performance.

Hi Daniel, Chen, Stefan,

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

So, what do we want to do about the series? Do we have an agreement? Is the patch okay or I should make a change?

I think your current patch here should be merged as is, as it is removing the mis-use of the trace infrastructure.

Hi Zhang Chen,
Do you agree?

It's OK for me.

Thanks
Zhang Chen

Quoted 3 lines

Thanks,
Stefan

#19 lore raw
In reply to Roman Bolshakov
Quoted 5 lines · Roman Bolshakov

Hi,

This is a small series that enables dtrace tracing backend on macOS. Whether or not it should go to 5.1 is up to discretion of tracing maintainers.

Thanks for the patches. I would like to apply them for QEMU 5.2.

I have reviewed patches 1-3 and will wait for discussion to finish on patch 4.

Stefan

#20 lore raw
In reply to Roman Bolshakov
Quoted 23 lines · Roman Bolshakov

Hi,

This is a small series that enables dtrace tracing backend on macOS. Whether or not it should go to 5.1 is up to discretion of tracing maintainers.

Thanks,
Roman

Changes since v1:
- Fixed a typo ANSI C to C99, wrt to _Bool in the first patch.
- Prevented a few [-Wpointer-sign] warnings by converting int8_t * to signed char * in static probe definitions.
- Moved COLO packet dump under #ifdef DEBUG_COLO_PACKETS (Daniel).
- Separated tracepoints in net/filter-rewriter.c to use matching is-enabled probe (Daniel).

Roman Bolshakov (4):
scripts/tracetool: Fix dtrace generation for macOS scripts/tracetool: Use void pointer for vcpu
build: Don't make object files for dtrace on macOS net/colo: Match is-enabled probe to tracepoint

Quoted 11 lines
 Makefile.objs                 |  2 ++
 net/colo-compare.c            | 42 ++++++++++++++++++-----------------
 net/filter-rewriter.c         | 10 +++++++--
 net/trace-events              |  2 --
 scripts/tracetool/format/d.py | 15 ++++++++++++-
 scripts/tracetool/vcpu.py     |  2 +-
 6 files changed, 47 insertions(+), 26 deletions(-)
Signature · 1 line
2.26.1

Thanks, applied to my tracing-next tree:
https://github.com/stefanha/qemu/commits/tracing-next

Stefan