x86/csum: Relax the len and proto constraints in 32-bit csum_ipv6_magic()
PATCH 1/1 x86/csum: Relax the len and proto constraints in 32-bit csum_ipv6_magic()
Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling:
In file included from net/netfilter/nf_synproxy_core.c:7:
In file included from ./include/linux/skbuff.h:26:
In file included from ./include/net/checksum.h:21:
In file included from ./arch/x86/include/asm/checksum.h:9:
./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than available
The csum_ipv6_magic() asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from.
In synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm. Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19, 21 and 22.
Neither len nor proto has to be in a register: adcl also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like.
ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, like nf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates.
---
KernelCI's kbuild-clang-21-i386-allmodconfig job has failed on mainline with this error since the 7.2 merge window, v7.3 included.
Tested on i386 with KernelCI's allmodconfig-based .config: with clang 19.1.7, 21.1.8 and 22.1.8, nf_synproxy_core.o fails before this change and builds after it, and net/{netfilter,ipv4,ipv6,bridge}/ and arch/x86/lib/ build without errors or warnings. The same directories also build cleanly with GCC 16.2 (i386 allmodconfig). A 32-bit userspace harness comparing the asm against a C reference over 2M random and carry-edge inputs shows no mismatches with either compiler. No full allmodconfig build or boot test.
arch/x86/include/asm/checksum_32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/checksum_32.h +1 -1
@@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory");return csum_fold (sum);
Signature · 1 line
2.53.0
Quoted 62 lines · Sasha Levin
Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling:
In file included from
net/netfilter/nf_synproxy_core.c:7:
In file included from./include/linux/skbuff.h:26:
In file included from./include/net/checksum.h:21:
In file included from./arch/x86/include/asm/checksum.h:9:
./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than availableThe
csum_ipv6_magic()asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from.In
synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm. Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19, 21 and 22.Neither len nor proto has to be in a register: adcl also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like.
ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, likenf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates.Fixes 403cec8ab6d0 ("netfilter: add option for GCOV profiling")Reported-by kernelci.org bot <[email protected]>Reported-by Jeff Johnson <[email protected]>Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>---
KernelCI's kbuild-clang-21-i386-allmodconfig job has failed on mainline with this error since the 7.2 merge window, v7.3 included.Tested on i386 with KernelCI's allmodconfig-based .config: with clang 19.1.7, 21.1.8 and 22.1.8, nf_synproxy_core.o fails before this change and builds after it, and
net/{netfilter,ipv4,ipv6,bridge}/andarch/x86/lib/build without errors or warnings. The same directories also build cleanly with GCC 16.2 (i386 allmodconfig). A 32-bit userspace harness comparing the asm against a C reference over 2M random and carry-edge inputs shows no mismatches with either compiler. No full allmodconfig build or boot test.arch/x86/include/asm/checksum_32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/include/asm/checksum_32.h +0
-0
arch/x86/include/asm/checksum_32.h static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, · line 163
Quoted 6 lines
arch/x86/include/asm/checksum_32.h +1
-1@@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory");
Quoted 5 lines
arch/x86/include/asm/checksum_32.h +0
-1return csum_fold (sum); --2.53.0
Borislav Petkov
maintainerQuoted 33 lines · Rosen Penev
Quoted 32 lines · Sasha Levin
Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling:
In file included from
net/netfilter/nf_synproxy_core.c:7:
In file included from./include/linux/skbuff.h:26:
In file included from./include/net/checksum.h:21:
In file included from./arch/x86/include/asm/checksum.h:9:
./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than availableThe
csum_ipv6_magic()asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from.In
synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm. Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19, 21 and 22.Neither len nor proto has to be in a register: adcl also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like.
ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, likenf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates.
Quoted 12 lines
Quoted 9 lines
Fixes 403cec8ab6d0 ("netfilter: add option for GCOV profiling")Reported-by kernelci.org bot <[email protected]>Reported-by Jeff Johnson <[email protected]>Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>Quoted 3 lines
---
KernelCI's kbuild-clang-21-i386-allmodconfig job has failed on mainline with this error since the 7.2 merge window, v7.3 included.
This'll tell you how much people including us care about 32-bit...
Quoted 12 lines
Quoted 12 lines
Tested on i386 with KernelCI's allmodconfig-based .config: with clang 19.1.7, 21.1.8 and 22.1.8, nf_synproxy_core.o fails before this change and builds after it, and
net/{netfilter,ipv4,ipv6,bridge}/andarch/x86/lib/build without errors or warnings. The same directories also build cleanly with GCC 16.2 (i386 allmodconfig). A 32-bit userspace harness comparing the asm against a C reference over 2M random and carry-edge inputs shows no mismatches with either compiler. No full allmodconfig build or boot test.arch/x86/include/asm/checksum_32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
arch/x86/include/asm/checksum_32.h static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, · line 163
Quoted 11 lines
arch/x86/include/asm/checksum_32.h +1
-1@@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory");
Except that Sasha's commit message explains it perfectly clear how this happens while for yours I would've asked how you're reproducing this.
OTOH, I'm not sure I care about Sasha's AI's blurb about what params should've been in what registers and so on... :)
If only you guys would agree on how to merge the two, assign authorship and drop the unnecessary blurb...
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 5 lines · Borislav Petkov
Quoted 3 lines · Sasha Levin
Quoted 2 lines
KernelCI's kbuild-clang-21-i386-allmodconfig job has failed on mainline with this error since the 7.2 merge window, v7.3 included.
This'll tell you how much people including us care about 32-bit...
I'm not stopping you from dropping it :)
Quoted 10 lines
Quoted 1 line
Except that Sasha's commit message explains it perfectly clear how this happens while for yours I would've asked how you're reproducing this.
OTOH, I'm not sure I care about Sasha's AI's blurb about what params should've been in what registers and so on... :)
If only you guys would agree on how to merge the two, assign authorship and drop the unnecessary blurb...
Any objection to just taking Rosen's? Maybe with the tags I had on mine to make tracking easier?
Signature · 2 lines
Thanks, Sasha
Borislav Petkov
maintainerQuoted 1 line · Sasha Levin
I'm not stopping you from dropping it :)
I'd love to.
Quoted 2 lines
Any objection to just taking Rosen's? Maybe with the tags I had on mine to make tracking easier?
Thanks, that's nice of you.
I'd like to use a trimmed version of your commit message because it explains the big picture better as to why we need this in the first place.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 6 lines · Borislav Petkov
Quoted 1 line · Sasha Levin
I'm not stopping you from dropping it :)
I'd love to.
Quoted 7 lines
Quoted 2 lines
Any objection to just taking Rosen's? Maybe with the tags I had on mine to make tracking easier?
Thanks, that's nice of you.
I'd like to use a trimmed version of your commit message because it explains the big picture better as to why we need this in the first place.
Feel free.
Quoted 8 lines
Thx.
--
Regards/Gruss,
Boris.
Quoted 2 lines · Borislav Petkov
I'd like to use a trimmed version of your commit message because it explains the big picture better as to why we need this in the first place.
Hi Boris,
Gentle ping on this one, I don't see it in tip yet. The clang i386 allmodconfig build of mainline is still failing on it.
--
Thanks,
Sasha
Quoted 2 lines · Sasha Levin
Gentle ping on this one, I don't see it in tip yet. The clang i386 allmodconfig build of mainline is still failing on it.
Yah, lost in the avalanche of mail. :-\
I have queued this below, it should appear next week, when the MW is over.
---
commit e0837307007837088ce417d8f061f90105f1b20c (HEAD -> refs/heads/queue)
Author: Rosen Penev <[email protected]> Date: Mon Oct 19 20:32:38 2026 -0400
x86/csum: Relax the len and proto constraints in 32-bit csum_ipv6_magic()
Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling:
In file included from net/netfilter/nf_synproxy_core.c:7:
In file included from ./include/linux/skbuff.h:26:
In file included from ./include/net/checksum.h:21:
In file included from ./arch/x86/include/asm/checksum.h:9:
./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than available
The csum_ipv6_magic() asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from.
In synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm.
Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19-22.
Neither len nor proto has to be in a register: ADCL also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like.
ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, like nf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates.
[ bp: Make Rosen Penev the author because of a previous identical submission
https://lore.kernel.org/all/[email protected]/ and Sasha graciously agreeing and giving his much more detailed commit message explaining the background of why this exists. ]
arch/x86/include/asm/checksum_32.h +1 -1
@@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory");return csum_fold (sum);
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 32 lines · Sasha Levin
Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling:
In file included from
net/netfilter/nf_synproxy_core.c:7:
In file included from./include/linux/skbuff.h:26:
In file included from./include/net/checksum.h:21:
In file included from./arch/x86/include/asm/checksum.h:9:
./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than availableThe
csum_ipv6_magic()asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from.In
synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm. Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19, 21 and 22.Neither len nor proto has to be in a register: adcl also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like.
ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, likenf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates.
Quoted 9 lines
Fixes 403cec8ab6d0 ("netfilter: add option for GCOV profiling")Reported-by kernelci.org bot <[email protected]>Reported-by Jeff Johnson <[email protected]>Assisted-by LLMSigned-off-by Sasha Levin <[email protected]>
Quoted 32 lines
---
KernelCI's kbuild-clang-21-i386-allmodconfig job has failed on mainline with this error since the 7.2 merge window, v7.3 included.Tested on i386 with KernelCI's allmodconfig-based .config: with clang 19.1.7, 21.1.8 and 22.1.8, nf_synproxy_core.o fails before this change and builds after it, and
net/{netfilter,ipv4,ipv6,bridge}/andarch/x86/lib/build without errors or warnings. The same directories also build cleanly with GCC 16.2 (i386 allmodconfig). A 32-bit userspace harness comparing the asm against a C reference over 2M random and carry-edge inputs shows no mismatches with either compiler. No full allmodconfig build or boot test.arch/x86/include/asm/checksum_32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/include/asm/checksum_32.h +1
-2@@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory");return csum_fold (sum); --2.53.0
Signature · 2 lines
Thanks, ~Nick Desaulniers