Skip to contentSkip to conversation

LLVM coverage support for Xen

PATCH In review Roger Pau Monne 7 participants 30 messages Jan 24, 2018 – Feb 13, 2018 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

v3 cover LLVM coverage support for Xen

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

http://xenbits.xen.org/people/royger/xen_profile/

I know the time is not the most appropriate given all the security work going on, but it seems like the series is quite close, and I would ike to avoid it bitrotting.

Thanks, Roger.

Roger Pau Monne (7):
gcov: rename sysctl and functions
gcov: introduce hooks for the sysctl
coverage: introduce generic file
kconfig/gcov: rename to coverage
coverage: introduce support for llvm profiling
xsm: add bodge when compiling with llvm coverage support
coverage: add documentation for LLVM coverage

 docs/misc/coverage.markdown    |  49 ++++++++++++-
 tools/misc/xencov.c            |  28 ++++----
 xen/Kconfig.debug              |   6 +-
 xen/Rules.mk                   |   9 ++-
 xen/common/Makefile            |   2 +-
 xen/common/coverage/Makefile   |   5 ++
 xen/common/coverage/coverage.c |  73 +++++++++++++++++++
 xen/common/coverage/coverage.h |  23 ++++++
 xen/common/coverage/gcov.c     |  42 ++---------
 xen/common/coverage/llvm.c     | 154 +++++++++++++++++++++++++++++++++++++++++
 xen/common/sysctl.c            |   6 +-
 xen/include/public/sysctl.h    |  18 +++--
 xen/include/xen/coverage.h     |   9 ++-
 xen/include/xsm/dummy.h        |  14 ++++
 14 files changed, 369 insertions(+), 69 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
 create mode 100644 xen/common/coverage/coverage.h
 create mode 100644 xen/common/coverage/llvm.c
Signature · 7 lines
2.15.1


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

PATCH v3 1/7 gcov: rename sysctl and functions

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v1:
- Use coverage instead of cov in the public interface.

---
 tools/misc/xencov.c         | 28 ++++++++++++++--------------
 xen/common/coverage/gcov.c  |  8 ++++----
 xen/common/sysctl.c         |  4 ++--
 xen/include/public/sysctl.h | 12 ++++++------
 xen/include/xen/coverage.h  |  2 +-
 5 files changed, 27 insertions(+), 27 deletions(-)
tools/misc/xencov.c +14 -14
index 4130f425dc..e5b40dba9c 100644
@@ -26,31 +26,31 @@
 
 static xc_interface *xch = NULL;
 
-int gcov_sysctl(int op, struct xen_sysctl *sysctl,
-                struct xc_hypercall_buffer *buf, uint32_t buf_size)
+int cov_sysctl(int op, struct xen_sysctl *sysctl,
+               struct xc_hypercall_buffer *buf, uint32_t buf_size)
 {
     DECLARE_HYPERCALL_BUFFER_ARGUMENT(buf);
 
     memset(sysctl, 0, sizeof(*sysctl));
-    sysctl->cmd = XEN_SYSCTL_gcov_op;
+    sysctl->cmd = XEN_SYSCTL_coverage_op;
 
-    sysctl->u.gcov_op.cmd = op;
-    sysctl->u.gcov_op.size = buf_size;
-    set_xen_guest_handle(sysctl->u.gcov_op.buffer, buf);
+    sysctl->u.coverage_op.cmd = op;
+    sysctl->u.coverage_op.size = buf_size;
+    set_xen_guest_handle(sysctl->u.coverage_op.buffer, buf);
 
     return xc_sysctl(xch, sysctl);
 }
 
-static void gcov_read(const char *fn)
+static void cov_read(const char *fn)
 {
     struct xen_sysctl sys;
     uint32_t total_len;
     DECLARE_HYPERCALL_BUFFER(uint8_t, p);
     FILE *f;
 
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_get_size, &sys, NULL, 0) < 0)
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_get_size, &sys, NULL, 0) < 0)
         err(1, "getting total length");
-    total_len = sys.u.gcov_op.size;
+    total_len = sys.u.coverage_op.size;
 
     /* Shouldn't exceed a few hundred kilobytes */
     if (total_len > 8u * 1024u * 1024u)
@@ -61,7 +61,7 @@ static void gcov_read(const char *fn)
         err(1, "allocating buffer");
 
     memset(p, 0, total_len);
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_read, &sys, HYPERCALL_BUFFER(p),
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_read, &sys, HYPERCALL_BUFFER(p),
                     total_len) < 0)
         err(1, "getting gcov data");
 
