direct-io.hg

changeset 15533:ef0a4a57523c

allen: fixed hvm guest restart and multiple PCI device assignment problems
author root@lweybridge0-64-fc6.sc.intel.com.sc.intel.com
date Wed Aug 29 12:50:02 2007 -0700 (2007-08-29)
parents 9163bea7b7bd
children da4c76340184
files tools/ioemu/hw/pass-through.c xen/arch/x86/domain.c xen/arch/x86/domctl.c xen/arch/x86/hvm/vioapic.c xen/arch/x86/hvm/vmx/intr.c xen/arch/x86/hvm/vmx/vmx.c xen/arch/x86/hvm/vmx/vtd/dmar.c xen/arch/x86/hvm/vmx/vtd/io.c xen/arch/x86/hvm/vpic.c xen/arch/x86/io_apic.c xen/arch/x86/irq.c xen/arch/x86/mm.c xen/arch/x86/mm/p2m.c xen/arch/x86/setup.c xen/common/grant_table.c xen/common/page_alloc.c xen/include/asm-x86/iommu.h
line diff
     1.1 --- a/tools/ioemu/hw/pass-through.c	Wed Aug 29 00:53:58 2007 +0300
     1.2 +++ b/tools/ioemu/hw/pass-through.c	Wed Aug 29 12:50:02 2007 -0700
     1.3 @@ -217,23 +217,21 @@ static void pt_pci_write_config(PCIDevic
     1.4      }
     1.5  
     1.6      /* PCI config pass-through */
     1.7 -    switch (len){
     1.8 -    case 1:
     1.9 -        pci_write_byte(pci_dev, address, val);
    1.10 -        break;
    1.11 -    case 2:
    1.12 -        pci_write_word(pci_dev, address, val);
    1.13 -        break;
    1.14 -    case 4:
    1.15 -        pci_write_long(pci_dev, address, val);
    1.16 -        break;
    1.17 -    }
    1.18 +    if (address == 0x4) {
    1.19 +        switch (len){
    1.20 +        case 1:
    1.21 +            pci_write_byte(pci_dev, address, val);
    1.22 +            break;
    1.23 +        case 2:
    1.24 +            pci_write_word(pci_dev, address, val);
    1.25 +            break;
    1.26 +        case 4:
    1.27 +            pci_write_long(pci_dev, address, val);
    1.28 +            break;
    1.29 +        }
    1.30  
    1.31 -    /* Post-write hooking */
    1.32 -    switch (address) {
    1.33 -    case 0x04:                  /* CMD register (enable IO access trap) */
    1.34 +        /* Post-write hooking */
    1.35          pci_default_write_config(d, address, val, len);
    1.36 -        break;
    1.37      }
    1.38  }
    1.39  
    1.40 @@ -421,6 +419,7 @@ int pt_init(PCIBus *e_bus, char *direct_
    1.41      int seg, b, d, f;
    1.42      struct pt_dev *pt_dev;
    1.43      struct pci_access *pci_access;
    1.44 +    int dev_count = pci_devs(direct_pci);
    1.45  
    1.46      /* Initialize libpci */
    1.47      pci_access = pci_alloc();
    1.48 @@ -433,7 +432,7 @@ int pt_init(PCIBus *e_bus, char *direct_
    1.49      pci_scan_bus(pci_access);
    1.50  
    1.51      /* Assign given devices to guest */
    1.52 -    for ( i = 0; i < pci_devs(direct_pci); i++ )
    1.53 +    for ( i = 0; i < dev_count; i++ )
    1.54      {
    1.55          /* Get next device bdf (bus, device, function) */
    1.56          next_bdf(direct_pci, &seg, &b, &d, &f);
     2.1 --- a/xen/arch/x86/domain.c	Wed Aug 29 00:53:58 2007 +0300
     2.2 +++ b/xen/arch/x86/domain.c	Wed Aug 29 12:50:02 2007 -0700
     2.3 @@ -486,7 +486,7 @@ int arch_domain_create(struct domain *d)
     2.4              virt_to_page(d->shared_info), d, XENSHARE_writable);
     2.5      }
     2.6  
     2.7 -    if ( vtd_enabled() )
     2.8 +    if (vtd_enabled)
     2.9          iommu_domain_init(d);
    2.10  
    2.11      if ( is_hvm_domain(d) )
     3.1 --- a/xen/arch/x86/domctl.c	Wed Aug 29 00:53:58 2007 +0300
     3.2 +++ b/xen/arch/x86/domctl.c	Wed Aug 29 12:50:02 2007 -0700
     3.3 @@ -432,12 +432,13 @@ long arch_do_domctl(
     3.4      break;
     3.5  
     3.6      case XEN_DOMCTL_assign_device:
     3.7 -#if 0
     3.8      {
     3.9          struct domain *d;
    3.10          struct hvm_iommu *hd;
    3.11          u8 bus, devfn;
    3.12 -        struct pci_dev *pdev;
    3.13 +
    3.14 +        if (!vtd_enabled)
    3.15 +            break;
    3.16  
    3.17          ret = -EINVAL;
    3.18          if ( unlikely((d = get_domain_by_id(domctl->domain)) == NULL) ) {
    3.19 @@ -448,21 +449,11 @@ long arch_do_domctl(
    3.20          hd = domain_hvm_iommu(d);
    3.21          bus = (domctl->u.assign_device.machine_bdf >> 16) & 0xff;
    3.22          devfn = (domctl->u.assign_device.machine_bdf >> 8) & 0xff;
    3.23 -
    3.24 -        if (vtd_enabled())
    3.25 -            ret = assign_device(d, bus, devfn);
    3.26 -        else {
    3.27 -            pdev = xmalloc(struct pci_dev);
    3.28 -            pdev->bus = bus;
    3.29 -            pdev->devfn = devfn;
    3.30 -            list_add(&pdev->list, &hd->pdev_list);
    3.31 -        }
    3.32 -
    3.33 +        ret = assign_device(d, bus, devfn);
    3.34          gdprintk(XENLOG_INFO, "XEN_DOMCTL_assign_device: bdf = %x:%x:%x\n",
    3.35              bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    3.36          put_domain(d);
    3.37      }
    3.38 -#endif
    3.39      break;
    3.40  
    3.41      case XEN_DOMCTL_bind_pt_irq:
    3.42 @@ -476,7 +467,7 @@ long arch_do_domctl(
    3.43  
    3.44          bind = &(domctl->u.bind_pt_irq);
    3.45          
    3.46 -        if ( vtd_enabled() )
    3.47 +        if (vtd_enabled)
    3.48              ret = pt_irq_create_bind_vtd(d, bind);
    3.49          else
    3.50              ret = pt_irq_create_bind_neo(bind);
     4.1 --- a/xen/arch/x86/hvm/vioapic.c	Wed Aug 29 00:53:58 2007 +0300
     4.2 +++ b/xen/arch/x86/hvm/vioapic.c	Wed Aug 29 12:50:02 2007 -0700
     4.3 @@ -463,7 +463,7 @@ void vioapic_update_EOI(struct domain *d
     4.4  
     4.5      ent->fields.remote_irr = 0;
     4.6  
     4.7 -    if (vtd_enabled())
     4.8 +    if (vtd_enabled)
     4.9      {
    4.10          spin_unlock(&d->arch.hvm_domain.irq_lock);
    4.11          hvm_dpci_eoi(gsi, ent);
     5.1 --- a/xen/arch/x86/hvm/vmx/intr.c	Wed Aug 29 00:53:58 2007 +0300
     5.2 +++ b/xen/arch/x86/hvm/vmx/intr.c	Wed Aug 29 12:50:02 2007 -0700
     5.3 @@ -159,7 +159,7 @@ asmlinkage void vmx_intr_assist(void)
     5.4      pt_update_irq(v);
     5.5  
     5.6      /* Pass-through interrupts handling */
     5.7 -    if ( vtd_enabled() )
     5.8 +    if (vtd_enabled)
     5.9      {
    5.10          if  (v->vcpu_id == 0)
    5.11              vmx_dirq_assist(v->domain);
     6.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Wed Aug 29 00:53:58 2007 +0300
     6.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Wed Aug 29 12:50:02 2007 -0700
     6.3 @@ -71,9 +71,7 @@ static int vmx_domain_initialise(struct 
     6.4  static void vmx_domain_destroy(struct domain *d)
     6.5  {
     6.6      vmx_free_vlapic_mapping(d);
     6.7 -#if 0
     6.8      release_devices(d);
     6.9 -#endif
    6.10  }
    6.11  
    6.12  static int vmx_vcpu_initialise(struct vcpu *v)
     7.1 --- a/xen/arch/x86/hvm/vmx/vtd/dmar.c	Wed Aug 29 00:53:58 2007 +0300
     7.2 +++ b/xen/arch/x86/hvm/vmx/vtd/dmar.c	Wed Aug 29 12:50:02 2007 -0700
     7.3 @@ -488,6 +488,7 @@ int acpi_dmar_init(void)
     7.4      if (list_empty(&acpi_drhd_units)) {
     7.5          printk(KERN_ERR PREFIX "No DMAR devices found\n");
     7.6          return -ENODEV;
     7.7 -    }
     7.8 +    } else
     7.9 +        vtd_enabled = 1;
    7.10      return 0;
    7.11  }
     8.1 --- a/xen/arch/x86/hvm/vmx/vtd/io.c	Wed Aug 29 00:53:58 2007 +0300
     8.2 +++ b/xen/arch/x86/hvm/vmx/vtd/io.c	Wed Aug 29 12:50:02 2007 -0700
     8.3 @@ -15,6 +15,7 @@
     8.4   * Place - Suite 330, Boston, MA 02111-1307 USA.
     8.5   *
     8.6   * Copyright (C) Allen Kay <allen.m.kay@intel.com>
     8.7 + * Copyright (C) Xiaohui Xin <xiaohui.xin@intel.com>
     8.8   */
     8.9  
    8.10  #include <xen/init.h>
    8.11 @@ -49,7 +50,7 @@ int hvm_do_IRQ_dpci(struct domain *d, un
    8.12      uint32_t link, isa_irq;
    8.13      struct hvm_irq *hvm_irq;
    8.14  
    8.15 -    if ((d == dom0) || !vtd_enabled())
    8.16 +    if (!vtd_enabled || (d == dom0))
    8.17          return 0;
    8.18  
    8.19      if (d->arch.hvm_domain.irq.mirq[mirq].valid)
    8.20 @@ -102,11 +103,11 @@ void hvm_dpci_eoi(unsigned int guest_gsi
    8.21  
    8.22  int release_devices(struct domain *d)
    8.23  {
    8.24 -    int ret = 0;
    8.25      struct hvm_domain *hd = &d->arch.hvm_domain;
    8.26      uint32_t i;
    8.27 +    int ret = 0;
    8.28  
    8.29 -    if (!vtd_enabled())
    8.30 +    if (!vtd_enabled)
    8.31          return ret;
    8.32  
    8.33      /* unbind irq */
    8.34 @@ -114,17 +115,6 @@ int release_devices(struct domain *d)
    8.35          if (hd->irq.mirq[i].valid)
    8.36              ret = pirq_guest_unbind(d, i);
    8.37      }
    8.38 -    if (vtd_enabled())
    8.39 -        iommu_domain_teardown(d);
    8.40 -    else {
    8.41 -        struct pci_dev *pdev;
    8.42 -        struct hvm_iommu *iommu = &d->arch.hvm_domain.hvm_iommu;
    8.43 -
    8.44 -        list_for_each_entry(pdev, &(iommu->pdev_list), list) {
    8.45 -            list_del(&(pdev->list));
    8.46 -            xfree(pdev);
    8.47 -        }
    8.48 -    }
    8.49 +    iommu_domain_teardown(d);
    8.50      return ret;
    8.51  }
    8.52 -
     9.1 --- a/xen/arch/x86/hvm/vpic.c	Wed Aug 29 00:53:58 2007 +0300
     9.2 +++ b/xen/arch/x86/hvm/vpic.c	Wed Aug 29 12:50:02 2007 -0700
     9.3 @@ -251,7 +251,7 @@ static void vpic_ioport_write(
     9.4                  vpic->isr &= ~(1 << irq);
     9.5                  if ( cmd == 7 )
     9.6                      vpic->priority_add = (irq + 1) & 7;
     9.7 -                if (vtd_enabled()) {
     9.8 +                if (vtd_enabled) {
     9.9                      /* chipset register 0xa0 is i8259 EOI register */
    9.10                      if (( old_addr & 0xa0) == 0xa0 )
    9.11                          irq = irq | 0x8;
    9.12 @@ -304,7 +304,7 @@ static void vpic_ioport_write(
    9.13  
    9.14      vpic_unlock(vpic);
    9.15  
    9.16 -    if (vtd_enabled() && pic_eoi && irq != 0)
    9.17 +    if (vtd_enabled && pic_eoi && irq != 0)
    9.18      {
    9.19          hvm_dpci_eoi(irq, NULL);
    9.20          pic_eoi = 0;
    10.1 --- a/xen/arch/x86/io_apic.c	Wed Aug 29 00:53:58 2007 +0300
    10.2 +++ b/xen/arch/x86/io_apic.c	Wed Aug 29 12:50:02 2007 -0700
    10.3 @@ -1421,7 +1421,7 @@ static void mask_and_ack_level_ioapic_ir
    10.4      if ( ioapic_ack_new )
    10.5          return;
    10.6  
    10.7 -    if (vtd_enabled())
    10.8 +    if (vtd_enabled)
    10.9          write_fake_IO_APIC_vector(irq);
   10.10      else
   10.11          mask_IO_APIC_irq(irq);
   10.12 @@ -1467,7 +1467,7 @@ static void end_level_ioapic_irq (unsign
   10.13      if ( !ioapic_ack_new )
   10.14      {
   10.15          if ( !(irq_desc[IO_APIC_VECTOR(irq)].status & IRQ_DISABLED) ) {
   10.16 -            if (vtd_enabled())
   10.17 +            if (vtd_enabled)
   10.18                  restore_real_IO_APIC_vector(irq);
   10.19              else
   10.20                  unmask_IO_APIC_irq(irq);
    11.1 --- a/xen/arch/x86/irq.c	Wed Aug 29 00:53:58 2007 +0300
    11.2 +++ b/xen/arch/x86/irq.c	Wed Aug 29 12:50:02 2007 -0700
    11.3 @@ -93,7 +93,7 @@ asmlinkage void do_IRQ(struct cpu_user_r
    11.4      spin_lock(&desc->lock);
    11.5      desc->handler->ack(vector);
    11.6  
    11.7 -    if ( !vtd_enabled() && do_IRQ_pt(vector) )
    11.8 +    if ( !vtd_enabled && do_IRQ_pt(vector) )
    11.9          goto out; 
   11.10  
   11.11      if ( likely(desc->status & IRQ_GUEST) )
    12.1 --- a/xen/arch/x86/mm.c	Wed Aug 29 00:53:58 2007 +0300
    12.2 +++ b/xen/arch/x86/mm.c	Wed Aug 29 12:50:02 2007 -0700
    12.3 @@ -2619,7 +2619,7 @@ static int create_grant_va_mapping(
    12.4      if ( !okay )
    12.5              return GNTST_general_error;
    12.6  
    12.7 -    if ( vtd_enabled() )
    12.8 +    if (vtd_enabled)
    12.9          iommu_map_page(d, l1e_get_pfn(nl1e), l1e_get_pfn(nl1e));
   12.10  
   12.11      if ( !paging_mode_refcounts(d) )
   12.12 @@ -2661,7 +2661,7 @@ static int replace_grant_va_mapping(
   12.13          goto out;
   12.14      }
   12.15  
   12.16 -    if ( vtd_enabled() )
   12.17 +    if (vtd_enabled)
   12.18          iommu_unmap_page(v->domain, mfn_to_gfn(d, _mfn(l1e_get_pfn(ol1e))));
   12.19  
   12.20   out:
   12.21 @@ -2775,7 +2775,7 @@ int steal_page(
   12.22      if ( !(memflags & MEMF_no_refcount) )
   12.23          d->tot_pages--;
   12.24      list_del(&page->list);
   12.25 -    if (vtd_enabled())
   12.26 +    if (vtd_enabled)
   12.27          iommu_unmap_page(d, page_to_mfn(page));
   12.28  
   12.29      spin_unlock(&d->page_alloc_lock);
    13.1 --- a/xen/arch/x86/mm/p2m.c	Wed Aug 29 00:53:58 2007 +0300
    13.2 +++ b/xen/arch/x86/mm/p2m.c	Wed Aug 29 12:50:02 2007 -0700
    13.3 @@ -235,7 +235,7 @@ set_p2m_entry(struct domain *d, unsigned
    13.4      /* Success */
    13.5      rv = 1;
    13.6   
    13.7 -    if (vtd_enabled() && is_hvm_domain(d) && mfn_valid(mfn))
    13.8 +    if (vtd_enabled && is_hvm_domain(d) && mfn_valid(mfn))
    13.9          iommu_flush(d, gfn, (u64*)p2m_entry);
   13.10  
   13.11   out:
   13.12 @@ -374,7 +374,7 @@ int p2m_alloc_table(struct domain *d,
   13.13      }
   13.14  
   13.15  #if CONFIG_PAGING_LEVELS >= 3
   13.16 -    if (vtd_enabled() && is_hvm_domain(d))
   13.17 +    if (vtd_enabled && is_hvm_domain(d))
   13.18          iommu_set_pgd(d);
   13.19  #endif
   13.20  
    14.1 --- a/xen/arch/x86/setup.c	Wed Aug 29 00:53:58 2007 +0300
    14.2 +++ b/xen/arch/x86/setup.c	Wed Aug 29 12:50:02 2007 -0700
    14.3 @@ -97,6 +97,9 @@ boolean_param("noapic", skip_ioapic_setu
    14.4  int opt_nativedom = 0;
    14.5  boolean_param("enable_nativedom", opt_nativedom);
    14.6  
    14.7 +/* will set if vt-d HW is found */
    14.8 +int vtd_enabled = 0;
    14.9 +
   14.10  int early_boot = 1;
   14.11  
   14.12  cpumask_t cpu_present_map;
    15.1 --- a/xen/common/grant_table.c	Wed Aug 29 00:53:58 2007 +0300
    15.2 +++ b/xen/common/grant_table.c	Wed Aug 29 12:50:02 2007 -0700
    15.3 @@ -949,7 +949,7 @@ gnttab_transfer(
    15.4          if ( unlikely(e->tot_pages++ == 0) )
    15.5              get_knownalive_domain(e);
    15.6          list_add_tail(&page->list, &e->page_list);
    15.7 -        if (vtd_enabled())
    15.8 +        if (vtd_enabled)
    15.9              iommu_map_page(e, mfn, mfn);
   15.10          page_set_owner(page, e);
   15.11  
    16.1 --- a/xen/common/page_alloc.c	Wed Aug 29 00:53:58 2007 +0300
    16.2 +++ b/xen/common/page_alloc.c	Wed Aug 29 12:50:02 2007 -0700
    16.3 @@ -814,7 +814,7 @@ int assign_pages(
    16.4          pg[i].count_info = PGC_allocated | 1;
    16.5          list_add_tail(&pg[i].list, &d->page_list);
    16.6  
    16.7 -        if (vtd_enabled() && !is_hvm_domain(d) && (dom0 != NULL))
    16.8 +        if (vtd_enabled && !is_hvm_domain(d) && (dom0 != NULL))
    16.9              iommu_map_page(d, page_to_mfn(&pg[i]), page_to_mfn(&pg[i]));
   16.10      }
   16.11  
   16.12 @@ -913,7 +913,7 @@ void free_domheap_pages(struct page_info
   16.13          {
   16.14              BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
   16.15              list_del(&pg[i].list);
   16.16 -            if ( vtd_enabled() && !is_hvm_domain(d) )
   16.17 +            if ( vtd_enabled && !is_hvm_domain(d) )
   16.18                  iommu_unmap_page(d, page_to_mfn(&pg[i]));
   16.19          }
   16.20  
    17.1 --- a/xen/include/asm-x86/iommu.h	Wed Aug 29 00:53:58 2007 +0300
    17.2 +++ b/xen/include/asm-x86/iommu.h	Wed Aug 29 12:50:02 2007 -0700
    17.3 @@ -29,8 +29,8 @@
    17.4  #include <asm/hvm/vmx/intel-iommu.h>
    17.5  #include <public/hvm/ioreq.h>
    17.6  
    17.7 -#define vtd_enabled()    (!list_empty(&acpi_drhd_units))
    17.8 -#define dev_assigned(d)  (!list_empty(&d->arch.hvm_domain.hvm_iommu.pdev_list))
    17.9 +extern int vtd_enabled;
   17.10 +
   17.11  #define domain_hvm_iommu(d)     (&d->arch.hvm_domain.hvm_iommu)
   17.12  #define domain_vmx_iommu(d)     (&d->arch.hvm_domain.hvm_iommu.vmx_iommu)
   17.13