linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: Fix filtering '-mno-global-merge'
@ 2022-03-22 17:35 Nathan Chancellor
  2022-03-22 23:57 ` David Gow
  2022-03-26  3:29 ` Masahiro Yamada
  0 siblings, 2 replies; 5+ messages in thread
From: Nathan Chancellor @ 2022-03-22 17:35 UTC (permalink / raw)
  To: Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: Nick Desaulniers, David Gow, linux-um, linux-kernel, llvm,
	Nathan Chancellor

When booting a clang compiled UML kernel, the kernel panics when trying
to run init:

  wait_stub_done : failed to wait for SIGTRAP, pid = 651294, n = 651294, errno = 0, status = 0xb7f
  Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b

After the commit in Fixes, many flags from KBUILD_CFLAGS do not appear
in USER_CFLAGS, likely due to USER_CFLAGS initially being a recursive
variable ("VAR =") then being switched to a simple ("VAR :=") variable.
For example, diffing arch/x86/um/.ptrace_user.o.cmd shows flags such as
'-Os' and '-fno-delete-null-pointer-checks' getting dropped, which both
impact code generation.

Rework the filtering to use filter-out instead of patsubst, which allows
all the patterns that USER_CFLAGS cares about to be excluded in one
command and ensures all flags from KBUILD_CFLAGS are transferred over to
USER_CFLAGS properly, which resolves the boot issue noted above.

Fixes: 6580c5c18fb3 ("um: clang: Strip out -mno-global-merge from USER_CFLAGS")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 arch/um/Makefile | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/um/Makefile b/arch/um/Makefile
index 320b09cd513c..d202f501e9e1 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -70,15 +70,11 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
 
 KBUILD_AFLAGS += $(ARCH_INCLUDE)
 
-USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
+USER_CFLAGS = $(filter-out $(KERNEL_DEFINES) -I% -mno-global-merge,$(KBUILD_CFLAGS)) \
 		$(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
 		-D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
 		-idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
 
-ifdef CONFIG_CC_IS_CLANG
-USER_CFLAGS := $(patsubst -mno-global-merge,,$(USER_CFLAGS))
-endif
-
 #This will adjust *FLAGS accordingly to the platform.
 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
 

base-commit: 82017457957a550d7d00dde419435dd74a890887
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] um: Fix filtering '-mno-global-merge'
  2022-03-22 17:35 [PATCH] um: Fix filtering '-mno-global-merge' Nathan Chancellor
@ 2022-03-22 23:57 ` David Gow
  2022-03-26  3:29 ` Masahiro Yamada
  1 sibling, 0 replies; 5+ messages in thread
From: David Gow @ 2022-03-22 23:57 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
	Nick Desaulniers, linux-um, Linux Kernel Mailing List, llvm

