mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Lukasz Wiecaszek <lukasz.wiecaszek@googlemail.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	Lukasz Wiecaszek <lukasz.wiecaszek@gmail.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] udmabuf: add vmap and vunmap methods to udmabuf_ops
Date: Fri, 18 Nov 2022 10:58:28 +0100	[thread overview]
Message-ID: <b31fc44a-5827-5213-2a8f-9f0529155542@amd.com> (raw)
In-Reply-To: <20221117171810.75637-1-lukasz.wiecaszek@gmail.com>

Pushed this one here to drm-misc-next.

Thanks,
Christian.

Am 17.11.22 um 18:18 schrieb Lukasz Wiecaszek:
> The reason behind that patch is associated with videobuf2 subsystem
> (or more genrally with v4l2 framework) and user created
> dma buffers (udmabuf). In some circumstances
> when dealing with V4L2_MEMORY_DMABUF buffers videobuf2 subsystem
> wants to use dma_buf_vmap() method on the attached dma buffer.
> As udmabuf does not have .vmap operation implemented,
> such dma_buf_vmap() natually fails.
>
> videobuf2_common: __vb2_queue_alloc: allocated 3 buffers, 1 plane(s) each
> videobuf2_common: __prepare_dmabuf: buffer for plane 0 changed
> videobuf2_common: __prepare_dmabuf: failed to map dmabuf for plane 0
> videobuf2_common: __buf_prepare: buffer preparation failed: -14
>
> The patch itself seems to be strighforward.
> It adds implementation of .vmap and .vunmap methods
> to 'struct dma_buf_ops udmabuf_ops'.
> .vmap method itself uses vm_map_ram() to map pages linearly
> into the kernel virtual address space.
> .vunmap removes mapping created earlier by .vmap.
> All locking and 'vmapping counting' is done in dma_buf.c
> so it seems to be redundant/unnecessary in .vmap/.vunmap.
>
> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Acked-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Lukasz Wiecaszek <lukasz.wiecaszek@gmail.com>
> ---
> v1: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flinux-media%2F202211120352.G7WPASoP-lkp%40intel.com%2FT%2F%23t&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7C9ef170d657a94849986f08dac8bfeb0f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638043023852257558%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=yml6LFzivvU1Vv4cHRf47BEeqRN%2BkH1Sy%2FN4h%2BMpRxU%3D&amp;reserved=0
> v2: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flinux-media%2F20221114052944.GA7264%40thinkpad-p72%2FT%2F%23t&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7C9ef170d657a94849986f08dac8bfeb0f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638043023852257558%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=mBEfWp7w8wTIhO2qF7ad9GrfMyX29EM3neHNHm0i2Zc%3D&amp;reserved=0
> v3: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flinux-media%2F4f92e95f-a0dc-4eac-4c08-0df85de78ae7%40collabora.com%2FT%2F%23t&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7C9ef170d657a94849986f08dac8bfeb0f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638043023852257558%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=2LTn8lzg48%2B%2BTK4w3vctyQ6PjUva%2BZKS8eZeLG%2FWR7I%3D&amp;reserved=0
> v4: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flinux-media%2F970e798d-ea26-5e1e-ace8-7915a866f7c7%40collabora.com%2FT%2F%23t&amp;data=05%7C01%7Cchristian.koenig%40amd.com%7C9ef170d657a94849986f08dac8bfeb0f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638043023852257558%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=tO4Tgd5jPeu6%2BNuWSl%2BSqF%2FEh4dI7vaah4%2FICimHvgo%3D&amp;reserved=0
>
> v4 -> v5: Added Acked-by and Reviewed-by to the commit message
> v3 -> v4: Removed line/info 'reported by kernel test robot'
> v2 -> v3: Added .vunmap to 'struct dma_buf_ops udmabuf_ops'
> v1 -> v2: Patch prepared and tested against 6.1.0-rc2+
>
>   drivers/dma-buf/udmabuf.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
>
> diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
> index 283816fbd72f..740d6e426ee9 100644
> --- a/drivers/dma-buf/udmabuf.c
> +++ b/drivers/dma-buf/udmabuf.c
> @@ -13,6 +13,8 @@
>   #include <linux/slab.h>
>   #include <linux/udmabuf.h>
>   #include <linux/hugetlb.h>
> +#include <linux/vmalloc.h>
> +#include <linux/iosys-map.h>
>   
>   static int list_limit = 1024;
>   module_param(list_limit, int, 0644);
> @@ -60,6 +62,30 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
>   	return 0;
>   }
>   
> +static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
> +{
> +	struct udmabuf *ubuf = buf->priv;
> +	void *vaddr;
> +
> +	dma_resv_assert_held(buf->resv);
> +
> +	vaddr = vm_map_ram(ubuf->pages, ubuf->pagecount, -1);
> +	if (!vaddr)
> +		return -EINVAL;
> +
> +	iosys_map_set_vaddr(map, vaddr);
> +	return 0;
> +}
> +
> +static void vunmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
> +{
> +	struct udmabuf *ubuf = buf->priv;
> +
> +	dma_resv_assert_held(buf->resv);
> +
> +	vm_unmap_ram(map->vaddr, ubuf->pagecount);
> +}
> +
>   static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf,
>   				     enum dma_data_direction direction)
>   {
> @@ -162,6 +188,8 @@ static const struct dma_buf_ops udmabuf_ops = {
>   	.unmap_dma_buf	   = unmap_udmabuf,
>   	.release	   = release_udmabuf,
>   	.mmap		   = mmap_udmabuf,
> +	.vmap		   = vmap_udmabuf,
> +	.vunmap		   = vunmap_udmabuf,
>   	.begin_cpu_access  = begin_cpu_udmabuf,
>   	.end_cpu_access    = end_cpu_udmabuf,
>   };


      reply	other threads:[~2022-11-18  9:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 17:18 Lukasz Wiecaszek
2022-11-18  9:58 ` Christian König [this message]

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=b31fc44a-5827-5213-2a8f-9f0529155542@amd.com \
    --to=christian.koenig@amd.com \
    --cc=dmitry.osipenko@collabora.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=lukasz.wiecaszek@gmail.com \
    --cc=lukasz.wiecaszek@googlemail.com \
    --cc=sumit.semwal@linaro.org \
    /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®