From: "Jan Beulich" Subject: [PATCH] IOMMU: don't disable bus mastering on faults for devices used by Xen or Dom0 Date: Mon, 05 Nov 2012 16:53:45 +0000 Message-ID: <5097FD2902000078000A66BF@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part49788309.4__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: wei.huang2@amd.com, weiwang.dd@gmail.com, xiantao.zhang@intel.com Cc: Tim Deegan , Dario Faggioli , xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part49788309.4__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Under the assumption that in these cases recurring faults aren't a security issue and it can be expected that the drivers there are going to try to take care of the problem. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -625,6 +625,18 @@ static void parse_event_log_entry(struct for ( bdf =3D 0; bdf < ivrs_bdf_entries; bdf++ ) if ( get_dma_requestor_id(iommu->seg, bdf) =3D=3D device_id ) { + const struct pci_dev *pdev; + + spin_lock(&pcidevs_lock); + pdev =3D pci_get_pdev(iommu->seg, PCI_BUS(bdf), PCI_DEVFN2= (bdf)); + if ( pdev && pdev->domain !=3D dom_xen && + (!pdev->domain || !IS_PRIV(pdev->domain)) ) + pdev =3D NULL; + spin_unlock(&pcidevs_lock); + + if ( pdev ) + continue; + cword =3D pci_conf_read16(iommu->seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf), PCI_COMMAND); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -916,7 +916,8 @@ static void __do_iommu_page_fault(struct reg =3D cap_fault_reg_offset(iommu->cap); while (1) { - u8 fault_reason; + const struct pci_dev *pdev; + u8 fault_reason, bus; u16 source_id, cword; u32 data; u64 guest_addr; @@ -950,14 +951,27 @@ static void __do_iommu_page_fault(struct iommu_page_fault_do_one(iommu, type, fault_reason, source_id, guest_addr); =20 - /* Tell the device to stop DMAing; we can't rely on the guest to - * control it for us. */ - cword =3D pci_conf_read16(iommu->intel->drhd->segment, - PCI_BUS(source_id), PCI_SLOT(source_id), - PCI_FUNC(source_id), PCI_COMMAND); - pci_conf_write16(iommu->intel->drhd->segment, PCI_BUS(source_id), - PCI_SLOT(source_id), PCI_FUNC(source_id), - PCI_COMMAND, cword & ~PCI_COMMAND_MASTER); + bus =3D PCI_BUS(source_id); + + spin_lock(&pcidevs_lock); + pdev =3D pci_get_pdev(iommu->intel->drhd->segment, bus, + PCI_DEVFN2(source_id)); + if ( pdev && pdev->domain !=3D dom_xen && + (!pdev->domain || !IS_PRIV(pdev->domain)) ) + pdev =3D NULL; + spin_unlock(&pcidevs_lock); + + if ( !pdev ) + { + /* Tell the device to stop DMAing; we can't rely on the guest = to + * control it for us. */ + cword =3D pci_conf_read16(iommu->intel->drhd->segment, bus, + PCI_SLOT(source_id), PCI_FUNC(source_i= d), + PCI_COMMAND); + pci_conf_write16(iommu->intel->drhd->segment, bus, + PCI_SLOT(source_id), PCI_FUNC(source_id), + PCI_COMMAND, cword & ~PCI_COMMAND_MASTER); + } =20 fault_index++; if ( fault_index > cap_num_fault_regs(iommu->cap) ) --=__Part49788309.4__= Content-Type: text/plain; name="IOMMU-disable-BM-not-dom0.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="IOMMU-disable-BM-not-dom0.patch" IOMMU: don't disable bus mastering on faults for devices used by Xen or = Dom0=0A=0AUnder the assumption that in these cases recurring faults aren't = a=0Asecurity issue and it can be expected that the drivers there are = going=0Ato try to take care of the problem.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/drivers/passthrough/amd/iommu_in= it.c=0A+++ b/xen/drivers/passthrough/amd/iommu_init.c=0A@@ -625,6 +625,18 = @@ static void parse_event_log_entry(struct=0A for ( bdf =3D 0; = bdf < ivrs_bdf_entries; bdf++ )=0A if ( get_dma_requestor_id(io= mmu->seg, bdf) =3D=3D device_id )=0A {=0A+ = const struct pci_dev *pdev;=0A+=0A+ spin_lock(&pcidevs_lock)= ;=0A+ pdev =3D pci_get_pdev(iommu->seg, PCI_BUS(bdf), = PCI_DEVFN2(bdf));=0A+ if ( pdev && pdev->domain !=3D = dom_xen &&=0A+ (!pdev->domain || !IS_PRIV(pdev->domain)= ) )=0A+ pdev =3D NULL;=0A+ spin_unlock(&p= cidevs_lock);=0A+=0A+ if ( pdev )=0A+ = continue;=0A+=0A cword =3D pci_conf_read16(iommu->seg, = PCI_BUS(bdf),=0A PCI_SLOT(bdf), = PCI_FUNC(bdf),=0A PCI_COMMAND);=0A-= -- a/xen/drivers/passthrough/vtd/iommu.c=0A+++ b/xen/drivers/passthrough/vt= d/iommu.c=0A@@ -916,7 +916,8 @@ static void __do_iommu_page_fault(struct=0A= reg =3D cap_fault_reg_offset(iommu->cap);=0A while (1)=0A = {=0A- u8 fault_reason;=0A+ const struct pci_dev *pdev;=0A+ = u8 fault_reason, bus;=0A u16 source_id, cword;=0A u32 = data;=0A u64 guest_addr;=0A@@ -950,14 +951,27 @@ static void = __do_iommu_page_fault(struct=0A iommu_page_fault_do_one(iommu, = type, fault_reason,=0A source_id, = guest_addr);=0A =0A- /* Tell the device to stop DMAing; we can't = rely on the guest to=0A- * control it for us. */=0A- cword = =3D pci_conf_read16(iommu->intel->drhd->segment,=0A- = PCI_BUS(source_id), PCI_SLOT(source_id),=0A- = PCI_FUNC(source_id), PCI_COMMAND);=0A- pci_conf_write16(io= mmu->intel->drhd->segment, PCI_BUS(source_id),=0A- = PCI_SLOT(source_id), PCI_FUNC(source_id),=0A- = PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);=0A+ bus =3D PCI_BUS(sourc= e_id);=0A+=0A+ spin_lock(&pcidevs_lock);=0A+ pdev =3D = pci_get_pdev(iommu->intel->drhd->segment, bus,=0A+ = PCI_DEVFN2(source_id));=0A+ if ( pdev && pdev->domain !=3D = dom_xen &&=0A+ (!pdev->domain || !IS_PRIV(pdev->domain)) )=0A+ = pdev =3D NULL;=0A+ spin_unlock(&pcidevs_lock);=0A+=0A+ = if ( !pdev )=0A+ {=0A+ /* Tell the device to stop = DMAing; we can't rely on the guest to=0A+ * control it for us. = */=0A+ cword =3D pci_conf_read16(iommu->intel->drhd->segment, = bus,=0A+ PCI_SLOT(source_id), PCI_FUNC(s= ource_id),=0A+ PCI_COMMAND);=0A+ = pci_conf_write16(iommu->intel->drhd->segment, bus,=0A+ = PCI_SLOT(source_id), PCI_FUNC(source_id),=0A+ = PCI_COMMAND, cword & ~PCI_COMMAND_MASTER);=0A+ }=0A =0A = fault_index++;=0A if ( fault_index > cap_num_fault_regs(iomm= u->cap) )=0A --=__Part49788309.4__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part49788309.4__=--