mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: iommu@lists.linux-foundation.org
Cc: linux-kernel@vger.kernel.org, joro@8bytes.org, jroedel@suse.de
Subject: [PATCH 19/23] iommu/amd: Initialize new aperture range before making it visible
Date: Tue, 22 Dec 2015 23:21:24 +0100	[thread overview]
Message-ID: <1450822888-22590-20-git-send-email-joro@8bytes.org> (raw)
In-Reply-To: <1450822888-22590-1-git-send-email-joro@8bytes.org>

From: Joerg Roedel <jroedel@suse.de>

Make sure the aperture range is fully initialized before it
is visible to the address allocator.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index ecdd3f7..11ee885 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -1425,8 +1425,10 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
 			   bool populate, gfp_t gfp)
 {
 	int index = dma_dom->aperture_size >> APERTURE_RANGE_SHIFT;
-	struct amd_iommu *iommu;
 	unsigned long i, old_size, pte_pgsize;
+	struct aperture_range *range;
+	struct amd_iommu *iommu;
+	unsigned long flags;
 
 #ifdef CONFIG_IOMMU_STRESS
 	populate = false;
@@ -1435,17 +1437,17 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
 	if (index >= APERTURE_MAX_RANGES)
 		return -ENOMEM;
 
-	dma_dom->aperture[index] = kzalloc(sizeof(struct aperture_range), gfp);
-	if (!dma_dom->aperture[index])
+	range = kzalloc(sizeof(struct aperture_range), gfp);
+	if (!range)
 		return -ENOMEM;
 
-	dma_dom->aperture[index]->bitmap = (void *)get_zeroed_page(gfp);
-	if (!dma_dom->aperture[index]->bitmap)
+	range->bitmap = (void *)get_zeroed_page(gfp);
+	if (!range->bitmap)
 		goto out_free;
 
-	dma_dom->aperture[index]->offset = dma_dom->aperture_size;
+	range->offset = dma_dom->aperture_size;
 
-	spin_lock_init(&dma_dom->aperture[index]->bitmap_lock);
+	spin_lock_init(&range->bitmap_lock);
 
 	if (populate) {
 		unsigned long address = dma_dom->aperture_size;
@@ -1458,14 +1460,18 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
 			if (!pte)
 				goto out_free;
 
-			dma_dom->aperture[index]->pte_pages[i] = pte_page;
+			range->pte_pages[i] = pte_page;
 
 			address += APERTURE_RANGE_SIZE / 64;
 		}
 	}
 
-	old_size                = dma_dom->aperture_size;
-	dma_dom->aperture_size += APERTURE_RANGE_SIZE;
+	/* First take the bitmap_lock and then publish the range */
+	spin_lock_irqsave(&range->bitmap_lock, flags);
+
+	old_size                 = dma_dom->aperture_size;
+	dma_dom->aperture[index] = range;
+	dma_dom->aperture_size  += APERTURE_RANGE_SIZE;
 
 	/* Reserve address range used for MSI messages */
 	if (old_size < MSI_ADDR_BASE_LO &&
@@ -1512,15 +1518,16 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
 
 	update_domain(&dma_dom->domain);
 
+	spin_unlock_irqrestore(&range->bitmap_lock, flags);
+
 	return 0;
 
 out_free:
 	update_domain(&dma_dom->domain);
 
-	free_page((unsigned long)dma_dom->aperture[index]->bitmap);
+	free_page((unsigned long)range->bitmap);
 
-	kfree(dma_dom->aperture[index]);
-	dma_dom->aperture[index] = NULL;
+	kfree(range);
 
 	return -ENOMEM;
 }
-- 
1.9.1


  parent reply	other threads:[~2015-12-22 22:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-22 22:21 [PATCH 00/23] AMD IOMMU DMA-API Scalability Improvements Joerg Roedel
2015-12-22 22:21 ` [PATCH 01/23] iommu/amd: Warn only once on unexpected pte value Joerg Roedel
2015-12-22 22:21 ` [PATCH 02/23] iommu/amd: Move 'struct dma_ops_domain' definition to amd_iommu.c Joerg Roedel
2015-12-22 22:21 ` [PATCH 03/23] iommu/amd: Introduce bitmap_lock in struct aperture_range Joerg Roedel
2015-12-22 22:21 ` [PATCH 04/23] iommu/amd: Flush IOMMU TLB on __map_single error path Joerg Roedel
2015-12-22 22:21 ` [PATCH 05/23] iommu/amd: Flush the IOMMU TLB before the addresses are freed Joerg Roedel
2015-12-22 22:21 ` [PATCH 06/23] iommu/amd: Pass correct shift to iommu_area_alloc() Joerg Roedel
2015-12-22 22:21 ` [PATCH 07/23] iommu/amd: Add dma_ops_aperture_alloc() function Joerg Roedel
2015-12-22 22:21 ` [PATCH 08/23] iommu/amd: Move aperture_range.offset to another cache-line Joerg Roedel
2015-12-22 22:21 ` [PATCH 09/23] iommu/amd: Retry address allocation within one aperture Joerg Roedel
2015-12-22 22:21 ` [PATCH 10/23] iommu/amd: Flush iommu tlb in dma_ops_aperture_alloc() Joerg Roedel
2015-12-22 22:21 ` [PATCH 11/23] iommu/amd: Remove 'start' parameter from dma_ops_area_alloc Joerg Roedel
2015-12-22 22:21 ` [PATCH 12/23] iommu/amd: Rename dma_ops_domain->next_address to next_index Joerg Roedel
2015-12-22 22:21 ` [PATCH 13/23] iommu/amd: Flush iommu tlb in dma_ops_free_addresses Joerg Roedel
2015-12-22 22:21 ` [PATCH 14/23] iommu/amd: Iterate over all aperture ranges in dma_ops_area_alloc Joerg Roedel
2015-12-22 22:21 ` [PATCH 15/23] iommu/amd: Remove need_flush from struct dma_ops_domain Joerg Roedel
2015-12-22 22:21 ` [PATCH 16/23] iommu/amd: Optimize dma_ops_free_addresses Joerg Roedel
2015-12-22 22:21 ` [PATCH 17/23] iommu/amd: Allocate new aperture ranges in dma_ops_alloc_addresses Joerg Roedel
2015-12-22 22:21 ` [PATCH 18/23] iommu/amd: Build io page-tables with cmpxchg64 Joerg Roedel
2015-12-22 22:21 ` Joerg Roedel [this message]
2015-12-22 22:21 ` [PATCH 20/23] iommu/amd: Relax locking in dma_ops path Joerg Roedel
2015-12-22 22:21 ` [PATCH 21/23] iommu/amd: Make dma_ops_domain->next_index percpu Joerg Roedel
2015-12-22 22:21 ` [PATCH 22/23] iommu/amd: Use trylock to aquire bitmap_lock Joerg Roedel
2015-12-22 22:21 ` [PATCH 23/23] iommu/amd: Preallocate dma_ops apertures based on dma_mask 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=1450822888-22590-20-git-send-email-joro@8bytes.org \
    --to=joro@8bytes.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®