Skip to contentSkip to conversation

net: fix skb_ext BUILD_BUG_ON failures with GCOV

PATCH Superseded Konstantin Khorenko 4 participants 13 messages Apr 2 – Apr 12

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

cover net: fix skb_ext BUILD_BUG_ON failures with GCOV

This mini-series fixes build failures in net/core/skbuff.c when the kernel is built with CONFIG_GCOV_PROFILE_ALL=y.

This is part of a larger effort to add -fprofile-update=atomic to global CFLAGS_GCOV (posted earlier as a combined series):
https://lore.kernel.org/lkml/[email protected]/T/#t

That combined series was split per subsystem as requested by Jakub. The companion patches are:

- iommu: disable GCOV for iommu_amdv1.o (sent to iommu maintainers)
- gcov: add -fprofile-update=atomic globally (sent to gcov/kbuild maintainers, depends on this series and the iommu patch)

Patch 1/2 fixes a pre-existing build failure with CONFIG_GCOV_PROFILE_ALL:
GCOV counters prevent GCC from constant-folding the skb_ext_total_length() loop. This is v3 of a previously posted standalone fix:
https://lore.kernel.org/lkml/[email protected]/T/#t

Patch 2/2 is an additional fix needed when -fprofile-update=atomic is added to CFLAGS_GCOV: __no_profile on the __always_inline function alone is insufficient because after inlining, the code resides in the caller's profiled body. The caller needs __no_profile as well.

Konstantin Khorenko (2):
net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL
net: add __no_profile to skb_extensions_init() for GCOV compatibility

 net/core/skbuff.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.5
#1 lore raw

PATCH 1/2 net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:

In file included from <command-line>:
In function 'skb_extensions_init',

      inlined from 'skb_init' at net/core/skbuff.c:5214:2:

././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255

CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result.
BUILD_BUG_ON requires a compile-time constant and fails.

The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.

Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.

This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0, as __no_profile handles both GCOV and KCOV instrumentation at the root cause level rather than just disabling the check.

Fixes 5d21d0a65b57 ("net: generalize calculation of skb extensions length")
Fixes d6e5794b06c0 ("net: avoid build bug in skb extension length calculation")
---
 net/core/skbuff.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -3
