public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
Cc: horms@kernel.org, arnd@arndb.de, linux@weissschuh.net,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Subject: [PATCH 1/1] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL
Date: Mon, 30 Mar 2026 16:53:37 +0300	[thread overview]
Message-ID: <20260330135337.937540-2-khorenko@virtuozzo.com> (raw)
In-Reply-To: <20260330135337.937540-1-khorenko@virtuozzo.com>

When CONFIG_GCOV_PROFILE_ALL=y is enabled, GCC inserts branch profiling
counters into skb_ext_total_length() and, combined with -fno-tree-loop-im
from GCOV, prevents the compiler from constant-folding the loop that
sums skb_ext_type_len[] array elements.  This causes the compile-time
BUILD_BUG_ON(skb_ext_total_length() > 255) check to fail, even though
the actual computed value is well below 255.

The kernel already has a guard for CONFIG_KCOV_INSTRUMENT_ALL, which
causes the same problem.  Add a similar guard for GCOV.

The number of loop iterations matters: with 4 extension types (as in
earlier kernels), GCC 11 can still constant-fold despite GCOV. With 5+
types (after SKB_EXT_CAN and other additions), it gives up.  This is
why the issue only manifests in recent kernels with GCOV enabled.

Tested with GCC 11.4.1 and GCC 16.0.1 20260327 (experimental) - both
exhibit the same behavior.

Note that skb_ext_total_length() is still correct at runtime; this
change only allows the build to succeed when GCOV_PROFILE_ALL is
enabled for coverage analysis.

Fixes: 5d21d0a65b57 ("net: generalize calculation of skb extensions length")

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 0e217041958a..98c3d4e63219 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5159,7 +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)
+#if !IS_ENABLED(CONFIG_KCOV_INSTRUMENT_ALL) && !IS_ENABLED(CONFIG_GCOV_PROFILE_ALL)
 	BUILD_BUG_ON(skb_ext_total_length() > 255);
 #endif
 
-- 
2.43.5


  reply	other threads:[~2026-03-30 13:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 13:53 [PATCH 0/1] Fix kernel build failure with CONFIG_GCOV_PROFILE_ALL=y Konstantin Khorenko
2026-03-30 13:53 ` Konstantin Khorenko [this message]
2026-03-30 14:48   ` [PATCH 1/1] net: fix skb_ext_total_length() BUILD_BUG_ON with CONFIG_GCOV_PROFILE_ALL Thomas Weißschuh
2026-03-30 17:23     ` Konstantin Khorenko
2026-03-31  7:07       ` Thomas Weißschuh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260330135337.937540-2-khorenko@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox