2020-06-28 01:54:43

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

CFLAGS_REMOVE_<file>.o works per object, that is, there is no
convenient way to filter out flags for every object in a directory.

Add ccflags-remove-y and asflags-remove-y to make it easily.

Use ccflags-remove-y to clean up some Makefiles.

Suggested-by: Sami Tolvanen <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
---

arch/arm/boot/compressed/Makefile | 6 +-----
arch/powerpc/xmon/Makefile | 3 +--
arch/sh/boot/compressed/Makefile | 5 +----
kernel/trace/Makefile | 4 ++--
lib/Makefile | 5 +----
scripts/Makefile.lib | 4 ++--
6 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 00602a6fba04..3d5691b23951 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -103,13 +103,9 @@ clean-files += piggy_data lib1funcs.S ashldi3.S bswapsdi2.S hyp-stub.S

KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING

-ifeq ($(CONFIG_FUNCTION_TRACER),y)
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
-endif
-
ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin \
-I$(obj) $(DISABLE_ARM_SSP_PER_TASK_PLUGIN)
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += -pg
asflags-y := -DZIMAGE

# Supply kernel BSS size to the decompressor via a linker symbol.
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index 89c76ca35640..55cbcdd88ac0 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
KASAN_SANITIZE := n

# Disable ftrace for the entire directory
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
+ccflags-remove-y += $(CC_FLAGS_FTRACE)

ifdef CONFIG_CC_IS_CLANG
# clang stores addresses on the stack causing the frame size to blow
diff --git a/arch/sh/boot/compressed/Makefile b/arch/sh/boot/compressed/Makefile
index ad0e2403e56f..589d2d8a573d 100644
--- a/arch/sh/boot/compressed/Makefile
+++ b/arch/sh/boot/compressed/Makefile
@@ -28,10 +28,7 @@ IMAGE_OFFSET := $(shell /bin/bash -c 'printf "0x%08x" \
$(CONFIG_BOOT_LINK_OFFSET)]')
endif

-ifeq ($(CONFIG_MCOUNT),y)
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_MCOUNT) += -pg

LDFLAGS_vmlinux := --oformat $(ld-bfd) -Ttext $(IMAGE_OFFSET) -e startup \
-T $(obj)/../../kernel/vmlinux.lds
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 6575bb0a0434..7492844a8b1b 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -2,9 +2,9 @@

# Do not instrument the tracer itself:

+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
+
ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))

# Avoid recursion due to instrumentation.
KCSAN_SANITIZE := n
diff --git a/lib/Makefile b/lib/Makefile
index b1c42c10073b..b2ed4beddd68 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -3,10 +3,7 @@
# Makefile for some libs needed in the kernel.
#

-ifdef CONFIG_FUNCTION_TRACER
-ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
-endif
+ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

# These files are disabled because they produce lots of non-interesting and/or
# flaky coverage that is not a function of syscall inputs. For example,
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 99ac59c59826..5da420f13f9b 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -113,10 +113,10 @@ modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))

orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(target-stem).o)
-_c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
+_c_flags = $(filter-out $(ccflags-remove-y) $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
$(asflags-y) $(AFLAGS_$(target-stem).o)
-_a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
+_a_flags = $(filter-out $(asflags-remove-y) $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)

#
--
2.25.1


2020-06-28 19:10:27

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

On Sun, 28 Jun 2020 10:50:41 +0900
Masahiro Yamada <[email protected]> wrote:

> CFLAGS_REMOVE_<file>.o works per object, that is, there is no
> convenient way to filter out flags for every object in a directory.
>
> Add ccflags-remove-y and asflags-remove-y to make it easily.
>
> Use ccflags-remove-y to clean up some Makefiles.
>
> Suggested-by: Sami Tolvanen <[email protected]>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---

Nice feature!

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

-- Steve

2020-06-29 19:19:30

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

Masahiro Yamada <[email protected]> writes:
> CFLAGS_REMOVE_<file>.o works per object, that is, there is no
> convenient way to filter out flags for every object in a directory.
>
> Add ccflags-remove-y and asflags-remove-y to make it easily.
>
> Use ccflags-remove-y to clean up some Makefiles.
>
> Suggested-by: Sami Tolvanen <[email protected]>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> arch/arm/boot/compressed/Makefile | 6 +-----
> arch/powerpc/xmon/Makefile | 3 +--
> arch/sh/boot/compressed/Makefile | 5 +----
> kernel/trace/Makefile | 4 ++--
> lib/Makefile | 5 +----
> scripts/Makefile.lib | 4 ++--
> 6 files changed, 8 insertions(+), 19 deletions(-)
>
> diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
> index 89c76ca35640..55cbcdd88ac0 100644
> --- a/arch/powerpc/xmon/Makefile
> +++ b/arch/powerpc/xmon/Makefile
> @@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
> KASAN_SANITIZE := n
>
> # Disable ftrace for the entire directory
> -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> +ccflags-remove-y += $(CC_FLAGS_FTRACE)

This could be:

ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

Similar to kernel/trace/Makefile below.

I don't mind though.

Acked-by: Michael Ellerman <[email protected]> (powerpc)

cheers

> diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> index 6575bb0a0434..7492844a8b1b 100644
> --- a/kernel/trace/Makefile
> +++ b/kernel/trace/Makefile
> @@ -2,9 +2,9 @@
>
> # Do not instrument the tracer itself:
>
> +ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> +
> ifdef CONFIG_FUNCTION_TRACER
> -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
>
> # Avoid recursion due to instrumentation.
> KCSAN_SANITIZE := n

2020-06-30 02:10:50

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

On Mon, Jun 29, 2020 at 2:55 PM Michael Ellerman <[email protected]> wrote:
>
> Masahiro Yamada <[email protected]> writes:
> > CFLAGS_REMOVE_<file>.o works per object, that is, there is no
> > convenient way to filter out flags for every object in a directory.
> >
> > Add ccflags-remove-y and asflags-remove-y to make it easily.
> >
> > Use ccflags-remove-y to clean up some Makefiles.
> >
> > Suggested-by: Sami Tolvanen <[email protected]>
> > Signed-off-by: Masahiro Yamada <[email protected]>
> > ---
> >
> > arch/arm/boot/compressed/Makefile | 6 +-----
> > arch/powerpc/xmon/Makefile | 3 +--
> > arch/sh/boot/compressed/Makefile | 5 +----
> > kernel/trace/Makefile | 4 ++--
> > lib/Makefile | 5 +----
> > scripts/Makefile.lib | 4 ++--
> > 6 files changed, 8 insertions(+), 19 deletions(-)
> >
> > diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
> > index 89c76ca35640..55cbcdd88ac0 100644
> > --- a/arch/powerpc/xmon/Makefile
> > +++ b/arch/powerpc/xmon/Makefile
> > @@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
> > KASAN_SANITIZE := n
> >
> > # Disable ftrace for the entire directory
> > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> > +ccflags-remove-y += $(CC_FLAGS_FTRACE)
>
> This could be:
>
> ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
>
> Similar to kernel/trace/Makefile below.


I fixed it up, and applied to linux-kbuild.
Thanks.


> I don't mind though.
>
> Acked-by: Michael Ellerman <[email protected]> (powerpc)
>
> cheers
>
> > diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> > index 6575bb0a0434..7492844a8b1b 100644
> > --- a/kernel/trace/Makefile
> > +++ b/kernel/trace/Makefile
> > @@ -2,9 +2,9 @@
> >
> > # Do not instrument the tracer itself:
> >
> > +ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> > +
> > ifdef CONFIG_FUNCTION_TRACER
> > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> >
> > # Avoid recursion due to instrumentation.
> > KCSAN_SANITIZE := n



--
Best Regards
Masahiro Yamada

2020-07-05 08:00:47

by kernel test robot

[permalink] [raw]
Subject: [kbuild] fbb020c0d4: WARNING:at_kernel/trace/trace.c:#run_tracer_selftest

Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: fbb020c0d412f42903b1926d75dabba3e6ab00cc ("[PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y")
url: https://github.com/0day-ci/linux/commits/Masahiro-Yamada/kbuild-introduce-ccflags-remove-y-and-asflags-remove-y/20200628-095456
base: https://git.kernel.org/cgit/linux/kernel/git/masahiroy/linux-kbuild.git for-next

in testcase: boot

on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


+-----------------------------------------------------------------+------------+------------+
| | 027ab64bdf | fbb020c0d4 |
+-----------------------------------------------------------------+------------+------------+
| boot_successes | 38 | 0 |
| boot_failures | 1 | 32 |
| WARNING:at_kernel/rcu/rcutorture.c:#rcutorture_oom_notify | 1 | |
| RIP:rcutorture_oom_notify | 1 | |
| canonical_address#:#[##] | 1 | |
| RIP:rcu_torture_fwd_cb_hist | 1 | |
| Kernel_panic-not_syncing:Fatal_exception | 1 | |
| WARNING:at_kernel/trace/trace.c:#run_tracer_selftest | 0 | 31 |
| RIP:run_tracer_selftest | 0 | 31 |
| WARNING:at_kernel/trace/trace.c:#init_trace_selftests | 0 | 31 |
| RIP:init_trace_selftests | 0 | 31 |
| WARNING:at_kernel/trace/ftrace.c:#ftrace_init_array_ops | 0 | 31 |
| RIP:ftrace_init_array_ops | 0 | 31 |
| BUG:kernel_hang_in_boot_stage | 0 | 5 |
| IP-Config:Auto-configuration_of_network_failed | 0 | 27 |
| WARNING:stack_going_in_the_wrong_direction?at_kernfs_add_one/0x | 0 | 1 |
| WARNING:stack_going_in_the_wrong_direction?at_wake_up_q/0x | 0 | 2 |
+-----------------------------------------------------------------+------------+------------+


If you fix the issue, kindly add following tag
Reported-by: kernel test robot <[email protected]>


[ 7.077846] WARNING: CPU: 1 PID: 1 at kernel/trace/trace.c:1814 run_tracer_selftest+0x23d/0x2f8
[ 7.077856] Modules linked in:
[ 7.077883] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.8.0-rc2-00003-gfbb020c0d412f #1
[ 7.077895] RIP: 0010:run_tracer_selftest+0x23d/0x2f8
[ 7.077909] Code: 11 01 4c 89 2d b1 08 d3 01 41 89 c4 85 c0 74 33 48 c7 c7 60 0b 6d 82 48 ff 05 7c 67 d2 02 e8 ae 0a f1 ff 48 ff 05 80 67 d2 02 <0f> 0b 48 ff 05 7f 67 d2 02 48 ff 05 80 67 d2 02 41 83 cc ff e9 98
[ 7.077919] RSP: 0000:ffffc9000001fdb8 EFLAGS: 00010202
[ 7.078092] RAX: 0000000000000007 RBX: ffffffff834802c0 RCX: 0000000000000000
[ 7.078105] RDX: 0000000000000000 RSI: 0000000000000004 RDI: fffff52000003fae
[ 7.078116] RBP: ffffffff83480362 R08: 0000000000000007 R09: 0000000000000000
[ 7.078127] R10: ffffed1020fbf6a1 R11: ffff888107dfb507 R12: 00000000ffffffff
[ 7.078140] R13: ffffffff8349a1e0 R14: 0000000000000000 R15: ffffffff83968070
[ 7.078153] FS: 0000000000000000(0000) GS:ffff8883a2300000(0000) knlGS:0000000000000000
[ 7.078165] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 7.078178] CR2: 00000000000b2001 CR3: 0000000002e14000 CR4: 00000000000406a0
[ 7.078191] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 7.078202] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 7.078212] Call Trace:
[ 7.078223] init_trace_selftests+0xf4/0x274
[ 7.078235] ? latency_fsnotify_init+0x54/0x54
[ 7.078247] do_one_initcall+0x150/0x309
[ 7.078260] ? rcu_lock_acquire+0x22/0x22
[ 7.078271] ? add_sysfs_param+0x6a0/0x6b6
[ 7.078271] ? __kasan_kmalloc+0x83/0x94
[ 7.078271] ? test_bit+0x23/0x2e
[ 7.078271] kernel_init_freeable+0x34e/0x3d0
[ 7.078271] ? rest_init+0x122/0x122
[ 7.078271] kernel_init+0xd/0x116
[ 7.078271] ret_from_fork+0x22/0x30
[ 7.078271] ---[ end trace b31ab4834bc3402a ]---


