mirror of https://lore.kernel.org/lkml/
 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: Mon, 28 Apr 2025 15:03:01 +0800	[thread overview]
Message-ID: <b077248e-8af5-46be-89a5-100da3ca35ba@vivo.com> (raw)
In-Reply-To: <IA0PR11MB7185FC46BE53F16BA6A9C7C9F8812@IA0PR11MB7185.namprd11.prod.outlook.com>


在 2025/4/28 12:16, Kasireddy, Vivek 写道:
> Hi Huan,
>
>> Subject: Re: [PATCH 1/2] Revert "udmabuf: fix vmap_udmabuf error page set"
>>
>>   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.
> Please consider having a commit message like below and resend both patches:
> "We cannot use vmap_pfn() in vmap_udmabuf() as it would fail the pfn_valid()
> check in vmap_pfn_apply(). This is because vmap_pfn() is intended to be
> used for mapping non-struct-page memory such as PCIe BARs. Since, udmabuf
> mostly works with pages/folios backed by shmem/hugetlbfs/THP, vmap_pfn()
> is not the right tool or API to invoke for implementing vmap."

Thanks, that's clearer, I'll update in v2 version. :)

Huan

>
> Thanks,
> Vivek
>
>> 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/#mbda4f64a3532b32e061f4e8763bc8e307bea3ca
>> 8
>> 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-28  7:04 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
2025-04-28  4:16         ` Kasireddy, Vivek
2025-04-28  7:03           ` Huan Yang [this message]
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=b077248e-8af5-46be-89a5-100da3ca35ba@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®