* [PATCH 0/5] csky: add shutdown and nolibc support
@ 2024-09-29 21:47 Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 1/5] drivers/virt: introduce csky_exit system poweroff driver Thomas Weißschuh
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
This series adds support for the C-SKY architecture to nolibc.
It is hard to find a usable C-SKY userspace and compiler, so having
support in nolibc provides an easy way to perform tests there.
The nolibc test suite requires system power off support in QEMU,
so a driver for that is added, too.
I'm not sure who is responsible for drivers/virt/ and can take the
driver.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (5):
drivers/virt: introduce csky_exit system poweroff driver
tools/nolibc: provide a fallback for lseek through llseek
selftests/nolibc: add support to use standalone kernels for tests
tools/nolibc: add csky support
selftests/nolibc: skip test for getppid() on csky
drivers/virt/Kconfig | 11 ++
drivers/virt/Makefile | 1 +
drivers/virt/csky_exit.c | 57 ++++++++++
tools/include/nolibc/arch-csky.h | 161 +++++++++++++++++++++++++++
tools/include/nolibc/arch.h | 2 +
tools/include/nolibc/sys.h | 8 ++
tools/testing/selftests/nolibc/Makefile | 21 +++-
tools/testing/selftests/nolibc/nolibc-test.c | 9 +-
8 files changed, 265 insertions(+), 5 deletions(-)
---
base-commit: e7ed343658792771cf1b868df061661b7bcc5cef
change-id: 20240928-nolibc-csky-eff1104825d2
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/5] drivers/virt: introduce csky_exit system poweroff driver
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
@ 2024-09-29 21:47 ` Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 2/5] tools/nolibc: provide a fallback for lseek through llseek Thomas Weißschuh
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
The C-SKY architecture does not support ACPI and no other standardized
mechanism for system poweroff.
On QEMU a virtual device "csky_exit" is available which can be used for
poweroff.
Add a driver for this virtual device.
There are more features provided by the device but these are not
required at this time and therefore not supported yet.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
The OF compatible will never show up in a DTS file, it is synthesized by
QEMU. Therefore I think it doesn't need explicit documentation.
---
drivers/virt/Kconfig | 11 ++++++++++
drivers/virt/Makefile | 1 +
drivers/virt/csky_exit.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index d8c848cf09a6afad65b28be20f5fd7e90a0c5307..652546c52d2e00138a782b949672d47c5f5d2189 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -41,6 +41,17 @@ config FSL_HV_MANAGER
4) A kernel interface for receiving callbacks when a managed
partition shuts down.
+config CSKY_EXIT
+ tristate "C-SKY QEMU shutdown driver"
+ depends on OF
+ depends on CSKY || COMPILE_TEST
+ help
+ This driver supports system shutdown via the virtual csky_exit device
+ provided by QEMU.
+
+ To compile this driver as a module, choose M here: the module will
+ be called csky_exit.
+
source "drivers/virt/vboxguest/Kconfig"
source "drivers/virt/nitro_enclaves/Kconfig"
diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile
index f29901bd782058d3552cdec2c2128ad47ce6fe27..5c62db9fbfa501a31c87c4902f835db91633daeb 100644
--- a/drivers/virt/Makefile
+++ b/drivers/virt/Makefile
@@ -3,6 +3,7 @@
# Makefile for drivers that support virtualization
#
+obj-$(CONFIG_CSKY_EXIT) += csky_exit.o
obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o
obj-$(CONFIG_VMGENID) += vmgenid.o
obj-y += vboxguest/
diff --git a/drivers/virt/csky_exit.c b/drivers/virt/csky_exit.c
new file mode 100644
index 0000000000000000000000000000000000000000..6f42eb74071ab9ac1b7e9ef03b32f9ba0ef2cf26
--- /dev/null
+++ b/drivers/virt/csky_exit.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * C-SKY QEMU shutdown driver
+ *
+ * Copyright (C) 2024 Thomas Weißschuh <linux@weissschuh.net>
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/types.h>
+
+#define CSKY_EXIT_COMMAND_EXIT 0
+
+static void csky_exit_command(void __iomem *base, u32 command, u64 value)
+{
+ writew(value, base + command);
+}
+
+static int csky_exit_poweroff(struct sys_off_data *data)
+{
+ csky_exit_command(data->cb_data, CSKY_EXIT_COMMAND_EXIT, 0);
+ return 0;
+}
+
+static int csky_exit_probe(struct platform_device *pdev)
+{
+ void __iomem *base;
+
+ base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ return devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_PLATFORM + 1,
+ csky_exit_poweroff, base);
+}
+
+static const struct of_device_id csky_exit_match[] = {
+ { .compatible = "csky,qemu-exit" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, csky_exit_match);
+
+static struct platform_driver csky_exit_driver = {
+ .driver.name = "csky_exit",
+ .driver.of_match_table = csky_exit_match,
+ .probe = csky_exit_probe,
+};
+module_platform_driver(csky_exit_driver);
+
+MODULE_AUTHOR("Thomas Weißschuh <linux@weissschuh.net>");
+MODULE_DESCRIPTION("C-SKY QEMU shutdown driver");
+MODULE_LICENSE("GPL");
--
2.46.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/5] tools/nolibc: provide a fallback for lseek through llseek
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 1/5] drivers/virt: introduce csky_exit system poweroff driver Thomas Weißschuh
@ 2024-09-29 21:47 ` Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 3/5] selftests/nolibc: add support to use standalone kernels for tests Thomas Weißschuh
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
Not all architectures implement the lseek syscall, for example csky for
which support will be added.
Provide a fallback implementation to the llseek syscall.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/sys.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 7b82bc3cf107439a3f09f98b99d4d540ffb9ba2a..b3b78343647177c9e5ecb7261997b4f5e03fb8f5 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -595,6 +595,14 @@ off_t sys_lseek(int fd, off_t offset, int whence)
{
#ifdef __NR_lseek
return my_syscall3(__NR_lseek, fd, offset, whence);
+#elif defined(__NR_llseek)
+ off_t result;
+ int ret;
+
+ ret = my_syscall5(__NR_llseek, fd,
+ sizeof(offset) > 4 ? offset >> 32 : 0,
+ offset, &result, whence);
+ return ret ? ret : result;
#else
return __nolibc_enosys(__func__, fd, offset, whence);
#endif
--
2.46.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/5] selftests/nolibc: add support to use standalone kernels for tests
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 1/5] drivers/virt: introduce csky_exit system poweroff driver Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 2/5] tools/nolibc: provide a fallback for lseek through llseek Thomas Weißschuh
@ 2024-09-29 21:47 ` Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 4/5] tools/nolibc: add csky support Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 5/5] selftests/nolibc: skip test for getppid() on csky Thomas Weißschuh
4 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
Not all architectures support loading an initramfs through qemu.
One example is csky for which support is going to be added.
By allowing to build the initramfs into the kernel itself this issue can
be avoided.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/testing/selftests/nolibc/Makefile | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index 8de98ea7af8071caa0597aa7b86d91a2d1d50e68..e8278924cf28f17144044e69724df1d4fde141a3 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -265,14 +265,21 @@ kernel:
kernel-standalone: initramfs
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null
+ifeq ($(QEMU_RUN_STANDALONE_$(XARCH)),)
+RUN_DEPS = kernel initramfs.cpio
+QEMU_INITRD = -initrd initramfs.cpio
+else
+RUN_DEPS = kernel-standalone
+endif
+
# run the tests after building the kernel
-run: kernel initramfs.cpio
- $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
+run: $(RUN_DEPS)
+ $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" $(QEMU_INITRD) -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
$(Q)$(REPORT) $(CURDIR)/run.out
# re-run the tests from an existing kernel
rerun:
- $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
+ $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" $(QEMU_INITRD) -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
$(Q)$(REPORT) $(CURDIR)/run.out
# report with existing test log
--
2.46.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/5] tools/nolibc: add csky support
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
` (2 preceding siblings ...)
2024-09-29 21:47 ` [PATCH 3/5] selftests/nolibc: add support to use standalone kernels for tests Thomas Weißschuh
@ 2024-09-29 21:47 ` Thomas Weißschuh
2024-09-30 3:49 ` Willy Tarreau
2024-09-29 21:47 ` [PATCH 5/5] selftests/nolibc: skip test for getppid() on csky Thomas Weißschuh
4 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
Add support for the C-SKY architecture, which is very similar to
LoongArch.
Only v2 ABI is supported.
Optimizations are disabled as the compiler[0] seems to misoptimize the
code, especially the r4 register gets clobbered.
Compile the initramfs directly into the kernel, as qemu does not support
passing the initrd via OF.
There is no qemu mainline support for qemu.
Testing was done with commit 1f172a2c7cd5c2e7 of the downstream csky qemu [1].
Some tiny changes were necessary on top [2].
[0] gcc 13.2.0 and 14.2.0 from kernel.org crosstools
[1] https://github.com/XUANTIE-RV/qemu/
[2]
diff --git a/target/csky/cpu-param.h b/target/csky/cpu-param.h
index 80554cc0fc03..9181b602a26f 100644
--- a/target/csky/cpu-param.h
+++ b/target/csky/cpu-param.h
@@ -24,11 +24,7 @@
#define TARGET_PAGE_BITS 12
#define TARGET_PHYS_ADDR_SPACE_BITS 32
-#ifdef CONFIG_USER_ONLY
-#define TARGET_VIRT_ADDR_SPACE_BITS 30
-#else
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#endif
#define TCG_GUEST_DEFAULT_MO (0)
#endif
diff --git a/target/csky/op_vdsp2.c b/target/csky/op_vdsp2.c
index a9985a03be33..d953f5ea94fe 100644
--- a/target/csky/op_vdsp2.c
+++ b/target/csky/op_vdsp2.c
@@ -4784,7 +4784,7 @@ void VDSP2_HELPER(vmulae)(CPUCSKYState *env, uint32_t insn)
wid = ((insn >> 20) & 0x1) | ((insn >> 24) & 0x2);
lng = 8 * pow(2, wid);
- cnt = 128 / lng;
+ cnt = 64 / lng;
sign = (insn >> CSKY_VDSP2_SIGN_SHI) & CSKY_VDSP2_SIGN_MASK;
rx = (insn >> CSKY_VDSP2_VREG_SHI_VRX) & CSKY_VDSP2_VREG_MASK;
ry = (insn >> CSKY_VDSP2_VREG_SHI_VRY) & CSKY_VDSP2_VREG_MASK;
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/arch-csky.h | 161 ++++++++++++++++++++++++++++++++
tools/include/nolibc/arch.h | 2 +
tools/testing/selftests/nolibc/Makefile | 8 ++
3 files changed, 171 insertions(+)
diff --git a/tools/include/nolibc/arch-csky.h b/tools/include/nolibc/arch-csky.h
new file mode 100644
index 0000000000000000000000000000000000000000..158e5499375c22a6572321337ba4e2b8162d0d65
--- /dev/null
+++ b/tools/include/nolibc/arch-csky.h
@@ -0,0 +1,161 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * C-SKY specific definitions for NOLIBC
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ * Copyright (C) 2024 Thomas Weißschuh <linux@weissschuh.net>
+ */
+
+#ifndef _NOLIBC_ARCH_CSKY_H
+#define _NOLIBC_ARCH_CSKY_H
+
+#include "compiler.h"
+#include "crt.h"
+
+#if __csky__ != 2
+#error Unsupported csky ABI
+#endif
+
+/* Syscalls for C-SKY :
+ * - stack is 8-byte aligned
+ * - syscall number is passed in r7
+ * - arguments are in r0, r1, r2, r3, r4, r5
+ * - the system call is performed by calling "trap 0"
+ * - syscall return comes in r0
+ * - 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", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9"
+
+#define my_syscall0(num) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0"); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "=r"(_arg1) \
+ : "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall1(num, arg1) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall2(num, arg1, arg2) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ register long _arg2 __asm__ ("r1") = (long)(arg2); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_arg2), \
+ "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall3(num, arg1, arg2, arg3) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ register long _arg2 __asm__ ("r1") = (long)(arg2); \
+ register long _arg3 __asm__ ("r2") = (long)(arg3); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_arg2), "r"(_arg3), \
+ "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall4(num, arg1, arg2, arg3, arg4) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ register long _arg2 __asm__ ("r1") = (long)(arg2); \
+ register long _arg3 __asm__ ("r2") = (long)(arg3); \
+ register long _arg4 __asm__ ("r3") = (long)(arg4); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_arg2), "r"(_arg3), "r"(_arg4), \
+ "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ register long _arg2 __asm__ ("r1") = (long)(arg2); \
+ register long _arg3 __asm__ ("r2") = (long)(arg3); \
+ register long _arg4 __asm__ ("r3") = (long)(arg4); \
+ register long _arg5 __asm__ ("r4") = (long)(arg5); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
+ "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
+({ \
+ register long _num __asm__ ("r7") = (num); \
+ register long _arg1 __asm__ ("r0") = (long)(arg1); \
+ register long _arg2 __asm__ ("r1") = (long)(arg2); \
+ register long _arg3 __asm__ ("r2") = (long)(arg3); \
+ register long _arg4 __asm__ ("r3") = (long)(arg4); \
+ register long _arg5 __asm__ ("r4") = (long)(arg5); \
+ register long _arg6 __asm__ ("r5") = (long)(arg6); \
+ \
+ __asm__ volatile ( \
+ "trap 0\n" \
+ : "+r"(_arg1) \
+ : "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6), \
+ "r"(_num) \
+ : _NOLIBC_SYSCALL_CLOBBERLIST \
+ ); \
+ _arg1; \
+})
+
+/* startup code */
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
+{
+ __asm__ volatile (
+ "mov r0, sp\n" /* save stack pointer to r0, as arg1 of _start_c */
+ "andni sp, sp, 8\n" /* sp must be 8-byte aligned in the callee */
+ "jbsr _start_c\n" /* transfer to c runtime */
+ );
+ __nolibc_entrypoint_epilogue();
+}
+
+#endif /* _NOLIBC_ARCH_CSKY_H */
diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h
index c8f4e5d3add9eb5b8a438900c084dc0449fcfbd6..71cdf1eedb2045b9abd22146c72ee891765ad553 100644
--- a/tools/include/nolibc/arch.h
+++ b/tools/include/nolibc/arch.h
@@ -33,6 +33,8 @@
#include "arch-s390.h"
#elif defined(__loongarch__)
#include "arch-loongarch.h"
+#elif defined(__csky__)
+#include "arch-csky.h"
#else
#error Unsupported Architecture
#endif
diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index e8278924cf28f17144044e69724df1d4fde141a3..2f51d8ea45f1c0658584f27553a9c8e1ecf428a9 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -67,6 +67,7 @@ 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
+IMAGE_csky = arch/csky/boot/Image
IMAGE = $(objtree)/$(IMAGE_$(XARCH))
IMAGE_NAME = $(notdir $(IMAGE))
@@ -84,9 +85,11 @@ DEFCONFIG_ppc64le = powernv_defconfig
DEFCONFIG_riscv = defconfig
DEFCONFIG_s390 = defconfig
DEFCONFIG_loongarch = defconfig
+DEFCONFIG_csky = defconfig
DEFCONFIG = $(DEFCONFIG_$(XARCH))
EXTRACONFIG_mips32be = -d CONFIG_CPU_LITTLE_ENDIAN -e CONFIG_CPU_BIG_ENDIAN
+EXTRACONFIG_csky = -e CONFIG_BLK_DEV_INITRD -e CONFIG_VIRT_DRIVERS -e CONFIG_CSKY_EXIT
EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
# optional tests to run (default = all)
@@ -106,6 +109,7 @@ QEMU_ARCH_ppc64le = ppc64
QEMU_ARCH_riscv = riscv64
QEMU_ARCH_s390 = s390x
QEMU_ARCH_loongarch = loongarch64
+QEMU_ARCH_csky = cskyv2
QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
QEMU_ARCH_USER_ppc64le = ppc64le
@@ -132,8 +136,11 @@ QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC
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_csky = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
+QEMU_RUN_STANDALONE_csky = 1
+
# OUTPUT is only set when run from the main makefile, otherwise
# it defaults to this nolibc directory.
OUTPUT ?= $(CURDIR)/
@@ -151,6 +158,7 @@ CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
CFLAGS_s390 = -m64
CFLAGS_mips32le = -EL -mabi=32 -fPIC
CFLAGS_mips32be = -EB -mabi=32
+CFLAGS_csky = -O0
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 -W -Wall -Wextra \
$(call cc-option,-fno-stack-protector) \
--
2.46.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/5] selftests/nolibc: skip test for getppid() on csky
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
` (3 preceding siblings ...)
2024-09-29 21:47 ` [PATCH 4/5] tools/nolibc: add csky support Thomas Weißschuh
@ 2024-09-29 21:47 ` Thomas Weißschuh
4 siblings, 0 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-29 21:47 UTC (permalink / raw)
To: Guo Ren, Willy Tarreau, Shuah Khan
Cc: linux-kernel, linux-csky, linux-kselftest, Thomas Weißschuh
Old non-mainline Linux and current non-mainline qemu-user use different
syscall numbers than mainline Linux.
__NR_getppid and __NR_rt_sigreturn are swapped.
As the runtime environment can't be determined during compilation,
sidestep the whole issue by skipping the test.
Link: https://lore.kernel.org/linux-csky/2fa3151f-5aab-406c-95d9-add398ae58b3@t-8ch.de/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/testing/selftests/nolibc/nolibc-test.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 6fba7025c5e3c002085862fdf6fa950da6000d6c..daf6a9b84a3051413cbb1d01918f745c3b83426c 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -995,7 +995,7 @@ int run_syscall(int min, int max)
int tmp;
int ret = 0;
void *p1, *p2;
- int has_gettid = 1;
+ int has_gettid = 1, has_getppid = 1;
int has_brk;
/* <proc> indicates whether or not /proc is mounted */
@@ -1009,6 +1009,11 @@ int run_syscall(int min, int max)
has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30);
#endif
+ /* qemu-user and non-mainline Linux use different syscall number */
+#if defined(__csky__)
+ has_getppid = 0;
+#endif
+
/* on musl setting brk()/sbrk() always fails */
has_brk = brk(0) == 0;
@@ -1020,7 +1025,7 @@ int run_syscall(int min, int max)
*/
switch (test + __LINE__ + 1) {
CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break;
- CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break;
+ CASE_TEST(getppid); EXPECT_SYSNE(has_getppid, getppid(), -1); break;
CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break;
CASE_TEST(getpgid_self); EXPECT_SYSNE(1, getpgid(0), -1); break;
CASE_TEST(getpgid_bad); EXPECT_SYSER(1, getpgid(-1), -1, ESRCH); break;
--
2.46.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] tools/nolibc: add csky support
2024-09-29 21:47 ` [PATCH 4/5] tools/nolibc: add csky support Thomas Weißschuh
@ 2024-09-30 3:49 ` Willy Tarreau
2024-09-30 5:23 ` Thomas Weißschuh
0 siblings, 1 reply; 9+ messages in thread
From: Willy Tarreau @ 2024-09-30 3:49 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Guo Ren, Shuah Khan, linux-kernel, linux-csky, linux-kselftest
Hi Thomas,
On Sun, Sep 29, 2024 at 11:47:39PM +0200, Thomas Weißschuh wrote:
> Add support for the C-SKY architecture, which is very similar to
> LoongArch.
> Only v2 ABI is supported.
> Optimizations are disabled as the compiler[0] seems to misoptimize the
> code, especially the r4 register gets clobbered.
> Compile the initramfs directly into the kernel, as qemu does not support
> passing the initrd via OF.
>
> There is no qemu mainline support for qemu.
> Testing was done with commit 1f172a2c7cd5c2e7 of the downstream csky qemu [1].
> Some tiny changes were necessary on top [2].
>
> [0] gcc 13.2.0 and 14.2.0 from kernel.org crosstools
> [1] https://github.com/XUANTIE-RV/qemu/
> [2]
I think you wanted to place a link or something above for [2].
> diff --git a/target/csky/cpu-param.h b/target/csky/cpu-param.h
> index 80554cc0fc03..9181b602a26f 100644
> --- a/target/csky/cpu-param.h
> +++ b/target/csky/cpu-param.h
(...)
> diff --git a/target/csky/op_vdsp2.c b/target/csky/op_vdsp2.c
> index a9985a03be33..d953f5ea94fe 100644
> --- a/target/csky/op_vdsp2.c
> +++ b/target/csky/op_vdsp2.c
Also, the first two patches look like fixes for the arch itself, they
should really go outside of the nolibc development tree, at least
because they might have to be backported to some stable branches,
or later fixed/reverted in case they wouldn't be optimal.
Aside this, it's been a long time since we last added an architecture
and it's pleasant to see how easy it has become over time, even when
requiring specific settings ;-)
Cheers,
Willy
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] tools/nolibc: add csky support
2024-09-30 3:49 ` Willy Tarreau
@ 2024-09-30 5:23 ` Thomas Weißschuh
2024-09-30 6:04 ` Willy Tarreau
0 siblings, 1 reply; 9+ messages in thread
From: Thomas Weißschuh @ 2024-09-30 5:23 UTC (permalink / raw)
To: Willy Tarreau
Cc: Guo Ren, Shuah Khan, linux-kernel, linux-csky, linux-kselftest
Hi Willy,
On 2024-09-30 05:49:46+0000, Willy Tarreau wrote:
> On Sun, Sep 29, 2024 at 11:47:39PM +0200, Thomas Weißschuh wrote:
> > Add support for the C-SKY architecture, which is very similar to
> > LoongArch.
> > Only v2 ABI is supported.
> > Optimizations are disabled as the compiler[0] seems to misoptimize the
> > code, especially the r4 register gets clobbered.
> > Compile the initramfs directly into the kernel, as qemu does not support
> > passing the initrd via OF.
> >
> > There is no qemu mainline support for qemu.
> > Testing was done with commit 1f172a2c7cd5c2e7 of the downstream csky qemu [1].
> > Some tiny changes were necessary on top [2].
> >
> > [0] gcc 13.2.0 and 14.2.0 from kernel.org crosstools
> > [1] https://github.com/XUANTIE-RV/qemu/
> > [2]
>
> I think you wanted to place a link or something above for [2].
[2] was supposed to be inline patches for QEMU, I'll try to make that a
bit clearer.
> > diff --git a/target/csky/cpu-param.h b/target/csky/cpu-param.h
> > index 80554cc0fc03..9181b602a26f 100644
> > --- a/target/csky/cpu-param.h
> > +++ b/target/csky/cpu-param.h
> (...)
> > diff --git a/target/csky/op_vdsp2.c b/target/csky/op_vdsp2.c
> > index a9985a03be33..d953f5ea94fe 100644
> > --- a/target/csky/op_vdsp2.c
> > +++ b/target/csky/op_vdsp2.c
>
> Also, the first two patches look like fixes for the arch itself, they
> should really go outside of the nolibc development tree, at least
> because they might have to be backported to some stable branches,
> or later fixed/reverted in case they wouldn't be optimal.
As mentioned above, these are patches for qemu, not Linux.
I don't know enough about QEMU or C-SKY to know if these are the
generally correct fixes. But they seem to work well enough for nolibc.
Guo, if these QEMU patches look reasonable to you I can also submit them.
> Aside this, it's been a long time since we last added an architecture
> and it's pleasant to see how easy it has become over time, even when
> requiring specific settings ;-)
Agreed!
Thomas
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/5] tools/nolibc: add csky support
2024-09-30 5:23 ` Thomas Weißschuh
@ 2024-09-30 6:04 ` Willy Tarreau
0 siblings, 0 replies; 9+ messages in thread
From: Willy Tarreau @ 2024-09-30 6:04 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Guo Ren, Shuah Khan, linux-kernel, linux-csky, linux-kselftest
On Mon, Sep 30, 2024 at 07:23:39AM +0200, Thomas Weißschuh wrote:
> > > [0] gcc 13.2.0 and 14.2.0 from kernel.org crosstools
> > > [1] https://github.com/XUANTIE-RV/qemu/
> > > [2]
> >
> > I think you wanted to place a link or something above for [2].
>
> [2] was supposed to be inline patches for QEMU, I'll try to make that a
> bit clearer.
>
> > > diff --git a/target/csky/cpu-param.h b/target/csky/cpu-param.h
> > > index 80554cc0fc03..9181b602a26f 100644
> > > --- a/target/csky/cpu-param.h
> > > +++ b/target/csky/cpu-param.h
> > (...)
> > > diff --git a/target/csky/op_vdsp2.c b/target/csky/op_vdsp2.c
> > > index a9985a03be33..d953f5ea94fe 100644
> > > --- a/target/csky/op_vdsp2.c
> > > +++ b/target/csky/op_vdsp2.c
> >
> > Also, the first two patches look like fixes for the arch itself, they
> > should really go outside of the nolibc development tree, at least
> > because they might have to be backported to some stable branches,
> > or later fixed/reverted in case they wouldn't be optimal.
>
> As mentioned above, these are patches for qemu, not Linux.
> I don't know enough about QEMU or C-SKY to know if these are the
> generally correct fixes. But they seem to work well enough for nolibc.
Ah I understand now. The problem with external patches inlined like this
is that it's hard to split them apart from the rest of the patch. For
example just doing patch -p1 < patch.mbox will fail, trying to patch
non-existing files.
What I'm used to doing when quoting code/patches/etc in messages is to
indent them by 2 or more chars. That could be sufficient to explain what
needs to be fixed in the upstream project without being taken for a part
of the patchset, especially for such tiny patches. In this case the quoted
part could include only the strict minimum (i.e. no diff --git header etc).
Just a suggestion.
Cheers,
Willy
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-09-30 6:04 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-29 21:47 [PATCH 0/5] csky: add shutdown and nolibc support Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 1/5] drivers/virt: introduce csky_exit system poweroff driver Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 2/5] tools/nolibc: provide a fallback for lseek through llseek Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 3/5] selftests/nolibc: add support to use standalone kernels for tests Thomas Weißschuh
2024-09-29 21:47 ` [PATCH 4/5] tools/nolibc: add csky support Thomas Weißschuh
2024-09-30 3:49 ` Willy Tarreau
2024-09-30 5:23 ` Thomas Weißschuh
2024-09-30 6:04 ` Willy Tarreau
2024-09-29 21:47 ` [PATCH 5/5] selftests/nolibc: skip test for getppid() on csky Thomas Weißschuh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox