lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 14 Jun 2019 14:41:25 +0200
From:   "Christian König" 
        <ckoenig.leichtzumerken@...il.com>
To:     daniel@...ll.ch, l.stach@...gutronix.de,
        linux+etnaviv@...linux.org.uk, christian.gmeiner@...il.com,
        yuq825@...il.com, eric@...olt.net, peterz@...radead.org,
        thellstrom@...are.com, dri-devel@...ts.freedesktop.org,
        linux-kernel@...r.kernel.org, etnaviv@...ts.freedesktop.org,
        lima@...ts.freedesktop.org
Subject: [PATCH 6/6] drm/vc4: use new ww_mutex_(un)lock_for_each macros

Use the provided macros instead of implementing deadlock handling on our own.

Signed-off-by: Christian König <christian.koenig@....com>
---
 drivers/gpu/drm/vc4/vc4_gem.c | 56 ++++++++---------------------------
 1 file changed, 13 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
index d9311be32a4f..628b3a8bcf6a 100644
--- a/drivers/gpu/drm/vc4/vc4_gem.c
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
@@ -584,53 +584,17 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 			 struct vc4_exec_info *exec,
 			 struct ww_acquire_ctx *acquire_ctx)
 {
-	int contended_lock = -1;
-	int i, ret;
+	struct ww_mutex *contended;
 	struct drm_gem_object *bo;
+	int i, ret;
 
 	ww_acquire_init(acquire_ctx, &reservation_ww_class);
 
-retry:
-	if (contended_lock != -1) {
-		bo = &exec->bo[contended_lock]->base;
-		ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
-						       acquire_ctx);
-		if (ret) {
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
-
-	for (i = 0; i < exec->bo_count; i++) {
-		if (i == contended_lock)
-			continue;
-
-		bo = &exec->bo[i]->base;
-
-		ret = ww_mutex_lock_interruptible(&bo->resv->lock, acquire_ctx);
-		if (ret) {
-			int j;
-
-			for (j = 0; j < i; j++) {
-				bo = &exec->bo[j]->base;
-				ww_mutex_unlock(&bo->resv->lock);
-			}
-
-			if (contended_lock != -1 && contended_lock >= i) {
-				bo = &exec->bo[contended_lock]->base;
-
-				ww_mutex_unlock(&bo->resv->lock);
-			}
-
-			if (ret == -EDEADLK) {
-				contended_lock = i;
-				goto retry;
-			}
-
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
+	ww_mutex_lock_for_each(for (i = 0; i < exec->bo_count; i++),
+			       &exec->bo[i]->base.resv->lock, contended, ret,
+			       true, acquire_ctx)
+		if (ret)
+			goto error;
 
 	ww_acquire_done(acquire_ctx);
 
@@ -648,6 +612,12 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 	}
 
 	return 0;
+
+error:
+	ww_mutex_unlock_for_each(for (i = 0; i < exec->bo_count; i++),
+				 &exec->bo[i]->base.resv->lock, contended);
+	ww_acquire_done(acquire_ctx);
+	return ret;
 }
 
 /* Queues a struct vc4_exec_info for execution.  If no job is
-- 
2.17.1

Powered by blists - more mailing lists