Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vmwgfx: Remove the reservation semaphore

Now since Christian reworked TTM to always keep objects on the LRU
list unless they are pinned we shouldn't need the reservation
semaphore. It makes the driver code a lot cleaner, especially
because it was a little hard to reason when and where the
reservation semaphore needed to be held.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210505035740.286923-5-zackr@vmware.com

+6 -535
+1 -1
drivers/gpu/drm/vmwgfx/Makefile
··· 9 9 vmwgfx_cotable.o vmwgfx_so.o vmwgfx_binding.o vmwgfx_msg.o \ 10 10 vmwgfx_simple_resource.o vmwgfx_va.o vmwgfx_blit.o \ 11 11 vmwgfx_validation.o vmwgfx_page_dirty.o vmwgfx_streamoutput.o \ 12 - ttm_object.o ttm_lock.o ttm_memory.o 12 + ttm_object.o ttm_memory.o 13 13 14 14 vmwgfx-$(CONFIG_DRM_FBDEV_EMULATION) += vmwgfx_fb.o 15 15 vmwgfx-$(CONFIG_TRANSPARENT_HUGEPAGE) += vmwgfx_thp.o
-194
drivers/gpu/drm/vmwgfx/ttm_lock.c
··· 1 - /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2 - /************************************************************************** 3 - * 4 - * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA 5 - * All Rights Reserved. 6 - * 7 - * Permission is hereby granted, free of charge, to any person obtaining a 8 - * copy of this software and associated documentation files (the 9 - * "Software"), to deal in the Software without restriction, including 10 - * without limitation the rights to use, copy, modify, merge, publish, 11 - * distribute, sub license, and/or sell copies of the Software, and to 12 - * permit persons to whom the Software is furnished to do so, subject to 13 - * the following conditions: 14 - * 15 - * The above copyright notice and this permission notice (including the 16 - * next paragraph) shall be included in all copies or substantial portions 17 - * of the Software. 18 - * 19 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 22 - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 23 - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 24 - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 25 - * USE OR OTHER DEALINGS IN THE SOFTWARE. 26 - * 27 - **************************************************************************/ 28 - /* 29 - * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 30 - */ 31 - 32 - #include <linux/atomic.h> 33 - #include <linux/errno.h> 34 - #include <linux/wait.h> 35 - #include <linux/sched/signal.h> 36 - #include "ttm_lock.h" 37 - #include "ttm_object.h" 38 - 39 - #define TTM_WRITE_LOCK_PENDING (1 << 0) 40 - #define TTM_VT_LOCK_PENDING (1 << 1) 41 - #define TTM_SUSPEND_LOCK_PENDING (1 << 2) 42 - #define TTM_VT_LOCK (1 << 3) 43 - #define TTM_SUSPEND_LOCK (1 << 4) 44 - 45 - void ttm_lock_init(struct ttm_lock *lock) 46 - { 47 - spin_lock_init(&lock->lock); 48 - init_waitqueue_head(&lock->queue); 49 - lock->rw = 0; 50 - lock->flags = 0; 51 - } 52 - 53 - void ttm_read_unlock(struct ttm_lock *lock) 54 - { 55 - spin_lock(&lock->lock); 56 - if (--lock->rw == 0) 57 - wake_up_all(&lock->queue); 58 - spin_unlock(&lock->lock); 59 - } 60 - 61 - static bool __ttm_read_lock(struct ttm_lock *lock) 62 - { 63 - bool locked = false; 64 - 65 - spin_lock(&lock->lock); 66 - if (lock->rw >= 0 && lock->flags == 0) { 67 - ++lock->rw; 68 - locked = true; 69 - } 70 - spin_unlock(&lock->lock); 71 - return locked; 72 - } 73 - 74 - int ttm_read_lock(struct ttm_lock *lock, bool interruptible) 75 - { 76 - int ret = 0; 77 - 78 - if (interruptible) 79 - ret = wait_event_interruptible(lock->queue, 80 - __ttm_read_lock(lock)); 81 - else 82 - wait_event(lock->queue, __ttm_read_lock(lock)); 83 - return ret; 84 - } 85 - 86 - static bool __ttm_read_trylock(struct ttm_lock *lock, bool *locked) 87 - { 88 - bool block = true; 89 - 90 - *locked = false; 91 - 92 - spin_lock(&lock->lock); 93 - if (lock->rw >= 0 && lock->flags == 0) { 94 - ++lock->rw; 95 - block = false; 96 - *locked = true; 97 - } else if (lock->flags == 0) { 98 - block = false; 99 - } 100 - spin_unlock(&lock->lock); 101 - 102 - return !block; 103 - } 104 - 105 - int ttm_read_trylock(struct ttm_lock *lock, bool interruptible) 106 - { 107 - int ret = 0; 108 - bool locked; 109 - 110 - if (interruptible) 111 - ret = wait_event_interruptible 112 - (lock->queue, __ttm_read_trylock(lock, &locked)); 113 - else 114 - wait_event(lock->queue, __ttm_read_trylock(lock, &locked)); 115 - 116 - if (unlikely(ret != 0)) { 117 - BUG_ON(locked); 118 - return ret; 119 - } 120 - 121 - return (locked) ? 0 : -EBUSY; 122 - } 123 - 124 - void ttm_write_unlock(struct ttm_lock *lock) 125 - { 126 - spin_lock(&lock->lock); 127 - lock->rw = 0; 128 - wake_up_all(&lock->queue); 129 - spin_unlock(&lock->lock); 130 - } 131 - 132 - static bool __ttm_write_lock(struct ttm_lock *lock) 133 - { 134 - bool locked = false; 135 - 136 - spin_lock(&lock->lock); 137 - if (lock->rw == 0 && ((lock->flags & ~TTM_WRITE_LOCK_PENDING) == 0)) { 138 - lock->rw = -1; 139 - lock->flags &= ~TTM_WRITE_LOCK_PENDING; 140 - locked = true; 141 - } else { 142 - lock->flags |= TTM_WRITE_LOCK_PENDING; 143 - } 144 - spin_unlock(&lock->lock); 145 - return locked; 146 - } 147 - 148 - int ttm_write_lock(struct ttm_lock *lock, bool interruptible) 149 - { 150 - int ret = 0; 151 - 152 - if (interruptible) { 153 - ret = wait_event_interruptible(lock->queue, 154 - __ttm_write_lock(lock)); 155 - if (unlikely(ret != 0)) { 156 - spin_lock(&lock->lock); 157 - lock->flags &= ~TTM_WRITE_LOCK_PENDING; 158 - wake_up_all(&lock->queue); 159 - spin_unlock(&lock->lock); 160 - } 161 - } else 162 - wait_event(lock->queue, __ttm_write_lock(lock)); 163 - 164 - return ret; 165 - } 166 - 167 - void ttm_suspend_unlock(struct ttm_lock *lock) 168 - { 169 - spin_lock(&lock->lock); 170 - lock->flags &= ~TTM_SUSPEND_LOCK; 171 - wake_up_all(&lock->queue); 172 - spin_unlock(&lock->lock); 173 - } 174 - 175 - static bool __ttm_suspend_lock(struct ttm_lock *lock) 176 - { 177 - bool locked = false; 178 - 179 - spin_lock(&lock->lock); 180 - if (lock->rw == 0) { 181 - lock->flags &= ~TTM_SUSPEND_LOCK_PENDING; 182 - lock->flags |= TTM_SUSPEND_LOCK; 183 - locked = true; 184 - } else { 185 - lock->flags |= TTM_SUSPEND_LOCK_PENDING; 186 - } 187 - spin_unlock(&lock->lock); 188 - return locked; 189 - } 190 - 191 - void ttm_suspend_lock(struct ttm_lock *lock) 192 - { 193 - wait_event(lock->queue, __ttm_suspend_lock(lock)); 194 - }
-218
drivers/gpu/drm/vmwgfx/ttm_lock.h
··· 1 - /************************************************************************** 2 - * 3 - * Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA 4 - * All Rights Reserved. 5 - * 6 - * Permission is hereby granted, free of charge, to any person obtaining a 7 - * copy of this software and associated documentation files (the 8 - * "Software"), to deal in the Software without restriction, including 9 - * without limitation the rights to use, copy, modify, merge, publish, 10 - * distribute, sub license, and/or sell copies of the Software, and to 11 - * permit persons to whom the Software is furnished to do so, subject to 12 - * the following conditions: 13 - * 14 - * The above copyright notice and this permission notice (including the 15 - * next paragraph) shall be included in all copies or substantial portions 16 - * of the Software. 17 - * 18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 - * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 - * 26 - **************************************************************************/ 27 - /* 28 - * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 - */ 30 - 31 - /** @file ttm_lock.h 32 - * This file implements a simple replacement for the buffer manager use 33 - * of the DRM heavyweight hardware lock. 34 - * The lock is a read-write lock. Taking it in read mode and write mode 35 - * is relatively fast, and intended for in-kernel use only. 36 - * 37 - * The vt mode is used only when there is a need to block all 38 - * user-space processes from validating buffers. 39 - * It's allowed to leave kernel space with the vt lock held. 40 - * If a user-space process dies while having the vt-lock, 41 - * it will be released during the file descriptor release. The vt lock 42 - * excludes write lock and read lock. 43 - * 44 - * The suspend mode is used to lock out all TTM users when preparing for 45 - * and executing suspend operations. 46 - * 47 - */ 48 - 49 - #ifndef _TTM_LOCK_H_ 50 - #define _TTM_LOCK_H_ 51 - 52 - #include <linux/atomic.h> 53 - #include <linux/wait.h> 54 - 55 - #include "ttm_object.h" 56 - 57 - /** 58 - * struct ttm_lock 59 - * 60 - * @base: ttm base object used solely to release the lock if the client 61 - * holding the lock dies. 62 - * @queue: Queue for processes waiting for lock change-of-status. 63 - * @lock: Spinlock protecting some lock members. 64 - * @rw: Read-write lock counter. Protected by @lock. 65 - * @flags: Lock state. Protected by @lock. 66 - */ 67 - 68 - struct ttm_lock { 69 - struct ttm_base_object base; 70 - wait_queue_head_t queue; 71 - spinlock_t lock; 72 - int32_t rw; 73 - uint32_t flags; 74 - }; 75 - 76 - 77 - /** 78 - * ttm_lock_init 79 - * 80 - * @lock: Pointer to a struct ttm_lock 81 - * Initializes the lock. 82 - */ 83 - extern void ttm_lock_init(struct ttm_lock *lock); 84 - 85 - /** 86 - * ttm_read_unlock 87 - * 88 - * @lock: Pointer to a struct ttm_lock 89 - * 90 - * Releases a read lock. 91 - */ 92 - extern void ttm_read_unlock(struct ttm_lock *lock); 93 - 94 - /** 95 - * ttm_read_lock 96 - * 97 - * @lock: Pointer to a struct ttm_lock 98 - * @interruptible: Interruptible sleeping while waiting for a lock. 99 - * 100 - * Takes the lock in read mode. 101 - * Returns: 102 - * -ERESTARTSYS If interrupted by a signal and interruptible is true. 103 - */ 104 - extern int ttm_read_lock(struct ttm_lock *lock, bool interruptible); 105 - 106 - /** 107 - * ttm_read_trylock 108 - * 109 - * @lock: Pointer to a struct ttm_lock 110 - * @interruptible: Interruptible sleeping while waiting for a lock. 111 - * 112 - * Tries to take the lock in read mode. If the lock is already held 113 - * in write mode, the function will return -EBUSY. If the lock is held 114 - * in vt or suspend mode, the function will sleep until these modes 115 - * are unlocked. 116 - * 117 - * Returns: 118 - * -EBUSY The lock was already held in write mode. 119 - * -ERESTARTSYS If interrupted by a signal and interruptible is true. 120 - */ 121 - extern int ttm_read_trylock(struct ttm_lock *lock, bool interruptible); 122 - 123 - /** 124 - * ttm_write_unlock 125 - * 126 - * @lock: Pointer to a struct ttm_lock 127 - * 128 - * Releases a write lock. 129 - */ 130 - extern void ttm_write_unlock(struct ttm_lock *lock); 131 - 132 - /** 133 - * ttm_write_lock 134 - * 135 - * @lock: Pointer to a struct ttm_lock 136 - * @interruptible: Interruptible sleeping while waiting for a lock. 137 - * 138 - * Takes the lock in write mode. 139 - * Returns: 140 - * -ERESTARTSYS If interrupted by a signal and interruptible is true. 141 - */ 142 - extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible); 143 - 144 - /** 145 - * ttm_lock_downgrade 146 - * 147 - * @lock: Pointer to a struct ttm_lock 148 - * 149 - * Downgrades a write lock to a read lock. 150 - */ 151 - extern void ttm_lock_downgrade(struct ttm_lock *lock); 152 - 153 - /** 154 - * ttm_suspend_lock 155 - * 156 - * @lock: Pointer to a struct ttm_lock 157 - * 158 - * Takes the lock in suspend mode. Excludes read and write mode. 159 - */ 160 - extern void ttm_suspend_lock(struct ttm_lock *lock); 161 - 162 - /** 163 - * ttm_suspend_unlock 164 - * 165 - * @lock: Pointer to a struct ttm_lock 166 - * 167 - * Releases a suspend lock 168 - */ 169 - extern void ttm_suspend_unlock(struct ttm_lock *lock); 170 - 171 - /** 172 - * ttm_vt_lock 173 - * 174 - * @lock: Pointer to a struct ttm_lock 175 - * @interruptible: Interruptible sleeping while waiting for a lock. 176 - * @tfile: Pointer to a struct ttm_object_file to register the lock with. 177 - * 178 - * Takes the lock in vt mode. 179 - * Returns: 180 - * -ERESTARTSYS If interrupted by a signal and interruptible is true. 181 - * -ENOMEM: Out of memory when locking. 182 - */ 183 - extern int ttm_vt_lock(struct ttm_lock *lock, bool interruptible, 184 - struct ttm_object_file *tfile); 185 - 186 - /** 187 - * ttm_vt_unlock 188 - * 189 - * @lock: Pointer to a struct ttm_lock 190 - * 191 - * Releases a vt lock. 192 - * Returns: 193 - * -EINVAL If the lock was not held. 194 - */ 195 - extern int ttm_vt_unlock(struct ttm_lock *lock); 196 - 197 - /** 198 - * ttm_write_unlock 199 - * 200 - * @lock: Pointer to a struct ttm_lock 201 - * 202 - * Releases a write lock. 203 - */ 204 - extern void ttm_write_unlock(struct ttm_lock *lock); 205 - 206 - /** 207 - * ttm_write_lock 208 - * 209 - * @lock: Pointer to a struct ttm_lock 210 - * @interruptible: Interruptible sleeping while waiting for a lock. 211 - * 212 - * Takes the lock in write mode. 213 - * Returns: 214 - * -ERESTARTSYS If interrupted by a signal and interruptible is true. 215 - */ 216 - extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible); 217 - 218 - #endif
-31
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
··· 96 96 int ret; 97 97 uint32_t new_flags; 98 98 99 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 100 - if (unlikely(ret != 0)) 101 - return ret; 102 - 103 99 vmw_execbuf_release_pinned_bo(dev_priv); 104 100 105 101 ret = ttm_bo_reserve(bo, interruptible, false, NULL); ··· 112 116 vmw_bo_pin_reserved(buf, true); 113 117 114 118 ttm_bo_unreserve(bo); 115 - 116 119 err: 117 - ttm_write_unlock(&dev_priv->reservation_sem); 118 120 return ret; 119 121 } 120 122 ··· 138 144 int ret; 139 145 uint32_t new_flags; 140 146 141 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 142 - if (unlikely(ret != 0)) 143 - return ret; 144 - 145 147 vmw_execbuf_release_pinned_bo(dev_priv); 146 148 147 149 ret = ttm_bo_reserve(bo, interruptible, false, NULL); ··· 162 172 163 173 ttm_bo_unreserve(bo); 164 174 err: 165 - ttm_write_unlock(&dev_priv->reservation_sem); 166 175 return ret; 167 176 } 168 177 ··· 217 228 placement.num_busy_placement = 1; 218 229 placement.busy_placement = &place; 219 230 220 - ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); 221 - if (unlikely(ret != 0)) 222 - return ret; 223 - 224 231 vmw_execbuf_release_pinned_bo(dev_priv); 225 232 ret = ttm_bo_reserve(bo, interruptible, false, NULL); 226 233 if (unlikely(ret != 0)) ··· 248 263 249 264 ttm_bo_unreserve(bo); 250 265 err_unlock: 251 - ttm_write_unlock(&dev_priv->reservation_sem); 252 266 253 267 return ret; 254 268 } ··· 271 287 struct ttm_buffer_object *bo = &buf->base; 272 288 int ret; 273 289 274 - ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible); 275 - if (unlikely(ret != 0)) 276 - return ret; 277 - 278 290 ret = ttm_bo_reserve(bo, interruptible, false, NULL); 279 291 if (unlikely(ret != 0)) 280 292 goto err; ··· 280 300 ttm_bo_unreserve(bo); 281 301 282 302 err: 283 - ttm_read_unlock(&dev_priv->reservation_sem); 284 303 return ret; 285 304 } 286 305 ··· 885 906 uint32_t handle; 886 907 int ret; 887 908 888 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 889 - if (unlikely(ret != 0)) 890 - return ret; 891 - 892 909 ret = vmw_user_bo_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 893 910 req->size, false, &handle, &vbo, 894 911 NULL); ··· 899 924 vmw_bo_unreference(&vbo); 900 925 901 926 out_no_bo: 902 - ttm_read_unlock(&dev_priv->reservation_sem); 903 927 904 928 return ret; 905 929 } ··· 1093 1119 args->pitch = args->width * ((args->bpp + 7) / 8); 1094 1120 args->size = args->pitch * args->height; 1095 1121 1096 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 1097 - if (unlikely(ret != 0)) 1098 - return ret; 1099 - 1100 1122 ret = vmw_user_bo_alloc(dev_priv, vmw_fpriv(file_priv)->tfile, 1101 1123 args->size, false, &args->handle, 1102 1124 &vbo, NULL); ··· 1101 1131 1102 1132 vmw_bo_unreference(&vbo); 1103 1133 out_no_bo: 1104 - ttm_read_unlock(&dev_priv->reservation_sem); 1105 1134 return ret; 1106 1135 } 1107 1136
+4 -9
drivers/gpu/drm/vmwgfx/vmwgfx_context.c
··· 748 748 ((dev_priv->has_mob) ? vmw_cmdbuf_res_man_size() : 0) + 749 749 + VMW_IDA_ACC_SIZE + TTM_OBJ_EXTRA_SIZE; 750 750 751 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 752 - if (unlikely(ret != 0)) 753 - return ret; 754 - 755 751 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), 756 752 vmw_user_context_size, 757 753 &ttm_opt_ctx); ··· 755 759 if (ret != -ERESTARTSYS) 756 760 DRM_ERROR("Out of graphics memory for context" 757 761 " creation.\n"); 758 - goto out_unlock; 762 + goto out_ret; 759 763 } 760 764 761 765 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); ··· 763 767 ttm_mem_global_free(vmw_mem_glob(dev_priv), 764 768 vmw_user_context_size); 765 769 ret = -ENOMEM; 766 - goto out_unlock; 770 + goto out_ret; 767 771 } 768 772 769 773 res = &ctx->res; ··· 776 780 777 781 ret = vmw_context_init(dev_priv, res, vmw_user_context_free, dx); 778 782 if (unlikely(ret != 0)) 779 - goto out_unlock; 783 + goto out_ret; 780 784 781 785 tmp = vmw_resource_reference(&ctx->res); 782 786 ret = ttm_base_object_init(tfile, &ctx->base, false, VMW_RES_CONTEXT, ··· 790 794 arg->cid = ctx->base.handle; 791 795 out_err: 792 796 vmw_resource_unreference(&res); 793 - out_unlock: 794 - ttm_read_unlock(&dev_priv->reservation_sem); 797 + out_ret: 795 798 return ret; 796 799 } 797 800
+1 -13
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 708 708 709 709 mutex_init(&dev_priv->cmdbuf_mutex); 710 710 mutex_init(&dev_priv->binding_mutex); 711 - ttm_lock_init(&dev_priv->reservation_sem); 712 711 spin_lock_init(&dev_priv->resource_lock); 713 712 spin_lock_init(&dev_priv->hw_lock); 714 713 spin_lock_init(&dev_priv->waiter_lock); ··· 965 966 DRM_INFO("SM4_1 support available.\n"); 966 967 if (dev_priv->sm_type == VMW_SM_4) 967 968 DRM_INFO("SM4 support available.\n"); 969 + DRM_INFO("Running without reservation semaphore\n"); 968 970 969 971 snprintf(host_log, sizeof(host_log), "vmwgfx: Module Version: %d.%d.%d", 970 972 VMWGFX_DRIVER_MAJOR, VMWGFX_DRIVER_MINOR, ··· 1191 1191 */ 1192 1192 void vmw_svga_enable(struct vmw_private *dev_priv) 1193 1193 { 1194 - (void) ttm_read_lock(&dev_priv->reservation_sem, false); 1195 1194 __vmw_svga_enable(dev_priv); 1196 - ttm_read_unlock(&dev_priv->reservation_sem); 1197 1195 } 1198 1196 1199 1197 /** ··· 1236 1238 * 1237 1239 */ 1238 1240 vmw_kms_lost_device(&dev_priv->drm); 1239 - ttm_write_lock(&dev_priv->reservation_sem, false); 1240 1241 if (ttm_resource_manager_used(man)) { 1241 1242 if (ttm_resource_manager_evict_all(&dev_priv->bdev, man)) 1242 1243 DRM_ERROR("Failed evicting VRAM buffers.\n"); ··· 1244 1247 SVGA_REG_ENABLE_HIDE | 1245 1248 SVGA_REG_ENABLE_ENABLE); 1246 1249 } 1247 - ttm_write_unlock(&dev_priv->reservation_sem); 1248 1250 } 1249 1251 1250 1252 static void vmw_remove(struct pci_dev *pdev) ··· 1283 1287 * Once user-space processes have been frozen, we can release 1284 1288 * the lock again. 1285 1289 */ 1286 - ttm_suspend_lock(&dev_priv->reservation_sem); 1287 1290 dev_priv->suspend_locked = true; 1288 1291 break; 1289 1292 case PM_POST_HIBERNATION: 1290 1293 case PM_POST_RESTORE: 1291 1294 if (READ_ONCE(dev_priv->suspend_locked)) { 1292 1295 dev_priv->suspend_locked = false; 1293 - ttm_suspend_unlock(&dev_priv->reservation_sem); 1294 1296 } 1295 1297 break; 1296 1298 default: ··· 1347 1353 int ret; 1348 1354 1349 1355 /* 1350 - * Unlock for vmw_kms_suspend. 1351 1356 * No user-space processes should be running now. 1352 1357 */ 1353 - ttm_suspend_unlock(&dev_priv->reservation_sem); 1354 1358 ret = vmw_kms_suspend(&dev_priv->drm); 1355 1359 if (ret) { 1356 - ttm_suspend_lock(&dev_priv->reservation_sem); 1357 1360 DRM_ERROR("Failed to freeze modesetting.\n"); 1358 1361 return ret; 1359 1362 } 1360 1363 if (dev_priv->enable_fb) 1361 1364 vmw_fb_off(dev_priv); 1362 1365 1363 - ttm_suspend_lock(&dev_priv->reservation_sem); 1364 1366 vmw_execbuf_release_pinned_bo(dev_priv); 1365 1367 vmw_resource_evict_all(dev_priv); 1366 1368 vmw_release_device_early(dev_priv); ··· 1369 1379 vmw_fifo_resource_inc(dev_priv); 1370 1380 WARN_ON(vmw_request_device_late(dev_priv)); 1371 1381 dev_priv->suspend_locked = false; 1372 - ttm_suspend_unlock(&dev_priv->reservation_sem); 1373 1382 if (dev_priv->suspend_state) 1374 1383 vmw_kms_resume(dev); 1375 1384 if (dev_priv->enable_fb) ··· 1405 1416 1406 1417 vmw_fence_fifo_up(dev_priv->fman); 1407 1418 dev_priv->suspend_locked = false; 1408 - ttm_suspend_unlock(&dev_priv->reservation_sem); 1409 1419 if (dev_priv->suspend_state) 1410 1420 vmw_kms_resume(&dev_priv->drm); 1411 1421
-6
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 40 40 #include <drm/ttm/ttm_bo_driver.h> 41 41 #include <drm/ttm/ttm_execbuf_util.h> 42 42 43 - #include "ttm_lock.h" 44 43 #include "ttm_object.h" 45 44 46 45 #include "vmwgfx_fence.h" ··· 591 592 bool suspend_locked; 592 593 593 594 atomic_t num_fifo_resources; 594 - 595 - /* 596 - * Replace this with an rwsem as soon as we have down_xx_interruptible() 597 - */ 598 - struct ttm_lock reservation_sem; 599 595 600 596 /* 601 597 * Query processing. These members
-5
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
··· 4443 4443 goto out; 4444 4444 } 4445 4445 4446 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 4447 - if (unlikely(ret != 0)) 4448 - return ret; 4449 - 4450 4446 ret = vmw_execbuf_process(file_priv, dev_priv, 4451 4447 (void __user *)(unsigned long)arg->commands, 4452 4448 NULL, arg->command_size, arg->throttle_us, ··· 4450 4454 (void __user *)(unsigned long)arg->fence_rep, 4451 4455 NULL, arg->flags); 4452 4456 4453 - ttm_read_unlock(&dev_priv->reservation_sem); 4454 4457 if (unlikely(ret != 0)) 4455 4458 goto out; 4456 4459
-8
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
··· 195 195 if (!cur_fb) 196 196 goto out_unlock; 197 197 198 - (void) ttm_read_lock(&vmw_priv->reservation_sem, false); 199 198 (void) ttm_bo_reserve(&vbo->base, false, false, NULL); 200 199 virtual = vmw_bo_map_and_cache(vbo); 201 200 if (!virtual) ··· 253 254 254 255 out_unreserve: 255 256 ttm_bo_unreserve(&vbo->base); 256 - ttm_read_unlock(&vmw_priv->reservation_sem); 257 257 if (w && h) { 258 258 WARN_ON_ONCE(par->set_fb->funcs->dirty(cur_fb, NULL, 0, 0, 259 259 &clip, 1)); ··· 394 396 struct vmw_buffer_object *vmw_bo; 395 397 int ret; 396 398 397 - (void) ttm_write_lock(&vmw_priv->reservation_sem, false); 398 - 399 399 vmw_bo = kmalloc(sizeof(*vmw_bo), GFP_KERNEL); 400 400 if (!vmw_bo) { 401 401 ret = -ENOMEM; ··· 408 412 goto err_unlock; /* init frees the buffer on failure */ 409 413 410 414 *out = vmw_bo; 411 - ttm_write_unlock(&vmw_priv->reservation_sem); 412 - 413 - return 0; 414 415 415 416 err_unlock: 416 - ttm_write_unlock(&vmw_priv->reservation_sem); 417 417 return ret; 418 418 } 419 419
-11
drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
··· 302 302 } 303 303 vfb = vmw_framebuffer_to_vfb(fb); 304 304 305 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 306 - if (unlikely(ret != 0)) 307 - goto out_no_ttm_lock; 308 - 309 305 ret = vmw_user_resource_lookup_handle(dev_priv, tfile, arg->sid, 310 306 user_surface_converter, 311 307 &res); ··· 318 322 vmw_surface_unreference(&surface); 319 323 320 324 out_no_surface: 321 - ttm_read_unlock(&dev_priv->reservation_sem); 322 - out_no_ttm_lock: 323 325 drm_framebuffer_put(fb); 324 326 out_no_fb: 325 327 drm_modeset_unlock_all(dev); ··· 385 391 goto out_no_ttm_lock; 386 392 } 387 393 388 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 389 - if (unlikely(ret != 0)) 390 - goto out_no_ttm_lock; 391 - 392 394 ret = vmw_kms_readback(dev_priv, file_priv, 393 395 vfb, user_fence_rep, 394 396 clips, num_clips); 395 397 396 - ttm_read_unlock(&dev_priv->reservation_sem); 397 398 out_no_ttm_lock: 398 399 drm_framebuffer_put(fb); 399 400 out_no_fb:
-7
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
··· 1008 1008 1009 1009 drm_modeset_lock_all(&dev_priv->drm); 1010 1010 1011 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 1012 - if (unlikely(ret != 0)) { 1013 - drm_modeset_unlock_all(&dev_priv->drm); 1014 - return ret; 1015 - } 1016 - 1017 1011 if (!num_clips) { 1018 1012 num_clips = 1; 1019 1013 clips = &norect; ··· 1031 1037 } 1032 1038 1033 1039 vmw_cmd_flush(dev_priv, false); 1034 - ttm_read_unlock(&dev_priv->reservation_sem); 1035 1040 1036 1041 drm_modeset_unlock_all(&dev_priv->drm); 1037 1042
-4
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
··· 990 990 struct vmw_private *dev_priv = res->dev_priv; 991 991 int ret; 992 992 993 - ttm_write_lock(&dev_priv->reservation_sem, interruptible); 994 993 mutex_lock(&dev_priv->cmdbuf_mutex); 995 994 ret = vmw_resource_reserve(res, interruptible, false); 996 995 if (ret) ··· 1028 1029 vmw_resource_unreserve(res, false, false, false, NULL, 0UL); 1029 1030 out_no_reserve: 1030 1031 mutex_unlock(&dev_priv->cmdbuf_mutex); 1031 - ttm_write_unlock(&dev_priv->reservation_sem); 1032 1032 1033 1033 return ret; 1034 1034 } ··· 1045 1047 struct vmw_private *dev_priv = res->dev_priv; 1046 1048 int ret; 1047 1049 1048 - (void) ttm_read_lock(&dev_priv->reservation_sem, false); 1049 1050 mutex_lock(&dev_priv->cmdbuf_mutex); 1050 1051 1051 1052 ret = vmw_resource_reserve(res, false, true); ··· 1062 1065 vmw_resource_unreserve(res, false, false, false, NULL, 0UL); 1063 1066 1064 1067 mutex_unlock(&dev_priv->cmdbuf_mutex); 1065 - ttm_read_unlock(&dev_priv->reservation_sem); 1066 1068 } 1067 1069 1068 1070 /**
-6
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
··· 876 876 goto out_bad_arg; 877 877 } 878 878 879 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 880 - if (unlikely(ret != 0)) 881 - goto out_bad_arg; 882 - 883 879 ret = vmw_user_shader_alloc(dev_priv, buffer, size, offset, 884 880 shader_type, num_input_sig, 885 881 num_output_sig, tfile, shader_handle); 886 - 887 - ttm_read_unlock(&dev_priv->reservation_sem); 888 882 out_bad_arg: 889 883 vmw_bo_unreference(&buffer); 890 884 return ret;
-5
drivers/gpu/drm/vmwgfx/vmwgfx_simple_resource.c
··· 162 162 account_size = ttm_round_pot(alloc_size) + VMW_IDA_ACC_SIZE + 163 163 TTM_OBJ_EXTRA_SIZE; 164 164 165 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 166 - if (ret) 167 - return ret; 168 - 169 165 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), account_size, 170 166 &ctx); 171 - ttm_read_unlock(&dev_priv->reservation_sem); 172 167 if (ret) { 173 168 if (ret != -ERESTARTSYS) 174 169 DRM_ERROR("Out of graphics memory for %s"
-17
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
··· 779 779 return -EINVAL; 780 780 } 781 781 782 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 783 - if (unlikely(ret != 0)) 784 - return ret; 785 - 786 782 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), 787 783 size, &ctx); 788 784 if (unlikely(ret != 0)) { ··· 909 913 rep->sid = user_srf->prime.base.handle; 910 914 vmw_resource_unreference(&res); 911 915 912 - ttm_read_unlock(&dev_priv->reservation_sem); 913 916 return 0; 914 917 out_no_copy: 915 918 kfree(srf->offsets); ··· 919 924 out_no_user_srf: 920 925 ttm_mem_global_free(vmw_mem_glob(dev_priv), size); 921 926 out_unlock: 922 - ttm_read_unlock(&dev_priv->reservation_sem); 923 927 return ret; 924 928 } 925 929 ··· 1536 1542 if (drm_is_primary_client(file_priv)) 1537 1543 user_srf->master = drm_master_get(file_priv->master); 1538 1544 1539 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 1540 - if (unlikely(ret != 0)) 1541 - return ret; 1542 - 1543 1545 res = &user_srf->srf.res; 1544 1546 1545 1547 if (req->base.buffer_handle != SVGA3D_INVALID_ID) { ··· 1617 1627 vmw_resource_unreference(&res); 1618 1628 1619 1629 out_unlock: 1620 - ttm_read_unlock(&dev_priv->reservation_sem); 1621 1630 return ret; 1622 1631 } 1623 1632 ··· 2114 2125 if (req->sizes != NULL) 2115 2126 return -EINVAL; 2116 2127 2117 - ret = ttm_read_lock(&dev_priv->reservation_sem, true); 2118 - if (unlikely(ret != 0)) 2119 - return ret; 2120 - 2121 2128 ret = ttm_mem_global_alloc(vmw_mem_glob(dev_priv), 2122 2129 user_accounting_size, &ctx); 2123 2130 if (ret != 0) { ··· 2177 2192 */ 2178 2193 ret = vmw_surface_init(dev_priv, srf, vmw_user_surface_free); 2179 2194 2180 - ttm_read_unlock(&dev_priv->reservation_sem); 2181 2195 return ret; 2182 2196 2183 2197 out_no_user_srf: 2184 2198 ttm_mem_global_free(vmw_mem_glob(dev_priv), user_accounting_size); 2185 2199 2186 2200 out_unlock: 2187 - ttm_read_unlock(&dev_priv->reservation_sem); 2188 2201 return ret; 2189 2202 }