Skip to content

Commit 0c207b7

Browse files
author
Herton R. Krzesinski
committed
Merge: Attend warnings with gcc 11&12 when building kernel and modules
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1852 Bugzilla: https://bugzilla.redhat.com/2159468 Attend the warnings encountered when building CentOS Stream 9 kernel and module for x86_64 and arm64 using GCC11 (cs9) and GCC12 (f37). Some warnings end up being disabled usptream (-Wdangling-pointer, -Warray-bounds for GCC12 and -Wdeprecated for the sign-file.c), so backport these changes to align with this behavior. A few configurations were introduced to deal with -Werror and specific warnings depending on the toolchain and target architecture. This merge-request tries to bring these relevant patches without breaking compilation (e.g, CONFIG_WERROR is introduced, but not set). https://bugzilla.redhat.com/2142659 was already opened separately to attend the -Wstringop-overread in net/core/dev.c. Signed-off-by: Eric Chanudet <echanude@redhat.com> Approved-by: Vladis Dronov <vdronov@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Prarit Bhargava <prarit@redhat.com> Approved-by: Jonathan Toppins <jtoppins@redhat.com> Approved-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 2b11252 + 0cfa199 commit 0c207b7

File tree

34 files changed

+225
-196
lines changed

34 files changed

+225
-196
lines changed

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,10 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
808808

809809
KBUILD_CFLAGS += $(stackp-flags-y)
810810

811+
KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
812+
KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
813+
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
814+
811815
ifdef CONFIG_CC_IS_CLANG
812816
KBUILD_CPPFLAGS += -Qunused-arguments
813817
# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
@@ -818,17 +822,18 @@ KBUILD_CFLAGS += -Wno-gnu
818822
KBUILD_CFLAGS += -mno-global-merge
819823
else
820824

821-
# Warn about unmarked fall-throughs in switch statement.
822-
# Disabled for clang while comment to attribute conversion happens and
823-
# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
824-
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
825+
# gcc inanely warns about local variables called 'main'
826+
KBUILD_CFLAGS += -Wno-main
825827
endif
826828

827829
# These warnings generated too much noise in a regular build.
828830
# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
829831
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
830-
831832
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
833+
834+
# These result in bogus false positives
835+
KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
836+
832837
ifdef CONFIG_FRAME_POINTER
833838
KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
834839
else
@@ -1011,12 +1016,15 @@ KBUILD_CFLAGS += -Wvla
10111016
# disable pointer signed / unsigned warnings in gcc 4.0
10121017
KBUILD_CFLAGS += -Wno-pointer-sign
10131018

1019+
# In order to make sure new function cast mismatches are not introduced
1020+
# in the kernel (to avoid tripping CFI checking), the kernel should be
1021+
# globally built with -Wcast-function-type.
1022+
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
1023+
10141024
# disable stringop warnings in gcc 8+
10151025
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
10161026

10171027
# We'll want to enable this eventually, but it's not going away for 5.7 at least
1018-
KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
1019-
KBUILD_CFLAGS += -Wno-array-bounds
10201028
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
10211029

10221030
# Another good warning that we'll want to enable eventually
@@ -1368,8 +1376,8 @@ scripts_unifdef: scripts_basic
13681376
# Install
13691377

13701378
# Many distributions have the custom install script, /sbin/installkernel.
1371-
# If DKMS is installed, 'make install' will eventually recuses back
1372-
# to the this Makefile to build and install external modules.
1379+
# If DKMS is installed, 'make install' will eventually recurse back
1380+
# to this Makefile to build and install external modules.
13731381
# Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
13741382

13751383
install: sub_make_done :=

arch/s390/Kconfig

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ config S390
124124
select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES
125125
select DMA_OPS if PCI
126126
select DYNAMIC_FTRACE if FUNCTION_TRACER
127+
select GCC12_NO_ARRAY_BOUNDS
127128
select GENERIC_ALLOCATOR
128129
select GENERIC_CPU_AUTOPROBE
129130
select GENERIC_CPU_VULNERABILITIES
@@ -707,16 +708,6 @@ config STACK_GUARD
707708
The minimum size for the stack guard should be 256 for 31 bit and
708709
512 for 64 bit.
709710

710-
config WARN_DYNAMIC_STACK
711-
def_bool n
712-
prompt "Emit compiler warnings for function with dynamic stack usage"
713-
help
714-
This option enables the compiler option -mwarn-dynamicstack. If the
715-
compiler supports this options generates warnings for functions
716-
that dynamically allocate stack space using alloca.
717-
718-
Say N if you are unsure.
719-
720711
endmenu
721712

