Skip to contentSkip to conversation

xen: More assorted improvements to domain creation

PATCH In review Andrew Cooper 5 participants 42 messages Mar 9, 2018 – Mar 16, 2018

lore
Share & tools
lore
#0 lore raw

cover xen: More assorted improvements to domain creation

This series is in preparation for passing more parameters via XEN_DOMCTL_createdomain. It is hypervisor side cleanup, with a couple of related tangents. The toolstack side of this work is forthcoming.

This series has been compile tested on all architecture, and functionally tested on x86.

Andrew Cooper (7):
xen/domain: Drop DOMCRF_dummy
xen/domain: Drop all DOMCRF_* constants
RFC arm/domain: Reject invalid combinations of domain creation flags x86/domain: Remove unused parameters from {hvm,pv}_domain_initialise() x86/domain: Optimise the order of actions in arch_domain_create() xen/domain: Pass the full domctl_createdomain struct to create_domain() xen/mm: Clean up share_xen_page_with_guest() API

 xen/arch/arm/domain.c             |  20 ++---
 xen/arch/arm/mm.c                 |  19 ++---
 xen/arch/arm/setup.c              |   8 +-
 xen/arch/x86/domain.c             | 159 ++++++++++++++++++--------------------
 xen/arch/x86/domain_page.c        |   3 +-
 xen/arch/x86/hvm/dom0_build.c     |   2 +-
 xen/arch/x86/hvm/hvm.c            |   3 +-
 xen/arch/x86/hvm/vmx/vmx.c        |   2 +-
 xen/arch/x86/mm.c                 |  26 +++----
 xen/arch/x86/mm/shadow/common.c   |   2 +-
 xen/arch/x86/pv/domain.c          |   3 +-
 xen/arch/x86/pv/shim.c            |   6 +-
 xen/arch/x86/setup.c              |  18 +++--
 xen/arch/x86/time.c               |   4 +-
 xen/arch/x86/x86_64/mm.c          |  16 ++--
 xen/common/domain.c               |  34 +++++---
 xen/common/domctl.c               |  20 +----
 xen/common/schedule.c             |   2 +-
 xen/common/trace.c                |   9 +--
 xen/common/xenoprof.c             |   3 +-
 xen/include/asm-arm/grant_table.h |   3 +-
 xen/include/asm-arm/mm.h          |   7 --
 xen/include/asm-x86/grant_table.h |   6 +-
 xen/include/asm-x86/hvm/hvm.h     |   3 +-
 xen/include/asm-x86/mm.h          |   8 --
 xen/include/asm-x86/pv/domain.h   |  11 +--
 xen/include/xen/domain.h          |   4 +-
 xen/include/xen/mm.h              |  14 ++++
 xen/include/xen/sched.h           |  32 +++-----
 29 files changed, 197 insertions(+), 250 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/7 xen/domain: Drop DOMCRF_dummy

At the moment, there is a tight coupling between the domid and the use of DOMCRF_dummy. Instead of using DOMCRF_dummy, base the one relevent decision on domid alone.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/mm.c       |  6 +++---
 xen/arch/x86/mm.c       |  6 +++---
 xen/common/domain.c     |  3 ++-
 xen/include/xen/sched.h | 11 +++++++----
 4 files changed, 15 insertions(+), 11 deletions(-)
xen/arch/arm/mm.c +3 -3
index 3c328e2..ce83f69 100644
@@ -520,7 +520,7 @@ void __init arch_init_memory(void)
      * Any Xen-heap pages that we will allow to be mapped will have
      * their domain field set to dom_xen.
      */
-    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_xen));
 
     /*
@@ -528,14 +528,14 @@ void __init arch_init_memory(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0, NULL);
+    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_io));
 
     /*
      * Initialise our COW domain.
      * This domain owns sharable pages.
      */
-    dom_cow = domain_create(DOMID_COW, DOMCRF_dummy, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_cow));
 }
 
xen/arch/x86/mm.c +3 -3
index 9b55944..c275d4b 100644
@@ -271,7 +271,7 @@ void __init arch_init_memory(void)
      * Hidden PCI devices will also be associated with this domain
      * (but be [partly] controlled by Dom0 nevertheless).
      */
-    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_xen));
     INIT_LIST_HEAD(&dom_xen->arch.pdev_list);
 
@@ -280,14 +280,14 @@ void __init arch_init_memory(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0, NULL);
+    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_io));
 
     /*
      * Initialise our COW domain.
      * This domain owns sharable pages.
      */
-    dom_cow = domain_create(DOMID_COW, DOMCRF_dummy, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
     BUG_ON(IS_ERR(dom_cow));
 
     /*
xen/common/domain.c +2 -1
index 219a3e3..cd39a58 100644
@@ -312,7 +312,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
     rangeset_domain_initialise(d);
     init_status |= INIT_rangeset;
 
-    if ( domcr_flags & DOMCRF_dummy )
+    /* DOMID_{XEN,IO,etc} (other than IDLE) are sufficiently constructed. */
+    if ( is_system_domain(d) && !is_idle_domain(d) )
         return d;
 
     if ( !is_idle_domain(d) )
xen/include/xen/sched.h +7 -4
index 39f9386..aa5729b 100644
@@ -491,9 +491,15 @@ extern spinlock_t domlist_update_lock;
 extern rcu_read_lock_t domlist_read_lock;
 
 extern struct vcpu *idle_vcpu[NR_CPUS];
+
 #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
 #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domain(const struct domain *d)
+{
+    return d->domain_id >= DOMID_FIRST_RESERVED;
+}
+
 #define DOMAIN_DESTROYED (1u << 31) /* assumes atomic_t is >= 32 bits */
 #define put_domain(_d) \
   if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destroy(_d)
@@ -531,7 +537,7 @@ void domain_update_node_affinity(struct domain *d);
 
 /*
  * Create a domain: the configuration is only necessary for real domain
- * (i.e !DOMCRF_dummy, excluded idle domain).
+ * (domid < DOMID_FIRST_RESERVED).
  */
 struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
                              uint32_t ssidref,
@@ -546,9 +552,6 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
                         by tboot */
 #define _DOMCRF_s3_integrity  2
 #define DOMCRF_s3_integrity   (1U<<_DOMCRF_s3_integrity)
- /* DOMCRF_dummy: Create a dummy domain (not scheduled; not on domain list) */
-#define _DOMCRF_dummy         3
-#define DOMCRF_dummy          (1U<<_DOMCRF_dummy)
  /* DOMCRF_oos_off: dont use out-of-sync optimization for shadow page tables */
 #define _DOMCRF_oos_off         4
 #define DOMCRF_oos_off          (1U<<_DOMCRF_oos_off)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] xen/domain: Drop DOMCRF_dummy

Quoted 5 lines · Andrew Cooper

At the moment, there is a tight coupling between the domid and the use of DOMCRF_dummy. Instead of using DOMCRF_dummy, base the one relevent decision on domid alone.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#3 lore raw

Re: [PATCH 1/7] xen/domain: Drop DOMCRF_dummy

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 15:12, <[email protected]> wrote:
Quoted 5 lines · Andrew Cooper

At the moment, there is a tight coupling between the domid and the use of DOMCRF_dummy. Instead of using DOMCRF_dummy, base the one relevent decision on domid alone.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/7
#4 lore raw

Re: [PATCH 1/7] xen/domain: Drop DOMCRF_dummy

In reply to Andrew Cooper

Hi Andrew,

Quoted 2 lines · Andrew Cooper

At the moment, there is a tight coupling between the domid and the use of DOMCRF_dummy. Instead of using DOMCRF_dummy, base the one relevent decision

NIT: s/relevent/relevant/

Quoted 3 lines

on domid alone.

Cheers,

Quoted 129 lines

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
  xen/arch/arm/mm.c       |  6 +++---
  xen/arch/x86/mm.c       |  6 +++---
  xen/common/domain.c     |  3 ++-
  xen/include/xen/sched.h | 11 +++++++----
  4 files changed, 15 insertions(+), 11 deletions(-)
xen/arch/arm/mm.c +3 -3
index 3c328e2..ce83f69 100644
@@ -520,7 +520,7 @@ void __init arch_init_memory(void)
       * Any Xen-heap pages that we will allow to be mapped will have
       * their domain field set to dom_xen.
       */
-    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_xen));
 
      /*
@@ -528,14 +528,14 @@ void __init arch_init_memory(void)
       * This domain owns I/O pages that are within the range of the page_info
       * array. Mappings occur at the priv of the caller.
       */
-    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0, NULL);
+    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_io));
 
      /*
       * Initialise our COW domain.
       * This domain owns sharable pages.
       */
-    dom_cow = domain_create(DOMID_COW, DOMCRF_dummy, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_cow));
  }
 
xen/arch/x86/mm.c +3 -3
index 9b55944..c275d4b 100644
@@ -271,7 +271,7 @@ void __init arch_init_memory(void)
       * Hidden PCI devices will also be associated with this domain
       * (but be [partly] controlled by Dom0 nevertheless).
       */
-    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_xen));
      INIT_LIST_HEAD(&dom_xen->arch.pdev_list);
 
@@ -280,14 +280,14 @@ void __init arch_init_memory(void)
       * This domain owns I/O pages that are within the range of the page_info
       * array. Mappings occur at the priv of the caller.
       */
-    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0, NULL);
+    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_io));
 
      /*
       * Initialise our COW domain.
       * This domain owns sharable pages.
       */
-    dom_cow = domain_create(DOMID_COW, DOMCRF_dummy, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
      BUG_ON(IS_ERR(dom_cow));
 
      /*
xen/common/domain.c +2 -1
index 219a3e3..cd39a58 100644
@@ -312,7 +312,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
      rangeset_domain_initialise(d);
      init_status |= INIT_rangeset;
 
-    if ( domcr_flags & DOMCRF_dummy )
+    /* DOMID_{XEN,IO,etc} (other than IDLE) are sufficiently constructed. */
+    if ( is_system_domain(d) && !is_idle_domain(d) )
          return d;
 
      if ( !is_idle_domain(d) )
xen/include/xen/sched.h +7 -4
index 39f9386..aa5729b 100644
@@ -491,9 +491,15 @@ extern spinlock_t domlist_update_lock;
  extern rcu_read_lock_t domlist_read_lock;
 
  extern struct vcpu *idle_vcpu[NR_CPUS];
+
  #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
  #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domain(const struct domain *d)
+{
+    return d->domain_id >= DOMID_FIRST_RESERVED;
+}
+
  #define DOMAIN_DESTROYED (1u << 31) /* assumes atomic_t is >= 32 bits */
  #define put_domain(_d) \
    if ( atomic_dec_and_test(&(_d)->refcnt) ) domain_destroy(_d)
@@ -531,7 +537,7 @@ void domain_update_node_affinity(struct domain *d);
 
  /*
   * Create a domain: the configuration is only necessary for real domain
- * (i.e !DOMCRF_dummy, excluded idle domain).
+ * (domid < DOMID_FIRST_RESERVED).
   */
  struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
                               uint32_t ssidref,
@@ -546,9 +552,6 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
                          by tboot */
  #define _DOMCRF_s3_integrity  2
  #define DOMCRF_s3_integrity   (1U<<_DOMCRF_s3_integrity)
- /* DOMCRF_dummy: Create a dummy domain (not scheduled; not on domain list) */
-#define _DOMCRF_dummy         3
-#define DOMCRF_dummy          (1U<<_DOMCRF_dummy)
   /* DOMCRF_oos_off: dont use out-of-sync optimization for shadow page tables */
  #define _DOMCRF_oos_off         4
  #define DOMCRF_oos_off          (1U<<_DOMCRF_oos_off)
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

PATCH 2/7 xen/domain: Drop all DOMCRF_* constants

In reply to Andrew Cooper

With DOMCRF_dummy removed, all remaining DOMCRF_* idenitcally match their DOMCTL counterparts. Avoid having a conversion between two different bit layouts, and use the DOMCTL_CDF_* constants everywhere.

---
CC: George Dunlap <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/x86/domain.c           |  4 ++--
 xen/arch/x86/mm/shadow/common.c |  2 +-
 xen/arch/x86/setup.c            |  6 +++---
 xen/common/domain.c             |  4 ++--
 xen/common/domctl.c             | 16 ++--------------
 xen/include/xen/sched.h         | 16 ----------------
 6 files changed, 10 insertions(+), 38 deletions(-)
xen/arch/x86/domain.c +2 -2
index 69679a6..36555ea 100644
@@ -435,7 +435,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     if ( config == NULL && !is_idle_domain(d) )
         return -EINVAL;
 
-    d->arch.s3_integrity = !!(domcr_flags & DOMCRF_s3_integrity);
+    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
 
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
@@ -497,7 +497,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         /* Need to determine if HAP is enabled before initialising paging */
         if ( is_hvm_domain(d) )
             d->arch.hvm_domain.hap_enabled =
-                hvm_funcs.hap_supported && (domcr_flags & DOMCRF_hap);
+                hvm_funcs.hap_supported && (domcr_flags & XEN_DOMCTL_CDF_hap);
 
         if ( (rc = paging_domain_init(d, domcr_flags)) != 0 )
             goto fail;
xen/arch/x86/mm/shadow/common.c +1 -1
index 20ded3e..1cf7b28 100644
@@ -62,7 +62,7 @@ int shadow_domain_init(struct domain *d, unsigned int domcr_flags)
 
 #if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC)
     d->arch.paging.shadow.oos_active = 0;
-    d->arch.paging.shadow.oos_off = (domcr_flags & DOMCRF_oos_off) ?  1 : 0;
+    d->arch.paging.shadow.oos_off = domcr_flags & XEN_DOMCTL_CDF_oos_off;
 #endif
     d->arch.paging.shadow.pagetable_dying_op = 0;
 
xen/arch/x86/setup.c +3 -3
index ac530ec..a6dc5df 100644
@@ -660,7 +660,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 {
     char *memmap_type = NULL;
     char *cmdline, *kextra, *loader;
-    unsigned int initrdidx, domcr_flags = DOMCRF_s3_integrity;
+    unsigned int initrdidx, domcr_flags = XEN_DOMCTL_CDF_s3_integrity;
     multiboot_info_t *mbi;
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, *module_map;
@@ -1632,9 +1632,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( dom0_pvh )
     {
-        domcr_flags |= DOMCRF_hvm |
+        domcr_flags |= XEN_DOMCTL_CDF_hvm_guest |
                        ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
-                         DOMCRF_hap : 0);
+                         XEN_DOMCTL_CDF_hap : 0);
         config.emulation_flags = XEN_X86_EMU_LAPIC|XEN_X86_EMU_IOAPIC;
     }
 
xen/common/domain.c +2 -2
index cd39a58..582e3e5 100644
@@ -304,7 +304,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
     if ( !zalloc_cpumask_var(&d->dirty_cpumask) )
         goto fail;
 
-    if ( domcr_flags & DOMCRF_hvm )
+    if ( domcr_flags & XEN_DOMCTL_CDF_hvm_guest )
         d->guest_type = guest_type_hvm;
     else
         d->guest_type = guest_type_pv;
@@ -331,7 +331,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
             hardware_domain = d;
         }
 
-        if ( domcr_flags & DOMCRF_xs_domain )
+        if ( domcr_flags & XEN_DOMCTL_CDF_xs_domain )
         {
             d->is_xenstore = 1;
             d->disable_migrate = 1;
xen/common/domctl.c +2 -14
index 50f7422..a73e1a4 100644
@@ -498,7 +498,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     {
         domid_t        dom;
         static domid_t rover = 0;
-        unsigned int domcr_flags;
 
         ret = -EINVAL;
         if ( (op->u.createdomain.flags &
@@ -533,19 +532,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             rover = dom;
         }
 
-        domcr_flags = 0;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hvm_guest )
-            domcr_flags |= DOMCRF_hvm;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hap )
-            domcr_flags |= DOMCRF_hap;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_s3_integrity )
-            domcr_flags |= DOMCRF_s3_integrity;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
-            domcr_flags |= DOMCRF_oos_off;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain )
-            domcr_flags |= DOMCRF_xs_domain;
-
-        d = domain_create(dom, domcr_flags, op->u.createdomain.ssidref,
+        d = domain_create(dom, op->u.createdomain.flags,
+                          op->u.createdomain.ssidref,
                           &op->u.createdomain.config);
         if ( IS_ERR(d) )
         {
xen/include/xen/sched.h +0 -16
index aa5729b..9af78ac 100644
@@ -542,22 +542,6 @@ void domain_update_node_affinity(struct domain *d);
 struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
                              uint32_t ssidref,
                              struct xen_arch_domainconfig *config);
- /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */
-#define _DOMCRF_hvm           0
-#define DOMCRF_hvm            (1U<<_DOMCRF_hvm)
- /* DOMCRF_hap: Create a domain with hardware-assisted paging. */
-#define _DOMCRF_hap           1
-#define DOMCRF_hap            (1U<<_DOMCRF_hap)
- /* DOMCRF_s3_integrity: Create a domain with tboot memory integrity protection
-                        by tboot */
-#define _DOMCRF_s3_integrity  2
-#define DOMCRF_s3_integrity   (1U<<_DOMCRF_s3_integrity)
- /* DOMCRF_oos_off: dont use out-of-sync optimization for shadow page tables */
-#define _DOMCRF_oos_off         4
-#define DOMCRF_oos_off          (1U<<_DOMCRF_oos_off)
- /* DOMCRF_xs_domain: xenstore domain */
-#define _DOMCRF_xs_domain       5
-#define DOMCRF_xs_domain        (1U<<_DOMCRF_xs_domain)
 
 /*
  * rcu_lock_domain_by_id() is more efficient than get_domain_by_id().
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

Re: [PATCH 2/7] xen/domain: Drop all DOMCRF_* constants

Quoted 18 lines · Andrew Cooper
xen/common/domctl.c +0 -3
index 50f7422..a73e1a4 100644
@@ -498,7 +498,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     {
         domid_t        dom;
         static domid_t rover = 0;
-        unsigned int domcr_flags;
 
         ret = -EINVAL;
         if ( (op->u.createdomain.flags &
@@ -533,19 +532,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             rover = dom;
         }
 
-        domcr_flags = 0;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hvm_guest )

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 547

Quoted 10 lines
xen/common/domctl.c +0 -10
-            domcr_flags |= DOMCRF_hvm;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hap )
-            domcr_flags |= DOMCRF_hap;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_s3_integrity )
-            domcr_flags |= DOMCRF_s3_integrity;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
-            domcr_flags |= DOMCRF_oos_off;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain )
-            domcr_flags |= DOMCRF_xs_domain;
-

Please consider adding a test to reject flags Xen doesn't recognise.

The rest looks OK.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [PATCH 2/7] xen/domain: Drop all DOMCRF_* constants

Quoted 17 lines · Wei Liu
Quoted 16 lines · Andrew Cooper
xen/common/domctl.c +0 -1
index 50f7422..a73e1a4 100644
@@ -498,7 +498,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     {
         domid_t        dom;
         static domid_t rover = 0;
-        unsigned int domcr_flags;
 
         ret = -EINVAL;
         if ( (op->u.createdomain.flags &
@@ -533,19 +532,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             rover = dom;
         }
 
Quoted 13 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 547

Quoted 12 lines
xen/common/domctl.c +0 -12
-        domcr_flags = 0;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hvm_guest )
-            domcr_flags |= DOMCRF_hvm;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hap )
-            domcr_flags |= DOMCRF_hap;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_s3_integrity )
-            domcr_flags |= DOMCRF_s3_integrity;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
-            domcr_flags |= DOMCRF_oos_off;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain )
-            domcr_flags |= DOMCRF_xs_domain;
-

Please consider adding a test to reject flags Xen doesn't recognise.

There already is, between these two hunks. :)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by
#8 lore raw

Re: [PATCH 2/7] xen/domain: Drop all DOMCRF_* constants

Quoted 32 lines · Andrew Cooper
Quoted 17 lines · Wei Liu
Quoted 16 lines · Andrew Cooper
xen/common/domctl.c +0 -1
index 50f7422..a73e1a4 100644
@@ -498,7 +498,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     {
         domid_t        dom;
         static domid_t rover = 0;
-        unsigned int domcr_flags;
 
         ret = -EINVAL;
         if ( (op->u.createdomain.flags &
@@ -533,19 +532,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             rover = dom;
         }
 
Quoted 13 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 547

Quoted 12 lines
xen/common/domctl.c +0 -12
-        domcr_flags = 0;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hvm_guest )
-            domcr_flags |= DOMCRF_hvm;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hap )
-            domcr_flags |= DOMCRF_hap;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_s3_integrity )
-            domcr_flags |= DOMCRF_s3_integrity;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
-            domcr_flags |= DOMCRF_oos_off;
-        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain )
-            domcr_flags |= DOMCRF_xs_domain;
-

Please consider adding a test to reject flags Xen doesn't recognise.

Quoted 2 lines

There already is, between these two hunks. :)

Yes, indeed.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [PATCH 2/7] xen/domain: Drop all DOMCRF_* constants

In reply to Andrew Cooper

Hi Andre,

Quoted 1 line · Andrew Cooper

With DOMCRF_dummy removed, all remaining DOMCRF_* idenitcally match their

NIT: s/idenitcally/identically/

Quoted 4 lines

DOMCTL counterparts. Avoid having a conversion between two different bit layouts, and use the DOMCTL_CDF_* constants everywhere.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

PATCH 3/7 RFC arm/domain: Reject invalid combinations of domain creation flags

In reply to Andrew Cooper

ARM guests are HVM and have hardware assisted paging. There are no PV guests or shadow paging, and all other creation flags are x86 specific.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

RFC. This is untested, but I noticed it when putting together the preceeding patch. There is a moderate chance that this will cause things to explode because of how libxl handles ARM guest construction, but something along these lines is the right thing to do.

---
 xen/arch/arm/domain.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/arm/domain.c +3 -0
index 8de4c0a..291c282 100644
@@ -585,6 +585,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     if ( is_idle_domain(d) )
         return 0;
 
+    if ( domcr_flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
+        return -EINVAL;
+
     ASSERT(config != NULL);
 
     /* p2m_init relies on some value initialized by the IOMMU subsystem */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

Re: [PATCH 3/7] RFC arm/domain: Reject invalid combinations of domain creation flags

Hi Andrew,

Quoted 10 lines · Andrew Cooper

ARM guests are HVM and have hardware assisted paging. There are no PV guests or shadow paging, and all other creation flags are x86 specific.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

Quoted 4 lines

RFC. This is untested, but I noticed it when putting together the preceeding patch. There is a moderate chance that this will cause things to explode because of how libxl handles ARM guest construction, but something along these lines is the right thing to do.

Tools and hypervisor are considering ARM guests as PV. So this patch is going to break boot. There are an action (XEN-102) to move ARM guests to behave more like PVH from the tools POV. I am not sure when I will have time to look at it thought.

For the time being, I am wondering if we could override the flags for Arm in the toolstack?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

Re: [PATCH 3/7] RFC arm/domain: Reject invalid combinations of domain creation flags

Quoted 18 lines · Julien Grall

Hi Andrew,

Quoted 10 lines · Andrew Cooper

ARM guests are HVM and have hardware assisted paging. There are no PV guests or shadow paging, and all other creation flags are x86 specific.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

Quoted 4 lines

RFC. This is untested, but I noticed it when putting together the preceeding patch. There is a moderate chance that this will cause things to explode because of how libxl handles ARM guest construction, but something along these lines is the right thing to do.

Quoted 8 lines

Tools and hypervisor are considering ARM guests as PV. So this patch is going to break boot. There are an action (XEN-102) to move ARM guests to behave more like PVH from the tools POV. I am not sure when I will have time to look at it thought.

For the time being, I am wondering if we could override the flags for Arm in the toolstack?

Is that necessary? I don't think the rest of this series will break ARM at first glance.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [PATCH 3/7] RFC arm/domain: Reject invalid combinations of domain creation flags

Hi,

Quoted 24 lines · Wei Liu
Quoted 23 lines · Julien Grall

Hi Andrew,

Quoted 10 lines · Andrew Cooper

ARM guests are HVM and have hardware assisted paging. There are no PV guests or shadow paging, and all other creation flags are x86 specific.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

Quoted 4 lines

RFC. This is untested, but I noticed it when putting together the preceeding patch. There is a moderate chance that this will cause things to explode because of how libxl handles ARM guest construction, but something along these lines is the right thing to do.

Tools and hypervisor are considering ARM guests as PV. So this patch is going to break boot. There are an action (XEN-102) to move ARM guests to behave more like PVH from the tools POV. I am not sure when I will have time to look at it thought.

Quoted 6 lines
Quoted 3 lines

For the time being, I am wondering if we could override the flags for Arm in the toolstack?

Is that necessary? I don't think the rest of this series will break ARM at first glance.

AFAICT, the rest of the series will not break ARM. So I think it would be fine to just drop this patch for the time being. Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

Re: [PATCH 3/7] RFC arm/domain: Reject invalid combinations of domain creation flags

Quoted 38 lines · Julien Grall

Hi,

Quoted 35 lines · Wei Liu
Quoted 33 lines · Julien Grall

Hi Andrew,

Quoted 11 lines · Andrew Cooper

ARM guests are HVM and have hardware assisted paging.  There are no PV guests
or shadow paging, and all other creation flags are x86 specific.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

Quoted 7 lines

RFC.  This is untested, but I noticed it when putting together the preceeding
patch.  There is a moderate chance that this will cause things to explode
because of how libxl handles ARM guest construction, but something along these
lines is the right thing to do.

Tools and hypervisor are considering ARM guests as PV. So this patch is going to break boot. There are an action (XEN-102) to move ARM guests to
behave more like PVH from the tools POV. I am not sure when I will have time
to look at it thought.

For the time being, I am wondering if we could override the flags for Arm in
the toolstack?

Quoted 5 lines
Quoted 2 lines

Is that necessary? I don't think the rest of this series will break ARM at first glance.

AFAICT, the rest of the series will not break ARM. So I think it would be fine to just drop this patch for the time being.

I'll drop the patch for now.  This was just meant to get the problem on peoples radar.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

PATCH 4/7 x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

In reply to Andrew Cooper

Neither domcr_flags nor config are used on either side. Drop them, making {hvm,pv}_domain_initialise() symmetric with all the other domain/vcpu initialise/destroy calls.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/domain.c           |  4 ++--
 xen/arch/x86/hvm/hvm.c          |  3 +--
 xen/arch/x86/pv/domain.c        |  3 +--
 xen/include/asm-x86/hvm/hvm.h   |  3 +--
 xen/include/asm-x86/pv/domain.h | 11 +++--------
 5 files changed, 8 insertions(+), 16 deletions(-)
xen/arch/x86/domain.c +2 -2
index 36555ea..81ee992 100644
@@ -538,7 +538,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 
     if ( is_hvm_domain(d) )
     {
-        if ( (rc = hvm_domain_initialise(d, domcr_flags, config)) != 0 )
+        if ( (rc = hvm_domain_initialise(d)) != 0 )
             goto fail;
     }
     else if ( is_idle_domain(d) )
@@ -553,7 +553,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     }
     else
     {
-        if ( (rc = pv_domain_initialise(d, domcr_flags, config)) != 0 )
+        if ( (rc = pv_domain_initialise(d)) != 0 )
             goto fail;
     }
 
xen/arch/x86/hvm/hvm.c +1 -2
index 4618664..b3a6e1f 100644
@@ -568,8 +568,7 @@ static int hvm_print_line(
     return X86EMUL_OKAY;
 }
 
-int hvm_domain_initialise(struct domain *d, unsigned long domcr_flags,
-                          struct xen_arch_domainconfig *config)
+int hvm_domain_initialise(struct domain *d)
 {
     unsigned int nr_gsis;
     int rc;
xen/arch/x86/pv/domain.c +1 -2
index 2c784fb..01c62e2 100644
@@ -177,8 +177,7 @@ void pv_domain_destroy(struct domain *d)
 }
 
 
-int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
-                         struct xen_arch_domainconfig *config)
+int pv_domain_initialise(struct domain *d)
 {
     static const struct arch_csw pv_csw = {
         .from = paravirt_ctxt_switch_from,
xen/include/asm-x86/hvm/hvm.h +1 -2
index 9aa6c72..2376ed6 100644
@@ -240,8 +240,7 @@ extern s8 hvm_port80_allowed;
 extern const struct hvm_function_table *start_svm(void);
 extern const struct hvm_function_table *start_vmx(void);
 
-int hvm_domain_initialise(struct domain *d, unsigned long domcr_flags,
-                          struct xen_arch_domainconfig *config);
+int hvm_domain_initialise(struct domain *d);
 void hvm_domain_relinquish_resources(struct domain *d);
 void hvm_domain_destroy(struct domain *d);
 void hvm_domain_soft_reset(struct domain *d);
xen/include/asm-x86/pv/domain.h +3 -8
index acdf140..5e34176 100644
@@ -26,8 +26,7 @@
 void pv_vcpu_destroy(struct vcpu *v);
 int pv_vcpu_initialise(struct vcpu *v);
 void pv_domain_destroy(struct domain *d);
-int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
-                         struct xen_arch_domainconfig *config);
+int pv_domain_initialise(struct domain *d);
 
 #else  /* !CONFIG_PV */
 
@@ -36,12 +35,8 @@ int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
 static inline void pv_vcpu_destroy(struct vcpu *v) {}
 static inline int pv_vcpu_initialise(struct vcpu *v) { return -EOPNOTSUPP; }
 static inline void pv_domain_destroy(struct domain *d) {}
-static inline int pv_domain_initialise(struct domain *d,
-                                       unsigned int domcr_flags,
-                                       struct xen_arch_domainconfig *config);
-{
-    return -EOPNOTSUPP;
-}
+static inline int pv_domain_initialise(struct domain *d) { return -EOPNOTSUPP; }
+
 #endif	/* CONFIG_PV */
 
 void paravirt_ctxt_switch_from(struct vcpu *v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/7
#17 lore raw

Re: [PATCH 4/7] x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

Quoted 5 lines · Andrew Cooper

Neither domcr_flags nor config are used on either side. Drop them, making {hvm,pv}_domain_initialise() symmetric with all the other domain/vcpu initialise/destroy calls.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#18 lore raw

Re: [PATCH 4/7] x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 15:13, <[email protected]> wrote:
Quoted 5 lines · Andrew Cooper

Neither domcr_flags nor config are used on either side. Drop them, making {hvm,pv}_domain_initialise() symmetric with all the other domain/vcpu initialise/destroy calls.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 4/7
#19 lore raw

Re: [PATCH 4/7] x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

Neither domcr_flags nor config are used on either side. Drop them, making {hvm,pv}_domain_initialise() symmetric with all the other domain/vcpu initialise/destroy calls.

Quoted 26 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/domain.c           |  4 ++--
 xen/arch/x86/hvm/hvm.c          |  3 +--
 xen/arch/x86/pv/domain.c        |  3 +--
 xen/include/asm-x86/hvm/hvm.h   |  3 +--
 xen/include/asm-x86/pv/domain.h | 11 +++--------
 5 files changed, 8 insertions(+), 16 deletions(-)
xen/arch/x86/domain.c +1 -1
index 36555ea..81ee992 100644
@@ -538,7 +538,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 
     if ( is_hvm_domain(d) )
     {
-        if ( (rc = hvm_domain_initialise(d, domcr_flags, config)) != 0 )
+        if ( (rc = hvm_domain_initialise(d)) != 0 )
             goto fail;
     }
     else if ( is_idle_domain(d) )

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 558

Quoted 7 lines
xen/arch/x86/domain.c +1 -1
@@ -553,7 +553,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     }
     else
     {
-        if ( (rc = pv_domain_initialise(d, domcr_flags, config)) != 0 )
+        if ( (rc = pv_domain_initialise(d)) != 0 )
             goto fail;
     }

Maybe this could be:

if ( is_idle_domain(d) )
...
else
{
rc = is_hvm_domain(d) ? hvm_domain_initialise(d)
: pv_domain_initialise(d);
if ( rc )
goto fail;
}

But that's maybe out of the scope of this patch.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw

Re: [PATCH 4/7] x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

Quoted 12 lines · Roger Pau Monné

Maybe this could be:

if ( is_idle_domain(d) )
...
else
{
rc = is_hvm_domain(d) ? hvm_domain_initialise(d)
: pv_domain_initialise(d);
if ( rc )
goto fail;
}

Quoted 1 line

But that's maybe out of the scope of this patch.

I'd actually like to reconsider our use of this design pattern.

As far as I can tell from some XTF examples, it forces the use of a function pointer rather than an "if call else call" which in turn forcibly out-of-lines static inline stubs, and prevents LTO from merging a cross TU call into its sole caller.

While the code does does look slightly neater as a result, I get the feeling that

if ( is_hvm_domain(d) )
    rc = hvm_domain_initialise(d);
else
    rc = pv_domain_initialise(d);

is far easier for the compiler to optimise when the opportunities arise.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw

Re: [PATCH 4/7] x86/domain: Remove unused parameters from {hvm, pv}_domain_initialise()

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 21:09, <[email protected]> wrote:
Quoted 12 lines · Roger Pau Monné

Maybe this could be:

if ( is_idle_domain(d) )
...
else
{
rc = is_hvm_domain(d) ? hvm_domain_initialise(d)
: pv_domain_initialise(d);
if ( rc )
goto fail;
}

Quoted 8 lines
Quoted 1 line

But that's maybe out of the scope of this patch.

I'd actually like to reconsider our use of this design pattern.

As far as I can tell from some XTF examples, it forces the use of a function pointer rather than an "if call else call" which in turn forcibly out-of-lines static inline stubs, and prevents LTO from merging a cross TU call into its sole caller.

Where's the function pointer coming from? I could see that happening with

rc = (is_hvm_domain(d) ? hvm_domain_initialise
: pv_domain_initialise)(d);

which I think Roger has been using variants of in a few other patches of his (and which I've been debating with myself whether to comment on while reviewing those patches).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

PATCH 5/7 x86/domain: Optimise the order of actions in arch_domain_create()

In reply to Andrew Cooper

The only relevent initialisation for the idle domain is the context switch and poisoned pointers. Collect these bits together early in the function and exit when complete (although as a consequence, the e820 and vtsc lock initialisation are moved forwards). This allows us to remove subsequent is_idle_domain() checks and unindent most of the logic.

Furthermore, we no longer call these functions for the idle domain:
* mapcache_domain_init() and tsc_set_info() were previously guarded against the idle domain, and have had their guards turned into ASSERT()s.
* pit_init() is implicitly guarded by has_vpit().
* psr_domain_init() no longer allocates a socket array.

Finally, two changes are introduced for the benefit of the following patch:
* For PV hardware domains, or XEN_X86_EMU_PIT into emflags rather than into config->emulation_flags, to facilitating config becoming const.
* References to domcr_flags are moved until after the idle early exist, to facilitiate them being unavailable for system domains.

No practical change in behaviour.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/domain.c      | 152 ++++++++++++++++++++++-----------------------
 xen/arch/x86/domain_page.c |   3 +-
 xen/arch/x86/time.c        |   4 +-
 3 files changed, 78 insertions(+), 81 deletions(-)
xen/arch/x86/domain.c +74 -78
index 81ee992..48dc2b9 100644
@@ -430,20 +430,37 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
+    uint32_t emflags;
     int rc;
 
-    if ( config == NULL && !is_idle_domain(d) )
-        return -EINVAL;
-
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
-
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
     d->arch.relmem = RELMEM_not_started;
     INIT_PAGE_LIST_HEAD(&d->arch.relmem_list);
 
-    if ( d->domain_id && !is_idle_domain(d) &&
-         cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+    spin_lock_init(&d->arch.e820_lock);
+    spin_lock_init(&d->arch.vtsc_lock);
+
+    /* Minimal initialisation for the idle domain. */
+    if ( unlikely(is_idle_domain(d)) )
+    {
+        static const struct arch_csw idle_csw = {
+            .from = paravirt_ctxt_switch_from,
+            .to   = paravirt_ctxt_switch_to,
+            .tail = continue_idle_domain,
+        };
+
+        d->arch.ctxt_switch = &idle_csw;
+
+        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
+
+        return 0;
+    }
+    else if ( !config )
+        return -EINVAL;
+
+    if ( d->domain_id && cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
     {
         if ( !opt_allow_unsafe )
         {
@@ -456,83 +473,69 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
-    if ( is_idle_domain(d) )
-    {
-        d->arch.emulation_flags = 0;
-        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
-        d->arch.msr = ZERO_BLOCK_PTR;
-    }
-    else
-    {
-        uint32_t emflags;
+    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
 
-        if ( is_hardware_domain(d) && is_pv_domain(d) )
-            config->emulation_flags |= XEN_X86_EMU_PIT;
+    emflags = config->emulation_flags;
 
-        emflags = config->emulation_flags;
-        if ( emflags & ~XEN_X86_EMU_ALL )
-        {
-            printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x\n",
-                   d->domain_id, emflags);
-            return -EINVAL;
-        }
+    if ( is_hardware_domain(d) && is_pv_domain(d) )
+        emflags |= XEN_X86_EMU_PIT;
 
-        if ( !emulation_flags_ok(d, emflags) )
-        {
-            printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation "
-                   "with the current selection of emulators: %#x\n",
-                   d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags);
-            return -EOPNOTSUPP;
-        }
-        d->arch.emulation_flags = emflags;
+    if ( emflags & ~XEN_X86_EMU_ALL )
+    {
+        printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x\n",
+               d->domain_id, emflags);
+        return -EINVAL;
     }
 
-    mapcache_domain_init(d);
+    if ( !emulation_flags_ok(d, emflags) )
+    {
+        printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation "
+               "with the current selection of emulators: %#x\n",
+               d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags);
+        return -EOPNOTSUPP;
+    }
+    d->arch.emulation_flags = emflags;
 
     HYPERVISOR_COMPAT_VIRT_START(d) =
         is_pv_domain(d) ? __HYPERVISOR_COMPAT_VIRT_START : ~0u;
 
-    if ( !is_idle_domain(d) )
-    {
-        /* Need to determine if HAP is enabled before initialising paging */
-        if ( is_hvm_domain(d) )
-            d->arch.hvm_domain.hap_enabled =
-                hvm_funcs.hap_supported && (domcr_flags & XEN_DOMCTL_CDF_hap);
+    /* Need to determine if HAP is enabled before initialising paging */
+    if ( is_hvm_domain(d) )
+        d->arch.hvm_domain.hap_enabled =
+            hvm_funcs.hap_supported && (domcr_flags & XEN_DOMCTL_CDF_hap);
 
-        if ( (rc = paging_domain_init(d, domcr_flags)) != 0 )
-            goto fail;
-        paging_initialised = 1;
+    if ( (rc = paging_domain_init(d, domcr_flags)) != 0 )
+        goto fail;
+    paging_initialised = true;
 
-        if ( (rc = init_domain_cpuid_policy(d)) )
-            goto fail;
+    if ( (rc = init_domain_cpuid_policy(d)) )
+        goto fail;
 
-        if ( (rc = init_domain_msr_policy(d)) )
-            goto fail;
+    if ( (rc = init_domain_msr_policy(d)) )
+        goto fail;
 
-        d->arch.ioport_caps = 
-            rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
-        rc = -ENOMEM;
-        if ( d->arch.ioport_caps == NULL )
-            goto fail;
+    d->arch.ioport_caps =
+        rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
+    rc = -ENOMEM;
+    if ( d->arch.ioport_caps == NULL )
+        goto fail;
 
-        /*
-         * The shared_info machine address must fit in a 32-bit field within a
-         * 32-bit guest's start_info structure. Hence we specify MEMF_bits(32).
-         */
-        if ( (d->shared_info = alloc_xenheap_pages(0, MEMF_bits(32))) == NULL )
-            goto fail;
+    /*
+     * The shared_info machine address must fit in a 32-bit field within a
+     * 32-bit guest's start_info structure. Hence we specify MEMF_bits(32).
+     */
+    if ( (d->shared_info = alloc_xenheap_pages(0, MEMF_bits(32))) == NULL )
+        goto fail;
 
-        clear_page(d->shared_info);
-        share_xen_page_with_guest(
-            virt_to_page(d->shared_info), d, XENSHARE_writable);
+    clear_page(d->shared_info);
+    share_xen_page_with_guest(
+        virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-        if ( (rc = init_domain_irq_mapping(d)) != 0 )
-            goto fail;
+    if ( (rc = init_domain_irq_mapping(d)) != 0 )
+        goto fail;
 
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
-    }
-    spin_lock_init(&d->arch.e820_lock);
+    if ( (rc = iommu_domain_init(d)) != 0 )
+        goto fail;
 
     psr_domain_init(d);
 
@@ -541,25 +544,18 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         if ( (rc = hvm_domain_initialise(d)) != 0 )
             goto fail;
     }
-    else if ( is_idle_domain(d) )
+    else if ( is_pv_domain(d) )
     {
-        static const struct arch_csw idle_csw = {
-            .from = paravirt_ctxt_switch_from,
-            .to   = paravirt_ctxt_switch_to,
-            .tail = continue_idle_domain,
-        };
+        mapcache_domain_init(d);
 
-        d->arch.ctxt_switch = &idle_csw;
-    }
-    else
-    {
         if ( (rc = pv_domain_initialise(d)) != 0 )
             goto fail;
     }
+    else
+        ASSERT_UNREACHABLE(); /* Not HVM and not PV? */
 
     /* initialize default tsc behavior in case tools don't */
     tsc_set_info(d, TSC_MODE_DEFAULT, 0UL, 0, 0);
-    spin_lock_init(&d->arch.vtsc_lock);
 
     /* PV/PVH guests get an emulated PIT too for video BIOSes to use. */
     pit_init(d, cpu_khz);
xen/arch/x86/domain_page.c +1 -2
index 3432a85..b5780f2 100644
@@ -236,8 +236,7 @@ int mapcache_domain_init(struct domain *d)
     struct mapcache_domain *dcache = &d->arch.pv_domain.mapcache;
     unsigned int bitmap_pages;
 
-    if ( !is_pv_domain(d) || is_idle_domain(d) )
-        return 0;
+    ASSERT(is_pv_domain(d));
 
 #ifdef NDEBUG
     if ( !mem_hotplug && max_page <= PFN_DOWN(__pa(HYPERVISOR_VIRT_END - 1)) )
xen/arch/x86/time.c +3 -1
index 1a6fde6..84c1c0c 100644
@@ -2124,7 +2124,9 @@ void tsc_set_info(struct domain *d,
                   uint32_t tsc_mode, uint64_t elapsed_nsec,
                   uint32_t gtsc_khz, uint32_t incarnation)
 {
-    if ( is_idle_domain(d) || is_hardware_domain(d) )
+    ASSERT(!is_system_domain(d));
+
+    if ( is_hardware_domain(d) )
     {
         d->arch.vtsc = 0;
         return;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 5/7
#23 lore raw

Re: [PATCH 5/7] x86/domain: Optimise the order of actions in arch_domain_create()

Quoted 18 lines · Andrew Cooper

The only relevent initialisation for the idle domain is the context switch and poisoned pointers. Collect these bits together early in the function and exit when complete (although as a consequence, the e820 and vtsc lock initialisation are moved forwards). This allows us to remove subsequent is_idle_domain() checks and unindent most of the logic.

Furthermore, we no longer call these functions for the idle domain:
* mapcache_domain_init() and tsc_set_info() were previously guarded against the idle domain, and have had their guards turned into ASSERT()s.
* pit_init() is implicitly guarded by has_vpit().
* psr_domain_init() no longer allocates a socket array.

Finally, two changes are introduced for the benefit of the following patch:
* For PV hardware domains, or XEN_X86_EMU_PIT into emflags rather than into config->emulation_flags, to facilitating config becoming const.
* References to domcr_flags are moved until after the idle early exist, to facilitiate them being unavailable for system domains.

Quoted 3 lines

No practical change in behaviour.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 5/7
#24 lore raw

Re: [PATCH 5/7] x86/domain: Optimise the order of actions in arch_domain_create()

In reply to Andrew Cooper
Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +11 -7
@@ -430,20 +430,37 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
+    uint32_t emflags;
     int rc;
 
-    if ( config == NULL && !is_idle_domain(d) )
-        return -EINVAL;
-
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
-
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
     d->arch.relmem = RELMEM_not_started;
     INIT_PAGE_LIST_HEAD(&d->arch.relmem_list);
 
-    if ( d->domain_id && !is_idle_domain(d) &&
-         cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+    spin_lock_init(&d->arch.e820_lock);
+    spin_lock_init(&d->arch.vtsc_lock);
+
+    /* Minimal initialisation for the idle domain. */
+    if ( unlikely(is_idle_domain(d)) )
+    {
+        static const struct arch_csw idle_csw = {
+            .from = paravirt_ctxt_switch_from,
+            .to   = paravirt_ctxt_switch_to,
+            .tail = continue_idle_domain,

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 460

Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+        };
+
+        d->arch.ctxt_switch = &idle_csw;
+
+        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
+
+        return 0;
+    }
+    else if ( !config )

May I suggest to avoid the "else" here? Other than that and with Wei's R-b

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw

Re: [PATCH 5/7] x86/domain: Optimise the order of actions in arch_domain_create()

Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +14 -7
@@ -430,20 +430,37 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
+    uint32_t emflags;
     int rc;
 
-    if ( config == NULL && !is_idle_domain(d) )
-        return -EINVAL;
-
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
-
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
     d->arch.relmem = RELMEM_not_started;
     INIT_PAGE_LIST_HEAD(&d->arch.relmem_list);
 
-    if ( d->domain_id && !is_idle_domain(d) &&
-         cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+    spin_lock_init(&d->arch.e820_lock);
+    spin_lock_init(&d->arch.vtsc_lock);
+
+    /* Minimal initialisation for the idle domain. */
+    if ( unlikely(is_idle_domain(d)) )
+    {
+        static const struct arch_csw idle_csw = {
+            .from = paravirt_ctxt_switch_from,
+            .to   = paravirt_ctxt_switch_to,
+            .tail = continue_idle_domain,
+        };
+
+        d->arch.ctxt_switch = &idle_csw;
Quoted 8 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 460

Quoted 7 lines
xen/arch/x86/domain.c +7 -0
+
+        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
+
+        return 0;
+    }
+    else if ( !config )

May I suggest to avoid the "else" here?

I've gone with

...
        return 0;
    }

    if ( !config )
    {
        /* Only IDLE is allowed with no config. */ ASSERT_UNREACHABLE();
        return -EINVAL;
    }
...

For runtime safety and debug sanity.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#26 lore raw

Re: [PATCH 5/7] x86/domain: Optimise the order of actions in arch_domain_create()

Quoted 58 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 21:15, <[email protected]> wrote:
Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +14 -7
@@ -430,20 +430,37 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
+    uint32_t emflags;
     int rc;
 
-    if ( config == NULL && !is_idle_domain(d) )
-        return -EINVAL;
-
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
-
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
     d->arch.relmem = RELMEM_not_started;
     INIT_PAGE_LIST_HEAD(&d->arch.relmem_list);
 
-    if ( d->domain_id && !is_idle_domain(d) &&
-         cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+    spin_lock_init(&d->arch.e820_lock);
+    spin_lock_init(&d->arch.vtsc_lock);
+
+    /* Minimal initialisation for the idle domain. */
+    if ( unlikely(is_idle_domain(d)) )
+    {
+        static const struct arch_csw idle_csw = {
+            .from = paravirt_ctxt_switch_from,
+            .to   = paravirt_ctxt_switch_to,
+            .tail = continue_idle_domain,
+        };
+
+        d->arch.ctxt_switch = &idle_csw;
Quoted 8 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 460

Quoted 7 lines
xen/arch/x86/domain.c +7 -0
+
+        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
+
+        return 0;
+    }
+    else if ( !config )

May I suggest to avoid the "else" here?

I've gone with

...

        return 0;
    }

    if ( !config )
    {
        /* Only IDLE is allowed with no config. */
        ASSERT_UNREACHABLE();
        return -EINVAL;
    }
Quoted 3 lines

...

For runtime safety and debug sanity.

Ah, yes, that's even better.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 5/7
#27 lore raw

Re: [PATCH 5/7] x86/domain: Optimise the order of actions in arch_domain_create()

In reply to Andrew Cooper
Quoted 1 line · Andrew Cooper

The only relevent initialisation for the idle domain is the context switch and

^ relevant

Quoted 11 lines

poisoned pointers. Collect these bits together early in the function and exit when complete (although as a consequence, the e820 and vtsc lock initialisation are moved forwards). This allows us to remove subsequent is_idle_domain() checks and unindent most of the logic.

Furthermore, we no longer call these functions for the idle domain:
* mapcache_domain_init() and tsc_set_info() were previously guarded against the idle domain, and have had their guards turned into ASSERT()s.
* pit_init() is implicitly guarded by has_vpit().
* psr_domain_init() no longer allocates a socket array.

Quoted 4 lines

Finally, two changes are introduced for the benefit of the following patch:
* For PV hardware domains, or XEN_X86_EMU_PIT into emflags rather than into config->emulation_flags, to facilitating config becoming const.
* References to domcr_flags are moved until after the idle early exist, to

^ exit

Quoted 5 lines

facilitiate them being unavailable for system domains.

No practical change in behaviour.

Quoted 43 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/domain.c      | 152 ++++++++++++++++++++++-----------------------
 xen/arch/x86/domain_page.c |   3 +-
 xen/arch/x86/time.c        |   4 +-
 3 files changed, 78 insertions(+), 81 deletions(-)
xen/arch/x86/domain.c +11 -7
index 81ee992..48dc2b9 100644
@@ -430,20 +430,37 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
     bool paging_initialised = false;
+    uint32_t emflags;
     int rc;
 
-    if ( config == NULL && !is_idle_domain(d) )
-        return -EINVAL;
-
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
-
     INIT_LIST_HEAD(&d->arch.pdev_list);
 
     d->arch.relmem = RELMEM_not_started;
     INIT_PAGE_LIST_HEAD(&d->arch.relmem_list);
 
-    if ( d->domain_id && !is_idle_domain(d) &&
-         cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
+    spin_lock_init(&d->arch.e820_lock);
+    spin_lock_init(&d->arch.vtsc_lock);
+
+    /* Minimal initialisation for the idle domain. */
+    if ( unlikely(is_idle_domain(d)) )
+    {
+        static const struct arch_csw idle_csw = {
+            .from = paravirt_ctxt_switch_from,
+            .to   = paravirt_ctxt_switch_to,
+            .tail = continue_idle_domain,

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 460

Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+        };
+
+        d->arch.ctxt_switch = &idle_csw;
+
+        d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
+
+        return 0;
+    }
+    else if ( !config )

Unneeded else.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

PATCH 6/7 xen/domain: Pass the full domctl_createdomain struct to create_domain()

In reply to Andrew Cooper

In future patches, the structure will be extended with further information, and this is far cleaner than adding extra parameters.

One minor tweak is that the setting of guest_type needs to be deferred until config is known-good to dereference, but this doesn't result in any changed behaviour as system domains never used to pass XEN_DOMCTL_CDF_hvm_guest.

Also for completeness, move the setting of d->handle into the tail of domain_create() where it more logically should live.

---
CC: George Dunlap <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/domain.c    | 16 ++++++++--------
 xen/arch/arm/mm.c        |  6 +++---
 xen/arch/arm/setup.c     |  8 ++++----
 xen/arch/x86/domain.c    | 12 ++++++------
 xen/arch/x86/mm.c        |  6 +++---
 xen/arch/x86/setup.c     | 18 +++++++++++-------
 xen/common/domain.c      | 31 ++++++++++++++++++++-----------
 xen/common/domctl.c      |  8 +-------
 xen/common/schedule.c    |  2 +-
 xen/include/xen/domain.h |  4 ++--
 xen/include/xen/sched.h  |  5 ++---
 11 files changed, 61 insertions(+), 55 deletions(-)
xen/arch/arm/domain.c +8 -8
index 291c282..4b45fad 100644
@@ -573,8 +573,8 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v)
     v->arch.hcr_el2 |= HCR_RW;
 }
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)
 {
     int rc, count = 0;
 
@@ -585,7 +585,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     if ( is_idle_domain(d) )
         return 0;
 
-    if ( domcr_flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
+    if ( config->flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
         return -EINVAL;
 
     ASSERT(config != NULL);
@@ -605,18 +605,18 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     share_xen_page_with_guest(
         virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-    switch ( config->gic_version )
+    switch ( config->config.gic_version )
     {
     case XEN_DOMCTL_CONFIG_GIC_NATIVE:
         switch ( gic_hw_version () )
         {
         case GIC_V2:
-            config->gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
+            config->config.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
             d->arch.vgic.version = GIC_V2;
             break;
 
         case GIC_V3:
-            config->gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
+            config->config.gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
             d->arch.vgic.version = GIC_V3;
             break;
 
@@ -644,10 +644,10 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     if ( (rc = domain_io_init(d, count + MAX_IO_HANDLER)) != 0 )
         goto fail;
 
-    if ( (rc = domain_vgic_init(d, config->nr_spis)) != 0 )
+    if ( (rc = domain_vgic_init(d, config->config.nr_spis)) != 0 )
         goto fail;
 
-    if ( (rc = domain_vtimer_init(d, config)) != 0 )
+    if ( (rc = domain_vtimer_init(d, &config->config)) != 0 )
         goto fail;
 
     update_domain_wallclock_time(d);
xen/arch/arm/mm.c +3 -3
index ce83f69..a09bea2 100644
@@ -520,7 +520,7 @@ void __init arch_init_memory(void)
      * Any Xen-heap pages that we will allow to be mapped will have
      * their domain field set to dom_xen.
      */
-    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, NULL);
     BUG_ON(IS_ERR(dom_xen));
 
     /*
@@ -528,14 +528,14 @@ void __init arch_init_memory(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
+    dom_io = domain_create(DOMID_IO, NULL);
     BUG_ON(IS_ERR(dom_io));
 
     /*
      * Initialise our COW domain.
      * This domain owns sharable pages.
      */
-    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, NULL);
     BUG_ON(IS_ERR(dom_cow));
 }
 
xen/arch/arm/setup.c +4 -4
index 4627366..b17797d 100644
@@ -693,7 +693,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     const char *cmdline;
     struct bootmodule *xen_bootmodule;
     struct domain *dom0;
-    struct xen_arch_domainconfig config;
+    struct xen_domctl_createdomain dom0_cfg = {};
 
     dcache_line_bytes = read_dcache_line_bytes();
 
@@ -840,10 +840,10 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     /* Create initial domain 0. */
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
-    config.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-    config.nr_spis = gic_number_lines() - 32;
+    dom0_cfg.config.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+    dom0_cfg.config.nr_spis = gic_number_lines() - 32;
 
-    dom0 = domain_create(0, 0, 0, &config);
+    dom0 = domain_create(0, &dom0_cfg);
     if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
             panic("Error creating domain 0");
 
xen/arch/x86/domain.c +6 -6
index 48dc2b9..12d0766 100644
@@ -426,8 +426,8 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)
 {
     bool paging_initialised = false;
     uint32_t emflags;
@@ -473,9 +473,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
+    d->arch.s3_integrity = config->flags & XEN_DOMCTL_CDF_s3_integrity;
 
-    emflags = config->emulation_flags;
+    emflags = config->config.emulation_flags;
 
     if ( is_hardware_domain(d) && is_pv_domain(d) )
         emflags |= XEN_X86_EMU_PIT;
@@ -502,9 +502,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     /* Need to determine if HAP is enabled before initialising paging */
     if ( is_hvm_domain(d) )
         d->arch.hvm_domain.hap_enabled =
-            hvm_funcs.hap_supported && (domcr_flags & XEN_DOMCTL_CDF_hap);
+            hvm_funcs.hap_supported && (config->flags & XEN_DOMCTL_CDF_hap);
 
-    if ( (rc = paging_domain_init(d, domcr_flags)) != 0 )
+    if ( (rc = paging_domain_init(d, config->flags)) != 0 )
         goto fail;
     paging_initialised = true;
 
xen/arch/x86/mm.c +3 -3
index c275d4b..1d4e396 100644
@@ -271,7 +271,7 @@ void __init arch_init_memory(void)
      * Hidden PCI devices will also be associated with this domain
      * (but be [partly] controlled by Dom0 nevertheless).
      */
-    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, NULL);
     BUG_ON(IS_ERR(dom_xen));
     INIT_LIST_HEAD(&dom_xen->arch.pdev_list);
 
@@ -280,14 +280,14 @@ void __init arch_init_memory(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
+    dom_io = domain_create(DOMID_IO, NULL);
     BUG_ON(IS_ERR(dom_io));
 
     /*
      * Initialise our COW domain.
      * This domain owns sharable pages.
      */
-    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, NULL);
     BUG_ON(IS_ERR(dom_cow));
 
     /*
xen/arch/x86/setup.c +11 -7
index a6dc5df..a4405b4 100644
@@ -660,7 +660,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 {
     char *memmap_type = NULL;
     char *cmdline, *kextra, *loader;
-    unsigned int initrdidx, domcr_flags = XEN_DOMCTL_CDF_s3_integrity;
+    unsigned int initrdidx;
     multiboot_info_t *mbi;
     module_t *mod;
     unsigned long nr_pages, raw_max_page, modules_headroom, *module_map;
@@ -671,7 +671,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .parity    = 'n',
         .stop_bits = 1
     };
-    struct xen_arch_domainconfig config = { .emulation_flags = 0 };
+    struct xen_domctl_createdomain dom0_cfg = {
+        .flags = XEN_DOMCTL_CDF_s3_integrity,
+    };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -1632,14 +1634,16 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( dom0_pvh )
     {
-        domcr_flags |= XEN_DOMCTL_CDF_hvm_guest |
-                       ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
-                         XEN_DOMCTL_CDF_hap : 0);
-        config.emulation_flags = XEN_X86_EMU_LAPIC|XEN_X86_EMU_IOAPIC;
+        dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm_guest |
+                           ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
+                            XEN_DOMCTL_CDF_hap : 0));
+
+        dom0_cfg.config.emulation_flags =
+            XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC;
     }
 
     /* Create initial domain 0. */
-    dom0 = domain_create(get_initial_domain_id(), domcr_flags, 0, &config);
+    dom0 = domain_create(get_initial_domain_id(), &dom0_cfg);
     if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
         panic("Error creating domain 0");
 
xen/common/domain.c +20 -11
index 582e3e5..b00cc1f 100644
@@ -260,9 +260,8 @@ static int __init parse_extra_guest_irqs(const char *s)
 }
 custom_param("extra_guest_irqs", parse_extra_guest_irqs);
 
-struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
-                             uint32_t ssidref,
-                             struct xen_arch_domainconfig *config)
+struct domain *domain_create(domid_t domid,
+                             struct xen_domctl_createdomain *config)
 {
     struct domain *d, **pd, *old_hwdom = NULL;
     enum { INIT_xsm = 1u<<0, INIT_watchdog = 1u<<1, INIT_rangeset = 1u<<2,
@@ -274,6 +273,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
     d->domain_id = domid;
 
+    /* Debug sanity. */
+    ASSERT(is_system_domain(d) ? config == NULL : config != NULL);
+
     TRACE_1D(TRC_DOM0_DOM_ADD, d->domain_id);
 
     lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid, "Domain");
@@ -304,11 +306,6 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
     if ( !zalloc_cpumask_var(&d->dirty_cpumask) )
         goto fail;
 
-    if ( domcr_flags & XEN_DOMCTL_CDF_hvm_guest )
-        d->guest_type = guest_type_hvm;
-    else
-        d->guest_type = guest_type_pv;
-
     rangeset_domain_initialise(d);
     init_status |= INIT_rangeset;
 
@@ -318,6 +315,11 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
     if ( !is_idle_domain(d) )
     {
+        if ( config->flags & XEN_DOMCTL_CDF_hvm_guest )
+            d->guest_type = guest_type_hvm;
+        else
+            d->guest_type = guest_type_pv;
+
         watchdog_domain_init(d);
         init_status |= INIT_watchdog;
 
@@ -331,7 +333,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
             hardware_domain = d;
         }
 
-        if ( domcr_flags & XEN_DOMCTL_CDF_xs_domain )
+        if ( config->flags & XEN_DOMCTL_CDF_xs_domain )
         {
             d->is_xenstore = 1;
             d->disable_migrate = 1;
@@ -342,7 +344,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         if ( !d->iomem_caps || !d->irq_caps )
             goto fail;
 
-        if ( (err = xsm_domain_create(XSM_HOOK, d, ssidref)) != 0 )
+        if ( (err = xsm_domain_create(XSM_HOOK, d, config->ssidref)) != 0 )
             goto fail;
 
         d->controller_pause_count = 1;
@@ -373,7 +375,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
             goto fail;
     }
 
-    if ( (err = arch_domain_create(d, domcr_flags, config)) != 0 )
+    if ( (err = arch_domain_create(d, config)) != 0 )
         goto fail;
     init_status |= INIT_arch;
 
@@ -385,6 +387,11 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         if ( (err = late_hwdom_init(d)) != 0 )
             goto fail;
 
+        /*
+         * Must not fail beyond this point, as our caller doesn't know whether
+         * the domain has been entered into domain_list or not.
+         */
+
         spin_lock(&domlist_update_lock);
         pd = &domain_list; /* NB. domain_list maintained in order of domid. */
         for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list )
@@ -395,6 +402,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         rcu_assign_pointer(*pd, d);
         rcu_assign_pointer(domain_hash[DOMAIN_HASH(domid)], d);
         spin_unlock(&domlist_update_lock);
+
+        memcpy(d->handle, config->handle, sizeof(d->handle));
     }
 
     return d;
xen/common/domctl.c +1 -7
index a73e1a4..9b7bc08 100644
@@ -532,9 +532,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             rover = dom;
         }
 
-        d = domain_create(dom, op->u.createdomain.flags,
-                          op->u.createdomain.ssidref,
-                          &op->u.createdomain.config);
+        d = domain_create(dom, &op->u.createdomain);
         if ( IS_ERR(d) )
         {
             ret = PTR_ERR(d);
@@ -543,10 +541,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
         }
 
         ret = 0;
-
-        memcpy(d->handle, op->u.createdomain.handle,
-               sizeof(xen_domain_handle_t));
-
         op->domain = d->domain_id;
         copyback = 1;
         d = NULL;
xen/common/schedule.c +1 -1
index 64524f4..b3c2660 100644
@@ -1734,7 +1734,7 @@ void __init scheduler_init(void)
         sched_ratelimit_us = SCHED_DEFAULT_RATELIMIT_US;
     }
 
-    idle_domain = domain_create(DOMID_IDLE, 0, 0, NULL);
+    idle_domain = domain_create(DOMID_IDLE, NULL);
     BUG_ON(IS_ERR(idle_domain));
     idle_domain->vcpu = idle_vcpu;
     idle_domain->max_vcpus = nr_cpu_ids;
xen/include/xen/domain.h +2 -2
index eb62f1d..177cb35 100644
@@ -55,8 +55,8 @@ void vcpu_destroy(struct vcpu *v);
 int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset);
 void unmap_vcpu_info(struct vcpu *v);
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config);
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config);
 
 void arch_domain_destroy(struct domain *d);
 
xen/include/xen/sched.h +2 -3
index 9af78ac..c15c39e 100644
@@ -539,9 +539,8 @@ void domain_update_node_affinity(struct domain *d);
  * Create a domain: the configuration is only necessary for real domain
  * (domid < DOMID_FIRST_RESERVED).
  */
-struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
-                             uint32_t ssidref,
-                             struct xen_arch_domainconfig *config);
+struct domain *domain_create(domid_t domid,
+                             struct xen_domctl_createdomain *config);
 
 /*
  * rcu_lock_domain_by_id() is more efficient than get_domain_by_id().
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 6/7
#29 lore raw

Re: [PATCH 6/7] xen/domain: Pass the full domctl_createdomain struct to create_domain()

Quoted 11 lines · Andrew Cooper

In future patches, the structure will be extended with further information, and this is far cleaner than adding extra parameters.

One minor tweak is that the setting of guest_type needs to be deferred until config is known-good to dereference, but this doesn't result in any changed behaviour as system domains never used to pass XEN_DOMCTL_CDF_hvm_guest.

Also for completeness, move the setting of d->handle into the tail of domain_create() where it more logically should live.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 6/7
#30 lore raw

Re: [PATCH 6/7] xen/domain: Pass the full domctl_createdomain struct to create_domain()

In reply to Andrew Cooper

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 430

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +2 -2
@@ -426,8 +426,8 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)

Is there any reason for this to not be const? There's no write now afaics, and I can't imagine you wanting to add one later on.

Quoted 4 lines
xen/arch/x86/domain.c +0 -0
@@ -1632,14 +1634,16 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( dom0_pvh )
     {

xen/arch/x86/domain.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1642

Quoted 10 lines
xen/arch/x86/domain.c +6 -4
-        domcr_flags |= XEN_DOMCTL_CDF_hvm_guest |
-                       ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
-                         XEN_DOMCTL_CDF_hap : 0);
-        config.emulation_flags = XEN_X86_EMU_LAPIC|XEN_X86_EMU_IOAPIC;
+        dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm_guest |
+                           ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
+                            XEN_DOMCTL_CDF_hap : 0));
+
+        dom0_cfg.config.emulation_flags =
+            XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC;

Would you mind making this |= for ease of future changes?

Other than these

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw

Re: [PATCH 6/7] xen/domain: Pass the full domctl_createdomain struct to create_domain()

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -426,8 +426,8 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
Quoted 6 lines

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 430

Quoted 4 lines
xen/arch/x86/domain.c +2 -2
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)

Is there any reason for this to not be const? There's no write now afaics, and I can't imagine you wanting to add one later on.

I originally planned to make them const, but the ARM side passes data back to the toolstack, and the prototype is (rightfully) common.

Quoted 16 lines
Quoted 5 lines
xen/arch/x86/domain.c +0 -0
@@ -1632,14 +1634,16 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( dom0_pvh )
     {

xen/arch/x86/domain.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1642

Quoted 10 lines
xen/arch/x86/domain.c +6 -4
-        domcr_flags |= XEN_DOMCTL_CDF_hvm_guest |
-                       ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
-                         XEN_DOMCTL_CDF_hap : 0);
-        config.emulation_flags = XEN_X86_EMU_LAPIC|XEN_X86_EMU_IOAPIC;
+        dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm_guest |
+                           ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
+                            XEN_DOMCTL_CDF_hap : 0));
+
+        dom0_cfg.config.emulation_flags =
+            XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC;

Would you mind making this |= for ease of future changes?

Certainly.

Quoted 6 lines

Other than these

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw

Re: [PATCH 6/7] xen/domain: Pass the full domctl_createdomain struct to create_domain()

Quoted 16 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 03/09/18 6:06 PM >>>

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 09.03.18 at 14:18, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -426,8 +426,8 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
     return true;
 }
 
Quoted 6 lines

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 430

Quoted 4 lines
xen/arch/x86/domain.c +2 -2
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)

Is there any reason for this to not be const? There's no write now afaics, and I can't imagine you wanting to add one later on.

Quoted 2 lines

I originally planned to make them const, but the ARM side passes data back to the toolstack, and the prototype is (rightfully) common.

Oh, I see - certainly a little odd, but that's the way it is then.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 6/7
#33 lore raw

Re: [PATCH 6/7] xen/domain: Pass the full domctl_createdomain struct to create_domain()

In reply to Andrew Cooper

Hi Andrew,

Quoted 11 lines · Andrew Cooper

In future patches, the structure will be extended with further information, and this is far cleaner than adding extra parameters.

One minor tweak is that the setting of guest_type needs to be deferred until config is known-good to dereference, but this doesn't result in any changed behaviour as system domains never used to pass XEN_DOMCTL_CDF_hvm_guest.

Also for completeness, move the setting of d->handle into the tail of domain_create() where it more logically should live.

Cheers,

Quoted 423 lines

---
CC: George Dunlap <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
  xen/arch/arm/domain.c    | 16 ++++++++--------
  xen/arch/arm/mm.c        |  6 +++---
  xen/arch/arm/setup.c     |  8 ++++----
  xen/arch/x86/domain.c    | 12 ++++++------
  xen/arch/x86/mm.c        |  6 +++---
  xen/arch/x86/setup.c     | 18 +++++++++++-------
  xen/common/domain.c      | 31 ++++++++++++++++++++-----------
  xen/common/domctl.c      |  8 +-------
  xen/common/schedule.c    |  2 +-
  xen/include/xen/domain.h |  4 ++--
  xen/include/xen/sched.h  |  5 ++---
  11 files changed, 61 insertions(+), 55 deletions(-)
xen/arch/arm/domain.c +8 -8
index 291c282..4b45fad 100644
@@ -573,8 +573,8 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v)
      v->arch.hcr_el2 |= HCR_RW;
  }
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)
  {
      int rc, count = 0;
 
@@ -585,7 +585,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
      if ( is_idle_domain(d) )
          return 0;
 
-    if ( domcr_flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
+    if ( config->flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
          return -EINVAL;
 
      ASSERT(config != NULL);
@@ -605,18 +605,18 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
      share_xen_page_with_guest(
          virt_to_page(d->shared_info), d, XENSHARE_writable);
 
-    switch ( config->gic_version )
+    switch ( config->config.gic_version )
      {
      case XEN_DOMCTL_CONFIG_GIC_NATIVE:
          switch ( gic_hw_version () )
          {
          case GIC_V2:
-            config->gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
+            config->config.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
              d->arch.vgic.version = GIC_V2;
              break;
 
          case GIC_V3:
-            config->gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
+            config->config.gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
              d->arch.vgic.version = GIC_V3;
              break;
 
@@ -644,10 +644,10 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
      if ( (rc = domain_io_init(d, count + MAX_IO_HANDLER)) != 0 )
          goto fail;
 
-    if ( (rc = domain_vgic_init(d, config->nr_spis)) != 0 )
+    if ( (rc = domain_vgic_init(d, config->config.nr_spis)) != 0 )
          goto fail;
 
-    if ( (rc = domain_vtimer_init(d, config)) != 0 )
+    if ( (rc = domain_vtimer_init(d, &config->config)) != 0 )
          goto fail;
 
      update_domain_wallclock_time(d);
xen/arch/arm/mm.c +3 -3
index ce83f69..a09bea2 100644
@@ -520,7 +520,7 @@ void __init arch_init_memory(void)
       * Any Xen-heap pages that we will allow to be mapped will have
       * their domain field set to dom_xen.
       */
-    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, NULL);
      BUG_ON(IS_ERR(dom_xen));
 
      /*
@@ -528,14 +528,14 @@ void __init arch_init_memory(void)
       * This domain owns I/O pages that are within the range of the page_info
       * array. Mappings occur at the priv of the caller.
       */
-    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
+    dom_io = domain_create(DOMID_IO, NULL);
      BUG_ON(IS_ERR(dom_io));
 
      /*
       * Initialise our COW domain.
       * This domain owns sharable pages.
       */
-    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, NULL);
      BUG_ON(IS_ERR(dom_cow));
  }
 
xen/arch/arm/setup.c +4 -4
index 4627366..b17797d 100644
@@ -693,7 +693,7 @@ void __init start_xen(unsigned long boot_phys_offset,
      const char *cmdline;
      struct bootmodule *xen_bootmodule;
      struct domain *dom0;
-    struct xen_arch_domainconfig config;
+    struct xen_domctl_createdomain dom0_cfg = {};
 
      dcache_line_bytes = read_dcache_line_bytes();
 
@@ -840,10 +840,10 @@ void __init start_xen(unsigned long boot_phys_offset,
 
      /* Create initial domain 0. */
      /* The vGIC for DOM0 is exactly emulating the hardware GIC */
-    config.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-    config.nr_spis = gic_number_lines() - 32;
+    dom0_cfg.config.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+    dom0_cfg.config.nr_spis = gic_number_lines() - 32;
 
-    dom0 = domain_create(0, 0, 0, &config);
+    dom0 = domain_create(0, &dom0_cfg);
      if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
              panic("Error creating domain 0");
 
xen/arch/x86/domain.c +6 -6
index 48dc2b9..12d0766 100644
@@ -426,8 +426,8 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
      return true;
  }
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config)
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config)
  {
      bool paging_initialised = false;
      uint32_t emflags;
@@ -473,9 +473,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                 d->domain_id);
      }
 
-    d->arch.s3_integrity = domcr_flags & XEN_DOMCTL_CDF_s3_integrity;
+    d->arch.s3_integrity = config->flags & XEN_DOMCTL_CDF_s3_integrity;
 
-    emflags = config->emulation_flags;
+    emflags = config->config.emulation_flags;
 
      if ( is_hardware_domain(d) && is_pv_domain(d) )
          emflags |= XEN_X86_EMU_PIT;
@@ -502,9 +502,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
      /* Need to determine if HAP is enabled before initialising paging */
      if ( is_hvm_domain(d) )
          d->arch.hvm_domain.hap_enabled =
-            hvm_funcs.hap_supported && (domcr_flags & XEN_DOMCTL_CDF_hap);
+            hvm_funcs.hap_supported && (config->flags & XEN_DOMCTL_CDF_hap);
 
-    if ( (rc = paging_domain_init(d, domcr_flags)) != 0 )
+    if ( (rc = paging_domain_init(d, config->flags)) != 0 )
          goto fail;
      paging_initialised = true;
 
xen/arch/x86/mm.c +3 -3
index c275d4b..1d4e396 100644
@@ -271,7 +271,7 @@ void __init arch_init_memory(void)
       * Hidden PCI devices will also be associated with this domain
       * (but be [partly] controlled by Dom0 nevertheless).
       */
-    dom_xen = domain_create(DOMID_XEN, 0, 0, NULL);
+    dom_xen = domain_create(DOMID_XEN, NULL);
      BUG_ON(IS_ERR(dom_xen));
      INIT_LIST_HEAD(&dom_xen->arch.pdev_list);
 
@@ -280,14 +280,14 @@ void __init arch_init_memory(void)
       * This domain owns I/O pages that are within the range of the page_info
       * array. Mappings occur at the priv of the caller.
       */
-    dom_io = domain_create(DOMID_IO, 0, 0, NULL);
+    dom_io = domain_create(DOMID_IO, NULL);
      BUG_ON(IS_ERR(dom_io));
 
      /*
       * Initialise our COW domain.
       * This domain owns sharable pages.
       */
-    dom_cow = domain_create(DOMID_COW, 0, 0, NULL);
+    dom_cow = domain_create(DOMID_COW, NULL);
      BUG_ON(IS_ERR(dom_cow));
 
      /*
xen/arch/x86/setup.c +11 -7
index a6dc5df..a4405b4 100644
@@ -660,7 +660,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
  {
      char *memmap_type = NULL;
      char *cmdline, *kextra, *loader;
-    unsigned int initrdidx, domcr_flags = XEN_DOMCTL_CDF_s3_integrity;
+    unsigned int initrdidx;
      multiboot_info_t *mbi;
      module_t *mod;
      unsigned long nr_pages, raw_max_page, modules_headroom, *module_map;
@@ -671,7 +671,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
          .parity    = 'n',
          .stop_bits = 1
      };
-    struct xen_arch_domainconfig config = { .emulation_flags = 0 };
+    struct xen_domctl_createdomain dom0_cfg = {
+        .flags = XEN_DOMCTL_CDF_s3_integrity,
+    };
 
      /* Critical region without IDT or TSS.  Any fault is deadly! */
 
@@ -1632,14 +1634,16 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
      if ( dom0_pvh )
      {
-        domcr_flags |= XEN_DOMCTL_CDF_hvm_guest |
-                       ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
-                         XEN_DOMCTL_CDF_hap : 0);
-        config.emulation_flags = XEN_X86_EMU_LAPIC|XEN_X86_EMU_IOAPIC;
+        dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm_guest |
+                           ((hvm_funcs.hap_supported && !opt_dom0_shadow) ?
+                            XEN_DOMCTL_CDF_hap : 0));
+
+        dom0_cfg.config.emulation_flags =
+            XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC;
      }
 
      /* Create initial domain 0. */
-    dom0 = domain_create(get_initial_domain_id(), domcr_flags, 0, &config);
+    dom0 = domain_create(get_initial_domain_id(), &dom0_cfg);
      if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
          panic("Error creating domain 0");
 
xen/common/domain.c +20 -11
index 582e3e5..b00cc1f 100644
@@ -260,9 +260,8 @@ static int __init parse_extra_guest_irqs(const char *s)
  }
  custom_param("extra_guest_irqs", parse_extra_guest_irqs);
 
-struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
-                             uint32_t ssidref,
-                             struct xen_arch_domainconfig *config)
+struct domain *domain_create(domid_t domid,
+                             struct xen_domctl_createdomain *config)
  {
      struct domain *d, **pd, *old_hwdom = NULL;
      enum { INIT_xsm = 1u<<0, INIT_watchdog = 1u<<1, INIT_rangeset = 1u<<2,
@@ -274,6 +273,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
      d->domain_id = domid;
 
+    /* Debug sanity. */
+    ASSERT(is_system_domain(d) ? config == NULL : config != NULL);
+
      TRACE_1D(TRC_DOM0_DOM_ADD, d->domain_id);
 
      lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid, "Domain");
@@ -304,11 +306,6 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
      if ( !zalloc_cpumask_var(&d->dirty_cpumask) )
          goto fail;
 
-    if ( domcr_flags & XEN_DOMCTL_CDF_hvm_guest )
-        d->guest_type = guest_type_hvm;
-    else
-        d->guest_type = guest_type_pv;
-
      rangeset_domain_initialise(d);
      init_status |= INIT_rangeset;
 
@@ -318,6 +315,11 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
      if ( !is_idle_domain(d) )
      {
+        if ( config->flags & XEN_DOMCTL_CDF_hvm_guest )
+            d->guest_type = guest_type_hvm;
+        else
+            d->guest_type = guest_type_pv;
+
          watchdog_domain_init(d);
          init_status |= INIT_watchdog;
 
@@ -331,7 +333,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
              hardware_domain = d;
          }
 
-        if ( domcr_flags & XEN_DOMCTL_CDF_xs_domain )
+        if ( config->flags & XEN_DOMCTL_CDF_xs_domain )
          {
              d->is_xenstore = 1;
              d->disable_migrate = 1;
@@ -342,7 +344,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
          if ( !d->iomem_caps || !d->irq_caps )
              goto fail;
 
-        if ( (err = xsm_domain_create(XSM_HOOK, d, ssidref)) != 0 )
+        if ( (err = xsm_domain_create(XSM_HOOK, d, config->ssidref)) != 0 )
              goto fail;
 
          d->controller_pause_count = 1;
@@ -373,7 +375,7 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
              goto fail;
      }
 
-    if ( (err = arch_domain_create(d, domcr_flags, config)) != 0 )
+    if ( (err = arch_domain_create(d, config)) != 0 )
          goto fail;
      init_status |= INIT_arch;
 
@@ -385,6 +387,11 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
          if ( (err = late_hwdom_init(d)) != 0 )
              goto fail;
 
+        /*
+         * Must not fail beyond this point, as our caller doesn't know whether
+         * the domain has been entered into domain_list or not.
+         */
+
          spin_lock(&domlist_update_lock);
          pd = &domain_list; /* NB. domain_list maintained in order of domid. */
          for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list )
@@ -395,6 +402,8 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
          rcu_assign_pointer(*pd, d);
          rcu_assign_pointer(domain_hash[DOMAIN_HASH(domid)], d);
          spin_unlock(&domlist_update_lock);
+
+        memcpy(d->handle, config->handle, sizeof(d->handle));
      }
 
      return d;
xen/common/domctl.c +1 -7
index a73e1a4..9b7bc08 100644
@@ -532,9 +532,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
              rover = dom;
          }
 
-        d = domain_create(dom, op->u.createdomain.flags,
-                          op->u.createdomain.ssidref,
-                          &op->u.createdomain.config);
+        d = domain_create(dom, &op->u.createdomain);
          if ( IS_ERR(d) )
          {
              ret = PTR_ERR(d);
@@ -543,10 +541,6 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
          }
 
          ret = 0;
-
-        memcpy(d->handle, op->u.createdomain.handle,
-               sizeof(xen_domain_handle_t));
-
          op->domain = d->domain_id;
          copyback = 1;
          d = NULL;
xen/common/schedule.c +1 -1
index 64524f4..b3c2660 100644
@@ -1734,7 +1734,7 @@ void __init scheduler_init(void)
          sched_ratelimit_us = SCHED_DEFAULT_RATELIMIT_US;
      }
 
-    idle_domain = domain_create(DOMID_IDLE, 0, 0, NULL);
+    idle_domain = domain_create(DOMID_IDLE, NULL);
      BUG_ON(IS_ERR(idle_domain));
      idle_domain->vcpu = idle_vcpu;
      idle_domain->max_vcpus = nr_cpu_ids;
xen/include/xen/domain.h +2 -2
index eb62f1d..177cb35 100644
@@ -55,8 +55,8 @@ void vcpu_destroy(struct vcpu *v);
  int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset);
  void unmap_vcpu_info(struct vcpu *v);
 
-int arch_domain_create(struct domain *d, unsigned int domcr_flags,
-                       struct xen_arch_domainconfig *config);
+int arch_domain_create(struct domain *d,
+                       struct xen_domctl_createdomain *config);
 
  void arch_domain_destroy(struct domain *d);
 
xen/include/xen/sched.h +2 -3
index 9af78ac..c15c39e 100644
@@ -539,9 +539,8 @@ void domain_update_node_affinity(struct domain *d);
   * Create a domain: the configuration is only necessary for real domain
   * (domid < DOMID_FIRST_RESERVED).
   */
-struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
-                             uint32_t ssidref,
-                             struct xen_arch_domainconfig *config);
+struct domain *domain_create(domid_t domid,
+                             struct xen_domctl_createdomain *config);
 
  /*
   * rcu_lock_domain_by_id() is more efficient than get_domain_by_id().
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#34 lore raw

PATCH 7/7 xen/mm: Clean up share_xen_page_with_guest() API

In reply to Andrew Cooper

The share_xen_page_with_guest() functions are used by common code, and are implemented the same by each arch. Move the declarations into the common mm.h rather than duplicating them in each arch/mm.h

Turn an int readonly into a boolean enum, to retain ro/rw context at the callsites, but use shorter labels which avoids a large number of split lines.

Implement share_xen_page_with_privileged_guests() as a static inline wrapper around share_xen_page_with_guest() to avoid having a call into a separate translation unit whose only purpose is to shuffle function arguments.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: George Dunlap <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/arm/domain.c             |  3 +--
 xen/arch/arm/mm.c                 | 13 ++++---------
 xen/arch/x86/domain.c             |  3 +--
 xen/arch/x86/hvm/dom0_build.c     |  2 +-
 xen/arch/x86/hvm/vmx/vmx.c        |  2 +-
 xen/arch/x86/mm.c                 | 20 +++++++-------------
 xen/arch/x86/pv/shim.c            |  6 ++----
 xen/arch/x86/x86_64/mm.c          | 16 ++++++----------
 xen/common/trace.c                |  9 +++------
 xen/common/xenoprof.c             |  3 +--
 xen/include/asm-arm/grant_table.h |  3 +--
 xen/include/asm-arm/mm.h          |  7 -------
 xen/include/asm-x86/grant_table.h |  6 ++----
 xen/include/asm-x86/mm.h          |  8 --------
 xen/include/xen/mm.h              | 14 ++++++++++++++
 15 files changed, 44 insertions(+), 71 deletions(-)
xen/arch/arm/domain.c +1 -2
index 4b45fad..23dac5d 100644
@@ -602,8 +602,7 @@ int arch_domain_create(struct domain *d,
         goto fail;
 
     clear_page(d->shared_info);
-    share_xen_page_with_guest(
-        virt_to_page(d->shared_info), d, XENSHARE_writable);
+    share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw);
 
     switch ( config->config.gic_version )
     {
xen/arch/arm/mm.c +4 -9
index a09bea2..baa3b0d 100644
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)
 {
     if ( page_get_owner(page) == d )
         return;
@@ -1196,7 +1196,8 @@ void share_xen_page_with_guest(struct page_info *page,
     spin_lock(&d->page_alloc_lock);
 
     /* The incremented type count pins as writable or read-only. */
-    page->u.inuse.type_info = (readonly ? PGT_none : PGT_writable_page) | 1;
+    page->u.inuse.type_info =
+        (flags == SHARE_ro ? PGT_none : PGT_writable_page) | 1;
 
     page_set_owner(page, d);
     smp_wmb(); /* install valid domain ptr before updating refcnt. */
@@ -1214,12 +1215,6 @@ void share_xen_page_with_guest(struct page_info *page,
     spin_unlock(&d->page_alloc_lock);
 }
 
-void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly)
-{
-    share_xen_page_with_guest(page, dom_xen, readonly);
-}
-
 int xenmem_add_to_physmap_one(
     struct domain *d,
     unsigned int space,
xen/arch/x86/domain.c +1 -2
index 12d0766..8006bed 100644
@@ -528,8 +528,7 @@ int arch_domain_create(struct domain *d,
         goto fail;
 
     clear_page(d->shared_info);
-    share_xen_page_with_guest(
-        virt_to_page(d->shared_info), d, XENSHARE_writable);
+    share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw);
 
     if ( (rc = init_domain_irq_mapping(d)) != 0 )
         goto fail;
xen/arch/x86/hvm/dom0_build.c +1 -1
index afebaec..1c70416 100644
@@ -297,7 +297,7 @@ static void __init pvh_steal_low_ram(struct domain *d, unsigned long start,
             continue;
         }
 
-        share_xen_page_with_guest(pg, d, XENSHARE_writable);
+        share_xen_page_with_guest(pg, d, SHARE_rw);
         rc = guest_physmap_add_entry(d, _gfn(mfn), _mfn(mfn), 0, p2m_ram_rw);
         if ( rc )
             printk("Unable to add mfn %#lx to p2m: %d\n", mfn, rc);
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index 18d8ce2..ebc6934 100644
@@ -2941,7 +2941,7 @@ static int vmx_alloc_vlapic_mapping(struct domain *d)
         return -ENOMEM;
     mfn = page_to_mfn(pg);
     clear_domain_page(_mfn(mfn));
-    share_xen_page_with_guest(pg, d, XENSHARE_writable);
+    share_xen_page_with_guest(pg, d, SHARE_rw);
     d->arch.hvm_domain.vmx.apic_access_mfn = mfn;
     set_mmio_p2m_entry(d, paddr_to_pfn(APIC_DEFAULT_PHYS_BASE), _mfn(mfn),
                        PAGE_ORDER_4K, p2m_get_hostp2m(d)->default_access);
xen/arch/x86/mm.c +7 -13
index 1d4e396..17558e0 100644
@@ -301,8 +301,7 @@ void __init arch_init_memory(void)
           i < (pvh_boot ? (1 + PFN_UP(trampoline_end - trampoline_start))
                         : 0x100);
           i++ )
-        share_xen_page_with_guest(mfn_to_page(_mfn(i)),
-                                  dom_io, XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(_mfn(i)), dom_io, SHARE_rw);
 
     /* Any areas not specified as RAM by the e820 map are considered I/O. */
     for ( i = 0, pfn = 0; pfn < max_page; i++ )
@@ -342,8 +341,8 @@ void __init arch_init_memory(void)
         {
             if ( !mfn_valid(_mfn(pfn)) )
                 continue;
-            share_xen_page_with_guest(
-                mfn_to_page(_mfn(pfn)), dom_io, XENSHARE_writable);
+
+            share_xen_page_with_guest(mfn_to_page(_mfn(pfn)), dom_io, SHARE_rw);
         }
 
         /* Skip the RAM region. */
@@ -439,8 +438,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     return (arch_get_max_pfn(d) ?: 1) - 1;
 }
 
-void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)
 {
     if ( page_get_owner(page) == d )
         return;
@@ -450,7 +449,8 @@ void share_xen_page_with_guest(
     spin_lock(&d->page_alloc_lock);
 
     /* The incremented type count pins as writable or read-only. */
-    page->u.inuse.type_info  = (readonly ? PGT_none : PGT_writable_page);
+    page->u.inuse.type_info =
+        (flags == SHARE_ro ? PGT_none : PGT_writable_page);
     page->u.inuse.type_info |= PGT_validated | 1;
 
     page_set_owner(page, d);
@@ -485,12 +485,6 @@ int __init unshare_xen_page_with_guest(struct page_info *page,
     return 0;
 }
 
-void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly)
-{
-    share_xen_page_with_guest(page, dom_xen, readonly);
-}
-
 void free_shared_domheap_page(struct page_info *page)
 {
     if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
xen/arch/x86/pv/shim.c +2 -4
index 534965c..dd76264 100644
@@ -171,8 +171,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
     (si) = param;                                                              \
     if ( va )                                                                  \
     {                                                                          \
-        share_xen_page_with_guest(mfn_to_page(_mfn(param)), d,                 \
-                                  XENSHARE_writable);                          \
+        share_xen_page_with_guest(mfn_to_page(_mfn(param)), d, SHARE_rw);      \
         replace_va_mapping(d, l4start, va, _mfn(param));                       \
         dom0_update_physmap(d, PFN_DOWN((va) - va_start), param, vphysmap);    \
     }                                                                          \
@@ -199,8 +198,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
         clear_page(page);
         console_mfn = virt_to_mfn(page);
         si->console.domU.mfn = mfn_x(console_mfn);
-        share_xen_page_with_guest(mfn_to_page(console_mfn), d,
-                                  XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(console_mfn), d, SHARE_rw);
         replace_va_mapping(d, l4start, console_va, console_mfn);
         dom0_update_physmap(d, (console_va - va_start) >> PAGE_SHIFT,
                             mfn_x(console_mfn), vphysmap);
xen/arch/x86/x86_64/mm.c +6 -10
index 9b37da6..8820f5c 100644
@@ -185,7 +185,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
         {
             struct page_info *page = mfn_to_page(m2p_start_mfn + i);
             if (hotadd_mem_valid(m2p_start_mfn + i, info))
-                share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
+                share_xen_page_with_privileged_guests(page, SHARE_ro);
         }
     }
 
@@ -206,7 +206,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
         {
             struct page_info *page = mfn_to_page(m2p_start_mfn + i);
             if (hotadd_mem_valid(m2p_start_mfn + i, info))
-                share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
+                share_xen_page_with_privileged_guests(page, SHARE_ro);
         }
     }
     return 0;
@@ -860,10 +860,8 @@ void __init subarch_init_memory(void)
         }
 
         for ( i = 0; i < n; i++ )
-        {
-            struct page_info *page = mfn_to_page(m2p_start_mfn + i);
-            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(m2p_start_mfn + i), SHARE_ro);
     }
 
     for ( v  = RDWR_COMPAT_MPT_VIRT_START;
@@ -880,10 +878,8 @@ void __init subarch_init_memory(void)
         m2p_start_mfn = l2e_get_pfn(l2e);
 
         for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
-        {
-            struct page_info *page = mfn_to_page(m2p_start_mfn + i);
-            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(m2p_start_mfn + i), SHARE_ro);
     }
 
     /* Mark all of direct map NX if hardware supports it. */
xen/common/trace.c +3 -6
index 2e18702..680f6ae 100644
@@ -227,7 +227,6 @@ static int alloc_trace_bufs(unsigned int pages)
     for_each_online_cpu(cpu)
     {
         struct t_buf *buf;
-        struct page_info *pg;
 
         spin_lock_init(&per_cpu(t_lock, cpu));
 
@@ -242,16 +241,14 @@ static int alloc_trace_bufs(unsigned int pages)
 
         /* Now share the trace pages */
         for ( i = 0; i < pages; i++ )
-        {
-            pg = mfn_to_page(t_info_mfn_list[offset + i]);
-            share_xen_page_with_privileged_guests(pg, XENSHARE_writable);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(t_info_mfn_list[offset + i]), SHARE_rw);
     }
 
     /* Finally, share the t_info page */
     for(i = 0; i < t_info_pages; i++)
         share_xen_page_with_privileged_guests(
-            virt_to_page(t_info) + i, XENSHARE_readonly);
+            virt_to_page(t_info) + i, SHARE_ro);
 
     data_size  = (pages * PAGE_SIZE - sizeof(struct t_buf));
     t_buf_highwater = data_size >> 1; /* 50% high water */
xen/common/xenoprof.c +1 -2
index 5acdde5..c1b4303 100644
@@ -159,8 +159,7 @@ share_xenoprof_page_with_guest(struct domain *d, mfn_t mfn, int npages)
     }
 
     for ( i = 0; i < npages; i++ )
-        share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)),
-                                  d, XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)), d, SHARE_rw);
 
     return 0;
 }
xen/include/asm-arm/grant_table.h +1 -2
index 5b8994c..be7ed75 100644
@@ -81,8 +81,7 @@ static inline unsigned int gnttab_dom0_max(void)
 #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);                                     \
+            virt_to_page((char *)(t)->shared_raw[i]), (d), SHARE_rw);    \
     } while ( 0 )
 
 #define gnttab_shared_gmfn(d, t, i)                                      \
xen/include/asm-arm/mm.h +0 -7
index 4d5563b..a0e922f 100644
@@ -159,13 +159,6 @@ extern vaddr_t xenheap_virt_start;
 
 #define maddr_get_owner(ma)   (page_get_owner(maddr_to_page((ma))))
 
-#define XENSHARE_writable 0
-#define XENSHARE_readonly 1
-extern void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly);
-extern void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly);
-
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
 /* PDX of the first page in the frame table. */
 extern unsigned long frametable_base_pdx;
xen/include/asm-x86/grant_table.h +2 -4
index 66e9742..8720159 100644
@@ -57,15 +57,13 @@ static inline unsigned int gnttab_dom0_max(void)
 #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);                                     \
+            virt_to_page((char *)(t)->shared_raw[i]), (d), SHARE_rw);    \
     } while ( 0 )
 
 #define gnttab_create_status_page(d, t, i)                               \
     do {                                                                 \
         share_xen_page_with_guest(                                       \
-           virt_to_page((char *)(t)->status[i]),                         \
-            (d), XENSHARE_writable);                                     \
+            virt_to_page((char *)(t)->status[i]), (d), SHARE_rw);        \
     } while ( 0 )
 
 
xen/include/asm-x86/mm.h +0 -8
index 96f3a34..c115661 100644
@@ -292,14 +292,6 @@ struct page_info
 
 #define maddr_get_owner(ma)   (page_get_owner(maddr_to_page((ma))))
 
-#define XENSHARE_writable 0
-#define XENSHARE_readonly 1
-extern void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly);
-extern int unshare_xen_page_with_guest(struct page_info *page,
-                                       struct domain *d);
-extern void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly);
 extern void free_shared_domheap_page(struct page_info *page);
 
 #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
xen/include/xen/mm.h +14 -0
index 0e0e511..142aa73 100644
@@ -634,4 +634,18 @@ static inline void filtered_flush_tlb_mask(uint32_t tlbflush_timestamp)
     }
 }
 
+enum XENSHARE_flags {
+    SHARE_rw,
+    SHARE_ro,
+};
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags);
+int unshare_xen_page_with_guest(struct page_info *page, struct domain *d);
+
+static inline void share_xen_page_with_privileged_guests(
+    struct page_info *page, enum XENSHARE_flags flags)
+{
+    share_xen_page_with_guest(page, dom_xen, flags);
+}
+
 #endif /* __XEN_MM_H__ */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 7/7
#35 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

Quoted 7 lines · Andrew Cooper

The share_xen_page_with_guest() functions are used by common code, and are implemented the same by each arch. Move the declarations into the common mm.h rather than duplicating them in each arch/mm.h

Turn an int readonly into a boolean enum, to retain ro/rw context at the callsites, but use shorter labels which avoids a large number of split lines.

Quoted 7 lines

Implement share_xen_page_with_privileged_guests() as a static inline wrapper around share_xen_page_with_guest() to avoid having a call into a separate translation unit whose only purpose is to shuffle function arguments.

No functional change.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 7/7
#36 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

In reply to Andrew Cooper

Hi Andrew,

Quoted 7 lines · Andrew Cooper

The share_xen_page_with_guest() functions are used by common code, and are implemented the same by each arch. Move the declarations into the common mm.h rather than duplicating them in each arch/mm.h

Turn an int readonly into a boolean enum, to retain ro/rw context at the callsites, but use shorter labels which avoids a large number of split lines.

Quoted 7 lines

Implement share_xen_page_with_privileged_guests() as a static inline wrapper around share_xen_page_with_guest() to avoid having a call into a separate translation unit whose only purpose is to shuffle function arguments.

No functional change.

Cheers,

Quoted 392 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: George Dunlap <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
  xen/arch/arm/domain.c             |  3 +--
  xen/arch/arm/mm.c                 | 13 ++++---------
  xen/arch/x86/domain.c             |  3 +--
  xen/arch/x86/hvm/dom0_build.c     |  2 +-
  xen/arch/x86/hvm/vmx/vmx.c        |  2 +-
  xen/arch/x86/mm.c                 | 20 +++++++-------------
  xen/arch/x86/pv/shim.c            |  6 ++----
  xen/arch/x86/x86_64/mm.c          | 16 ++++++----------
  xen/common/trace.c                |  9 +++------
  xen/common/xenoprof.c             |  3 +--
  xen/include/asm-arm/grant_table.h |  3 +--
  xen/include/asm-arm/mm.h          |  7 -------
  xen/include/asm-x86/grant_table.h |  6 ++----
  xen/include/asm-x86/mm.h          |  8 --------
  xen/include/xen/mm.h              | 14 ++++++++++++++
  15 files changed, 44 insertions(+), 71 deletions(-)
xen/arch/arm/domain.c +1 -2
index 4b45fad..23dac5d 100644
@@ -602,8 +602,7 @@ int arch_domain_create(struct domain *d,
          goto fail;
 
      clear_page(d->shared_info);
-    share_xen_page_with_guest(
-        virt_to_page(d->shared_info), d, XENSHARE_writable);
+    share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw);
 
      switch ( config->config.gic_version )
      {
xen/arch/arm/mm.c +4 -9
index a09bea2..baa3b0d 100644
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
      return gfn_x(d->arch.p2m.max_mapped_gfn);
  }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)
  {
      if ( page_get_owner(page) == d )
          return;
@@ -1196,7 +1196,8 @@ void share_xen_page_with_guest(struct page_info *page,
      spin_lock(&d->page_alloc_lock);
 
      /* The incremented type count pins as writable or read-only. */
-    page->u.inuse.type_info = (readonly ? PGT_none : PGT_writable_page) | 1;
+    page->u.inuse.type_info =
+        (flags == SHARE_ro ? PGT_none : PGT_writable_page) | 1;
 
      page_set_owner(page, d);
      smp_wmb(); /* install valid domain ptr before updating refcnt. */
@@ -1214,12 +1215,6 @@ void share_xen_page_with_guest(struct page_info *page,
      spin_unlock(&d->page_alloc_lock);
  }
 
-void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly)
-{
-    share_xen_page_with_guest(page, dom_xen, readonly);
-}
-
  int xenmem_add_to_physmap_one(
      struct domain *d,
      unsigned int space,
xen/arch/x86/domain.c +1 -2
index 12d0766..8006bed 100644
@@ -528,8 +528,7 @@ int arch_domain_create(struct domain *d,
          goto fail;
 
      clear_page(d->shared_info);
-    share_xen_page_with_guest(
-        virt_to_page(d->shared_info), d, XENSHARE_writable);
+    share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw);
 
      if ( (rc = init_domain_irq_mapping(d)) != 0 )
          goto fail;
xen/arch/x86/hvm/dom0_build.c +1 -1
index afebaec..1c70416 100644
@@ -297,7 +297,7 @@ static void __init pvh_steal_low_ram(struct domain *d, unsigned long start,
              continue;
          }
 
-        share_xen_page_with_guest(pg, d, XENSHARE_writable);
+        share_xen_page_with_guest(pg, d, SHARE_rw);
          rc = guest_physmap_add_entry(d, _gfn(mfn), _mfn(mfn), 0, p2m_ram_rw);
          if ( rc )
              printk("Unable to add mfn %#lx to p2m: %d\n", mfn, rc);
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index 18d8ce2..ebc6934 100644
@@ -2941,7 +2941,7 @@ static int vmx_alloc_vlapic_mapping(struct domain *d)
          return -ENOMEM;
      mfn = page_to_mfn(pg);
      clear_domain_page(_mfn(mfn));
-    share_xen_page_with_guest(pg, d, XENSHARE_writable);
+    share_xen_page_with_guest(pg, d, SHARE_rw);
      d->arch.hvm_domain.vmx.apic_access_mfn = mfn;
      set_mmio_p2m_entry(d, paddr_to_pfn(APIC_DEFAULT_PHYS_BASE), _mfn(mfn),
                         PAGE_ORDER_4K, p2m_get_hostp2m(d)->default_access);
xen/arch/x86/mm.c +7 -13
index 1d4e396..17558e0 100644
@@ -301,8 +301,7 @@ void __init arch_init_memory(void)
            i < (pvh_boot ? (1 + PFN_UP(trampoline_end - trampoline_start))
                          : 0x100);
            i++ )
-        share_xen_page_with_guest(mfn_to_page(_mfn(i)),
-                                  dom_io, XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(_mfn(i)), dom_io, SHARE_rw);
 
      /* Any areas not specified as RAM by the e820 map are considered I/O. */
      for ( i = 0, pfn = 0; pfn < max_page; i++ )
@@ -342,8 +341,8 @@ void __init arch_init_memory(void)
          {
              if ( !mfn_valid(_mfn(pfn)) )
                  continue;
-            share_xen_page_with_guest(
-                mfn_to_page(_mfn(pfn)), dom_io, XENSHARE_writable);
+
+            share_xen_page_with_guest(mfn_to_page(_mfn(pfn)), dom_io, SHARE_rw);
          }
 
          /* Skip the RAM region. */
@@ -439,8 +438,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
      return (arch_get_max_pfn(d) ?: 1) - 1;
  }
 
-void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)
  {
      if ( page_get_owner(page) == d )
          return;
@@ -450,7 +449,8 @@ void share_xen_page_with_guest(
      spin_lock(&d->page_alloc_lock);
 
      /* The incremented type count pins as writable or read-only. */
-    page->u.inuse.type_info  = (readonly ? PGT_none : PGT_writable_page);
+    page->u.inuse.type_info =
+        (flags == SHARE_ro ? PGT_none : PGT_writable_page);
      page->u.inuse.type_info |= PGT_validated | 1;
 
      page_set_owner(page, d);
@@ -485,12 +485,6 @@ int __init unshare_xen_page_with_guest(struct page_info *page,
      return 0;
  }
 
-void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly)
-{
-    share_xen_page_with_guest(page, dom_xen, readonly);
-}
-
  void free_shared_domheap_page(struct page_info *page)
  {
      if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
xen/arch/x86/pv/shim.c +2 -4
index 534965c..dd76264 100644
@@ -171,8 +171,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
      (si) = param;                                                              \
      if ( va )                                                                  \
      {                                                                          \
-        share_xen_page_with_guest(mfn_to_page(_mfn(param)), d,                 \
-                                  XENSHARE_writable);                          \
+        share_xen_page_with_guest(mfn_to_page(_mfn(param)), d, SHARE_rw);      \
          replace_va_mapping(d, l4start, va, _mfn(param));                       \
          dom0_update_physmap(d, PFN_DOWN((va) - va_start), param, vphysmap);    \
      }                                                                          \
@@ -199,8 +198,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
          clear_page(page);
          console_mfn = virt_to_mfn(page);
          si->console.domU.mfn = mfn_x(console_mfn);
-        share_xen_page_with_guest(mfn_to_page(console_mfn), d,
-                                  XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(console_mfn), d, SHARE_rw);
          replace_va_mapping(d, l4start, console_va, console_mfn);
          dom0_update_physmap(d, (console_va - va_start) >> PAGE_SHIFT,
                              mfn_x(console_mfn), vphysmap);
xen/arch/x86/x86_64/mm.c +6 -10
index 9b37da6..8820f5c 100644
@@ -185,7 +185,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
          {
              struct page_info *page = mfn_to_page(m2p_start_mfn + i);
              if (hotadd_mem_valid(m2p_start_mfn + i, info))
-                share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
+                share_xen_page_with_privileged_guests(page, SHARE_ro);
          }
      }
 
@@ -206,7 +206,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info)
          {
              struct page_info *page = mfn_to_page(m2p_start_mfn + i);
              if (hotadd_mem_valid(m2p_start_mfn + i, info))
-                share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
+                share_xen_page_with_privileged_guests(page, SHARE_ro);
          }
      }
      return 0;
@@ -860,10 +860,8 @@ void __init subarch_init_memory(void)
          }
 
          for ( i = 0; i < n; i++ )
-        {
-            struct page_info *page = mfn_to_page(m2p_start_mfn + i);
-            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(m2p_start_mfn + i), SHARE_ro);
      }
 
      for ( v  = RDWR_COMPAT_MPT_VIRT_START;
@@ -880,10 +878,8 @@ void __init subarch_init_memory(void)
          m2p_start_mfn = l2e_get_pfn(l2e);
 
          for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
-        {
-            struct page_info *page = mfn_to_page(m2p_start_mfn + i);
-            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(m2p_start_mfn + i), SHARE_ro);
      }
 
      /* Mark all of direct map NX if hardware supports it. */
xen/common/trace.c +3 -6
index 2e18702..680f6ae 100644
@@ -227,7 +227,6 @@ static int alloc_trace_bufs(unsigned int pages)
      for_each_online_cpu(cpu)
      {
          struct t_buf *buf;
-        struct page_info *pg;
 
          spin_lock_init(&per_cpu(t_lock, cpu));
 
@@ -242,16 +241,14 @@ static int alloc_trace_bufs(unsigned int pages)
 
          /* Now share the trace pages */
          for ( i = 0; i < pages; i++ )
-        {
-            pg = mfn_to_page(t_info_mfn_list[offset + i]);
-            share_xen_page_with_privileged_guests(pg, XENSHARE_writable);
-        }
+            share_xen_page_with_privileged_guests(
+                mfn_to_page(t_info_mfn_list[offset + i]), SHARE_rw);
      }
 
      /* Finally, share the t_info page */
      for(i = 0; i < t_info_pages; i++)
          share_xen_page_with_privileged_guests(
-            virt_to_page(t_info) + i, XENSHARE_readonly);
+            virt_to_page(t_info) + i, SHARE_ro);
 
      data_size  = (pages * PAGE_SIZE - sizeof(struct t_buf));
      t_buf_highwater = data_size >> 1; /* 50% high water */
xen/common/xenoprof.c +1 -2
index 5acdde5..c1b4303 100644
@@ -159,8 +159,7 @@ share_xenoprof_page_with_guest(struct domain *d, mfn_t mfn, int npages)
      }
 
      for ( i = 0; i < npages; i++ )
-        share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)),
-                                  d, XENSHARE_writable);
+        share_xen_page_with_guest(mfn_to_page(mfn_add(mfn, i)), d, SHARE_rw);
 
      return 0;
  }
xen/include/asm-arm/grant_table.h +1 -2
index 5b8994c..be7ed75 100644
@@ -81,8 +81,7 @@ static inline unsigned int gnttab_dom0_max(void)
  #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);                                     \
+            virt_to_page((char *)(t)->shared_raw[i]), (d), SHARE_rw);    \
      } while ( 0 )
 
  #define gnttab_shared_gmfn(d, t, i)                                      \
xen/include/asm-arm/mm.h +0 -7
index 4d5563b..a0e922f 100644
@@ -159,13 +159,6 @@ extern vaddr_t xenheap_virt_start;
 
  #define maddr_get_owner(ma)   (page_get_owner(maddr_to_page((ma))))
 
-#define XENSHARE_writable 0
-#define XENSHARE_readonly 1
-extern void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly);
-extern void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly);
-
  #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
  /* PDX of the first page in the frame table. */
  extern unsigned long frametable_base_pdx;
xen/include/asm-x86/grant_table.h +2 -4
index 66e9742..8720159 100644
@@ -57,15 +57,13 @@ static inline unsigned int gnttab_dom0_max(void)
  #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);                                     \
+            virt_to_page((char *)(t)->shared_raw[i]), (d), SHARE_rw);    \
      } while ( 0 )
 
  #define gnttab_create_status_page(d, t, i)                               \
      do {                                                                 \
          share_xen_page_with_guest(                                       \
-           virt_to_page((char *)(t)->status[i]),                         \
-            (d), XENSHARE_writable);                                     \
+            virt_to_page((char *)(t)->status[i]), (d), SHARE_rw);        \
      } while ( 0 )
 
 
xen/include/asm-x86/mm.h +0 -8
index 96f3a34..c115661 100644
@@ -292,14 +292,6 @@ struct page_info
 
  #define maddr_get_owner(ma)   (page_get_owner(maddr_to_page((ma))))
 
-#define XENSHARE_writable 0
-#define XENSHARE_readonly 1
-extern void share_xen_page_with_guest(
-    struct page_info *page, struct domain *d, int readonly);
-extern int unshare_xen_page_with_guest(struct page_info *page,
-                                       struct domain *d);
-extern void share_xen_page_with_privileged_guests(
-    struct page_info *page, int readonly);
  extern void free_shared_domheap_page(struct page_info *page);
 
  #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
xen/include/xen/mm.h +14 -0
index 0e0e511..142aa73 100644
@@ -634,4 +634,18 @@ static inline void filtered_flush_tlb_mask(uint32_t tlbflush_timestamp)
      }
  }
 
+enum XENSHARE_flags {
+    SHARE_rw,
+    SHARE_ro,
+};
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags);
+int unshare_xen_page_with_guest(struct page_info *page, struct domain *d);
+
+static inline void share_xen_page_with_privileged_guests(
+    struct page_info *page, enum XENSHARE_flags flags)
+{
+    share_xen_page_with_guest(page, dom_xen, flags);
+}
+
  #endif /* __XEN_MM_H__ */
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#37 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

In reply to Andrew Cooper
Quoted 59 lines · Andrew Cooper

The share_xen_page_with_guest() functions are used by common code, and are implemented the same by each arch. Move the declarations into the common mm.h rather than duplicating them in each arch/mm.h

Turn an int readonly into a boolean enum, to retain ro/rw context at the callsites, but use shorter labels which avoids a large number of split lines.

Implement share_xen_page_with_privileged_guests() as a static inline wrapper around share_xen_page_with_guest() to avoid having a call into a separate translation unit whose only purpose is to shuffle function arguments.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: George Dunlap <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/arm/domain.c             |  3 +--
 xen/arch/arm/mm.c                 | 13 ++++---------
 xen/arch/x86/domain.c             |  3 +--
 xen/arch/x86/hvm/dom0_build.c     |  2 +-
 xen/arch/x86/hvm/vmx/vmx.c        |  2 +-
 xen/arch/x86/mm.c                 | 20 +++++++-------------
 xen/arch/x86/pv/shim.c            |  6 ++----
 xen/arch/x86/x86_64/mm.c          | 16 ++++++----------
 xen/common/trace.c                |  9 +++------
 xen/common/xenoprof.c             |  3 +--
 xen/include/asm-arm/grant_table.h |  3 +--
 xen/include/asm-arm/mm.h          |  7 -------
 xen/include/asm-x86/grant_table.h |  6 ++----
 xen/include/asm-x86/mm.h          |  8 --------
 xen/include/xen/mm.h              | 14 ++++++++++++++
 15 files changed, 44 insertions(+), 71 deletions(-)
xen/arch/arm/domain.c +1 -2
index 4b45fad..23dac5d 100644
@@ -602,8 +602,7 @@ int arch_domain_create(struct domain *d,
         goto fail;
 
     clear_page(d->shared_info);
-    share_xen_page_with_guest(
-        virt_to_page(d->shared_info), d, XENSHARE_writable);
+    share_xen_page_with_guest(virt_to_page(d->shared_info), d, SHARE_rw);
 
     switch ( config->config.gic_version )
     {
xen/arch/arm/mm.c +0 -0
index a09bea2..baa3b0d 100644

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain *d) · line 1191

Quoted 7 lines
xen/arch/arm/mm.c +2 -2
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)

Naming this _flags feels wrong to me, I would assume flags to be something which can be used as (SHARE_r | SHARE_w) (ie: stacked) and so on. I would maybe name this XENSHARE_options rather than flags.

TBH I would be OK with renaming the parameter to "bool ro/readonly" and let the callers use true and false directly. It seems like over-engineering to use an enum for this, or maybe you have further changes in mind that are going to expand the set of options?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#38 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 13:28, <[email protected]> wrote:

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain *d) · line 1191

Quoted 10 lines · Andrew Cooper
xen/arch/arm/mm.c +2 -2
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)

Naming this _flags feels wrong to me, I would assume flags to be something which can be used as (SHARE_r | SHARE_w) (ie: stacked) and so on. I would maybe name this XENSHARE_options rather than flags.

Quoted 4 lines

TBH I would be OK with renaming the parameter to "bool ro/readonly" and let the callers use true and false directly. It seems like over-engineering to use an enum for this, or maybe you have further changes in mind that are going to expand the set of options?

On one hand I agree that an enum like this is somewhat strange to have, and a boolean would seem like a better fit. Otoh using plain true/false at the call sites would make it pretty unclear whether "true" means r/o or r/w. So another option might be to have multiple inline wrappers around the actual worker, like share_xen_page_with_guest_ro().

Nevertheless the x86 parts of the patch can also have

as they currently are.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#39 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

Quoted 20 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 13:28, <[email protected]> wrote:

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain *d) · line 1191

Quoted 10 lines · Andrew Cooper
xen/arch/arm/mm.c +2 -2
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)

Naming this _flags feels wrong to me, I would assume flags to be something which can be used as (SHARE_r | SHARE_w) (ie: stacked) and so on. I would maybe name this XENSHARE_options rather than flags.

Quoted 4 lines

TBH I would be OK with renaming the parameter to "bool ro/readonly" and let the callers use true and false directly. It seems like over-engineering to use an enum for this, or maybe you have further changes in mind that are going to expand the set of options?

Quoted 6 lines

On one hand I agree that an enum like this is somewhat strange to have, and a boolean would seem like a better fit. Otoh using plain true/false at the call sites would make it pretty unclear whether "true" means r/o or r/w. So another option might be to have multiple inline wrappers around the actual worker, like share_xen_page_with_guest_ro().

Splitting into (SHARE_r | SHARE_w( doesn't make sense because the underlying implementation take a boolean idea of whether to use PGT_none or PGT_writable_page.

We've already got share_xen_page_with_privileged_guests() as a wrapper around share_xen_page_with_guest().  Therefore, we'd end up with a total of 4 extra wrappers if we wanted _rw and _ro suffixes, which seems over the top to me.

I agree its not completely great like this, but it is the least bad option I managed to come up with.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#40 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 21:25, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 13:28, <[email protected]> wrote:

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain

Quoted 3 lines · Andrew Cooper
xen/arch/arm/mm.c +0 -0
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain 

*d)

Quoted 15 lines
Quoted 11 lines

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain *d) · line 1191

Quoted 7 lines
xen/arch/arm/mm.c +2 -2
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)

Naming this _flags feels wrong to me, I would assume flags to be something which can be used as (SHARE_r | SHARE_w) (ie: stacked) and so on. I would maybe name this XENSHARE_options rather than flags.

Quoted 4 lines

TBH I would be OK with renaming the parameter to "bool ro/readonly" and let the callers use true and false directly. It seems like over-engineering to use an enum for this, or maybe you have further changes in mind that are going to expand the set of options?

Quoted 6 lines

On one hand I agree that an enum like this is somewhat strange to have, and a boolean would seem like a better fit. Otoh using plain true/false at the call sites would make it pretty unclear whether "true" means r/o or r/w. So another option might be to have multiple inline wrappers around the actual worker, like share_xen_page_with_guest_ro().

Splitting into (SHARE_r | SHARE_w( doesn't make sense because the underlying implementation take a boolean idea of whether to use PGT_none or PGT_writable_page.

Quoted 7 lines

We've already got share_xen_page_with_privileged_guests() as a wrapper around share_xen_page_with_guest(). Therefore, we'd end up with a total of 4 extra wrappers if we wanted _rw and _ro suffixes, which seems over the top to me.

I agree its not completely great like this, but it is the least bad option I managed to come up with.

Well, without wanting put under question the ack I've already given, the question of course is whether the code is much better after the change than it was before. If there's no really good shape to put this in, leaving things as they are is certainly also an option.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#41 lore raw

Re: [PATCH 7/7] xen/mm: Clean up share_xen_page_with_guest() API

Quoted 38 lines · Jan Beulich
Quoted 38 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 21:25, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.03.18 at 13:28, <[email protected]> wrote:

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain

Quoted 3 lines · Andrew Cooper
xen/arch/arm/mm.c +0 -0
@@ -1187,8 +1187,8 @@ unsigned long domain_get_maximum_gpfn(struct domain 

*d)

Quoted 15 lines
Quoted 11 lines

xen/arch/arm/mm.c unsigned long domain_get_maximum_gpfn(struct domain *d) · line 1191

Quoted 7 lines
xen/arch/arm/mm.c +2 -2
     return gfn_x(d->arch.p2m.max_mapped_gfn);
 }
 
-void share_xen_page_with_guest(struct page_info *page,
-                          struct domain *d, int readonly)
+void share_xen_page_with_guest(struct page_info *page, struct domain *d,
+                               enum XENSHARE_flags flags)

Naming this _flags feels wrong to me, I would assume flags to be something which can be used as (SHARE_r | SHARE_w) (ie: stacked) and so on. I would maybe name this XENSHARE_options rather than flags.

Quoted 4 lines

TBH I would be OK with renaming the parameter to "bool ro/readonly" and let the callers use true and false directly. It seems like over-engineering to use an enum for this, or maybe you have further changes in mind that are going to expand the set of options?

Quoted 6 lines

On one hand I agree that an enum like this is somewhat strange to have, and a boolean would seem like a better fit. Otoh using plain true/false at the call sites would make it pretty unclear whether "true" means r/o or r/w. So another option might be to have multiple inline wrappers around the actual worker, like share_xen_page_with_guest_ro().

Splitting into (SHARE_r | SHARE_w( doesn't make sense because the underlying implementation take a boolean idea of whether to use PGT_none or PGT_writable_page.

We've already got share_xen_page_with_privileged_guests() as a wrapper around share_xen_page_with_guest(). Therefore, we'd end up with a total of 4 extra wrappers if we wanted _rw and _ro suffixes, which seems over the top to me.

Quoted 7 lines
Quoted 2 lines

I agree its not completely great like this, but it is the least bad option I managed to come up with.

Well, without wanting put under question the ack I've already given, the question of course is whether the code is much better after the change than it was before. If there's no really good shape to put this in, leaving things as they are is certainly also an option.

The code is in better shape with the change, than without it (common prototypes, share_xen_page_with_privileged_guests() being a wrapper, fewer linebreaks, etc).  I just can't see a way of getting it into a yet-better state.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel