From patchwork Tue Jun 4 06:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10974227 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC67514E5 for ; Tue, 4 Jun 2019 06:55:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9EC127F94 for ; Tue, 4 Jun 2019 06:55:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDBDD280FC; Tue, 4 Jun 2019 06:55:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SUSPICIOUS_RECIPS autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F2C727F94 for ; Tue, 4 Jun 2019 06:55:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA6C56B000D; Tue, 4 Jun 2019 02:55:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E0B146B0010; Tue, 4 Jun 2019 02:55:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAC036B0266; Tue, 4 Jun 2019 02:55:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 942046B000D for ; Tue, 4 Jun 2019 02:55:16 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id o184so4878805pfg.1 for ; Mon, 03 Jun 2019 23:55:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/4JrYgSgHdndUDJKcPMt28vvDvs6001/lFYfiqCR+8k=; b=LhgHoYp92iI5vePLZEKK1E9QldMiuwsenbTEC2N2g1YbAo1vg+IzcIr+8OmiD70Ig1 L7ibx8LXFSFKajiPvgLKUNQoG2V3JVhNMBjaFZYUcqZ6dPBgkUtkVdjmPPvJmxCrL/jD gwGjYuk+LXsvAWcewBw+uZviZ8piYEl4KMDeQPkt///w/RzEOng8nkh597UI29rPIE2l OyBU6gJZcgXhUk2/iXDzt+muRIYUWokG9ee/rKbXIGuyR3T/BKECwROeqcHccL04uMt0 D9oFsN74q2kev4h5ZEg4Qjpsd8KzT8QtErQv9KnybqRx8JZZUOF+RvgEfN9NIx9Pife/ ufNQ== X-Gm-Message-State: APjAAAUVmLpGIHn+WaJxbeqXuNxdiENN8tu4BiRDRXpoBf30KH7UntXK y3Pixq8gAwX4yyyDNCyGlSRDG10X0Az84KuxqRRKdDnmiFMNYNzgpOIwRJGDvr9E78iUcz+y6Z/ dH8RbQ5XOiDyUmKD7xW54LGqQabs51aEnhDIJUohHGSmU7Q7Kp5FR6cpyxn/2k6o= X-Received: by 2002:aa7:80d2:: with SMTP id a18mr1043540pfn.152.1559631316056; Mon, 03 Jun 2019 23:55:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb0M0Lfr8tzHpR3jOKYxF760yIDOWAj/LoqbXpSt67qM/v+3JU9TYPEWepLKv+4Ri1BYl1 X-Received: by 2002:aa7:80d2:: with SMTP id a18mr1043499pfn.152.1559631314981; Mon, 03 Jun 2019 23:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559631314; cv=none; d=google.com; s=arc-20160816; b=hO/oSjMKAGtbtLuv1vl7WU6HsxigGxenUMnSpuY8jOT+yiTrxSP3WLtHP8MKPaULhu 1PFFe67C3uS/QAe1FOCjG8VxQZSV16m9noNQt1ZjaowY8C8eo+mSltGyoBP1PZ7CJ0UR 7uTwQLpGkwg+wAbG5OdtNabTvTpwgX0zW6NCsUMwIdA6LwQj6Lw/ccPRcYYF13oVlIts oeiyXr046ozIVqtowHYBRVPPKxnDlGEWq0pQmELSNNvHMlggWd2X90e1R/C0YDboSgTu V1Ms30q4rkq+ogf+Z6BZBuxG60TURB7S22dg6Y2ITW7uSUheW6VVlpZb92yrdfzeFJwU uLwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=/4JrYgSgHdndUDJKcPMt28vvDvs6001/lFYfiqCR+8k=; b=eJqXEYsrOYbullfnJ95GiORBatsw9dLpG00jjXUFRRrkGHA9Ln9GxuPk7TtKgDikXZ HSdCCTcRajzy5hkAaJdEG3XahoDPHL342idS8YZ8pBUfQRU5Q5hO3za2YbQtoeenaXxc 7t+3fbHsVqtp0xe6tice4qOSQegSXC58eAgpqtFIvZxXIvaBXBBWbVIFceX/GOzipNRX ZZirbxVvKFBcOUl3uIlrhYiZtGPc9IiOFDXw5sQ1Kb7KDD6ylQWCdGiN3FmpDVzMcX7D oUQjTG6zEhZq2wWGfvJwLwmGb3EYbnr8iG+pTsW6GQ8YXX3GMMU/AU17GXetPZcJmf6w JNQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=kV1L0jbz; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id q8si7956775pgp.333.2019.06.03.23.55.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 23:55:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=kV1L0jbz; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org 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: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=/4JrYgSgHdndUDJKcPMt28vvDvs6001/lFYfiqCR+8k=; b=kV1L0jbzTM25ktTT2kTpM8el2N 0kEj0MDtBMvQ2Ljyct5xMT7zRuh/lxfzgeJCJZn27WeJtVLTV3o8lUSWvtB0zBuzbaIDvGl3Uk8fl myqFCYZEeVauOQYpeDd1h2dsq+n4px0Cufobx5V3ujQyBVOQEsdHxnU7OrTaQMWzdgs8jFg/WMvcc XceS4APlrhd2eDhESp3fNgLYsU23nUUmwMuPyTevnPN5QlcN21pl1bpt+BBxixZIkbLFhIwEo/bm2 l2So5bkiWzmPtqeGbTLzviqP5Y+s4TjOkkq9ZE4wpHw4wX+NIzdzyqKyOGB5s5G4YXCtbKLa7UAv5 uw+TV+Nw==; Received: from 089144193064.atnat0002.highway.a1.net ([89.144.193.64] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hY3Li-0003ST-8n; Tue, 04 Jun 2019 06:55:10 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Russell King , Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-xtensa@linux-xtensa.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] vmalloc: lift the arm flag for coherent mappings to common code Date: Tue, 4 Jun 2019 08:55:02 +0200 Message-Id: <20190604065504.25662-2-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190604065504.25662-1-hch@lst.de> References: <20190604065504.25662-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The arm architecture had a VM_ARM_DMA_CONSISTENT flag to mark DMA coherent remapping for a while. Lift this flag to common code so that we can use it generically. We also check it in the only place VM_USERMAP is directly check so that we can entirely replace that flag as well (although I'm not even sure why we'd want to allow remapping DMA appings, but I'd rather not change behavior). Signed-off-by: Christoph Hellwig --- arch/arm/mm/dma-mapping.c | 22 +++++++--------------- arch/arm/mm/mm.h | 3 --- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 5 ++++- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 0a75058c11f3..e197b028e341 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -360,19 +360,13 @@ static void * __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot, const void *caller) { - /* - * DMA allocation can be mapped to user space, so lets - * set VM_USERMAP flags too. - */ - return dma_common_contiguous_remap(page, size, - VM_ARM_DMA_CONSISTENT | VM_USERMAP, + return dma_common_contiguous_remap(page, size, VM_DMA_COHERENT, prot, caller); } static void __dma_free_remap(void *cpu_addr, size_t size) { - dma_common_free_remap(cpu_addr, size, - VM_ARM_DMA_CONSISTENT | VM_USERMAP); + dma_common_free_remap(cpu_addr, size, VM_DMA_COHERENT); } #define DEFAULT_DMA_COHERENT_POOL_SIZE SZ_256K @@ -1387,8 +1381,8 @@ static void * __iommu_alloc_remap(struct page **pages, size_t size, gfp_t gfp, pgprot_t prot, const void *caller) { - return dma_common_pages_remap(pages, size, - VM_ARM_DMA_CONSISTENT | VM_USERMAP, prot, caller); + return dma_common_pages_remap(pages, size, VM_DMA_COHERENT, prot, + caller); } /* @@ -1472,7 +1466,7 @@ static struct page **__iommu_get_pages(void *cpu_addr, unsigned long attrs) return cpu_addr; area = find_vm_area(cpu_addr); - if (area && (area->flags & VM_ARM_DMA_CONSISTENT)) + if (area && (area->flags & VM_DMA_COHERENT)) return area->pages; return NULL; } @@ -1630,10 +1624,8 @@ void __arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, return; } - if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) { - dma_common_free_remap(cpu_addr, size, - VM_ARM_DMA_CONSISTENT | VM_USERMAP); - } + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) + dma_common_free_remap(cpu_addr, size, VM_DMA_COHERENT); __iommu_remove_mapping(dev, handle, size); __iommu_free_buffer(dev, pages, size, attrs); diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h index 6b045c6653ea..6ec48188ef9f 100644 --- a/arch/arm/mm/mm.h +++ b/arch/arm/mm/mm.h @@ -68,9 +68,6 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page #define VM_ARM_MTYPE(mt) ((mt) << 20) #define VM_ARM_MTYPE_MASK (0x1f << 20) -/* consistent regions used by dma_alloc_attrs() */ -#define VM_ARM_DMA_CONSISTENT 0x20000000 - struct static_vm { struct vm_struct vm; diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 51e131245379..500fa4fb06f0 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -18,6 +18,7 @@ struct notifier_block; /* in notifier.h */ #define VM_ALLOC 0x00000002 /* vmalloc() */ #define VM_MAP 0x00000004 /* vmap()ed pages */ #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */ +#define VM_DMA_COHERENT 0x00000010 /* dma_alloc_coherent */ #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */ #define VM_NO_GUARD 0x00000040 /* don't add guard page */ #define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */ @@ -26,6 +27,7 @@ struct notifier_block; /* in notifier.h */ * vfree_atomic(). */ #define VM_FLUSH_RESET_PERMS 0x00000100 /* Reset direct map and flush TLB on unmap */ + /* bits [20..32] reserved for arch specific ioremap internals */ /* diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 233af6936c93..c4b5784bccc1 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2948,7 +2948,7 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr, if (!area) return -EINVAL; - if (!(area->flags & VM_USERMAP)) + if (!(area->flags & (VM_USERMAP | VM_DMA_COHERENT))) return -EINVAL; if (kaddr + size > area->addr + get_vm_area_size(area)) @@ -3438,6 +3438,9 @@ static int s_show(struct seq_file *m, void *p) if (v->flags & VM_USERMAP) seq_puts(m, " user"); + if (v->flags & VM_DMA_COHERENT) + seq_puts(m, " dma-coherent"); + if (is_vmalloc_addr(v->pages)) seq_puts(m, " vpages"); From patchwork Tue Jun 4 06:55:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10974229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 409291398 for ; Tue, 4 Jun 2019 06:55:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E2DC27F94 for ; Tue, 4 Jun 2019 06:55:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21B702841D; Tue, 4 Jun 2019 06:55:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SUSPICIOUS_RECIPS autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52B3427F94 for ; Tue, 4 Jun 2019 06:55:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41DFE6B000A; Tue, 4 Jun 2019 02:55:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3D03C6B0010; Tue, 4 Jun 2019 02:55:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 249F76B0266; Tue, 4 Jun 2019 02:55:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id DF29D6B000A for ; Tue, 4 Jun 2019 02:55:20 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id q6so10972443pll.22 for ; Mon, 03 Jun 2019 23:55:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wan4rbeY7cbGtXjCNpPv6QqnlnRBq+yu6GRnZJKpN4w=; b=E1HPmqnjVpDn/bO7uSjIcKonfCDWjyRBmmCQdw6BWSLhwHUeHeef0Gk8KT4JHrHBu7 s8MF1N7XQr8wzsyDKiDS8QKUU/HLT2v0X0Mhgi2H71jDAxknnGWTy+od7zZL8XMGAk8f vYQwDm0fi6EuLKBlrUdGj78fLAwxt+66GNYOL92BqzSvOF9JyZI3NmCFjTGr5ktvYAcx BLFNJQzdvfQSmvE2RYZFVkRy5cY/3Yru+X5NiRsM8v+sIlT/DwGTGF0JIhQBuQplXp0R wqg45dm9jRPtfljRX4Glo/RF+ERL5Xd+CqY0jJe4x0R65/uincbZ7OnYg+5DHivSO2OU BG8w== X-Gm-Message-State: APjAAAUzC4q834vwWyrMlQCq2Cige5n6sAYGwgzYMHaJ8pxPQ+yJg33/ Uo28Ga+Ms9IMXBmVAmE4uku8Mhc0t+eAl5+PQmq/i+0Tv1d1QJ74QlD8aVwICyPSqIbMpgMpZpt 1dF6N3n/QRs6219VRqU7oDOvUt+szaGSSqhcCmP8+V/xw0vr7uVL7EPjuZaSPhyg= X-Received: by 2002:a65:60cd:: with SMTP id r13mr33483893pgv.58.1559631320405; Mon, 03 Jun 2019 23:55:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOJDekF/ZxgRbBHR2wjVaXS05rYVB7UVThLjGzF04ayhyxGxhn59q9btbPbAawWKN3Z2wQ X-Received: by 2002:a65:60cd:: with SMTP id r13mr33483838pgv.58.1559631319222; Mon, 03 Jun 2019 23:55:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559631319; cv=none; d=google.com; s=arc-20160816; b=zG7uJwh+bpk7PQP5gYYhI1zbT4KJfZPmqpCn4zEV9IQjGq3Ig/BeAj/xSzcQUynAxf WrUgUM4c6d3x9SBaiRrmdMKfqMhmnVoGSEoT35x1UgG0gHFCZ/oRMev0ccA5atVAqLFJ Xn7XKaDtE1qEAjeYzVOwb6E11Bo7rqiVQnksbtZZWK6+aQJsgqAnAaDKcLHQ223kGBD7 ePUQCRTH9O+/ik9GiNWyjWTfJQHr59lblbYkmhRqRugFDgq7dsuTUuVirrOhPm8Dv8bp QmnBnbdOEr0ywxkHQpX9T7hKAtNf6x8o0O1RdUTq3iFE6NBzpvhnxoVYRcuWeDe1N/Vc fNXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wan4rbeY7cbGtXjCNpPv6QqnlnRBq+yu6GRnZJKpN4w=; b=x9SOKqoFou4a4OlddWX/e/GOEBFCtIp0rOBHDVn+nMpkyS34AhxIiSs7nCmPI3LRpq tfw1UPxNKzTTL6ENZqhS46pYNq92icheewfNWTDAcpG6nRoJbaLVaYAlyPKtUpFMj+ux dsa4BSMqhgrVMtNIw08+ea730wH1p7Y6sZoCIuQSy4vgbk5GhlCoEnv5aGOFxlRZr17w vAHHWTvE7LTMueDu11mIZ8C7J+m3dLb7rDPHcsjDmMc84NWO62JexywJQ5XvDPtELM2g oY7c02edOnmak1+msD717iP6oJQdiGBbzqftndCpghHOFRvxz7nrA7cKeaxuV89TCyX2 Okuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=QVjgP3Ut; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id y11si18982471plr.377.2019.06.03.23.55.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 23:55:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=QVjgP3Ut; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org 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: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=wan4rbeY7cbGtXjCNpPv6QqnlnRBq+yu6GRnZJKpN4w=; b=QVjgP3Ut5uN1RLA2L2HZSgrbpo ki2bji0CcR+cbtIciJ9b5eOdvgWjhHFLw65t3e+uwOtD++ihzVNvqGPF0AyG4ur8pSHlUb6M4ebtp k4S3OpPx4ow75YhQz756J0ew6BChFrKJcWDSqFmagaXKplgdx2MLGivoDrCLV6uPMdY6AwM8Bq9lR XjupM3W73ZE5KsfDvP3/HKcbz3HhY5m94TlB5hUM8VQ56KA67MUCfZZP6gH7QZLQrrfHm+7syrBKf xdfHNSvpBlejwVFp1qEazE+OGRveWTdLV4Yk4w/VwUJ6TfbcOg1ZwM/9PbLhuGNhWJ6VbGSbapIqh nkp6Ii7g==; Received: from 089144193064.atnat0002.highway.a1.net ([89.144.193.64] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hY3Ll-0003V7-3j; Tue, 04 Jun 2019 06:55:13 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Russell King , Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-xtensa@linux-xtensa.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] dma-mapping: always use VM_DMA_COHERENT for generic DMA remap Date: Tue, 4 Jun 2019 08:55:03 +0200 Message-Id: <20190604065504.25662-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190604065504.25662-1-hch@lst.de> References: <20190604065504.25662-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently the generic dma remap allocator gets a vm_flags passed by the caller that is a little confusing. We just introduced a generic vmalloc-level flag to identify the dma coherent allocations, so use that everywhere and remove the now pointless argument. Signed-off-by: Christoph Hellwig --- arch/arm/mm/dma-mapping.c | 37 +++++++----------------------------- arch/xtensa/kernel/pci-dma.c | 4 ++-- drivers/iommu/dma-iommu.c | 6 +++--- include/linux/dma-mapping.h | 6 ++---- kernel/dma/remap.c | 25 +++++++++++------------- 5 files changed, 25 insertions(+), 53 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index e197b028e341..647fd25d2aba 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -356,19 +356,6 @@ static void *__alloc_remap_buffer(struct device *dev, size_t size, gfp_t gfp, pgprot_t prot, struct page **ret_page, const void *caller, bool want_vaddr); -static void * -__dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot, - const void *caller) -{ - return dma_common_contiguous_remap(page, size, VM_DMA_COHERENT, - prot, caller); -} - -static void __dma_free_remap(void *cpu_addr, size_t size) -{ - dma_common_free_remap(cpu_addr, size, VM_DMA_COHERENT); -} - #define DEFAULT_DMA_COHERENT_POOL_SIZE SZ_256K static struct gen_pool *atomic_pool __ro_after_init; @@ -525,7 +512,7 @@ static void *__alloc_remap_buffer(struct device *dev, size_t size, gfp_t gfp, if (!want_vaddr) goto out; - ptr = __dma_alloc_remap(page, size, gfp, prot, caller); + ptr = dma_common_contiguous_remap(page, size, gfp, prot, caller); if (!ptr) { __dma_free_buffer(page, size); return NULL; @@ -592,7 +579,8 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size, goto out; if (PageHighMem(page)) { - ptr = __dma_alloc_remap(page, size, GFP_KERNEL, prot, caller); + ptr = dma_common_contiguous_remap(page, size, GFP_KERNEL, prot, + caller); if (!ptr) { dma_release_from_contiguous(dev, page, count); return NULL; @@ -612,7 +600,7 @@ static void __free_from_contiguous(struct device *dev, struct page *page, { if (want_vaddr) { if (PageHighMem(page)) - __dma_free_remap(cpu_addr, size); + dma_common_free_remap(cpu_addr, size); else __dma_remap(page, size, PAGE_KERNEL); } @@ -704,7 +692,7 @@ static void *remap_allocator_alloc(struct arm_dma_alloc_args *args, static void remap_allocator_free(struct arm_dma_free_args *args) { if (args->want_vaddr) - __dma_free_remap(args->cpu_addr, args->size); + dma_common_free_remap(args->cpu_addr, args->size); __dma_free_buffer(args->page, args->size); } @@ -1374,17 +1362,6 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages, return 0; } -/* - * Create a CPU mapping for a specified pages - */ -static void * -__iommu_alloc_remap(struct page **pages, size_t size, gfp_t gfp, pgprot_t prot, - const void *caller) -{ - return dma_common_pages_remap(pages, size, VM_DMA_COHERENT, prot, - caller); -} - /* * Create a mapping in device IO address space for specified pages */ @@ -1541,7 +1518,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size, if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) return pages; - addr = __iommu_alloc_remap(pages, size, gfp, prot, + addr = dma_common_pages_remap(pages, size, gfp, prot, __builtin_return_address(0)); if (!addr) goto err_mapping; @@ -1625,7 +1602,7 @@ void __arm_iommu_free_attrs(struct device *dev, size_t size, void *cpu_addr, } if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) - dma_common_free_remap(cpu_addr, size, VM_DMA_COHERENT); + dma_common_free_remap(cpu_addr, size); __iommu_remove_mapping(dev, handle, size); __iommu_free_buffer(dev, pages, size, attrs); diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c index 9171bff76fc4..81c1def6b5a2 100644 --- a/arch/xtensa/kernel/pci-dma.c +++ b/arch/xtensa/kernel/pci-dma.c @@ -175,7 +175,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, if (PageHighMem(page)) { void *p; - p = dma_common_contiguous_remap(page, size, VM_MAP, + p = dma_common_contiguous_remap(page, size, pgprot_noncached(PAGE_KERNEL), __builtin_return_address(0)); if (!p) { @@ -202,7 +202,7 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr, page = virt_to_page(platform_vaddr_to_cached(vaddr)); } else { #ifdef CONFIG_MMU - dma_common_free_remap(vaddr, size, VM_MAP); + dma_common_free_remap(vaddr, size); #endif page = pfn_to_page(PHYS_PFN(dma_to_phys(dev, dma_handle))); } diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 0dee374fc64a..cea561897086 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -619,7 +619,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size, < size) goto out_free_sg; - vaddr = dma_common_pages_remap(pages, size, VM_USERMAP, prot, + vaddr = dma_common_pages_remap(pages, size, prot, __builtin_return_address(0)); if (!vaddr) goto out_unmap; @@ -943,7 +943,7 @@ static void __iommu_dma_free(struct device *dev, size_t size, void *cpu_addr) pages = __iommu_dma_get_pages(cpu_addr); if (!pages) page = vmalloc_to_page(cpu_addr); - dma_common_free_remap(cpu_addr, alloc_size, VM_USERMAP); + dma_common_free_remap(cpu_addr, alloc_size); } else { /* Lowmem means a coherent atomic or CMA allocation */ page = virt_to_page(cpu_addr); @@ -983,7 +983,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size, pgprot_t prot = arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs); cpu_addr = dma_common_contiguous_remap(page, alloc_size, - VM_USERMAP, prot, __builtin_return_address(0)); + prot, __builtin_return_address(0)); if (!cpu_addr) goto out_free_pages; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 6309a721394b..ac320b7cacfd 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -616,13 +616,11 @@ extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, unsigned long attrs); void *dma_common_contiguous_remap(struct page *page, size_t size, - unsigned long vm_flags, pgprot_t prot, const void *caller); void *dma_common_pages_remap(struct page **pages, size_t size, - unsigned long vm_flags, pgprot_t prot, - const void *caller); -void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags); + pgprot_t prot, const void *caller); +void dma_common_free_remap(void *cpu_addr, size_t size); int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot); bool dma_in_atomic_pool(void *start, size_t size); diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 7a723194ecbe..51958d21c810 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -12,12 +12,11 @@ #include static struct vm_struct *__dma_common_pages_remap(struct page **pages, - size_t size, unsigned long vm_flags, pgprot_t prot, - const void *caller) + size_t size, pgprot_t prot, const void *caller) { struct vm_struct *area; - area = get_vm_area_caller(size, vm_flags, caller); + area = get_vm_area_caller(size, VM_DMA_COHERENT, caller); if (!area) return NULL; @@ -34,12 +33,11 @@ static struct vm_struct *__dma_common_pages_remap(struct page **pages, * Cannot be used in non-sleeping contexts */ void *dma_common_pages_remap(struct page **pages, size_t size, - unsigned long vm_flags, pgprot_t prot, - const void *caller) + pgprot_t prot, const void *caller) { struct vm_struct *area; - area = __dma_common_pages_remap(pages, size, vm_flags, prot, caller); + area = __dma_common_pages_remap(pages, size, prot, caller); if (!area) return NULL; @@ -53,7 +51,6 @@ void *dma_common_pages_remap(struct page **pages, size_t size, * Cannot be used in non-sleeping contexts */ void *dma_common_contiguous_remap(struct page *page, size_t size, - unsigned long vm_flags, pgprot_t prot, const void *caller) { int i; @@ -67,7 +64,7 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, for (i = 0; i < (size >> PAGE_SHIFT); i++) pages[i] = nth_page(page, i); - area = __dma_common_pages_remap(pages, size, vm_flags, prot, caller); + area = __dma_common_pages_remap(pages, size, prot, caller); kfree(pages); @@ -79,11 +76,11 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, /* * Unmaps a range previously mapped by dma_common_*_remap */ -void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) +void dma_common_free_remap(void *cpu_addr, size_t size) { struct vm_struct *area = find_vm_area(cpu_addr); - if (!area || (area->flags & vm_flags) != vm_flags) { + if (!area || area->flags != VM_DMA_COHERENT) { WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr); return; } @@ -127,8 +124,8 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) if (!atomic_pool) goto free_page; - addr = dma_common_contiguous_remap(page, atomic_pool_size, VM_USERMAP, - prot, __builtin_return_address(0)); + addr = dma_common_contiguous_remap(page, atomic_pool_size, prot, + __builtin_return_address(0)); if (!addr) goto destroy_genpool; @@ -143,7 +140,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) return 0; remove_mapping: - dma_common_free_remap(addr, atomic_pool_size, VM_USERMAP); + dma_common_free_remap(addr, atomic_pool_size); destroy_genpool: gen_pool_destroy(atomic_pool); atomic_pool = NULL; @@ -220,7 +217,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, } /* create a coherent mapping */ - ret = dma_common_contiguous_remap(page, size, VM_USERMAP, + ret = dma_common_contiguous_remap(page, size, arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs), __builtin_return_address(0)); if (!ret) { From patchwork Tue Jun 4 06:55:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10974233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B704B14E5 for ; Tue, 4 Jun 2019 06:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A57F727FB7 for ; Tue, 4 Jun 2019 06:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97466280FC; Tue, 4 Jun 2019 06:55:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SUSPICIOUS_RECIPS autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B80B27FB7 for ; Tue, 4 Jun 2019 06:55:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D45E86B0010; Tue, 4 Jun 2019 02:55:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CCFFF6B0266; Tue, 4 Jun 2019 02:55:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC1616B0269; Tue, 4 Jun 2019 02:55:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 7EB0C6B0010 for ; Tue, 4 Jun 2019 02:55:24 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id q2so13389488plr.19 for ; Mon, 03 Jun 2019 23:55:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=97BhO94V8jLdTUMw7JoDn6KQHii2re3fulwUdwFjYBI=; b=QbxC61VF/VKkAA7BWoRCjH5yFXudMnJT1P9jTR8rnqPkTeWfVm/QCIXcHYxAWu5fBH u2TCispZgOeauqtZQCIIJZzQQ2pkQK/MfomAmxRfCb13x+m/CQ+JEU8RXJOcT70O0MHH NxOeCfGqFo4wWrKBmrgJQC8zXIVMrmJZvECad3dt2iGk6ETvqtSJ25TQDAxxHgoFiU3O lWcle57NAbybzegqBZLgZ/jOklDmhJfhQhoNuAgX0MOx3U3nUoJLl+0EdnyZc51fRAiC H5rN0igtUcIVUfLWutFnK3ThAKg3TkaWjOe3oPdm+1QAAtCamzFVB67+cyxcy4qf24cc tioQ== X-Gm-Message-State: APjAAAWJ8UXyximHDgLFHLy76cHJaAEHUrBnDhpE3dpfsumEV6Qimz8z Y5hI1/YTE/lJUlyLJOhltip+BZ8ZIEED3bYLUJD8iDdjG/A8TawylfmISEfvpxwpJbuxMLza2Fx tsj4HGLahCgsUoBAaTRstmnFTeSqRs+GsUpiCAx2I3wXk2h1PGkRK0uP+4n6lDTA= X-Received: by 2002:a65:5308:: with SMTP id m8mr33176075pgq.54.1559631324019; Mon, 03 Jun 2019 23:55:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3KU43Q1FuiY1x+4k/X2L/c7xrV3GUX8rWveRVItaxq4Xz4iU5yLu2wit2a2GeN6DNIXxc X-Received: by 2002:a65:5308:: with SMTP id m8mr33176038pgq.54.1559631323013; Mon, 03 Jun 2019 23:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559631323; cv=none; d=google.com; s=arc-20160816; b=CYtFzpwtPKNjJnJ+9B3Fx1fv+/r01kvuuk8Zk8GXSf2fWu4rYa28CSBIHJZZ0l3cvX 1KtHgjnq2G9hzYy+14nD7Fdrkge0r5tb24/ZDEJ5NvLcnB4Wcl6V5EoG15jeOFVptATP wQOOMu5xJaEpv59CkQRNt/chP1KkDAmNtTm+Oc9/GijdcM3u2NZtajfD0BLNMAmnhDZf bK549a9/Sob20skeErIUhx1dIsFOaj7Te8dheBAS6oImI40vYUZu+7dgHRhMySt+WJ+K cyyaXb/XFCWr32FARVx3dj1MceY+DWc68koRGkecWE95fEYpCOFh7oBdCoMjrxrvz2ZJ SUvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=97BhO94V8jLdTUMw7JoDn6KQHii2re3fulwUdwFjYBI=; b=Z4mU4jTA6q7sBk28gToQhopdc2f9ZgY+TJBJR6+DI12GS9/3lNtOWmsB+WL0F+BfVO 324Zm5P1PLT7idtiHVRVKIPOc//Jd633yAsItY8hsXogLDhGJPcCE4gmHg3WYBHMJNX2 h/+VnmhRSCv73VVQ3NzFBSfFqgaK1Nwp/Xl6YFYaGaP8YhjIwln0STLsx2dvZLQo3ezc fwYqjA8M36BSSVDF3Q/NRwmM+/QpyVTVxBOlH11CpzUpLGO2R5Updkjj5EmFHHso8xGo uqASBujtrmlh1ntPZoxOnvuYfUhkv7RYo67dvDLXtm9BG8bvYf0ycLlkLLXKvdRAl1ar Napw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b="tFue28d/"; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id y135si24578796pfc.114.2019.06.03.23.55.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 23:55:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b="tFue28d/"; spf=pass (google.com: best guess record for domain of batv+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8160fb773a6c716236a8+5763+infradead.org+hch@bombadil.srs.infradead.org 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: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=97BhO94V8jLdTUMw7JoDn6KQHii2re3fulwUdwFjYBI=; b=tFue28d/NACZJWIBnHUgst3mcC kSW3mXpirIcDda6kq0ORR53gZV/3aWOou7YOP7/jjVUsx9Nq13hyKqovanMtUDh+9cn+kOOfmdZ3h WuSN3frnRaStXDjmp8W4abdA4+x4/t6n7m3jG4/uq4kmsZCuhHmmXlB2E4Puc4LNWeUGLMuatoaxz zB8Wu3eSa8uwVv8yJg64x21cXloaW9LfIeeyqjQUfUuWp4EjVxWT+8wF++127uFmcK+VAEIYu4M80 /qSyg0M7Un4DX1zlJikp5XiCM3ltmJeLSKjwcDfqc9yc30nFQLNNmq2JD/E+tAdSp53e+f8lgLCLs AuHQbzBw==; Received: from 089144193064.atnat0002.highway.a1.net ([89.144.193.64] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hY3Lo-0003ZV-DH; Tue, 04 Jun 2019 06:55:16 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Russell King , Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-xtensa@linux-xtensa.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] dma-mapping: introduce a dma_common_find_pages helper Date: Tue, 4 Jun 2019 08:55:04 +0200 Message-Id: <20190604065504.25662-4-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190604065504.25662-1-hch@lst.de> References: <20190604065504.25662-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP A helper to find the backing page array based on a virtual address. This also ensures we do the same vm_flags check everywhere instead of slightly different or missing ones in a few places. Signed-off-by: Christoph Hellwig --- arch/arm/mm/dma-mapping.c | 7 +------ drivers/iommu/dma-iommu.c | 15 +++------------ include/linux/dma-mapping.h | 1 + kernel/dma/remap.c | 13 +++++++++++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 647fd25d2aba..7620d4f55e92 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1434,18 +1434,13 @@ static struct page **__atomic_get_pages(void *addr) static struct page **__iommu_get_pages(void *cpu_addr, unsigned long attrs) { - struct vm_struct *area; - if (__in_atomic_pool(cpu_addr, PAGE_SIZE)) return __atomic_get_pages(cpu_addr); if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) return cpu_addr; - area = find_vm_area(cpu_addr); - if (area && (area->flags & VM_DMA_COHERENT)) - return area->pages; - return NULL; + return dma_common_find_pages(cpu_addr); } static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp, diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index cea561897086..002d3bb6254a 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -543,15 +543,6 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, return pages; } -static struct page **__iommu_dma_get_pages(void *cpu_addr) -{ - struct vm_struct *area = find_vm_area(cpu_addr); - - if (!area || !area->pages) - return NULL; - return area->pages; -} - /** * iommu_dma_alloc_remap - Allocate and map a buffer contiguous in IOVA space * @dev: Device to allocate memory for. Must be a real device @@ -940,7 +931,7 @@ static void __iommu_dma_free(struct device *dev, size_t size, void *cpu_addr) * If it the address is remapped, then it's either non-coherent * or highmem CMA, or an iommu_dma_alloc_remap() construction. */ - pages = __iommu_dma_get_pages(cpu_addr); + pages = dma_common_find_pages(cpu_addr); if (!pages) page = vmalloc_to_page(cpu_addr); dma_common_free_remap(cpu_addr, alloc_size); @@ -1050,7 +1041,7 @@ static int iommu_dma_mmap(struct device *dev, struct vm_area_struct *vma, return -ENXIO; if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { - struct page **pages = __iommu_dma_get_pages(cpu_addr); + struct page **pages = dma_common_find_pages(cpu_addr); if (pages) return __iommu_dma_mmap(pages, size, vma); @@ -1072,7 +1063,7 @@ static int iommu_dma_get_sgtable(struct device *dev, struct sg_table *sgt, int ret; if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { - struct page **pages = __iommu_dma_get_pages(cpu_addr); + struct page **pages = dma_common_find_pages(cpu_addr); if (pages) { return sg_alloc_table_from_pages(sgt, pages, diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index ac320b7cacfd..cb07d1388d66 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -615,6 +615,7 @@ extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs); +struct page **dma_common_find_pages(void *cpu_addr); void *dma_common_contiguous_remap(struct page *page, size_t size, pgprot_t prot, const void *caller); diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 51958d21c810..52cdca386de0 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -11,6 +11,15 @@ #include #include +struct page **dma_common_find_pages(void *cpu_addr) +{ + struct vm_struct *area = find_vm_area(cpu_addr); + + if (!area || area->flags != VM_DMA_COHERENT) + return NULL; + return area->pages; +} + static struct vm_struct *__dma_common_pages_remap(struct page **pages, size_t size, pgprot_t prot, const void *caller) { @@ -78,9 +87,9 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, */ void dma_common_free_remap(void *cpu_addr, size_t size) { - struct vm_struct *area = find_vm_area(cpu_addr); + struct page **pages = dma_common_find_pages(cpu_addr); - if (!area || area->flags != VM_DMA_COHERENT) { + if (!pages) { WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr); return; }