Skip to contentSkip to conversation

xen: arm: 64-bit guest support and domU FDT autogeneration

RFC PATCH Superseded Ian Campbell 2 participants 42 messages Oct 7, 2013 – Oct 24, 2013

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover xen: arm: 64-bit guest support and domU FDT autogeneration

This isn't quite ready yet (see TODOs in the commit messages) but I just took a high priority interrupt so I thought I'd send it out for initial comments (it's good enough for that I think)

The actual 64-bit guest support is mostly pretty simple but there was one huge yakk which needed shaving: arm64 Linux does not support appended dtb so I had to implement autogeneration of guest dtb, which was quite a bit of code. Still, it needed to be done anyway, so it's useful...

I've not tried any of this with 32-bit guests yet.

Ian.

#1 lore raw

RFC PATCH 1/15 xen: arm: Report aarch64 capability.

---
 xen/arch/arm/setup.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/arch/arm/setup.c +4 -0
index 49f344c..faf9d50 100644
@@ -730,6 +730,10 @@ void arch_get_xen_caps(xen_capabilities_info_t *info)
 
     (*info)[0] = '\0';
 
+#ifdef CONFIG_ARM_64
+    snprintf(s, sizeof(s), "xen-%d.%d-aarch64 ", major, minor);
+    safe_strcat(*info, s);
+#endif
     snprintf(s, sizeof(s), "xen-%d.%d-armv7l ", major, minor);
     safe_strcat(*info, s);
 }
Signature · 1 line
1.7.10.4
Acked-by on v1 1/15
#2 lore raw

Re: [PATCH RFC 01/15] xen: arm: Report aarch64 capability.

Quoted 1 line · Ian Campbell
Quoted 20 lines
---
 xen/arch/arm/setup.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/arch/arm/setup.c +4 -0
index 49f344c..faf9d50 100644
@@ -730,6 +730,10 @@ void arch_get_xen_caps(xen_capabilities_info_t *info)
 
     (*info)[0] = '\0';
 
+#ifdef CONFIG_ARM_64
+    snprintf(s, sizeof(s), "xen-%d.%d-aarch64 ", major, minor);
+    safe_strcat(*info, s);
+#endif
     snprintf(s, sizeof(s), "xen-%d.%d-armv7l ", major, minor);
     safe_strcat(*info, s);
 }
Signature · 1 line
Julien Grall
#3 lore raw

RFC PATCH 2/15 xen: arm: Add comment regard arm64 zImage v0 vs v1

In reply to Ian Campbell
---
 xen/arch/arm/kernel.c |    1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/kernel.c +1 -0
index 6d2c164..8efd24a 100644
@@ -132,6 +132,7 @@ static int kernel_try_zimage64_prepare(struct kernel_info *info,
         uint64_t text_offset;  /* Image load offset */
         uint64_t res1;
         uint64_t res2;
+        /* zImage V1 only from here */
         uint64_t res3;
         uint64_t res4;
         uint64_t res5;
Signature · 1 line
1.7.10.4
Acked-by on v1 2/15
#4 lore raw

Re: [PATCH RFC 02/15] xen: arm: Add comment regard arm64 zImage v0 vs v1

Quoted 1 line · Ian Campbell
Quoted 17 lines
---
 xen/arch/arm/kernel.c |    1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/kernel.c +1 -0
index 6d2c164..8efd24a 100644
@@ -132,6 +132,7 @@ static int kernel_try_zimage64_prepare(struct kernel_info *info,
         uint64_t text_offset;  /* Image load offset */
         uint64_t res1;
         uint64_t res2;
+        /* zImage V1 only from here */
         uint64_t res3;
         uint64_t res4;
         uint64_t res5;
Signature · 1 line
Julien Grall
#5 lore raw

RFC PATCH 3/15 xen: arm: allocate dom0 memory separately from preparing the dtb

In reply to Ian Campbell

Mixing these two together is a pain, it forces us to prepare the dtb before processing the kernel which means we don't know whether the guest is 32- or 64-bit while we construct its DTB.

Instead split out the memory allocation (including 1:1 workaround handling) and p2m setup into a seaprate phase and then fill in the memory nodes in the DTB based on the result while generating the DTB.

This allows us to move kernel parsing before DTB setup.

---
 xen/arch/arm/domain_build.c |   94 ++++++++++++++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 29 deletions(-)
xen/arch/arm/domain_build.c +65 -29
index fb1fa56..1287934 100644
@@ -63,11 +63,8 @@ struct vcpu *__init alloc_dom0_vcpu0(void)
     return alloc_vcpu(dom0, 0, 0);
 }
 
-static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
-                             const struct dt_property *pp,
-                             const struct dt_device_node *np, __be32 *new_cell)
+static int allocate_memory_11(struct domain *d, struct kernel_info *kinfo)
 {
-    int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
     paddr_t start;
     paddr_t size;
     struct page_info *pg;
@@ -91,40 +88,53 @@ static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
     if ( res )
         panic("Unable to add pages in DOM0: %d\n", res);
 
-    dt_set_range(&new_cell, np, start, size);
-
     kinfo->mem.bank[0].start = start;
     kinfo->mem.bank[0].size = size;
     kinfo->mem.nr_banks = 1;
 
-    return reg_size;
+    kinfo->unassigned_mem -= size;
+
+    return 0;
 }
 
-static int set_memory_reg(struct domain *d, struct kernel_info *kinfo,
-                          const struct dt_property *pp,
-                          const struct dt_device_node *np, __be32 *new_cell)
+static int allocate_memory(struct domain *d, struct kernel_info *kinfo)
 {
-    int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
-    int l = 0;
+
+    const struct dt_device_node *memory;
+    const void *reg;
+    u32 reg_len, reg_size;
+    int l = 0, ret;
     unsigned int bank = 0;
-    u64 start;
-    u64 size;
-    int ret;
 
     if ( platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11) )
-        return set_memory_reg_11(d, kinfo, pp, np, new_cell);
+        return allocate_memory_11(d, kinfo);
+
+    memory = dt_find_node_by_type(NULL, "memory");
+    if ( memory == NULL )
+    {
+        panic("No host memory node when building dom0!\n");
+    }
+
+    reg_size = dt_cells_to_size(dt_n_addr_cells(memory) + dt_n_size_cells(memory));
 
-    while ( kinfo->unassigned_mem > 0 && l + reg_size <= pp->length
+    reg = dt_get_property(memory, "reg", &reg_len);
+    if ( reg == NULL )
+    {
+        panic("Memory node has now reg property!\n");
+    }
+
+    while ( kinfo->unassigned_mem > 0 && l + reg_size <= reg_len
             && kinfo->mem.nr_banks < NR_MEM_BANKS )
     {
-        ret = dt_device_get_address(np, bank, &start, &size);
+        paddr_t start, size;
+
+        ret = dt_device_get_address(memory, bank, &start, &size);
         if ( ret )
             panic("Unable to retrieve the bank %u for %s\n",
-                  bank, dt_node_full_name(np));
+                  bank, dt_node_full_name(memory));
 
         if ( size > kinfo->unassigned_mem )
             size = kinfo->unassigned_mem;
-        dt_set_range(&new_cell, np, start, size);
 
         printk("Populate P2M %#"PRIx64"->%#"PRIx64"\n", start, start + size);
         if ( p2m_populate_ram(d, start, start + size) < 0 )
@@ -132,12 +142,34 @@ static int set_memory_reg(struct domain *d, struct kernel_info *kinfo,
         kinfo->mem.bank[kinfo->mem.nr_banks].start = start;
         kinfo->mem.bank[kinfo->mem.nr_banks].size = size;
         kinfo->mem.nr_banks++;
+
         kinfo->unassigned_mem -= size;
 
         l += reg_size;
     }
+    return 0;
+}
 
-    return l;
+static int set_memory_reg(struct domain *d, struct kernel_info *kinfo,
+                          const struct dt_device_node *np, __be32 *new_cell)
+{
+    int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
+    u64 start;
+    u64 size;
+    int i;
+
+    for ( i = 0 ; i < kinfo->mem.nr_banks; i++ )
+    {
+        start = kinfo->mem.bank[i].start;
+        size = kinfo->mem.bank[i].size;
+
+        DPRINT("Memory Bank %d: %#"PRIx64"->%#"PRIx64"\n",
+                i, start, start + size);
+
+        dt_set_range(&new_cell, np, start, size);
+    }
+
+    return kinfo->mem.nr_banks * reg_size;
 }
 
 static int write_properties(struct domain *d, struct kernel_info *kinfo,
@@ -194,7 +226,7 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,
                 if ( new_data  == NULL )
                     return -FDT_ERR_XEN(ENOMEM);
 
-                prop_len = set_memory_reg(d, kinfo, pp, np,
+                prop_len = set_memory_reg(d, kinfo, np,
                                           (__be32 *)new_data);
                 prop_data = new_data;
             }
@@ -768,8 +800,6 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo)
 
     ASSERT(dt_host && (dt_host->sibling == NULL));
 
-    kinfo->unassigned_mem = dom0_mem;
-
     fdt = device_tree_flattened;
 
     new_size = fdt_totalsize(fdt) + DOM0_FDT_EXTRA_SIZE;
@@ -858,7 +888,9 @@ int construct_dom0(struct domain *d)
 
     d->max_pages = ~0U;
 
-    rc = prepare_dtb(d, &kinfo);
+    kinfo.unassigned_mem = dom0_mem;
+
+    rc = allocate_memory(d, &kinfo);
     if ( rc < 0 )
         return rc;
 
@@ -866,6 +898,14 @@ int construct_dom0(struct domain *d)
     if ( rc < 0 )
         return rc;
 
+#ifdef CONFIG_ARM_64
+    d->arch.type = kinfo.type;
+#endif
+
+    rc = prepare_dtb(d, &kinfo);
+    if ( rc < 0 )
+        return rc;
+
     rc = platform_specific_mapping(d);
     if ( rc < 0 )
         return rc;
@@ -888,10 +928,6 @@ int construct_dom0(struct domain *d)
 
     regs->pc = (register_t)kinfo.entry;
 
