Skip to contentSkip to conversation

Basic early_printk and smoke test implementation

PATCH Superseded Oleksii Kurochko 5 participants 21 messages Jan 10, 2023 – Jan 11, 2023 RISC-V

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover Basic early_printk and smoke test implementation

The patch series introduces the following:
- the minimal set of headers and changes inside them.
- SBI (RISC-V Supervisor Binary Interface) things necessary for basic early_printk implementation.
- things needed to set up the stack.
- early_printk() function to print only strings.
- RISC-V smoke test which checks if "Hello from C env" message is present in serial.tmp

---
Changes in V3:
- Most of "[PATCH v2 7/8] xen/riscv: print hello message from C env" was merged with [PATCH v2 3/6] xen/riscv: introduce stack stuff.
- "[PATCH v2 7/8] xen/riscv: print hello message from C env" was merged with "[PATCH v2 6/8] xen/riscv: introduce early_printk basic stuff".
- "[PATCH v2 5/8] xen/include: include <asm/types.h> in <xen/early_printk.h>" was removed as it has been already merged to mainline staging.
- code style fixes.
---
Changes in V2:
- update commit patches commit messages according to the mailing list comments
- Remove unneeded types in <asm/types.h>
- Introduce definition of STACK_SIZE
- order the files alphabetically in Makefile
- Add license to early_printk.c
- Add RISCV_32 dependecy to config EARLY_PRINTK in Kconfig.debug
- Move dockerfile changes to separate config and sent them as separate patch to mailing list.
- Update test.yaml to wire up smoke test
---

Bobby Eshleman (2):
xen/riscv: introduce sbi call to putchar to console xen/riscv: introduce early_printk basic stuff

Oleksii Kurochko (4):
xen/riscv: introduce dummy asm/init.h
xen/riscv: introduce asm/types.h header file
xen/riscv: introduce stack stuff
automation: add RISC-V smoke test

 automation/gitlab-ci/test.yaml            | 20 ++++++++++
 automation/scripts/qemu-smoke-riscv64.sh  | 20 ++++++++++
 xen/arch/riscv/Kconfig.debug              |  7 ++++
 xen/arch/riscv/Makefile                   |  3 ++
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++
 xen/arch/riscv/include/asm/config.h       |  2 +
 xen/arch/riscv/include/asm/early_printk.h | 12 ++++++
 xen/arch/riscv/include/asm/init.h         | 12 ++++++
 xen/arch/riscv/include/asm/sbi.h          | 34 +++++++++++++++++
 xen/arch/riscv/include/asm/types.h        | 22 +++++++++++
 xen/arch/riscv/riscv64/head.S             |  6 ++-
 xen/arch/riscv/sbi.c                      | 45 +++++++++++++++++++++++
 xen/arch/riscv/setup.c                    | 18 +++++++++
 13 files changed, 233 insertions(+), 1 deletion(-)
 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
 create mode 100644 xen/arch/riscv/include/asm/init.h
 create mode 100644 xen/arch/riscv/include/asm/sbi.h
 create mode 100644 xen/arch/riscv/include/asm/types.h
 create mode 100644 xen/arch/riscv/sbi.c
 create mode 100644 xen/arch/riscv/setup.c
Signature · 1 line
2.38.1
#1 lore raw

PATCH v3 1/6 xen/riscv: introduce dummy asm/init.h

The following patches require <xen/init.h> which includes <asm/init.h>

---
Changes in V3:
- Nothing changed
---
Changes in V2:
- Add explanation comment to the comment message

---
 xen/arch/riscv/include/asm/init.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/init.h
xen/arch/riscv/include/asm/init.h new file +12 -0
new file mode 100644
index 0000000000..237ec25e4e
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
+
+#endif /* _XEN_ASM_INIT_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.38.1
#15 lore raw

PATCH v3 3/6 xen/riscv: introduce stack stuff

In reply to Oleksii Kurochko

The patch introduces and sets up a stack in order to go to C environment

---
Changes in V3:
- reorder headers in alphabetical order
- merge changes related to start_xen() function from "[PATCH v2 7/8] xen/riscv: print hello message from C env" to this patch
- remove unneeded parentheses in definition of STACK_SIZE
---
Changes in V2:
- introduce STACK_SIZE define.
- use consistent padding between instruction mnemonic and operand(s)

---
 xen/arch/riscv/Makefile             |  1 +
 xen/arch/riscv/include/asm/config.h |  2 ++
 xen/arch/riscv/riscv64/head.S       |  6 +++++-
 xen/arch/riscv/setup.c              | 14 ++++++++++++++
 4 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/riscv/setup.c
xen/arch/riscv/Makefile +1 -0
index 248f2cbb3e..5a67a3f493 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += setup.o
 
 $(TARGET): $(TARGET)-syms
 	$(OBJCOPY) -O binary -S $< $@
xen/arch/riscv/include/asm/config.h +2 -0
index 0370f865f3..763a922a04 100644
@@ -43,6 +43,8 @@
 
 #define SMP_CACHE_BYTES (1 << 6)
 
+#define STACK_SIZE PAGE_SIZE
+
 #endif /* __RISCV_CONFIG_H__ */
 /*
  * Local variables:
xen/arch/riscv/riscv64/head.S +5 -1
index 990edb70a0..d444dd8aad 100644
@@ -1,4 +1,8 @@
         .section .text.header, "ax", %progbits
 
 ENTRY(start)
-        j  start
+        la      sp, cpu0_boot_stack
+        li      t0, STACK_SIZE
+        add     sp, sp, t0
+
+        tail    start_xen
xen/arch/riscv/setup.c new file +14 -0
new file mode 100644
index 0000000000..13e24e2fe1
@@ -0,0 +1,14 @@
+#include <xen/compile.h>
+#include <xen/init.h>
+
+/* Xen stack for bringing up the first CPU. */
+unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
+    __aligned(STACK_SIZE);
+
+void __init noreturn start_xen(void)
+{
+    for ( ;; )
+        asm volatile ("wfi");
+
+    unreachable();
+}
Signature · 1 line
2.38.1
#17 lore raw

PATCH v3 4/6 xen/riscv: introduce sbi call to putchar to console

In reply to Oleksii Kurochko

From: Bobby Eshleman <[email protected]>

Originally SBI implementation for Xen was introduced by Bobby Eshleman <[email protected]> but it was removed all the stuff for simplicity except SBI call for putting character to console.

The patch introduces sbi_putchar() SBI call which is necessary to implement initial early_printk.

---
Changes in V3:
- update copyright's year
- rename define __CPU_SBI_H__ to __ASM_RISCV_SBI_H__
- fix identations
- change an author of the commit
---
Changes in V2:
- add an explanatory comment about sbi_console_putchar() function.
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Makefile          |  1 +
 xen/arch/riscv/include/asm/sbi.h | 34 ++++++++++++++++++++++++
 xen/arch/riscv/sbi.c             | 45 ++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/sbi.h
 create mode 100644 xen/arch/riscv/sbi.c
xen/arch/riscv/Makefile +1 -0
index 5a67a3f493..fd916e1004 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += sbi.o
 obj-y += setup.o
 
 $(TARGET): $(TARGET)-syms
xen/arch/riscv/include/asm/sbi.h new file +34 -0
new file mode 100644
index 0000000000..0e6820a4ed
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: (GPL-2.0-or-later) */
+/*
+ * Copyright (c) 2021-2023 Vates SAS.
+ *
+ * Taken from xvisor, modified by Bobby Eshleman ([email protected]).
+ *
+ * Taken/modified from Xvisor project with the following copyright:
+ *
+ * Copyright (c) 2019 Western Digital Corporation or its affiliates.
+ */
+
+#ifndef __ASM_RISCV_SBI_H__
+#define __ASM_RISCV_SBI_H__
+
+#define SBI_EXT_0_1_CONSOLE_PUTCHAR		0x1
+
+struct sbiret {
+    long error;
+    long value;
+};
+
+struct sbiret sbi_ecall(unsigned long ext, unsigned long fid,
+                        unsigned long arg0, unsigned long arg1,
+                        unsigned long arg2, unsigned long arg3,
+                        unsigned long arg4, unsigned long arg5);
+
+/**
+ * Writes given character to the console device.
+ *
+ * @param ch The data to be written to the console.
+ */
+void sbi_console_putchar(int ch);
+
+#endif /* __ASM_RISCV_SBI_H__ */
xen/arch/riscv/sbi.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.38.1
#18 lore raw

PATCH v3 5/6 xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko

From: Bobby Eshleman <[email protected]>

The patch introduces a basic stuff of early_printk functionality which will be enough to print 'hello from C environment". early_printk() function was changed in comparison with original as common isn't being built now so there is no vscnprintf.

Because printk() relies on a serial driver (like the ns16550 driver) and drivers require working virtual memory (ioremap()) there is not print functionality early in Xen boot.

This commit adds early printk implementation built on the putc SBI call.

As sbi_console_putchar() is being already planned for deprecation it is used temporary now and will be removed or reworked after real uart will be ready.

---
Changes in V3:
- reorder "include <header>" in erly_printk.c
- change an author of the commit
---
Changes in V2:
- add license to early_printk.c
- add signed-off-by Bobby
- add RISCV_32 to Kconfig.debug to EARLY_PRINTK config
- update commit message
- order the files alphabetically in Makefile

---
 xen/arch/riscv/Kconfig.debug              |  7 +++++
 xen/arch/riscv/Makefile                   |  1 +
 xen/arch/riscv/early_printk.c             | 33 +++++++++++++++++++++++
 xen/arch/riscv/include/asm/early_printk.h | 12 +++++++++
 xen/arch/riscv/setup.c                    |  4 +++
 5 files changed, 57 insertions(+)
 create mode 100644 xen/arch/riscv/early_printk.c
 create mode 100644 xen/arch/riscv/include/asm/early_printk.h
xen/arch/riscv/Kconfig.debug +7 -0
index e69de29bb2..e21649781d 100644
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32
+    help
+
+      Enables early printk debug messages
xen/arch/riscv/Makefile +1 -0
index fd916e1004..1a4f1a6015 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 obj-$(CONFIG_RISCV_64) += riscv64/
 obj-y += sbi.o
 obj-y += setup.o
xen/arch/riscv/early_printk.c new file +33 -0
new file mode 100644
index 0000000000..348c21bdaa
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/early_printk.h>
+#include <asm/sbi.h>
+
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprecation
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)
+    {
+        early_puts(str, 1);
+        str++;
+    }
+}
xen/arch/riscv/include/asm/early_printk.h new file +12 -0
new file mode 100644
index 0000000000..05106e160d
@@ -0,0 +1,12 @@
+#ifndef __EARLY_PRINTK_H__
+#define __EARLY_PRINTK_H__
+
+#include <xen/early_printk.h>
+
+#ifdef CONFIG_EARLY_PRINTK
+void early_printk(const char *str);
+#else
+static inline void early_printk(const char *s) {};
+#endif
+
+#endif /* __EARLY_PRINTK_H__ */
xen/arch/riscv/setup.c +4 -0
index 13e24e2fe1..d09ffe1454 100644
@@ -1,12 +1,16 @@
 #include <xen/compile.h>
 #include <xen/init.h>
 
+#include <asm/early_printk.h>
+
 /* Xen stack for bringing up the first CPU. */
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
 void __init noreturn start_xen(void)
 {
+    early_printk("Hello from C env\n");
+
     for ( ;; )
         asm volatile ("wfi");
 
Signature · 1 line
2.38.1
#6 lore raw

PATCH v3 2/6 xen/riscv: introduce asm/types.h header file

In reply to Oleksii Kurochko

---
Changes in V3:
- Nothing changed
---
Changes in V2:
- Remove unneeded now types from <asm/types.h>

---
 xen/arch/riscv/include/asm/types.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 xen/arch/riscv/include/asm/types.h
xen/arch/riscv/include/asm/types.h new file +22 -0
new file mode 100644
index 0000000000..fbe352ef20
@@ -0,0 +1,22 @@
+#ifndef __RISCV_TYPES_H__
+#define __RISCV_TYPES_H__
+
+#ifndef __ASSEMBLY__
+
+#if defined(__SIZE_TYPE__)
+typedef __SIZE_TYPE__ size_t;
+#else
+typedef unsigned long size_t;
+#endif
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __RISCV_TYPES_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.38.1
#20 lore raw

PATCH v3 6/6 automation: add RISC-V smoke test

In reply to Oleksii Kurochko

Add check if there is a message 'Hello from C env' presents in log file to be sure that stack is set and C part of early printk is working.

---
Changes in V3:
- Nothing changed
- All mentioned comments by Stefano in Xen mailing list will be fixed as a separate patch out of this patch series.
---
Changes in V2:
- Move changes in the dockerfile to separate patch and send it to mailing list separately:
[PATCH] automation: add qemu-system-riscv to riscv64.dockerfile
- Update test.yaml to wire up smoke test

---
 automation/gitlab-ci/test.yaml           | 20 ++++++++++++++++++++
 automation/scripts/qemu-smoke-riscv64.sh | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 automation/scripts/qemu-smoke-riscv64.sh
automation/gitlab-ci/test.yaml +20 -0
index afd80adfe1..64f47a0ab9 100644
@@ -54,6 +54,19 @@
   tags:
     - x86_64
 
+.qemu-riscv64:
+  extends: .test-jobs-common
+  variables:
+    CONTAINER: archlinux:riscv64
+    LOGFILE: qemu-smoke-riscv64.log
+  artifacts:
+    paths:
+      - smoke.serial
+      - '*.log'
+    when: always
+  tags:
+    - x86_64
+
 .yocto-test:
   extends: .test-jobs-common
   script:
@@ -234,6 +247,13 @@ qemu-smoke-x86-64-clang-pvh:
   needs:
     - debian-unstable-clang-debug
 
+qemu-smoke-riscv64-gcc:
+  extends: .qemu-riscv64
+  script:
+    - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE}
+  needs:
+    - riscv64-cross-gcc
+
 # Yocto test jobs
 yocto-qemuarm64:
   extends: .yocto-test-arm64
automation/scripts/qemu-smoke-riscv64.sh new file +20 -0
new file mode 100755
index 0000000000..e0f06360bc
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+set -ex
+
+# Run the test
+rm -f smoke.serial
+set +e
+
+timeout -k 1 2 \
+qemu-system-riscv64 \
+    -M virt \
+    -smp 1 \
+    -nographic \
+    -m 2g \
+    -kernel binaries/xen \
+    |& tee smoke.serial
+
+set -e
+(grep -q "Hello from C env" smoke.serial) || exit 1
+exit 0
Signature · 1 line
2.38.1
#19 lore raw

Re: [PATCH v3 5/6] xen/riscv: introduce early_printk basic stuff

In reply to Oleksii Kurochko

xen/arch/riscv/Kconfig.debug line 4

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/Kconfig.debug +4 -0
@@ -0,0 +1,7 @@
+config EARLY_PRINTK
+    bool "Enable early printk"
+    default DEBUG
+    depends on RISCV_64 || RISCV_32

You're in a RISC-V-specific Kconfig - do you really need this line?

Quoted 12 lines
xen/arch/riscv/early_printk.c new file +9 -0
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * RISC-V early printk using SBI
+ *
+ * Copyright (C) 2021 Bobby Eshleman <[email protected]>
+ */
+#include <asm/early_printk.h>
+#include <asm/sbi.h>
+

xen/arch/riscv/early_printk.c line 19

Quoted 10 lines
xen/arch/riscv/early_printk.c new file +10 -0
+/*
+ * TODO:
+ *   sbi_console_putchar is already planned for deprecation
+ *   so it should be reworked to use UART directly.
+*/
+void early_puts(const char *s, size_t nr)
+{
+    while ( nr-- > 0 )
+    {
+        if (*s == '\n')

Nit (style): Missing blanks.

xen/arch/riscv/early_printk.c line 28

Quoted 9 lines
xen/arch/riscv/early_printk.c new file +9 -0
+            sbi_console_putchar('\r');
+        sbi_console_putchar(*s);
+        s++;
+    }
+}
+
+void early_printk(const char *str)
+{
+    while (*str)

Again.

Quoted 8 lines
xen/arch/riscv/setup.c +2 -0
@@ -1,12 +1,16 @@
 #include <xen/compile.h>
 #include <xen/init.h>
 
+#include <asm/early_printk.h>
+

xen/arch/riscv/setup.c line 15

Quoted 10 lines
xen/arch/riscv/setup.c +2 -0
 /* Xen stack for bringing up the first CPU. */
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
 void __init noreturn start_xen(void)
 {
+    early_printk("Hello from C env\n");
+
     for ( ;; )
         asm volatile ("wfi");

While this is only context here, it affects an earlier patch in the series; this wants to be

    for ( ; ; )
        asm volatile ( "wfi" );

Jan

#7 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

In reply to Oleksii Kurochko
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
- Nothing changed
---
Changes in V2:
- Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you do not build that yet, will want declaring right away imo. Of course I should finally try and get rid of at least some of the being-phased-out ones (s8 and s16 look to be relatively low hanging fruit, for example, and of these only s16 looks to be used in common code) ...

Jan

#2 lore raw

Re: [PATCH v3 1/6] xen/riscv: introduce dummy asm/init.h

In reply to Oleksii Kurochko

Arm maintainers,

xen/arch/riscv/include/asm/init.h line 4

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/init.h new file +4 -0
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
+
+#endif /* _XEN_ASM_INIT_H */

instead of having RISC-V introduce an empty stub matching what x86 has, what would it take to empty Arm's as well, allowing both present ones to go away and no new one to be introduced? The only thing you have in there is struct init_info, which doesn't feel like it's properly placed in this header (x86 has such stuff in setup.h) ...

Jan

author
#3 lore raw

Re: [PATCH v3 1/6] xen/riscv: introduce dummy asm/init.h

Hello Jan,

Sorry for breaking into the conversation.

Quoted 13 lines · Jan Beulich

Arm maintainers,

xen/arch/riscv/include/asm/init.h line 4

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/init.h new file +4 -0
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
+
+#endif /* _XEN_ASM_INIT_H */

instead of having RISC-V introduce an empty stub matching what x86 has,

Have you had a chance to look at the answer (Re: [PATCH v1 0/8] Basic early_printk and smoke test implementation) of Andrew:
https://lore.kernel.org/xen-devel/[email protected]/#t

I agree with his point regarding the usage of __has_include() to not produce empty headers stubs for RISCV and for future architectures too.

Quoted 10 lines

If maintainers are OK I can start to use __has_include() in the correspondent <xen/*.h> files.what would it take to empty Arm's as well, allowing both present ones to
go away and no new one to be introduced? The only thing you have in there
is struct init_info, which doesn't feel like it's properly placed in this
header (x86 has such stuff in setup.h) ...

Jan

~Oleksii

Reviewed-by on v3 3/6
#16 lore raw

Re: [PATCH v3 3/6] xen/riscv: introduce stack stuff

In reply to Oleksii Kurochko
Quoted 4 lines · Oleksii Kurochko

The patch introduces and sets up a stack in order to go to C environment

Alistair

Quoted 79 lines

---
Changes in V3:
- reorder headers in alphabetical order
- merge changes related to start_xen() function from "[PATCH v2 7/8] xen/riscv: print hello message from C env" to this patch
- remove unneeded parentheses in definition of STACK_SIZE
---
Changes in V2:
- introduce STACK_SIZE define.
- use consistent padding between instruction mnemonic and operand(s)

---
 xen/arch/riscv/Makefile             |  1 +
 xen/arch/riscv/include/asm/config.h |  2 ++
 xen/arch/riscv/riscv64/head.S       |  6 +++++-
 xen/arch/riscv/setup.c              | 14 ++++++++++++++
 4 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/riscv/setup.c
xen/arch/riscv/Makefile +1 -0
index 248f2cbb3e..5a67a3f493 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RISCV_64) += riscv64/
+obj-y += setup.o
 
 $(TARGET): $(TARGET)-syms
        $(OBJCOPY) -O binary -S $< $@
xen/arch/riscv/include/asm/config.h +2 -0
index 0370f865f3..763a922a04 100644
@@ -43,6 +43,8 @@
 
 #define SMP_CACHE_BYTES (1 << 6)
 
+#define STACK_SIZE PAGE_SIZE
+
 #endif /* __RISCV_CONFIG_H__ */
 /*
  * Local variables:
xen/arch/riscv/riscv64/head.S +5 -1
index 990edb70a0..d444dd8aad 100644
@@ -1,4 +1,8 @@
         .section .text.header, "ax", %progbits
 
 ENTRY(start)
-        j  start
+        la      sp, cpu0_boot_stack
+        li      t0, STACK_SIZE
+        add     sp, sp, t0
+
+        tail    start_xen
xen/arch/riscv/setup.c new file +14 -1
new file mode 100644
index 0000000000..13e24e2fe1
@@ -0,0 +1,14 @@
+#include <xen/compile.h>
+#include <xen/init.h>
+
+/* Xen stack for bringing up the first CPU. */
+unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
+    __aligned(STACK_SIZE);
+
+void __init noreturn start_xen(void)
+{
+    for ( ;; )
+        asm volatile ("wfi");
+
+    unreachable();
+}
--

2.38.1

#5 lore raw

Re: [PATCH v3 1/6] xen/riscv: introduce dummy asm/init.h

In reply to Jan Beulich
Quoted 1 line · Jan Beulich

Arm maintainers,

Hi Jan,

Quoted 6 lines · Oleksii Kurochko
Quoted 5 lines
xen/arch/riscv/include/asm/init.h new file +2 -0
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
Quoted 8 lines

xen/arch/riscv/include/asm/init.h line 4

Quoted 2 lines
xen/arch/riscv/include/asm/init.h new file +2 -0
+
+#endif /* _XEN_ASM_INIT_H */

instead of having RISC-V introduce an empty stub matching what x86 has, what would it take to empty Arm's as well, allowing both present ones to go away and no new one to be introduced? The only thing you have in there is struct init_info, which doesn't feel like it's properly placed in this header (x86 has such stuff in setup.h) ...

Yes. setup.h should be a good place even though the header is getting quite crowded.

I am happy to send a patch for it.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v3 1/6] xen/riscv: introduce dummy asm/init.h

In reply to Oleksii
Quoted 1 line · Oleksii

Sorry for breaking into the conversation.

That's perfectly fine; no need to be sorry.

Quoted 14 lines · Jan Beulich
Quoted 13 lines

Arm maintainers,

xen/arch/riscv/include/asm/init.h line 4

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/init.h new file +4 -0
@@ -0,0 +1,12 @@
+#ifndef _XEN_ASM_INIT_H
+#define _XEN_ASM_INIT_H
+
+#endif /* _XEN_ASM_INIT_H */

instead of having RISC-V introduce an empty stub matching what x86 has,

Quoted 6 lines

Have you had a chance to look at the answer (Re: [PATCH v1 0/8] Basic early_printk and smoke test implementation) of Andrew:
https://lore.kernel.org/xen-devel/[email protected]/#t

I agree with his point regarding the usage of __has_include() to not produce empty headers stubs for RISCV and for future architectures too.

Sure, but as he said, that requires settling on a new toolchain baseline, which is something that we've failed to come to any results for, for a considerable number of years. Plus if we could get rid of this (then optional) arch header altogether, it would imo be even better.

Jan

author
#8 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
    - Nothing changed
---
Changes in V2:
    - Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you

It looks then I didn't understand which one of types are needed.

In "[PATCH v1 2/8] xen/riscv: introduce asm/types.h header file" all types were introduced as most of them are used in <xen/types.h>:
__{u|s}{8|16|32|64}. Thereby it looks like the following types in <asm/types.h> should be present from the start:
typedef __signed__ char __s8;
typedef unsigned char __u8;

typedef __signed__ short __s16;
typedef unsigned short __u16;

typedef __signed__ int __s32;
typedef unsigned int __u32;

  #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  #if defined(CONFIG_RISCV_32)
    typedef __signed__ long long __s64;
    typedef unsigned long long __u64;
  #elif defined (CONFIG_RISCV_64)
    typedef __signed__ long __s64;
    typedef unsigned long __u64;
  #endif
  #endif

Then it turns out that there is no any sense in:
typedef signed char s8;
typedef unsigned char u8;

typedef signed short s16;
typedef unsigned short u16;

typedef signed int s32;
typedef unsigned int u32;

typedef signed long long s64;
typedef unsigned long long u64;
OR
typedef signed long s64;
typedef unsigned long u64;
As I understand instead of them should be used: {u|s}int<N>_t.

All other types such as {v,p}addr_t, register_t and definitions PRIvaddr, INVALID_PADDR, PRIpaadr, PRIregister should be present in <asm/types.h> from the start.

Am I right?

Quoted 9 lines

do not build that yet, will want declaring right away imo. Of course I
should finally try and get rid of at least some of the being-phased- out
ones (s8 and s16 look to be relatively low hanging fruit, for example,
and of these only s16 looks to be used in common code) ...

Jan

~Oleksii

#9 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 47 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
    - Nothing changed
---
Changes in V2:
    - Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you

It looks then I didn't understand which one of types are needed.

In "[PATCH v1 2/8] xen/riscv: introduce asm/types.h header file" all types were introduced as most of them are used in <xen/types.h>:
__{u|s}{8|16|32|64}. Thereby it looks like the following types in <asm/types.h> should be present from the start:
typedef __signed__ char __s8;
typedef unsigned char __u8;

typedef __signed__ short __s16;
typedef unsigned short __u16;

typedef __signed__ int __s32;
typedef unsigned int __u32;

  #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  #if defined(CONFIG_RISCV_32)
    typedef __signed__ long long __s64;
    typedef unsigned long long __u64;
  #elif defined (CONFIG_RISCV_64)
    typedef __signed__ long __s64;
    typedef unsigned long __u64;
  #endif
  #endif

Then it turns out that there is no any sense in:
typedef signed char s8;
typedef unsigned char u8;

typedef signed short s16;
typedef unsigned short u16;

typedef signed int s32;
typedef unsigned int u32;

Quoted 6 lines

typedef signed long long s64;
typedef unsigned long long u64;
OR
typedef signed long s64;
typedef unsigned long u64;
As I understand instead of them should be used: {u|s}int<N>_t.

Hmm, the situation is worse than I thought (recalled) it was: You're right, xen/types.h actually uses __{u,s}<N>. So I'm sorry for mis- guiding you; we'll need to do more cleanup first for asm/types.h to become smaller.

Jan

#10 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 55 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
    - Nothing changed
---
Changes in V2:
    - Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you

It looks then I didn't understand which one of types are needed.

In "[PATCH v1 2/8] xen/riscv: introduce asm/types.h header file" all types were introduced as most of them are used in <xen/types.h>:
__{u|s}{8|16|32|64}. Thereby it looks like the following types in <asm/types.h> should be present from the start:

   typedef __signed__ char __s8;
   typedef unsigned char __u8;

   typedef __signed__ short __s16;
   typedef unsigned short __u16;

   typedef __signed__ int __s32;
   typedef unsigned int __u32;

   #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
   #if defined(CONFIG_RISCV_32)
     typedef __signed__ long long __s64;
     typedef unsigned long long __u64;
   #elif defined (CONFIG_RISCV_64)
     typedef __signed__ long __s64;
     typedef unsigned long __u64;
   #endif
   #endif

Then it turns out that there is no any sense in:

   typedef signed char s8;
   typedef unsigned char u8;

   typedef signed short s16;
   typedef unsigned short u16;

   typedef signed int s32;
   typedef unsigned int u32;

   typedef signed long long s64;
   typedef unsigned long long u64;
     OR
   typedef signed long s64;
   typedef unsigned long u64;
Quoted 1 line

As I understand instead of them should be used: {u|s}int<N>_t.

Quoted 4 lines

Hmm, the situation is worse than I thought (recalled) it was: You're right, xen/types.h actually uses __{u,s}<N>. So I'm sorry for mis- guiding you; we'll need to do more cleanup first for asm/types.h to become smaller.

What is the reason for not declaring __{u,s}<N> directly in xen/types.h as type alias to {u,s}<N>?

IIUC __{u,s}<N> and {u,s}<N> are needed by code ported from Linux while Xen code should use {u|s}int<N>_t instead, right?

Signature · 1 line
Xenia
#11 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 62 lines · Xenia Ragiadakou
Quoted 55 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
    - Nothing changed
---
Changes in V2:
    - Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you

It looks then I didn't understand which one of types are needed.

In "[PATCH v1 2/8] xen/riscv: introduce asm/types.h header file" all types were introduced as most of them are used in <xen/types.h>:
__{u|s}{8|16|32|64}. Thereby it looks like the following types in <asm/types.h> should be present from the start:

   typedef __signed__ char __s8;
   typedef unsigned char __u8;

   typedef __signed__ short __s16;
   typedef unsigned short __u16;

   typedef __signed__ int __s32;
   typedef unsigned int __u32;

   #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
   #if defined(CONFIG_RISCV_32)
     typedef __signed__ long long __s64;
     typedef unsigned long long __u64;
   #elif defined (CONFIG_RISCV_64)
     typedef __signed__ long __s64;
     typedef unsigned long __u64;
   #endif
   #endif

Then it turns out that there is no any sense in:

   typedef signed char s8;
   typedef unsigned char u8;

   typedef signed short s16;
   typedef unsigned short u16;

   typedef signed int s32;
   typedef unsigned int u32;

   typedef signed long long s64;
   typedef unsigned long long u64;
     OR
   typedef signed long s64;
   typedef unsigned long u64;
Quoted 1 line

As I understand instead of them should be used: {u|s}int<N>_t.

Quoted 4 lines

Hmm, the situation is worse than I thought (recalled) it was: You're right, xen/types.h actually uses __{u,s}<N>. So I'm sorry for mis- guiding you; we'll need to do more cleanup first for asm/types.h to become smaller.

Quoted 5 lines

What is the reason for not declaring __{u,s}<N> directly in xen/types.h as type alias to {u,s}<N>?

IIUC __{u,s}<N> and {u,s}<N> are needed by code ported from Linux while Xen code should use {u|s}int<N>_t instead, right?

Yes. Hence in the long run only Linux files should get to see __{u,s}<N> and {u,s}<N>, perhaps from a new linux-types.h.

Jan

#12 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 63 lines · Jan Beulich
Quoted 62 lines · Xenia Ragiadakou
Quoted 59 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko

---
Changes in V3:
    - Nothing changed
---
Changes in V2:
    - Remove unneeded now types from <asm/types.h>

I guess you went a little too far: Types used in common code, even if you

It looks then I didn't understand which one of types are needed.

In "[PATCH v1 2/8] xen/riscv: introduce asm/types.h header file" all types were introduced as most of them are used in <xen/types.h>:
__{u|s}{8|16|32|64}. Thereby it looks like the following types in <asm/types.h> should be present from the start:

    typedef __signed__ char __s8;
    typedef unsigned char __u8;

    typedef __signed__ short __s16;
    typedef unsigned short __u16;

    typedef __signed__ int __s32;
    typedef unsigned int __u32;

    #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
    #if defined(CONFIG_RISCV_32)
      typedef __signed__ long long __s64;
      typedef unsigned long long __u64;
    #elif defined (CONFIG_RISCV_64)
      typedef __signed__ long __s64;
      typedef unsigned long __u64;
    #endif
    #endif
   Then it turns out that there is no any sense in:
    typedef signed char s8;
    typedef unsigned char u8;

    typedef signed short s16;
    typedef unsigned short u16;

    typedef signed int s32;
    typedef unsigned int u32;

    typedef signed long long s64;
    typedef unsigned long long u64;
      OR
    typedef signed long s64;
    typedef unsigned long u64;
Quoted 1 line

As I understand instead of them should be used: {u|s}int<N>_t.

Hmm, the situation is worse than I thought (recalled) it was: You're right, xen/types.h actually uses __{u,s}<N>. So I'm sorry for mis- guiding you; we'll need to do more cleanup first for asm/types.h to become smaller.

Quoted 8 lines
Quoted 5 lines

What is the reason for not declaring __{u,s}<N> directly in xen/types.h as type alias to {u,s}<N>?

IIUC __{u,s}<N> and {u,s}<N> are needed by code ported from Linux while Xen code should use {u|s}int<N>_t instead, right?

Yes. Hence in the long run only Linux files should get to see __{u,s}<N> and {u,s}<N>, perhaps from a new linux-types.h.

Thanks for the clarification. Could you please help me understand also why __signed__ keyword is required when declaring __{u,s}<N>? I mean why __{u,s}<N> cannot be declared using the signed type specifier, just like {u,s}<N>?

Signature · 1 line
Xenia
#13 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 4 lines · Xenia Ragiadakou

Could you please help me understand also
why __signed__ keyword is required when declaring __{u,s}<N>? I mean why __{u,s}<N> cannot be declared using the signed type specifier, just like {u,s}<N>?

I'm afraid I can't, as this looks to have been (blindly?) imported from Linux very, very long ago. Having put time in going through our own history, I'm afraid I don't want to go further and see whether I could spot the reason for you by going through Linux'es.

Jan

#14 lore raw

Re: [PATCH v3 2/6] xen/riscv: introduce asm/types.h header file

Quoted 10 lines · Jan Beulich
Quoted 4 lines · Xenia Ragiadakou

Could you please help me understand also
why __signed__ keyword is required when declaring __{u,s}<N>? I mean why __{u,s}<N> cannot be declared using the signed type specifier, just like {u,s}<N>?

I'm afraid I can't, as this looks to have been (blindly?) imported from Linux very, very long ago. Having put time in going through our own history, I'm afraid I don't want to go further and see whether I could spot the reason for you by going through Linux'es.

Sorry, I was not aiming to drag you (or anyone) into spotting why Linux uses __signed__ when declaring __s<N>. AfAIU these types are exported and used in userspace and maybe the reason is to support building with pre-standard C compilers. I am just wondering why Xen, that is compiled with std=c99, uses __signed__. If there is no reason, I think this difference between the declarations of __{u,s}<N> and {u,s}<N> is misleading and confusing (to me at least).

Signature · 1 line
Xenia