Skip to contentSkip to conversation

drm/i915: Disallow pin ioctl completely for kms drivers

PATCH In review Daniel Vetter 5 participants 9 messages Nov 24, 2014 – Feb 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/i915: Disallow pin ioctl completely for kms drivers

The problem here is that SNA pins batchbuffers to etch out a bit more performance. Iirc it started out as a w/a for i830M (which we've implemented in the kernel since a long time already). The problem is that the pin ioctl wasn't added in

commit d23db88c3ab233daed18709e3a24d6c95344117f

Author: Chris Wilson <[email protected]>
Date:   Fri May 23 08:48:08 2014 +0200

drm/i915: Prevent negative relocation deltas from wrapping

Fix this by simply disallowing pinning from userspace so that the kernel is in full control of batch placement again. Especially since distros are moving towards running X as non-root, so most users won't even be able to see any benefits.

UMS support is dead now, but we need this minimal patch for backporting. Follow-up patch will remove the pin ioctl code completely.

References: https://bugs.freedesktop.org/show_bug.cgi?id=76554#c116

---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +4 -1
index 3c64eb6abf2d..fb5ce2b89aba 100644
@@ -4245,7 +4245,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_gem_object *obj;
 	int ret;
 
-	if (INTEL_INFO(dev)->gen >= 6)
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
 		return -ENODEV;
 
 	ret = i915_mutex_lock_interruptible(dev);
@@ -4301,6 +4301,9 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_gem_object *obj;
 	int ret;
 
+	if (drm_core_check_feature(dev, DRIVER_MODESET))
+		return -ENODEV;
+
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
 		return ret;
Signature · 6 lines
2.1.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/2 drm/i915: Remove user pinning code

Now unused.

---
 drivers/gpu/drm/i915/i915_debugfs.c   |   4 +-
 drivers/gpu/drm/i915/i915_dma.c       |  11 +++-
 drivers/gpu/drm/i915/i915_drv.h       |   8 ---
 drivers/gpu/drm/i915/i915_gem.c       | 106 +---------------------------------
 drivers/gpu/drm/i915/i915_gem_gtt.h   |   9 ++-
 drivers/gpu/drm/i915/i915_gpu_error.c |   2 -
 6 files changed, 17 insertions(+), 123 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -3
index b4f23a8f7779..b50458360a2d 100644
@@ -96,9 +96,7 @@ static int i915_capabilities(struct seq_file *m, void *data)
 
 static const char *get_pin_flag(struct drm_i915_gem_object *obj)
 {
-	if (obj->user_pin_count > 0)
-		return "P";
-	else if (i915_gem_obj_is_pinned(obj))
+	if (i915_gem_obj_is_pinned(obj))
 		return "p";
 	else
 		return " ";
drivers/gpu/drm/i915/i915_dma.c +9 -2
index ecee3bcc8772..887d88f4c688 100644
@@ -1004,6 +1004,13 @@ void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
 	kfree(file_priv);
 }
 
+static int
+i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
+			  struct drm_file *file)
+{
+	return -ENODEV;
+}
+
 const struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 	DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
@@ -1025,8 +1032,8 @@ const struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
-	DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
-	DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED),
 	DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
drivers/gpu/drm/i915/i915_drv.h +0 -8
index e67ce6157c63..bfac5b1fdd5b 100644
@@ -1958,10 +1958,6 @@ struct drm_i915_gem_object {
 	/** Record of address bit 17 of each page at last unbind. */
 	unsigned long *bit_17;
 
-	/** User space pin count and filp owning the pin */
-	unsigned long user_pin_count;
-	struct drm_file *pin_filp;
-
 	union {
 		/** for phy allocated objects */
 		struct drm_dma_handle *phys_handle;
@@ -2428,10 +2424,6 @@ int i915_gem_execbuffer(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 int i915_gem_execbuffer2(struct drm_device *dev, void *data,
 			 struct drm_file *file_priv);
-int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
-		       struct drm_file *file_priv);
-int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
-			 struct drm_file *file_priv);
 int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
 			struct drm_file *file_priv);
 int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/i915/i915_gem.c +3 -103

123 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gem_gtt.h +4 -5
index beaf4bcfdac8..92db6654f93b 100644
@@ -146,11 +146,10 @@ struct i915_vma {
 
 	/**
 	 * How many users have pinned this object in GTT space. The following
-	 * users can each hold at most one reference: pwrite/pread, pin_ioctl
-	 * (via user_pin_count), execbuffer (objects are not allowed multiple
-	 * times for the same batchbuffer), and the framebuffer code. When
-	 * switching/pageflipping, the framebuffer code has at most two buffers
-	 * pinned per crtc.
+	 * users can each hold at most one reference: pwrite/pread, execbuffer
+	 * (objects are not allowed multiple times for the same batchbuffer),
+	 * and the framebuffer code. When switching/pageflipping, the
+	 * framebuffer code has at most two buffers pinned per crtc.
 	 *
 	 * In the worst case this is 1 + 1 + 1 + 2*2 = 7. That would fit into 3
 	 * bits with absolutely no headroom. So use 4 bits. */
drivers/gpu/drm/i915/i915_gpu_error.c +0 -2
index cdaee6ce05f8..eea98d567431 100644
@@ -679,8 +679,6 @@ static void capture_bo(struct drm_i915_error_buffer *err,
 	err->pinned = 0;
 	if (i915_gem_obj_is_pinned(obj))
 		err->pinned = 1;
-	if (obj->user_pin_count > 0)
-		err->pinned = -1;
 	err->tiling = obj->tiling_mode;
 	err->dirty = obj->dirty;
 	err->purgeable = obj->madv != I915_MADV_WILLNEED;
Signature · 6 lines
2.1.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Tested-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/i915: Remove user pinning code

-------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied

PNV                 -2              367/367              365/367
ILK                 -3              375/375              372/375
SNB                                  450/450              450/450
IVB                 -2              503/503              501/503
BYT                                  289/289              289/289
HSW                 -3              567/567              564/567
BDW                 -1              417/417              416/417
-------------------------------------Detailed-------------------------------------
Platform  Test                                drm-intel-nightly          Series Applied
PNV  igt_gem_pin      PASS(2, M23)      NSPT(1, M23)
PNV  igt_gen3_mixed_blits      PASS(5, M23)      CRASH(1, M23)
ILK  igt_gem_pin      PASS(2, M37)      NSPT(1, M37)
ILK  igt_gem_reset_stats_close-pending-fork-render      TIMEOUT(6, M37M26)PASS(1, M26)      TIMEOUT(1, M37)
ILK  igt_kms_flip_vblank-vs-hang      TIMEOUT(6, M37M26)PASS(1, M26)      TIMEOUT(1, M37)
IVB  igt_gem_bad_reloc_negative-reloc      NSPT(9, M34M21M4)PASS(1, M21)      NSPT(1, M34)
IVB  igt_gem_bad_reloc_negative-reloc-lut      NSPT(3, M21M34M4)PASS(10, M21M34M4)      NSPT(1, M34)
HSW  igt_gem_bad_reloc_negative-reloc-lut      NSPT(18, M40M20M19)PASS(1, M20)      NSPT(1, M19)
HSW  igt_kms_rotation_crc_primary-rotation      PASS(18, M20M40M19)      DMESG_WARN(1, M19)
HSW  igt_pm_rc6_residency_rc6-accuracy      PASS(19, M20M40M19)      FAIL(1, M19)
BDW  igt_gem_render_linear_blits      TIMEOUT(1, M30)PASS(1, M28)      TIMEOUT(1, M30)

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Daniel Vetter
Quoted 3 lines · Daniel Vetter

The problem here is that SNA pins batchbuffers to etch out a bit more performance. Iirc it started out as a w/a for i830M (which we've implemented in the kernel since a long time already).

Hmm, we only finally fixed it in the kernel a couple of months ago.

Quoted 7 lines

The problem is
that the pin ioctl wasn't added in

commit d23db88c3ab233daed18709e3a24d6c95344117f

Author: Chris Wilson <[email protected]>
Date:   Fri May 23 08:48:08 2014 +0200
Quoted 6 lines

drm/i915: Prevent negative relocation deltas from wrapping

Fix this by simply disallowing pinning from userspace so that the kernel is in full control of batch placement again. Especially since distros are moving towards running X as non-root, so most users won't even be able to see any benefits.

Pinning is a useful tool and it would also be useful to have again on gen6+.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw
Quoted 6 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

The problem here is that SNA pins batchbuffers to etch out a bit more performance. Iirc it started out as a w/a for i830M (which we've implemented in the kernel since a long time already).

Hmm, we only finally fixed it in the kernel a couple of months ago.

The original wa hack has landed in 3.8:

commit b45305fce5bb1abec263fcff9d81ebecd6306ede

Author: Daniel Vetter <[email protected]>
Date:   Mon Dec 17 16:21:27 2012 +0100

drm/i915: Implement workaround for broken CS tlb on i830/845

The follow-up fix from you was cc: stable:

commit c4d69da167fa967749aeb70bc0e94a457e5d00c1

Author: Chris Wilson <[email protected]>
Date:   Mon Sep 8 14:25:41 2014 +0100

drm/i915: Evict CS TLBs between batches

So as long as people backport all of this and don't try to run it on 3.8 we should be fine I think wrt backwards/forwards compat. I'll add this to the commit message.

Quoted 9 lines
Quoted 9 lines

The problem is
that the pin ioctl wasn't added in

commit d23db88c3ab233daed18709e3a24d6c95344117f

Author: Chris Wilson <[email protected]>
Date:   Fri May 23 08:48:08 2014 +0200

drm/i915: Prevent negative relocation deltas from wrapping

Quoted 7 lines
Quoted 4 lines

Fix this by simply disallowing pinning from userspace so that the kernel is in full control of batch placement again. Especially since distros are moving towards running X as non-root, so most users won't even be able to see any benefits.

Pinning is a useful tool and it would also be useful to have again on gen6+.

I think softpin or similar is doable with ppgtt. But with shared ggtt I'm not really enthusiastic about providing this kind of rope to userspace. And softpin is a different type of pinning, so we don't really lose anything by ripping out the userspace hard pinning ioctls. -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw
Quoted 19 lines · Daniel Vetter
Quoted 6 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

The problem here is that SNA pins batchbuffers to etch out a bit more performance. Iirc it started out as a w/a for i830M (which we've implemented in the kernel since a long time already).

Hmm, we only finally fixed it in the kernel a couple of months ago.

The original wa hack has landed in 3.8:

commit b45305fce5bb1abec263fcff9d81ebecd6306ede

Author: Daniel Vetter <[email protected]>
Date:   Mon Dec 17 16:21:27 2012 +0100

drm/i915: Implement workaround for broken CS tlb on i830/845

The follow-up fix from you was cc: stable:

commit c4d69da167fa967749aeb70bc0e94a457e5d00c1

Quoted 8 lines
Author: Chris Wilson <[email protected]>
Date:   Mon Sep 8 14:25:41 2014 +0100

drm/i915: Evict CS TLBs between batches

So as long as people backport all of this and don't try to run it on 3.8 we should be fine I think wrt backwards/forwards compat. I'll add this to the commit message.

You should also mention that the kernel w/a is inferior to the userspace w/a to tune of 10-20%.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

The problem is
that the pin ioctl wasn't added in

commit d23db88c3ab233daed18709e3a24d6c95344117f

Author: Chris Wilson <[email protected]>
Date:   Fri May 23 08:48:08 2014 +0200

drm/i915: Prevent negative relocation deltas from wrapping

Fix this by simply disallowing pinning from userspace so that the kernel is in full control of batch placement again. Especially since distros are moving towards running X as non-root, so most users won't even be able to see any benefits.

Quoted 7 lines
Quoted 2 lines

Pinning is a useful tool and it would also be useful to have again on gen6+.

I think softpin or similar is doable with ppgtt. But with shared ggtt I'm not really enthusiastic about providing this kind of rope to userspace. And softpin is a different type of pinning, so we don't really lose anything by ripping out the userspace hard pinning ioctls.

I am not talking about softpin, but being able to pin memory and a GGTT binding itself is useful.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw
Quoted 5 lines · Chris Wilson
Quoted 4 lines · Daniel Vetter
Quoted 2 lines · Chris Wilson

Pinning is a useful tool and it would also be useful to have again on gen6+.

Quoted 7 lines
Quoted 4 lines

I think softpin or similar is doable with ppgtt. But with shared ggtt I'm not really enthusiastic about providing this kind of rope to userspace. And softpin is a different type of pinning, so we don't really lose anything by ripping out the userspace hard pinning ioctls.

I am not talking about softpin, but being able to pin memory and a GGTT binding itself is useful.

I see you merged this over Chris's objections and then shot down his revert. I'm not clear on why you're so opposed to the pin ioctl? It's a privileged op and definitely has its uses as Chris has repeatedly pointed out.

Why so insistent on dropping this particular ioctl? Do you see it causing actual problems? Or do you just like preventing userspace from doing things you don't agree with?

(Sorry, catching up on ancient backlog from intel-gfx, so maybe there's a thread I missed when re-looking at this. If so, please point me at it.)

Thanks,
Jesse

#7 lore raw
Quoted 19 lines · Jesse Barnes
Quoted 5 lines · Chris Wilson
Quoted 4 lines · Daniel Vetter
Quoted 2 lines · Chris Wilson

Pinning is a useful tool and it would also be useful to have again on gen6+.

Quoted 7 lines
Quoted 4 lines

I think softpin or similar is doable with ppgtt. But with shared ggtt I'm not really enthusiastic about providing this kind of rope to userspace. And softpin is a different type of pinning, so we don't really lose anything by ripping out the userspace hard pinning ioctls.

I am not talking about softpin, but being able to pin memory and a GGTT binding itself is useful.

I see you merged this over Chris's objections and then shot down his revert. I'm not clear on why you're so opposed to the pin ioctl? It's a privileged op and definitely has its uses as Chris has repeatedly pointed out.

Quoted 6 lines

Why so insistent on dropping this particular ioctl? Do you see it causing actual problems? Or do you just like preventing userspace from doing things you don't agree with?

(Sorry, catching up on ancient backlog from intel-gfx, so maybe there's a thread I missed when re-looking at this. If so, please point me at it.)

People are way too happy to abuse it instead of using dma-buf. And at least some of the uses sna has also cause a bunch of problems with being a bit too clever around reloc handling (so we essentially _have_ to take the toys away since giving it back would cause regressions).

If there's a real users then we can look at this again imo, but I think most things are better solved with proper kernel interfaces since in the end the kernel does mm for the gpu, and if userspace interferes we can't do that.

So overall my answer is:
- re-enable will cause regressions
- I don't see a justified user
- we should never have allowed this with kms to begin with, it was an oversight.

Thanks, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#8 lore raw
Quoted 24 lines · Daniel Vetter
Quoted 23 lines · Jesse Barnes
Quoted 5 lines · Chris Wilson
Quoted 4 lines · Daniel Vetter
Quoted 2 lines · Chris Wilson

Pinning is a useful tool and it would also be useful to have again on gen6+.

Quoted 7 lines
Quoted 4 lines

I think softpin or similar is doable with ppgtt. But with shared ggtt I'm not really enthusiastic about providing this kind of rope to userspace. And softpin is a different type of pinning, so we don't really lose anything by ripping out the userspace hard pinning ioctls.

I am not talking about softpin, but being able to pin memory and a GGTT binding itself is useful.

I see you merged this over Chris's objections and then shot down his revert. I'm not clear on why you're so opposed to the pin ioctl? It's a privileged op and definitely has its uses as Chris has repeatedly pointed out.

Why so insistent on dropping this particular ioctl? Do you see it causing actual problems? Or do you just like preventing userspace from doing things you don't agree with?

Quoted 7 lines
Quoted 2 lines

(Sorry, catching up on ancient backlog from intel-gfx, so maybe there's a thread I missed when re-looking at this. If so, please point me at it.)

People are way too happy to abuse it instead of using dma-buf. And at least some of the uses sna has also cause a bunch of problems with being a bit too clever around reloc handling (so we essentially _have_ to take the toys away since giving it back would cause regressions).

Some interfaces are more dangerous than others. But that doesn't mean they're necessarily bad.

Quoted 7 lines

If there's a real users then we can look at this again imo, but I think most things are better solved with proper kernel interfaces since in the end the kernel does mm for the gpu, and if userspace interferes we can't do that.

So overall my answer is:
- re-enable will cause regressions

Which regressions? In SNA? It sounded like Chris was the one requesting this here. And really, dropping pin altogether was a big regression in the ABI to begin with and probably shouldn't have been allowed (the one back in 2013; I think both Chris and Ben objected back then too).

Quoted 1 line

- I don't see a justified user

What about SNA? What about debug? Yes there's an alternative in the SNA case, but Chris mentioned it had a huge perf hit. And fwiw the Beignet team is using this too, so at the very least it needs to work on aliasing PPGTT on gen7/7.5.

Quoted 2 lines

- we should never have allowed this with kms to begin with, it was an oversight.

Not sure about that; as Chris mentioned, mlock() has uses too. It needs to be limited, obviously, and can cause trouble if you're not careful. But that's not a reason to disallow it or remove it altogether.

Anyway, the patches have no r-bs or acks, only nacks going back to gen6, and you're still merging these. That's what's not sitting well with me.

Jesse