index 0e217041958a..47c7f0ab6e84 100644
@@ -5145,7 +5145,7 @@ static const u8 skb_ext_type_len[] = {
 #endif
 };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 {
 	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
 	int i;
@@ -5159,9 +5159,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
 static void skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif
 
 	skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache",
 					     SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
Signature · 1 line
2.43.5
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

Quoted 64 lines · Konstantin Khorenko

When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:

In file included from <command-line>:
In function 'skb_extensions_init',

       inlined from 'skb_init' at net/core/skbuff.c:5214:2:

././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255

CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result.
BUILD_BUG_ON requires a compile-time constant and fails.

The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.

Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.

This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0, as __no_profile handles both GCOV and KCOV instrumentation at the root cause level rather than just disabling the check.

Fixes 5d21d0a65b57 ("net: generalize calculation of skb extensions length")
Fixes d6e5794b06c0 ("net: avoid build bug in skb extension length calculation")
---
  net/core/skbuff.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -3
index 0e217041958a..47c7f0ab6e84 100644
@@ -5145,7 +5145,7 @@ static const u8 skb_ext_type_len[] = {
  #endif
  };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
  {
  	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
  	int i;
@@ -5159,9 +5159,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
  static void skb_extensions_init(void)
  {
  	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
  	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif
 
  	skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache",
  					     SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
maintainer
#3 lore raw

Re: [PATCH 1/2] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

In reply to Konstantin Khorenko
Quoted 32 lines · Konstantin Khorenko

When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:

In file included from <command-line>:
In function 'skb_extensions_init',

      inlined from 'skb_init' at net/core/skbuff.c:5214:2:

././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255

CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result.
BUILD_BUG_ON requires a compile-time constant and fails.

The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.

Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.

This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0, as __no_profile handles both GCOV and KCOV instrumentation at the root cause level rather than just disabling the check.

Quoted 4 lines
Fixes 5d21d0a65b57 ("net: generalize calculation of skb extensions length")
Fixes d6e5794b06c0 ("net: avoid build bug in skb extension length calculation")

No empty lines in the tags area.

Also given the commit description, isn't the introduction of the 5th skb extension a better fixes tag?

Quoted 19 lines
---
 net/core/skbuff.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -1
index 0e217041958a..47c7f0ab6e84 100644
@@ -5145,7 +5145,7 @@ static const u8 skb_ext_type_len[] = {
 #endif
 };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 {
 	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
 	int i;

net/core/skbuff.c static __always_inline unsigned int skb_ext_total_length(void) · line 5164

Quoted 6 lines
net/core/skbuff.c +0 -2
@@ -5159,9 +5159,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
 static void skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif

Sashiko notes that there could be still build breakage:

https://sashiko.dev/#/patchset/20260402140558.1437002-1-khorenko%40virtuozzo.com

Could you please double check the above?

I think a 'noinline' in skb_extensions_init() would address any complains on patch 2/2

/P

Quoted 3 lines
net/core/skbuff.c +0 -0
 	skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache",
 					     SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
#4 lore raw

Re: [PATCH 1/2] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

Quoted 1 line · Paolo Abeni

On 4/2/26 4:05 PM, Konstantin Khorenko wrote:

...

Quoted 7 lines
Quoted 5 lines
Fixes 5d21d0a65b57 ("net: generalize calculation of skb extensions length")
Fixes d6e5794b06c0 ("net: avoid build bug in skb extension length calculation")

No empty lines in the tags area.

Sure, will fix.

Quoted 2 lines

Also given the commit description, isn't the introduction of the 5th skb extension a better fixes tag?

Well, if we did not have 5d21d0a65b57 ("net: generalize calculation of skb extensions length"), we won't have a problem even after 5th skb extension.

On the other hand, yes, the defect reveals itself only after the appearance of the 5th skb extension, so we can also treat it guilty.

i will change the Fixes: tag.

Quoted 28 lines
Quoted 19 lines
---
  net/core/skbuff.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -1
index 0e217041958a..47c7f0ab6e84 100644
@@ -5145,7 +5145,7 @@ static const u8 skb_ext_type_len[] = {
  #endif
  };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
  {
  	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
  	int i;

net/core/skbuff.c static __always_inline unsigned int skb_ext_total_length(void) · line 5164

Quoted 6 lines
net/core/skbuff.c +0 -2
@@ -5159,9 +5159,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
  static void skb_extensions_init(void)
  {
  	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
  	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif

Sashiko notes that there could be still build breakage:

Quoted 3 lines

https://sashiko.dev/#/patchset/20260402140558.1437002-1-khorenko%40virtuozzo.com

Could you please double check the above?

Sashiko is great!

The concern about KCOV is valid in theory but doesn't apply in practice. Here's why:

__no_profile (__no_profile_instrument_function__) indeed only prevents GCOV profiling counters (-fprofile-arcs) from being inserted. It has no effect on KCOV instrumentation (-fsanitize-coverage=trace-pc), which would require __no_sanitize_coverage instead.

However, KCOV instrumentation does not break constant folding in the first place.
I verified this with a standalone test: a __always_inline function with a loop over a const array (mimicking skb_ext_total_length()), compiled with different instrumentation flags:

* No instrumentation: BUILD_BUG_ON passes (constant folded)
* GCOV (-fprofile-arcs -ftest-coverage -fno-tree-loop-im): BUILD_BUG_ON fails
* KCOV (-fsanitize-coverage=trace-pc): BUILD_BUG_ON passes (constant folded)
* GCOV + atomic (-fprofile-arcs -ftest-coverage -fno-tree-loop-im -fprofile-update=atomic):
BUILD_BUG_ON fails

The difference is in how GCC instruments code. GCOV inserts global counter increments inside the loop body. Combined with -fno-tree-loop-im, these counter operations prevent GCC from proving the loop result is a compile-time constant.

KCOV only inserts __sanitizer_cov_trace_pc() callbacks at basic block entries - these are opaque function calls that don't participate in value computation, so GCC can still see the loop iterates over a const array and fold it.

Quoted 2 lines

I think a 'noinline' in skb_extensions_init() would address any complains on patch 2/2

Yes, will add "noinline" to be on a safe side.

--
Konstantin Khorenko

#5 lore raw

PATCH 2/2 net: add __no_profile to skb_extensions_init() for GCOV compatibility

In reply to Konstantin Khorenko

With -fprofile-update=atomic in global CFLAGS_GCOV, GCC still cannot constant-fold the skb_ext_total_length() loop when it is inlined into a profiled caller. The existing __no_profile on skb_ext_total_length() itself is insufficient because after __always_inline expansion the code resides in the caller's body, which still carries GCOV instrumentation.

Mark skb_extensions_init() with __no_profile so the BUILD_BUG_ON checks can be evaluated at compile time.

---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
index 47c7f0ab6e84..99704d6832e2 100644
@@ -5156,7 +5156,7 @@ static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 	return l;
 }
 
-static void skb_extensions_init(void)
+static void __no_profile skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
Signature · 1 line
2.43.5
#6 lore raw

v2 cover net: fix skb_ext BUILD_BUG_ON failures with GCOV

In reply to Konstantin Khorenko

This mini-series fixes build failures in net/core/skbuff.c when the kernel is built with CONFIG_GCOV_PROFILE_ALL=y.

This is part of a larger effort to add -fprofile-update=atomic to global CFLAGS_GCOV (posted earlier as a combined series) [1].

The companion patch:
- gcov: add -fprofile-update=atomic globally (sent to gcov/kbuild maintainers, depends on this series) [2]

There was another companion patch here, but i appeared to be already applied recently: 8b72aa5704c7 ("iommupt/amdv1: mark amdv1pt_install_leaf_entry as __always_inline").

Patch 1/2 fixes a pre-existing build failure with CONFIG_GCOV_PROFILE_ALL:
GCOV counters prevent GCC from constant-folding the skb_ext_total_length() loop. It also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard from d6e5794b06c0: that guard was a precaution in case KCOV instrumentation also prevented constant folding, but KCOV's -fsanitize-coverage=trace-pc does not interfere with GCC's constant folding (verified experimentally with GCC 14.2 and GCC 16.0.1), so the guard is unnecessary.

Patch 2/2 is an additional fix needed when -fprofile-update=atomic is added to CFLAGS_GCOV: __no_profile on the __always_inline function alone is insufficient because after inlining, the code resides in the caller's profiled body. The caller (skb_extensions_init) needs __no_profile and noinline to prevent re-exposure to GCOV instrumentation.

Changes v1 -> v2:
- Patch 1/2: expanded the commit message to explain why removing the CONFIG_KCOV_INSTRUMENT_ALL guard is safe (KCOV's -fsanitize-coverage=trace-pc does not inhibit constant folding, unlike GCOV's -fprofile-arcs + -fno-tree-loop-im). Changed Fixes tag to point at the commit that introduced the 5th SKB extension type which triggered the failure.
Removed empty lines in tags area.

- Patch 2/2: added noinline to skb_extensions_init() to prevent the compiler from inlining it into skb_init(), which would re-expose the function body to GCOV instrumentation.

v1: https://lore.kernel.org/lkml/[email protected]/T/#t

[1] https://lore.kernel.org/lkml/[email protected]/T/#t
[2] https://lore.kernel.org/lkml/[email protected]/T/#t

Tested with:
- GCC 14.2.1, CONFIG_GCOV_PROFILE_ALL=y
- GCC 14.2.1, CONFIG_KCOV_INSTRUMENT_ALL=y (GCOV disabled)
- GCC 16.0.1 20260327 (experimental), CONFIG_GCOV_PROFILE_ALL=y

Konstantin Khorenko (2):
net: fix skb_ext_total_length() BUILD_BUG_ON with
CONFIG_GCOV_PROFILE_ALL
net: add noinline __no_profile to skb_extensions_init() for GCOV
compatibility

 net/core/skbuff.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.5
#7 lore raw

PATCH v2 1/2 net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:

In file included from <command-line>:
In function 'skb_extensions_init',

      inlined from 'skb_init' at net/core/skbuff.c:5214:2:

././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255

CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result.
BUILD_BUG_ON requires a compile-time constant and fails.

The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.

Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.

This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0. That guard was added as a precaution because KCOV instrumentation was also suspected of inhibiting constant folding. However, KCOV uses -fsanitize-coverage=trace-pc, which inserts lightweight trace callbacks that do not interfere with GCC's constant folding or loop optimization passes. Only GCOV's -fprofile-arcs combined with -fno-tree-loop-im actually prevents the compiler from evaluating the loop at compile time. The guard is therefore unnecessary and can be safely removed.

Fixes 96ea3a1e2d31 ("can: add CAN skb extension infrastructure")
---
 net/core/skbuff.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -3
index 43ee86dcf2ea..59fb4b2bb821 100644
@@ -5142,7 +5142,7 @@ static const u8 skb_ext_type_len[] = {
 #endif
 };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 {
 	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
 	int i;
@@ -5156,9 +5156,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
 static void skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif
 
 	skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache",
 					     SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
Signature · 1 line
2.43.5
#8 lore raw

PATCH v2 2/2 net: add noinline __no_profile to skb_extensions_init() for GCOV compatibility

In reply to Konstantin Khorenko

With -fprofile-update=atomic in global CFLAGS_GCOV, GCC still cannot constant-fold the skb_ext_total_length() loop when it is inlined into a profiled caller. The existing __no_profile on skb_ext_total_length() itself is insufficient because after __always_inline expansion the code resides in the caller's body, which still carries GCOV instrumentation.

Mark skb_extensions_init() with __no_profile so the BUILD_BUG_ON checks can be evaluated at compile time. Also mark it noinline to prevent the compiler from inlining it into skb_init() (which lacks __no_profile), which would re-expose the function body to GCOV instrumentation.

Build-tested with both CONFIG_GCOV_PROFILE_ALL=y and CONFIG_KCOV_INSTRUMENT_ALL=y.

---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
index 59fb4b2bb821..8d75e352e3b1 100644
@@ -5153,7 +5153,7 @@ static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 	return l;
 }
 
-static void skb_extensions_init(void)
+static noinline void __no_profile skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
Signature · 1 line
2.43.5
#9 lore raw

v3 cover net: fix skb_ext BUILD_BUG_ON failures with GCOV

In reply to Konstantin Khorenko

This mini-series fixes build failures in net/core/skbuff.c when the kernel is built with CONFIG_GCOV_PROFILE_ALL=y.

This is part of a larger effort to add -fprofile-update=atomic to global CFLAGS_GCOV (posted earlier as a combined series):
https://lore.kernel.org/lkml/[email protected]/T/#t

That combined series was split per subsystem as requested by Jakub. The companion patches are:

- iommu: use __always_inline for amdv1pt_install_leaf_entry() (sent to iommu maintainers)
- gcov: add -fprofile-update=atomic globally (sent to gcov/kbuild maintainers, depends on this series and the iommu patch)

Patch 1/2 fixes a pre-existing build failure with CONFIG_GCOV_PROFILE_ALL:
GCOV counters prevent GCC from constant-folding the skb_ext_total_length() loop. It also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard from d6e5794b06c0: that guard was a precaution in case KCOV instrumentation also prevented constant folding, but KCOV's -fsanitize-coverage=trace-pc does not interfere with GCC's constant folding (verified experimentally with GCC 14.2 and GCC 16.0.1), so the guard is unnecessary.

Patch 2/2 is an additional fix needed when -fprofile-update=atomic is added to CFLAGS_GCOV: __no_profile on the __always_inline function alone is insufficient because after inlining, the code resides in the caller's profiled body. The caller (skb_extensions_init) needs __no_profile and noinline to prevent re-exposure to GCOV instrumentation.

Changes v2 -> v3:
- Patch 2/2: added __init since skb_extensions_init() is only called from __init skb_init() - without it noinline would keep the function in permanent .text, wasting memory after boot.

Changes v1 -> v2:
- Patch 1/2: expanded the commit message to explain why removing the CONFIG_KCOV_INSTRUMENT_ALL guard is safe (KCOV's -fsanitize-coverage=trace-pc does not inhibit constant folding, unlike GCOV's -fprofile-arcs + -fno-tree-loop-im). Changed Fixes tag to point at the commit that introduced the 5th SKB extension type which triggered the failure.
Removed empty lines in tags area.
- Patch 2/2: added noinline to skb_extensions_init() to prevent the compiler from inlining it into skb_init(), which would re-expose the function body to GCOV instrumentation.

v2: https://lore.kernel.org/lkml/[email protected]/T/#t
v1: https://lore.kernel.org/lkml/[email protected]/T/#t

Tested with:
- GCC 14.2.1, CONFIG_GCOV_PROFILE_ALL=y
- GCC 14.2.1, CONFIG_KCOV_INSTRUMENT_ALL=y (GCOV disabled)
- GCC 16.0.1 20260327 (experimental), CONFIG_GCOV_PROFILE_ALL=y

Konstantin Khorenko (2):
net: fix skb_ext_total_length() BUILD_BUG_ON with
CONFIG_GCOV_PROFILE_ALL
net: add noinline __init __no_profile to skb_extensions_init() for
GCOV compatibility

 net/core/skbuff.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.5
#10 lore raw

PATCH v3 1/2 net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

When CONFIG_GCOV_PROFILE_ALL=y is enabled, the kernel fails to build:

In file included from <command-line>:
In function 'skb_extensions_init',

      inlined from 'skb_init' at net/core/skbuff.c:5214:2:

././include/linux/compiler_types.h:706:45: error: call to
'__compiletime_assert_1490' declared with attribute error:
BUILD_BUG_ON failed: skb_ext_total_length() > 255

CONFIG_GCOV_PROFILE_ALL adds -fprofile-arcs -ftest-coverage -fno-tree-loop-im to CFLAGS globally. GCC inserts branch profiling counters into the skb_ext_total_length() loop and, combined with -fno-tree-loop-im (which disables loop invariant motion), cannot constant-fold the result.
BUILD_BUG_ON requires a compile-time constant and fails.

The issue manifests in kernels with 5+ SKB extension types enabled (e.g., after addition of SKB_EXT_CAN, SKB_EXT_PSP). With 4 extensions GCC can still unroll and fold the loop despite GCOV instrumentation; with 5+ it gives up.

Mark skb_ext_total_length() with __no_profile to prevent GCOV from inserting counters into this function. Without counters the loop is "clean" and GCC can constant-fold it even with -fno-tree-loop-im active. This allows BUILD_BUG_ON to work correctly while keeping GCOV profiling for the rest of the kernel.

This also removes the CONFIG_KCOV_INSTRUMENT_ALL preprocessor guard introduced by d6e5794b06c0. That guard was added as a precaution because KCOV instrumentation was also suspected of inhibiting constant folding. However, KCOV uses -fsanitize-coverage=trace-pc, which inserts lightweight trace callbacks that do not interfere with GCC's constant folding or loop optimization passes. Only GCOV's -fprofile-arcs combined with -fno-tree-loop-im actually prevents the compiler from evaluating the loop at compile time. The guard is therefore unnecessary and can be safely removed.

Fixes 96ea3a1e2d31 ("can: add CAN skb extension infrastructure")
---
 net/core/skbuff.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/skbuff.c +1 -3
index 43ee86dcf2ea..59fb4b2bb821 100644
@@ -5142,7 +5142,7 @@ static const u8 skb_ext_type_len[] = {
 #endif
 };
 
-static __always_inline unsigned int skb_ext_total_length(void)
+static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 {
 	unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
 	int i;
@@ -5156,9 +5156,7 @@ static __always_inline unsigned int skb_ext_total_length(void)
 static void skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
-#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL)
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
-#endif
 
 	skbuff_ext_cache = kmem_cache_create("skbuff_ext_cache",
 					     SKB_EXT_ALIGN_VALUE * skb_ext_total_length(),
Signature · 1 line
2.43.5
#11 lore raw

PATCH v3 2/2 net: add noinline __init __no_profile to skb_extensions_init() for GCOV compatibility

In reply to Konstantin Khorenko

With -fprofile-update=atomic in global CFLAGS_GCOV, GCC still cannot constant-fold the skb_ext_total_length() loop when it is inlined into a profiled caller. The existing __no_profile on skb_ext_total_length() itself is insufficient because after __always_inline expansion the code resides in the caller's body, which still carries GCOV instrumentation.

Mark skb_extensions_init() with __no_profile so the BUILD_BUG_ON checks can be evaluated at compile time. Also mark it noinline to prevent the compiler from inlining it into skb_init() (which lacks __no_profile), which would re-expose the function body to GCOV instrumentation.

Add __init since skb_extensions_init() is only called from __init skb_init(). Previously it was implicitly inlined into the .init.text section; with noinline it would otherwise remain in permanent .text, wasting memory after boot.

Build-tested with both CONFIG_GCOV_PROFILE_ALL=y and CONFIG_KCOV_INSTRUMENT_ALL=y.

---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/skbuff.c +1 -1
index 59fb4b2bb821..0978f526acf4 100644
@@ -5153,7 +5153,7 @@ static __always_inline __no_profile unsigned int skb_ext_total_length(void)
 	return l;
 }
 
-static void skb_extensions_init(void)
+static noinline void __init __no_profile skb_extensions_init(void)
 {
 	BUILD_BUG_ON(SKB_EXT_NUM > 8);
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
Signature · 1 line
2.43.5
#12 lore raw
In reply to Konstantin Khorenko
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 10 Apr 2026 19:21:48 +0300 you wrote:

This mini-series fixes build failures in net/core/skbuff.c when the kernel is built with CONFIG_GCOV_PROFILE_ALL=y.

This is part of a larger effort to add -fprofile-update=atomic to global CFLAGS_GCOV (posted earlier as a combined series):
https://lore.kernel.org/lkml/[email protected]/T/#t

[...]

Here is the summary with links:
- [v3,1/2] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL

    https://git.kernel.org/netdev/net-next/c/c0b4382c86e3
  - [v3,2/2] net: add noinline __init __no_profile to skb_extensions_init() for GCOV compatibility
    https://git.kernel.org/netdev/net-next/c/29b1ee8788c5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html