Skip to contentSkip to conversation

linux-6.1.y: fix build errors with newer GCC/glibc

PATCH In review Clark Williams 4 participants 6 messages Jun 17 – Jul 2

Subsystems (6)
Stable branch x86 KVM BPF +2 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover linux-6.1.y: fix build errors with newer GCC/glibc

Please apply to linux-6.1.y.

Two build fixes for newer toolchains (GCC 15+ / glibc 2.43+):

1) tools/lib/bpf: strchr() now propagates const in newer glibc, causing -Werror=discarded-qualifiers on next_path in resolve_full_path(). Equivalent to upstream commit d70f79fef658.

2) KVM: VMX: regparm(0) on vmread_error_trampoline is a no-op on x86-64 and newer GCC emits -Wattributes for it. Guard with CONFIG_X86_32. Simpler equivalent of upstream commit 0b5e7a16a0a7 which redesigns the declaration entirely.

Changes since v1:
- Fixed Assisted-by tag format per coding-assistants.html
- Added upstream commit references per stable-kernel-rules.html
- Updated KVM subsystem prefix to conventional KVM: VMX: style
- Fixed Author/Signed-off-by email mismatch

Clark Williams (2):
tools/lib/bpf: fix const-qualifier discard in resolve_full_path
KVM: VMX: guard regparm(0) on vmread_error_trampoline for x86_32 only

 arch/x86/kvm/vmx/vmx_ops.h | 7 +++++--
 tools/lib/bpf/libbpf.c     | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

base-commit: 228da13e907e2b46b7222cfc35290fbfad920bef

Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/2 tools/lib/bpf: fix const-qualifier discard in resolve_full_path

[ Upstream commit d70f79fef65810faf64dbae1f3a1b5623cdb2345 ]

strchr() now propagates const when passed a const char * argument in newer GCC/glibc combinations, causing -Werror=discarded-qualifiers to fire on the assignment to next_path. Declare next_path as const char * since it is only used for pointer arithmetic, never written through.

[ clrkwllms: only the next_path change from the upstream commit applies
to 6.1.y ]

Assisted-by Claude:claude-sonnet-4.6
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 7bd6aff6e260..33b214a91338 100644
@@ -10748,7 +10748,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
 		if (!search_paths[i])
 			continue;
 		for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
-			char *next_path;
+			const char *next_path;
 			int seg_len;
 
 			if (s[0] == ':')
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH v2 1/2] tools/lib/bpf: fix const-qualifier discard in resolve_full_path

Quoted 8 lines · Clark Williams

[ Upstream commit d70f79fef65810faf64dbae1f3a1b5623cdb2345 ]

strchr() now propagates const when passed a const char * argument in newer GCC/glibc combinations, causing -Werror=discarded-qualifiers to fire on the assignment to next_path. Declare next_path as const char * since it is only used for pointer arithmetic, never written through.

Quoted 5 lines

[ clrkwllms: only the next_path change from the upstream commit applies
to 6.1.y ]

Assisted-by Claude:claude-sonnet-4.6

No. There is no reason to backport this patch. Distros build and ship libbpf from official github source. The kernel source tree is the source of truth though. From there it gets synced into github automatically. Anything but the latest bpf-next and bpf trees are irrelevant. Hence, please do NOT backport any tools/lib/bpf/ patches. Ever. It is just a waste of electrons.

maintainer
#3 lore raw

Re: [PATCH v2 1/2] tools/lib/bpf: fix const-qualifier discard in resolve_full_path

In reply to Clark Williams
Quoted 7 lines · Clark Williams

[ Upstream commit d70f79fef65810faf64dbae1f3a1b5623cdb2345 ]

strchr() now propagates const when passed a const char * argument in newer GCC/glibc combinations, causing -Werror=discarded-qualifiers to fire on the assignment to next_path. Declare next_path as const char * since it is only used for pointer arithmetic, never written through.

Quoted 8 lines

[ clrkwllms: only the next_path change from the upstream commit applies
to 6.1.y ]

Assisted-by Claude:claude-sonnet-4.6
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Looks nothing like the original, including stripping off the tags :(

Please be more careful when you resend a new series.

thanks,

greg k-h

#4 lore raw

PATCH v2 2/2 KVM: VMX: guard regparm(0) on vmread_error_trampoline for x86_32 only

In reply to Clark Williams

[ Upstream commit 0b5e7a16a0a79a3742f0df9e45bca46f01b40e6a ]

regparm(0) overrides the kernel's -mregparm=3 convention on x86-32 so that vmread_error_trampoline receives its arguments on the stack, matching the inline asm callers that push args before the call. On x86-64 the attribute is a no-op and newer GCC now emits -Wattributes for it, which becomes a build error under -Werror. Guard it with CONFIG_X86_32.

[ clrkwllms: the upstream commit redesigns the trampoline declaration as
an opaque symbol; this simpler approach guards the regparm(0) attribute with CONFIG_X86_32 since the attribute is only meaningful on x86-32. ]

Assisted-by Claude:claude-sonnet-4.6
---
 arch/x86/kvm/vmx/vmx_ops.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx_ops.h +5 -2
index 5edab28dfb2e..50328be40b2b 100644
@@ -11,8 +11,11 @@
 #include "../x86.h"
 
 void vmread_error(unsigned long field, bool fault);
-__attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,
-							 bool fault);
+/* regparm(0) overrides -mregparm=3 so args are stack-passed, matching asm callers */
+#ifdef CONFIG_X86_32
+__attribute__((regparm(0)))
+#endif
+void vmread_error_trampoline(unsigned long field, bool fault);
 void vmwrite_error(unsigned long field, unsigned long value);
 void vmclear_error(struct vmcs *vmcs, u64 phys_addr);
 void vmptrld_error(struct vmcs *vmcs, u64 phys_addr);
Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH v2 2/2] KVM: VMX: guard regparm(0) on vmread_error_trampoline for x86_32 only

Quoted 26 lines · Clark Williams

[ Upstream commit 0b5e7a16a0a79a3742f0df9e45bca46f01b40e6a ]

regparm(0) overrides the kernel's -mregparm=3 convention on x86-32 so that vmread_error_trampoline receives its arguments on the stack, matching the inline asm callers that push args before the call. On x86-64 the attribute is a no-op and newer GCC now emits -Wattributes for it, which becomes a build error under -Werror. Guard it with CONFIG_X86_32.

[ clrkwllms: the upstream commit redesigns the trampoline declaration as
an opaque symbol; this simpler approach guards the regparm(0) attribute with CONFIG_X86_32 since the attribute is only meaningful on x86-32. ]

Assisted-by Claude:claude-sonnet-4.6
---
  arch/x86/kvm/vmx/vmx_ops.h | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx_ops.h +0 -0
index 5edab28dfb2e..50328be40b2b 100644
@@ -11,8 +11,11 @@
  #include "../x86.h"
 
  void vmread_error(unsigned long field, bool fault);

arch/x86/kvm/vmx/vmx_ops.h line 21

Quoted 10 lines
arch/x86/kvm/vmx/vmx_ops.h +5 -2
-__attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,
-							 bool fault);
+/* regparm(0) overrides -mregparm=3 so args are stack-passed, matching asm callers */
+#ifdef CONFIG_X86_32
+__attribute__((regparm(0)))
+#endif
+void vmread_error_trampoline(unsigned long field, bool fault);
  void vmwrite_error(unsigned long field, unsigned long value);
  void vmclear_error(struct vmcs *vmcs, u64 phys_addr);
  void vmptrld_error(struct vmcs *vmcs, u64 phys_addr);

Hi,

I've sent a backport patch for this commit, see here:

https://lore.kernel.org/lkml/[email protected]/

The commit applies cleanly without any modifications, and compiles without errors with gcc-16, and boots.

For commits that apply cleanly, you can simply use:

git cherry-pick -s -x <commit-id>

And after that

    git commit --amend

to add the required [ Upstream commit <commit-id> ] line.

I wasn't able to see other compilation errors for v6.1.175 using gcc-16. I tried with allyesconfig and my local config.

Hope this helps.

Best regards,

Hanne-Lotta Mäenpää