xen/arm: Add support for non-pci passthrough
v3 cover xen/arm: Add support for non-pci passthrough
Hello all,
This is the third version of this patch series to add support for platform device passthrough on ARM.
Compare to the previous version [1], the automatic mapping of MMIO/IRQ and the generation of the device tree has been dropped.
Instead the user will have to:
- Map manually MMIO/IRQ
- Describe the device in the newly partial device tree support
- Specify the list of device protected by an IOMMU to assign to the guest.
While this solution is primitive, this is allow us to support more complex device in Xen with an little additionnal work for the user. Attempting to do it automatically is more difficult because we may not know the dependencies between devices (for instance a Network card and a phy).
To avoid adding code in DOM0 to manage platform device deassignment, the user has to add the property "xen,passthrough" to the device tree node describing the device. This can be easily done via U-Boot. For instance, if we want to passthrough the second network card of a Midway server to the guest. The user will have to add the following line the u-boot script:
fdt set /soc/ethernet@fff51000 xen,passthrough
This series has been tested on Midway by assigning the secondary network card to a guest (see instruction below). I plan to do futher testing on other boards.
There is some TODO, mostly related to XSM in different patches (see commit message or /* TODO: ... */ in the files).
This series is based on my series "Find automatically a PPI for DOM0 event channel IRQ" [2] and "xen/arm: Resync the SMMU driver with the Linux one" [3]. A working tree can be found here:
git://xenbits.xen.org/julieng/xen-unstable.git branch passthrough-v3
Major changes in v3:
- Rework the approach to passthrough a device (xen,passthrough + partial device tree).
- Extend the existing hypercalls to assign/deassign device rather than adding new one.
- Merge series [4] and [5] in this serie.
Major changes in v2:
- Drop the patch #1 of the previous version
- Virtual IRQ are not anymore equal to the physical interrupt
- Move the hypercall to get DT informations for privcmd to domctl
- Split the domain creation in 2 two parts to allow per guest VGIC configuration (such as the number of SPIs).
- Bunch of typoes, commit improvement, function renaming.
For all changes see in each patch.
I believe, it's better to have a basic support in Xen rather than nothing. This could be improved later.
Sincerely yours,
[1] http://lists.xen.org/archives/html/xen-devel/2014-07/msg04090.html
[2] http://lists.xenproject.org/archives/html/xen-devel/2014-12/msg01386.html
[3] http://lists.xenproject.org/archives/html/xen-devel/2014-12/msg01612.html
[4] http://lists.xen.org/archives/html/xen-devel/2014-11/msg01672.html
[5] http://lists.xenproject.org/archives/html/xen-devel/2014-07/msg02098.html
=========================================================================
Instructions to passthrough a non-PCI device
The example will use the secondary network card for the midway server.
1) Mark the device to let Xen knowns the device will be used for passthrough. This is done in the device tree node describing the device by adding the property "xen,passthrough". The command to do it in U-Boot is:
fdt set /soc/ethernet@fff51000 xen,passthrough
2) Create the partial device tree describing the device. The IRQ are mapped 1:1 to the guest (i.e VIRQ == IRQ). For MMIO will have to find hole in the guest memory layout (see xen/include/public/arch-arm.h, noted the layout is not stable and can change between 2 releases version of Xen).
/dts-v1/;
/ {
#address-cells = <2>;
#size-cells = <2>;
aliases {
net = &mac0;
};
passthrough {
compatible = "simple-bus";
ranges;
#address-cells = <2>;
#size-cells = <2>;
mac0: ethernet@10000000 {
compatible = "calxeda,hb-xgmac";
reg = <0 0x10000000 0 0x1000>;
interrupts = <0 80 4 0 81 4 0 82 4>;
/* dma-coherent can't be set because it requires platform
* specific code for highbank
*/
/* dma-coherent; */
};
foo {
my = <&mac0>;
};
};
};3) Compile the partial guest device with dtc (Device Tree Compiler). For our purpose, the compiled file will be called guest-midway.dtb and placed in /root in DOM0.
3) Add the following options in the guest configuration file:
device_tree = "/root/guest-midway.dtb"
dtdev = [ "/soc/ethernet@fff51000" ]
irqs = [ 112, 113, 114 ]
iomem = [ "0xfff51,1@0x10000" ]
Julien Grall (24):
xen: Extend DOMCTL createdomain to support arch configuration xen/arm: Divide GIC initialization in 2 parts
xen/dts: Allow only IRQ translation that are mapped to main GIC
xen: guestcopy: Provide an helper to safely copy string from guest xen/arm: vgic: Introduce a function to initialize pending_irq xen/arm: Map disabled device in DOM0
xen/arm: Introduce xen,passthrough property
xen/arm: Allow virq != irq
xen/arm: route_irq_to_guest: Check validity of the IRQ xen/arm: gic: Add sanity checks gic_route_irq_to_guest xen/arm: Let the toolstack configure the number of SPIs xen/arm: Release IRQ routed to a domain when it's destroying xen/arm: Implement hypercall PHYSDEVOP_{,un}map_pirq xen/dts: Use unsigned int for MMIO and IRQ index
xen/dts: Provide an helper to get a DT node from a path provided by a
guest
xen/passthrough: Introduce iommu_construct xen/passthrough: arm: release earlier the DT devices assigned to a
guest
xen/passthrough: iommu_deassign_device_dt: By default reassign device
to nobody
xen/iommu: arm: Wire iommu DOMCTL for ARM
xen/passthrough: Extend XEN_DOMCTL_assign_device to support DT device tools/(lib)xl: Add partial device tree support for ARM tools/libxl: arm: Use an higher value for the GIC phandle
libxl: Add support for non-PCI passthrough
xl: Add new option dtdev
docs/man/xl.cfg.pod.5 | 12 ++ docs/misc/arm/device-tree/passthrough.txt | 7 + tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/libxc/include/xenctrl.h | 24 ++- tools/libxc/xc_domain.c | 142 ++++++++++-- tools/libxl/Makefile | 2 +- tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 309 +++++++++++++++++++++++++-- tools/libxl/libxl_create.c | 31 ++- tools/libxl/libxl_dm.c | 3 +- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_dtdev.c | 34 +++ tools/libxl/libxl_internal.h | 12 +- tools/libxl/libxl_types.idl | 6 + tools/libxl/libxl_x86.c | 10 + tools/libxl/xl_cmdimpl.c | 22 +- xen/arch/arm/device.c | 2 +- xen/arch/arm/domain.c | 39 +++- xen/arch/arm/domain_build.c | 119 +++++++---- xen/arch/arm/domctl.c | 37 +--- xen/arch/arm/gic-v2.c | 70 +++--- xen/arch/arm/gic-v3.c | 75 +++---- xen/arch/arm/gic.c | 97 ++++++++- xen/arch/arm/irq.c | 163 ++++++++++++-- xen/arch/arm/mm.c | 6 +- xen/arch/arm/physdev.c | 136 +++++++++++- xen/arch/arm/platforms/omap5.c | 12 -- xen/arch/arm/platforms/xgene-storm.c | 2 +- xen/arch/arm/setup.c | 10 +- xen/arch/arm/vgic.c | 65 +++--- xen/arch/x86/domain.c | 3 +- xen/arch/x86/mm.c | 6 +- xen/arch/x86/setup.c | 8 +- xen/common/Makefile | 1 + xen/common/device_tree.c | 44 +++- xen/common/domain.c | 7 +- xen/common/domctl.c | 3 +- xen/common/guestcopy.c | 30 +++ xen/common/schedule.c | 3 +- xen/drivers/passthrough/arm/iommu.c | 7 +- xen/drivers/passthrough/arm/smmu.c | 8 +- xen/drivers/passthrough/device_tree.c | 115 +++++++++- xen/drivers/passthrough/iommu.c | 26 +++ xen/drivers/passthrough/pci.c | 58 +++-- xen/include/asm-arm/domain.h | 2 + xen/include/asm-arm/gic.h | 18 +- xen/include/asm-arm/irq.h | 8 +- xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 8 +- xen/include/public/arch-arm.h | 10 + xen/include/public/arch-x86/xen.h | 4 + xen/include/public/domctl.h | 33 ++- xen/include/xen/device_tree.h | 35 ++- xen/include/xen/domain.h | 3 +- xen/include/xen/guest_access.h | 5 + xen/include/xen/iommu.h | 7 +- xen/include/xen/sched.h | 9 +- xen/xsm/flask/flask_op.c | 43 +--- xen/xsm/flask/hooks.c | 3 - xen/xsm/flask/policy/access_vectors | 2 - 60 files changed, 1570 insertions(+), 397 deletions(-) create mode 100644 docs/misc/arm/device-tree/passthrough.txt create mode 100644 tools/libxl/libxl_dtdev.c create mode 100644 xen/common/guestcopy.c
Signature · 1 line
2.1.4
PATCH v3 1/24 xen: Extend DOMCTL createdomain to support arch configuration
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation and can never change.
For now only the gic_version is set. In long run, there will be more parameters such as the number of SPIs. All will be required to be set at the same time.
A new arch-specific structure arch_domainconfig has been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.
Some external tools (qemu, xenstore) may require to create a domain. Rather than asking them to take care of the arch-specific domain configuration, let the current function (xc_domain_create) to chose a default configuration and introduce a new one (xc_domain_create_config).
This patch also drop the previously DOMCTL arm_configure_domain introduced in Xen 4.5, as it has been made useless.
---
This is a follow-up of http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.html
TODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
For the xc_domain_create, Stefano S. was looking to drop PV domain creation support in QEMU. So maybe I could simply extend xc_domain_create and drop the xc_domain_create_config.
Changes in v3:
- Patch was previously sent in a separate series [1]
- Rename arch_domainconfig to xen_arch_domainconfig
- Drop the typedef
- Pass NULL for DOM0 config on x86
- Drop spurious changes
- Update comment in start_xen in arch/arm/setup.c
[1] https://patches.linaro.org/41083/
--- tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/libxc/include/xenctrl.h | 14 +++++---- tools/libxc/xc_domain.c | 46 ++++++++++++++++------------ tools/libxl/libxl_arch.h | 6 ++++ tools/libxl/libxl_arm.c | 28 ++++++++++------- tools/libxl/libxl_create.c | 21 ++++++++++--- tools/libxl/libxl_dm.c | 3 +- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_internal.h | 7 +++-- tools/libxl/libxl_x86.c | 10 ++++++ xen/arch/arm/domain.c | 28 ++++++++++++++++- xen/arch/arm/domctl.c | 34 -------------------- xen/arch/arm/mm.c | 6 ++-- xen/arch/arm/setup.c | 6 +++- xen/arch/x86/domain.c | 3 +- xen/arch/x86/mm.c | 6 ++-- xen/arch/x86/setup.c | 8 +++-- xen/common/domain.c | 7 +++-- xen/common/domctl.c | 3 +- xen/common/schedule.c | 3 +- xen/include/public/arch-arm.h | 8 +++++ xen/include/public/arch-x86/xen.h | 4 +++ xen/include/public/domctl.h | 18 +---------- xen/include/xen/domain.h | 3 +- xen/include/xen/sched.h | 9 ++++-- xen/xsm/flask/hooks.c | 3 -- xen/xsm/flask/policy/access_vectors | 2 -- 27 files changed, 170 insertions(+), 120 deletions(-)
tools/flask/policy/policy/modules/xen/xen.if +1 -1
@@ -51,7 +51,7 @@ define(`create_domain_common', ` getaffinity setaffinity setvcpuextstate }; allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim set_max_evtchn set_vnumainfo get_vnumainfo cacheflush - psr_cmt_op configure_domain }; + psr_cmt_op }; allow $1 $2:security check_context; allow $1 $2:shadow enable; allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
tools/libxc/include/xenctrl.h +8 -6
@@ -477,18 +477,20 @@ typedef union } start_info_any_t;#endif + +typedef struct xen_arch_domainconfig xc_domain_configuration_t ; +int xc_domain_create_config (xc_interface *xch, +uint32_t ssidref, +xen_domain_handle_t handle, +uint32_t flags, +uint32_t *pdomid, +xc_domain_configuration_t *config);int xc_domain_create (xc_interface *xch,uint32_t ssidref,xen_domain_handle_t handle,uint32_t flags,uint32_t *pdomid); -#if defined(__arm__) || defined(__aarch64__) -typedef xen_domctl_arm_configuredomain_t xc_domain_configuration_t ; - -int xc_domain_configure (xc_interface *xch,uint32_t domid, -xc_domain_configuration_t *config); -#endif /* Functions to produce a dump of a given domain * xc_domain_dumpcore - produces a dump to a specified file
tools/libxc/xc_domain.c +27 -19
70 lines not on this page · raw message
tools/libxl/libxl_arch.h +6 -0
@@ -15,6 +15,11 @@#ifndef LIBXL_ARCH_H #define LIBXL_ARCH_H +/* fill the arch specific configuration for the domain */ +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config); +/* arch specific internal domain creation function */ int libxl__arch_domain_create (libxl__gc *gc,libxl_domain_config *d_config,uint32_t domid);
@@ -22,6 +27,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,/* setup arch specific hardware description, i.e. DTB on ARM */ int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom);/* finalize arch specific hardware description. */ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,
tools/libxl/libxl_arm.c +17 -11
@@ -35,6 +35,15 @@ static const char *gicv_to_string(uint8_t gic_version) } } +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config) +{ + xc_config->gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + +return 0 ; +} +int libxl__arch_domain_create (libxl__gc *gc,libxl_domain_config *d_config,uint32_t domid) {
@@ -516,9 +525,9 @@ out:int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom) { -xc_domain_configuration_t config;void *fdt =NULL ;int rc, res;size_t fdt_size =0 ;
@@ -526,6 +535,9 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,const libxl_version_info *vers;const struct arch_info *ainfo; +/* convenience aliases */ +xc_domain_configuration_t *xc_config = &state->config; +assert (info->type ==LIBXL_DOMAIN_TYPE_PV ); vers =libxl_get_version_info (CTX );
@@ -534,16 +546,9 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc, ainfo =get_arch_info (gc, dom);if (ainfo ==NULL )return ERROR_FAIL ; -LOG (DEBUG ,"configure the domain" ); - config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; -if (xc_domain_configure (CTX ->xch, dom->guest_domid, &config) !=0 ) { -LOG (ERROR ,"couldn't configure the domain" ); -return ERROR_FAIL ; - } -LOG (DEBUG ,"constructing DTB for Xen version %d.%d guest" , vers->xen_version_major, vers->xen_version_minor); -LOG (DEBUG ," - vGIC version: %s" ,gicv_to_string (config.gic_version)); +LOG (DEBUG ," - vGIC version: %s\n" ,gicv_to_string (xc_config->gic_version));/* * Call "call" handling FDT_ERR_*. Will either:
@@ -592,7 +597,7 @@ next_resize:FDT (make_memory_nodes (gc, fdt, dom) ); -switch (config.gic_version) { +switch (xc_config->gic_version) {case XEN_DOMCTL_CONFIG_GIC_V2 : FDT( make_gicv2_node(gc, fdt, GUEST_GICD_BASE, GUEST_GICD_SIZE,
@@ -602,7 +607,8 @@ next_resize:FDT (make_gicv3_node (gc, fdt) );break ;default : -LOG (ERROR ,"Unknown GIC version %d" , config.gic_version); +LOG (ERROR ,"Unknown GIC version %s" , +gicv_to_string (xc_config->gic_version)); rc =ERROR_FAIL ; goto out; }
tools/libxl/libxl_create.c +17 -4
@@ -489,8 +489,8 @@ out:return ret; } -int libxl__domain_make (libxl__gc *gc,libxl_domain_create_info *info, -uint32_t *domid) +int libxl__domain_make (libxl__gc *gc,libxl_domain_config *d_config, +uint32_t *domid,xc_domain_configuration_t *xc_config) {libxl_ctx *ctx =libxl__gc_owner (gc);int flags, ret, rc, nb_vm;
@@ -503,6 +503,8 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,xen_domain_handle_t handle;libxl_vminfo *vm_list; +/* convenience aliases */ +libxl_domain_create_info *info = &d_config->c_info;assert (!libxl_domid_valid_guest (*domid));
@@ -531,7 +533,16 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,/* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy (ctx, (libxl_uuid *)handle, &info->uuid); - ret =xc_domain_create (ctx->xch, info->ssidref, handle, flags, domid); + ret =libxl__arch_domain_prepare_config (gc, d_config, xc_config); +if (ret <0 ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"fail to get domain config" ); + rc =ERROR_FAIL ; + goto out; + } + + ret =xc_domain_create_config (ctx->xch, info->ssidref, + handle, flags, domid, + xc_config);if (ret <0 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"domain creation fail" ); rc =ERROR_FAIL ;
@@ -764,9 +775,11 @@ static void initiate_domain_create(libxl__egc *egc,/* convenience aliases */ libxl_domain_config *const d_config = dcs->guest_config; +libxl__domain_build_state *const state = &dcs->build_state;const int restore_fd = dcs->restore_fd;memset (&dcs->build_state,0 ,sizeof (dcs->build_state)); + domid =0 ;if (d_config->c_info.ssid_label) {
@@ -848,7 +861,7 @@ static void initiate_domain_create(libxl__egc *egc, ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info);if (ret) goto error_out; - ret =libxl__domain_make (gc, &d_config->c_info, &domid); + ret =libxl__domain_make (gc, d_config, &domid, &state->config);if (ret) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"cannot make domain: %d" , ret); dcs->guest_domid = domid;
tools/libxl/libxl_dm.c +2 -1
@@ -1063,7 +1063,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) stubdom_state->pv_ramdisk.path ="" ;/* fixme: this function can leak the stubdom if it fails */ - ret =libxl__domain_make (gc, &dm_config->c_info, &sdss->pvqemu.guest_domid); + ret =libxl__domain_make (gc, dm_config, &sdss->pvqemu.guest_domid, + &stubdom_state->config);if (ret) goto out;uint32_t dm_domid = sdss->pvqemu.guest_domid;
tools/libxl/libxl_dom.c +1 -1
@@ -586,7 +586,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,LOGE (ERROR ,"xc_dom_parse_image failed" ); goto out; } -if ( (ret =libxl__arch_domain_init_hw_description (gc, info, dom)) !=0 ) { +if ( (ret =libxl__arch_domain_init_hw_description (gc, info, state, dom)) !=0 ) {LOGE (ERROR ,"libxl__arch_domain_init_hw_description failed" ); goto out; }
tools/libxl/libxl_internal.h +5 -2
@@ -973,6 +973,8 @@ typedef struct {libxl__file_reference pv_ramdisk;const char * pv_cmdline;bool pvh_enabled; + +xc_domain_configuration_t config; } libxl__domain_build_state; _hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,
@@ -1462,8 +1464,9 @@ _hidden void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,/* on entry, libxl_domid_valid_guest(domid) must be false; * on exit (even error exit), domid may be valid and refer to a domain */ _hidden int libxl__domain_make(libxl__gc *gc, -libxl_domain_create_info *info, -uint32_t *domid); +libxl_domain_config *d_config, +uint32_t *domid, +xc_domain_configuration_t *xc_config); _hidden int libxl__domain_build(libxl__gc *gc, libxl_domain_config *d_config,
tools/libxl/libxl_x86.c +10 -0
@@ -1,6 +1,15 @@#include "libxl_internal.h" #include "libxl_arch.h" +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config) +{ +/* No specific configuration right now */ + +return 0 ; +} +static const char *e820_names (int type) {switch (type) {
@@ -313,6 +322,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom) {return 0 ;
xen/arch/arm/domain.c +27 -1
@@ -504,9 +504,11 @@ void vcpu_destroy(struct vcpu *v)free_xenheap_pages (v->arch.stack,STACK_ORDER ); } -int arch_domain_create (struct domain *d,unsigned int domcr_flags) +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config) {int rc; +uint8_t gic_version; d->arch.relmem = RELMEM_not_started;
@@ -514,6 +516,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if (is_idle_domain (d) )return 0 ; +ASSERT (config !=NULL );if ( (rc =p2m_init (d)) !=0 ) goto fail;
@@ -534,6 +537,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if ( (rc =p2m_alloc_table (d)) !=0 ) goto fail; +/* +* Currently the vGIC is emulating the same version of the +* hardware GIC. Only the value XEN_DOMCTL_CONFIG_GIC_DEFAULT +* is allowed. The DOMCTL will return the actual version of the +* GIC. +*/ + rc = -EOPNOTSUPP ; +if ( config->gic_version !=XEN_DOMCTL_CONFIG_GIC_DEFAULT ) + goto fail; + +switch (gic_hw_version () ) + { +case GIC_V3 : + gic_version =XEN_DOMCTL_CONFIG_GIC_V3 ; +break ; +case GIC_V2 : + gic_version =XEN_DOMCTL_CONFIG_GIC_V2 ; +break ; +default : +BUG (); + } + config->gic_version = gic_version; +if ( (rc =gicv_setup (d)) !=0 ) goto fail;
xen/arch/arm/domctl.c +0 -34
@@ -32,40 +32,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,return p2m_cache_flush (d, s, e); } -case XEN_DOMCTL_arm_configure_domain: - { -uint8_t gic_version; - -/* -* Currently the vGIC is emulating the same version of the -* hardware GIC. Only the value XEN_DOMCTL_CONFIG_GIC_DEFAULT -* is allowed. The DOMCTL will return the actual version of the -* GIC. -*/ -if ( domctl->u.configuredomain.gic_version !=XEN_DOMCTL_CONFIG_GIC_DEFAULT ) -return -EOPNOTSUPP ; - -switch (gic_hw_version () ) - { -case GIC_V3 : - gic_version =XEN_DOMCTL_CONFIG_GIC_V3 ; -break ; -case GIC_V2 : - gic_version =XEN_DOMCTL_CONFIG_GIC_V2 ; -break ; -default : -BUG (); - } - - domctl->u.configuredomain.gic_version = gic_version; - -/* TODO: Make the copy generic for all ARCH domctl */ -if (__copy_to_guest (u_domctl, domctl,1 ) ) -return -EFAULT ; - -return 0 ; - } -default :return subarch_do_domctl (domctl, d, u_domctl); }
xen/arch/arm/mm.c +3 -3
@@ -399,7 +399,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 ); + dom_xen =domain_create (DOMID_XEN , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_xen));/*
@@ -407,14 +407,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 ); + dom_io =domain_create (DOMID_IO , DOMCRF_dummy,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 ); + dom_cow =domain_create (DOMID_COW , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_cow)); }
xen/arch/arm/setup.c +5 -1
@@ -697,6 +697,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;setup_cache ();
@@ -811,7 +812,10 @@ void __init start_xen(unsigned long boot_phys_offset,do_initcalls ();/* Create initial domain 0. */ - dom0 =domain_create (0 ,0 ,0 ); +/* The vGIC for DOM0 is exactly emulated the hardware GIC */ + config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + + dom0 =domain_create (0 ,0 ,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" );
xen/arch/x86/domain.c +2 -1
@@ -514,7 +514,8 @@ void vcpu_destroy(struct vcpu *v)xfree (v->arch.pv_vcpu.trap_ctxt); } -int arch_domain_create (struct domain *d,unsigned int domcr_flags) +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config) {int i, paging_initialised =0 ;int rc = -ENOMEM ;
xen/arch/x86/mm.c +3 -3
@@ -275,7 +275,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 ); + dom_xen =domain_create (DOMID_XEN , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_xen));INIT_LIST_HEAD (&dom_xen->arch.pdev_list);
@@ -284,14 +284,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 ); + dom_io =domain_create (DOMID_IO , DOMCRF_dummy,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 ); + dom_cow =domain_create (DOMID_COW , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_cow));/* First 1MB of RAM is historically marked as I/O. */
xen/arch/x86/setup.c +6 -2
@@ -1347,8 +1347,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( opt_dom0pvh ) domcr_flags |= DOMCRF_pvh | DOMCRF_hap; -/* Create initial domain 0. */ - dom0 =domain_create (0 , domcr_flags,0 ); +/* +* Create initial domain 0. +* x86 doesn't support arch-configuration. So it's fine to pass +* NULL. +*/ + dom0 =domain_create (0 , domcr_flags,0 ,NULL );if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" );
xen/common/domain.c +4 -3
@@ -242,8 +242,9 @@ static void __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 domain *domain_create (domid_t domid,unsigned int domcr_flags, +uint32_t ssidref, +struct xen_arch_domainconfig *config) {struct domain *d, **pd, *old_hwdom =NULL ;enum { INIT_xsm =1u <<0 , INIT_watchdog =1u <<1 , INIT_rangeset =1u <<2 ,
@@ -353,7 +354,7 @@ struct domain *domain_create( goto fail; } -if ( (err =arch_domain_create (d, domcr_flags)) !=0 ) +if ( (err =arch_domain_create (d, domcr_flags, config)) !=0 ) goto fail; init_status |= INIT_arch;
xen/common/domctl.c +2 -1
@@ -582,7 +582,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off ) domcr_flags |= DOMCRF_oos_off; - d =domain_create (dom, domcr_flags, op->u.createdomain.ssidref); + d =domain_create (dom, domcr_flags, op->u.createdomain.ssidref, + &op->u.createdomain.config);if (IS_ERR (d) ) { ret =PTR_ERR (d);
xen/common/schedule.c +2 -1
@@ -1421,7 +1421,8 @@ void __init scheduler_init(void) sched_ratelimit_us =SCHED_DEFAULT_RATELIMIT_US ; } - idle_domain =domain_create (DOMID_IDLE ,0 ,0 ); +/* There is no need of arch-specific configuration for an idle domain */ + idle_domain =domain_create (DOMID_IDLE ,0 ,0 ,NULL );BUG_ON (IS_ERR (idle_domain)); idle_domain->vcpu = idle_vcpu; idle_domain->max_vcpus = nr_cpu_ids;
xen/include/public/arch-arm.h +8 -0
@@ -314,6 +314,14 @@ struct arch_shared_info {typedef struct arch_shared_info arch_shared_info_t ;typedef uint64_t xen_callback_t ; +#define XEN_DOMCTL_CONFIG_GIC_DEFAULT 0 +#define XEN_DOMCTL_CONFIG_GIC_V2 1 +#define XEN_DOMCTL_CONFIG_GIC_V3 2 +struct xen_arch_domainconfig { +/* IN/OUT */ +uint8_t gic_version; +}; +#endif #if defined(__XEN__) || defined(__XEN_TOOLS__)
xen/include/public/arch-x86/xen.h +4 -0
@@ -258,6 +258,10 @@ struct arch_shared_info { };typedef struct arch_shared_info arch_shared_info_t ; +struct xen_arch_domainconfig { +char dummy; +}; +#endif /* !__ASSEMBLY__ */ /*
xen/include/public/domctl.h +1 -17
@@ -64,23 +64,11 @@ struct xen_domctl_createdomain {#define _XEN_DOMCTL_CDF_pvh_guest 4#define XEN_DOMCTL_CDF_pvh_guest (1U<<_XEN_DOMCTL_CDF_pvh_guest)uint32_t flags; +struct xen_arch_domainconfig config; };typedef struct xen_domctl_createdomain xen_domctl_createdomain_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_createdomain_t); -#if defined(__arm__) || defined(__aarch64__) -#define XEN_DOMCTL_CONFIG_GIC_DEFAULT 0 -#define XEN_DOMCTL_CONFIG_GIC_V2 1 -#define XEN_DOMCTL_CONFIG_GIC_V3 2 -/* XEN_DOMCTL_configure_domain */ -struct xen_domctl_arm_configuredomain { -/* IN/OUT parameters */ -uint8_t gic_version; -}; -typedef struct xen_domctl_arm_configuredomain xen_domctl_arm_configuredomain_t ; -DEFINE_XEN_GUEST_HANDLE (xen_domctl_arm_configuredomain_t); -#endif -/* XEN_DOMCTL_getdomaininfo */ struct xen_domctl_getdomaininfo {/* OUT variables. */
@@ -1069,7 +1057,6 @@ struct xen_domctl {#define XEN_DOMCTL_set_vcpu_msrs 73#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75 -#define XEN_DOMCTL_arm_configure_domain 76#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1078,9 +1065,6 @@ struct xen_domctl {domid_t domain;union {struct xen_domctl_createdomain createdomain; -#if defined(__arm__) || defined(__aarch64__) -struct xen_domctl_arm_configuredomain configuredomain; -#endif struct xen_domctl_getdomaininfo getdomaininfo;struct xen_domctl_getmemlist getmemlist;struct xen_domctl_getpageframeinfo getpageframeinfo;
xen/include/xen/domain.h +2 -1
@@ -55,7 +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); +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config);void arch_domain_destroy (struct domain *d);
xen/include/xen/sched.h +7 -2
@@ -525,8 +525,13 @@ static inline void get_knownalive_domain(struct domain *d)int domain_set_node_affinity (struct domain *d,const nodemask_t *affinity);void domain_update_node_affinity (struct domain *d); -struct domain *domain_create ( -domid_t domid,unsigned int domcr_flags,uint32_t ssidref); +/* +* Create a domain: the configuration is only necessary for real domain +* (i.e !DOMCRF_dummy, excluded idle domain). +*/ +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)
xen/xsm/flask/hooks.c +0 -3
@@ -729,9 +729,6 @@ static int flask_domctl(struct domain *d, int cmd)case XEN_DOMCTL_psr_cmt_op:return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__PSR_CMT_OP ); -case XEN_DOMCTL_arm_configure_domain: -return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__CONFIGURE_DOMAIN ); -default :printk ("flask_domctl: Unknown op %d\n" , cmd);return -EPERM ;
xen/xsm/flask/policy/access_vectors +0 -2
@@ -218,8 +218,6 @@ class domain2 get_vnumainfo # XEN_DOMCTL_psr_cmt_op psr_cmt_op -# XEN_DOMCTL_configure_domain - configure_domain } # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 1 line
2.1.4
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Quoted 16 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters such as the number of SPIs. All will be required to be set at the same time.A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.Some external tools (qemu, xenstore) may require to create a domain. Rather than asking them to take care of the arch-specific domain configuration, let the current function (
xc_domain_create) to chose a default configuration and introduce a new one (xc_domain_create_config).
Quoted 4 lines
This patch also drop the previously DOMCTL
arm_configure_domainintroduced in Xen 4.5, as it has been made useless.Signed-off-by Julien Grall <[email protected]>
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Julien Grallxen/include/public/domctl.h struct xen_domctl { · line 1072
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/include/public/domctl.h +0
-1@@ -1069,7 +1057,6 @@ struct xen_domctl {#define XEN_DOMCTL_set_vcpu_msrs 73#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75 -#define XEN_DOMCTL_arm_configure_domain 76
This and the other removals from this file requires XEN_DOMCTL_INTERFACE_VERSION to be bumped.
With that fixed, for x86 and the common hypervisor pieces
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Hi Jan,
Quoted 9 lines · Jan Beulich
xen/include/public/domctl.h struct xen_domctl { · line 1072
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/include/public/domctl.h +0
-1@@ -1069,7 +1057,6 @@ struct xen_domctl {#define XEN_DOMCTL_set_vcpu_msrs 73#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75 -#define XEN_DOMCTL_arm_configure_domain 76This and the other removals from this file requires
XEN_DOMCTL_INTERFACE_VERSIONto be bumped.
I will do.
Quoted 2 lines
With that fixed, for x86 and the common hypervisor pieces
Acked-by Jan Beulich <[email protected]>
Thanks,
Signature · 1 line
Julien Grall
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Julien GrallQuoted 19 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters such as the number of SPIs. All will be required to be set at the same time.A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.Some external tools (qemu, xenstore) may require to create a domain. Rather than asking them to take care of the arch-specific domain configuration, let the current function (
xc_domain_create) to chose a default configuration and introduce a new one (xc_domain_create_config).This patch also drop the previously DOMCTL
arm_configure_domainintroduced in Xen 4.5, as it has been made useless.
Quoted 9 lines
Signed-off-by Julien Grall <[email protected]>Cc Daniel De Graaf <[email protected]>Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>
Quoted 832 lines
This is a follow-up of http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.html
TODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
For the
xc_domain_create, Stefano S. was looking to drop PV domain creation support in QEMU. So maybe I could simply extendxc_domain_createand drop thexc_domain_create_config.Changes in v3:
- Patch was previously sent in a separate series [1]
- Renamearch_domainconfigtoxen_arch_domainconfig
- Drop the typedef
- Pass NULL for DOM0 config on x86
- Drop spurious changes
- Update comment instart_xeninarch/arm/setup.c[1] https://patches.linaro.org/41083/
--- tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/libxc/include/xenctrl.h | 14 +++++---- tools/libxc/xc_domain.c | 46 ++++++++++++++++------------ tools/libxl/libxl_arch.h | 6 ++++ tools/libxl/libxl_arm.c | 28 ++++++++++------- tools/libxl/libxl_create.c | 21 ++++++++++--- tools/libxl/libxl_dm.c | 3 +- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_internal.h | 7 +++-- tools/libxl/libxl_x86.c | 10 ++++++ xen/arch/arm/domain.c | 28 ++++++++++++++++- xen/arch/arm/domctl.c | 34 -------------------- xen/arch/arm/mm.c | 6 ++-- xen/arch/arm/setup.c | 6 +++- xen/arch/x86/domain.c | 3 +- xen/arch/x86/mm.c | 6 ++-- xen/arch/x86/setup.c | 8 +++-- xen/common/domain.c | 7 +++-- xen/common/domctl.c | 3 +- xen/common/schedule.c | 3 +- xen/include/public/arch-arm.h | 8 +++++ xen/include/public/arch-x86/xen.h | 4 +++ xen/include/public/domctl.h | 18 +---------- xen/include/xen/domain.h | 3 +- xen/include/xen/sched.h | 9 ++++-- xen/xsm/flask/hooks.c | 3 -- xen/xsm/flask/policy/access_vectors | 2 -- 27 files changed, 170 insertions(+), 120 deletions(-)tools/flask/policy/policy/modules/xen/xen.if +1
-1@@ -51,7 +51,7 @@ define(`create_domain_common', ` getaffinity setaffinity setvcpuextstate }; allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim set_max_evtchn set_vnumainfo get_vnumainfo cacheflush - psr_cmt_op configure_domain }; + psr_cmt_op }; allow $1 $2:security check_context; allow $1 $2:shadow enable; allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };tools/libxc/include/xenctrl.h +8
-6@@ -477,18 +477,20 @@ typedef union } start_info_any_t;#endif + +typedef struct xen_arch_domainconfig xc_domain_configuration_t ; +int xc_domain_create_config (xc_interface *xch, +uint32_t ssidref, +xen_domain_handle_t handle, +uint32_t flags, +uint32_t *pdomid, +xc_domain_configuration_t *config);int xc_domain_create (xc_interface *xch,uint32_t ssidref,xen_domain_handle_t handle,uint32_t flags,uint32_t *pdomid); -#if defined(__arm__) || defined(__aarch64__) -typedef xen_domctl_arm_configuredomain_t xc_domain_configuration_t ; - -int xc_domain_configure (xc_interface *xch,uint32_t domid, -xc_domain_configuration_t *config); -#endif /* Functions to produce a dump of a given domain * xc_domain_dumpcore - produces a dump to a specified file tools/libxc/xc_domain.c +27
-19@@ -27,11 +27,12 @@#include <xen/memory.h> #include <xen/hvm/hvm_op.h> -int xc_domain_create (xc_interface *xch, -uint32_t ssidref, -xen_domain_handle_t handle, -uint32_t flags, -uint32_t *pdomid) +int xc_domain_create_config (xc_interface *xch, +uint32_t ssidref, +xen_domain_handle_t handle, +uint32_t flags, +uint32_t *pdomid, +xc_domain_configuration_t *config) {int err;DECLARE_DOMCTL ;@@ -41,32 +42,39 @@ int xc_domain_create(xc_interface *xch, domctl.u.createdomain.ssidref = ssidref; domctl.u.createdomain.flags = flags;memcpy (domctl.u.createdomain.handle, handle,sizeof (xen_domain_handle_t)); +/* xc_domain_configure_t is an alias of arch_domainconfig_t */ +memcpy (&domctl.u.createdomain.config, config,sizeof (*config));if ( (err =do_domctl (xch, &domctl)) !=0 )return err; *pdomid = (uint16_t )domctl.domain; +memcpy (config, &domctl.u.createdomain.config,sizeof (*config)); +return 0 ; } -#if defined(__arm__) || defined(__aarch64__) -int xc_domain_configure (xc_interface *xch,uint32_t domid, -xc_domain_configuration_t *config) +int xc_domain_create (xc_interface *xch, +uint32_t ssidref, +xen_domain_handle_t handle, +uint32_t flags, +uint32_t *pdomid) { -int rc; -DECLARE_DOMCTL ; +xc_domain_configuration_t config; - domctl.cmd = XEN_DOMCTL_arm_configure_domain; - domctl.domain = (domid_t )domid; -/* xc_domain_configure_t is an alias of xen_domctl_arm_configuredomain */ -memcpy (&domctl.u.configuredomain, config,sizeof (*config)); +memset (&config,0 ,sizeof (config)); - rc =do_domctl (xch, &domctl); -if ( !rc ) -memcpy (config, &domctl.u.configuredomain,sizeof (*config)); +#if defined (__i386) || defined(__x86_64__) +/* No arch-specific configuration for now */ +#elif defined (__arm__) || defined(__aarch64__) + config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; +#else + errno =ENOSYS ; +return -1 ; +#endif -return rc; +return xc_domain_create_config (xch, ssidref, handle, + flags, pdomid, &config); } -#endif int xc_domain_cacheflush (xc_interface *xch,uint32_t domid,xen_pfn_t start_pfn,xen_pfn_t nr_pfns)tools/libxl/libxl_arch.h +6
-0@@ -15,6 +15,11 @@#ifndef LIBXL_ARCH_H #define LIBXL_ARCH_H +/* fill the arch specific configuration for the domain */ +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config); +/* arch specific internal domain creation function */ int libxl__arch_domain_create (libxl__gc *gc,libxl_domain_config *d_config,uint32_t domid);@@ -22,6 +27,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,/* setup arch specific hardware description, i.e. DTB on ARM */ int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom);/* finalize arch specific hardware description. */ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,tools/libxl/libxl_arm.c +17
-11@@ -35,6 +35,15 @@ static const char *gicv_to_string(uint8_t gic_version) } } +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config) +{ + xc_config->gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + +return 0 ; +} +int libxl__arch_domain_create (libxl__gc *gc,libxl_domain_config *d_config,uint32_t domid) {@@ -516,9 +525,9 @@ out:int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom) { -xc_domain_configuration_t config;void *fdt =NULL ;int rc, res;size_t fdt_size =0 ;@@ -526,6 +535,9 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,const libxl_version_info *vers;const struct arch_info *ainfo; +/* convenience aliases */ +xc_domain_configuration_t *xc_config = &state->config; +assert (info->type ==LIBXL_DOMAIN_TYPE_PV ); vers =libxl_get_version_info (CTX );@@ -534,16 +546,9 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc, ainfo =get_arch_info (gc, dom);if (ainfo ==NULL )return ERROR_FAIL ; -LOG (DEBUG ,"configure the domain" ); - config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; -if (xc_domain_configure (CTX ->xch, dom->guest_domid, &config) !=0 ) { -LOG (ERROR ,"couldn't configure the domain" ); -return ERROR_FAIL ; - } -LOG (DEBUG ,"constructing DTB for Xen version %d.%d guest" , vers->xen_version_major, vers->xen_version_minor); -LOG (DEBUG ," - vGIC version: %s" ,gicv_to_string (config.gic_version)); +LOG (DEBUG ," - vGIC version: %s\n" ,gicv_to_string (xc_config->gic_version));/* * Call "call" handling FDT_ERR_*. Will either: @@ -592,7 +597,7 @@ next_resize:FDT (make_memory_nodes (gc, fdt, dom) ); -switch (config.gic_version) { +switch (xc_config->gic_version) {case XEN_DOMCTL_CONFIG_GIC_V2 : FDT( make_gicv2_node(gc, fdt, GUEST_GICD_BASE, GUEST_GICD_SIZE,@@ -602,7 +607,8 @@ next_resize:FDT (make_gicv3_node (gc, fdt) );break ;default : -LOG (ERROR ,"Unknown GIC version %d" , config.gic_version); +LOG (ERROR ,"Unknown GIC version %s" , +gicv_to_string (xc_config->gic_version)); rc =ERROR_FAIL ; goto out; }tools/libxl/libxl_create.c +17
-4@@ -489,8 +489,8 @@ out:return ret; } -int libxl__domain_make (libxl__gc *gc,libxl_domain_create_info *info, -uint32_t *domid) +int libxl__domain_make (libxl__gc *gc,libxl_domain_config *d_config, +uint32_t *domid,xc_domain_configuration_t *xc_config) {libxl_ctx *ctx =libxl__gc_owner (gc);int flags, ret, rc, nb_vm;@@ -503,6 +503,8 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,xen_domain_handle_t handle;libxl_vminfo *vm_list; +/* convenience aliases */ +libxl_domain_create_info *info = &d_config->c_info;assert (!libxl_domid_valid_guest (*domid));@@ -531,7 +533,16 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,/* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy (ctx, (libxl_uuid *)handle, &info->uuid); - ret =xc_domain_create (ctx->xch, info->ssidref, handle, flags, domid); + ret =libxl__arch_domain_prepare_config (gc, d_config, xc_config); +if (ret <0 ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"fail to get domain config" ); + rc =ERROR_FAIL ; + goto out; + } + + ret =xc_domain_create_config (ctx->xch, info->ssidref, + handle, flags, domid, + xc_config);if (ret <0 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"domain creation fail" ); rc =ERROR_FAIL ;@@ -764,9 +775,11 @@ static void initiate_domain_create(libxl__egc *egc,/* convenience aliases */ libxl_domain_config *const d_config = dcs->guest_config; +libxl__domain_build_state *const state = &dcs->build_state;const int restore_fd = dcs->restore_fd;memset (&dcs->build_state,0 ,sizeof (dcs->build_state)); + domid =0 ;if (d_config->c_info.ssid_label) {@@ -848,7 +861,7 @@ static void initiate_domain_create(libxl__egc *egc, ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info);if (ret) goto error_out; - ret =libxl__domain_make (gc, &d_config->c_info, &domid); + ret =libxl__domain_make (gc, d_config, &domid, &state->config);if (ret) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"cannot make domain: %d" , ret); dcs->guest_domid = domid;tools/libxl/libxl_dm.c +2
-1@@ -1063,7 +1063,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) stubdom_state->pv_ramdisk.path ="" ;/* fixme: this function can leak the stubdom if it fails */ - ret =libxl__domain_make (gc, &dm_config->c_info, &sdss->pvqemu.guest_domid); + ret =libxl__domain_make (gc, dm_config, &sdss->pvqemu.guest_domid, + &stubdom_state->config);if (ret) goto out;uint32_t dm_domid = sdss->pvqemu.guest_domid;tools/libxl/libxl_dom.c +1
-1@@ -586,7 +586,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,LOGE (ERROR ,"xc_dom_parse_image failed" ); goto out; } -if ( (ret =libxl__arch_domain_init_hw_description (gc, info, dom)) !=0 ) { +if ( (ret =libxl__arch_domain_init_hw_description (gc, info, state, dom)) !=0 ) {LOGE (ERROR ,"libxl__arch_domain_init_hw_description failed" ); goto out; }tools/libxl/libxl_internal.h +5
-2@@ -973,6 +973,8 @@ typedef struct {libxl__file_reference pv_ramdisk;const char * pv_cmdline;bool pvh_enabled; + +xc_domain_configuration_t config; } libxl__domain_build_state; _hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,@@ -1462,8 +1464,9 @@ _hidden void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,/* on entry, libxl_domid_valid_guest(domid) must be false; * on exit (even error exit), domid may be valid and refer to a domain */ _hidden int libxl__domain_make(libxl__gc *gc, -libxl_domain_create_info *info, -uint32_t *domid); +libxl_domain_config *d_config, +uint32_t *domid, +xc_domain_configuration_t *xc_config); _hidden int libxl__domain_build(libxl__gc *gc, libxl_domain_config *d_config,tools/libxl/libxl_x86.c +10
-0@@ -1,6 +1,15 @@#include "libxl_internal.h" #include "libxl_arch.h" +int libxl__arch_domain_prepare_config (libxl__gc *gc, +libxl_domain_config *d_config, +xc_domain_configuration_t *xc_config) +{ +/* No specific configuration right now */ + +return 0 ; +} +static const char *e820_names (int type) {switch (type) {@@ -313,6 +322,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,int libxl__arch_domain_init_hw_description (libxl__gc *gc,libxl_domain_build_info *info, +libxl__domain_build_state *state,struct xc_dom_image *dom) {return 0 ;xen/arch/arm/domain.c +27
-1@@ -504,9 +504,11 @@ void vcpu_destroy(struct vcpu *v)free_xenheap_pages (v->arch.stack,STACK_ORDER ); } -int arch_domain_create (struct domain *d,unsigned int domcr_flags) +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config) {int rc; +uint8_t gic_version; d->arch.relmem = RELMEM_not_started;@@ -514,6 +516,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if (is_idle_domain (d) )return 0 ; +ASSERT (config !=NULL );if ( (rc =p2m_init (d)) !=0 ) goto fail;@@ -534,6 +537,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if ( (rc =p2m_alloc_table (d)) !=0 ) goto fail; +/* +* Currently the vGIC is emulating the same version of the +* hardware GIC. Only the value XEN_DOMCTL_CONFIG_GIC_DEFAULT +* is allowed. The DOMCTL will return the actual version of the +* GIC. +*/ + rc = -EOPNOTSUPP ; +if ( config->gic_version !=XEN_DOMCTL_CONFIG_GIC_DEFAULT ) + goto fail; + +switch (gic_hw_version () ) + { +case GIC_V3 : + gic_version =XEN_DOMCTL_CONFIG_GIC_V3 ; +break ; +case GIC_V2 : + gic_version =XEN_DOMCTL_CONFIG_GIC_V2 ; +break ; +default : +BUG (); + } + config->gic_version = gic_version; +if ( (rc =gicv_setup (d)) !=0 ) goto fail;xen/arch/arm/domctl.c +0
-34@@ -32,40 +32,6 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,return p2m_cache_flush (d, s, e); } -case XEN_DOMCTL_arm_configure_domain: - { -uint8_t gic_version; - -/* -* Currently the vGIC is emulating the same version of the -* hardware GIC. Only the value XEN_DOMCTL_CONFIG_GIC_DEFAULT -* is allowed. The DOMCTL will return the actual version of the -* GIC. -*/ -if ( domctl->u.configuredomain.gic_version !=XEN_DOMCTL_CONFIG_GIC_DEFAULT ) -return -EOPNOTSUPP ; - -switch (gic_hw_version () ) - { -case GIC_V3 : - gic_version =XEN_DOMCTL_CONFIG_GIC_V3 ; -break ; -case GIC_V2 : - gic_version =XEN_DOMCTL_CONFIG_GIC_V2 ; -break ; -default : -BUG (); - } - - domctl->u.configuredomain.gic_version = gic_version; - -/* TODO: Make the copy generic for all ARCH domctl */ -if (__copy_to_guest (u_domctl, domctl,1 ) ) -return -EFAULT ; - -return 0 ; - } -default :return subarch_do_domctl (domctl, d, u_domctl); }xen/arch/arm/mm.c +3
-3@@ -399,7 +399,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 ); + dom_xen =domain_create (DOMID_XEN , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_xen));/* @@ -407,14 +407,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 ); + dom_io =domain_create (DOMID_IO , DOMCRF_dummy,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 ); + dom_cow =domain_create (DOMID_COW , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_cow)); }xen/arch/arm/setup.c +5
-1@@ -697,6 +697,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;setup_cache ();@@ -811,7 +812,10 @@ void __init start_xen(unsigned long boot_phys_offset,do_initcalls ();/* Create initial domain 0. */ - dom0 =domain_create (0 ,0 ,0 ); +/* The vGIC for DOM0 is exactly emulated the hardware GIC */ + config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + + dom0 =domain_create (0 ,0 ,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" );xen/arch/x86/domain.c +2
-1@@ -514,7 +514,8 @@ void vcpu_destroy(struct vcpu *v)xfree (v->arch.pv_vcpu.trap_ctxt); } -int arch_domain_create (struct domain *d,unsigned int domcr_flags) +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config) {int i, paging_initialised =0 ;int rc = -ENOMEM ;xen/arch/x86/mm.c +3
-3@@ -275,7 +275,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 ); + dom_xen =domain_create (DOMID_XEN , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_xen));INIT_LIST_HEAD (&dom_xen->arch.pdev_list);@@ -284,14 +284,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 ); + dom_io =domain_create (DOMID_IO , DOMCRF_dummy,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 ); + dom_cow =domain_create (DOMID_COW , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_cow));/* First 1MB of RAM is historically marked as I/O. */ xen/arch/x86/setup.c +6
-2@@ -1347,8 +1347,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( opt_dom0pvh ) domcr_flags |= DOMCRF_pvh | DOMCRF_hap; -/* Create initial domain 0. */ - dom0 =domain_create (0 , domcr_flags,0 ); +/* +* Create initial domain 0. +* x86 doesn't support arch-configuration. So it's fine to pass +* NULL. +*/ + dom0 =domain_create (0 , domcr_flags,0 ,NULL );if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" );xen/common/domain.c +4
-3@@ -242,8 +242,9 @@ static void __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 domain *domain_create (domid_t domid,unsigned int domcr_flags, +uint32_t ssidref, +struct xen_arch_domainconfig *config) {struct domain *d, **pd, *old_hwdom =NULL ;enum { INIT_xsm =1u <<0 , INIT_watchdog =1u <<1 , INIT_rangeset =1u <<2 ,@@ -353,7 +354,7 @@ struct domain *domain_create( goto fail; } -if ( (err =arch_domain_create (d, domcr_flags)) !=0 ) +if ( (err =arch_domain_create (d, domcr_flags, config)) !=0 ) goto fail; init_status |= INIT_arch;xen/common/domctl.c +2
-1@@ -582,7 +582,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off ) domcr_flags |= DOMCRF_oos_off; - d =domain_create (dom, domcr_flags, op->u.createdomain.ssidref); + d =domain_create (dom, domcr_flags, op->u.createdomain.ssidref, + &op->u.createdomain.config);if (IS_ERR (d) ) { ret =PTR_ERR (d);xen/common/schedule.c +2
-1@@ -1421,7 +1421,8 @@ void __init scheduler_init(void) sched_ratelimit_us =SCHED_DEFAULT_RATELIMIT_US ; } - idle_domain =domain_create (DOMID_IDLE ,0 ,0 ); +/* There is no need of arch-specific configuration for an idle domain */ + idle_domain =domain_create (DOMID_IDLE ,0 ,0 ,NULL );BUG_ON (IS_ERR (idle_domain)); idle_domain->vcpu = idle_vcpu; idle_domain->max_vcpus = nr_cpu_ids;xen/include/public/arch-arm.h +8
-0@@ -314,6 +314,14 @@ struct arch_shared_info {typedef struct arch_shared_info arch_shared_info_t ;typedef uint64_t xen_callback_t ; +#define XEN_DOMCTL_CONFIG_GIC_DEFAULT 0 +#define XEN_DOMCTL_CONFIG_GIC_V2 1 +#define XEN_DOMCTL_CONFIG_GIC_V3 2 +struct xen_arch_domainconfig { +/* IN/OUT */ +uint8_t gic_version; +}; +#endif #if defined(__XEN__) || defined(__XEN_TOOLS__)xen/include/public/arch-x86/xen.h +4
-0@@ -258,6 +258,10 @@ struct arch_shared_info { };typedef struct arch_shared_info arch_shared_info_t ; +struct xen_arch_domainconfig { +char dummy; +}; +#endif /* !__ASSEMBLY__ */ /* xen/include/public/domctl.h +1
-17@@ -64,23 +64,11 @@ struct xen_domctl_createdomain {#define _XEN_DOMCTL_CDF_pvh_guest 4#define XEN_DOMCTL_CDF_pvh_guest (1U<<_XEN_DOMCTL_CDF_pvh_guest)uint32_t flags; +struct xen_arch_domainconfig config; };typedef struct xen_domctl_createdomain xen_domctl_createdomain_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_createdomain_t); -#if defined(__arm__) || defined(__aarch64__) -#define XEN_DOMCTL_CONFIG_GIC_DEFAULT 0 -#define XEN_DOMCTL_CONFIG_GIC_V2 1 -#define XEN_DOMCTL_CONFIG_GIC_V3 2 -/* XEN_DOMCTL_configure_domain */ -struct xen_domctl_arm_configuredomain { -/* IN/OUT parameters */ -uint8_t gic_version; -}; -typedef struct xen_domctl_arm_configuredomain xen_domctl_arm_configuredomain_t ; -DEFINE_XEN_GUEST_HANDLE (xen_domctl_arm_configuredomain_t); -#endif -/* XEN_DOMCTL_getdomaininfo */ struct xen_domctl_getdomaininfo {/* OUT variables. */ @@ -1069,7 +1057,6 @@ struct xen_domctl {#define XEN_DOMCTL_set_vcpu_msrs 73#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75 -#define XEN_DOMCTL_arm_configure_domain 76#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002@@ -1078,9 +1065,6 @@ struct xen_domctl {domid_t domain;union {struct xen_domctl_createdomain createdomain; -#if defined(__arm__) || defined(__aarch64__) -struct xen_domctl_arm_configuredomain configuredomain; -#endif struct xen_domctl_getdomaininfo getdomaininfo;struct xen_domctl_getmemlist getmemlist;struct xen_domctl_getpageframeinfo getpageframeinfo;xen/include/xen/domain.h +2
-1@@ -55,7 +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); +int arch_domain_create (struct domain *d,unsigned int domcr_flags, +struct xen_arch_domainconfig *config);void arch_domain_destroy (struct domain *d);xen/include/xen/sched.h +7
-2@@ -525,8 +525,13 @@ static inline void get_knownalive_domain(struct domain *d)int domain_set_node_affinity (struct domain *d,const nodemask_t *affinity);void domain_update_node_affinity (struct domain *d); -struct domain *domain_create ( -domid_t domid,unsigned int domcr_flags,uint32_t ssidref); +/* +* Create a domain: the configuration is only necessary for real domain +* (i.e !DOMCRF_dummy, excluded idle domain). +*/ +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)xen/xsm/flask/hooks.c +0
-3@@ -729,9 +729,6 @@ static int flask_domctl(struct domain *d, int cmd)case XEN_DOMCTL_psr_cmt_op:return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__PSR_CMT_OP ); -case XEN_DOMCTL_arm_configure_domain: -return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__CONFIGURE_DOMAIN ); -default :printk ("flask_domctl: Unknown op %d\n" , cmd);return -EPERM ;xen/xsm/flask/policy/access_vectors +0
-2@@ -218,8 +218,6 @@ class domain2 get_vnumainfo # XEN_DOMCTL_psr_cmt_op psr_cmt_op -# XEN_DOMCTL_configure_domain - configure_domain } # Similar to class domain, but primarily contains domctls related to HVM domainsSignature · 1 line
2.1.4
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Julien GrallQuoted 2 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation
"This information is already known at domain creation..."
Quoted 3 lines
and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters
"In the long run".
Quoted 5 lines
such as the number of SPIs. All will be required to be set at the same time.
A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.
I'm not sure what you mean by factorize here.
Quoted 1 line
Some external tools (qemu, xenstore) may require to create a domain. Rather
"may be required" perhaps? I'm not 100% sure what you are trying to say.
Quoted 2 lines
than asking them to take care of the arch-specific domain configuration, let the current function (
xc_domain_create) to chose a default configuration and
s/to//
Quoted 3 lines
introduce a new one (
xc_domain_create_config).This patch also drop the previously DOMCTL
arm_configure_domainintroduced
"drops the previously introduced DOMCTL arm...".
Quoted 12 lines
in Xen 4.5, as it has been made useless.
Signed-off-by Julien Grall <[email protected]>Cc Daniel De Graaf <[email protected]>Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>
Quoted 6 lines
---
This is a follow-up of http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.htmlTODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
Things like the GIC version and number of SPIs would normally end up being encoded in the hvm save records, i.e. the blob which Xen provides to the toolstack to be included in the save stream. That would then be alongside the actual related interrupt architectural state etc (e.g. pending, active, masked etc).
That's problematic here because you can't pass that blob to the create function and the toolstack cannot really parse the blob to figure out the details to pass.
Looking back at msg00522.html it does seem like migration is a good motivation for doing it as a separate hypercall as you originally did, so initial create would be
DOMCTL_create
DOMCTL_set_the_variables
and restore would be
DOMCTL_create
DOMCTL_restore_from_blob
In both cases this needn't preclude requiring the call to be made before unpause or that it is only called exactly once.
Write once HVM params would be another option here.
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
Quoted 2 lines
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
It's a domctl so we aren't exactly painting ourselves into a corner, but it would be good to have some idea that we aren't going down a blind alley at least. Especially if the way out of the alley is to come back to where we are now...
(There doesn't seem much point in looking at the code until we conclude the approach is correct, so I haven't)
Ian.
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Hi Ian,
Quoted 12 lines · Ian Campbell
Quoted 2 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation
"This information is already known at domain creation..."
Quoted 3 lines
and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters"In the long run".
Quoted 7 lines
Quoted 5 lines
such as the number of SPIs. All will be required to be set at the same time.
A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.I'm not sure what you mean by factorize here.
There is an arch-specific function where
Quoted 4 lines
Quoted 2 lines
Some external tools (qemu, xenstore) may require to create a domain. Rather
"may be required" perhaps? I'm not 100% sure what you are trying to say.
I meant some external tools (such as qemu, xenstore) needs to create domain. So we have to keep the old xc_domain_create.
I will use "may be required".
Quoted 37 lines
Quoted 3 lines
than asking them to take care of the arch-specific domain configuration, let the current function (
xc_domain_create) to chose a default configuration ands/to//
Quoted 3 lines
introduce a new one (
xc_domain_create_config).This patch also drop the previously DOMCTL
arm_configure_domainintroduced"drops the previously introduced DOMCTL arm...".
Quoted 12 lines
in Xen 4.5, as it has been made useless.
Signed-off-by Julien Grall <[email protected]>Cc Daniel De Graaf <[email protected]>Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>Quoted 6 lines
---
This is a follow-up of http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.htmlTODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
Things like the GIC version and number of SPIs would normally end up being encoded in the hvm save records, i.e. the blob which Xen provides to the toolstack to be included in the save stream. That would then be alongside the actual related interrupt architectural state etc (e.g. pending, active, masked etc).
Quoted 3 lines
That's problematic here because you can't pass that blob to the create function and the toolstack cannot really parse the blob to figure out the details to pass.
I was thinking to pass those information the same way we do to know the domain is a PVH/HVM...
AFAICT they are required in order to create the domain.
Quoted 9 lines
Looking back at msg00522.html it does seem like migration is a good motivation for doing it as a separate hypercall as you originally did, so initial create would be
DOMCTL_create
DOMCTL_set_the_variables
and restore would be
DOMCTL_create
DOMCTL_restore_from_blob
Quoted 8 lines
In both cases this needn't preclude requiring the call to be made before unpause or that it is only called exactly once.
Write once HVM params would be another option here.
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
The problem with HVM params is we need to wait until every HVM parameters is set and we have to do it before vCPU are initialized.
The problem with a new DOMCTL is it make the code more complicate in the hypervisor as it require some kind of synchronization to know if everything as been correctly initialized.
Quoted 11 lines
Quoted 3 lines
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
It's a domctl so we aren't exactly painting ourselves into a corner, but it would be good to have some idea that we aren't going down a blind alley at least. Especially if the way out of the alley is to come back to where we are now...
(There doesn't seem much point in looking at the code until we conclude the approach is correct, so I haven't)
I believe that the migration can be taken in different way without modifying the current approach.
What we have to do is moving this internal information to the global structure... That wouldn't be too bad because sooner or later we will have to let the user choose between vGICv2 and vGICv3.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:09, <[email protected]> wrote:
Quoted 3 lines · Ian Campbell
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
The problem with HVM params is we need to wait until every HVM parameters is set and we have to do it before vCPU are initialized.
vCPU initialization could simply fail is certain params didn't get set yet.
Jan
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Julien GrallQuoted 17 lines · Julien Grall
Hi Ian,
Quoted 14 lines · Ian Campbell
Quoted 2 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation
"This information is already known at domain creation..."
Quoted 3 lines
and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters"In the long run".
Quoted 2 lines
such as the number of SPIs. All will be required to be set at the same time.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.I'm not sure what you mean by factorize here.
There is an arch-specific function where
... truncated sentence?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Some external tools (qemu, xenstore) may require to create a domain. Rather
"may be required" perhaps? I'm not 100% sure what you are trying to say.
I meant some external tools (such as qemu, xenstore) needs to create domain. So we have to keep the old
xc_domain_create.
FWIW libxc does not have a stable interface...
xenstore we could just update in lockstep since it is in the same tree. (I suppose you are thinking of the stubdom launcher helper).
qemu -- well, I suppose if it is easy to keep it working we might as well, although I'm not sure it's actually used/maintained (maybe this is a good way to find out :-P).
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
TODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
Things like the GIC version and number of SPIs would normally end up being encoded in the hvm save records, i.e. the blob which Xen provides to the toolstack to be included in the save stream. That would then be alongside the actual related interrupt architectural state etc (e.g. pending, active, masked etc).
Quoted 8 lines
Quoted 3 lines
That's problematic here because you can't pass that blob to the create function and the toolstack cannot really parse the blob to figure out the details to pass.
I was thinking to pass those information the same way we do to know the domain is a PVH/HVM...
AFAICT they are required in order to create the domain.
IIRC you said on Friday that you spoke with Andy Cooper and thought about adding new records to the migration v2 format to allow such things to be part of the migration stream (with requirements on the ordering).
Quoted 34 lines
Quoted 9 lines
Looking back at msg00522.html it does seem like migration is a good motivation for doing it as a separate hypercall as you originally did, so initial create would be
DOMCTL_create
DOMCTL_set_the_variables
and restore would be
DOMCTL_create
DOMCTL_restore_from_blobQuoted 8 lines
In both cases this needn't preclude requiring the call to be made before unpause or that it is only called exactly once.
Write once HVM params would be another option here.
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
The problem with HVM params is we need to wait until every HVM parameters is set and we have to do it before vCPU are initialized.
The problem with a new DOMCTL is it make the code more complicate in the hypervisor as it require some kind of synchronization to know if everything as been correctly initialized.
Quoted 9 lines
Quoted 3 lines
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
It's a domctl so we aren't exactly painting ourselves into a corner, but it would be good to have some idea that we aren't going down a blind alley at least. Especially if the way out of the alley is to come back to where we are now...
Quoted 5 lines
Quoted 2 lines
(There doesn't seem much point in looking at the code until we conclude the approach is correct, so I haven't)
I believe that the migration can be taken in different way without modifying the current approach.
What I meant was if that when implementing migration we end up back where we started before this patch, because that approach turns out to be the right one, then it's all a bit of a waste of time, so we should try and understand at least to the level required to have a good feeling we won't be doing that.
Ian.
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Ian CampbellQuoted 28 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 16:15, <[email protected]> wrote:
Quoted 1 line · Julien Grall
This is a follow-up of
http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.html
Quoted 4 lines
TODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
Things like the GIC version and number of SPIs would normally end up being encoded in the hvm save records, i.e. the blob which Xen provides to the toolstack to be included in the save stream. That would then be alongside the actual related interrupt architectural state etc (e.g. pending, active, masked etc).
That's problematic here because you can't pass that blob to the create function and the toolstack cannot really parse the blob to figure out the details to pass.
Looking back at msg00522.html it does seem like migration is a good motivation for doing it as a separate hypercall as you originally did, so initial create would be
DOMCTL_create
DOMCTL_set_the_variables
and restore would be
DOMCTL_create
DOMCTL_restore_from_blob
Quoted 8 lines
In both cases this needn't preclude requiring the call to be made before unpause or that it is only called exactly once.
Write once HVM params would be another option here.
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
Not really (HVM params are already being dealt with for migration iirc, i.e. one wouldn't even need to think about that aspect), but considering the other domctl-vs-HVM-param discussion we're having I suppose at least Andrew might be of a different opinion. My main reservation against domctl-s is (more there than here) that HVM params scale better (there it's domain creation flag being defined, of which we have only so many), along with said "built-in" migration.
But then again - if everyone else thinks domctl-s are the mechanism to use (here and there), I don#t want to stand in the way...
Jan
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
In reply to Ian CampbellQuoted 77 lines · Ian Campbell
Quoted 2 lines · Julien Grall
On ARM the virtual GIC may differ between each guest (emulated GIC version, number of SPIs...). Those informations are already known at the domain creation
"This information is already known at domain creation..."
Quoted 3 lines
and can never change.
For now only the
gic_versionis set. In long run, there will be more parameters"In the long run".
Quoted 5 lines
such as the number of SPIs. All will be required to be set at the same time.
A new arch-specific structure
arch_domainconfighas been created, the x86 one doesn't have any specific configuration, a dummy structure (C-spec compliant) has been created to factorize the code on the toolstack.I'm not sure what you mean by factorize here.
Quoted 1 line
Some external tools (qemu, xenstore) may require to create a domain. Rather
"may be required" perhaps? I'm not 100% sure what you are trying to say.
Quoted 2 lines
than asking them to take care of the arch-specific domain configuration, let the current function (
xc_domain_create) to chose a default configuration ands/to//
Quoted 3 lines
introduce a new one (
xc_domain_create_config).This patch also drop the previously DOMCTL
arm_configure_domainintroduced"drops the previously introduced DOMCTL arm...".
Quoted 12 lines
in Xen 4.5, as it has been made useless.
Signed-off-by Julien Grall <[email protected]>Cc Daniel De Graaf <[email protected]>Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>Quoted 6 lines
---
This is a follow-up of http://lists.xen.org/archives/html/xen-devel/2014-11/msg00522.htmlTODO: What about migration? For now the configuration lives in internal libxl structure. We need a way to pass the domain configuration to the other end.
Things like the GIC version and number of SPIs would normally end up being encoded in the hvm save records, i.e. the blob which Xen provides to the toolstack to be included in the save stream. That would then be alongside the actual related interrupt architectural state etc (e.g. pending, active, masked etc).
That's problematic here because you can't pass that blob to the create function and the toolstack cannot really parse the blob to figure out the details to pass.
Looking back at msg00522.html it does seem like migration is a good motivation for doing it as a separate hypercall as you originally did, so initial create would be
DOMCTL_create
DOMCTL_set_the_variables
and restore would be
DOMCTL_create
DOMCTL_restore_from_blobIn both cases this needn't preclude requiring the call to be made before unpause or that it is only called exactly once.
Write once HVM params would be another option here.
Jan, do you find any of that convincing as to the need for doing this outside the the create domctl? Based on msg00522 is seems you would prefer some HVM params over a new domctl?
Quoted 2 lines
I'm not sure if we should care of this right now as migration doesn't yet exists on ARM.
Quoted 7 lines
It's a domctl so we aren't exactly painting ourselves into a corner, but it would be good to have some idea that we aren't going down a blind alley at least. Especially if the way out of the alley is to come back to where we are now...
(There doesn't seem much point in looking at the code until we conclude the approach is correct, so I haven't)
GIC version and SPIs should absolutely be part of the migration stream. They are domain architectural state.
I have a similar issue with my plans for cpuid improvements in x86, and was going to introduce a domain architectural state near the head of the migration stream. (There is currently a chicken & egg problem in x86 with the hvm params, the cpu state and the cpuid policy. In Xen, we currently check the cpu state for plausibility because it is not currently possible to load the policy before xc_domain_restore() is complete.)
At first glance, extending createdomian would look like a sensible action to ensure that these bits of state get set appropriately. A consequence would be that the createdomain hypercall must move down into xc_domain_restore(), which causes problems in the XSM case (where the permissions are along the lines of "sub builder $X is permitted to issue hypercalls on domid $Y).
An alternative is instead to move more of domain construction into the xc_domain_restore(), so architectural state from the stream can be used to construct the domain. (For x86 cpuid, I believe I need to set part of the architectural state before the set_max_vcpus hypercall, and I certainly need to propagate maxphysaddr from the source before I can validate any memory frames in the stream.)
This would result in a leaning towards separate hypercalls.
~Andrew
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Quoted 2 lines · Andrew Cooper
GIC version and SPIs should absolutely be part of the migration stream. They are domain architectural state.
Of course, the question is where.
They could be part of the Xen hvmsave blob for the GIC (i.e. along with the other GIC architectural state such as which interrupts are currently active,pending,masked etc).
Or they could be part of a new migration v2 record for such things.
Or they could be part of the hvm params migration record.
Or they could be part of the libxl json cfg blob, (but I think that option is a bad one).
Quoted 27 lines
I have a similar issue with my plans for cpuid improvements in x86, and was going to introduce a domain architectural state near the head of the migration stream. (There is currently a chicken & egg problem in x86 with the hvm params, the cpu state and the cpuid policy. In Xen, we currently check the cpu state for plausibility because it is not currently possible to load the policy before
xc_domain_restore()is complete.)At first glance, extending createdomian would look like a sensible action to ensure that these bits of state get set appropriately. A consequence would be that the createdomain hypercall must move down into
xc_domain_restore(), which causes problems in the XSM case (where the permissions are along the lines of "sub builder $X is permitted to issue hypercalls on domid $Y).An alternative is instead to move more of domain construction into the
xc_domain_restore(), so architectural state from the stream can be used to construct the domain. (For x86 cpuid, I believe I need to set part of the architectural state before theset_max_vcpushypercall, and I certainly need to propagate maxphysaddr from the source before I can validate any memory frames in the stream.)This would result in a leaning towards separate hypercalls.
~Andrew
_
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Hi Ian,
Quoted 11 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper
GIC version and SPIs should absolutely be part of the migration stream. They are domain architectural state.
Of course, the question is where.
They could be part of the Xen hvmsave blob for the GIC (i.e. along with the other GIC architectural state such as which interrupts are currently active,pending,masked etc).
Or they could be part of a new migration v2 record for such things.
With the extension of the DOMCTL createdomain, this would be the best solution. The implementation would be cleaner.
Quoted 1 line
Or they could be part of the hvm params migration record.
And how do you restore? As we may have some default value (such as choosing the default GIC version), how do you know that all the parameters is correctly given?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 01/24] xen: Extend DOMCTL createdomain to support arch configuration
Quoted 9 lines · Julien Grall
Hi Ian,
Quoted 6 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper
GIC version and SPIs should absolutely be part of the migration stream. They are domain architectural state.
Of course, the question is where.
Quoted 8 lines
Quoted 5 lines
They could be part of the Xen hvmsave blob for the GIC (i.e. along with the other GIC architectural state such as which interrupts are currently active,pending,masked etc).
Or they could be part of a new migration v2 record for such things.
With the extension of the DOMCTL createdomain, this would be the best solution. The implementation would be cleaner.
and this sounds like it fits in with the approach Andrew wants to take for x86 too.
Quoted 5 lines
Quoted 1 line
Or they could be part of the hvm params migration record.
And how do you restore? As we may have some default value (such as choosing the default GIC version), how do you know that all the parameters is correctly given?
IIRC the migration v2 has a list of hvm params to transport in the save stream (either in a dedicated record or one per param, I don't recall), i.e. it reads them back on the source and writes them on the target.
The read would presumably have to reflect the actual selection made for that domain if there was defaulting going on and the write would have to reject things it couldn't deal with (like GICv2 on v3 only hardware).
Ian.
PATCH v3 2/24 xen/arm: Divide GIC initialization in 2 parts
In reply to Julien GrallCurrently the function to translate IRQ from the device tree is set unconditionally to be able to be able to retrieve serial/timer IRQ before the GIC has been initialized.
It assumes that the xlate function won't never changed. We may also need to have the primary interrupt controller very early.
Rework the gic initialization in 2 parts:
- gic_preinit: Get the interrupt controller device tree node and set
up GIC and xlate callbacks
- gic_init: Initialize the interrupt controller and the boot CPU interrupts.
The former function will be called just after the IRQ subsystem as been initialized.
---
Changes in v3:
- Patch was previously sent in a separate series [1]
- Reorder the function to avoid forward declaration
- Make gic-v3 driver compliant to the new interface
- Remove spurious field addition in gicv2 structure
Changelog based on the separate series:
Changes in v3:
- Patch added.
[1] https://patches.linaro.org/33313/
--- xen/arch/arm/gic-v2.c | 70 ++++++++++++++++++++++--------------------- xen/arch/arm/gic-v3.c | 75 ++++++++++++++++++++++++----------------------- xen/arch/arm/gic.c | 16 ++++++++-- xen/arch/arm/setup.c | 3 +- xen/include/asm-arm/gic.h | 8 +++++ 5 files changed, 100 insertions(+), 72 deletions(-)
xen/arch/arm/gic-v2.c +37 -33
@@ -655,37 +655,10 @@ static hw_irq_controller gicv2_guest_irq_type = { .set_affinity = gicv2_irq_set_affinity, }; -const static struct gic_hw_operations gicv2_ops = { - .info = &gicv2_info, - .secondary_init = gicv2_secondary_cpu_init, - .save_state = gicv2_save_state, - .restore_state = gicv2_restore_state, - .dump_state = gicv2_dump_state, - .gicv_setup = gicv2v_setup, - .gic_host_irq_type = &gicv2_host_irq_type, - .gic_guest_irq_type = &gicv2_guest_irq_type, - .eoi_irq = gicv2_eoi_irq, - .deactivate_irq = gicv2_dir_irq, - .read_irq = gicv2_read_irq, - .set_irq_properties = gicv2_set_irq_properties, - .send_SGI = gicv2_send_SGI, - .disable_interface = gicv2_disable_interface, - .update_lr = gicv2_update_lr, - .update_hcr_status = gicv2_hcr_status, - .clear_lr = gicv2_clear_lr, - .read_lr = gicv2_read_lr, - .write_lr = gicv2_write_lr, - .read_vmcr_priority = gicv2_read_vmcr_priority, - .read_apr = gicv2_read_apr, - .make_dt_node = gicv2_make_dt_node, -}; - -/* Set up the GIC */ -static int __init gicv2_init (struct dt_device_node *node,const void *data) +static int __init gicv2_init (void ) {int res; - -dt_device_set_used_by (node,DOMID_XEN ); +const struct dt_device_node *node = gicv2_info.node; res =dt_device_get_address (node,0 , &gicv2.dbase,NULL );if ( res || !gicv2.dbase || (gicv2.dbase & ~PAGE_MASK ) )
@@ -708,9 +681,6 @@ static int __init gicv2_init(struct dt_device_node *node, const void *data)panic ("GICv2: Cannot find the maintenance IRQ" ); gicv2_info.maintenance_irq = res; -/* Set the GIC as the primary interrupt controller */ - dt_interrupt_controller = node; -/* TODO: Add check on distributor, cpu size */ printk("GICv2 initialization:\n"
@@ -755,8 +725,42 @@ static int __init gicv2_init(struct dt_device_node *node, const void *data)spin_unlock (&gicv2.lock); +return 0 ; +} + +const static struct gic_hw_operations gicv2_ops = { + .info = &gicv2_info, + .init = gicv2_init, + .secondary_init = gicv2_secondary_cpu_init, + .save_state = gicv2_save_state, + .restore_state = gicv2_restore_state, + .dump_state = gicv2_dump_state, + .gicv_setup = gicv2v_setup, + .gic_host_irq_type = &gicv2_host_irq_type, + .gic_guest_irq_type = &gicv2_guest_irq_type, + .eoi_irq = gicv2_eoi_irq, + .deactivate_irq = gicv2_dir_irq, + .read_irq = gicv2_read_irq, + .set_irq_properties = gicv2_set_irq_properties, + .send_SGI = gicv2_send_SGI, + .disable_interface = gicv2_disable_interface, + .update_lr = gicv2_update_lr, + .update_hcr_status = gicv2_hcr_status, + .clear_lr = gicv2_clear_lr, + .read_lr = gicv2_read_lr, + .write_lr = gicv2_write_lr, + .read_vmcr_priority = gicv2_read_vmcr_priority, + .read_apr = gicv2_read_apr, + .make_dt_node = gicv2_make_dt_node, +}; + +/* Set up the GIC */ +static int __init gicv2_preinit (struct dt_device_node *node,const void *data) +{ gicv2_info.hw_version =GIC_V2 ; + gicv2_info.node = node;register_gic_ops (&gicv2_ops); + dt_irq_xlate = gic_irq_xlate;return 0 ; }
@@ -769,7 +773,7 @@ static const struct dt_device_match gicv2_dt_match[] __initconst =DT_DEVICE_START (gicv2,"GICv2" ,DEVICE_GIC ) .dt_match = gicv2_dt_match, - .init = gicv2_init, + .init = gicv2_preinit,DT_DEVICE_END /*
xen/arch/arm/gic-v3.c +39 -36
115 lines not on this page · raw message
xen/arch/arm/gic.c +14 -2
@@ -163,8 +163,10 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,return 0 ; } -/* Set up the GIC */ -void __init gic_init (void ) +/* Find the interrupt controller and set up the callback to translate +* device tree IRQ. +*/ +void __init gic_preinit (void ) {int rc;struct dt_device_node *node;
@@ -189,6 +191,16 @@ void __init gic_init(void)if ( !num_gics )panic ("Unable to find compatible GIC in the device tree" ); +/* Set the GIC as the primary interrupt controller */ + dt_interrupt_controller = node; +dt_device_set_used_by (node,DOMID_XEN ); +} + +/* Set up the GIC */ +void __init gic_init (void ) +{ +if ( gic_hw_ops->init () ) +panic ("Failed to initialize the GIC drivers" );/* Clear LR mask for cpu0 */ clear_cpu_lr_mask (); }
xen/arch/arm/setup.c +2 -1
@@ -740,10 +740,11 @@ void __init start_xen(unsigned long boot_phys_offset,vm_init ();dt_unflatten_host_device_tree (); - dt_irq_xlate = gic_irq_xlate;init_IRQ (); +gic_preinit (); +dt_uart_init ();console_init_preirq ();console_init_ring ();
xen/include/asm-arm/gic.h +8 -0
@@ -229,6 +229,10 @@ extern void gic_remove_from_queues(struct vcpu *v, unsigned int virtual_irq);/* Accept an interrupt from the GIC and dispatch its handler */ extern void gic_interrupt (struct cpu_user_regs *regs,int is_fiq); +/* Find the interrupt controller and set up the callback to translate +* device tree IRQ. +*/ +extern void gic_preinit (void );/* Bring up the interrupt controller, and report # cpus attached */ extern void gic_init (void );/* Bring up a secondary CPU's per-CPU GIC interface */
@@ -281,11 +285,15 @@ struct gic_info {uint8_t nr_lrs;/* Maintenance irq number */ unsigned int maintenance_irq; +/* Pointer to the device tree node representing the interrupt controller */ +const struct dt_device_node *node; };struct gic_hw_operations {/* Hold GIC HW information */ const struct gic_info *info; +/* Initialize the GIC and the boot CPU */ +int (*init)(void );/* Save GIC registers */ void (*save_state)(struct vcpu *);/* Restore GIC registers */
Signature · 1 line
2.1.4
Re: [PATCH v3 02/24] xen/arm: Divide GIC initialization in 2 parts
Quoted 13 lines · Julien Grall
Currently the function to translate IRQ from the device tree is set unconditionally to be able to be able to retrieve serial/timer IRQ before the GIC has been initialized.
It assumes that the xlate function won't never changed. We may also need to have the primary interrupt controller very early.
Rework the gic initialization in 2 parts:
-gic_preinit: Get the interrupt controller device tree node and set
up GIC and xlate callbacks
-gic_init: Initialize the interrupt controller and the boot CPU interrupts.
Quoted 4 lines
The former function will be called just after the IRQ subsystem as been initialized.
Signed-off-by Julien Grall <[email protected]>
Quoted 336 lines
---
Changes in v3:
- Patch was previously sent in a separate series [1]
- Reorder the function to avoid forward declaration
- Make gic-v3 driver compliant to the new interface
- Remove spurious field addition in gicv2 structureChangelog based on the separate series:
Changes in v3:
- Patch added.[1] https://patches.linaro.org/33313/
--- xen/arch/arm/gic-v2.c | 70 ++++++++++++++++++++++--------------------- xen/arch/arm/gic-v3.c | 75 ++++++++++++++++++++++++----------------------- xen/arch/arm/gic.c | 16 ++++++++-- xen/arch/arm/setup.c | 3 +- xen/include/asm-arm/gic.h | 8 +++++ 5 files changed, 100 insertions(+), 72 deletions(-)xen/arch/arm/gic-v2.c +37
-33@@ -655,37 +655,10 @@ static hw_irq_controller gicv2_guest_irq_type = { .set_affinity = gicv2_irq_set_affinity, }; -const static struct gic_hw_operations gicv2_ops = { - .info = &gicv2_info, - .secondary_init = gicv2_secondary_cpu_init, - .save_state = gicv2_save_state, - .restore_state = gicv2_restore_state, - .dump_state = gicv2_dump_state, - .gicv_setup = gicv2v_setup, - .gic_host_irq_type = &gicv2_host_irq_type, - .gic_guest_irq_type = &gicv2_guest_irq_type, - .eoi_irq = gicv2_eoi_irq, - .deactivate_irq = gicv2_dir_irq, - .read_irq = gicv2_read_irq, - .set_irq_properties = gicv2_set_irq_properties, - .send_SGI = gicv2_send_SGI, - .disable_interface = gicv2_disable_interface, - .update_lr = gicv2_update_lr, - .update_hcr_status = gicv2_hcr_status, - .clear_lr = gicv2_clear_lr, - .read_lr = gicv2_read_lr, - .write_lr = gicv2_write_lr, - .read_vmcr_priority = gicv2_read_vmcr_priority, - .read_apr = gicv2_read_apr, - .make_dt_node = gicv2_make_dt_node, -}; - -/* Set up the GIC */ -static int __init gicv2_init (struct dt_device_node *node,const void *data) +static int __init gicv2_init (void ) {int res; - -dt_device_set_used_by (node,DOMID_XEN ); +const struct dt_device_node *node = gicv2_info.node; res =dt_device_get_address (node,0 , &gicv2.dbase,NULL );if ( res || !gicv2.dbase || (gicv2.dbase & ~PAGE_MASK ) )@@ -708,9 +681,6 @@ static int __init gicv2_init(struct dt_device_node *node, const void *data)panic ("GICv2: Cannot find the maintenance IRQ" ); gicv2_info.maintenance_irq = res; -/* Set the GIC as the primary interrupt controller */ - dt_interrupt_controller = node; -/* TODO: Add check on distributor, cpu size */ printk("GICv2 initialization:\n"@@ -755,8 +725,42 @@ static int __init gicv2_init(struct dt_device_node *node, const void *data)spin_unlock (&gicv2.lock); +return 0 ; +} + +const static struct gic_hw_operations gicv2_ops = { + .info = &gicv2_info, + .init = gicv2_init, + .secondary_init = gicv2_secondary_cpu_init, + .save_state = gicv2_save_state, + .restore_state = gicv2_restore_state, + .dump_state = gicv2_dump_state, + .gicv_setup = gicv2v_setup, + .gic_host_irq_type = &gicv2_host_irq_type, + .gic_guest_irq_type = &gicv2_guest_irq_type, + .eoi_irq = gicv2_eoi_irq, + .deactivate_irq = gicv2_dir_irq, + .read_irq = gicv2_read_irq, + .set_irq_properties = gicv2_set_irq_properties, + .send_SGI = gicv2_send_SGI, + .disable_interface = gicv2_disable_interface, + .update_lr = gicv2_update_lr, + .update_hcr_status = gicv2_hcr_status, + .clear_lr = gicv2_clear_lr, + .read_lr = gicv2_read_lr, + .write_lr = gicv2_write_lr, + .read_vmcr_priority = gicv2_read_vmcr_priority, + .read_apr = gicv2_read_apr, + .make_dt_node = gicv2_make_dt_node, +}; + +/* Set up the GIC */ +static int __init gicv2_preinit (struct dt_device_node *node,const void *data) +{ gicv2_info.hw_version =GIC_V2 ; + gicv2_info.node = node;register_gic_ops (&gicv2_ops); + dt_irq_xlate = gic_irq_xlate;return 0 ; }@@ -769,7 +773,7 @@ static const struct dt_device_match gicv2_dt_match[] __initconst =DT_DEVICE_START (gicv2,"GICv2" ,DEVICE_GIC ) .dt_match = gicv2_dt_match, - .init = gicv2_init, + .init = gicv2_preinit,DT_DEVICE_END /* xen/arch/arm/gic-v3.c +39
-36@@ -1141,37 +1141,13 @@ static const hw_irq_controller gicv3_guest_irq_type = { .set_affinity = gicv3_irq_set_affinity, }; -static const struct gic_hw_operations gicv3_ops = { - .info = &gicv3_info, - .save_state = gicv3_save_state, - .restore_state = gicv3_restore_state, - .dump_state = gicv3_dump_state, - .gicv_setup = gicv_v3_init, - .gic_host_irq_type = &gicv3_host_irq_type, - .gic_guest_irq_type = &gicv3_guest_irq_type, - .eoi_irq = gicv3_eoi_irq, - .deactivate_irq = gicv3_dir_irq, - .read_irq = gicv3_read_irq, - .set_irq_properties = gicv3_set_irq_properties, - .send_SGI = gicv3_send_sgi, - .disable_interface = gicv3_disable_interface, - .update_lr = gicv3_update_lr, - .update_hcr_status = gicv3_hcr_status, - .clear_lr = gicv3_clear_lr, - .read_lr = gicv3_read_lr, - .write_lr = gicv3_write_lr, - .read_vmcr_priority = gicv3_read_vmcr_priority, - .read_apr = gicv3_read_apr, - .secondary_init = gicv3_secondary_cpu_init, - .make_dt_node = gicv3_make_dt_node, -}; -/* Set up the GIC */ -static int __init gicv3_init (struct dt_device_node *node,const void *data) +static int __init gicv3_init (void ) {struct rdist_region *rdist_regs;int res, i;uint32_t reg; +const struct dt_device_node *node = gicv3_info.node;if ( !cpu_has_gicv3 ) {@@ -1179,8 +1155,6 @@ static int __init gicv3_init(struct dt_device_node *node, const void *data)return -ENODEV ; } -dt_device_set_used_by (node,DOMID_XEN ); - res =dt_device_get_address (node,0 , &gicv3.dbase, &gicv3.dbase_size);if ( res || !gicv3.dbase )panic ("GICv3: Cannot find a valid distributor address" );@@ -1232,9 +1206,6 @@ static int __init gicv3_init(struct dt_device_node *node, const void *data)panic ("GICv3: Cannot find the maintenance IRQ" ); gicv3_info.maintenance_irq = res; -/* Set the GIC as the primary interrupt controller */ - dt_interrupt_controller = node; -for ( i =0 ; i < gicv3.rdist_count; i++ ) {/* map dbase & rdist regions */ @@ -1269,15 +1240,47 @@ static int __init gicv3_init(struct dt_device_node *node, const void *data) res =gicv3_cpu_init ();gicv3_hyp_init (); - gicv3_info.hw_version =GIC_V3 ; -/* Register hw ops*/ -register_gic_ops (&gicv3_ops); -spin_unlock (&gicv3.lock);return res; } +static const struct gic_hw_operations gicv3_ops = { + .info = &gicv3_info, + .init = gicv3_init, + .save_state = gicv3_save_state, + .restore_state = gicv3_restore_state, + .dump_state = gicv3_dump_state, + .gicv_setup = gicv_v3_init, + .gic_host_irq_type = &gicv3_host_irq_type, + .gic_guest_irq_type = &gicv3_guest_irq_type, + .eoi_irq = gicv3_eoi_irq, + .deactivate_irq = gicv3_dir_irq, + .read_irq = gicv3_read_irq, + .set_irq_properties = gicv3_set_irq_properties, + .send_SGI = gicv3_send_sgi, + .disable_interface = gicv3_disable_interface, + .update_lr = gicv3_update_lr, + .update_hcr_status = gicv3_hcr_status, + .clear_lr = gicv3_clear_lr, + .read_lr = gicv3_read_lr, + .write_lr = gicv3_write_lr, + .read_vmcr_priority = gicv3_read_vmcr_priority, + .read_apr = gicv3_read_apr, + .secondary_init = gicv3_secondary_cpu_init, + .make_dt_node = gicv3_make_dt_node, +}; + +static int __init gicv3_preinit (struct dt_device_node *node,const void *data) +{ + gicv3_info.hw_version =GIC_V3 ; + gicv3_info.node = node; +register_gic_ops (&gicv3_ops); + dt_irq_xlate = gic_irq_xlate; + +return 0 ; +} +static const struct dt_device_match gicv3_dt_match[]__initconst = {DT_MATCH_GIC_V3 ,@@ -1286,7 +1289,7 @@ static const struct dt_device_match gicv3_dt_match[] __initconst =DT_DEVICE_START (gicv3,"GICv3" ,DEVICE_GIC ) .dt_match = gicv3_dt_match, - .init = gicv3_init, + .init = gicv3_preinit,DT_DEVICE_END /* xen/arch/arm/gic.c +14
-2@@ -163,8 +163,10 @@ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,return 0 ; } -/* Set up the GIC */ -void __init gic_init (void ) +/* Find the interrupt controller and set up the callback to translate +* device tree IRQ. +*/ +void __init gic_preinit (void ) {int rc;struct dt_device_node *node;@@ -189,6 +191,16 @@ void __init gic_init(void)if ( !num_gics )panic ("Unable to find compatible GIC in the device tree" ); +/* Set the GIC as the primary interrupt controller */ + dt_interrupt_controller = node; +dt_device_set_used_by (node,DOMID_XEN ); +} + +/* Set up the GIC */ +void __init gic_init (void ) +{ +if ( gic_hw_ops->init () ) +panic ("Failed to initialize the GIC drivers" );/* Clear LR mask for cpu0 */ clear_cpu_lr_mask (); }xen/arch/arm/setup.c +2
-1@@ -740,10 +740,11 @@ void __init start_xen(unsigned long boot_phys_offset,vm_init ();dt_unflatten_host_device_tree (); - dt_irq_xlate = gic_irq_xlate;init_IRQ (); +gic_preinit (); +dt_uart_init ();console_init_preirq ();console_init_ring ();xen/include/asm-arm/gic.h +8
-0@@ -229,6 +229,10 @@ extern void gic_remove_from_queues(struct vcpu *v, unsigned int virtual_irq);/* Accept an interrupt from the GIC and dispatch its handler */ extern void gic_interrupt (struct cpu_user_regs *regs,int is_fiq); +/* Find the interrupt controller and set up the callback to translate +* device tree IRQ. +*/ +extern void gic_preinit (void );/* Bring up the interrupt controller, and report # cpus attached */ extern void gic_init (void );/* Bring up a secondary CPU's per-CPU GIC interface */ @@ -281,11 +285,15 @@ struct gic_info {uint8_t nr_lrs;/* Maintenance irq number */ unsigned int maintenance_irq; +/* Pointer to the device tree node representing the interrupt controller */ +const struct dt_device_node *node; };struct gic_hw_operations {/* Hold GIC HW information */ const struct gic_info *info; +/* Initialize the GIC and the boot CPU */ +int (*init)(void );/* Save GIC registers */ void (*save_state)(struct vcpu *);/* Restore GIC registers */ Signature · 1 line
2.1.4
Ian Campbell
Acked-byRe: [PATCH v3 02/24] xen/arm: Divide GIC initialization in 2 parts
Quoted 14 lines · Stefano Stabellini
Quoted 13 lines · Julien Grall
Currently the function to translate IRQ from the device tree is set unconditionally to be able to be able to retrieve serial/timer IRQ before the GIC has been initialized.
It assumes that the xlate function won't never changed. We may also need to have the primary interrupt controller very early.
Rework the gic initialization in 2 parts:
-gic_preinit: Get the interrupt controller device tree node and set
up GIC and xlate callbacks
-gic_init: Initialize the interrupt controller and the boot CPU interrupts.
Quoted 6 lines
Quoted 4 lines
The former function will be called just after the IRQ subsystem as been initialized.
Signed-off-by Julien Grall <[email protected]>
Re: [PATCH v3 02/24] xen/arm: Divide GIC initialization in 2 parts
In reply to Julien GrallQuoted 5 lines · Julien Grall
Currently the function to translate IRQ from the device tree is set unconditionally to be able to be able to retrieve serial/timer IRQ before the GIC has been initialized.
It assumes that the xlate function won't never changed. We may also need to
Forgot to say: either "will never change" or "won't ever change" here
PATCH v3 3/24 xen/dts: Allow only IRQ translation that are mapped to main GIC
In reply to Julien GrallXen is only able to handle one GIC controller. Some platform may contain other interrupt controller.
Make sure to only translate IRQ mapped into the GIC handled by Xen.
---
Changes in v3:
- Patch was previously sent a separate series [1]
- Rework the comment in dt_irq_translate.
Changelog based on the separate series:
Changes in v3:
- Add an ASSERT to check that dt_interrupt_controller is not NULL.
Changes in v2:
- Fix compilation...
[1] https://patches.linaro.org/33312/
--- xen/common/device_tree.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/common/device_tree.c +7 -1
@@ -1058,8 +1058,14 @@ int dt_irq_translate(const struct dt_raw_irq *raw, struct dt_irq *out_irq) {ASSERT (dt_irq_xlate !=NULL ); +ASSERT (dt_interrupt_controller !=NULL ); -/* TODO: Retrieve the right irq_xlate. This is only work for the gic */ +/* +* TODO: Retrieve the right irq_xlate. This is only works for the primary +* interrupt controller. +*/ +if ( raw->controller != dt_interrupt_controller ) +return -EINVAL ;return dt_irq_xlate (raw->specifier, raw->size, &out_irq->irq, &out_irq->type);
Signature · 1 line
2.1.4
Re: [PATCH v3 03/24] xen/dts: Allow only IRQ translation that are mapped to main GIC
Quoted 7 lines · Julien Grall
Xen is only able to handle one GIC controller. Some platform may contain other interrupt controller.
Make sure to only translate IRQ mapped into the GIC handled by Xen.
Signed-off-by Julien Grall <[email protected]>
Quoted 42 lines
Changes in v3:
- Patch was previously sent a separate series [1]
- Rework the comment indt_irq_translate.Changelog based on the separate series:
Changes in v3:
- Add an ASSERT to check thatdt_interrupt_controlleris not NULL.Changes in v2:
- Fix compilation...[1] https://patches.linaro.org/33312/
--- xen/common/device_tree.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/common/device_tree.c +7
-1@@ -1058,8 +1058,14 @@ int dt_irq_translate(const struct dt_raw_irq *raw, struct dt_irq *out_irq) {ASSERT (dt_irq_xlate !=NULL ); +ASSERT (dt_interrupt_controller !=NULL ); -/* TODO: Retrieve the right irq_xlate. This is only work for the gic */ +/* +* TODO: Retrieve the right irq_xlate. This is only works for the primary +* interrupt controller. +*/ +if ( raw->controller != dt_interrupt_controller ) +return -EINVAL ;return dt_irq_xlate (raw->specifier, raw->size, &out_irq->irq, &out_irq->type);Signature · 1 line
2.1.4
Re: [PATCH v3 03/24] xen/dts: Allow only IRQ translation that are mapped to main GIC
In reply to Julien GrallQuoted 2 lines · Julien Grall
Xen is only able to handle one GIC controller. Some platform may contain other interrupt controller.
"platforms" and "controllers"
Quoted 3 lines
Make sure to only translate IRQ mapped into the GIC handled by Xen.
Signed-off-by Julien Grall <[email protected]>
PATCH v3 4/24 xen: guestcopy: Provide an helper to safely copy string from guest
In reply to Julien GrallFlask code already provides an helper to copy a string from guest. In a later patch, the new DT hypercalls will need a similar function.
To avoid code duplication, copy the flask helper (flask_copying_string) to common code:
- Rename into safe_copy_string_from_guest
- Add comment to explain the extra +1
- Return directly the buffer and use the macros provided by xen/err.h to return an error code if necessary.
---
Changes in v3:
- Use macros of xen/err.h to return either the buffer or an error code
- Reuse size_t instead of unsigned long
- Update comment and commit message
Changes in v2:
- Rename copy_string_from_guest into safe_copy_string_from_guest
- Update commit message and comment in the code
--- xen/common/Makefile | 1 + xen/common/guestcopy.c | 30 +++++++++++++++++++++++++++++ xen/include/xen/guest_access.h | 5 +++++ xen/xsm/flask/flask_op.c | 43 ++++++++++-------------------------------- 4 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 xen/common/guestcopy.c
xen/common/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-y += event_2l.o obj-y += event_channel.o obj-y += event_fifo.o obj-y += grant_table.o +obj-y += guestcopy.o obj-y += irq.o obj-y += kernel.o obj-y += keyhandler.o
xen/common/guestcopy.c new file +30 -0
@@ -0,0 +1,30 @@ +#include <xen/config.h> +#include <xen/lib.h> +#include <xen/guest_access.h> +#include <xen/err.h> + +/* The function copies a string from the guest and adds a NUL to +* make sure the string is correctly terminated. +*/ +void *safe_copy_string_from_guest (XEN_GUEST_HANDLE (char ) u_buf, +size_t size,size_t max_size) +{ +char *tmp; + +if ( size > max_size ) +return ERR_PTR (-ENOENT ); + +/* Add an extra +1 to append \0 */ + tmp =xmalloc_array (char, size +1 ); +if ( !tmp ) +return ERR_PTR (-ENOMEM ); + +if (copy_from_guest (tmp, u_buf, size) ) + { +xfree (tmp); +return ERR_PTR (-EFAULT ); + } + tmp[size] =0 ; + +return tmp; +}
xen/include/xen/guest_access.h +5 -0
@@ -8,6 +8,8 @@#define __XEN_GUEST_ACCESS_H__#include <asm/guest_access.h> +#include <xen/types.h> +#include <public/xen.h> #define copy_to_guest (hnd, ptr, nr) \ copy_to_guest_offset(hnd, 0, ptr, nr)
@@ -27,4 +29,7 @@#define __clear_guest (hnd, nr) \ __clear_guest_offset(hnd, 0, nr) +void *safe_copy_string_from_guest (XEN_GUEST_HANDLE (char ) u_buf, +size_t size,size_t max_size); +#endif /* __XEN_GUEST_ACCESS_H__ */
xen/xsm/flask/flask_op.c +10 -33
77 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest
Quoted 11 lines · Julien Grall
Flask code already provides an helper to copy a string from guest. In a later patch, the new DT hypercalls will need a similar function.
To avoid code duplication, copy the flask helper (
flask_copying_string) to common code:
- Rename intosafe_copy_string_from_guest
- Add comment to explain the extra +1
- Return directly the buffer and use the macros provided byxen/err.hto return an error code if necessary.Signed-off-by Julien Grall <[email protected]>
Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest
In reply to Julien Grallxen/common/guestcopy.c line 8
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/common/guestcopy.c new file +8
-0@@ -0,0 +1,30 @@ +#include <xen/config.h> +#include <xen/lib.h> +#include <xen/guest_access.h> +#include <xen/err.h> + +/* The function copies a string from the guest and adds a NUL to +* make sure the string is correctly terminated. +*/
Coding style.
xen/common/guestcopy.c line 10
Quoted 2 lines
xen/common/guestcopy.c new file +2
-0+void *safe_copy_string_from_guest (XEN_GUEST_HANDLE (char ) u_buf, +size_t size,size_t max_size)
Is the "safe_" prefix really meaningful? I.e. is this function more safe than e.g. copy_from_guest()?
xen/common/guestcopy.c line 15
Quoted 5 lines
xen/common/guestcopy.c new file +5
-0+{ +char *tmp; + +if ( size > max_size ) +return ERR_PTR (-ENOENT );
-ENOBUFS?
Jan
Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest
Hi Jan,
Quoted 14 lines · Jan Beulich
xen/common/guestcopy.c line 8
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/common/guestcopy.c new file +8
-0@@ -0,0 +1,30 @@ +#include <xen/config.h> +#include <xen/lib.h> +#include <xen/guest_access.h> +#include <xen/err.h> + +/* The function copies a string from the guest and adds a NUL to +* make sure the string is correctly terminated. +*/ Coding style.
Ok.
Quoted 6 lines
xen/common/guestcopy.c line 10
Quoted 3 lines
xen/common/guestcopy.c new file +2
-0+void *safe_copy_string_from_guest (XEN_GUEST_HANDLE (char ) u_buf, +size_t size,size_t max_size)Is the "
safe_" prefix really meaningful? I.e. is this function more safe than e.g.copy_from_guest()?
It's safe in the sense, the function adds a NUL to make sure the strings is correctly terminated.
On the first v1, you said that name "copy_string_from_guest" doesn't match the behavior of the generic helper [1]. So which name do you suggest for this function?
Quoted 8 lines
xen/common/guestcopy.c line 15
Quoted 6 lines
xen/common/guestcopy.c new file +5
-0+{ +char *tmp; + +if ( size > max_size ) +return ERR_PTR (-ENOENT );
-ENOBUFS?
I will use it.
Regards,
[1] http://lists.xen.org/archives/html/xen-devel/2014-06/msg02361.html
Signature · 1 line
Julien Grall
Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 13:45, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/common/guestcopy.c line 10
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/common/guestcopy.c new file +2
-0+void *safe_copy_string_from_guest (XEN_GUEST_HANDLE (char ) u_buf, +size_t size,size_t max_size)Is the "
safe_" prefix really meaningful? I.e. is this function more safe than e.g.copy_from_guest()?
Quoted 6 lines
It's safe in the sense, the function adds a NUL to make sure the strings is correctly terminated.
On the first v1, you said that name "
copy_string_from_guest" doesn't match the behavior of the generic helper [1]. So which name do you suggest for this function?
Ah, so the safe_ here follows safe_str{cat,cpy}() - that's fine then I guess.
Jan
Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest
In reply to Julien GrallQuoted 1 line · Julien Grall
Flask code already provides an helper to copy a string from guest. In a later
"a helper".
Quoted 7 lines
patch, the new DT hypercalls will need a similar function.
To avoid code duplication, copy the flask helper (
flask_copying_string) to common code:
- Rename intosafe_copy_string_from_guest
- Add comment to explain the extra +1
- Return directly the buffer and use the macros provided by
"Return the buffer directly and...".
Quoted 7 lines
xen/err.hto return an error code if necessary.Signed-off-by Julien Grall <[email protected]>Cc Daniel De Graaf <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Keir Fraser <[email protected]>
PATCH v3 5/24 xen/arm: vgic: Introduce a function to initialize pending_irq
In reply to Julien GrallThe structure pending_irq is initialized on the same way in 2 differents place. Introduce vgic_init_pending_irq to avoid code duplication.
Also move the setting of the irq field in this function as we need to initialize it once rather than every time an IRQ is injected to the guest.
Finally, use unsigned int for the "irq" field to be consistent with the virq variable
---
Changes in v3:
- Add Stefano's acked
- The irq field is now unsigned int
- Update commit message to speak about the int -> unsigned int change
- Use "unsigned int" rather than "unsigned"
Changes in v2:
- Patch added
--- xen/arch/arm/gic.c | 2 +- xen/arch/arm/vgic.c | 19 ++++++++++--------- xen/include/asm-arm/vgic.h | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-)
xen/arch/arm/gic.c +1 -1
@@ -627,7 +627,7 @@ void gic_dump_info(struct vcpu *v) list_for_each_entry ( p, &v->arch.vgic.inflight_irqs, inflight ) { -printk ("Inflight irq=%d lr=%u\n" , p->irq, p->lr); +printk ("Inflight irq=%u lr=%u\n" , p->irq, p->lr); }list_for_each_entry ( p, &v->arch.vgic.lr_pending, lr_queue )
xen/arch/arm/vgic.c +10 -9
@@ -60,6 +60,13 @@ struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq)return vgic_get_rank (v, rank); } +static void vgic_init_pending_irq (struct pending_irq *p,unsigned int virq) +{ +INIT_LIST_HEAD (&p->inflight); +INIT_LIST_HEAD (&p->lr_queue); + p->irq = virq; +} +int domain_vgic_init (struct domain *d) {int i;
@@ -100,10 +107,8 @@ int domain_vgic_init(struct domain *d)return -ENOMEM ;for (i=0 ; i<d->arch.vgic.nr_spis; i++) - { -INIT_LIST_HEAD (&d->arch.vgic.pending_irqs[i].inflight); -INIT_LIST_HEAD (&d->arch.vgic.pending_irqs[i].lr_queue); - } +vgic_init_pending_irq (&d->arch.vgic.pending_irqs[i], i +32 ); +for (i=0 ; i<DOMAIN_NR_RANKS (d); i++)spin_lock_init (&d->arch.vgic.shared_irqs[i].lock);
@@ -147,10 +152,7 @@ int vcpu_vgic_init(struct vcpu *v)memset (&v->arch.vgic.pending_irqs,0 ,sizeof (v->arch.vgic.pending_irqs));for (i =0 ; i <32 ; i++) - { -INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].inflight); -INIT_LIST_HEAD (&v->arch.vgic.pending_irqs[i].lr_queue); - } +vgic_init_pending_irq (&v->arch.vgic.pending_irqs[i], i);INIT_LIST_HEAD (&v->arch.vgic.inflight_irqs);INIT_LIST_HEAD (&v->arch.vgic.lr_pending);
@@ -407,7 +409,6 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq) goto out; } - n->irq = irq; n->priority = priority;/* the irq is enabled */
xen/include/asm-arm/vgic.h +1 -1
@@ -67,7 +67,7 @@ struct pending_irq#define GIC_IRQ_GUEST_MIGRATING 4unsigned long status;struct irq_desc *desc;/* only set it the irq corresponds to a physical irq */ -int irq; +unsigned int irq;#define GIC_INVALID_LR ~(uint8_t)0uint8_t lr;uint8_t priority;
Signature · 1 line
2.1.4
Re: [PATCH v3 05/24] xen/arm: vgic: Introduce a function to initialize pending_irq
Quoted 1 line · Julien Grall
The structure
pending_irqis initialized on the same way in 2 differents
"in the same way in 2 different places".
Quoted 3 lines
place. Introduce
vgic_init_pending_irqto avoid code duplication.Also move the setting of the irq field in this function as we need to
"...into this function..."
Quoted 7 lines
initialize it once rather than every time an IRQ is injected to the guest.
Finally, use unsigned int for the "irq" field to be consistent with the virq variable
Signed-off-by Julien Grall <[email protected]>
PATCH v3 6/24 xen/arm: Map disabled device in DOM0
In reply to Julien GrallThe check to avoid mapping disabled device in DOM0 was added in the anticipation of the device passthrough. But, a brand new property will be added later to mark device which will passthrough. At the same time, remove the memory type check because those nodes has been blacklisted.
Futhermore, some platform (such as the OMAP) may try to poke device even if the property "status" is set to "disabled".
---
Changes in v3:
- Patch added
- "xen/arm: follow-up to allow DOM0 manage IRQ and MMIO" has been split in 2 patch [1]
- Drop the check for memory type. Thoses nodes have been blacklisted.
[1] https://patches.linaro.org/34669/
--- xen/arch/arm/domain_build.c | 19 +++---------------- xen/arch/arm/platforms/omap5.c | 12 ------------ 2 files changed, 3 insertions(+), 28 deletions(-)
xen/arch/arm/domain_build.c +3 -16
@@ -1104,22 +1104,9 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,return 0 ; } -/* -* Some device doesn't need to be mapped in Xen: -* - Memory: the guest will see a different view of memory. It will -* be allocated later. -* - Disabled device: Linux is able to cope with status="disabled" -* property. Therefore these device doesn't need to be mapped. This -* solution can be use later for pass through. -*/ -if ( !dt_device_type_is_equal (node,"memory" ) && -dt_device_is_available (node) ) - { - res =map_device (d, node); - -if ( res ) -return res; - } + res =map_device (d, node); +if ( res) +return res;/* * The property "name" is used to have a different name on older FDT
xen/arch/arm/platforms/omap5.c +0 -12
@@ -155,17 +155,6 @@ static const char * const dra7_dt_compat[] __initconst =NULL }; -static const struct dt_device_match dra7_blacklist_dev[]__initconst = -{ -/* OMAP Linux kernel handles devices with status "disabled" in a -* weird manner - tries to reset them. While their memory ranges -* are not mapped, this leads to data aborts, so skip these devices -* from DT for dom0. -*/ -DT_MATCH_NOT_AVAILABLE (), - {/* sentinel */ }, -}; -PLATFORM_START (omap5,"TI OMAP5" ) .compatible = omap5_dt_compat, .init_time = omap5_init_time,
@@ -185,7 +174,6 @@ PLATFORM_START(dra7, "TI DRA7") .dom0_gnttab_start = 0x4b000000, .dom0_gnttab_size =0x20000 , - .blacklist_dev = dra7_blacklist_dev,PLATFORM_END /*
Signature · 1 line
2.1.4
Re: [PATCH v3 06/24] xen/arm: Map disabled device in DOM0
Quoted 4 lines · Julien Grall
The check to avoid mapping disabled device in DOM0 was added in the anticipation of the device passthrough. But, a brand new property will be added later to mark device which will passthrough. At the same time, remove the memory type check because those nodes has been blacklisted.
Sorry, I don't understand the explanation on why you removed the check on dt_device_type_is_equal(node, "memory") too.
Quoted 84 lines
Futhermore, some platform (such as the OMAP) may try to poke device even if the property "status" is set to "disabled".
Signed-off-by Julien Grall <[email protected]>Cc Andrii Tseglytskyi <[email protected]>---
Changes in v3:
- Patch added
- "xen/arm: follow-up to allow DOM0 manage IRQ and MMIO" has been split in 2 patch [1]
- Drop the check for memory type. Thoses nodes have been blacklisted.[1] https://patches.linaro.org/34669/
--- xen/arch/arm/domain_build.c | 19 +++---------------- xen/arch/arm/platforms/omap5.c | 12 ------------ 2 files changed, 3 insertions(+), 28 deletions(-)xen/arch/arm/domain_build.c +3
-16@@ -1104,22 +1104,9 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,return 0 ; } -/* -* Some device doesn't need to be mapped in Xen: -* - Memory: the guest will see a different view of memory. It will -* be allocated later. -* - Disabled device: Linux is able to cope with status="disabled" -* property. Therefore these device doesn't need to be mapped. This -* solution can be use later for pass through. -*/ -if ( !dt_device_type_is_equal (node,"memory" ) && -dt_device_is_available (node) ) - { - res =map_device (d, node); - -if ( res ) -return res; - } + res =map_device (d, node); +if ( res) +return res;/* * The property "name" is used to have a different name on older FDT xen/arch/arm/platforms/omap5.c +0
-12@@ -155,17 +155,6 @@ static const char * const dra7_dt_compat[] __initconst =NULL }; -static const struct dt_device_match dra7_blacklist_dev[]__initconst = -{ -/* OMAP Linux kernel handles devices with status "disabled" in a -* weird manner - tries to reset them. While their memory ranges -* are not mapped, this leads to data aborts, so skip these devices -* from DT for dom0. -*/ -DT_MATCH_NOT_AVAILABLE (), - {/* sentinel */ }, -}; -PLATFORM_START (omap5,"TI OMAP5" ) .compatible = omap5_dt_compat, .init_time = omap5_init_time,@@ -185,7 +174,6 @@ PLATFORM_START(dra7, "TI DRA7") .dom0_gnttab_start = 0x4b000000, .dom0_gnttab_size =0x20000 , - .blacklist_dev = dra7_blacklist_dev,PLATFORM_END /* Signature · 1 line
2.1.4
Re: [PATCH v3 06/24] xen/arm: Map disabled device in DOM0
Hi Stefano,
Quoted 8 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall
The check to avoid mapping disabled device in DOM0 was added in the anticipation of the device passthrough. But, a brand new property will be added later to mark device which will passthrough. At the same time, remove the memory type check because those nodes has been blacklisted.
Sorry, I don't understand the explanation on why you removed the check on
dt_device_type_is_equal(node, "memory")too.
The memory nodes has been skipped earlier via the skip_matches variable.
How about "Also, remove the memory type check as we already skipped them earlier in the function"?
Regards,
Signature · 1 line
Julien Grall
Stefano Stabellini
Acked-byRe: [PATCH v3 06/24] xen/arm: Map disabled device in DOM0
Quoted 9 lines · Julien Grall
Hi Stefano,
Quoted 6 lines · Stefano Stabellini
Quoted 4 lines · Julien Grall
The check to avoid mapping disabled device in DOM0 was added in the anticipation of the device passthrough. But, a brand new property will be added later to mark device which will passthrough. At the same time, remove the memory type check because those nodes has been blacklisted.
Quoted 7 lines
Quoted 2 lines
Sorry, I don't understand the explanation on why you removed the check on
dt_device_type_is_equal(node, "memory")too.The memory nodes has been skipped earlier via the
skip_matchesvariable.How about "Also, remove the memory type check as we already skipped them earlier in the function"?
"earlier in the function via skip_matches."
With that:
Re: [PATCH v3 06/24] xen/arm: Map disabled device in DOM0
In reply to Julien GrallQuoted 1 line · Julien Grall
The check to avoid mapping disabled device in DOM0 was added in the anticipation
"disabled devices" and "in anticipation of device passthrough"
Quoted 2 lines
of the device passthrough. But, a brand new property will be added later to mark device which will passthrough. At the same time, remove the memory type
"which will be passedthrough" or maybe "which will be passthrough"? (It's hard to say because passthrough isn't really a word...)
Quoted 3 lines
check because those nodes has been blacklisted.
Futhermore, some platform (such as the OMAP) may try to poke device even
"Furthermore".
Quoted 4 lines
if the property "status" is set to "disabled".
Signed-off-by Julien Grall <[email protected]>Cc Andrii Tseglytskyi <[email protected]>
With that and the change Stefano requested:
Quoted 76 lines
---
Changes in v3:
- Patch added
- "xen/arm: follow-up to allow DOM0 manage IRQ and MMIO" has been split in 2 patch [1]
- Drop the check for memory type. Thoses nodes have been blacklisted.[1] https://patches.linaro.org/34669/
--- xen/arch/arm/domain_build.c | 19 +++---------------- xen/arch/arm/platforms/omap5.c | 12 ------------ 2 files changed, 3 insertions(+), 28 deletions(-)xen/arch/arm/domain_build.c +3
-16@@ -1104,22 +1104,9 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,return 0 ; } -/* -* Some device doesn't need to be mapped in Xen: -* - Memory: the guest will see a different view of memory. It will -* be allocated later. -* - Disabled device: Linux is able to cope with status="disabled" -* property. Therefore these device doesn't need to be mapped. This -* solution can be use later for pass through. -*/ -if ( !dt_device_type_is_equal (node,"memory" ) && -dt_device_is_available (node) ) - { - res =map_device (d, node); - -if ( res ) -return res; - } + res =map_device (d, node); +if ( res) +return res;/* * The property "name" is used to have a different name on older FDT xen/arch/arm/platforms/omap5.c +0
-12@@ -155,17 +155,6 @@ static const char * const dra7_dt_compat[] __initconst =NULL }; -static const struct dt_device_match dra7_blacklist_dev[]__initconst = -{ -/* OMAP Linux kernel handles devices with status "disabled" in a -* weird manner - tries to reset them. While their memory ranges -* are not mapped, this leads to data aborts, so skip these devices -* from DT for dom0. -*/ -DT_MATCH_NOT_AVAILABLE (), - {/* sentinel */ }, -}; -PLATFORM_START (omap5,"TI OMAP5" ) .compatible = omap5_dt_compat, .init_time = omap5_init_time,@@ -185,7 +174,6 @@ PLATFORM_START(dra7, "TI DRA7") .dom0_gnttab_start = 0x4b000000, .dom0_gnttab_size =0x20000 , - .blacklist_dev = dra7_blacklist_dev,PLATFORM_END /*
PATCH v3 7/24 xen/arm: Introduce xen, passthrough property
In reply to Julien GrallWhen a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Rework the function map_device (renamed into handle_device) to:
* For a given device node:
- Give permission to manage IRQ/MMIO for this device
- Retrieve the IRQ configuration (i.e edge/level) from the device tree
* When the device is not marked for guest passthrough:
- Assign the device to the guest if it's protected by an IOMMU
- Map the IRQs and MMIOs regions to the guest
---
Changes in v3:
- This patch was formely "xen/arm: Follow-up to allow DOM0 manage IRQ and MMIO". It has been split in 2 parts [1].
- Update commit title and improve message
- Remove spurious change
[1] https://patches.linaro.org/34669/
--- docs/misc/arm/device-tree/passthrough.txt | 7 ++ xen/arch/arm/device.c | 2 +- xen/arch/arm/domain_build.c | 102 ++++++++++++++++++++++-------- xen/common/device_tree.c | 6 ++ xen/include/xen/device_tree.h | 11 ++++ 5 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 docs/misc/arm/device-tree/passthrough.txt
docs/misc/arm/device-tree/passthrough.txt new file +7 -0
@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.
xen/arch/arm/device.c +1 -1
@@ -30,7 +30,7 @@ int __init device_init(struct dt_device_node *dev, enum device_match type,ASSERT (dev !=NULL ); -if ( !dt_device_is_available (dev) ) +if ( !dt_device_is_available (dev) ||dt_device_for_passthrough (dev) )return -ENODEV ;for ( desc = _sdevice; desc != _edevice; desc++ )
xen/arch/arm/domain_build.c +75 -27
168 lines not on this page · raw message
xen/common/device_tree.c +6 -0
@@ -1103,6 +1103,12 @@ bool_t dt_device_is_available(const struct dt_device_node *device)return 0 ; } +bool_t dt_device_for_passthrough (const struct dt_device_node *device) +{ +return (dt_find_property (device,"xen,passthrough" ,NULL ) !=NULL ); + +} + static int __dt_parse_phandle_with_args(const struct dt_device_node *np, const char *list_name, const char *cells_name,
xen/include/xen/device_tree.h +11 -0
@@ -555,6 +555,17 @@ int dt_n_addr_cells(const struct dt_device_node *np);bool_t dt_device_is_available (const struct dt_device_node *device);/** +* dt_device_for_passthrough - Check if a device will be used for +* passthrough later +* +* @device: Node to check +* +* Return true if the property "xen,passthrough" is present in the node, +* false otherwise. +*/ +bool_t dt_device_for_passthrough (const struct dt_device_node *device); + +/** * dt_match_node - Tell if a device_node has a matching of dt_device_match * @matches: array of dt_device_match structures to search in * @node: the dt_device_node structure to match against
Signature · 1 line
2.1.4
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 100 lines · Julien Grall
When a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Rework the function
map_device(renamed intohandle_device) to:* For a given device node:
- Give permission to manage IRQ/MMIO for this device
- Retrieve the IRQ configuration (i.e edge/level) from the device tree
* When the device is not marked for guest passthrough:
- Assign the device to the guest if it's protected by an IOMMU
- Map the IRQs and MMIOs regions to the guestSigned-off-by Julien Grall <[email protected]>---
Changes in v3:
- This patch was formely "xen/arm: Follow-up to allow DOM0 manage IRQ and MMIO". It has been split in 2 parts [1].
- Update commit title and improve message
- Remove spurious change[1] https://patches.linaro.org/34669/
--- docs/misc/arm/device-tree/passthrough.txt | 7 ++ xen/arch/arm/device.c | 2 +- xen/arch/arm/domain_build.c | 102 ++++++++++++++++++++++-------- xen/common/device_tree.c | 6 ++ xen/include/xen/device_tree.h | 11 ++++ 5 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 docs/misc/arm/device-tree/passthrough.txtdocs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.xen/arch/arm/device.c +1
-1@@ -30,7 +30,7 @@ int __init device_init(struct dt_device_node *dev, enum device_match type,ASSERT (dev !=NULL ); -if ( !dt_device_is_available (dev) ) +if ( !dt_device_is_available (dev) ||dt_device_for_passthrough (dev) )return -ENODEV ;for ( desc = _sdevice; desc != _edevice; desc++ )xen/arch/arm/domain_build.c +12
-1@@ -402,7 +402,7 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) {const char *bootargs =NULL ; -const struct dt_property *prop; +const struct dt_property *prop, *status =NULL ;int res =0 ;int had_dom0_bootargs =0 ;@@ -457,6 +457,17 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, } } +/* Don't expose the property "xen,passthrough" to the guest */ +if (dt_property_name_is_equal (prop,"xen,passthrough" ) ) +continue ; + +/* Remember and skip the status property as Xen may modify it later */ +if (dt_property_name_is_equal (prop,"status" ) ) + { + status = prop; +continue ; + } + res =fdt_property (kinfo->fdt, prop->name, prop_data, prop_len);xfree (new_data);@@ -465,6 +476,19 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,return res; }
xen/arch/arm/domain_build.c static int write_properties(struct domain *d, struct kernel_info *kinfo, · line 487
Quoted 10 lines
xen/arch/arm/domain_build.c +9
-0+/* +* Override the property "status" to disable the device when it's +* marked for passthrough. +*/ +if (dt_device_for_passthrough (node) ) + res =fdt_property_string (kinfo->fdt,"status" ,"disabled" ); +else if ( status ) + res =fdt_property (kinfo->fdt,"status" , status->value, + status->length);
Why is the "else" needed? Wouldn't the status property for non-passtrough devices already be covered by the dt_for_each_property_node loop above?
Quoted 178 lines
xen/arch/arm/domain_build.c +53
-26+if ( res ) +return res; +if (dt_node_path_is_equal (node,"/chosen" ) ) {const struct bootmodule *mod = kinfo->initrd_bootmodule;@@ -919,8 +943,14 @@ static int make_timer_node(const struct domain *d, void *fdt,return res; } -/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +/* For a given device node: +* - Give permission to the guest to manage IRQ and MMIO range +* - Retrieve the IRQ configuration (i.e edge/level) from device tree +* When the device is not marked for guest passthrough: +* - Assign the device to the guest if it's protected by an IOMMU +* - Map the IRQs and iomem regions to DOM0 +*/ +static int handle_device (struct domain *d,struct dt_device_node *dev) {unsigned int nirq;unsigned int naddr;@@ -929,13 +959,15 @@ static int map_device(struct domain *d, struct dt_device_node *dev)unsigned int irq;struct dt_raw_irq rirq;u64 addr, size; +bool_t need_mapping = !dt_device_for_passthrough (dev); nirq =dt_number_of_irq (dev); naddr =dt_number_of_address (dev); -DPRINT ("%s nirq = %d naddr = %u\n" ,dt_node_full_name (dev), nirq, naddr); +DPRINT ("%s passthrough = %d nirq = %d naddr = %u\n" ,dt_node_full_name (dev), + need_mapping, nirq, naddr); -if (dt_device_is_protected (dev) ) +if (dt_device_is_protected (dev) && need_mapping ) {DPRINT ("%s setup iommu\n" ,dt_node_full_name (dev)); res =iommu_assign_dt_device (d, dev);@@ -947,7 +979,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } -/* Map IRQs */ +/* Give permission and map IRQs */ for ( i =0 ; i < nirq; i++ ) { res =dt_device_get_raw_irq (dev, i, &rirq);@@ -980,22 +1012,34 @@ static int map_device(struct domain *d, struct dt_device_node *dev) irq = res;DPRINT ("irq %u = %u\n" , i, irq); -/* -* Checking the return of vgic_reserve_virq is not -* necessary. It should not fail except when we try to map -* twice the IRQ. This can happen if the IRQ is shared -*/ -vgic_reserve_virq (d, irq); - res =route_irq_to_guest (d, irq,dt_node_name (dev)); + + res =irq_permit_access (d, irq);if ( res ) { -printk (XENLOG_ERR "Unable to route IRQ %u to domain %u\n" , - irq, d->domain_id); +printk (XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n" , + d->domain_id, irq);return res; } + +if ( need_mapping ) + { +/* +* Checking the return of vgic_reserve_virq is not +* necessary. It should not fail except when we try to map +* twice the IRQ. This can happen if the IRQ is shared +*/ +vgic_reserve_virq (d, irq); + res =route_irq_to_guest (d, irq,dt_node_name (dev)); +if ( res ) + { +printk (XENLOG_ERR "Unable to route IRQ %u to domain %u\n" , + irq, d->domain_id); +return res; + } + } } -/* Map the address ranges */ +/* Give permission and map MMIOs */ for ( i =0 ; i < naddr; i++ ) { res =dt_device_get_address (dev, i, &addr, &size);@@ -1019,17 +1063,21 @@ static int map_device(struct domain *d, struct dt_device_node *dev) addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1);return res; } - res =map_mmio_regions (d, -paddr_to_pfn (addr &PAGE_MASK ), -DIV_ROUND_UP (size,PAGE_SIZE ), -paddr_to_pfn (addr &PAGE_MASK )); -if ( res ) + +if ( need_mapping ) { -printk (XENLOG_ERR "Unable to map 0x%" PRIx64 -" - 0x%" PRIx64" in domain %d\n" , - addr &PAGE_MASK ,PAGE_ALIGN (addr + size) -1 , - d->domain_id); -return res; + res =map_mmio_regions (d, +paddr_to_pfn (addr &PAGE_MASK ), +DIV_ROUND_UP (size,PAGE_SIZE ), +paddr_to_pfn (addr &PAGE_MASK )); +if ( res ) + { +printk (XENLOG_ERR "Unable to map 0x%" PRIx64 +" - 0x%" PRIx64" in domain %d\n" , + addr &PAGE_MASK ,PAGE_ALIGN (addr + size) -1 , + d->domain_id); +return res; + } } }@@ -1104,7 +1152,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,return 0 ; } - res =map_device (d, node); + res =handle_device (d, node);if ( res)return res;xen/common/device_tree.c +6
-0@@ -1103,6 +1103,12 @@ bool_t dt_device_is_available(const struct dt_device_node *device)return 0 ; } +bool_t dt_device_for_passthrough (const struct dt_device_node *device) +{ +return (dt_find_property (device,"xen,passthrough" ,NULL ) !=NULL ); + +} + static int __dt_parse_phandle_with_args(const struct dt_device_node *np, const char *list_name, const char *cells_name,xen/include/xen/device_tree.h +11
-0@@ -555,6 +555,17 @@ int dt_n_addr_cells(const struct dt_device_node *np);bool_t dt_device_is_available (const struct dt_device_node *device);/** +* dt_device_for_passthrough - Check if a device will be used for +* passthrough later +* +* @device: Node to check +* +* Return true if the property "xen,passthrough" is present in the node, +* false otherwise. +*/ +bool_t dt_device_for_passthrough (const struct dt_device_node *device); + +/** * dt_match_node - Tell if a device_node has a matching of dt_device_match * @matches: array of dt_device_match structures to search in * @node: the dt_device_node structure to match against Signature · 1 line
2.1.4
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 102 lines · Stefano Stabellini
Quoted 101 lines · Julien Grall
When a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Rework the function
map_device(renamed intohandle_device) to:* For a given device node:
- Give permission to manage IRQ/MMIO for this device
- Retrieve the IRQ configuration (i.e edge/level) from the device tree
* When the device is not marked for guest passthrough:
- Assign the device to the guest if it's protected by an IOMMU
- Map the IRQs and MMIOs regions to the guestSigned-off-by Julien Grall <[email protected]>---
Changes in v3:
- This patch was formely "xen/arm: Follow-up to allow DOM0 manage IRQ and MMIO". It has been split in 2 parts [1].
- Update commit title and improve message
- Remove spurious change[1] https://patches.linaro.org/34669/
--- docs/misc/arm/device-tree/passthrough.txt | 7 ++ xen/arch/arm/device.c | 2 +- xen/arch/arm/domain_build.c | 102 ++++++++++++++++++++++-------- xen/common/device_tree.c | 6 ++ xen/include/xen/device_tree.h | 11 ++++ 5 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 docs/misc/arm/device-tree/passthrough.txtdocs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.xen/arch/arm/device.c +1
-1@@ -30,7 +30,7 @@ int __init device_init(struct dt_device_node *dev, enum device_match type,ASSERT (dev !=NULL ); -if ( !dt_device_is_available (dev) ) +if ( !dt_device_is_available (dev) ||dt_device_for_passthrough (dev) )return -ENODEV ;for ( desc = _sdevice; desc != _edevice; desc++ )xen/arch/arm/domain_build.c +12
-1@@ -402,7 +402,7 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) {const char *bootargs =NULL ; -const struct dt_property *prop; +const struct dt_property *prop, *status =NULL ;int res =0 ;int had_dom0_bootargs =0 ;@@ -457,6 +457,17 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, } } +/* Don't expose the property "xen,passthrough" to the guest */ +if (dt_property_name_is_equal (prop,"xen,passthrough" ) ) +continue ; + +/* Remember and skip the status property as Xen may modify it later */ +if (dt_property_name_is_equal (prop,"status" ) ) + { + status = prop; +continue ; + } + res =fdt_property (kinfo->fdt, prop->name, prop_data, prop_len);xfree (new_data);@@ -465,6 +476,19 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,return res; }
Quoted 13 lines
xen/arch/arm/domain_build.c static int write_properties(struct domain *d, struct kernel_info *kinfo, · line 487
Quoted 9 lines
xen/arch/arm/domain_build.c +9
-0+/* +* Override the property "status" to disable the device when it's +* marked for passthrough. +*/ +if (dt_device_for_passthrough (node) ) + res =fdt_property_string (kinfo->fdt,"status" ,"disabled" ); +else if ( status ) + res =fdt_property (kinfo->fdt,"status" , status->value, + status->length);Why is the "else" needed? Wouldn't the status property for non-passtrough devices already be covered by the
dt_for_each_property_nodeloop above?
Because the property "status" is skipped earlier in any case.
Regards,
Signature · 1 line
Julien Grall
Stefano Stabellini
Acked-byRe: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 118 lines · Julien Grall
Quoted 102 lines · Stefano Stabellini
Quoted 101 lines · Julien Grall
When a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Rework the function
map_device(renamed intohandle_device) to:* For a given device node:
- Give permission to manage IRQ/MMIO for this device
- Retrieve the IRQ configuration (i.e edge/level) from the device tree
* When the device is not marked for guest passthrough:
- Assign the device to the guest if it's protected by an IOMMU
- Map the IRQs and MMIOs regions to the guestSigned-off-by Julien Grall <[email protected]>---
Changes in v3:
- This patch was formely "xen/arm: Follow-up to allow DOM0 manage IRQ and MMIO". It has been split in 2 parts [1].
- Update commit title and improve message
- Remove spurious change[1] https://patches.linaro.org/34669/
--- docs/misc/arm/device-tree/passthrough.txt | 7 ++ xen/arch/arm/device.c | 2 +- xen/arch/arm/domain_build.c | 102 ++++++++++++++++++++++-------- xen/common/device_tree.c | 6 ++ xen/include/xen/device_tree.h | 11 ++++ 5 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 docs/misc/arm/device-tree/passthrough.txtdocs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.xen/arch/arm/device.c +1
-1@@ -30,7 +30,7 @@ int __init device_init(struct dt_device_node *dev, enum device_match type,ASSERT (dev !=NULL ); -if ( !dt_device_is_available (dev) ) +if ( !dt_device_is_available (dev) ||dt_device_for_passthrough (dev) )return -ENODEV ;for ( desc = _sdevice; desc != _edevice; desc++ )xen/arch/arm/domain_build.c +12
-1@@ -402,7 +402,7 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) {const char *bootargs =NULL ; -const struct dt_property *prop; +const struct dt_property *prop, *status =NULL ;int res =0 ;int had_dom0_bootargs =0 ;@@ -457,6 +457,17 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo, } } +/* Don't expose the property "xen,passthrough" to the guest */ +if (dt_property_name_is_equal (prop,"xen,passthrough" ) ) +continue ; + +/* Remember and skip the status property as Xen may modify it later */ +if (dt_property_name_is_equal (prop,"status" ) ) + { + status = prop; +continue ; + } + res =fdt_property (kinfo->fdt, prop->name, prop_data, prop_len);xfree (new_data);@@ -465,6 +476,19 @@ static int write_properties(struct domain *d, struct kernel_info *kinfo,return res; }Quoted 13 lines
xen/arch/arm/domain_build.c static int write_properties(struct domain *d, struct kernel_info *kinfo, · line 487
Quoted 9 lines
xen/arch/arm/domain_build.c +9
-0+/* +* Override the property "status" to disable the device when it's +* marked for passthrough. +*/ +if (dt_device_for_passthrough (node) ) + res =fdt_property_string (kinfo->fdt,"status" ,"disabled" ); +else if ( status ) + res =fdt_property (kinfo->fdt,"status" , status->value, + status->length);Why is the "else" needed? Wouldn't the status property for non-passtrough devices already be covered by the
dt_for_each_property_nodeloop above?
Quoted 1 line
Because the property "status" is skipped earlier in any case.
I see that now.
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
In reply to Julien GrallQuoted 2 lines · Julien Grall
When a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should
"must not access the device (i.e. not load a driver)"
perhaps "should still be able"
Quoted 8 lines
be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Is it true to say "already the case for Linux, and required by ePAPR"? Or are we relying on a Linux implementation detail here?
docs/misc/arm/device-tree/passthrough.txt line 7
Quoted 13 lines
docs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.
This (and the commit message to some extent) seem stricter than what I think is actually required here.
I understand that it is a very good idea for any sort of passthrough to prevent dom0 from messing with a device before it gets assigned to the eventual guest domain.
But AIUI it is not strictly speaking a hard requirement that dom0 does not do this and depending on the device it may be perfectly acceptable for dom0 to drive a device for a bit and then give it to a guest and then have it back again etc.
So I would suggest to invert the wording a bit, currently it reads something like "if a device is to be passed through then it must have this property set, then dom0 will not touch".
So I'd suggest something weaker like:
Devices with this property set will not be exposed to dom0 and therefore no driver will be loaded.
It is highly recommended to set this property on devices which are to be passed through since many devices will not cope with being accessed by dom0 and then handed over to another domain.
(second half of the second paragraph could be clearer though I think)
(I'll hit send now and then review the code itself)
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Hi Ian,
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Julien Grall
When a device is marked for passthrough (via the new property "xen,passthrough"), dom0 must not access to the device (i.e not loading a driver), but should
"must not access the device (i.e. not load a driver)"
perhaps "should still be able"
Quoted 5 lines
be able to manage the MMIO/interrupt of the passthrough device.
The latter part will allow the toolstack to map MMIO/IRQ when a device is pass through to a guest.
Quoted 6 lines
Quoted 3 lines
The property "xen,passthrough" will be translated as 'status="disabled"' in the device tree to avoid DOM0 using the device. We assume that DOM0 is able to cope with this property (already the case for Linux).
Is it true to say "already the case for Linux, and required by ePAPR"? Or are we relying on a Linux implementation detail here?
The ePAPR says:
"Indicates that the device is not presently operational, but it might become operational in the future (for example, something is not plugged in, or switched off).
Refer to the device binding for details on what disabled means for a given device."
So I think we can say "required by ePAPR".
Quoted 17 lines
docs/misc/arm/device-tree/passthrough.txt line 7
Quoted 13 lines
docs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.This (and the commit message to some extent) seem stricter than what I think is actually required here.
Quoted 8 lines
I understand that it is a very good idea for any sort of passthrough to prevent dom0 from messing with a device before it gets assigned to the eventual guest domain.
But AIUI it is not strictly speaking a hard requirement that dom0 does not do this and depending on the device it may be perfectly acceptable for dom0 to drive a device for a bit and then give it to a guest and then have it back again etc.
When the device has the property "xen,passthrough", Xen won't map the MMIO and IRQ to DOM0. So it's an hard requirement.
We may want to be less strict if we decide to let DOM0 cope with platform device passthrough (as it's done for PCI).
But this is more complicate than the current use case for this type of passthrough.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 21 lines · Julien Grall
Quoted 21 lines
docs/misc/arm/device-tree/passthrough.txt line 7
Quoted 13 lines
docs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.This (and the commit message to some extent) seem stricter than what I think is actually required here.
I understand that it is a very good idea for any sort of passthrough to prevent dom0 from messing with a device before it gets assigned to the eventual guest domain.
Quoted 7 lines
Quoted 4 lines
But AIUI it is not strictly speaking a hard requirement that dom0 does not do this and depending on the device it may be perfectly acceptable for dom0 to drive a device for a bit and then give it to a guest and then have it back again etc.
When the device has the property "xen,passthrough", Xen won't map the MMIO and IRQ to DOM0. So it's an hard requirement.
That's not what I meant.
What I was getting at is that it's not 100% mandatory for a device you want to pass through to have the "xen,passthrough" property at all, but the wording of the binding implies otherwise..
There will be at least some devices in the world (even if only trivial ones) where you can pass them through even if dom0 has been touching them before. Or dom0 might choose to implement a reset helper for some device or other.
Ian.
Quoted 8 lines
We may want to be less strict if we decide to let DOM0 cope with platform device passthrough (as it's done for PCI).
But this is more complicate than the current use case for this type of passthrough.
Regards,
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Hi Ian,
Quoted 32 lines · Ian Campbell
Quoted 21 lines · Julien Grall
Quoted 21 lines
docs/misc/arm/device-tree/passthrough.txt line 7
Quoted 13 lines
docs/misc/arm/device-tree/passthrough.txt new file +7
-0@@ -0,0 +1,7 @@ +Device passthrough +=================== + +Any device that will be passthrough to a guest should have a property +"xen,passthrough" in their device tree node. + +The device won't be exposed to DOM0 and therefore no driver will be loaded.This (and the commit message to some extent) seem stricter than what I think is actually required here.
I understand that it is a very good idea for any sort of passthrough to prevent dom0 from messing with a device before it gets assigned to the eventual guest domain.
Quoted 7 lines
Quoted 4 lines
But AIUI it is not strictly speaking a hard requirement that dom0 does not do this and depending on the device it may be perfectly acceptable for dom0 to drive a device for a bit and then give it to a guest and then have it back again etc.
When the device has the property "xen,passthrough", Xen won't map the MMIO and IRQ to DOM0. So it's an hard requirement.
That's not what I meant.
Quoted 8 lines
What I was getting at is that it's not 100% mandatory for a device you want to pass through to have the "xen,passthrough" property at all, but the wording of the binding implies otherwise..
There will be at least some devices in the world (even if only trivial ones) where you can pass them through even if dom0 has been touching them before. Or dom0 might choose to implement a reset helper for some device or other.
Hmmm right... I will update the binding.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
In reply to Julien Grallxen/arch/arm/domain_build.c static int make_timer_node(const struct domain *d, void *fdt, · line 946
Quoted 7 lines · Julien Grall
xen/arch/arm/domain_build.c +1
-2@@ -919,8 +943,14 @@ static int make_timer_node(const struct domain *d, void *fdt,return res; } -/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +/* For a given device node:
Strictly speaking should be:
/*
* For a given...
(I don't care all that much, but since I'm commenting elsewhere)
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 982
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -947,7 +979,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } -/* Map IRQs */ +/* Give permission and map IRQs */
Another Nit: " " -> " ".
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 1029
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+if ( need_mapping ) + { +/* +* Checking the return of vgic_reserve_virq is not +* necessary. It should not fail except when we try to map +* twice the IRQ. This can happen if the IRQ is shared
"when we try to map the IRQ twice"
Other than those nits the code itself looks good, will ack once we've agreed on the bindings wording.
Ian.
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 13 lines · Ian Campbell
xen/arch/arm/domain_build.c static int make_timer_node(const struct domain *d, void *fdt, · line 946
Quoted 7 lines · Julien Grall
xen/arch/arm/domain_build.c +1
-2@@ -919,8 +943,14 @@ static int make_timer_node(const struct domain *d, void *fdt,return res; } -/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +/* For a given device node: Strictly speaking should be:
/*
* For a given...
Quoted 1 line
(I don't care all that much, but since I'm commenting elsewhere)
Hmmm right. I will change it.
Quoted 16 lines
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 982
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -947,7 +979,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } -/* Map IRQs */ +/* Give permission and map IRQs */ Another Nit: " " -> " ".
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 1029
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+if ( need_mapping ) + { +/* +* Checking the return of vgic_reserve_virq is not +* necessary. It should not fail except when we try to map +* twice the IRQ. This can happen if the IRQ is shared
Quoted 4 lines
"when we try to map the IRQ twice"
Other than those nits the code itself looks good, will ack once we've agreed on the bindings wording.
BTW, should we upstream the bindings to device tree git?
Thanks,
Signature · 1 line
Julien Grall
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 14 lines · Julien Grall
Quoted 13 lines · Ian Campbell
xen/arch/arm/domain_build.c static int make_timer_node(const struct domain *d, void *fdt, · line 946
Quoted 7 lines · Julien Grall
xen/arch/arm/domain_build.c +1
-2@@ -919,8 +943,14 @@ static int make_timer_node(const struct domain *d, void *fdt,return res; } -/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +/* For a given device node: Strictly speaking should be:
/*
* For a given...
Quoted 3 lines
Quoted 1 line
(I don't care all that much, but since I'm commenting elsewhere)
Hmmm right. I will change it.
FWIW I noticed this pattern a lot in this series.
Quoted 16 lines
Quoted 16 lines
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 982
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -947,7 +979,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } -/* Map IRQs */ +/* Give permission and map IRQs */ Another Nit: " " -> " ".
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+if ( need_mapping ) + { +/* +* Checking the return of vgic_reserve_virq is not +* necessary. It should not fail except when we try to map +* twice the IRQ. This can happen if the IRQ is shared
Quoted 6 lines
Quoted 4 lines
"when we try to map the IRQ twice"
Other than those nits the code itself looks good, will ack once we've agreed on the bindings wording.
BTW, should we upstream the bindings to device tree git?
Arguably we should upstream all of our bindings (e.g. docs/misc/arm/device-tree/*, admittedly a single file right now) but doing just one/some seems worse than keeping them in tree.
IOW it should be all or nothing, and I have no problem with you deciding that nothing is easier for you here...
Ian.
Re: [PATCH v3 07/24] xen/arm: Introduce xen, passthrough property
Quoted 42 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 13 lines · Ian Campbell
xen/arch/arm/domain_build.c static int make_timer_node(const struct domain *d, void *fdt, · line 946
Quoted 7 lines · Julien Grall
xen/arch/arm/domain_build.c +1
-2@@ -919,8 +943,14 @@ static int make_timer_node(const struct domain *d, void *fdt,return res; } -/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +/* For a given device node: Strictly speaking should be:
/*
* For a given...Quoted 3 lines
Quoted 1 line
(I don't care all that much, but since I'm commenting elsewhere)
Hmmm right. I will change it.
FWIW I noticed this pattern a lot in this series.
Quoted 21 lines
Quoted 20 lines
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 982
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -947,7 +979,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } -/* Map IRQs */ +/* Give permission and map IRQs */ Another Nit: " " -> " ".
xen/arch/arm/domain_build.c static int map_device(struct domain *d, struct dt_device_node *dev) · line 1029
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+if ( need_mapping ) + { +/* +* Checking the return of vgic_reserve_virq is not +* necessary. It should not fail except when we try to map +* twice the IRQ. This can happen if the IRQ is shared "when we try to map the IRQ twice"
Other than those nits the code itself looks good, will ack once we've agreed on the bindings wording.
Quoted 8 lines
Quoted 1 line
BTW, should we upstream the bindings to device tree git?
Arguably we should upstream all of our bindings (e.g. docs/misc/arm/device-tree/*, admittedly a single file right now) but doing just one/some seems worse than keeping them in tree.
IOW it should be all or nothing, and I have no problem with you deciding that nothing is easier for you here...
For now, I will stick for nothing :).
Regards,
Signature · 1 line
Julien Grall
PATCH v3 8/24 xen/arm: Allow virq != irq
In reply to Julien GrallActually Xen is assuming that the virtual IRQ will always be the same as IRQ.
Modify route_guest_irq to take the virtual IRQ in parameter and let Xen assign a different IRQ number. Also store the vIRQ in the desc action to easily retrieve easily the IRQ target when we need to inject the interrupt.
As DOM0 will get most the devices, the vIRQ is equal to the IRQ in that case.
At the same time modify the behavior of irq_get_domain. The function now assumes that the irq_desc belongs to an IRQ assigned to a guest.
---
Changes in v3
- Spelling/grammar nits
- Fix compilation on ARM64. Forgot to update route_irq_to_guest call for xgene platform.
- Add a word about irq_get_domain behavior change
- More s/irq/virq/ because of the rebasing on the latest staging
Changes in v2:
- Patch added
--- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic.c | 5 ++-- xen/arch/arm/irq.c | 47 ++++++++++++++++++++++++++---------- xen/arch/arm/platforms/xgene-storm.c | 2 +- xen/arch/arm/vgic.c | 20 +++++++-------- xen/include/asm-arm/gic.h | 3 ++- xen/include/asm-arm/irq.h | 4 +-- xen/include/asm-arm/vgic.h | 4 +-- 8 files changed, 55 insertions(+), 32 deletions(-)
xen/arch/arm/domain_build.c +1 -1
@@ -1029,7 +1029,7 @@ static int handle_device(struct domain *d, struct dt_device_node *dev)* twice the IRQ. This can happen if the IRQ is shared */ vgic_reserve_virq (d, irq); - res =route_irq_to_guest (d, irq,dt_node_name (dev)); + res =route_irq_to_guest (d, irq, irq,dt_node_name (dev));if ( res ) { printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n",
xen/arch/arm/gic.c +3 -2
@@ -126,7 +126,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,/* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest (struct domain *d,struct irq_desc *desc, +void gic_route_irq_to_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority) {struct pending_irq *p;
@@ -139,7 +140,7 @@ void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,/* Use vcpu0 to retrieve the pending_irq struct. Given that we only * route SPIs to guests, it doesn't make any difference. */ - p =irq_to_pending (d->vcpu[0 ], desc->irq); + p =irq_to_pending (d->vcpu[0 ], virq); p->desc = desc; }
xen/arch/arm/irq.c +34 -13
104 lines not on this page · raw message
xen/arch/arm/platforms/xgene-storm.c +1 -1
@@ -75,7 +75,7 @@ static int map_one_spi(struct domain *d, const char *what,printk ("Failed to reserve the vIRQ %u on dom%d\n" , irq, d->domain_id); - ret =route_irq_to_guest (d, irq, what); + ret =route_irq_to_guest (d, irq, irq, what);if ( ret )printk ("Failed to route %s to dom%d\n" , what, d->domain_id);
xen/arch/arm/vgic.c +10 -10
@@ -380,16 +380,16 @@ void vgic_clear_pending_irqs(struct vcpu *v)spin_unlock_irqrestore (&v->arch.vgic.lock, flags); } -void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int irq) +void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int virq) {uint8_t priority; -struct vgic_irq_rank *rank =vgic_rank_irq (v, irq); -struct pending_irq *iter, *n =irq_to_pending (v, irq); +struct vgic_irq_rank *rank =vgic_rank_irq (v, virq); +struct pending_irq *iter, *n =irq_to_pending (v, virq);unsigned long flags;bool_t running;vgic_lock_rank (v, rank, flags); - priority = v->domain->arch.vgic.handler->get_irq_priority (v, irq); + priority = v->domain->arch.vgic.handler->get_irq_priority (v, virq);vgic_unlock_rank (v, rank, flags);spin_lock_irqsave (&v->arch.vgic.lock, flags);
@@ -405,7 +405,7 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)if ( !list_empty (&n->inflight) ) { -gic_raise_inflight_irq (v, irq); +gic_raise_inflight_irq (v, virq); goto out; }
@@ -413,7 +413,7 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)/* the irq is enabled */ if (test_bit (GIC_IRQ_GUEST_ENABLED , &n->status) ) -gic_raise_guest_irq (v, irq, priority); +gic_raise_guest_irq (v, virq, priority); list_for_each_entry ( iter, &v->arch.vgic.inflight_irqs, inflight ) {
@@ -433,15 +433,15 @@ out:smp_send_event_check_mask (cpumask_of (v->processor)); } -void vgic_vcpu_inject_spi (struct domain *d,unsigned int irq) +void vgic_vcpu_inject_spi (struct domain *d,unsigned int virq) {struct vcpu *v;/* the IRQ needs to be an SPI */ -ASSERT (irq >=32 && irq <=gic_number_lines ()); +ASSERT (virq >=32 && virq <=vgic_num_irqs (d)); - v =vgic_get_target_vcpu (d->vcpu[0 ], irq); -vgic_vcpu_inject_irq (v, irq); + v =vgic_get_target_vcpu (d->vcpu[0 ], virq); +vgic_vcpu_inject_irq (v, virq); }void arch_evtchn_inject (struct vcpu *v)
xen/include/asm-arm/gic.h +2 -1
@@ -213,7 +213,8 @@ extern enum gic_version gic_hw_version(void);/* Program the GIC to route an interrupt */ extern void gic_route_irq_to_xen (struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority); -extern void gic_route_irq_to_guest (struct domain *,struct irq_desc *desc, +extern void gic_route_irq_to_guest (struct domain *,unsigned int virq, +struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority);
xen/include/asm-arm/irq.h +2 -2
@@ -40,8 +40,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);void init_IRQ (void );void init_secondary_IRQ (void ); -int route_irq_to_guest (struct domain *d,unsigned int irq, -const char *devname); +int route_irq_to_guest (struct domain *d,unsigned int virq, +unsigned int irq,const char *devname);void arch_move_irqs (struct vcpu *v);/* Set IRQ type for an SPI */
xen/include/asm-arm/vgic.h +2 -2
@@ -181,8 +181,8 @@ extern int domain_vgic_init(struct domain *d);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); -extern void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int irq); -extern void vgic_vcpu_inject_spi (struct domain *d,unsigned int irq); +extern void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int virq); +extern void vgic_vcpu_inject_spi (struct domain *d,unsigned int virq);extern void vgic_clear_pending_irqs (struct vcpu *v);extern struct pending_irq *irq_to_pending (struct vcpu *v,unsigned int irq);extern struct vgic_irq_rank *vgic_rank_offset (struct vcpu *v,int b,int n,int s);
Signature · 1 line
2.1.4
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 75 lines · Julien Grall
Actually Xen is assuming that the virtual IRQ will always be the same as IRQ.
Modify
route_guest_irqto take the virtual IRQ in parameter and let Xen assign a different IRQ number. Also store the vIRQ in the desc action to easily retrieve easily the IRQ target when we need to inject the interrupt.As DOM0 will get most the devices, the vIRQ is equal to the IRQ in that case.
At the same time modify the behavior of
irq_get_domain. The function now assumes that theirq_descbelongs to an IRQ assigned to a guest.Signed-off-by Julien Grall <[email protected]>---
Changes in v3
- Spelling/grammar nits
- Fix compilation on ARM64. Forgot to updateroute_irq_to_guestcall for xgene platform.
- Add a word aboutirq_get_domainbehavior change
- More s/irq/virq/ because of the rebasing on the latest stagingChanges in v2:
- Patch added--- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic.c | 5 ++-- xen/arch/arm/irq.c | 47 ++++++++++++++++++++++++++---------- xen/arch/arm/platforms/xgene-storm.c | 2 +- xen/arch/arm/vgic.c | 20 +++++++-------- xen/include/asm-arm/gic.h | 3 ++- xen/include/asm-arm/irq.h | 4 +-- xen/include/asm-arm/vgic.h | 4 +-- 8 files changed, 55 insertions(+), 32 deletions(-)xen/arch/arm/domain_build.c +1
-1@@ -1029,7 +1029,7 @@ static int handle_device(struct domain *d, struct dt_device_node *dev)* twice the IRQ. This can happen if the IRQ is shared */ vgic_reserve_virq (d, irq); - res =route_irq_to_guest (d, irq,dt_node_name (dev)); + res =route_irq_to_guest (d, irq, irq,dt_node_name (dev));if ( res ) { printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n",xen/arch/arm/gic.c +3
-2@@ -126,7 +126,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,/* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest (struct domain *d,struct irq_desc *desc, +void gic_route_irq_to_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority) {struct pending_irq *p;@@ -139,7 +140,7 @@ void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,/* Use vcpu0 to retrieve the pending_irq struct. Given that we only * route SPIs to guests, it doesn't make any difference. */ - p =irq_to_pending (d->vcpu[0 ], desc->irq); + p =irq_to_pending (d->vcpu[0 ], virq); p->desc = desc; }xen/arch/arm/irq.c +0
-0
xen/arch/arm/irq.c line 39
Quoted 9 lines
xen/arch/arm/irq.c +6
-0@@ -31,6 +31,13 @@static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock); +/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +};
I would prefer if you didn't use dev_id for this and just added a virq field to irqaction.
Quoted 223 lines
xen/arch/arm/irq.c +27
-13static void ack_none (struct irq_desc *irq) {printk ("unexpected IRQ trap at irq %02x\n" , irq->irq);@@ -122,18 +129,20 @@ void __cpuinit init_secondary_IRQ(void)BUG_ON (init_local_irq_data () <0 ); } -static inline struct domain *irq_get_domain (struct irq_desc *desc) +static inline struct irq_guest *irq_get_guest_info (struct irq_desc *desc) {ASSERT (spin_is_locked (&desc->lock)); - -if ( !test_bit (_IRQ_GUEST, &desc->status) ) -return dom_xen; - +ASSERT (test_bit (_IRQ_GUEST, &desc->status));ASSERT (desc->action !=NULL );return desc->action->dev_id; } +static inline struct domain *irq_get_domain (struct irq_desc *desc) +{ +return irq_get_guest_info (desc)->d; +} +void irq_set_affinity (struct irq_desc *desc,const cpumask_t *cpu_mask) {if ( desc !=NULL )@@ -197,7 +206,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)if (test_bit (_IRQ_GUEST, &desc->status) ) { -struct domain *d =irq_get_domain (desc); +struct irq_guest *info =irq_get_guest_info (desc); desc->handler->end (desc);@@ -206,7 +215,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)/* the irq cannot be a PPI, we only support delivery of SPIs to * guests */ -vgic_vcpu_inject_spi (d, irq); +vgic_vcpu_inject_spi (info->d, info->virq); goto out_no_end; }@@ -370,19 +379,30 @@ err:return rc; } -int route_irq_to_guest (struct domain *d,unsigned int irq, -const char * devname) +int route_irq_to_guest (struct domain *d,unsigned int virq, +unsigned int irq,const char * devname) {struct irqaction *action; -struct irq_desc *desc =irq_to_desc (irq); +struct irq_guest *info; +struct irq_desc *desc;unsigned long flags;int retval =0 ; action = xmalloc(struct irqaction); -if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest); +if ( !info ) + { +xfree (action);return -ENOMEM ; + } + + info->d = d; + info->virq = virq; - action->dev_id = d; + action->dev_id = info; action->name = devname; action->free_on_release =1 ;@@ -413,7 +433,7 @@ int route_irq_to_guest(struct domain *d, unsigned int irq,if ( retval ) goto out; -gic_route_irq_to_guest (d, desc,cpumask_of (smp_processor_id ()), +gic_route_irq_to_guest (d, virq, desc,cpumask_of (smp_processor_id ()),GIC_PRI_IRQ );spin_unlock_irqrestore (&desc->lock, flags);return 0 ;@@ -421,6 +441,7 @@ int route_irq_to_guest(struct domain *d, unsigned int irq, out:spin_unlock_irqrestore (&desc->lock, flags);xfree (action); +xfree (info);return retval; }xen/arch/arm/platforms/xgene-storm.c +1
-1@@ -75,7 +75,7 @@ static int map_one_spi(struct domain *d, const char *what,printk ("Failed to reserve the vIRQ %u on dom%d\n" , irq, d->domain_id); - ret =route_irq_to_guest (d, irq, what); + ret =route_irq_to_guest (d, irq, irq, what);if ( ret )printk ("Failed to route %s to dom%d\n" , what, d->domain_id);xen/arch/arm/vgic.c +10
-10@@ -380,16 +380,16 @@ void vgic_clear_pending_irqs(struct vcpu *v)spin_unlock_irqrestore (&v->arch.vgic.lock, flags); } -void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int irq) +void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int virq) {uint8_t priority; -struct vgic_irq_rank *rank =vgic_rank_irq (v, irq); -struct pending_irq *iter, *n =irq_to_pending (v, irq); +struct vgic_irq_rank *rank =vgic_rank_irq (v, virq); +struct pending_irq *iter, *n =irq_to_pending (v, virq);unsigned long flags;bool_t running;vgic_lock_rank (v, rank, flags); - priority = v->domain->arch.vgic.handler->get_irq_priority (v, irq); + priority = v->domain->arch.vgic.handler->get_irq_priority (v, virq);vgic_unlock_rank (v, rank, flags);spin_lock_irqsave (&v->arch.vgic.lock, flags);@@ -405,7 +405,7 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)if ( !list_empty (&n->inflight) ) { -gic_raise_inflight_irq (v, irq); +gic_raise_inflight_irq (v, virq); goto out; }@@ -413,7 +413,7 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)/* the irq is enabled */ if (test_bit (GIC_IRQ_GUEST_ENABLED , &n->status) ) -gic_raise_guest_irq (v, irq, priority); +gic_raise_guest_irq (v, virq, priority); list_for_each_entry ( iter, &v->arch.vgic.inflight_irqs, inflight ) {@@ -433,15 +433,15 @@ out:smp_send_event_check_mask (cpumask_of (v->processor)); } -void vgic_vcpu_inject_spi (struct domain *d,unsigned int irq) +void vgic_vcpu_inject_spi (struct domain *d,unsigned int virq) {struct vcpu *v;/* the IRQ needs to be an SPI */ -ASSERT (irq >=32 && irq <=gic_number_lines ()); +ASSERT (virq >=32 && virq <=vgic_num_irqs (d)); - v =vgic_get_target_vcpu (d->vcpu[0 ], irq); -vgic_vcpu_inject_irq (v, irq); + v =vgic_get_target_vcpu (d->vcpu[0 ], virq); +vgic_vcpu_inject_irq (v, virq); }void arch_evtchn_inject (struct vcpu *v)xen/include/asm-arm/gic.h +2
-1@@ -213,7 +213,8 @@ extern enum gic_version gic_hw_version(void);/* Program the GIC to route an interrupt */ extern void gic_route_irq_to_xen (struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority); -extern void gic_route_irq_to_guest (struct domain *,struct irq_desc *desc, +extern void gic_route_irq_to_guest (struct domain *,unsigned int virq, +struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority);xen/include/asm-arm/irq.h +2
-2@@ -40,8 +40,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);void init_IRQ (void );void init_secondary_IRQ (void ); -int route_irq_to_guest (struct domain *d,unsigned int irq, -const char *devname); +int route_irq_to_guest (struct domain *d,unsigned int virq, +unsigned int irq,const char *devname);void arch_move_irqs (struct vcpu *v);/* Set IRQ type for an SPI */ xen/include/asm-arm/vgic.h +2
-2@@ -181,8 +181,8 @@ extern int domain_vgic_init(struct domain *d);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); -extern void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int irq); -extern void vgic_vcpu_inject_spi (struct domain *d,unsigned int irq); +extern void vgic_vcpu_inject_irq (struct vcpu *v,unsigned int virq); +extern void vgic_vcpu_inject_spi (struct domain *d,unsigned int virq);extern void vgic_clear_pending_irqs (struct vcpu *v);extern struct pending_irq *irq_to_pending (struct vcpu *v,unsigned int irq);extern struct vgic_irq_rank *vgic_rank_offset (struct vcpu *v,int b,int n,int s);Signature · 1 line
2.1.4
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 8 lines · Stefano Stabellini
Quoted 8 lines
xen/arch/arm/irq.c +0
-0@@ -31,6 +31,13 @@static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);
Quoted 9 lines
xen/arch/arm/irq.c line 39
Quoted 6 lines
xen/arch/arm/irq.c +6
-0+/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +};I would prefer if you didn't use
dev_idfor this and just added a virq field to irqaction.
We already talked about it on v2. You were fine with the idea and acked the patch. Although, I haven't add your acked-by here because of the new changes in the code.
Here my answer to the same question on v2:
"I though about it. If we add another field in arch_irq_desc, we will likely use more memory than xmalloc. This is because most of the platform doesn't use 1024 interrupts but about 256 interrupts.
As the new field will be a pointer (on ARM64, 8 bytes), that would make Xen use statically about 8K more.
We could allocate irq_desc dynamically during Xen boot."
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 19 lines · Julien Grall
Quoted 8 lines · Stefano Stabellini
Quoted 8 lines
xen/arch/arm/irq.c +0
-0@@ -31,6 +31,13 @@static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);Quoted 9 lines
xen/arch/arm/irq.c line 39
Quoted 6 lines
xen/arch/arm/irq.c +6
-0+/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +};I would prefer if you didn't use
dev_idfor this and just added a virq field to irqaction.
Quoted 3 lines
We already talked about it on v2. You were fine with the idea and acked the patch. Although, I haven't add your acked-by here because of the new changes in the code.
For reference: https://patches.linaro.org/34671/
Quoted 10 lines
Here my answer to the same question on v2:
"I though about it. If we add another field in
arch_irq_desc, we will likely use more memory than xmalloc. This is because most of the platform doesn't use 1024 interrupts but about 256 interrupts.As the new field will be a pointer (on ARM64, 8 bytes), that would make Xen use statically about 8K more.
We could allocate
irq_descdynamically during Xen boot."
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
In reply to Julien GrallQuoted 19 lines · Julien Grall
Quoted 8 lines · Stefano Stabellini
Quoted 8 lines
xen/arch/arm/irq.c +0
-0@@ -31,6 +31,13 @@static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);Quoted 9 lines
xen/arch/arm/irq.c line 39
Quoted 6 lines
xen/arch/arm/irq.c +6
-0+/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +};I would prefer if you didn't use
dev_idfor this and just added a virq field to irqaction.
Quoted 3 lines
We already talked about it on v2. You were fine with the idea and acked the patch. Although, I haven't add your acked-by here because of the new changes in the code.
It is good to be consistent :-D
Quoted 10 lines
Here my answer to the same question on v2:
"I though about it. If we add another field in
arch_irq_desc, we will likely use more memory than xmalloc. This is because most of the platform doesn't use 1024 interrupts but about 256 interrupts.As the new field will be a pointer (on ARM64, 8 bytes), that would make Xen use statically about 8K more.
We could allocate
irq_descdynamically during Xen boot."
I remember now. Go ahead and add back my ack.
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
In reply to Julien GrallQuoted 1 line · Julien Grall
Actually Xen is assuming that the virtual IRQ will always be the same as IRQ.
s/Actually/Currently/?
Quoted 2 lines
Modify
route_guest_irqto take the virtual IRQ in parameter and let Xen assign a different IRQ number.
I think I must be misunderstanding this, but if route_guest_irq is taking the vIRQ as a parameter then why does it then need to assign a different IRQ number?
Oh, did you mean allowing the *caller* to setup a non-1:1 mapping perhaps? I think s/and let Xen assign/which allows Xen to.../ might be closer to that meaning if that's the intention?
Quoted 2 lines
Also store the vIRQ in the desc action to
easily retrieve easily the IRQ target when we need to inject the interrupt.
-ETooManyEasilys ;-)
(I think you want to drop the second one)
Quoted 1 line
As DOM0 will get most the devices, the vIRQ is equal to the IRQ in that case.
Am I correct that after this patch all callers still pass irq==virq to the new function?
Quoted 2 lines
At the same time modify the behavior of
irq_get_domain. The function now assumes that theirq_descbelongs to an IRQ assigned to a guest.
s/assumes/requires/?
xen/arch/arm/irq.c err: · line 395
Quoted 7 lines
action = xmalloc(struct irqaction);xen/arch/arm/irq.c +4
-1-if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest);
FWIW you might (subject to sizing/alignment needs) be able to do
action = _xmalloc(sizeof(struct irqaction) + sizeof(struct irq_guest); info = (sturct irq_guest *)(action + 1);
which would save some memory overhead for free pointers etc and allow you to avoid manually managing the info.
You probably won't like that though, so feel free to ignore.
Ian.
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall
Actually Xen is assuming that the virtual IRQ will always be the same as IRQ.
s/Actually/Currently/?
Yes, I always mix both because the former is close to the french word.
Quoted 10 lines
Quoted 2 lines
Modify
route_guest_irqto take the virtual IRQ in parameter and let Xen assign a different IRQ number.I think I must be misunderstanding this, but if
route_guest_irqis taking the vIRQ as a parameter then why does it then need to assign a different IRQ number?Oh, did you mean allowing the *caller* to setup a non-1:1 mapping perhaps? I think s/and let Xen assign/which allows Xen to.../ might be closer to that meaning if that's the intention?
Yes, the IRQ is not mapped 1:1 to the guest. I will replace by "which allows Xen to...".
Quoted 6 lines
Quoted 2 lines
Also store the vIRQ in the desc action to
easily retrieve easily the IRQ target when we need to inject the interrupt.-ETooManyEasilys ;-)
(I think you want to drop the second one)
Will fix it.
Quoted 10 lines
Quoted 2 lines
As DOM0 will get most the devices, the vIRQ is equal to the IRQ in that case.
Am I correct that after this patch all callers still pass irq==virq to the new function?
Quoted 2 lines
At the same time modify the behavior of
irq_get_domain. The function now assumes that theirq_descbelongs to an IRQ assigned to a guest.s/assumes/requires/?
Will fix it.
Quoted 8 lines
xen/arch/arm/irq.c err: · line 395
Quoted 7 lines
action = xmalloc(struct irqaction);xen/arch/arm/irq.c +4
-1-if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest);
Quoted 8 lines
FWIW you might (subject to sizing/alignment needs) be able to do
action = _xmalloc(sizeof(struct irqaction) + sizeof(struct irq_guest); info = (sturct irq_guest *)(action + 1);which would save some memory overhead for free pointers etc and allow you to avoid manually managing the info.
You probably won't like that though, so feel free to ignore.
Actually it's a good idea :). I haven't though about it.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Hi Ian,
Quoted 13 lines · Julien Grall
Quoted 12 lines · Ian Campbell
xen/arch/arm/irq.c err: · line 395
Quoted 7 lines
action = xmalloc(struct irqaction);xen/arch/arm/irq.c +4
-1-if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest);FWIW you might (subject to sizing/alignment needs) be able to do
action = _xmalloc(sizeof(struct irqaction) + sizeof(struct irq_guest); info = (sturct irq_guest *)(action + 1);
Quoted 6 lines
Quoted 4 lines
which would save some memory overhead for free pointers etc and allow you to avoid manually managing the info.
You probably won't like that though, so feel free to ignore.
Actually it's a good idea :). I haven't though about it.
I though about it. The pointer to irq_guest may not be correctly aligned with this solution, right?
So I prefer to keep separate the allocation. We can revisit it later.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 19 lines · Julien Grall
Hi Ian,
Quoted 16 lines · Julien Grall
Quoted 15 lines · Ian Campbell
xen/arch/arm/irq.c err: · line 395
Quoted 7 lines
action = xmalloc(struct irqaction);xen/arch/arm/irq.c +4
-1-if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest);FWIW you might (subject to sizing/alignment needs) be able to do
action = _xmalloc(sizeof(struct irqaction) + sizeof(struct irq_guest); info = (sturct irq_guest *)(action + 1);which would save some memory overhead for free pointers etc and allow you to avoid manually managing the info.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
You probably won't like that though, so feel free to ignore.
Actually it's a good idea :). I haven't though about it.
I though about it. The pointer to
irq_guestmay not be correctly aligned with this solution, right?
It depends on sizeof(struct irqaction) (which is what I meant by "subject to..."). t'd probably need a ROUNDUP(sizeof(foo), pointer-alignement) in there somewhere.
Quoted 1 line
So I prefer to keep separate the allocation. We can revisit it later.
OK.
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Julien Grall
Hi Ian,
Quoted 18 lines · Julien Grall
Quoted 16 lines · Ian Campbell
xen/arch/arm/irq.c err: · line 395
Quoted 7 lines
action = xmalloc(struct irqaction);xen/arch/arm/irq.c +4
-1-if (!action) +if ( !action ) +return -ENOMEM ; + + info = xmalloc(struct irq_guest);FWIW you might (subject to sizing/alignment needs) be able to do
action = _xmalloc(sizeof(struct irqaction) + sizeof(struct irq_guest); info = (sturct irq_guest *)(action + 1);which would save some memory overhead for free pointers etc and allow you to avoid manually managing the info.
You probably won't like that though, so feel free to ignore.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Actually it's a good idea :). I haven't though about it.
I though about it. The pointer to
irq_guestmay not be correctly aligned with this solution, right?It depends on sizeof(struct irqaction) (which is what I meant by "subject to..."). t'd probably need a
ROUNDUP(sizeof(foo), pointer-alignement)in there somewhere.
Oh right, I missed the parentheses part.
The pointer alignment is not the same on ARM32 and ARM64, I need to think more about it.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/24] xen/arm: Allow virq != irq
In reply to Ian CampbellHi Ian,
Quoted 4 lines · Ian Campbell
Quoted 1 line
As DOM0 will get most the devices, the vIRQ is equal to the IRQ in that case.
Am I correct that after this patch all callers still pass irq==virq to the new function?
Sorry, I forgot to answer to this question. Yes, all the callers will pass irq == virq in case of DOM0.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 9/24 xen/arm: route_irq_to_guest: Check validity of the IRQ
In reply to Julien GrallCurrently Xen only supports SPIs routing for guest, add a function is_assignable_irq to check if we can assign a given IRQ to the guest.
Secondly, make sure the vIRQ is not the greater that the number of IRQs handle to the vGIC and it's an SPIs.
Thirdly, when the IRQ is already assigned to the domain, check the user is not asking to use a different vIRQ than the one already bound.
Finally, desc->arch.type which contains the IRQ type (i.e level/edge) must be correctly configured before. The IRQ type won't be configure when:
- the device has been blacklist for the current platform
- the IRQ has not been describe in the device tree
I think we can safely assume that a user won't never ask to route as such IRQ to the guest.
Also, use XENLOG_G_ERR in the error message within the function as it will be later called from a guest.
---
Changes in v3:
- Fix typo in commit message and comment
- Add a check that the vIRQ is an SPI
- Check if the user is not asking for a different vIRQ when the IRQ is already assigned to the guest
Changes in v2:
- Rename is_routable_irq into is_assignable_irq
- Check if the IRQ is not greater than the number handled by the number of IRQs handled by the gic
- Move is_assignable_irq in irq.c rather than defining in the header irq.h
- Retrieve the irq descriptor after checking the validity of the IRQ
- vgic_num_irqs has been moved in a separate patch
- Fix the irq check against vgic_num_irqs
- Use virq instead of irq for vGIC sanity check
--- xen/arch/arm/irq.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-)
xen/arch/arm/irq.c +54 -4
@@ -379,6 +379,15 @@ err:return rc; } +bool_t is_assignable_irq (unsigned int irq) +{ +/* For now, we can only route SPIs to the guest */ +return ((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())); +} + +/* Route an IRQ to a specific guest. +* For now only SPIs are assignabled to the guest. +*/ int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char * devname) {
@@ -388,6 +397,29 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,unsigned long flags;int retval =0 ; +if ( !is_assignable_irq (irq) ) + { +dprintk (XENLOG_G_ERR ,"the IRQ%u is not routable\n" , irq); +return -EINVAL ; + } + + desc =irq_to_desc (irq); + +if ( virq >=vgic_num_irqs (d) ) + { +dprintk (XENLOG_G_ERR , +"the vIRQ number %u is too high for domain %u (max = %u)\n" , + irq, d->domain_id,vgic_num_irqs (d)); +return -EINVAL ; + } + +/* Only routing to virtual SPIs is supported */ +if ( virq <32 ) + { +dprintk (XENLOG_G_ERR ,"IRQ can only be routed to a virtual SPIs" ); +return -EINVAL ; + } + action = xmalloc(struct irqaction);if ( !action )return -ENOMEM ;
@@ -408,8 +440,18 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,spin_lock_irqsave (&desc->lock, flags); +if ( desc->arch.type ==DT_IRQ_TYPE_INVALID ) + { +dprintk (XENLOG_G_ERR ,"IRQ %u has not been configured\n" , + irq); + retval = -EIO ; + goto out; + } +/* If the IRQ is already used by someone -* - If it's the same domain -> Xen doesn't need to update the IRQ desc +* - If it's the same domain -> Xen doesn't need to update the IRQ desc. +* For safety check if we are not trying to assign the IRQ to a +* different vIRQ. * - Otherwise -> For now, don't allow the IRQ to be shared between * Xen and domains. */
@@ -418,13 +460,21 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,struct domain *ad =irq_get_domain (desc);if (test_bit (_IRQ_GUEST, &desc->status) && d == ad ) + { +if (irq_get_guest_info (desc)->virq != virq ) + { +dprintk (XENLOG_G_ERR ,"d%u: IRQ %u is already assigned to vIRQ %u\n" , + d->domain_id, irq,irq_get_guest_info (desc)->virq); + retval = -EPERM ; + } goto out; + }if (test_bit (_IRQ_GUEST, &desc->status) ) -printk (XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n" , - irq, ad->domain_id); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by domain %u\n" , + irq, ad->domain_id);else -printk (XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n" , irq); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by Xen\n" , irq); retval = -EBUSY ; goto out; }
xen/include/asm-arm/irq.h +2 -0
@@ -37,6 +37,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);#define domain_pirq_to_irq (d, pirq) (pirq) +bool_t is_assignable_irq (unsigned int irq); +void init_IRQ (void );void init_secondary_IRQ (void );
Signature · 1 line
2.1.4
Re: [PATCH v3 09/24] xen/arm: route_irq_to_guest: Check validity of the IRQ
Quoted 50 lines · Julien Grall
Currently Xen only supports SPIs routing for guest, add a function
is_assignable_irqto check if we can assign a given IRQ to the guest.Secondly, make sure the vIRQ is not the greater that the number of IRQs handle to the vGIC and it's an SPIs.
Thirdly, when the IRQ is already assigned to the domain, check the user is not asking to use a different vIRQ than the one already bound.
Finally,
desc->arch.typewhich contains the IRQ type (i.e level/edge) must be correctly configured before. The IRQ type won't be configure when:
- the device has been blacklist for the current platform
- the IRQ has not been describe in the device treeI think we can safely assume that a user won't never ask to route as such IRQ to the guest.
Also, use
XENLOG_G_ERRin the error message within the function as it will be later called from a guest.Signed-off-by Julien Grall <[email protected]>---
Changes in v3:
- Fix typo in commit message and comment
- Add a check that the vIRQ is an SPI
- Check if the user is not asking for a different vIRQ when the IRQ is already assigned to the guestChanges in v2:
- Renameis_routable_irqintois_assignable_irq
- Check if the IRQ is not greater than the number handled by the number of IRQs handled by the gic
- Moveis_assignable_irqinirq.crather than defining in the headerirq.h
- Retrieve the irq descriptor after checking the validity of the IRQ
-vgic_num_irqshas been moved in a separate patch
- Fix the irq check againstvgic_num_irqs
- Use virq instead of irq for vGIC sanity check--- xen/arch/arm/irq.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-)xen/arch/arm/irq.c +0
-0
xen/arch/arm/irq.c err: · line 382
Quoted 4 lines
xen/arch/arm/irq.c +1
-0@@ -379,6 +379,15 @@ err:return rc; } +bool_t is_assignable_irq (unsigned int irq)
static inline?
Quoted 62 lines
xen/arch/arm/irq.c +42
-1+{ +/* For now, we can only route SPIs to the guest */ +return ((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())); +} + +/* Route an IRQ to a specific guest. +* For now only SPIs are assignabled to the guest. +*/ int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char * devname) {@@ -388,6 +397,29 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,unsigned long flags;int retval =0 ; +if ( !is_assignable_irq (irq) ) + { +dprintk (XENLOG_G_ERR ,"the IRQ%u is not routable\n" , irq); +return -EINVAL ; + } + + desc =irq_to_desc (irq); + +if ( virq >=vgic_num_irqs (d) ) + { +dprintk (XENLOG_G_ERR , +"the vIRQ number %u is too high for domain %u (max = %u)\n" , + irq, d->domain_id,vgic_num_irqs (d)); +return -EINVAL ; + } + +/* Only routing to virtual SPIs is supported */ +if ( virq <32 ) + { +dprintk (XENLOG_G_ERR ,"IRQ can only be routed to a virtual SPIs" ); +return -EINVAL ; + } + action = xmalloc(struct irqaction);if ( !action )return -ENOMEM ;@@ -408,8 +440,18 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,spin_lock_irqsave (&desc->lock, flags); +if ( desc->arch.type ==DT_IRQ_TYPE_INVALID ) + { +dprintk (XENLOG_G_ERR ,"IRQ %u has not been configured\n" , + irq); + retval = -EIO ; + goto out; + } +/* If the IRQ is already used by someone -* - If it's the same domain -> Xen doesn't need to update the IRQ desc +* - If it's the same domain -> Xen doesn't need to update the IRQ desc. +* For safety check if we are not trying to assign the IRQ to a +* different vIRQ. * - Otherwise -> For now, don't allow the IRQ to be shared between * Xen and domains. */
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 468
Quoted 9 lines
xen/arch/arm/irq.c +6
-0@@ -418,13 +460,21 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,struct domain *ad =irq_get_domain (desc);if (test_bit (_IRQ_GUEST, &desc->status) && d == ad ) + { +if (irq_get_guest_info (desc)->virq != virq ) + { +dprintk (XENLOG_G_ERR ,"d%u: IRQ %u is already assigned to vIRQ %u\n" , + d->domain_id, irq,irq_get_guest_info (desc)->virq); + retval = -EPERM ;
I don't think that EPERM is the right error for this. Maybe EBUSY?
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 469
Quoted 1 line
xen/arch/arm/irq.c +1
-0+ }
Should we return error for this too? Maybe EEXIST?
Quoted 30 lines
xen/arch/arm/irq.c +4
-3goto out; + }if (test_bit (_IRQ_GUEST, &desc->status) ) -printk (XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n" , - irq, ad->domain_id); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by domain %u\n" , + irq, ad->domain_id);else -printk (XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n" , irq); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by Xen\n" , irq); retval = -EBUSY ; goto out; }xen/include/asm-arm/irq.h +2
-0@@ -37,6 +37,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);#define domain_pirq_to_irq (d, pirq) (pirq) +bool_t is_assignable_irq (unsigned int irq); +void init_IRQ (void );void init_secondary_IRQ (void );Signature · 1 line
2.1.4
Re: [PATCH v3 09/24] xen/arm: route_irq_to_guest: Check validity of the IRQ
Quoted 13 lines · Stefano Stabellini
Quoted 13 lines
--- xen/arch/arm/irq.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-)xen/arch/arm/irq.c +0
-0@@ -379,6 +379,15 @@ err:return rc; }
Quoted 3 lines
xen/arch/arm/irq.c err: · line 382
Quoted 1 line
xen/arch/arm/irq.c +1
-0+bool_t is_assignable_irq (unsigned int irq)static inline?
It's exported (will be used later) and not possible to inline in irq.h because of interdependency between irq.h and gic.h
[..]
Quoted 12 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 468
Quoted 10 lines
xen/arch/arm/irq.c +6
-0@@ -418,13 +460,21 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,struct domain *ad =irq_get_domain (desc);if (test_bit (_IRQ_GUEST, &desc->status) && d == ad ) + { +if (irq_get_guest_info (desc)->virq != virq ) + { +dprintk (XENLOG_G_ERR ,"d%u: IRQ %u is already assigned to vIRQ %u\n" , + d->domain_id, irq,irq_get_guest_info (desc)->virq); + retval = -EPERM ;I don't think that EPERM is the right error for this. Maybe EBUSY?
Right.
Quoted 4 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 469
Quoted 2 lines
xen/arch/arm/irq.c +1
-0+ }Should we return error for this too? Maybe EEXIST?
No, this is a valid use case especially for DOM0. The device tree may expose twice the same IRQ.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 09/24] xen/arm: route_irq_to_guest: Check validity of the IRQ
Quoted 39 lines · Julien Grall
Quoted 13 lines · Stefano Stabellini
Quoted 13 lines
--- xen/arch/arm/irq.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-)xen/arch/arm/irq.c +0
-0@@ -379,6 +379,15 @@ err:return rc; }Quoted 3 lines
xen/arch/arm/irq.c err: · line 382
Quoted 1 line
xen/arch/arm/irq.c +1
-0+bool_t is_assignable_irq (unsigned int irq)static inline?
It's exported (will be used later) and not possible to inline in
irq.hbecause of interdependency betweenirq.handgic.h[..]
Quoted 12 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 468
Quoted 10 lines
xen/arch/arm/irq.c +6
-0@@ -418,13 +460,21 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,struct domain *ad =irq_get_domain (desc);if (test_bit (_IRQ_GUEST, &desc->status) && d == ad ) + { +if (irq_get_guest_info (desc)->virq != virq ) + { +dprintk (XENLOG_G_ERR ,"d%u: IRQ %u is already assigned to vIRQ %u\n" , + d->domain_id, irq,irq_get_guest_info (desc)->virq); + retval = -EPERM ;I don't think that EPERM is the right error for this. Maybe EBUSY?
Right.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 469
Quoted 1 line
xen/arch/arm/irq.c +1
-0+ }Should we return error for this too? Maybe EEXIST?
No, this is a valid use case especially for DOM0. The device tree may expose twice the same IRQ.
OK
Re: [PATCH v3 09/24] xen/arm: route_irq_to_guest: Check validity of the IRQ
In reply to Julien GrallQuoted 5 lines · Julien Grall
Currently Xen only supports SPIs routing for guest, add a function
is_assignable_irqto check if we can assign a given IRQ to the guest.Secondly, make sure the vIRQ is not the greater that the number of IRQs handle to the vGIC and it's an SPIs.
I think you mean the "number of IRQs handled by the vGIC" (or configured in?) and it would just be "an SPI".
Quoted 5 lines
Thirdly, when the IRQ is already assigned to the domain, check the user is not asking to use a different vIRQ than the one already bound.
Finally,
desc->arch.typewhich contains the IRQ type (i.e level/edge) must be correctly configured before. The IRQ type won't be configure when:
^routing?
Quoted 1 line
- the device has been blacklist for the current platform
"blacklisted".
Quoted 1 line
- the IRQ has not been describe in the device tree
"described".
Quoted 2 lines
I think we can safely assume that a user won't never ask to route as such IRQ to the guest.
Can we now ;-) Does this mean the code doesn't check for and abort on these cases?
<later>Having read further I think you do catch it, so I think you can remove that sentence, or at least append "...but we check for this anyway"</later>.
Quoted 6 lines
xen/arch/arm/irq.c +0
-0@@ -379,6 +379,15 @@ err:return rc;
xen/arch/arm/irq.c err: · line 389
Quoted 10 lines
xen/arch/arm/irq.c +8
-0} +bool_t is_assignable_irq (unsigned int irq) +{ +/* For now, we can only route SPIs to the guest */ +return ((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())); +} + +/* Route an IRQ to a specific guest. +* For now only SPIs are assignabled to the guest.
"assignable"
Quoted 5 lines
xen/arch/arm/irq.c +1
-0+*/ int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char * devname) {
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 406
Quoted 10 lines
xen/arch/arm/irq.c +7
-0@@ -388,6 +397,29 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,unsigned long flags;int retval =0 ; +if ( !is_assignable_irq (irq) ) + { +dprintk (XENLOG_G_ERR ,"the IRQ%u is not routable\n" , irq); +return -EINVAL ; + } + + desc =irq_to_desc (irq);
I can't remember if this is expensive, but you could safely do it further down after more of the sanity checks.
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 417
Quoted 11 lines
xen/arch/arm/irq.c +11
-0+ +if ( virq >=vgic_num_irqs (d) ) + { +dprintk (XENLOG_G_ERR , +"the vIRQ number %u is too high for domain %u (max = %u)\n" , + irq, d->domain_id,vgic_num_irqs (d)); +return -EINVAL ; + } + +/* Only routing to virtual SPIs is supported */ +if ( virq <32 )
NR_LOCAL_IRQS?
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 419
Quoted 2 lines
xen/arch/arm/irq.c +2
-0+ { +dprintk (XENLOG_G_ERR ,"IRQ can only be routed to a virtual SPIs" );
Just "SPI".
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 477
Quoted 7 lines
xen/arch/arm/irq.c +3
-3-printk (XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n" , - irq, ad->domain_id); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by domain %u\n" , + irq, ad->domain_id); else - printk(XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n", irq); + dprintk(XENLOG_G_ERR, "IRQ %u is already used by Xen\n", irq);
Is the file/line really needed here? The messages seem reasonably unique already.
Re: [PATCH v3 09/24] xen/arm: route_irq_to_guest: Check validity of the IRQ
Hi Ian,
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Julien Grall
Currently Xen only supports SPIs routing for guest, add a function
is_assignable_irqto check if we can assign a given IRQ to the guest.Secondly, make sure the vIRQ is not the greater that the number of IRQs handle to the vGIC and it's an SPIs.
I think you mean the "number of IRQs handled by the vGIC" (or configured in?) and it would just be "an SPI".
I think "configured in" is better here. I will change to "number of IRQs configured in the vGIC".
Quoted 6 lines
Quoted 5 lines
Thirdly, when the IRQ is already assigned to the domain, check the user is not asking to use a different vIRQ than the one already bound.
Finally,
desc->arch.typewhich contains the IRQ type (i.e level/edge) must be correctly configured before. The IRQ type won't be configure when:^routing?
No, I wanted to mean when a IRQ type is not set.
I will replace the last sentence by "This can happen when:"
Quoted 9 lines
Quoted 2 lines
- the device has been blacklist for the current platform
"blacklisted".
Quoted 1 line
- the IRQ has not been describe in the device tree
"described".
Quoted 8 lines
Quoted 2 lines
I think we can safely assume that a user won't never ask to route as such IRQ to the guest.
Can we now ;-) Does this mean the code doesn't check for and abort on these cases?
<later>Having read further I think you do catch it, so I think you can remove that sentence, or at least append "...but we check for this anyway"</later>.
Right, this sentence is not clear. What I wanted to mean is we won't support any IRQ not described in the DT or which belong to a specific domain.
But with an upcoming patch from Parth, the IRQ configuration (edge/level) will be deferred until the guest has enabled this IRQ.
Quoted 27 lines
Quoted 6 lines
xen/arch/arm/irq.c +0
-0@@ -379,6 +379,15 @@ err:return rc;xen/arch/arm/irq.c err: · line 389
Quoted 10 lines
xen/arch/arm/irq.c +8
-0} +bool_t is_assignable_irq (unsigned int irq) +{ +/* For now, we can only route SPIs to the guest */ +return ((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())); +} + +/* Route an IRQ to a specific guest. +* For now only SPIs are assignabled to the guest. "assignable"
Quoted 8 lines
xen/arch/arm/irq.c +1
-0+*/ int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char * devname) {@@ -388,6 +397,29 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,unsigned long flags;int retval =0 ;
Quoted 10 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 406
Quoted 7 lines
xen/arch/arm/irq.c +7
-0+if ( !is_assignable_irq (irq) ) + { +dprintk (XENLOG_G_ERR ,"the IRQ%u is not routable\n" , irq); +return -EINVAL ; + } + + desc =irq_to_desc (irq);I can't remember if this is expensive, but you could safely do it further down after more of the sanity checks.
For now we retrieve it from an array. But Vijay's plan to replace the array by a radix tree.
I will move the whole block (if () ... desc = ) after the vGIC because I think they should be tight.
Quoted 14 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 417
Quoted 12 lines
xen/arch/arm/irq.c +11
-0+ +if ( virq >=vgic_num_irqs (d) ) + { +dprintk (XENLOG_G_ERR , +"the vIRQ number %u is too high for domain %u (max = %u)\n" , + irq, d->domain_id,vgic_num_irqs (d)); +return -EINVAL ; + } + +/* Only routing to virtual SPIs is supported */ +if ( virq <32 )
NR_LOCAL_IRQS?
Yes. I think I have multiple place where 32 is open-coded. I will replace them.
Quoted 14 lines
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 419
Quoted 3 lines
xen/arch/arm/irq.c +2
-0+ { +dprintk (XENLOG_G_ERR ,"IRQ can only be routed to a virtual SPIs" );Just "SPI".
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 477
Quoted 7 lines
xen/arch/arm/irq.c +3
-3-printk (XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n" , - irq, ad->domain_id); +dprintk (XENLOG_G_ERR ,"IRQ %u is already used by domain %u\n" , + irq, ad->domain_id); else - printk(XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n", irq); + dprintk(XENLOG_G_ERR, "IRQ %u is already used by Xen\n", irq);
Quoted 2 lines
Is the file/line really needed here? The messages seem reasonably unique already.
I don't remember why I made this change. I will drop it.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 10/24 xen/arm: gic: Add sanity checks gic_route_irq_to_guest
In reply to Julien GrallWith the addition of interrupt assignment to guest, we need to make sure the guest don't blow up the interrupt management in Xen.
Before associating the IRQ to a vIRQ we need to make sure:
- the vIRQ is not already associated to another IRQ
- the guest didn't enable the vIRQ
---
Changes in v3:
- Patch added
--- xen/arch/arm/gic.c | 34 ++++++++++++++++++++++++++-------- xen/arch/arm/irq.c | 12 ++++++++++-- xen/include/asm-arm/gic.h | 7 +++---- 3 files changed, 39 insertions(+), 14 deletions(-)
xen/arch/arm/gic.c +26 -8
@@ -126,22 +126,40 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,/* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest (struct domain *d,unsigned int virq, -struct irq_desc *desc, -const cpumask_t *cpu_mask,unsigned int priority) +int gic_route_irq_to_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc,unsigned int priority) { -struct pending_irq *p; +unsigned long flags; +/* Use vcpu0 to retrieve the pending_irq struct. Given that we only +* route SPIs to guests, it doesn't make any difference. */ +struct vcpu *v_target =vgic_get_target_vcpu (d->vcpu[0 ], virq); +struct vgic_irq_rank *rank =vgic_rank_irq (v_target, virq); +struct pending_irq *p =irq_to_pending (v_target, virq); +int res = -EBUSY ; +ASSERT (spin_is_locked (&desc->lock)); +/* We only support SPIs */ +ASSERT (virq >=32 && virq <vgic_num_irqs (d)); + +vgic_lock_rank (v_target, rank, flags); + +if ( p->desc || +/* The VIRQ should not be already enabled by the guest */ +test_bit (GIC_IRQ_GUEST_ENABLED , &p->status) ) + goto out; desc->handler = gic_hw_ops->gic_guest_irq_type;set_bit (_IRQ_GUEST, &desc->status); -gic_set_irq_properties (desc,cpumask_of (smp_processor_id ()),GIC_PRI_IRQ ); +gic_set_irq_properties (desc,cpumask_of (v_target->processor), priority); -/* Use vcpu0 to retrieve the pending_irq struct. Given that we only -* route SPIs to guests, it doesn't make any difference. */ - p =irq_to_pending (d->vcpu[0 ], virq); p->desc = desc; + res =0 ; + +out: +vgic_unlock_rank (v_target, rank, flags); + +return res; } int gic_irq_xlate(const u32 *intspec, unsigned int intsize,
xen/arch/arm/irq.c +10 -2
@@ -483,14 +483,22 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,if ( retval ) goto out; -gic_route_irq_to_guest (d, virq, desc,cpumask_of (smp_processor_id ()), -GIC_PRI_IRQ ); + retval =gic_route_irq_to_guest (d, virq, desc,GIC_PRI_IRQ ); +spin_unlock_irqrestore (&desc->lock, flags); + +if ( retval ) + { +release_irq (desc->irq, info); + goto free_info; + } +return 0 ; out:spin_unlock_irqrestore (&desc->lock, flags);xfree (action); +free_info:xfree (info);return retval;
xen/include/asm-arm/gic.h +3 -4
@@ -213,10 +213,9 @@ extern enum gic_version gic_hw_version(void);/* Program the GIC to route an interrupt */ extern void gic_route_irq_to_xen (struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority); -extern void gic_route_irq_to_guest (struct domain *,unsigned int virq, -struct irq_desc *desc, -const cpumask_t *cpu_mask, -unsigned int priority); +extern int gic_route_irq_to_guest (struct domain *,unsigned int virq, +struct irq_desc *desc, +unsigned int priority);extern void gic_inject (void );extern void gic_clear_pending_irqs (struct vcpu *v);
Signature · 1 line
2.1.4
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Quoted 8 lines · Julien Grall
With the addition of interrupt assignment to guest, we need to make sure the guest don't blow up the interrupt management in Xen.
Before associating the IRQ to a vIRQ we need to make sure:
- the vIRQ is not already associated to another IRQ
- the guest didn't enable the vIRQSigned-off-by Julien Grall <[email protected]>
Quoted 111 lines
Changes in v3:
- Patch added--- xen/arch/arm/gic.c | 34 ++++++++++++++++++++++++++-------- xen/arch/arm/irq.c | 12 ++++++++++-- xen/include/asm-arm/gic.h | 7 +++---- 3 files changed, 39 insertions(+), 14 deletions(-)xen/arch/arm/gic.c +26
-8@@ -126,22 +126,40 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,/* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest (struct domain *d,unsigned int virq, -struct irq_desc *desc, -const cpumask_t *cpu_mask,unsigned int priority) +int gic_route_irq_to_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc,unsigned int priority) { -struct pending_irq *p; +unsigned long flags; +/* Use vcpu0 to retrieve the pending_irq struct. Given that we only +* route SPIs to guests, it doesn't make any difference. */ +struct vcpu *v_target =vgic_get_target_vcpu (d->vcpu[0 ], virq); +struct vgic_irq_rank *rank =vgic_rank_irq (v_target, virq); +struct pending_irq *p =irq_to_pending (v_target, virq); +int res = -EBUSY ; +ASSERT (spin_is_locked (&desc->lock)); +/* We only support SPIs */ +ASSERT (virq >=32 && virq <vgic_num_irqs (d)); + +vgic_lock_rank (v_target, rank, flags); + +if ( p->desc || +/* The VIRQ should not be already enabled by the guest */ +test_bit (GIC_IRQ_GUEST_ENABLED , &p->status) ) + goto out; desc->handler = gic_hw_ops->gic_guest_irq_type;set_bit (_IRQ_GUEST, &desc->status); -gic_set_irq_properties (desc,cpumask_of (smp_processor_id ()),GIC_PRI_IRQ ); +gic_set_irq_properties (desc,cpumask_of (v_target->processor), priority); -/* Use vcpu0 to retrieve the pending_irq struct. Given that we only -* route SPIs to guests, it doesn't make any difference. */ - p =irq_to_pending (d->vcpu[0 ], virq); p->desc = desc; + res =0 ; + +out: +vgic_unlock_rank (v_target, rank, flags); + +return res; } int gic_irq_xlate(const u32 *intspec, unsigned int intsize,xen/arch/arm/irq.c +10
-2@@ -483,14 +483,22 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,if ( retval ) goto out; -gic_route_irq_to_guest (d, virq, desc,cpumask_of (smp_processor_id ()), -GIC_PRI_IRQ ); + retval =gic_route_irq_to_guest (d, virq, desc,GIC_PRI_IRQ ); +spin_unlock_irqrestore (&desc->lock, flags); + +if ( retval ) + { +release_irq (desc->irq, info); + goto free_info; + } +return 0 ; out:spin_unlock_irqrestore (&desc->lock, flags);xfree (action); +free_info:xfree (info);return retval;xen/include/asm-arm/gic.h +3
-4@@ -213,10 +213,9 @@ extern enum gic_version gic_hw_version(void);/* Program the GIC to route an interrupt */ extern void gic_route_irq_to_xen (struct irq_desc *desc,const cpumask_t *cpu_mask,unsigned int priority); -extern void gic_route_irq_to_guest (struct domain *,unsigned int virq, -struct irq_desc *desc, -const cpumask_t *cpu_mask, -unsigned int priority); +extern int gic_route_irq_to_guest (struct domain *,unsigned int virq, +struct irq_desc *desc, +unsigned int priority);extern void gic_inject (void );extern void gic_clear_pending_irqs (struct vcpu *v);Signature · 1 line
2.1.4
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
In reply to Julien GrallQuoted 2 lines · Julien Grall
With the addition of interrupt assignment to guest, we need to make sure the guest don't blow up the interrupt management in Xen.
s/don't/can't/
Quoted 31 lines
Before associating the IRQ to a vIRQ we need to make sure:
- the vIRQ is not already associated to another IRQ
- the guest didn't enable the vIRQSigned-off-by Julien Grall <[email protected]>---
Changes in v3:
- Patch added--- xen/arch/arm/gic.c | 34 ++++++++++++++++++++++++++-------- xen/arch/arm/irq.c | 12 ++++++++++-- xen/include/asm-arm/gic.h | 7 +++---- 3 files changed, 39 insertions(+), 14 deletions(-)xen/arch/arm/gic.c +2
-4@@ -126,22 +126,40 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,/* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest (struct domain *d,unsigned int virq, -struct irq_desc *desc, -const cpumask_t *cpu_mask,unsigned int priority) +int gic_route_irq_to_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc,unsigned int priority) { -struct pending_irq *p;
xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, · line 141
Quoted 10 lines
xen/arch/arm/gic.c +9
-0+unsigned long flags; +/* Use vcpu0 to retrieve the pending_irq struct. Given that we only +* route SPIs to guests, it doesn't make any difference. */ +struct vcpu *v_target =vgic_get_target_vcpu (d->vcpu[0 ], virq); +struct vgic_irq_rank *rank =vgic_rank_irq (v_target, virq); +struct pending_irq *p =irq_to_pending (v_target, virq); +int res = -EBUSY ; +ASSERT (spin_is_locked (&desc->lock)); +/* We only support SPIs */
More importantly: We have (hopefully) guaranteed elsewhere that an PPI or SGI can never make it here, I take it. If that's the case then either the comment should say that, or more likely, the comment is redundently restating the assert's condition.
xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, · line 142
Quoted 1 line
xen/arch/arm/gic.c +1
-0+ASSERT (virq >=32 && virq <vgic_num_irqs (d));
NR_LOCAL_IRQS?
Also splitting the two conditions into two asserts will make it more obvious which one failed if we hit it.
xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, · line 154
Quoted 13 lines
xen/arch/arm/gic.c +8
-1+ +vgic_lock_rank (v_target, rank, flags); + +if ( p->desc || +/* The VIRQ should not be already enabled by the guest */ +test_bit (GIC_IRQ_GUEST_ENABLED , &p->status) ) + goto out; desc->handler = gic_hw_ops->gic_guest_irq_type;set_bit (_IRQ_GUEST, &desc->status); -gic_set_irq_properties (desc,cpumask_of (smp_processor_id ()),GIC_PRI_IRQ ); +gic_set_irq_properties (desc,cpumask_of (v_target->processor), priority);
This smells like a functional change, not a sanity check, what is it for?
Is v_target->processor always configured, even for the first routing of an IRQ to dom0?
Care needs to be taken here that priority is not under unfettered guest control -- since this configures the physical GIC we need to e.g. ensure that Xen's own IPIs have higher priority than anything a guest can ever set. (Realistically this probably means we want to constrain guests to the bottom half of the priority range and expose different BPR etc in the vgic, out of scope here though)
Ian.
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Hi Ian,
Quoted 4 lines · Ian Campbell
More importantly: We have (hopefully) guaranteed elsewhere that an PPI or SGI can never make it here, I take it. If that's the case then either the comment should say that, or more likely, the comment is redundently restating the assert's condition.
I will update the comment to /* Caller has already checked that the IRQ is an SPIs */
Quoted 3 lines
Quoted 1 line
+
ASSERT(virq >= 32 && virq < vgic_num_irqs(d));
NR_LOCAL_IRQS?
Yes.
Quoted 2 lines
Also splitting the two conditions into two asserts will make it more obvious which one failed if we hit it.
Will do.
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/gic.c +7
-0+ +vgic_lock_rank (v_target, rank, flags); + +if ( p->desc || +/* The VIRQ should not be already enabled by the guest */ +test_bit (GIC_IRQ_GUEST_ENABLED , &p->status) ) + goto out;
Quoted 8 lines
xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, · line 154
Quoted 5 lines
desc->handler = gic_hw_ops->gic_guest_irq_type; set_bit(_IRQ_GUEST, &desc->status);xen/arch/arm/gic.c +1
-1-gic_set_irq_properties (desc,cpumask_of (smp_processor_id ()),GIC_PRI_IRQ ); +gic_set_irq_properties (desc,cpumask_of (v_target->processor), priority);This smells like a functional change, not a sanity check, what is it for?
Hmmm right. I will move it to a separate patch.
Quoted 2 lines
Is
v_target->processoralways configured, even for the first routing of an IRQ to dom0?
Yes, IRQ are routed to CPU0 by default.
Quoted 7 lines
Care needs to be taken here that priority is not under unfettered guest control -- since this configures the physical GIC we need to e.g. ensure that Xen's own IPIs have higher priority than anything a guest can ever set. (Realistically this probably means we want to constrain guests to the bottom half of the priority range and expose different BPR etc in the vgic, out of scope here though)
The priority is controlled by route_irq_to_guest and set statically using GIC_PRI_IRQ.
If we decide to hardcoded the priority here, we should drop the parameter on gic_route_irq_guest. But not keeping both.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Quoted 10 lines · Julien Grall
Hi Ian,
Quoted 4 lines · Ian Campbell
More importantly: We have (hopefully) guaranteed elsewhere that an PPI or SGI can never make it here, I take it. If that's the case then either the comment should say that, or more likely, the comment is redundently restating the assert's condition.
I will update the comment to /* Caller has already checked that the IRQ is an SPIs */
Just "SPI", but otherwise sounds good.
Quoted 7 lines
Quoted 6 lines
Care needs to be taken here that priority is not under unfettered guest control -- since this configures the physical GIC we need to e.g. ensure that Xen's own IPIs have higher priority than anything a guest can ever set. (Realistically this probably means we want to constrain guests to the bottom half of the priority range and expose different BPR etc in the vgic, out of scope here though)
Quoted 5 lines
The priority is controlled by
route_irq_to_guestand set statically usingGIC_PRI_IRQ.If we decide to hardcoded the priority here, we should drop the parameter on
gic_route_irq_guest. But not keeping both.
There is a middle ground, which is for guest-routed IRQs to be allowed a subset of the real priorities, but until those associated checks are in place I think hardcoding in gic_route_irq_to_guest leaves less scope for mistakes.
Ian.
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Hi Ian,
Quoted 11 lines · Ian Campbell
Quoted 5 lines · Julien Grall
The priority is controlled by
route_irq_to_guestand set statically usingGIC_PRI_IRQ.If we decide to hardcoded the priority here, we should drop the parameter on
gic_route_irq_guest. But not keeping both.There is a middle ground, which is for guest-routed IRQs to be allowed a subset of the real priorities, but until those associated checks are in place I think hardcoding in
gic_route_irq_to_guestleaves less scope for mistakes.
The interface for routing an IRQ to xen (gic_route_irq_to_xen) is taking the priority in parameter.
I would prefer if we keep the same interface for guest and then hardcode the value in route_irq_to_guest.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Quoted 10 lines · Julien Grall
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Julien Grall
The priority is controlled by
route_irq_to_guestand set statically usingGIC_PRI_IRQ.If we decide to hardcoded the priority here, we should drop the parameter on
gic_route_irq_guest. But not keeping both.
Quoted 7 lines
Quoted 4 lines
There is a middle ground, which is for guest-routed IRQs to be allowed a subset of the real priorities, but until those associated checks are in place I think hardcoding in
gic_route_irq_to_guestleaves less scope for mistakes.The interface for routing an IRQ to xen (
gic_route_irq_to_xen) is taking the priority in parameter.
It's useful and safe in the route to xen case.
Quoted 2 lines
I would prefer if we keep the same interface for guest and then hardcode the value in
route_irq_to_guest.
In which case I think route_irq_to_guest should complain/error-out if the priority given is not the default one until such a time as it understands which inputs are safe.
Ian.
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Quoted 19 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Julien Grall
The priority is controlled by
route_irq_to_guestand set statically usingGIC_PRI_IRQ.If we decide to hardcoded the priority here, we should drop the parameter on
gic_route_irq_guest. But not keeping both.Quoted 7 lines
Quoted 4 lines
There is a middle ground, which is for guest-routed IRQs to be allowed a subset of the real priorities, but until those associated checks are in place I think hardcoding in
gic_route_irq_to_guestleaves less scope for mistakes.The interface for routing an IRQ to xen (
gic_route_irq_to_xen) is taking the priority in parameter.
Quoted 8 lines
It's useful and safe in the route to xen case.
Quoted 2 lines
I would prefer if we keep the same interface for guest and then hardcode the value in
route_irq_to_guest.In which case I think
route_irq_to_guestshould complain/error-out if the priority given is not the default one until such a time as it understands which inputs are safe.
I guess you mean gic_route_irq_to_guest?
I could add a check and error-out for this case.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest
Quoted 22 lines · Julien Grall
Quoted 21 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 5 lines · Julien Grall
The priority is controlled by
route_irq_to_guestand set statically usingGIC_PRI_IRQ.If we decide to hardcoded the priority here, we should drop the parameter on
gic_route_irq_guest. But not keeping both.Quoted 7 lines
Quoted 4 lines
There is a middle ground, which is for guest-routed IRQs to be allowed a subset of the real priorities, but until those associated checks are in place I think hardcoding in
gic_route_irq_to_guestleaves less scope for mistakes.The interface for routing an IRQ to xen (
gic_route_irq_to_xen) is taking the priority in parameter.It's useful and safe in the route to xen case.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I would prefer if we keep the same interface for guest and then hardcode the value in
route_irq_to_guest.In which case I think
route_irq_to_guestshould complain/error-out if the priority given is not the default one until such a time as it understands which inputs are safe.I guess you mean
gic_route_irq_to_guest?
Whichever function is ignoring its priority argument in favour of a hardcoded value.
Quoted 4 lines
I could add a check and error-out for this case.
Regards,
PATCH v3 11/24 xen/arm: Let the toolstack configure the number of SPIs
In reply to Julien GrallEach domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
---
Changes in v3:
- Fix typoes
- A separate has been created to extend the DOMCTL create domain
Changes in v2:
- Patch added
--- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 38 insertions(+), 7 deletions(-)
tools/libxc/xc_domain.c +1 -0
@@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch,/* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =0 ;#else errno =ENOSYS ;return -1 ;
tools/libxl/libxl_arm.c +19 -0
@@ -39,6 +39,25 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config) { +uint32_t nr_spis =0 ; +unsigned int i; + +for (i =0 ; i < d_config->b_info.num_irqs; i++) { +int irq = d_config->b_info.irqs[i]; +int spi = irq -32 ; + +if (irq <32 ) +continue ; + +if (nr_spis <= spi) + nr_spis = spi +1 ; + } + +LOG (DEBUG ,"Configure the domain" ); + + xc_config->nr_spis = nr_spis; +LOG (DEBUG ," - Allocate %u SPIs" , nr_spis); + xc_config->gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ;return 0 ;
xen/arch/arm/domain.c +6 -1
@@ -560,10 +560,15 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, } config->gic_version = gic_version; +/* Sanity check on the number of SPIs */ + rc = -EINVAL ; +if ( config->nr_spis > (gic_number_lines () -32 ) ) + goto fail; +if ( (rc =gicv_setup (d)) !=0 ) goto fail; -if ( (rc =domain_vgic_init (d)) !=0 ) +if ( (rc =domain_vgic_init (d, config->nr_spis)) !=0 ) goto fail;if ( (rc =domain_vtimer_init (d)) !=0 )
xen/arch/arm/setup.c +1 -0
@@ -815,6 +815,7 @@ void __init start_xen(unsigned long boot_phys_offset,/* Create initial domain 0. */ /* The vGIC for DOM0 is exactly emulated the hardware GIC */ config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =gic_number_lines () -32 ; dom0 =domain_create (0 ,0 ,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )
xen/arch/arm/vgic.c +5 -5
@@ -67,16 +67,16 @@ static void vgic_init_pending_irq(struct pending_irq *p, unsigned int 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 has to be aligned to 32 see +* GICD_TYPER.ITLinesNumber definition +*/ + d->arch.vgic.nr_spis =ROUNDUP (nr_spis,32 );switch (gic_hw_version () ) {
xen/include/asm-arm/domain.h +2 -0
@@ -121,6 +121,8 @@ struct arch_domainunsigned int evtchn_irq; } __cacheline_aligned; +#define domain_is_configured (d) ((d)->arch.is_configured) + struct arch_vcpu { struct {
xen/include/asm-arm/setup.h +1 -0
@@ -54,6 +54,7 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);void arch_get_xen_caps (xen_capabilities_info_t *info);int construct_dom0 (struct domain *d); +int configure_dom0 (struct domain *d);void discard_initial_modules (void );
xen/include/asm-arm/vgic.h +1 -1
@@ -177,7 +177,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);
xen/include/public/arch-arm.h +2 -0
@@ -320,6 +320,8 @@ typedef uint64_t xen_callback_t;struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version; +/* IN */ +uint32_t nr_spis; };#endif
Signature · 1 line
2.1.4
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Quoted 51 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
Signed-off-by Julien Grall <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Wei Liu <[email protected]>---
Changes in v3:
- Fix typoes
- A separate has been created to extend the DOMCTL create domainChanges in v2:
- Patch added--- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 38 insertions(+), 7 deletions(-)tools/libxc/xc_domain.c +1
-0@@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch,/* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =0 ;#else errno =ENOSYS ;return -1 ;tools/libxl/libxl_arm.c +0
-0
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 46
Quoted 8 lines
tools/libxl/libxl_arm.c +5
-0@@ -39,6 +39,25 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config) { +uint32_t nr_spis =0 ; +unsigned int i; + +for (i =0 ; i < d_config->b_info.num_irqs; i++) { +int irq = d_config->b_info.irqs[i];
unsigned int
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 47
Quoted 1 line
tools/libxl/libxl_arm.c +1
-0+int spi = irq -32 ;
unsigned int
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 53
Quoted 5 lines
tools/libxl/libxl_arm.c +5
-0+if (irq <32 ) +continue ; + +if (nr_spis <= spi) + nr_spis = spi +1 ;
overflow check?
Quoted 74 lines
tools/libxl/libxl_arm.c +7
-0+ } + +LOG (DEBUG ,"Configure the domain" ); + + xc_config->nr_spis = nr_spis; +LOG (DEBUG ," - Allocate %u SPIs" , nr_spis); + xc_config->gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ;return 0 ;xen/arch/arm/domain.c +6
-1@@ -560,10 +560,15 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, } config->gic_version = gic_version; +/* Sanity check on the number of SPIs */ + rc = -EINVAL ; +if ( config->nr_spis > (gic_number_lines () -32 ) ) + goto fail; +if ( (rc =gicv_setup (d)) !=0 ) goto fail; -if ( (rc =domain_vgic_init (d)) !=0 ) +if ( (rc =domain_vgic_init (d, config->nr_spis)) !=0 ) goto fail;if ( (rc =domain_vtimer_init (d)) !=0 )xen/arch/arm/setup.c +1
-0@@ -815,6 +815,7 @@ void __init start_xen(unsigned long boot_phys_offset,/* Create initial domain 0. */ /* The vGIC for DOM0 is exactly emulated the hardware GIC */ config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =gic_number_lines () -32 ; dom0 =domain_create (0 ,0 ,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )xen/arch/arm/vgic.c +5
-5@@ -67,16 +67,16 @@ static void vgic_init_pending_irq(struct pending_irq *p, unsigned int 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 has to be aligned to 32 see +* GICD_TYPER.ITLinesNumber definition +*/ + d->arch.vgic.nr_spis =ROUNDUP (nr_spis,32 );switch (gic_hw_version () ) {xen/include/asm-arm/domain.h +0
-0
xen/include/asm-arm/domain.h struct arch_domain · line 124
Quoted 4 lines
xen/include/asm-arm/domain.h +1
-0@@ -121,6 +121,8 @@ struct arch_domainunsigned int evtchn_irq; } __cacheline_aligned; +#define domain_is_configured (d) ((d)->arch.is_configured)
This is unused. Moreover it cannot find "is_configured" anywhere.
Quoted 44 lines
xen/include/asm-arm/domain.h +0
-0struct arch_vcpu { struct {xen/include/asm-arm/setup.h +1
-0@@ -54,6 +54,7 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);void arch_get_xen_caps (xen_capabilities_info_t *info);int construct_dom0 (struct domain *d); +int configure_dom0 (struct domain *d);void discard_initial_modules (void );xen/include/asm-arm/vgic.h +1
-1@@ -177,7 +177,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);xen/include/public/arch-arm.h +2
-0@@ -320,6 +320,8 @@ typedef uint64_t xen_callback_t;struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version; +/* IN */ +uint32_t nr_spis; };#endif Signature · 1 line
2.1.4
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Hi Stefano,
Quoted 54 lines · Stefano Stabellini
Quoted 53 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
Signed-off-by Julien Grall <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Wei Liu <[email protected]>---
Changes in v3:
- Fix typoes
- A separate has been created to extend the DOMCTL create domainChanges in v2:
- Patch added--- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 38 insertions(+), 7 deletions(-)tools/libxc/xc_domain.c +1
-0@@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch,/* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =0 ;#else errno =ENOSYS ;return -1 ;tools/libxl/libxl_arm.c +0
-0@@ -39,6 +39,25 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config)
Quoted 8 lines
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 46
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0{ +uint32_t nr_spis =0 ; +unsigned int i; + +for (i =0 ; i < d_config->b_info.num_irqs; i++) { +int irq = d_config->b_info.irqs[i];unsigned int
I will use uint32_t.
Quoted 1 line
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 47
Quoted 1 line
tools/libxl/libxl_arm.c +1
-0+int spi = irq -32 ;
Same here.
Quoted 8 lines
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 53
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0+if (irq <32 ) +continue ; + +if (nr_spis <= spi) + nr_spis = spi +1 ;overflow check?
If I use unsigned int, the overflow will go back to 0. While it won't affect the code, the domain creation will fail later (unable to assign the SPI).
So is it useful to add a check here?
[..]
Quoted 11 lines
xen/include/asm-arm/domain.h struct arch_domain · line 124
Quoted 9 lines
xen/include/asm-arm/domain.h +1
-0@@ -121,6 +121,8 @@ struct arch_domainunsigned int evtchn_irq; } __cacheline_aligned; +#define domain_is_configured (d) ((d)->arch.is_configured)This is unused. Moreover it cannot find "
is_configured" anywhere.
Left-over of a previous version. Sorry.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Quoted 79 lines · Julien Grall
Hi Stefano,
Quoted 54 lines · Stefano Stabellini
Quoted 53 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
Signed-off-by Julien Grall <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Wei Liu <[email protected]>---
Changes in v3:
- Fix typoes
- A separate has been created to extend the DOMCTL create domainChanges in v2:
- Patch added--- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 38 insertions(+), 7 deletions(-)tools/libxc/xc_domain.c +1
-0@@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch,/* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =0 ;#else errno =ENOSYS ;return -1 ;tools/libxl/libxl_arm.c +0
-0@@ -39,6 +39,25 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config)Quoted 8 lines
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 46
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0{ +uint32_t nr_spis =0 ; +unsigned int i; + +for (i =0 ; i < d_config->b_info.num_irqs; i++) { +int irq = d_config->b_info.irqs[i];unsigned int
I will use
uint32_t.Quoted 1 line
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 47
Quoted 1 line
tools/libxl/libxl_arm.c +1
-0+int spi = irq -32 ;Same here.
Quoted 7 lines
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0+if (irq <32 ) +continue ; + +if (nr_spis <= spi) + nr_spis = spi +1 ;
Quoted 7 lines
Quoted 1 line
overflow check?
If I use unsigned int, the overflow will go back to 0. While it won't affect the code, the domain creation will fail later (unable to assign the SPI).
So is it useful to add a check here?
The maximum number of allowed spis has to be lower than UINT_MAX, right?
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Quoted 82 lines · Stefano Stabellini
Quoted 81 lines · Julien Grall
Hi Stefano,
Quoted 54 lines · Stefano Stabellini
Quoted 53 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
Signed-off-by Julien Grall <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Wei Liu <[email protected]>---
Changes in v3:
- Fix typoes
- A separate has been created to extend the DOMCTL create domainChanges in v2:
- Patch added--- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 38 insertions(+), 7 deletions(-)tools/libxc/xc_domain.c +1
-0@@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch,/* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version =XEN_DOMCTL_CONFIG_GIC_DEFAULT ; + config.nr_spis =0 ;#else errno =ENOSYS ;return -1 ;tools/libxl/libxl_arm.c +0
-0@@ -39,6 +39,25 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config)Quoted 8 lines
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 46
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0{ +uint32_t nr_spis =0 ; +unsigned int i; + +for (i =0 ; i < d_config->b_info.num_irqs; i++) { +int irq = d_config->b_info.irqs[i];unsigned int
I will use
uint32_t.Quoted 1 line
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 47
Quoted 1 line
tools/libxl/libxl_arm.c +1
-0+int spi = irq -32 ;Same here.
Quoted 8 lines
tools/libxl/libxl_arm.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 53
Quoted 6 lines
tools/libxl/libxl_arm.c +5
-0+if (irq <32 ) +continue ; + +if (nr_spis <= spi) + nr_spis = spi +1 ;overflow check?
Quoted 7 lines
Quoted 5 lines
If I use unsigned int, the overflow will go back to 0. While it won't affect the code, the domain creation will fail later (unable to assign the SPI).
So is it useful to add a check here?
The maximum number of allowed spis has to be lower than
UINT_MAX, right?
UINT_MAX + 1 would give 0. So it's still < UINT_MAX. When the toolstack will try to assign the IRQ. The hypervisor will see the SPI is too high for the vGIC. So it will reject.
Anyway, technically it's even 1024. I forgot to add this check in the vgic code. I will do it in the next version.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
In reply to Stefano StabelliniQuoted 3 lines · Stefano Stabellini
Quoted 1 line
+ int spi = irq - 32;
unsigned int
and underflow?
Ian.
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 1 line
+ int spi = irq - 32;
unsigned int
and underflow?
No because there is a check (irq < 32) before using the variable spi. It was more convenient to initialize it directly.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Quoted 11 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 1 line
+ int spi = irq - 32;
unsigned int
and underflow?
No because there is a check (irq < 32) before using the variable spi. It was more convenient to initialize it directly.
You'd have to be sure that "irq - 32" wasn't undefined behaviour then, or the compiler can decide to omit the rest of the function, or perhaps just that second check, because things are undefined from the initialiser onwards.
I think with unsigned you are probably ok.
Ian.
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Hi Ian,
Quoted 13 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 1 line
+ int spi = irq - 32;
unsigned int
and underflow?
No because there is a check (irq < 32) before using the variable spi. It was more convenient to initialize it directly.
Quoted 6 lines
You'd have to be sure that "irq - 32" wasn't undefined behaviour then, or the compiler can decide to omit the rest of the function, or perhaps just that second check, because things are undefined from the initialiser onwards.
I think with unsigned you are probably ok.
I will move the (irq - 32) after the check for safety.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
In reply to Julien GrallQuoted 4 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the
^than and "hardware" (although "physical" might be better)
Quoted 2 lines
toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
"will avoid wasting memory".
Quoted 2 lines
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
I don't see any xl changes here, and I think all that really matters is the semantics of the libxl_domain_build_info.irqs[] array, which currently I think can only express 1:1 mappings anyway.
So:
"To calculate the number of SPIs, we take advantage of the fact that the libxl interface can only expose a 1:1 mapping and look for the largest SPI in the list" or something.
Ian.
Re: [PATCH v3 11/24] xen/arm: Let the toolstack configure the number of SPIs
Hi Ian,
Quoted 15 lines · Ian Campbell
Quoted 4 lines · Julien Grall
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather re-using the number of IRQs used by the hardwared GIC, let the
^than and "hardware" (although "physical" might be better)
Quoted 2 lines
toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory.
"will avoid wasting memory".
Quoted 2 lines
To calculate the number of SPIs, we assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest.
Quoted 8 lines
I don't see any xl changes here, and I think all that really matters is the semantics of the libxl_domain_build_info.irqs[] array, which currently I think can only express 1:1 mappings anyway.
So:"To calculate the number of SPIs, we take advantage of the fact that the libxl interface can only expose a 1:1 mapping and look for the largest SPI in the list" or something.
I will use this.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 12/24 xen/arm: Release IRQ routed to a domain when it's destroying
In reply to Julien GrallXen has to release IRQ routed to a domain in order to reuse later. Currently only SPIs can be routed to the guest so we only need to browse SPIs for a specific domain.
Futhermore, a guest can crash and let the IRQ in an incorrect state (i.e has not being EOIed). Xen will have to reset the IRQ in order to be able to reuse the IRQ later.
Introduce 2 new functions for release an IRQ routed to a domain:
- release_guest_irq: upper level to retrieve the IRQ, call the GIC code and release the action
- gic_remove_guest_irq: Check if we can remove the IRQ, and reset it if necessary
---
Changes in v3:
- Take the vgic rank lock to protect p->desc
- Correctly check if the IRQ is disabled
- Extend the check on the virq in release_guest_irq
- Use vgic_get_target_vcpu to get the target vCPU
- Remove spurious change
Changes in v2:
- Drop the desc->handler = &no_irq_type in release_irq as it's buggy if the IRQ is routed to Xen
- Add release_guest_irq and gic_remove_guest_irq
--- xen/arch/arm/gic.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/irq.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic.c | 16 ++++++++++++++++ xen/include/asm-arm/gic.h | 4 ++++ xen/include/asm-arm/irq.h | 2 ++ 5 files changed, 116 insertions(+)
xen/arch/arm/gic.c +46 -0
@@ -162,6 +162,52 @@ out:return res; } +/* This function only works with SPIs for now */ +int gic_remove_irq_from_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc) +{ +struct vcpu *v_target =vgic_get_target_vcpu (d->vcpu[0 ], virq); +struct vgic_irq_rank *rank =vgic_rank_irq (v_target, virq); +struct pending_irq *p =irq_to_pending (v_target, virq); +unsigned long flags; + +ASSERT (spin_is_locked (&desc->lock)); +ASSERT (test_bit (_IRQ_GUEST, &desc->status)); +ASSERT (p->desc == desc); + +vgic_lock_rank (v_target, rank, flags); + +/* If the IRQ is removed when the domain is dying, we only need to +* EOI the IRQ if it has not been done by the guest +*/ +if ( d->is_dying ) + { + desc->handler->shutdown (desc); +if (test_bit (_IRQ_INPROGRESS, &desc->status) ) + gic_hw_ops->deactivate_irq (desc); +clear_bit (_IRQ_INPROGRESS, &desc->status); + goto end; + } + +/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled. +*/ +if (test_bit (_IRQ_INPROGRESS, &desc->status) || + !test_bit (_IRQ_DISABLED, &desc->status) ) +return -EBUSY ; + +end: +clear_bit (_IRQ_GUEST, &desc->status); + desc->handler = &no_irq_type; + + p->desc =NULL ; + +vgic_unlock_rank (v_target, rank, flags); + + +return 0 ; +} +int gic_irq_xlate (const u32 *intspec,unsigned int intsize,unsigned int *out_hwirq,unsigned int *out_type)
xen/arch/arm/irq.c +48 -0
54 lines not on this page · raw message
xen/arch/arm/vgic.c +16 -0
@@ -133,6 +133,22 @@ void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)void domain_vgic_free (struct domain *d) { +int i; +int ret; + +for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i]; + +if ( p->desc ) + { + ret =release_guest_irq (d, p->irq); +if ( ret ) +dprintk (XENLOG_G_WARNING ,"d%u: Failed to release virq %u ret = %d\n" , + d->domain_id, p->irq, ret); + } + } +xfree (d->arch.vgic.shared_irqs);xfree (d->arch.vgic.pending_irqs);xfree (d->arch.vgic.allocated_irqs);
xen/include/asm-arm/gic.h +4 -0
@@ -217,6 +217,10 @@ extern int gic_route_irq_to_guest(struct domain *, unsigned int virq,struct irq_desc *desc, unsigned int priority); +/* Remove an IRQ passthrough to a guest */ +int gic_remove_irq_from_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc); +extern void gic_inject (void );extern void gic_clear_pending_irqs (struct vcpu *v);extern int gic_events_need_delivery (void );
xen/include/asm-arm/irq.h +2 -0
@@ -44,6 +44,8 @@ void init_secondary_IRQ(void);int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char *devname); +int release_guest_irq (struct domain *d,unsigned int irq); +void arch_move_irqs (struct vcpu *v);/* Set IRQ type for an SPI */
Signature · 1 line
2.1.4
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
Quoted 8 lines · Julien Grall
Xen has to release IRQ routed to a domain in order to reuse later. Currently only SPIs can be routed to the guest so we only need to browse SPIs for a specific domain.
Futhermore, a guest can crash and let the IRQ in an incorrect state (i.e has not being EOIed). Xen will have to reset the IRQ in order to be able to reuse the IRQ later.
Quoted 7 lines
Introduce 2 new functions for release an IRQ routed to a domain:
-release_guest_irq: upper level to retrieve the IRQ, call the GIC code and release the action
-gic_remove_guest_irq: Check if we can remove the IRQ, and reset it if necessarySigned-off-by Julien Grall <[email protected]>
Quoted 194 lines
---
Changes in v3:
- Take the vgic rank lock to protectp->desc
- Correctly check if the IRQ is disabled
- Extend the check on the virq inrelease_guest_irq
- Usevgic_get_target_vcputo get the target vCPU
- Remove spurious changeChanges in v2:
- Drop thedesc->handler=&no_irq_typeinrelease_irqas it's buggy if the IRQ is routed to Xen
- Addrelease_guest_irqandgic_remove_guest_irq--- xen/arch/arm/gic.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/irq.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic.c | 16 ++++++++++++++++ xen/include/asm-arm/gic.h | 4 ++++ xen/include/asm-arm/irq.h | 2 ++ 5 files changed, 116 insertions(+)xen/arch/arm/gic.c +46
-0@@ -162,6 +162,52 @@ out:return res; } +/* This function only works with SPIs for now */ +int gic_remove_irq_from_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc) +{ +struct vcpu *v_target =vgic_get_target_vcpu (d->vcpu[0 ], virq); +struct vgic_irq_rank *rank =vgic_rank_irq (v_target, virq); +struct pending_irq *p =irq_to_pending (v_target, virq); +unsigned long flags; + +ASSERT (spin_is_locked (&desc->lock)); +ASSERT (test_bit (_IRQ_GUEST, &desc->status)); +ASSERT (p->desc == desc); + +vgic_lock_rank (v_target, rank, flags); + +/* If the IRQ is removed when the domain is dying, we only need to +* EOI the IRQ if it has not been done by the guest +*/ +if ( d->is_dying ) + { + desc->handler->shutdown (desc); +if (test_bit (_IRQ_INPROGRESS, &desc->status) ) + gic_hw_ops->deactivate_irq (desc); +clear_bit (_IRQ_INPROGRESS, &desc->status); + goto end; + } + +/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled. +*/ +if (test_bit (_IRQ_INPROGRESS, &desc->status) || + !test_bit (_IRQ_DISABLED, &desc->status) ) +return -EBUSY ; + +end: +clear_bit (_IRQ_GUEST, &desc->status); + desc->handler = &no_irq_type; + + p->desc =NULL ; + +vgic_unlock_rank (v_target, rank, flags); + + +return 0 ; +} +int gic_irq_xlate (const u32 *intspec,unsigned int intsize,unsigned int *out_hwirq,unsigned int *out_type)xen/arch/arm/irq.c +48
-0@@ -504,6 +504,54 @@ free_info:return retval; } +int release_guest_irq (struct domain *d,unsigned int virq) +{ +struct irq_desc *desc; +struct irq_guest *info; +unsigned long flags; +struct pending_irq *p; +int ret; + +/* Only SPIs are supported */ +if ( virq <32 || virq >=vgic_num_irqs (d) ) +return -EINVAL ; + + p =irq_to_pending (d->vcpu[0 ], virq); +if ( !p->desc ) +return -EINVAL ; + + desc = p->desc; + +spin_lock_irqsave (&desc->lock, flags); + + ret = -EINVAL ; +if ( !test_bit (_IRQ_GUEST, &desc->status) ) + goto unlock; + + ret = -EINVAL ; + + info =irq_get_guest_info (desc); +if ( d != info->d ) + goto unlock; + + ret =gic_remove_irq_from_guest (d, virq, desc); + +spin_unlock_irqrestore (&desc->lock, flags); + +if ( !ret ) + { +release_irq (desc->irq, info); +xfree (info); + } + +return ret; + +unlock: +spin_unlock_irqrestore (&desc->lock, flags); + +return ret; +} +/* * pirq event channels. We don't use these on ARM, instead we use the * features of the GIC to inject virtualised normal interrupts. xen/arch/arm/vgic.c +16
-0@@ -133,6 +133,22 @@ void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)void domain_vgic_free (struct domain *d) { +int i; +int ret; + +for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i]; + +if ( p->desc ) + { + ret =release_guest_irq (d, p->irq); +if ( ret ) +dprintk (XENLOG_G_WARNING ,"d%u: Failed to release virq %u ret = %d\n" , + d->domain_id, p->irq, ret); + } + } +xfree (d->arch.vgic.shared_irqs);xfree (d->arch.vgic.pending_irqs);xfree (d->arch.vgic.allocated_irqs);xen/include/asm-arm/gic.h +4
-0@@ -217,6 +217,10 @@ extern int gic_route_irq_to_guest(struct domain *, unsigned int virq,struct irq_desc *desc, unsigned int priority); +/* Remove an IRQ passthrough to a guest */ +int gic_remove_irq_from_guest (struct domain *d,unsigned int virq, +struct irq_desc *desc); +extern void gic_inject (void );extern void gic_clear_pending_irqs (struct vcpu *v);extern int gic_events_need_delivery (void );xen/include/asm-arm/irq.h +2
-0@@ -44,6 +44,8 @@ void init_secondary_IRQ(void);int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char *devname); +int release_guest_irq (struct domain *d,unsigned int irq); +void arch_move_irqs (struct vcpu *v);/* Set IRQ type for an SPI */ Signature · 1 line
2.1.4
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
In reply to Julien GrallQuoted 1 line · Julien Grall
Futhermore, a guest can crash and let the IRQ in an incorrect state (i.e has
"Furthermore" (I think your finger macros have this one wrong, you might want to grep the series ;-))
xen/arch/arm/gic.c out: · line 193
Quoted 2 lines
xen/arch/arm/gic.c +2
-0+/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled.
If we are ungracefully killing a guest doesn't this risk ending up with an undestroyable domain? i.e. if the guest is paused with an inflight IRQ and then destroyed, how does the inflight IRQ ever become not-inflight again? A similar argument could apply if the guest has e.g. crashed, paniced or is otherwise not processing any more interrupts or generating EOIs for existing ones.
We need to be able to kill a guest in such a state somehow.
(BTW, I notice the comment style is consistently wrong through the series)
xen/arch/arm/irq.c free_info: · line 521
Quoted 7 lines
xen/arch/arm/irq.c +7
-0+/* Only SPIs are supported */ +if ( virq <32 || virq >=vgic_num_irqs (d) ) +return -EINVAL ; + + p =irq_to_pending (d->vcpu[0 ], virq); +if ( !p->desc ) +return -EINVAL ;
Are we seeing this pattern a lot? It seems so, I wonder if a helper could be useful:
p = spi_to_pending(d, virq);
if ( !p->desc )
return -EINVAL;with the < 32 check etc in the helper where it only needs commenting on once.
xen/arch/arm/irq.c free_info: · line 531
Quoted 10 lines
xen/arch/arm/irq.c +10
-0+ + desc = p->desc; + +spin_lock_irqsave (&desc->lock, flags); + + ret = -EINVAL ; +if ( !test_bit (_IRQ_GUEST, &desc->status) ) + goto unlock; + + ret = -EINVAL ;
A bit redundant, or should nestle the info = like you did above with the test_bit.
xen/arch/arm/irq.c free_info: · line 541
Quoted 9 lines
xen/arch/arm/irq.c +9
-0+ info =irq_get_guest_info (desc); +if ( d != info->d ) + goto unlock; + + ret =gic_remove_irq_from_guest (d, virq, desc); + +spin_unlock_irqrestore (&desc->lock, flags); + +if ( !ret )
This is a bit unconventional (it looks essentially like you have three exit paths, with this extra special success case and two error cases).
It would better if the gic_remove_irq_from_guest failure case went to unlock like all the other failure cases, then the success path would be a straight line.
(yes, that would mean a goto unlock right before the first spin_unlock, but the code flow would be clearer).
Quoted 21 lines
xen/arch/arm/irq.c +13
-0+ { +release_irq (desc->irq, info); +xfree (info); + } + +return ret; + +unlock: +spin_unlock_irqrestore (&desc->lock, flags); + +return ret; +} +/* * pirq event channels. We don't use these on ARM, instead we use the * features of the GIC to inject virtualised normal interrupts. xen/arch/arm/vgic.c +0
-0
xen/arch/arm/vgic.c void register_vgic_ops(struct domain *d, const struct vgic_ops *ops) · line 141
Quoted 9 lines
xen/arch/arm/vgic.c +6
-0@@ -133,6 +133,22 @@ void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)void domain_vgic_free (struct domain *d) { +int i; +int ret; + +for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i];
Is there not a helper for this lookup? If so it should be used.
Ian.
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
Hi Ian,
Quoted 6 lines · Ian Campbell
Quoted 1 line · Julien Grall
Futhermore, a guest can crash and let the IRQ in an incorrect state (i.e has
"Furthermore" (I think your finger macros have this one wrong, you might want to grep the series ;-))
I do this mistake every-time. I will check this series (and upcoming series)
Quoted 10 lines
xen/arch/arm/gic.c out: · line 193
Quoted 3 lines
xen/arch/arm/gic.c +2
-0+/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled. If we are ungracefully killing a guest doesn't this risk ending up with an undestroyable domain? i.e. if the guest is paused with an inflight IRQ and then destroyed, how does the inflight IRQ ever become not-inflight again? A similar argument could apply if the guest has e.g. crashed, paniced or is otherwise not processing any more interrupts or generating EOIs for existing ones.
No, this will fall on the "is_dying" part. During domain destruction, the hypervisor will release all the IRQ still assigned to the guest one by one.
Quoted 1 line
We need to be able to kill a guest in such a state somehow.
The TODO is here for running domain where we try to deassign an inflight IRQ.
Quoted 2 lines
(BTW, I notice the comment style is consistently wrong through the series)
I will check all the patches.
Quoted 8 lines
xen/arch/arm/irq.c free_info: · line 521
Quoted 7 lines
xen/arch/arm/irq.c +7
-0+/* Only SPIs are supported */ +if ( virq <32 || virq >=vgic_num_irqs (d) ) +return -EINVAL ; + + p =irq_to_pending (d->vcpu[0 ], virq); +if ( !p->desc ) +return -EINVAL ;
Quoted 8 lines
Are we seeing this pattern a lot? It seems so, I wonder if a helper could be useful:
p = spi_to_pending(d, virq); if ( !p->desc ) return -EINVAL;with the < 32 check etc in the helper where it only needs commenting on once.
IIRC, there is only 2 places. I will replace it by an helper.
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/irq.c +5
-0+ + desc = p->desc; + +spin_lock_irqsave (&desc->lock, flags); +
Quoted 8 lines
xen/arch/arm/irq.c free_info: · line 531
Quoted 5 lines
xen/arch/arm/irq.c +5
-0+ ret = -EINVAL ; +if ( !test_bit (_IRQ_GUEST, &desc->status) ) + goto unlock; + + ret = -EINVAL ;A bit redundant, or should nestle the info = like you did above with the
test_bit.
I will invert it.
Quoted 13 lines
xen/arch/arm/irq.c free_info: · line 541
Quoted 9 lines
xen/arch/arm/irq.c +9
-0+ info =irq_get_guest_info (desc); +if ( d != info->d ) + goto unlock; + + ret =gic_remove_irq_from_guest (d, virq, desc); + +spin_unlock_irqrestore (&desc->lock, flags); + +if ( !ret )This is a bit unconventional (it looks essentially like you have three exit paths, with this extra special success case and two error cases).
Quoted 6 lines
It would better if the
gic_remove_irq_from_guestfailure case went to unlock like all the other failure cases, then the success path would be a straight line.(yes, that would mean a goto unlock right before the first
spin_unlock, but the code flow would be clearer).
I will do.
Quoted 23 lines
Quoted 23 lines
xen/arch/arm/irq.c +13
-0+ { +release_irq (desc->irq, info); +xfree (info); + } + +return ret; + +unlock: +spin_unlock_irqrestore (&desc->lock, flags); + +return ret; +} +/* * pirq event channels. We don't use these on ARM, instead we use the * features of the GIC to inject virtualised normal interrupts. xen/arch/arm/vgic.c +0
-0@@ -133,6 +133,22 @@ void register_vgic_ops(struct domain *d, const struct vgic_ops *ops)
Quoted 10 lines
xen/arch/arm/vgic.c void register_vgic_ops(struct domain *d, const struct vgic_ops *ops) · line 141
Quoted 8 lines
xen/arch/arm/vgic.c +6
-0void domain_vgic_free (struct domain *d) { +int i; +int ret; + +for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i];Is there not a helper for this lookup? If so it should be used.
The irq_pending code is adding extra-check. But I guess we don't care for domain destruction?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
Quoted 10 lines · Julien Grall
Quoted 9 lines
xen/arch/arm/gic.c out: · line 193
Quoted 2 lines
xen/arch/arm/gic.c +2
-0+/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled. If we are ungracefully killing a guest doesn't this risk ending up with an undestroyable domain? i.e. if the guest is paused with an inflight IRQ and then destroyed, how does the inflight IRQ ever become not-inflight again? A similar argument could apply if the guest has e.g. crashed, paniced or is otherwise not processing any more interrupts or generating EOIs for existing ones.
Quoted 8 lines
No, this will fall on the "
is_dying" part. During domain destruction, the hypervisor will release all the IRQ still assigned to the guest one by one.Quoted 1 line
We need to be able to kill a guest in such a state somehow.
The TODO is here for running domain where we try to deassign an inflight IRQ.
I see. I think either expand the comment to say "for a running domain" or, probably better, put this bit of code (and the comment) in an else of the is_dying and get rid of the goto in the is_dying==true case.
Quoted 8 lines
Quoted 5 lines
xen/arch/arm/vgic.c void register_vgic_ops(struct domain *d, const struct vgic_ops *ops) · line 141
Quoted 3 lines
xen/arch/arm/vgic.c +3
-0+for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i];Is there not a helper for this lookup? If so it should be used.
The
irq_pendingcode is adding extra-check. But I guess we don't care for domain destruction?
I don't think so.
Ian.
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
Hi Ian,
Quoted 16 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 9 lines
xen/arch/arm/gic.c out: · line 193
Quoted 2 lines
xen/arch/arm/gic.c +2
-0+/* TODO: Handle eviction from LRs. For now, deny remove if the IRQ +* is inflight and not disabled. If we are ungracefully killing a guest doesn't this risk ending up with an undestroyable domain? i.e. if the guest is paused with an inflight IRQ and then destroyed, how does the inflight IRQ ever become not-inflight again? A similar argument could apply if the guest has e.g. crashed, paniced or is otherwise not processing any more interrupts or generating EOIs for existing ones.
No, this will fall on the "
is_dying" part. During domain destruction, the hypervisor will release all the IRQ still assigned to the guest one by one.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
We need to be able to kill a guest in such a state somehow.
The TODO is here for running domain where we try to deassign an inflight IRQ.
I see. I think either expand the comment to say "for a running domain" or, probably better, put this bit of code (and the comment) in an else of the
is_dyingand get rid of the goto in the is_dying==true case.
I will do.
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
xen/arch/arm/vgic.c void register_vgic_ops(struct domain *d, const struct vgic_ops *ops) · line 141
Quoted 3 lines
xen/arch/arm/vgic.c +3
-0+for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) + { +struct pending_irq *p = &d->arch.vgic.pending_irqs[i];Is there not a helper for this lookup? If so it should be used.
The
irq_pendingcode is adding extra-check. But I guess we don't care for domain destruction?I don't think so.
Ok.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/24] xen/arm: Release IRQ routed to a domain when it's destroying
In reply to Julien GrallHi Ian,
Quoted 14 lines · Julien Grall
Quoted 14 lines
xen/arch/arm/irq.c free_info: · line 521
Quoted 7 lines
xen/arch/arm/irq.c +7
-0+/* Only SPIs are supported */ +if ( virq <32 || virq >=vgic_num_irqs (d) ) +return -EINVAL ; + + p =irq_to_pending (d->vcpu[0 ], virq); +if ( !p->desc ) +return -EINVAL ;Are we seeing this pattern a lot? It seems so, I wonder if a helper could be useful:
p = spi_to_pending(d, virq); if ( !p->desc ) return -EINVAL;
Quoted 4 lines
Quoted 2 lines
with the < 32 check etc in the helper where it only needs commenting on once.
IIRC, there is only 2 places. I will replace it by an helper.
Hmmmm.... I only found 1 place. So I will keep open-coding in the function.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 13/24 xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
In reply to Julien GrallThe physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type MAP_PIRQ_TYPE_GSI is used for this purpose.
---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Changes in v3:
- Functions to allocate/release/reserved a VIRQ has been moved in a separate patch
- Make clear that only MAP_PIRQ_GSI is only supported for now
Changes in v2:
- Add PHYSDEVOP_unmap_pirq
- Rework commit message
- Add functions to allocate/release a VIRQ
- is_routable_irq has been renamed into is_assignable_irq
--- xen/arch/arm/physdev.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-)
xen/arch/arm/physdev.c +134 -2
@@ -8,13 +8,145 @@#include <xen/types.h> #include <xen/lib.h> #include <xen/errno.h> +#include <xen/iocap.h> +#include <xen/guest_access.h> +#include <xsm/xsm.h> +#include <asm/current.h> #include <asm/hypercall.h> +#include <public/physdev.h> +static int physdev_map_pirq (domid_t domid,int type,int index,int *pirq_p) +{ +struct domain *d; +int ret; +int irq = index; +int virq; + + d =rcu_lock_domain_by_any_id (domid); +if ( d ==NULL ) +return -ESRCH ; + + ret =xsm_map_domain_pirq (XSM_TARGET , d); +if ( ret ) + goto free_domain; + +/* For now we only suport GSI */ +if ( type !=MAP_PIRQ_TYPE_GSI ) + { + ret = -EINVAL ; +dprintk (XENLOG_G_ERR , +"dom%u: wrong map_pirq type 0x%x, only MAP_PIRQ_TYPE_GSI is supported.\n" , + d->domain_id, type); + goto free_domain; + } + +if ( !is_assignable_irq (irq) ) + { + ret = -EINVAL ; +dprintk (XENLOG_G_ERR ,"IRQ%u is not routable to a guest\n" , irq); + goto free_domain; + } + + ret = -EPERM ; +if ( !irq_access_permitted (current->domain, irq) ) + goto free_domain; + +if ( *pirq_p <0 ) + { +BUG_ON (irq <16 );/* is_assignable_irq already denies SGIs */ + virq =vgic_allocate_virq (d, (irq >=32 )); + + ret = -ENOSPC ; +if ( virq <0 ) + goto free_domain; + } +else + { + ret = -EBUSY ; + virq = *pirq_p; + +if ( !vgic_reserve_virq (d, virq) ) + goto free_domain; + } + +gdprintk (XENLOG_DEBUG ,"irq = %u virq = %u\n" , irq, virq); + + ret =route_irq_to_guest (d, virq, irq,"routed IRQ" ); + +if ( !ret ) + *pirq_p = virq; +else +vgic_free_virq (d, virq); + +free_domain: +rcu_unlock_domain (d); + +return ret; +} + +int physdev_unmap_pirq (domid_t domid,int pirq) +{ +struct domain *d; +int ret; + + d =rcu_lock_domain_by_any_id (domid); +if ( d ==NULL ) +return -ESRCH ; + + ret =xsm_unmap_domain_pirq (XSM_TARGET , d); +if ( ret ) + goto free_domain; + + ret =release_guest_irq (d, pirq); +if ( ret ) + goto free_domain; + +vgic_free_virq (d, pirq); + +free_domain: +rcu_unlock_domain (d); + +return ret; +}int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); -return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: + { +physdev_map_pirq_t map; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + ret =physdev_map_pirq (map.domid, map.type, map.index, &map.pirq); + +if (__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; + } +break ; + +case PHYSDEVOP_unmap_pirq: + { +physdev_unmap_pirq_t unmap; + + ret = -EFAULT ; +if (copy_from_guest (&unmap, arg,1 ) !=0 ) +break ; + + ret =physdev_unmap_pirq (unmap.domid, unmap.pirq); + } + +default : + ret = -ENOSYS ; +break ; + } + +return ret; }/*
Signature · 1 line
2.1.4
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?
I'm not sure either - much depends on the possible confusion this may cause to the callers (i.e. if they live in common code, they may expect the hypercall to do a certain thing, whereas if the callers are all [expected to be] in arch code, then I'd consider such overloading okay).
Jan
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 19 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?
Quoted 5 lines
I'm not sure either - much depends on the possible confusion this may cause to the callers (i.e. if they live in common code, they may expect the hypercall to do a certain thing, whereas if the callers are all [expected to be] in arch code, then I'd consider such overloading okay).
PHYSDEVOP_{,un}map_pirq hypercalls are used in common code such as libxl (tools/libxl/libxc_create.c and pci code). There is a similar problem with XEN_DOMCTL_irq_permission.
AFAIK, Linux is also using PHYSDEVOP_{,un}map_pirq to map an interrupt into itself.
It may have confusion, if we decide to implement PIRQ in ARM. I believe it will never happen because the interrupt can be delivered via a virtual interface.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
In reply to Julien GrallQuoted 9 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?
I think it is OK, as long as we write down very clearly what we are doing.
Quoted 2 lines
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Why do you say that? From the code in this patch it looks like it supports vIRQ != IRQ already.
Quoted 3 lines
Changes in v3:
- Functions to allocate/release/reserved a VIRQ has been moved in a separate patch
That might be a good idea, but then you need to move that patch before this one, otherwise it won't compile. As is it would break the build.
Quoted 169 lines
- Make clear that only
MAP_PIRQ_GSIis only supported for nowChanges in v2:
- AddPHYSDEVOP_unmap_pirq
- Rework commit message
- Add functions to allocate/release a VIRQ
-is_routable_irqhas been renamed intois_assignable_irq--- xen/arch/arm/physdev.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-)xen/arch/arm/physdev.c +134
-2@@ -8,13 +8,145 @@#include <xen/types.h> #include <xen/lib.h> #include <xen/errno.h> +#include <xen/iocap.h> +#include <xen/guest_access.h> +#include <xsm/xsm.h> +#include <asm/current.h> #include <asm/hypercall.h> +#include <public/physdev.h> +static int physdev_map_pirq (domid_t domid,int type,int index,int *pirq_p) +{ +struct domain *d; +int ret; +int irq = index; +int virq; + + d =rcu_lock_domain_by_any_id (domid); +if ( d ==NULL ) +return -ESRCH ; + + ret =xsm_map_domain_pirq (XSM_TARGET , d); +if ( ret ) + goto free_domain; + +/* For now we only suport GSI */ +if ( type !=MAP_PIRQ_TYPE_GSI ) + { + ret = -EINVAL ; +dprintk (XENLOG_G_ERR , +"dom%u: wrong map_pirq type 0x%x, only MAP_PIRQ_TYPE_GSI is supported.\n" , + d->domain_id, type); + goto free_domain; + } + +if ( !is_assignable_irq (irq) ) + { + ret = -EINVAL ; +dprintk (XENLOG_G_ERR ,"IRQ%u is not routable to a guest\n" , irq); + goto free_domain; + } + + ret = -EPERM ; +if ( !irq_access_permitted (current->domain, irq) ) + goto free_domain; + +if ( *pirq_p <0 ) + { +BUG_ON (irq <16 );/* is_assignable_irq already denies SGIs */ + virq =vgic_allocate_virq (d, (irq >=32 )); + + ret = -ENOSPC ; +if ( virq <0 ) + goto free_domain; + } +else + { + ret = -EBUSY ; + virq = *pirq_p; + +if ( !vgic_reserve_virq (d, virq) ) + goto free_domain; + } + +gdprintk (XENLOG_DEBUG ,"irq = %u virq = %u\n" , irq, virq); + + ret =route_irq_to_guest (d, virq, irq,"routed IRQ" ); + +if ( !ret ) + *pirq_p = virq; +else +vgic_free_virq (d, virq); + +free_domain: +rcu_unlock_domain (d); + +return ret; +} + +int physdev_unmap_pirq (domid_t domid,int pirq) +{ +struct domain *d; +int ret; + + d =rcu_lock_domain_by_any_id (domid); +if ( d ==NULL ) +return -ESRCH ; + + ret =xsm_unmap_domain_pirq (XSM_TARGET , d); +if ( ret ) + goto free_domain; + + ret =release_guest_irq (d, pirq); +if ( ret ) + goto free_domain; + +vgic_free_virq (d, pirq); + +free_domain: +rcu_unlock_domain (d); + +return ret; +}int do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { -printk ("%s %d cmd=%d: not implemented yet\n" , __func__, __LINE__, cmd); -return -ENOSYS ; +int ret; + +switch ( cmd ) + { +case PHYSDEVOP_map_pirq: + { +physdev_map_pirq_t map; + + ret = -EFAULT ; +if (copy_from_guest (&map, arg,1 ) !=0 ) +break ; + + ret =physdev_map_pirq (map.domid, map.type, map.index, &map.pirq); + +if (__copy_to_guest (arg, &map,1 ) ) + ret = -EFAULT ; + } +break ; + +case PHYSDEVOP_unmap_pirq: + { +physdev_unmap_pirq_t unmap; + + ret = -EFAULT ; +if (copy_from_guest (&unmap, arg,1 ) !=0 ) +break ; + + ret =physdev_unmap_pirq (unmap.domid, unmap.pirq); + } + +default : + ret = -ENOSYS ; +break ; + } + +return ret;}
/*
Signature · 1 line
2.1.4
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Hi Stefano,
Quoted 23 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Quoted 5 lines
Quoted 2 lines
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Why do you say that? From the code in this patch it looks like it supports vIRQ != IRQ already.
Because PHYSDEV_map_pirq is taking a vIRQ number in parameter. This vIRQ is only valid for the domain which issue the hypercall.
In our use case, it's DOM0. DOM0 may not have all the time vIRQ == IRQ.
Futhermore, on PHYSDEV_unmap_pirq I assume the DOM0 virq == guest virq.
Quoted 7 lines
Quoted 4 lines
Changes in v3:
- Functions to allocate/release/reserved a VIRQ has been moved in a separate patchThat might be a good idea, but then you need to move that patch before this one, otherwise it won't compile. As is it would break the build.
This patch belongs to a separate patch series. FIY, on the cover letter I explicitly wrote the dependency in other to apply this series.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 26 lines · Julien Grall
Hi Stefano,
Quoted 23 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Why do you say that? From the code in this patch it looks like it supports vIRQ != IRQ already.
Because
PHYSDEV_map_pirqis taking a vIRQ number in parameter. This vIRQ is only valid for the domain which issue the hypercall.
That's not very useful. I think that the vIRQ passed to PHYSDEV_map_pirq should be a vIRQ in the destination domain, not the source domain.
In fact on x86 the pirq parameter to PHYSDEV_map_pirq is interpreted as pirq in the destination domain too.
Quoted 3 lines
In our use case, it's DOM0. DOM0 may not have all the time vIRQ == IRQ.
Futhermore, on
PHYSDEV_unmap_pirqI assume the DOM0 virq == guest virq.
That's bad.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Changes in v3:
- Functions to allocate/release/reserved a VIRQ has been moved in a separate patchThat might be a good idea, but then you need to move that patch before this one, otherwise it won't compile. As is it would break the build.
This patch belongs to a separate patch series. FIY, on the cover letter I explicitly wrote the dependency in other to apply this series.
OK
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 33 lines · Stefano Stabellini
Quoted 32 lines · Julien Grall
Hi Stefano,
Quoted 28 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Quoted 2 lines
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Why do you say that? From the code in this patch it looks like it supports vIRQ != IRQ already.
Quoted 8 lines
Quoted 2 lines
Because
PHYSDEV_map_pirqis taking a vIRQ number in parameter. This vIRQ is only valid for the domain which issue the hypercall.That's not very useful. I think that the vIRQ passed to
PHYSDEV_map_pirqshould be a vIRQ in the destination domain, not the source domain.In fact on x86 the pirq parameter to
PHYSDEV_map_pirqis interpreted as pirq in the destination domain too.
I'm talking about the index parameter. It's a vIRQ in the domain issue the hypercall not the real IRQ.
Quoted 5 lines
Quoted 3 lines
In our use case, it's DOM0. DOM0 may not have all the time vIRQ == IRQ.
Futhermore, on
PHYSDEV_unmap_pirqI assume the DOM0 virq == guest virq.That's bad.
I plan to support it for the next series. This change shouldn't impact the other patches of the series, so I decided to send a new version to gather some comments.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 37 lines · Julien Grall
Quoted 36 lines · Stefano Stabellini
Quoted 34 lines · Julien Grall
Hi Stefano,
Quoted 23 lines · Stefano Stabellini
Quoted 9 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Quoted 5 lines
Quoted 2 lines
TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version.
Why do you say that? From the code in this patch it looks like it supports vIRQ != IRQ already.
Because
PHYSDEV_map_pirqis taking a vIRQ number in parameter. This vIRQ is only valid for the domain which issue the hypercall.
Quoted 8 lines
Quoted 5 lines
That's not very useful. I think that the vIRQ passed to
PHYSDEV_map_pirqshould be a vIRQ in the destination domain, not the source domain.In fact on x86 the pirq parameter to
PHYSDEV_map_pirqis interpreted as pirq in the destination domain too.I'm talking about the index parameter. It's a vIRQ in the domain issue the hypercall not the real IRQ.
I see. OK.
Quoted 15 lines
Quoted 5 lines
Quoted 3 lines
In our use case, it's DOM0. DOM0 may not have all the time vIRQ == IRQ.
Futhermore, on
PHYSDEV_unmap_pirqI assume the DOM0 virq == guest virq.That's bad.
I plan to support it for the next series. This change shouldn't impact the other patches of the series, so I decided to send a new version to gather some comments.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
Hi Stefano,
Quoted 13 lines · Stefano Stabellini
Quoted 12 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Would adding MAP_PIRQ_TYPE_PPI (even as an alias for TYPE_GSI) be helpful?
I have a feeling not, since type is, I think, declaring the "namespace" of the index parameter, whereas the pirq is the one containing the vGIC provided virq (or the pirq-type evtchn on x86). Does that make sense?
Are we absolutely 100% sure that we will never ever want to map hardware IRQs to guests on ARMs using pirq-type event channels? Because that is what we are essentially ruling out here.
x86 is, I think, in the process of gaining vapic support and things like direct irq injection -- essentially the same as what we are doing here. In that case they clearly won't be able to use the same interfaces.
The main issue is that physdevop is a stable ABI interface, once we use it one way we are stuck with it. Is there actually any need for this "map a physical irq to a hardware virtualised guest irq" to be a stable API (i.e. used from the dom0 kernel)? If not then I'm inclined to suggest that we can skirt all of these concerns by just adding a new domctl and be done with it. Internally it would perhaps share a lot of code with the map_pirq call, but externally it would give us more flexibility...
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Jan
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Actually, I think bind_pt_irq with a new PT_IRQ_TYPE_* would be a good option.
An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
Ian.
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Hi Ian,
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Quoted 5 lines
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
We have to think about MSI and other type too...
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 16 lines · Julien Grall
Hi Ian,
Quoted 13 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.
Quoted 7 lines
Quoted 2 lines
An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
We have to think about MSI and other type too...
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
I don't follow, setting up device passthrough is very much a toolstack operation, isn't it? Where does the guest kernel get involved?
As for ACPI, I think dom0 propagating ACPI derived platform info to Xen should be handled differently (at the hypercall interface at least) separate from passthrough.
Ian.
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Julien Grall
Hi Ian,
Quoted 15 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
Quoted 7 lines
Quoted 4 lines
We have to think about MSI and other type too...
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
I don't follow, setting up device passthrough is very much a toolstack operation, isn't it? Where does the guest kernel get involved?
Sorry I meant the DOM0 kernel.
Not really. On platform device pass-through there is no way to know the IRQ, so for now the routing is done by the toolstack.
But we could decide to implement a driver in DOM0 which will unbind/bind/reset device. In this case it will require to assign/deassign the IRQ from DOM0.
There is also the case of MSI.
Quoted 3 lines
As for ACPI, I think dom0 propagating ACPI derived platform info to Xen should be handled differently (at the hypercall interface at least) separate from passthrough.
There is no difference between routing because of ACPI and/or because pass-through. So this should be done the same way.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 29 lines · Julien Grall
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Julien Grall
Hi Ian,
Quoted 15 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
Quoted 7 lines
Quoted 4 lines
We have to think about MSI and other type too...
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
I don't follow, setting up device passthrough is very much a toolstack operation, isn't it? Where does the guest kernel get involved?
Quoted 7 lines
Sorry I meant the DOM0 kernel.
Not really. On platform device pass-through there is no way to know the IRQ, so for now the routing is done by the toolstack.
But we could decide to implement a driver in DOM0 which will unbind/bind/reset device.
Sure, but...
Quoted 2 lines
In this case it will require to
assign/deassign the IRQ from DOM0.
...why does that follow?
Quoted 1 line
There is also the case of MSI.
Handled via XEN_DOMCTL_bind_pt_irq for the toolstack configuration angle, the actual guest usage of them is a separate interface which doesn't yet concern us, at least not in this series.
Quoted 6 lines
Quoted 3 lines
As for ACPI, I think dom0 propagating ACPI derived platform info to Xen should be handled differently (at the hypercall interface at least) separate from passthrough.
There is no difference between routing because of ACPI and/or because pass-through. So this should be done the same way.
I'm not convinced. Routing all the IRQs is only one aspect of dom0 propagating ACPI derived platform info to Xen.
I suppose we will see once I look at the ACPI series. In the meantime I think XEN_DOMCTL_bind_pt_irq matches your requirements in for this series (and is a domctl so we aren't tied to it once we have a better understanding of the other stuff).
Ian.
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Hi Ian,
Quoted 38 lines · Ian Campbell
Quoted 29 lines · Julien Grall
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Julien Grall
Hi Ian,
Quoted 15 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
Quoted 7 lines
Quoted 4 lines
We have to think about MSI and other type too...
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
I don't follow, setting up device passthrough is very much a toolstack operation, isn't it? Where does the guest kernel get involved?
Quoted 7 lines
Sorry I meant the DOM0 kernel.
Not really. On platform device pass-through there is no way to know the IRQ, so for now the routing is done by the toolstack.
But we could decide to implement a driver in DOM0 which will unbind/bind/reset device.
Quoted 6 lines
Sure, but...
Quoted 2 lines
In this case it will require to
assign/deassign the IRQ from DOM0....why does that follow?
Because we may decide to re-use the device to DOM0.
In the case of the DOMCTL, it's not possible to do it.
Quoted 5 lines
Quoted 1 line
There is also the case of MSI.
Handled via
XEN_DOMCTL_bind_pt_irqfor the toolstack configuration angle, the actual guest usage of them is a separate interface which doesn't yet concern us, at least not in this series.
That would require some rework in the toolstack to make the IRQ routing (xc_physdev...) per architecture.
Also what about IRQ permission? Should we just ignore it and not give permission to the guest domain?
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
As for ACPI, I think dom0 propagating ACPI derived platform info to Xen should be handled differently (at the hypercall interface at least) separate from passthrough.
There is no difference between routing because of ACPI and/or because pass-through. So this should be done the same way.
Quoted 7 lines
I'm not convinced. Routing all the IRQs is only one aspect of dom0 propagating ACPI derived platform info to Xen.
I suppose we will see once I look at the ACPI series. In the meantime I think
XEN_DOMCTL_bind_pt_irqmatches your requirements in for this series (and is a domctl so we aren't tied to it once we have a better understanding of the other stuff).
ACPI is one part of the problem, MSI with PCI is another problem.
Anyway, I suspect we will have the same talk before 4.6 release so we just defer the problem.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
In reply to Julien GrallQuoted 14 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 16:53, <[email protected]> wrote:
Hi Ian,
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 17:53, <[email protected]> wrote:
Jan, do you have any feeling for how this is going to play out on x86 with the vapic stuff?
The vapic logic shouldn't require any physdevop involvement, so if I read right what you propose (not having such a requirement / connection on ARM) either, I agree that a new domctl should be all that's needed (if XEN_DOMCTL_{,un}bind_pt_irq can't be re-used).
Quoted 7 lines
Quoted 5 lines
Actually, I think
bind_pt_irqwith a new PT_IRQ_TYPE_* would be a good option.An ARM SPI is a bit like an ISA IRQ, but not close enough to reuse IMHO (and the datatype would need widening).
We have to think about MSI and other type too...
Which that domctl already provides for.
Quoted 2 lines
In any case a DOMCTL is not suitable here because a guest kernel may need to map/unmap IRQ too (think about ACPI or device passthrough).
But not the physical IRQ I suppose. The virtual counterpart is what should be used there, and that's what said domctl extablishes.
Jan
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
In reply to Ian CampbellHi Ian,
Quoted 32 lines · Ian Campbell
Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
Hi Stefano,
Quoted 13 lines · Stefano Stabellini
Quoted 12 lines · Julien Grall
The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ.
For now, we allow only SPIs to be mapped to the guest. The type
MAP_PIRQ_TYPE_GSIis used for this purpose.Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
---
I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs?I think it is OK, as long as we write down very clearly what we are doing.
Would adding
MAP_PIRQ_TYPE_PPI(even as an alias forTYPE_GSI) be helpful?
Quoted 7 lines
I have a feeling not, since type is, I think, declaring the "namespace" of the index parameter, whereas the pirq is the one containing the vGIC provided virq (or the pirq-type evtchn on x86). Does that make sense?
Are we absolutely 100% sure that we will never ever want to map hardware IRQs to guests on ARMs using pirq-type event channels? Because that is what we are essentially ruling out here.
That would happen if we decide to implement an interrupt controller which doesn't support virtualization.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 8 lines · Julien Grall
Quoted 3 lines · Ian Campbell
Are we absolutely 100% sure that we will never ever want to map hardware IRQs to guests on ARMs using pirq-type event channels? Because that is what we are essentially ruling out here.
That would happen if we decide to implement an interrupt controller which doesn't support virtualization.
Good point. It's pretty unlikely but not absolutely impossible. So we should avoid reusing the pirq evtchn type for this. Jan suggested XENDOMCTL_bind_pt_irq which is looking better and better...
Ian.
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Hi,
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 3 lines · Ian Campbell
Are we absolutely 100% sure that we will never ever want to map hardware IRQs to guests on ARMs using pirq-type event channels? Because that is what we are essentially ruling out here.
Quoted 6 lines
Quoted 2 lines
That would happen if we decide to implement an interrupt controller which doesn't support virtualization.
Good point. It's pretty unlikely but not absolutely impossible. So we should avoid reusing the pirq evtchn type for this. Jan suggested
XENDOMCTL_bind_pt_irqwhich is looking better and better...
I looked to the interface of XENDOMCTL_bind_pt_irq and I'm not sure about the meaning of machine_irq and isa_irq.
AFAIU the code:
machine_irq => guest PIRQ
isa_irq => host IRQ
am I right?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.03.15 at 15:37, <[email protected]> wrote:
I looked to the interface of
XENDOMCTL_bind_pt_irqand I'm not sure about the meaning ofmachine_irqandisa_irq.AFAIU the code:
machine_irq=> guest PIRQ
Yes (i.e. the Xen assigned representation of an IRQ the guest has been granted access to).
Quoted 1 line
isa_irq=> host IRQ
But only for ISA ones, not PCI (i.e. you likely don't care about this at all).
Note that the PCI case here still lacks a segment number - if you in the end decided you want/need non-zero segments on ARM, then this will need extension (which it would need anyway if anyone was serious about to running Xen on such [x86] hardware).
Jan
Re: [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.03.15 at 15:37, <[email protected]> wrote:
I looked to the interface of
XENDOMCTL_bind_pt_irqand I'm not sure about the meaning ofmachine_irqandisa_irq.AFAIU the code:
machine_irq=> guest PIRQYes (i.e. the Xen assigned representation of an IRQ the guest has been granted access to).
Thank you for the confirmation.
Quoted 9 lines
Quoted 1 line
isa_irq=> host IRQBut only for ISA ones, not PCI (i.e. you likely don't care about this at all).
Note that the PCI case here still lacks a segment number - if you in the end decided you want/need non-zero segments on ARM, then this will need extension (which it would need anyway if anyone was serious about to running Xen on such [x86] hardware).
I don't care about PCI right now. I'm looking for mapping SPI (kind of ISA) to the guest.
I'm planning to introduce a new type of this purpose.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 14/24 xen/dts: Use unsigned int for MMIO and IRQ index
In reply to Julien GrallThere is no reason to use signed integer for an index.
---
Changes in v3:
- Slightly update commit message to drop the reference to new hypercalls.
- Add Stefano's acked
Changes in v2:
- Use unsigned int instead fancy one like unsigned or uint32_t
--- xen/common/device_tree.c | 11 ++++++----- xen/include/xen/device_tree.h | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-)
xen/common/device_tree.c +6 -5
@@ -496,7 +496,7 @@ static const struct dt_bus *dt_match_bus(const struct dt_device_node *np) }static const __be32 *dt_get_address (const struct dt_device_node *dev, -int index,u64 *size, +unsigned int index,u64 *size,unsigned int *flags) {const __be32 *prop;
@@ -683,7 +683,7 @@ bail: }/* dt_device_address - Translate device tree address and return it */ -int dt_device_get_address (const struct dt_device_node *dev,int index, +int dt_device_get_address (const struct dt_device_node *dev,unsigned int index,u64 *addr,u64 *size) {const __be32 *addrp;
@@ -1006,7 +1006,8 @@ fail:return -EINVAL ; } -int dt_device_get_raw_irq (const struct dt_device_node *device,int index, +int dt_device_get_raw_irq (const struct dt_device_node *device, +unsigned int index,struct dt_raw_irq *out_irq) {const struct dt_device_node *p;
@@ -1014,7 +1015,7 @@ int dt_device_get_raw_irq(const struct dt_device_node *device, int index,u32 intsize, intlen;int res = -EINVAL ; -dt_dprintk ("dt_device_get_raw_irq: dev=%s, index=%d\n" , +dt_dprintk ("dt_device_get_raw_irq: dev=%s, index=%u\n" , device->full_name, index);/* Get the interrupts property */
@@ -1071,7 +1072,7 @@ int dt_irq_translate(const struct dt_raw_irq *raw, &out_irq->irq, &out_irq->type); } -int dt_device_get_irq (const struct dt_device_node *device,int index, +int dt_device_get_irq (const struct dt_device_node *device,unsigned int index,struct dt_irq *out_irq) {struct dt_raw_irq raw;
xen/include/xen/device_tree.h +4 -3
@@ -474,7 +474,7 @@ const struct dt_device_node *dt_get_parent(const struct dt_device_node *node);* This function resolves an address, walking the tree, for a give * device-tree node. It returns 0 on success. */ -int dt_device_get_address (const struct dt_device_node *dev,int index, +int dt_device_get_address (const struct dt_device_node *dev,unsigned int index,u64 *addr,u64 *size);/**
@@ -504,7 +504,7 @@ unsigned int dt_number_of_address(const struct dt_device_node *device);* This function resolves an interrupt, walking the tree, for a given * device-tree node. It's the high level pendant to dt_device_get_raw_irq(). */ -int dt_device_get_irq (const struct dt_device_node *device,int index, +int dt_device_get_irq (const struct dt_device_node *device,unsigned int index,struct dt_irq *irq);/**
@@ -516,7 +516,8 @@ int dt_device_get_irq(const struct dt_device_node *device, int index,* This function resolves an interrupt for a device, no translation is * made. dt_irq_translate can be called after. */ -int dt_device_get_raw_irq (const struct dt_device_node *device,int index, +int dt_device_get_raw_irq (const struct dt_device_node *device, +unsigned int index,struct dt_raw_irq *irq);/**
Signature · 1 line
2.1.4
Re: [PATCH v3 14/24] xen/dts: Use unsigned int for MMIO and IRQ index
Quoted 1 line · Julien Grall
There is no reason to use signed integer for an index.
Did you check for now pointless "if ( uthing < 0 ) which a picky compiler might whinge about?
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>
Re: [PATCH v3 14/24] xen/dts: Use unsigned int for MMIO and IRQ index
Hi Ian,
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
There is no reason to use signed integer for an index.
Did you check for now pointless "if ( uthing < 0 ) which a picky compiler might whinge about?
I just checked and we don't have a such test in those function.
BTW, I think clang is picky on pointless if ( ufoo < 0 ) but we don't support it on ARM right now.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>
Thanks,
Signature · 1 line
Julien Grall
PATCH v3 15/24 xen/dts: Provide an helper to get a DT node from a path provided by a guest
In reply to Julien Grall---
Changes in v3:
- Use the new prototype of safe_copy_string_from_guest
Changes in v2:
- guest_copy_string_from_guest has been renamed into safe_copy_string_from_guest
--- xen/common/device_tree.c | 19 +++++++++++++++++++ xen/include/xen/device_tree.h | 17 +++++++++++++++++ 2 files changed, 36 insertions(+)
xen/common/device_tree.c +19 -0
@@ -13,6 +13,7 @@#include <xen/config.h> #include <xen/types.h> #include <xen/init.h> +#include <xen/guest_access.h> #include <xen/device_tree.h> #include <xen/kernel.h> #include <xen/lib.h>
@@ -23,6 +24,7 @@#include <xen/cpumask.h> #include <xen/ctype.h> #include <asm/setup.h> +#include <xen/err.h> const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;
@@ -277,6 +279,23 @@ struct dt_device_node *dt_find_node_by_path(const char *path)return np; } +int dt_find_node_by_gpath (XEN_GUEST_HANDLE (char ) u_path,uint32_t u_plen, +struct dt_device_node **node) +{ +char *path; + + path =safe_copy_string_from_guest (u_path, u_plen, +DEVICE_TREE_MAX_PATHLEN ); +if (IS_ERR (path) ) +return PTR_ERR (path); + + *node =dt_find_node_by_path (path); + +xfree (path); + +return (*node ==NULL ) ? -ESRCH :0 ; +} +struct dt_device_node *dt_find_node_by_alias (const char *alias) {const struct dt_alias_prop *app;
xen/include/xen/device_tree.h +17 -0
@@ -22,6 +22,9 @@#define DEVICE_TREE_MAX_DEPTH 16 +/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024 +/* * Struct used for matching a device */
@@ -456,6 +459,20 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias);*/ struct dt_device_node *dt_find_node_by_path (const char *path); + +/** +* dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the +* path from the guest +* +* @u_path: Xen Guest handle to the buffer containing the path +* @u_plen: Length of the buffer +* @node: TODO +* +* Return 0 if succeed otherwise -errno +*/ +int dt_find_node_by_gpath (XEN_GUEST_HANDLE (char ) u_path,uint32_t u_plen, +struct dt_device_node **node); +/** * dt_get_parent - Get a node's parent if any * @node: Node to get parent
Signature · 1 line
2.1.4
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
Is this function still needed in the new model which doesn't do automatic mappings etc?
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>Is this function still needed in the new model which doesn't do automatic mappings etc?
It's used is the pass-through DOMCTL code.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 8 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>Is this function still needed in the new model which doesn't do automatic mappings etc?
It's used is the pass-through DOMCTL code.
Yeah, I realised that later, sorry.
Ian.
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
In reply to Julien Grallxen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024
Is this something you've made up or derived from the DT spec/ePAPR etc?
Apart from this the patch seems fine, clarifying the genesis of that number in the commit log would be sufficient for me.
Ian.
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024Is this something you've made up or derived from the DT spec/ePAPR etc?
I didn't find a such requirements on the spec.
I chose this number based on the linux pathlen because the path is also used in the sysfs (/sys/firmware/devicetree).
Quoted 2 lines
Apart from this the patch seems fine, clarifying the genesis of that number in the commit log would be sufficient for me.
I will update the commit message.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 11 lines · Julien Grall
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024Is this something you've made up or derived from the DT spec/ePAPR etc?
I didn't find a such requirements on the spec.
I vaguely recall a limit on the length of a single node name, and a limit on the depth which they may nest, which can be multiplied. It's probably an unhelpfully large number though, so...
Quoted 2 lines
I chose this number based on the linux pathlen because the path is also used in the sysfs (
/sys/firmware/devicetree).
...that's a good as anything I suppose!
Quoted 4 lines
Quoted 2 lines
Apart from this the patch seems fine, clarifying the genesis of that number in the commit log would be sufficient for me.
I will update the commit message.
Ian.
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 13 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024Is this something you've made up or derived from the DT spec/ePAPR etc?
I didn't find a such requirements on the spec.
Quoted 8 lines
I vaguely recall a limit on the length of a single node name, and a limit on the depth which they may nest, which can be multiplied. It's probably an unhelpfully large number though, so...
Quoted 2 lines
I chose this number based on the linux pathlen because the path is also used in the sysfs (
/sys/firmware/devicetree)....that's a good as anything I suppose!
Hmmm... I'm not so sure about the 1024 limit anymore. Linux is defining PATH_MAX to 4096 but I don't see many usage in the sysfs code.
And this value may change from one OS to another. Although, 1024 sounds a very long path to write in the configuration file... Maybe we should support alias too?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 21 lines · Julien Grall
Quoted 20 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024Is this something you've made up or derived from the DT spec/ePAPR etc?
I didn't find a such requirements on the spec.
I vaguely recall a limit on the length of a single node name, and a limit on the depth which they may nest, which can be multiplied. It's probably an unhelpfully large number though, so...
Quoted 2 lines
I chose this number based on the linux pathlen because the path is also used in the sysfs (
/sys/firmware/devicetree).
Quoted 7 lines
Quoted 1 line
...that's a good as anything I suppose!
Hmmm... I'm not so sure about the 1024 limit anymore. Linux is defining
PATH_MAXto 4096 but I don't see many usage in the sysfs code.And this value may change from one OS to another. Although, 1024 sounds a very long path to write in the configuration file...
I imagine in practice it will be cut-and-pasted, but yes.
Quoted 2 lines
Maybe we should
support alias too?
Perhaps 2048 + (optionally, perhaps later) add alias support?
2048 because I assume 4096 being PAGE_SIZE would have some interesting corner cases, especially for a target buffer on the stack. If not then why not go straight for 4096?
Ian.
Re: [PATCH v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest
Quoted 32 lines · Ian Campbell
Quoted 21 lines · Julien Grall
Quoted 20 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Hi Ian,
Quoted 6 lines · Ian Campbell
xen/include/xen/device_tree.h line 26
Quoted 2 lines · Julien Grall
xen/include/xen/device_tree.h +2
-0+/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024Is this something you've made up or derived from the DT spec/ePAPR etc?
I didn't find a such requirements on the spec.
I vaguely recall a limit on the length of a single node name, and a limit on the depth which they may nest, which can be multiplied. It's probably an unhelpfully large number though, so...
Quoted 2 lines
I chose this number based on the linux pathlen because the path is also used in the sysfs (
/sys/firmware/devicetree).Quoted 7 lines
Quoted 1 line
...that's a good as anything I suppose!
Hmmm... I'm not so sure about the 1024 limit anymore. Linux is defining
PATH_MAXto 4096 but I don't see many usage in the sysfs code.And this value may change from one OS to another. Although, 1024 sounds a very long path to write in the configuration file...
I imagine in practice it will be cut-and-pasted, but yes.
Quoted 8 lines
Quoted 2 lines
Maybe we should
support alias too?Perhaps 2048 + (optionally, perhaps later) add alias support?
2048 because I assume 4096 being
PAGE_SIZEwould have some interesting corner cases, especially for a target buffer on the stack. If not then why not go straight for 4096?
XSM seems to use 4096 to copy string for an hypercall buffer. I will use the same here.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 16/24 xen/passthrough: Introduce iommu_construct
In reply to Julien GrallThis new function will correctly initialize the IOMMU page table for the current domain.
Also use it in iommu_assign_dt_device even though the current IOMMU implementation on ARM shares P2M with the processor.
---
Changes in v3:
- The ASSERT in iommu_construct was redundant with the if ()
- Remove d->need_iommu = 1 in assign_device has it's already done by iommu_construct.
- Simplify the code in the caller of iommu_construct
Changes in v2:
- Add missing Signed-off-by
- Rename iommu_buildup to iommu_construct
--- xen/drivers/passthrough/arm/iommu.c | 6 ++++++ xen/drivers/passthrough/device_tree.c | 4 ++++ xen/drivers/passthrough/iommu.c | 19 +++++++++++++++++++ xen/drivers/passthrough/pci.c | 15 ++++----------- xen/include/xen/iommu.h | 2 ++ 5 files changed, 35 insertions(+), 11 deletions(-)
xen/drivers/passthrough/arm/iommu.c +6 -0
@@ -68,3 +68,9 @@ void arch_iommu_domain_destroy(struct domain *d) {iommu_dt_domain_destroy (d); } + +int arch_iommu_populate_page_table (struct domain *d) +{ +/* The IOMMU shares the p2m with the CPU */ +return -ENOSYS ; +}
xen/drivers/passthrough/device_tree.c +4 -0
@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail; + rc =iommu_construct (d); +if ( rc ) + goto fail; + rc = hd->platform_ops->assign_device (d,0 ,dt_to_dev (dev));if ( rc )
xen/drivers/passthrough/iommu.c +19 -0
@@ -187,6 +187,25 @@ void iommu_teardown(struct domain *d)tasklet_schedule (&iommu_pt_cleanup_tasklet); } +int iommu_construct (struct domain *d) +{ +int rc =0 ; + +if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; + +return rc; +} +void iommu_domain_destroy (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
xen/drivers/passthrough/pci.c +4 -11
@@ -1355,18 +1355,11 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn)if ( !spin_trylock (&pcidevs_lock) )return -ERESTART ; -if (need_iommu (d) <=0 ) + rc =iommu_construct (d); +if ( rc ) { -if ( !iommu_use_hap_pt (d) ) - { - rc =arch_iommu_populate_page_table (d); -if ( rc ) - { -spin_unlock (&pcidevs_lock); -return rc; - } - } - d->need_iommu =1 ; +spin_unlock (&pcidevs_lock); +return rc; } pdev =pci_get_pdev_by_domain (hardware_domain, seg, bus, devfn);
xen/include/xen/iommu.h +2 -0
@@ -65,6 +65,8 @@ int arch_iommu_domain_init(struct domain *d);int arch_iommu_populate_page_table (struct domain *d);void arch_iommu_check_autotranslated_hwdom (struct domain *d); +int iommu_construct (struct domain *d); +/* Function used internally, use iommu_domain_destroy */ void iommu_teardown (struct domain *d);
Signature · 1 line
2.1.4
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +3
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail; + rc =iommu_construct (d); +if ( rc ) + goto fail;
Considering that the only (current) caller of this it domain_build.c I'm afraid you're going to get into trouble if you get back -ERESTART here. Note that on x86 Dom0 setup works via iommu_hwdom_init(), which deals with the preemption needs (at that point in time) by calling process_pending_softirqs() every once in a while.
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Hi Jan,
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +0
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail;
Quoted 9 lines
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 3 lines
xen/drivers/passthrough/device_tree.c +3
-0+ rc =iommu_construct (d); +if ( rc ) + goto fail;Considering that the only (current) caller of this it
domain_build.cI'm afraid you're going to get into trouble if you get back-ERESTARThere. Note that on x86 Dom0 setup works viaiommu_hwdom_init(), which deals with the preemption needs (at that point in time) by callingprocess_pending_softirqs()every once in a while.
iommu_hwdom_init is also called for ARM (it's part of the common domain creation code). So, I don't see any issue here as we match the same behavior as PCI.
FWIW, on the previous version you asked to check the need_iommu(d) in iommu_construct. For DOM0 it will return 0 and therefore never return -ERESTART.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 15:28, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +0
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail;Quoted 9 lines
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 3 lines
xen/drivers/passthrough/device_tree.c +3
-0+ rc =iommu_construct (d); +if ( rc ) + goto fail;Considering that the only (current) caller of this it
domain_build.cI'm afraid you're going to get into trouble if you get back-ERESTARThere. Note that on x86 Dom0 setup works viaiommu_hwdom_init(), which deals with the preemption needs (at that point in time) by callingprocess_pending_softirqs()every once in a while.
Quoted 7 lines
iommu_hwdom_initis also called for ARM (it's part of the common domain creation code). So, I don't see any issue here as we match the same behavior as PCI.FWIW, on the previous version you asked to check the
need_iommu(d)iniommu_construct. For DOM0 it will return 0 and therefore never return-ERESTART.
Quoting the function:
+int iommu_construct(struct domain *d)
+{
+ int rc = 0;
+
+ if ( need_iommu(d) > 0 )
+ return 0;
+
+ if ( !iommu_use_hap_pt(d) )
+ {
+ rc = arch_iommu_populate_page_table(d);
+ if ( rc )
+ return rc;
+ }
+
+ d->need_iommu = 1;
+
+ return rc;
+}
If need_iommu() returns 0 for Dom0, then the early return won't get used. Hence I don't follow your comment above. And if what you say there was correct, then I don't understand why you add the call quoted at the very top in the first place (again taking into consideration that - afaict - the only [current] caller is in domain_build.c).
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 48 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 15:28, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +0
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail;Quoted 9 lines
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 3 lines
xen/drivers/passthrough/device_tree.c +3
-0+ rc =iommu_construct (d); +if ( rc ) + goto fail;Considering that the only (current) caller of this it
domain_build.cI'm afraid you're going to get into trouble if you get back-ERESTARThere. Note that on x86 Dom0 setup works viaiommu_hwdom_init(), which deals with the preemption needs (at that point in time) by callingprocess_pending_softirqs()every once in a while.Quoted 7 lines
iommu_hwdom_initis also called for ARM (it's part of the common domain creation code). So, I don't see any issue here as we match the same behavior as PCI.FWIW, on the previous version you asked to check the
need_iommu(d)iniommu_construct. For DOM0 it will return 0 and therefore never return-ERESTART.Quoting the function:
xen/drivers/passthrough/iommu.c +18
-0+int iommu_construct (struct domain *d) +{ +int rc =0 ; + +if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; + +return rc; +}
Quoted 5 lines
If
need_iommu()returns 0 for Dom0, then the early return won't get used. Hence I don't follow your comment above. And if what you say there was correct, then I don't understand why you add the call quoted at the very top in the first place (again taking into consideration that - afaict - the only [current] caller is indomain_build.c).
I don't understand what is the issue in the device tree use case. As I said, assign_device in the pci do exactly the same things.
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 15:28, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +0
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct
dt_device_node*dev)Quoted 41 lines
Quoted 13 lines
Quoted 7 lines
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 6 lines
xen/drivers/passthrough/device_tree.c +3
-0if ( !list_empty (&dev->domain_list) ) goto fail; + rc =iommu_construct (d); +if ( rc ) + goto fail;Quoted 5 lines
Considering that the only (current) caller of this it
domain_build.cI'm afraid you're going to get into trouble if you get back-ERESTARThere. Note that on x86 Dom0 setup works viaiommu_hwdom_init(), which deals with the preemption needs (at that point in time) by callingprocess_pending_softirqs()every once in a while.Quoted 7 lines
iommu_hwdom_initis also called for ARM (it's part of the common domain creation code). So, I don't see any issue here as we match the same behavior as PCI.FWIW, on the previous version you asked to check the
need_iommu(d)iniommu_construct. For DOM0 it will return 0 and therefore never return-ERESTART.Quoting the function:
xen/drivers/passthrough/iommu.c +18
-0+int iommu_construct (struct domain *d) +{ +int rc =0 ; + +if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; + +return rc; +}
Quoted 8 lines
Quoted 5 lines
If
need_iommu()returns 0 for Dom0, then the early return won't get used. Hence I don't follow your comment above. And if what you say there was correct, then I don't understand why you add the call quoted at the very top in the first place (again taking into consideration that - afaict - the only [current] caller is indomain_build.c).I don't understand what is the issue in the device tree use case. As I said,
assign_devicein the pci do exactly the same things.
Sure, but it's not being called for Dom0, but only out of the domctl handler.
Quoted 2 lines
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 57 lines · Jan Beulich
Quoted 57 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 15:28, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/drivers/passthrough/device_tree.c +0
-0@@ -41,6 +41,10 @@ int iommu_assign_dt_device(struct domain *d, struct
dt_device_node*dev)Quoted 47 lines
Quoted 13 lines
Quoted 7 lines
xen/drivers/passthrough/device_tree.c int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) · line 46
Quoted 6 lines
xen/drivers/passthrough/device_tree.c +3
-0if ( !list_empty (&dev->domain_list) ) goto fail; + rc =iommu_construct (d); +if ( rc ) + goto fail;Quoted 5 lines
Considering that the only (current) caller of this it
domain_build.cI'm afraid you're going to get into trouble if you get back-ERESTARThere. Note that on x86 Dom0 setup works viaiommu_hwdom_init(), which deals with the preemption needs (at that point in time) by callingprocess_pending_softirqs()every once in a while.Quoted 7 lines
iommu_hwdom_initis also called for ARM (it's part of the common domain creation code). So, I don't see any issue here as we match the same behavior as PCI.FWIW, on the previous version you asked to check the
need_iommu(d)iniommu_construct. For DOM0 it will return 0 and therefore never return-ERESTART.Quoting the function:
xen/drivers/passthrough/iommu.c +18
-0+int iommu_construct (struct domain *d) +{ +int rc =0 ; + +if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; + +return rc; +}If
need_iommu()returns 0 for Dom0, then the early return won't get used. Hence I don't follow your comment above. And if what you say there was correct, then I don't understand why you add the call quoted at the very top in the first place (again taking into consideration that - afaict - the only [current] caller is indomain_build.c).
Quoted 5 lines
Quoted 2 lines
I don't understand what is the issue in the device tree use case. As I said,
assign_devicein the pci do exactly the same things.Sure, but it's not being called for Dom0, but only out of the domctl handler.
Hmmm right. It's the main difference between non-PCI and PCI passthrough.
Quoted 6 lines
Quoted 3 lines
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
As iommu_hwdom_init is initialized correctly the IOMMU for DOM0, iommu_construct is a no-op.
Would an if ( need_iommu(d) ) will be more clear? Maybe we an assert (!is_hardware_domain(d)).
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 11:37, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Quoted 8 lines
Quoted 2 lines
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
As
iommu_hwdom_initis initialized correctly the IOMMU for DOM0,iommu_constructis a no-op.Would an if (
need_iommu(d)) will be more clear? Maybe we an assert (!is_hardware_domain(d)).
Just think this through properly: iommu_hwdom_init() may leave Dom0's ->need_iommu at 0 or 1 (depending on iommu_dom0_strict). And iommu_construct() specifically is a nop only when ->need_iommu is positive (x86's arch_iommu_populate_page_table() sets it to a negative value to indicate "being set up", and I wonder how ARM gets away without doing so).
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Hi Jan,
Quoted 15 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 11:37, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Quoted 8 lines
Quoted 2 lines
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
As
iommu_hwdom_initis initialized correctly the IOMMU for DOM0,iommu_constructis a no-op.Would an if (
need_iommu(d)) will be more clear? Maybe we an assert (!is_hardware_domain(d)).
Quoted 6 lines
Just think this through properly:
iommu_hwdom_init()may leave Dom0's ->need_iommu at 0 or 1 (depending oniommu_dom0_strict). Andiommu_construct()specifically is a nop only when ->need_iommu is positive (x86'sarch_iommu_populate_page_table()sets it to a negative value to indicate "being set up", and I wonder how ARM gets away without doing so).
iommu_dom0_strict is always set to 1 when IOMMU is used on ARM (see check_hwdom_reqs).
Futhermore, we always share the page table with the processor, so we never need to populate the page table.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 13:13, <[email protected]> wrote:
Hi Jan,
Quoted 15 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 11:37, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Quoted 8 lines
Quoted 2 lines
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
As
iommu_hwdom_initis initialized correctly the IOMMU for DOM0,iommu_constructis a no-op.Would an if (
need_iommu(d)) will be more clear? Maybe we an assert (!is_hardware_domain(d)).Quoted 6 lines
Just think this through properly:
iommu_hwdom_init()may leave Dom0's ->need_iommu at 0 or 1 (depending oniommu_dom0_strict). Andiommu_construct()specifically is a nop only when ->need_iommu is positive (x86'sarch_iommu_populate_page_table()sets it to a negative value to indicate "being set up", and I wonder how ARM gets away without doing so).
Quoted 5 lines
iommu_dom0_strictis always set to 1 when IOMMU is used on ARM (seecheck_hwdom_reqs).Futhermore, we always share the page table with the processor, so we never need to populate the page table.
That's all far from obvious looking at the patch at hand. And you can then only hope that these two "always" will always remain to be that way.
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 13:13, <[email protected]> wrote:
Hi Jan,
Quoted 15 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 11:37, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 18:11, <[email protected]> wrote:
While this function is currently only used for DOM0, this will be used in a later patch for guest non-PCI passthrough.
Quoted 8 lines
Quoted 2 lines
Okay, but you shouldn't break (or alter in [seemingly] benign ways) the Dom0 case imo.
As
iommu_hwdom_initis initialized correctly the IOMMU for DOM0,iommu_constructis a no-op.Would an if (
need_iommu(d)) will be more clear? Maybe we an assert (!is_hardware_domain(d)).Quoted 6 lines
Just think this through properly:
iommu_hwdom_init()may leave Dom0's ->need_iommu at 0 or 1 (depending oniommu_dom0_strict). Andiommu_construct()specifically is a nop only when ->need_iommu is positive (x86'sarch_iommu_populate_page_table()sets it to a negative value to indicate "being set up", and I wonder how ARM gets away without doing so).
iommu_dom0_strictis always set to 1 when IOMMU is used on ARM (seecheck_hwdom_reqs).
Quoted 6 lines
Quoted 2 lines
Futhermore, we always share the page table with the processor, so we never need to populate the page table.
That's all far from obvious looking at the patch at hand. And you can then only hope that these two "always" will always remain to be that way.
Hence the suggested ASSERT on a previous mail. I could also add a comment in the code explaining the ASSERT().
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 15:22, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 21.01.15 at 13:13, <[email protected]> wrote:
iommu_dom0_strictis always set to 1 when IOMMU is used on ARM (seecheck_hwdom_reqs).Futhermore, we always share the page table with the processor, so we never need to populate the page table.
Quoted 6 lines
Quoted 3 lines
That's all far from obvious looking at the patch at hand. And you can then only hope that these two "always" will always remain to be that way.
Hence the suggested ASSERT on a previous mail. I could also add a comment in the code explaining the
ASSERT().
Yes please, for both parts.
Jan
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
In reply to Julien GrallQuoted 8 lines · Julien Grall
This new function will correctly initialize the IOMMU page table for the current domain.
Also use it in
iommu_assign_dt_deviceeven though the current IOMMU implementation on ARM shares P2M with the processor.Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Although I'm not actually sure what it is going to be used for.
Also, needs Jan to ack I think.
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
This new function will correctly initialize the IOMMU page table for the current domain.
Also use it in
iommu_assign_dt_deviceeven though the current IOMMU implementation on ARM shares P2M with the processor.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>Although I'm not actually sure what it is going to be used for.
The caller are in this patch too :) (see pci.c and device_tree.c changes).
Quoted 1 line
Also, needs Jan to ack I think.
I have some comments from Jan which I need to address in the next series.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Quoted 8 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
This new function will correctly initialize the IOMMU page table for the current domain.
Also use it in
iommu_assign_dt_deviceeven though the current IOMMU implementation on ARM shares P2M with the processor.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>Although I'm not actually sure what it is going to be used for.
The caller are in this patch too :) (see
pci.canddevice_tree.cchanges).
Right, I meant "what non-trivial functionality is going to land here" i..e what the grandparent callers etc will eventually expect from it.
Ian
Re: [PATCH v3 16/24] xen/passthrough: Introduce iommu_construct
Hi Ian,
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Julien Grall
This new function will correctly initialize the IOMMU page table for the current domain.
Also use it in
iommu_assign_dt_deviceeven though the current IOMMU implementation on ARM shares P2M with the processor.Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Acked-by Ian Campbell <[email protected]>Although I'm not actually sure what it is going to be used for.
The caller are in this patch too :) (see
pci.canddevice_tree.cchanges).Right, I meant "what non-trivial functionality is going to land here" i..e what the grandparent callers etc will eventually expect from it.
Oh ok. The function is used to the prepare the IOMMU structure for the domain. Currently, the steps are:
- build the page table on platforms which don't share the P2M
- set need_iommu to 1.
Within this series, this is the only patch who touch this function.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 17/24 xen/passthrough: arm: release earlier the DT devices assigned to a guest
In reply to Julien GrallThe toolstack may not have deassign every device used by a guest. Therefore we have to go through the device list and removing them before asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
---
Changes in v3:
- Patch added. Superseed the patch "xen/passthrough: call arch_iommu_domain_destroy before calling iommu teardown" in the previous patch series.
--- xen/arch/arm/domain.c | 4 ++++ xen/drivers/passthrough/arm/iommu.c | 1 - xen/drivers/passthrough/device_tree.c | 5 ++++- xen/include/xen/iommu.h | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-)
xen/arch/arm/domain.c +4 -0
@@ -772,6 +772,10 @@ int domain_relinquish_resources(struct domain *d)switch ( d->arch.relmem ) {case RELMEM_not_started: + ret =iommu_release_dt_devices (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_xen;/* Falltrough */
xen/drivers/passthrough/arm/iommu.c +0 -1
@@ -66,7 +66,6 @@ int arch_iommu_domain_init(struct domain *d)void arch_iommu_domain_destroy (struct domain *d) { -iommu_dt_domain_destroy (d); }int arch_iommu_populate_page_table (struct domain *d)
xen/drivers/passthrough/device_tree.c +4 -1
@@ -97,7 +97,7 @@ int iommu_dt_domain_init(struct domain *d)return 0 ; } -void iommu_dt_domain_destroy (struct domain *d) +int iommu_release_dt_devices (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);struct dt_device_node *dev, *_dev;
@@ -109,5 +109,8 @@ void iommu_dt_domain_destroy(struct domain *d)if ( rc )dprintk (XENLOG_ERR ,"Failed to deassign %s in domain %u\n" ,dt_node_full_name (dev), d->domain_id); +return rc; } + +return 0 ; }
xen/include/xen/iommu.h +1 -1
@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);#endif /* HAS_DEVICE_TREE */
Signature · 1 line
2.1.4
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg); · line 120
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/include/xen/iommu.h +1
-1@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);
I don't think you really need an ack from me on this trivial change, but in case you feel otherwise, don't hesitate to add it.
Jan
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Hi Jan,
Quoted 12 lines · Jan Beulich
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg); · line 120
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/include/xen/iommu.h +1
-1@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);I don't think you really need an ack from me on this trivial change, but in case you feel otherwise, don't hesitate to add it.
I wasn't sure if I add to cc you. You were in the list of maintainers with scripts/get_maintainers.pl because the include is part of the "IOMMU VENDOR INDEPENDENT CODE".
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 20.01.15 at 15:30, <[email protected]> wrote:
Hi Jan,
Quoted 4 lines · Jan Beulich
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
xen/include/xen/iommu.h +0
-0@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc,struct
msi_msg*msg);Quoted 8 lines
xen/include/xen/iommu.h void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg); · line 120
Quoted 5 lines
xen/include/xen/iommu.h +1
-1int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);I don't think you really need an ack from me on this trivial change, but in case you feel otherwise, don't hesitate to add it.
Quoted 3 lines
I wasn't sure if I add to cc you. You were in the list of maintainers with
scripts/get_maintainers.plbecause the include is part of the "IOMMU VENDOR INDEPENDENT CODE".
Which is fine - I merely wanted to point out that a trivial prototype adjustment can imo go in without requiring an ack.
Jan
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
In reply to Julien GrallQuoted 8 lines · Julien Grall
The toolstack may not have deassign every device used by a guest. Therefore we have to go through the device list and removing them before asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Quoted 7 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Changes in v3:
- Patch added. Superseed the patch "xen/passthrough: callarch_iommu_domain_destroybefore calling iommu teardown" in the previous patch series.
Quoted 71 lines
xen/arch/arm/domain.c | 4 ++++ xen/drivers/passthrough/arm/iommu.c | 1 - xen/drivers/passthrough/device_tree.c | 5 ++++- xen/include/xen/iommu.h | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-)xen/arch/arm/domain.c +4
-0@@ -772,6 +772,10 @@ int domain_relinquish_resources(struct domain *d)switch ( d->arch.relmem ) {case RELMEM_not_started: + ret =iommu_release_dt_devices (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_xen;/* Falltrough */ xen/drivers/passthrough/arm/iommu.c +0
-1@@ -66,7 +66,6 @@ int arch_iommu_domain_init(struct domain *d)void arch_iommu_domain_destroy (struct domain *d) { -iommu_dt_domain_destroy (d); }int arch_iommu_populate_page_table (struct domain *d)xen/drivers/passthrough/device_tree.c +4
-1@@ -97,7 +97,7 @@ int iommu_dt_domain_init(struct domain *d)return 0 ; } -void iommu_dt_domain_destroy (struct domain *d) +int iommu_release_dt_devices (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);struct dt_device_node *dev, *_dev;@@ -109,5 +109,8 @@ void iommu_dt_domain_destroy(struct domain *d)if ( rc )dprintk (XENLOG_ERR ,"Failed to deassign %s in domain %u\n" ,dt_node_full_name (dev), d->domain_id); +return rc; } + +return 0 ; }xen/include/xen/iommu.h +1
-1@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);#endif /* HAS_DEVICE_TREE */ Signature · 1 line
2.1.4
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
In reply to Julien GrallOn Tue, 2015-01-13 at 14:25 +0000, Julien Grall wrote:
Subject: "release the DT devices assigned to a guest earlier"
Quoted 1 line
The toolstack may not have deassign every device used by a guest.
"deassigned"
Quoted 1 line
Therefore we have to go through the device list and removing them before
"and remove them"
Quoted 8 lines
asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
I'd like to hear Jan's opinion though.
Quoted 75 lines
---
Changes in v3:
- Patch added. Superseed the patch "xen/passthrough: callarch_iommu_domain_destroybefore calling iommu teardown" in the previous patch series.--- xen/arch/arm/domain.c | 4 ++++ xen/drivers/passthrough/arm/iommu.c | 1 - xen/drivers/passthrough/device_tree.c | 5 ++++- xen/include/xen/iommu.h | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-)xen/arch/arm/domain.c +4
-0@@ -772,6 +772,10 @@ int domain_relinquish_resources(struct domain *d)switch ( d->arch.relmem ) {case RELMEM_not_started: + ret =iommu_release_dt_devices (d); +if ( ret ) +return ret; + d->arch.relmem = RELMEM_xen;/* Falltrough */ xen/drivers/passthrough/arm/iommu.c +0
-1@@ -66,7 +66,6 @@ int arch_iommu_domain_init(struct domain *d)void arch_iommu_domain_destroy (struct domain *d) { -iommu_dt_domain_destroy (d); }int arch_iommu_populate_page_table (struct domain *d)xen/drivers/passthrough/device_tree.c +4
-1@@ -97,7 +97,7 @@ int iommu_dt_domain_init(struct domain *d)return 0 ; } -void iommu_dt_domain_destroy (struct domain *d) +int iommu_release_dt_devices (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);struct dt_device_node *dev, *_dev;@@ -109,5 +109,8 @@ void iommu_dt_domain_destroy(struct domain *d)if ( rc )dprintk (XENLOG_ERR ,"Failed to deassign %s in domain %u\n" ,dt_node_full_name (dev), d->domain_id); +return rc; } + +return 0 ; }xen/include/xen/iommu.h +1
-1@@ -117,7 +117,7 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d); -void iommu_dt_domain_destroy (struct domain *d); +int iommu_release_dt_devices (struct domain *d);#endif /* HAS_DEVICE_TREE */
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Quoted 18 lines · Ian Campbell
On Tue, 2015-01-13 at 14:25 +0000, Julien Grall wrote:
Subject: "release the DT devices assigned to a guest earlier"
Quoted 1 line
The toolstack may not have deassign every device used by a guest.
"deassigned"
Quoted 1 line
Therefore we have to go through the device list and removing them before
"and remove them"
Quoted 6 lines
asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>I'd like to hear Jan's opinion though.
FWIW, this is how it's done for PCI.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:46, <[email protected]> wrote:
Quoted 18 lines · Ian Campbell
On Tue, 2015-01-13 at 14:25 +0000, Julien Grall wrote:
Subject: "release the DT devices assigned to a guest earlier"
Quoted 1 line
The toolstack may not have deassign every device used by a guest.
"deassigned"
Quoted 1 line
Therefore we have to go through the device list and removing them before
"and remove them"
Quoted 6 lines
asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>I'd like to hear Jan's opinion though.
FWIW, this is how it's done for PCI.
Right, IOW I agree to the idea of the patch.
Jan
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:46, <[email protected]> wrote:
Quoted 21 lines · Ian Campbell
On Tue, 2015-01-13 at 14:25 +0000, Julien Grall wrote:
Subject: "release the DT devices assigned to a guest earlier"
Quoted 1 line
The toolstack may not have deassign every device used by a guest.
"deassigned"
Quoted 1 line
Therefore we have to go through the device list and removing them before
"and remove them"
Quoted 8 lines
asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Acked-by Ian Campbell <[email protected]>I'd like to hear Jan's opinion though.
FWIW, this is how it's done for PCI.
Right, IOW I agree to the idea of the patch.
Thanks. If Julien could record this in the form of an ack that would save me remembering you've said so (otherwise it could just go as a comment after the --- I suppose).
Ian.
Re: [PATCH v3 17/24] xen/passthrough: arm: release earlier the DT devices assigned to a guest
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 16:33, <[email protected]> wrote:
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:46, <[email protected]> wrote:
Quoted 24 lines · Ian Campbell
On Tue, 2015-01-13 at 14:25 +0000, Julien Grall wrote:
Subject: "release the DT devices assigned to a guest earlier"
Quoted 1 line
The toolstack may not have deassign every device used by a guest.
"deassigned"
Quoted 1 line
Therefore we have to go through the device list and removing them before
"and remove them"
Quoted 8 lines
asking the IOMMU drivers to release memory for this domain.
This can be done by moving the call to the release function when we relinquish the resources. The IOMMU part will be destroyed later when the domain is freed.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>I'd like to hear Jan's opinion though.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
FWIW, this is how it's done for PCI.
Right, IOW I agree to the idea of the patch.
Thanks. If Julien could record this in the form of an ack that would save me remembering you've said so (otherwise it could just go as a comment after the --- I suppose).
That's fine with me, I just didn't say so because it seemed a bit odd on an ARM-only change.
Jan
PATCH v3 18/24 xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Julien GrallCurrently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
---
Changes in v3:
- Use the coding style of the new SMMU drivers
Changes in v2:
- Fix typoes in the commit message
- Update commit message
--- xen/drivers/passthrough/arm/smmu.c | 8 +++++++- xen/drivers/passthrough/device_tree.c | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-)
xen/drivers/passthrough/arm/smmu.c +7 -1
@@ -2774,7 +2774,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,int ret =0 ;/* Don't allow remapping on other domain than hwdom */ -if (t != hardware_domain) +if (t && t != hardware_domain)return -EPERM ;if (t == s)
@@ -2784,6 +2784,12 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,if (ret)return ret; +if (t) { + ret =arm_smmu_assign_dev (t, devfn, dev); +if (ret) +return ret; + } +return 0 ; }
xen/drivers/passthrough/device_tree.c +3 -6
@@ -72,15 +72,12 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev)spin_lock (&dtdevs_lock); - rc = hd->platform_ops->reassign_device (d, hardware_domain, -0 ,dt_to_dev (dev)); + rc = hd->platform_ops->reassign_device (d,NULL ,0 ,dt_to_dev (dev));if ( rc ) goto fail; -list_del (&dev->domain_list); - -dt_device_set_used_by (dev, hardware_domain->domain_id); -list_add (&dev->domain_list, &domain_hvm_iommu (hardware_domain)->dt_devices); +list_del_init (&dev->domain_list); +dt_device_set_used_by (dev,DOMID_IO ); fail:spin_unlock (&dtdevs_lock);
Signature · 1 line
2.1.4
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Looks like this is because of ...
Quoted 1 line
xen/drivers/passthrough/device_tree.c | 9 +++------
... this. Which I think is a mistake, as I wasn't involved in the addition of that file. I'd appreciate an update to ./MAINTAINERS adding this file to the ARM section.
Jan
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Hi Jan,
Quoted 21 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 15:25, <[email protected]> wrote:
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 7 lines
Looks like this is because of ...
Quoted 1 line
xen/drivers/passthrough/device_tree.c | 9 +++------... this. Which I think is a mistake, as I wasn't involved in the addition of that file. I'd appreciate an update to ./MAINTAINERS adding this file to the ARM section.
Ok. I will send a patch to add xen/drivers/passthrough/device_tree.c in the "ARM section".
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Julien GrallQuoted 13 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 6 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 63 lines
Changes in v3:
- Use the coding style of the new SMMU driversChanges in v2:
- Fix typoes in the commit message
- Update commit message--- xen/drivers/passthrough/arm/smmu.c | 8 +++++++- xen/drivers/passthrough/device_tree.c | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-)xen/drivers/passthrough/arm/smmu.c +7
-1@@ -2774,7 +2774,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,int ret =0 ;/* Don't allow remapping on other domain than hwdom */ -if (t != hardware_domain) +if (t && t != hardware_domain)return -EPERM ;if (t == s)@@ -2784,6 +2784,12 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,if (ret)return ret; +if (t) { + ret =arm_smmu_assign_dev (t, devfn, dev); +if (ret) +return ret; + } +return 0 ; }xen/drivers/passthrough/device_tree.c +3
-6@@ -72,15 +72,12 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev)spin_lock (&dtdevs_lock); - rc = hd->platform_ops->reassign_device (d, hardware_domain, -0 ,dt_to_dev (dev)); + rc = hd->platform_ops->reassign_device (d,NULL ,0 ,dt_to_dev (dev));if ( rc ) goto fail; -list_del (&dev->domain_list); - -dt_device_set_used_by (dev, hardware_domain->domain_id); -list_add (&dev->domain_list, &domain_hvm_iommu (hardware_domain)->dt_devices); +list_del_init (&dev->domain_list); +dt_device_set_used_by (dev,DOMID_IO ); fail:spin_unlock (&dtdevs_lock);Signature · 1 line
2.1.4
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Julien GrallQuoted 7 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
Quoted 8 lines
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Quoted 65 lines
Signed-off-by Julien Grall <[email protected]>Cc Jan Beulich <[email protected]>---
Changes in v3:
- Use the coding style of the new SMMU driversChanges in v2:
- Fix typoes in the commit message
- Update commit message--- xen/drivers/passthrough/arm/smmu.c | 8 +++++++- xen/drivers/passthrough/device_tree.c | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-)xen/drivers/passthrough/arm/smmu.c +7
-1@@ -2774,7 +2774,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,int ret =0 ;/* Don't allow remapping on other domain than hwdom */ -if (t != hardware_domain) +if (t && t != hardware_domain)return -EPERM ;if (t == s)@@ -2784,6 +2784,12 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t,if (ret)return ret; +if (t) { + ret =arm_smmu_assign_dev (t, devfn, dev); +if (ret) +return ret; + } +return 0 ; }xen/drivers/passthrough/device_tree.c +3
-6@@ -72,15 +72,12 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev)spin_lock (&dtdevs_lock); - rc = hd->platform_ops->reassign_device (d, hardware_domain, -0 ,dt_to_dev (dev)); + rc = hd->platform_ops->reassign_device (d,NULL ,0 ,dt_to_dev (dev));if ( rc ) goto fail; -list_del (&dev->domain_list); - -dt_device_set_used_by (dev, hardware_domain->domain_id); -list_add (&dev->domain_list, &domain_hvm_iommu (hardware_domain)->dt_devices); +list_del_init (&dev->domain_list); +dt_device_set_used_by (dev,DOMID_IO ); fail:spin_unlock (&dtdevs_lock);
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 4 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption
or
Quoted 9 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
Jan
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Hi Jan,
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 4 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption
or
Quoted 11 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Quoted 7 lines
Quoted 2 lines
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Hi Jan,
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 4 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption
or
Quoted 11 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Quoted 7 lines
Quoted 2 lines
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
Quoted 8 lines
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
And I think spelling this out in the description is what Ian is asking for.
Jan
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 4 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption
or
Quoted 9 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
Quoted 4 lines
Quoted 4 lines
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
Quoted 11 lines
Quoted 8 lines
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
And I think spelling this out in the description is what Ian is asking for.
Yes.
I think it probably ought to be mentioned in the docs surrounding the hypercalls in question, for both PCI, DT and any other device type whether or not there is some implicit rebinding or not.
Ian.
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 16:39, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Hi Jan,
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 1 line · Julien Grall
Currently, when the device is deassigned from a domain, we directly
reassign
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to DOM0.
As the device may not have been correctly reset, this may lead to
corruption
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
or
Quoted 9 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
Quoted 4 lines
Quoted 4 lines
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
Quoted 8 lines
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
I suppose this was really targeted at Julien...
Jan
Quoted 19 lines
Quoted 11 lines
Quoted 8 lines
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
And I think spelling this out in the description is what Ian is asking for.
Yes.
I think it probably ought to be mentioned in the docs surrounding the hypercalls in question, for both PCI, DT and any other device type whether or not there is some implicit rebinding or not.
Ian.
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 44 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 16:39, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Hi Jan,
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 1 line · Julien Grall
Currently, when the device is deassigned from a domain, we directly
reassign
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to DOM0.
As the device may not have been correctly reset, this may lead to
corruption
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
or
Quoted 9 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
Quoted 4 lines
Quoted 4 lines
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
Quoted 6 lines
Quoted 4 lines
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
I suppose this was really targeted at Julien...
Right, sorry that wasn't very clear of me.
Quoted 25 lines
Jan
Quoted 19 lines
Quoted 11 lines
Quoted 8 lines
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
And I think spelling this out in the description is what Ian is asking for.
Yes.
I think it probably ought to be mentioned in the docs surrounding the hypercalls in question, for both PCI, DT and any other device type whether or not there is some implicit rebinding or not.
Ian.
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Ian CampbellQuoted 37 lines · Ian Campbell
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Hi Jan,
Quoted 26 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 20.02.15 at 18:04, <[email protected]> wrote:
Quoted 4 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption
or
Quoted 9 lines
expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
Indeed this is different from x86, and I think such behavior should be consistent across architectures. If Dom0 isn't handed back the device, who's going to do the supposedly prerequisite reset? On x86/PCI that's pciback's job, and it would be illegitimate for the driver to do _anything_ with the device if it wasn't owned by Dom0.
Quoted 4 lines
Quoted 4 lines
I think we already had this discussion on a previous version...
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
Quoted 8 lines
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
The list of things to do for resetting a device would be:
- Deassign device from DOMU (though it's done during destruction)
- Assign the device to DOM0 and map MMIO
- Reset the device
But that not my concern right now. As we agreed, this feature (i.e reset a device) is not in the scope of this series.
So assigning the device to DOM0 is not safe at all.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
This series doesn't intend to have a generic solution for platform device pass-through. It's target embedded people who will always passthrough the same device to the same guest.
As DOM0 *should not* use the device (no reset driver, and no possibility to unbind), the safest way is to reassign the device to nobody.
So if the device is not quiescent it may mess up DOM0.
Quoted 8 lines
Quoted 2 lines
And I think spelling this out in the description is what Ian is asking for.
Yes.
I think it probably ought to be mentioned in the docs surrounding the hypercalls in question, for both PCI, DT and any other device type whether or not there is some implicit rebinding or not.
Ok.
Signature · 1 line
Julien Grall
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 17:37, <[email protected]> wrote:
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
Quoted 8 lines
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
The list of things to do for resetting a device would be:
- Deassign device from DOMU (though it's done during destruction)
- Assign the device to DOM0 and map MMIO
- Reset the device
Quoted 4 lines
But that not my concern right now. As we agreed, this feature (i.e reset a device) is not in the scope of this series.
So assigning the device to DOM0 is not safe at all.
Kind of confusing - above you state "assign the device to DOM0 and map MMIO" as a prereq step for resetting the device, yet then you state assigning it back to Dom0 is not safe. Which of the two do you mean after all?
Jan
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 17:37, <[email protected]> wrote:
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:10, <[email protected]> wrote:
Right now, there is no possibility to reset a platform device in the kernel. There is some discussion about it but nothing more.
Quoted 8 lines
"there is no possibility to reset a platform device" isn't quite true, there is certainly a theoretical possibility (i.e. it is obviously the case that a dom0 could be written to do so for at least some devices).
So what happens if such a dom0 arises in the future? I suppose the intention is that the user would having deassigned from domU and determined that there kernel has the necessary feature would do some sort of xl command to assign to dom0?
The list of things to do for resetting a device would be:
- Deassign device from DOMU (though it's done during destruction)
- Assign the device to DOM0 and map MMIO
- Reset the deviceBut that not my concern right now. As we agreed, this feature (i.e reset a device) is not in the scope of this series.
Quoted 6 lines
Quoted 1 line
So assigning the device to DOM0 is not safe at all.
Kind of confusing - above you state "assign the device to DOM0 and map MMIO" as a prereq step for resetting the device, yet then you state assigning it back to Dom0 is not safe. Which of the two do you mean after all?
Ian was asking how would it be possible to reset the device and I gave him a list of things to do.
Reassigning the device to DOM0 is not safe if there is no reset driver in the DOM0 kernel. Unlike PCI, there is no generic way to reset a platform device.
As for now, there is no reset driver at all in DOM0. Not reassign the device is the better thing to do.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 18/24] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Ian CampbellQuoted 14 lines · Ian Campbell
Quoted 13 lines · Julien Grall
Currently, when the device is deassigned from a domain, we directly reassign to DOM0.
As the device may not have been correctly reset, this may lead to corruption or expose some part of DOM0 memory. Also, we may have no way to reset some platform devices.
If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). Unfortunately there is no simple way to quiesce a buggy hardware. I think we could live with that for a first version of platform device passthrough.
Quoted 5 lines
Quoted 2 lines
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
Does this behaviour differ from x86? If so then it is worth calling that out explicitly (even if not, good to know I think!)
What do you mean by "calling that out explicitly"?
Regards,
Signature · 1 line
Julien Grall