Skip to contentSkip to conversation

locking/rwsem: Add down_write_interruptible and use it

PATCH In review Zack Rusin 2 participants 5 messages Mar 8, 2021 – Mar 9, 2021

Subsystems (4)
lore
Share & tools
lore
author
#1 lore raw

PATCH 1/2 locking/rwsem: Add down_write_interruptible

In reply to Zack Rusin

Add an interruptible version of down_write. It's the other side of the already implemented down_read_interruptible. It allows drivers which used custom locking code to support interruptible rw semaphores to switch over to rwsem.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
---
 include/linux/rwsem.h  |  1 +
 kernel/locking/rwsem.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/linux/rwsem.h +1 -0
index 4c715be48717..753ae2cb8677 100644
@@ -135,6 +135,7 @@ extern int down_read_trylock(struct rw_semaphore *sem);
  * lock for writing
  */
 extern void down_write(struct rw_semaphore *sem);
+extern int __must_check down_write_interruptible(struct rw_semaphore *sem);
 extern int __must_check down_write_killable(struct rw_semaphore *sem);
 
 /*
kernel/locking/rwsem.c +23 -0
index abba5df50006..0eadd20347de 100644
@@ -1270,6 +1270,11 @@ static inline void __down_write(struct rw_semaphore *sem)
 	__down_write_common(sem, TASK_UNINTERRUPTIBLE);
 }
 
+static inline int __down_write_interruptible(struct rw_semaphore *sem)
+{
+	return __down_write_common(sem, TASK_INTERRUPTIBLE);
+}
+
 static inline int __down_write_killable(struct rw_semaphore *sem)
 {
 	return __down_write_common(sem, TASK_KILLABLE);
@@ -1408,6 +1413,24 @@ void __sched down_write(struct rw_semaphore *sem)
 }
 EXPORT_SYMBOL(down_write);
 
+/*
+ * interruptible lock for writing
+ */
+int __sched down_write_interruptible(struct rw_semaphore *sem)
+{
+	might_sleep();
+	rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
+
+	if (LOCK_CONTENDED_RETURN(sem, __down_write_trylock,
+				  __down_write_interruptible)) {
+		rwsem_release(&sem->dep_map, _RET_IP_);
+		return -EINTR;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(down_write_interruptible);
+
 /*
  * lock for writing
  */
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Zack Rusin

author
#0 lore raw

cover locking/rwsem: Add down_write_interruptible and use it

vmwgfx has really ugly implemention of an interruptible lock trying to match rw sem semantics. By adding a small bit of code implementing down_write_interruptible to rwsem which already supported down_read_interruptible we can completely remove all of the custom code from vmwgfx.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Martin Krastev <[email protected]>
Cc Roland Scheidegger <[email protected]>

Zack Rusin (2):
locking/rwsem: Add down_write_interruptible
drm/vmwgfx: Remove custom locking code

 drivers/gpu/drm/vmwgfx/Makefile               |   2 +-
 drivers/gpu/drm/vmwgfx/ttm_lock.c             | 194 ----------------
 drivers/gpu/drm/vmwgfx/ttm_lock.h             | 218 ------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c            |  24 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c       |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           |  57 +----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  32 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c       |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c            |  10 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c         |   8 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c           |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |   8 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c        |   4 +-
 .../gpu/drm/vmwgfx/vmwgfx_simple_resource.c   |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c       |  16 +-
 include/linux/rwsem.h                         |   1 +
 kernel/locking/rwsem.c                        |  23 ++
 17 files changed, 98 insertions(+), 515 deletions(-)
 delete mode 100644 drivers/gpu/drm/vmwgfx/ttm_lock.c
 delete mode 100644 drivers/gpu/drm/vmwgfx/ttm_lock.h
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#4 lore raw

PATCH 2/2 drm/vmwgfx: Remove custom locking code

vmwgfx used a custom locking code to support semantics of a interruptible rwsem. Now with down_(read|write)_interruptible implemented in the rwsem we can completely remove the custom locking code. It also allows us to remove the hacks we needed to support proper waits for write resources before hibernation.

Cc Martin Krastev <[email protected]>
Cc Roland Scheidegger <[email protected]>
---
 drivers/gpu/drm/vmwgfx/Makefile               |   2 +-
 drivers/gpu/drm/vmwgfx/ttm_lock.c             | 194 ----------------
 drivers/gpu/drm/vmwgfx/ttm_lock.h             | 218 ------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c            |  24 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c       |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           |  57 +----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  32 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c       |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_fb.c            |  10 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c         |   8 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c           |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |   8 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c        |   4 +-
 .../gpu/drm/vmwgfx/vmwgfx_simple_resource.c   |   4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c       |  16 +-
 15 files changed, 74 insertions(+), 515 deletions(-)
 delete mode 100644 drivers/gpu/drm/vmwgfx/ttm_lock.c
 delete mode 100644 drivers/gpu/drm/vmwgfx/ttm_lock.h
drivers/gpu/drm/vmwgfx/Makefile +1 -1
index cc4cdca7176e..744a806918df 100644
@@ -9,7 +9,7 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \
 	    vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \
 	    vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \
 	    vmwgfx_validation.o vmwgfx_page_dirty.o vmwgfx_streamoutput.o \
-	    ttm_object.o ttm_lock.o
+	    ttm_object.o
 
 vmwgfx-$(CONFIG_TRANSPARENT_HUGEPAGE) += vmwgfx_thp.o
 obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
drivers/gpu/drm/vmwgfx/ttm_lock.c deleted +0 -194

194 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/ttm_lock.h deleted +0 -218

218 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +12 -12
index 63dbc44eebe0..70e4ef01ee7b 100644
@@ -96,7 +96,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 	int ret;
 	uint32_t new_flags;
 
-	ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
+	ret = vmw_reservation_down_write(dev_priv, interruptible);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -118,7 +118,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 	ttm_bo_unreserve(bo);
 
 err:
-	ttm_write_unlock(&dev_priv->reservation_sem);
+	up_write(&dev_priv->reservation_sem);
 	return ret;
 }
 
@@ -145,7 +145,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 	int ret;
 	uint32_t new_flags;
 
-	ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
+	ret = vmw_reservation_down_write(dev_priv, interruptible);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -173,7 +173,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 
 	ttm_bo_unreserve(bo);
 err:
-	ttm_write_unlock(&dev_priv->reservation_sem);
+	up_write(&dev_priv->reservation_sem);
 	return ret;
 }
 
