- * [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code
  2013-01-14 17:03 [PATCH 0/4] xen/arm: compile and run xl Stefano Stabellini
@ 2013-01-14 17:04 ` Stefano Stabellini
  2013-01-14 18:22   ` Keir Fraser
  2013-01-15 10:13   ` Ian Campbell
  2013-01-14 17:04 ` [PATCH 2/4] xen/arm: implement gnttab_create_shared_page and gnttab_shared_gmfn Stefano Stabellini
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-14 17:04 UTC (permalink / raw)
  To: xen-devel; +Cc: tim, Ian.Campbell, Stefano Stabellini
Move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and
XEN_SYSCTL_topologyinfo from x86/sysctl.c to common/sysctl.c.
The implementation of XEN_SYSCTL_physinfo is mostly generic but needs to
fill in few arch specific details: introduce arch_do_physinfo to do that.
The implementation of XEN_SYSCTL_physinfo relies on two global
variables: total_pages and cpu_khz. Make them available on ARM.
Allow xsm_physinfo on ARM.
Implement node_spanned_pages and __node_distance on ARM, assuming 1 numa
node for now.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 xen/arch/arm/mm.c        |    1 +
 xen/arch/arm/setup.c     |    2 +-
 xen/arch/arm/sysctl.c    |    2 +
 xen/arch/arm/time.c      |   10 ++--
 xen/arch/x86/sysctl.c    |  134 +++------------------------------------------
 xen/common/sysctl.c      |  121 +++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/mm.h |    3 +
 xen/include/xen/sched.h  |    2 +
 xen/include/xsm/xsm.h    |   12 ++--
 9 files changed, 150 insertions(+), 137 deletions(-)
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index ca66395..fbb6da7 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -57,6 +57,7 @@ unsigned long frametable_base_mfn __read_mostly;
 unsigned long frametable_virt_end __read_mostly;
 
 unsigned long max_page;
+unsigned long total_pages;
 
 extern char __init_begin[], __init_end[];
 
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 89ef3df..a3a830a 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -119,7 +119,7 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size)
     ram_start = early_info.mem.bank[0].start;
     ram_size  = early_info.mem.bank[0].size;
     ram_end = ram_start + ram_size;
-    ram_pages = ram_size >> PAGE_SHIFT;
+    total_pages = ram_pages = ram_size >> PAGE_SHIFT;
 
     /*
      * Calculate the sizes for the heaps using these constraints:
diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c
index a286abe..a5d9cf0 100644
--- a/xen/arch/arm/sysctl.c
+++ b/xen/arch/arm/sysctl.c
@@ -12,6 +12,8 @@
 #include <xen/errno.h>
 #include <public/sysctl.h>
 
+void arch_do_physinfo(xen_sysctl_physinfo_t *pi) { }
+
 long arch_do_sysctl(struct xen_sysctl *sysctl,
                     XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index 9515b42..bcd7769 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -41,16 +41,16 @@ uint64_t __read_mostly boot_count;
 
 /* For fine-grained timekeeping, we use the ARM "Generic Timer", a
  * register-mapped time source in the SoC. */