-#ifdef CONFIG_ARM_64
-    d->arch.type = kinfo.type;
-#endif
-
     if ( is_pv32_domain(d) )
     {
         regs->cpsr = PSR_GUEST32_INIT;
Signature · 1 line
1.7.10.4
#6 lore raw

Re: [PATCH RFC 03/15] xen: arm: allocate dom0 memory separately from preparing the dtb

Quoted 6 lines · Ian Campbell

Mixing these two together is a pain, it forces us to prepare the dtb before processing the kernel which means we don't know whether the guest is 32- or 64-bit while we construct its DTB.

Instead split out the memory allocation (including 1:1 workaround handling) and p2m setup into a seaprate phase and then fill in the memory nodes in the

separate

Quoted 14 lines

DTB based on the result while generating the DTB.

This allows us to move kernel parsing before DTB setup.

---
 xen/arch/arm/domain_build.c |   94 ++++++++++++++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 29 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index fb1fa56..1287934 100644

xen/arch/arm/domain_build.c struct vcpu *__init alloc_dom0_vcpu0(void) · line 66

Quoted 7 lines
xen/arch/arm/domain_build.c +1 -3
@@ -63,11 +63,8 @@ struct vcpu *__init alloc_dom0_vcpu0(void)
     return alloc_vcpu(dom0, 0, 0);
 }
 
-static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
-                             const struct dt_property *pp,
-                             const struct dt_device_node *np, __be32 *new_cell)
+static int allocate_memory_11(struct domain *d, struct kernel_info *kinfo)

This function always return 0 or panic if an error occurred. Perhaps you can move the return type to void?

Quoted 15 lines
xen/arch/arm/domain_build.c +0 -3
 {
-    int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
     paddr_t start;
     paddr_t size;
     struct page_info *pg;
@@ -91,40 +88,53 @@ static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo,
     if ( res )
         panic("Unable to add pages in DOM0: %d\n", res);
 
-    dt_set_range(&new_cell, np, start, size);
-
     kinfo->mem.bank[0].start = start;
     kinfo->mem.bank[0].size = size;
     kinfo->mem.nr_banks = 1;
 

xen/arch/arm/domain_build.c static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo, · line 100

Quoted 10 lines
xen/arch/arm/domain_build.c +4 -4
-    return reg_size;
+    kinfo->unassigned_mem -= size;
+
+    return 0;
 }
 
-static int set_memory_reg(struct domain *d, struct kernel_info *kinfo,
-                          const struct dt_property *pp,
-                          const struct dt_device_node *np, __be32 *new_cell)
+static int allocate_memory(struct domain *d, struct kernel_info *kinfo)

Same here.

Quoted 8 lines
xen/arch/arm/domain_build.c +5 -2
 {
-    int reg_size = dt_cells_to_size(dt_n_addr_cells(np) + dt_n_size_cells(np));
-    int l = 0;
+
+    const struct dt_device_node *memory;
+    const void *reg;
+    u32 reg_len, reg_size;
+    int l = 0, ret;

xen/arch/arm/domain_build.c static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo, · line 112

Quoted 10 lines
xen/arch/arm/domain_build.c +3 -4
     unsigned int bank = 0;
-    u64 start;
-    u64 size;
-    int ret;
 
     if ( platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11) )
-        return set_memory_reg_11(d, kinfo, pp, np, new_cell);
+        return allocate_memory_11(d, kinfo);
+
+    memory = dt_find_node_by_type(NULL, "memory");

Can we try to have the same way to retrieve the memory node in each place?

- common/device_tree.c: looking by memory@unit
- arch/arm/domain_build.c:write_properties: looking only the exact node name "memory"
- here: looking by type "memory"

Furthermore, your are assuming that there is only one memory node in DTS tree. Perhaps a loop is better here?

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH RFC 03/15] xen: arm: allocate dom0 memory separately from preparing the dtb

Quoted 2 lines · Julien Grall

This function always return 0 or panic if an error occurred. Perhaps you can move the return type to void?

Yes, done all the way up the call chain.

Quoted 7 lines

xen/arch/arm/domain_build.c static int set_memory_reg_11(struct domain *d, struct kernel_info *kinfo, · line 112

Quoted 5 lines

if ( platform_has_quirk(PLATFORM_QUIRK_DOM0_MAPPING_11) )

xen/arch/arm/domain_build.c +3 -1
-        return set_memory_reg_11(d, kinfo, pp, np, new_cell);
+        return allocate_memory_11(d, kinfo);
+
+    memory = dt_find_node_by_type(NULL, "memory");

Can we try to have the same way to retrieve the memory node in each place?

Hrm. The first one (device_tree.c) is using the early stuff while the other two are using the full datastructures.

But for the last two I think the right thing to do is to check for device_type = "memory".

Quoted 7 lines

- common/device_tree.c: looking by memory@unit
- arch/arm/domain_build.c:write_properties: looking only the exact node name "memory"
- here: looking by type "memory"

Furthermore, your are assuming that there is only one memory node in DTS tree. Perhaps a loop is better here?

Yes, I'll change that.

Ian.

#8 lore raw

RFC PATCH 4/15 xen: arm: add enable-method to cpu nodes for arm64 guests.

In reply to Ian Campbell

This is required by the Linux arm64 boot protocol.

We use PSCI.

---
 xen/arch/arm/domain_build.c |    7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/arm/domain_build.c +7 -0
index 1287934..10dea5d 100644
@@ -468,6 +468,13 @@ static int make_cpus_node(const struct domain *d, void *fdt,
         if ( res )
             return res;
 
+        if ( is_pv64_domain(d) )
+        {
+            res = fdt_property_string(fdt, "enable-method", "psci");
+            if ( res )
+                return res;
+        }
+
         res = fdt_end_node(fdt);
         if ( res )
             return res;
Signature · 1 line
1.7.10.4
Acked-by on v1 4/15
#9 lore raw

Re: [PATCH RFC 04/15] xen: arm: add enable-method to cpu nodes for arm64 guests.

Quoted 5 lines · Ian Campbell

This is required by the Linux arm64 boot protocol.

We use PSCI.

Quoted 23 lines
---
 xen/arch/arm/domain_build.c |    7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/arm/domain_build.c +7 -0
index 1287934..10dea5d 100644
@@ -468,6 +468,13 @@ static int make_cpus_node(const struct domain *d, void *fdt,
         if ( res )
             return res;
 
+        if ( is_pv64_domain(d) )
+        {
+            res = fdt_property_string(fdt, "enable-method", "psci");
+            if ( res )
+                return res;
+        }
+
         res = fdt_end_node(fdt);
         if ( res )
             return res;
Signature · 1 line
Julien Grall
#10 lore raw

RFC PATCH 5/15 xen: arm: implement XEN_DOMCTL_set_address_size

In reply to Ian Campbell

This subarch specific to plumb through to arm32 and arm64 versions.

The toolstack uses this to select 32- vs 64-bit guests (or rather it does on x86 an soon will for arm too).

I noticed that domctl.c and sysctl.c weren't including xen/hypercall.h to get their arch_do_fooctl prototypes, so fix that.

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/domctl.c     |   35 +++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/domctl.c     |   59 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/domctl.c           |    7 ++++-
 xen/arch/arm/sysctl.c           |    1 +
 xen/include/asm-arm/hypercall.h |    3 ++
 7 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 xen/arch/arm/arm32/domctl.c
 create mode 100644 xen/arch/arm/arm64/domctl.c
xen/arch/arm/arm32/Makefile +1 -0
index aacdcb9..65ecff4 100644
@@ -7,5 +7,6 @@ obj-y += traps.o
 obj-y += domain.o
 obj-y += vfp.o
 obj-y += smpboot.o
+obj-y += domctl.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/domctl.c new file +35 -0
new file mode 100644
index 0000000..c2ca4d3
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * Subarch-specific domctl.c
+ *
+ * Copyright (c) 2013, Citrix Systems
+ */
+
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/lib.h>
+#include <xen/errno.h>
+#include <xen/sched.h>
+#include <xen/hypercall.h>
+#include <public/domctl.h>
+
+long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
+               XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
+{
+    switch ( domctl->cmd )
+    {
+    case XEN_DOMCTL_set_address_size:
+        return domctl->u.address_size.size == 32 ? 0 : -EINVAL;
+    default:
+        return -ENOSYS;
+    }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/arm/arm64/Makefile +1 -0
index 5d28bad..d2d5875 100644
@@ -6,5 +6,6 @@ obj-y += traps.o
 obj-y += domain.o
 obj-y += vfp.o
 obj-y += smpboot.o
+obj-y += domctl.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm64/domctl.c new file +59 -0

59 lines not on this page · raw message

xen/arch/arm/domctl.c +6 -1
index 851ee40..546e86b 100644
@@ -9,12 +9,17 @@
 #include <xen/lib.h>
 #include <xen/errno.h>
 #include <xen/sched.h>
+#include <xen/hypercall.h>
 #include <public/domctl.h>
 
 long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
-    return -ENOSYS;
+    switch ( domctl->cmd )
+    {
+    default:
+        return subarch_do_domctl(domctl, d, u_domctl);
+    }
 }
 
 void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
xen/arch/arm/sysctl.c +1 -0
index 6388204..98bab6a 100644
@@ -10,6 +10,7 @@
 #include <xen/types.h>
 #include <xen/lib.h>
 #include <xen/errno.h>
+#include <xen/hypercall.h>
 #include <public/sysctl.h>
 
 void arch_do_physinfo(xen_sysctl_physinfo_t *pi) { }
xen/include/asm-arm/hypercall.h +3 -0
index 3327a96..94a92d4 100644
@@ -6,6 +6,9 @@ int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
 long do_arm_vcpu_op(int cmd, int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg);
 
+long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
+                       XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+
 #endif /* __ASM_ARM_HYPERCALL_H__ */
 /*
  * Local variables:
Signature · 1 line
1.7.10.4
#11 lore raw

RFC PATCH 6/15 xen: arm: implement arch_set_info_guest for 64-bit vcpus

In reply to Ian Campbell

This all seems too easy...

---
 xen/arch/arm/domain.c |   66 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 14 deletions(-)
xen/arch/arm/domain.c +52 -14
index cb0424d..907d5c0 100644
@@ -550,7 +550,7 @@ void arch_domain_destroy(struct domain *d)
     free_xenheap_page(d->shared_info);
 }
 
-static int is_guest_psr(uint32_t psr)
+static int is_guest_pv32_psr(uint32_t psr)
 {
     switch (psr & PSR_MODE_MASK)
     {
@@ -569,6 +569,29 @@ static int is_guest_psr(uint32_t psr)
     }
 }
 
+
+#ifdef CONFIG_ARM_64
+static int is_guest_pv64_psr(uint32_t psr)
+{
+    if ( psr & PSR_MODE_BIT )
+        return 0;
+
+    switch (psr & PSR_MODE_MASK)
+    {
+    case PSR_MODE_EL1h:
+    case PSR_MODE_EL1t:
+    case PSR_MODE_EL0t:
+        return 1;
+    case PSR_MODE_EL3h:
+    case PSR_MODE_EL3t:
+    case PSR_MODE_EL2h:
+    case PSR_MODE_EL2t:
+    default:
+        return 0;
+    }
+}
+#endif
+
 /*
  * Initialise VCPU state. The context can be supplied by either the
  * toolstack (XEN_DOMCTL_setvcpucontext) or the guest
@@ -577,22 +600,37 @@ static int is_guest_psr(uint32_t psr)
 int arch_set_info_guest(
     struct vcpu *v, vcpu_guest_context_u c)
 {
+    struct domain *d = v->domain;
     struct vcpu_guest_context *ctxt = c.nat;
     struct vcpu_guest_core_regs *regs = &c.nat->user_regs;
 
-    if ( !is_guest_psr(regs->cpsr) )
-        return -EINVAL;
-
-    if ( regs->spsr_svc && !is_guest_psr(regs->spsr_svc) )
-        return -EINVAL;
-    if ( regs->spsr_abt && !is_guest_psr(regs->spsr_abt) )
-        return -EINVAL;
-    if ( regs->spsr_und && !is_guest_psr(regs->spsr_und) )
-        return -EINVAL;
-    if ( regs->spsr_irq && !is_guest_psr(regs->spsr_irq) )
-        return -EINVAL;
-    if ( regs->spsr_fiq && !is_guest_psr(regs->spsr_fiq) )
-        return -EINVAL;
+
+    if ( is_pv32_domain(d) )
+    {
+        if ( !is_guest_pv32_psr(regs->cpsr) )
+            return -EINVAL;
+
+        if ( regs->spsr_svc && !is_guest_pv32_psr(regs->spsr_svc) )
+            return -EINVAL;
+        if ( regs->spsr_abt && !is_guest_pv32_psr(regs->spsr_abt) )
+            return -EINVAL;
+        if ( regs->spsr_und && !is_guest_pv32_psr(regs->spsr_und) )
+            return -EINVAL;
+        if ( regs->spsr_irq && !is_guest_pv32_psr(regs->spsr_irq) )
+            return -EINVAL;
+        if ( regs->spsr_fiq && !is_guest_pv32_psr(regs->spsr_fiq) )
+            return -EINVAL;
+    }
+#ifdef CONFIG_ARM_64
+    else
+    {
+        if ( !is_guest_pv64_psr(regs->cpsr) )
+            return -EINVAL;
+
+        if ( regs->spsr_el1 && !is_guest_pv64_psr(regs->spsr_el1) )
+            return -EINVAL;
+    }
+#endif
 
     vcpu_regs_user_to_hyp(v, regs);
 
Signature · 1 line
1.7.10.4
#12 lore raw

RFC PATCH 7/15 xenctx: fix typo in arm64 output

In reply to Ian Campbell
---
 tools/xentrace/xenctx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xentrace/xenctx.c +1 -1
index 1214185..4b774af 100644
@@ -497,7 +497,7 @@ static void print_ctx_64(vcpu_guest_context_t *ctx)
     print_symbol(regs->pc64);
     printf("\n");
 
-    printf("LR:       %016"PRIx64"zn", regs->x30);
+    printf("LR:       %016"PRIx64"\n", regs->x30);
     printf("ELR_EL1:  %016"PRIx64"\n", regs->elr_el1);
 
     printf("CPSR:     %08"PRIx32"\n", regs->cpsr);
Signature · 1 line
1.7.10.4
Acked-by on v1 7/15
#13 lore raw

Re: [PATCH RFC 07/15] xenctx: fix typo in arm64 output

Quoted 1 line · Ian Campbell
Quoted 18 lines
---
 tools/xentrace/xenctx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xentrace/xenctx.c +1 -1
index 1214185..4b774af 100644
@@ -497,7 +497,7 @@ static void print_ctx_64(vcpu_guest_context_t *ctx)
     print_symbol(regs->pc64);
     printf("\n");
 
-    printf("LR:       %016"PRIx64"zn", regs->x30);
+    printf("LR:       %016"PRIx64"\n", regs->x30);
     printf("ELR_EL1:  %016"PRIx64"\n", regs->elr_el1);
 
     printf("CPSR:     %08"PRIx32"\n", regs->cpsr);
Signature · 1 line
Julien Grall
#15 lore raw

RFC PATCH 8/15 tools: check for libfdt when building for ARM

In reply to Ian Campbell

libxl is going to want this to aid in the creation of guest device tree blobs.

---
 tools/config.h.in  |    3 +++
 tools/configure    |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/configure.ac |    6 ++++++
 3 files changed, 61 insertions(+)
tools/config.h.in +3 -0
index b1c9531..015f2a1 100644
@@ -9,6 +9,9 @@
 /* Define to 1 if you have the `crypto' library (-lcrypto). */
 #undef HAVE_LIBCRYPTO
 
+/* Define to 1 if you have the `fdt' library (-lfdt). */
+#undef HAVE_LIBFDT
+
 /* Define to 1 if you have the `yajl' library (-lyajl). */
 #undef HAVE_LIBYAJL
 
tools/configure +52 -0

58 lines not on this page · raw message

tools/configure.ac +6 -0
index 4f3c33a..c366efb 100644
@@ -216,6 +216,12 @@ AC_CHECK_LIB([z], [deflateCopy], [], [AC_MSG_ERROR([Could not find zlib])])
 AC_CHECK_LIB([iconv], [libiconv_open], [libiconv="y"], [libiconv="n"])
 AC_SUBST(libiconv)
 
+# FDT is needed only on ARM
+case "$host_cpu" in
+arm*|aarch64)
+AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])])
+esac
+
 # Checks for header files.
 AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h])
 
Signature · 1 line
1.7.10.4
#16 lore raw

RFC PATCH 9/15 libxc: arm: rename various bits of zimage load with 32 suffix

In reply to Ian Campbell

Making room for a 64 bit implementation.

Also fix a typo and stop refering to it as a bzImage, which is an x86-ism.

---
 tools/libxc/xc_dom_armzimageloader.c |   44 ++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 18 deletions(-)
tools/libxc/xc_dom_armzimageloader.c +26 -18
index 54728b8..b693390 100644
@@ -36,12 +36,6 @@
  */
 #define GUEST_RAM_BASE 0x80000000
 
-#define ZIMAGE_MAGIC_OFFSET 0x24
-#define ZIMAGE_START_OFFSET 0x28
-#define ZIMAGE_END_OFFSET   0x2c
-
-#define ZIMAGE_MAGIC 0x016f2818
-
 struct minimal_dtb_header {
     uint32_t magic;
     uint32_t total_size;
@@ -50,7 +44,17 @@ struct minimal_dtb_header {
 
 #define DTB_MAGIC 0xd00dfeed
 
-static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
+/* ------------------------------------------------------------ */
+/* 32-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE32_MAGIC_OFFSET 0x24
+#define ZIMAGE32_START_OFFSET 0x28
+#define ZIMAGE32_END_OFFSET   0x2c
+
+#define ZIMAGE32_MAGIC 0x016f2818
+
+static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
 {
     uint32_t *zimage;
     uint32_t end;
@@ -69,13 +73,13 @@ static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
     }
 
     zimage = (uint32_t *)dom->kernel_blob;
-    if ( zimage[ZIMAGE_MAGIC_OFFSET/4] != ZIMAGE_MAGIC )
+    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
     {
-        xc_dom_printf(dom->xch, "%s: kernel is not a bzImage", __FUNCTION__);
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
         return -EINVAL;
     }
 
-    end = zimage[ZIMAGE_END_OFFSET/4];
+    end = zimage[ZIMAGE32_END_OFFSET/4];
 
     /*
      * Check for an appended DTB.
@@ -94,7 +98,7 @@ static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
-static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
+static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
 {
     uint32_t *zimage;
     uint32_t start, entry_addr;
@@ -111,7 +115,7 @@ static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
     v_start = rambase + 0x8000;
     v_end = v_start + dom->kernel_size;
 
-    start = zimage[ZIMAGE_START_OFFSET/4];
+    start = zimage[ZIMAGE32_START_OFFSET/4];
 
     if (start == 0)
         entry_addr = v_start;
@@ -134,6 +138,10 @@ static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
+/* ------------------------------------------------------------ */
+/* Common zImage Support                                        */
+/* ------------------------------------------------------------ */
+
 static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
 {
     void *dst;
@@ -148,7 +156,7 @@ static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
         return -1;
     }
 
-    DOMPRINTF("%s: kernel sed %#"PRIx64"-%#"PRIx64,
+    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
               __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
     DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
               __func__, dom->kernel_size, dom->kernel_blob, dst);
@@ -158,16 +166,16 @@ static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
-static struct xc_dom_loader zimage_loader = {
-    .name = "Linux zImage (ARM)",
-    .probe = xc_dom_probe_zimage_kernel,
-    .parser = xc_dom_parse_zimage_kernel,
+static struct xc_dom_loader zimage32_loader = {
+    .name = "Linux zImage (ARM32)",
+    .probe = xc_dom_probe_zimage32_kernel,
+    .parser = xc_dom_parse_zimage32_kernel,
     .loader = xc_dom_load_zimage_kernel,
 };
 
 static void __init register_loader(void)
 {
-    xc_dom_register_loader(&zimage_loader);
+    xc_dom_register_loader(&zimage32_loader);
 }
 
 /*
Signature · 1 line
1.7.10.4
Acked-by on v1 9/15
#17 lore raw

Re: [PATCH RFC 09/15] libxc: arm: rename various bits of zimage load with 32 suffix

Quoted 5 lines · Ian Campbell

Making room for a 64 bit implementation.

Also fix a typo and stop refering to it as a bzImage, which is an x86-ism.

Quoted 118 lines
---
 tools/libxc/xc_dom_armzimageloader.c |   44 ++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 18 deletions(-)
tools/libxc/xc_dom_armzimageloader.c +26 -18
index 54728b8..b693390 100644
@@ -36,12 +36,6 @@
  */
 #define GUEST_RAM_BASE 0x80000000
 
-#define ZIMAGE_MAGIC_OFFSET 0x24
-#define ZIMAGE_START_OFFSET 0x28
-#define ZIMAGE_END_OFFSET   0x2c
-
-#define ZIMAGE_MAGIC 0x016f2818
-
 struct minimal_dtb_header {
     uint32_t magic;
     uint32_t total_size;
@@ -50,7 +44,17 @@ struct minimal_dtb_header {
 
 #define DTB_MAGIC 0xd00dfeed
 
-static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
+/* ------------------------------------------------------------ */
+/* 32-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE32_MAGIC_OFFSET 0x24
+#define ZIMAGE32_START_OFFSET 0x28
+#define ZIMAGE32_END_OFFSET   0x2c
+
+#define ZIMAGE32_MAGIC 0x016f2818
+
+static int xc_dom_probe_zimage32_kernel(struct xc_dom_image *dom)
 {
     uint32_t *zimage;
     uint32_t end;
@@ -69,13 +73,13 @@ static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
     }
 
     zimage = (uint32_t *)dom->kernel_blob;
-    if ( zimage[ZIMAGE_MAGIC_OFFSET/4] != ZIMAGE_MAGIC )
+    if ( zimage[ZIMAGE32_MAGIC_OFFSET/4] != ZIMAGE32_MAGIC )
     {
-        xc_dom_printf(dom->xch, "%s: kernel is not a bzImage", __FUNCTION__);
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm32 zImage", __FUNCTION__);
         return -EINVAL;
     }
 
-    end = zimage[ZIMAGE_END_OFFSET/4];
+    end = zimage[ZIMAGE32_END_OFFSET/4];
 
     /*
      * Check for an appended DTB.
@@ -94,7 +98,7 @@ static int xc_dom_probe_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
-static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
+static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
 {
     uint32_t *zimage;
     uint32_t start, entry_addr;
@@ -111,7 +115,7 @@ static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
     v_start = rambase + 0x8000;
     v_end = v_start + dom->kernel_size;
 
-    start = zimage[ZIMAGE_START_OFFSET/4];
+    start = zimage[ZIMAGE32_START_OFFSET/4];
 
     if (start == 0)
         entry_addr = v_start;
@@ -134,6 +138,10 @@ static int xc_dom_parse_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
+/* ------------------------------------------------------------ */
+/* Common zImage Support                                        */
+/* ------------------------------------------------------------ */
+
 static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
 {
     void *dst;
@@ -148,7 +156,7 @@ static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
         return -1;
     }
 
-    DOMPRINTF("%s: kernel sed %#"PRIx64"-%#"PRIx64,
+    DOMPRINTF("%s: kernel seg %#"PRIx64"-%#"PRIx64,
               __func__, dom->kernel_seg.vstart, dom->kernel_seg.vend);
     DOMPRINTF("%s: copy %zd bytes from blob %p to dst %p",
               __func__, dom->kernel_size, dom->kernel_blob, dst);
@@ -158,16 +166,16 @@ static int xc_dom_load_zimage_kernel(struct xc_dom_image *dom)
     return 0;
 }
 
-static struct xc_dom_loader zimage_loader = {
-    .name = "Linux zImage (ARM)",
-    .probe = xc_dom_probe_zimage_kernel,
-    .parser = xc_dom_parse_zimage_kernel,
+static struct xc_dom_loader zimage32_loader = {
+    .name = "Linux zImage (ARM32)",
+    .probe = xc_dom_probe_zimage32_kernel,
+    .parser = xc_dom_parse_zimage32_kernel,
     .loader = xc_dom_load_zimage_kernel,
 };
 
 static void __init register_loader(void)
 {
-    xc_dom_register_loader(&zimage_loader);
+    xc_dom_register_loader(&zimage32_loader);
 }
 
 /*
Signature · 1 line
Julien Grall
#18 lore raw

RFC PATCH 10/15 libxc: allow caller to specify guest rambase rather than hardcoding

In reply to Ian Campbell

It's still hardcoded but it could now be plausibly be made variable.

TODO: the #if is a bit lame.

---
 tools/libxc/xc_dom.h                 |    1 +
 tools/libxc/xc_dom_armzimageloader.c |   12 +-----------
 tools/libxc/xc_dom_core.c            |    8 ++++++++
 tools/libxl/libxl_dom.c              |   10 ++++++++++
 4 files changed, 20 insertions(+), 11 deletions(-)
tools/libxc/xc_dom.h +1 -0
index 86e23ee..ed49aa7 100644
@@ -197,6 +197,7 @@ struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
                                      const char *cmdline, const char *features);
 void xc_dom_release_phys(struct xc_dom_image *dom);
 void xc_dom_release(struct xc_dom_image *dom);
+int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase);
 int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
 
 /* Set this larger if you have enormous ramdisks/kernels. Note that
tools/libxc/xc_dom_armzimageloader.c +1 -11
index b693390..4e3f7ae 100644
@@ -30,12 +30,6 @@
 
 #include <arpa/inet.h> /* XXX ntohl is not the right function... */
 
-/*
- * Guest virtual RAM starts here. This must be consistent with the DTB
- * appended to the guest kernel.
- */
-#define GUEST_RAM_BASE 0x80000000
-
 struct minimal_dtb_header {
     uint32_t magic;
     uint32_t total_size;
@@ -103,14 +97,12 @@ static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
     uint32_t *zimage;
     uint32_t start, entry_addr;
     uint64_t v_start, v_end;
-    uint64_t rambase = GUEST_RAM_BASE;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
 
     DOMPRINTF_CALLED(dom->xch);
 
     zimage = (uint32_t *)dom->kernel_blob;
 
-    dom->rambase_pfn = rambase >> XC_PAGE_SHIFT;
-
     /* Do not load kernel at the very first RAM address */
     v_start = rambase + 0x8000;
     v_end = v_start + dom->kernel_size;
@@ -130,8 +122,6 @@ static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
     dom->parms.virt_base = rambase;
 
     dom->guest_type = "xen-3.0-armv7l";
-    DOMPRINTF("%s: %s: RAM starts at %"PRI_xen_pfn,
-              __FUNCTION__, dom->guest_type, dom->rambase_pfn);
     DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
               __FUNCTION__, dom->guest_type,
               dom->kernel_seg.vstart, dom->kernel_seg.vend);
tools/libxc/xc_dom_core.c +8 -0
index 0f367f6..a67f718 100644
@@ -785,6 +785,14 @@ int xc_dom_parse_image(struct xc_dom_image *dom)
     return -1;
 }
 
+int xc_dom_rambase_init(struct xc_dom_image *dom, uint64_t rambase)
+{
+    dom->rambase_pfn = rambase >> XC_PAGE_SHIFT;
+    DOMPRINTF("%s: RAM starts at %"PRI_xen_pfn,
+              __FUNCTION__, dom->rambase_pfn);
+    return 0;
+}
+
 int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb)
 {
     unsigned int page_shift;
tools/libxl/libxl_dom.c +10 -0
index 6e2252a..631cdf5 100644
@@ -24,6 +24,10 @@
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/hvm_xs_strings.h>
 
+#if defined(__arm__) || defined(__aarch64__)
+#define GUEST_RAM_BASE 0x80000000
+#endif
+
 libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -380,6 +384,12 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
         LOGE(ERROR, "xc_dom_boot_xen_init failed");
         goto out;
     }
+#ifdef GUEST_RAM_BASE
+    if ( (ret = xc_dom_rambase_init(dom, GUEST_RAM_BASE)) != 0 ) {
+        LOGE(ERROR, "xc_dom_rambase failed");
+        goto out;
+    }
+#endif
     if ( (ret = xc_dom_parse_image(dom)) != 0 ) {
         LOGE(ERROR, "xc_dom_parse_image failed");
         goto out;
Signature · 1 line
1.7.10.4
#19 lore raw

Re: [PATCH RFC 10/15] libxc: allow caller to specify guest rambase rather than hardcoding

Quoted 1 line · Ian Campbell

It's still hardcoded but it could now be plausibly be made variable.

There is a thread were people asking to change the base address. For the xl side, how about a parameter in the configuration file? The default value would be 0.

Quoted 2 lines

TODO: the #if is a bit lame.

Signature · 1 line
Julien Grall
#20 lore raw

Re: [PATCH RFC 10/15] libxc: allow caller to specify guest rambase rather than hardcoding

Quoted 6 lines · Julien Grall
Quoted 1 line · Ian Campbell

It's still hardcoded but it could now be plausibly be made variable.

There is a thread were people asking to change the base address. For the xl side, how about a parameter in the configuration file? The default value would be 0.

For future work, sure.

At the moment I don't want to start shaving the yak of plumbing ARM specific parameters through libxl to xl.

I've been thinking of making the hardcoded default be 0 in any case.

Ian.

#21 lore raw

RFC PATCH 11/15 libxc: allow passing a device tree blob to the guest

In reply to Ian Campbell

TODO: placement is rather simplistic

---
 tools/libxc/xc_dom.h      |    8 ++++++++
 tools/libxc/xc_dom_arm.c  |   15 +++++++++++++-
 tools/libxc/xc_dom_core.c |   48 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)
tools/libxc/xc_dom.h +8 -0
index ed49aa7..bf56436 100644
@@ -54,9 +54,12 @@ struct xc_dom_image {
     size_t kernel_size;
     void *ramdisk_blob;
     size_t ramdisk_size;
+    void *devicetree_blob;
+    size_t devicetree_size;
 
     size_t max_kernel_size;
     size_t max_ramdisk_size;
+    size_t max_devicetree_size;
 
     /* arguments and parameters */
     char *cmdline;
@@ -217,6 +220,8 @@ int xc_dom_kernel_max_size(struct xc_dom_image *dom, size_t sz);
 int xc_dom_ramdisk_check_size(struct xc_dom_image *dom, size_t sz);
 int xc_dom_ramdisk_max_size(struct xc_dom_image *dom, size_t sz);
 
+int xc_dom_devicetree_max_size(struct xc_dom_image *dom, size_t sz);
+
 size_t xc_dom_check_gzip(xc_interface *xch,
                      void *blob, size_t ziplen);
 int xc_dom_do_gunzip(xc_interface *xch,
@@ -229,6 +234,9 @@ int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem,
                       size_t memsize);
 int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem,
                        size_t memsize);
+int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename);
+int xc_dom_devicetree_mem(struct xc_dom_image *dom, const void *mem,
+                          size_t memsize);
 
 int xc_dom_parse_image(struct xc_dom_image *dom);
 struct xc_dom_arch *xc_dom_find_arch_hooks(xc_interface *xch, char *guest_type);
tools/libxc/xc_dom_arm.c +14 -1
index df59ffb..ecdaea9 100644
@@ -124,7 +124,8 @@ static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
      * using CONFIG_ARM_APPENDED_DTB. Ensure that r2 does not look
      * like a valid pointer to a set of ATAGS or a DTB.
      */
-    ctxt->user_regs.r2_usr = 0xffffffff;
+    ctxt->user_regs.r2_usr = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
 
     ctxt->sctlr = /* #define SCTLR_BASE */0x00c50078;
 
@@ -191,6 +192,18 @@ int arch_setup_meminit(struct xc_dom_image *dom)
             0, 0, &dom->p2m_host[i]);
     }
 
+    if ( dom->devicetree_blob )
+    {
+        uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+        /* XXX intelligent placement */
+        dom->devicetree_seg.vstart = rambase + 127*1024*1024;
+        dom->devicetree_seg.vend =
+            dom->devicetree_seg.vstart + dom->devicetree_size;
+        DOMPRINTF("%s: devicetree: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+                  __FUNCTION__,
+                  dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
+    }
+
     return 0;
 }
 
tools/libxc/xc_dom_core.c +48 -0

78 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#22 lore raw

RFC PATCH 12/15 libxc: support for arm64 Image format

In reply to Ian Campbell
---
 tools/libxc/xc_dom_armzimageloader.c |   88 ++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
tools/libxc/xc_dom_armzimageloader.c +88 -0
index 4e3f7ae..609d3a0 100644
@@ -129,6 +129,86 @@ static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
 }
 
 /* ------------------------------------------------------------ */
+/* 64-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE64_MAGIC_V0 0x14000008
+#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
+
+/* linux/Documentation/arm64/booting.txt */
+struct zimage64_hdr {
+    uint32_t magic0;
+    uint32_t res0;
+    uint64_t text_offset;  /* Image load offset */
+    uint64_t res1;
+    uint64_t res2;
+    /* zImage V1 only from here */
+    uint64_t res3;
+    uint64_t res4;
+    uint64_t res5;
+    uint32_t magic1;
+    uint32_t res6;
+};
+static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < sizeof(*zimage) )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage =  dom->kernel_blob;
+    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
+         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+    uint32_t entry_addr;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = dom->kernel_blob;
+
+    v_start = rambase + zimage->text_offset;
+    v_end = v_start + dom->kernel_size;
+
+    entry_addr = v_start;
+
+    /* find kernel segment */
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_start + dom->kernel_size;
+
+    dom->parms.virt_entry = entry_addr;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-aarch64";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
 /* Common zImage Support                                        */
 /* ------------------------------------------------------------ */
 
@@ -163,9 +243,17 @@ static struct xc_dom_loader zimage32_loader = {
     .loader = xc_dom_load_zimage_kernel,
 };
 
+static struct xc_dom_loader zimage64_loader = {
+    .name = "Linux zImage (ARM64)",
+    .probe = xc_dom_probe_zimage64_kernel,
+    .parser = xc_dom_parse_zimage64_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
 static void __init register_loader(void)
 {
     xc_dom_register_loader(&zimage32_loader);
+    xc_dom_register_loader(&zimage64_loader);
 }
 
 /*
Signature · 1 line
1.7.10.4
#23 lore raw

Re: [PATCH RFC 12/15] libxc: support for arm64 Image format

I think all the code in this patch should in an ifdef __aarch64__.

Quoted 115 lines · Ian Campbell
---
 tools/libxc/xc_dom_armzimageloader.c |   88 ++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
tools/libxc/xc_dom_armzimageloader.c +88 -0
index 4e3f7ae..609d3a0 100644
@@ -129,6 +129,86 @@ static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
 }
 
 /* ------------------------------------------------------------ */
+/* 64-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE64_MAGIC_V0 0x14000008
+#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
+
+/* linux/Documentation/arm64/booting.txt */
+struct zimage64_hdr {
+    uint32_t magic0;
+    uint32_t res0;
+    uint64_t text_offset;  /* Image load offset */
+    uint64_t res1;
+    uint64_t res2;
+    /* zImage V1 only from here */
+    uint64_t res3;
+    uint64_t res4;
+    uint64_t res5;
+    uint32_t magic1;
+    uint32_t res6;
+};
+static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < sizeof(*zimage) )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage =  dom->kernel_blob;
+    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
+         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+    uint32_t entry_addr;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = dom->kernel_blob;
+
+    v_start = rambase + zimage->text_offset;
+    v_end = v_start + dom->kernel_size;
+
+    entry_addr = v_start;
+
+    /* find kernel segment */
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_start + dom->kernel_size;
+
+    dom->parms.virt_entry = entry_addr;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-aarch64";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
 /* Common zImage Support                                        */
 /* ------------------------------------------------------------ */
 
@@ -163,9 +243,17 @@ static struct xc_dom_loader zimage32_loader = {
     .loader = xc_dom_load_zimage_kernel,
 };
 
+static struct xc_dom_loader zimage64_loader = {
+    .name = "Linux zImage (ARM64)",
+    .probe = xc_dom_probe_zimage64_kernel,
+    .parser = xc_dom_parse_zimage64_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
 static void __init register_loader(void)
 {
     xc_dom_register_loader(&zimage32_loader);
+    xc_dom_register_loader(&zimage64_loader);
 }
 
 /*
Signature · 1 line
Julien Grall
#24 lore raw

Re: [PATCH RFC 12/15] libxc: support for arm64 Image format

Quoted 1 line · Julien Grall

I think all the code in this patch should in an ifdef __aarch64__.

Oops, yes. I did say I hadn't tried it on 32 bit ;-)

Quoted 119 lines · Ian Campbell
Quoted 115 lines
---
 tools/libxc/xc_dom_armzimageloader.c |   88 ++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
tools/libxc/xc_dom_armzimageloader.c +88 -0
index 4e3f7ae..609d3a0 100644
@@ -129,6 +129,86 @@ static int xc_dom_parse_zimage32_kernel(struct xc_dom_image *dom)
 }
 
 /* ------------------------------------------------------------ */
+/* 64-bit zImage Support                                        */
+/* ------------------------------------------------------------ */
+
+#define ZIMAGE64_MAGIC_V0 0x14000008
+#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */
+
+/* linux/Documentation/arm64/booting.txt */
+struct zimage64_hdr {
+    uint32_t magic0;
+    uint32_t res0;
+    uint64_t text_offset;  /* Image load offset */
+    uint64_t res1;
+    uint64_t res2;
+    /* zImage V1 only from here */
+    uint64_t res3;
+    uint64_t res4;
+    uint64_t res5;
+    uint32_t magic1;
+    uint32_t res6;
+};
+static int xc_dom_probe_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+
+    if ( dom->kernel_blob == NULL )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    if ( dom->kernel_size < sizeof(*zimage) )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel image too small", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    zimage =  dom->kernel_blob;
+    if ( zimage->magic0 != ZIMAGE64_MAGIC_V0 &&
+         zimage->magic1 != ZIMAGE64_MAGIC_V1 )
+    {
+        xc_dom_printf(dom->xch, "%s: kernel is not an arm64 Image", __FUNCTION__);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int xc_dom_parse_zimage64_kernel(struct xc_dom_image *dom)
+{
+    struct zimage64_hdr *zimage;
+    uint32_t entry_addr;
+    uint64_t v_start, v_end;
+    uint64_t rambase = dom->rambase_pfn << XC_PAGE_SHIFT;
+
+    DOMPRINTF_CALLED(dom->xch);
+
+    zimage = dom->kernel_blob;
+
+    v_start = rambase + zimage->text_offset;
+    v_end = v_start + dom->kernel_size;
+
+    entry_addr = v_start;
+
+    /* find kernel segment */
+    dom->kernel_seg.vstart = v_start;
+    dom->kernel_seg.vend   = v_start + dom->kernel_size;
+
+    dom->parms.virt_entry = entry_addr;
+    dom->parms.virt_base = rambase;
+
+    dom->guest_type = "xen-3.0-aarch64";
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------ */
 /* Common zImage Support                                        */
 /* ------------------------------------------------------------ */
 
@@ -163,9 +243,17 @@ static struct xc_dom_loader zimage32_loader = {
     .loader = xc_dom_load_zimage_kernel,
 };
 
+static struct xc_dom_loader zimage64_loader = {
+    .name = "Linux zImage (ARM64)",
+    .probe = xc_dom_probe_zimage64_kernel,
+    .parser = xc_dom_parse_zimage64_kernel,
+    .loader = xc_dom_load_zimage_kernel,
+};
+
 static void __init register_loader(void)
 {
     xc_dom_register_loader(&zimage32_loader);
+    xc_dom_register_loader(&zimage64_loader);
 }
 
 /*
#25 lore raw

Re: [PATCH RFC 12/15] libxc: support for arm64 Image format

Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall

I think all the code in this patch should in an ifdef __aarch64__.

Oops, yes. I did say I hadn't tried it on 32 bit ;-)

Upon second thought -- it is reasonable to want to build a 64-bit guest while running a 32-bit dom0 on a 64-bit Xen.

I think this should work, although I've not tried it.

Ian.

#26 lore raw

Re: [PATCH RFC 12/15] libxc: support for arm64 Image format

Quoted 8 lines · Ian Campbell
Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall

I think all the code in this patch should in an ifdef __aarch64__.

Oops, yes. I did say I hadn't tried it on 32 bit ;-)

Upon second thought -- it is reasonable to want to build a 64-bit guest while running a 32-bit dom0 on a 64-bit Xen.

Right, I forget that it's possible to boot 32 kernel, so 32 bit userspace, on ARM64.

Quoted 1 line

I think this should work, although I've not tried it.

There is a bunch of #ifdef __aarch64__ in the public interface. To support dom0 32 bit, we will need to remove theses #ifdef.

Signature · 1 line
Julien Grall
#27 lore raw

RFC PATCH 13/15 libxc: arm64 vcpu initialisation

In reply to Ian Campbell
---
 tools/libxc/xc_dom_arm.c |   90 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 88 insertions(+), 2 deletions(-)
tools/libxc/xc_dom_arm.c +88 -2
index ecdaea9..a6d2259 100644
@@ -105,7 +105,7 @@ static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
 
 /* ------------------------------------------------------------------------ */
 
-static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
+static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
 {
     vcpu_guest_context_t *ctxt = ptr;
 
@@ -143,6 +143,41 @@ static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
     return 0;
 }
 
+static int vcpu_arm64(struct xc_dom_image *dom, void *ptr)
+{
+    vcpu_guest_context_t *ctxt = ptr;
+
+    DOMPRINTF_CALLED(dom->xch);
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc64 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
+    ctxt->user_regs.x0 = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+    ctxt->user_regs.x1 = 0;
+    ctxt->user_regs.x2 = 0;
+    ctxt->user_regs.x3 = 0;
+
+    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
+
+    ctxt->sctlr = /* #define SCTLR_BASE */0x00c50078;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h;
+
+    ctxt->flags = VGCF_online;
+
+    DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
+           ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
+
+    return 0;
+}
+
 /* ------------------------------------------------------------------------ */
 
 static struct xc_dom_arch xc_dom_32 = {
@@ -155,12 +190,59 @@ static struct xc_dom_arch xc_dom_32 = {
     .setup_pgtables = setup_pgtables_arm,
     .start_info = start_info_arm,
     .shared_info = shared_info_arm,
-    .vcpu = vcpu_arm,
+    .vcpu = vcpu_arm32,
+};
+
+static struct xc_dom_arch xc_dom_64 = {
+    .guest_type = "xen-3.0-aarch64",
+    .native_protocol = XEN_IO_PROTO_ABI_ARM,
+    .page_shift = PAGE_SHIFT_ARM,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,
+    .count_pgtables = count_pgtables_arm,
+    .setup_pgtables = setup_pgtables_arm,
+    .start_info = start_info_arm,
+    .shared_info = shared_info_arm,
+    .vcpu = vcpu_arm64,
 };
 
 static void __init register_arch_hooks(void)
 {
     xc_dom_register_arch_hooks(&xc_dom_32);
+    xc_dom_register_arch_hooks(&xc_dom_64);
+}
+
+static int set_mode(xc_interface *xch, domid_t domid, char *guest_type)
+{
+    static const struct {
+        char           *guest;
+        uint32_t        size;
+    } types[] = {
+        { "xen-3.0-aarch64", 64 },
+        { "xen-3.0-armv7l",  32 },
+    };
+    DECLARE_DOMCTL;
+    int i,rc;
+
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_set_address_size;
+    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
+        if ( !strcmp(types[i].guest, guest_type) )
+            domctl.u.address_size.size = types[i].size;
+    if ( domctl.u.address_size.size == 0 )
+    {
+        xc_dom_printf(xch, "%s: warning: unknown guest type %s",
+                      __FUNCTION__, guest_type);
+        return -EINVAL;
+    }
+
+    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
+                  guest_type, domctl.u.address_size.size);
+    rc = do_domctl(xch, &domctl);
+    if ( rc != 0 )
+        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
+                      __FUNCTION__, rc);
+    return rc;
 }
 
 int arch_setup_meminit(struct xc_dom_image *dom)
@@ -168,6 +250,10 @@ int arch_setup_meminit(struct xc_dom_image *dom)
     int rc;
     xen_pfn_t pfn, allocsz, i;
 
+    rc = set_mode(dom->xch, dom->guest_domid, dom->guest_type);
+    if ( rc )
+        return rc;
+
     dom->shadow_enabled = 1;
 
     dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
Signature · 1 line
1.7.10.4
#28 lore raw

Re: [PATCH RFC 13/15] libxc: arm64 vcpu initialisation

Quoted 38 lines · Ian Campbell
---
 tools/libxc/xc_dom_arm.c |   90 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 88 insertions(+), 2 deletions(-)
tools/libxc/xc_dom_arm.c +17 -1
index ecdaea9..a6d2259 100644
@@ -105,7 +105,7 @@ static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
 
 /* ------------------------------------------------------------------------ */
 
-static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
+static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
 {
     vcpu_guest_context_t *ctxt = ptr;
 
@@ -143,6 +143,41 @@ static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
     return 0;
 }
 
+static int vcpu_arm64(struct xc_dom_image *dom, void *ptr)
+{
+    vcpu_guest_context_t *ctxt = ptr;
+
+    DOMPRINTF_CALLED(dom->xch);
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc64 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
+    ctxt->user_regs.x0 = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+    ctxt->user_regs.x1 = 0;
+    ctxt->user_regs.x2 = 0;
+    ctxt->user_regs.x3 = 0;

tools/libxc/xc_dom_arm.c static int vcpu_arm(struct xc_dom_image *dom, void *ptr) · line 171

Quoted 10 lines
tools/libxc/xc_dom_arm.c +10 -0
+
+    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
+
+    ctxt->sctlr = /* #define SCTLR_BASE */0x00c50078;
+
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h;

PSR_MODE_EL1h is only defined on arm64. I think you will need to prefix all the code by #ifdef __aarch64__

BTW, can you use PSR_GUEST64_INIT here? So if we modified it in Xen, the behaviour will also change here.

Signature · 1 line
Julien Grall
#29 lore raw

Re: [PATCH RFC 13/15] libxc: arm64 vcpu initialisation

Quoted 44 lines · Julien Grall
Quoted 43 lines · Ian Campbell
---
 tools/libxc/xc_dom_arm.c |   90 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 88 insertions(+), 2 deletions(-)
tools/libxc/xc_dom_arm.c +22 -1
index ecdaea9..a6d2259 100644
@@ -105,7 +105,7 @@ static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
 
 /* ------------------------------------------------------------------------ */
 
-static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
+static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
 {
     vcpu_guest_context_t *ctxt = ptr;
 
@@ -143,6 +143,41 @@ static int vcpu_arm(struct xc_dom_image *dom, void *ptr)
     return 0;
 }
 
+static int vcpu_arm64(struct xc_dom_image *dom, void *ptr)
+{
+    vcpu_guest_context_t *ctxt = ptr;
+
+    DOMPRINTF_CALLED(dom->xch);
+    /* clear everything */
+    memset(ctxt, 0, sizeof(*ctxt));
+
+    ctxt->user_regs.pc64 = dom->parms.virt_entry;
+
+    /* Linux boot protocol. See linux.Documentation/arm/Booting. */
+    ctxt->user_regs.x0 = dom->devicetree_blob ?
+        dom->devicetree_seg.vstart : 0xffffffff;
+    ctxt->user_regs.x1 = 0;
+    ctxt->user_regs.x2 = 0;
+    ctxt->user_regs.x3 = 0;
+
+    DOMPRINTF("DTB %"PRIx64, ctxt->user_regs.x0);
+
+    ctxt->sctlr = /* #define SCTLR_BASE */0x00c50078;
+
Quoted 8 lines

tools/libxc/xc_dom_arm.c static int vcpu_arm(struct xc_dom_image *dom, void *ptr) · line 171

Quoted 5 lines
tools/libxc/xc_dom_arm.c +5 -0
+    ctxt->ttbr0 = 0;
+    ctxt->ttbr1 = 0;
+    ctxt->ttbcr = 0; /* Defined Reset Value */
+
+    ctxt->user_regs.cpsr = PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h;

PSR_MODE_EL1h is only defined on arm64. I think you will need to prefix all the code by #ifdef __aarch64__

Correct.

Quoted 2 lines

BTW, can you use PSR_GUEST64_INIT here? So if we modified it in Xen, the behaviour will also change here.

It's a bit annoying, but PSR_GUEST*_INIT are no in the public interfaces and libxc can't include anything else. I don't want to expose this to guests incase it becomes ABI...

Oh, maybe I can just us #if on __XEN_TOOLS__ and/or __XEN__ as appropaite.

I'll have a play with that.

#30 lore raw

Re: [PATCH RFC 13/15] libxc: arm64 vcpu initialisation

Quoted 6 lines · Ian Campbell
Quoted 2 lines

BTW, can you use PSR_GUEST64_INIT here? So if we modified it in Xen, the behaviour will also change here.

It's a bit annoying, but PSR_GUEST*_INIT are no in the public interfaces and libxc can't include anything else. I don't want to expose this to guests incase it becomes ABI...

Until the commit bcac10f "xen: arm: support building a 64-bit dom0 domain", PSR_GUEST*_INIT was in the public interface. I'm not sure why you have removed from the interface.

Quoted 2 lines

Oh, maybe I can just us #if on __XEN_TOOLS__ and/or __XEN__ as appropaite.

Guest doesn't need that, but tools should have the same PSR as Linux. Why boot VCPU initialization can't be done in Xen?

Signature · 1 line
Julien Grall
#31 lore raw

Re: [PATCH RFC 13/15] libxc: arm64 vcpu initialisation

Quoted 11 lines · Julien Grall
Quoted 6 lines · Ian Campbell
Quoted 2 lines

BTW, can you use PSR_GUEST64_INIT here? So if we modified it in Xen, the behaviour will also change here.

It's a bit annoying, but PSR_GUEST*_INIT are no in the public interfaces and libxc can't include anything else. I don't want to expose this to guests incase it becomes ABI...

Until the commit bcac10f "xen: arm: support building a 64-bit dom0 domain", PSR_GUEST*_INIT was in the public interface. I'm not sure why you have removed from the interface.

It's an implementation detail which the guest shouldn't rely upon.

Quoted 4 lines
Quoted 2 lines

Oh, maybe I can just us #if on __XEN_TOOLS__ and/or __XEN__ as appropaite.

Guest doesn't need that, but tools should have the same PSR as Linux.

"the same PSR as Linux" -- did you mean Xen?

Quoted 1 line

Why boot VCPU initialization can't be done in Xen?

The domain builder is the one which knows what is going on, what the layout is etc, it's appropriate for it to also control the initial state of the vcpus.

Ian.

#32 lore raw

Re: [PATCH RFC 13/15] libxc: arm64 vcpu initialisation

Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall

Guest doesn't need that, but tools should have the same PSR as Linux.

"the same PSR as Linux" -- did you mean Xen?

Yes

Signature · 1 line
Julien Grall
#33 lore raw

RFC PATCH 14/15 libxl: build a device tree for ARM guests

In reply to Ian Campbell

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be carefully sequenced to be after xc_dom_parse_image (so we can tell which kind of guest we are building, although we don't use this yet) and before xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this change. Remove IA64 as part of this patch.

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

TODO:
- Hardcoded armv8 bits need abstracting. Perhaps e.g. read CPU compatiblity node from sysfs?
- Try it with armv7
- Debug hook should be #ifdef DEBUG?
- Various values (e.g. GIC base addresses, evtchn PPI) should be passed down to the hypervisor by some mechanism I've not decided on yet. Perhaps domctl but maybe better would be via the HVM save format to more easily support migration of the settings?
- TODOs and //comments in the code

---
 tools/libxl/Makefile       |    6 +-
 tools/libxl/libxl_arch.h   |    4 +
 tools/libxl/libxl_arm.c    |  523 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_dom.c    |    4 +
 tools/libxl/libxl_noarch.c |    8 -
 tools/libxl/libxl_x86.c    |    7 +
 6 files changed, 542 insertions(+), 10 deletions(-)
 create mode 100644 tools/libxl/libxl_arm.c
 delete mode 100644 tools/libxl/libxl_noarch.c
tools/libxl/Makefile +4 -2
index cf214bb..d8495bb 100644
@@ -28,9 +28,12 @@ CFLAGS_LIBXL += $(CFLAGS_libxenstore)
 CFLAGS_LIBXL += $(CFLAGS_libblktapctl) 
 CFLAGS_LIBXL += -Wshadow
 
+LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
+
 CFLAGS += $(PTHREAD_CFLAGS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 LIBXL_LIBS += $(PTHREAD_LIBS)
+LIBXL_LIBS += $(LIBXL_LIBS-y)
 
 LIBXLU_LIBS =
 
@@ -41,8 +44,7 @@ else
 LIBXL_OBJS-y += libxl_noblktap2.o
 endif
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o
-LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o libxl_noarch.o
-LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_noarch.o
+LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
 
 ifeq ($(CONFIG_NetBSD),y)
 LIBXL_OBJS-y += libxl_netbsd.o
tools/libxl/libxl_arch.h +4 -0
index abe6685..3de2d76 100644
@@ -19,4 +19,8 @@
 int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
                uint32_t domid);
 
+/* */
+int libxl__arch_domain_configure(libxl__gc *gc,
+                                 libxl_domain_build_info *info,
+                                 struct xc_dom_image *dom);
 #endif
tools/libxl/libxl_arm.c new file +523 -0

523 lines not on this page · raw message

tools/libxl/libxl_dom.c +4 -0
index 631cdf5..78ba8f1 100644
@@ -394,6 +394,10 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
         LOGE(ERROR, "xc_dom_parse_image failed");
         goto out;
     }
+    if ( (ret = libxl__arch_domain_configure(gc, info, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_configure failed");
+        goto out;
+    }
     if ( (ret = xc_dom_mem_init(dom, info->target_memkb / 1024)) != 0 ) {
         LOGE(ERROR, "xc_dom_mem_init failed");
         goto out;
tools/libxl/libxl_noarch.c deleted +0 -8
deleted file mode 100644
index 7893535..0000000
@@ -1,8 +0,0 @@
-#include "libxl_internal.h"
-#include "libxl_arch.h"
-
-int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
-                              uint32_t domid)
-{
-    return 0;
-}
tools/libxl/libxl_x86.c +7 -0
index a78c91d..dd13c45 100644
@@ -308,3 +308,10 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
 
     return ret;
 }
+
+int libxl__arch_domain_configure(libxl__gc *gc,
+                                 libxl_domain_build_info *info,
+                                 struct xc_dom_image *dom)
+{
+    return 0;
+}
Signature · 1 line
1.7.10.4
#34 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 8 lines · Ian Campbell

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be carefully sequenced to be after xc_dom_parse_image (so we can tell which kind of guest we are building, although we don't use this yet) and before xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this change. Remove IA64 as part of this patch.

Quoted 7 lines

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

TODO:
- Hardcoded armv8 bits need abstracting. Perhaps e.g. read CPU compatiblity node from sysfs?

I'm wondering if it's usefull to have the property compatible. From Linux documentation:
So under /cpus, you are supposed to create a node for every CPU on
the machine. There is no specific restriction on the name of the
CPU, though it's common to call it <architecture>,<core>. For
example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX.
However, the Generic Names convention suggests that it would be
better to simply use 'cpu' for each cpu node and use the compatible property to identify the specific cpu core.

Linux doesn't seems to retrieve the compatible node and Freebsd also.
The only way to read this property is from /proc/device-tree. But this directory exists only if CONFIG_PROC_DEVICETREE=y.

Quoted 1 line

- Try it with armv7

The previous point will be the same for the timer and the GIC.

Quoted 6 lines

- Debug hook should be #ifdef DEBUG?
- Various values (e.g. GIC base addresses, evtchn PPI) should be passed down to the hypervisor by some mechanism I've not decided on yet. Perhaps domctl but maybe better would be via the HVM save format to more easily support migration of the settings?
- TODOs and //comments in the code

- Add initrd support?

Quoted 2 lines

[..]

Quoted 5 lines
tools/libxl/libxl_arm.c new file +0 -0
new file mode 100644
index 0000000..913741d

[..]

Quoted 4 lines
tools/libxl/libxl_arm.c new file +4 -0
+static int fdt_property_interrupts(libxl__gc *gc, void *fdt,
+                                   gic_interrupt_t *intr,
+                                   unsigned num_irq)
+{

tools/libxl/libxl_arm.c line 98

Quoted 10 lines
tools/libxl/libxl_arm.c new file +10 -0
+    int res;
+
+    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(fdt, "interrupt-parent", PHANDLE_GIC);
+
+    return res;
+}

You don't need this function if the interrupt-parent properties is set in the root node. Which is the case below in make_root_properties.

[..]

Quoted 28 lines
tools/libxl/libxl_arm.c new file +28 -0
+static int make_cpus_node(libxl__gc *gc, void *fdt, int nr_cpus)
+{
+    int res, i;
+
+    res = fdt_begin_node(fdt, "cpus");
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(fdt, "#address-cells", 1);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(fdt, "#size-cells", 0);
+    if ( res )
+        return res;
+
+    for (i = 0; i < nr_cpus; i++) {
+        char name[strlen("cpu@") + 2 + 1];
+
+        if ( snprintf(name, sizeof(name)-1, "cpu@%d", i) < 0 )
+        {
+            perror("snprintf");
+            exit(1);
+        }
+
+        res = fdt_begin_node(fdt, name);
+        if ( res )
+            return res;

tools/libxl/libxl_arm.c line 213

Quoted 10 lines
tools/libxl/libxl_arm.c new file +10 -0
+
+        res = fdt_property_string(fdt, "device_type", "cpu");
+        if ( res )
+            return res;
+
+        res = fdt_property_compat(gc, fdt, 1, "arm,armv8");
+        if ( res )
+            return res;
+
+        res = fdt_property_string(fdt, "enable-method", "psci");

#ifdef CONFIG_ARM64 and if it's a 64 bit domain?

Quoted 31 lines
tools/libxl/libxl_arm.c new file +31 -0
+        if ( res )
+            return res;
+
+        res = fdt_property_regs(gc, fdt, 1, 0, 1, (uint64_t)i);
+        if ( res )
+            return res;
+
+        res = fdt_end_node(fdt);
+        if ( res )
+            return res;
+
+    }
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}
+
+static int make_psci_node(libxl__gc *gc, void *fdt)
+{
+    int res;
+
+    res = fdt_begin_node(fdt, "psci");
+    if ( res )
+        return res;
+
+    res = fdt_property_compat(gc, fdt, 1, "arm,psci");
+    if ( res )
+        return res;
+
+    res = fdt_property_string(fdt, "method", "hvc");

tools/libxl/libxl_arm.c line 254

Quoted 10 lines
tools/libxl/libxl_arm.c new file +10 -0
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(fdt, "cpu_off", 0x1);
+    if ( res )
+        return res;
+
+    res = fdt_property_cell(fdt, "cpu_on", 0x2);
+    if ( res )
+        return res;

Can we export include/asm-arm/psci.h and reuse the value here?

Quoted 5 lines
tools/libxl/libxl_arm.c new file +5 -0
+
+    res = fdt_end_node(fdt);
+
+    return res;
+}

[..]

Quoted 14 lines
tools/libxl/libxl_arm.c new file +14 -0
+static int make_hypervisor_node(libxl__gc *gc, void *fdt,
+                                const libxl_version_info *vers)
+{
+    int res;
+    gic_interrupt_t intr;
+
+    /* See linux Documentation/devicetree/bindings/arm/xen.txt */
+    res = fdt_begin_node(fdt, "hypervisor");
+    if ( res )
+        return res;
+
+    res = fdt_property_compat(gc, fdt, 2,
+                              GCSPRINTF("xen,xen-%d.%d",
+                                        vers->xen_version_major,

tools/libxl/libxl_arm.c line 392

Quoted 10 lines
tools/libxl/libxl_arm.c new file +10 -0
+                                        vers->xen_version_minor),
+                              "xen,xen");
+    if ( res )
+        return res;
+
+    //DPRINT("  Grant table range: 0xb0000000-0x20000\n");
+    /* reg 0 is grant table space */
+    res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+                            1,
+                            (uint64_t)0xb0000000,

I still don't know where this value comes from... if it's a random value, can we autogenerate it?

Signature · 1 line
Julien Grall
#35 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 17 lines · Julien Grall
Quoted 8 lines · Ian Campbell

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be carefully sequenced to be after xc_dom_parse_image (so we can tell which kind of guest we are building, although we don't use this yet) and before xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this change. Remove IA64 as part of this patch.

Quoted 7 lines

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

TODO:
- Hardcoded armv8 bits need abstracting. Perhaps e.g. read CPU compatiblity node from sysfs?

Quoted 9 lines

I'm wondering if it's usefull to have the property compatible. From Linux documentation:
So under /cpus, you are supposed to create a node for every CPU on the machine. There is no specific restriction on the name of the CPU, though it's common to call it <architecture>,<core>. For example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX. However, the Generic Names convention suggests that it would be better to simply use 'cpu' for each cpu node and use the compatible property to identify the specific cpu core.

Hrm this seems to imply that either you should name the node <architecture>,<core> *or* you should call it cpu and have a compatibility property <architecture>,<core>.

Quoted 3 lines

Linux doesn't seems to retrieve the compatible node and Freebsd also. The only way to read this property is from /proc/device-tree. But this directory exists only if CONFIG_PROC_DEVICETREE=y.

Yes.

I suppose we could try /proc/device-tree and fall back to /proc/cpuinfo (which should at least get us v7 vs v8) and finally fallback to a hardcoded value based on the architecture the tools are compiled for (which is lame, but better than nothing?).

Or maybe we add a hypercall to get the underlying CPU compatibility node direct from Xen. It's the sort of thing I guess "xl info" ought to be able to display I suppose.

Quoted 3 lines
Quoted 1 line

- Try it with armv7

The previous point will be the same for the timer and the GIC.

Yes.

Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_arm.c new file +9 -0
+static int fdt_property_interrupts(libxl__gc *gc, void *fdt,
+                                   gic_interrupt_t *intr,
+                                   unsigned num_irq)
+{
+    int res;
+
+    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    if ( res )
+        return res;
Quoted 8 lines

tools/libxl/libxl_arm.c line 98

Quoted 5 lines
tools/libxl/libxl_arm.c new file +5 -0
+
+    res = fdt_property_cell(fdt, "interrupt-parent", PHANDLE_GIC);
+
+    return res;
+}

You don't need this function if the interrupt-parent properties is set in the root node. Which is the case below in make_root_properties.

OK. The reason we have this for dom0 is that we can't control whether the host DTB has interrupt-parent or not?

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+        res = fdt_property_string(fdt, "enable-method", "psci");

#ifdef CONFIG_ARM64 and if it's a 64 bit domain?

Yes.

Quoted 5 lines

tools/libxl/libxl_arm.c line 254

Quoted 3 lines
tools/libxl/libxl_arm.c new file +3 -0
+    res = fdt_property_cell(fdt, "cpu_on", 0x2);
+    if ( res )
+        return res;

Can we export include/asm-arm/psci.h and reuse the value here?

I suppose we ought to, since Xen is the one implementing the actual functionality. I notice that even Xen itself isn't using those #defines (nothing is AFAICT!)

Quoted 8 lines

tools/libxl/libxl_arm.c line 392

Quoted 5 lines
tools/libxl/libxl_arm.c new file +5 -0
+    //DPRINT("  Grant table range: 0xb0000000-0x20000\n");
+    /* reg 0 is grant table space */
+    res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+                            1,
+                            (uint64_t)0xb0000000,

I still don't know where this value comes from... if it's a random value, can we autogenerate it?

It's an arbitrary value which we picked when we defined our guest virtual platform. It's "random" in the same way as the address of the UART picked by an SoC designer is.

It should be a #define for sure though.

Hardcoding this for dom0 seems like a mistake though, we need a way to find a hole in the paddr space...

Ian.

#36 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 36 lines · Ian Campbell
Quoted 17 lines · Julien Grall
Quoted 8 lines · Ian Campbell

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be carefully sequenced to be after xc_dom_parse_image (so we can tell which kind of guest we are building, although we don't use this yet) and before xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this change. Remove IA64 as part of this patch.

Quoted 7 lines

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

TODO:
- Hardcoded armv8 bits need abstracting. Perhaps e.g. read CPU compatiblity node from sysfs?

Quoted 9 lines

I'm wondering if it's usefull to have the property compatible. From Linux documentation:
So under /cpus, you are supposed to create a node for every CPU on the machine. There is no specific restriction on the name of the CPU, though it's common to call it <architecture>,<core>. For example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX. However, the Generic Names convention suggests that it would be better to simply use 'cpu' for each cpu node and use the compatible property to identify the specific cpu core.

Hrm this seems to imply that either you should name the node <architecture>,<core> *or* you should call it cpu and have a compatibility property <architecture>,<core>.

Quoted 3 lines

Linux doesn't seems to retrieve the compatible node and Freebsd also. The only way to read this property is from /proc/device-tree. But this directory exists only if CONFIG_PROC_DEVICETREE=y.

Quoted 6 lines

Yes.

I suppose we could try /proc/device-tree and fall back to /proc/cpuinfo (which should at least get us v7 vs v8) and finally fallback to a hardcoded value based on the architecture the tools are compiled for (which is lame, but better than nothing?).

Reading the value from /proc/device-tree is a bit complicate. You need to parse each directory to find a CPU.

Quoted 24 lines
Quoted 3 lines
Quoted 1 line

- Try it with armv7

The previous point will be the same for the timer and the GIC.

Yes.

Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_arm.c new file +9 -0
+static int fdt_property_interrupts(libxl__gc *gc, void *fdt,
+                                   gic_interrupt_t *intr,
+                                   unsigned num_irq)
+{
+    int res;
+
+    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    if ( res )
+        return res;
Quoted 8 lines

tools/libxl/libxl_arm.c line 98

Quoted 5 lines
tools/libxl/libxl_arm.c new file +5 -0
+
+    res = fdt_property_cell(fdt, "interrupt-parent", PHANDLE_GIC);
+
+    return res;
+}

You don't need this function if the interrupt-parent properties is set in the root node. Which is the case below in make_root_properties.

Quoted 2 lines

OK. The reason we have this for dom0 is that we can't control whether the host DTB has interrupt-parent or not?

Right. Some device tree have a simple-bus where all nodes live and also the interrupt-property

/ {

smb {
compatible = "simple,bus"
interrupt-parent = &gic
...
}
}

During dom0 DT creation, Xen will add the node in / which may not have the right property.

Quoted 9 lines
Quoted 5 lines

tools/libxl/libxl_arm.c line 254

Quoted 3 lines
tools/libxl/libxl_arm.c new file +3 -0
+    res = fdt_property_cell(fdt, "cpu_on", 0x2);
+    if ( res )
+        return res;

Can we export include/asm-arm/psci.h and reuse the value here?

I suppose we ought to, since Xen is the one implementing the actual functionality. I notice that even Xen itself isn't using those #defines (nothing is AFAICT!)

It's used in traps.c via in the macro PSCI and in domain_build.c when the PSCI node is creating.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
tools/libxl/libxl_arm.c new file +5 -0
+    //DPRINT("  Grant table range: 0xb0000000-0x20000\n");
+    /* reg 0 is grant table space */
+    res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+                            1,
+                            (uint64_t)0xb0000000,
Quoted 8 lines
Quoted 2 lines

I still don't know where this value comes from... if it's a random value, can we autogenerate it?

It's an arbitrary value which we picked when we defined our guest virtual platform. It's "random" in the same way as the address of the UART picked by an SoC designer is.

It should be a #define for sure though.

If you choose to hardcode this address, can you add a TODO? So we won't forget later.

Signature · 1 line
Julien Grall
#37 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 4 lines · Julien Grall
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
tools/libxl/libxl_arm.c new file +3 -0
+    res = fdt_property_cell(fdt, "cpu_on", 0x2);
+    if ( res )
+        return res;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Can we export include/asm-arm/psci.h and reuse the value here?

I suppose we ought to, since Xen is the one implementing the actual functionality. I notice that even Xen itself isn't using those #defines (nothing is AFAICT!)

It's used in traps.c via in the macro PSCI and in domain_build.c when the PSCI node is creating.

Ah, macros ;-) Also I was grepping for __PSCI_cpu_suspend which isn't used...

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

tools/libxl/libxl_arm.c line 392

Quoted 6 lines
tools/libxl/libxl_arm.c new file +5 -0
+    //DPRINT("  Grant table range: 0xb0000000-0x20000\n");
+    /* reg 0 is grant table space */
+    res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+                            1,
+                            (uint64_t)0xb0000000,

I still don't know where this value comes from... if it's a random value, can we autogenerate it?

Quoted 8 lines
Quoted 5 lines

It's an arbitrary value which we picked when we defined our guest virtual platform. It's "random" in the same way as the address of the UART picked by an SoC designer is.

It should be a #define for sure though.

If you choose to hardcode this address, can you add a TODO? So we won't forget later.

Unless you have a use case for making this value changeable there is nothing wrong with us picking a number and using it, I don't think there is any TODO here.

Ian.

#38 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 4 lines · Ian Campbell

Unless you have a use case for making this value changeable there is nothing wrong with us picking a number and using it, I don't think there is any TODO here.

What about a large memory RAM for the domain? With this solution the only space available is between 0x80000000 (base ram address) and 0xb0000000 (base grant table). So we are limiting the domain to 768MB of RAM.

I think this limitation should be at least documented somewhere.

Signature · 1 line
Julien Grall
#39 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell

Unless you have a use case for making this value changeable there is nothing wrong with us picking a number and using it, I don't think there is any TODO here.

What about a large memory RAM for the domain? With this solution the only space available is between 0x80000000 (base ram address) and 0xb0000000 (base grant table). So we are limiting the domain to 768MB of RAM.

We can either move the grant table to a different hardcoded address to avoid any clash or use multiple memory banks.

Quoted 1 line

I think this limitation should be at least documented somewhere.

In general the virtual platform could do with being written down more clearly..

#40 lore raw

Re: [PATCH RFC 14/15] libxl: build a device tree for ARM guests

In reply to Ian Campbell
Quoted 25 lines · Ian Campbell

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be carefully sequenced to be after xc_dom_parse_image (so we can tell which kind of guest we are building, although we don't use this yet) and before xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this change. Remove IA64 as part of this patch.

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

TODO:
- Hardcoded armv8 bits need abstracting. Perhaps e.g. read CPU compatiblity node from sysfs?
- Try it with armv7
- Debug hook should be #ifdef DEBUG?
- Various values (e.g. GIC base addresses, evtchn PPI) should be passed down to the hypervisor by some mechanism I've not decided on yet. Perhaps domctl but maybe better would be via the HVM save format to more easily support migration of the settings?
- TODOs and //comments in the code

---

[..]

Quoted 4 lines
tools/libxl/libxl_arm.c new file +4 -0
+int libxl__arch_domain_configure(libxl__gc *gc,
+                                 libxl_domain_build_info *info,
+                                 struct xc_dom_image *dom)
+{

[..]

Quoted 1 line

+ res = make_memory_node(gc, fdt, 0x80000000UL, 0x8000000UL);

dom->rambase_pfn << PAGE_SHIFT.
and the size should not be hardcoded.

Signature · 1 line
Julien Grall
#41 lore raw

RFC PATCH 15/15 libxl: remove spurious newline from LOG() message

In reply to Ian Campbell

The macro already includes this.

---
 tools/libxl/libxl_dom.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_dom.c +1 -1
index 78ba8f1..25bb182 100644
@@ -342,7 +342,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
         return ERROR_FAIL;
     }
 
-    LOG(DEBUG, "pv kernel mapped %d path %s\n", state->pv_kernel.mapped, state->pv_kernel.path);
+    LOG(DEBUG, "pv kernel mapped %d path %s", state->pv_kernel.mapped, state->pv_kernel.path);
     if (state->pv_kernel.mapped) {
         ret = xc_dom_kernel_mem(dom,
                                 state->pv_kernel.data,
Signature · 1 line
1.7.10.4