@@ -229,7 +229,7 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 	placement.num_busy_placement = 1;
 	placement.busy_placement = &place;
 
-	ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
+	ret = vmw_reservation_down_write(dev_priv, interruptible);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -264,7 +264,7 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 
 	ttm_bo_unreserve(bo);
 err_unlock:
-	ttm_write_unlock(&dev_priv->reservation_sem);
+	up_write(&dev_priv->reservation_sem);
 
 	return ret;
 }
@@ -288,7 +288,7 @@ int vmw_bo_unpin(struct vmw_private *dev_priv,
 	struct ttm_buffer_object *bo = &buf->base;
 	int ret;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible);
+	ret = vmw_reservation_down_read(dev_priv, interruptible);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -301,7 +301,7 @@ int vmw_bo_unpin(struct vmw_private *dev_priv,
 	ttm_bo_unreserve(bo);
 
 err:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
 
@@ -882,7 +882,7 @@ int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
 	uint32_t handle;
 	int ret;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -900,7 +900,7 @@ int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
 	vmw_bo_unreference(&vbo);
 
 out_no_bo:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 
 	return ret;
 }
@@ -1095,7 +1095,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
 	args->pitch = args->width * ((args->bpp + 7) / 8);
 	args->size = args->pitch * args->height;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -1107,7 +1107,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
 
 	vmw_bo_unreference(&vbo);
 out_no_bo:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
 
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +2 -2
index 6f4d0da11ad8..e8b150bb4e32 100644
@@ -748,7 +748,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
 		  ((dev_priv->has_mob) ? vmw_cmdbuf_res_man_size() : 0) +
 		  + VMW_IDA_ACC_SIZE + TTM_OBJ_EXTRA_SIZE;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -795,7 +795,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
 out_err:
 	vmw_resource_unreference(&res);
 out_unlock:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
 
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +5 -52

134 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +25 -7
index 5fa5bcd20cc5..6bd9ba2d1ba2 100644
@@ -28,6 +28,7 @@
 #ifndef _VMWGFX_DRV_H_
 #define _VMWGFX_DRV_H_
 
+#include <linux/rwsem.h>
 #include <linux/suspend.h>
 #include <linux/sync_file.h>
 
@@ -40,7 +41,6 @@
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_execbuf_util.h>
 
-#include "ttm_lock.h"
 #include "ttm_object.h"
 
 #include "vmwgfx_fence.h"
@@ -588,17 +588,12 @@ struct vmw_private {
 	/**
 	 * PM management.
 	 */
-	struct notifier_block pm_nb;
 	bool refuse_hibernation;
-	bool suspend_locked;
 
 	struct mutex release_mutex;
 	atomic_t num_fifo_resources;
 
-	/*
-	 * Replace this with an rwsem as soon as we have down_xx_interruptible()
-	 */
-	struct ttm_lock reservation_sem;
+	struct rw_semaphore reservation_sem;
 
 	/*
 	 * Query processing. These members
@@ -1577,4 +1572,27 @@ static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
 {
 	WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
 }
+
+static inline int vmw_reservation_down_write(struct vmw_private *vmw,
+					     bool interruptible)
+{
+	if (interruptible) {
+		return down_write_interruptible(&vmw->reservation_sem);
+	} else {
+		down_write(&vmw->reservation_sem);
+		return 0;
+	}
+}
+
+static inline int vmw_reservation_down_read(struct vmw_private *vmw,
+					    bool interruptible)
+{
+	if (interruptible) {
+		return down_read_interruptible(&vmw->reservation_sem);
+	} else {
+		down_read(&vmw->reservation_sem);
+		return 0;
+	}
+}
+
 #endif
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +2 -2
index 462f17320708..960bdf9be12a 100644
@@ -4427,7 +4427,7 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
 			goto out;
 	}
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -4438,7 +4438,7 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
 				  (void __user *)(unsigned long)arg->fence_rep,
 				  NULL, arg->flags);
 
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		goto out;
 
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +5 -5
index 33f07abfc3ae..c5a1905bd479 100644
@@ -195,7 +195,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work)
 	if (!cur_fb)
 		goto out_unlock;
 
-	(void) ttm_read_lock(&vmw_priv->reservation_sem, false);
+	(void) down_read(&vmw_priv->reservation_sem);
 	(void) ttm_bo_reserve(&vbo->base, false, false, NULL);
 	virtual = vmw_bo_map_and_cache(vbo);
 	if (!virtual)
@@ -254,7 +254,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work)
 
 out_unreserve:
 	ttm_bo_unreserve(&vbo->base);
-	ttm_read_unlock(&vmw_priv->reservation_sem);
+	up_read(&vmw_priv->reservation_sem);
 	if (w && h) {
 		WARN_ON_ONCE(par->set_fb->funcs->dirty(cur_fb, NULL, 0, 0,
 						       &clip, 1));
@@ -396,7 +396,7 @@ static int vmw_fb_create_bo(struct vmw_private *vmw_priv,
 	struct vmw_buffer_object *vmw_bo;
 	int ret;
 
-	(void) ttm_write_lock(&vmw_priv->reservation_sem, false);
+	(void) down_write(&vmw_priv->reservation_sem);
 
 	vmw_bo = kmalloc(sizeof(*vmw_bo), GFP_KERNEL);
 	if (!vmw_bo) {
@@ -412,12 +412,12 @@ static int vmw_fb_create_bo(struct vmw_private *vmw_priv,
 		goto err_unlock; /* init frees the buffer on failure */
 
 	*out = vmw_bo;
-	ttm_write_unlock(&vmw_priv->reservation_sem);
+	up_write(&vmw_priv->reservation_sem);
 
 	return 0;
 
 err_unlock:
-	ttm_write_unlock(&vmw_priv->reservation_sem);
+	up_write(&vmw_priv->reservation_sem);
 	return ret;
 }
 
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c +4 -4
index 80af8772b8c2..3b4f9132e03a 100644
@@ -302,7 +302,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
 	}
 	vfb = vmw_framebuffer_to_vfb(fb);
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		goto out_no_ttm_lock;
 
@@ -322,7 +322,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
 	vmw_surface_unreference(&surface);
 
 out_no_surface:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 out_no_ttm_lock:
 	drm_framebuffer_put(fb);
 out_no_fb:
@@ -391,7 +391,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
 		goto out_no_ttm_lock;
 	}
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		goto out_no_ttm_lock;
 
@@ -399,7 +399,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
 			       vfb, user_fence_rep,
 			       clips, num_clips);
 
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 out_no_ttm_lock:
 	drm_framebuffer_put(fb);
 out_no_fb:
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +2 -2
index 9a89f658e501..d197bb2f3d34 100644
@@ -1001,7 +1001,7 @@ static int vmw_framebuffer_bo_dirty(struct drm_framebuffer *framebuffer,
 
 	drm_modeset_lock_all(&dev_priv->drm);
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0)) {
 		drm_modeset_unlock_all(&dev_priv->drm);
 		return ret;
@@ -1030,7 +1030,7 @@ static int vmw_framebuffer_bo_dirty(struct drm_framebuffer *framebuffer,
 	}
 
 	vmw_cmd_flush(dev_priv, false);
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 
 	drm_modeset_unlock_all(&dev_priv->drm);
 
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +4 -4
index d1e7b9608145..104c52bc4d4d 100644
@@ -989,7 +989,7 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible)
 	struct vmw_private *dev_priv = res->dev_priv;
 	int ret;
 
-	ttm_write_lock(&dev_priv->reservation_sem, interruptible);
+	vmw_reservation_down_write(dev_priv, interruptible);
 	mutex_lock(&dev_priv->cmdbuf_mutex);
 	ret = vmw_resource_reserve(res, interruptible, false);
 	if (ret)
@@ -1028,7 +1028,7 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible)
 	vmw_resource_unreserve(res, false, false, false, NULL, 0UL);
 out_no_reserve:
 	mutex_unlock(&dev_priv->cmdbuf_mutex);
-	ttm_write_unlock(&dev_priv->reservation_sem);
+	up_write(&dev_priv->reservation_sem);
 
 	return ret;
 }
@@ -1046,7 +1046,7 @@ void vmw_resource_unpin(struct vmw_resource *res)
 	struct vmw_private *dev_priv = res->dev_priv;
 	int ret;
 
-	(void) ttm_read_lock(&dev_priv->reservation_sem, false);
+	(void) down_read(&dev_priv->reservation_sem);
 	mutex_lock(&dev_priv->cmdbuf_mutex);
 
 	ret = vmw_resource_reserve(res, false, true);
@@ -1064,7 +1064,7 @@ void vmw_resource_unpin(struct vmw_resource *res)
 	vmw_resource_unreserve(res, false, false, false, NULL, 0UL);
 
 	mutex_unlock(&dev_priv->cmdbuf_mutex);
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 }
 
 /**
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +2 -2
index 905ae50aaa2a..618a0b9500e0 100644
@@ -876,7 +876,7 @@ static int vmw_shader_define(struct drm_device *dev, struct drm_file *file_priv,
 		goto out_bad_arg;
 	}
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		goto out_bad_arg;
 
@@ -884,7 +884,7 @@ static int vmw_shader_define(struct drm_device *dev, struct drm_file *file_priv,
 				    shader_type, num_input_sig,
 				    num_output_sig, tfile, shader_handle);
 
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 out_bad_arg:
 	vmw_bo_unreference(&buffer);
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c +2 -2
index 73e9a487e659..b0000bfafe4f 100644
@@ -162,13 +162,13 @@ vmw_simple_resource_create_ioctl(struct drm_device *dev, void *data,
 	account_size = ttm_round_pot(alloc_size) + VMW_IDA_ACC_SIZE +
 		TTM_OBJ_EXTRA_SIZE;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (ret)
 		return ret;
 
 	ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size,
 				   &ctx);
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	if (ret) {
 		if (ret != -ERESTARTSYS)
 			DRM_ERROR("Out of graphics memory for %s"
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +8 -8
index f6cab77075a0..682832ecf1a4 100644
@@ -776,7 +776,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
 		return -EINVAL;
 	}
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -910,7 +910,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
 	rep->sid = user_srf->prime.base.handle;
 	vmw_resource_unreference(&res);
 
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return 0;
 out_no_copy:
 	kfree(srf->offsets);
@@ -921,7 +921,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
 out_no_user_srf:
 	ttm_mem_global_free(vmw_mem_glob(dev_priv), size);
 out_unlock:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
 
@@ -1539,7 +1539,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
 	if (drm_is_primary_client(file_priv))
 		user_srf->master = drm_master_get(file_priv->master);
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -1624,7 +1624,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
 	vmw_resource_unreference(&res);
 
 out_unlock:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
 
@@ -2109,7 +2109,7 @@ int vmw_gb_surface_define(struct vmw_private *dev_priv,
 	if (req->sizes != NULL)
 		return -EINVAL;
 
-	ret = ttm_read_lock(&dev_priv->reservation_sem, true);
+	ret = down_read_interruptible(&dev_priv->reservation_sem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -2176,13 +2176,13 @@ int vmw_gb_surface_define(struct vmw_private *dev_priv,
 	 */
 	ret = vmw_surface_init(dev_priv, srf, vmw_user_surface_free);
 
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 
 out_no_user_srf:
 	ttm_mem_global_free(vmw_mem_glob(dev_priv), user_accounting_size);
 
 out_unlock:
-	ttm_read_unlock(&dev_priv->reservation_sem);
+	up_read(&dev_priv->reservation_sem);
 	return ret;
 }
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] locking/rwsem: Add down_write_interruptible

In reply to Zack Rusin
Quoted 11 lines · Zack Rusin

Add an interruptible version of down_write. It's the other side of the already implemented down_read_interruptible. It allows drivers which used custom locking code to support interruptible rw semaphores to switch over to rwsem.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>

No SoB!

Assuning you actually wrote and and simply forgot to add it, the patch does look ok, so:

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#3 lore raw

Re: [PATCH 1/2] locking/rwsem: Add down_write_interruptible

Quoted 7 lines · Peter Zijlstra
Quoted 6 lines · Zack Rusin

Add an interruptible version of down_write. It's the other side of the already implemented down_read_interruptible. It allows drivers which used custom locking code to support interruptible rw semaphores to switch over to rwsem.

Quoted 7 lines
Quoted 5 lines
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>

No SoB!

Ah, sorry, fixed that locally.

Quoted 4 lines

Assuning you actually wrote and and simply forgot to add it, the patch does look ok, so:

Thank you. I didn't want to bother you with the code in vmwgfx, so I only sent it to the lists (it was missing SoB as well):
https://lore.kernel.org/patchwork/patch/1391810/

z
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel