From: "Xu, Quan" <quan.xu@intel.com>
To: xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@intel.com>, Feng Wu <feng.wu@intel.com>,
Jan Beulich <jbeulich@suse.com>,
dario.faggioli@citrix.com,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Quan Xu <quan.xu@intel.com>
Subject: [PATCH v12 4/6] IOMMU/x86: using a struct pci_dev* instead of SBDF
Date: Fri, 24 Jun 2016 13:51:56 +0800 [thread overview]
Message-ID: <1466747518-54402-5-git-send-email-quan.xu@intel.com> (raw)
In-Reply-To: <1466747518-54402-1-git-send-email-quan.xu@intel.com>
From: Quan Xu <quan.xu@intel.com>
a struct pci_dev* instead of SBDF is stored inside struct
pci_ats_dev and parameter to enable_ats_device().
Signed-off-by: Quan Xu <quan.xu@intel.com>
CC: Jan Beulich <jbeulich@suse.com>
CC: Kevin Tian <kevin.tian@intel.com>
CC: Feng Wu <feng.wu@intel.com>
CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
xen/drivers/passthrough/amd/iommu_cmd.c | 11 +++---
xen/drivers/passthrough/amd/pci_amd_iommu.c | 2 +-
xen/drivers/passthrough/ats.h | 6 ++--
xen/drivers/passthrough/vtd/iommu.c | 8 ++---
xen/drivers/passthrough/vtd/x86/ats.c | 20 ++++++++---
xen/drivers/passthrough/x86/ats.c | 52 +++++++++++++++++++----------
6 files changed, 62 insertions(+), 37 deletions(-)
diff --git a/xen/drivers/passthrough/amd/iommu_cmd.c b/xen/drivers/passthrough/amd/iommu_cmd.c
index 7c9d9be..b3094f3 100644
--- a/xen/drivers/passthrough/amd/iommu_cmd.c
+++ b/xen/drivers/passthrough/amd/iommu_cmd.c
@@ -298,24 +298,23 @@ void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev,
if ( ats_pdev == NULL )
return;
- if ( !pci_ats_enabled(ats_pdev->seg, ats_pdev->bus, ats_pdev->devfn) )
+ if ( !pci_ats_enabled(pdev->seg, pdev->bus, pdev->devfn) )
return;
- iommu = find_iommu_for_device(ats_pdev->seg,
- PCI_BDF2(ats_pdev->bus, ats_pdev->devfn));
+ iommu = find_iommu_for_device(pdev->seg, PCI_BDF2(pdev->bus, pdev->devfn));
if ( !iommu )
{
AMD_IOMMU_DEBUG("%s: Can't find iommu for %04x:%02x:%02x.%u\n",
- __func__, ats_pdev->seg, ats_pdev->bus,
- PCI_SLOT(ats_pdev->devfn), PCI_FUNC(ats_pdev->devfn));
+ __func__, pdev->seg, pdev->bus,
+ PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
return;
}
if ( !iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) )
return;
- req_id = get_dma_requestor_id(iommu->seg, PCI_BDF2(ats_pdev->bus, devfn));
+ req_id = get_dma_requestor_id(iommu->seg, PCI_BDF2(pdev->bus, devfn));
queueid = req_id;
maxpend = ats_pdev->ats_queue_depth & 0xff;
diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c
index 7761241..64ca78e 100644
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -162,7 +162,7 @@ static void amd_iommu_setup_domain_device(
!pci_ats_enabled(iommu->seg, bus, pdev->devfn) )
{
if ( devfn == pdev->devfn )
- enable_ats_device(iommu->seg, bus, devfn, iommu);
+ enable_ats_device(iommu, pdev);
amd_iommu_flush_iotlb(devfn, pdev, INV_IOMMU_ALL_PAGES_ADDRESS, 0);
}
diff --git a/xen/drivers/passthrough/ats.h b/xen/drivers/passthrough/ats.h
index 5c91572..1359841 100644
--- a/xen/drivers/passthrough/ats.h
+++ b/xen/drivers/passthrough/ats.h
@@ -19,9 +19,7 @@
struct pci_ats_dev {
struct list_head list;
- u16 seg;
- u8 bus;
- u8 devfn;
+ struct pci_dev *pci_dev;
u16 ats_queue_depth; /* ATS device invalidation queue depth */
const void *iommu; /* No common IOMMU struct so use void pointer */
};
@@ -34,7 +32,7 @@ struct pci_ats_dev {
extern struct list_head ats_devices;
extern bool_t ats_enabled;
-int enable_ats_device(int seg, int bus, int devfn, const void *iommu);
+int enable_ats_device(const void *iommu, struct pci_dev *pci_dev);
void disable_ats_device(int seg, int bus, int devfn);
struct pci_ats_dev *get_ats_device(int seg, int bus, int devfn);
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index f010612..1b0a0f0 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1461,8 +1461,8 @@ int domain_context_mapping_one(
return rc;
}
-static int domain_context_mapping(
- struct domain *domain, u8 devfn, const struct pci_dev *pdev)
+static int domain_context_mapping(struct domain *domain, u8 devfn,
+ struct pci_dev *pdev)
{
struct acpi_drhd_unit *drhd;
int ret = 0;
@@ -1498,7 +1498,7 @@ static int domain_context_mapping(
ret = domain_context_mapping_one(domain, drhd->iommu, bus, devfn,
pdev);
if ( !ret && devfn == pdev->devfn && ats_device(pdev, drhd) > 0 )
- enable_ats_device(seg, bus, devfn, drhd->iommu);
+ enable_ats_device(drhd->iommu, pdev);
break;
@@ -1994,7 +1994,7 @@ static int intel_iommu_enable_device(struct pci_dev *pdev)
if ( ret <= 0 )
return ret;
- ret = enable_ats_device(pdev->seg, pdev->bus, pdev->devfn, drhd->iommu);
+ ret = enable_ats_device(drhd->iommu, pdev);
return ret >= 0 ? 0 : ret;
}
diff --git a/xen/drivers/passthrough/vtd/x86/ats.c b/xen/drivers/passthrough/vtd/x86/ats.c
index dfa4d30..a6c53ea 100644
--- a/xen/drivers/passthrough/vtd/x86/ats.c
+++ b/xen/drivers/passthrough/vtd/x86/ats.c
@@ -76,21 +76,25 @@ static int device_in_domain(struct iommu *iommu, struct pci_ats_dev *pdev, u16 d
struct root_entry *root_entry = NULL;
struct context_entry *ctxt_entry = NULL;
int tt, found = 0;
+ struct pci_dev *pci_dev = pdev->pci_dev;
+
+ if ( !pci_dev )
+ return -ENODEV;
root_entry = (struct root_entry *) map_vtd_domain_page(iommu->root_maddr);
- if ( !root_entry || !root_present(root_entry[pdev->bus]) )
+ if ( !root_entry || !root_present(root_entry[pci_dev->bus]) )
goto out;
ctxt_entry = (struct context_entry *)
- map_vtd_domain_page(root_entry[pdev->bus].val);
+ map_vtd_domain_page(root_entry[pci_dev->bus].val);
if ( ctxt_entry == NULL )
goto out;
- if ( context_domain_id(ctxt_entry[pdev->devfn]) != did )
+ if ( context_domain_id(ctxt_entry[pci_dev->devfn]) != did )
goto out;
- tt = context_translation_type(ctxt_entry[pdev->devfn]);
+ tt = context_translation_type(ctxt_entry[pci_dev->devfn]);
if ( tt != CONTEXT_TT_DEV_IOTLB )
goto out;
@@ -116,10 +120,16 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
list_for_each_entry( pdev, &ats_devices, list )
{
- u16 sid = PCI_BDF2(pdev->bus, pdev->devfn);
+ struct pci_dev *pci_dev = pdev->pci_dev;
+ u16 sid;
bool_t sbit;
int rc = 0;
+ if ( !pci_dev )
+ continue;
+
+ sid = PCI_BDF2(pci_dev->bus, pci_dev->devfn);
+
/* Only invalidate devices that belong to this IOMMU */
if ( pdev->iommu != iommu )
continue;
diff --git a/xen/drivers/passthrough/x86/ats.c b/xen/drivers/passthrough/x86/ats.c
index 40c9f40..8ce759f 100644
--- a/xen/drivers/passthrough/x86/ats.c
+++ b/xen/drivers/passthrough/x86/ats.c
@@ -22,26 +22,34 @@ LIST_HEAD(ats_devices);
bool_t __read_mostly ats_enabled = 0;
boolean_param("ats", ats_enabled);
-int enable_ats_device(int seg, int bus, int devfn, const void *iommu)
+int enable_ats_device(const void *iommu, struct pci_dev *pci_dev)
{
struct pci_ats_dev *pdev = NULL;
u32 value;
int pos;
- pos = pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS);
+ pos = pci_find_ext_capability(pci_dev->seg, pci_dev->bus, pci_dev->devfn,
+ PCI_EXT_CAP_ID_ATS);
BUG_ON(!pos);
if ( iommu_verbose )
dprintk(XENLOG_INFO, "%04x:%02x:%02x.%u: ATS capability found\n",
- seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+ pci_dev->seg, pci_dev->bus, PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn));
- value = pci_conf_read16(seg, bus, PCI_SLOT(devfn),
- PCI_FUNC(devfn), pos + ATS_REG_CTL);
+ value = pci_conf_read16(pci_dev->seg, pci_dev->bus, PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn), pos + ATS_REG_CTL);
if ( value & ATS_ENABLE )
{
list_for_each_entry ( pdev, &ats_devices, list )
{
- if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn )
+ struct pci_dev *pci_dev = pdev->pci_dev;
+
+ if ( !pci_dev )
+ continue;
+ if ( pci_dev->seg == pci_dev->seg &&
+ pci_dev->bus == pci_dev->bus &&
+ pci_dev->devfn == pci_dev->devfn )
{
pos = 0;
break;
@@ -56,18 +64,16 @@ int enable_ats_device(int seg, int bus, int devfn, const void *iommu)
if ( !(value & ATS_ENABLE) )
{
value |= ATS_ENABLE;
- pci_conf_write16(seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
- pos + ATS_REG_CTL, value);
+ pci_conf_write16(pci_dev->seg, pci_dev->bus, PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn), pos + ATS_REG_CTL, value);
}
if ( pos )
{
- pdev->seg = seg;
- pdev->bus = bus;
- pdev->devfn = devfn;
+ pdev->pci_dev = pci_dev;
pdev->iommu = iommu;
- value = pci_conf_read16(seg, bus, PCI_SLOT(devfn),
- PCI_FUNC(devfn), pos + ATS_REG_CAP);
+ value = pci_conf_read16(pci_dev->seg, pci_dev->bus, PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn), pos + ATS_REG_CAP);
pdev->ats_queue_depth = value & ATS_QUEUE_DEPTH_MASK ?:
ATS_QUEUE_DEPTH_MASK + 1;
list_add(&pdev->list, &ats_devices);
@@ -75,8 +81,8 @@ int enable_ats_device(int seg, int bus, int devfn, const void *iommu)
if ( iommu_verbose )
dprintk(XENLOG_INFO, "%04x:%02x:%02x.%u: ATS %s enabled\n",
- seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
- pos ? "is" : "was");
+ pci_dev->seg, pci_dev->bus, PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn), pos ? "is" : "was");
return pos;
}
@@ -98,7 +104,13 @@ void disable_ats_device(int seg, int bus, int devfn)
list_for_each_entry ( pdev, &ats_devices, list )
{
- if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn )
+ struct pci_dev *pci_dev = pdev->pci_dev;
+
+ if ( !pci_dev )
+ continue;
+ if ( pci_dev->seg == seg &&
+ pci_dev->bus == bus &&
+ pci_dev->devfn == devfn )
{
list_del(&pdev->list);
xfree(pdev);
@@ -120,7 +132,13 @@ struct pci_ats_dev *get_ats_device(int seg, int bus, int devfn)
list_for_each_entry ( pdev, &ats_devices, list )
{
- if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn )
+ struct pci_dev *pci_dev = pdev->pci_dev;
+
+ if ( !pci_dev )
+ continue;
+ if ( pci_dev->seg == seg &&
+ pci_dev->bus == bus &&
+ pci_dev->devfn == devfn )
return pdev;
}
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-24 5:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 5:51 [PATCH v12 0/6] VT-d Device-TLB flush issue Xu, Quan
2016-06-24 5:51 ` [PATCH v12 1/6] IOMMU: add a timeout parameter for device IOTLB invalidation Xu, Quan
2016-06-24 11:30 ` Tian, Kevin
2016-06-27 8:03 ` Jan Beulich
2016-06-27 8:19 ` Xu, Quan
2016-06-27 8:28 ` Jan Beulich
2016-06-27 8:34 ` Xu, Quan
2016-06-24 5:51 ` [PATCH v12 2/6] vt-d: synchronize for Device-TLB flush one by one Xu, Quan
2016-06-24 11:33 ` Tian, Kevin
2016-06-24 5:51 ` [PATCH v12 3/6] vt-d: convert conditionals of qi_ctrl->qinval_maddr into ASSERT()s Xu, Quan
2016-06-24 11:35 ` Tian, Kevin
2016-06-24 5:51 ` Xu, Quan [this message]
2016-06-24 11:46 ` [PATCH v12 4/6] IOMMU/x86: using a struct pci_dev* instead of SBDF Tian, Kevin
2016-06-26 8:57 ` Xu, Quan
2016-06-26 10:32 ` Xu, Quan
2016-06-29 1:59 ` Tian, Kevin
2016-06-27 8:17 ` Jan Beulich
2016-06-27 8:25 ` Jan Beulich
2016-06-27 11:11 ` Xu, Quan
2016-06-27 15:19 ` Jan Beulich
2016-06-28 1:31 ` Xu, Quan
2016-06-24 5:51 ` [PATCH v12 5/6] IOMMU: move the domain crash logic up to the generic IOMMU layer Xu, Quan
2016-06-24 11:48 ` Tian, Kevin
2016-06-26 8:58 ` Xu, Quan
2016-06-27 8:18 ` Jan Beulich
2016-06-24 5:51 ` [PATCH v12 6/6] vt-d: fix vt-d Device-TLB flush timeout issue Xu, Quan
2016-06-24 11:55 ` Tian, Kevin
2016-06-24 12:54 ` Jan Beulich
2016-06-26 9:18 ` Xu, Quan
2016-06-27 7:56 ` Jan Beulich
2016-06-27 8:24 ` Jan Beulich
2016-06-27 12:56 ` Xu, Quan
2016-06-27 15:21 ` Jan Beulich
2016-06-28 7:06 ` Xu, Quan
2016-06-28 7:24 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466747518-54402-5-git-send-email-quan.xu@intel.com \
--to=quan.xu@intel.com \
--cc=dario.faggioli@citrix.com \
--cc=feng.wu@intel.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).