Skip to contentSkip to conversation

riscv: enable kcov

PATCH In review Tobias Klauser 3 participants 6 messages Jun 26, 2020 – Jul 11, 2020 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: enable kcov

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of vdso.

Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 arch/riscv/Kconfig              | 2 ++
 arch/riscv/kernel/vdso/Makefile | 1 +
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +2 -0
index 089293e4ad46..a7d7f8184f15 100644
@@ -19,6 +19,7 @@ config RISCV
 	select ARCH_HAS_DEBUG_WX
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_GIGANTIC_PAGE
+	select ARCH_HAS_KCOV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SET_DIRECT_MAP
@@ -57,6 +58,7 @@ config RISCV
 	select HAVE_DMA_CONTIGUOUS if MMU
 	select HAVE_EBPF_JIT if MMU
 	select HAVE_FUTEX_CMPXCHG if FUTEX
+	select HAVE_GCC_PLUGINS
 	select HAVE_GENERIC_VDSO if MMU && 64BIT
 	select HAVE_PCI
 	select HAVE_PERF_EVENTS
arch/riscv/kernel/vdso/Makefile +1 -0
index 38ba55b0eb9d..9debbaab393d 100644
@@ -29,6 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
Signature · 7 lines
2.27.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Tobias Klauser

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of vdso.

Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>

If it boots:

FWIW for x86 we needed to do much more of this:

$ find arch/x86/ -name Makefile -exec grep KCOV_INSTRUMENT {} \; -print
KCOV_INSTRUMENT := n
arch/x86/kernel/Makefile
KCOV_INSTRUMENT := n
arch/x86/kernel/apic/Makefile
KCOV_INSTRUMENT_common.o := n
KCOV_INSTRUMENT_perf_event.o := n
arch/x86/kernel/cpu/Makefile
KCOV_INSTRUMENT := n
arch/x86/realmode/rm/Makefile
KCOV_INSTRUMENT := n
arch/x86/boot/Makefile
KCOV_INSTRUMENT := n
arch/x86/boot/compressed/Makefile
KCOV_INSTRUMENT := n
arch/x86/entry/Makefile
KCOV_INSTRUMENT := n
arch/x86/entry/vdso/Makefile
KCOV_INSTRUMENT                := n
arch/x86/um/vdso/Makefile
KCOV_INSTRUMENT_delay.o := n
KCOV_INSTRUMENT_cmdline.o := n
arch/x86/lib/Makefile
KCOV_INSTRUMENT_tlb.o := n
KCOV_INSTRUMENT_mem_encrypt.o := n
KCOV_INSTRUMENT_mem_encrypt_identity.o := n
arch/x86/mm/Makefile
KCOV_INSTRUMENT := n
arch/x86/purgatory/Makefile
Quoted 38 lines
---
 arch/riscv/Kconfig              | 2 ++
 arch/riscv/kernel/vdso/Makefile | 1 +
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +2 -0
index 089293e4ad46..a7d7f8184f15 100644
@@ -19,6 +19,7 @@ config RISCV
        select ARCH_HAS_DEBUG_WX
        select ARCH_HAS_GCOV_PROFILE_ALL
        select ARCH_HAS_GIGANTIC_PAGE
+       select ARCH_HAS_KCOV
        select ARCH_HAS_MMIOWB
        select ARCH_HAS_PTE_SPECIAL
        select ARCH_HAS_SET_DIRECT_MAP
@@ -57,6 +58,7 @@ config RISCV
        select HAVE_DMA_CONTIGUOUS if MMU
        select HAVE_EBPF_JIT if MMU
        select HAVE_FUTEX_CMPXCHG if FUTEX
+       select HAVE_GCC_PLUGINS
        select HAVE_GENERIC_VDSO if MMU && 64BIT
        select HAVE_PCI
        select HAVE_PERF_EVENTS
arch/riscv/kernel/vdso/Makefile +1 -1
index 38ba55b0eb9d..9debbaab393d 100644
@@ -29,6 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
--
Quoted 2 lines

2.27.0

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 5 lines · Dmitry Vyukov
Quoted 4 lines · Tobias Klauser

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of vdso.

Quoted 8 lines
Quoted 3 lines
Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>

If it boots:

Yeah turns out I boot-tested this with a kernel which didn't have CONFIG_KCOV enabled :-/ Will send a v2 patch.

Quoted 23 lines

FWIW for x86 we needed to do much more of this:

$ find arch/x86/ -name Makefile -exec grep KCOV_INSTRUMENT {} \; -print
KCOV_INSTRUMENT := n
arch/x86/kernel/Makefile
KCOV_INSTRUMENT := n
arch/x86/kernel/apic/Makefile
KCOV_INSTRUMENT_common.o := n
KCOV_INSTRUMENT_perf_event.o := n
arch/x86/kernel/cpu/Makefile
KCOV_INSTRUMENT := n
arch/x86/realmode/rm/Makefile
KCOV_INSTRUMENT := n
arch/x86/boot/Makefile
KCOV_INSTRUMENT := n
arch/x86/boot/compressed/Makefile
KCOV_INSTRUMENT := n
arch/x86/entry/Makefile
KCOV_INSTRUMENT := n
arch/x86/entry/vdso/Makefile
KCOV_INSTRUMENT                := n
arch/x86/um/vdso/Makefile
KCOV_INSTRUMENT_delay.o := n
Quoted 8 lines
KCOV_INSTRUMENT_cmdline.o := n
arch/x86/lib/Makefile
KCOV_INSTRUMENT_tlb.o := n
KCOV_INSTRUMENT_mem_encrypt.o := n
KCOV_INSTRUMENT_mem_encrypt_identity.o := n
arch/x86/mm/Makefile
KCOV_INSTRUMENT := n
arch/x86/purgatory/Makefile

Thanks, that's very helpful.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw

PATCH v2 1/1 riscv: Allow building with kcov coverage

In reply to Tobias Klauser

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of some early boot code and vdso.

Boot-tested on QEMU's riscv64 virt machine.

Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 arch/riscv/Kconfig              | 2 ++
 arch/riscv/boot/Makefile        | 2 ++
 arch/riscv/kernel/vdso/Makefile | 1 +
 arch/riscv/mm/Makefile          | 2 ++
 4 files changed, 7 insertions(+)
arch/riscv/Kconfig +2 -0
index 089293e4ad46..a7d7f8184f15 100644
@@ -19,6 +19,7 @@ config RISCV
 	select ARCH_HAS_DEBUG_WX
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_GIGANTIC_PAGE
+	select ARCH_HAS_KCOV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SET_DIRECT_MAP
@@ -57,6 +58,7 @@ config RISCV
 	select HAVE_DMA_CONTIGUOUS if MMU
 	select HAVE_EBPF_JIT if MMU
 	select HAVE_FUTEX_CMPXCHG if FUTEX
+	select HAVE_GCC_PLUGINS
 	select HAVE_GENERIC_VDSO if MMU && 64BIT
 	select HAVE_PCI
 	select HAVE_PERF_EVENTS
arch/riscv/boot/Makefile +2 -0
index 3530c59b3ea7..c59fca695f9d 100644
@@ -14,6 +14,8 @@
 # Based on the ia64 and arm64 boot/Makefile.
 #
 
+KCOV_INSTRUMENT := n
+
 OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
 
 targets := Image loader
arch/riscv/kernel/vdso/Makefile +1 -0
index 29cf052f6541..4b0d3bcc44e5 100644
@@ -29,6 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
arch/riscv/mm/Makefile +2 -0
index 363ef01c30b1..c0185e556ca5 100644
@@ -5,6 +5,8 @@ ifdef CONFIG_FTRACE
 CFLAGS_REMOVE_init.o = -pg
 endif
 
+KCOV_INSTRUMENT_init.o := n
+
 obj-y += init.o
 obj-y += extable.o
 obj-$(CONFIG_MMU) += fault.o pageattr.o
Signature · 1 line
2.27.0
Acked-by on v2 1/1
#4 lore raw

Re: [PATCH v2] riscv: Allow building with kcov coverage

Quoted 9 lines · Tobias Klauser

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of some early boot code and vdso.

Boot-tested on QEMU's riscv64 virt machine.

Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>

Assuming it boots now :)

Quoted 68 lines
---
 arch/riscv/Kconfig              | 2 ++
 arch/riscv/boot/Makefile        | 2 ++
 arch/riscv/kernel/vdso/Makefile | 1 +
 arch/riscv/mm/Makefile          | 2 ++
 4 files changed, 7 insertions(+)
arch/riscv/Kconfig +2 -0
index 089293e4ad46..a7d7f8184f15 100644
@@ -19,6 +19,7 @@ config RISCV
        select ARCH_HAS_DEBUG_WX
        select ARCH_HAS_GCOV_PROFILE_ALL
        select ARCH_HAS_GIGANTIC_PAGE
