[PATCH 0/1] gcov: add -fprofile-update=atomic to fix concurrent access crashes

From: Konstantin Khorenko

Date: Thu Apr 02 2026 - 10:22:12 EST


This patch adds -fprofile-update=atomic to global CFLAGS_GCOV in the
top-level Makefile to fix crashes caused by GCC merging GCOV counters
with loop induction variables in concurrent code paths.

History
-------

This was originally posted as a zlib-only fix:
https://lore.kernel.org/lkml/20260330143256.306326-1-khorenko@xxxxxxxxxxxxx/T/#t

During review, it was suggested to apply the flag globally instead of
per-subsystem, as it not only fixes the observed crash but makes GCOV
coverage data more consistent overall. A combined series was posted:
https://lore.kernel.org/lkml/20260401142020.1434243-1-khorenko@xxxxxxxxxxxxx/T/#t

That combined series is now split per subsystem as requested by
reviewers.

The GCC bug report for the underlying compiler issue:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124749

Dependencies
------------

This patch requires the following preparatory fixes to be applied first,
otherwise CONFIG_GCOV_PROFILE_ALL=y builds will fail:

- net: fix skb_ext BUILD_BUG_ON failures with GCOV (sent to netdev):
__no_profile on skb_ext_total_length() and skb_extensions_init()
https://lore.kernel.org/lkml/20260402140558.1437002-1-khorenko@xxxxxxxxxxxxx/T/#t

- iommu/generic_pt: disable GCOV for iommu_amdv1.o (sent to iommu):
GCOV_PROFILE_iommu_amdv1.o := n
https://lore.kernel.org/lkml/20260402141012.1437095-1-khorenko@xxxxxxxxxxxxx/T/#t

Without those patches, -fprofile-update=atomic prevents GCC from
constant-folding expressions inside profiled inline functions, breaking
BUILD_BUG_ON / FIELD_PREP compile-time checks.

The crash
---------

Observed during LTP IPComp stress testing on a GCOV-enabled kernel:

BUG: unable to handle page fault for address: ffffd0a3c0902ffa
RIP: inflate_fast+1431
Call Trace:
zlib_inflate
__deflate_decompress
crypto_comp_decompress
ipcomp_decompress [xfrm_ipcomp]
ipcomp_input [xfrm_ipcomp]
xfrm_input

GCC merged a global GCOV counter with the loop induction variable.
Another CPU modified the counter between loads, causing a write 3.4 MB
past a 65 KB buffer. -fprofile-update=atomic forces atomic counter
updates and prevents this merging.

Testing
-------

Build-tested with CONFIG_GCOV_PROFILE_ALL=y using GCC 11.4.1 and
GCC 16.0.1 20260327 (experimental). Both fail without the full set
of patches, both succeed with all three series applied.

Assembly-verified that -fprofile-update=atomic prevents counter-IV
merging in inflate_fast() on both compiler versions.

Also tested by Peter Oberparleiter:

Quote: "Successfully tested this series on s390 (except for patch 3 which
depends on x86) using GCC 15.2.0, GCC 10.1.0, and current Clang from git
(20260401)."

Konstantin Khorenko (1):
gcov: use atomic counter updates to fix concurrent access crashes

Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--
2.43.5