Skip to contentSkip to conversation

arm: perf: Fix ARCH=arm build with GCC

PATCH Applied James Clark 4 participants 5 messages Dec 15, 2023 – Dec 17, 2023

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

v2 cover arm: perf: Fix ARCH=arm build with GCC

Changes since V1:

* Instead of wrapping everything in #if, just use GENMASK_ULL instead which fixes both issues in one commit.

A fix for the broken build with GCC currently in linux-next (next-20231214)

James Clark (1):
arm: perf: Fix ARCH=arm build with GCC

 include/linux/perf/arm_pmuv3.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 arm: perf: Fix ARCH=arm build with GCC

LLVM ignores everything inside the if statement and doesn't generate errors, but GCC doesn't ignore it, resulting in the following error:

drivers/perf/arm_pmuv3.c: In function ‘armv8pmu_write_evtype’:
include/linux/bits.h:34:29: error: left shift count >= width of type [-Werror=shift-count-overflow]
34 | (((~UL(0)) - (UL(1) << (l)) + 1) & \

Fix it by using GENMASK_ULL which doesn't overflow on arm32 (even though the value is never used there).

Fixes 3115ee021bfb ("arm64: perf: Include threshold control fields in PMEVTYPER mask")
---
 include/linux/perf/arm_pmuv3.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/perf/arm_pmuv3.h +2 -2
index 0f4d62ef3a9a..46377e134d67 100644
@@ -234,8 +234,8 @@
  * PMXEVTYPER: Event selection reg
  */
 #define ARMV8_PMU_EVTYPE_EVENT	GENMASK(15, 0)	/* Mask for EVENT bits */
-#define ARMV8_PMU_EVTYPE_TH	GENMASK(43, 32)
-#define ARMV8_PMU_EVTYPE_TC	GENMASK(63, 61)
+#define ARMV8_PMU_EVTYPE_TH	GENMASK_ULL(43, 32) /* arm64 only */
+#define ARMV8_PMU_EVTYPE_TC	GENMASK_ULL(63, 61) /* arm64 only */
 
 /*
  * Event filters for PMUv3
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#2 lore raw
Quoted 23 lines · James Clark

LLVM ignores everything inside the if statement and doesn't generate errors, but GCC doesn't ignore it, resulting in the following error:

drivers/perf/arm_pmuv3.c: In function ‘armv8pmu_write_evtype’:
include/linux/bits.h:34:29: error: left shift count >= width of type [-Werror=shift-count-overflow]
34 | (((~UL(0)) - (UL(1) << (l)) + 1) & \

Fix it by using GENMASK_ULL which doesn't overflow on arm32 (even though the value is never used there).

Fixes 3115ee021bfb ("arm64: perf: Include threshold control fields in PMEVTYPER mask")
---
 include/linux/perf/arm_pmuv3.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/perf/arm_pmuv3.h +0 -0
index 0f4d62ef3a9a..46377e134d67 100644

include/linux/perf/arm_pmuv3.h line 238

Quoted 7 lines
include/linux/perf/arm_pmuv3.h +2 -2
@@ -234,8 +234,8 @@
  * PMXEVTYPER: Event selection reg
  */
 #define ARMV8_PMU_EVTYPE_EVENT	GENMASK(15, 0)	/* Mask for EVENT bits */
-#define ARMV8_PMU_EVTYPE_TH	GENMASK(43, 32)
-#define ARMV8_PMU_EVTYPE_TC	GENMASK(63, 61)
+#define ARMV8_PMU_EVTYPE_TH	GENMASK_ULL(43, 32) /* arm64 only */
+#define ARMV8_PMU_EVTYPE_TC	GENMASK_ULL(63, 61) /* arm64 only */

As expected this fixes compilation on my end, too and it's nicer than v1.

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer Acked-by on v2 1/1
#3 lore raw
In reply to James Clark
Quoted 9 lines · James Clark

LLVM ignores everything inside the if statement and doesn't generate errors, but GCC doesn't ignore it, resulting in the following error:

drivers/perf/arm_pmuv3.c: In function 'armv8pmu_write_evtype':
include/linux/bits.h:34:29: error: left shift count >= width of type [-Werror=shift-count-overflow]
34 | (((~UL(0)) - (UL(1) << (l)) + 1) & \

Fix it by using GENMASK_ULL which doesn't overflow on arm32 (even though the value is never used there).

It would be nice if this could explain the overflow problem, i.e.

| The GENMASK() macro creates masks of type unsigned long, and we use this to
| geenrate the ARMV8_PMU_EVTYPE_TH and ARMV8_PMU_EVTYPE_TC constants. These
| include bits above bit 31, and generating these requires shifting more than the
| size of unsigned long on 32-bit ARM.
| 
| Consequently when building for 32-bit arm, GCC warns about their use:
| 
|   drivers/perf/arm_pmuv3.c: In function 'armv8pmu_write_evtype':
|   include/linux/bits.h:34:29: error: left shift count >= width of type [-Werror=shift-count-overflow]
|   34 |         (((~UL(0)) - (UL(1) << (l)) + 1) & \
| 
| ... though LLVM does not warn as the actual usage is not reachable on 32-bit
| ARM due to `if (IS_ENABLED(...)` checks.
| 
| Avoid the warning by using GENMACK_ULL(), which doesn't overflow on 32-bit arm.
Quoted 4 lines
Fixes 3115ee021bfb ("arm64: perf: Include threshold control fields in PMEVTYPER mask")

Thanks for this!

Will, Catalin, the broken commit is queued in the arm64 for-next/perf branch (and merged into for-next/core); is this something we can easily fold in?

Mark.

Quoted 22 lines
---
 include/linux/perf/arm_pmuv3.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/perf/arm_pmuv3.h +2 -2
index 0f4d62ef3a9a..46377e134d67 100644
@@ -234,8 +234,8 @@
  * PMXEVTYPER: Event selection reg
  */
 #define ARMV8_PMU_EVTYPE_EVENT	GENMASK(15, 0)	/* Mask for EVENT bits */
-#define ARMV8_PMU_EVTYPE_TH	GENMASK(43, 32)
-#define ARMV8_PMU_EVTYPE_TC	GENMASK(63, 61)
+#define ARMV8_PMU_EVTYPE_TH	GENMASK_ULL(43, 32) /* arm64 only */
+#define ARMV8_PMU_EVTYPE_TC	GENMASK_ULL(63, 61) /* arm64 only */
 
 /*
  * Event filters for PMUv3
Signature · 1 line
2.34.1
maintainer Applied
#4 lore raw
In reply to James Clark
Quoted 9 lines · James Clark

Changes since V1:

* Instead of wrapping everything in #if, just use GENMASK_ULL instead which fixes both issues in one commit.

A fix for the broken build with GCC currently in linux-next (next-20231214)

[...]

Applied to will (for-next/perf), thanks!

[1/1] arm: perf: Fix ARCH=arm build with GCC

      https://git.kernel.org/will/c/bb339db4d363

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev