Hi, Willy, Thomas
v3 here is to fix up two issues introduced in v2 powerpc patchset [1].
- One is restore the wrongly removed '' for a '$$ARCH'
- Another is add the missing $(ARCH).config for ppc, the default variant for powerpc is renamed to ppc in v2 (as discussed with Willy in [2]), but ppc.config is missing in v2 patchset, not sure why this happen, may a 'git clean -fdx .' is required to do a new test, just did it.
Btw, the v3 tinyconfig-part1 for powerpc is ready, I will send it out soon.
Best regards, Zhangjin --- [1]: https://lore.kernel.org/lkml/cover.1690373704.git.falcon@tinylab.org/ [2]: https://lore.kernel.org/lkml/ZL9leVOI25S2+0+g@1wt.eu/
Zhangjin Wu (7): tools/nolibc: add support for powerpc tools/nolibc: add support for powerpc64 selftests/nolibc: add extra configs customize support selftests/nolibc: add XARCH and ARCH mapping support selftests/nolibc: add test support for ppc selftests/nolibc: add test support for ppc64le selftests/nolibc: add test support for ppc64
tools/include/nolibc/arch-powerpc.h | 202 ++++++++++++++++++ tools/include/nolibc/arch.h | 2 + tools/testing/selftests/nolibc/Makefile | 46 +++- .../selftests/nolibc/configs/ppc.config | 3 + 4 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 tools/include/nolibc/arch-powerpc.h create mode 100644 tools/testing/selftests/nolibc/configs/ppc.config
Both syscall declarations and _start code definition are added for powerpc to nolibc.
Like mips, powerpc uses a register (exactly, the summary overflow bit) to record the error occurred, and uses another register to return the value [1]. So, the return value of every syscall declaration must be normalized to match the __sysret() helper, return -value when there is an error, otheriwse, return value directly.
Glibc and musl use different methods to check the summary overflow bit, glibc (sysdeps/unix/sysv/linux/powerpc/sysdep.h) saves the cr register to r0 at first, and then check the summary overflow bit in cr0:
mfcr r0 r0 & (1 << 28) ? -r3 : r3
-->
10003c14: 7c 00 00 26 mfcr r0 10003c18: 74 09 10 00 andis. r9,r0,4096 10003c1c: 41 82 00 08 beq 0x10003c24 10003c20: 7c 63 00 d0 neg r3,r3
Musl (arch/powerpc/syscall_arch.h) directly checks the summary overflow bit with the 'bns' instruction, it is smaller:
/* no summary overflow bit means no error, return value directly */ bns+ 1f /* otherwise, return negated value */ neg r3, r3 1:
-->
10000418: 40 a3 00 08 bns 0x10000420 1000041c: 7c 63 00 d0 neg r3,r3
Like musl, Linux (arch/powerpc/include/asm/vdso/gettimeofday.h) uses the same method for do_syscall_2() too.
Here applies the second method to get smaller size.
[1]: https://man7.org/linux/man-pages/man2/syscall.2.html
Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/include/nolibc/arch-powerpc.h | 188 ++++++++++++++++++++++++++++ tools/include/nolibc/arch.h | 2 + 2 files changed, 190 insertions(+) create mode 100644 tools/include/nolibc/arch-powerpc.h
diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arch-powerpc.h new file mode 100644 index 000000000000..caa943e1521a --- /dev/null +++ b/tools/include/nolibc/arch-powerpc.h @@ -0,0 +1,188 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * PowerPC specific definitions for NOLIBC + * Copyright (C) 2023 Zhangjin Wu falcon@tinylab.org + */ + +#ifndef _NOLIBC_ARCH_POWERPC_H +#define _NOLIBC_ARCH_POWERPC_H + +#include "compiler.h" +#include "crt.h" + +/* Syscalls for PowerPC : + * - stack is 16-byte aligned + * - syscall number is passed in r0 + * - arguments are in r3, r4, r5, r6, r7, r8, r9 + * - the system call is performed by calling "sc" + * - syscall return comes in r3, and the summary overflow bit is checked + * to know if an error occurred, in which case errno is in r3. + * - the arguments are cast to long and assigned into the target + * registers which are then simply passed as registers to the asm code, + * so that we don't have to experience issues with register constraints. + */ + +#define _NOLIBC_SYSCALL_CLOBBERLIST \ + "memory", "cr0", "r12", "r11", "r10", "r9" + +#define my_syscall0(num) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num) \ + : \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8", "r7", "r6", "r5", "r4" \ + ); \ + _ret; \ +}) + +#define my_syscall1(num, arg1) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8", "r7", "r6", "r5", "r4" \ + ); \ + _ret; \ +}) + + +#define my_syscall2(num, arg1, arg2) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + register long _arg2 __asm__ ("r4") = (long)(arg2); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num), "+r"(_arg2) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8", "r7", "r6", "r5" \ + ); \ + _ret; \ +}) + + +#define my_syscall3(num, arg1, arg2, arg3) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + register long _arg2 __asm__ ("r4") = (long)(arg2); \ + register long _arg3 __asm__ ("r5") = (long)(arg3); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num), "+r"(_arg2), "+r"(_arg3) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8", "r7", "r6" \ + ); \ + _ret; \ +}) + + +#define my_syscall4(num, arg1, arg2, arg3, arg4) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + register long _arg2 __asm__ ("r4") = (long)(arg2); \ + register long _arg3 __asm__ ("r5") = (long)(arg3); \ + register long _arg4 __asm__ ("r6") = (long)(arg4); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num), "+r"(_arg2), "+r"(_arg3), \ + "+r"(_arg4) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8", "r7" \ + ); \ + _ret; \ +}) + + +#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + register long _arg2 __asm__ ("r4") = (long)(arg2); \ + register long _arg3 __asm__ ("r5") = (long)(arg3); \ + register long _arg4 __asm__ ("r6") = (long)(arg4); \ + register long _arg5 __asm__ ("r7") = (long)(arg5); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num), "+r"(_arg2), "+r"(_arg3), \ + "+r"(_arg4), "+r"(_arg5) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST, "r8" \ + ); \ + _ret; \ +}) + +#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \ +({ \ + register long _ret __asm__ ("r3"); \ + register long _num __asm__ ("r0") = (num); \ + register long _arg1 __asm__ ("r3") = (long)(arg1); \ + register long _arg2 __asm__ ("r4") = (long)(arg2); \ + register long _arg3 __asm__ ("r5") = (long)(arg3); \ + register long _arg4 __asm__ ("r6") = (long)(arg4); \ + register long _arg5 __asm__ ("r7") = (long)(arg5); \ + register long _arg6 __asm__ ("r8") = (long)(arg6); \ + \ + __asm__ volatile ( \ + " sc\n" \ + " bns+ 1f\n" \ + " neg %0, %0\n" \ + "1:\n" \ + : "=r"(_ret), "+r"(_num), "+r"(_arg2), "+r"(_arg3), \ + "+r"(_arg4), "+r"(_arg5), "+r"(_arg6) \ + : "0"(_arg1) \ + : _NOLIBC_SYSCALL_CLOBBERLIST \ + ); \ + _ret; \ +}) + +/* startup code */ +void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) +{ + __asm__ volatile ( + "mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */ + "clrrwi 1, 1, 4\n" /* align the stack to 16 bytes */ + "li 0, 0\n" /* zero the frame pointer */ + "stwu 1, -16(1)\n" /* the initial stack frame */ + "bl _start_c\n" /* transfer to c runtime */ + ); + __builtin_unreachable(); +} + +#endif /* _NOLIBC_ARCH_POWERPC_H */ diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h index 82b43935650f..e276fb0680af 100644 --- a/tools/include/nolibc/arch.h +++ b/tools/include/nolibc/arch.h @@ -25,6 +25,8 @@ #include "arch-aarch64.h" #elif defined(__mips__) && defined(_ABIO32) #include "arch-mips.h" +#elif defined(__powerpc__) +#include "arch-powerpc.h" #elif defined(__riscv) #include "arch-riscv.h" #elif defined(__s390x__)
This follows the 64-bit PowerPC ABI [1], refers to the slides: "A new ABI for little-endian PowerPC64 Design & Implementation" [2] and the musl code in arch/powerpc64/crt_arch.h.
First, stdu and clrrdi are used instead of stwu and clrrwi for powerpc64.
Second, the stack frame size is increased to 32 bytes for powerpc64, 32 bytes is the minimal stack frame size supported described in [2].
Besides, the TOC pointer (GOT pointer) must be saved to r2.
This works on both little endian and big endian 64-bit PowerPC.
[1]: https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.pdf [2]: https://www.llvm.org/devmtg/2014-04/PDFs/Talks/Euro-LLVM-2014-Weigand.pdf
Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/include/nolibc/arch-powerpc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arch-powerpc.h index caa943e1521a..d783ed0b5dbd 100644 --- a/tools/include/nolibc/arch-powerpc.h +++ b/tools/include/nolibc/arch-powerpc.h @@ -175,6 +175,19 @@ /* startup code */ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) { +#ifdef __powerpc64__ + /* On 64-bit PowerPC, save TOC/GOT pointer to r2 */ + extern char TOC __asm__ (".TOC."); + register volatile long r2 __asm__ ("r2") = (void *)&TOC - (void *)_start; + + __asm__ volatile ( + "mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */ + "clrrdi 1, 1, 4\n" /* align the stack to 16 bytes */ + "li 0, 0\n" /* zero the frame pointer */ + "stdu 1, -32(1)\n" /* the initial stack frame */ + "bl _start_c\n" /* transfer to c runtime */ + ); +#else __asm__ volatile ( "mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */ "clrrwi 1, 1, 4\n" /* align the stack to 16 bytes */ @@ -182,6 +195,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_ "stwu 1, -16(1)\n" /* the initial stack frame */ "bl _start_c\n" /* transfer to c runtime */ ); +#endif __builtin_unreachable(); }
The default DEFCONFIG_<ARCH> may not always work for all architectures, some architectures require to add extra kernel config options, this allows to add extra options in the defconfig target.
Based on the .config generated from DEFCONFIG_<ARCH>, It allows to customize extra kernel config options via both the common common.config and the architecture specific <ARCH>.config, at last trigger 'allnoconfig' to let them take effect with missing config options as disabled.
The scripts/kconfig/merge_config.sh tool is used to merge the extra config files.
Suggested-by: Thomas Weißschuh linux@weissschuh.net Link: https://lore.kernel.org/lkml/67eb70d4-c9ff-4afc-bac7-7f36cc2c81bc@t-8ch.de/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index f42adef87e12..9576f1a0a98d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -39,6 +39,9 @@ DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig DEFCONFIG = $(DEFCONFIG_$(ARCH))
+# extra kernel config files under configs/, include common + architecture specific +EXTCONFIG = common.config $(ARCH).config + # optional tests to run (default = all) TEST =
@@ -161,6 +164,8 @@ initramfs: nolibc-test
defconfig: $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare + $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTCONFIG),$(wildcard $(CURDIR)/configs/$c)) + $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
kernel: initramfs $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
On 2023-07-27 23:02:02+0800, Zhangjin Wu wrote:
The default DEFCONFIG_<ARCH> may not always work for all architectures, some architectures require to add extra kernel config options, this allows to add extra options in the defconfig target.
Based on the .config generated from DEFCONFIG_<ARCH>, It allows to customize extra kernel config options via both the common common.config and the architecture specific <ARCH>.config, at last trigger 'allnoconfig' to let them take effect with missing config options as disabled.
The scripts/kconfig/merge_config.sh tool is used to merge the extra config files.
Suggested-by: Thomas Weißschuh linux@weissschuh.net Link: https://lore.kernel.org/lkml/67eb70d4-c9ff-4afc-bac7-7f36cc2c81bc@t-8ch.de/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org
tools/testing/selftests/nolibc/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index f42adef87e12..9576f1a0a98d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -39,6 +39,9 @@ DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig DEFCONFIG = $(DEFCONFIG_$(ARCH)) +# extra kernel config files under configs/, include common + architecture specific +EXTCONFIG = common.config $(ARCH).config
As this series seems to need a respin anyways:
extconfig means "extended config", correct? That is fairly nondescript.
I would prefer something like "NOLIBC_TEST_CONFIG" and something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
# optional tests to run (default = all) TEST = @@ -161,6 +164,8 @@ initramfs: nolibc-test defconfig: $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
- $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTCONFIG),$(wildcard $(CURDIR)/configs/$c))
- $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
kernel: initramfs $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs -- 2.25.1
On 2023-07-27 23:02:02+0800, Zhangjin Wu wrote:
The default DEFCONFIG_<ARCH> may not always work for all architectures, some architectures require to add extra kernel config options, this allows to add extra options in the defconfig target.
Based on the .config generated from DEFCONFIG_<ARCH>, It allows to customize extra kernel config options via both the common common.config and the architecture specific <ARCH>.config, at last trigger 'allnoconfig' to let them take effect with missing config options as disabled.
The scripts/kconfig/merge_config.sh tool is used to merge the extra config files.
Suggested-by: Thomas Weißschuh linux@weissschuh.net Link: https://lore.kernel.org/lkml/67eb70d4-c9ff-4afc-bac7-7f36cc2c81bc@t-8ch.de/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org
tools/testing/selftests/nolibc/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index f42adef87e12..9576f1a0a98d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -39,6 +39,9 @@ DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig DEFCONFIG = $(DEFCONFIG_$(ARCH)) +# extra kernel config files under configs/, include common + architecture specific +EXTCONFIG = common.config $(ARCH).config
As this series seems to need a respin anyways:
extconfig means "extended config", correct? That is fairly nondescript.
It is more about 'extra' as commented (or 'additional'), for both defconfig (may) and tinyconfig (must) require more options to make boot and print work for nolibc-test.
defconfig ------\ \ \ EXTCONFIG ----> a working .config for nolibc-test / / tinyconfig------/
I would prefer something like "NOLIBC_TEST_CONFIG"
Using NOLIBC_TEST_CONFIG is ok, but with this name, do we still only put the 'additional' options there? or we simply use EXTRA_CONFIG instead?
# extra kernel config files under configs/, include common + architecture specific EXTRA_CONFIG = common.config $(ARCH).config
From the name, NOLIBC_TEST_CONFIG should be a standalone config file to include all necessary options? but as Willy suggested, he want to reserve defconfig as an optional target, and tinyconfig does may be more easier to fail than defconfig, if only consider tinyconfig, it is ok for us to put all of the .config generated from tinyconfig + extra config to NOLIBC_TEST_CONFIG.
NOLIBC_TEST_CONFIG = tinyconfig + common.config + $(ARCH).config
But it may be harder to maintain a standalone config than an additional config file.
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config: $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
Currently, we use 'defconfig' by default and we use 'make defconfig DEFCONFIG=tinyconfig' to switch to tinyconfig, in the next weeks, when all of the nolibc supported architectures have tinyconfig support, it is able to switch 'tinyconfig' as the default config target.
PHONY += $(KERNEL_CONFIG) $(KERNEL_CONFIG): $(Q)if [ ! -f "$(KERNEL_CONFIG)" ]; then $(MAKE) --no-print-directory defconfig DEFCONFIG=tinyconfig; fi
kernel: $(KERNEL_CONFIG) $(Q)$(MAKE) --no-print-directory initramfs $(Q)$(MAKE_KERNEL) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
Welcome more discussion.
Thanks, Zhangjin
# optional tests to run (default = all) TEST = @@ -161,6 +164,8 @@ initramfs: nolibc-test defconfig: $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
- $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTCONFIG),$(wildcard $(CURDIR)/configs/$c))
- $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
kernel: initramfs $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs -- 2.25.1
On Sat, Jul 29, 2023 at 10:39:33PM +0800, Zhangjin Wu wrote:
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index f42adef87e12..9576f1a0a98d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -39,6 +39,9 @@ DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig DEFCONFIG = $(DEFCONFIG_$(ARCH)) +# extra kernel config files under configs/, include common + architecture specific +EXTCONFIG = common.config $(ARCH).config
As this series seems to need a respin anyways:
extconfig means "extended config", correct? That is fairly nondescript.
It is more about 'extra' as commented (or 'additional'), for both defconfig (may) and tinyconfig (must) require more options to make boot and print work for nolibc-test. defconfig ------\ \ \ EXTCONFIG ----> a working .config for nolibc-test / / tinyconfig------/
I would prefer something like "NOLIBC_TEST_CONFIG"
Using NOLIBC_TEST_CONFIG is ok, but with this name, do we still only put the 'additional' options there? or we simply use EXTRA_CONFIG instead?
# extra kernel config files under configs/, include common + architecture specific EXTRA_CONFIG = common.config $(ARCH).config
Either are fine to me. The most important is to mention that these configs are appended to the config during the defconfig and tinyconfig targets.
Also I find it odd to use $(ARCH) here, I would have expected $(XARCH) since you probably want to distinguish ppc64 from ppc for example.
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config:
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
I think that as long as we don't claim to call topdir's makefile targets from this directory, we can reuse some similarly named targets which are documented in "make help" and are non-ambiguous.
Currently, we use 'defconfig' by default and we use 'make defconfig DEFCONFIG=tinyconfig' to switch to tinyconfig, in the next weeks, when all of the nolibc supported architectures have tinyconfig support, it is able to switch 'tinyconfig' as the default config target.
As long as it doesn't require to locally maintain too many options, I think I'm fine with that. But we'll see.
Willy
On Sat, Jul 29, 2023 at 10:39:33PM +0800, Zhangjin Wu wrote:
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index f42adef87e12..9576f1a0a98d 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -39,6 +39,9 @@ DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig DEFCONFIG = $(DEFCONFIG_$(ARCH)) +# extra kernel config files under configs/, include common + architecture specific +EXTCONFIG = common.config $(ARCH).config
As this series seems to need a respin anyways:
extconfig means "extended config", correct? That is fairly nondescript.
It is more about 'extra' as commented (or 'additional'), for both defconfig (may) and tinyconfig (must) require more options to make boot and print work for nolibc-test. defconfig ------\ \ \ EXTCONFIG ----> a working .config for nolibc-test / / tinyconfig------/
I would prefer something like "NOLIBC_TEST_CONFIG"
Using NOLIBC_TEST_CONFIG is ok, but with this name, do we still only put the 'additional' options there? or we simply use EXTRA_CONFIG instead?
# extra kernel config files under configs/, include common + architecture specific EXTRA_CONFIG = common.config $(ARCH).config
Either are fine to me. The most important is to mention that these configs are appended to the config during the defconfig and tinyconfig targets.
Ok, will update the comment to something like this:
# extra configs/ files appended to .config during the defconfig and tinyconfig targets # include common parts + architecture specific parts EXTRA_CONFIG = common.config $(ARCH).config
Also I find it odd to use $(ARCH) here, I would have expected $(XARCH) since you probably want to distinguish ppc64 from ppc for example.
Yes, we do, but the XARCH and ARCH mmapping patch is the 4th, will update this to XARCH, this one is the 3th one, do we need to add this one after the 4th one?
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config:
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
I think that as long as we don't claim to call topdir's makefile targets from this directory, we can reuse some similarly named targets which are documented in "make help" and are non-ambiguous.
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
Currently, we use 'defconfig' by default and we use 'make defconfig DEFCONFIG=tinyconfig' to switch to tinyconfig, in the next weeks, when all of the nolibc supported architectures have tinyconfig support, it is able to switch 'tinyconfig' as the default config target.
As long as it doesn't require to locally maintain too many options, I think I'm fine with that. But we'll see.
Ok.
Thanks, Zhangjin
Willy
On Sun, Jul 30, 2023 at 12:54:45AM +0800, Zhangjin Wu wrote:
Also I find it odd to use $(ARCH) here, I would have expected $(XARCH) since you probably want to distinguish ppc64 from ppc for example.
Yes, we do, but the XARCH and ARCH mmapping patch is the 4th, will update this to XARCH, this one is the 3th one, do we need to add this one after the 4th one?
OK indeed it's the 4th one that will modify this one then, no need to reorder.
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config:
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
I think that as long as we don't claim to call topdir's makefile targets from this directory, we can reuse some similarly named targets which are documented in "make help" and are non-ambiguous.
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
As a user, I'd ask "why not make tinyconfig" ? But see my other message, now I'm having strong doubts about the relevance of tinyconfig if it works as bad as you described it.
Willy
On Sun, Jul 30, 2023 at 12:54:45AM +0800, Zhangjin Wu wrote:
Also I find it odd to use $(ARCH) here, I would have expected $(XARCH) since you probably want to distinguish ppc64 from ppc for example.
Yes, we do, but the XARCH and ARCH mmapping patch is the 4th, will update this to XARCH, this one is the 3rd one, do we need to add this one after the 4th one?
OK indeed it's the 4th one that will modify this one then, no need to reorder.
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config:
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
I think that as long as we don't claim to call topdir's makefile targets from this directory, we can reuse some similarly named targets which are documented in "make help" and are non-ambiguous.
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
As a user, I'd ask "why not make tinyconfig" ? But see my other message, now I'm having strong doubts about the relevance of tinyconfig if it works as bad as you described it.
I have added a nolibc tinyconfig target before, as the same reason, based on your suggestion, I have removed the tinyconfig target and even moved the extconfig to this defconfig to avoid add more similar or extra complex targets in nolibc Makefile. before, tinyconfig + extconfig together work for nolibc-test, so, tinyconfig is the same as the top-level one, it should be removed as your suggested.
But since now, we are ready to get a real different target from the top-level one, we may be able to have different targets for 'defconfig+EXTRA_CONFIG' and 'tinyconfig+EXTRA_CONFIG' like this:
nolibc-test-config: $(Q)echo $(MAKE_KERNEL) mrproper $(or $(CONFIG),defconfig) $(Q)echo $(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)echo $(MAKE_KERNEL) KCONFIG_ALLCONFIG="$(KERNEL_CONFIG)" allnoconfig $(Q)echo $(MAKE_KERNEL) prepare
nolibc-test-defconfig nolibc-test-tinyconfig: nolibc-test-config nolibc-test-tinyconfig: CONFIG=tinyconfig
The complexity here is we have planned to support both defconfig and tinyconfig, what about this solution?
Thanks, Zhangjin
Willy
Hi, Willy, Thomas
On Sun, Jul 30, 2023 at 12:54:45AM +0800, Zhangjin Wu wrote:
Also I find it odd to use $(ARCH) here, I would have expected $(XARCH) since you probably want to distinguish ppc64 from ppc for example.
Yes, we do, but the XARCH and ARCH mmapping patch is the 4th, will update this to XARCH, this one is the 3rd one, do we need to add this one after the 4th one?
OK indeed it's the 4th one that will modify this one then, no need to reorder.
something like "make nolibctestconfig" to make an existing config ready for nolibc-test.
Do you mean rename 'defconfig' to 'nolibctestconfig'? or something nolibc-test-config:
nolibc-test-config:
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -O "$(srctree)" -m "$(srctree)/.config" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) KCONFIG_ALLCONFIG="$(srctree)/.config" allnoconfig
It looks too long ;-)
I think that as long as we don't claim to call topdir's makefile targets from this directory, we can reuse some similarly named targets which are documented in "make help" and are non-ambiguous.
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
As a user, I'd ask "why not make tinyconfig" ? But see my other message, now I'm having strong doubts about the relevance of tinyconfig if it works as bad as you described it.
I have added a nolibc tinyconfig target before, as the same reason, based on your suggestion, I have removed the tinyconfig target and even moved the extconfig to this defconfig to avoid add more similar or extra complex targets in nolibc Makefile. before, tinyconfig + extconfig together work for nolibc-test, so, tinyconfig is the same as the top-level one, it should be removed as your suggested.
But since now, we are ready to get a real different target from the top-level one, we may be able to have different targets for 'defconfig+EXTRA_CONFIG' and 'tinyconfig+EXTRA_CONFIG' like this:
nolibc-test-config: $(Q)echo $(MAKE_KERNEL) mrproper $(or $(CONFIG),defconfig)
It should be $(or $(CONFIG),$(DEFCONFIG))
$(Q)echo $(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)echo $(MAKE_KERNEL) KCONFIG_ALLCONFIG="$(KERNEL_CONFIG)" allnoconfig $(Q)echo $(MAKE_KERNEL) prepare nolibc-test-defconfig nolibc-test-tinyconfig: nolibc-test-config nolibc-test-tinyconfig: CONFIG=tinyconfig
The above two are not really required in this powerpc series, let's delay them to the next tinyconfig part1 series.
In this series, we only need:
nolibc-test-config: $(Q)$(MAKE_KERNEL) mrproper $(or $(CONFIG),$(DEFCONFIG)) $(Q)$(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE_KERNEL) KCONFIG_ALLCONFIG="$(KERNEL_CONFIG)" allnoconfig $(Q)$(MAKE_KERNEL) prepare
And this:
# extra configs/ files appended to .config during the nolibc-test-config target # include common + architecture specific EXTRA_CONFIG = common.config $(XARCH).config
And the update of the help target too.
If both of you are happy with this? let's do it ;-)
Best regards, Zhangjin
The complexity here is we have planned to support both defconfig and tinyconfig, what about this solution?
Thanks, Zhangjin
Willy
Hi Zhangjin,
On Sun, Jul 30, 2023 at 02:01:31PM +0800, Zhangjin Wu wrote:
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
As a user, I'd ask "why not make tinyconfig" ? But see my other message, now I'm having strong doubts about the relevance of tinyconfig if it works as bad as you described it.
I have added a nolibc tinyconfig target before, as the same reason, based on your suggestion, I have removed the tinyconfig target and even moved the extconfig to this defconfig to avoid add more similar or extra complex targets in nolibc Makefile. before, tinyconfig + extconfig together work for nolibc-test, so, tinyconfig is the same as the top-level one, it should be removed as your suggested.
But since now, we are ready to get a real different target from the top-level one, we may be able to have different targets for 'defconfig+EXTRA_CONFIG' and 'tinyconfig+EXTRA_CONFIG' like this:
nolibc-test-config: $(Q)echo $(MAKE_KERNEL) mrproper $(or $(CONFIG),defconfig)
It should be $(or $(CONFIG),$(DEFCONFIG))
$(Q)echo $(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)echo $(MAKE_KERNEL) KCONFIG_ALLCONFIG="$(KERNEL_CONFIG)" allnoconfig $(Q)echo $(MAKE_KERNEL) prepare nolibc-test-defconfig nolibc-test-tinyconfig: nolibc-test-config nolibc-test-tinyconfig: CONFIG=tinyconfig
The above two are not really required in this powerpc series, let's delay them to the next tinyconfig part1 series.
In this series, we only need:
nolibc-test-config: $(Q)$(MAKE_KERNEL) mrproper $(or $(CONFIG),$(DEFCONFIG)) $(Q)$(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(EXTRA_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE_KERNEL) KCONFIG_ALLCONFIG="$(KERNEL_CONFIG)" allnoconfig $(Q)$(MAKE_KERNEL) prepare
And this:
# extra configs/ files appended to .config during the nolibc-test-config target # include common + architecture specific EXTRA_CONFIG = common.config $(XARCH).config
And the update of the help target too.
If both of you are happy with this? let's do it ;-)
Well, I understand "nolibc-test-config" as "the config suitable to correctly run nolibc-test". In that case I agree. We can indeed start from the defconfig, and if we manage to refine it we can later map it to anything else that's known to work. And if we eventually split nolibc-test into multiple tests (libc, syscalls, ipc, network, whatever) then we might as well adopt different configs in the future. I'd also want to keep defconfig on its own because it relies on each arch's defconfig and is a simple way to verify they work (as they should). As I said, till now I haven't met issues with defconfig so probably we don't need to patch it, but we could revisit that option later if needed.
I'm still having that question about your "make allnoconfig" at the end, which for me simply replaces the config you've just created, thus which makes no sense. There might be a trick that I'm missing but if so it should be explained there because the only situation where anybody should start a question with "why" when reading code is when they discovered a bug.
Also please split the mrproper and defconfig on two distinc lines, as there's no point anymore in keeping them as a single one.
Since you're using the extra options for nolibc-test-config, I think they should be called "nolibc-test-common.config" and "nolibc-test-$XARCH.config" so that we don't restart with tons of "if" and macros when adding a new target.
Thomas, are you also OK with this ?
Thanks, Willy
On Sun, Jul 30, 2023 at 02:01:31PM +0800, Zhangjin Wu wrote:
Seems 'nolibc-test-config' is really more meaningful than 'defconfig', especially when we want to use tinyconfig through it?
$ make nolibc-test-config DEFCONFIG=tinyconfig
[...]
And this:
# extra configs/ files appended to .config during the nolibc-test-config target # include common + architecture specific EXTRA_CONFIG = common.config $(XARCH).config
And the update of the help target too.
If both of you are happy with this? let's do it ;-)
Well, I understand "nolibc-test-config" as "the config suitable to correctly run nolibc-test". In that case I agree. We can indeed start from the defconfig, and if we manage to refine it we can later map it to anything else that's known to work. And if we eventually split nolibc-test into multiple tests (libc, syscalls, ipc, network, whatever) then we might as well adopt different configs in the future. I'd also
Agree, with this info, I do like nolibc-test-config, let's align all related with nolibc-test- prefix and NOLIBC_TEST_CONFIG too ;-)
I have thought about a simpler 'config' target for both tinyconfig and defconfig before, but I'm worried about the same issue mentioned by Willy, it may conflict with the one from top-level Makefile.
With exact nolibc-test prefix, it is better.
want to keep defconfig on its own because it relies on each arch's defconfig and is a simple way to verify they work (as they should). As I said, till now I haven't met issues with defconfig so probably we don't need to patch it, but we could revisit that option later if needed.
No Willy, this patch here is not originally for tinyconfig, is for pmac32_defconfig used by the default ppc32 qemu machine has no builtin console, it is configured as a module:
CONFIG_SERIAL_8250=m CONFIG_SERIAL_PMACZILOG=m CONFIG_SERIAL_PMACZILOG_TTYS=y
This is why we also need to add such extra logic also for defconfig target. Another solution is ask the kernel maintainer to switch the =m to =y, but as we discussed before, it is better to depends on the kernel part, so, an extra logic is used here for better flexibility and less dependency.
If we still to reserve the 'defconfig' target, is this ok for you?
defconfig: nolibc-test-config
Or
nolibc-test-defconfig: nolibc-test-config
Which one do you like? If 'defconfig', the one for tinyconfig may also better to use 'tinyconfig':
tinyconfig defconfig: nolibc-test-config tinyconfig: CONFIG=tinyconfig
Otherwise,
nolibc-test-tinyconfig nolibc-test-defconfig: nolibc-test-config nolibc-test-tinyconfig: CONFIG=tinyconfig
I'm ok with anyone of them (note, the tinyconfig related parts will not be really added here), what about you?
I'm still having that question about your "make allnoconfig" at the end, which for me simply replaces the config you've just created, thus which makes no sense. There might be a trick that I'm missing but if so it should be explained there because the only situation where anybody should start a question with "why" when reading code is when they discovered a bug.
Yeah, the name of allnoconfig doesn't confuse a little, to simplify it a lot, let's simply use 'olddefconfig' (as 'oldconfig' you suggested in another replay, but without prompt and silently set new options as default) instead?
Also please split the mrproper and defconfig on two distinc lines, as there's no point anymore in keeping them as a single one.
Yeah, it is better.
Since you're using the extra options for nolibc-test-config, I think they should be called "nolibc-test-common.config" and "nolibc-test-$XARCH.config" so that we don't restart with tons of "if" and macros when adding a new target.
Done.
Btw, since this one does have some relationship with another three patches (two are from tinyconfig part1, like the XARCH you mentioned two times), in order to make them more fast forward, I have reorder them to make things clear.
* selftests/nolibc: fix up O= option support
Fix up the wrong srctree previously used, then, we can use objtree directly in this patch.
* selftests/nolibc: add macros to reduce duplicated changes
Some of the macros are heavily used in our new nolibc-test-config target, for we require to split mrproper and prepare into more lines, shorter macros prepared earlier does help this.
* selftests/nolibc: add XARCH and ARCH mapping support
Add this one earlier, then, our patch can use the XARCH directly.
As you suggested, If no other opposite, another two about CROSS_COMPILE will be moved to this powerpc series too:
* selftests/nolibc: allow customize CROSS_COMPILE by architecture * selftests/nolibc: customize CROSS_COMPILE for 32/64-bit powerpc
At last, here is it?
# extra configs/ files appended to .config during the nolibc-test-config target # include common + architecture specific NOLIBC_TEST_CONFIG = nolibc-test-common.config nolibc-test-$(XARCH).config
nolibc-test-config: $(Q)$(MAKE_KERNEL) mrproper $(Q)$(MAKE_KERNEL) $(or $(CONFIG),$(DEFCONFIG)) prepare $(Q)$(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(NOLIBC_TEST_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE_KERNEL) olddefconfig $(Q)$(MAKE_KERNEL) prepare
defconfig: nolibc-test-config
The last line still depends on your confirm.
Without more issues, I will renew this patchset as v4, thanks very much!
(will update the XARCH patch to get your confirm in another reply too)
Best regards, Zhangjin
Thomas, are you also OK with this ?
Thanks, Willy
Hi,
At last, here is it?
# extra configs/ files appended to .config during the nolibc-test-config target # include common + architecture specific NOLIBC_TEST_CONFIG = nolibc-test-common.config nolibc-test-$(XARCH).config nolibc-test-config:
$(Q)$(MAKE_KERNEL) mrproper $(Q)$(MAKE_KERNEL) $(or $(CONFIG),$(DEFCONFIG)) prepare
The 'prepare' should be removed, we have one in the end.
$(Q)$(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(NOLIBC_TEST_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE_KERNEL) olddefconfig
Oh, sorry, test shows, 'allnoconfig' worth a comment ;-)
'allnoconfig' is ~2x faster than 'olddefconfig', it is more deterministic for it set all new symbols (the ones not specified in .config) with no.
// scripts/kconfig/Makefile
@echo ' oldconfig - Update current config utilising a provided .config as base' @echo ' defconfig - New config with default from ARCH supplied defconfig' @echo ' allnoconfig - New config where all options are answered with no' @echo ' allyesconfig - New config where all options are accepted with yes' @echo ' olddefconfig - Same as oldconfig but sets new symbols to their' @echo ' default value without prompting'
here is the result:
// with 'allnoconfig' $ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'; arch=ppc; time make tinyconfig kernel -C tools/testing/selftests/nolibc CONFIG=tinyconfig XARCH=$arch O=$PWD/kernel-$arch real 3m37.337s user 3m11.576s sys 0m16.899s
// with 'olddefconfig' $ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'; arch=ppc; time make tinyconfig kernel -C tools/testing/selftests/nolibc CONFIG=tinyconfig XARCH=$arch O=$PWD/kernel-$arch real 5m28.759s user 4m47.873s sys 0m30.115s
// with 'defconfig'
Both merge_tools.sh and tinyconfig target use 'allnoconfig', the usage is clear enough, no risk:
scripts/kconfig/merge_config.sh:
# Use the merged file as the starting point for: # alldefconfig: Fills in any missing symbols with Kconfig default # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
scripts/kconfig/Makefile:
tinyconfig: $(Q)KCONFIG_ALLCONFIG=kernel/configs/tiny-base.config $(MAKE) -f $(srctree)/Makefile allnoconfig $(Q)$(MAKE) -f $(srctree)/Makefile tiny.config
And also since I have carefully test 'allnoconfig' for all of the nolibc supported architectures, it is not good to waste time to test 'olddefconfig'. 'allnoconfig' is also more deterministic than 'olddefconfig' since it only enable the options specified by us explicitly, so, no new symbols will be randomly enabled.
I plan to add more comments before 'nolibc-test-config':
# kernel config for nolibc-test # # - delete the current configuration and all generated files via 'mrproper' target # - generate .config via '$(CONFIG)' or '$(DEFCONFIG_$(XARCH))' target # - merge extra config options from $(NOLIBC_TEST_CONFIG) files to .config # - use merged .config as base and fills in any missing symbols with '# CONFIG_* is not set' via 'allnoconfig' target # - prepare things we need to do before we recursively start building the kernel via 'prepare' target #
nolibc-test-config: $(Q)$(MAKE_KERNEL) mrproper $(Q)$(MAKE_KERNEL) $(or $(CONFIG),$(DEFCONFIG)) $(Q)$(srctree)/scripts/kconfig/merge_config.sh -Q -O "$(objtree)" -m "$(KERNEL_CONFIG)" $(foreach c,$(NOLIBC_TEST_CONFIG),$(wildcard $(CURDIR)/configs/$c)) $(Q)$(MAKE_KERNEL) KCONFIG_ALLCONFIG=$(KERNEL_CONFIG) allnoconfig $(Q)$(MAKE_KERNEL) prepare
$(Q)$(MAKE_KERNEL) prepare
defconfig: nolibc-test-config
The last line still depends on your confirm.
Without more issues, I will renew this patchset as v4, thanks very much!
(will update the XARCH patch to get your confirm in another reply too)
Best regards, Zhangjin
Most of the CPU architectures have different variants, but kernel usually only accepts parts of them via the ARCH variable, the others should be customized via kernel config files.
To simplify testing, the external ARCH variable is extended to accept more CPU variants from user's input, a new internal XARCH variable is added to save users' ARCH input and used to customize variant specific variables, at last XARCH is converted to the internal ARCH variable acceptable by kernel:
e.g. make run ARCH=<one of the supported variants> / v external ARCH from cmdline -> internal XARCH -> internal ARCH for kernel | `--> variant specific variables
XARCH and ARCH are carefully mapped to allow users to pass architecture variants via external ARCH (or XARCH) from cmdline:
- From developers' perspective
- XARCH records the architecture variant from user's ARCH input, after 'override ARCH', ARCH is overridden and mapped from XARCH to the one supported by kernel
- Map from XARCH to the kernel supported ARCH: 'ARCH_<XARCH> = <ARCH>'
- Configure a default variant for kernel supported ARCH: 'XARCH_<ARCH> = <XARCH>'
- From users' perspective
- ARCH (or XARCH) are architecture variants of a target architecture
- the variants are XARCH names from the "ARCH_<XARCH> = <ARCH>" mapping list
PowerPC is the first user and also a very good reference architecture of this mapping, it has variants with different combinations of 32-bit/64-bit and bit endian/little endian.
To use this mapping, the other architectures can refer to PowerPC, If the target architecture only has one variant, XARCH is simply an alias of ARCH, no additional mapping required.
Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/lkml/20230702171715.GD16233@1wt.eu/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 9576f1a0a98d..5afb3e7d7723 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -14,6 +14,14 @@ include $(srctree)/scripts/subarch.include ARCH = $(SUBARCH) endif
+# XARCH is used to save user-input ARCH variant +# configure default variants for target kernel supported architectures +XARCH := $(or $(XARCH_$(ARCH)),$(ARCH)) + +# ARCH is supported by kernel +# map from user input variants to their kernel supported architectures +override ARCH := $(or $(ARCH_$(XARCH)),$(XARCH)) + # kernel image names by architecture IMAGE_i386 = arch/x86/boot/bzImage IMAGE_x86_64 = arch/x86/boot/bzImage @@ -24,7 +32,7 @@ IMAGE_mips = vmlinuz IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi -IMAGE = $(IMAGE_$(ARCH)) +IMAGE = $(IMAGE_$(XARCH)) IMAGE_NAME = $(notdir $(IMAGE))
# default kernel configurations that appear to be usable @@ -37,10 +45,10 @@ DEFCONFIG_mips = malta_defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig -DEFCONFIG = $(DEFCONFIG_$(ARCH)) +DEFCONFIG = $(DEFCONFIG_$(XARCH))
# extra kernel config files under configs/, include common + architecture specific -EXTCONFIG = common.config $(ARCH).config +EXTCONFIG = common.config $(XARCH).config
# optional tests to run (default = all) TEST = @@ -55,7 +63,7 @@ QEMU_ARCH_mips = mipsel # works with malta_defconfig QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x QEMU_ARCH_loongarch = loongarch64 -QEMU_ARCH = $(QEMU_ARCH_$(ARCH)) +QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
# QEMU_ARGS : some arch-specific args to pass to qemu QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -67,7 +75,7 @@ QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" -QEMU_ARGS = $(QEMU_ARGS_$(ARCH)) $(QEMU_ARGS_EXTRA) +QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_EXTRA)
# OUTPUT is only set when run from the main makefile, otherwise # it defaults to this nolibc directory. @@ -84,7 +92,7 @@ CFLAGS_mips = -EL CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ $(call cc-option,-fno-stack-protector) \ - $(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR) + $(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) LDFLAGS := -s
REPORT ?= awk '/[OK][\r]*$$/{p++} /[FAIL][\r]*$$/{if (!f) printf("\n"); f++; print;} /[SKIPPED][\r]*$$/{s++} \ @@ -111,12 +119,13 @@ help: @echo "" @echo "Currently using the following variables:" @echo " ARCH = $(ARCH)" + @echo " XARCH = $(XARCH)" @echo " CROSS_COMPILE = $(CROSS_COMPILE)" @echo " CC = $(CC)" @echo " OUTPUT = $(OUTPUT)" @echo " TEST = $(TEST)" - @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from $$ARCH]" - @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from $$ARCH]" + @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from $$XARCH]" + @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from $$XARCH]" @echo ""
all: run
Hi, Willy, Thomas
Beside the extra config stuff, here is the left one need your last confirm.
Let's summarize it, without 'override', we are able to use such styles (I added a $(error ARCH=$(ARCH) XARCH=$(XARCH)) line for tmp test):
$ make ARCH=powerpc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop.
$ make ARCH=powerpc XARCH=ppc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=powerpc XARCH=ppc64 Makefile:29: *** ARCH=powerpc, XARCH=ppc64. Stop. $ make ARCH=powerpc XARCH=ppc66le Makefile:29: *** ARCH=powerpc, XARCH=ppc66le. Stop.
$ make XARCH=ppc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make XARCH=ppc64 Makefile:29: *** ARCH=powerpc, XARCH=ppc64. Stop. $ make XARCH=ppc64le Makefile:29: *** ARCH=powerpc, XARCH=ppc64le. Stop.
with 'override', we are further able to use:
$ make ARCH=powerpc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc64 Makefile:29: *** ARCH=powerpc, XARCH=ppc64. Stop. $ make ARCH=ppc64le Makefile:29: *** ARCH=powerpc, XARCH=ppc64le. Stop.
So, with 'override', users will be able to directly use the famous ARCH, it is able to accept powerpc, ppc, ppc64, ppc64le and users can simply ignore XARCH and we are able to only use XARCH as an internal variable to temply save input ARCH and then convert it to an internal ARCH.
Without 'override', we must carefully document its usage, it may be:
# XARCH and ARCH mapping # # Usage: # $ make ARCH=<kernel-supported-ARCH> XARCH=<nolibc-test-supported-variants> ... # # e.g. make ARCH=powerpc XARCH=[ppc|ppc64|ppc64le]
# XARCH is used to save user-input ARCH variant # configure default variants for target kernel supported architectures
For the help page, if we only use '$$XARCH or $$ARCH', it may mislead users:
@echo " run-user runs the executable under QEMU (uses $$ARCH or \$XARCH, $$TEST)"
That's why I at last add the 'override' keyword to make sure even if users wrongly and only use ARCH as the argument, it must not fail, or we forcely ask user pass ARCH and XARCH together.
@echo " run-user runs the executable under QEMU (uses $$ARCH and \$XARCH, $$TEST)"
Or we simply only and always ask users to use XARCH (as the first version does) for nolibc-test and let ARCH as the default one from a previous build kernel:
@echo " run-user runs the executable under QEMU (uses $$XARCH, $$TEST)"
That means, the ugly 'override' does help us to save lots of teach work ;-)
I'm ok with 'override' or not, welcome your confirm, which direction do you prefer?
Thanks, Zhangjin
Most of the CPU architectures have different variants, but kernel usually only accepts parts of them via the ARCH variable, the others should be customized via kernel config files.
To simplify testing, the external ARCH variable is extended to accept more CPU variants from user's input, a new internal XARCH variable is added to save users' ARCH input and used to customize variant specific variables, at last XARCH is converted to the internal ARCH variable acceptable by kernel:
e.g. make run ARCH=<one of the supported variants> / v external ARCH from cmdline -> internal XARCH -> internal ARCH for kernel | `--> variant specific variables
XARCH and ARCH are carefully mapped to allow users to pass architecture variants via external ARCH (or XARCH) from cmdline:
From developers' perspective
XARCH records the architecture variant from user's ARCH input, after 'override ARCH', ARCH is overridden and mapped from XARCH to the one supported by kernel
Map from XARCH to the kernel supported ARCH: 'ARCH_<XARCH> = <ARCH>'
Configure a default variant for kernel supported ARCH: 'XARCH_<ARCH> = <XARCH>'
From users' perspective
ARCH (or XARCH) are architecture variants of a target architecture
the variants are XARCH names from the "ARCH_<XARCH> = <ARCH>" mapping list
PowerPC is the first user and also a very good reference architecture of this mapping, it has variants with different combinations of 32-bit/64-bit and bit endian/little endian.
To use this mapping, the other architectures can refer to PowerPC, If the target architecture only has one variant, XARCH is simply an alias of ARCH, no additional mapping required.
Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/lkml/20230702171715.GD16233@1wt.eu/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org
tools/testing/selftests/nolibc/Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 9576f1a0a98d..5afb3e7d7723 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -14,6 +14,14 @@ include $(srctree)/scripts/subarch.include ARCH = $(SUBARCH) endif +# XARCH is used to save user-input ARCH variant +# configure default variants for target kernel supported architectures +XARCH := $(or $(XARCH_$(ARCH)),$(ARCH))
+# ARCH is supported by kernel +# map from user input variants to their kernel supported architectures +override ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
# kernel image names by architecture IMAGE_i386 = arch/x86/boot/bzImage IMAGE_x86_64 = arch/x86/boot/bzImage @@ -24,7 +32,7 @@ IMAGE_mips = vmlinuz IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi -IMAGE = $(IMAGE_$(ARCH)) +IMAGE = $(IMAGE_$(XARCH)) IMAGE_NAME = $(notdir $(IMAGE)) # default kernel configurations that appear to be usable @@ -37,10 +45,10 @@ DEFCONFIG_mips = malta_defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig -DEFCONFIG = $(DEFCONFIG_$(ARCH)) +DEFCONFIG = $(DEFCONFIG_$(XARCH)) # extra kernel config files under configs/, include common + architecture specific -EXTCONFIG = common.config $(ARCH).config +EXTCONFIG = common.config $(XARCH).config # optional tests to run (default = all) TEST = @@ -55,7 +63,7 @@ QEMU_ARCH_mips = mipsel # works with malta_defconfig QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x QEMU_ARCH_loongarch = loongarch64 -QEMU_ARCH = $(QEMU_ARCH_$(ARCH)) +QEMU_ARCH = $(QEMU_ARCH_$(XARCH)) # QEMU_ARGS : some arch-specific args to pass to qemu QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -67,7 +75,7 @@ QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" -QEMU_ARGS = $(QEMU_ARGS_$(ARCH)) $(QEMU_ARGS_EXTRA) +QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_EXTRA) # OUTPUT is only set when run from the main makefile, otherwise # it defaults to this nolibc directory. @@ -84,7 +92,7 @@ CFLAGS_mips = -EL CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ $(call cc-option,-fno-stack-protector) \
$(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR)
$(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR)
LDFLAGS := -s REPORT ?= awk '/[OK][\r]*$$/{p++} /[FAIL][\r]*$$/{if (!f) printf("\n"); f++; print;} /[SKIPPED][\r]*$$/{s++} \ @@ -111,12 +119,13 @@ help: @echo "" @echo "Currently using the following variables:" @echo " ARCH = $(ARCH)"
- @echo " XARCH = $(XARCH)" @echo " CROSS_COMPILE = $(CROSS_COMPILE)" @echo " CC = $(CC)" @echo " OUTPUT = $(OUTPUT)" @echo " TEST = $(TEST)"
- @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from $$ARCH]"
- @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from $$ARCH]"
- @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from $$XARCH]"
- @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from $$XARCH]" @echo ""
all: run -- 2.25.1
On Sun, Jul 30, 2023 at 02:38:18PM +0800, Zhangjin Wu wrote:
with 'override', we are further able to use:
$ make ARCH=powerpc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc64 Makefile:29: *** ARCH=powerpc, XARCH=ppc64. Stop. $ make ARCH=ppc64le Makefile:29: *** ARCH=powerpc, XARCH=ppc64le. Stop.
So, with 'override', users will be able to directly use the famous ARCH, it is able to accept powerpc, ppc, ppc64, ppc64le and users can simply ignore XARCH and we are able to only use XARCH as an internal variable to temply save input ARCH and then convert it to an internal ARCH.
But it's extremely confusing as you can see above: the user passes one value and another one is found instead inside the makefile. Initially I said that I didn't want that we'd put incorrect values in ARCH so that it could be properly propagated through the various makefile layers and include files, and that led to XARCH.
Without 'override', we must carefully document its usage, it may be:
# XARCH and ARCH mapping # # Usage: # $ make ARCH=<kernel-supported-ARCH> XARCH=<nolibc-test-supported-variants> ... # # e.g. make ARCH=powerpc XARCH=[ppc|ppc64|ppc64le]
Please let's do much simpler:
# XARCH extends the kernel's ARCH with a few variants of the same # architecture that only differ by the configuration, the toolchain # and the Qemu program used. It is copied as-is into ARCH except for # a few specific values which are mapped like this: # XARCH ARCH config # ppc powerpc 32 bits # ppc64 powerpc 64 bits big endian # ppc64le powerpc 64 bits little endian # # It is recommended to only use XARCH, though it does not harm if # ARCH is already set. For simplicity, ARCH is sufficient for all # architectures where both are equal.
This way we'll even have the luxury of adding armv5, armv7 and thumb2 if we want.
# XARCH is used to save user-input ARCH variant # configure default variants for target kernel supported architectures
For the help page, if we only use '$$XARCH or $$ARCH', it may mislead users:
@echo " run-user runs the executable under QEMU (uses $$ARCH or \$XARCH, $$TEST)"
That's why I at last add the 'override' keyword to make sure even if users wrongly and only use ARCH as the argument, it must not fail, or we forcely ask user pass ARCH and XARCH together.
@echo " run-user runs the executable under QEMU (uses $$ARCH and \$XARCH, $$TEST)"
Or we simply only and always ask users to use XARCH (as the first version does) for nolibc-test and let ARCH as the default one from a previous build kernel:
@echo " run-user runs the executable under QEMU (uses $$XARCH, $$TEST)"
No, no, no, we don't use some defaults from a previous build. That makes problems much harder to debug and reproduce. However I'm fine with only indicating that QEMU uses XARCH if you want.
That means, the ugly 'override' does help us to save lots of teach work ;-)
Precisely not. In my opinion you focus a lot on first use but not enough on troubleshooting. If someone wastes 20 minutes because they didn't want to take 20 seconds to read a help message, it's their problem. But if someones wastes one hour trying to debug a horribly inconsistent makefile that modifies their most critical variables along the execution, and they have to figure how to insert their stuff there to be accepted by the code, it's not respectful of their time and it becomes our problem.
I'm ok with 'override' or not, welcome your confirm, which direction do you prefer?
The one with least complications and which doesn't override ARCH. Also please remember the example I provided where the test can be fired from the top dir where ARCH has a well-defined set of values. You found yourself inconvenient to have to change it between commands and that's why you were trying to add menuconfig here to work around this problem.
Thanks, Willy
Hi, Willy
On Sun, Jul 30, 2023 at 02:38:18PM +0800, Zhangjin Wu wrote:
with 'override', we are further able to use:
$ make ARCH=powerpc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc Makefile:29: *** ARCH=powerpc, XARCH=ppc. Stop. $ make ARCH=ppc64 Makefile:29: *** ARCH=powerpc, XARCH=ppc64. Stop. $ make ARCH=ppc64le Makefile:29: *** ARCH=powerpc, XARCH=ppc64le. Stop.
So, with 'override', users will be able to directly use the famous ARCH, it is able to accept powerpc, ppc, ppc64, ppc64le and users can simply ignore XARCH and we are able to only use XARCH as an internal variable to temply save input ARCH and then convert it to an internal ARCH.
But it's extremely confusing as you can see above: the user passes one value and another one is found instead inside the makefile.
Yeah, there really is some deviation and confusion.
Initially I said that I didn't want that we'd put incorrect values in ARCH so that it could be properly propagated through the various makefile layers and include files, and that led to XARCH.
I remember the good trick to set a default variant for ARCH.
Without 'override', we must carefully document its usage, it may be:
# XARCH and ARCH mapping # # Usage: # $ make ARCH=<kernel-supported-ARCH> XARCH=<nolibc-test-supported-variants> ... # # e.g. make ARCH=powerpc XARCH=[ppc|ppc64|ppc64le]
Please let's do much simpler:
# XARCH extends the kernel's ARCH with a few variants of the same # architecture that only differ by the configuration, the toolchain # and the Qemu program used. It is copied as-is into ARCH except for # a few specific values which are mapped like this: # XARCH ARCH config # ppc powerpc 32 bits # ppc64 powerpc 64 bits big endian # ppc64le powerpc 64 bits little endian # # It is recommended to only use XARCH, though it does not harm if # ARCH is already set. For simplicity, ARCH is sufficient for all # architectures where both are equal.
It is clearer enough, applied.
# XARCH extends the kernel's ARCH with a few variants of the same # architecture that only differ by the configuration, the toolchain # and the Qemu program used. It is copied as-is into ARCH except for # a few specific values which are mapped like this: # # XARCH | ARCH | config # -------------|-----------|------------------------- # ppc | powerpc | 32 bits # ppc64 | powerpc | 64 bits big endian # ppc64le | powerpc | 64 bits little endian # # It is recommended to only use XARCH, though it does not harm if # ARCH is already set. For simplicity, ARCH is sufficient for all # architectures where both are equal.
# configure default variants for target kernel supported architectures XARCH_powerpc = ppc XARCH = $(or $(XARCH_$(ARCH)),$(ARCH))
# map from user input variants to their kernel supported architectures ARCH_ppc = powerpc ARCH_ppc64 = powerpc ARCH_ppc64le = powerpc ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
Any more discovery?
Note, ':=' above is required to fix up the 'recusive' warning when no ARCH passed for the default x86.
This way we'll even have the luxury of adding armv5, armv7 and thumb2 if we want.
# XARCH is used to save user-input ARCH variant # configure default variants for target kernel supported architectures
For the help page, if we only use '$$XARCH or $$ARCH', it may mislead users:
@echo " run-user runs the executable under QEMU (uses $$ARCH or \$XARCH, $$TEST)"
That's why I at last add the 'override' keyword to make sure even if users wrongly and only use ARCH as the argument, it must not fail, or we forcely ask user pass ARCH and XARCH together.
@echo " run-user runs the executable under QEMU (uses $$ARCH and \$XARCH, $$TEST)"
Or we simply only and always ask users to use XARCH (as the first version does) for nolibc-test and let ARCH as the default one from a previous build kernel:
@echo " run-user runs the executable under QEMU (uses $$XARCH, $$TEST)"
No, no, no, we don't use some defaults from a previous build. That makes problems much harder to debug and reproduce. However I'm fine with only indicating that QEMU uses XARCH if you want.
Ok, hope I have not misunderstood again ;-) so, here is the latest version I prepared:
help: @echo "Supported targets under selftests/nolibc:" @echo " all call the "run" target below" @echo " help this help" @echo " sysroot create the nolibc sysroot here (uses $$ARCH)" @echo " nolibc-test build the executable (uses $$CC and $$CROSS_COMPILE)" @echo " libc-test build an executable using the compiler's default libc instead" @echo " run-user runs the executable under QEMU (uses $$XARCH, $$TEST)" @echo " initramfs prepare the initramfs with nolibc-test" @echo " defconfig create a fresh new default config (uses $$XARCH)" @echo " kernel (re)build the kernel with the initramfs (uses $$XARCH)" @echo " run runs the kernel in QEMU after building it (uses $$XARCH, $$TEST)" @echo " rerun runs a previously prebuilt kernel in QEMU (uses $$XARCH, $$TEST)" @echo " clean clean the sysroot, initramfs, build and output files" @echo "" @echo "The output file is "run.out". Test ranges may be passed using $$TEST." @echo "" @echo "Currently using the following variables:" @echo " ARCH = $(ARCH)" @echo " XARCH = $(XARCH)" @echo " CROSS_COMPILE = $(CROSS_COMPILE)" @echo " CC = $(CC)" @echo " OUTPUT = $(OUTPUT)" @echo " TEST = $(TEST)" @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from $$XARCH]" @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from $$XARCH]" @echo ""
That means, the ugly 'override' does help us to save lots of teach work ;-)
Precisely not. In my opinion you focus a lot on first use but not enough on troubleshooting. If someone wastes 20 minutes because they didn't want to take 20 seconds to read a help message, it's their problem. But if someones wastes one hour trying to debug a horribly inconsistent makefile that modifies their most critical variables along the execution, and they have to figure how to insert their stuff there to be accepted by the code, it's not respectful of their time and it becomes our problem.
It is reasonable, we did discuss this before, the critical area is small but is there, so, it may really introduce risks in the future, let's give up 'override' completely.
I'm ok with 'override' or not, welcome your confirm, which direction do you prefer?
The one with least complications and which doesn't override ARCH. Also please remember the example I provided where the test can be fired from the top dir where ARCH has a well-defined set of values. You found yourself inconvenient to have to change it between commands and that's why you were trying to add menuconfig here to work around this problem.
Best regards, Zhangjin
Thanks, Willy
Kernel uses ARCH=powerpc for both 32-bit and 64-bit PowerPC, here adds a ppc variant for 32-bit PowerPC and uses it as the default variant of powerpc architecture.
Users can pass ARCH=powerpc or ARCH=ppc to test 32-bit PowerPC.
The default qemu-system-ppc g3beige machine [1] is used to run 32-bit powerpc kernel.
The pmac32_defconfig is used with extra PMACZILOG console options to enable normal print.
Note, zImage doesn't boot due to "qemu-system-ppc: Some ROM regions are overlapping" error, so, vmlinux is used instead.
[1]: https://qemu.readthedocs.io/en/latest/system/ppc/powermac.html
Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/lkml/ZL9leVOI25S2+0+g@1wt.eu/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/Makefile | 6 ++++++ tools/testing/selftests/nolibc/configs/ppc.config | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 tools/testing/selftests/nolibc/configs/ppc.config
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 5afb3e7d7723..832b9ffcbac4 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -16,10 +16,12 @@ endif
# XARCH is used to save user-input ARCH variant # configure default variants for target kernel supported architectures +XARCH_powerpc = ppc XARCH := $(or $(XARCH_$(ARCH)),$(ARCH))
# ARCH is supported by kernel # map from user input variants to their kernel supported architectures +ARCH_ppc = powerpc override ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
# kernel image names by architecture @@ -29,6 +31,7 @@ IMAGE_x86 = arch/x86/boot/bzImage IMAGE_arm64 = arch/arm64/boot/Image IMAGE_arm = arch/arm/boot/zImage IMAGE_mips = vmlinuz +IMAGE_ppc = vmlinux IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi @@ -42,6 +45,7 @@ DEFCONFIG_x86 = defconfig DEFCONFIG_arm64 = defconfig DEFCONFIG_arm = multi_v7_defconfig DEFCONFIG_mips = malta_defconfig +DEFCONFIG_ppc = pmac32_defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig @@ -60,6 +64,7 @@ QEMU_ARCH_x86 = x86_64 QEMU_ARCH_arm64 = aarch64 QEMU_ARCH_arm = arm QEMU_ARCH_mips = mipsel # works with malta_defconfig +QEMU_ARCH_ppc = ppc QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x QEMU_ARCH_loongarch = loongarch64 @@ -72,6 +77,7 @@ QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $( QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" diff --git a/tools/testing/selftests/nolibc/configs/ppc.config b/tools/testing/selftests/nolibc/configs/ppc.config new file mode 100644 index 000000000000..b1975f8253f7 --- /dev/null +++ b/tools/testing/selftests/nolibc/configs/ppc.config @@ -0,0 +1,3 @@ +CONFIG_SERIAL_PMACZILOG=y +CONFIG_SERIAL_PMACZILOG_TTYS=y +CONFIG_SERIAL_PMACZILOG_CONSOLE=y
Kernel uses ARCH=powerpc for both 32-bit and 64-bit PowerPC, here adds a ppc64le variant for little endian 64-bit PowerPC, users can pass ARCH=ppc64le to test it.
The powernv machine of qemu-system-ppc64le is used for there is just a working powernv_defconfig.
As the document [1] shows:
PowerNV (as Non-Virtualized) is the “bare metal” platform using the OPAL firmware. It runs Linux on IBM and OpenPOWER systems and it can be used as an hypervisor OS, running KVM guests, or simply as a host OS.
Note, since the VSX support may be disabled in kernel side, to avoid "illegal instruction" errors due to missing VSX kernel support, let's simply let compiler not generate vector/scalar (VSX) instructions via the '-mno-vsx' option.
[1]: https://qemu.readthedocs.io/en/latest/system/ppc/powernv.html
Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/lkml/20230722120747.GC17311@1wt.eu/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 832b9ffcbac4..dfc411cd4f10 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -22,6 +22,7 @@ XARCH := $(or $(XARCH_$(ARCH)),$(ARCH)) # ARCH is supported by kernel # map from user input variants to their kernel supported architectures ARCH_ppc = powerpc +ARCH_ppc64le = powerpc override ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
# kernel image names by architecture @@ -32,6 +33,7 @@ IMAGE_arm64 = arch/arm64/boot/Image IMAGE_arm = arch/arm/boot/zImage IMAGE_mips = vmlinuz IMAGE_ppc = vmlinux +IMAGE_ppc64le = arch/powerpc/boot/zImage IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi @@ -46,6 +48,7 @@ DEFCONFIG_arm64 = defconfig DEFCONFIG_arm = multi_v7_defconfig DEFCONFIG_mips = malta_defconfig DEFCONFIG_ppc = pmac32_defconfig +DEFCONFIG_ppc64le = powernv_defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig DEFCONFIG_loongarch = defconfig @@ -65,6 +68,7 @@ QEMU_ARCH_arm64 = aarch64 QEMU_ARCH_arm = arm QEMU_ARCH_mips = mipsel # works with malta_defconfig QEMU_ARCH_ppc = ppc +QEMU_ARCH_ppc64le = ppc64le QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x QEMU_ARCH_loongarch = loongarch64 @@ -78,6 +82,7 @@ QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -93,6 +98,7 @@ else Q=@ endif
+CFLAGS_ppc64le = -m64 -mlittle-endian -Wl,-EL,-melf64ppc -mno-vsx CFLAGS_s390 = -m64 CFLAGS_mips = -EL CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
Kernel uses ARCH=powerpc for both 32-bit and 64-bit PowerPC, here adds a ppc64 variant for big endian 64-bit PowerPC, users can pass ARCH=ppc64 to test it.
The powernv machine of qemu-system-ppc64 is used with powernv_be_defconfig.
As the document [1] shows:
PowerNV (as Non-Virtualized) is the “bare metal” platform using the OPAL firmware. It runs Linux on IBM and OpenPOWER systems and it can be used as an hypervisor OS, running KVM guests, or simply as a host OS.
Notes,
- differs from little endian 64-bit PowerPC, vmlinux is used instead of zImage, because big endian zImage [2] only boot on qemu with x-vof=on (added from qemu v7.0) and a fixup patch [3] for qemu v7.0.51:
- since the VSX support may be disabled in kernel side, to avoid "illegal instruction" errors due to missing VSX kernel support, let's simply let compiler not generate vector/scalar (VSX) instructions via the '-mno-vsx' option.
- as 'man gcc' shows, '-mmultiple' is used to generate code that uses the load multiple word instructions and the store multiple word instructions. Those instructions do not work when the processor is in little-endian mode (except PPC740/PPC750), so, we only enable it for big endian powerpc.
[1]: https://qemu.readthedocs.io/en/latest/system/ppc/powernv.html [2]: https://github.com/linuxppc/issues/issues/402 [3]: https://lore.kernel.org/qemu-devel/20220504065536.3534488-1-aik@ozlabs.ru/
Suggested-by: Willy Tarreau w@1wt.eu Link: https://lore.kernel.org/lkml/20230722121019.GD17311@1wt.eu/ Link: https://lore.kernel.org/lkml/20230719043353.GC5331@1wt.eu/ Reviewed-by: Thomas Weißschuh linux@weissschuh.net Signed-off-by: Zhangjin Wu falcon@tinylab.org --- tools/testing/selftests/nolibc/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index dfc411cd4f10..2e9694370913 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -22,6 +22,7 @@ XARCH := $(or $(XARCH_$(ARCH)),$(ARCH)) # ARCH is supported by kernel # map from user input variants to their kernel supported architectures ARCH_ppc = powerpc +ARCH_ppc64 = powerpc ARCH_ppc64le = powerpc override ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
@@ -33,6 +34,7 @@ IMAGE_arm64 = arch/arm64/boot/Image IMAGE_arm = arch/arm/boot/zImage IMAGE_mips = vmlinuz IMAGE_ppc = vmlinux +IMAGE_ppc64 = vmlinux IMAGE_ppc64le = arch/powerpc/boot/zImage IMAGE_riscv = arch/riscv/boot/Image IMAGE_s390 = arch/s390/boot/bzImage @@ -48,6 +50,7 @@ DEFCONFIG_arm64 = defconfig DEFCONFIG_arm = multi_v7_defconfig DEFCONFIG_mips = malta_defconfig DEFCONFIG_ppc = pmac32_defconfig +DEFCONFIG_ppc64 = powernv_be_defconfig DEFCONFIG_ppc64le = powernv_defconfig DEFCONFIG_riscv = defconfig DEFCONFIG_s390 = defconfig @@ -68,6 +71,7 @@ QEMU_ARCH_arm64 = aarch64 QEMU_ARCH_arm = arm QEMU_ARCH_mips = mipsel # works with malta_defconfig QEMU_ARCH_ppc = ppc +QEMU_ARCH_ppc64 = ppc64 QEMU_ARCH_ppc64le = ppc64le QEMU_ARCH_riscv = riscv64 QEMU_ARCH_s390 = s390x @@ -82,6 +86,7 @@ QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" +QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" @@ -98,6 +103,7 @@ else Q=@ endif
+CFLAGS_ppc64 = -m64 -mbig-endian -Wl,-EB,-melf64ppc -mmultiple -mno-vsx CFLAGS_ppc64le = -m64 -mlittle-endian -Wl,-EL,-melf64ppc -mno-vsx CFLAGS_s390 = -m64 CFLAGS_mips = -EL
linux-kselftest-mirror@lists.linaro.org