All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huan Yang <link@vivo.com>
To: "Kasireddy, Vivek" <vivek.kasireddy@intel.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Dave Airlie" <airlied@redhat.com>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "opensource.kernel@vivo.com" <opensource.kernel@vivo.com>,
	Bingbu Cao <bingbu.cao@linux.intel.com>
Subject: Re: [PATCH 1/2] Revert "udmabuf: fix vmap_udmabuf error page set"
Date: Wed, 23 Apr 2025 15:26:37 +0800	[thread overview]
Message-ID: <c752a31d-e7c5-49bf-8722-8eeaf582a4d1@vivo.com> (raw)
In-Reply-To: <63297d3f-5e37-411e-8150-108a03a01a89@vivo.com>

 From 38aa11d92f209e7529736f3e11e08dfc804bdfae Mon Sep 17 00:00:00 2001
From: Huan Yang <link@vivo.com>
Date: Tue, 15 Apr 2025 10:04:18 +0800
Subject: [PATCH 1/2] Revert "udmabuf: fix vmap_udmabuf error page set"

This reverts commit 18d7de823b7150344d242c3677e65d68c5271b04.

This given a misuse of vmap_pfn, vmap_pfn give a !pfn_valid check
to avoid user miss use it. This API design to only for none-page struct
based user invoke, i.e. PCIe BARs and other. So any page based will
inject by !pfn_valid check.

udmabuf used shmem or hugetlb as folio src, hence, page/folio based,
can't use it.

Signed-off-by: Huan Yang <link@vivo.com>
Reported-by: Bingbu Cao <bingbu.cao@linux.intel.com>
Closes: https://lore.kernel.org/dri-devel/eb7e0137-3508-4287-98c4-816c5fd98e10@vivo.com/T/#mbda4f64a3532b32e061f4e8763bc8e307bea3ca8
Acked-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
  drivers/dma-buf/Kconfig   |  1 -
  drivers/dma-buf/udmabuf.c | 22 +++++++---------------
  2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index fee04fdb0822..b46eb8a552d7 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -36,7 +36,6 @@ config UDMABUF
      depends on DMA_SHARED_BUFFER
      depends on MEMFD_CREATE || COMPILE_TEST
      depends on MMU
-    select VMAP_PFN
      help
        A driver to let userspace turn memfd regions into dma-bufs.
        Qemu can use this to create host dmabufs for guest framebuffers.
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 7eee3eb47a8e..79845565089d 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -109,29 +109,21 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
  static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
  {
      struct udmabuf *ubuf = buf->priv;
-    unsigned long *pfns;
+    struct page **pages;
      void *vaddr;
      pgoff_t pg;

      dma_resv_assert_held(buf->resv);

-    /**
-     * HVO may free tail pages, so just use pfn to map each folio
-     * into vmalloc area.
-     */
-    pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL);
-    if (!pfns)
+    pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
+    if (!pages)
          return -ENOMEM;

-    for (pg = 0; pg < ubuf->pagecount; pg++) {
-        unsigned long pfn = folio_pfn(ubuf->folios[pg]);
-
-        pfn += ubuf->offsets[pg] >> PAGE_SHIFT;
-        pfns[pg] = pfn;
-    }
+    for (pg = 0; pg < ubuf->pagecount; pg++)
+        pages[pg] = &ubuf->folios[pg]->page;

-    vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL);
-    kvfree(pfns);
+    vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
+    kvfree(pages);
      if (!vaddr)
          return -EINVAL;

--
2.48.1



  reply	other threads:[~2025-04-23  7:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15  3:15 [PATCH 0/2] Fix udmabuf vmap error Huan Yang
2025-04-15  3:15 ` [PATCH 1/2] Revert "udmabuf: fix vmap_udmabuf error page set" Huan Yang
2025-04-22  5:14   ` Kasireddy, Vivek
2025-04-23  7:22     ` Huan Yang
2025-04-23  7:26       ` Huan Yang [this message]
2025-04-28  4:16         ` Kasireddy, Vivek
2025-04-28  7:03           ` Huan Yang
2025-04-15  3:15 ` [PATCH 2/2] udmabuf: fix vmap missed offset page Huan Yang
2025-04-22  5:22   ` Kasireddy, Vivek
2025-04-23  7:25     ` Huan Yang
2025-04-25  2:59     ` Bingbu Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c752a31d-e7c5-49bf-8722-8eeaf582a4d1@vivo.com \
    --to=link@vivo.com \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bingbu.cao@linux.intel.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=opensource.kernel@vivo.com \
    --cc=sumit.semwal@linaro.org \
    --cc=vivek.kasireddy@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.