+       select ARCH_HAS_KCOV
        select ARCH_HAS_MMIOWB
        select ARCH_HAS_PTE_SPECIAL
        select ARCH_HAS_SET_DIRECT_MAP
@@ -57,6 +58,7 @@ config RISCV
        select HAVE_DMA_CONTIGUOUS if MMU
        select HAVE_EBPF_JIT if MMU
        select HAVE_FUTEX_CMPXCHG if FUTEX
+       select HAVE_GCC_PLUGINS
        select HAVE_GENERIC_VDSO if MMU && 64BIT
        select HAVE_PCI
        select HAVE_PERF_EVENTS
arch/riscv/boot/Makefile +2 -0
index 3530c59b3ea7..c59fca695f9d 100644
@@ -14,6 +14,8 @@
 # Based on the ia64 and arm64 boot/Makefile.
 #
 
+KCOV_INSTRUMENT := n
+
 OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
 
 targets := Image loader
arch/riscv/kernel/vdso/Makefile +1 -0
index 29cf052f6541..4b0d3bcc44e5 100644
@@ -29,6 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
arch/riscv/mm/Makefile +2 -1
index 363ef01c30b1..c0185e556ca5 100644
@@ -5,6 +5,8 @@ ifdef CONFIG_FTRACE
 CFLAGS_REMOVE_init.o = -pg
 endif
 
+KCOV_INSTRUMENT_init.o := n
+
 obj-y += init.o
 obj-y += extable.o
 obj-$(CONFIG_MMU) += fault.o pageattr.o
--

2.27.0

maintainer
#5 lore raw

Re: [PATCH v2] riscv: Allow building with kcov coverage

In reply to Tobias Klauser
Quoted 4 lines · On Fri, 26 Jun 2020 05:40:56 PDT (-0700), [email protected] wrote:

Add ARCH_HAS_KCOV and HAVE_GCC_PLUGINS to the riscv Kconfig. Also disable instrumentation of some early boot code and vdso.

Boot-tested on QEMU's riscv64 virt machine.

Thanks. This is on for-next (with the ack). I'm boot testing a config with

CONFIG_KCOV=y
CONFIG_KCOV_ENABLE_COMPARISONS=y

but LMK if there's something more interesting to test. I don't see anything coverage-related in the boot log...

Quoted 68 lines
Cc Björn Töpel <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 arch/riscv/Kconfig              | 2 ++
 arch/riscv/boot/Makefile        | 2 ++
 arch/riscv/kernel/vdso/Makefile | 1 +
 arch/riscv/mm/Makefile          | 2 ++
 4 files changed, 7 insertions(+)
arch/riscv/Kconfig +2 -0
index 089293e4ad46..a7d7f8184f15 100644
@@ -19,6 +19,7 @@ config RISCV
 	select ARCH_HAS_DEBUG_WX
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_GIGANTIC_PAGE
+	select ARCH_HAS_KCOV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SET_DIRECT_MAP
@@ -57,6 +58,7 @@ config RISCV
 	select HAVE_DMA_CONTIGUOUS if MMU
 	select HAVE_EBPF_JIT if MMU
 	select HAVE_FUTEX_CMPXCHG if FUTEX
+	select HAVE_GCC_PLUGINS
 	select HAVE_GENERIC_VDSO if MMU && 64BIT
 	select HAVE_PCI
 	select HAVE_PERF_EVENTS
arch/riscv/boot/Makefile +2 -0
index 3530c59b3ea7..c59fca695f9d 100644
@@ -14,6 +14,8 @@
 # Based on the ia64 and arm64 boot/Makefile.
 #
 
+KCOV_INSTRUMENT := n
+
 OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
 
 targets := Image loader
arch/riscv/kernel/vdso/Makefile +1 -0
index 29cf052f6541..4b0d3bcc44e5 100644
@@ -29,6 +29,7 @@ CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
 
 # Disable gcov profiling for VDSO code
 GCOV_PROFILE := n
+KCOV_INSTRUMENT := n
 
 # Force dependency
 $(obj)/vdso.o: $(obj)/vdso.so
arch/riscv/mm/Makefile +2 -0
index 363ef01c30b1..c0185e556ca5 100644
@@ -5,6 +5,8 @@ ifdef CONFIG_FTRACE
 CFLAGS_REMOVE_init.o = -pg
 endif
 
+KCOV_INSTRUMENT_init.o := n
+
 obj-y += init.o
 obj-y += extable.o
 obj-$(CONFIG_MMU) += fault.o pageattr.o