All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel-/w4YWyX8dFk@public.gmane.org>
To: DRI Development
	<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	Intel Graphics Development
	<intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
	Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Daniel Vetter
	<daniel.vetter-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
Date: Wed, 18 Sep 2019 11:29:47 +0200	[thread overview]
Message-ID: <20190918092947.GE3958@phenom.ffwll.local> (raw)
In-Reply-To: <20190903081714.GO2112-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>

On Tue, Sep 03, 2019 at 10:17:14AM +0200, Daniel Vetter wrote:
> On Wed, Aug 21, 2019 at 11:50:29PM +0200, Daniel Vetter wrote:
> > We can't copy_*_user while holding reservations, that will (soon even
> > for nouveau) lead to deadlocks. And it breaks the cross-driver
> > contract around dma_resv.
> > 
> > Fix this by adding a slowpath for when we need relocations, and by
> > pushing the writeback of the new presumed offsets to the very end.
> > 
> > Aside from "it compiles" entirely untested unfortunately.
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Ben Skeggs <bskeggs@redhat.com>
> > Cc: nouveau@lists.freedesktop.org
> 
> Ping for some review/testing (apparently needs pre-nv50). I'd really like
> to land this series here, it should help a lot in making sure everyone
> uses dma_resv in a compatible way across drivers.

Now that the gem/ttm fallout is fixed, ping for testing on this one here
... Also need some r-b to get this landed.

Thanks, Daniel

> > ---
> >  drivers/gpu/drm/nouveau/nouveau_gem.c | 57 ++++++++++++++++++---------
> >  1 file changed, 38 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > index c77302f969e8..60309b997951 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > @@ -482,12 +482,9 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
> >  
> >  static int
> >  validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> > -	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
> > -	      uint64_t user_pbbo_ptr)
> > +	      struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo)
> >  {
> >  	struct nouveau_drm *drm = chan->drm;
> > -	struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> > -				(void __force __user *)(uintptr_t)user_pbbo_ptr;
> >  	struct nouveau_bo *nvbo;
> >  	int ret, relocs = 0;
> >  
> > @@ -531,10 +528,6 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
> >  			b->presumed.offset = nvbo->bo.offset;
> >  			b->presumed.valid = 0;
> >  			relocs++;
> > -
> > -			if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
> > -					     &b->presumed, sizeof(b->presumed)))
> > -				return -EFAULT;
> >  		}
> >  	}
> >  
> > @@ -545,8 +538,8 @@ static int
> >  nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
> >  			     struct drm_file *file_priv,
> >  			     struct drm_nouveau_gem_pushbuf_bo *pbbo,
> > -			     uint64_t user_buffers, int nr_buffers,
> > -			     struct validate_op *op, int *apply_relocs)
> > +			     int nr_buffers,
> > +			     struct validate_op *op, bool *apply_relocs)
> >  {
> >  	struct nouveau_cli *cli = nouveau_cli(file_priv);
> >  	int ret;
> > @@ -563,7 +556,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
> >  		return ret;
> >  	}
> >  
> > -	ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
> > +	ret = validate_list(chan, cli, &op->list, pbbo);
> >  	if (unlikely(ret < 0)) {
> >  		if (ret != -ERESTARTSYS)
> >  			NV_PRINTK(err, cli, "validating bo list\n");
> > @@ -603,16 +596,12 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
> >  static int
> >  nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
> >  				struct drm_nouveau_gem_pushbuf *req,
> > +				struct drm_nouveau_gem_pushbuf_reloc *reloc,
> >  				struct drm_nouveau_gem_pushbuf_bo *bo)
> >  {
> > -	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
> >  	int ret = 0;
> >  	unsigned i;
> >  
> > -	reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> > -	if (IS_ERR(reloc))
> > -		return PTR_ERR(reloc);
> > -
> >  	for (i = 0; i < req->nr_relocs; i++) {
> >  		struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
> >  		struct drm_nouveau_gem_pushbuf_bo *b;
> > @@ -691,11 +680,13 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	struct nouveau_drm *drm = nouveau_drm(dev);
> >  	struct drm_nouveau_gem_pushbuf *req = data;
> >  	struct drm_nouveau_gem_pushbuf_push *push;
> > +	struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
> >  	struct drm_nouveau_gem_pushbuf_bo *bo;
> >  	struct nouveau_channel *chan = NULL;
> >  	struct validate_op op;
> >  	struct nouveau_fence *fence = NULL;
> > -	int i, j, ret = 0, do_reloc = 0;
> > +	int i, j, ret = 0;
> > +	bool do_reloc = false;
> >  
> >  	if (unlikely(!abi16))
> >  		return -ENOMEM;
> > @@ -753,7 +744,8 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	}
> >  
> >  	/* Validate buffer list */
> > -	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
> > +revalidate:
> > +	ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo,
> >  					   req->nr_buffers, &op, &do_reloc);
> >  	if (ret) {
> >  		if (ret != -ERESTARTSYS)
> > @@ -763,7 +755,18 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  
> >  	/* Apply any relocations that are required */
> >  	if (do_reloc) {
> > -		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
> > +		if (!reloc) {
> > +			validate_fini(&op, chan, NULL, bo);
> > +			reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
> > +			if (IS_ERR(reloc)) {
> > +				ret = PTR_ERR(reloc);
> > +				goto out_prevalid;
> > +			}
> > +
> > +			goto revalidate;
> > +		}
> > +
> > +		ret = nouveau_gem_pushbuf_reloc_apply(cli, req, reloc, bo);
> >  		if (ret) {
> >  			NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
> >  			goto out;
> > @@ -849,6 +852,22 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
> >  	validate_fini(&op, chan, fence, bo);
> >  	nouveau_fence_unref(&fence);
> >  
> > +	if (do_reloc) {
> > +		struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
> > +			u64_to_user_ptr(req->buffers);
> > +
> > +		for (i = 0; i < req->nr_buffers; i++) {
> > +			if (bo[i].presumed.valid)
> > +				continue;
> > +
> > +			if (copy_to_user(&upbbo[i].presumed, &bo[i].presumed,
> > +					 sizeof(bo[i].presumed))) {
> > +				ret = -EFAULT;
> > +				break;
> > +			}
> > +		}
> > +		u_free(reloc);
> > +	}
> >  out_prevalid:
> >  	u_free(bo);
> >  	u_free(push);
> > -- 
> > 2.23.0.rc1
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

  parent reply	other threads:[~2019-09-18  9:29 UTC|newest]

Thread overview: 40+ 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 [this message]
2019-08-21 21:50 ` [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-08-21 22:20 ` [PATCH 1/3] dma_resv: prime lockdep annotations Chris Wilson
2019-08-21 22:22 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " 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
     [not found] ` <20191104173801.2972-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-11-04 17:38   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
2019-11-04 17:38     ` Daniel Vetter
2019-11-05 11:04     ` Daniel Vetter
2019-11-05 11:04       ` Daniel Vetter
     [not found]       ` <20191105110419.GG10326-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2019-11-05 12:30         ` Maarten Lankhorst
2019-11-05 12:30           ` Maarten Lankhorst
2019-10-21 14:50 [PATCH 0/3] dma_resv lockdep annotations/priming Daniel Vetter
     [not found] ` <20191021145017.17384-1-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2019-10-21 14:50   ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl Daniel Vetter
2019-10-24  9:04     ` Daniel Vetter
2019-10-24  9:04       ` Daniel Vetter
2019-08-20 14:53 [PATCH 0/3] RFC/T: dma_resv vs. mmap_sem Daniel Vetter
2019-08-20 14:53 ` [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl 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=20190918092947.GE3958@phenom.ffwll.local \
    --to=daniel-/w4ywyx8dfk@public.gmane.org \
    --cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=daniel.vetter-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 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.