To reproduce:

# build kernel
cd linux
cp config-5.8.0-rc2-00003-gfbb020c0d412f .config
make HOSTCC=gcc-9 CC=gcc-9 ARCH=x86_64 olddefconfig prepare modules_prepare bzImage

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp qemu -k <bzImage> job-script # job-script is attached in this email



Thanks,
lkp


Attachments:
(No filename) (4.92 kB)
config-5.8.0-rc2-00003-gfbb020c0d412f (152.56 kB)
job-script (4.92 kB)
dmesg.xz (15.82 kB)
Download all attachments

2020-07-06 11:24:55

by Anders Roxell

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

Hi,

When I built an allmodconfig kernel for arm64, and boot that in qemu
guest I see the following issues:

[...]
[ 10.451561][ T1] Testing tracer function: PASSED
[ 33.087895][ T1] Testing dynamic ftrace: .. filter did not
filter .. FAILED!
[ 51.127094][ T1] ------------[ cut here ]------------
[ 51.132387][ T1] WARNING: CPU: 0 PID: 1 at
kernel/trace/trace.c:1814 run_tracer_selftest+0x314/0x40c
[ 51.140805][ T1] Modules linked in:
[ 51.145398][ T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
5.8.0-rc3-next-20200703-00004-g8cd4bc531754 #1
[ 51.154146][ T1] Hardware name: linux,dummy-virt (DT)
[ 51.159536][ T1] pstate: 80400005 (Nzcv daif +PAN -UAO BTYPE=--)
[ 51.165711][ T1] pc : run_tracer_selftest+0x314/0x40c
[ 51.171167][ T1] lr : run_tracer_selftest+0x308/0x40c
[ 51.176475][ T1] sp : ffff000069c07c40
[ 51.180855][ T1] x29: ffff000069c07c40 x28: ffffa00015e80320
[ 51.187187][ T1] x27: ffffa00013e074a0 x26: ffffa000150f22ee
[ 51.193520][ T1] x25: ffffa000125b35a0 x24: ffffa00013f6a000
[ 51.199868][ T1] x23: ffffa00013f6adc0 x22: 00000000ffffffff
[ 51.206225][ T1] x21: ffffa000150f2250 x20: ffffa00015e801c0
[ 51.212582][ T1] x19: ffffa00015e7fa80 x18: 0000000000002750
[ 51.218887][ T1] x17: 00000000000014c0 x16: 00000000000016f0
[ 51.225229][ T1] x15: 00000000000014f8 x14: ffffa0001000a3c8
[ 51.231584][ T1] x13: ffffa000124a5fb8 x12: ffff80000d494822
[ 51.237935][ T1] x11: 1fffe0000d494821 x10: ffff80000d494821
[ 51.244293][ T1] x9 : ffffa000101763b0 x8 : ffff000069c077d7
[ 51.250704][ T1] x7 : 0000000000000001 x6 : ffff000069c077d0
[ 51.257060][ T1] x5 : ffff00006a7fc040 x4 : 0000000000000000
[ 51.263423][ T1] x3 : ffffa00010211118 x2 : 8af0509000018b00
[ 51.269757][ T1] x1 : 0000000000000000 x0 : 0000000000000001
[ 51.276084][ T1] Call trace:
[ 51.279934][ T1] run_tracer_selftest+0x314/0x40c
[ 51.285174][ T1] init_trace_selftests+0x110/0x31c
[ 51.290391][ T1] do_one_initcall+0x410/0x960
[ 51.295315][ T1] kernel_init_freeable+0x430/0x4f0
[ 51.300595][ T1] kernel_init+0x20/0x1d8
[ 51.305180][ T1] ret_from_fork+0x10/0x18
[ 51.309741][ T1] irq event stamp: 1401832
[ 51.314399][ T1] hardirqs last enabled at (1401831):
[<ffffa0001020d10c>] console_unlock+0xc04/0xd10
[ 51.322973][ T1] hardirqs last disabled at (1401832):
[<ffffa00010050fe4>] debug_exception_enter+0xbc/0x200
[ 51.331993][ T1] softirqs last enabled at (1401828):
[<ffffa000100023a4>] __do_softirq+0x95c/0x9f8
[ 51.340490][ T1] softirqs last disabled at (1401821):
[<ffffa0001010f7d0>] irq_exit+0x118/0x198
[ 51.348717][ T1] _warn_unseeded_randomness: 5 callbacks suppressed
[ 51.349263][ T1] random: get_random_bytes called from
print_oops_end_marker+0x48/0x80 with crng_init=0
[ 51.350502][ T1] ---[ end trace c566e8a71c933d3c ]---
[...]
[40709.672335][ C0] pool 2: cpus=0 flags=0x5 nice=0 hung=3s
workers=3 manager: 1455
[40739.960593][ T26] INFO: lockdep is turned off.
[40775.312499][ T26] Kernel panic - not syncing: hung_task: blocked tasks
[40775.341521][ T26] CPU: 0 PID: 26 Comm: khungtaskd Tainted: G
W 5.8.0-rc3-next-20200703-00004-g8cd4bc531754 #1
[40775.352848][ T26] Hardware name: linux,dummy-virt (DT)
[40775.359304][ T26] Call trace:
[40775.364148][ T26] dump_backtrace+0x0/0x418
[40775.369918][ T26] show_stack+0x34/0x48
[40775.375468][ T26] dump_stack+0x1f4/0x2b0
[40775.381136][ T26] panic+0x2dc/0x6ec
[40775.386430][ T26] watchdog+0x1400/0x1460
[40775.392103][ T26] kthread+0x23c/0x250
[40775.397548][ T26] ret_from_fork+0x10/0x18
[40775.407039][ T26] Kernel Offset: disabled
[40775.412634][ T26] CPU features: 0x240002,20002004
[40775.418751][ T26] Memory Limit: none
[40775.425823][ T26] ---[ end Kernel panic - not syncing: hung_task:
blocked tasks ]---

The full log can be found here [1].

Without this patch for 'trace_selftest_dynamic' for instance, CC_FLAGS_FTRACE
was removed from kernel/trace/*, and then added back to
kernel/trace/trace_selftest_dynamic.
While with this patch it looks like we add the flag (even though it is
already there), and then
removes the flag for all files in kernel/trace/* .

Cheers,
Anders
[1] https://people.linaro.org/~anders.roxell/output-next-20200703.log

On Tue, 30 Jun 2020 at 04:09, Masahiro Yamada <[email protected]> wrote:
>
> On Mon, Jun 29, 2020 at 2:55 PM Michael Ellerman <[email protected]> wrote:
> >
> > Masahiro Yamada <[email protected]> writes:
> > > CFLAGS_REMOVE_<file>.o works per object, that is, there is no
> > > convenient way to filter out flags for every object in a directory.
> > >
> > > Add ccflags-remove-y and asflags-remove-y to make it easily.
> > >
> > > Use ccflags-remove-y to clean up some Makefiles.
> > >
> > > Suggested-by: Sami Tolvanen <[email protected]>
> > > Signed-off-by: Masahiro Yamada <[email protected]>
> > > ---
> > >
> > > arch/arm/boot/compressed/Makefile | 6 +-----
> > > arch/powerpc/xmon/Makefile | 3 +--
> > > arch/sh/boot/compressed/Makefile | 5 +----
> > > kernel/trace/Makefile | 4 ++--
> > > lib/Makefile | 5 +----
> > > scripts/Makefile.lib | 4 ++--
> > > 6 files changed, 8 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
> > > index 89c76ca35640..55cbcdd88ac0 100644
> > > --- a/arch/powerpc/xmon/Makefile
> > > +++ b/arch/powerpc/xmon/Makefile
> > > @@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
> > > KASAN_SANITIZE := n
> > >
> > > # Disable ftrace for the entire directory
> > > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> > > +ccflags-remove-y += $(CC_FLAGS_FTRACE)
> >
> > This could be:
> >
> > ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> >
> > Similar to kernel/trace/Makefile below.
>
>
> I fixed it up, and applied to linux-kbuild.
> Thanks.
>
>
> > I don't mind though.
> >
> > Acked-by: Michael Ellerman <[email protected]> (powerpc)
> >
> > cheers
> >
> > > diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> > > index 6575bb0a0434..7492844a8b1b 100644
> > > --- a/kernel/trace/Makefile
> > > +++ b/kernel/trace/Makefile
> > > @@ -2,9 +2,9 @@
> > >
> > > # Do not instrument the tracer itself:
> > >
> > > +ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> > > +
> > > ifdef CONFIG_FUNCTION_TRACER
> > > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> > >
> > > # Avoid recursion due to instrumentation.
> > > KCSAN_SANITIZE := n
>
>
>
> --
> Best Regards
> Masahiro Yamada

2020-07-06 12:04:01

by Anders Roxell

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

On Mon, 6 Jul 2020 at 13:24, Anders Roxell <[email protected]> wrote:
>
> Hi,
>
> When I built an allmodconfig kernel for arm64, and boot that in qemu
> guest I see the following issues:
>
> [...]
> [ 10.451561][ T1] Testing tracer function: PASSED
> [ 33.087895][ T1] Testing dynamic ftrace: .. filter did not
> filter .. FAILED!
> [ 51.127094][ T1] ------------[ cut here ]------------
> [ 51.132387][ T1] WARNING: CPU: 0 PID: 1 at
> kernel/trace/trace.c:1814 run_tracer_selftest+0x314/0x40c
> [ 51.140805][ T1] Modules linked in:
> [ 51.145398][ T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
> 5.8.0-rc3-next-20200703-00004-g8cd4bc531754 #1
> [ 51.154146][ T1] Hardware name: linux,dummy-virt (DT)
> [ 51.159536][ T1] pstate: 80400005 (Nzcv daif +PAN -UAO BTYPE=--)
> [ 51.165711][ T1] pc : run_tracer_selftest+0x314/0x40c
> [ 51.171167][ T1] lr : run_tracer_selftest+0x308/0x40c
> [ 51.176475][ T1] sp : ffff000069c07c40
> [ 51.180855][ T1] x29: ffff000069c07c40 x28: ffffa00015e80320
> [ 51.187187][ T1] x27: ffffa00013e074a0 x26: ffffa000150f22ee
> [ 51.193520][ T1] x25: ffffa000125b35a0 x24: ffffa00013f6a000
> [ 51.199868][ T1] x23: ffffa00013f6adc0 x22: 00000000ffffffff
> [ 51.206225][ T1] x21: ffffa000150f2250 x20: ffffa00015e801c0
> [ 51.212582][ T1] x19: ffffa00015e7fa80 x18: 0000000000002750
> [ 51.218887][ T1] x17: 00000000000014c0 x16: 00000000000016f0
> [ 51.225229][ T1] x15: 00000000000014f8 x14: ffffa0001000a3c8
> [ 51.231584][ T1] x13: ffffa000124a5fb8 x12: ffff80000d494822
> [ 51.237935][ T1] x11: 1fffe0000d494821 x10: ffff80000d494821
> [ 51.244293][ T1] x9 : ffffa000101763b0 x8 : ffff000069c077d7
> [ 51.250704][ T1] x7 : 0000000000000001 x6 : ffff000069c077d0
> [ 51.257060][ T1] x5 : ffff00006a7fc040 x4 : 0000000000000000
> [ 51.263423][ T1] x3 : ffffa00010211118 x2 : 8af0509000018b00
> [ 51.269757][ T1] x1 : 0000000000000000 x0 : 0000000000000001
> [ 51.276084][ T1] Call trace:
> [ 51.279934][ T1] run_tracer_selftest+0x314/0x40c
> [ 51.285174][ T1] init_trace_selftests+0x110/0x31c
> [ 51.290391][ T1] do_one_initcall+0x410/0x960
> [ 51.295315][ T1] kernel_init_freeable+0x430/0x4f0
> [ 51.300595][ T1] kernel_init+0x20/0x1d8
> [ 51.305180][ T1] ret_from_fork+0x10/0x18
> [ 51.309741][ T1] irq event stamp: 1401832
> [ 51.314399][ T1] hardirqs last enabled at (1401831):
> [<ffffa0001020d10c>] console_unlock+0xc04/0xd10
> [ 51.322973][ T1] hardirqs last disabled at (1401832):
> [<ffffa00010050fe4>] debug_exception_enter+0xbc/0x200
> [ 51.331993][ T1] softirqs last enabled at (1401828):
> [<ffffa000100023a4>] __do_softirq+0x95c/0x9f8
> [ 51.340490][ T1] softirqs last disabled at (1401821):
> [<ffffa0001010f7d0>] irq_exit+0x118/0x198
> [ 51.348717][ T1] _warn_unseeded_randomness: 5 callbacks suppressed
> [ 51.349263][ T1] random: get_random_bytes called from
> print_oops_end_marker+0x48/0x80 with crng_init=0
> [ 51.350502][ T1] ---[ end trace c566e8a71c933d3c ]---
> [...]
> [40709.672335][ C0] pool 2: cpus=0 flags=0x5 nice=0 hung=3s
> workers=3 manager: 1455
> [40739.960593][ T26] INFO: lockdep is turned off.
> [40775.312499][ T26] Kernel panic - not syncing: hung_task: blocked tasks
> [40775.341521][ T26] CPU: 0 PID: 26 Comm: khungtaskd Tainted: G
> W 5.8.0-rc3-next-20200703-00004-g8cd4bc531754 #1
> [40775.352848][ T26] Hardware name: linux,dummy-virt (DT)
> [40775.359304][ T26] Call trace:
> [40775.364148][ T26] dump_backtrace+0x0/0x418
> [40775.369918][ T26] show_stack+0x34/0x48
> [40775.375468][ T26] dump_stack+0x1f4/0x2b0
> [40775.381136][ T26] panic+0x2dc/0x6ec
> [40775.386430][ T26] watchdog+0x1400/0x1460
> [40775.392103][ T26] kthread+0x23c/0x250
> [40775.397548][ T26] ret_from_fork+0x10/0x18
> [40775.407039][ T26] Kernel Offset: disabled
> [40775.412634][ T26] CPU features: 0x240002,20002004
> [40775.418751][ T26] Memory Limit: none
> [40775.425823][ T26] ---[ end Kernel panic - not syncing: hung_task:
> blocked tasks ]---
>
> The full log can be found here [1].
>
> Without this patch for 'trace_selftest_dynamic' for instance, CC_FLAGS_FTRACE
> was removed from kernel/trace/*, and then added back to
> kernel/trace/trace_selftest_dynamic.
> While with this patch it looks like we add the flag (even though it is
> already there), and then
> removes the flag for all files in kernel/trace/* .

Hi again,

I think the patch below solved the issue for trace_selftest_dynamic. However,
I think there is still differences in lib/* .

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index cc5e3c6aaa20..5632a711921f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -111,12 +111,12 @@ basename_flags = -DKBUILD_BASENAME=$(call
name-fix,$(basetarget))
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))

-orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
- $(ccflags-y) $(CFLAGS_$(target-stem).o)
+orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)
_c_flags = $(filter-out $(ccflags-remove-y)
$(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
-orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
- $(asflags-y) $(AFLAGS_$(target-stem).o)
+_c_flags += $(CFLAGS_$(target-stem).o)
+orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)
_a_flags = $(filter-out $(asflags-remove-y)
$(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
+_a_flags += $(AFLAGS_$(target-stem).o)
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y)
$(CPPFLAGS_$(target-stem).lds)

#


>
> Cheers,
> Anders
> [1] https://people.linaro.org/~anders.roxell/output-next-20200703.log
>
> On Tue, 30 Jun 2020 at 04:09, Masahiro Yamada <[email protected]> wrote:
> >
> > On Mon, Jun 29, 2020 at 2:55 PM Michael Ellerman <[email protected]> wrote:
> > >
> > > Masahiro Yamada <[email protected]> writes:
> > > > CFLAGS_REMOVE_<file>.o works per object, that is, there is no
> > > > convenient way to filter out flags for every object in a directory.
> > > >
> > > > Add ccflags-remove-y and asflags-remove-y to make it easily.
> > > >
> > > > Use ccflags-remove-y to clean up some Makefiles.
> > > >
> > > > Suggested-by: Sami Tolvanen <[email protected]>
> > > > Signed-off-by: Masahiro Yamada <[email protected]>
> > > > ---
> > > >
> > > > arch/arm/boot/compressed/Makefile | 6 +-----
> > > > arch/powerpc/xmon/Makefile | 3 +--
> > > > arch/sh/boot/compressed/Makefile | 5 +----
> > > > kernel/trace/Makefile | 4 ++--
> > > > lib/Makefile | 5 +----
> > > > scripts/Makefile.lib | 4 ++--
> > > > 6 files changed, 8 insertions(+), 19 deletions(-)
> > > >
> > > > diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
> > > > index 89c76ca35640..55cbcdd88ac0 100644
> > > > --- a/arch/powerpc/xmon/Makefile
> > > > +++ b/arch/powerpc/xmon/Makefile
> > > > @@ -7,8 +7,7 @@ UBSAN_SANITIZE := n
> > > > KASAN_SANITIZE := n
> > > >
> > > > # Disable ftrace for the entire directory
> > > > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > > > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> > > > +ccflags-remove-y += $(CC_FLAGS_FTRACE)
> > >
> > > This could be:
> > >
> > > ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> > >
> > > Similar to kernel/trace/Makefile below.
> >
> >
> > I fixed it up, and applied to linux-kbuild.
> > Thanks.
> >
> >
> > > I don't mind though.
> > >
> > > Acked-by: Michael Ellerman <[email protected]> (powerpc)
> > >
> > > cheers
> > >
> > > > diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> > > > index 6575bb0a0434..7492844a8b1b 100644
> > > > --- a/kernel/trace/Makefile
> > > > +++ b/kernel/trace/Makefile
> > > > @@ -2,9 +2,9 @@
> > > >
> > > > # Do not instrument the tracer itself:
> > > >
> > > > +ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)
> > > > +
> > > > ifdef CONFIG_FUNCTION_TRACER
> > > > -ORIG_CFLAGS := $(KBUILD_CFLAGS)
> > > > -KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
> > > >
> > > > # Avoid recursion due to instrumentation.
> > > > KCSAN_SANITIZE := n
> >
> >
> >
> > --
> > Best Regards
> > Masahiro Yamada

2020-07-06 18:16:23

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

Hi Anders,

On Mon, Jul 6, 2020 at 8:24 PM Anders Roxell <[email protected]> wrote:
>

> The full log can be found here [1].
>
> Without this patch for 'trace_selftest_dynamic' for instance, CC_FLAGS_FTRACE
> was removed from kernel/trace/*, and then added back to
> kernel/trace/trace_selftest_dynamic.
> While with this patch it looks like we add the flag (even though it is
> already there), and then
> removes the flag for all files in kernel/trace/* .


You are right.

I will drop this patch,
and send v2.


Thank you.




--
Best Regards
Masahiro Yamada