From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755330AbbLVWXu (ORCPT ); Tue, 22 Dec 2015 17:23:50 -0500 Received: from 8bytes.org ([81.169.241.247]:47614 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755457AbbLVWWE (ORCPT ); Tue, 22 Dec 2015 17:22:04 -0500 From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, joro@8bytes.org, jroedel@suse.de Subject: [PATCH 17/23] iommu/amd: Allocate new aperture ranges in dma_ops_alloc_addresses Date: Tue, 22 Dec 2015 23:21:22 +0100 Message-Id: <1450822888-22590-18-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450822888-22590-1-git-send-email-joro@8bytes.org> References: <1450822888-22590-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel It really belongs there and not in __map_single. Signed-off-by: Joerg Roedel --- drivers/iommu/amd_iommu.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index c657e48..4c926da 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1597,13 +1597,19 @@ static unsigned long dma_ops_alloc_addresses(struct device *dev, unsigned long align_mask, u64 dma_mask) { - unsigned long address; + unsigned long address = -1; #ifdef CONFIG_IOMMU_STRESS dom->next_index = 0; #endif - address = dma_ops_area_alloc(dev, dom, pages, align_mask, dma_mask); + while (address == -1) { + address = dma_ops_area_alloc(dev, dom, pages, + align_mask, dma_mask); + + if (address == -1 && alloc_new_range(dom, true, GFP_ATOMIC)) + break; + } if (unlikely(address == -1)) address = DMA_ERROR_CODE; @@ -2460,26 +2466,11 @@ static dma_addr_t __map_single(struct device *dev, if (align) align_mask = (1UL << get_order(size)) - 1; -retry: address = dma_ops_alloc_addresses(dev, dma_dom, pages, align_mask, dma_mask); - if (unlikely(address == DMA_ERROR_CODE)) { - if (alloc_new_range(dma_dom, false, GFP_ATOMIC)) - goto out; - - /* - * setting next_index here will let the address - * allocator only scan the new allocated range in the - * first run. This is a small optimization. - */ - dma_dom->next_index = dma_dom->aperture_size >> APERTURE_RANGE_SHIFT; - /* - * aperture was successfully enlarged by 128 MB, try - * allocation again - */ - goto retry; - } + if (address == DMA_ERROR_CODE) + goto out; start = address; for (i = 0; i < pages; ++i) { -- 1.9.1