Skip to contentSkip to conversation

x86/vdso: Address sparse warnings

PATCH In review Thomas Gleixner 2 participants 6 messages Jan 17 – Jan 22

Subsystems (3)
lore
Share & tools
lore

Thomas Gleixner

author maintainer
#0 lore raw

cover x86/vdso: Address sparse warnings

Sparse is unhappy when building the 32-bit VDSO for a 64-bit kernel and complains about an empty switch statement when all config knobs which guard the cases are disabled.

The following series cures both.

Thanks,

tglx

---
 Makefile |    4 ++++
 vma.c    |    2 ++
 2 files changed, 6 insertions(+)
author maintainer
#1 lore raw

PATCH 1/2 x86/vdso: Tweak CHECKFLAGS for 32-bit VDSO build

Sparse complains about a too large shift in the VDSO32 source file:

arch/x86/entry/vdso/vdso32/vclock_gettime.c: note: in included file (through /home/tglx/work/kernel/tip/tip/arch/x86/entry/vdso/vdso32/../vclock_gettime.c):
arch/x86/entry/vdso/vdso32/../../../../../lib/vdso/gettimeofday.c:454:26: warning: shift too big (40) for type unsigned long

That's because sparse is invoked with -D__x86_64__ -m64 on the command line, which causes it to use __BITS_PER_LONG = 64. That causes __GENMASK() to use a way too big shift value.

Give the CHECKFLAGS which are handed to sparse a similar treatment as KBUILD_CFLAGS get for the 32-bit VDSO build.

---
 arch/x86/entry/vdso/Makefile |    4 ++++
 1 file changed, 4 insertions(+)
arch/x86/entry/vdso/Makefile +4 -0
@@ -144,6 +144,10 @@ endif
 
 $(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
 
+CHECKFLAGS_32 := $(subst -m64,-m32,$(CHECKFLAGS))
+CHECKFLAGS_32 := $(subst -D__x86_64__,-D__i386__,$(CHECKFLAGS_32))
+$(obj)/vdso32.so.dbg: CHECKFLAGS = $(CHECKFLAGS_32)
+
 $(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
 	$(call if_changed,vdso_and_check)
 
author maintainer
#4 lore raw

PATCH 2/2 x86/vdso: Prevent empty switch case warning

In reply to Thomas Gleixner

Sparse complains rightfully when CONFIG_PARAVIRT_CLOCK and CONFIG_HYPERV_TIMER are both not set:

arch/x86/entry/vdso/vma.c:94:9: warning: switch with no cases

Add a default case to fix that.

---
 arch/x86/entry/vdso/vma.c |    2 ++
 1 file changed, 2 insertions(+)
arch/x86/entry/vdso/vma.c +2 -0
@@ -114,6 +114,8 @@ static vm_fault_t vvar_vclock_fault(cons
 		break;
 	}
 #endif /* CONFIG_HYPERV_TIMER */
+	default:
+		break;
 	}
 
 	return VM_FAULT_SIGBUS;
#5 lore raw

Re: [patch 2/2] x86/vdso: Prevent empty switch case warning

Hi,

Quoted 15 lines · Thomas Gleixner

Sparse complains rightfully when CONFIG_PARAVIRT_CLOCK and CONFIG_HYPERV_TIMER are both not set:

arch/x86/entry/vdso/vma.c:94:9: warning: switch with no cases

Add a default case to fix that.

---
 arch/x86/entry/vdso/vma.c |    2 ++
 1 file changed, 2 insertions(+)

arch/x86/entry/vdso/vma.c static vm_fault_t vvar_vclock_fault(cons · line 118

Quoted 5 lines
arch/x86/entry/vdso/vma.c +2 -0
@@ -114,6 +114,8 @@ static vm_fault_t vvar_vclock_fault(cons
 		break;
 	}
 #endif /* CONFIG_HYPERV_TIMER */
+	default:
+		break;

This makes the code uglier only to pacify sparse.
It turns out all the necessary stub functions are in place to just delete the ifdefs altogether. Maybe replace them with IS_ENABLED() to make it clearer to reader what is going on.

Quoted 4 lines
arch/x86/entry/vdso/vma.c +0 -0
 	}
 
 	return VM_FAULT_SIGBUS;
Reviewed-by on v1 1/2
#2 lore raw

Re: [patch 1/2] x86/vdso: Tweak CHECKFLAGS for 32-bit VDSO build

In reply to Thomas Gleixner
Quoted 5 lines · Thomas Gleixner

Sparse complains about a too large shift in the VDSO32 source file:

arch/x86/entry/vdso/vdso32/vclock_gettime.c: note: in included file (through /home/tglx/work/kernel/tip/tip/arch/x86/entry/vdso/vdso32/../vclock_gettime.c):
arch/x86/entry/vdso/vdso32/../../../../../lib/vdso/gettimeofday.c:454:26: warning: shift too big (40) for type unsigned long

Quoted 8 lines

That's because sparse is invoked with -D__x86_64__ -m64 on the command line, which causes it to use __BITS_PER_LONG = 64. That causes __GENMASK() to use a way too big shift value.

Give the CHECKFLAGS which are handed to sparse a similar treatment as KBUILD_CFLAGS get for the 32-bit VDSO build.

arch/x86/entry/vdso/Makefile endif · line 149

Quoted 13 lines
---
 arch/x86/entry/vdso/Makefile |    4 ++++
 1 file changed, 4 insertions(+)
arch/x86/entry/vdso/Makefile +3 -0
@@ -144,6 +144,10 @@ endif
 
 $(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
 
+CHECKFLAGS_32 := $(subst -m64,-m32,$(CHECKFLAGS))
+CHECKFLAGS_32 := $(subst -D__x86_64__,-D__i386__,$(CHECKFLAGS_32))
+$(obj)/vdso32.so.dbg: CHECKFLAGS = $(CHECKFLAGS_32)

It would be nice if we had a strict variant of $(subst ...) which errors out if nothing is substituted.

Quoted 5 lines
arch/x86/entry/vdso/Makefile +1 -0
+
 $(obj)/vdso32.so.dbg: $(obj)/vdso32/vdso32.lds $(vobjs32) FORCE
 	$(call if_changed,vdso_and_check)
 
author maintainer
#3 lore raw

Re: [patch 1/2] x86/vdso: Tweak CHECKFLAGS for 32-bit VDSO build

Quoted 9 lines · Thomas Weißschuh

arch/x86/entry/vdso/Makefile endif · line 149

Quoted 5 lines · Thomas Gleixner

$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)

arch/x86/entry/vdso/Makefile +3 -0
+CHECKFLAGS_32 := $(subst -m64,-m32,$(CHECKFLAGS))
+CHECKFLAGS_32 := $(subst -D__x86_64__,-D__i386__,$(CHECKFLAGS_32))
+$(obj)/vdso32.so.dbg: CHECKFLAGS = $(CHECKFLAGS_32)

It would be nice if we had a strict variant of $(subst ...) which errors out if nothing is substituted.

Which would fail a arch=i386 build then, no? :)