From: Daniel Vetter <daniel@ffwll.ch>
To: DRI Development <dri-devel@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
Ben Skeggs <bskeggs@redhat.com>,
nouveau@lists.freedesktop.org,
Daniel Vetter <daniel.vetter@intel.com>,
Ilia Mirkin <imirkin@alum.mit.edu>
Subject: Re: [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
Date: Tue, 5 Nov 2019 12:04:19 +0100 [thread overview]
Message-ID: <20191105110419.GG10326@phenom.ffwll.local> (raw)
In-Reply-To: <20191104173801.2972-2-daniel.vetter@ffwll.ch>
On Mon, Nov 04, 2019 at 06:38:00PM +0100, 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: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org
Ping for ack/review so I can land this entire series. intel-gfx-ci is all
happy with the rebased version, so nouveau ack is the only hold-up here.
-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 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,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;
>
> @@ -533,10 +530,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;
> }
> }
>
> @@ -547,8 +540,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;
> @@ -565,7 +558,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");
> @@ -605,16 +598,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;
> @@ -693,11 +682,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;
> @@ -755,7 +746,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)
> @@ -765,7 +757,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;
> @@ -851,6 +854,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.24.0.rc2
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel@ffwll.ch>
To: DRI Development <dri-devel@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
Ben Skeggs <bskeggs@redhat.com>,
nouveau@lists.freedesktop.org,
Daniel Vetter <daniel.vetter@intel.com>,
Ilia Mirkin <imirkin@alum.mit.edu>
Subject: Re: [Intel-gfx] [PATCH 2/3] drm/nouveau: slowpath for pushbuf ioctl
Date: Tue, 5 Nov 2019 12:04:19 +0100 [thread overview]
Message-ID: <20191105110419.GG10326@phenom.ffwll.local> (raw)
Message-ID: <20191105110419.8ODeaw5SLUWJeu6SFDtjY3BeXBkhFb2_eugCcPeMYS4@z> (raw)
In-Reply-To: <20191104173801.2972-2-daniel.vetter@ffwll.ch>
On Mon, Nov 04, 2019 at 06:38:00PM +0100, 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: Ilia Mirkin <imirkin@alum.mit.edu>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: nouveau@lists.freedesktop.org
Ping for ack/review so I can land this entire series. intel-gfx-ci is all
happy with the rebased version, so nouveau ack is the only hold-up here.
-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 1324c19f4e5c..05ec8edd6a8b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -484,12 +484,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;
>
> @@ -533,10 +530,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;
> }
> }
>
> @@ -547,8 +540,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;
> @@ -565,7 +558,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");
> @@ -605,16 +598,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;
> @@ -693,11 +682,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;
> @@ -755,7 +746,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)
> @@ -765,7 +757,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;
> @@ -851,6 +854,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.24.0.rc2
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-11-05 11:04 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 17:37 [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
2019-11-04 17:37 ` [Intel-gfx] " 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 ` [Intel-gfx] " Daniel Vetter
2019-11-05 11:04 ` Daniel Vetter [this message]
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 ` [Intel-gfx] " Maarten Lankhorst
2019-11-04 17:38 ` [PATCH 3/3] drm/ttm: remove ttm_bo_wait_unreserved Daniel Vetter
2019-11-04 17:38 ` [Intel-gfx] " Daniel Vetter
2019-11-06 10:24 ` Daniel Vetter
2019-11-06 10:24 ` [Intel-gfx] " Daniel Vetter
2019-11-04 17:48 ` [PATCH 1/3] dma_resv: prime lockdep annotations Daniel Vetter
2019-11-04 17:48 ` [Intel-gfx] " Daniel Vetter
2019-11-04 20:01 ` Koenig, Christian
2019-11-04 20:01 ` [Intel-gfx] " Koenig, Christian
2019-11-04 20:55 ` Daniel Vetter
2019-11-04 20:55 ` [Intel-gfx] " Daniel Vetter
2019-11-04 21:00 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] " Patchwork
2019-11-04 21:00 ` [Intel-gfx] " Patchwork
2019-11-04 21:22 ` ✓ Fi.CI.BAT: success " Patchwork
2019-11-04 21:22 ` [Intel-gfx] " Patchwork
2019-11-05 8:31 ` ✓ Fi.CI.IGT: " Patchwork
2019-11-05 8:31 ` [Intel-gfx] " Patchwork
2019-11-11 13:11 ` [PATCH 1/3] " Steven Price
2019-11-11 13:11 ` [Intel-gfx] " Steven Price
2019-11-11 15:42 ` Daniel Vetter
2019-11-11 15:42 ` [Intel-gfx] " Daniel Vetter
2019-11-14 11:50 ` Steven Price
2019-11-14 11:50 ` [Intel-gfx] " Steven Price
2019-11-20 10:51 ` Daniel Vetter
2019-11-20 10:51 ` [Intel-gfx] " Daniel Vetter
2019-11-11 18:12 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/3] dma_resv: prime lockdep annotations (rev2) Patchwork
2019-11-11 18:12 ` [Intel-gfx] " Patchwork
2019-11-11 18:48 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-11-11 18:48 ` [Intel-gfx] " Patchwork
-- strict thread matches above, loose matches on Subject: below --
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-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-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=20191105110419.GG10326@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=bskeggs@redhat.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=imirkin@alum.mit.edu \
--cc=intel-gfx@lists.freedesktop.org \
--cc=nouveau@lists.freedesktop.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