From: Daniel Vetter <daniel@ffwll.ch>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: daniel@ffwll.ch, christian.koenig@amd.com, airlied@linux.ie,
sumit.semwal@linaro.org, maarten.lankhorst@linux.intel.com,
mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com,
sean@poorly.run, eric@anholt.net, sam@ravnborg.org,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v3 5/8] drm/cma-helper: Provide a vmap function for short-term mappings
Date: Fri, 11 Dec 2020 11:02:47 +0100 [thread overview]
Message-ID: <20201211100247.GO401619@phenom.ffwll.local> (raw)
In-Reply-To: <20201211094000.GK401619@phenom.ffwll.local>
On Fri, Dec 11, 2020 at 10:40:00AM +0100, Daniel Vetter wrote:
> On Wed, Dec 09, 2020 at 03:25:24PM +0100, Thomas Zimmermann wrote:
> > Implementations of the vmap/vunmap GEM callbacks may perform pinning
> > of the BO and may acquire the associated reservation object's lock.
> > Callers that only require a mapping of the contained memory can thus
> > interfere with other tasks that require exact pinning, such as scanout.
> > This is less of an issue with private CMA buffers, but may happen
> > with imported ones.
> >
> > Therefore provide the new interface drm_gem_cma_vmap_local(), which only
> > performs the vmap operations. Callers have to hold the reservation lock
> > while the mapping persists.
> >
> > This patch also connects GEM CMA helpers to the GEM object function with
> > equivalent functionality.
> >
> > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> > ---
> > drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++++++++++++++++++++++++
> > drivers/gpu/drm/vc4/vc4_bo.c | 13 +++++++++++
> > drivers/gpu/drm/vc4/vc4_drv.h | 1 +
> > include/drm/drm_gem_cma_helper.h | 1 +
> > 4 files changed, 50 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
> > index 7942cf05cd93..40b3e8e3fc42 100644
> > --- a/drivers/gpu/drm/drm_gem_cma_helper.c
> > +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
> > @@ -38,6 +38,7 @@ static const struct drm_gem_object_funcs drm_gem_cma_default_funcs = {
> > .print_info = drm_gem_cma_print_info,
> > .get_sg_table = drm_gem_cma_get_sg_table,
> > .vmap = drm_gem_cma_vmap,
> > + .vmap_local = drm_gem_cma_vmap_local,
> > .mmap = drm_gem_cma_mmap,
> > .vm_ops = &drm_gem_cma_vm_ops,
> > };
> > @@ -471,6 +472,40 @@ int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
> > }
> > EXPORT_SYMBOL_GPL(drm_gem_cma_vmap);
> >
> > +/**
> > + * drm_gem_cma_vmap_local - map a CMA GEM object into the kernel's virtual
> > + * address space
> > + * @obj: GEM object
> > + * @map: Returns the kernel virtual address of the CMA GEM object's backing
> > + * store.
> > + *
> > + * This function maps a buffer into the kernel's
> > + * virtual address space. Since the CMA buffers are already mapped into the
> > + * kernel virtual address space this simply returns the cached virtual
> > + * address. Drivers using the CMA helpers should set this as their DRM
> > + * driver's &drm_gem_object_funcs.vmap_local callback.
> > + *
> > + * Returns:
> > + * 0 on success, or a negative error code otherwise.
> > + */
> > +int drm_gem_cma_vmap_local(struct drm_gem_object *obj, struct dma_buf_map *map)
> > +{
> > + struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
> > +
> > + /*
> > + * TODO: The code in drm_gem_cma_prime_import_sg_table_vmap()
> > + * establishes this mapping. The correct solution would
> > + * be to call dma_buf_vmap_local() here.
> > + *
> > + * If we find a case where we absolutely have to call
> > + * dma_buf_vmap_local(), the code needs to be restructured.
>
> dma_buf_vmap_local is only relevant for dynamic importers, pinning at
> import time is actually what you get anyway. That's what Christian meant
> with his comments for the ->pin hook. So the TODO here doesn't make sense
> imo, just delete it. We're very far away from making cma dynamic :-)
>
> > + */
> > + dma_buf_map_set_vaddr(map, cma_obj->vaddr);
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(drm_gem_cma_vmap_local);
> > +
> > /**
> > * drm_gem_cma_mmap - memory-map an exported CMA GEM object
> > * @obj: GEM object
> > diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
> > index dc316cb79e00..ec57326c69c4 100644
> > --- a/drivers/gpu/drm/vc4/vc4_bo.c
> > +++ b/drivers/gpu/drm/vc4/vc4_bo.c
> > @@ -387,6 +387,7 @@ static const struct drm_gem_object_funcs vc4_gem_object_funcs = {
> > .export = vc4_prime_export,
> > .get_sg_table = drm_gem_cma_get_sg_table,
> > .vmap = vc4_prime_vmap,
> > + .vmap_local = vc4_prime_vmap_local,
> > .vm_ops = &vc4_vm_ops,
> > };
> >
> > @@ -797,6 +798,18 @@ int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
> > return drm_gem_cma_vmap(obj, map);
> > }
> >
> > +int vc4_prime_vmap_local(struct drm_gem_object *obj, struct dma_buf_map *map)
> > +{
> > + struct vc4_bo *bo = to_vc4_bo(obj);
> > +
> > + if (bo->validated_shader) {
>
> This freaks me out. It should be impossible to export a validated shader
> as a dma-buf, and indeed the check exists already.
>
> All the wrapper functions here are imo pointless. Either we should remove
> them, or replace the if with a BUG_ON here since if that ever happens we
> have a security bug already. I'd go with removing, less code. Maybe throw
> a patch on top?
On 2nd thought, since I asked for the driver parts to be split out in all
the follow-up patches. Maybe best if you do the removal of these wrappers
here first, that gets rid of the vc4 changes in this patch here too.
-Daniel
>
> Anyway this patch looks good, with the todo deleted:
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>
>
> > + DRM_DEBUG("mmaping of shader BOs not allowed.\n");
> > + return -EINVAL;
> > + }
> > +
> > + return drm_gem_cma_vmap_local(obj, map);
> > +}
> > +
> > struct drm_gem_object *
> > vc4_prime_import_sg_table(struct drm_device *dev,
> > struct dma_buf_attachment *attach,
> > diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> > index 43a1af110b3e..efb6c47d318f 100644
> > --- a/drivers/gpu/drm/vc4/vc4_drv.h
> > +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> > @@ -812,6 +812,7 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
> > struct dma_buf_attachment *attach,
> > struct sg_table *sgt);
> > int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
> > +int vc4_prime_vmap_local(struct drm_gem_object *obj, struct dma_buf_map *map);
> > int vc4_bo_cache_init(struct drm_device *dev);
> > int vc4_bo_inc_usecnt(struct vc4_bo *bo);
> > void vc4_bo_dec_usecnt(struct vc4_bo *bo);
> > diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h
> > index 0a9711caa3e8..05122e71bc6d 100644
> > --- a/include/drm/drm_gem_cma_helper.h
> > +++ b/include/drm/drm_gem_cma_helper.h
> > @@ -99,6 +99,7 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
> > struct dma_buf_attachment *attach,
> > struct sg_table *sgt);
> > int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
> > +int drm_gem_cma_vmap_local(struct drm_gem_object *obj, struct dma_buf_map *map);
> > int drm_gem_cma_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
> >
> > /**
> > --
> > 2.29.2
> >
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2020-12-11 10:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 14:25 [PATCH v3 0/8] drm: Support short-term vmap via vmap_local Thomas Zimmermann
2020-12-09 14:25 ` [PATCH v3 1/8] drm/ast: Don't pin cursor source BO explicitly during update Thomas Zimmermann
2020-12-11 10:14 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 2/8] drm/ast: Only map cursor BOs during updates Thomas Zimmermann
2020-12-11 10:18 ` Daniel Vetter
2020-12-11 10:49 ` Thomas Zimmermann
2020-12-11 13:57 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 3/8] dma-buf: Add vmap_local and vnumap_local operations Thomas Zimmermann
2020-12-09 14:27 ` Thomas Zimmermann
2020-12-11 9:24 ` Daniel Vetter
2020-12-11 14:09 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 4/8] drm/gem: Create infrastructure for GEM vmap_local Thomas Zimmermann
2020-12-11 9:29 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 5/8] drm/cma-helper: Provide a vmap function for short-term mappings Thomas Zimmermann
2020-12-11 9:40 ` Daniel Vetter
2020-12-11 10:02 ` Daniel Vetter [this message]
2020-12-09 14:25 ` [PATCH v3 6/8] drm/shmem-helper: " Thomas Zimmermann
2020-12-11 9:50 ` Daniel Vetter
2021-01-07 10:28 ` Thomas Zimmermann
2021-01-07 15:01 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 7/8] drm/vram-helper: " Thomas Zimmermann
2020-12-11 9:57 ` Daniel Vetter
2020-12-09 14:25 ` [PATCH v3 8/8] drm/fb-helper: Move BO locking from DRM client to fbdev damage worker Thomas Zimmermann
2020-12-11 10:01 ` Daniel Vetter
2020-12-11 10:16 ` Thomas Zimmermann
2020-12-11 14:00 ` Daniel Vetter
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=20201211100247.GO401619@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=airlied@linux.ie \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric@anholt.net \
--cc=hdegoede@redhat.com \
--cc=kraxel@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sam@ravnborg.org \
--cc=sean@poorly.run \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux-foundation.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