@@ -971,9 +971,9 @@ void __init create_domUs(void)
panic("'llc-colors' found, but LLC coloring is disabled\n");
/*
- * The variable max_init_domid is initialized with zero, so here it's
- * very important to use the pre-increment operator to call
- * domain_create() with a domid > 0. (domid == 0 is reserved for Dom0)
+ * NB: it's very important to use the pre-increment operator to call
+ * domain_create() with a domid > get_initial_domain_id().
+ * domid == get_initial_domain_id() is reserved for Dom0.
*/
d = domain_create(++max_init_domid, &d_cfg, flags);
if ( IS_ERR(d) )
@@ -2357,6 +2357,7 @@ void __init create_dom0(void)
.grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version),
};
unsigned int flags = CDF_privileged;
+ domid_t domid = get_initial_domain_id();
int rc;
/* The vGIC for DOM0 is exactly emulating the hardware GIC */
@@ -2387,15 +2388,15 @@ void __init create_dom0(void)
if ( !llc_coloring_enabled )
flags |= CDF_directmap;
- dom0 = domain_create(0, &dom0_cfg, flags);
+ dom0 = domain_create(domid, &dom0_cfg, CDF_privileged | CDF_directmap);
if ( IS_ERR(dom0) )
- panic("Error creating domain 0 (rc = %ld)\n", PTR_ERR(dom0));
+ panic("Error creating domain %d (rc = %ld)\n", domid, PTR_ERR(dom0));
if ( llc_coloring_enabled && (rc = dom0_set_llc_colors(dom0)) )
panic("Error initializing LLC coloring for domain 0 (rc = %d)\n", rc);
if ( alloc_dom0_vcpu0(dom0) == NULL )
- panic("Error creating domain 0 vcpu0\n");
+ panic("Error creating domain %d vcpu0\n", domid);
rc = construct_dom0(dom0);
if ( rc )
@@ -25,8 +25,6 @@ struct map_range_data
struct rangeset *irq_ranges;
};
-extern domid_t max_init_domid;
-
void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
size_t estimate_efi_size(unsigned int mem_nr_banks);
@@ -60,8 +60,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;
bool __read_mostly acpi_disabled;
#endif
-domid_t __read_mostly max_init_domid;
-
static __used void init_done(void)
{
int rc;
@@ -1,6 +1,4 @@
#ifndef __ASM_PPC_SETUP_H__
#define __ASM_PPC_SETUP_H__
-#define max_init_domid (0)
-
#endif /* __ASM_PPC_SETUP_H__ */
@@ -5,8 +5,6 @@
#include <xen/types.h>
-#define max_init_domid (0)
-
void setup_mm(void);
void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
@@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data);
long cf_check pv_shim_cpu_down(void *data);
void pv_shim_online_memory(unsigned int nr, unsigned int order);
void pv_shim_offline_memory(unsigned int nr, unsigned int order);
-domid_t get_initial_domain_id(void);
+domid_t pv_shim_get_initial_domain_id(void);
uint64_t pv_shim_mem(uint64_t avail);
void pv_shim_fixup_e820(void);
const struct platform_bad_page *pv_shim_reserved_pages(unsigned int *size);
@@ -76,8 +76,9 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order)
{
ASSERT_UNREACHABLE();
}
-static inline domid_t get_initial_domain_id(void)
+static inline domid_t pv_shim_get_initial_domain_id(void)
{
+ ASSERT_UNREACHABLE();
return 0;
}
static inline uint64_t pv_shim_mem(uint64_t avail)
@@ -69,6 +69,4 @@ extern bool opt_dom0_verbose;
extern bool opt_dom0_cpuid_faulting;
extern bool opt_dom0_msr_relaxed;
-#define max_init_domid (0)
-
#endif
@@ -1018,13 +1018,10 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order)
}
}
-domid_t get_initial_domain_id(void)
+domid_t pv_shim_get_initial_domain_id(void)
{
uint32_t eax, ebx, ecx, edx;
- if ( !pv_shim )
- return 0;
-
cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx);
return (eax & XEN_HVM_CPUID_DOMID_PRESENT) ? ecx : 1;
@@ -43,6 +43,9 @@
#include <xsm/xsm.h>
#include <xen/trace.h>
#include <asm/setup.h>
+#ifdef CONFIG_PV_SHIM
+#include <asm/pv/shim.h>
+#endif
#ifdef CONFIG_X86
#include <asm/guest.h>
@@ -65,6 +68,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);
static struct domain *domain_hash[DOMAIN_HASH_SIZE];
struct domain *domain_list;
+/* Last known non-system domain ID. */
+domid_t __read_mostly max_init_domid;
+
/*
* Insert a domain into the domlist/hash. This allows the domain to be looked
* up by domid, and therefore to be the subject of hypercalls/etc.
@@ -2261,6 +2267,15 @@ int continue_hypercall_on_cpu(
return 0;
}
+domid_t get_initial_domain_id(void)
+{
+#ifdef CONFIG_PV_SHIM
+ if ( pv_shim )
+ return pv_shim_get_initial_domain_id();
+#endif
+ return hardware_domid;
+}
+
/*
* Local variables:
* mode: C
@@ -415,10 +415,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
case XEN_DOMCTL_createdomain:
{
domid_t dom;
- static domid_t rover = 0;
dom = op->domain;
- if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) )
+ if ( (dom > max_init_domid) && (dom < DOMID_FIRST_RESERVED) )
{
ret = -EEXIST;
if ( !is_free_domid(dom) )
@@ -426,19 +425,19 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
}
else
{
- for ( dom = rover + 1; dom != rover; dom++ )
+ for ( dom = max_init_domid + 1; dom != max_init_domid; dom++ )
{
if ( dom == DOMID_FIRST_RESERVED )
- dom = 1;
+ dom = max_init_domid + 1;
if ( is_free_domid(dom) )
break;
}
ret = -ENOMEM;
- if ( dom == rover )
+ if ( dom == max_init_domid )
break;
- rover = dom;
+ max_init_domid = dom;
}
d = domain_create(dom, &op->u.createdomain, false);
@@ -568,6 +568,14 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
return sz;
}
+static int __init cf_check globals_init(void)
+{
+ max_init_domid = get_initial_domain_id();
+
+ return 0;
+}
+__initcall(globals_init);
+
long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
{
bool deny = xsm_xen_version(XSM_OTHER, cmd);
@@ -175,4 +175,8 @@ extern bool vmtrace_available;
extern bool vpmu_is_available;
+extern domid_t max_init_domid;
+
+domid_t get_initial_domain_id(void);
+
#endif /* __XEN_DOMAIN_H__ */