Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp592449ybb; Wed, 8 Apr 2020 06:11:56 -0700 (PDT) X-Google-Smtp-Source: APiQypISbEJ6FPlO0YrMQWb+Riyk+fcbC/Ur6wYJRujuhZKkSve1cr6j4n/lSMSdYIed8rA5Neom X-Received: by 2002:a9d:7cd5:: with SMTP id r21mr5773184otn.346.1586351516358; Wed, 08 Apr 2020 06:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586351516; cv=none; d=google.com; s=arc-20160816; b=IJT4cOIhBYfYyvR57bSgVgZs5D0kafKhHLwA84bUUKv1TrnmDCk3lFAZLy+e5FZxSo ahJi55GPUI3E+Dv0xDKIWAPF9ihz1nCS7hDYLnEj+b6FFADFVovmZHD1jxOlOlppPAOb OWJV4s4qVBGUwjFz7MZmlCO2T6FCH83VzpouDDub1V1rb9UcfWl62nKSCi3LAPX2s2pV icSmTipfIjPA53AabfkKK9Nq87SdMDihwNtRpyW6BUuyw3Ln3aqLioq9YfKsCIBu9YVm GYSo0nERolOBsoydjqRgHwnrRBXK+mZp8OSTMaA42Qgc5AYM0plQ1rTit/yps442fmLL sp+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+4crHe3uhOmeHMYSCHBlBmEtvSN8/No0ezjzDuAPTuI=; b=Uz5t7twlZyBMUvaQ7gpKDY4oq+k4IpPA5RgoRLzUqoMQ4Z5PlLMrrZ6dOxyPxpmXul 1iPkpBwWxrzr9Wo4uVg2kolG1g2qXb6MEZ0bxCYvTkcYH9aPt8cQF/L9fsK3bDHzs3Ag CFmaSHvWFndlgAYdtsWYPrgqDPvftLP8lZex9oh0lGjW9QdWajNHru7zOpxUnlpnmtKa LfJ0y5h87Cdvhz0DjSYDQcj8o8RBQE05pvXeHa+Wcm2/bee2HVSAFCDjs952EYeYGc9t vxnPC+Q3XzvvBokjJnYmOS4GfmvgP8bRdssPHfesG5Z9U6DacL9QrGwPvXikXNh3n9BL NKbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AiON82kA; 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 j184si1902263oih.216.2020.04.08.06.11.10; Wed, 08 Apr 2020 06:11:56 -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=AiON82kA; 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 S1728808AbgDHMAF (ORCPT + 99 others); Wed, 8 Apr 2020 08:00:05 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46778 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728187AbgDHMAE (ORCPT ); Wed, 8 Apr 2020 08:00:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+4crHe3uhOmeHMYSCHBlBmEtvSN8/No0ezjzDuAPTuI=; b=AiON82kAyefLxy+FnZ++rrbSGF 8ljclPntA9K5i1rFNcDzzNtb63TTWtGJSdnMqW0bhVGAYZt+qQcOqPfq4fDc568XB7I7cWIgfoqy+ 6aenP3/iW/aR8b0vgGnlg0/i1bQGTrRgtjPifPNjiGXsxt5wbwP+/2dAdjbu9jFF+sVu6xIZlzI8o 3UkjBpDdKvNbq45B5GA71q8xbnKt3wrPiFv5ystbAKd7zx7YxnjPKJNYX2mPxSKe0km6OLETZ3nj5 3paLvGqR73XDd5RV0Xn10xsA1T1zo/zYu9OVpyCR9CkQIy+VawEhi9xD2bMjIzI1c97gMiqCU45fY rKKah2mA==; Received: from [2001:4bb8:180:5765:65b6:f11e:f109:b151] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jM9Ms-0001h3-0H; Wed, 08 Apr 2020 11:59:42 +0000 From: Christoph Hellwig To: Andrew Morton , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , x86@kernel.org, David Airlie , Daniel Vetter , Laura Abbott , Sumit Semwal , Sakari Ailus , Minchan Kim , Nitin Gupta Cc: Robin Murphy , Christophe Leroy , Peter Zijlstra , linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/28] dma-mapping: use vmap insted of reimplementing it Date: Wed, 8 Apr 2020 13:59:02 +0200 Message-Id: <20200408115926.1467567-5-hch@lst.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200408115926.1467567-1-hch@lst.de> References: <20200408115926.1467567-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Replace the open coded instance of vmap with the actual function. In the non-contiguous (IOMMU) case this requires an extra find_vm_area, but given that this isn't a fast path function that is a small price to pay. Signed-off-by: Christoph Hellwig --- kernel/dma/remap.c | 48 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index d14cbc83986a..7a8ba60951e8 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -20,23 +20,6 @@ struct page **dma_common_find_pages(void *cpu_addr) return area->pages; } -static struct vm_struct *__dma_common_pages_remap(struct page **pages, - size_t size, pgprot_t prot, const void *caller) -{ - struct vm_struct *area; - - area = get_vm_area_caller(size, VM_DMA_COHERENT, caller); - if (!area) - return NULL; - - if (map_vm_area(area, prot, pages)) { - vunmap(area->addr); - return NULL; - } - - return area; -} - /* * Remaps an array of PAGE_SIZE pages into another vm_area. * Cannot be used in non-sleeping contexts @@ -44,15 +27,12 @@ static struct vm_struct *__dma_common_pages_remap(struct page **pages, void *dma_common_pages_remap(struct page **pages, size_t size, pgprot_t prot, const void *caller) { - struct vm_struct *area; + void *vaddr; - area = __dma_common_pages_remap(pages, size, prot, caller); - if (!area) - return NULL; - - area->pages = pages; - - return area->addr; + vaddr = vmap(pages, count, VM_DMA_COHERENT, prot); + if (vaddr) + find_vm_area(vaddr)->pages = pages; + return vaddr; } /* @@ -62,24 +42,20 @@ void *dma_common_pages_remap(struct page **pages, size_t size, void *dma_common_contiguous_remap(struct page *page, size_t size, pgprot_t prot, const void *caller) { - int i; + int count = size >> PAGE_SHIFT; struct page **pages; - struct vm_struct *area; + void *vaddr; + int i; - pages = kmalloc(sizeof(struct page *) << get_order(size), GFP_KERNEL); + pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL); if (!pages) return NULL; - - for (i = 0; i < (size >> PAGE_SHIFT); i++) + for (i = 0; i < count; i++) pages[i] = nth_page(page, i); - - area = __dma_common_pages_remap(pages, size, prot, caller); - + vaddr = vmap(pages, count, VM_DMA_COHERENT, prot); kfree(pages); - if (!area) - return NULL; - return area->addr; + return vaddr; } /* -- 2.25.1