Enable PCI passthru for HVM guest
PATCH 3/4 Enable PCI passthru for HVM guest
3-passthru-xen.patch: passthru support, modifications to in xen and vtd code
Signed-off-by Wei Wang <[email protected]>
xen/arch/x86/domain.c +7 -0
@@ -46,6 +46,7 @@#include <asm/msr.h> #include <asm/nmi.h> #include <asm/iommu.h> +#include <asm/amd-iommu.h> #ifdef CONFIG_COMPAT #include <compat/vcpu.h> #endif
@@ -518,11 +519,15 @@ int arch_domain_create(struct domain *d)if ( (rc =iommu_domain_init (d)) !=0 ) goto fail; +if ( (rc =amd_iommu_domain_init (d)) !=0 ) + goto fail; +if (is_hvm_domain (d) ) {if ( (rc =hvm_domain_initialise (d)) !=0 ) {iommu_domain_destroy (d); +amd_iommu_domain_destroy (d); goto fail; } }
@@ -555,6 +560,8 @@ void arch_domain_destroy(struct domain *hvm_domain_destroy (d);iommu_domain_destroy (d); + +amd_iommu_domain_destroy (d);paging_final_teardown (d);
xen/arch/x86/domctl.c +8 -3
@@ -27,6 +27,7 @@#include <asm/processor.h> #include <xsm/xsm.h> #include <asm/iommu.h> +#include <asm/amd-iommu.h> long arch_do_domctl( struct xen_domctl *domctl,
@@ -532,7 +533,7 @@ long arch_do_domctl(u8 bus, devfn; ret = -EINVAL ; -if ( !vtd_enabled ) +if ( !vtd_enabled && !amd_iommu_enabled )break ;if (unlikely ((d =get_domain_by_id (domctl->domain)) ==NULL ) )
@@ -548,7 +549,11 @@ long arch_do_domctl(if (device_assigned (bus, devfn) )break ; - ret =assign_device (d, bus, devfn); +if ( vtd_enabled ) + ret =assign_device (d, bus, devfn); +else if ( amd_iommu_enabled ) + ret =amd_iommu_assign_device (d, bus, devfn); +gdprintk (XENLOG_INFO ,"XEN_DOMCTL_assign_device: bdf = %x:%x:%x\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn));put_domain (d);
@@ -564,7 +569,7 @@ long arch_do_domctl(if ( (d =rcu_lock_domain_by_id (domctl->domain)) ==NULL )break ; bind = &(domctl->u.bind_pt_irq); -if (vtd_enabled) +if ( vtd_enabled || amd_iommu_enabled ) ret =pt_irq_create_bind_vtd (d, bind);if (ret <0 )gdprintk (XENLOG_ERR ,"pt_irq_create_bind failed!\n" );
xen/arch/x86/hvm/svm/intr.c +41 -0
53 lines not on this page · raw message
xen/arch/x86/hvm/vioapic.c +1 -1
@@ -458,7 +458,7 @@ void vioapic_update_EOI(struct domain *d ent->fields.remote_irr =0 ; -if ( vtd_enabled ) +if ( vtd_enabled || amd_iommu_enabled ) {spin_unlock (&d->arch.hvm_domain.irq_lock);hvm_dpci_eoi (current->domain, gsi, ent);
xen/arch/x86/hvm/vmx/vtd/io.c +3 -3
@@ -141,7 +141,7 @@ int hvm_do_IRQ_dpci(struct domain *d, un {struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq; -if ( !vtd_enabled || (d == dom0) || (hvm_irq->dpci ==NULL ) || +if ( (!vtd_enabled && !amd_iommu_enabled) || (d == dom0) || (hvm_irq->dpci ==NULL ) || !hvm_irq->dpci->mirq[mirq].valid )return 0 ;
@@ -167,7 +167,7 @@ static void hvm_dpci_isairq_eoi(struct dint i;ASSERT (isairq <NR_ISAIRQS ); -if ( !vtd_enabled || !dpci || +if ( (!vtd_enabled && !amd_iommu_enabled) || !dpci || !test_bit (isairq, dpci->isairq_map) )return ;
@@ -205,7 +205,7 @@ void hvm_dpci_eoi(struct domain *d, unsistruct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;uint32_t device, intx, machine_gsi; -if ( !vtd_enabled || (hvm_irq_dpci ==NULL ) || +if ( (!vtd_enabled && !amd_iommu_enabled) || (hvm_irq_dpci ==NULL ) || (guest_gsi >=NR_ISAIRQS && !hvm_irq_dpci->girq[guest_gsi].valid) )return ;
xen/arch/x86/mm/p2m.c +9 -0
@@ -28,6 +28,7 @@#include <asm/paging.h> #include <asm/p2m.h> #include <asm/iommu.h> +#include <asm/amd-iommu.h> /* Debugging and auditing of the P2M code? */ #define P2M_AUDIT 0
@@ -257,6 +258,14 @@ set_p2m_entry(struct domain *d, unsignedif ( vtd_enabled && (p2mt == p2m_mmio_direct) &&is_hvm_domain (d) )iommu_flush (d, gfn, (u64 *)p2m_entry); + +if ( amd_iommu_enabled &&is_hvm_domain (d) && (p2mt != p2m_mmio_direct)) + { +if (mfn_valid (mfn) ) +amd_iommu_map_page (d, gfn,mfn_x (mfn)); +else +amd_iommu_unmap_page (d, gfn); + }/* Success */ rv =1 ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel