* re: iommu/amd: Put IOMMUv2 devices in a direct mapped domain
@ 2015-06-10 15:36 Dan Carpenter
2015-06-11 7:35 ` [PATCH] iommu/amd: Handle errors returned from iommu_init_device Joerg Roedel
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2015-06-10 15:36 UTC (permalink / raw)
To: jroedel-l3A5Bk7waGM; +Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Hello Joerg Roedel,
This is a semi-automatic email about new static checker warnings.
The patch 0a3da4517107: "iommu/amd: Put IOMMUv2 devices in a direct
mapped domain" from May 28, 2015, leads to the following Smatch
complaint:
drivers/iommu/amd_iommu.c:2285 amd_iommu_add_device()
error: we previously assumed 'dev_data' could be null (see line 2279)
drivers/iommu/amd_iommu.c
2278 dev_data = get_dev_data(dev);
2279 if (dev_data && dev_data->iommu_v2)
^^^^^^^^
Check.
2280 iommu_request_dm_for_dev(dev);
2281
2282 /* Domains are initialized for this device - have a look what we ended up with */
2283 domain = iommu_get_domain_for_dev(dev);
2284 if (domain->type == IOMMU_DOMAIN_IDENTITY) {
2285 dev_data->passthrough = true;
^^^^^^^^^^
Unchecked dereference.
2286 dev->archdata.dma_ops = &nommu_dma_ops;
2287 } else {
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] iommu/amd: Handle errors returned from iommu_init_device
2015-06-10 15:36 iommu/amd: Put IOMMUv2 devices in a direct mapped domain Dan Carpenter
@ 2015-06-11 7:35 ` Joerg Roedel
0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2015-06-11 7:35 UTC (permalink / raw)
To: Dan Carpenter; +Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Hi Dan,
On Wed, Jun 10, 2015 at 06:36:18PM +0300, Dan Carpenter wrote:
> This is a semi-automatic email about new static checker warnings.
>
> The patch 0a3da4517107: "iommu/amd: Put IOMMUv2 devices in a direct
> mapped domain" from May 28, 2015, leads to the following Smatch
> complaint:
>
> drivers/iommu/amd_iommu.c:2285 amd_iommu_add_device()
> error: we previously assumed 'dev_data' could be null (see line 2279)
>
> drivers/iommu/amd_iommu.c
> 2278 dev_data = get_dev_data(dev);
> 2279 if (dev_data && dev_data->iommu_v2)
> ^^^^^^^^
> Check.
>
> 2280 iommu_request_dm_for_dev(dev);
> 2281
> 2282 /* Domains are initialized for this device - have a look what we ended up with */
> 2283 domain = iommu_get_domain_for_dev(dev);
> 2284 if (domain->type == IOMMU_DOMAIN_IDENTITY) {
> 2285 dev_data->passthrough = true;
> ^^^^^^^^^^
> Unchecked dereference.
>
> 2286 dev->archdata.dma_ops = &nommu_dma_ops;
> 2287 } else {
This was a bit more complicated. I fixed it with this add-on patch:
>From 8a683d98936d7aa4e3ae554efca3a52c042593b9 Mon Sep 17 00:00:00 2001
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Date: Thu, 11 Jun 2015 09:21:39 +0200
Subject: [PATCH] iommu/amd: Handle errors returned from iommu_init_device
Without this patch only -ENOTSUPP is handled, but there are
other possible errors. Handle them too.
Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 6659b51..73fc4b7 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2265,7 +2265,11 @@ static int amd_iommu_add_device(struct device *dev)
iommu = amd_iommu_rlookup_table[devid];
ret = iommu_init_device(dev);
- if (ret == -ENOTSUPP) {
+ if (ret) {
+ if (ret != -ENOTSUPP)
+ pr_err("Failed to initialize device %s - trying to proceed anyway\n",
+ dev_name(dev));
+
iommu_ignore_device(dev);
dev->archdata.dma_ops = &nommu_dma_ops;
goto out;
@@ -2273,7 +2277,10 @@ static int amd_iommu_add_device(struct device *dev)
init_iommu_group(dev);
dev_data = get_dev_data(dev);
- if (dev_data && dev_data->iommu_v2)
+
+ BUG_ON(!dev_data);
+
+ if (dev_data->iommu_v2)
iommu_request_dm_for_dev(dev);
/* Domains are initialized for this device - have a look what we ended up with */
--
1.8.4.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-06-11 7:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-10 15:36 iommu/amd: Put IOMMUv2 devices in a direct mapped domain Dan Carpenter
2015-06-11 7:35 ` [PATCH] iommu/amd: Handle errors returned from iommu_init_device Joerg Roedel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.