-static uint32_t __read_mostly cntfrq;      /* Ticks per second */
+unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
 
 /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
 {
-    return muldiv64(ticks, SECONDS(1), cntfrq);
+    return muldiv64(ticks, SECONDS(1), cpu_khz);
 }
 
 /*static inline*/ uint64_t ns_to_ticks(s_time_t ns)
 {
-    return muldiv64(ns, cntfrq, SECONDS(1));
+    return muldiv64(ns, cpu_khz, SECONDS(1));
 }
 
 /* TODO: On a real system the firmware would have set the frequency in
@@ -91,9 +91,9 @@ int __init init_xen_time(void)
     if ( (READ_CP32(ID_PFR1) & ID_PFR1_GT_MASK) != ID_PFR1_GT_v1 )
         panic("CPU does not support the Generic Timer v1 interface.\n");
 
-    cntfrq = READ_CP32(CNTFRQ);
+    cpu_khz = READ_CP32(CNTFRQ);
     boot_count = READ_CP64(CNTPCT);
-    printk("Using generic timer at %"PRIu32" Hz\n", cntfrq);
+    printk("Using generic timer at %lu Hz\n", cpu_khz);
 
     return 0;
 }
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index b84dd34..e6de997 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -57,6 +57,15 @@ long cpu_down_helper(void *data)
     return ret;
 }
 
+void arch_do_physinfo(xen_sysctl_physinfo_t *pi)
+{
+    memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
+    if ( hvm_enabled )
+        pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm;
+    if ( iommu_enabled )
+        pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio;
+}
+
 long arch_do_sysctl(
     struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
@@ -64,132 +73,7 @@ long arch_do_sysctl(
 
     switch ( sysctl->cmd )
     {
-
-    case XEN_SYSCTL_physinfo:
-    {
-        xen_sysctl_physinfo_t *pi = &sysctl->u.physinfo;
-
-        ret = xsm_physinfo();
-        if ( ret )
-            break;
-
-
-        memset(pi, 0, sizeof(*pi));
-        pi->threads_per_core =
-            cpumask_weight(per_cpu(cpu_sibling_mask, 0));
-        pi->cores_per_socket =
-            cpumask_weight(per_cpu(cpu_core_mask, 0)) / pi->threads_per_core;
-        pi->nr_cpus = num_online_cpus();
-        pi->nr_nodes = num_online_nodes();
-        pi->max_node_id = MAX_NUMNODES-1;
-        pi->max_cpu_id = nr_cpu_ids - 1;
-        pi->total_pages = total_pages;
-        pi->free_pages = avail_domheap_pages();
-        pi->scrub_pages = 0;
-        pi->cpu_khz = cpu_khz;
-        memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
-        if ( hvm_enabled )
-            pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm;
-        if ( iommu_enabled )
-            pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio;
-
-        if ( copy_to_guest(u_sysctl, sysctl, 1) )
-            ret = -EFAULT;
-    }
-    break;
         
-    case XEN_SYSCTL_topologyinfo:
-    {
-        uint32_t i, max_cpu_index, last_online_cpu;
-        xen_sysctl_topologyinfo_t *ti = &sysctl->u.topologyinfo;
-
-        ret = xsm_physinfo();
-        if ( ret )
-            break;
-
-        last_online_cpu = cpumask_last(&cpu_online_map);
-        max_cpu_index = min_t(uint32_t, ti->max_cpu_index, last_online_cpu);
-        ti->max_cpu_index = last_online_cpu;
-
-        for ( i = 0; i <= max_cpu_index; i++ )
-        {
-            if ( !guest_handle_is_null(ti->cpu_to_core) )
-            {
-                uint32_t core = cpu_online(i) ? cpu_to_core(i) : ~0u;
-                if ( copy_to_guest_offset(ti->cpu_to_core, i, &core, 1) )
-                    break;
-            }
-            if ( !guest_handle_is_null(ti->cpu_to_socket) )
-            {
-                uint32_t socket = cpu_online(i) ? cpu_to_socket(i) : ~0u;
-                if ( copy_to_guest_offset(ti->cpu_to_socket, i, &socket, 1) )
-                    break;
-            }
-            if ( !guest_handle_is_null(ti->cpu_to_node) )
-            {
-                uint32_t node = cpu_online(i) ? cpu_to_node(i) : ~0u;
-                if ( copy_to_guest_offset(ti->cpu_to_node, i, &node, 1) )
-                    break;
-            }
-        }
-
-        ret = ((i <= max_cpu_index) || copy_to_guest(u_sysctl, sysctl, 1))
-            ? -EFAULT : 0;
-    }
-    break;
-
-    case XEN_SYSCTL_numainfo:
-    {
-        uint32_t i, j, max_node_index, last_online_node;
-        xen_sysctl_numainfo_t *ni = &sysctl->u.numainfo;
-
-        ret = xsm_physinfo();
-        if ( ret )
-            break;
-
-        last_online_node = last_node(node_online_map);
-        max_node_index = min_t(uint32_t, ni->max_node_index, last_online_node);
-        ni->max_node_index = last_online_node;
-
-        for ( i = 0; i <= max_node_index; i++ )
-        {
-            if ( !guest_handle_is_null(ni->node_to_memsize) )
-            {
-                uint64_t memsize = node_online(i) ? 
-                                   node_spanned_pages(i) << PAGE_SHIFT : 0ul;
-                if ( copy_to_guest_offset(ni->node_to_memsize, i, &memsize, 1) )
-                    break;
-            }
-            if ( !guest_handle_is_null(ni->node_to_memfree) )
-            {
-                uint64_t memfree = node_online(i) ? 
-                                   avail_node_heap_pages(i) << PAGE_SHIFT : 0ul;
-                if ( copy_to_guest_offset(ni->node_to_memfree, i, &memfree, 1) )
-                    break;
-            }
-
-            if ( !guest_handle_is_null(ni->node_to_node_distance) )
-            {
-                for ( j = 0; j <= max_node_index; j++)
-                {
-                    uint32_t distance = ~0u;
-                    if ( node_online(i) && node_online(j) )
-                        distance = __node_distance(i, j);
-                    if ( copy_to_guest_offset(
-                        ni->node_to_node_distance, 
-                        i*(max_node_index+1) + j, &distance, 1) )
-                        break;
-                }
-                if ( j <= max_node_index )
-                    break;
-            }
-        }
-
-        ret = ((i <= max_node_index) || copy_to_guest(u_sysctl, sysctl, 1))
-            ? -EFAULT : 0;
-    }
-    break;
-    
     case XEN_SYSCTL_cpu_hotplug:
     {
         unsigned int cpu = sysctl->u.cpu_hotplug.cpu;
diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c
index 47142f4..7a9f5e8 100644
--- a/xen/common/sysctl.c
+++ b/xen/common/sysctl.c
@@ -344,6 +344,127 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
+    case XEN_SYSCTL_physinfo:
+    {
+        xen_sysctl_physinfo_t *pi = &op->u.physinfo;
+
+        ret = xsm_physinfo();
+        if ( ret )
+            break;
+
+        memset(pi, 0, sizeof(*pi));
+        pi->threads_per_core =
+            cpumask_weight(per_cpu(cpu_sibling_mask, 0));
+        pi->cores_per_socket =
+            cpumask_weight(per_cpu(cpu_core_mask, 0)) / pi->threads_per_core;
+        pi->nr_cpus = num_online_cpus();
+        pi->nr_nodes = num_online_nodes();
+        pi->max_node_id = MAX_NUMNODES-1;
+        pi->max_cpu_id = nr_cpu_ids - 1;
+        pi->total_pages = total_pages;
+        pi->free_pages = avail_domheap_pages();
+        pi->scrub_pages = 0;
+        pi->cpu_khz = cpu_khz;
+        arch_do_physinfo(pi);
+
+        if ( copy_to_guest(u_sysctl, op, 1) )
+            ret = -EFAULT;
+    }
+    break;
+
+    case XEN_SYSCTL_numainfo:
+    {
+        uint32_t i, j, max_node_index, last_online_node;
+        xen_sysctl_numainfo_t *ni = &op->u.numainfo;
+
+        ret = xsm_physinfo();
+        if ( ret )
+            break;
+
+        last_online_node = last_node(node_online_map);
+        max_node_index = min_t(uint32_t, ni->max_node_index, last_online_node);
+        ni->max_node_index = last_online_node;
+
+        for ( i = 0; i <= max_node_index; i++ )
+        {
+            if ( !guest_handle_is_null(ni->node_to_memsize) )
+            {
+                uint64_t memsize = node_online(i) ? 
+                                   node_spanned_pages(i) << PAGE_SHIFT : 0ul;
+                if ( copy_to_guest_offset(ni->node_to_memsize, i, &memsize, 1) )
+                    break;
+            }
+            if ( !guest_handle_is_null(ni->node_to_memfree) )
+            {
+                uint64_t memfree = node_online(i) ? 
+                                   avail_node_heap_pages(i) << PAGE_SHIFT : 0ul;
+                if ( copy_to_guest_offset(ni->node_to_memfree, i, &memfree, 1) )
+                    break;
+            }
+
+            if ( !guest_handle_is_null(ni->node_to_node_distance) )
+            {
+                for ( j = 0; j <= max_node_index; j++)
+                {
+                    uint32_t distance = ~0u;
+                    if ( node_online(i) && node_online(j) )
+                        distance = __node_distance(i, j);
+                    if ( copy_to_guest_offset(
+                        ni->node_to_node_distance, 
+                        i*(max_node_index+1) + j, &distance, 1) )
+                        break;
+                }
+                if ( j <= max_node_index )
+                    break;
+            }
+        }
+
+        ret = ((i <= max_node_index) || copy_to_guest(u_sysctl, op, 1))
+            ? -EFAULT : 0;
+    }
+    break;
+
+    case XEN_SYSCTL_topologyinfo:
+    {
+        uint32_t i, max_cpu_index, last_online_cpu;
+        xen_sysctl_topologyinfo_t *ti = &op->u.topologyinfo;
+
+        ret = xsm_physinfo();
+        if ( ret )
+            break;
+
+        last_online_cpu = cpumask_last(&cpu_online_map);
+        max_cpu_index = min_t(uint32_t, ti->max_cpu_index, last_online_cpu);
+        ti->max_cpu_index = last_online_cpu;
+
+        for ( i = 0; i <= max_cpu_index; i++ )
+        {
+            if ( !guest_handle_is_null(ti->cpu_to_core) )
+            {
+                uint32_t core = cpu_online(i) ? cpu_to_core(i) : ~0u;
+                if ( copy_to_guest_offset(ti->cpu_to_core, i, &core, 1) )
+                    break;
+            }
+            if ( !guest_handle_is_null(ti->cpu_to_socket) )
+            {
+                uint32_t socket = cpu_online(i) ? cpu_to_socket(i) : ~0u;
+                if ( copy_to_guest_offset(ti->cpu_to_socket, i, &socket, 1) )
+                    break;
+            }
+            if ( !guest_handle_is_null(ti->cpu_to_node) )
+            {
+                uint32_t node = cpu_online(i) ? cpu_to_node(i) : ~0u;
+                if ( copy_to_guest_offset(ti->cpu_to_node, i, &node, 1) )
+                    break;
+            }
+        }
+
+        ret = ((i <= max_cpu_index) || copy_to_guest(u_sysctl, op, 1))
+            ? -EFAULT : 0;
+    }
+    break;
+
+
     default:
         ret = arch_do_sysctl(op, u_sysctl);
         break;
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 4ed5df6..96b36c2 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -136,6 +136,9 @@ extern unsigned long frametable_base_mfn;
 
 extern unsigned long max_page;
 extern unsigned long total_pages;
+/* XXX: implement NUMA support */
+#define node_spanned_pages(nid)	(total_pages)
+#define __node_distance(a, b) (20)
 
 /* Boot-time pagetable setup */
 extern void setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr);
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 6c55039..ea5e716 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -742,6 +742,8 @@ extern void dump_runq(unsigned char key);
 
 #define num_cpupool_cpus(c) cpumask_weight((c)->cpu_valid)
 
