[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 08/21] xen/arm: Initialize the virtual GIC later



Hi Julien,


On 31 July 2014 20:30, Julien Grall <julien.grall@xxxxxxxxxx> wrote:
The virtual GIC may differ between each guest (number of SPIs, emulate GIC
version...). Those informations may not be know when the domain is created
(for instance in case of migration). Therefore, move the VGIC initialization
in a separate function.

Introduce a new DOMCTL for ARM to configure the domain. This has to be called
before setting the maximum number of VCPUs for the guest.

For the moment, only configure the number SPIs. New informations could be
added later.

Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>

---
  Changes in v2:
    - Patch added
---
Âtools/libxc/xc_domain.c      Â| Â12 ++++++++++++
Âtools/libxc/xenctrl.h       Â|  4 ++++
Âtools/libxl/libxl_arch.h      |  3 +++
Âtools/libxl/libxl_arm.c      Â| Â19 +++++++++++++++++++
Âtools/libxl/libxl_dom.c      Â|  4 ++++
Âtools/libxl/libxl_x86.c      Â|  7 +++++++
Âxen/arch/arm/domain.c       Â| Â28 ++++++++++++++++++++++------
Âxen/arch/arm/domctl.c       Â| Â11 +++++++++++
Âxen/arch/arm/setup.c        | Â10 ++++++++--
Âxen/arch/arm/vgic.c        Â| Â10 +++++-----
Âxen/include/asm-arm/domain.h    |  6 ++++++
Âxen/include/asm-arm/vgic.h     |  4 +++-
Âxen/include/public/domctl.h    Â| Â14 ++++++++++++++
Âxen/xsm/flask/hooks.c       Â|  3 +++
Âxen/xsm/flask/policy/access_vectors |Â Â 2 ++
Â15 files changed, 123 insertions(+), 14 deletions(-)

diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 27fe3b6..1348905 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -48,6 +48,18 @@ int xc_domain_create(xc_interface *xch,
  Âreturn 0;
Â}

+#if defined(__arm__) || defined(__arch64__)
Â
Please change __arch64__ to __aarch64__ , otherwise it will break on arm64.

Thanks,
Pranav
Â
+int xc_domain_configure(xc_interface *xch, uint32_t domid,
+Â Â Â Â Â Â Â Â Â Â Â Â uint32_t nr_spis)
+{
+Â Â DECLARE_DOMCTL;
+Â Â domctl.cmd = XEN_DOMCTL_configure_domain;
+Â Â domctl.domain = (domid_t)domid;
+Â Â domctl.u.configuredomain.nr_spis = nr_spis;
+Â Â return do_domctl(xch, &domctl);
+}
+#endif
+
Âint xc_domain_cacheflush(xc_interface *xch, uint32_t domid,
             xen_pfn_t start_pfn, xen_pfn_t nr_pfns)
Â{
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 5beb846..cdda4e5 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -482,6 +482,10 @@ int xc_domain_create(xc_interface *xch,
           uint32_t flags,
           uint32_t *pdomid);

+#if defined(__arm__) || defined(__aarch64__)
+int xc_domain_configure(xc_interface *xch, uint32_t domid,
+Â Â Â Â Â Â Â Â Â Â Â Â uint32_t nr_spis);
+#endif

Â/* Functions to produce a dump of a given domain
 * xc_domain_dumpcore - produces a dump to a specified file
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index d3bc136..454f8db 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -16,6 +16,9 @@
Â#define LIBXL_ARCH_H

Â/* arch specific internal domain creation function */
+int libxl__arch_domain_create_pre(libxl__gc *gc, libxl_domain_config *d_config,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__domain_build_state *state,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint32_t domid);
Âint libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
        uint32_t domid);

diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index e19e2f4..b0491c3 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -23,6 +23,25 @@
Â#define DT_IRQ_TYPE_LEVEL_HIGHÂ Â Â0x00000004
Â#define DT_IRQ_TYPE_LEVEL_LOWÂ Â Â 0x00000008

+int libxl__arch_domain_create_pre(libxl__gc *gc, libxl_domain_config *d_config,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__domain_build_state *state,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint32_t domid)
+{
+Â Â uint32_t nr_spis = 0;
+
+Â Â nr_spis += d_config->b_info.num_irqs;
+
+Â Â LOG(DEBUG, "Allocate %u SPIs\n", nr_spis);
+
+Â Â if (xc_domain_configure(CTX->xch, domid, nr_spis) != 0) {
+Â Â Â Â LOG(ERROR, "Couldn't configure the domain");
+Â Â Â Â return ERROR_FAIL;
+Â Â }
+
+Â Â return 0;
+}
+
+
Âint libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
               Âuint32_t domid)
Â{
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index c944804..a0e4e34 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -235,6 +235,10 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
  Âchar *xs_domid, *con_domid;
  Âint rc;

+Â Â rc = libxl__arch_domain_create_pre(gc, d_config, state, domid);
+Â Â if (rc != 0)
+Â Â Â Â return rc;
+
  Âif (xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus) != 0) {
    ÂLOG(ERROR, "Couldn't set max vcpu count");
    Âreturn ERROR_FAIL;
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index 7589060..0abc1aa 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -244,6 +244,13 @@ static int libxl__e820_alloc(libxl__gc *gc, uint32_t domid,
  Âreturn 0;
Â}

+int libxl__arch_domain_create_pre(libxl__gc *gc, libxl_domain_config *d_config,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__domain_build_state *state,
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint32_t domid)
+{
+Â Â return 0;
+}
+
Âint libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
    Âuint32_t domid)
Â{
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index aa4a8d7..fc97f8c 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -472,6 +472,13 @@ int vcpu_initialise(struct vcpu *v)
  Âif ( is_idle_vcpu(v) )
    Âreturn rc;

+Â Â /* We can't initialize the VCPU if the VGIC has not been correctly
+Â Â Â* initialized.
+Â Â Â*/
+Â Â rc = -ENXIO;
+Â Â if ( !domain_vgic_is_initialized(v->domain) )
+Â Â Â Â goto fail;
+
  Âv->arch.sctlr = SCTLR_GUEST_INIT;

  Â/*
@@ -534,12 +541,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
  Âif ( (rc = p2m_alloc_table(d)) != 0 )
    Âgoto fail;

-Â Â if ( (rc = gicv_setup(d)) != 0 )
-Â Â Â Â goto fail;
-
-Â Â if ( (rc = domain_vgic_init(d)) != 0 )
-Â Â Â Â goto fail;
-
  Âif ( (rc = domain_vtimer_init(d)) != 0 )
    Âgoto fail;

@@ -580,6 +581,21 @@ void arch_domain_destroy(struct domain *d)
  Âfree_xenheap_page(d->shared_info);
Â}

+int domain_configure_vgic(struct domain *d, unsigned int nr_spis)
+{
+Â Â int rc;
+
+Â Â if ( (rc = gicv_setup(d)) != 0 )
+Â Â Â Â return rc;
+
+Â Â if ( (rc = domain_vgic_init(d, nr_spis)) != 0 )
+Â Â Â Â return rc;
+
+Â Â d->arch.vgic.initialized = 1;
+
+Â Â return 0;
+}
+
Âstatic int is_guest_pv32_psr(uint32_t psr)
Â{
  Âswitch (psr & PSR_MODE_MASK)
diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 45974e7..bab92b2 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -30,6 +30,17 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,

    Âreturn p2m_cache_flush(d, s, e);
  Â}
+Â Â case XEN_DOMCTL_configure_domain:
+Â Â {
+Â Â Â Â if ( domain_vgic_is_initialized(d) )
+Â Â Â Â Â Â return -EBUSY;
+
+Â Â Â Â /* Sanity check on the number of SPIs */
+Â Â Â Â if ( domctl->u.configuredomain.nr_spis > (gic_number_lines() - 32) )
+Â Â Â Â Â Â return -EINVAL;
+
+Â Â Â Â return domain_configure_vgic(d, domctl->u.configuredomain.nr_spis);
+Â Â }

  Âdefault:
    Âreturn subarch_do_domctl(domctl, d, u_domctl);
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 446b4dc..2be7dd1 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -840,8 +840,14 @@ void __init start_xen(unsigned long boot_phys_offset,

  Â/* Create initial domain 0. */
  Âdom0 = domain_create(0, 0, 0);
-Â Â if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) )
-Â Â Â Â Â Â panic("Error creating domain 0");
+Â Â if ( IS_ERR(dom0) )
+Â Â Â Â panic("Error creating domain 0");
+
+Â Â if ( domain_configure_vgic(dom0, gic_number_lines() - 32) )
+Â Â Â Â Âpanic("Error configure the vgic for domain 0");
+
+Â Â if ( alloc_dom0_vcpu0(dom0) == NULL )
+Â Â Â Â panic("Error create vcpu0 for domain 0");

  Âdom0->is_privileged = 1;
  Âdom0->target = NULL;
diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
index 17cde7a..a037ecc 100644
--- a/xen/arch/arm/vgic.c
+++ b/xen/arch/arm/vgic.c
@@ -60,16 +60,16 @@ static void vgic_init_pending_irq(struct pending_irq *p, unsigned virq)
  Âp->irq = virq;
Â}

-int domain_vgic_init(struct domain *d)
+int domain_vgic_init(struct domain *d, unsigned int nr_spis)
Â{
  Âint i;

  Âd->arch.vgic.ctlr = 0;

-Â Â if ( is_hardware_domain(d) )
-Â Â Â Â d->arch.vgic.nr_spis = gic_number_lines() - 32;
-Â Â else
-Â Â Â Â d->arch.vgic.nr_spis = 0; /* We don't need SPIs for the guest */
+Â Â /* The number of SPIs as to be aligned to 32 see
+Â Â Â* GICD_TYPER.ITLinesNumber definition
+Â Â Â*/
+Â Â d->arch.vgic.nr_spis = ROUNDUP(nr_spis, 32);

  Âswitch ( gic_hw_version() )
  Â{
diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
index 5719fe5..44727b2 100644
--- a/xen/include/asm-arm/domain.h
+++ b/xen/include/asm-arm/domain.h
@@ -76,6 +76,10 @@ struct arch_domain
  Â} virt_timer_base;

  Âstruct {
+Â Â Â Â /* The VGIC initialization is defered to let the toolstack
+Â Â Â Â Â* configure the emulated GIC (such as number of SPIs, version...)
+Â Â Â Â Â*/
+Â Â Â Â bool_t initialized;
    Â/* GIC HW version specific vGIC driver handler */
    Âconst struct vgic_ops *handler;
    Â/*
@@ -241,6 +245,8 @@ struct arch_vcpu
Âvoid vcpu_show_execution_state(struct vcpu *);
Âvoid vcpu_show_registers(const struct vcpu *);

+int domain_configure_vgic(struct domain *d, unsigned int spis_number);
+
Â#endif /* __ASM_DOMAIN_H__ */

Â/*
diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h
index 5ddc681..84ae441 100644
--- a/xen/include/asm-arm/vgic.h
+++ b/xen/include/asm-arm/vgic.h
@@ -148,6 +148,8 @@ static inline void vgic_byte_write(uint32_t *reg, uint32_t var, int offset)
  Â*reg |= var;
Â}

+#define domain_vgic_is_initialized(d) ((d)->arch.vgic.initialized)
+
Âenum gic_sgi_mode;

Â/*
@@ -158,7 +160,7 @@ enum gic_sgi_mode;

Â#define vgic_num_irqs(d)Â Â Â Â ((d)->arch.vgic.nr_spis + 32)

-extern int domain_vgic_init(struct domain *d);
+extern int domain_vgic_init(struct domain *d, unsigned int nr_spis);
Âextern void domain_vgic_free(struct domain *d);
Âextern int vcpu_vgic_init(struct vcpu *v);
Âextern struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq);
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 5b11bbf..b5f2ed7 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -67,6 +67,16 @@ struct xen_domctl_createdomain {
Âtypedef struct xen_domctl_createdomain xen_domctl_createdomain_t;
ÂDEFINE_XEN_GUEST_HANDLE(xen_domctl_createdomain_t);

+#if defined(__arm__) || defined(__aarch64__)
+/* XEN_DOMCTL_configure_domain */
+struct xen_domctl_configuredomain {
+Â Â /* IN parameters */
+Â Â uint32_t nr_spis;
+};
+typedef struct xen_domctl_configuredomain xen_domctl_configuredomain_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_configuredomain_t);
+#endif
+
Â/* XEN_DOMCTL_getdomaininfo */
Âstruct xen_domctl_getdomaininfo {
  Â/* OUT variables. */
@@ -1008,6 +1018,7 @@ struct xen_domctl {
Â#define XEN_DOMCTL_cacheflush          71
Â#define XEN_DOMCTL_get_vcpu_msrs        Â72
Â#define XEN_DOMCTL_set_vcpu_msrs        Â73
+#define XEN_DOMCTL_configure_domain       74
Â#define XEN_DOMCTL_gdbsx_guestmemio      1000
Â#define XEN_DOMCTL_gdbsx_pausevcpu      Â1001
Â#define XEN_DOMCTL_gdbsx_unpausevcpu     Â1002
@@ -1016,6 +1027,9 @@ struct xen_domctl {
  Âdomid_t domain;
  Âunion {
    Âstruct xen_domctl_createdomain   createdomain;
+#if defined(__arm__) || defined(__aarch64__)
+    struct xen_domctl_configuredomain Âconfiguredomain;
+#endif
    Âstruct xen_domctl_getdomaininfo  Âgetdomaininfo;
    Âstruct xen_domctl_getmemlist    getmemlist;
    Âstruct xen_domctl_getpageframeinfo getpageframeinfo;
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index f2f59ea..4759461 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -715,6 +715,9 @@ static int flask_domctl(struct domain *d, int cmd)
  Âcase XEN_DOMCTL_cacheflush:
    Âreturn current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__CACHEFLUSH);

+Â Â case XEN_DOMCTL_configure_domain:
+Â Â Â Â return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__CONFIGURE_DOMAIN);
+
  Âdefault:
    Âprintk("flask_domctl: Unknown op %d\n", cmd);
    Âreturn -EPERM;
diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors
index 32371a9..33eec66 100644
--- a/xen/xsm/flask/policy/access_vectors
+++ b/xen/xsm/flask/policy/access_vectors
@@ -200,6 +200,8 @@ class domain2
  Âcacheflush
Â# Creation of the hardware domain when it is not dom0
  Âcreate_hardware_domain
+# XEN_DOMCTL_configure_domain
+Â Â configure_domain
Â}

Â# Similar to class domain, but primarily contains domctls related to HVM domains
--
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.