Received: by 10.213.65.68 with SMTP id h4csp1448107imn; Mon, 19 Mar 2018 04:35:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELtxP/Mi8ytnl+ocGTELAmJD12GPuXKxqT1kt1aoAh1RN9TMZgWeeu2Asu14yaMErrMBzKUA X-Received: by 10.101.93.71 with SMTP id e7mr8704299pgt.171.1521459327346; Mon, 19 Mar 2018 04:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521459327; cv=none; d=google.com; s=arc-20160816; b=nO2VQa9alr5VOGY/iWjBz6D47HTJhDk1cw7JcueeFjnr91im6s3zvrAS//wx4hp3En vab32ppSd8zKFZ4lRk4WrLfFwTHa+tstiA8HkpdqTb6vjv3H/xvcWaXbHPvnMdNGL/1p o2fZ5dQvWIWzIPUu6Jo+qO4OukpVcnLVdGLYe6m/6kDpp/Hb1u3qpLzViE3vn+Sqr+BF uZY3qEfpiQsNKH1y6dgMJmHqrBLeQJOdBi7vFSGSxpW8+3uVgCUPLerohV7hCawegy2D Gt+ljvx+Fmd+zuhXeDJPljjTH+NyDwZw3K6x6ZzuJYaUDmNYfuT5r6V2RD61J+sxWVUq pzSA== 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=rs2/MVg0+8NB35SUzRTiMf9cg6kx/F76H/4fY4ANPM0=; b=L0M2RDM6RdFURCTrkJiFM/q3j2Yor5e6/STC1FjFH94affH82FHonV/jCJfHFBTHVR YdphWibwVMxhM4GgW/xL2HmnX68En6/koL/Kwc/b2pTbXL8cg7V3PYcBP/3O6B6HgENf 8kWhDzqd8DUXAbyVk5l5DJpc+LsgjN6eNnvwquO6eJX+vWyCNEyLvGC2vyIap3IAS0gg wgptaPw5qJrYFjcUMzPBoDbWmEuHzI5/CR5iAZYQo4qGKIP4U7DZH7B7dHsKy0OnIC/X 9/zqGbnlSJuWCj3jzUJ4/mmWastp+cWUjxumjKaUc2r0cWPmQyWcoHlmp7PG4ZVG+GCr litA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bo4ZiaCA; 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 s23-v6si868882plp.592.2018.03.19.04.35.12; Mon, 19 Mar 2018 04:35:27 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bo4ZiaCA; 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 S932831AbeCSKiu (ORCPT + 99 others); Mon, 19 Mar 2018 06:38:50 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55006 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932415AbeCSKip (ORCPT ); Mon, 19 Mar 2018 06:38:45 -0400 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=rs2/MVg0+8NB35SUzRTiMf9cg6kx/F76H/4fY4ANPM0=; b=bo4ZiaCA2Kg7BMFwZ1Qk1eRR8 gVcoyRI8Whrat8Q22WxUHtxkJqJ+2bgAYJQ42AXxGQEEJIeEDbNZfhTeYd8Zo3ZpaeHRso/PGSgU5 dnYkU2K17lzurptbwYoXPwbrZgzhXx1XQRJCO27ubN68Uw1fyh2TTV3M11ez7Bj3UyxhaG8Tvqjx2 yanMEmv2WMW3jxXGPgMS2Ja0WK1B/uaDiZsGzoDEMOGdLlAenkz5TzEnEHgM6PWz1tcGa7SWVJr6J dNMD2tLcu+w2Mdar7XAI0b3DXTvL6AuECgKVGmPrpLnTVBhlmmp4yPZHFY8Lj22IFGJ0xvQ6Wxgsb wOy3RiVyA==; Received: from 178.114.187.156.wireless.dyn.drei.com ([178.114.187.156] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1exsBX-0005mc-D6; Mon, 19 Mar 2018 10:38:35 +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 02/14] x86: remove dma_alloc_coherent_mask Date: Mon, 19 Mar 2018 11:38:14 +0100 Message-Id: <20180319103826.12853-3-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180319103826.12853-1-hch@lst.de> References: <20180319103826.12853-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 These days all devices (including the ISA fallback device) have a coherent DMA mask set, so remove the workaround. Signed-off-by: Christoph Hellwig Reviewed-by: Konrad Rzeszutek Wilk --- arch/x86/include/asm/dma-mapping.h | 18 ++---------------- arch/x86/kernel/pci-dma.c | 10 ++++------ arch/x86/mm/mem_encrypt.c | 4 +--- drivers/xen/swiotlb-xen.c | 16 +--------------- 4 files changed, 8 insertions(+), 40 deletions(-) diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 6277c83c0eb1..545bf3721bc0 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -44,26 +44,12 @@ extern void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_addr, unsigned long attrs); -static inline unsigned long dma_alloc_coherent_mask(struct device *dev, - gfp_t gfp) -{ - unsigned long dma_mask = 0; - - dma_mask = dev->coherent_dma_mask; - if (!dma_mask) - dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32); - - return dma_mask; -} - static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp) { - unsigned long dma_mask = dma_alloc_coherent_mask(dev, gfp); - - if (dma_mask <= DMA_BIT_MASK(24)) + if (dev->coherent_dma_mask <= DMA_BIT_MASK(24)) gfp |= GFP_DMA; #ifdef CONFIG_X86_64 - if (dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA)) + if (dev->coherent_dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA)) gfp |= GFP_DMA32; #endif return gfp; diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index df7ab02f959f..b59820872ec7 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -80,13 +80,10 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, gfp_t flag, unsigned long attrs) { - unsigned long dma_mask; struct page *page; unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; dma_addr_t addr; - dma_mask = dma_alloc_coherent_mask(dev, flag); - again: page = NULL; /* CMA can be used only in the context which permits sleeping */ @@ -95,7 +92,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, flag); if (page) { addr = phys_to_dma(dev, page_to_phys(page)); - if (addr + size > dma_mask) { + if (addr + size > dev->coherent_dma_mask) { dma_release_from_contiguous(dev, page, count); page = NULL; } @@ -108,10 +105,11 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, return NULL; addr = phys_to_dma(dev, page_to_phys(page)); - if (addr + size > dma_mask) { + if (addr + size > dev->coherent_dma_mask) { __free_pages(page, get_order(size)); - if (dma_mask < DMA_BIT_MASK(32) && !(flag & GFP_DMA)) { + if (dev->coherent_dma_mask < DMA_BIT_MASK(32) && + !(flag & GFP_DMA)) { flag = (flag & ~GFP_DMA32) | GFP_DMA; goto again; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 1a53071e2e17..75dc8b525c12 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -203,12 +203,10 @@ void __init sme_early_init(void) static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { - unsigned long dma_mask; unsigned int order; struct page *page; void *vaddr = NULL; - dma_mask = dma_alloc_coherent_mask(dev, gfp); order = get_order(size); /* @@ -226,7 +224,7 @@ static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, * mask with it already cleared. */ addr = __sme_clr(phys_to_dma(dev, page_to_phys(page))); - if ((addr + size) > dma_mask) { + if ((addr + size) > dev->coherent_dma_mask) { __free_pages(page, get_order(size)); } else { vaddr = page_address(page); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 5bb72d3f8337..e1c60899fdbc 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -53,20 +53,6 @@ * API. */ -#ifndef CONFIG_X86 -static unsigned long dma_alloc_coherent_mask(struct device *dev, - gfp_t gfp) -{ - unsigned long dma_mask = 0; - - dma_mask = dev->coherent_dma_mask; - if (!dma_mask) - dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32); - - return dma_mask; -} -#endif - #define XEN_SWIOTLB_ERROR_CODE (~(dma_addr_t)0x0) static char *xen_io_tlb_start, *xen_io_tlb_end; @@ -328,7 +314,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, return ret; if (hwdev && hwdev->coherent_dma_mask) - dma_mask = dma_alloc_coherent_mask(hwdev, flags); + dma_mask = hwdev->coherent_dma_mask; /* At this point dma_handle is the physical address, next we are * going to set it to the machine address. -- 2.14.2