@@ -82,11 +82,11 @@ static void gcov_read(const char *fn)
     xc_hypercall_buffer_free(xch, p);
 }
 
-static void gcov_reset(void)
+static void cov_reset(void)
 {
     struct xen_sysctl sys;
 
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_reset, &sys, NULL, 0) < 0)
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_reset, &sys, NULL, 0) < 0)
         err(1, "resetting gcov information");
 }
 
@@ -126,9 +126,9 @@ int main(int argc, char **argv)
         err(1, "opening xc interface");
 
     if (strcmp(argv[0], "reset") == 0)
-        gcov_reset();
+        cov_reset();
     else if (strcmp(argv[0], "read") == 0)
-        gcov_read(argc > 1 ? argv[1] : "-");
+        cov_read(argc > 1 ? argv[1] : "-");
     else
         usage(1);
 
xen/common/coverage/gcov.c +4 -4
index 283d2eec86..798032cbbb 100644
@@ -209,18 +209,18 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
-int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
+int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 {
     int ret;
 
     switch ( op->cmd )
     {
-    case XEN_SYSCTL_GCOV_get_size:
+    case XEN_SYSCTL_COVERAGE_get_size:
         op->size = gcov_get_size();
         ret = 0;
         break;
 
-    case XEN_SYSCTL_GCOV_read:
+    case XEN_SYSCTL_COVERAGE_read:
     {
         XEN_GUEST_HANDLE_PARAM(char) buf;
         uint32_t size = op->size;
@@ -233,7 +233,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
     }
 
-    case XEN_SYSCTL_GCOV_reset:
+    case XEN_SYSCTL_COVERAGE_reset:
         gcov_reset_all_counters();
         ret = 0;
         break;
xen/common/sysctl.c +2 -2
index 56def766e6..f2ae6295ff 100644
@@ -397,8 +397,8 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     break;
 
 #ifdef CONFIG_GCOV
-    case XEN_SYSCTL_gcov_op:
-        ret = sysctl_gcov_op(&op->u.gcov_op);
+    case XEN_SYSCTL_coverage_op:
+        ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
 #endif
xen/include/public/sysctl.h +6 -6
index f7f26c38e3..ef10368d79 100644
@@ -646,11 +646,11 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */
 
-#define XEN_SYSCTL_GCOV_get_size 0 /* Get total size of output data */
-#define XEN_SYSCTL_GCOV_read     1 /* Read output data */
-#define XEN_SYSCTL_GCOV_reset    2 /* Reset all counters */
+#define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */
+#define XEN_SYSCTL_COVERAGE_read     1 /* Read output data */
+#define XEN_SYSCTL_COVERAGE_reset    2 /* Reset all counters */
 
-struct xen_sysctl_gcov_op {
+struct xen_sysctl_coverage_op {
     uint32_t cmd;
     uint32_t size; /* IN/OUT: size of the buffer  */
     XEN_GUEST_HANDLE_64(char) buffer; /* OUT */
@@ -1073,7 +1073,7 @@ struct xen_sysctl {
 #define XEN_SYSCTL_numainfo                      17
 #define XEN_SYSCTL_cpupool_op                    18
 #define XEN_SYSCTL_scheduler_op                  19
-#define XEN_SYSCTL_gcov_op                       20
+#define XEN_SYSCTL_coverage_op                   20
 #define XEN_SYSCTL_psr_cmt_op                    21
 #define XEN_SYSCTL_pcitopoinfo                   22
 #define XEN_SYSCTL_psr_alloc                     23
@@ -1103,7 +1103,7 @@ struct xen_sysctl {
         struct xen_sysctl_lockprof_op       lockprof_op;
         struct xen_sysctl_cpupool_op        cpupool_op;
         struct xen_sysctl_scheduler_op      scheduler_op;
-        struct xen_sysctl_gcov_op           gcov_op;
+        struct xen_sysctl_coverage_op       coverage_op;
         struct xen_sysctl_psr_cmt_op        psr_cmt_op;
         struct xen_sysctl_psr_alloc         psr_alloc;
         struct xen_sysctl_tmem_op           tmem_op;
xen/include/xen/coverage.h +1 -1
index b34c304cba..daddef37d3 100644
@@ -3,7 +3,7 @@
 
 #ifdef CONFIG_GCOV
 #include <public/sysctl.h>
-int sysctl_gcov_op(struct xen_sysctl_gcov_op *op);
+int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.15.1


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

Re: [PATCH v3 1/7] gcov: rename sysctl and functions

Quoted 6 lines · Roger Pau Monne

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

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

#3 lore raw

PATCH v3 2/7 gcov: introduce hooks for the sysctl

In reply to Roger Pau Monne

So that other implementations of the sysctl can be added.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v2:
- Add editor block.

Changes since v1:
- Constify cov_ops.
- Introduce a local coverage.h provate header and place the definition of cov_sysctl_ops there.

---
 xen/common/coverage/coverage.h | 22 ++++++++++++++++++++++
 xen/common/coverage/gcov.c     | 13 ++++++++++---
 2 files changed, 32 insertions(+), 3 deletions(-)
 create mode 100644 xen/common/coverage/coverage.h
xen/common/coverage/coverage.h new file +22 -0
new file mode 100644
index 0000000000..9991939b70
@@ -0,0 +1,22 @@
+#ifndef _XEN_COV_PRIV_H
+#define _XEN_COV_PRIV_H
+
+#include <xen/types.h>
+
+struct cov_sysctl_ops {
+    uint32_t (*get_size)(void);
+    void     (*reset_counters)(void);
+    int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
+};
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/common/coverage/gcov.c +10 -3
index 798032cbbb..8627ef3355 100644
@@ -22,6 +22,7 @@
 
 #include <public/sysctl.h>
 
+#include "coverage.h"
 #include "gcov.h"
 
 /**
@@ -209,6 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
+static const struct cov_sysctl_ops cov_ops = {
+    .get_size = gcov_get_size,
+    .reset_counters = gcov_reset_all_counters,
+    .dump = gcov_dump_all,
+};
+
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 {
     int ret;
@@ -216,7 +223,7 @@ int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
     switch ( op->cmd )
     {
     case XEN_SYSCTL_COVERAGE_get_size:
-        op->size = gcov_get_size();
+        op->size = cov_ops.get_size();
         ret = 0;
         break;
 
@@ -227,14 +234,14 @@ int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 
         buf = guest_handle_cast(op->buffer, char);
 
-        ret = gcov_dump_all(buf, &size);
+        ret = cov_ops.dump(buf, &size);
         op->size = size;
 
         break;
     }
 
     case XEN_SYSCTL_COVERAGE_reset:
-        gcov_reset_all_counters();
+        cov_ops.reset_counters();
         ret = 0;
         break;
 
Signature · 7 lines
2.15.1


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

PATCH v3 3/7 coverage: introduce generic file

In reply to Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use private coverage.h header.
- Sort alphabetically the obj-y list.

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 73 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/coverage.h |  1 +
 xen/common/coverage/gcov.c     | 39 +---------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index a7a48494ca..5387bc6429 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += coverage.o gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
xen/common/coverage/coverage.c new file +73 -0

73 lines not on this page · raw message

xen/common/coverage/coverage.h +1 -0
index 9991939b70..aa66396c08 100644
@@ -8,6 +8,7 @@ struct cov_sysctl_ops {
     void     (*reset_counters)(void);
     int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
 };
+extern const struct cov_sysctl_ops cov_ops;
 
 #endif
 
xen/common/coverage/gcov.c +1 -38
index 8627ef3355..3cc98728bf 100644
@@ -210,49 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
-static const struct cov_sysctl_ops cov_ops = {
+const struct cov_sysctl_ops cov_ops = {
     .get_size = gcov_get_size,
     .reset_counters = gcov_reset_all_counters,
     .dump = gcov_dump_all,
 };
 
-int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
-{
-    int ret;
-
-    switch ( op->cmd )
-    {
-    case XEN_SYSCTL_COVERAGE_get_size:
-        op->size = cov_ops.get_size();
-        ret = 0;
-        break;
-
-    case XEN_SYSCTL_COVERAGE_read:
-    {
-        XEN_GUEST_HANDLE_PARAM(char) buf;
-        uint32_t size = op->size;
-
-        buf = guest_handle_cast(op->buffer, char);
-
-        ret = cov_ops.dump(buf, &size);
-        op->size = size;
-
-        break;
-    }
-
-    case XEN_SYSCTL_COVERAGE_reset:
-        cov_ops.reset_counters();
-        ret = 0;
-        break;
-
-    default:
-        ret = -EOPNOTSUPP;
-        break;
-    }
-
-    return ret;
-}
-
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 3/7
#6 lore raw

Re: [PATCH v3 3/7] coverage: introduce generic file

Quoted 5 lines · Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

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

#7 lore raw

Re: [PATCH v3 3/7] coverage: introduce generic file

In reply to Roger Pau Monne
Quoted 42 lines · Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use private coverage.h header.
- Sort alphabetically the obj-y list.

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 73 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/coverage.h |  1 +
 xen/common/coverage/gcov.c     | 39 +---------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index a7a48494ca..5387bc6429 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += coverage.o gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
xen/common/coverage/coverage.c new file +0 -0
new file mode 100644
index 0000000000..bd90f28663

xen/common/coverage/coverage.c line 4

Quoted 4 lines
xen/common/coverage/coverage.c new file +4 -0
@@ -0,0 +1,73 @@
+/*
+ * Generic functionality for coverage analysis.
+ *
+ * Copyright (C) 2017 Citrix Systems R&D

2018 now I believe.

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

#8 lore raw

Re: [PATCH v3 3/7] coverage: introduce generic file

Quoted 41 lines · Konrad Rzeszutek Wilk
Quoted 40 lines · Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use private coverage.h header.
- Sort alphabetically the obj-y list.

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 73 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/coverage.h |  1 +
 xen/common/coverage/gcov.c     | 39 +---------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index a7a48494ca..5387bc6429 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += coverage.o gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
xen/common/coverage/coverage.c new file +0 -1
new file mode 100644
index 0000000000..bd90f28663
--- /dev/null
Quoted 8 lines

xen/common/coverage/coverage.c line 4

Quoted 6 lines

+++ b/xen/common/coverage/coverage.c

xen/common/coverage/coverage.c new file +4 -0
@@ -0,0 +1,73 @@
+/*
+ * Generic functionality for coverage analysis.
+ *
+ * Copyright (C) 2017 Citrix Systems R&D

2018 now I believe.

I'm pretty sure the copyright starts from the time the work is created, not the time it gets checked into a public tree. Most of this would have been written last year.

Since we're being pedantic. ;-)

-George

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

#9 lore raw

Re: [PATCH v3 3/7] coverage: introduce generic file

George Dunlap writes ("Re: [PATCH v3 3/7] coverage: introduce generic file"):

Quoted 5 lines

I'm pretty sure the copyright starts from the time the work is created, not the time it gets checked into a public tree. Most of this would have been written last year.

Since we're being pedantic. ;-)

`(maintain) Copyright Notices' says:

To update the list of year numbers, add each year in which you have made nontrivial changes to the package. (Here we assume you're using a publicly accessible revision control server, so that every revision installed is also immediately and automatically published.) ...

So I think it is the date on which the _overall version_ is published, ie for us the date it gets pushed to staging, or the date it gets published by the submitter as a git branch (if sooner). But I doubt this really matters very much.

Ian.

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

#10 lore raw

PATCH v3 4/7 kconfig/gcov: rename to coverage

In reply to Roger Pau Monne

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v2:
- select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS when enabling coverage support in Kconfig.
- Introduce COV_FLAGS to store the compiler flags to enable coverage support for clang and gcc.
- Return -EOPNOTSUPP in sysctl_cov_op if not implemented.

Changes since v1:
- Use a choice in kconfig to select code coverage technology.
- Compile coverage.c regardless of selected code coverage technology.
- Introduce an unimplemented sysctl_cov_op function if CONFIG_COVERAGE is not set.

---
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 6 +++---
 xen/Rules.mk                 | 9 +++++++--
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 7 files changed, 22 insertions(+), 11 deletions(-)
docs/misc/coverage.markdown +1 -1
index b47aba2648..430cd27b2f 100644
@@ -10,7 +10,7 @@ down your hypervisor.
 
 ## Enable coverage
 
-Test coverage support can be turned on compiling Xen with the `CONFIG_GCOV`
+Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
 option set to `y`.
 
 Change your `.config` or run `make -C xen menuconfig`.
xen/Kconfig.debug +3 -3
index 7bb0465b5d..380c4e8d75 100644
@@ -28,12 +28,12 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
-config GCOV
-	bool "Gcov Support"
+config COVERAGE
+	bool "Code coverage support"
 	depends on !LIVEPATCH
 	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
 	---help---
-	  Enable gcov (a test coverage program in GCC) support.
+	  Enable code coverage support.
 
 	  If unsure, say N here.
 
xen/Rules.mk +7 -2
index 3cf40754a6..0bc40fd0e6 100644
@@ -115,8 +115,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY
 
-ifeq ($(CONFIG_GCOV),y)
-$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+    COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
+else
+    COV_FLAGS := -fprofile-arcs -ftest-coverage
+endif
+    $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += $(COV_FLAGS)
 endif
 
 ifeq ($(CONFIG_UBSAN),y)
xen/common/Makefile +1 -1
index ad181636f6..3a349f478b 100644
@@ -74,7 +74,7 @@ tmem-y := tmem.o tmem_xen.o tmem_control.o
 tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o
 obj-$(CONFIG_TMEM) += $(tmem-y)
 
-subdir-$(CONFIG_GCOV) += coverage
+subdir-$(CONFIG_COVERAGE) += coverage
 subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-y += libelf
xen/common/coverage/Makefile +4 -1
index 5387bc6429..1039a160c4 100644
@@ -1,6 +1,9 @@
-obj-y += coverage.o gcov_base.o gcov.o
+obj-y += coverage.o
+ifneq ($(clang),y)
+obj-y += gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
 		gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+endif
xen/common/sysctl.c +0 -2
index f2ae6295ff..8e83c33a16 100644
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 
 #ifdef CONFIG_HAS_PCI
     case XEN_SYSCTL_pcitopoinfo:
xen/include/xen/coverage.h +6 -1
index daddef37d3..ba5fb67947 100644
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H
 #define _XEN_COV_H
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -EOPNOTSUPP;
+}
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.15.1


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

Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage

Quoted 12 lines · Roger Pau Monne

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

xen/Rules.mk +0 -0
index 3cf40754a6..0bc40fd0e6 100644
@@ -115,8 +115,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY

xen/Rules.mk subdir-all := $(subdir-y) $(subdir-n) · line 124

Quoted 10 lines
xen/Rules.mk +7 -2
 
-ifeq ($(CONFIG_GCOV),y)
-$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+    COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
+else
+    COV_FLAGS := -fprofile-arcs -ftest-coverage
+endif
+    $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += $(COV_FLAGS)

Please also change nogcov to nocov. Also remove the leading spaces from this line.

Other than this, this patch looks good.

Wei.

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

#12 lore raw

PATCH v4 4/7 kconfig/gcov: rename to coverage

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v3:
- s/nogcov/nocov.
- Remove leading spaces in filter-out.

Changes since v2:
- select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS when enabling coverage support in Kconfig.
- Introduce COV_FLAGS to store the compiler flags to enable coverage support for clang and gcc.
- Return -EOPNOTSUPP in sysctl_cov_op if not implemented.

Changes since v1:
- Use a choice in kconfig to select code coverage technology.
- Compile coverage.c regardless of selected code coverage technology.
- Introduce an unimplemented sysctl_cov_op function if CONFIG_COVERAGE is not set.

---
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 6 +++---
 xen/Rules.mk                 | 9 +++++++--
 xen/arch/x86/efi/Makefile    | 2 +-
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 8 files changed, 23 insertions(+), 12 deletions(-)
docs/misc/coverage.markdown +1 -1
index b47aba2648..430cd27b2f 100644
@@ -10,7 +10,7 @@ down your hypervisor.
 
 ## Enable coverage
 
-Test coverage support can be turned on compiling Xen with the `CONFIG_GCOV`
+Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
 option set to `y`.
 
 Change your `.config` or run `make -C xen menuconfig`.
xen/Kconfig.debug +3 -3
index 7bb0465b5d..380c4e8d75 100644
@@ -28,12 +28,12 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
-config GCOV
-	bool "Gcov Support"
+config COVERAGE
+	bool "Code coverage support"
 	depends on !LIVEPATCH
 	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
 	---help---
-	  Enable gcov (a test coverage program in GCC) support.
+	  Enable code coverage support.
 
 	  If unsure, say N here.
 
xen/Rules.mk +7 -2
index 541ed13aa1..da3c35ba36 100644
@@ -119,8 +119,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY
 
-ifeq ($(CONFIG_GCOV),y)
-$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+    COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
+else
+    COV_FLAGS := -fprofile-arcs -ftest-coverage
+endif
+$(filter-out %.init.o $(nocov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += $(COV_FLAGS)
 endif
 
 ifeq ($(CONFIG_UBSAN),y)
xen/arch/x86/efi/Makefile +1 -1
index 3edff1cf24..3be9661108 100644
@@ -13,4 +13,4 @@ boot.init.o: buildid.o
 obj-y := stub.o
 obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o
 extra-$(efi) += buildid.o
-nogcov-$(efi) += stub.o
+nocov-$(efi) += stub.o
xen/common/Makefile +1 -1
index ad181636f6..3a349f478b 100644
@@ -74,7 +74,7 @@ tmem-y := tmem.o tmem_xen.o tmem_control.o
 tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o
 obj-$(CONFIG_TMEM) += $(tmem-y)
 
-subdir-$(CONFIG_GCOV) += coverage
+subdir-$(CONFIG_COVERAGE) += coverage
 subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-y += libelf
xen/common/coverage/Makefile +4 -1
index 5387bc6429..1039a160c4 100644
@@ -1,6 +1,9 @@
-obj-y += coverage.o gcov_base.o gcov.o
+obj-y += coverage.o
+ifneq ($(clang),y)
+obj-y += gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
 		gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+endif
xen/common/sysctl.c +0 -2
index f2ae6295ff..8e83c33a16 100644
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 
 #ifdef CONFIG_HAS_PCI
     case XEN_SYSCTL_pcitopoinfo:
xen/include/xen/coverage.h +6 -1
index daddef37d3..ba5fb67947 100644
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H
 #define _XEN_COV_H
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -EOPNOTSUPP;
+}
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v4 4/7
#13 lore raw

Re: [PATCH v4 4/7] kconfig/gcov: rename to coverage

Quoted 5 lines · Roger Pau Monne

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw

Re: [PATCH v4 4/7] kconfig/gcov: rename to coverage

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.02.18 at 11:53, <[email protected]> wrote:
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 6 +++---
 xen/Rules.mk                 | 9 +++++++--
 xen/arch/x86/efi/Makefile    | 2 +-
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 8 files changed, 23 insertions(+), 12 deletions(-)

I've taken the liberty to also adjust the shim's stored config while committing.

Jan

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

#16 lore raw

Re: [PATCH v4 4/7] kconfig/gcov: rename to coverage

Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.02.18 at 11:53, <[email protected]> wrote:
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 6 +++---
 xen/Rules.mk                 | 9 +++++++--
 xen/arch/x86/efi/Makefile    | 2 +-
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 8 files changed, 23 insertions(+), 12 deletions(-)
Quoted 2 lines

I've taken the liberty to also adjust the shim's stored config while committing.

Thanks. This shim config is going to be a PITA.

Roger.

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

#17 lore raw

Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH v3 4/7] kconfig/gcov: rename to coverage"):

Quoted 3 lines

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

...

Quoted 5 lines
xen/common/sysctl.c +0 -0
index f2ae6295ff..8e83c33a16 100644

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 403

Quoted 10 lines
xen/common/sysctl.c +0 -2
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 

This hunk seems erroneous ? Surely the name should be updated, but the #ifdef should remain.

Thanks,
Ian.

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

#18 lore raw

Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage

Quoted 13 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH v3 4/7] kconfig/gcov: rename to coverage"):

Quoted 3 lines

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

...

Quoted 8 lines
xen/common/sysctl.c +0 -0
index f2ae6295ff..8e83c33a16 100644
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
Quoted 11 lines

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 403

Quoted 7 lines
xen/common/sysctl.c +0 -2
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 

This hunk seems erroneous ? Surely the name should be updated, but the #ifdef should remain.

No the ifdef needs to go.

There is a new stub introduced in this patch.

Wei.

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

#19 lore raw

Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage

Wei Liu writes ("Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage"):

Quoted 7 lines · Ian Jackson
Quoted 2 lines

This hunk seems erroneous ? Surely the name should be updated, but the #ifdef should remain.

No the ifdef needs to go.

There is a new stub introduced in this patch.

Oh, hrm. Yes, there is. But why is this better ?

One reason for all this Kconfig stuff is to be able to disable unused interfaces for security reasons. That also means being able to easily audit what interfaces are enabled, which is a lot simpler if you can read the main switch statement for the relevant hypercall, than if you have to go chasing off after definitions.

Ian.

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

#20 lore raw

Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage

Quoted 11 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v3 4/7] kconfig/gcov: rename to coverage"):

Quoted 7 lines · Ian Jackson
Quoted 2 lines

This hunk seems erroneous ? Surely the name should be updated, but the #ifdef should remain.

No the ifdef needs to go.

There is a new stub introduced in this patch.

Oh, hrm. Yes, there is. But why is this better ?

It is not better or worse but that's how Roger managed to return -EOPNOTSUPP I assume.

Wei.

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

#21 lore raw

PATCH v3 5/7 coverage: introduce support for llvm profiling

In reply to Roger Pau Monne

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct. Note that the functionality is still not wired into the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Note that the file that contains the helpers is under a BSD 2-clause license. This is done so it can be shared with other OSes that use the llvm/clang compiler.
---
Changes since v1:
- Include private coverage.h header.
- Define LLVM_PROFILE_MAGIC based on the bitness of the arch.
- Add a comment regarding __llvm_profile_runtime.
- Constify data/names extern symbols.
- Use defines instead of variables to store the addresses of the external symbols.
- Parenthesize size in APPEND_TO_BUFFER.
- Use >= for minor version check.
- Use sizeof(header).

---
 xen/common/coverage/Makefile |   2 +
 xen/common/coverage/llvm.c   | 154 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h  |   6 ++
 3 files changed, 162 insertions(+)
 create mode 100644 xen/common/coverage/llvm.c
xen/common/coverage/Makefile +2 -0
index 1039a160c4..46c78d1086 100644
@@ -6,4 +6,6 @@ obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
 		gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+else
+obj-y += llvm.o
 endif
xen/common/coverage/llvm.c new file +154 -0

154 lines not on this page · raw message

xen/include/public/sysctl.h +6 -0
index ef10368d79..cfc7b11de8 100644
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */
 
+/*
+ * Ouput format of LLVM coverage data is just a raw stream, as would be
+ * written by the compiler_rt run time library into a .profraw file. There
+ * are no special Xen tags or delimiters because none are needed.
+ */
+
 #define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */
 #define XEN_SYSCTL_COVERAGE_read     1 /* Read output data */
 #define XEN_SYSCTL_COVERAGE_reset    2 /* Reset all counters */
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 5/7
#22 lore raw

Re: [PATCH v3 5/7] coverage: introduce support for llvm profiling

Quoted 6 lines · Roger Pau Monne

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct. Note that the functionality is still not wired into the build system.

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

#23 lore raw

PATCH v3 6/7 xsm: add bodge when compiling with llvm coverage support

In reply to Roger Pau Monne

llvm coverage support seems to disable some of the optimizations needed in order to compile xsm, and the end result is that references to __xsm_action_mismatch_detected are left in the object files.

Since coverage support cannot be used in production, introduce __xsm_action_mismatch_detected for llvm coverage builds.

---
Cc: Daniel De Graaf <[email protected]>
---
Changes since v1:
- Add inline.
- Use CONIFG_COVERAGE and __clang__ to detect if the bodge is needed.

---
 xen/include/xsm/dummy.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/include/xsm/dummy.h +14 -0
index d6ddadcafd..466bbcbde8 100644
@@ -24,8 +24,22 @@
  * if references remain at link time.
  */
 #define LINKER_BUG_ON(x) do { if (x) __xsm_action_mismatch_detected(); } while (0)
+
+#if defined(CONFIG_COVERAGE) && defined(__clang__)
+/*
+ * LLVM coverage support seems to disable some of the optimizations needed in
+ * order for XSM to compile. Since coverage should not be used in production
+ * provide an implementation of __xsm_action_mismatch_detected to satisfy the
+ * linker.
+ */
+static inline void __xsm_action_mismatch_detected(void)
+{
+    ASSERT_UNREACHABLE();
+}
+#else
 /* DO NOT implement this function; it is supposed to trigger link errors */
 void __xsm_action_mismatch_detected(void);
+#endif
 
 #ifdef CONFIG_XSM
 
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v3 6/7
#24 lore raw

Re: [PATCH v3 6/7] xsm: add bodge when compiling with llvm coverage support

Quoted 8 lines · Roger Pau Monne

llvm coverage support seems to disable some of the optimizations needed in order to compile xsm, and the end result is that references to __xsm_action_mismatch_detected are left in the object files.

Since coverage support cannot be used in production, introduce __xsm_action_mismatch_detected for llvm coverage builds.

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

#25 lore raw

PATCH v3 7/7 coverage: add documentation for LLVM coverage

In reply to Roger Pau Monne

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- s/gmake/make/.
- Fix gcov section to mention CONFIG_COVERAGE instead of CONFIG_GCOV.

---
 docs/misc/coverage.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
docs/misc/coverage.markdown +47 -0
index 430cd27b2f..3554659fe4 100644
@@ -8,6 +8,8 @@ information. Every basic block in the code will be instrumented by the compiler
 to compute these statistics. It should not be used in production as it slows
 down your hypervisor.
 
+# GCOV (GCC coverage)
+
 ## Enable coverage
 
 Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
@@ -75,3 +77,48 @@ blob extracted from xencov!**
 * See output in a browser
 
         firefox cov/index.html
+
+# LLVM coverage
+
+## Enable coverage
+
+Coverage can be enabled using a Kconfig option, from the top-level directory
+use the following command to display the Kconfig menu:
+
+    make -C xen menuconfig clang=y
+
+The code coverage option can be found inside of the "Debugging Options"
+section. After enabling it just compile Xen as you would normally do:
+
+    make xen clang=y
+
+## Extract coverage data
+
+LLVM coverage can be extracted from the hypervisor using the `xencov` tool.
+The following actions are available:
+
+* `xencov read` extract data
+* `xencov reset` reset all coverage counters
+* `xencov read-reset` extract data and reset counters at the same time.
+
+## Possible use
+
+**This section is just an example on how to use these tools!**
+
+This example assumes you compiled Xen and copied the xen-syms file from
+xen/xen-syms into your current directory.
+
+* Extract the coverage data from Xen:
+
+    xencov read xen.profraw
+
+* Convert the data into a profile. Note that you can merge more than one
+  profraw file into a single profdata file.
+
+    llvm-profdata merge xen.profraw -o xen.profdata
+
+* Generate a HTML report of the code coverage:
+
+    llvm-cov show -format=html -output-dir=cov/ xen-syms -instr-profile=xen.profdata
+
+* Open cov/index.html with your browser in order to display the profile.
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#27 lore raw
In reply to Roger Pau Monne
Quoted 11 lines · Roger Pau Monne

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

http://xenbits.xen.org/people/royger/xen_profile/

I know the time is not the most appropriate given all the security work going on, but it seems like the series is quite close, and I would ike to avoid it bitrotting.

Patches 5, 6 and 7 have already been reviewed/acked by the relevant maintainers, is there anything preventing them from going in?

Thanks, Roger.

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

#28 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 16:53, <[email protected]> wrote:
Quoted 6 lines · Roger Pau Monne

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

Quoted 8 lines
Quoted 5 lines

http://xenbits.xen.org/people/royger/xen_profile/

I know the time is not the most appropriate given all the security work going on, but it seems like the series is quite close, and I would ike to avoid it bitrotting.

Patches 5, 6 and 7 have already been reviewed/acked by the relevant maintainers, is there anything preventing them from going in?

I didn't keep them in my inbox when it became clear that patch 4 needs another version, which is why I did apply only that single patch.

Jan

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

#29 lore raw
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 16:53, <[email protected]> wrote:
Quoted 11 lines · Roger Pau Monne

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

http://xenbits.xen.org/people/royger/xen_profile/

I know the time is not the most appropriate given all the security work going on, but it seems like the series is quite close, and I would ike to avoid it bitrotting.

Quoted 6 lines
Quoted 2 lines

Patches 5, 6 and 7 have already been reviewed/acked by the relevant maintainers, is there anything preventing them from going in?

I didn't keep them in my inbox when it became clear that patch 4 needs another version, which is why I did apply only that single patch.

Oh, since patch 4 was the only one that had comments I only sent that. Would you like me to send or push to a git branch the remaining ones?

Thanks, Roger.

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

#30 lore raw
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 17:28, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 16:53, <[email protected]> wrote:
Quoted 11 lines · Roger Pau Monne

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

http://xenbits.xen.org/people/royger/xen_profile/

I know the time is not the most appropriate given all the security work going on, but it seems like the series is quite close, and I would ike to avoid it bitrotting.

Patches 5, 6 and 7 have already been reviewed/acked by the relevant maintainers, is there anything preventing them from going in?

Quoted 6 lines
Quoted 3 lines

I didn't keep them in my inbox when it became clear that patch 4 needs another version, which is why I did apply only that single patch.

Oh, since patch 4 was the only one that had comments I only sent that. Would you like me to send or push to a git branch the remaining ones?

Normally I think it would have been best if you resent them without asking, rather than just sending a singleton 4/7 patch. This time, however, I've managed to fish them out of the mail client's waste basket, and I've just committed and pushed them.

Jan

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