All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: DRI Development <dri-devel@lists.freedesktop.org>
Cc: "Rob Herring" <robh@kernel.org>,
	"Thomas Hellstrom" <thellstrom@vmware.com>,
	"Tomeu Vizoso" <tomeu.vizoso@collabora.com>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	"Intel Graphics Development" <intel-gfx@lists.freedesktop.org>,
	"VMware Graphics" <linux-graphics-maintainer@vmware.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Ben Skeggs" <bskeggs@redhat.com>
Subject: Re: [PATCH 1/3] dma_resv: prime lockdep annotations
Date: Wed, 21 Aug 2019 23:20:51 +0100	[thread overview]
Message-ID: <156642605147.20466.13019420195083819968@skylake-alporthouse-com> (raw)
In-Reply-To: <20190821215030.31660-1-daniel.vetter@ffwll.ch>

Quoting Daniel Vetter (2019-08-21 22:50:28)
> Full audit of everyone:
> 
> - i915, radeon, amdgpu should be clean per their maintainers.
> 
> - vram helpers should be fine, they don't do command submission, so
>   really no business holding struct_mutex while doing copy_*_user. But
>   I haven't checked them all.
> 
> - panfrost seems to dma_resv_lock only in panfrost_job_push, which
>   looks clean.
> 
> - v3d holds dma_resv locks in the tail of its v3d_submit_cl_ioctl(),
>   copying from/to userspace happens all in v3d_lookup_bos which is
>   outside of the critical section.
> 
> - vmwgfx has a bunch of ioctls that do their own copy_*_user:
>   - vmw_execbuf_process: First this does some copies in
>     vmw_execbuf_cmdbuf() and also in the vmw_execbuf_process() itself.
>     Then comes the usual ttm reserve/validate sequence, then actual
>     submission/fencing, then unreserving, and finally some more
>     copy_to_user in vmw_execbuf_copy_fence_user. Glossing over tons of
>     details, but looks all safe.
>   - vmw_fence_event_ioctl: No ttm_reserve/dma_resv_lock anywhere to be
>     seen, seems to only create a fence and copy it out.
>   - a pile of smaller ioctl in vmwgfx_ioctl.c, no reservations to be
>     found there.
>   Summary: vmwgfx seems to be fine too.
> 
> - virtio: There's virtio_gpu_execbuffer_ioctl, which does all the
>   copying from userspace before even looking up objects through their
>   handles, so safe. Plus the getparam/getcaps ioctl, also both safe.
> 
> - qxl only has qxl_execbuffer_ioctl, which calls into
>   qxl_process_single_command. There's a lovely comment before the
>   __copy_from_user_inatomic that the slowpath should be copied from
>   i915, but I guess that never happened. Try not to be unlucky and get
>   your CS data evicted between when it's written and the kernel tries
>   to read it. The only other copy_from_user is for relocs, but those
>   are done before qxl_release_reserve_list(), which seems to be the
>   only thing reserving buffers (in the ttm/dma_resv sense) in that
>   code. So looks safe.
> 
> - A debugfs file in nouveau_debugfs_pstate_set() and the usif ioctl in
>   usif_ioctl() look safe. nouveau_gem_ioctl_pushbuf() otoh breaks this
>   everywhere and needs to be fixed up.
> 
> v2: Thomas pointed at that vmwgfx calls dma_resv_init while it holds a
> dma_resv lock of a different object already. Christian mentioned that
> ttm core does this too for ghost objects. intel-gfx-ci highlighted
> that i915 has similar issues.
> 
> Unfortunately we can't do this in the usual module init functions,
> because kernel threads don't have an ->mm - we have to wait around for
> some user thread to do this.
> 
> Solution is to spawn a worker (but only once). It's horrible, but it
> works.
> 
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: "VMware Graphics" <linux-graphics-maintainer@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/dma-buf/dma-resv.c | 42 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 42a8f3f11681..29988b1564c1 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -34,6 +34,7 @@
>  
>  #include <linux/dma-resv.h>
>  #include <linux/export.h>
> +#include <linux/sched/mm.h>
>  
>  /**
>   * DOC: Reservation Object Overview
> @@ -95,6 +96,28 @@ static void dma_resv_list_free(struct dma_resv_list *list)
>         kfree_rcu(list, rcu);
>  }
>  
> +#if IS_ENABLED(CONFIG_LOCKDEP)
> +struct lockdep_work {
> +       struct work_struct work;
> +       struct dma_resv obj;
> +       struct mm_struct *mm;
> +} lockdep_work;
> +
> +void lockdep_work_fn(struct work_struct *work)
> +{
> +       dma_resv_init(&lockdep_work.obj);
> +
> +       down_read(&lockdep_work.mm->mmap_sem);
> +       ww_mutex_lock(&lockdep_work.obj.lock, NULL);
> +       fs_reclaim_acquire(GFP_KERNEL);
> +       fs_reclaim_release(GFP_KERNEL);
> +       ww_mutex_unlock(&lockdep_work.obj.lock);
> +       up_read(&lockdep_work.mm->mmap_sem);
> +       
> +       mmput(lockdep_work.mm);
> +}
> +#endif

#if IS_ENABLED(CONFIG_LOCKDEP)
static void dma_resv_lockmap(void)
{
	struct mm_struct *mm = alloc_mm();
	struct dma_resv obj;

	dma_resv_init(&obj);

	down_read(&mm->mmap_sem);
	ww_mutex_lock(&obj.lock, NULL);
	fs_reclaim_acquire(GFP_KERNEL);
	fs_reclaim_release(GFP_KERNEL);
	ww_mutex_unlock(&obj.lock);
	up_read(&mm->mmap_sem);

	mmput(mm);
}
core_initcall(dma_resv_lockmap);
#endif

as a thought.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-08-21 22:20 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21 21:50 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
     [not found] ` <20190821215030.31660-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-08-21 21:50   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
     [not found]     ` <20190821215030.31660-2-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-09-03  8:17       ` Daniel Vetter
     [not found]         ` <20190903081714.GO2112-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2019-09-18  9:29           ` Daniel Vetter
2019-08-21 21:50 ` [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-08-21 22:20 ` Chris Wilson [this message]
2019-08-21 22:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] dma_resv: prime lockdep annotations Patchwork
2019-08-21 22:46 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-22  6:49 ` [PATCH] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-08-22  7:56   ` Koenig, Christian
2019-08-22  8:47     ` Daniel Vetter
2019-08-22  9:53       ` Thomas Hellström (VMware)
2019-08-22 13:06     ` Daniel Vetter
2019-08-22 14:02       ` Koenig, Christian
2019-08-22 14:24         ` Thomas Hellström (VMware)
2019-08-22 14:30           ` Thomas Hellström (VMware)
2019-08-22  6:54 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
2019-08-22  7:48   ` Chris Wilson
2019-08-22  7:53   ` Koenig, Christian
2019-09-03  8:16     ` Daniel Vetter
2019-09-03  9:02       ` Koenig, Christian
2019-08-22 12:56   ` Rob Herring
2019-08-22  8:40 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
2019-08-22  9:16 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-22 13:07 ` [PATCH] dma_resv: prime lockdep annotations Daniel Vetter
2019-08-22 13:30   ` Thomas Hellström (VMware)
2019-08-22 13:36     ` Daniel Vetter
2019-08-22 14:56       ` Thomas Hellström (VMware)
2019-08-22 14:46 ` ✓ Fi.CI.IGT: success for series starting with [1/3] " Patchwork
2019-08-23  1:43 ` ✓ Fi.CI.IGT: success for series starting with dma_resv: prime lockdep annotations (rev3) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2019-11-04 17:37 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
2019-11-04 17:37 ` Daniel Vetter
2019-11-04 17:48 ` Daniel Vetter
2019-11-04 17:48   ` Daniel Vetter
2019-11-04 20:01 ` Koenig, Christian
2019-11-04 20:01   ` Koenig, Christian
2019-11-04 20:55   ` Daniel Vetter
2019-11-04 20:55     ` Daniel Vetter
2019-11-11 13:11 ` Steven Price
2019-11-11 15:42   ` Daniel Vetter
2019-11-11 15:42     ` Daniel Vetter
2019-11-14 11:50     ` Steven Price
2019-11-14 11:50       ` Steven Price
2019-11-20 10:51       ` Daniel Vetter
2019-10-21 14:50 [PATCH 0/3] dma_resv lockdep annotations/priming Daniel Vetter
2019-10-21 14:50 ` [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
2019-10-21 16:56   ` Thomas Hellstrom
2019-10-22  7:55   ` kbuild test robot
2019-10-22  7:55     ` kbuild test robot
2019-08-21 18:31 Koenig, Christian
2019-08-20 14:53 [PATCH 0/3] RFC/T: dma_resv vs. mmap_sem Daniel Vetter
2019-08-20 14:53 ` [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
2019-08-20 14:56   ` Koenig, Christian
2019-08-21 15:44     ` Daniel Vetter
2019-08-20 14:58   ` Chris Wilson
2019-08-21 15:54   ` Thomas Hellström (VMware)
2019-08-21 16:34     ` Daniel Vetter
2019-08-21 17:06       ` Thomas Hellström (VMware)
2019-08-21 18:11         ` Daniel Vetter
2019-08-21 18:27           ` Thomas Hellström (VMware)
2019-08-21 19:51             ` Daniel Vetter
2019-08-22  6:42               ` Thomas Hellström (VMware)
2019-08-22  6:47                 ` 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=156642605147.20466.13019420195083819968@skylake-alporthouse-com \
    --to=chris@chris-wilson.co.uk \
    --cc=airlied@redhat.com \
    --cc=alexander.deucher@amd.com \
    --cc=bskeggs@redhat.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=robh@kernel.org \
    --cc=thellstrom@vmware.com \
    --cc=tomeu.vizoso@collabora.com \
    --cc=tzimmermann@suse.de \
    /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.