Linux IOMMU Development
 help / color / mirror / Atom feed
From: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
To: George Wang <xuw2015-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: dma_ops_domain_alloc causes kernel 4.1.0-next-20150626+ panic
Date: Tue, 30 Jun 2015 09:44:54 +0200	[thread overview]
Message-ID: <20150630074454.GO18569@8bytes.org> (raw)
In-Reply-To: <CAPBX1xLA_GDeoi9wq-9A7njwzL3NBqJYYT_PqhwEzBAg=9=8kA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Tue, Jun 30, 2015 at 11:55:24AM +0800, George Wang wrote:
> [   11.734774] Call Trace:
> [   11.735635]  [<ffffffff8168fde1>] __mutex_lock_slowpath+0x91/0x120
> [   11.737676]  [<ffffffff81318798>] ? ida_simple_get+0x98/0x100
> [   11.739682]  [<ffffffff8168fe93>] mutex_lock+0x23/0x37
> [   11.741407]  [<ffffffff8143513a>] amd_iommu_map+0x4a/0x1b0
> [   11.743293]  [<ffffffff8143081a>] iommu_map+0xfa/0x200
> [   11.745025]  [<ffffffff81431587>] iommu_group_add_device+0x327/0x390
> [   11.747184]  [<ffffffff814316fb>] iommu_group_get_forv+0x10b/0x1f0
> [   11.849564]  [<ffffffff81436ac6>] amd_iommu_add_device+0x1b6/0x580

Ah, your AMD IOMMU system probably has unity mappings defined in its
ACPI table. I don't have systems with unity mappings defined, so I
couldn't test this. On what system you are running this test (system or
mainboard vendor and type)

Anyway, here is a patch that should fix this issue for you, can you
please test it?

>From a83e7544c3bc1bd843478e0809cc9781e844fd08 Mon Sep 17 00:00:00 2001
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Date: Tue, 30 Jun 2015 08:56:11 +0200
Subject: [PATCH] iommu/amd: Introduce protection_domain_init() function

This function contains the common parts between the
initialization of dma_ops_domains and usual protection
domains. This also fixes a long-standing bug which was
uncovered by recent changes, in which the api_lock was not
initialized for dma_ops_domains.

Reported-by: George Wang <xuw2015-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
 drivers/iommu/amd_iommu.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index c5677ed..cedbf00 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -116,6 +116,7 @@ struct kmem_cache *amd_iommu_irq_cache;
 
 static void update_domain(struct protection_domain *domain);
 static int alloc_passthrough_domain(void);
+static int protection_domain_init(struct protection_domain *domain);
 
 /****************************************************************************
  *
@@ -1880,12 +1881,9 @@ static struct dma_ops_domain *dma_ops_domain_alloc(void)
 	if (!dma_dom)
 		return NULL;
 
-	spin_lock_init(&dma_dom->domain.lock);
-
-	dma_dom->domain.id = domain_id_alloc();
-	if (dma_dom->domain.id == 0)
+	if (protection_domain_init(&dma_dom->domain))
 		goto free_dma_dom;
-	INIT_LIST_HEAD(&dma_dom->domain.dev_list);
+
 	dma_dom->domain.mode = PAGE_MODE_2_LEVEL;
 	dma_dom->domain.pt_root = (void *)get_zeroed_page(GFP_KERNEL);
 	dma_dom->domain.flags = PD_DMA_OPS_MASK;
@@ -2915,6 +2913,18 @@ static void protection_domain_free(struct protection_domain *domain)
 	kfree(domain);
 }
 
+static int protection_domain_init(struct protection_domain *domain)
+{
+	spin_lock_init(&domain->lock);
+	mutex_init(&domain->api_lock);
+	domain->id = domain_id_alloc();
+	if (!domain->id)
+		return -ENOMEM;
+	INIT_LIST_HEAD(&domain->dev_list);
+
+	return 0;
+}
+
 static struct protection_domain *protection_domain_alloc(void)
 {
 	struct protection_domain *domain;
@@ -2923,12 +2933,8 @@ static struct protection_domain *protection_domain_alloc(void)
 	if (!domain)
 		return NULL;
 
-	spin_lock_init(&domain->lock);
-	mutex_init(&domain->api_lock);
-	domain->id = domain_id_alloc();
-	if (!domain->id)
+	if (protection_domain_init(domain))
 		goto out_err;
-	INIT_LIST_HEAD(&domain->dev_list);
 
 	add_domain_to_list(domain);
 
-- 
1.8.4.5

  parent reply	other threads:[~2015-06-30  7:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 17:44 dma_ops_domain_alloc causes kernel 4.1.0-next-20150626+ panic George Wang
     [not found] ` <CAPBX1x+zagVVYebbXU0M7VkEaDkzvqBGnkt6PW_N42fRQRQ9Gg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-29 19:34   ` Joerg Roedel
     [not found]     ` <20150629193402.GM18569-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-06-30  3:55       ` George Wang
     [not found]         ` <CAPBX1xLA_GDeoi9wq-9A7njwzL3NBqJYYT_PqhwEzBAg=9=8kA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-30  7:44           ` Joerg Roedel [this message]
     [not found]             ` <20150630074454.GO18569-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-07-01  5:20               ` George Wang
     [not found]                 ` <CAPBX1x+OK8EMwDsripY71jF44d73Qv0jBxyM+jJgPMzNVPTyaw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-01  6:44                   ` Joerg Roedel

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=20150630074454.GO18569@8bytes.org \
    --to=joro-zlv9swrftaidnm+yrofe0a@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=xuw2015-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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