From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68C47C2BA2B for ; Wed, 8 Apr 2020 12:00:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B41D20936 for ; Wed, 8 Apr 2020 12:00:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Aw93+jFA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B41D20936 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BBC0F8E0010; Wed, 8 Apr 2020 08:00:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B44CC8E0006; Wed, 8 Apr 2020 08:00:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0CEB8E0010; Wed, 8 Apr 2020 08:00:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 85B818E0006 for ; Wed, 8 Apr 2020 08:00:06 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4904298A5 for ; Wed, 8 Apr 2020 12:00:06 +0000 (UTC) X-FDA: 76684544412.11.move67_1df97e321cf15 X-HE-Tag: move67_1df97e321cf15 X-Filterd-Recvd-Size: 6296 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Apr 2020 12:00:05 +0000 (UTC) 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=hvIl8nFdM9AKvvDd2B5Ptj/sPZlvFIjnu0sAKeiFvVM=; b=Aw93+jFA2GdNKeSsa38wNjnfeJ /Hxs35R5BvUIjAi75y9i06TKeMeJbZEpxu+5xdycGhgCnuMKfysp5Xo29U87h+hjXj05dBgfGKrWf i91U3+oTCKj4kvk5IzZbHTAvVhzAiQp/zMp5dFUe+PvkjRZkXTi92j4SSBAM/VBRNxIotnDHo5aQ/ 2mXhOdSdmKmXpCO8V3CsqLFu1Bjml4USrfdhJMKZ631fM0E0nBcJirRT2+fCqkHq+fRYLuqt949GV Si/voJR5Bp21VepCL6NCwOddv+lAijSqgdykatW2/GLZ2L/I+/7pJ67IF1ZHnLDSPWi+KEDDMxI8x NESmQdmQ==; 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 1jM9Mo-0001cr-R8; Wed, 08 Apr 2020 11:59:39 +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 03/28] staging: media: ipu3: use vmap insted of reimplementing it Date: Wed, 8 Apr 2020 13:59:01 +0200 Message-Id: <20200408115926.1467567-4-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: quoted-printable 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: Just use vmap instead of messing with vmalloc internals. Signed-off-by: Christoph Hellwig --- drivers/staging/media/ipu3/ipu3-css-pool.h | 4 +-- drivers/staging/media/ipu3/ipu3-dmamap.c | 30 ++++++---------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css-pool.h b/drivers/staging= /media/ipu3/ipu3-css-pool.h index f4a60b41401b..a8ccd4f70320 100644 --- a/drivers/staging/media/ipu3/ipu3-css-pool.h +++ b/drivers/staging/media/ipu3/ipu3-css-pool.h @@ -15,14 +15,12 @@ struct imgu_device; * @size: size of the buffer in bytes. * @vaddr: kernel virtual address. * @daddr: iova dma address to access IPU3. - * @vma: private, a pointer to &struct vm_struct, - * used for imgu_dmamap_free. */ struct imgu_css_map { size_t size; void *vaddr; dma_addr_t daddr; - struct vm_struct *vma; + struct page **pages; }; =20 /** diff --git a/drivers/staging/media/ipu3/ipu3-dmamap.c b/drivers/staging/m= edia/ipu3/ipu3-dmamap.c index 7431322379f6..8a19b0024152 100644 --- a/drivers/staging/media/ipu3/ipu3-dmamap.c +++ b/drivers/staging/media/ipu3/ipu3-dmamap.c @@ -96,6 +96,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struc= t imgu_css_map *map, unsigned long shift =3D iova_shift(&imgu->iova_domain); struct device *dev =3D &imgu->pci_dev->dev; size_t size =3D PAGE_ALIGN(len); + int count =3D size >> PAGE_SHIFT; struct page **pages; dma_addr_t iovaddr; struct iova *iova; @@ -114,7 +115,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, str= uct imgu_css_map *map, =20 /* Call IOMMU driver to setup pgt */ iovaddr =3D iova_dma_addr(&imgu->iova_domain, iova); - for (i =3D 0; i < size / PAGE_SIZE; ++i) { + for (i =3D 0; i < count; ++i) { rval =3D imgu_mmu_map(imgu->mmu, iovaddr, page_to_phys(pages[i]), PAGE_SIZE); if (rval) @@ -123,33 +124,23 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, s= truct imgu_css_map *map, iovaddr +=3D PAGE_SIZE; } =20 - /* Now grab a virtual region */ - map->vma =3D __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END= ); - if (!map->vma) + map->vaddr =3D vmap(pages, count, VM_USERMAP, PAGE_KERNEL); + if (!map->vaddr) goto out_unmap; =20 - map->vma->pages =3D pages; - /* And map it in KVA */ - if (map_vm_area(map->vma, PAGE_KERNEL, pages)) - goto out_vunmap; - + map->pages =3D pages; map->size =3D size; map->daddr =3D iova_dma_addr(&imgu->iova_domain, iova); - map->vaddr =3D map->vma->addr; =20 dev_dbg(dev, "%s: allocated %zu @ IOVA %pad @ VA %p\n", __func__, - size, &map->daddr, map->vma->addr); - - return map->vma->addr; + size, &map->daddr, map->vaddr); =20 -out_vunmap: - vunmap(map->vma->addr); + return map->vaddr; =20 out_unmap: imgu_dmamap_free_buffer(pages, size); imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova), i * PAGE_SIZE); - map->vma =3D NULL; =20 out_free_iova: __free_iova(&imgu->iova_domain, iova); @@ -177,8 +168,6 @@ void imgu_dmamap_unmap(struct imgu_device *imgu, stru= ct imgu_css_map *map) */ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map= ) { - struct vm_struct *area =3D map->vma; - dev_dbg(&imgu->pci_dev->dev, "%s: freeing %zu @ IOVA %pad @ VA %p\n", __func__, map->size, &map->daddr, map->vaddr); =20 @@ -187,11 +176,8 @@ void imgu_dmamap_free(struct imgu_device *imgu, stru= ct imgu_css_map *map) =20 imgu_dmamap_unmap(imgu, map); =20 - if (WARN_ON(!area) || WARN_ON(!area->pages)) - return; - - imgu_dmamap_free_buffer(area->pages, map->size); vunmap(map->vaddr); + imgu_dmamap_free_buffer(map->pages, map->size); map->vaddr =3D NULL; } =20 --=20 2.25.1