722713
menu "I/O subsystem"

arch/s390/Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ KBUILD_CFLAGS_DECOMPRESSOR += -fno-stack-protector
3232
KBUILD_CFLAGS_DECOMPRESSOR += $(call cc-disable-warning, address-of-packed-member)
3333
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g)
3434
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,))
35+
KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds)
36+
3537
UTS_MACHINE := s390x
3638
STACK_SIZE := $(if $(CONFIG_KASAN),65536,16384)
3739
CHECKFLAGS += -D__s390__ -D__s390x__
@@ -85,13 +87,6 @@ cflags-$(CONFIG_CHECK_STACK) += -mstack-guard=$(CONFIG_STACK_GUARD)
8587
endif
8688
endif
8789

88-
ifdef CONFIG_WARN_DYNAMIC_STACK
89-
ifneq ($(call cc-option,-mwarn-dynamicstack),)
90-
KBUILD_CFLAGS += -mwarn-dynamicstack
91-
KBUILD_CFLAGS_DECOMPRESSOR += -mwarn-dynamicstack
92-
endif
93-
endif
94-
9590
ifdef CONFIG_EXPOLINE
9691
ifdef CONFIG_EXPOLINE_EXTERN
9792
KBUILD_LDFLAGS_MODULE += arch/s390/lib/expoline/expoline.o

arch/sparc/include/asm/smp_32.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ extern volatile unsigned long cpu_callin_map[NR_CPUS];
3333
extern cpumask_t smp_commenced_mask;
3434
extern struct linux_prom_registers smp_penguin_ctable;
3535

36-
typedef void (*smpfunc_t)(unsigned long, unsigned long, unsigned long,
37-
unsigned long, unsigned long);
38-
3936
void cpu_panic(void);
4037

4138
/*
@@ -57,7 +54,7 @@ void smp_bogo(struct seq_file *);
5754
void smp_info(struct seq_file *);
5855

5956
struct sparc32_ipi_ops {
60-
void (*cross_call)(smpfunc_t func, cpumask_t mask, unsigned long arg1,
57+
void (*cross_call)(void *func, cpumask_t mask, unsigned long arg1,
6158
unsigned long arg2, unsigned long arg3,
6259
unsigned long arg4);
6360
void (*resched)(int cpu);
@@ -66,28 +63,28 @@ struct sparc32_ipi_ops {
6663
};
6764
extern const struct sparc32_ipi_ops *sparc32_ipi_ops;
6865

69-
static inline void xc0(smpfunc_t func)
66+
static inline void xc0(void *func)
7067
{
7168
sparc32_ipi_ops->cross_call(func, *cpu_online_mask, 0, 0, 0, 0);
7269
}
7370

74-
static inline void xc1(smpfunc_t func, unsigned long arg1)
71+
static inline void xc1(void *func, unsigned long arg1)
7572
{
7673
sparc32_ipi_ops->cross_call(func, *cpu_online_mask, arg1, 0, 0, 0);
7774
}
78-
static inline void xc2(smpfunc_t func, unsigned long arg1, unsigned long arg2)
75+
static inline void xc2(void *func, unsigned long arg1, unsigned long arg2)
7976
{
8077
sparc32_ipi_ops->cross_call(func, *cpu_online_mask, arg1, arg2, 0, 0);
8178
}
8279

83-
static inline void xc3(smpfunc_t func, unsigned long arg1, unsigned long arg2,
80+
static inline void xc3(void *func, unsigned long arg1, unsigned long arg2,
8481
unsigned long arg3)
8582
{
8683
sparc32_ipi_ops->cross_call(func, *cpu_online_mask,
8784
arg1, arg2, arg3, 0);
8885
}
8986

90-
static inline void xc4(smpfunc_t func, unsigned long arg1, unsigned long arg2,
87+
static inline void xc4(void *func, unsigned long arg1, unsigned long arg2,
9188
unsigned long arg3, unsigned long arg4)
9289
{
9390
sparc32_ipi_ops->cross_call(func, *cpu_online_mask,

arch/sparc/kernel/leon_smp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void leonsmp_ipi_interrupt(void)
359359
}
360360

361361
static struct smp_funcall {
362-
smpfunc_t func;
362+
void *func;
363363
unsigned long arg1;
364364
unsigned long arg2;
365365
unsigned long arg3;
@@ -372,7 +372,7 @@ static struct smp_funcall {
372372
static DEFINE_SPINLOCK(cross_call_lock);
373373

374374
/* Cross calls must be serialized, at least currently. */
375-
static void leon_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
375+
static void leon_cross_call(void *func, cpumask_t mask, unsigned long arg1,
376376
unsigned long arg2, unsigned long arg3,
377377
unsigned long arg4)
378378
{
@@ -384,7 +384,7 @@ static void leon_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
384384

385385
{
386386
/* If you make changes here, make sure gcc generates proper code... */
387-
register smpfunc_t f asm("i0") = func;
387+
register void *f asm("i0") = func;
388388
register unsigned long a1 asm("i1") = arg1;
389389
register unsigned long a2 asm("i2") = arg2;
390390
register unsigned long a3 asm("i3") = arg3;
@@ -444,11 +444,13 @@ static void leon_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
444444
/* Running cross calls. */
445445
void leon_cross_call_irq(void)
446446
{
447+
void (*func)(unsigned long, unsigned long, unsigned long, unsigned long,
448+
unsigned long) = ccall_info.func;
447449
int i = smp_processor_id();
448450

449451
ccall_info.processors_in[i] = 1;
450-
ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
451-
ccall_info.arg4, ccall_info.arg5);
452+
func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3, ccall_info.arg4,
453+
ccall_info.arg5);
452454
ccall_info.processors_out[i] = 1;
453455
}
454456

arch/sparc/kernel/sun4d_smp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static void sun4d_ipi_resched(int cpu)
268268
}
269269

270270
static struct smp_funcall {
271-
smpfunc_t func;
271+
void *func;
272272
unsigned long arg1;
273273
unsigned long arg2;
274274
unsigned long arg3;
@@ -281,7 +281,7 @@ static struct smp_funcall {
281281
static DEFINE_SPINLOCK(cross_call_lock);
282282

283283
/* Cross calls must be serialized, at least currently. */
284-
static void sun4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
284+
static void sun4d_cross_call(void *func, cpumask_t mask, unsigned long arg1,
285285
unsigned long arg2, unsigned long arg3,
286286
unsigned long arg4)
287287
{
@@ -296,7 +296,7 @@ static void sun4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
296296
* If you make changes here, make sure
297297
* gcc generates proper code...
298298
*/
299-
register smpfunc_t f asm("i0") = func;
299+
register void *f asm("i0") = func;
300300
register unsigned long a1 asm("i1") = arg1;
301301
register unsigned long a2 asm("i2") = arg2;
302302
register unsigned long a3 asm("i3") = arg3;
@@ -353,11 +353,13 @@ static void sun4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
353353
/* Running cross calls. */
354354
void smp4d_cross_call_irq(void)
355355
{
356+
void (*func)(unsigned long, unsigned long, unsigned long, unsigned long,
357+
unsigned long) = ccall_info.func;
356358
int i = hard_smp_processor_id();
357359

358360
ccall_info.processors_in[i] = 1;
359-
ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
360-
ccall_info.arg4, ccall_info.arg5);
361+
func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3, ccall_info.arg4,
362+
ccall_info.arg5);
361363
ccall_info.processors_out[i] = 1;
362364
}
363365

arch/sparc/kernel/sun4m_smp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void sun4m_ipi_mask_one(int cpu)
157157
}
158158

159159
static struct smp_funcall {
160-
smpfunc_t func;
160+
void *func;
161161
unsigned long arg1;
162162
unsigned long arg2;
163163
unsigned long arg3;
@@ -170,7 +170,7 @@ static struct smp_funcall {
170170
static DEFINE_SPINLOCK(cross_call_lock);
171171

172172
/* Cross calls must be serialized, at least currently. */
173-
static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
173+
static void sun4m_cross_call(void *func, cpumask_t mask, unsigned long arg1,
174174
unsigned long arg2, unsigned long arg3,
175175
unsigned long arg4)
176176
{
@@ -230,11 +230,13 @@ static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
230230
/* Running cross calls. */
231231
void smp4m_cross_call_irq(void)
232232
{
233+
void (*func)(unsigned long, unsigned long, unsigned long, unsigned long,
234+
unsigned long) = ccall_info.func;
233235
int i = smp_processor_id();
234236

235237
ccall_info.processors_in[i] = 1;
236-
ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
237-
ccall_info.arg4, ccall_info.arg5);
238+
func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3, ccall_info.arg4,
239+
ccall_info.arg5);
238240
ccall_info.processors_out[i] = 1;
239241
}
240242

arch/sparc/mm/srmmu.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,19 +1636,19 @@ static void __init get_srmmu_type(void)
16361636
/* Local cross-calls. */
16371637
static void smp_flush_page_for_dma(unsigned long page)
16381638
{
1639-
xc1((smpfunc_t) local_ops->page_for_dma, page);
1639+
xc1(local_ops->page_for_dma, page);
16401640
local_ops->page_for_dma(page);
16411641
}
16421642

16431643
static void smp_flush_cache_all(void)
16441644
{
1645-
xc0((smpfunc_t) local_ops->cache_all);
1645+
xc0(local_ops->cache_all);
16461646
local_ops->cache_all();
16471647
}
16481648

16491649
static void smp_flush_tlb_all(void)
16501650
{
1651-
xc0((smpfunc_t) local_ops->tlb_all);
1651+
xc0(local_ops->tlb_all);
16521652
local_ops->tlb_all();
16531653
}
16541654

@@ -1659,7 +1659,7 @@ static void smp_flush_cache_mm(struct mm_struct *mm)
16591659
cpumask_copy(&cpu_mask, mm_cpumask(mm));
16601660
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
16611661
if (!cpumask_empty(&cpu_mask))
1662-
xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
1662+
xc1(local_ops->cache_mm, (unsigned long)mm);
16631663
local_ops->cache_mm(mm);
16641664
}
16651665
}
@@ -1671,7 +1671,7 @@ static void smp_flush_tlb_mm(struct mm_struct *mm)
16711671
cpumask_copy(&cpu_mask, mm_cpumask(mm));
16721672
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
16731673
if (!cpumask_empty(&cpu_mask)) {
1674-
xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
1674+
xc1(local_ops->tlb_mm, (unsigned long)mm);
16751675
if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
16761676
cpumask_copy(mm_cpumask(mm),
16771677
cpumask_of(smp_processor_id()));
@@ -1691,8 +1691,8 @@ static void smp_flush_cache_range(struct vm_area_struct *vma,
16911691
cpumask_copy(&cpu_mask, mm_cpumask(mm));
16921692
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
16931693
if (!cpumask_empty(&cpu_mask))
1694-
xc3((smpfunc_t) local_ops->cache_range,
1695-
(unsigned long) vma, start, end);
1694+
xc3(local_ops->cache_range, (unsigned long)vma, start,
1695+
end);
16961696
local_ops->cache_range(vma, start, end);
16971697
}
16981698
}
@@ -1708,8 +1708,8 @@ static void smp_flush_tlb_range(struct vm_area_struct *vma,
17081708
cpumask_copy(&cpu_mask, mm_cpumask(mm));
17091709
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
17101710
if (!cpumask_empty(&cpu_mask))
1711-
xc3((smpfunc_t) local_ops->tlb_range,
1712-
(unsigned long) vma, start, end);
1711+
xc3(local_ops->tlb_range, (unsigned long)vma, start,
1712+
end);
17131713
local_ops->tlb_range(vma, start, end);
17141714
}
17151715
}
@@ -1723,8 +1723,7 @@ static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
17231723
cpumask_copy(&cpu_mask, mm_cpumask(mm));
17241724
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
17251725
if (!cpumask_empty(&cpu_mask))
1726-
xc2((smpfunc_t) local_ops->cache_page,
1727-
(unsigned long) vma, page);
1726+
xc2(local_ops->cache_page, (unsigned long)vma, page);
17281727
local_ops->cache_page(vma, page);
17291728
}
17301729
}
@@ -1738,8 +1737,7 @@ static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
17381737
cpumask_copy(&cpu_mask, mm_cpumask(mm));
17391738
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
17401739
if (!cpumask_empty(&cpu_mask))
1741-
xc2((smpfunc_t) local_ops->tlb_page,
1742-
(unsigned long) vma, page);
1740+
xc2(local_ops->tlb_page, (unsigned long)vma, page);
17431741
local_ops->tlb_page(vma, page);
17441742
}
17451743
}
@@ -1753,7 +1751,7 @@ static void smp_flush_page_to_ram(unsigned long page)
17531751
* XXX This experiment failed, research further... -DaveM
17541752
*/
17551753
#if 1
1756-
xc1((smpfunc_t) local_ops->page_to_ram, page);
1754+
xc1(local_ops->page_to_ram, page);
17571755
#endif
17581756
local_ops->page_to_ram(page);
17591757
}
@@ -1764,8 +1762,7 @@ static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
17641762
cpumask_copy(&cpu_mask, mm_cpumask(mm));
17651763
cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
17661764
if (!cpumask_empty(&cpu_mask))
1767-
xc2((smpfunc_t) local_ops->sig_insns,
1768-
(unsigned long) mm, insn_addr);
1765+
xc2(local_ops->sig_insns, (unsigned long)mm, insn_addr);
17691766
local_ops->sig_insns(mm, insn_addr);
17701767
}
17711768

0 commit comments

Comments
 (0)