+void arch_do_physinfo(xen_sysctl_physinfo_t *pi);
+
 #endif /* __SCHED_H__ */
 
 /*
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index a949c1e..d186276 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -141,6 +141,7 @@ struct xsm_operations {
 
     long (*__do_xsm_op) (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op);
 
+    int (*physinfo) (void);
 #ifdef CONFIG_X86
     int (*shadow_control) (struct domain *d, uint32_t op);
     int (*getpageframeinfo) (struct domain *d);
@@ -160,7 +161,6 @@ struct xsm_operations {
     int (*xen_settime) (void);
     int (*memtype) (uint32_t access);
     int (*microcode) (void);
-    int (*physinfo) (void);
     int (*platform_quirk) (uint32_t);
     int (*firmware_info) (void);
     int (*efi_call) (void);
@@ -611,6 +611,11 @@ static inline int xsm_init (unsigned long *module_map,
 }
 #endif
 
+static inline int xsm_physinfo (void)
+{
+    return xsm_call(physinfo());
+}
+
 #ifdef CONFIG_X86
 static inline int xsm_shadow_control (struct domain *d, uint32_t op)
 {
@@ -702,11 +707,6 @@ static inline int xsm_microcode (void)
     return xsm_call(microcode());
 }
 
-static inline int xsm_physinfo (void)
-{
-    return xsm_call(physinfo());
-}
-
 static inline int xsm_platform_quirk (uint32_t quirk)
 {
     return xsm_call(platform_quirk(quirk));
-- 
1.7.2.5
^ permalink raw reply related	[flat|nested] 10+ messages in thread
- * Re: [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code
  2013-01-14 17:04 ` [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Stefano Stabellini
@ 2013-01-14 18:22   ` Keir Fraser
  2013-01-15 10:13   ` Ian Campbell
  1 sibling, 0 replies; 10+ messages in thread
From: Keir Fraser @ 2013-01-14 18:22 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel; +Cc: tim, Ian.Campbell
On 14/01/2013 17:04, "Stefano Stabellini" <stefano.stabellini@eu.citrix.com>
wrote:
> Move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and
> XEN_SYSCTL_topologyinfo from x86/sysctl.c to common/sysctl.c.
> 
> The implementation of XEN_SYSCTL_physinfo is mostly generic but needs to
> fill in few arch specific details: introduce arch_do_physinfo to do that.
> 
> The implementation of XEN_SYSCTL_physinfo relies on two global
> variables: total_pages and cpu_khz. Make them available on ARM.
> 
> Allow xsm_physinfo on ARM.
> 
> Implement node_spanned_pages and __node_distance on ARM, assuming 1 numa
> node for now.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
^ permalink raw reply	[flat|nested] 10+ messages in thread 
- * Re: [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code
  2013-01-14 17:04 ` [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Stefano Stabellini
  2013-01-14 18:22   ` Keir Fraser
@ 2013-01-15 10:13   ` Ian Campbell
  2013-01-15 11:19     ` Stefano Stabellini
  1 sibling, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2013-01-15 10:13 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel@lists.xensource.com, Tim (Xen.org)
On Mon, 2013-01-14 at 17:04 +0000, Stefano Stabellini wrote:
> diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
> index 9515b42..bcd7769 100644
> --- a/xen/arch/arm/time.c
> +++ b/xen/arch/arm/time.c
> @@ -41,16 +41,16 @@ uint64_t __read_mostly boot_count;
> 
>  /* For fine-grained timekeeping, we use the ARM "Generic Timer", a
>   * register-mapped time source in the SoC. */
> -static uint32_t __read_mostly cntfrq;      /* Ticks per second */
> +unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz.
> */
> 
>  /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
>  {
> -    return muldiv64(ticks, SECONDS(1), cntfrq);
> +    return muldiv64(ticks, SECONDS(1), cpu_khz);
>  }
cntfrq and cpu_khz appear to have different units, so is this really
correct? (or else the existing comment on cntfrq is wrong, it implies
that the units are HZ).
^ permalink raw reply	[flat|nested] 10+ messages in thread
- * Re: [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code
  2013-01-15 10:13   ` Ian Campbell
@ 2013-01-15 11:19     ` Stefano Stabellini
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-15 11:19 UTC (permalink / raw)
  To: Ian Campbell
  Cc: xen-devel@lists.xensource.com, Tim (Xen.org), Stefano Stabellini
On Tue, 15 Jan 2013, Ian Campbell wrote:
> On Mon, 2013-01-14 at 17:04 +0000, Stefano Stabellini wrote:
> > diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
> > index 9515b42..bcd7769 100644
> > --- a/xen/arch/arm/time.c
> > +++ b/xen/arch/arm/time.c
> > @@ -41,16 +41,16 @@ uint64_t __read_mostly boot_count;
> > 
> >  /* For fine-grained timekeeping, we use the ARM "Generic Timer", a
> >   * register-mapped time source in the SoC. */
> > -static uint32_t __read_mostly cntfrq;      /* Ticks per second */
> > +unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz.
> > */
> > 
> >  /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
> >  {
> > -    return muldiv64(ticks, SECONDS(1), cntfrq);
> > +    return muldiv64(ticks, SECONDS(1), cpu_khz);
> >  }
> 
> cntfrq and cpu_khz appear to have different units, so is this really
> correct? (or else the existing comment on cntfrq is wrong, it implies
> that the units are HZ).
 
Yes, you are right, they have different units. I'll fix it.
^ permalink raw reply	[flat|nested] 10+ messages in thread
 
 
- * [PATCH 2/4] xen/arm: implement gnttab_create_shared_page and gnttab_shared_gmfn
  2013-01-14 17:03 [PATCH 0/4] xen/arm: compile and run xl Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Stefano Stabellini
@ 2013-01-14 17:04 ` Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 3/4] libxc: fixes for the ARM platform Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 4/4] xen/arm: compile and run libxl/xl Stefano Stabellini
  3 siblings, 0 replies; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-14 17:04 UTC (permalink / raw)
  To: xen-devel; +Cc: tim, Ian.Campbell, Stefano Stabellini
Introduce a simple pfn array, grant_table_gpfn, to keep track of the
grant table pages mapped in guest gpfn space.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 xen/arch/arm/domain.c             |    3 +++
 xen/arch/arm/mm.c                 |    2 ++
 xen/include/asm-arm/domain.h      |    1 +
 xen/include/asm-arm/grant_table.h |   13 +++++++++++--
 4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 193a931..977ab2c 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -6,6 +6,7 @@
 #include <xen/wait.h>
 #include <xen/errno.h>
 #include <xen/bitops.h>
+#include <xen/grant_table.h>
 
 #include <asm/current.h>
 #include <asm/regs.h>
@@ -328,11 +329,13 @@ struct domain *alloc_domain_struct(void)
     d = alloc_xenheap_pages(0, 0);
     if ( d != NULL )
         clear_page(d);
+    d->arch.grant_table_gpfn = xmalloc_array(xen_pfn_t, max_nr_grant_frames);
     return d;
 }
 
 void free_domain_struct(struct domain *d)
 {
+    xfree(d->arch.grant_table_gpfn);
     free_xenheap_page(d);
 }
 
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index fbb6da7..7f211a4 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -530,6 +530,8 @@ static int xenmem_add_to_physmap_one(
             if ( idx < nr_grant_frames(d->grant_table) )
                 mfn = virt_to_mfn(d->grant_table->shared_raw[idx]);
         }
+        
+        d->arch.grant_table_gpfn[idx] = gpfn;
 
         spin_unlock(&d->grant_table->lock);
         break;
diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
index 577ad19..29fe808 100644
--- a/xen/include/asm-arm/domain.h
+++ b/xen/include/asm-arm/domain.h
@@ -39,6 +39,7 @@ struct arch_domain
 {
     struct p2m_domain p2m;
     struct hvm_domain hvm_domain;
+    xen_pfn_t *grant_table_gpfn;
 
     struct {
         /*
diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index e49aa8d..3fa270d 100644
--- a/xen/include/asm-arm/grant_table.h
+++ b/xen/include/asm-arm/grant_table.h
@@ -15,8 +15,6 @@ int replace_grant_host_mapping(unsigned long gpaddr, unsigned long mfn,
         unsigned long new_gpaddr, unsigned int flags);
 void gnttab_mark_dirty(struct domain *d, unsigned long l);
 #define gnttab_create_status_page(d, t, i) do {} while (0)
-#define gnttab_create_shared_page(d, t, i) do {} while (0)
-#define gnttab_shared_gmfn(d, t, i) (0)
 #define gnttab_status_gmfn(d, t, i) (0)
 #define gnttab_release_host_mappings(domain) 1
 static inline int replace_grant_supported(void)
@@ -24,6 +22,17 @@ static inline int replace_grant_supported(void)
     return 1;
 }
 
+#define gnttab_create_shared_page(d, t, i)                               \
+    do {                                                                 \
+        share_xen_page_with_guest(                                       \
+            virt_to_page((char *)(t)->shared_raw[i]),                    \
+            (d), XENSHARE_writable);                                     \
+    } while ( 0 )
+
+#define gnttab_shared_gmfn(d, t, i)                                      \
+    ( ((i >= nr_grant_frames(d->grant_table)) &&                         \
+     (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i]))
+
 #endif /* __ASM_GRANT_TABLE_H__ */
 /*
  * Local variables:
-- 
1.7.2.5
^ permalink raw reply related	[flat|nested] 10+ messages in thread
- * [PATCH 3/4] libxc: fixes for the ARM platform
  2013-01-14 17:03 [PATCH 0/4] xen/arm: compile and run xl Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 1/4] xen: move XEN_SYSCTL_physinfo, XEN_SYSCTL_numainfo and XEN_SYSCTL_topologyinfo to common code Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 2/4] xen/arm: implement gnttab_create_shared_page and gnttab_shared_gmfn Stefano Stabellini
@ 2013-01-14 17:04 ` Stefano Stabellini
  2013-01-14 17:04 ` [PATCH 4/4] xen/arm: compile and run libxl/xl Stefano Stabellini
  3 siblings, 0 replies; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-14 17:04 UTC (permalink / raw)
  To: xen-devel; +Cc: tim, Ian.Campbell, Stefano Stabellini
Make xc_dom_feature_translated an arch-dependent function.
alloc_magic_pages: save console and xenstore pfn's in xc_dom_image.
alloc_magic_pages: set HVM_PARAM_CONSOLE_EVTCHN and
HVM_PARAM_STORE_EVTCHN hvm_params using the event channels allocated by
the toolstack.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/libxc/xc_core_arm.h |    2 ++
 tools/libxc/xc_core_x86.h |    5 +++++
 tools/libxc/xc_dom.h      |    6 +-----
 tools/libxc/xc_dom_arm.c  |   19 ++++++++++++-------
 4 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/tools/libxc/xc_core_arm.h b/tools/libxc/xc_core_arm.h
index 3a6be2a..c046250 100644
--- a/tools/libxc/xc_core_arm.h
+++ b/tools/libxc/xc_core_arm.h
@@ -33,6 +33,8 @@ struct xc_core_arch_context {
                                                                 (0)
 #define xc_core_arch_context_dump(xch, arch_ctxt, args, dump_rtn)    (0)
 
+#define xc_dom_feature_translated(dom) (1)
+
 int
 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
                               unsigned long pfn);
diff --git a/tools/libxc/xc_core_x86.h b/tools/libxc/xc_core_x86.h
index 7b209f6..ee7d8b1 100644
--- a/tools/libxc/xc_core_x86.h
+++ b/tools/libxc/xc_core_x86.h
@@ -34,6 +34,11 @@ struct xc_core_arch_context {
                                                                 (0)
 #define xc_core_arch_context_dump(xch, arch_ctxt, args, dump_rtn)    (0)
 
+static inline int xc_dom_feature_translated(struct xc_dom_image *dom)
+{
+    return elf_xen_feature_get(XENFEAT_auto_translated_physmap, dom->f_active);
+}
+
 int
 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
                               unsigned long pfn);
diff --git a/tools/libxc/xc_dom.h b/tools/libxc/xc_dom.h
index eccc516..b5e17be 100644
--- a/tools/libxc/xc_dom.h
+++ b/tools/libxc/xc_dom.h
@@ -15,6 +15,7 @@
  */
 
 #include <xen/libelf/libelf.h>
+#include <xc_core.h>
 
 #define INVALID_P2M_ENTRY   ((xen_pfn_t)-1)
 
@@ -312,11 +313,6 @@ static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
     return (ptr ? (ptr + offset) : NULL);
 }
 
-static inline int xc_dom_feature_translated(struct xc_dom_image *dom)
-{
-    return elf_xen_feature_get(XENFEAT_auto_translated_physmap, dom->f_active);
-}
-
 static inline xen_pfn_t xc_dom_p2m_host(struct xc_dom_image *dom, xen_pfn_t pfn)
 {
     if (dom->shadow_enabled)
diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c
index b743a6c..0cec774 100644
--- a/tools/libxc/xc_dom_arm.c
+++ b/tools/libxc/xc_dom_arm.c
@@ -51,7 +51,7 @@ static int setup_pgtables_arm(struct xc_dom_image *dom)
 static int alloc_magic_pages(struct xc_dom_image *dom)
 {
     int rc, i;
-    xen_pfn_t store_pfn, console_pfn, p2m[NR_MAGIC_PAGES];
+    xen_pfn_t p2m[NR_MAGIC_PAGES];
 
     DOMPRINTF_CALLED(dom->xch);
 
@@ -64,15 +64,20 @@ static int alloc_magic_pages(struct xc_dom_image *dom)
     if ( rc < 0 )
         return rc;
 
-    console_pfn = dom->rambase_pfn + dom->total_pages + CONSOLE_PFN_OFFSET;
-    store_pfn = dom->rambase_pfn + dom->total_pages + XENSTORE_PFN_OFFSET;
+    dom->console_pfn = dom->rambase_pfn + dom->total_pages + CONSOLE_PFN_OFFSET;
+    dom->xenstore_pfn = dom->rambase_pfn + dom->total_pages + XENSTORE_PFN_OFFSET;
 
-    xc_clear_domain_page(dom->xch, dom->guest_domid, console_pfn);
-    xc_clear_domain_page(dom->xch, dom->guest_domid, store_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->console_pfn);
+    xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn);
     xc_set_hvm_param(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_PFN,
-            console_pfn);
+            dom->console_pfn);
     xc_set_hvm_param(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN,
-            store_pfn);
+            dom->xenstore_pfn);
+    /* allocated by toolstack */
+    xc_set_hvm_param(dom->xch, dom->guest_domid, HVM_PARAM_CONSOLE_EVTCHN,
+            dom->console_evtchn);
+    xc_set_hvm_param(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN,
+            dom->xenstore_evtchn);
 
     return 0;
 }
-- 
1.7.2.5
^ permalink raw reply related	[flat|nested] 10+ messages in thread
- * [PATCH 4/4] xen/arm: compile and run libxl/xl
  2013-01-14 17:03 [PATCH 0/4] xen/arm: compile and run xl Stefano Stabellini
                   ` (2 preceding siblings ...)
  2013-01-14 17:04 ` [PATCH 3/4] libxc: fixes for the ARM platform Stefano Stabellini
@ 2013-01-14 17:04 ` Stefano Stabellini
  2013-01-15 10:53   ` Ian Campbell
  3 siblings, 1 reply; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-14 17:04 UTC (permalink / raw)
  To: xen-devel; +Cc: tim, Ian.Campbell, Stefano Stabellini
Move tsc, rtc, memmap_limit, localtime and shadow settings from
libxl__build_pre to libxl__arch_domain_create.
Get the console and xenstore pfn's from struct xc_dom_image for
autotranslated guests.
Call xc_dom_gnttab_hvm_seed instead of xc_dom_gnttab_init for
autotranslated guests.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/libxl/libxl_dom.c |   67 +++++++++++-----------------------------------
 tools/libxl/libxl_x86.c |   48 +++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 51 deletions(-)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 95da18e..41d39e5 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -202,9 +202,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
               libxl_domain_build_info *info, libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    int tsc_mode;
     char *xs_domid, *con_domid;
-    uint32_t rtc_timeoffset;
 
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
 
@@ -233,49 +231,6 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
 
     xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
-    if (info->type == LIBXL_DOMAIN_TYPE_PV)
-        xc_domain_set_memmap_limit(ctx->xch, domid,
-                (info->max_memkb + info->u.pv.slack_memkb));
-    switch (info->tsc_mode) {
-    case LIBXL_TSC_MODE_DEFAULT:
-        tsc_mode = 0;
-        break;
-    case LIBXL_TSC_MODE_ALWAYS_EMULATE:
-        tsc_mode = 1;
-        break;
-    case LIBXL_TSC_MODE_NATIVE:
-        tsc_mode = 2;
-        break;
-    case LIBXL_TSC_MODE_NATIVE_PARAVIRT:
-        tsc_mode = 3;
-        break;
-    default:
-        abort();
-    }
-    xc_domain_set_tsc_info(ctx->xch, domid, tsc_mode, 0, 0, 0);
-    if (libxl_defbool_val(info->disable_migrate))
-        xc_domain_disable_migrate(ctx->xch, domid);
-
-    rtc_timeoffset = info->rtc_timeoffset;
-    if (libxl_defbool_val(info->localtime)) {
-        time_t t;
-        struct tm *tm;
-
-        t = time(NULL);
-        tm = localtime(&t);
-
-        rtc_timeoffset += tm->tm_gmtoff;
-    }
-
-    if (rtc_timeoffset)
-        xc_domain_set_time_offset(ctx->xch, domid, rtc_timeoffset);
-
-    if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
-        unsigned long shadow;
-        shadow = (info->shadow_memkb + 1023) / 1024;
-        xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
-    }
-
     xs_domid = xs_read(ctx->xsh, XBT_NULL, "/tool/xenstored/domid", NULL);
     state->store_domid = xs_domid ? atoi(xs_domid) : 0;
     free(xs_domid);
@@ -438,14 +393,24 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_boot_image failed");
         goto out;
     }
-    if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_gnttab_init failed");
-        goto out;
+    if (xc_dom_feature_translated(dom)) {
+        if ( (ret = xc_dom_gnttab_hvm_seed(ctx->xch, domid, dom->console_pfn,
+                        dom->xenstore_pfn, dom->console_domid,
+                        dom->xenstore_domid)) != 0 ) {
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_gnttab_hvm_seed failed");
+            goto out;
+        }
+        state->console_mfn = dom->console_pfn;
+        state->store_mfn = dom->xenstore_pfn;
+    } else {
+        if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
+            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_gnttab_init failed");
+            goto out;
+        }
+        state->console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
+        state->store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
     }
 
-    state->console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
-    state->store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
-
     libxl__file_reference_unmap(&state->pv_kernel);
     libxl__file_reference_unmap(&state->pv_ramdisk);
 
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index 590e39d..a17f6ae 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -248,6 +248,54 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
         uint32_t domid)
 {
     int ret = 0;
+    int tsc_mode;
+    uint32_t rtc_timeoffset;
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+
+    if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_PV)
+        xc_domain_set_memmap_limit(ctx->xch, domid,
+                                   (d_config->b_info.max_memkb +
+                                    d_config->b_info.u.pv.slack_memkb));
+
+    switch (d_config->b_info.tsc_mode) {
+    case LIBXL_TSC_MODE_DEFAULT:
+        tsc_mode = 0;
+        break;
+    case LIBXL_TSC_MODE_ALWAYS_EMULATE:
+        tsc_mode = 1;
+        break;
+    case LIBXL_TSC_MODE_NATIVE:
+        tsc_mode = 2;
+        break;
+    case LIBXL_TSC_MODE_NATIVE_PARAVIRT:
+        tsc_mode = 3;
+        break;
+    default:
+        abort();
+    }
+    xc_domain_set_tsc_info(ctx->xch, domid, tsc_mode, 0, 0, 0);
+    if (libxl_defbool_val(d_config->b_info.disable_migrate))
+        xc_domain_disable_migrate(ctx->xch, domid);
+    rtc_timeoffset = d_config->b_info.rtc_timeoffset;
+    if (libxl_defbool_val(d_config->b_info.localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        rtc_timeoffset += tm->tm_gmtoff;
+    }
+
+    if (rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, rtc_timeoffset);
+
+    if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM) {
+        unsigned long shadow;
+        shadow = (d_config->b_info.shadow_memkb + 1023) / 1024;
+        xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
+    }
+
     if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&
             libxl_defbool_val(d_config->b_info.u.pv.e820_host)) {
         ret = libxl__e820_alloc(gc, domid, d_config);
-- 
1.7.2.5
^ permalink raw reply related	[flat|nested] 10+ messages in thread
- * Re: [PATCH 4/4] xen/arm: compile and run libxl/xl
  2013-01-14 17:04 ` [PATCH 4/4] xen/arm: compile and run libxl/xl Stefano Stabellini
@ 2013-01-15 10:53   ` Ian Campbell
  2013-01-15 11:38     ` Stefano Stabellini
  0 siblings, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2013-01-15 10:53 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel@lists.xensource.com, Tim (Xen.org)
On Mon, 2013-01-14 at 17:04 +0000, Stefano Stabellini wrote:
> Move tsc, rtc, memmap_limit, localtime and shadow settings from
> libxl__build_pre to libxl__arch_domain_create.
Ultimately we're going to have to make the build_info type union
somewhat arch specific too.
> Get the console and xenstore pfn's from struct xc_dom_image for
> autotranslated guests.
> 
> Call xc_dom_gnttab_hvm_seed instead of xc_dom_gnttab_init for
> autotranslated guests.
Should/could this be taken care of transparently inside libxc?
Ian.
^ permalink raw reply	[flat|nested] 10+ messages in thread 
- * Re: [PATCH 4/4] xen/arm: compile and run libxl/xl
  2013-01-15 10:53   ` Ian Campbell
@ 2013-01-15 11:38     ` Stefano Stabellini
  0 siblings, 0 replies; 10+ messages in thread
From: Stefano Stabellini @ 2013-01-15 11:38 UTC (permalink / raw)
  To: Ian Campbell
  Cc: xen-devel@lists.xensource.com, Tim (Xen.org), Stefano Stabellini
On Tue, 15 Jan 2013, Ian Campbell wrote:
> On Mon, 2013-01-14 at 17:04 +0000, Stefano Stabellini wrote:
> > Move tsc, rtc, memmap_limit, localtime and shadow settings from
> > libxl__build_pre to libxl__arch_domain_create.
> 
> Ultimately we're going to have to make the build_info type union
> somewhat arch specific too.
yeah
> > Get the console and xenstore pfn's from struct xc_dom_image for
> > autotranslated guests.
> > 
> > Call xc_dom_gnttab_hvm_seed instead of xc_dom_gnttab_init for
> > autotranslated guests.
> 
> Should/could this be taken care of transparently inside libxc?
good idea, I'll do that
^ permalink raw reply	[flat|nested] 10+ messages in thread