xen/arm: Add support for non-PCI passthrough
v6 cover xen/arm: Add support for non-PCI passthrough
Hello all,
This is the sixth version of this patch series to add support for platform device passthrough on ARM.
In order to passthrough a non-PCI device, 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 allows 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). Though, it requires a separate patch as we decide to not support the Midway SMMU within the new drivers.
A working tree can be found here:
git://xenbits.xen.org/julieng/xen-unstable.git branch passthrough-v6
Major changes in v6:
- Update docs
- Typoes
Major changes in v5:
- Series divided in 2 parts. The first part [6] has been pushed to Xen upstream
- Add more documentation
- Modify XSM check for bind_pt_irq on ARM
Major changes in v4:
- The partial device tree option can only be used with trusted device tree
- Add more documentation
- Use DOMCTL_bind_pt_irq rather than PHYSDEVOP_map_pirq
- Add XSM support for non-PCI passthrough
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.
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
[6] http://lists.xenproject.org/archives/html/xen-devel/2015-04/msg00248.html
Julien Grall (19):
xen/arm: Let the toolstack configure the number of SPIs xen/arm: vgic: Add spi_to_pending
xen/arm: Release IRQ routed to a domain when it's destroying xen/arm: Implement hypercall DOMCTL_{,un}bind_pt_pirq
xen: guestcopy: Provide an helper to safely copy string from guest 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 the DT devices assigned to a guest
earlier
xen/passthrough: iommu_deassign_device_dt: By default reassign device
to nobody
xen/iommu: arm: Wire iommu DOMCTL for ARM
xen/xsm: Add helpers to check permission for device tree passthrough xen/passthrough: Extend XEN_DOMCTL_*assign_device to support DT device tools/libxl: Create a per-arch function to map IRQ to a domain tools/libxl: Check if fdt_{first,next}_subnode are present in libfdt 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 Device Tree passthrough
xl: Add new option dtdev
docs/misc: arm: Add documentation about Device Tree passthrough
docs/man/xl.cfg.pod.5 | 18 ++++ docs/misc/arm/passthrough.txt | 63 +++++++++++ tools/config.h.in | 6 ++ tools/configure.ac | 5 + tools/libxc/include/xenctrl.h | 20 ++++ tools/libxc/xc_domain.c | 156 +++++++++++++++++++++++++-- tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 7 ++ tools/libxl/libxl_arch.h | 4 + tools/libxl/libxl_arm.c | 192 +++++++++++++++++++++++++++++++++- tools/libxl/libxl_create.c | 38 ++++++- tools/libxl/libxl_internal.h | 5 + tools/libxl/libxl_libfdt_compat.c | 92 ++++++++++++++++ tools/libxl/libxl_types.idl | 11 ++ tools/libxl/libxl_x86.c | 13 +++ tools/libxl/xl_cmdimpl.c | 23 +++- xen/arch/arm/domain.c | 6 +- xen/arch/arm/domctl.c | 89 +++++++++++++++- xen/arch/arm/gic.c | 45 ++++++++ xen/arch/arm/irq.c | 46 ++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 34 +++++- xen/common/Makefile | 1 + xen/common/device_tree.c | 18 ++++ xen/common/guestcopy.c | 31 ++++++ xen/drivers/passthrough/arm/iommu.c | 7 +- xen/drivers/passthrough/arm/smmu.c | 8 +- xen/drivers/passthrough/device_tree.c | 136 ++++++++++++++++++++++-- xen/drivers/passthrough/iommu.c | 33 +++++- xen/drivers/passthrough/pci.c | 69 ++++++------ xen/include/asm-arm/gic.h | 4 + xen/include/asm-arm/irq.h | 2 + xen/include/asm-arm/vgic.h | 3 +- xen/include/public/arch-arm.h | 2 + xen/include/public/domctl.h | 28 ++++- xen/include/xen/device_tree.h | 14 +++ xen/include/xen/guest_access.h | 5 + xen/include/xen/iommu.h | 7 +- xen/include/xsm/dummy.h | 47 ++++++--- xen/include/xsm/xsm.h | 55 +++++++--- xen/xsm/dummy.c | 10 +- xen/xsm/flask/avc.c | 3 + xen/xsm/flask/flask_op.c | 49 +++------ xen/xsm/flask/hooks.c | 139 +++++++++++++++++------- xen/xsm/flask/include/avc.h | 2 + xen/xsm/flask/policy/access_vectors | 2 +- 46 files changed, 1377 insertions(+), 174 deletions(-) create mode 100644 docs/misc/arm/passthrough.txt create mode 100644 tools/libxl/libxl_libfdt_compat.c create mode 100644 xen/common/guestcopy.c
Signature · 1 line
2.1.4
PATCH v6 1/19 xen/arm: Let the toolstack configure the number of SPIs
From: Julien Grall <[email protected]>
Each domain may have a different number of IRQs depending on the devices assigned to it.
Rather than 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 wasting memory.
To calculate the number of SPIs, we take advantage of the fact that the libxl interface can only expose 1:1 mapping and look for the largest SPI in the list.
---
Changes in v6:
- Rework the SPIs check in domain_vgic_init to avoid overflow
- Fix typoes in commit message
- Add Ian's Ack
Changes in v5:
- Remove stray change
- Limit the number of SPIs to (1020 - 32) rather than the number supported by the hardware
Changes in v4:
- Check the number of SPIs supported by the virtual GIC against the number supported by the hardware GIC.
- Use uint32_t rather than int in the toolstack code.
- Initialize spi after the check in the toolstack code
- Typoes
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 | 21 +++++++++++++++++++++ xen/arch/arm/domain.c | 2 +- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 11 ++++++----- xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 7 files changed, 33 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 +21 -0
@@ -39,6 +39,27 @@ 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++) { +uint32_t irq = d_config->b_info.irqs[i]; +uint32_t spi; + +if (irq <32 ) +continue ; + + spi = irq -32 ; + +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 +1 -1
@@ -590,7 +590,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,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
@@ -830,6 +830,7 @@ void __init start_xen(unsigned long boot_phys_offset,/* Create initial domain 0. */ /* The vGIC for DOM0 is exactly emulating the hardware GIC */ config.gic_version =XEN_DOMCTL_CONFIG_GIC_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 +6 -5
@@ -68,16 +68,17 @@ 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 */ +/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ +if ( nr_spis > (1020 -NR_LOCAL_IRQS ) ) +return -EINVAL ; + + d->arch.vgic.nr_spis = nr_spis;switch (gic_hw_version () ) {
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
@@ -315,6 +315,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
PATCH v6 2/19 xen/arm: vgic: Add spi_to_pending
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Introduce spi_to_pending in order retrieve the irq_pending structure for a specific SPI.
It's not possible to re-use irq_to_pending because it's required a VCPU and some call of the new function may during domain destruction after the VCPUs are freed.
---
Changes in v5:
- Add Ian's Ack
Changes in v4:
- Patch added
--- xen/arch/arm/vgic.c | 7 +++++++ xen/include/asm-arm/vgic.h | 1 + 2 files changed, 8 insertions(+)
xen/arch/arm/vgic.c +7 -0
@@ -371,6 +371,13 @@ struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq)return n; } +struct pending_irq *spi_to_pending (struct domain *d,unsigned int irq) +{ +ASSERT (irq >=NR_LOCAL_IRQS ); + +return &d->arch.vgic.pending_irqs[irq -32 ]; +} +void vgic_clear_pending_irqs (struct vcpu *v) {struct pending_irq *p, *t;
xen/include/asm-arm/vgic.h +1 -0
@@ -185,6 +185,7 @@ 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 pending_irq *spi_to_pending (struct domain *d,unsigned int irq);extern struct vgic_irq_rank *vgic_rank_offset (struct vcpu *v,int b,int n,int s);extern struct vgic_irq_rank *vgic_rank_irq (struct vcpu *v,unsigned int irq);extern int vgic_emulate (struct cpu_user_regs *regs,union hsr hsr);
Signature · 1 line
2.1.4
PATCH v6 3/19 xen/arm: Release IRQ routed to a domain when it's destroying
In reply to Julien GrallFrom: Julien Grall <[email protected]>
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.
Furthermore, a guest can crash and leave the IRQ in an incorrect state (i.e has not been 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 v5:
- Typoes in the commit message
- Add Ian's Ack
Changes in v4:
- Reorder the code flow
- Typoes and coding style
- Use the newly helper spi_to_pending
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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/irq.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic.c | 16 ++++++++++++++++ xen/include/asm-arm/gic.h | 4 ++++ xen/include/asm-arm/irq.h | 2 ++ 5 files changed, 113 insertions(+)
xen/arch/arm/gic.c +45 -0
@@ -163,6 +163,51 @@ 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 ( d->is_dying ) + { + desc->handler->shutdown (desc); + +/* EOI the IRQ it it has not been done by the guest */ +if (test_bit (_IRQ_INPROGRESS, &desc->status) ) + gic_hw_ops->deactivate_irq (desc); +clear_bit (_IRQ_INPROGRESS, &desc->status); + } +else + { +/* +* TODO: Handle eviction from LRs For now, deny +* remove if the IRQ is inflight or not disabled. +*/ +if (test_bit (_IRQ_INPROGRESS, &desc->status) || + !test_bit (_IRQ_DISABLED, &desc->status) ) +return -EBUSY ; + } + +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 +46 -0
52 lines not on this page · raw message
xen/arch/arm/vgic.c +16 -0
@@ -135,6 +135,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 =spi_to_pending (d, i +32 ); + +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
@@ -220,6 +220,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
PATCH v6 4/19 xen/arm: Implement hypercall DOMCTL_{, un}bind_pt_pirq
In reply to Julien GrallFrom: Julien Grall <[email protected]>
On x86, an IRQ is assigned in 2 steps to an HVM guest:
- The toolstack is calling PHYSDEVOP_map_pirq in order to create a guest PIRQ (IRQ bound to an event channel)
- The emulator (QEMU) is calling DOMCTL_bind_pt_irq in order to bind the IRQ
On ARM, there is no concept of PIRQ as the IRQ can be assigned to a virtual IRQ using the interrupt controller.
It's not clear if we will need 2 different hypercalls on ARM to assign IRQ and, for now, only the toolstack will manage IRQ.
In order to avoid re-using a fixed ABI hypercall (PHYSDEVOP_*) for a different purpose and allow us more time to figure out the right out, only DOMCTL_{,un}bind_pt_pirq is implemented on ARM.
The DOMCTL is extended with a new type PT_IRQ_TYPE_SPI and only IRQ == vIRQ (i.e machine_irq == spi) is supported.
In order to keep the same XSM checks done by the 2 hypercalls on x86, call both xsm_map_domain_irq & xsm_bind_pt_irq in the ARM implementation.
Note: The toolstack changes for routing an IRQ to a guest will be done in a separate patch.
---
Contrawise PHYSDEV, DOMCTL interface is not fixed. This version is using a DOMCTL in order to let us more to to see if we need a new PHYSDEV op for vIRQ assignation.
DOMCTL_unbind_pt_irq has been implemented, although I haven't test it. I'm not sure if we want to keep it.
xc_domain_{,un}bind_pt_irq are left unchanged because QEMU upstream & traditional are using them. I will send a follow-up series to drop this 2 functions in order to avoid defering this series while awaiting changes pushed for QEMU upstream.
Changes in v6:
- Rebase on the latest staging (conflict in xsm/flask/hooks.c with memaccess changes)
- Remove obsolete paragraph in the commit message
- Fix indentation in libxc
- Don't rely on vspi == spi in xc_domain_{,un}bind_pt_spi_irq
- Typoes in comment
- Add Daniel's ack (XSM part)
Changes in v5:
- Do the check of XSM PHYSDEVOP_map_pirq in the ARM implementation
- Left xc_domain_{,un}bind_pt_irq unchanged
- Introduce xc_domain_{,un}bind_pt_spi_irq
Changes in v4:
- Move the implementation from PHYSDEV to DOMCTL. Reuse DOMCTL_{,un}bind_pt_irq for this purpose.
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
--- tools/libxc/include/xenctrl.h | 10 ++++++ tools/libxc/xc_domain.c | 60 +++++++++++++++++++++++++++++++-- xen/arch/arm/domctl.c | 78 +++++++++++++++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 4 +++ xen/include/xsm/dummy.h | 24 ++++++------- xen/include/xsm/xsm.h | 28 ++++++++-------- xen/xsm/dummy.c | 4 +-- xen/xsm/flask/hooks.c | 70 +++++++++++++++++++------------------- 8 files changed, 213 insertions(+), 65 deletions(-)
tools/libxc/include/xenctrl.h +10 -0
@@ -2115,6 +2115,16 @@ int xc_domain_bind_pt_isa_irq(xc_interface *xch,uint32_t domid, uint8_t machine_irq); +int xc_domain_bind_pt_spi_irq (xc_interface *xch, +uint32_t domid, +uint16_t vspi, +uint16_t spi); + +int xc_domain_unbind_pt_spi_irq (xc_interface *xch, +uint32_t domid, +uint16_t vspi, +uint16_t spi); +int xc_domain_set_machine_address_size (xc_interface *xch,uint32_t domid,unsigned int width);
tools/libxc/xc_domain.c +57 -3
108 lines not on this page · raw message
xen/arch/arm/domctl.c +78 -0
90 lines not on this page · raw message
xen/include/public/domctl.h +4 -0
@@ -504,6 +504,7 @@ typedef enum pt_irq_type_e { PT_IRQ_TYPE_ISA,PT_IRQ_TYPE_MSI ,PT_IRQ_TYPE_MSI_TRANSLATE , +PT_IRQ_TYPE_SPI ,/* ARM: valid range 32-1019 */ } pt_irq_type_t;struct xen_domctl_bind_pt_irq {uint32_t machine_irq;
@@ -524,6 +525,9 @@ struct xen_domctl_bind_pt_irq {uint32_t gflags;uint64_aligned_t gtable; } msi; +struct { +uint16_t spi; + } spi; } u; };typedef struct xen_domctl_bind_pt_irq xen_domctl_bind_pt_irq_t ;
xen/include/xsm/dummy.h +12 -12
@@ -445,6 +445,18 @@ static XSM_INLINE int xsm_unmap_domain_pirq(XSM_DEFAULT_ARG struct domain *d)return xsm_default_action (action, current->domain, d); } +static XSM_INLINE int xsm_bind_pt_irq(XSM_DEFAULT_ARG struct domain *d, struct xen_domctl_bind_pt_irq *bind) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + +static XSM_INLINE int xsm_unbind_pt_irq(XSM_DEFAULT_ARG struct domain *d, struct xen_domctl_bind_pt_irq *bind) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + static XSM_INLINE int xsm_unmap_domain_irq(XSM_DEFAULT_ARG struct domain *d, int irq, void *data) {XSM_ASSERT_ACTION (XSM_HOOK );
@@ -647,18 +659,6 @@ static XSM_INLINE int xsm_priv_mapping(XSM_DEFAULT_ARG struct domain *d, structreturn xsm_default_action (action, d, t); } -static XSM_INLINE int xsm_bind_pt_irq(XSM_DEFAULT_ARG struct domain *d, struct xen_domctl_bind_pt_irq *bind) -{ -XSM_ASSERT_ACTION (XSM_HOOK ); -return xsm_default_action (action, current->domain, d); -} - -static XSM_INLINE int xsm_unbind_pt_irq(XSM_DEFAULT_ARG struct domain *d, struct xen_domctl_bind_pt_irq *bind) -{ -XSM_ASSERT_ACTION (XSM_HOOK ); -return xsm_default_action (action, current->domain, d); -} - static XSM_INLINE int xsm_ioport_permission(XSM_DEFAULT_ARG struct domain *d, uint32_t s, uint32_t e, uint8_t allow) {XSM_ASSERT_ACTION (XSM_HOOK );
xen/include/xsm/xsm.h +14 -14
@@ -107,6 +107,8 @@ struct xsm_operations {int (*map_domain_irq) (struct domain *d,int irq,void *data);int (*unmap_domain_pirq) (struct domain *d);int (*unmap_domain_irq) (struct domain *d,int irq,void *data); +int (*bind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind); +int (*unbind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind);int (*irq_permission) (struct domain *d,int pirq,uint8_t allow);int (*iomem_permission) (struct domain *d,uint64_t s,uint64_t e,uint8_t allow);int (*iomem_mapping) (struct domain *d,uint64_t s,uint64_t e,uint8_t allow);
@@ -178,8 +180,6 @@ struct xsm_operations {int (*mmuext_op) (struct domain *d,struct domain *f);int (*update_va_mapping) (struct domain *d,struct domain *f,l1_pgentry_t pte);int (*priv_mapping) (struct domain *d,struct domain *t); -int (*bind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind); -int (*unbind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind);int (*ioport_permission) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);#endif
@@ -428,6 +428,18 @@ static inline int xsm_unmap_domain_irq (xsm_default_t def, struct domain *d, intreturn xsm_ops->unmap_domain_irq (d, irq, data); } +static inline int xsm_bind_pt_irq (xsm_default_t def,struct domain *d, +struct xen_domctl_bind_pt_irq *bind) +{ +return xsm_ops->bind_pt_irq (d, bind); +} + +static inline int xsm_unbind_pt_irq (xsm_default_t def,struct domain *d, +struct xen_domctl_bind_pt_irq *bind) +{ +return xsm_ops->unbind_pt_irq (d, bind); +} +static inline int xsm_irq_permission (xsm_default_t def,struct domain *d,int pirq,uint8_t allow) {return xsm_ops->irq_permission (d, pirq, allow);
@@ -666,18 +678,6 @@ static inline int xsm_priv_mapping(xsm_default_t def, struct domain *d, struct dreturn xsm_ops->priv_mapping (d, t); } -static inline int xsm_bind_pt_irq (xsm_default_t def,struct domain *d, -struct xen_domctl_bind_pt_irq *bind) -{ -return xsm_ops->bind_pt_irq (d, bind); -} - -static inline int xsm_unbind_pt_irq (xsm_default_t def,struct domain *d, -struct xen_domctl_bind_pt_irq *bind) -{ -return xsm_ops->unbind_pt_irq (d, bind); -} -static inline int xsm_ioport_permission (xsm_default_t def,struct domain *d,uint32_t s,uint32_t e,uint8_t allow) {return xsm_ops->ioport_permission (d, s, e, allow);
xen/xsm/dummy.c +2 -2
@@ -81,6 +81,8 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, map_domain_irq);set_to_dummy_if_null (ops, unmap_domain_pirq);set_to_dummy_if_null (ops, unmap_domain_irq); +set_to_dummy_if_null (ops, bind_pt_irq); +set_to_dummy_if_null (ops, unbind_pt_irq);set_to_dummy_if_null (ops, irq_permission);set_to_dummy_if_null (ops, iomem_permission);set_to_dummy_if_null (ops, iomem_mapping);
@@ -149,8 +151,6 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, mmuext_op);set_to_dummy_if_null (ops, update_va_mapping);set_to_dummy_if_null (ops, priv_mapping); -set_to_dummy_if_null (ops, bind_pt_irq); -set_to_dummy_if_null (ops, unbind_pt_irq);set_to_dummy_if_null (ops, ioport_permission);set_to_dummy_if_null (ops, ioport_mapping);#endif
xen/xsm/flask/hooks.c +36 -34
104 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v6 5/19 xen: guestcopy: Provide an helper to safely copy string from guest
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Flask code already provides a 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 the buffer directly and use the macros provided by xen/err.h to return an error code if necessary.
---
Changes in v5:
- return a char* rather than a void*
- Use '\0' rather than 0
Changes in v4:
- Use -ENOBUFS rather than -ENOENT
- Fix coding style in comment
- Typoes in commit message
- Convert the new flask_copying_string (for DT) in safe_copy_string_from_guest
- Add Ian and Daniel's ack
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 | 31 ++++++++++++++++++++++++++ xen/include/xen/guest_access.h | 5 +++++ xen/xsm/flask/flask_op.c | 49 +++++++++++------------------------------- 4 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 xen/common/guestcopy.c
xen/common/Makefile +1 -0
@@ -9,6 +9,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 +31 -0
@@ -0,0 +1,31 @@ +#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. +*/ +char *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 (-ENOBUFS ); + +/* 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) +char *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 +13 -36
89 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v6 6/19 xen/dts: Provide an helper to get a DT node from a path provided by a guest
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The maximum size of the copied string has been chosen based on the value use by XSM in similar case.
Furthermore, Linux seems to allow path up to 4096 characters. Though this could vary from one OS to another.
---
Changes in v6:
- Add Ian's ack
Changes in v4:
- Drop DEVICE_TREE_MAX_PATHLEN
- Bump the value to PAGE_SIZE (i.e 4096). It's used in XSM and this value seems sensible for Linux
- Clarify how the maximum size has been chosen
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 | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+)
xen/common/device_tree.c +18 -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,22 @@ 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,PAGE_SIZE ); +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 +14 -0
@@ -456,6 +456,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
PATCH v6 7/19 xen/passthrough: Introduce iommu_construct
In reply to Julien GrallFrom: Julien Grall <[email protected]>
This 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 v5:
- Limit the scope of rc
- Add Jan's and Ian's ack
Changes in v4:
- Move memory_type_changed in iommu_construct. Added by commit 06ed8cc "x86: avoid needless EPT table ajustment and cache flush"
- And an ASSERT and a comment in iommu_assign_dt_device to explain why the call is safe for DOM0
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 | 12 ++++++++++++ xen/drivers/passthrough/iommu.c | 26 ++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 22 ++++------------------ xen/include/xen/iommu.h | 2 ++ 5 files changed, 50 insertions(+), 18 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 +12 -0
@@ -41,6 +41,18 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail; +if (need_iommu (d) <=0 ) + { +/* +* The hwdom is forced to use IOMMU for protecting assigned +* device. Therefore the IOMMU data is already set up. +*/ +ASSERT (!is_hardware_domain (d)); + 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 +26 -0
@@ -187,6 +187,32 @@ void iommu_teardown(struct domain *d)tasklet_schedule (&iommu_pt_cleanup_tasklet); } +int iommu_construct (struct domain *d) +{ +if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { +int rc; + + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; +/* +* There may be dirty cache lines when a device is assigned +* and before need_iommu(d) becoming true, this will cause +* memory_type_changed lose effect if memory type changes. +* Call memory_type_changed here to amend this. +*/ +memory_type_changed (d); + +return 0 ; +} +void iommu_domain_destroy (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
xen/drivers/passthrough/pci.c +4 -18
@@ -1358,25 +1358,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 ; -/* -* There may be dirty cache lines when a device is assigned -* and before need_iommu(d) becoming true, this will cause -* memory_type_changed lose effect if memory type changes. -* Call memory_type_changed here to amend this. -*/ -memory_type_changed (d); +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 v6 07/19] xen/passthrough: Introduce iommu_construct
Quoted 83 lines · Julien Grall
From: Julien Grall <[email protected]>
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]>Acked-by Jan Beulich <[email protected]>Acked-by Ian Campbell <[email protected]>---
Changes in v5:
- Limit the scope of rc
- Add Jan's and Ian's ackChanges in v4:
- Movememory_type_changediniommu_construct. Added by commit 06ed8cc "x86: avoid needless EPT table ajustment and cache flush"
- And an ASSERT and a comment iniommu_assign_dt_deviceto explain why the call is safe for DOM0Changes in v3:
- The ASSERT iniommu_constructwas redundant with the if ()
- Removed->need_iommu= 1 inassign_devicehas it's already done byiommu_construct.
- Simplify the code in the caller ofiommu_constructChanges in v2:
- Add missing Signed-off-by
- Renameiommu_builduptoiommu_construct--- xen/drivers/passthrough/arm/iommu.c | 6 ++++++ xen/drivers/passthrough/device_tree.c | 12 ++++++++++++ xen/drivers/passthrough/iommu.c | 26 ++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 22 ++++------------------ xen/include/xen/iommu.h | 2 ++ 5 files changed, 50 insertions(+), 18 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 +12
-0@@ -41,6 +41,18 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev)if ( !list_empty (&dev->domain_list) ) goto fail; +if (need_iommu (d) <=0 ) + { +/* +* The hwdom is forced to use IOMMU for protecting assigned +* device. Therefore the IOMMU data is already set up. +*/ +ASSERT (!is_hardware_domain (d)); + 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 +0
-0
xen/drivers/passthrough/iommu.c void iommu_teardown(struct domain *d) · line 191
Quoted 5 lines
xen/drivers/passthrough/iommu.c +2
-0@@ -187,6 +187,32 @@ void iommu_teardown(struct domain *d)tasklet_schedule (&iommu_pt_cleanup_tasklet); } +int iommu_construct (struct domain *d) +
What is the meaning of construct here. How it is different from init ?
Also iommu refers to iommu_domain or there is some other datastructure which is being updated ? Please write function header comments or use similar naming prefix in code.
Quoted 74 lines
xen/drivers/passthrough/iommu.c +24
-0+if (need_iommu (d) >0 ) +return 0 ; + +if ( !iommu_use_hap_pt (d) ) + { +int rc; + + rc =arch_iommu_populate_page_table (d); +if ( rc ) +return rc; + } + + d->need_iommu =1 ; +/* +* There may be dirty cache lines when a device is assigned +* and before need_iommu(d) becoming true, this will cause +* memory_type_changed lose effect if memory type changes. +* Call memory_type_changed here to amend this. +*/ +memory_type_changed (d); + +return 0 ; +} +void iommu_domain_destroy (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);xen/drivers/passthrough/pci.c +4
-18@@ -1358,25 +1358,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 ; -/* -* There may be dirty cache lines when a device is assigned -* and before need_iommu(d) becoming true, this will cause -* memory_type_changed lose effect if memory type changes. -* Call memory_type_changed here to amend this. -*/ -memory_type_changed (d); +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);
PATCH v6 8/19 xen/passthrough: arm: release the DT devices assigned to a guest earlier
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The toolstack may not have deassigned every device used by a guest. Therefore we have to go through the device list and remove 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 v5:
- Add Ian's ack
Changes in v4:
- Typoes in commit message
- Add Jan's ack
- iommu_release_dt_devices was only release the first device by mistake. Thanks for Robert VanVossen for spotting it.
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 | 7 ++++++- xen/include/xen/iommu.h | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/arm/domain.c +4 -0
@@ -795,6 +795,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;/* Fallthrough */
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 +6 -1
@@ -105,7 +105,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;
@@ -115,7 +115,12 @@ void iommu_dt_domain_destroy(struct domain *d) { rc =iommu_deassign_dt_device (d, dev);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
PATCH v6 9/19 xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody
In reply to Julien GrallFrom: Julien Grall <[email protected]>
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.
DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it.
---
Note: This behavior is documented in a following patch which extend DOMCT_*assign_device to support non-PCI passthrough.
Changes in v5:
- Add Ian's ack
Changes in v4:
- Add Stefano's ack
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
@@ -2692,7 +2692,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)
@@ -2702,6 +2702,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
@@ -80,15 +80,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
PATCH v6 10/19 xen/iommu: arm: Wire iommu DOMCTL for ARM
In reply to Julien GrallFrom: Julien Grall <[email protected]>
---
Changes in v4:
- Add Ian's ack
Changes in v3:
- Add Stefano's ack
Changes in v2:
- Don't move the call in common code.
--- xen/arch/arm/domctl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/arm/domctl.c +10 -1
@@ -109,7 +109,16 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,return 0 ; }default : -return subarch_do_domctl (domctl, d, u_domctl); + { +int rc; + + rc =subarch_do_domctl (domctl, d, u_domctl); + +if ( rc == -ENOSYS ) + rc =iommu_do_domctl (domctl, d, u_domctl); + +return rc; + } } }
Signature · 1 line
2.1.4
PATCH v6 11/19 xen/xsm: Add helpers to check permission for device tree passthrough
In reply to Julien GrallFrom: Julien Grall <[email protected]>
This is a follow-up of commit 525ee49 "xsm: add device tree labeling support" which add support for device tree labelling in flask.
Those helpers will be use latter when non-pci passthrough (i.e device tree) will be added.
---
Changes in v6:
- Rebase on the latest staging (conflict with in xsm/flask/hooks.c with memaccess changes)
Changes in v5:
- Add Ian and Daniel's ack
Changes in v4:
- Patch added
--- xen/include/xsm/dummy.h | 23 +++++++++++++ xen/include/xsm/xsm.h | 27 +++++++++++++++ xen/xsm/dummy.c | 6 ++++ xen/xsm/flask/avc.c | 3 ++ xen/xsm/flask/hooks.c | 69 ++++++++++++++++++++++++++++++++++++- xen/xsm/flask/include/avc.h | 2 ++ xen/xsm/flask/policy/access_vectors | 2 +- 7 files changed, 130 insertions(+), 2 deletions(-)
xen/include/xsm/dummy.h +23 -0
@@ -350,6 +350,29 @@ static XSM_INLINE int xsm_deassign_device(XSM_DEFAULT_ARG struct domain *d, uint#endif /* HAS_PASSTHROUGH && HAS_PCI */ +#if defined(HAS_PASSTHROUGH ) && defined(HAS_DEVICE_TREE ) +static XSM_INLINE int xsm_test_assign_dtdevice(XSM_DEFAULT_ARG const char *dtpath) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain,NULL ); +} + +static XSM_INLINE int xsm_assign_dtdevice(XSM_DEFAULT_ARG struct domain *d, +const char *dtpath) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + +static XSM_INLINE int xsm_deassign_dtdevice(XSM_DEFAULT_ARG struct domain *d, +const char *dtpath) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + +#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */ + static XSM_INLINE int xsm_resource_plug_core(XSM_DEFAULT_VOID) {XSM_ASSERT_ACTION (XSM_HOOK );
xen/include/xsm/xsm.h +27 -0
@@ -121,6 +121,12 @@ struct xsm_operations {int (*deassign_device) (struct domain *d,uint32_t machine_bdf);#endif +#if defined(HAS_PASSTHROUGH ) && defined(HAS_DEVICE_TREE ) +int (*test_assign_dtdevice) (const char *dtpath); +int (*assign_dtdevice) (struct domain *d,const char *dtpath); +int (*deassign_dtdevice) (struct domain *d,const char *dtpath); +#endif +int (*resource_plug_core) (void );int (*resource_unplug_core) (void );int (*resource_plug_pci) (uint32_t machine_bdf);
@@ -482,6 +488,27 @@ static inline int xsm_deassign_device(xsm_default_t def, struct domain *d, uint3 }#endif /* HAS_PASSTHROUGH && HAS_PCI) */ +#if defined(HAS_PASSTHROUGH ) && defined(HAS_DEVICE_TREE ) +static inline int xsm_assign_dtdevice (xsm_default_t def,struct domain *d, +const char *dtpath) +{ +return xsm_ops->assign_dtdevice (d, dtpath); +} + +static inline int xsm_test_assign_dtdevice (xsm_default_t def, +const char *dtpath) +{ +return xsm_ops->test_assign_dtdevice (dtpath); +} + +static inline int xsm_deassign_dtdevice (xsm_default_t def,struct domain *d, +const char *dtpath) +{ +return xsm_ops->deassign_dtdevice (d, dtpath); +} + +#endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */ +static inline int xsm_resource_plug_pci (xsm_default_t def,uint32_t machine_bdf) {return xsm_ops->resource_plug_pci (machine_bdf);
xen/xsm/dummy.c +6 -0
@@ -96,6 +96,12 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, deassign_device);#endif +#if defined(HAS_PASSTHROUGH ) && defined(HAS_DEVICE_TREE ) +set_to_dummy_if_null (ops, test_assign_dtdevice); +set_to_dummy_if_null (ops, assign_dtdevice); +set_to_dummy_if_null (ops, deassign_dtdevice); +#endif +set_to_dummy_if_null (ops, resource_plug_core);set_to_dummy_if_null (ops, resource_unplug_core);set_to_dummy_if_null (ops, resource_plug_pci);
xen/xsm/flask/avc.c +3 -0
@@ -600,6 +600,9 @@ void avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 requested,case AVC_AUDIT_DATA_MEMORY :avc_printk (&buf,"pte=%#lx mfn=%#lx " , a->memory.pte, a->memory.mfn);break ; +case AVC_AUDIT_DATA_DTDEV : +avc_printk (&buf,"dtdevice=%s " , a->dtdev); +break ; }avc_dump_query (&buf, ssid, tsid, tclass);
xen/xsm/flask/hooks.c +68 -1
87 lines not on this page · raw message
xen/xsm/flask/include/avc.h +2 -0
@@ -39,6 +39,7 @@ struct avc_audit_data {#define AVC_AUDIT_DATA_IRQ 2#define AVC_AUDIT_DATA_RANGE 3#define AVC_AUDIT_DATA_MEMORY 4 +#define AVC_AUDIT_DATA_DTDEV 5struct domain *sdom;struct domain *tdom;union {
@@ -52,6 +53,7 @@ struct avc_audit_data {unsigned long pte;unsigned long mfn; } memory; +const char *dtdev; }; };
xen/xsm/flask/policy/access_vectors +1 -1
@@ -424,7 +424,7 @@ class resource remove_iomem # XEN_DOMCTL_get_device_group, XEN_DOMCTL_test_assign_device: # source = domain making the hypercall -# target = PCI device being queried +# target = device being queried stat_device # XEN_DOMCTL_assign_device add_device
Signature · 1 line
2.1.4
PATCH v6 12/19 xen/passthrough: Extend XEN_DOMCTL_*assign_device to support DT device
In reply to Julien GrallFrom: Julien Grall <[email protected]>
A device node is described by a path. It will be used to retrieve the node in the device tree and assign the related device to the domain.
Only non-PCI devices protected by an IOMMU can be assigned to a guest.
Also document the behavior of XEN_DOMCTL_deassign_device in the public headers which differ between non-PCI and PCI.
---
Changes in v6:
- Fix typo and add missing word in commit message
- Add Ian's ack
Changes in v5:
- Fix comment in public/domctl.h
- Remove unecessary comment in drivers/passthrough/device_tree.c
- Check d->is_dying before assigning a device (consistency with PCI code)
- Invert the if in iommu.c in order to avoid extra return
- Add Jan's ack for non-ARM part
Changes in v4:
- Add XSM bits
- Return -ENODEV rather than -ENOSYS
- Move the if (...) into the ifdef (see iommu.c)
- Document the behavior of XEN_DOMCTL_deassign_device
- Use PCI_BUS and PCI_DEVFN2 when it's possible
- iommu_dt_device_is_assigned now returns 0 when the device is not protected
Changes in v2:
- Use a different number for XEN_DOMCTL_assign_dt_device
--- tools/libxc/include/xenctrl.h | 10 ++++ tools/libxc/xc_domain.c | 95 ++++++++++++++++++++++++++++-- xen/drivers/passthrough/device_tree.c | 108 +++++++++++++++++++++++++++++++++- xen/drivers/passthrough/iommu.c | 7 ++- xen/drivers/passthrough/pci.c | 47 ++++++++++----- xen/include/public/domctl.h | 24 +++++++- xen/include/xen/iommu.h | 3 + 7 files changed, 269 insertions(+), 25 deletions(-)
tools/libxc/include/xenctrl.h +10 -0
@@ -2058,6 +2058,16 @@ int xc_deassign_device(xc_interface *xch,uint32_t domid, uint32_t machine_sbdf); +int xc_assign_dt_device (xc_interface *xch, +uint32_t domid, +char *path); +int xc_test_assign_dt_device (xc_interface *xch, +uint32_t domid, +char *path); +int xc_deassign_dt_device (xc_interface *xch, +uint32_t domid, +char *path); + int xc_domain_memory_mapping(xc_interface *xch, uint32_t domid, unsigned long first_gfn,
tools/libxc/xc_domain.c +91 -4
116 lines not on this page · raw message
xen/drivers/passthrough/device_tree.c +105 -3
131 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +6 -1
@@ -335,7 +335,7 @@ int iommu_do_domctl( struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { - int ret = -ENOSYS; + int ret = -ENODEV;if ( !iommu_enabled )return -ENOSYS ;
@@ -344,6 +344,11 @@ int iommu_do_domctl( ret =iommu_do_pci_domctl (domctl, d, u_domctl);#endif +#ifdef HAS_DEVICE_TREE +if ( ret == -ENODEV ) + ret =iommu_do_dt_domctl (domctl, d, u_domctl); +#endif +return ret; }
xen/drivers/passthrough/pci.c +33 -14
92 lines not on this page · raw message
xen/include/public/domctl.h +21 -3
@@ -475,12 +475,30 @@ typedef struct xen_domctl_sendtrigger xen_domctl_sendtrigger_t;DEFINE_XEN_GUEST_HANDLE (xen_domctl_sendtrigger_t); -/* Assign PCI device to HVM guest. Sets up IOMMU structures. */ +/* Assign a device to a guest. Sets up IOMMU structures. */ /* XEN_DOMCTL_assign_device */ /* XEN_DOMCTL_test_assign_device */ -/* XEN_DOMCTL_deassign_device */ +/* +* XEN_DOMCTL_deassign_device: The behavior of this DOMCTL differs +* between the different type of device: +* - PCI device (XEN_DOMCTL_DEV_PCI) will be reassigned to DOM0 +* - DT device (XEN_DOMCTL_DT_PCI) will left unassigned. DOM0 +* will have to call XEN_DOMCTL_assign_device in order to use the +* device. +*/ +#define XEN_DOMCTL_DEV_PCI 0 +#define XEN_DOMCTL_DEV_DT 1struct xen_domctl_assign_device { -uint32_t machine_sbdf;/* machine PCI ID of assigned device */ +uint32_t dev;/* XEN_DOMCTL_DEV_* */ +union { +struct { +uint32_t machine_sbdf;/* machine PCI ID of assigned device */ + } pci; +struct { +uint32_t size;/* Length of the path */ +XEN_GUEST_HANDLE_64 (char ) path;/* path to the device tree node */ + } dt; + } u; };typedef struct xen_domctl_assign_device xen_domctl_assign_device_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_assign_device_t);
xen/include/xen/iommu.h +3 -0
@@ -119,6 +119,9 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev);int iommu_dt_domain_init (struct domain *d);int iommu_release_dt_devices (struct domain *d); +int iommu_do_dt_domctl (struct xen_domctl *,struct domain *, +XEN_GUEST_HANDLE_PARAM (xen_domctl_t )); +#endif /* HAS_DEVICE_TREE */ struct page_info ;
Signature · 1 line
2.1.4
PATCH v6 13/19 tools/libxl: Create a per-arch function to map IRQ to a domain
In reply to Julien GrallFrom: Julien Grall <[email protected]>
ARM and x86 use a different hypercall to map an IRQ to a domain.
The hypercall to give IRQ permission to the domain has also been moved to be an x86 specific function as ARM guest won't be able to manage the IRQ. We may want to support it later.
---
Changes in v6:
- Update the call to xc_domain_bind_pt_spi_irq according to the new protype
- Add Ian's ack
Changes in v5:
- Use the new function xc_domain_bind_pt_spi_irq
- Fix typoes
Changes in v4:
- Patch added
--- tools/libxl/libxl_arch.h | 4 ++++ tools/libxl/libxl_arm.c | 5 +++++ tools/libxl/libxl_create.c | 6 ++---- tools/libxl/libxl_x86.c | 13 +++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-)
tools/libxl/libxl_arch.h +4 -0
@@ -39,4 +39,8 @@ int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,uint32_t domid, libxl_domain_build_info *b_info, libxl__domain_build_state *state); + +/* arch specific irq map function */ +int libxl__arch_domain_map_irq (libxl__gc *gc,uint32_t domid,int irq); +#endif
tools/libxl/libxl_arm.c +5 -0
@@ -742,6 +742,11 @@ int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,return libxl__vnuma_build_vmemrange_pv_generic (gc, domid, info, state); } +int libxl__arch_domain_map_irq (libxl__gc *gc,uint32_t domid,int irq) +{ +return xc_domain_bind_pt_spi_irq (CTX ->xch, domid, irq, irq); +} +/* * Local variables: * mode: C
tools/libxl/libxl_create.c +2 -4
@@ -1205,11 +1205,9 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,LOG (DEBUG ,"dom%d irq %d" , domid, irq); - ret = irq >=0 ?xc_physdev_map_pirq (CTX ->xch, domid, irq, &irq) + ret = irq >=0 ?libxl__arch_domain_map_irq (gc, domid, irq) : -EOVERFLOW ; -if (!ret) - ret =xc_domain_irq_permission (CTX ->xch, domid, irq,1 ); -if (ret <0 ) { +if (ret) {LOGE (ERROR ,"failed give dom%d access to irq %d" , domid, irq); ret =ERROR_FAIL ; goto error_out;
tools/libxl/libxl_x86.c +13 -0
@@ -424,6 +424,19 @@ out:return rc; } +int libxl__arch_domain_map_irq (libxl__gc *gc,uint32_t domid,int irq) +{ +int ret; + + ret =xc_physdev_map_pirq (CTX ->xch, domid, irq, &irq); +if (ret) +return ret; + + ret =xc_domain_irq_permission (CTX ->xch, domid, irq,1 ); + +return ret; +} +/* * Local variables: * mode: C
Signature · 1 line
2.1.4
PATCH v6 14/19 tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The functions fdt_{fisrt,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...
The later has been fixed recently in the dtc repo [1]
When the functions are not available, implement our own in order to use them in a following patch.
[1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git
commit a4b093f7366fdb429ca1781144d3985fa50d0fbb
---
tools/configure needs to be regenerate as this patch is modifying tools/configure.ac
Changes in v6:
- Add Ian's Ack
Changes in v5:
- Add Ian's Signed-off-by for the license part and update the license
- Rename libxl_fdt to libxl_libfdt_compat.c
Changes in v4:
- Patch added
--- tools/config.h.in | 6 +++ tools/configure.ac | 5 +++ tools/libxl/Makefile | 2 +- tools/libxl/libxl_libfdt_compat.c | 92 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_libfdt_compat.c
tools/config.h.in +6 -0
@@ -3,6 +3,12 @@ /* Blktap2 enabled */ #undef HAVE_BLKTAP2 +/* Define to 1 if you have the `fdt_first_subnode' function. */ +#undef HAVE_FDT_FIRST_SUBNODE + +/* Define to 1 if you have the `fdt_next_subnode' function. */ +#undef HAVE_FDT_NEXT_SUBNODE + /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H
tools/configure.ac +5 -0
@@ -355,6 +355,11 @@ AC_SUBST(libiconv) case "$host_cpu" in arm*|aarch64) AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])]) + +# The functions fdt_{first,next}_subnode may not be available because: +# * It has been introduced in 2013 => Doesn't work on Wheezy +# * The prototype exists but the functions are not exposed. Don't ask why... +AC_CHECK_FUNCS([fdt_first_subnode fdt_next_subnode]) esac # Checks for header files.
tools/libxl/Makefile +1 -1
@@ -59,7 +59,7 @@ endif LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o -LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o +LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o ifeq ($(CONFIG_NetBSD),y) LIBXL_OBJS-y += libxl_netbsd.o
tools/libxl/libxl_libfdt_compat.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v6 14/19] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 15 lines · Julien Grall
From: Julien Grall <[email protected]>
The functions fdt_{fisrt,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...The later has been fixed recently in the dtc repo [1]
When the functions are not available, implement our own in order to use them in a following patch.
[1]
git://git.kernel.org/pub/scm/utils/dtc/dtc.gitcommit a4b093f7366fdb429ca1781144d3985fa50d0fbb
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>---
tools/configureneeds to be regenerate as this patch is modifyingtools/configure.ac
Even with that I get on both 32 and 64-bit:
arm32:
libxl_libfdt_compat.c:63:5: error: no previous declaration for ‘fdt_first_subnode’ [-Werror=missing-declarations] libxl_libfdt_compat.c:76:5: error: no previous declaration for ‘fdt_next_subnode’ [-Werror=missing-declarations]
cc1: all warnings being treated as errors
arm64:
libxl_libfdt_compat.c:63:5: error: no previous declaration for 'fdt_first_subnode' [-Werror=missing-declarations]
int fdt_first_subnode(const void *fdt, int offset)
^
libxl_libfdt_compat.c:76:5: error: no previous declaration for 'fdt_next_subnode' [-Werror=missing-declarations]
int fdt_next_subnode(const void *fdt, int offset)
^cc1: all warnings being treated as errors
Is a file missing? I expected some compat in a .h file too.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 14/19] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 37 lines · Ian Campbell
Quoted 15 lines · Julien Grall
From: Julien Grall <[email protected]>
The functions fdt_{fisrt,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...The later has been fixed recently in the dtc repo [1]
When the functions are not available, implement our own in order to use them in a following patch.
[1]
git://git.kernel.org/pub/scm/utils/dtc/dtc.gitcommit a4b093f7366fdb429ca1781144d3985fa50d0fbbQuoted 8 lines
Signed-off-by Julien Grall <[email protected]>Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>---
tools/configureneeds to be regenerate as this patch is modifyingtools/configure.acEven with that I get on both 32 and 64-bit:
arm32:
libxl_libfdt_compat.c:63:5: error: no previous declaration for ‘fdt_first_subnode’ [-Werror=missing-declarations] libxl_libfdt_compat.c:76:5: error: no previous declaration for ‘fdt_next_subnode’ [-Werror=missing-declarations]
cc1: all warnings being treated as errorsarm64:
libxl_libfdt_compat.c:63:5: error: no previous declaration for '
fdt_first_subnode' [-Werror=missing-declarations]
intfdt_first_subnode(const void *fdt, int offset)
Quoted 7 lines
^ libxl_libfdt_compat.c:76:5: error: no previous declaration for 'fdt_next_subnode' [-Werror=missing-declarations] int fdt_next_subnode(const void *fdt, int offset) ^cc1: all warnings being treated as errors
Is a file missing? I expected some compat in a .h file too.
I forgot to test it on a platform where the function is not present in both the header and the library.
I will see if I can detect via the configure when the function is not present in the headers.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 15/19 tools/(lib)xl: Add partial device tree support for ARM
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Allow the user to pass additional nodes to the guest device tree. For this purpose, everything in the node /passthrough from the partial device tree will be copied into the guest device tree.
The node /aliases will be also copied to allow the user to define aliases which can be used by the guest kernel.
A simple partial device tree will look like:
/dts-v1/;
/ {
#address-cells = <2>;
#size-cells = <2>;
passthrough {
compatible = "simple-bus";
ranges;
#address-cells = <2>;
#size-cells = <2>;
/* List of your nodes */
}
};Note that:
* The interrupt-parent property will be added by the toolstack in the root node
* The properties compatible, ranges, #address-cells and #size-cells in /passthrough are mandatory.
The helpers provided by the libfdt don't perform all the necessary security check on a given device tree. Therefore, only trusted device tree should be used.
---
An example of the partial device tree, as long as how to passthrough a non-pci device will be added to the tree in a follow-up patch.
A new LIBXL_HAVE_* will be added in the patch which add support for non-PCI passthrough as both are tight.
Changes in v6:
- Fix grammar in the commit message
- Spelling mistake the IDL
- Add Ian J. and Ian C.'s ack
Changes in v5:
- Add a warning in the IDL
- Remove the requirement to use only the version 17 of the FDT format.
Changes in v4:
- Mark the option as unsafe
- The _fdt_* helpers has been moved in a separate patch/file. Only the prototype is declared
- The partial DT is considered valid. Remove some security check which make the code cleaner
- Typoes
Changes in v3:
- Patch added
--- docs/man/xl.cfg.pod.5 | 10 +++ tools/libxl/libxl_arm.c | 157 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 4 ++ tools/libxl/xl_cmdimpl.c | 1 + 4 files changed, 172 insertions(+)
docs/man/xl.cfg.pod.5 +10 -0
@@ -460,6 +460,16 @@ not emulated. Specify that this domain is a driver domain. This enables certain features needed in order to run a driver domain. +=item B<device_tree=PATH> + +Specify a partial device tree (compiled via the Device Tree Compiler). +Everything under the node "/passthrough" will be copied into the guest +device tree. For convenience, the node "/aliases" is also copied to allow +the user to defined aliases which can be used by the guest kernel. + +Given the complexity of verifying the validity of a device tree, this +option should only be used with trusted device tree. + =back =head2 Devices
tools/libxl/libxl_arm.c +157 -0
183 lines not on this page · raw message
tools/libxl/libxl_types.idl +4 -0
@@ -412,6 +412,10 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("kernel", string), ("cmdline", string), ("ramdisk", string), + # Given the complexity of verifying the validity of a device tree, + # libxl doesn't do any security check on it. It's the responsibility + # of the caller to provide only trusted device tree. + ("device_tree", string), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),
tools/libxl/xl_cmdimpl.c +1 -0
@@ -1379,6 +1379,7 @@ static void parse_config_data(const char *config_source,xlu_cfg_replace_string (config,"kernel" , &b_info->kernel,0 );xlu_cfg_replace_string (config,"ramdisk" , &b_info->ramdisk,0 ); +xlu_cfg_replace_string (config,"device_tree" , &b_info->device_tree,0 ); b_info->cmdline =parse_cmdline (config);xlu_cfg_get_defbool (config,"driver_domain" , &c_info->driver_domain,0 );
Signature · 1 line
2.1.4
PATCH v6 16/19 tools/libxl: arm: Use an higher value for the GIC phandle
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The partial device tree may contains phandle. The Device Tree Compiler tends to allocate the phandle from 1.
Reserve the ID 65000 for the GIC phandle. I think we can safely assume that the partial device tree will never contain a such ID.
---
To allocate dynamically the phandle, we would need to fill in post-hoc (like we do with e.g the initramfs location) the #interrupt-parent in "/". That would also require some refactoring in the code to pass the phandle every time.
Defer this solution to a follow-up in order as having 65000 would be very unlikely.
Changes in v6:
- Add a note in the doc about the reserved phandle
Changes in v5:
- Add Ian C.'s Ack.
Changes in v3:
- Patch added
--- docs/man/xl.cfg.pod.5 | 3 +++ tools/libxl/libxl_arm.c | 9 +++++---- tools/libxl/libxl_types.idl | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5 +3 -0
@@ -470,6 +470,9 @@ the user to defined aliases which can be used by the guest kernel. Given the complexity of verifying the validity of a device tree, this option should only be used with trusted device tree. +Note that the partial device tree should avoid to use the phandle 65000 +which is reserved by the toolstack. + =back =head2 Devices
tools/libxl/libxl_arm.c +5 -4
@@ -80,10 +80,11 @@ static struct arch_info { {"xen-3.0-aarch64", "arm,armv8-timer", "arm,armv8" }, }; -enum { -PHANDLE_NONE =0 , -PHANDLE_GIC , -}; +/* +* The device tree compiler (DTC) is allocating the phandle from 1 to +* onwards. Reserve a high value for the GIC phandle. +*/ +#define PHANDLE_GIC (65000)typedef uint32_t be32 ;typedef be32 gic_interrupt [3 ];
tools/libxl/libxl_types.idl +2 -0
@@ -415,6 +415,8 @@ libxl_domain_build_info = Struct("domain_build_info",[ # Given the complexity of verifying the validity of a device tree, # libxl doesn't do any security check on it. It's the responsibility # of the caller to provide only trusted device tree. + # Note that the partial device tree should avoid to use the phandle + # 65000 which is reserved by the toolstack. ("device_tree", string), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string),
Signature · 1 line
2.1.4
PATCH v6 17/19 libxl: Add support for Device Tree passthrough
In reply to Julien GrallFrom: Julien Grall <[email protected]>
On ARM, every non-PCI device are described in the device tree. Each of them can be found via a path.
This patch introduces a very basic support, only the IOMMU will be set up correctly. The user will have to:
- Describe the device in the partial device tree
- Map manually MMIO/IRQ
This is a first approach, that will allow to have a basic Device Tree passthrough support in Xen. This could be improved later.
Furthermore add LIBXL_HAVE_DEVICETREE_PASSTHROUGH to indicate we support Device Tree passthrough and partial device tree (introduced by a previous patch).
---
Changes in v6:
- Add Ian C. and Ian J.'s ack
Changes in v5:
- Replace some "non-PCI" to "Device Tree"
Changes in v4:
- Add LIBXL_HAVE_DEVICTREE_PASSTHROUGH to indicate we support non-PCI passthrough. This is also used in order to indicate partial device tree is supported
- Remove libxl_dtdev.c as it contains only a 2 lines functions and call directly xc_* from libxl_create.c
- Introduce domcreate_attach_dtdev
Changes in v3:
- Dynamic allocation has been dropped
- Rework the commit message in accordance with the previous item
Changes in v2:
- Get DT infos earlier
- Allocate/map IRQ in libxl__arch_domain_create rather than in libxl__device_dt_add
- Use VIRQ rather than the PIRQ to construct the interrupts properties of the device tree
- Correct cpumask in make_dtdev_node. We allow the interrupt to be used on the 8 CPUs
- Fix LOGE when we map the MMIO region in the guest in libxl__device_dt_add. The domain and the IRQ were inverted
- Calculate the number of SPIs to configure the VGIC
- xc_physdev_dtdev_* helpers has been renamed to xc_dtdev_*
- Rename libxl_device_dt to libxl_device_dtdev
--- tools/libxl/libxl.h | 7 +++++++ tools/libxl/libxl_create.c | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 5 +++++ tools/libxl/libxl_types.idl | 5 +++++ 4 files changed, 49 insertions(+)
tools/libxl/libxl.h +7 -0
@@ -192,6 +192,13 @@* is not present, instead of ERROR_INVAL. */ #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1 + +/* +* libxl_domain_build_info has device_tree and libxl_device_dtdev +* exists. This mean Device Tree passthrough is supported for ARM +*/ +#define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +/* * libxl ABI compatibility *
tools/libxl/libxl_create.c +32 -0
@@ -751,6 +751,8 @@ static void domcreate_attach_vtpms(libxl__egc *egc, libxl__multidev *multidev, int ret);static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *aodevs,int ret); +static void domcreate_attach_dtdev (libxl__egc *egc, +libxl__domain_create_state *dcs);static void domcreate_console_available (libxl__egc *egc,libxl__domain_create_state *dcs);
@@ -1444,6 +1446,36 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev, } } +domcreate_attach_dtdev (egc, dcs); +return ; + +error_out: +assert (ret); +domcreate_complete (egc, dcs, ret); +} + +static void domcreate_attach_dtdev (libxl__egc *egc, +libxl__domain_create_state *dcs) +{ +STATE_AO_GC (dcs->ao); +int i; +int ret; +int domid = dcs->guest_domid; + +/* convenience aliases */ +libxl_domain_config *const d_config = dcs->guest_config; + +for (i =0 ; i < d_config->num_dtdevs; i++) { +const libxl_device_dtdev *dtdev = &d_config->dtdevs[i]; + +LOG (DEBUG ,"Assign device \"%s\" to dom%u" , dtdev->path, domid); + ret =xc_assign_dt_device (CTX ->xch, domid, dtdev->path); +if (ret <0 ) { +LOG (ERROR ,"xc_assign_dtdevice failed: %d\n" , ret); + goto error_out; + } + } +domcreate_console_available (egc, dcs);domcreate_complete (egc, dcs,0 );
tools/libxl/libxl_internal.h +5 -0
@@ -1203,6 +1203,11 @@ _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num); _hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); +/* from libxl_dtdev */ + +_hidden int libxl__device_dt_add(libxl__gc *gc, uint32_t domid, +const libxl_device_dtdev *dtdev); +/*----- xswait: wait for a xenstore node to be suitable -----*/ typedef struct libxl__xswait_state libxl__xswait_state ;
tools/libxl/libxl_types.idl +5 -0
@@ -540,6 +540,10 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_dtdev = Struct("device_dtdev", [ + ("path", string), + ]) + libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),
@@ -566,6 +570,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
Signature · 1 line
2.1.4
PATCH v6 18/19 xl: Add new option dtdev
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The option "dtdev" will be used to passthrough a device described in the device tree to a guest.
---
Changes in v5:
- Drop "non-PCI" in the commit message
- Add Ian's ack
Changes in v4:
- Typoes in the documentation
- Wrap the line in xl_cmdimpl.c
Changes in v2:
- libxl_device_dt has been rename to libxl_device_dtdev
- use xrealloc instead of realloc
--- docs/man/xl.cfg.pod.5 | 5 +++++ tools/libxl/xl_cmdimpl.c | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +5 -0
@@ -789,6 +789,11 @@ More information about Xen gfx_passthru feature is available on the XenVGAPassthrough L<http://wiki.xen.org/wiki/XenVGAPassthrough> wiki page. +=item B<dtdev=[ "DTDEV_PATH", "DTDEV_PATH", ... ]> + +Specifies the host device tree nodes to passthrough to this guest. Each +DTDEV_PATH is the absolute path in the device tree. + =item B<ioports=[ "IOPORT_RANGE", "IOPORT_RANGE", ... ]> Allow guest to access specific legacy I/O ports. Each B<IOPORT_RANGE>
tools/libxl/xl_cmdimpl.c +21 -1
@@ -1169,7 +1169,7 @@ static void parse_config_data(const char *config_source,long l, vcpus =0 ;XLU_Config *config;XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; -XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian; +XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs;int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian;int pci_power_mgmt =0 ;int pci_msitranslate =0 ;
@@ -1941,6 +1941,26 @@ skip_vfb:libxl_defbool_set (&b_info->u.pv.e820_host, true); } +if (!xlu_cfg_get_list (config,"dtdev" , &dtdevs,0 ,0 )) { + d_config->num_dtdevs =0 ; + d_config->dtdevs =NULL ; +for (i =0 ; (buf =xlu_cfg_get_listitem (dtdevs, i)) !=NULL ; i++) { +libxl_device_dtdev *dtdev; + + d_config->dtdevs =xrealloc (d_config->dtdevs, +sizeof (libxl_device_dtdev) * (i +1 )); + dtdev = d_config->dtdevs + d_config->num_dtdevs; +libxl_device_dtdev_init (dtdev); + + dtdev->path =strdup (buf); +if (dtdev->path ==NULL ) { +fprintf (stderr,"unable to duplicate string for dtdevs\n" ); +exit (-1 ); + } + d_config->num_dtdevs++; + } + } +switch (xlu_cfg_get_list (config,"cpuid" , &cpuids,0 ,1 )) {case 0 : {
Signature · 1 line
2.1.4
PATCH v6 19/19 docs/misc: arm: Add documentation about Device Tree passthrough
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Note that the example is done on Midway whose SMMU driver is not supported on Xen upstream.
Currently, I don't have other platform where I can test Device Tree passthrough.
---
Changes in v6:
- Typo in the doc
- Add a link to http://www.devicetree.org/Device_Tree_Usage
- Add Ian's ack
Changes in v5:
- Drop references to "non-PCI" in favor of "Device Tree"
- Typoes and update the docs
Changes in v4:
- Patch added
--- docs/misc/arm/passthrough.txt | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 docs/misc/arm/passthrough.txt
docs/misc/arm/passthrough.txt new file +63 -0
@@ -0,0 +1,63 @@ +Passthrough a device described in the Device Tree to a guest +============================================================ + +The example will use the secondary network card for the midway server. + +1) Mark the device to let Xen know 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 a partial device tree describing the device. The IRQ are mapped +1:1 to the guest (i.e VIRQ == IRQ). For MMIO, you will have to find a hole +in the guest memory layout (see xen/include/public/arch-arm.h, note that +the layout is not stable and can change between versions of Xen). + +/dts-v1/; + +/ { + /* #*cells are here to keep DTC happy */ + #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>; + }; + }; +}; + +Note: + * The interrupt-parent property will be added by the toolstack in the + root node; + * The following properties are mandatory with the /passthrough node: + - compatible: It should always contain "simple-bus" + - ranges + - #address-cells + - #size-cells + * See http://www.devicetree.org/Device_Tree_Usage for more + information about device tree. + +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" ] + +
Signature · 1 line
2.1.4
Quoted 4 lines · Julien Grall
Hello all,
This is the sixth version of this patch series to add support for platform device passthrough on ARM.
Jan,
Quoted 1 line
From my side this is all acked, and I think you've acked everything you
are interested in apart from perhaps:
[PATCH v6 05/19] xen: guestcopy: Provide an helper to safely copy string from guest
which I think you looked happy with last time you commented but you
haven't formally acked so I just wanted to give you a chance to object before I commit early next week.
Ian.
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 15:48, <[email protected]> wrote:
Quoted 2 lines · Julien Grall
This is the sixth version of this patch series to add support for platform device passthrough on ARM.
Quoted 7 lines
From my side this is all acked, and I think you've acked everything you are interested in apart from perhaps:
[PATCH v6 05/19] xen: guestcopy: Provide an helper to safely copy
string from guest
which I think you looked happy with last time you commented but you haven't formally acked so I just wanted to give you a chance to object before I commit early next week.
Fine with me - I saw it acked by you, which is sufficient for common code changes, and hence didn't feel the need to add mine.
Jan
Quoted 13 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 15:48, <[email protected]> wrote:
Quoted 2 lines · Julien Grall
This is the sixth version of this patch series to add support for platform device passthrough on ARM.
Quoted 7 lines
From my side this is all acked, and I think you've acked everything you are interested in apart from perhaps:
[PATCH v6 05/19] xen: guestcopy: Provide an helper to safely copy
string from guest
which I think you looked happy with last time you commented but you haven't formally acked so I just wanted to give you a chance to object before I commit early next week.
Quoted 3 lines
Fine with me - I saw it acked by you, which is sufficient for common code changes, and hence didn't feel the need to add mine.
Thanks, just wanted to check.
I was going to apply but there was an error which I'll reply to Julien about...
Ian.
Quoted 4 lines · Julien Grall
Hello all,
This is the sixth version of this patch series to add support for platform device passthrough on ARM.
I've applied up to but not including "tools/libxl: Check if fdt_{first,next}_subnode are present in libfdt" which I've replied to you about.
Ian.