Received: by 10.213.65.68 with SMTP id h4csp662880imn; Fri, 23 Mar 2018 12:52:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELudBht7xeqMYQywOCeLLcqcLOgadIb+TeRxuylYT9wkS9dzmnan4J1fK6elPjxPzijWZLG8 X-Received: by 2002:a17:902:b088:: with SMTP id p8-v6mr15854903plr.235.1521834770675; Fri, 23 Mar 2018 12:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521834770; cv=none; d=google.com; s=arc-20160816; b=BjbTZgoqsQvOe+1oa4Icj/awE7blfmj22PkPlEbrTrQ4ynu2YrL8SBJKiW3GUKjU0C MYfEs+qHCWVwyalNTzSMZ3MEClZNIwpd0fH/8wMfUw3sL09gxwt0qOWx+oj+ZhSlblXq pGljaKzRKFk0/79zgUSV/t2PIZhPqf1lv25HmA9oa+QWeqrpfhP3QbMo1/CDnhBli08v h397OxROfuGUWDZ+9mkHELEb7GX12Nu2I77xEIMInYVQet0yEHgSCj7ERyeYhRCleEPv 5lL8mcKGNarL3Zy8pR76v30dAWEsqs+KKHNhv8vt/xOeAoAjxO07VE85lIkqLMGV2Nm3 Ue4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=KvxnCWIlBuMjTXhYmp0bF4++KGxfYOSHOBmL3Xk/Z8g=; b=kEXDZI77bncL05/l5Hq6OQgAoV4ZdBtsyWCWeVCoCdBJ+jaNDYlNQgXZWYvOJDSZpz Z0SiZM4G15Ukl3OKBmPkRwv+VAZZISrj/AVa6Fir4iY0ODCtxRJYUtaE24S7FVcIsE9Z +ngpq9HPBte+hyVi+BCNxnWNYBuhmZcdWpOPYm0K5zy83itLE/nqZvep2h+c3sU4z5RB gE2WZtCrDohOj74Hxr61zK655L5TQyCMhTIeAoPTxh2RmAkjr8+ORX4FWcaJ43gge3an I12c/MriFMIh6mFNu64fXnsxr2omCpJIgeKw4BBdg8+JHm9EIJq4dFJ2jcRNzpxH8+P4 sUrg== ARC-Authentication-Results: i=1; mx.google.com; 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 bf1-v6si8878096plb.477.2018.03.23.12.52.36; Fri, 23 Mar 2018 12:52:50 -0700 (PDT) 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; 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 S1752496AbeCWTvI (ORCPT + 99 others); Fri, 23 Mar 2018 15:51:08 -0400 Received: from terminus.zytor.com ([198.137.202.136]:45015 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbeCWTvH (ORCPT ); Fri, 23 Mar 2018 15:51:07 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2NJodrZ019631; Fri, 23 Mar 2018 12:50:39 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2NJodfd019628; Fri, 23 Mar 2018 12:50:39 -0700 Date: Fri, 23 Mar 2018 12:50:39 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Christoph Hellwig Message-ID: Cc: linux-kernel@vger.kernel.org, konrad.wilk@oracle.com, mulix@mulix.org, hpa@zytor.com, tglx@linutronix.de, dwmw2@infradead.org, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, jdmason@kudzu.us, hch@lst.de, joro@8bytes.org, thomas.lendacky@amd.com Reply-To: mingo@kernel.org, dwmw2@infradead.org, tglx@linutronix.de, hpa@zytor.com, mulix@mulix.org, linux-kernel@vger.kernel.org, konrad.wilk@oracle.com, thomas.lendacky@amd.com, hch@lst.de, joro@8bytes.org, peterz@infradead.org, jdmason@kudzu.us, torvalds@linux-foundation.org In-Reply-To: <20180319103826.12853-7-hch@lst.de> References: <20180319103826.12853-7-hch@lst.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/dma] x86/dma/amd_gart: Use dma_direct_{alloc,free}() Git-Commit-ID: 51c7eeba7975c1d2a02eefd00ece6de25176f5f3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 51c7eeba7975c1d2a02eefd00ece6de25176f5f3 Gitweb: https://git.kernel.org/tip/51c7eeba7975c1d2a02eefd00ece6de25176f5f3 Author: Christoph Hellwig AuthorDate: Mon, 19 Mar 2018 11:38:18 +0100 Committer: Ingo Molnar CommitDate: Tue, 20 Mar 2018 10:01:57 +0100 x86/dma/amd_gart: Use dma_direct_{alloc,free}() This gains support for CMA allocations for the force_iommu case, and cleans up the code a bit. Tested-by: Tom Lendacky Signed-off-by: Christoph Hellwig Reviewed-by: Thomas Gleixner Cc: David Woodhouse Cc: Joerg Roedel Cc: Jon Mason Cc: Konrad Rzeszutek Wilk Cc: Linus Torvalds Cc: Muli Ben-Yehuda Cc: Peter Zijlstra Cc: iommu@lists.linux-foundation.org Link: http://lkml.kernel.org/r/20180319103826.12853-7-hch@lst.de Signed-off-by: Ingo Molnar --- 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; }