[-- Attachment #1: Type: text/plain, Size: 2349 bytes --]

On Wed, Mar 23, 2022 at 1:39 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> When booting a clang compiled UML kernel, the kernel panics when trying
> to run init:
>
>   wait_stub_done : failed to wait for SIGTRAP, pid = 651294, n = 651294, errno = 0, status = 0xb7f
>   Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
>
> After the commit in Fixes, many flags from KBUILD_CFLAGS do not appear
> in USER_CFLAGS, likely due to USER_CFLAGS initially being a recursive
> variable ("VAR =") then being switched to a simple ("VAR :=") variable.
> For example, diffing arch/x86/um/.ptrace_user.o.cmd shows flags such as
> '-Os' and '-fno-delete-null-pointer-checks' getting dropped, which both
> impact code generation.
>
> Rework the filtering to use filter-out instead of patsubst, which allows
> all the patterns that USER_CFLAGS cares about to be excluded in one
> command and ensures all flags from KBUILD_CFLAGS are transferred over to
> USER_CFLAGS properly, which resolves the boot issue noted above.
>
> Fixes: 6580c5c18fb3 ("um: clang: Strip out -mno-global-merge from USER_CFLAGS")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---

Thanks. I was able to reproduce the panic here, and this indeed fixes it.

Reviewed-by: David Gow <davidgow@google.com>

Cheers,
-- David

>  arch/um/Makefile | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/arch/um/Makefile b/arch/um/Makefile
> index 320b09cd513c..d202f501e9e1 100644
> --- a/arch/um/Makefile
> +++ b/arch/um/Makefile
> @@ -70,15 +70,11 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
>
>  KBUILD_AFLAGS += $(ARCH_INCLUDE)
>
> -USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
> +USER_CFLAGS = $(filter-out $(KERNEL_DEFINES) -I% -mno-global-merge,$(KBUILD_CFLAGS)) \
>                 $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
>                 -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
>                 -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
>
> -ifdef CONFIG_CC_IS_CLANG
> -USER_CFLAGS := $(patsubst -mno-global-merge,,$(USER_CFLAGS))
> -endif
> -
>  #This will adjust *FLAGS accordingly to the platform.
>  include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
>
>
> base-commit: 82017457957a550d7d00dde419435dd74a890887
> --
> 2.35.1
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4003 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] um: Fix filtering '-mno-global-merge'
  2022-03-22 17:35 [PATCH] um: Fix filtering '-mno-global-merge' Nathan Chancellor
  2022-03-22 23:57 ` David Gow
@ 2022-03-26  3:29 ` Masahiro Yamada
  2022-03-26 20:00   ` Nathan Chancellor
  1 sibling, 1 reply; 5+ messages in thread
From: Masahiro Yamada @ 2022-03-26  3:29 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
	Nick Desaulniers, David Gow, linux-um, Linux Kernel Mailing List,
	llvm

On Wed, Mar 23, 2022 at 2:39 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> When booting a clang compiled UML kernel, the kernel panics when trying
> to run init:
>
>   wait_stub_done : failed to wait for SIGTRAP, pid = 651294, n = 651294, errno = 0, status = 0xb7f
>   Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
>
> After the commit in Fixes, many flags from KBUILD_CFLAGS do not appear
> in USER_CFLAGS, likely due to USER_CFLAGS initially being a recursive
> variable ("VAR =") then being switched to a simple ("VAR :=") variable.
> For example, diffing arch/x86/um/.ptrace_user.o.cmd shows flags such as
> '-Os' and '-fno-delete-null-pointer-checks' getting dropped, which both
> impact code generation.
>
> Rework the filtering to use filter-out instead of patsubst, which allows
> all the patterns that USER_CFLAGS cares about to be excluded in one
> command and ensures all flags from KBUILD_CFLAGS are transferred over to
> USER_CFLAGS properly, which resolves the boot issue noted above.
>
> Fixes: 6580c5c18fb3 ("um: clang: Strip out -mno-global-merge from USER_CFLAGS")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>



Can we remove -mno-global-merge entirely?


61163efae02040f66a95 was a very old commit,
without enough explanation.

Shall we remove  -mno-global-merge, and do compile-tests.
If we are hit by problems for arm/arm64, we can re-add it.









> ---
>  arch/um/Makefile | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/arch/um/Makefile b/arch/um/Makefile
> index 320b09cd513c..d202f501e9e1 100644
> --- a/arch/um/Makefile
> +++ b/arch/um/Makefile
> @@ -70,15 +70,11 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
>
>  KBUILD_AFLAGS += $(ARCH_INCLUDE)
>
> -USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
> +USER_CFLAGS = $(filter-out $(KERNEL_DEFINES) -I% -mno-global-merge,$(KBUILD_CFLAGS)) \
>                 $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
>                 -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
>                 -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
>
> -ifdef CONFIG_CC_IS_CLANG
> -USER_CFLAGS := $(patsubst -mno-global-merge,,$(USER_CFLAGS))
> -endif
> -
>  #This will adjust *FLAGS accordingly to the platform.
>  include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
>
>
> base-commit: 82017457957a550d7d00dde419435dd74a890887
> --
> 2.35.1
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] um: Fix filtering '-mno-global-merge'
  2022-03-26  3:29 ` Masahiro Yamada
@ 2022-03-26 20:00   ` Nathan Chancellor
  2022-04-01 13:10     ` Masahiro Yamada
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2022-03-26 20:00 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
	Nick Desaulniers, David Gow, linux-um, Linux Kernel Mailing List,
	llvm

On Sat, Mar 26, 2022 at 12:29:55PM +0900, Masahiro Yamada wrote:
> On Wed, Mar 23, 2022 at 2:39 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > When booting a clang compiled UML kernel, the kernel panics when trying
> > to run init:
> >
> >   wait_stub_done : failed to wait for SIGTRAP, pid = 651294, n = 651294, errno = 0, status = 0xb7f
> >   Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> >
> > After the commit in Fixes, many flags from KBUILD_CFLAGS do not appear
> > in USER_CFLAGS, likely due to USER_CFLAGS initially being a recursive
> > variable ("VAR =") then being switched to a simple ("VAR :=") variable.
> > For example, diffing arch/x86/um/.ptrace_user.o.cmd shows flags such as
> > '-Os' and '-fno-delete-null-pointer-checks' getting dropped, which both
> > impact code generation.
> >
> > Rework the filtering to use filter-out instead of patsubst, which allows
> > all the patterns that USER_CFLAGS cares about to be excluded in one
> > command and ensures all flags from KBUILD_CFLAGS are transferred over to
> > USER_CFLAGS properly, which resolves the boot issue noted above.
> >
> > Fixes: 6580c5c18fb3 ("um: clang: Strip out -mno-global-merge from USER_CFLAGS")
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> 
> 
> 
> Can we remove -mno-global-merge entirely?
> 
> 
> 61163efae02040f66a95 was a very old commit,
> without enough explanation.
> 
> Shall we remove  -mno-global-merge, and do compile-tests.
> If we are hit by problems for arm/arm64, we can re-add it.

Yes, I think that was the conversation that we had on the commit that
this fixes:

https://lore.kernel.org/r/YiD7R2wRxoWxtVq7@dev-arch.thelio-3990X/

I can test that on my Raspberry Pi 3 and 4 on Monday, although I would
like for this patch to be picked up in the meantime so that it is
possible to test UML on -next with clang. We can remove
-mno-global-merge in a follow up change, if you do not have any
objections?

Cheers,
Nathano

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] um: Fix filtering '-mno-global-merge'
  2022-03-26 20:00   ` Nathan Chancellor
@ 2022-04-01 13:10     ` Masahiro Yamada
  0 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-04-01 13:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
	Nick Desaulniers, David Gow, linux-um, Linux Kernel Mailing List,
	llvm

On Sun, Mar 27, 2022 at 5:00 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Sat, Mar 26, 2022 at 12:29:55PM +0900, Masahiro Yamada wrote:
> > On Wed, Mar 23, 2022 at 2:39 AM Nathan Chancellor <nathan@kernel.org> wrote:
> > >
> > > When booting a clang compiled UML kernel, the kernel panics when trying
> > > to run init:
> > >
> > >   wait_stub_done : failed to wait for SIGTRAP, pid = 651294, n = 651294, errno = 0, status = 0xb7f
> > >   Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> > >
> > > After the commit in Fixes, many flags from KBUILD_CFLAGS do not appear
> > > in USER_CFLAGS, likely due to USER_CFLAGS initially being a recursive
> > > variable ("VAR =") then being switched to a simple ("VAR :=") variable.
> > > For example, diffing arch/x86/um/.ptrace_user.o.cmd shows flags such as
> > > '-Os' and '-fno-delete-null-pointer-checks' getting dropped, which both
> > > impact code generation.
> > >
> > > Rework the filtering to use filter-out instead of patsubst, which allows
> > > all the patterns that USER_CFLAGS cares about to be excluded in one
> > > command and ensures all flags from KBUILD_CFLAGS are transferred over to
> > > USER_CFLAGS properly, which resolves the boot issue noted above.
> > >
> > > Fixes: 6580c5c18fb3 ("um: clang: Strip out -mno-global-merge from USER_CFLAGS")
> > > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> >
> >
> >
> > Can we remove -mno-global-merge entirely?
> >
> >
> > 61163efae02040f66a95 was a very old commit,
> > without enough explanation.
> >
> > Shall we remove  -mno-global-merge, and do compile-tests.
> > If we are hit by problems for arm/arm64, we can re-add it.
>
> Yes, I think that was the conversation that we had on the commit that
> this fixes:
>
> https://lore.kernel.org/r/YiD7R2wRxoWxtVq7@dev-arch.thelio-3990X/
>
> I can test that on my Raspberry Pi 3 and 4 on Monday, although I would
> like for this patch to be picked up in the meantime so that it is
> possible to test UML on -next with clang. We can remove
> -mno-global-merge in a follow up change, if you do not have any
> objections?
>
> Cheers,
> Nathano


This patch is unneeded now
because I picked up the alternative:

https://lore.kernel.org/all/CAK7LNAS6C6Uj9cCQ0o=bYF1F-EVD=VgdR8YYx-1PJc9toX_HZA@mail.gmail.com/



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-01 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22 17:35 [PATCH] um: Fix filtering '-mno-global-merge' Nathan Chancellor
2022-03-22 23:57 ` David Gow
2022-03-26  3:29 ` Masahiro Yamada
2022-03-26 20:00   ` Nathan Chancellor
2022-04-01 13:10     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).