Skip to contentSkip to conversation

perf arm_spe: Fix bitfield dependency failure

PATCH In review Leo Yan 3 participants 5 messages Jan 23

Subsystems (2)
lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/1 perf arm_spe: Fix bitfield dependency failure

A perf build failure was reported by Thomas Voegtle on stable kernel v6.6.120:

make perf NO_JEVENTS=1 NO_LIBTRACEEVENT=1
BUILD: Doing 'make -j12' parallel build
HOSTCC fixdep.o
HOSTLD fixdep-in.o
...
...

    CC      tests/sample-parsing.o
    CC      util/intel-pt-decoder/intel-pt-pkt-decoder.o
    CC      util/perf-regs-arch/perf_regs_csky.o
    CC      util/arm-spe-decoder/arm-spe-pkt-decoder.o
    CC      util/perf-regs-arch/perf_regs_loongarch.o
  In file included from util/arm-spe-decoder/arm-spe-pkt-decoder.h:10,
                   from util/arm-spe-decoder/arm-spe-pkt-decoder.c:14:
  /local/git/linux-stable-rc/tools/include/linux/bitfield.h: In function ‘le16_encode_bits’:
  /local/git/linux-stable-rc/tools/include/linux/bitfield.h:166:31: error: implicit declaration of
  function ‘cpu_to_le16’; did you mean ‘htole16’? [-Werror=implicit-function-declaration]
    ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
                                 ^~~~~~~~~
  /local/git/linux-stable-rc/tools/include/linux/bitfield.h:149:9: note: in definition of macro
  ‘____MAKE_OP’
    return to((v & field_mask(field)) * field_multiplier(field)); \
           ^~

/local/git/linux-stable-rc/tools/include/linux/bitfield.h:170:1: note: in expansion of macro ‘__MAKE_OP’
__MAKE_OP(16)

Fix this by including linux/kernel.h, which provides the required definitions.

The relevant C file in mainline already includes kernel.h, so the issue is not exposed. It'd be good to merge this change on mainline as well for robustness.

Fixes 64d86c03e144 ("perf arm-spe: Extend branch operations")
---
 tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +1 -0
index adf4cde320aa..8d16619cd098 100644
@@ -7,6 +7,7 @@
 #ifndef INCLUDE__ARM_SPE_PKT_DECODER_H__
 #define INCLUDE__ARM_SPE_PKT_DECODER_H__
 
+#include <linux/kernel.h>
 #include <linux/bitfield.h>
 #include <stddef.h>
 #include <stdint.h>
Signature · 1 line
2.34.1
reviewer
#1 lore raw
Quoted 50 lines · Leo Yan

A perf build failure was reported by Thomas Voegtle on stable kernel v6.6.120:

make perf NO_JEVENTS=1 NO_LIBTRACEEVENT=1
BUILD: Doing 'make -j12' parallel build
HOSTCC fixdep.o
HOSTLD fixdep-in.o
...
...

     CC      tests/sample-parsing.o
     CC      util/intel-pt-decoder/intel-pt-pkt-decoder.o
     CC      util/perf-regs-arch/perf_regs_csky.o
     CC      util/arm-spe-decoder/arm-spe-pkt-decoder.o
     CC      util/perf-regs-arch/perf_regs_loongarch.o
   In file included from util/arm-spe-decoder/arm-spe-pkt-decoder.h:10,
                    from util/arm-spe-decoder/arm-spe-pkt-decoder.c:14:
   /local/git/linux-stable-rc/tools/include/linux/bitfield.h: In function ‘le16_encode_bits’:
   /local/git/linux-stable-rc/tools/include/linux/bitfield.h:166:31: error: implicit declaration of
   function ‘cpu_to_le16’; did you mean ‘htole16’? [-Werror=implicit-function-declaration]
     ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
                                  ^~~~~~~~~
   /local/git/linux-stable-rc/tools/include/linux/bitfield.h:149:9: note: in definition of macro
   ‘____MAKE_OP’
     return to((v & field_mask(field)) * field_multiplier(field)); \
            ^~
   /local/git/linux-stable-rc/tools/include/linux/bitfield.h:170:1: note: in expansion of macro
   ‘__MAKE_OP’
    __MAKE_OP(16)

Fix this by including linux/kernel.h, which provides the required definitions.

The relevant C file in mainline already includes kernel.h, so the issue is not exposed. It'd be good to merge this change on mainline as well for robustness.

Fixes 64d86c03e144 ("perf arm-spe: Extend branch operations")
---
  tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h | 1 +
  1 file changed, 1 insertion(+)
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +0 -0
index adf4cde320aa..8d16619cd098 100644

tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h line 11

Quoted 5 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +1 -0
@@ -7,6 +7,7 @@
  #ifndef INCLUDE__ARM_SPE_PKT_DECODER_H__
  #define INCLUDE__ARM_SPE_PKT_DECODER_H__
 
+#include <linux/kernel.h>
  #include <linux/bitfield.h>

This isn't the first time I've seen this issue. Isn't the real fix to include kernel.h in bitfield.h if it depends on it? Usually you shouldn't have to know what all the dependencies of a header are when you include it. Or is there a reason it wasn't done that way in the first place? Maybe this has been discussed before?

Quoted 2 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +0 -0
  #include <stddef.h>
  #include <stdint.h>
author
#2 lore raw

On Fri, Jan 23, 2026 at 10:27:42AM +0000, James Clark wrote:

[...]

Quoted 4 lines
Quoted 4 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +0 -0
index adf4cde320aa..8d16619cd098 100644
Quoted 8 lines

tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h line 10

Quoted 5 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +1 -0
@@ -7,6 +7,7 @@
  #ifndef INCLUDE__ARM_SPE_PKT_DECODER_H__
  #define INCLUDE__ARM_SPE_PKT_DECODER_H__
+#include <linux/kernel.h>
  #include <linux/bitfield.h>

This isn't the first time I've seen this issue. Isn't the real fix to include kernel.h in bitfield.h if it depends on it?

Good point!

bitfield.h is a common header so I did not change it. I digged a bit and found diverage between kernel's bitfield.h and tool's bitfield.h.

1) The kernel's bitfield.h includes asm/byteorder.h, and finally it includes linux/byteorder/generic.h, cpu_to_le{16|32|64} are defined in this file.

2) The tool's bitfield.h will includes asm/byteorder.h, but this hooks to the headers provided by the toolchain. cpu_to_le{16|32|64} are not C lib API, they are defined in tool's kernel.h.

As a result, we need to include kernel.h for perf build.

As you said, we can include kernel.h in bitfield.h, I will respin and send a new series.

Quoted 4 lines

Usually you shouldn't
have to know what all the dependencies of a header are when you include it. Or is there a reason it wasn't done that way in the first place? Maybe this has been discussed before?

This issue is for tools only, and only Arm modules in perf folder use this header, I don't expect this is widely spread issue.

Thanks,
Leo

#3 lore raw
Quoted 22 lines · On Fri, 23 Jan 2026 12:08:47 +0000 Leo Yan <[email protected]> wrote:

On Fri, Jan 23, 2026 at 10:27:42AM +0000, James Clark wrote:

[...]

Quoted 4 lines
Quoted 4 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +0 -0
index adf4cde320aa..8d16619cd098 100644
Quoted 8 lines

tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h line 10

Quoted 5 lines
tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.h +1 -0
@@ -7,6 +7,7 @@
  #ifndef INCLUDE__ARM_SPE_PKT_DECODER_H__
  #define INCLUDE__ARM_SPE_PKT_DECODER_H__
+#include <linux/kernel.h>
  #include <linux/bitfield.h>  

This isn't the first time I've seen this issue. Isn't the real fix to include kernel.h in bitfield.h if it depends on it?

Good point!

bitfield.h is a common header so I did not change it. I digged a bit and found diverage between kernel's bitfield.h and tool's bitfield.h.

Quoted 7 lines

1) The kernel's bitfield.h includes asm/byteorder.h, and finally it includes linux/byteorder/generic.h, cpu_to_le{16|32|64} are defined in this file.

2) The tool's bitfield.h will includes asm/byteorder.h, but this hooks to the headers provided by the toolchain. cpu_to_le{16|32|64} are not C lib API, they are defined in tool's kernel.h.

Perhaps cpu_to_le16() and friends should be defined in the tools asm/byteorder.h rather than its kernel.h.

David

Quoted 17 lines

As a result, we need to include kernel.h for perf build.

As you said, we can include kernel.h in bitfield.h, I will respin and send a new series.

Quoted 4 lines

Usually you shouldn't
have to know what all the dependencies of a header are when you include it. Or is there a reason it wasn't done that way in the first place? Maybe this has been discussed before?

This issue is for tools only, and only Arm modules in perf folder use this header, I don't expect this is widely spread issue.

Thanks,
Leo

author
#4 lore raw

On Fri, Jan 23, 2026 at 02:03:17PM +0000, David Laight wrote:

[...]

Quoted 7 lines
Quoted 7 lines

bitfield.h is a common header so I did not change it. I digged a bit and found diverage between kernel's bitfield.h and tool's bitfield.h.

1) The kernel's bitfield.h includes asm/byteorder.h, and finally it includes linux/byteorder/generic.h, cpu_to_le{16|32|64} are defined in this file.

Quoted 6 lines
Quoted 3 lines

2) The tool's bitfield.h will includes asm/byteorder.h, but this hooks to the headers provided by the toolchain. cpu_to_le{16|32|64} are not C lib API, they are defined in tool's kernel.h.

Perhaps cpu_to_le16() and friends should be defined in the tools asm/byteorder.h rather than its kernel.h.

This will override the toolchain's asm/byteorder.h.

Another issue is:

  $ git grep -l cpu_to_le tools/
  tools/arch/x86/include/asm/insn.h
  tools/include/asm-generic/io.h
  tools/include/linux/bitfield.h
  tools/include/linux/kernel.h
  tools/include/linux/unaligned.h
  tools/perf/util/intel-pt.c
  tools/testing/cxl/test/mem.c
  tools/testing/nvdimm/test/ndtest.c
  tools/testing/selftests/arm64/fp/fp-ptrace.c
  tools/testing/selftests/kvm/include/arm64/processor.h
  tools/testing/selftests/kvm/lib/arm64/gic_v3_its.c
  tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
  tools/usb/ffs-test.c

I assume these programs include kernel.h for calling cpu_to_le(), if move cpu_to_le() out from kernel.h, it will break build for these programs.

Thanks,
Leo