* [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal
@ 2015-10-20 15:33 Joerg Roedel
2015-10-20 15:33 ` [PATCH 01/12] iommu/amd: Do not BUG_ON in __detach_device() Joerg Roedel
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
Hi,
This patch-set cleans up the alias handling code in the AMD
IOMMU driver. Most of the alias handling is done already in
the IOMMU group code. Only the handling of request-ids that
are not backed by a 'struct pci_dev' still needs to happen
in the AMD IOMMU driver, as the IOMMU group code has no way
of handling that.
A few other cleanups which accumulated during implemented
this are also included in this patch-set.
Regards,
Joerg
Joerg Roedel (12):
iommu/amd: Do not BUG_ON in __detach_device()
iommu/amd: Do not iterate over alias-list in __[attach|detach]_device
iommu/amd: Don't disable IRQs in __detach_device
iommu/amd: WARN when __[attach|detach]_device are called with irqs
enabled
iommu/amd: Set alias DTE in do_attach/do_detach
iommu/amd: Remove old alias handling code
iommu/amd: Align DTE flag definitions
iommu/amd: Remove cmd_buf_size and evt_buf_size from struct amd_iommu
iommu/amd: Cleanup buffer allocation
iommu/amd: Initialize amd_iommu_last_bdf for DEV_ALL
iommu/amd: Remove first/last_device handling
iommu/amd: Remove find_last_devid_on_pci()
drivers/iommu/amd_iommu.c | 172 +++++++++-------------------------------
drivers/iommu/amd_iommu_init.c | 111 ++++++--------------------
drivers/iommu/amd_iommu_types.h | 13 +--
3 files changed, 64 insertions(+), 232 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 01/12] iommu/amd: Do not BUG_ON in __detach_device()
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 02/12] iommu/amd: Do not iterate over alias-list in __[attach|detach]_device Joerg Roedel
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The condition in the BUG_ON is an indicator of a BUG, but no
reason to kill the code path. Turn it into a WARN_ON and
bail out if it is hit.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 08d2775..bde87be 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2213,7 +2213,8 @@ static void __detach_device(struct iommu_dev_data *dev_data)
struct protection_domain *domain;
unsigned long flags;
- BUG_ON(!dev_data->domain);
+ if (WARN_ON(!dev_data->domain))
+ return;
domain = dev_data->domain;
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 02/12] iommu/amd: Do not iterate over alias-list in __[attach|detach]_device
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
2015-10-20 15:33 ` [PATCH 01/12] iommu/amd: Do not BUG_ON in __detach_device() Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 03/12] iommu/amd: Don't disable IRQs in __detach_device Joerg Roedel
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The alias list is handled aleady by iommu core code. No need
anymore to handle it in this part of the AMD IOMMU code
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 26 +++-----------------------
1 file changed, 3 insertions(+), 23 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index bde87be..b86c5f0 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2037,29 +2037,17 @@ static void do_detach(struct iommu_dev_data *dev_data)
static int __attach_device(struct iommu_dev_data *dev_data,
struct protection_domain *domain)
{
- struct iommu_dev_data *head, *entry;
int ret;
/* lock domain */
spin_lock(&domain->lock);
- head = dev_data;
-
- if (head->alias_data != NULL)
- head = head->alias_data;
-
- /* Now we have the root of the alias group, if any */
-
ret = -EBUSY;
- if (head->domain != NULL)
+ if (dev_data->domain != NULL)
goto out_unlock;
/* Attach alias group root */
- do_attach(head, domain);
-
- /* Attach other devices in the alias group */
- list_for_each_entry(entry, &head->alias_list, alias_list)
- do_attach(entry, domain);
+ do_attach(dev_data, domain);
ret = 0;
@@ -2209,7 +2197,6 @@ static int attach_device(struct device *dev,
*/
static void __detach_device(struct iommu_dev_data *dev_data)
{
- struct iommu_dev_data *head, *entry;
struct protection_domain *domain;
unsigned long flags;
@@ -2220,14 +2207,7 @@ static void __detach_device(struct iommu_dev_data *dev_data)
spin_lock_irqsave(&domain->lock, flags);
- head = dev_data;
- if (head->alias_data != NULL)
- head = head->alias_data;
-
- list_for_each_entry(entry, &head->alias_list, alias_list)
- do_detach(entry);
-
- do_detach(head);
+ do_detach(dev_data);
spin_unlock_irqrestore(&domain->lock, flags);
}
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 03/12] iommu/amd: Don't disable IRQs in __detach_device
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
2015-10-20 15:33 ` [PATCH 01/12] iommu/amd: Do not BUG_ON in __detach_device() Joerg Roedel
2015-10-20 15:33 ` [PATCH 02/12] iommu/amd: Do not iterate over alias-list in __[attach|detach]_device Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 04/12] iommu/amd: WARN when __[attach|detach]_device are called with irqs enabled Joerg Roedel
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
This function is already called with IRQs disabled already.
So no need to disable them again.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b86c5f0..54e0862 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2198,18 +2198,17 @@ static int attach_device(struct device *dev,
static void __detach_device(struct iommu_dev_data *dev_data)
{
struct protection_domain *domain;
- unsigned long flags;
if (WARN_ON(!dev_data->domain))
return;
domain = dev_data->domain;
- spin_lock_irqsave(&domain->lock, flags);
+ spin_lock(&domain->lock);
do_detach(dev_data);
- spin_unlock_irqrestore(&domain->lock, flags);
+ spin_unlock(&domain->lock);
}
/*
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 04/12] iommu/amd: WARN when __[attach|detach]_device are called with irqs enabled
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (2 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 03/12] iommu/amd: Don't disable IRQs in __detach_device Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 05/12] iommu/amd: Set alias DTE in do_attach/do_detach Joerg Roedel
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
These functions rely on being called with IRQs disabled. Add
a WARN_ON to detect early when its not.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 54e0862..d47c4b1 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2039,6 +2039,12 @@ static int __attach_device(struct iommu_dev_data *dev_data,
{
int ret;
+ /*
+ * Must be called with IRQs disabled. Warn here to detect early
+ * when its not.
+ */
+ WARN_ON(!irqs_disabled());
+
/* lock domain */
spin_lock(&domain->lock);
@@ -2199,6 +2205,12 @@ static void __detach_device(struct iommu_dev_data *dev_data)
{
struct protection_domain *domain;
+ /*
+ * Must be called with IRQs disabled. Warn here to detect early
+ * when its not.
+ */
+ WARN_ON(!irqs_disabled());
+
if (WARN_ON(!dev_data->domain))
return;
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 05/12] iommu/amd: Set alias DTE in do_attach/do_detach
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (3 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 04/12] iommu/amd: WARN when __[attach|detach]_device are called with irqs enabled Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 06/12] iommu/amd: Remove old alias handling code Joerg Roedel
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
With this we don't have to create dev_data entries for
non-existent devices (which only exist as request-ids).
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index d47c4b1..187a8bf 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -1114,11 +1114,15 @@ static int device_flush_iotlb(struct iommu_dev_data *dev_data,
static int device_flush_dte(struct iommu_dev_data *dev_data)
{
struct amd_iommu *iommu;
+ u16 alias;
int ret;
iommu = amd_iommu_rlookup_table[dev_data->devid];
+ alias = amd_iommu_alias_table[dev_data->devid];
ret = iommu_flush_dte(iommu, dev_data->devid);
+ if (!ret && alias != dev_data->devid)
+ ret = iommu_flush_dte(iommu, alias);
if (ret)
return ret;
@@ -1984,27 +1988,33 @@ static void do_attach(struct iommu_dev_data *dev_data,
struct protection_domain *domain)
{
struct amd_iommu *iommu;
+ u16 alias;
bool ats;
iommu = amd_iommu_rlookup_table[dev_data->devid];
+ alias = amd_iommu_alias_table[dev_data->devid];
ats = dev_data->ats.enabled;
/* Update data structures */
dev_data->domain = domain;
list_add(&dev_data->list, &domain->dev_list);
- set_dte_entry(dev_data->devid, domain, ats);
/* Do reference counting */
domain->dev_iommu[iommu->index] += 1;
domain->dev_cnt += 1;
- /* Flush the DTE entry */
+ /* Update device table */
+ set_dte_entry(dev_data->devid, domain, ats);
+ if (alias != dev_data->devid)
+ set_dte_entry(dev_data->devid, domain, ats);
+
device_flush_dte(dev_data);
}
static void do_detach(struct iommu_dev_data *dev_data)
{
struct amd_iommu *iommu;
+ u16 alias;
/*
* First check if the device is still attached. It might already
@@ -2016,6 +2026,7 @@ static void do_detach(struct iommu_dev_data *dev_data)
return;
iommu = amd_iommu_rlookup_table[dev_data->devid];
+ alias = amd_iommu_alias_table[dev_data->devid];
/* decrease reference counters */
dev_data->domain->dev_iommu[iommu->index] -= 1;
@@ -2025,6 +2036,8 @@ static void do_detach(struct iommu_dev_data *dev_data)
dev_data->domain = NULL;
list_del(&dev_data->list);
clear_dte_entry(dev_data->devid);
+ if (alias != dev_data->devid)
+ clear_dte_entry(alias);
/* Flush the DTE entry */
device_flush_dte(dev_data);
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 06/12] iommu/amd: Remove old alias handling code
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (4 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 05/12] iommu/amd: Set alias DTE in do_attach/do_detach Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 07/12] iommu/amd: Align DTE flag definitions Joerg Roedel
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
This mostly removes the code to create dev_data structures
for alias device ids. They are not necessary anymore, as
they were only created for device ids which have no struct
pci_dev associated with it. But these device ids are
handled in a simpler way now, so there is no need for this
code anymore.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 99 -----------------------------------------------
1 file changed, 99 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 187a8bf..1a7c78d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -89,8 +89,6 @@ static struct dma_map_ops amd_iommu_dma_ops;
struct iommu_dev_data {
struct list_head list; /* For domain->dev_list */
struct list_head dev_data_list; /* For global dev_data_list */
- struct list_head alias_list; /* Link alias-groups together */
- struct iommu_dev_data *alias_data;/* The alias dev_data */
struct protection_domain *domain; /* Domain the device is bound to */
u16 devid; /* PCI Device ID */
bool iommu_v2; /* Device can make use of IOMMUv2 */
@@ -136,8 +134,6 @@ static struct iommu_dev_data *alloc_dev_data(u16 devid)
if (!dev_data)
return NULL;
- INIT_LIST_HEAD(&dev_data->alias_list);
-
dev_data->devid = devid;
spin_lock_irqsave(&dev_data_list_lock, flags);
@@ -147,17 +143,6 @@ static struct iommu_dev_data *alloc_dev_data(u16 devid)
return dev_data;
}
-static void free_dev_data(struct iommu_dev_data *dev_data)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&dev_data_list_lock, flags);
- list_del(&dev_data->dev_data_list);
- spin_unlock_irqrestore(&dev_data_list_lock, flags);
-
- kfree(dev_data);
-}
-
static struct iommu_dev_data *search_dev_data(u16 devid)
{
struct iommu_dev_data *dev_data;
@@ -311,73 +296,10 @@ out:
iommu_group_put(group);
}
-static int __last_alias(struct pci_dev *pdev, u16 alias, void *data)
-{
- *(u16 *)data = alias;
- return 0;
-}
-
-static u16 get_alias(struct device *dev)
-{
- struct pci_dev *pdev = to_pci_dev(dev);
- u16 devid, ivrs_alias, pci_alias;
-
- devid = get_device_id(dev);
- ivrs_alias = amd_iommu_alias_table[devid];
- pci_for_each_dma_alias(pdev, __last_alias, &pci_alias);
-
- if (ivrs_alias == pci_alias)
- return ivrs_alias;
-
- /*
- * DMA alias showdown
- *
- * The IVRS is fairly reliable in telling us about aliases, but it
- * can't know about every screwy device. If we don't have an IVRS
- * reported alias, use the PCI reported alias. In that case we may
- * still need to initialize the rlookup and dev_table entries if the
- * alias is to a non-existent device.
- */
- if (ivrs_alias == devid) {
- if (!amd_iommu_rlookup_table[pci_alias]) {
- amd_iommu_rlookup_table[pci_alias] =
- amd_iommu_rlookup_table[devid];
- memcpy(amd_iommu_dev_table[pci_alias].data,
- amd_iommu_dev_table[devid].data,
- sizeof(amd_iommu_dev_table[pci_alias].data));
- }
-
- return pci_alias;
- }
-
- pr_info("AMD-Vi: Using IVRS reported alias %02x:%02x.%d "
- "for device %s[%04x:%04x], kernel reported alias "
- "%02x:%02x.%d\n", PCI_BUS_NUM(ivrs_alias), PCI_SLOT(ivrs_alias),
- PCI_FUNC(ivrs_alias), dev_name(dev), pdev->vendor, pdev->device,
- PCI_BUS_NUM(pci_alias), PCI_SLOT(pci_alias),
- PCI_FUNC(pci_alias));
-
- /*
- * If we don't have a PCI DMA alias and the IVRS alias is on the same
- * bus, then the IVRS table may know about a quirk that we don't.
- */
- if (pci_alias == devid &&
- PCI_BUS_NUM(ivrs_alias) == pdev->bus->number) {
- pdev->dev_flags |= PCI_DEV_FLAGS_DMA_ALIAS_DEVFN;
- pdev->dma_alias_devfn = ivrs_alias & 0xff;
- pr_info("AMD-Vi: Added PCI DMA alias %02x.%d for %s\n",
- PCI_SLOT(ivrs_alias), PCI_FUNC(ivrs_alias),
- dev_name(dev));
- }
-
- return ivrs_alias;
-}
-
static int iommu_init_device(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct iommu_dev_data *dev_data;
- u16 alias;
if (dev->archdata.iommu)
return 0;
@@ -386,24 +308,6 @@ static int iommu_init_device(struct device *dev)
if (!dev_data)
return -ENOMEM;
- alias = get_alias(dev);
-
- if (alias != dev_data->devid) {
- struct iommu_dev_data *alias_data;
-
- alias_data = find_dev_data(alias);
- if (alias_data == NULL) {
- pr_err("AMD-Vi: Warning: Unhandled device %s\n",
- dev_name(dev));
- free_dev_data(dev_data);
- return -ENOTSUPP;
- }
- dev_data->alias_data = alias_data;
-
- /* Add device to the alias_list */
- list_add(&dev_data->alias_list, &alias_data->alias_list);
- }
-
if (pci_iommuv2_capable(pdev)) {
struct amd_iommu *iommu;
@@ -445,9 +349,6 @@ static void iommu_uninit_device(struct device *dev)
iommu_group_remove_device(dev);
- /* Unlink from alias, it may change if another device is re-plugged */
- dev_data->alias_data = NULL;
-
/* Remove dma-ops */
dev->archdata.dma_ops = NULL;
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 07/12] iommu/amd: Align DTE flag definitions
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (5 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 06/12] iommu/amd: Remove old alias handling code Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 08/12] iommu/amd: Remove cmd_buf_size and evt_buf_size from struct amd_iommu Joerg Roedel
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
No functional change.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_types.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index f659088..3026b34 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -295,8 +295,8 @@
#define IOMMU_PTE_IR (1ULL << 61)
#define IOMMU_PTE_IW (1ULL << 62)
-#define DTE_FLAG_IOTLB (0x01UL << 32)
-#define DTE_FLAG_GV (0x01ULL << 55)
+#define DTE_FLAG_IOTLB (1ULL << 32)
+#define DTE_FLAG_GV (1ULL << 55)
#define DTE_GLX_SHIFT (56)
#define DTE_GLX_MASK (3)
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 08/12] iommu/amd: Remove cmd_buf_size and evt_buf_size from struct amd_iommu
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (6 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 07/12] iommu/amd: Align DTE flag definitions Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 09/12] iommu/amd: Cleanup buffer allocation Joerg Roedel
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The driver always uses a constant size for these buffers
anyway, so there is no need to waste memory to store the
sizes.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 10 ++++------
drivers/iommu/amd_iommu_init.c | 8 +-------
drivers/iommu/amd_iommu_types.h | 4 ----
3 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 1a7c78d..8886488 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -534,7 +534,7 @@ static void iommu_poll_events(struct amd_iommu *iommu)
while (head != tail) {
iommu_print_event(iommu, iommu->evt_buf + head);
- head = (head + EVENT_ENTRY_SIZE) % iommu->evt_buf_size;
+ head = (head + EVENT_ENTRY_SIZE) % EVT_BUFFER_SIZE;
}
writel(head, iommu->mmio_base + MMIO_EVT_HEAD_OFFSET);
@@ -684,7 +684,7 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
u8 *target;
target = iommu->cmd_buf + tail;
- tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size;
+ tail = (tail + sizeof(*cmd)) % CMD_BUFFER_SIZE;
/* Copy command to buffer */
memcpy(target, cmd, sizeof(*cmd));
@@ -851,15 +851,13 @@ static int iommu_queue_command_sync(struct amd_iommu *iommu,
u32 left, tail, head, next_tail;
unsigned long flags;
- WARN_ON(iommu->cmd_buf_size & CMD_BUFFER_UNINITIALIZED);
-
again:
spin_lock_irqsave(&iommu->lock, flags);
head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET);
tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
- next_tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size;
- left = (head - next_tail) % iommu->cmd_buf_size;
+ next_tail = (tail + sizeof(*cmd)) % CMD_BUFFER_SIZE;
+ left = (head - next_tail) % CMD_BUFFER_SIZE;
if (left <= 2) {
struct iommu_cmd sync_cmd;
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 1b066e7..930a5d4 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -521,8 +521,6 @@ static u8 * __init alloc_command_buffer(struct amd_iommu *iommu)
if (cmd_buf == NULL)
return NULL;
- iommu->cmd_buf_size = CMD_BUFFER_SIZE | CMD_BUFFER_UNINITIALIZED;
-
return cmd_buf;
}
@@ -557,13 +555,11 @@ static void iommu_enable_command_buffer(struct amd_iommu *iommu)
&entry, sizeof(entry));
amd_iommu_reset_cmd_buffer(iommu);
- iommu->cmd_buf_size &= ~(CMD_BUFFER_UNINITIALIZED);
}
static void __init free_command_buffer(struct amd_iommu *iommu)
{
- free_pages((unsigned long)iommu->cmd_buf,
- get_order(iommu->cmd_buf_size & ~(CMD_BUFFER_UNINITIALIZED)));
+ free_pages((unsigned long)iommu->cmd_buf, get_order(CMD_BUFFER_SIZE));
}
/* allocates the memory where the IOMMU will log its events to */
@@ -575,8 +571,6 @@ static u8 * __init alloc_event_buffer(struct amd_iommu *iommu)
if (iommu->evt_buf == NULL)
return NULL;
- iommu->evt_buf_size = EVT_BUFFER_SIZE;
-
return iommu->evt_buf;
}
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 3026b34..921b2e9 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -528,11 +528,7 @@ struct amd_iommu {
/* command buffer virtual address */
u8 *cmd_buf;
- /* size of command buffer */
- u32 cmd_buf_size;
- /* size of event buffer */
- u32 evt_buf_size;
/* event buffer virtual address */
u8 *evt_buf;
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 09/12] iommu/amd: Cleanup buffer allocation
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (7 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 08/12] iommu/amd: Remove cmd_buf_size and evt_buf_size from struct amd_iommu Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 10/12] iommu/amd: Initialize amd_iommu_last_bdf for DEV_ALL Joerg Roedel
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Clean up the functions to allocate the command, event and
ppr-log buffers. Remove redundant code and change the return
value to int.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_init.c | 46 +++++++++++++++---------------------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 930a5d4..2f7fb1e 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -513,15 +513,12 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)
* write commands to that buffer later and the IOMMU will execute them
* asynchronously
*/
-static u8 * __init alloc_command_buffer(struct amd_iommu *iommu)
+static int __init alloc_command_buffer(struct amd_iommu *iommu)
{
- u8 *cmd_buf = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
- get_order(CMD_BUFFER_SIZE));
+ iommu->cmd_buf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+ get_order(CMD_BUFFER_SIZE));
- if (cmd_buf == NULL)
- return NULL;
-
- return cmd_buf;
+ return iommu->cmd_buf ? 0 : -ENOMEM;
}
/*
@@ -563,15 +560,12 @@ static void __init free_command_buffer(struct amd_iommu *iommu)
}
/* allocates the memory where the IOMMU will log its events to */
-static u8 * __init alloc_event_buffer(struct amd_iommu *iommu)
+static int __init alloc_event_buffer(struct amd_iommu *iommu)
{
- iommu->evt_buf = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
- get_order(EVT_BUFFER_SIZE));
+ iommu->evt_buf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+ get_order(EVT_BUFFER_SIZE));
- if (iommu->evt_buf == NULL)
- return NULL;
-
- return iommu->evt_buf;
+ return iommu->evt_buf ? 0 : -ENOMEM;
}
static void iommu_enable_event_buffer(struct amd_iommu *iommu)
@@ -598,15 +592,12 @@ static void __init free_event_buffer(struct amd_iommu *iommu)
}
/* allocates the memory where the IOMMU will log its events to */
-static u8 * __init alloc_ppr_log(struct amd_iommu *iommu)
+static int __init alloc_ppr_log(struct amd_iommu *iommu)
{
- iommu->ppr_log = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
- get_order(PPR_LOG_SIZE));
+ iommu->ppr_log = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+ get_order(PPR_LOG_SIZE));
- if (iommu->ppr_log == NULL)
- return NULL;
-
- return iommu->ppr_log;
+ return iommu->ppr_log ? 0 : -ENOMEM;
}
static void iommu_enable_ppr_log(struct amd_iommu *iommu)
@@ -1105,12 +1096,10 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
if (!iommu->mmio_base)
return -ENOMEM;
- iommu->cmd_buf = alloc_command_buffer(iommu);
- if (!iommu->cmd_buf)
+ if (alloc_command_buffer(iommu))
return -ENOMEM;
- iommu->evt_buf = alloc_event_buffer(iommu);
- if (!iommu->evt_buf)
+ if (alloc_event_buffer(iommu))
return -ENOMEM;
iommu->int_enabled = false;
@@ -1302,11 +1291,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)
amd_iommu_v2_present = true;
}
- if (iommu_feature(iommu, FEATURE_PPR)) {
- iommu->ppr_log = alloc_ppr_log(iommu);
- if (!iommu->ppr_log)
- return -ENOMEM;
- }
+ if (iommu_feature(iommu, FEATURE_PPR) && alloc_ppr_log(iommu))
+ return -ENOMEM;
if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE))
amd_iommu_np_cache = true;
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 10/12] iommu/amd: Initialize amd_iommu_last_bdf for DEV_ALL
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (8 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 09/12] iommu/amd: Cleanup buffer allocation Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 11/12] iommu/amd: Remove first/last_device handling Joerg Roedel
2015-10-20 15:33 ` [PATCH 12/12] iommu/amd: Remove find_last_devid_on_pci() Joerg Roedel
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Also initialize the amd_iommu_last_bdf variable when a
IVHD_DEV_ALL entry is found in the ACPI table.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_init.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 2f7fb1e..6432bdb 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -441,6 +441,10 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h)
while (p < end) {
dev = (struct ivhd_entry *)p;
switch (dev->type) {
+ case IVHD_DEV_ALL:
+ /* Use maximum BDF value for DEV_ALL */
+ update_last_devid(0xffff);
+ break;
case IVHD_DEV_SELECT:
case IVHD_DEV_RANGE_END:
case IVHD_DEV_ALIAS:
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 11/12] iommu/amd: Remove first/last_device handling
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (9 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 10/12] iommu/amd: Initialize amd_iommu_last_bdf for DEV_ALL Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
2015-10-20 15:33 ` [PATCH 12/12] iommu/amd: Remove find_last_devid_on_pci() Joerg Roedel
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The code is buggy and the values read from PCI are not
reliable anyway, so it is the best to just remove this code.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_init.c | 34 +++-------------------------------
drivers/iommu/amd_iommu_types.h | 5 -----
2 files changed, 3 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 6432bdb..e3afa37 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -824,20 +824,10 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
switch (e->type) {
case IVHD_DEV_ALL:
- DUMP_printk(" DEV_ALL\t\t\t first devid: %02x:%02x.%x"
- " last device %02x:%02x.%x flags: %02x\n",
- PCI_BUS_NUM(iommu->first_device),
- PCI_SLOT(iommu->first_device),
- PCI_FUNC(iommu->first_device),
- PCI_BUS_NUM(iommu->last_device),
- PCI_SLOT(iommu->last_device),
- PCI_FUNC(iommu->last_device),
- e->flags);
+ DUMP_printk(" DEV_ALL\t\t\tflags: %02x\n", e->flags);
- for (dev_i = iommu->first_device;
- dev_i <= iommu->last_device; ++dev_i)
- set_dev_entry_from_acpi(iommu, dev_i,
- e->flags, 0);
+ for (dev_i = 0; dev_i <= amd_iommu_last_bdf; ++dev_i)
+ set_dev_entry_from_acpi(iommu, dev_i, e->flags, 0);
break;
case IVHD_DEV_SELECT:
@@ -993,17 +983,6 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
return 0;
}
-/* Initializes the device->iommu mapping for the driver */
-static int __init init_iommu_devices(struct amd_iommu *iommu)
-{
- u32 i;
-
- for (i = iommu->first_device; i <= iommu->last_device; ++i)
- set_iommu_for_device(iommu, i);
-
- return 0;
-}
-
static void __init free_iommu_one(struct amd_iommu *iommu)
{
free_command_buffer(iommu);
@@ -1122,8 +1101,6 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
*/
amd_iommu_rlookup_table[iommu->devid] = NULL;
- init_iommu_devices(iommu);
-
return 0;
}
@@ -1253,11 +1230,6 @@ static int iommu_init_pci(struct amd_iommu *iommu)
pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET,
&misc);
- iommu->first_device = PCI_DEVID(MMIO_GET_BUS(range),
- MMIO_GET_FD(range));
- iommu->last_device = PCI_DEVID(MMIO_GET_BUS(range),
- MMIO_GET_LD(range));
-
if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB)))
amd_iommu_iotlb_sup = false;
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index 921b2e9..fc9501d 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -516,11 +516,6 @@ struct amd_iommu {
/* pci domain of this IOMMU */
u16 pci_seg;
- /* first device this IOMMU handles. read from PCI */
- u16 first_device;
- /* last device this IOMMU handles. read from PCI */
- u16 last_device;
-
/* start of exclusion range of that IOMMU */
u64 exclusion_start;
/* length of exclusion range of that IOMMU */
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 12/12] iommu/amd: Remove find_last_devid_on_pci()
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
` (10 preceding siblings ...)
2015-10-20 15:33 ` [PATCH 11/12] iommu/amd: Remove first/last_device handling Joerg Roedel
@ 2015-10-20 15:33 ` Joerg Roedel
11 siblings, 0 replies; 13+ messages in thread
From: Joerg Roedel @ 2015-10-20 15:33 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The value read from the PCI header is not reliable, so
remove this code.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_init.c | 19 -------------------
1 file changed, 19 deletions(-)
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index e3afa37..65674104 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -408,20 +408,6 @@ static inline int ivhd_entry_length(u8 *ivhd)
}
/*
- * This function reads the last device id the IOMMU has to handle from the PCI
- * capability header for this IOMMU
- */
-static int __init find_last_devid_on_pci(int bus, int dev, int fn, int cap_ptr)
-{
- u32 cap;
-
- cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET);
- update_last_devid(PCI_DEVID(MMIO_GET_BUS(cap), MMIO_GET_LD(cap)));
-
- return 0;
-}
-
-/*
* After reading the highest device id from the IOMMU PCI capability header
* this function looks if there is a higher device id defined in the ACPI table
*/
@@ -433,11 +419,6 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h)
p += sizeof(*h);
end += h->length;
- find_last_devid_on_pci(PCI_BUS_NUM(h->devid),
- PCI_SLOT(h->devid),
- PCI_FUNC(h->devid),
- h->cap_ptr);
-
while (p < end) {
dev = (struct ivhd_entry *)p;
switch (dev->type) {
--
1.9.1
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2015-10-20 15:36 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-20 15:33 [PATCH 00/12] AMD IOMMU alias handling cleanups and code removal Joerg Roedel
2015-10-20 15:33 ` [PATCH 01/12] iommu/amd: Do not BUG_ON in __detach_device() Joerg Roedel
2015-10-20 15:33 ` [PATCH 02/12] iommu/amd: Do not iterate over alias-list in __[attach|detach]_device Joerg Roedel
2015-10-20 15:33 ` [PATCH 03/12] iommu/amd: Don't disable IRQs in __detach_device Joerg Roedel
2015-10-20 15:33 ` [PATCH 04/12] iommu/amd: WARN when __[attach|detach]_device are called with irqs enabled Joerg Roedel
2015-10-20 15:33 ` [PATCH 05/12] iommu/amd: Set alias DTE in do_attach/do_detach Joerg Roedel
2015-10-20 15:33 ` [PATCH 06/12] iommu/amd: Remove old alias handling code Joerg Roedel
2015-10-20 15:33 ` [PATCH 07/12] iommu/amd: Align DTE flag definitions Joerg Roedel
2015-10-20 15:33 ` [PATCH 08/12] iommu/amd: Remove cmd_buf_size and evt_buf_size from struct amd_iommu Joerg Roedel
2015-10-20 15:33 ` [PATCH 09/12] iommu/amd: Cleanup buffer allocation Joerg Roedel
2015-10-20 15:33 ` [PATCH 10/12] iommu/amd: Initialize amd_iommu_last_bdf for DEV_ALL Joerg Roedel
2015-10-20 15:33 ` [PATCH 11/12] iommu/amd: Remove first/last_device handling Joerg Roedel
2015-10-20 15:33 ` [PATCH 12/12] iommu/amd: Remove find_last_devid_on_pci() Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®