Skip to contentSkip to conversation

Minimal build for RISCV

PATCH Superseded Connor Davis 6 participants 34 messages Feb 25, 2021 – May 14, 2021 RISC-V

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover Minimal build for RISCV

Hi all,

This series introduces a minimal build for RISCV. It is based on Bobby's previous work from last year[0]. I have worked to rebase onto current Xen, as well as update the various header files borrowed from Linux.

This series provides the patches necessary to get a minimal build working. The build is "minimal" in the sense that 1) it uses a minimal config and 2) files, functions, and variables are included if and only if they are required for a successful build based on the config. It doesn't run at all, as the functions just have stub implementations.

My hope is that this can serve as a useful example for future ports as well as inform the community of exactly what is imposed by common code onto new architectures.

The first 4 patches are mods to non-RISCV bits that enable building a config with:

!CONFIG_HAS_NS16550
!CONFIG_HAS_PASSTHROUGH
NR_CPUS == 1
!CONFIG_GRANT_TABLE

respectively. The fifth patch adds the RISCV files, and the last patch adds a docker container for doing the build. To build from the docker container (after creating it locally), you can run the following:

  $ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen 

The sources taken from Linux are documented in arch/riscv/README.sources. There were also some files copied from arm:

asm-arm/softirq.h
asm-arm/random.h
asm-arm/nospec.h
asm-arm/numa.h
asm-arm/p2m.h
asm-arm/delay.h
asm-arm/debugger.h
asm-arm/desc.h
asm-arm/guest_access.h
asm-arm/hardirq.h
lib/find_next_bit.c

I imagine some of these will want some consolidation, but I put them under the respective RISCV directories for now.

[0] https://lore.kernel.org/xen-devel/[email protected]/

Connor Davis (6):
xen/char: Default HAS_NS16550 to y only for X86 and ARM xen/common: Guard iommu symbols with CONFIG_HAS_PASSTHROUGH xen/sched: Fix build when NR_CPUS == 1
xen: Fix build when !CONFIG_GRANT_TABLE
xen: Add files needed for minimal riscv build
automation: add container for riscv64 builds

 automation/build/archlinux/riscv64.dockerfile |  32 ++
 automation/scripts/containerize               |   1 +
 config/riscv64.mk                             |   7 +
 xen/Makefile                                  |   8 +-
 xen/arch/riscv/Kconfig                        |  54 +++
 xen/arch/riscv/Kconfig.debug                  |   0
 xen/arch/riscv/Makefile                       |  57 +++
 xen/arch/riscv/README.source                  |  19 +
 xen/arch/riscv/Rules.mk                       |  13 +
 xen/arch/riscv/arch.mk                        |   7 +
 xen/arch/riscv/configs/riscv64_defconfig      |  12 +
 xen/arch/riscv/delay.c                        |  16 +
 xen/arch/riscv/domain.c                       | 144 +++++++
 xen/arch/riscv/domctl.c                       |  36 ++
 xen/arch/riscv/guestcopy.c                    |  57 +++
 xen/arch/riscv/head.S                         |   6 +
 xen/arch/riscv/irq.c                          |  78 ++++
 xen/arch/riscv/lib/Makefile                   |   1 +
 xen/arch/riscv/lib/find_next_bit.c            | 284 +++++++++++++
 xen/arch/riscv/mm.c                           |  93 +++++
 xen/arch/riscv/p2m.c                          | 150 +++++++
 xen/arch/riscv/percpu.c                       |  17 +
 xen/arch/riscv/platforms/Kconfig              |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c          |  31 ++
 xen/arch/riscv/setup.c                        |  27 ++
 xen/arch/riscv/shutdown.c                     |  28 ++
 xen/arch/riscv/smp.c                          |  35 ++
 xen/arch/riscv/smpboot.c                      |  34 ++
 xen/arch/riscv/sysctl.c                       |  33 ++
 xen/arch/riscv/time.c                         |  35 ++
 xen/arch/riscv/traps.c                        |  35 ++
 xen/arch/riscv/vm_event.c                     |  39 ++
 xen/arch/riscv/xen.lds.S                      | 113 ++++++
 xen/common/domain.c                           |   2 +
 xen/common/memory.c                           |  10 +
 xen/common/sched/core.c                       |   2 +-
 xen/common/sysctl.c                           |   2 +
 xen/drivers/char/Kconfig                      |   2 +-
 xen/drivers/char/serial.c                     |   1 +
 xen/include/asm-riscv/altp2m.h                |  39 ++
 xen/include/asm-riscv/asm.h                   |  77 ++++
 xen/include/asm-riscv/asm_defns.h             |  24 ++
 xen/include/asm-riscv/atomic.h                | 204 ++++++++++
 xen/include/asm-riscv/bitops.h                | 331 +++++++++++++++
 xen/include/asm-riscv/bug.h                   |  54 +++
 xen/include/asm-riscv/byteorder.h             |  16 +
 xen/include/asm-riscv/cache.h                 |  24 ++
 xen/include/asm-riscv/cmpxchg.h               | 382 ++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h        |  32 ++
 xen/include/asm-riscv/config.h                | 110 +++++
 xen/include/asm-riscv/cpufeature.h            |  17 +
 xen/include/asm-riscv/csr.h                   | 219 ++++++++++
 xen/include/asm-riscv/current.h               |  47 +++
 xen/include/asm-riscv/debugger.h              |  15 +
 xen/include/asm-riscv/delay.h                 |  15 +
 xen/include/asm-riscv/desc.h                  |  12 +
 xen/include/asm-riscv/device.h                |  15 +
 xen/include/asm-riscv/div64.h                 |  23 ++
 xen/include/asm-riscv/domain.h                |  50 +++
 xen/include/asm-riscv/event.h                 |  42 ++
 xen/include/asm-riscv/fence.h                 |  12 +
 xen/include/asm-riscv/flushtlb.h              |  34 ++
 xen/include/asm-riscv/grant_table.h           |  12 +
 xen/include/asm-riscv/guest_access.h          |  41 ++
 xen/include/asm-riscv/guest_atomics.h         |  60 +++
 xen/include/asm-riscv/hardirq.h               |  27 ++
 xen/include/asm-riscv/hypercall.h             |  12 +
 xen/include/asm-riscv/init.h                  |  42 ++
 xen/include/asm-riscv/io.h                    | 283 +++++++++++++
 xen/include/asm-riscv/iocap.h                 |  13 +
 xen/include/asm-riscv/iommu.h                 |  46 +++
 xen/include/asm-riscv/irq.h                   |  58 +++
 xen/include/asm-riscv/mem_access.h            |   4 +
 xen/include/asm-riscv/mm.h                    | 246 +++++++++++
 xen/include/asm-riscv/monitor.h               |  65 +++
 xen/include/asm-riscv/nospec.h                |  25 ++
 xen/include/asm-riscv/numa.h                  |  41 ++
 xen/include/asm-riscv/p2m.h                   | 218 ++++++++++
 xen/include/asm-riscv/page-bits.h             |  11 +
 xen/include/asm-riscv/page.h                  |  73 ++++
 xen/include/asm-riscv/paging.h                |  15 +
 xen/include/asm-riscv/pci.h                   |  31 ++
 xen/include/asm-riscv/percpu.h                |  33 ++
 xen/include/asm-riscv/processor.h             |  59 +++
 xen/include/asm-riscv/random.h                |   9 +
 xen/include/asm-riscv/regs.h                  |  23 ++
 xen/include/asm-riscv/setup.h                 |  14 +
 xen/include/asm-riscv/smp.h                   |  46 +++
 xen/include/asm-riscv/softirq.h               |  16 +
 xen/include/asm-riscv/spinlock.h              |  12 +
 xen/include/asm-riscv/string.h                |  28 ++
 xen/include/asm-riscv/sysregs.h               |  16 +
 xen/include/asm-riscv/system.h                |  99 +++++
 xen/include/asm-riscv/time.h                  |  31 ++
 xen/include/asm-riscv/trace.h                 |  12 +
 xen/include/asm-riscv/types.h                 |  60 +++
 xen/include/asm-riscv/vm_event.h              |  55 +++
 xen/include/asm-riscv/xenoprof.h              |  12 +
 xen/include/public/arch-riscv.h               | 183 +++++++++
 xen/include/public/arch-riscv/hvm/save.h      |  39 ++
 xen/include/public/hvm/save.h                 |   2 +
 xen/include/public/pmu.h                      |   2 +
 xen/include/public/xen.h                      |   2 +
 xen/include/xen/domain.h                      |   1 +
 xen/include/xen/grant_table.h                 |   2 +
 105 files changed, 5421 insertions(+), 4 deletions(-)
 create mode 100644 automation/build/archlinux/riscv64.dockerfile
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Kconfig.debug
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/README.source
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/arch.mk
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/asm_defns.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/compiler_types.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/cpufeature.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page-bits.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/6 xen/char: Default HAS_NS16550 to y only for X86 and ARM

Defaulting to yes only for X86 and ARM reduces the requirements for a minimal build when porting new architectures.

---
 xen/drivers/char/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/char/Kconfig +1 -1
index b572305657..b15b0c8d6a 100644
@@ -1,6 +1,6 @@
 config HAS_NS16550
 	bool "NS16550 UART driver" if ARM
-	default y
+	default y if (ARM || X86)
 	help
 	  This selects the 16550-series UART support. For most systems, say Y.
 
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/6 xen/common: Guard iommu symbols with CONFIG_HAS_PASSTHROUGH

In reply to Connor Davis

The variables iommu_enabled and iommu_dont_flush_iotlb are defined in drivers/passthrough/iommu.c and are referenced in common code, which causes the link to fail when !CONFIG_HAS_PASSTHROUGH.

Guard references to these variables in common code so that xen builds when !CONFIG_HAS_PASSTHROUGH.

---
 xen/common/domain.c |  2 ++
 xen/common/memory.c | 10 ++++++++++
 xen/common/sysctl.c |  2 ++
 3 files changed, 14 insertions(+)
xen/common/domain.c +2 -0
index d85984638a..ad66bca325 100644
@@ -501,7 +501,9 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
             return -EINVAL;
         }
 
+#ifdef CONFIG_HAS_PASSTHROUGH
         if ( !iommu_enabled )
+#endif
         {
             dprintk(XENLOG_INFO, "IOMMU requested but not available\n");
             return -EINVAL;
xen/common/memory.c +10 -0
index 76b9f58478..7135324857 100644
@@ -294,7 +294,9 @@ int guest_remove_page(struct domain *d, unsigned long gmfn)
     p2m_type_t p2mt;
 #endif
     mfn_t mfn;
+#ifdef CONFIG_HAS_PASSTHROUGH
     bool *dont_flush_p, dont_flush;
+#endif
     int rc;
 
 #ifdef CONFIG_X86
@@ -385,13 +387,17 @@ int guest_remove_page(struct domain *d, unsigned long gmfn)
      * Since we're likely to free the page below, we need to suspend
      * xenmem_add_to_physmap()'s suppressing of IOMMU TLB flushes.
      */
+#ifdef CONFIG_HAS_PASSTHROUGH
     dont_flush_p = &this_cpu(iommu_dont_flush_iotlb);
     dont_flush = *dont_flush_p;
     *dont_flush_p = false;
+#endif
 
     rc = guest_physmap_remove_page(d, _gfn(gmfn), mfn, 0);
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     *dont_flush_p = dont_flush;
+#endif
 
     /*
      * With the lack of an IOMMU on some platforms, domains with DMA-capable
@@ -839,11 +845,13 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
     xatp->gpfn += start;
     xatp->size -= start;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     if ( is_iommu_enabled(d) )
     {
        this_cpu(iommu_dont_flush_iotlb) = 1;
        extra.ppage = &pages[0];
     }
+#endif
 
     while ( xatp->size > done )
     {
@@ -868,6 +876,7 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
         }
     }
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     if ( is_iommu_enabled(d) )
     {
         int ret;
@@ -894,6 +903,7 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
         if ( unlikely(ret) && rc >= 0 )
             rc = ret;
     }
+#endif
 
     return rc;
 }
xen/common/sysctl.c +2 -0
index 3558641cd9..b4dde7bef6 100644
@@ -271,12 +271,14 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         pi->cpu_khz = cpu_khz;
         pi->max_mfn = get_upper_mfn_bound();
         arch_do_physinfo(pi);
+#ifdef CONFIG_HAS_PASSTHROUGH
         if ( iommu_enabled )
         {
             pi->capabilities |= XEN_SYSCTL_PHYSCAP_directio;
             if ( iommu_hap_pt_share )
                 pi->capabilities |= XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share;
         }
+#endif
         if ( vmtrace_available )
             pi->capabilities |= XEN_SYSCTL_PHYSCAP_vmtrace;
 
Signature · 1 line
2.27.0
#3 lore raw

Re: [PATCH for-next 2/6] xen/common: Guard iommu symbols with CONFIG_HAS_PASSTHROUGH

xen/common/domain.c static int sanitise_domain_config(struct xen_domctl_createdomain *config) · line 509

Quoted 12 lines · Connor Davis
xen/common/domain.c +2 -0
@@ -501,7 +501,9 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
             return -EINVAL;
         }
 
+#ifdef CONFIG_HAS_PASSTHROUGH
         if ( !iommu_enabled )
+#endif
         {
             dprintk(XENLOG_INFO, "IOMMU requested but not available\n");
             return -EINVAL;

Where possible - to avoid such #ifdef-ary - the symbol instead should get #define-d to a sensible value ("false" in this case) in the header. The other cases here may indeed need to remain as you have them.

Jan

#4 lore raw

Re: [PATCH for-next 2/6] xen/common: Guard iommu symbols with CONFIG_HAS_PASSTHROUGH

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Connor Davis
xen/common/domain.c +0 -0
@@ -501,7 +501,9 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
             return -EINVAL;
         }
 
Quoted 11 lines

xen/common/domain.c static int sanitise_domain_config(struct xen_domctl_createdomain *config) · line 509

Quoted 6 lines
xen/common/domain.c +2 -0
+#ifdef CONFIG_HAS_PASSTHROUGH
         if ( !iommu_enabled )
+#endif
         {
             dprintk(XENLOG_INFO, "IOMMU requested but not available\n");
             return -EINVAL;

Where possible - to avoid such #ifdef-ary - the symbol instead should get #define-d to a sensible value ("false" in this case) in the header. The other cases here may indeed need to remain as you have them.

Do you prefer the #define in the same function near the if or somwhere near the top of the file?

Connor

#5 lore raw

Re: [PATCH for-next 2/6] xen/common: Guard iommu symbols with CONFIG_HAS_PASSTHROUGH

Quoted 19 lines · Connor Davis
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Connor Davis
xen/common/domain.c +0 -0
@@ -501,7 +501,9 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
             return -EINVAL;
         }
 
Quoted 11 lines

xen/common/domain.c static int sanitise_domain_config(struct xen_domctl_createdomain *config) · line 509

Quoted 6 lines
xen/common/domain.c +2 -0
+#ifdef CONFIG_HAS_PASSTHROUGH
         if ( !iommu_enabled )
+#endif
         {
             dprintk(XENLOG_INFO, "IOMMU requested but not available\n");
             return -EINVAL;

Where possible - to avoid such #ifdef-ary - the symbol instead should get #define-d to a sensible value ("false" in this case) in the header. The other cases here may indeed need to remain as you have them.

Quoted 2 lines

Do you prefer the #define in the same function near the if or somwhere near the top of the file?

Neither, if I understand you correctly. It should be in the same header where the extern declaration lives, for the whole code base to consume.

Jan

#6 lore raw

PATCH 3/6 xen/sched: Fix build when NR_CPUS == 1

In reply to Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index 9745a77eee..f5ec65bf9b 100644
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
     if ( idle_vcpu[cpu] == NULL )
Signature · 1 line
2.27.0
#7 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 19 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +0 -0
index 9745a77eee..f5ec65bf9b 100644

xen/common/sched/core.c static int cpu_schedule_up(unsigned int cpu) · line 2769

Quoted 8 lines
xen/common/sched/core.c +1 -1
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
     if ( idle_vcpu[cpu] == NULL )

I'm not convinced a compiler warning is due here, and in turn I'm not sure we want/need to work around this the way you do. First question is whether that's just a specific compiler version that's flawed. If it's not just a special case (e.g. some unreleased version) we may want to think of possible alternatives - the addition looks really odd to me.

Jan

#8 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 27 lines · Jan Beulich
Quoted 26 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index 9745a77eee..f5ec65bf9b 100644
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
Quoted 4 lines

xen/common/sched/core.c static int cpu_schedule_up(unsigned int cpu) · line 2769

Quoted 1 line
xen/common/sched/core.c +0 -0
     if ( idle_vcpu[cpu] == NULL )

I'm not convinced a compiler warning is due here, and in turn I'm not sure we want/need to work around this the way you do.

It seems like a reasonable warning to me, but of course I'm open to dealing with it in a different way.

Quoted 2 lines

First question is whether that's just a specific compiler version that's flawed. If it's not just a special case (e.g.

The docker container uses gcc 10.2.0 from
https://github.com/riscv/riscv-gnu-toolchain

Quoted 4 lines

some unreleased version) we may want to think of possible alternatives - the addition looks really odd to me.

Jan

Connor

#9 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 33 lines · Connor Davis
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index 9745a77eee..f5ec65bf9b 100644
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
Quoted 4 lines

xen/common/sched/core.c static int cpu_schedule_up(unsigned int cpu) · line 2769

Quoted 1 line
xen/common/sched/core.c +0 -0
     if ( idle_vcpu[cpu] == NULL )

I'm not convinced a compiler warning is due here, and in turn I'm not sure we want/need to work around this the way you do.

Quoted 8 lines

It seems like a reasonable warning to me, but of course I'm open to dealing with it in a different way.

Quoted 2 lines

First question is whether that's just a specific compiler version that's flawed. If it's not just a special case (e.g.

The docker container uses gcc 10.2.0 from
https://github.com/riscv/riscv-gnu-toolchain

Ah yes, at -O2 I can observe the warning on e.g.

extern int array[N];

int test(unsigned i) {
	if(i == N - 1)
		return 0;
	return array[i];
}

when N=1. No warning appears when N=2 or higher, yet if it is sensible to emit for N=1 then it would imo be similarly sensible to emit in other cases. The only difference is that when N=1, there's no i for which the array access would ever be valid, while e.g. for N=2 there's exactly one such i.

I've tried an x86 build with NR_CPUS=1, and this hits the case you found and a 2nd one, where behavior is even more puzzling. For the case you've found I'd like to suggest as alternative

@@ -2769,6 +2769,12 @@ static int cpu_schedule_up(unsigned int

     if ( cpu == 0 )
         return 0;

+ /*

+     * Guard in particular also against the compiler suspecting out-of-bounds
+     * array accesses below when NR_CPUS=1.
+     */
+    BUG_ON(cpu >= NR_CPUS);
+
     if ( idle_vcpu[cpu] == NULL )
         vcpu_create(idle_vcpu[0]->domain, cpu);
     else

To fix the x86 build in this regard we'd additionally need something along the lines of

xen/arch/x86/genapic/x2apic.c +11 -1
@@ -54,7 +54,17 @@ static void init_apic_ldr_x2apic_cluster
     per_cpu(cluster_cpus, this_cpu) = cluster_cpus_spare;
     for_each_online_cpu ( cpu )
     {
-        if (this_cpu == cpu || x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
+        if ( this_cpu == cpu )
+            continue;
+        /*
+         * Guard in particular against the compiler suspecting out-of-bounds
+         * array accesses below when NR_CPUS=1 (oddly enough with gcc 10 it
+         * is the 1st of these alone which actually helps, not the 2nd, nor
+         * are both required together there).
+         */
+        BUG_ON(this_cpu >= NR_CPUS);
+        BUG_ON(cpu >= NR_CPUS);
+        if ( x2apic_cluster(this_cpu) != x2apic_cluster(cpu) )
             continue;
         per_cpu(cluster_cpus, this_cpu) = per_cpu(cluster_cpus, cpu);
         break;

but the comment points out how strangely the compiler behaves here. Even flipping around the two sides of the != doesn't change its behavior. It is perhaps relevant to note here that there's no special casing of smp_processor_id() in the NR_CPUS=1 case, so the compiler can't infer this_cpu == 0.

Once we've settled on how to change common/sched/core.c I guess I'll then adjust the x86-specific change accordingly and submit as a separate fix (or I could of course also bundle both changes then).

Jan

#10 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 20 lines · Jan Beulich
Quoted 15 lines · Connor Davis
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Connor Davis

index 9745a77eee..f5ec65bf9b 100644

xen/common/sched/core.c +0 -0
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int
 cpu)
      cpumask_set_cpu(cpu, &sched_res_mask);


     /* Boot CPU is dealt with later in scheduler_init(). */ -    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;

     if ( idle_vcpu[cpu] == NULL )

(quoted diff) +0 -0
@@ -2769,6 +2769,12 @@ static int cpu_schedule_up(unsigned int
      if ( cpu == 0 )
          return 0;
Quoted 9 lines


+    /*
+     * Guard in particular also against the compiler suspecting out- of-bounds
+     * array accesses below when NR_CPUS=1.
+     */
+    BUG_ON(cpu >= NR_CPUS);
+

I would be fine with this.

Actually, I do prefer it too, over the "is index 0 or is the array length 1" check, which I also find confusing.

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#11 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

In reply to Jan Beulich
Quoted 34 lines · Jan Beulich
Quoted 11 lines · Connor Davis
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |

Ah yes, at -O2 I can observe the warning on e.g.

extern int array[N];

int test(unsigned i) {
	if(i == N - 1)
		return 0;
	return array[i];
}

when N=1. No warning appears when N=2 or higher, yet if it is sensible to emit for N=1 then it would imo be similarly sensible to emit in other cases. The only difference is that when N=1, there's no i for which the array access would ever be valid, while e.g. for N=2 there's exactly one such i.

I've tried an x86 build with NR_CPUS=1, and this hits the case you found and a 2nd one, where behavior is even more puzzling. For the case you've found I'd like to suggest as alternative

Review static int cpu_schedule_up(unsigned int · line 2777

Quoted 9 lines
(quoted diff) +6 -0
@@ -2769,6 +2769,12 @@ static int cpu_schedule_up(unsigned int
     if ( cpu == 0 )
         return 0;
 
+    /*
+     * Guard in particular also against the compiler suspecting out-of-bounds
+     * array accesses below when NR_CPUS=1.
+     */
+    BUG_ON(cpu >= NR_CPUS);
+

Yeah I like this better than my approach.

Quoted 35 lines
(quoted diff) +0 -0
     if ( idle_vcpu[cpu] == NULL )
         vcpu_create(idle_vcpu[0]->domain, cpu);
     else

To fix the x86 build in this regard we'd additionally need something along the lines of

xen/arch/x86/genapic/x2apic.c +11 -1
@@ -54,7 +54,17 @@ static void init_apic_ldr_x2apic_cluster
     per_cpu(cluster_cpus, this_cpu) = cluster_cpus_spare;
     for_each_online_cpu ( cpu )
     {
-        if (this_cpu == cpu || x2apic_cluster(this_cpu) != x2apic_cluster(cpu))
+        if ( this_cpu == cpu )
+            continue;
+        /*
+         * Guard in particular against the compiler suspecting out-of-bounds
+         * array accesses below when NR_CPUS=1 (oddly enough with gcc 10 it
+         * is the 1st of these alone which actually helps, not the 2nd, nor
+         * are both required together there).
+         */
+        BUG_ON(this_cpu >= NR_CPUS);
+        BUG_ON(cpu >= NR_CPUS);
+        if ( x2apic_cluster(this_cpu) != x2apic_cluster(cpu) )
             continue;
         per_cpu(cluster_cpus, this_cpu) = per_cpu(cluster_cpus, cpu);
         break;

but the comment points out how strangely the compiler behaves here. Even flipping around the two sides of the != doesn't change its behavior. It is perhaps relevant to note here that there's no special casing of smp_processor_id() in the NR_CPUS=1 case, so the compiler can't infer this_cpu == 0.

Quoted 3 lines

Once we've settled on how to change common/sched/core.c I guess I'll then adjust the x86-specific change accordingly and submit as a separate fix (or I could of course also bundle both changes then).

Feel free to bundle both.

Connor

#12 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

In reply to Connor Davis
Quoted 20 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +0 -0
index 9745a77eee..f5ec65bf9b 100644

xen/common/sched/core.c static int cpu_schedule_up(unsigned int cpu) · line 2769

Quoted 8 lines
xen/common/sched/core.c +1 -1
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
     if ( idle_vcpu[cpu] == NULL )

Interesting. I wonder when this changed in GCC.

I haven't yet seen this issue compiling with:
NR_CPUS=1
ARCH=riscv64
riscv64-unknown-linux-gnu-gcc (GCC) 10.1.0

Which version of GCC are you seeing emit this?

- Bob

#13 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 32 lines · Bob Eshleman
Quoted 20 lines · Connor Davis

Return from cpu_schedule_up when either cpu is 0 or NR_CPUS == 1. This fixes the following:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds]
2769 | if ( idle_vcpu[cpu] == NULL )

      |
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +0 -0
index 9745a77eee..f5ec65bf9b 100644

xen/common/sched/core.c static int cpu_schedule_up(unsigned int cpu) · line 2769

Quoted 8 lines
xen/common/sched/core.c +1 -1
@@ -2763,7 +2763,7 @@ static int cpu_schedule_up(unsigned int cpu)
     cpumask_set_cpu(cpu, &sched_res_mask);
 
     /* Boot CPU is dealt with later in scheduler_init(). */
-    if ( cpu == 0 )
+    if ( cpu == 0 || NR_CPUS == 1 )
         return 0;
 
     if ( idle_vcpu[cpu] == NULL )

Interesting. I wonder when this changed in GCC.

Quoted 6 lines

I haven't yet seen this issue compiling with:
NR_CPUS=1
ARCH=riscv64
riscv64-unknown-linux-gnu-gcc (GCC) 10.1.0

Which version of GCC are you seeing emit this?

The one from cloned from github.com/riscv/riscv-gnu-toolchain in the docker container uses 10.2.0

Connor

#14 lore raw

Re: [PATCH for-next 3/6] xen/sched: Fix build when NR_CPUS == 1

Quoted 10 lines · Connor Davis
Quoted 3 lines · Bob Eshleman

riscv64-unknown-linux-gnu-gcc (GCC) 10.1.0

Which version of GCC are you seeing emit this?

The one from cloned from github.com/riscv/riscv-gnu-toolchain in the docker container uses 10.2.0

Connor

The commit I pinned in the container is actually for GDB only, since more recent versions broke when used with QEMU at the time of writing the dockerfile (this last June).

Since I built the container some months ago and no commit pinning for the compiler, it still contains 10.1.0 for me.

It _shouldn't_ be necessary... but since there is a lot of dev done on riscv-gcc, it might be worth talking about pinning the compiler version in the container.

-Bob

#15 lore raw

PATCH 4/6 xen: Fix build when !CONFIG_GRANT_TABLE

In reply to Connor Davis

Declare struct grant_table {}; in grant_table.h when !CONFIG_GRANT_TABLE. This fixes the following:

/build/xen/include/xen/grant_table.h:84:50: error: 'struct grant_table' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
84 | static inline int mem_sharing_gref_to_gfn(struct grant_table *gt,

      |
---
 xen/include/xen/grant_table.h | 2 ++
 1 file changed, 2 insertions(+)
xen/include/xen/grant_table.h +2 -0
index 63b6dc78f4..0e5f6f85c7 100644
@@ -66,6 +66,8 @@ int gnttab_acquire_resource(
 
 #define opt_max_grant_frames 0
 
+struct grant_table {};
+
 static inline int grant_table_init(struct domain *d,
                                    int max_grant_frames,
                                    int max_maptrack_frames)
Signature · 1 line
2.27.0
#16 lore raw

Re: [PATCH for-next 4/6] xen: Fix build when !CONFIG_GRANT_TABLE

xen/include/xen/grant_table.h int gnttab_acquire_resource( · line 73

Quoted 11 lines · Connor Davis
xen/include/xen/grant_table.h +2 -0
@@ -66,6 +66,8 @@ int gnttab_acquire_resource(
 
 #define opt_max_grant_frames 0
 
+struct grant_table {};
+
 static inline int grant_table_init(struct domain *d,
                                    int max_grant_frames,
                                    int max_maptrack_frames)

You shouldn't actually declare a struct, all you need is to move the forward decl further up in the file ahead of the #ifdef.

Jan

#17 lore raw

Re: [PATCH for-next 4/6] xen: Fix build when !CONFIG_GRANT_TABLE

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Connor Davis
xen/include/xen/grant_table.h +0 -0
@@ -66,6 +66,8 @@ int gnttab_acquire_resource(
 
 #define opt_max_grant_frames 0
 
Quoted 9 lines

xen/include/xen/grant_table.h int gnttab_acquire_resource( · line 73

Quoted 5 lines
xen/include/xen/grant_table.h +2 -0
+struct grant_table {};
+
 static inline int grant_table_init(struct domain *d,
                                    int max_grant_frames,
                                    int max_maptrack_frames)

You shouldn't actually declare a struct, all you need is to move the forward decl further up in the file ahead of the #ifdef.

Thanks, will fix this in v2.

Connor

#18 lore raw

PATCH 5/6 xen: Add files needed for minimal riscv build

In reply to Connor Davis

Add the minimum code required to get xen to build with XEN_TARGET_ARCH=riscv64. It is minimal in the sense that every file and function added is required for a successful build, given the .config generated from riscv64_defconfig. The function implementations are just stubs; actual implmentations will need to be added later.

---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   8 +-
 xen/arch/riscv/Kconfig                   |  54 ++++
 xen/arch/riscv/Kconfig.debug             |   0
 xen/arch/riscv/Makefile                  |  57 ++++
 xen/arch/riscv/README.source             |  19 ++
 xen/arch/riscv/Rules.mk                  |  13 +
 xen/arch/riscv/arch.mk                   |   7 +
 xen/arch/riscv/configs/riscv64_defconfig |  12 +
 xen/arch/riscv/delay.c                   |  16 +
 xen/arch/riscv/domain.c                  | 144 +++++++++
 xen/arch/riscv/domctl.c                  |  36 +++
 xen/arch/riscv/guestcopy.c               |  57 ++++
 xen/arch/riscv/head.S                    |   6 +
 xen/arch/riscv/irq.c                     |  78 +++++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++++++++++++
 xen/arch/riscv/mm.c                      |  93 ++++++
 xen/arch/riscv/p2m.c                     | 150 +++++++++
 xen/arch/riscv/percpu.c                  |  17 +
 xen/arch/riscv/platforms/Kconfig         |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c     |  31 ++
 xen/arch/riscv/setup.c                   |  27 ++
 xen/arch/riscv/shutdown.c                |  28 ++
 xen/arch/riscv/smp.c                     |  35 +++
 xen/arch/riscv/smpboot.c                 |  34 ++
 xen/arch/riscv/sysctl.c                  |  33 ++
 xen/arch/riscv/time.c                    |  35 +++
 xen/arch/riscv/traps.c                   |  35 +++
 xen/arch/riscv/vm_event.c                |  39 +++
 xen/arch/riscv/xen.lds.S                 | 113 +++++++
 xen/drivers/char/serial.c                |   1 +
 xen/include/asm-riscv/altp2m.h           |  39 +++
 xen/include/asm-riscv/asm.h              |  77 +++++
 xen/include/asm-riscv/asm_defns.h        |  24 ++
 xen/include/asm-riscv/atomic.h           | 204 ++++++++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++++++++++++++
 xen/include/asm-riscv/bug.h              |  54 ++++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 ++
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h   |  32 ++
 xen/include/asm-riscv/config.h           | 110 +++++++
 xen/include/asm-riscv/cpufeature.h       |  17 +
 xen/include/asm-riscv/csr.h              | 219 +++++++++++++
 xen/include/asm-riscv/current.h          |  47 +++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  15 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 ++
 xen/include/asm-riscv/domain.h           |  50 +++
 xen/include/asm-riscv/event.h            |  42 +++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  34 ++
 xen/include/asm-riscv/grant_table.h      |  12 +
 xen/include/asm-riscv/guest_access.h     |  41 +++
 xen/include/asm-riscv/guest_atomics.h    |  60 ++++
 xen/include/asm-riscv/hardirq.h          |  27 ++
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +++
 xen/include/asm-riscv/io.h               | 283 +++++++++++++++++
 xen/include/asm-riscv/iocap.h            |  13 +
 xen/include/asm-riscv/iommu.h            |  46 +++
 xen/include/asm-riscv/irq.h              |  58 ++++
 xen/include/asm-riscv/mem_access.h       |   4 +
 xen/include/asm-riscv/mm.h               | 246 +++++++++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++++
 xen/include/asm-riscv/nospec.h           |  25 ++
 xen/include/asm-riscv/numa.h             |  41 +++
 xen/include/asm-riscv/p2m.h              | 218 +++++++++++++
 xen/include/asm-riscv/page-bits.h        |  11 +
 xen/include/asm-riscv/page.h             |  73 +++++
 xen/include/asm-riscv/paging.h           |  15 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  33 ++
 xen/include/asm-riscv/processor.h        |  59 ++++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  23 ++
 xen/include/asm-riscv/setup.h            |  14 +
 xen/include/asm-riscv/smp.h              |  46 +++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  12 +
 xen/include/asm-riscv/string.h           |  28 ++
 xen/include/asm-riscv/sysregs.h          |  16 +
 xen/include/asm-riscv/system.h           |  99 ++++++
 xen/include/asm-riscv/time.h             |  31 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  60 ++++
 xen/include/asm-riscv/vm_event.h         |  55 ++++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 183 +++++++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +
 97 files changed, 5370 insertions(+), 2 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Kconfig.debug
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/README.source
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/arch.mk
 create mode 100644 xen/arch/riscv/configs/riscv64_defconfig
 create mode 100644 xen/arch/riscv/delay.c
 create mode 100644 xen/arch/riscv/domain.c
 create mode 100644 xen/arch/riscv/domctl.c
 create mode 100644 xen/arch/riscv/guestcopy.c
 create mode 100644 xen/arch/riscv/head.S
 create mode 100644 xen/arch/riscv/irq.c
 create mode 100644 xen/arch/riscv/lib/Makefile
 create mode 100644 xen/arch/riscv/lib/find_next_bit.c
 create mode 100644 xen/arch/riscv/mm.c
 create mode 100644 xen/arch/riscv/p2m.c
 create mode 100644 xen/arch/riscv/percpu.c
 create mode 100644 xen/arch/riscv/platforms/Kconfig
 create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c
 create mode 100644 xen/arch/riscv/setup.c
 create mode 100644 xen/arch/riscv/shutdown.c
 create mode 100644 xen/arch/riscv/smp.c
 create mode 100644 xen/arch/riscv/smpboot.c
 create mode 100644 xen/arch/riscv/sysctl.c
 create mode 100644 xen/arch/riscv/time.c
 create mode 100644 xen/arch/riscv/traps.c
 create mode 100644 xen/arch/riscv/vm_event.c
 create mode 100644 xen/arch/riscv/xen.lds.S
 create mode 100644 xen/include/asm-riscv/altp2m.h
 create mode 100644 xen/include/asm-riscv/asm.h
 create mode 100644 xen/include/asm-riscv/asm_defns.h
 create mode 100644 xen/include/asm-riscv/atomic.h
 create mode 100644 xen/include/asm-riscv/bitops.h
 create mode 100644 xen/include/asm-riscv/bug.h
 create mode 100644 xen/include/asm-riscv/byteorder.h
 create mode 100644 xen/include/asm-riscv/cache.h
 create mode 100644 xen/include/asm-riscv/cmpxchg.h
 create mode 100644 xen/include/asm-riscv/compiler_types.h
 create mode 100644 xen/include/asm-riscv/config.h
 create mode 100644 xen/include/asm-riscv/cpufeature.h
 create mode 100644 xen/include/asm-riscv/csr.h
 create mode 100644 xen/include/asm-riscv/current.h
 create mode 100644 xen/include/asm-riscv/debugger.h
 create mode 100644 xen/include/asm-riscv/delay.h
 create mode 100644 xen/include/asm-riscv/desc.h
 create mode 100644 xen/include/asm-riscv/device.h
 create mode 100644 xen/include/asm-riscv/div64.h
 create mode 100644 xen/include/asm-riscv/domain.h
 create mode 100644 xen/include/asm-riscv/event.h
 create mode 100644 xen/include/asm-riscv/fence.h
 create mode 100644 xen/include/asm-riscv/flushtlb.h
 create mode 100644 xen/include/asm-riscv/grant_table.h
 create mode 100644 xen/include/asm-riscv/guest_access.h
 create mode 100644 xen/include/asm-riscv/guest_atomics.h
 create mode 100644 xen/include/asm-riscv/hardirq.h
 create mode 100644 xen/include/asm-riscv/hypercall.h
 create mode 100644 xen/include/asm-riscv/init.h
 create mode 100644 xen/include/asm-riscv/io.h
 create mode 100644 xen/include/asm-riscv/iocap.h
 create mode 100644 xen/include/asm-riscv/iommu.h
 create mode 100644 xen/include/asm-riscv/irq.h
 create mode 100644 xen/include/asm-riscv/mem_access.h
 create mode 100644 xen/include/asm-riscv/mm.h
 create mode 100644 xen/include/asm-riscv/monitor.h
 create mode 100644 xen/include/asm-riscv/nospec.h
 create mode 100644 xen/include/asm-riscv/numa.h
 create mode 100644 xen/include/asm-riscv/p2m.h
 create mode 100644 xen/include/asm-riscv/page-bits.h
 create mode 100644 xen/include/asm-riscv/page.h
 create mode 100644 xen/include/asm-riscv/paging.h
 create mode 100644 xen/include/asm-riscv/pci.h
 create mode 100644 xen/include/asm-riscv/percpu.h
 create mode 100644 xen/include/asm-riscv/processor.h
 create mode 100644 xen/include/asm-riscv/random.h
 create mode 100644 xen/include/asm-riscv/regs.h
 create mode 100644 xen/include/asm-riscv/setup.h
 create mode 100644 xen/include/asm-riscv/smp.h
 create mode 100644 xen/include/asm-riscv/softirq.h
 create mode 100644 xen/include/asm-riscv/spinlock.h
 create mode 100644 xen/include/asm-riscv/string.h
 create mode 100644 xen/include/asm-riscv/sysregs.h
 create mode 100644 xen/include/asm-riscv/system.h
 create mode 100644 xen/include/asm-riscv/time.h
 create mode 100644 xen/include/asm-riscv/trace.h
 create mode 100644 xen/include/asm-riscv/types.h
 create mode 100644 xen/include/asm-riscv/vm_event.h
 create mode 100644 xen/include/asm-riscv/xenoprof.h
 create mode 100644 xen/include/public/arch-riscv.h
 create mode 100644 xen/include/public/arch-riscv/hvm/save.h
config/riscv64.mk new file +7 -0
new file mode 100644
index 0000000000..0ec97838f9
@@ -0,0 +1,7 @@
+CONFIG_RISCV := y
+CONFIG_RISCV_64 := y
+CONFIG_RISCV_$(XEN_OS) := y
+
+CONFIG_XEN_INSTALL_SUFFIX :=
+
+CFLAGS +=
xen/Makefile +6 -2
index 544cc0995d..2381486c1f 100644
@@ -26,7 +26,9 @@ MAKEFLAGS += -rR
 EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
 
 ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+SRCARCH=$(shell echo $(ARCH) | \
+	  sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+	      -e s'/riscv.*/riscv/g')
 
 # Don't break if the build process wasn't called from the top level
 # we need XEN_TARGET_ARCH to generate the proper config
@@ -35,7 +37,8 @@ include $(XEN_ROOT)/Config.mk
 # Set ARCH/SUBARCH appropriately.
 export TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
 export TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
-                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+			        -e s'/riscv.*/riscv/g')
 
 # Allow someone to change their config file
 export KCONFIG_CONFIG ?= .config
@@ -335,6 +338,7 @@ _clean: delete-unfresh-files
 	$(MAKE) $(clean) xsm
 	$(MAKE) $(clean) crypto
 	$(MAKE) $(clean) arch/arm
+	$(MAKE) $(clean) arch/riscv
 	$(MAKE) $(clean) arch/x86
 	$(MAKE) $(clean) test
 	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
xen/arch/riscv/Kconfig new file +54 -0

54 lines not on this page · raw message

xen/arch/riscv/Kconfig.debug new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/Makefile new file +57 -0

57 lines not on this page · raw message

xen/arch/riscv/README.source new file +19 -0
new file mode 100644
index 0000000000..a04e06c5f7
@@ -0,0 +1,19 @@
+External RISCV Sources
+======================
+This documents the files copied from other projects for use in the
+RISCV code of Xen. 
+
+Linux (commit f40ddce88593, Feb. 14 2021)
+=========================================
+The following files were copied from arch/riscv/include/asm to
+xen/include/asm-riscv:
+
+asm.h -> asm.h
+atomic.h -> atomic.h
+bitops.h -> bitops.h
+csr.h -> csr.h
+{mmio,io}.h -> io.h
+fence.h -> fence.h
+cmpxchg.h -> cmpxchg.h
+compiler_types.h -> compiler_types.h
+timex.h -> time.h
xen/arch/riscv/Rules.mk new file +13 -0
new file mode 100644
index 0000000000..3c368fa05d
@@ -0,0 +1,13 @@
+########################################
+# RISCV-specific definitions
+
+ifeq ($(CONFIG_RISCV_64),y)
+    c_flags += -mabi=lp64
+    a_flags += -mabi=lp64
+endif
+
+riscv-march-$(CONFIG_RISCV_ISA_RV64IMA) := rv64ima
+riscv-march-$(CONFIG_RISCV_ISA_C)       := $(riscv-march-y)c
+
+c_flags += -march=$(riscv-march-y) -mstrict-align -mcmodel=medany
+a_flags += -march=$(riscv-march-y) -mstrict-align -mcmodel=medany
xen/arch/riscv/arch.mk new file +7 -0
new file mode 100644
index 0000000000..d5d68c9150
@@ -0,0 +1,7 @@
+########################################
+# riscv-specific definitions
+
+CFLAGS += -I$(BASEDIR)/include
+
+$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
+$(call cc-option-add,CFLAGS,CC,-Wnested-externs)
xen/arch/riscv/configs/riscv64_defconfig new file +12 -0
new file mode 100644
index 0000000000..664a5d2378
@@ -0,0 +1,12 @@
+# CONFIG_SCHED_CREDIT is not set
+# CONFIG_SCHED_RTDS is not set
+# CONFIG_SCHED_NULL is not set
+# CONFIG_SCHED_ARINC653 is not set
+# CONFIG_TRACEBUFFER is not set
+# CONFIG_DEBUG is not set
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_HYPFS is not set
+# CONFIG_GRANT_TABLE is not set
+# CONFIG_SPECULATIVE_HARDEN_ARRAY is not set
+
+CONFIG_EXPERT=y
xen/arch/riscv/delay.c new file +16 -0
new file mode 100644
index 0000000000..403b139b96
@@ -0,0 +1,16 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+void udelay(unsigned long usecs)
+{
+}
+EXPORT_SYMBOL(udelay);
xen/arch/riscv/domain.c new file +144 -0

144 lines not on this page · raw message

xen/arch/riscv/domctl.c new file +36 -0
new file mode 100644
index 0000000000..f81a13a9c4
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * Arch-specific domctl.c
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/sched.h>
+#include <public/domctl.h>
+
+void arch_get_domain_info(const struct domain *d,
+                          struct xen_domctl_getdomaininfo *info)
+{
+}
+
+long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
+                    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
+{
+    return -EOPNOTSUPP;
+}
+
+void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/guestcopy.c new file +57 -0

57 lines not on this page · raw message

xen/arch/riscv/head.S new file +6 -0
new file mode 100644
index 0000000000..0dbc27ba75
@@ -0,0 +1,6 @@
+#include <asm/config.h>
+
+        .text
+
+ENTRY(start)
+        j  start
xen/arch/riscv/irq.c new file +78 -0

78 lines not on this page · raw message

xen/arch/riscv/lib/Makefile new file +1 -0
new file mode 100644
index 0000000000..6fae6a1f10
@@ -0,0 +1 @@
+obj-y += find_next_bit.o
xen/arch/riscv/lib/find_next_bit.c new file +284 -0

284 lines not on this page · raw message

xen/arch/riscv/mm.c new file +93 -0

93 lines not on this page · raw message

xen/arch/riscv/p2m.c new file +150 -0

150 lines not on this page · raw message

xen/arch/riscv/percpu.c new file +17 -0
new file mode 100644
index 0000000000..31c0cce606
@@ -0,0 +1,17 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/percpu.h>
+#include <xen/cpu.h>
+#include <xen/init.h>
+
+unsigned long __per_cpu_offset[NR_CPUS];
xen/arch/riscv/platforms/Kconfig new file +31 -0
new file mode 100644
index 0000000000..6959ec35a2
@@ -0,0 +1,31 @@
+choice
+	prompt "Platform Support"
+	default ALL_PLAT
+	---help---
+	Choose which hardware platform to enable in Xen.
+
+	If unsure, choose ALL_PLAT.
+
+config ALL_PLAT
+	bool "All Platforms"
+	---help---
+	Enable support for all available hardware platforms. It doesn't
+	automatically select any of the related drivers.
+
+config QEMU
+	bool "QEMU RISC-V virt machine support"
+	depends on RISCV
+	select HAS_NS16550
+	---help---
+	Enable all the required drivers for QEMU RISC-V virt emulated
+	machine.
+
+endchoice
+
+config ALL64_PLAT
+	bool
+	default (ALL_PLAT && RISCV_64)
+
+config ALL32_PLAT
+	bool
+	default (ALL_PLAT && RISCV_32)
xen/arch/riscv/riscv64/asm-offsets.c new file +31 -0
new file mode 100644
index 0000000000..994d5f60c9
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#define COMPILE_OFFSETS
+
+#include <asm/init.h>
+
+#define DEFINE(_sym, _val)                                                 \
+    asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
+                  : : "i" (_val) )
+#define BLANK()                                                            \
+    asm volatile ( "\n.ascii\"==><==\"" : : )
+#define OFFSET(_sym, _str, _mem)                                           \
+    DEFINE(_sym, offsetof(_str, _mem));
+
+void asm_offsets(void)
+{
+   BLANK();
+   OFFSET(INITINFO_stack, struct init_info, stack);
+}
xen/arch/riscv/setup.c new file +27 -0
new file mode 100644
index 0000000000..129e3db58f
@@ -0,0 +1,27 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/types.h>
+#include <public/version.h>
+
+void arch_get_xen_caps(xen_capabilities_info_t *info)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/shutdown.c new file +28 -0
new file mode 100644
index 0000000000..bfa1174366
@@ -0,0 +1,28 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+void machine_halt(void)
+{
+}
+
+void machine_restart(unsigned int delay_millisecs)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/smp.c new file +35 -0
new file mode 100644
index 0000000000..66f1012b37
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/cpumask.h>
+#include <asm/smp.h>
+
+void arch_flush_tlb_mask(const cpumask_t *mask)
+{
+}
+
+void smp_send_event_check_mask(const cpumask_t *mask)
+{
+}
+
+void smp_send_call_function_mask(const cpumask_t *mask)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/smpboot.c new file +34 -0
new file mode 100644
index 0000000000..567d12a262
@@ -0,0 +1,34 @@
+/*
+ * Dummy smpboot support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <xen/cpu.h>
+#include <xen/cpumask.h>
+#include <xen/errno.h>
+#include <xen/init.h>
+#include <xen/sched.h>
+#include <xen/smp.h>
+#include <xen/nodemask.h>
+
+cpumask_t cpu_online_map;
+cpumask_t cpu_present_map;
+cpumask_t cpu_possible_map;
+
+DEFINE_PER_CPU(unsigned int, cpu_id);
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask);
+
+/* Fake one node for now. See also include/asm-arm/numa.h */
+nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
+
+/* Boot cpu data */
+struct init_info init_data = {};
xen/arch/riscv/sysctl.c new file +33 -0
new file mode 100644
index 0000000000..9b4ef27aac
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * Arch-specific sysctl.c
+ *
+ * System management operations. For use by node control stack.
+ *
+ * Copyright (c) 2012, Citrix Systems
+ */
+
+#include <xen/types.h>
+#include <xen/lib.h>
+#include <xen/errno.h>
+#include <xen/hypercall.h>
+#include <public/sysctl.h>
+
+void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
+{
+}
+
+long arch_do_sysctl(struct xen_sysctl *sysctl,
+                    XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
+{
+    return -EOPNOTSUPP;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/time.c new file +35 -0
new file mode 100644
index 0000000000..4d7269195d
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <xen/sched.h>
+#include <xen/time.h>
+
+unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
+
+s_time_t get_s_time(void)
+{
+    return 0;
+}
+
+/* VCPU PV timers. */
+void send_timer_event(struct vcpu *v)
+{
+}
+
+void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds)
+{
+}
+
+int reprogram_timer(s_time_t timeout)
+{
+    return 0;
+}
xen/arch/riscv/traps.c new file +35 -0
new file mode 100644
index 0000000000..5287894954
@@ -0,0 +1,35 @@
+/*
+ * RISC-V Trap handlers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <public/xen.h>
+#include <xen/multicall.h>
+#include <xen/sched.h>
+#include <asm/processor.h>
+
+void show_execution_state(const struct cpu_user_regs *regs)
+{
+}
+
+void vcpu_show_execution_state(struct vcpu *v)
+{
+}
+
+void arch_hypercall_tasklet_result(struct vcpu *v, long res)
+{
+}
+
+enum mc_disposition arch_do_multicall_call(struct mc_state *state)
+{
+    return mc_continue;
+}
xen/arch/riscv/vm_event.c new file +39 -0
new file mode 100644
index 0000000000..6c759f85a6
@@ -0,0 +1,39 @@
+/*
+ * Architecture-specific vm_event handling routines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/sched.h>
+#include <asm/vm_event.h>
+
+void vm_event_fill_regs(vm_event_request_t *req)
+{
+}
+
+void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp)
+{
+}
+
+void vm_event_monitor_next_interrupt(struct vcpu *v)
+{
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/riscv/xen.lds.S new file +113 -0

113 lines not on this page · raw message

xen/drivers/char/serial.c +1 -0
index 5ecba0af33..b84c316784 100644
@@ -12,6 +12,7 @@
 #include <xen/param.h>
 #include <xen/serial.h>
 #include <xen/cache.h>
+#include <asm/processor.h>
 
 /* Never drop characters, even if the async transmit buffer fills. */
 /* #define SERIAL_NEVER_DROP_CHARS 1 */
xen/include/asm-riscv/altp2m.h new file +39 -0
new file mode 100644
index 0000000000..8554495f94
@@ -0,0 +1,39 @@
+/*
+ * Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_RISCV_ALTP2M_H
+#define __ASM_RISCV_ALTP2M_H
+
+#include <xen/sched.h>
+
+/* Alternate p2m on/off per domain */
+static inline bool altp2m_active(const struct domain *d)
+{
+    /* Not implemented on RISCV. */
+    return false;
+}
+
+/* Alternate p2m VCPU */
+static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
+{
+    /* Not implemented on RISCV, should not be reached. */
+    BUG();
+    return 0;
+}
+
+#endif /* __ASM_RISCV_ALTP2M_H */
xen/include/asm-riscv/asm.h new file +77 -0

77 lines not on this page · raw message

xen/include/asm-riscv/asm_defns.h new file +24 -0
new file mode 100644
index 0000000000..9145f9cbf1
@@ -0,0 +1,24 @@
+#ifndef __RISCV_ASM_DEFNS_H__
+#define __RISCV_ASM_DEFNS_H__
+
+#ifndef COMPILE_OFFSETS
+/* NB. Auto-generated from arch/.../asm-offsets.c */
+#include <asm/asm-offsets.h>
+#endif
+#include <asm/processor.h>
+
+#define ASM_INT(label, val)                 \
+    .p2align 2;                             \
+label: .long (val);                         \
+    .size label, . - label;                 \
+    .type label, @object
+
+#endif /* __RISCV_ASM_DEFNS_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/atomic.h new file +204 -0

204 lines not on this page · raw message

xen/include/asm-riscv/bitops.h new file +331 -0

331 lines not on this page · raw message

xen/include/asm-riscv/bug.h new file +54 -0

54 lines not on this page · raw message

xen/include/asm-riscv/byteorder.h new file +16 -0
new file mode 100644
index 0000000000..320a03c88f
@@ -0,0 +1,16 @@
+#ifndef __ASM_RISCV_BYTEORDER_H__
+#define __ASM_RISCV_BYTEORDER_H__
+
+#define __BYTEORDER_HAS_U64__
+
+#include <xen/byteorder/little_endian.h>
+
+#endif /* __ASM_RISCV_BYTEORDER_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/cache.h new file +24 -0
new file mode 100644
index 0000000000..394782ca8e
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 Chen Liqin <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2021 Connor Davis <[email protected]>
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT		CONFIG_RISCV_L1_CACHE_SHIFT
+#define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
+
+#define __read_mostly __section(".data.read_mostly")
+
+#endif /* _ASM_RISCV_CACHE_H */
xen/include/asm-riscv/cmpxchg.h new file +382 -0

382 lines not on this page · raw message

xen/include/asm-riscv/compiler_types.h new file +32 -0
new file mode 100644
index 0000000000..dbe4a8bbff
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_COMPILER_TYPES_H
+#define __LINUX_COMPILER_TYPES_H
+
+/*
+ * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
+ *			       non-scalar types unchanged.
+ */
+/*
+ * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
+ * is not type-compatible with 'signed char', and we define a separate case.
+ */
+#define __scalar_type_to_expr_cases(type)				\
+		unsigned type:	(unsigned type)0,			\
+		signed type:	(signed type)0
+
+#define __unqual_scalar_typeof(x) typeof(				\
+		_Generic((x),						\
+			 char:	(char)0,				\
+			 __scalar_type_to_expr_cases(char),		\
+			 __scalar_type_to_expr_cases(short),		\
+			 __scalar_type_to_expr_cases(int),		\
+			 __scalar_type_to_expr_cases(long),		\
+			 __scalar_type_to_expr_cases(long long),	\
+			 default: (x)))
+
+/* Is this type a native word size -- useful for atomic operations */
+#define __native_word(t) \
+	(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
+	 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
+
+#endif /* __LINUX_COMPILER_TYPES_H */
xen/include/asm-riscv/config.h new file +110 -0

110 lines not on this page · raw message

xen/include/asm-riscv/cpufeature.h new file +17 -0
new file mode 100644
index 0000000000..15133ed63e
@@ -0,0 +1,17 @@
+#ifndef __ASM_RISCV_CPUFEATURE_H
+#define __ASM_RISCV_CPUFEATURE_H
+
+static inline int cpu_nr_siblings(unsigned int cpu)
+{
+    return 1;
+}
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-riscv/csr.h new file +219 -0

165 lines not on this page · raw message

xen/include/asm-riscv/current.h new file +47 -0

47 lines not on this page · raw message

xen/include/asm-riscv/debugger.h new file +15 -0
new file mode 100644
index 0000000000..af4fc8a838

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/delay.h new file +15 -0
new file mode 100644
index 0000000000..181c54844c

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/desc.h new file +12 -0
new file mode 100644
index 0000000000..a4d02d5eef

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/device.h new file +15 -0
new file mode 100644
index 0000000000..e38d2a9712

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/div64.h new file +23 -0
new file mode 100644
index 0000000000..0a88dd30ad

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/domain.h new file +50 -0

50 lines not on this page · raw message

xen/include/asm-riscv/event.h new file +42 -0

42 lines not on this page · raw message

xen/include/asm-riscv/fence.h new file +12 -0
new file mode 100644
index 0000000000..2b443a3a48

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/flushtlb.h new file +34 -0
new file mode 100644
index 0000000000..7a4a4eee23

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/grant_table.h new file +12 -0
new file mode 100644
index 0000000000..8bcc05a60b

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/guest_access.h new file +41 -0

41 lines not on this page · raw message

xen/include/asm-riscv/guest_atomics.h new file +60 -0

60 lines not on this page · raw message

xen/include/asm-riscv/hardirq.h new file +27 -0
new file mode 100644
index 0000000000..67b6a673db

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/hypercall.h new file +12 -0
new file mode 100644
index 0000000000..8af474b5e2

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/init.h new file +42 -0

42 lines not on this page · raw message

xen/include/asm-riscv/io.h new file +283 -0

283 lines not on this page · raw message

xen/include/asm-riscv/iocap.h new file +13 -0
new file mode 100644
index 0000000000..e38a7ff3dc

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/iommu.h new file +46 -0

46 lines not on this page · raw message

xen/include/asm-riscv/irq.h new file +58 -0

58 lines not on this page · raw message

xen/include/asm-riscv/mem_access.h new file +4 -0
new file mode 100644
index 0000000000..8348a04a53

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/mm.h new file +246 -0

246 lines not on this page · raw message

xen/include/asm-riscv/monitor.h new file +65 -0

65 lines not on this page · raw message

xen/include/asm-riscv/nospec.h new file +25 -0
new file mode 100644
index 0000000000..55087fa831

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/numa.h new file +41 -0

41 lines not on this page · raw message

xen/include/asm-riscv/p2m.h new file +218 -0

218 lines not on this page · raw message

xen/include/asm-riscv/page-bits.h new file +11 -0
new file mode 100644
index 0000000000..5a47701fea

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/page.h new file +73 -0

73 lines not on this page · raw message

xen/include/asm-riscv/paging.h new file +15 -0
new file mode 100644
index 0000000000..3f9f704273

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/pci.h new file +31 -0
new file mode 100644
index 0000000000..0ccf335e34

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/percpu.h new file +33 -0
new file mode 100644
index 0000000000..0d165d6aa1

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/processor.h new file +59 -0

59 lines not on this page · raw message

xen/include/asm-riscv/random.h new file +9 -0
new file mode 100644
index 0000000000..b4acee276b

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/regs.h new file +23 -0
new file mode 100644
index 0000000000..82e7dd2aee

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/setup.h new file +14 -0
new file mode 100644
index 0000000000..d0fc75054e

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/smp.h new file +46 -0

46 lines not on this page · raw message

xen/include/asm-riscv/softirq.h new file +16 -0
new file mode 100644
index 0000000000..976e0ebd70

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/spinlock.h new file +12 -0
new file mode 100644
index 0000000000..77e6736e71

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/string.h new file +28 -0
new file mode 100644
index 0000000000..733e9e00d3

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/sysregs.h new file +16 -0
new file mode 100644
index 0000000000..ae0945d902

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/system.h new file +99 -0

99 lines not on this page · raw message

xen/include/asm-riscv/time.h new file +31 -0
new file mode 100644
index 0000000000..af1a8ece45

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/trace.h new file +12 -0
new file mode 100644
index 0000000000..e06def61f6

Lines of this file are not shown. View the raw message.

xen/include/asm-riscv/types.h new file +60 -0

60 lines not on this page · raw message

xen/include/asm-riscv/vm_event.h new file +55 -0

55 lines not on this page · raw message

xen/include/asm-riscv/xenoprof.h new file +12 -0
new file mode 100644
index 0000000000..3db6ce3ab2

Lines of this file are not shown. View the raw message.

xen/include/public/arch-riscv.h new file +183 -0

183 lines not on this page · raw message

xen/include/public/arch-riscv/hvm/save.h new file +39 -0
new file mode 100644
index 0000000000..fa010f0315

Lines of this file are not shown. View the raw message.

xen/include/public/hvm/save.h +2 -0
index f72e3a9bc4..d7505f279c 100644

Lines of this file are not shown. View the raw message.

xen/include/public/pmu.h +2 -0
index cc2fcf8816..3fb1bcd900 100644

Lines of this file are not shown. View the raw message.

xen/include/public/xen.h +2 -0
index e373592c33..1d80b64ee0 100644

Lines of this file are not shown. View the raw message.

xen/include/xen/domain.h +1 -0
index 1708c36964..fd0b75677c 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.27.0

Part of the diff is not shown here. View the raw message.

#19 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 97 lines · Connor Davis

Add the minimum code required to get xen to build with XEN_TARGET_ARCH=riscv64. It is minimal in the sense that every file and function added is required for a successful build, given the .config generated from riscv64_defconfig. The function implementations are just stubs; actual implmentations will need to be added later.

---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   8 +-
 xen/arch/riscv/Kconfig                   |  54 ++++
 xen/arch/riscv/Kconfig.debug             |   0
 xen/arch/riscv/Makefile                  |  57 ++++
 xen/arch/riscv/README.source             |  19 ++
 xen/arch/riscv/Rules.mk                  |  13 +
 xen/arch/riscv/arch.mk                   |   7 +
 xen/arch/riscv/configs/riscv64_defconfig |  12 +
 xen/arch/riscv/delay.c                   |  16 +
 xen/arch/riscv/domain.c                  | 144 +++++++++
 xen/arch/riscv/domctl.c                  |  36 +++
 xen/arch/riscv/guestcopy.c               |  57 ++++
 xen/arch/riscv/head.S                    |   6 +
 xen/arch/riscv/irq.c                     |  78 +++++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++++++++++++
 xen/arch/riscv/mm.c                      |  93 ++++++
 xen/arch/riscv/p2m.c                     | 150 +++++++++
 xen/arch/riscv/percpu.c                  |  17 +
 xen/arch/riscv/platforms/Kconfig         |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c     |  31 ++
 xen/arch/riscv/setup.c                   |  27 ++
 xen/arch/riscv/shutdown.c                |  28 ++
 xen/arch/riscv/smp.c                     |  35 +++
 xen/arch/riscv/smpboot.c                 |  34 ++
 xen/arch/riscv/sysctl.c                  |  33 ++
 xen/arch/riscv/time.c                    |  35 +++
 xen/arch/riscv/traps.c                   |  35 +++
 xen/arch/riscv/vm_event.c                |  39 +++
 xen/arch/riscv/xen.lds.S                 | 113 +++++++
 xen/drivers/char/serial.c                |   1 +
 xen/include/asm-riscv/altp2m.h           |  39 +++
 xen/include/asm-riscv/asm.h              |  77 +++++
 xen/include/asm-riscv/asm_defns.h        |  24 ++
 xen/include/asm-riscv/atomic.h           | 204 ++++++++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++++++++++++++
 xen/include/asm-riscv/bug.h              |  54 ++++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 ++
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h   |  32 ++
 xen/include/asm-riscv/config.h           | 110 +++++++
 xen/include/asm-riscv/cpufeature.h       |  17 +
 xen/include/asm-riscv/csr.h              | 219 +++++++++++++
 xen/include/asm-riscv/current.h          |  47 +++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  15 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 ++
 xen/include/asm-riscv/domain.h           |  50 +++
 xen/include/asm-riscv/event.h            |  42 +++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  34 ++
 xen/include/asm-riscv/grant_table.h      |  12 +
 xen/include/asm-riscv/guest_access.h     |  41 +++
 xen/include/asm-riscv/guest_atomics.h    |  60 ++++
 xen/include/asm-riscv/hardirq.h          |  27 ++
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +++
 xen/include/asm-riscv/io.h               | 283 +++++++++++++++++
 xen/include/asm-riscv/iocap.h            |  13 +
 xen/include/asm-riscv/iommu.h            |  46 +++
 xen/include/asm-riscv/irq.h              |  58 ++++
 xen/include/asm-riscv/mem_access.h       |   4 +
 xen/include/asm-riscv/mm.h               | 246 +++++++++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++++
 xen/include/asm-riscv/nospec.h           |  25 ++
 xen/include/asm-riscv/numa.h             |  41 +++
 xen/include/asm-riscv/p2m.h              | 218 +++++++++++++
 xen/include/asm-riscv/page-bits.h        |  11 +
 xen/include/asm-riscv/page.h             |  73 +++++
 xen/include/asm-riscv/paging.h           |  15 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  33 ++
 xen/include/asm-riscv/processor.h        |  59 ++++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  23 ++
 xen/include/asm-riscv/setup.h            |  14 +
 xen/include/asm-riscv/smp.h              |  46 +++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  12 +
 xen/include/asm-riscv/string.h           |  28 ++
 xen/include/asm-riscv/sysregs.h          |  16 +
 xen/include/asm-riscv/system.h           |  99 ++++++
 xen/include/asm-riscv/time.h             |  31 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  60 ++++
Quoted 8 lines
 xen/include/asm-riscv/vm_event.h         |  55 ++++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 183 +++++++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

Now is also an excellent opportunity to nuke the x86isms which have escaped into common code (debugger and xenoprof in particular), and rethink some of our common/arch split.

When it comes to header files specifically, I want to start using xen/arch/$ARCH/include/asm/ and retrofit this to x86 and ARM.  It has two important properties - first, that you don't need to symlink the tree to make compilation work, and second that patches touching multiple architectures have hunks ordered in a more logical way.

~Andrew

#20 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Connor Davis

Add the minimum code required to get xen to build with XEN_TARGET_ARCH=riscv64. It is minimal in the sense that every file and function added is required for a successful build, given the .config generated from riscv64_defconfig. The function implementations are just stubs; actual implmentations will need to be added later.

This is awesome, Connor! I am glad you are continuing this work and I am really looking forward to have it in the tree.

Quoted 99 lines
Quoted 90 lines
---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   8 +-
 xen/arch/riscv/Kconfig                   |  54 ++++
 xen/arch/riscv/Kconfig.debug             |   0
 xen/arch/riscv/Makefile                  |  57 ++++
 xen/arch/riscv/README.source             |  19 ++
 xen/arch/riscv/Rules.mk                  |  13 +
 xen/arch/riscv/arch.mk                   |   7 +
 xen/arch/riscv/configs/riscv64_defconfig |  12 +
 xen/arch/riscv/delay.c                   |  16 +
 xen/arch/riscv/domain.c                  | 144 +++++++++
 xen/arch/riscv/domctl.c                  |  36 +++
 xen/arch/riscv/guestcopy.c               |  57 ++++
 xen/arch/riscv/head.S                    |   6 +
 xen/arch/riscv/irq.c                     |  78 +++++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++++++++++++
 xen/arch/riscv/mm.c                      |  93 ++++++
 xen/arch/riscv/p2m.c                     | 150 +++++++++
 xen/arch/riscv/percpu.c                  |  17 +
 xen/arch/riscv/platforms/Kconfig         |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c     |  31 ++
 xen/arch/riscv/setup.c                   |  27 ++
 xen/arch/riscv/shutdown.c                |  28 ++
 xen/arch/riscv/smp.c                     |  35 +++
 xen/arch/riscv/smpboot.c                 |  34 ++
 xen/arch/riscv/sysctl.c                  |  33 ++
 xen/arch/riscv/time.c                    |  35 +++
 xen/arch/riscv/traps.c                   |  35 +++
 xen/arch/riscv/vm_event.c                |  39 +++
 xen/arch/riscv/xen.lds.S                 | 113 +++++++
 xen/drivers/char/serial.c                |   1 +
 xen/include/asm-riscv/altp2m.h           |  39 +++
 xen/include/asm-riscv/asm.h              |  77 +++++
 xen/include/asm-riscv/asm_defns.h        |  24 ++
 xen/include/asm-riscv/atomic.h           | 204 ++++++++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++++++++++++++
 xen/include/asm-riscv/bug.h              |  54 ++++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 ++
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h   |  32 ++
 xen/include/asm-riscv/config.h           | 110 +++++++
 xen/include/asm-riscv/cpufeature.h       |  17 +
 xen/include/asm-riscv/csr.h              | 219 +++++++++++++
 xen/include/asm-riscv/current.h          |  47 +++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  15 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 ++
 xen/include/asm-riscv/domain.h           |  50 +++
 xen/include/asm-riscv/event.h            |  42 +++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  34 ++
 xen/include/asm-riscv/grant_table.h      |  12 +
 xen/include/asm-riscv/guest_access.h     |  41 +++
 xen/include/asm-riscv/guest_atomics.h    |  60 ++++
 xen/include/asm-riscv/hardirq.h          |  27 ++
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +++
 xen/include/asm-riscv/io.h               | 283 +++++++++++++++++
 xen/include/asm-riscv/iocap.h            |  13 +
 xen/include/asm-riscv/iommu.h            |  46 +++
 xen/include/asm-riscv/irq.h              |  58 ++++
 xen/include/asm-riscv/mem_access.h       |   4 +
 xen/include/asm-riscv/mm.h               | 246 +++++++++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++++
 xen/include/asm-riscv/nospec.h           |  25 ++
 xen/include/asm-riscv/numa.h             |  41 +++
 xen/include/asm-riscv/p2m.h              | 218 +++++++++++++
 xen/include/asm-riscv/page-bits.h        |  11 +
 xen/include/asm-riscv/page.h             |  73 +++++
 xen/include/asm-riscv/paging.h           |  15 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  33 ++
 xen/include/asm-riscv/processor.h        |  59 ++++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  23 ++
 xen/include/asm-riscv/setup.h            |  14 +
 xen/include/asm-riscv/smp.h              |  46 +++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  12 +
 xen/include/asm-riscv/string.h           |  28 ++
 xen/include/asm-riscv/sysregs.h          |  16 +
 xen/include/asm-riscv/system.h           |  99 ++++++
 xen/include/asm-riscv/time.h             |  31 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  60 ++++
Quoted 8 lines
 xen/include/asm-riscv/vm_event.h         |  55 ++++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 183 +++++++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +
Quoted 6 lines

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

I'd love to see this patch split into several smaller patches. Ideally one patch per header file or per group of headers. It is fine if it ends up being a very large series. For patches imported from Linux, make sure to say that they are coming from Linux commit XXX in the commit message. It is going to make it a lot easier to ack them.

Also, I think we need a concrete build target in mind: we don't want to add a function stub if it is not needed to build something. Make sure to specify what you are building in patch 0.

I tried building this series. The container didn't build for me, so I build the toolchain myself. I noticed a couple of things:

XEN_TARGET_ARCH=riscv64 works but XEN_TARGET_ARCH=riscv doesn't. Maybe we should make XEN_TARGET_ARCH=riscv work too using the xen/Makefile TARGET transformations.

It seems to be building quite a few things under common. However it breaks with:

vm_event.c: In function 'vm_event_resume':
vm_event.c:428:17: error: implicit declaration of function 'vm_event_reset_vmtrace'; did you mean 'vm_event_resume'? [-Werror=implicit-function-declaration]

  428 |                 vm_event_reset_vmtrace(v);
      |                 ^~~~~~~~~~~~~~~~~~~~~~
      |                 vm_event_resume

vm_event.c:428:17: error: nested extern declaration of 'vm_event_reset_vmtrace' [-Werror=nested-externs]

I got past that with a hack, but then I got this error:

ns16550.c: In function 'ns16550_init_preirq':
ns16550.c:353:42: error: implicit declaration of function 'ioremap'; did you mean 'ioremap_wc'? [-Werror=implicit-function-declaration]

  353 |         uart->remapped_io_base = (char *)ioremap(uart->io_base, uart->io_size);
      |                                          ^~~~~~~
      |                                          ioremap_wc

ns16550.c:353:42: error: nested extern declaration of 'ioremap' [-Werror=nested-externs] ns16550.c:353:34: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
353 | uart->remapped_io_base = (char *)ioremap(uart->io_base, uart->io_size);
| ^
At top level:
ns16550.c:628:13: error: 'ns16550_init_common' defined but not used [-Werror=unused-function]
628 | static void ns16550_init_common(struct ns16550 *uart)

      |             ^~~~~~~~~~~~~~~~~~~
ns16550.c:610:41: error: 'ns16550_driver' defined but not used [-Werror=unused-variable]
  610 | static struct uart_driver __read_mostly ns16550_driver = {
      |                                         ^~~~~~~~~~~~~~
ns16550.c:204:13: error: '__ns16550_poll' defined but not used [-Werror=unused-function]
  204 | static void __ns16550_poll(struct cpu_user_regs *regs)
      |             ^~~~~~~~~~~~~~
ns16550.c:76:3: error: 'ns16550_com' defined but not used [-Werror=unused-variable]
   76 | } ns16550_com[2] = { { 0 } };
      |   ^~~~~~~~~~~

cc1: all warnings being treated as errors

Which is strange given that ns16550.c shouldn't be built at all. "QEMU RISC-V virt machine support" is forcing CONFIG_HAS_NS16550=y on my system. I chose "All Platforms" and CONFIG_HAS_NS16550=y went away. That can't be right :-)

After that, I could actually finish the build:

sstabellini@sstabellini-ThinkPad-T480s:/local/repos/xen-upstream/xen$ find . -name \*.o
./common/spinlock.o
./common/irq.o
./common/sysctl.o
./common/sched/built_in.o
./common/sched/cpupool.o
./common/sched/credit2.o
./common/sched/core.o
./common/stop_machine.o
./common/gunzip.init.o
./common/multicall.o
./common/symbols.o
./common/rwlock.o
./common/event_channel.o
./common/guestcopy.o
./common/softirq.o
./common/virtual_region.o
./common/lib.o
./common/wait.o
./common/time.o
./common/notifier.o
./common/cpu.o
./common/page_alloc.o
./common/string.o
./common/vm_event.o
./common/tasklet.o
./common/version.o
./common/symbols-dummy.o
./common/memory.o
./common/warning.o
./common/xmalloc_tlsf.o
./common/kernel.o
./common/gunzip.o
./common/warning.init.o
./common/domain.o
./common/event_2l.o
./common/radix-tree.o
./common/timer.o
./common/built_in.o
./common/bitmap.o
./common/smp.o
./common/vsprintf.o
./common/keyhandler.o
./common/shutdown.o
./common/rcupdate.o
./common/rangeset.o
./common/vmap.o
./common/domctl.o
./common/preempt.o
./common/event_fifo.o
./common/monitor.o
./common/random.o
./lib/bsearch.o
./lib/rbtree.o
./lib/parse-size.o
./lib/ctype.o
./lib/ctors.o
./lib/list-sort.o
./lib/sort.o
./lib/built_in.o
./drivers/built_in.o
./drivers/char/serial.o
./drivers/char/built_in.o
./drivers/char/console.o
./arch/riscv/irq.o
./arch/riscv/sysctl.o
./arch/riscv/delay.o
./arch/riscv/lib/built_in.o
./arch/riscv/lib/find_next_bit.o
./arch/riscv/guestcopy.o
./arch/riscv/time.o
./arch/riscv/prelink.o
./arch/riscv/vm_event.o
./arch/riscv/setup.o
./arch/riscv/domain.o
./arch/riscv/traps.o
./arch/riscv/built_in.o
./arch/riscv/smp.o
./arch/riscv/mm.o
./arch/riscv/percpu.o
./arch/riscv/p2m.o
./arch/riscv/shutdown.o
./arch/riscv/head.o
./arch/riscv/domctl.o
./arch/riscv/smpboot.o

Which is absolutely astounding! Great job! I didn't imagine you already managed to build the whole of commons!

#21 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 117 lines · Stefano Stabellini
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Connor Davis

Add the minimum code required to get xen to build with XEN_TARGET_ARCH=riscv64. It is minimal in the sense that every file and function added is required for a successful build, given the .config generated from riscv64_defconfig. The function implementations are just stubs; actual implmentations will need to be added later.

This is awesome, Connor! I am glad you are continuing this work and I am really looking forward to have it in the tree.

Quoted 103 lines
Quoted 90 lines
---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   8 +-
 xen/arch/riscv/Kconfig                   |  54 ++++
 xen/arch/riscv/Kconfig.debug             |   0
 xen/arch/riscv/Makefile                  |  57 ++++
 xen/arch/riscv/README.source             |  19 ++
 xen/arch/riscv/Rules.mk                  |  13 +
 xen/arch/riscv/arch.mk                   |   7 +
 xen/arch/riscv/configs/riscv64_defconfig |  12 +
 xen/arch/riscv/delay.c                   |  16 +
 xen/arch/riscv/domain.c                  | 144 +++++++++
 xen/arch/riscv/domctl.c                  |  36 +++
 xen/arch/riscv/guestcopy.c               |  57 ++++
 xen/arch/riscv/head.S                    |   6 +
 xen/arch/riscv/irq.c                     |  78 +++++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++++++++++++
 xen/arch/riscv/mm.c                      |  93 ++++++
 xen/arch/riscv/p2m.c                     | 150 +++++++++
 xen/arch/riscv/percpu.c                  |  17 +
 xen/arch/riscv/platforms/Kconfig         |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c     |  31 ++
 xen/arch/riscv/setup.c                   |  27 ++
 xen/arch/riscv/shutdown.c                |  28 ++
 xen/arch/riscv/smp.c                     |  35 +++
 xen/arch/riscv/smpboot.c                 |  34 ++
 xen/arch/riscv/sysctl.c                  |  33 ++
 xen/arch/riscv/time.c                    |  35 +++
 xen/arch/riscv/traps.c                   |  35 +++
 xen/arch/riscv/vm_event.c                |  39 +++
 xen/arch/riscv/xen.lds.S                 | 113 +++++++
 xen/drivers/char/serial.c                |   1 +
 xen/include/asm-riscv/altp2m.h           |  39 +++
 xen/include/asm-riscv/asm.h              |  77 +++++
 xen/include/asm-riscv/asm_defns.h        |  24 ++
 xen/include/asm-riscv/atomic.h           | 204 ++++++++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++++++++++++++
 xen/include/asm-riscv/bug.h              |  54 ++++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 ++
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h   |  32 ++
 xen/include/asm-riscv/config.h           | 110 +++++++
 xen/include/asm-riscv/cpufeature.h       |  17 +
 xen/include/asm-riscv/csr.h              | 219 +++++++++++++
 xen/include/asm-riscv/current.h          |  47 +++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  15 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 ++
 xen/include/asm-riscv/domain.h           |  50 +++
 xen/include/asm-riscv/event.h            |  42 +++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  34 ++
 xen/include/asm-riscv/grant_table.h      |  12 +
 xen/include/asm-riscv/guest_access.h     |  41 +++
 xen/include/asm-riscv/guest_atomics.h    |  60 ++++
 xen/include/asm-riscv/hardirq.h          |  27 ++
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +++
 xen/include/asm-riscv/io.h               | 283 +++++++++++++++++
 xen/include/asm-riscv/iocap.h            |  13 +
 xen/include/asm-riscv/iommu.h            |  46 +++
 xen/include/asm-riscv/irq.h              |  58 ++++
 xen/include/asm-riscv/mem_access.h       |   4 +
 xen/include/asm-riscv/mm.h               | 246 +++++++++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++++
 xen/include/asm-riscv/nospec.h           |  25 ++
 xen/include/asm-riscv/numa.h             |  41 +++
 xen/include/asm-riscv/p2m.h              | 218 +++++++++++++
 xen/include/asm-riscv/page-bits.h        |  11 +
 xen/include/asm-riscv/page.h             |  73 +++++
 xen/include/asm-riscv/paging.h           |  15 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  33 ++
 xen/include/asm-riscv/processor.h        |  59 ++++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  23 ++
 xen/include/asm-riscv/setup.h            |  14 +
 xen/include/asm-riscv/smp.h              |  46 +++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  12 +
 xen/include/asm-riscv/string.h           |  28 ++
 xen/include/asm-riscv/sysregs.h          |  16 +
 xen/include/asm-riscv/system.h           |  99 ++++++
 xen/include/asm-riscv/time.h             |  31 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  60 ++++
Quoted 8 lines
 xen/include/asm-riscv/vm_event.h         |  55 ++++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 183 +++++++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Quoted 8 lines
Quoted 2 lines

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

I'd love to see this patch split into several smaller patches. Ideally one patch per header file or per group of headers. It is fine if it ends up being a very large series. For patches imported from Linux, make sure to say that they are coming from Linux commit XXX in the commit message. It is going to make it a lot easier to ack them.

I was trying to keep the series bisectable so that every commit built successfully. Not including any of the files above would have cause a build error. Adding one file per patch would certainly make it easier to review, but the series wouldn't build cleanly.

Quoted 3 lines

Also, I think we need a concrete build target in mind: we don't want to add a function stub if it is not needed to build something. Make sure to specify what you are building in patch 0.

Agreed. Do you have a target in mind?

Quoted 10 lines

I tried building this series. The container didn't build for me, so I build the toolchain myself. I noticed a couple of things:

XEN_TARGET_ARCH=riscv64 works but XEN_TARGET_ARCH=riscv doesn't. Maybe we should make XEN_TARGET_ARCH=riscv work too using the xen/Makefile TARGET transformations.

It seems to be building quite a few things under common. However it breaks with:

Quoted 6 lines

vm_event.c: In function 'vm_event_resume':
vm_event.c:428:17: error: implicit declaration of function 'vm_event_reset_vmtrace'; did you mean 'vm_event_resume'? [-Werror=implicit-function-declaration]

  428 |                 vm_event_reset_vmtrace(v);
      |                 ^~~~~~~~~~~~~~~~~~~~~~
      |                 vm_event_resume

vm_event.c:428:17: error: nested extern declaration of 'vm_event_reset_vmtrace' [-Werror=nested-externs]

Yes, I failed to re-test the build after rebasing on the latest master. Found this myself after I sent it out but then it was too late :/

Quoted 24 lines

I got past that with a hack, but then I got this error:

ns16550.c: In function 'ns16550_init_preirq':
ns16550.c:353:42: error: implicit declaration of function 'ioremap'; did you mean 'ioremap_wc'? [-Werror=implicit-function-declaration]

  353 |         uart->remapped_io_base = (char *)ioremap(uart->io_base, uart->io_size);
      |                                          ^~~~~~~
      |                                          ioremap_wc

ns16550.c:353:42: error: nested extern declaration of 'ioremap' [-Werror=nested-externs] ns16550.c:353:34: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
353 | uart->remapped_io_base = (char *)ioremap(uart->io_base, uart->io_size);
| ^
At top level:
ns16550.c:628:13: error: 'ns16550_init_common' defined but not used [-Werror=unused-function]
628 | static void ns16550_init_common(struct ns16550 *uart)

      |             ^~~~~~~~~~~~~~~~~~~
ns16550.c:610:41: error: 'ns16550_driver' defined but not used [-Werror=unused-variable]
  610 | static struct uart_driver __read_mostly ns16550_driver = {
      |                                         ^~~~~~~~~~~~~~
ns16550.c:204:13: error: '__ns16550_poll' defined but not used [-Werror=unused-function]
  204 | static void __ns16550_poll(struct cpu_user_regs *regs)
      |             ^~~~~~~~~~~~~~
ns16550.c:76:3: error: 'ns16550_com' defined but not used [-Werror=unused-variable]
   76 | } ns16550_com[2] = { { 0 } };
      |   ^~~~~~~~~~~
Quoted 7 lines

cc1: all warnings being treated as errors

Which is strange given that ns16550.c shouldn't be built at all. "QEMU RISC-V virt machine support" is forcing CONFIG_HAS_NS16550=y on my system. I chose "All Platforms" and CONFIG_HAS_NS16550=y went away. That can't be right :-)

Hmm, did you apply patch 1? That patch should have taken care of this error.

Quoted 91 lines

After that, I could actually finish the build:

sstabellini@sstabellini-ThinkPad-T480s:/local/repos/xen-upstream/xen$ find . -name \*.o
./common/spinlock.o
./common/irq.o
./common/sysctl.o
./common/sched/built_in.o
./common/sched/cpupool.o
./common/sched/credit2.o
./common/sched/core.o
./common/stop_machine.o
./common/gunzip.init.o
./common/multicall.o
./common/symbols.o
./common/rwlock.o
./common/event_channel.o
./common/guestcopy.o
./common/softirq.o
./common/virtual_region.o
./common/lib.o
./common/wait.o
./common/time.o
./common/notifier.o
./common/cpu.o
./common/page_alloc.o
./common/string.o
./common/vm_event.o
./common/tasklet.o
./common/version.o
./common/symbols-dummy.o
./common/memory.o
./common/warning.o
./common/xmalloc_tlsf.o
./common/kernel.o
./common/gunzip.o
./common/warning.init.o
./common/domain.o
./common/event_2l.o
./common/radix-tree.o
./common/timer.o
./common/built_in.o
./common/bitmap.o
./common/smp.o
./common/vsprintf.o
./common/keyhandler.o
./common/shutdown.o
./common/rcupdate.o
./common/rangeset.o
./common/vmap.o
./common/domctl.o
./common/preempt.o
./common/event_fifo.o
./common/monitor.o
./common/random.o
./lib/bsearch.o
./lib/rbtree.o
./lib/parse-size.o
./lib/ctype.o
./lib/ctors.o
./lib/list-sort.o
./lib/sort.o
./lib/built_in.o
./drivers/built_in.o
./drivers/char/serial.o
./drivers/char/built_in.o
./drivers/char/console.o
./arch/riscv/irq.o
./arch/riscv/sysctl.o
./arch/riscv/delay.o
./arch/riscv/lib/built_in.o
./arch/riscv/lib/find_next_bit.o
./arch/riscv/guestcopy.o
./arch/riscv/time.o
./arch/riscv/prelink.o
./arch/riscv/vm_event.o
./arch/riscv/setup.o
./arch/riscv/domain.o
./arch/riscv/traps.o
./arch/riscv/built_in.o
./arch/riscv/smp.o
./arch/riscv/mm.o
./arch/riscv/percpu.o
./arch/riscv/p2m.o
./arch/riscv/shutdown.o
./arch/riscv/head.o
./arch/riscv/domctl.o
./arch/riscv/smpboot.o

Which is absolutely astounding! Great job! I didn't imagine you already managed to build the whole of commons!

#22 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

In reply to Andrew Cooper
Quoted 107 lines · Andrew Cooper
Quoted 97 lines · Connor Davis

Add the minimum code required to get xen to build with XEN_TARGET_ARCH=riscv64. It is minimal in the sense that every file and function added is required for a successful build, given the .config generated from riscv64_defconfig. The function implementations are just stubs; actual implmentations will need to be added later.

---
 config/riscv64.mk                        |   7 +
 xen/Makefile                             |   8 +-
 xen/arch/riscv/Kconfig                   |  54 ++++
 xen/arch/riscv/Kconfig.debug             |   0
 xen/arch/riscv/Makefile                  |  57 ++++
 xen/arch/riscv/README.source             |  19 ++
 xen/arch/riscv/Rules.mk                  |  13 +
 xen/arch/riscv/arch.mk                   |   7 +
 xen/arch/riscv/configs/riscv64_defconfig |  12 +
 xen/arch/riscv/delay.c                   |  16 +
 xen/arch/riscv/domain.c                  | 144 +++++++++
 xen/arch/riscv/domctl.c                  |  36 +++
 xen/arch/riscv/guestcopy.c               |  57 ++++
 xen/arch/riscv/head.S                    |   6 +
 xen/arch/riscv/irq.c                     |  78 +++++
 xen/arch/riscv/lib/Makefile              |   1 +
 xen/arch/riscv/lib/find_next_bit.c       | 284 +++++++++++++++++
 xen/arch/riscv/mm.c                      |  93 ++++++
 xen/arch/riscv/p2m.c                     | 150 +++++++++
 xen/arch/riscv/percpu.c                  |  17 +
 xen/arch/riscv/platforms/Kconfig         |  31 ++
 xen/arch/riscv/riscv64/asm-offsets.c     |  31 ++
 xen/arch/riscv/setup.c                   |  27 ++
 xen/arch/riscv/shutdown.c                |  28 ++
 xen/arch/riscv/smp.c                     |  35 +++
 xen/arch/riscv/smpboot.c                 |  34 ++
 xen/arch/riscv/sysctl.c                  |  33 ++
 xen/arch/riscv/time.c                    |  35 +++
 xen/arch/riscv/traps.c                   |  35 +++
 xen/arch/riscv/vm_event.c                |  39 +++
 xen/arch/riscv/xen.lds.S                 | 113 +++++++
 xen/drivers/char/serial.c                |   1 +
 xen/include/asm-riscv/altp2m.h           |  39 +++
 xen/include/asm-riscv/asm.h              |  77 +++++
 xen/include/asm-riscv/asm_defns.h        |  24 ++
 xen/include/asm-riscv/atomic.h           | 204 ++++++++++++
 xen/include/asm-riscv/bitops.h           | 331 ++++++++++++++++++++
 xen/include/asm-riscv/bug.h              |  54 ++++
 xen/include/asm-riscv/byteorder.h        |  16 +
 xen/include/asm-riscv/cache.h            |  24 ++
 xen/include/asm-riscv/cmpxchg.h          | 382 +++++++++++++++++++++++
 xen/include/asm-riscv/compiler_types.h   |  32 ++
 xen/include/asm-riscv/config.h           | 110 +++++++
 xen/include/asm-riscv/cpufeature.h       |  17 +
 xen/include/asm-riscv/csr.h              | 219 +++++++++++++
 xen/include/asm-riscv/current.h          |  47 +++
 xen/include/asm-riscv/debugger.h         |  15 +
 xen/include/asm-riscv/delay.h            |  15 +
 xen/include/asm-riscv/desc.h             |  12 +
 xen/include/asm-riscv/device.h           |  15 +
 xen/include/asm-riscv/div64.h            |  23 ++
 xen/include/asm-riscv/domain.h           |  50 +++
 xen/include/asm-riscv/event.h            |  42 +++
 xen/include/asm-riscv/fence.h            |  12 +
 xen/include/asm-riscv/flushtlb.h         |  34 ++
 xen/include/asm-riscv/grant_table.h      |  12 +
 xen/include/asm-riscv/guest_access.h     |  41 +++
 xen/include/asm-riscv/guest_atomics.h    |  60 ++++
 xen/include/asm-riscv/hardirq.h          |  27 ++
 xen/include/asm-riscv/hypercall.h        |  12 +
 xen/include/asm-riscv/init.h             |  42 +++
 xen/include/asm-riscv/io.h               | 283 +++++++++++++++++
 xen/include/asm-riscv/iocap.h            |  13 +
 xen/include/asm-riscv/iommu.h            |  46 +++
 xen/include/asm-riscv/irq.h              |  58 ++++
 xen/include/asm-riscv/mem_access.h       |   4 +
 xen/include/asm-riscv/mm.h               | 246 +++++++++++++++
 xen/include/asm-riscv/monitor.h          |  65 ++++
 xen/include/asm-riscv/nospec.h           |  25 ++
 xen/include/asm-riscv/numa.h             |  41 +++
 xen/include/asm-riscv/p2m.h              | 218 +++++++++++++
 xen/include/asm-riscv/page-bits.h        |  11 +
 xen/include/asm-riscv/page.h             |  73 +++++
 xen/include/asm-riscv/paging.h           |  15 +
 xen/include/asm-riscv/pci.h              |  31 ++
 xen/include/asm-riscv/percpu.h           |  33 ++
 xen/include/asm-riscv/processor.h        |  59 ++++
 xen/include/asm-riscv/random.h           |   9 +
 xen/include/asm-riscv/regs.h             |  23 ++
 xen/include/asm-riscv/setup.h            |  14 +
 xen/include/asm-riscv/smp.h              |  46 +++
 xen/include/asm-riscv/softirq.h          |  16 +
 xen/include/asm-riscv/spinlock.h         |  12 +
 xen/include/asm-riscv/string.h           |  28 ++
 xen/include/asm-riscv/sysregs.h          |  16 +
 xen/include/asm-riscv/system.h           |  99 ++++++
 xen/include/asm-riscv/time.h             |  31 ++
 xen/include/asm-riscv/trace.h            |  12 +
 xen/include/asm-riscv/types.h            |  60 ++++
Quoted 8 lines
 xen/include/asm-riscv/vm_event.h         |  55 ++++
 xen/include/asm-riscv/xenoprof.h         |  12 +
 xen/include/public/arch-riscv.h          | 183 +++++++++++
 xen/include/public/arch-riscv/hvm/save.h |  39 +++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +
Quoted 7 lines

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

Yes, IIRC most is pulled in from common code. If it would be helpful I could play around with not building common to see what the difference is.

Quoted 9 lines

Now is also an excellent opportunity to nuke the x86isms which have escaped into common code (debugger and xenoprof in particular), and rethink some of our common/arch split.

When it comes to header files specifically, I want to start using xen/arch/$ARCH/include/asm/ and retrofit this to x86 and ARM.  It has two important properties - first, that you don't need to symlink the tree to make compilation work, and second that patches touching multiple architectures have hunks ordered in a more logical way.

+1 for removing the symlink, that would have saved me an embarrasingly large amount of time when I started this work and had failed to clean the existing x86 symlink :).

Connor

#23 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

In reply to Andrew Cooper
Quoted 12 lines · Andrew Cooper

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

Now is also an excellent opportunity to nuke the x86isms which have escaped into common code (debugger and xenoprof in particular), and rethink some of our common/arch split.

Quoted 8 lines

When it comes to header files specifically, I want to start using xen/arch/$ARCH/include/asm/ and retrofit this to x86 and ARM.  It has two important properties - first, that you don't need to symlink the tree to make compilation work, and second that patches touching multiple architectures have hunks ordered in a more logical way.

~Andrew

I think we may have envisioned different things here.... I was under the impression that we wanted to implicate common, so that changes there that broke the RISC-V build would present themselves on CI... and to demonstrate which "arch_*" calls common expects to exist.

It sounds like you'd prefer no common to start and none of the arch_* calls it relies on?

#24 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 20 lines · Bob Eshleman
Quoted 11 lines · Andrew Cooper

Well - this is orders of magnitude more complicated than it ought to be.  An empty head.S doesn't (well - shouldn't) need the overwhelming majority of this.

Do you know how all of this is being pulled in?  Is it from attempting to compile common/ by any chance?

Now is also an excellent opportunity to nuke the x86isms which have escaped into common code (debugger and xenoprof in particular), and rethink some of our common/arch split.

Quoted 8 lines

When it comes to header files specifically, I want to start using xen/arch/$ARCH/include/asm/ and retrofit this to x86 and ARM.  It has two important properties - first, that you don't need to symlink the tree to make compilation work, and second that patches touching multiple architectures have hunks ordered in a more logical way.

~Andrew

Quoted 7 lines

I think we may have envisioned different things here.... I was under the impression that we wanted to implicate common, so that changes there that broke the RISC-V build would present themselves on CI... and to demonstrate which "arch_*" calls common expects to exist.

It sounds like you'd prefer no common to start and none of the arch_* calls it relies on?

We definitely want "stuff compiled under RISC-V" to be caught in CI, but that doesn't mean "wedge all of common in with stubs to begin with".

Honestly - I want to see the build issues/failures in common, to help us fix the rough corners on Kconfig system and include hierarchy.

In light of this patch, there are definitely some things which should be fixed as prerequisites, rather than forcing yet-more x86-isms into every new arch.

~Andrew

#25 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 8 lines
Quoted 4 lines · Andrew Cooper

It sounds like you'd prefer no common to start and none of the arch_* calls it relies on?

We definitely want "stuff compiled under RISC-V" to be caught in CI, but that doesn't mean "wedge all of common in with stubs to begin with".

Quoted 9 lines

Honestly - I want to see the build issues/failures in common, to help us fix the rough corners on Kconfig system and include hierarchy.

In light of this patch, there are definitely some things which should be fixed as prerequisites, rather than forcing yet-more x86-isms into every new arch.

~Andrew

Ah I see. There's more that could be Kconfig'd away and if they can't be Kconfig'd away, their should be some commits to make it so they can be.

But things like, for example, arch_domain_create() would still be stubbed, because this is and always will be required.

-Bobby

#26 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 14 lines · Bob Eshleman
Quoted 14 lines
Quoted 4 lines · Andrew Cooper

It sounds like you'd prefer no common to start and none of the arch_* calls it relies on?

We definitely want "stuff compiled under RISC-V" to be caught in CI, but that doesn't mean "wedge all of common in with stubs to begin with".

Honestly - I want to see the build issues/failures in common, to help us fix the rough corners on Kconfig system and include hierarchy.

In light of this patch, there are definitely some things which should be fixed as prerequisites, rather than forcing yet-more x86-isms into every new arch.

Quoted 7 lines
Quoted 2 lines

~Andrew

Ah I see. There's more that could be Kconfig'd away and if they can't be Kconfig'd away, their should be some commits to make it so they can be.

But things like, for example, arch_domain_create() would still be stubbed, because this is and always will be required.

Some bits are very mandatory (at the point you start compiling domain.c), but it absolutely shouldn't be necessary to implement that much in the way of stubs to bootstrap an architecture.

~Andrew

#27 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

In reply to Connor Davis

xen/drivers/char/serial.c line 15

Quoted 7 lines · Connor Davis
xen/drivers/char/serial.c +1 -0
@@ -12,6 +12,7 @@
 #include <xen/param.h>
 #include <xen/serial.h>
 #include <xen/cache.h>
+#include <asm/processor.h>

Btw - changes like this one would better be split off, so they would come with a justification / description. A file like this one shouldn't really need to include processor.h, so I'm curious what the requirement is.

Jan

#28 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

In reply to Connor Davis
Quoted 102 lines · Connor Davis
xen/include/public/arch-riscv.h new file +99 -0
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * arch-riscv.h
+ *
+ * Guest OS interface to RISC-V Xen.
+ * Initially based on the ARM implementation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright 2019 (C) Alistair Francis <[email protected]>
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_RISCV_H__
+#define __XEN_PUBLIC_ARCH_RISCV_H__
+
+#include <xen/types.h>
+
+#define  int64_aligned_t  int64_t __attribute__((aligned(8)))
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
+
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name
+
+/*
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
+ * in a struct in memory. On rv64 it is 8 bytes long and 8-byte aligned.
+ *
+ * XEN_GUEST_HANDLE_PARAM represents a guest pointer, when passed as a
+ * hypercall argument. It is 4 bytes on rv32 and 8 bytes on rv64.
+ */
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \
+    } while ( 0 )
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+/* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
+# define __DECL_REG(n64, n32) union {          \
+        uint64_t n64;                          \
+        uint32_t n32;                          \
+    }
+#else
+/* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
+#define __DECL_REG(n64, n32) uint64_t n64
+#endif
+
+struct vcpu_guest_core_regs
+{
+    unsigned long zero;
+    unsigned long ra;
+    unsigned long sp;
+    unsigned long gp;
+    unsigned long tp;
+    unsigned long t0;
+    unsigned long t1;
+    unsigned long t2;
+    unsigned long s0;
+    unsigned long s1;
+    unsigned long a0;
+    unsigned long a1;
+    unsigned long a2;
+    unsigned long a3;
+    unsigned long a4;
+    unsigned long a5;
+    unsigned long a6;
+    unsigned long a7;
+    unsigned long s2;
+    unsigned long s3;
+    unsigned long s4;
+    unsigned long s5;

xen/include/public/arch-riscv.h line 109

Quoted 10 lines
xen/include/public/arch-riscv.h new file +10 -0
+    unsigned long s6;
+    unsigned long s7;
+    unsigned long s8;
+    unsigned long s9;
+    unsigned long s10;
+    unsigned long s11;
+    unsigned long t3;
+    unsigned long t4;
+    unsigned long t5;
+    unsigned long t6;

Please avoid use of "unsigned long" in the public headers. Consumers, potentially even cross-bitness or cross-arch ones, may have a different view on what unsigned long is. uint<N>_t wants using here, and if you mean to abstract 32-bit and 64-bit right away, then something like a register_t typedef may want introducing.

Also iirc all the integer registers can also be referred to as x<N>, in which case it might be nice to allow for both names (in a union). You have a __DECL_REG() further up, but you don't appear to be using it ...

xen/include/public/hvm/save.h DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end); · line 110

Quoted 8 lines
xen/include/public/hvm/save.h +2 -0
@@ -106,6 +106,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);
 #include "../arch-x86/hvm/save.h"
 #elif defined(__arm__) || defined(__aarch64__)
 #include "../arch-arm/hvm/save.h"
+#elif defined(__riscv)
+#include "../arch-riscv/hvm/save.h"

Does the compiler not also provide __riscv__? If it does, using it here (and elsewhere) would fit better with the existing logic.

Jan

#29 lore raw

Re: [PATCH for-next 5/6] xen: Add files needed for minimal riscv build

Quoted 12 lines · Jan Beulich

xen/include/public/hvm/save.h DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end); · line 110

Quoted 8 lines · Connor Davis
xen/include/public/hvm/save.h +2 -0
@@ -106,6 +106,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);
  #include "../arch-x86/hvm/save.h"
  #elif defined(__arm__) || defined(__aarch64__)
  #include "../arch-arm/hvm/save.h"
+#elif defined(__riscv)
+#include "../arch-riscv/hvm/save.h"

Does the compiler not also provide __riscv__? If it does, using it here (and elsewhere) would fit better with the existing logic.

No only __riscv is defined

Thanks,

Connor

#30 lore raw

PATCH 6/6 automation: add container for riscv64 builds

In reply to Connor Davis

Add a container for cross-compiling xen to riscv64. This just includes the cross-compiler and necessary packages for building xen itself (packages for tools, stubdoms, etc., can be added later).

To build xen in the container run the following:

$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen
---
 automation/build/archlinux/riscv64.dockerfile | 32 +++++++++++++++++++
 automation/scripts/containerize               |  1 +
 2 files changed, 33 insertions(+)
 create mode 100644 automation/build/archlinux/riscv64.dockerfile
automation/build/archlinux/riscv64.dockerfile new file +32 -0
new file mode 100644
index 0000000000..d94048b6c3
@@ -0,0 +1,32 @@
+FROM archlinux/base
+LABEL maintainer.name="The Xen Project" \
+      maintainer.email="[email protected]"
+
+# Packages needed for the build
+RUN pacman --noconfirm -Syu \
+    base-devel \
+    gcc \
+    git
+
+# Packages needed for QEMU
+RUN pacman --noconfirm -Syu \
+    pixman \
+    python \
+    sh
+
+# There is a regression in GDB that causes an assertion error
+# when setting breakpoints, use this commit until it is fixed!
+RUN git clone --recursive -j$(nproc) --progress https://github.com/riscv/riscv-gnu-toolchain && \
+    cd riscv-gnu-toolchain/riscv-gdb && \
+    git checkout 1dd588507782591478882a891f64945af9e2b86c && \
+    cd  .. && \
+    ./configure --prefix=/opt/riscv && \
+    make linux -j$(nproc) && \
+    rm -R /riscv-gnu-toolchain
+
+# Add compiler path
+ENV PATH=/opt/riscv/bin/:${PATH}
+
+RUN useradd --create-home user
+USER user
+WORKDIR /build
automation/scripts/containerize +1 -0
index da45baed4e..1901e8c0ef 100755
@@ -25,6 +25,7 @@ die() {
 BASE="registry.gitlab.com/xen-project/xen"
 case "_${CONTAINER}" in
     _archlinux|_arch) CONTAINER="${BASE}/archlinux:current" ;;
+    _riscv64) CONTAINER="${BASE}/archlinux:riscv64" ;;
     _centos7) CONTAINER="${BASE}/centos:7" ;;
     _centos72) CONTAINER="${BASE}/centos:7.2" ;;
     _fedora) CONTAINER="${BASE}/fedora:29";;
Signature · 1 line
2.27.0
#31 lore raw

Re: [PATCH for-next 6/6] automation: add container for riscv64 builds

Quoted 10 lines · Connor Davis

Add a container for cross-compiling xen to riscv64. This just includes the cross-compiler and necessary packages for building xen itself (packages for tools, stubdoms, etc., can be added later).

To build xen in the container run the following:

$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen

The container build failed for me with:

Creating user git (git daemon user) with uid 977 and gid 977.
:: Running post-transaction hooks...
( 1/13) Creating system user accounts...
( 2/13) Updating journal message catalog...
( 3/13) Reloading system manager configuration...
Skipped: Current root is not booted.
( 4/13) Updating udev hardware database...
( 5/13) Applying kernel sysctl settings...
Skipped: Current root is not booted.
( 6/13) Creating temporary files...
/usr/lib/tmpfiles.d/journal-nocow.conf:26: Failed to resolve specifier: uninitialized /etc detected, skipping All rules containing unresolvable specifiers will be skipped.
( 7/13) Reloading device manager configuration...
Skipped: Device manager is not running.
( 8/13) Arming ConditionNeedsUpdate...
( 9/13) Rebuilding certificate stores...
(10/13) Reloading system bus configuration...
Skipped: Current root is not booted.
(11/13) Warn about old perl modules
(12/13) Cleaning up package cache...
(13/13) Updating the info directory file...
Removing intermediate container 81e02adffada
---> 575bfaafc6af
Step 4/9 : RUN pacman --noconfirm -Syu pixman python sh
---> Running in 9010bd7932b5
error: failed to initialize alpm library
(could not find or read directory: /var/lib/pacman/)
The command '/bin/sh -c pacman --noconfirm -Syu pixman python sh' returned a non-zero code: 255

Quoted 60 lines
---
 automation/build/archlinux/riscv64.dockerfile | 32 +++++++++++++++++++
 automation/scripts/containerize               |  1 +
 2 files changed, 33 insertions(+)
 create mode 100644 automation/build/archlinux/riscv64.dockerfile
automation/build/archlinux/riscv64.dockerfile new file +32 -0
new file mode 100644
index 0000000000..d94048b6c3
@@ -0,0 +1,32 @@
+FROM archlinux/base
+LABEL maintainer.name="The Xen Project" \
+      maintainer.email="[email protected]"
+
+# Packages needed for the build
+RUN pacman --noconfirm -Syu \
+    base-devel \
+    gcc \
+    git
+
+# Packages needed for QEMU
+RUN pacman --noconfirm -Syu \
+    pixman \
+    python \
+    sh
+
+# There is a regression in GDB that causes an assertion error
+# when setting breakpoints, use this commit until it is fixed!
+RUN git clone --recursive -j$(nproc) --progress https://github.com/riscv/riscv-gnu-toolchain && \
+    cd riscv-gnu-toolchain/riscv-gdb && \
+    git checkout 1dd588507782591478882a891f64945af9e2b86c && \
+    cd  .. && \
+    ./configure --prefix=/opt/riscv && \
+    make linux -j$(nproc) && \
+    rm -R /riscv-gnu-toolchain
+
+# Add compiler path
+ENV PATH=/opt/riscv/bin/:${PATH}
+
+RUN useradd --create-home user
+USER user
+WORKDIR /build
automation/scripts/containerize +1 -0
index da45baed4e..1901e8c0ef 100755
@@ -25,6 +25,7 @@ die() {
 BASE="registry.gitlab.com/xen-project/xen"
 case "_${CONTAINER}" in
     _archlinux|_arch) CONTAINER="${BASE}/archlinux:current" ;;
+    _riscv64) CONTAINER="${BASE}/archlinux:riscv64" ;;
     _centos7) CONTAINER="${BASE}/centos:7" ;;
     _centos72) CONTAINER="${BASE}/centos:7.2" ;;
     _fedora) CONTAINER="${BASE}/fedora:29";;
Signature · 1 line
2.27.0
#32 lore raw

Re: [PATCH for-next 6/6] automation: add container for riscv64 builds

Quoted 8 lines · Stefano Stabellini
Quoted 7 lines · Connor Davis

Add a container for cross-compiling xen to riscv64. This just includes the cross-compiler and necessary packages for building xen itself (packages for tools, stubdoms, etc., can be added later).

To build xen in the container run the following:

Quoted 8 lines
Quoted 1 line
$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen

The container build failed for me with:

error: failed to initialize alpm library (could not find or read directory: /var/lib/pacman/)
The command '/bin/sh -c pacman --noconfirm -Syu pixman python sh' returned a non-zero code: 255

Ooof, apparently archlinux/base has been broken for a few weeks now due to interactions between faccessat2 and the host's libseccomp version [0]. This thread [1] suggests the next docker release will have a fix.

As a temporary workaround I got the attached patch to work (based on this one[2]) if you want to give that a go.

Connor

[0] https://bugs.archlinux.org/task/69563
[1] https://github.com/actions/virtual-environments/issues/2658
[2] https://github.com/MiguelNdeCarvalho/docker-baseimage-archlinux/pull/8/files

automation/build/archlinux/riscv64.dockerfile +8 -0
index d94048b6c3..5b3c3b9e3b 100644
@@ -2,6 +2,11 @@ FROM archlinux/base
 LABEL maintainer.name="The Xen Project" \
       maintainer.email="[email protected]"
 
+RUN patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst && \
+    curl -LO "https://repo.archlinuxcn.org/x86_64/$patched_glibc" && \
+    bsdtar -C / -xvf "$patched_glibc" && \
+    sed -i 's/#IgnorePkg   =/IgnorePkg   = glibc/' /etc/pacman.conf
+
 # Packages needed for the build
 RUN pacman --noconfirm -Syu \
     base-devel \
@@ -26,6 +31,9 @@ RUN git clone --recursive -j$(nproc) --progress https://github.com/riscv/riscv-g
 
 # Add compiler path
 ENV PATH=/opt/riscv/bin/:${PATH}
+ENV CROSS_COMPILE=riscv64-unknown-linux-gnu-
+ENV XEN_TARGET_ARCH=riscv64
+ENV SUBSYSTEMS=xen
 
 RUN useradd --create-home user
 USER user
#33 lore raw
In reply to Connor Davis
Quoted 25 lines · Connor Davis

Hi all,

This series introduces a minimal build for RISCV. It is based on Bobby's previous work from last year[0]. I have worked to rebase onto current Xen, as well as update the various header files borrowed from Linux.

This series provides the patches necessary to get a minimal build working. The build is "minimal" in the sense that 1) it uses a minimal config and 2) files, functions, and variables are included if and only if they are required for a successful build based on the config. It doesn't run at all, as the functions just have stub implementations.

My hope is that this can serve as a useful example for future ports as well as inform the community of exactly what is imposed by common code onto new architectures.

The first 4 patches are mods to non-RISCV bits that enable building a config with:

!CONFIG_HAS_NS16550
!CONFIG_HAS_PASSTHROUGH
NR_CPUS == 1
!CONFIG_GRANT_TABLE

Quoted 6 lines

respectively. The fifth patch adds the RISCV files, and the last patch adds a docker container for doing the build. To build from the docker container (after creating it locally), you can run the following:

  $ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen 

Thanks for getting this out! Looking forward to continue working with you on this. Great job on fixing these up and fixing the rebase!

For anyone interested in peeking in on how other RISC-V developments are advancing, the out-of-tree repo is located here:
https://gitlab.com/xen-on-risc-v/xen

The parallel work has been on getting dom0 up and running. We're just beyond making domain_create/construct_dom0 calls work (and getting all of common and _init calls involved working appropriately), and are currently on mapping in and launching the dom0 created (this is being done on branch riscv-create-dom0 and be forewarned, there is still a good amount of churn there).

I'm not sure on the optimal way to keep the ML informed about how things are going... as I'm not sure I foresee many intermediate patches between this initial build and seeing a dom0 console... save for common fixes and questions. I think Connor and I are both on the IRC. Any suggestions, of course, are welcome.

Best,
Bob