2018-05-09 08:58:35

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 0/4] kernel hacking: GCC optimization for better debug experience (-Og)

From: Changbin Du <[email protected]>

Hi all,
I know some kernel developers was searching for a method to dissable GCC
optimizations, probably they want to apply GCC '-O0' option. But since Linux
kernel replys on GCC optimization to remove some dead code, so '-O0' just
breaks the build. They do need this because they want to debug kernel with
qemu, simics, kgtp or kgdb.

Thanks for the GCC '-Og' optimization level introduced in GCC 4.8, which
offers a reasonable level of optimization while maintaining fast compilation
and a good debugging experience. It is similar to '-O1' while perferring to
keep debug ability over runtime speed. With '-Og', we can build a kernel with
better debug ability and little performance drop after some simple change.

In this series, firstly introduce a new config CONFIG_NO_AUTO_INLINE after two
fixes for this new option. With this option, only functions explicitly marked
with "inline" will be inlined. This will allow the function tracer to trace
more functions because it only traces functions that the compiler has not
inlined.

Then introduce new config CC_OPTIMIZE_FOR_DEBUGGING which apply '-Og'
optimization level for whole kernel, with a simple fix in fix_to_virt().
Currently I have only tested this option on x86 and ARM platform. Other
platforms should also work but probably need some compiling fixes as what
having done in this series. I leave that to who want to try this debug
option.

Comparison of vmlinux size: a bit smaller.

w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ size vmlinux
text data bss dec hex filename
22665554 9709674 2920908 35296136 21a9388 vmlinux

w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ size vmlinux
text data bss dec hex filename
21499032 10102758 2920908 34522698 20ec64a vmlinux


Comparison of system performance: a bit drop (~6%).
This benchmark of kernel compilation is suggested by Ingo Molnar.
https://lkml.org/lkml/2018/5/2/74

Preparation: Set cpufreq to 'performance'.
for ((cpu=0; cpu<120; cpu++)); do
G=/sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor
[ -f $G ] && echo performance > $G
done

w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ perf stat --repeat 5 --null --pre '\
cp -a kernel ../kernel.copy.$(date +%s); \
rm -rf *; \
git checkout .; \
echo 1 > /proc/sys/vm/drop_caches; \
find ../kernel* -type f | xargs cat >/dev/null; \
make -j kernel >/dev/null; \
make clean >/dev/null 2>&1; \
sync '\
\
make -j8 >/dev/null

Performance counter stats for 'make -j8' (5 runs):

219.764246652 seconds time elapsed ( +- 0.78% )

w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ perf stat --repeat 5 --null --pre '\
cp -a kernel ../kernel.copy.$(date +%s); \
rm -rf *; \
git checkout .; \
echo 1 > /proc/sys/vm/drop_caches; \
find ../kernel* -type f | xargs cat >/dev/null; \
make -j kernel >/dev/null; \
make clean >/dev/null 2>&1; \
sync '\
\
make -j8 >/dev/null

Performance counter stats for 'make -j8' (5 runs):

233.574187771 seconds time elapsed ( +- 0.19% )

v4:
o Remove aready merged one "regulator: add dummy function of_find_regulator_by_node".

Changbin Du (4):
x86/mm: surround level4_kernel_pgt with #ifdef
CONFIG_X86_5LEVEL...#endif
kernel hacking: new config NO_AUTO_INLINE to disable compiler
auto-inline optimizations
kernel hacking: new config CC_OPTIMIZE_FOR_DEBUGGING to apply GCC -Og
optimization
asm-generic: fix build error in fix_to_virt with
CONFIG_CC_OPTIMIZE_FOR_DEBUGGING

Makefile | 10 ++++++++++
arch/arm/mm/mmu.c | 2 +-
arch/x86/include/asm/pgtable_64.h | 2 ++
arch/x86/kernel/head64.c | 13 ++++++-------
include/linux/compiler-gcc.h | 2 +-
include/linux/compiler.h | 2 +-
init/Kconfig | 19 +++++++++++++++++++
lib/Kconfig.debug | 17 +++++++++++++++++
8 files changed, 57 insertions(+), 10 deletions(-)

--
2.7.4



2018-05-09 08:57:25

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 3/4] kernel hacking: new config CC_OPTIMIZE_FOR_DEBUGGING to apply GCC -Og optimization

From: Changbin Du <[email protected]>

This will apply GCC '-Og' optimization level which is supported
since GCC 4.8. This optimization level offers a reasonable level
of optimization while maintaining fast compilation and a good
debugging experience. It is similar to '-O1' while perferring
to keep debug ability over runtime speed.

If enabling this option breaks your kernel, you should either
disable this or find a fix (mostly in the arch code). Currently
this option has only been tested on x86_64 and arm platform.

This option can satisfy people who was searching for a method
to disable compiler optimizations so to achieve better kernel
debugging experience with kgdb or qemu.

The main problem of '-Og' is we must not use __attribute__((error(msg))).
The compiler will report error though the call to error function
still can be optimize out. So we must fallback to array tricky.

Comparison of vmlinux size: a bit smaller.

w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ size vmlinux
text data bss dec hex filename
22665554 9709674 2920908 35296136 21a9388 vmlinux

w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ size vmlinux
text data bss dec hex filename
21499032 10102758 2920908 34522698 20ec64a vmlinux

Comparison of system performance: a bit drop (~6%).
This benchmark of kernel compilation is suggested by Ingo Molnar.
https://lkml.org/lkml/2018/5/2/74

Preparation: Set cpufreq to 'performance'.
for ((cpu=0; cpu<120; cpu++)); do
G=/sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor
[ -f $G ] && echo performance > $G
done

w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ perf stat --repeat 5 --null --pre '\
cp -a kernel ../kernel.copy.$(date +%s); \
rm -rf *; \
git checkout .; \
echo 1 > /proc/sys/vm/drop_caches; \
find ../kernel* -type f | xargs cat >/dev/null; \
make -j kernel >/dev/null; \
make clean >/dev/null 2>&1; \
sync '\
\
make -j8 >/dev/null

Performance counter stats for 'make -j8' (5 runs):

219.764246652 seconds time elapsed ( +- 0.78% )

w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
$ perf stat --repeat 5 --null --pre '\
cp -a kernel ../kernel.copy.$(date +%s); \
rm -rf *; \
git checkout .; \
echo 1 > /proc/sys/vm/drop_caches; \
find ../kernel* -type f | xargs cat >/dev/null; \
make -j kernel >/dev/null; \
make clean >/dev/null 2>&1; \
sync '\
\
make -j8 >/dev/null

Performance counter stats for 'make -j8' (5 runs):

233.574187771 seconds time elapsed ( +- 0.19% )

Signed-off-by: Changbin Du <[email protected]>

---
v3:
o Rename DEBUG_EXPERIENCE to CC_OPTIMIZE_FOR_DEBUGGING
o Move new configuration item to "General setup->Compiler optimization level"
v2:
o Improve performance benchmark as suggested by Ingo.
o Grammar updates in description. (Randy Dunlap)
---
Makefile | 4 ++++
include/linux/compiler-gcc.h | 2 +-
include/linux/compiler.h | 2 +-
init/Kconfig | 19 +++++++++++++++++++
4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6720c40..977418a 100644
--- a/Makefile
+++ b/Makefile
@@ -639,6 +639,9 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)

+ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUGGING
+KBUILD_CFLAGS += $(call cc-option, -Og)
+else
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += $(call cc-option,-Oz,-Os)
KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
@@ -649,6 +652,7 @@ else
KBUILD_CFLAGS += -O2
endif
endif
+endif

KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
$(call cc-disable-warning,maybe-uninitialized,))
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index b4bf73f..586ed11 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -192,7 +192,7 @@

#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)

-#ifndef __CHECKER__
+#if !defined(__CHECKER__) && !defined(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING)
# define __compiletime_warning(message) __attribute__((warning(message)))
# define __compiletime_error(message) __attribute__((error(message)))
#endif /* __CHECKER__ */
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index ab4711c..e97caf4 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -301,7 +301,7 @@ unsigned long read_word_at_a_time(const void *addr)
* sparse see a constant array size without breaking compiletime_assert on old
* versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
*/
-# ifndef __CHECKER__
+# if !defined(__CHECKER__) && !defined(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING)
# define __compiletime_error_fallback(condition) \
do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
# endif
diff --git a/init/Kconfig b/init/Kconfig
index f013afc..aa52535 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1036,6 +1036,25 @@ config CC_OPTIMIZE_FOR_SIZE

If unsure, say N.

+config CC_OPTIMIZE_FOR_DEBUGGING
+ bool "Optimize for better debugging experience (-Og)"
+ select NO_AUTO_INLINE
+ help
+ This will apply GCC '-Og' optimization level which is supported
+ since GCC 4.8. This optimization level offers a reasonable level
+ of optimization while maintaining fast compilation and a good
+ debugging experience. It is similar to '-O1' while preferring to
+ keep debug ability over runtime speed. The overall performance
+ will drop a bit (~6%).
+
+ Use only if you want to debug the kernel, especially if you want
+ to have better kernel debugging experience with gdb facilities
+ like kgdb or qemu. If enabling this option breaks your kernel,
+ you should either disable this or find a fix (mostly in the arch
+ code).
+
+ If unsure, select N.
+
endchoice

config SYSCTL
--
2.7.4


2018-05-09 08:58:09

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 4/4] asm-generic: fix build error in fix_to_virt with CONFIG_CC_OPTIMIZE_FOR_DEBUGGING

From: Changbin Du <[email protected]>

With '-Og' optimization level, GCC would not optimize a count for a loop
as a constant value. But BUILD_BUG_ON() only accept compile-time constant
values. Let's use __fix_to_virt() to avoid the error.

arch/arm/mm/mmu.o: In function `fix_to_virt':
/home/changbin/work/linux/./include/asm-generic/fixmap.h:31: undefined reference to `__compiletime_assert_31'
Makefile:1051: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

Signed-off-by: Changbin Du <[email protected]>

---
v2: use __fix_to_virt() to fix the issue.
---
arch/arm/mm/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index e46a6a4..c08d74e 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1599,7 +1599,7 @@ static void __init early_fixmap_shutdown(void)
pte_t *pte;
struct map_desc map;

- map.virtual = fix_to_virt(i);
+ map.virtual = __fix_to_virt(i);
pte = pte_offset_early_fixmap(pmd_off_k(map.virtual), map.virtual);

/* Only i/o device mappings are supported ATM */
--
2.7.4


2018-05-09 08:58:31

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 2/4] kernel hacking: new config NO_AUTO_INLINE to disable compiler auto-inline optimizations

From: Changbin Du <[email protected]>

This patch add a new kernel hacking option NO_AUTO_INLINE. Selecting
this option will prevent the compiler from optimizing the kernel by
auto-inlining functions not marked with the inline keyword.

With this option, only functions explicitly marked with "inline" will
be inlined. This will allow the function tracer to trace more functions
because it only traces functions that the compiler has not inlined.

Signed-off-by: Changbin Du <[email protected]>
Cc: Steven Rostedt <[email protected]>

---
v2: Some grammar updates from Steven.
---
Makefile | 6 ++++++
lib/Kconfig.debug | 17 +++++++++++++++++
2 files changed, 23 insertions(+)

diff --git a/Makefile b/Makefile
index d0d2652..6720c40 100644
--- a/Makefile
+++ b/Makefile
@@ -775,6 +775,12 @@ KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
$(call cc-option,-fno-var-tracking)
endif

+ifdef CONFIG_NO_AUTO_INLINE
+KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions) \
+ $(call cc-option, -fno-inline-small-functions) \
+ $(call cc-option, -fno-inline-functions-called-once)
+endif
+
ifdef CONFIG_FUNCTION_TRACER
ifndef CC_FLAGS_FTRACE
CC_FLAGS_FTRACE := -pg
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c40c7b7..da52243 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -198,6 +198,23 @@ config GDB_SCRIPTS
instance. See Documentation/dev-tools/gdb-kernel-debugging.rst
for further details.

+config NO_AUTO_INLINE
+ bool "Disable compiler auto-inline optimizations"
+ help
+ This will prevent the compiler from optimizing the kernel by
+ auto-inlining functions not marked with the inline keyword.
+ With this option, only functions explicitly marked with
+ "inline" will be inlined. This will allow the function tracer
+ to trace more functions because it only traces functions that
+ the compiler has not inlined.
+
+ Enabling this function can help debugging a kernel if using
+ the function tracer. But it can also change how the kernel
+ works, because inlining functions may change the timing,
+ which could make it difficult while debugging race conditions.
+
+ If unsure, select N.
+
config ENABLE_WARN_DEPRECATED
bool "Enable __deprecated logic"
default y
--
2.7.4


2018-05-09 08:58:50

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 1/4] x86/mm: surround level4_kernel_pgt with #ifdef CONFIG_X86_5LEVEL...#endif

From: Changbin Du <[email protected]>

The level4_kernel_pgt is only defined when X86_5LEVEL is enabled. So
surround level4_kernel_pgt with #ifdef CONFIG_X86_5LEVEL...#endif to
make code correct.

Signed-off-by: Changbin Du <[email protected]>
---
arch/x86/include/asm/pgtable_64.h | 2 ++
arch/x86/kernel/head64.c | 13 ++++++-------
2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 877bc27..9e7f667 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -15,7 +15,9 @@
#include <linux/bitops.h>
#include <linux/threads.h>

+#ifdef CONFIG_X86_5LEVEL
extern p4d_t level4_kernel_pgt[512];
+#endif
extern p4d_t level4_ident_pgt[512];
extern pud_t level3_kernel_pgt[512];
extern pud_t level3_ident_pgt[512];
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 0c408f8..775d7a6 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -143,16 +143,15 @@ unsigned long __head __startup_64(unsigned long physaddr,

pgd = fixup_pointer(&early_top_pgt, physaddr);
p = pgd + pgd_index(__START_KERNEL_map);
- if (la57)
- *p = (unsigned long)level4_kernel_pgt;
- else
- *p = (unsigned long)level3_kernel_pgt;
- *p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta;
-
+#ifdef CONFIG_X86_5LEVEL
if (la57) {
+ *p = (unsigned long)level4_kernel_pgt;
p4d = fixup_pointer(&level4_kernel_pgt, physaddr);
p4d[511] += load_delta;
- }
+ } else
+#endif
+ *p = (unsigned long)level3_kernel_pgt;
+ *p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta;

pud = fixup_pointer(&level3_kernel_pgt, physaddr);
pud[510] += load_delta;
--
2.7.4


2018-05-09 12:52:56

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH v4 4/4] asm-generic: fix build error in fix_to_virt with CONFIG_CC_OPTIMIZE_FOR_DEBUGGING

On Wed, 9 May 2018 16:43:16 +0800
[email protected] wrote:

> From: Changbin Du <[email protected]>
>
> With '-Og' optimization level, GCC would not optimize a count for a loop
> as a constant value. But BUILD_BUG_ON() only accept compile-time constant
> values. Let's use __fix_to_virt() to avoid the error.
>
> arch/arm/mm/mmu.o: In function `fix_to_virt':
> /home/changbin/work/linux/./include/asm-generic/fixmap.h:31: undefined reference to `__compiletime_assert_31'
> Makefile:1051: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1

Perhaps we should put this patch ahead of patch 3. Why allow it to
break?

Anyway, besides that, I think the series looks good.

For the series: Acked-by: Steven Rostedt (VMware) <[email protected]>

-- Steve


>
> Signed-off-by: Changbin Du <[email protected]>
>
> ---
> v2: use __fix_to_virt() to fix the issue.
> ---
> arch/arm/mm/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
> index e46a6a4..c08d74e 100644
> --- a/arch/arm/mm/mmu.c
> +++ b/arch/arm/mm/mmu.c
> @@ -1599,7 +1599,7 @@ static void __init early_fixmap_shutdown(void)
> pte_t *pte;
> struct map_desc map;
>
> - map.virtual = fix_to_virt(i);
> + map.virtual = __fix_to_virt(i);
> pte = pte_offset_early_fixmap(pmd_off_k(map.virtual), map.virtual);
>
> /* Only i/o device mappings are supported ATM */


2018-05-09 18:30:21

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 2/4] kernel hacking: new config NO_AUTO_INLINE to disable compiler auto-inline optimizations

Hi Changbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.17-rc4 next-20180509]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/changbin-du-intel-com/kernel-hacking-GCC-optimization-for-better-debug-experience-Og/20180509-213955
config: arm64-allmodconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

All warnings (new ones prefixed by >>):

>> WARNING: vmlinux.o(.text+0x6223c): Section mismatch in reference from the function init_subsystems() to the function .init.text:hyp_cpu_pm_init()
The function init_subsystems() references
the function __init hyp_cpu_pm_init().
This is often because init_subsystems lacks a __init
annotation or the annotation of hyp_cpu_pm_init is wrong.
--
>> WARNING: vmlinux.o(.text+0x62378): Section mismatch in reference from the function teardown_hyp_mode() to the function .init.text:hyp_cpu_pm_exit()
The function teardown_hyp_mode() references
the function __init hyp_cpu_pm_exit().
This is often because teardown_hyp_mode lacks a __init
annotation or the annotation of hyp_cpu_pm_exit is wrong.
--
>> WARNING: vmlinux.o(.text+0x968978): Section mismatch in reference from the function kirin_pcie_probe() to the function .init.text:kirin_add_pcie_port.isra.4()
The function kirin_pcie_probe() references
the function __init kirin_add_pcie_port.isra.4().
This is often because kirin_pcie_probe lacks a __init
annotation or the annotation of kirin_add_pcie_port.isra.4 is wrong.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (2.06 kB)
.config.gz (57.64 kB)
Download all attachments

2018-05-09 20:05:30

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 2/4] kernel hacking: new config NO_AUTO_INLINE to disable compiler auto-inline optimizations

Hi Changbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.17-rc4 next-20180509]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/changbin-du-intel-com/kernel-hacking-GCC-optimization-for-better-debug-experience-Og/20180509-213955
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386

All warnings (new ones prefixed by >>):

>> WARNING: vmlinux.o(.text.unlikely+0xce5): Section mismatch in reference from the function init_xstate_size() to the function .init.text:get_xsave_size()
The function init_xstate_size() references
the function __init get_xsave_size().
This is often because init_xstate_size lacks a __init
annotation or the annotation of get_xsave_size is wrong.
--
>> WARNING: vmlinux.o(.text.unlikely+0xcf7): Section mismatch in reference from the function init_xstate_size() to the function .init.text:get_xsaves_size()
The function init_xstate_size() references
the function __init get_xsaves_size().
This is often because init_xstate_size lacks a __init
annotation or the annotation of get_xsaves_size is wrong.
--
>> WARNING: vmlinux.o(.text.unlikely+0x22a6): Section mismatch in reference from the function percpu_setup_debug_store() to the function .init.text:cea_map_percpu_pages()
The function percpu_setup_debug_store() references
the function __init cea_map_percpu_pages().
This is often because percpu_setup_debug_store lacks a __init
annotation or the annotation of cea_map_percpu_pages is wrong.
--
>> WARNING: vmlinux.o(.text.unlikely+0x2564): Section mismatch in reference from the function can_free_region() to the function .init.text:e820__mapped_all()
The function can_free_region() references
the function __init e820__mapped_all().
This is often because can_free_region lacks a __init
annotation or the annotation of e820__mapped_all is wrong.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (2.29 kB)
.config.gz (61.47 kB)
Download all attachments

2018-05-10 12:41:35

by Du, Changbin

[permalink] [raw]
Subject: Re: [PATCH v4 4/4] asm-generic: fix build error in fix_to_virt with CONFIG_CC_OPTIMIZE_FOR_DEBUGGING

On Wed, May 09, 2018 at 08:52:24AM -0400, Steven Rostedt wrote:
> On Wed, 9 May 2018 16:43:16 +0800
> [email protected] wrote:
>
> > From: Changbin Du <[email protected]>
> >
> > With '-Og' optimization level, GCC would not optimize a count for a loop
> > as a constant value. But BUILD_BUG_ON() only accept compile-time constant
> > values. Let's use __fix_to_virt() to avoid the error.
> >
> > arch/arm/mm/mmu.o: In function `fix_to_virt':
> > /home/changbin/work/linux/./include/asm-generic/fixmap.h:31: undefined reference to `__compiletime_assert_31'
> > Makefile:1051: recipe for target 'vmlinux' failed
> > make: *** [vmlinux] Error 1
>
> Perhaps we should put this patch ahead of patch 3. Why allow it to
> break?
>
Agree, let me exchange the last two patches.

> Anyway, besides that, I think the series looks good.
>
> For the series: Acked-by: Steven Rostedt (VMware) <[email protected]>
>
> -- Steve
>
>
> >
> > Signed-off-by: Changbin Du <[email protected]>
> >
> > ---
> > v2: use __fix_to_virt() to fix the issue.
> > ---
> > arch/arm/mm/mmu.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
> > index e46a6a4..c08d74e 100644
> > --- a/arch/arm/mm/mmu.c
> > +++ b/arch/arm/mm/mmu.c
> > @@ -1599,7 +1599,7 @@ static void __init early_fixmap_shutdown(void)
> > pte_t *pte;
> > struct map_desc map;
> >
> > - map.virtual = fix_to_virt(i);
> > + map.virtual = __fix_to_virt(i);
> > pte = pte_offset_early_fixmap(pmd_off_k(map.virtual), map.virtual);
> >
> > /* Only i/o device mappings are supported ATM */
>

--
Thanks,
Changbin Du

2018-05-10 21:01:23

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 3/4] kernel hacking: new config CC_OPTIMIZE_FOR_DEBUGGING to apply GCC -Og optimization

