Received: by 10.223.185.116 with SMTP id b49csp2863221wrg; Mon, 5 Mar 2018 09:52:57 -0800 (PST) X-Google-Smtp-Source: AG47ELvUXLmdXWvN1mt4JK/jyrxgNVZ+Urj7CliU0YUlp5kaR+jQUOPKyZCWckaxmn7QKsf6gD57 X-Received: by 2002:a17:902:9883:: with SMTP id s3-v6mr13592292plp.96.1520272377455; Mon, 05 Mar 2018 09:52:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520272377; cv=none; d=google.com; s=arc-20160816; b=WCXO8CtuHeiIDKtXXeCJqNq17LHSBfrft/SADW5ADRAYTKXp0RtpmI8h8UDoV7xiZJ ucLB62ykl2vgd9KXI/Sc4IyOe64yJt6b1wkrLs/8yUGw+HWPpMe5iddjqlgsvUYZco7P B4mf4z5RehHLIQxVFQMfE4S9eE2h1itNzzf7icAoKJDTc5MKAA25Nt3ZSMIhQrJMjVnd 4qvo0P+r1WdkOHPbVqzoJjrXSP+0AxZm0AZPekAip6GcfOoNc6suB25+VEr31swTIpV4 plauj1G+86Sydw2h3NnqE94SwSglf/RnzKIuwaBWXJMVBeJyTYmM6/wywGOl/0dxqM9t bhGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=frM5LW3HlTQT1xjEeg60meoidMKDkQvSgNe/NslqtQI=; b=vywgNYupd7oDafUWWXt7xjhIPWAK4xJ54h5R2JVbpaNpybXAl8VrVXK2foK0lR6IKG JpDUlZlPN+kds/tBVEPVe672r11vKD8VWI1RqeI3GBET9j5TbWN0daas+TeTWVstKLDD e+CYNfUdM1i/+h8z/of1vjMrC5cgzDCyKnanKnng2G6PoY/I3d/I2KxxqMjgFpPg87G5 0BFXomt4eiR9VSzgYhq9i00/Ka1y4utZH1cd2Egl5j+u0BZPMSf/GhfBEA/Ma+VV40MX va8tBPRiV/K2K1cW/haVTDkIOL7ulyMfjoODvfFntWnonBOxMftQtpDjQe3GJ0ovC8kn rVvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nmAB+MFS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10-v6si9675421plk.706.2018.03.05.09.52.43; Mon, 05 Mar 2018 09:52:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nmAB+MFS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932555AbeCERue (ORCPT + 99 others); Mon, 5 Mar 2018 12:50:34 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:60246 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752561AbeCERrO (ORCPT ); Mon, 5 Mar 2018 12:47:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=frM5LW3HlTQT1xjEeg60meoidMKDkQvSgNe/NslqtQI=; b=nmAB+MFSU3f/sXa1QhJv5eKDT lubQMgkv4tglE5PnFxsS8jN9/iJlvlI521oziT1+KxvkNPCM9HnZIDrosY1SIm5ev8jesE7Igsl6L XPse+9+ULd/bMs0bfI+8dQ4Eg5/ytJZ5EhcuT+DPggwglz3VDSKnB6XBsq+CXSLwzxSDHJcCTHn6l qnU3AZk9K6dtmkjhEfUxxtavUthXQU4iMQNYUuO5ap339NndzW3+Go6YNmj7owzDyDnG7lZpRY9Wc HlYVAn+nlVnsxOd/5GI+9kPbjVB0PZwDOJTjAveJqXtp8d6jFz1ue3jDk80dzEtw6I2GLnlH5L7tP VkIFnKiSQ==; Received: from [209.116.154.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1esuCT-0002u3-Cr; Mon, 05 Mar 2018 17:47:01 +0000 From: Christoph Hellwig To: x86@kernel.org Cc: Konrad Rzeszutek Wilk , Tom Lendacky , David Woodhouse , Muli Ben-Yehuda , Jon Mason , Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/13] x86/amd_gart: use dma_direct_{alloc,free} Date: Mon, 5 Mar 2018 09:46:48 -0800 Message-Id: <20180305174655.9878-7-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180305174655.9878-1-hch@lst.de> References: <20180305174655.9878-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This gains support for CMA allocations for the force_iommu case, and cleans up the code a bit. Signed-off-by: Christoph Hellwig --- arch/x86/kernel/amd_gart_64.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c index 79ac6caaaabb..f299d8a479bb 100644 --- a/arch/x86/kernel/amd_gart_64.c +++ b/arch/x86/kernel/amd_gart_64.c @@ -480,29 +480,21 @@ static void * gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, gfp_t flag, unsigned long attrs) { - dma_addr_t paddr; - unsigned long align_mask; - struct page *page; - - if (force_iommu && dev->coherent_dma_mask > DMA_BIT_MASK(24)) { - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); - page = alloc_pages(flag | __GFP_ZERO, get_order(size)); - if (!page) - return NULL; - - align_mask = (1UL << get_order(size)) - 1; - paddr = dma_map_area(dev, page_to_phys(page), size, - DMA_BIDIRECTIONAL, align_mask); - - flush_gart(); - if (paddr != bad_dma_addr) { - *dma_addr = paddr; - return page_address(page); - } - __free_pages(page, get_order(size)); - } else - return dma_direct_alloc(dev, size, dma_addr, flag, attrs); + void *vaddr; + + vaddr = dma_direct_alloc(dev, size, dma_addr, flag, attrs); + if (!vaddr || + !force_iommu || dev->coherent_dma_mask <= DMA_BIT_MASK(24)) + return vaddr; + *dma_addr = dma_map_area(dev, virt_to_phys(vaddr), size, + DMA_BIDIRECTIONAL, (1UL << get_order(size)) - 1); + flush_gart(); + if (unlikely(*dma_addr == bad_dma_addr)) + goto out_free; + return vaddr; +out_free: + dma_direct_free(dev, size, vaddr, *dma_addr, attrs); return NULL; } -- 2.14.2