Skip to contentSkip to conversation

getting things like CONFIG_ARCH_HAS_SYSCALL_WRAPPER without bothering with selects

RFC In review Al Viro 3 participants 3 messages Aug 9, 2022 – Aug 10, 2022

Subsystems (5)
x86 Kbuild arm64 s390 +1 more subsystems
lore
Share & tools
lore

Al Viro

author
#0 lore raw

RFC 1/1 getting things like CONFIG_ARCH_HAS_SYSCALL_WRAPPER without bothering with selects

Sometimes we have situations when we want linux/foo.h
include asm/bar.h if the latter exists; one example is includes of asm/syscall_wrapper.h. Right now there are two ways to do that:
1) ARCH_HAS_BAR_H, explicitly selected by architectures
that have asm/bar.h and include guarded by #ifdef CONFIG_ARCH_HAS_BAR_H
2) include/asm-default/bar.h, either empty or with
something like #define __ARCH_HAS_NO_BAR_H, with mandatory-y += bar.h in include/asm-generic/Kbuild and unconditional includes of asm/bar.h, possibly followed by #ifdef __ARCH_HAS_NO_BAR_H ... #endif

However, kconfig could do (1) without selects - something like bool ARCH_HAS_BAR_H

	def_bool $(header-exists,bar.h)

Does anybody see problems with the patch below?

---

arch/arm64/Kconfig +0 -1
index 1652a9800ebe..277437f329ce 100644
@@ -42,7 +42,6 @@ config ARM64
 	select ARCH_HAS_STRICT_MODULE_RWX
 	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
 	select ARCH_HAS_SYNC_DMA_FOR_CPU
-	select ARCH_HAS_SYSCALL_WRAPPER
 	select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAS_VM_GET_PAGE_PROT
arch/s390/Kconfig +0 -1
index 91c0b80a8bf0..86e905b8462c 100644
@@ -78,7 +78,6 @@ config S390
 	select ARCH_HAS_SET_MEMORY
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
-	select ARCH_HAS_SYSCALL_WRAPPER
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_HAS_VDSO_DATA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/x86/Kconfig +0 -1
index be0b95e51df6..64592d027a0d 100644
@@ -92,7 +92,6 @@ config X86
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
 	select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
-	select ARCH_HAS_SYSCALL_WRAPPER
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_HAS_VM_GET_PAGE_PROT
 	select ARCH_HAS_DEBUG_WX
init/Kconfig +1 -1
index c7900e8975f1..ce88397c4e46 100644
@@ -2257,4 +2257,4 @@ config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
 # kernel/time/posix-stubs.c. All these overrides need to be available in
 # <asm/syscall_wrapper.h>.
 config ARCH_HAS_SYSCALL_WRAPPER
-	def_bool n
+	def_bool $(header-exists,syscall_wrapper.h)
scripts/Kconfig.include +4 -0
index 0496efd6e117..465bb836f82a 100644
@@ -23,6 +23,10 @@ success = $(if-success,$(1),y,n)
 # Return n if <command> exits with 0, y otherwise
 failure = $(if-success,$(1),n,y)
 
+# $(header-exists,<header>)
+# Return y if arch/$(ARCH)/include/asm/<header> exists, n otherwise
+header-exists = $(success,test -e $(srctree)/arch/$(ARCH)/include/asm/$(1))
+
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
 cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
#1 lore raw
Quoted 6 lines · Al Viro

However, kconfig could do (1) without selects - something like bool ARCH_HAS_BAR_H

        def_bool $(header-exists,bar.h)

Does anybody see problems with the patch below?

I like the concept, but I'm not entirely sure how generic it is. How many of those "arch has this header" do we really end up having?

Just looking at some of the "ARCH_HAS_XYZ" options, very few strike me as being about a header file existing.

I'm not saying you picked the _only_ such case, but it doesn't seem _entirely_ impossible that you did..

Looking at some of the other cases, they might be more interested in not "does it have a header file", but "can I grep for this symbol name"?

And that kind of "do you expose symbol XYZ in header ABC" query might work for this ARCH_HAS_SYSCALL_WRAPPER case too?

So that seems like it might potentially be a more general-purpose Kconfig helper. Hmm?

Linus

#2 lore raw
In reply to Al Viro
Quoted 12 lines · Al Viro

Sometimes we have situations when we want linux/foo.h
include asm/bar.h if the latter exists; one example is includes of asm/syscall_wrapper.h. Right now there are two ways to do that:
1) ARCH_HAS_BAR_H, explicitly selected by architectures
that have asm/bar.h and include guarded by #ifdef CONFIG_ARCH_HAS_BAR_H
2) include/asm-default/bar.h, either empty or with
something like #define __ARCH_HAS_NO_BAR_H, with mandatory-y += bar.h in include/asm-generic/Kbuild and unconditional includes of asm/bar.h, possibly followed by #ifdef __ARCH_HAS_NO_BAR_H ... #endif

Quoted 5 lines

However, kconfig could do (1) without selects - something like bool ARCH_HAS_BAR_H

        def_bool $(header-exists,bar.h)

Does anybody see problems with the patch below?

A problem is that Kconfig does not react to addition/removal of asm/syscall_wrapper.h

For example, with the patch applied,
touch or rm arch/arm/include/asm/syscall_wrapper.h and rebuild the arm kernel.

$ touch   arch/arm/include/asm/syscall_wrapper.h
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-  -j8
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  Kernel: arch/arm/boot/Image is ready
  Kernel: arch/arm/boot/zImage is ready
$ rm     arch/arm/include/asm/syscall_wrapper.h
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-  -j8
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  Kernel: arch/arm/boot/Image is ready
  Kernel: arch/arm/boot/zImage is ready

When the header is added or removed, the kernel must be rebuilt with CONFIG_ARCH_HAS_SYSCALL_WRAPPER updated, but Kconfig is actually not invoked at all.

The condition for triggering Kconfig is generated in include/config/auto.conf.cmd but I do not know how to handle this case correctly.

I think it is better to not have Kconfig think too much. We do several compiler tests in Kconfig, but that is because otherwise we cannot know
users' build environments.

We know everything in the source tree.
"test -e arch/$(ARCH)/include/asm/syscall_wrapper.h" does not seem sensible to me.

Masahiro Yamada

Quoted 64 lines

---

arch/arm64/Kconfig +0 -1
index 1652a9800ebe..277437f329ce 100644
@@ -42,7 +42,6 @@ config ARM64
        select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_SYNC_DMA_FOR_DEVICE
        select ARCH_HAS_SYNC_DMA_FOR_CPU
-       select ARCH_HAS_SYSCALL_WRAPPER
        select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_HAS_VM_GET_PAGE_PROT
arch/s390/Kconfig +0 -1
index 91c0b80a8bf0..86e905b8462c 100644
@@ -78,7 +78,6 @@ config S390
        select ARCH_HAS_SET_MEMORY
        select ARCH_HAS_STRICT_KERNEL_RWX
        select ARCH_HAS_STRICT_MODULE_RWX
-       select ARCH_HAS_SYSCALL_WRAPPER
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAS_VDSO_DATA
        select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/x86/Kconfig +0 -1
index be0b95e51df6..64592d027a0d 100644
@@ -92,7 +92,6 @@ config X86
        select ARCH_HAS_STRICT_KERNEL_RWX
        select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
-       select ARCH_HAS_SYSCALL_WRAPPER
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARCH_HAS_VM_GET_PAGE_PROT
        select ARCH_HAS_DEBUG_WX
init/Kconfig +1 -1
index c7900e8975f1..ce88397c4e46 100644
@@ -2257,4 +2257,4 @@ config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
 # kernel/time/posix-stubs.c. All these overrides need to be available in
 # <asm/syscall_wrapper.h>.
 config ARCH_HAS_SYSCALL_WRAPPER
-       def_bool n
+       def_bool $(header-exists,syscall_wrapper.h)
scripts/Kconfig.include +4 -0
index 0496efd6e117..465bb836f82a 100644
@@ -23,6 +23,10 @@ success = $(if-success,$(1),y,n)
 # Return n if <command> exits with 0, y otherwise
 failure = $(if-success,$(1),n,y)
 
+# $(header-exists,<header>)
+# Return y if arch/$(ARCH)/include/asm/<header> exists, n otherwise
+header-exists = $(success,test -e $(srctree)/arch/$(ARCH)/include/asm/$(1))
+
 # $(cc-option,<flag>)
 # Return y if the compiler supports <flag>, n otherwise
 cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
Signature · 2 lines
Best Regards
Masahiro Yamada