Hi Changbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.17-rc4 next-20180510]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/changbin-du-intel-com/kernel-hacking-GCC-optimization-for-better-debug-experience-Og/20180509-213955
config: x86_64-randconfig-s1-05100951 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_freq':
>> drivers//net/wireless/zydas/zd1201.c:939:10: warning: 'channel' may be used uninitialized in this function [-Wmaybe-uninitialized]
freq->m = channel;
~~~~~~~~^~~~~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_mode':
>> drivers//net/wireless/zydas/zd1201.c:1016:2: warning: 'porttype' may be used uninitialized in this function [-Wmaybe-uninitialized]
switch(porttype) {
^~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_rate':
>> drivers//net/wireless/zydas/zd1201.c:1282:2: warning: 'rate' may be used uninitialized in this function [-Wmaybe-uninitialized]
switch(rate) {
^~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_rts':
>> drivers//net/wireless/zydas/zd1201.c:1334:13: warning: 'rtst' may be used uninitialized in this function [-Wmaybe-uninitialized]
rts->value = rtst;
~~~~~~~~~~~^~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_frag':
>> drivers//net/wireless/zydas/zd1201.c:1372:14: warning: 'fragt' may be used uninitialized in this function [-Wmaybe-uninitialized]
frag->value = fragt;
~~~~~~~~~~~~^~~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_set_power':
>> drivers//net/wireless/zydas/zd1201.c:1503:28: warning: 'duration' may be used uninitialized in this function [-Wmaybe-uninitialized]
level = vwrq->value * 4 / duration;
~~~~~~~~~~~~~~~~^~~~~~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_power':
drivers//net/wireless/zydas/zd1201.c:1542:27: warning: 'duration' may be used uninitialized in this function [-Wmaybe-uninitialized]
vwrq->value = duration * level / 4;
~~~~~~~~~^~~~~~~
>> drivers//net/wireless/zydas/zd1201.c:1547:15: warning: 'level' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (enabled && level)
~~~~~~~~^~~~~~~~
>> drivers//net/wireless/zydas/zd1201.c:1547:6: warning: 'enabled' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (enabled && level)
^
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_hostauth':
>> drivers//net/wireless/zydas/zd1201.c:1631:13: warning: 'hostauth' may be used uninitialized in this function [-Wmaybe-uninitialized]
rrq->value = hostauth;
~~~~~~~~~~~^~~~~~~~~~
drivers//net/wireless/zydas/zd1201.c: In function 'zd1201_get_maxassoc':
>> drivers//net/wireless/zydas/zd1201.c:1681:13: warning: 'maxassoc' may be used uninitialized in this function [-Wmaybe-uninitialized]
rrq->value = maxassoc;
~~~~~~~~~~~^~~~~~~~~~
--
drivers/rtc/rtc-da9052.c: In function 'da9052_read_alarm':
>> drivers/rtc/rtc-da9052.c:25:3: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
^~~~~~~
In file included from drivers/rtc/rtc-da9052.c:21:0:
include/linux/mfd/da9052/da9052.h:157:6: note: 'ret' was declared here
int ret;
^~~
>> drivers/rtc/rtc-da9052.c:25:3: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
^~~~~~~
In file included from drivers/rtc/rtc-da9052.c:21:0:
include/linux/mfd/da9052/da9052.h:157:6: note: 'ret' was declared here
int ret;
^~~
drivers/rtc/rtc-da9052.c: In function 'da9052_rtc_read_time':
>> drivers/rtc/rtc-da9052.c:25:3: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
^~~~~~~
In file included from drivers/rtc/rtc-da9052.c:21:0:
include/linux/mfd/da9052/da9052.h:157:6: note: 'ret' was declared here
int ret;
^~~
>> drivers/rtc/rtc-da9052.c:25:3: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
^~~~~~~
In file included from drivers/rtc/rtc-da9052.c:21:0:
include/linux/mfd/da9052/da9052.h:157:6: note: 'ret' was declared here
int ret;
^~~
--
net/bluetooth/mgmt.c: In function 'read_local_oob_ext_data_complete':
>> net/bluetooth/mgmt.c:5669:27: warning: 'r256' may be used uninitialized in this function [-Wmaybe-uninitialized]
u8 *h192, *r192, *h256, *r256;
^~~~
--
In file included from drivers//net/wireless/zydas/zd1211rw/zd_usb.c:28:0:
drivers//net/wireless/zydas/zd1211rw/zd_usb.c: In function 'eject_installer':
>> include/linux/usb.h:1922:23: warning: 'bulk_out_ep' may be used uninitialized in this function [-Wmaybe-uninitialized]
((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
^~~~~~~~~~~~~
drivers//net/wireless/zydas/zd1211rw/zd_usb.c:1278:5: note: 'bulk_out_ep' was declared here
u8 bulk_out_ep;
^~~~~~~~~~~
--
drivers/slimbus/messaging.c: In function 'slim_do_transfer':
>> drivers/slimbus/messaging.c:126:4: warning: 'tid' may be used uninitialized in this function [-Wmaybe-uninitialized]
idr_remove(&ctrl->tid_idr, tid);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
drivers//staging/comedi/drivers/serial2002.c: In function 'serial2002_setup_subdevs':
>> drivers//staging/comedi/drivers/serial2002.c:497:7: warning: 'cfg' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (serial2002_setup_subdevice(s, cfg, range, mapping, kind))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from drivers/net/wireless/zydas/zd1211rw/zd_usb.c:28:0:
drivers/net/wireless/zydas/zd1211rw/zd_usb.c: In function 'eject_installer':
>> include/linux/usb.h:1922:23: warning: 'bulk_out_ep' may be used uninitialized in this function [-Wmaybe-uninitialized]
((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
^~~~~~~~~~~~~
drivers/net/wireless/zydas/zd1211rw/zd_usb.c:1278:5: note: 'bulk_out_ep' was declared here
u8 bulk_out_ep;
^~~~~~~~~~~
--
drivers//regulator/max8925-regulator.c: In function 'max8925_regulator_probe':
>> drivers//regulator/max8925-regulator.c:315:3: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
dev_err(&pdev->dev, "failed to register regulator %s\n",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ri->desc.name);
~~~~~~~~~~~~~~
--
drivers//bcma/sprom.c: In function 'bcma_sprom_get':
>> drivers//bcma/sprom.c:642:3: warning: 'sprom' may be used uninitialized in this function [-Wmaybe-uninitialized]
kfree(sprom);
^~~~~~~~~~~~
--
drivers//block/rbd.c: In function 'rbd_v2_snap_id_by_name':
>> drivers//block/rbd.c:4797:25: warning: 'snap_id' may be used uninitialized in this function [-Wmaybe-uninitialized]
return found ? snap_id : CEPH_NOSNAP;

drivers//block/rbd.c: In function 'rbd_dev_image_id':
>> drivers//block/rbd.c:5349:27: warning: 'image_id' may be used uninitialized in this function [-Wmaybe-uninitialized]
rbd_dev->spec->image_id = image_id;
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
--
drivers//firmware/qemu_fw_cfg.c: In function 'fw_cfg_build_symlink':
>> drivers//firmware/qemu_fw_cfg.c:557:9: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
return ret;
^~~
..

vim +/seq +33 include/linux/compiler.h

1f0d69a9 Steven Rostedt 2008-11-12 22
d45ae1f7 Steven Rostedt (VMware 2017-01-17 23) #define __branch_check__(x, expect, is_constant) ({ \
1f0d69a9 Steven Rostedt 2008-11-12 24 int ______r; \
134e6a03 Steven Rostedt (VMware 2017-01-19 25) static struct ftrace_likely_data \
1f0d69a9 Steven Rostedt 2008-11-12 26 __attribute__((__aligned__(4))) \
45b79749 Steven Rostedt 2008-11-21 27 __attribute__((section("_ftrace_annotated_branch"))) \
1f0d69a9 Steven Rostedt 2008-11-12 28 ______f = { \
134e6a03 Steven Rostedt (VMware 2017-01-19 29) .data.func = __func__, \
134e6a03 Steven Rostedt (VMware 2017-01-19 30) .data.file = __FILE__, \
134e6a03 Steven Rostedt (VMware 2017-01-19 31) .data.line = __LINE__, \
1f0d69a9 Steven Rostedt 2008-11-12 32 }; \
d45ae1f7 Steven Rostedt (VMware 2017-01-17 @33) ______r = __builtin_expect(!!(x), expect); \
d45ae1f7 Steven Rostedt (VMware 2017-01-17 34) ftrace_likely_update(&______f, ______r, \
d45ae1f7 Steven Rostedt (VMware 2017-01-17 35) expect, is_constant); \
1f0d69a9 Steven Rostedt 2008-11-12 36 ______r; \
1f0d69a9 Steven Rostedt 2008-11-12 37 })
1f0d69a9 Steven Rostedt 2008-11-12 38

:::::: The code at line 33 was first introduced by commit
:::::: d45ae1f7041ac52ade6c5ec76d96bbed765d67aa tracing: Process constants for (un)likely() profiler

:::::: TO: Steven Rostedt (VMware) <[email protected]>
:::::: CC: Steven Rostedt (VMware) <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (10.08 kB)
.config.gz (35.08 kB)
Download all attachments

2018-05-11 03:20:19

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 3/4] kernel hacking: new config CC_OPTIMIZE_FOR_DEBUGGING to apply GCC -Og optimization

Hi Changbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.17-rc4 next-20180510]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/changbin-du-intel-com/kernel-hacking-GCC-optimization-for-better-debug-experience-Og/20180509-213955
config: x86_64-randconfig-s1-05100951 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

lib/test_firmware.c: In function 'trigger_batched_requests_async_store':
>> lib/test_firmware.c:779:31: warning: 'rc' may be used uninitialized in this function [-Wmaybe-uninitialized]
test_fw_config->test_result = rc;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
--
kernel/futex.c: In function 'futex_atomic_op_inuser':
>> kernel/futex.c:1604:17: warning: 'oldval' may be used uninitialized in this function [-Wmaybe-uninitialized]
return oldval > cmparg;
~~~~~~~^~~~~~~~
--
kernel/kexec_file.c: In function 'kexec_apply_relocations':
>> kernel/kexec_file.c:896:6: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (ret)
^
--
mm/swap_state.c: In function '__add_to_swap_cache':
>> mm/swap_state.c:156:9: warning: 'error' may be used uninitialized in this function [-Wmaybe-uninitialized]
return error;
^~~~~
--
mm/swapfile.c: In function 'setup_swap_map_and_extents':
>> mm/swapfile.c:3061:10: warning: 'nr_extents' may be used uninitialized in this function [-Wmaybe-uninitialized]
return nr_extents;
^~~~~~~~~~
--
mm/ksm.c: In function 'stable_node_dup':
>> mm/ksm.c:1365:15: warning: 'found_rmap_hlist_len' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (!found ||
~~~~~~~^~
dup->rmap_hlist_len > found_rmap_hlist_len) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
mm/huge_memory.c: In function 'do_huge_pmd_wp_page':
>> mm/huge_memory.c:1318:15: warning: 'huge_gfp' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (unlikely(mem_cgroup_try_charge(new_page, vma->vm_mm,
^~~~~~~~~~~~~~~~~~~~~
--
fs/splice.c: In function 'iter_file_splice_write':
>> fs/splice.c:694:10: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
ssize_t ret;
^~~
--
In file included from include/asm-generic/bug.h:5:0,
from arch/x86/include/asm/bug.h:83,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/gfp.h:5,
from include/linux/slab.h:15,
from ipc/sem.c:73:
ipc/sem.c: In function 'find_alloc_undo':
>> include/linux/compiler.h:215:31: warning: 'ulp' may be used uninitialized in this function [-Wmaybe-uninitialized]
case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
ipc/sem.c:1843:24: note: 'ulp' was declared here
struct sem_undo_list *ulp;
^~~
--
block/blk-merge.c: In function '__blk_recalc_rq_segments':
>> block/blk-merge.c:284:21: warning: 'bbio' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (seg_size > bbio->bi_seg_back_size)
~~~~^~~~~~~~~~~~~~~~~~

vim +/ulp +215 include/linux/compiler.h

230fa253 Christian Borntraeger 2014-11-25 208
43239cbe Christian Borntraeger 2015-01-13 209 static __always_inline void __write_once_size(volatile void *p, void *res, int size)
230fa253 Christian Borntraeger 2014-11-25 210 {
230fa253 Christian Borntraeger 2014-11-25 211 switch (size) {
230fa253 Christian Borntraeger 2014-11-25 212 case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
230fa253 Christian Borntraeger 2014-11-25 213 case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
230fa253 Christian Borntraeger 2014-11-25 214 case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
230fa253 Christian Borntraeger 2014-11-25 @215 case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
230fa253 Christian Borntraeger 2014-11-25 216 default:
230fa253 Christian Borntraeger 2014-11-25 217 barrier();
230fa253 Christian Borntraeger 2014-11-25 218 __builtin_memcpy((void *)p, (const void *)res, size);
230fa253 Christian Borntraeger 2014-11-25 219 barrier();
230fa253 Christian Borntraeger 2014-11-25 220 }
230fa253 Christian Borntraeger 2014-11-25 221 }
230fa253 Christian Borntraeger 2014-11-25 222

:::::: The code at line 215 was first introduced by commit
:::::: 230fa253df6352af12ad0a16128760b5cb3f92df kernel: Provide READ_ONCE and ASSIGN_ONCE

:::::: TO: Christian Borntraeger <[email protected]>
:::::: CC: Christian Borntraeger <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (5.31 kB)
.config.gz (35.08 kB)
Download all attachments