From patchwork Wed Jul 3 13:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13722223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3DFBC31D97 for ; Wed, 3 Jul 2024 13:26:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 448EF10E013; Wed, 3 Jul 2024 13:26:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L64qxKBN"; dkim-atps=neutral Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2CD1010E013 for ; Wed, 3 Jul 2024 13:26:07 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4256aee6d4fso33059385e9.3 for ; Wed, 03 Jul 2024 06:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013165; x=1720617965; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4CxJJEdicDCb6IZeT3uMULK0SV5Cncp7AGUzQdXGY/s=; b=L64qxKBNZi/eZ7a680wpt2d+AYCgH8zdOv4fONcj7Rv9RqFBrS5sgPbm8syg9TN7vx xs0j5LZjuCBcOUpd41kE3Tsz1xULMVvy81GhclWXpsUU5IGrYdZdzSAlmzz6SsLkuCVk gj42lOQXCJJ3LZRRtT9W1+k62A4r6PViq/9z6YPxzo5Zbljz26xsJa3gL2T8Hsy3VoWX qH5gD729Vuz6/W0MwOEpIQsCari7ujWrfi9/guwe0qbeKgJNoxRqtkz6xrrVj82Bwuj5 2APeEohnA+fbDaZ/devjCmJ5nEMo1nS2TwYy/weXJlzKhBdLCZvIVPP+GKQGuBEglOa2 XlyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013165; x=1720617965; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4CxJJEdicDCb6IZeT3uMULK0SV5Cncp7AGUzQdXGY/s=; b=Q2puwKZEAZjAwsHGbuRkdf97P/f1zKoosRWMkvJXmUtNP17ndGfaYQAy1WVClIeEwc zkUMRpg6DG3JQMIw/aGiyhvejpfBr3KRXkIoKK4PSjbOZgJnERp0ZdyYSfSWzXqFK7LQ i6dlissNO2jFDa2PZth+XdH5jsD+dQSWRe2EEWgtwBgwIlNBJ64Lpb2dVPjuRp7WEc+W ypg4iI7AAwcQxRQm4EdnFXM3OCp9eP36cnib1pWvPNTNrf8ebe94hh6HdiVOJC/lfBAC Qk7rJiuql1dDZq2W2TG9CTrT9qsweG/wZQ9bDz+WeVHtSET3K+MEoHBjyjP39IeWDkbz oGMw== X-Gm-Message-State: AOJu0Yx79F4cb67mK1SpEavMLDoGP0U78PkZLgKw+MBiyTwypSQF7sbG 7y2zt4ZVzbXiGE97RXcUfxycmsQfHMXlvxyZ32QQy2yNTjKu4Ol8y2DEbTwht1s= X-Google-Smtp-Source: AGHT+IH5eOzqvMGazNWjbpb+sHtC59G7AmyiAaSXe+sc4V30YI5sYlUokwJCvSeF5c9FofvOCES+4A== X-Received: by 2002:a05:600c:4e91:b0:426:4186:efae with SMTP id 5b1f17b1804b1-4264186f0c9mr11828905e9.14.1720013165203; Wed, 03 Jul 2024 06:26:05 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:1559:9300:5f5d:6303:9414:d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5ba51sm237197665e9.12.2024.07.03.06.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 06:26:04 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] dma-buf/dma-resv: Introduce dma_resv_trylock_ctx() Date: Wed, 3 Jul 2024 15:25:58 +0200 Message-Id: <20240703132602.4756-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703132602.4756-1-christian.koenig@amd.com> References: <20240703132602.4756-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Thomas Hellström For the drm_exec_trylock() functionality, there is a need to be able to trylock a dma-resv object as part of a drm_exec transaction. Therefore expose a variant of dma_resv_trylock that also takes a struct ww_acquire_ctx parameter. Cc: Christian König Cc: Somalapuram Amaranath Cc: Matthew Brost Cc: Cc: Signed-off-by: Thomas Hellström --- include/linux/dma-resv.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h index 8d0e34dad446..68dae8f2a22c 100644 --- a/include/linux/dma-resv.h +++ b/include/linux/dma-resv.h @@ -405,6 +405,27 @@ static inline int dma_resv_lock_slow_interruptible(struct dma_resv *obj, return ww_mutex_lock_slow_interruptible(&obj->lock, ctx); } +/** + * dma_resv_trylock_ctx - trylock the reservation object + * @obj: the reservation object + * @ctx: The ww acquire context or NULL. + * + * Tries to lock the reservation object for exclusive access and modification. + * Note, that the lock is only against other writers, readers will run + * concurrently with a writer under RCU. The seqlock is used to notify readers + * if they overlap with a writer. The context parameter ensures that other + * ww transactions can perform deadlock backoff if necessary, and that + * subsequent attempts to dma_resv_lock() @obj for @ctx will return + * -EALREADY. + * + * Return: true if the lock was acquired, false otherwise. + */ +static inline bool __must_check +dma_resv_trylock_ctx(struct dma_resv *obj, struct ww_acquire_ctx *ctx) +{ + return ww_mutex_trylock(&obj->lock, ctx); +} + /** * dma_resv_trylock - trylock the reservation object * @obj: the reservation object @@ -421,7 +442,7 @@ static inline int dma_resv_lock_slow_interruptible(struct dma_resv *obj, */ static inline bool __must_check dma_resv_trylock(struct dma_resv *obj) { - return ww_mutex_trylock(&obj->lock, NULL); + return dma_resv_trylock_ctx(obj, NULL); } /** From patchwork Wed Jul 3 13:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13722226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72271C3271E for ; Wed, 3 Jul 2024 13:26:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3B3C10E0EE; Wed, 3 Jul 2024 13:26:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JKhLU1s9"; dkim-atps=neutral Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id E0F1510E013 for ; Wed, 3 Jul 2024 13:26:07 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-36798779d75so86607f8f.3 for ; Wed, 03 Jul 2024 06:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013166; x=1720617966; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zrGWK9ix3Z5llLRfYODIcW20ljsKJIUMR1M7aT6SnbA=; b=JKhLU1s9RESKQfhLfg2FdKONMMkcGgm0NrUCK8fykGFto6VOw9ojdmE49/2mn92Np6 CBisuiB38wD7uHFttJ2qp2A1WhFsbrPTcJRr010+sTIfHWuc2amW+fP5lbkfhbYOmWca 4inQZ3WZaSyOHPmSX2//d/XkDM0b3EYVux49I+FGcAInAY0eXszTZN4vhsDULTTssE+m 8tvnno7mLsIsXMnhhM66OdI7pyyuM0wxw0NAkQ/85paAW2wmygRcoYgcudcP9fL+fPLC CA8U8lhSKM7EDCzmxfBDQAmBdkIPaRssRwuo44UeWAXY6QuY5vILsnEFvYYVqGn9m5MO 439w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013166; x=1720617966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zrGWK9ix3Z5llLRfYODIcW20ljsKJIUMR1M7aT6SnbA=; b=WlhZXeAzyT+X7NlJ726jrga+mxXE1kjnX9ZglTVLu6bC9Gkz540sFPFunFYb/sUnIv xRWOuv/+CTXhSxcFq/c9pq1kq/8IZErBBjIsrBFAmgbeJjj3N+DX2Jrf3g9x+oelUPrM 9efiu/tpscS4B+6/a+C1fheE0Kn5Qvd5DAD852O8QQJYbDqDWhaUDDGcPQWqvu60EVvM V7tF3Q2olWtsbuELyO6QspHgvkc7BTMeIALF1T0Rqlx+++KnG7K8WalnYeMHruTdrefB Il8rhY4Iq2z5dJqyHt6jbJtKj4biFIKNA4Y8Jn1eKOP93IM8HjXYn3eGTS1A7p2wrUhr BMQw== X-Gm-Message-State: AOJu0Ywzo+MA6edz+94c2If8xAiV1vO/lBTFaA4tGZdoyj21WkcnTElr EU/afY472cb9Vd7gzM+CA+DL860Ia24FwJo50cv5T8qmv0JKOjWY X-Google-Smtp-Source: AGHT+IHoLZoUG7som/ugw3WN2aXPUwp9seP/PtSIbWW2tjcUdADh6TDTU0ugYB+eGSTw7K8v13aYtw== X-Received: by 2002:a5d:66c6:0:b0:367:918e:a10a with SMTP id ffacd0b85a97d-367918ea186mr1587574f8f.28.1720013165891; Wed, 03 Jul 2024 06:26:05 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:1559:9300:5f5d:6303:9414:d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5ba51sm237197665e9.12.2024.07.03.06.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 06:26:05 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/exec: don't immediately add the prelocked obj Date: Wed, 3 Jul 2024 15:25:59 +0200 Message-Id: <20240703132602.4756-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703132602.4756-1-christian.koenig@amd.com> References: <20240703132602.4756-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Some contended objects might never be locked again in the case of eviction handling for example. Make sure that those doesn't show up in the list of locked objects until they are explicitely mentioned. Signed-off-by: Christian König --- drivers/gpu/drm/drm_exec.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c index 2da094bdf8a4..220df336fbd9 100644 --- a/drivers/gpu/drm/drm_exec.c +++ b/drivers/gpu/drm/drm_exec.c @@ -61,8 +61,11 @@ static void drm_exec_unlock_all(struct drm_exec *exec) drm_gem_object_put(obj); } - drm_gem_object_put(exec->prelocked); - exec->prelocked = NULL; + if (exec->prelocked) { + dma_resv_unlock(exec->prelocked->resv); + drm_gem_object_put(exec->prelocked); + exec->prelocked = NULL; + } } /** @@ -179,16 +182,9 @@ static int drm_exec_lock_contended(struct drm_exec *exec) dma_resv_lock_slow(obj->resv, &exec->ticket); } - ret = drm_exec_obj_locked(exec, obj); - if (unlikely(ret)) - goto error_unlock; - exec->prelocked = obj; return 0; -error_unlock: - dma_resv_unlock(obj->resv); - error_dropref: drm_gem_object_put(obj); return ret; @@ -214,6 +210,10 @@ int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj) return ret; if (exec->prelocked == obj) { + ret = drm_exec_obj_locked(exec, obj); + if (unlikely(ret)) + return ret; + drm_gem_object_put(exec->prelocked); exec->prelocked = NULL; return 0; From patchwork Wed Jul 3 13:26:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13722224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36FFEC2BD09 for ; Wed, 3 Jul 2024 13:26:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4955410E07B; Wed, 3 Jul 2024 13:26:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SHXq1Wrz"; dkim-atps=neutral Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4950610E07B for ; Wed, 3 Jul 2024 13:26:09 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2ebe785b234so55968731fa.1 for ; Wed, 03 Jul 2024 06:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013167; x=1720617967; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wqDOtib2IWFavjXl6U2wSV2USEnbi4NLN6orparHipU=; b=SHXq1Wrz6yCubVN4Rhj3nkjVFS8d6dXrstA2bGriv467POZOr/SVWDBAyKeog0W94f IhSCTe7LmHVXZWYTIVKW8V5mS21uQ1Rek2Vg3Z8oi8ys7eicxtzkddhvG0SNAJYgovWO yc7s2bEVcR2fSfzJF0Lwe/BvBfmoELqqg4qO8e5fG+8slTf9M9PQkd9S7dLW+vt5cFW4 fQ+Qfhb9/ys+Vsd5q4aEDSi0UMlZmvE5M85st+YIlWcDfowZAoPXNKw6bdFGM/o0pPXC P/lVCjs4MzcIpK8iRLJJ9PG9uwEAkCXW3GaYil5Q68Uium6IGTwsCPJPbLLwT4nBN1HB AgxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013167; x=1720617967; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wqDOtib2IWFavjXl6U2wSV2USEnbi4NLN6orparHipU=; b=UpnOhCswQCNMwOHCVDJGvoR4ZKXeOsYO5RvnNq6wJ84o2RnTN6KzeaQ3O0RgqBMtgu UD4VwDB1jxc8zFifsHM1iFMp9oaSPSHRcp8tx2ei8ly32c69HhKJE5ahpPj4C8yXAGVt dNYIYZtdn3kt1bhoGsDnNyyLHTdXIjrcJvnhN0Ge7ycEqzexjUxq0PtbkT0ocBef9ZRs ZmRUvx6CgFqjWiKQjkHw1Ee+DVFKw6cpy4enXKAUW8OAmcuXgu6CtPPmmxpapoe7eYkh PO+eLouNkKoIRDlCf5nVdXIIoowvZ4A4aZEbrNVbcVsZb/Du3TDOWCy+eZUbEA+HaU42 HEIA== X-Gm-Message-State: AOJu0Yy1RjIcQ14zwVv3/K9jcsPvHPStnlB2kXL3kXBv+bblIK9ALt8B I87rsTDgCGQxUZTbeXVKuVqZY9txBZTrIbNW/zT4qBCDqc9zWX/y X-Google-Smtp-Source: AGHT+IEqD8rKg0B6A9/TCTKvIiizdWpwtfHZSIj/TpFhFFZGHwUOHYYuOvAoRDhUskHH8p+qSfwGqA== X-Received: by 2002:a2e:b53a:0:b0:2ec:6cbe:5e4c with SMTP id 38308e7fff4ca-2ee5e4c38c3mr65664711fa.26.1720013166569; Wed, 03 Jul 2024 06:26:06 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:1559:9300:5f5d:6303:9414:d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5ba51sm237197665e9.12.2024.07.03.06.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 06:26:06 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/exec: provide trylock interface for eviction Date: Wed, 3 Jul 2024 15:26:00 +0200 Message-Id: <20240703132602.4756-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703132602.4756-1-christian.koenig@amd.com> References: <20240703132602.4756-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The TTM eviction path has some additional requirements which make it necessary to trylock an object and then eventually keep or drop the lock again. Signed-off-by: Christian König --- drivers/gpu/drm/drm_exec.c | 77 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_exec.h | 5 +++ 2 files changed, 82 insertions(+) diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c index 220df336fbd9..b81bf5a92d97 100644 --- a/drivers/gpu/drm/drm_exec.c +++ b/drivers/gpu/drm/drm_exec.c @@ -336,5 +336,82 @@ int drm_exec_prepare_array(struct drm_exec *exec, } EXPORT_SYMBOL(drm_exec_prepare_array); +/** + * drm_exec_trylock_obj - try to lock a GEM object + * @exec: the drm_exec object with the state + * @obj: the GEM object to trylock + * + * Try to lock a GEM object but don't grab a reference yet. + * + * Since we can't handle contention here it's illegal to trylock the first + * object. + * + * This function is suposed to be used from atomic context and we don't + * know if the GEM object will actually be used or not. So we don't grab a + * reference yet. + * + * Returns: True if the object could be locked, false otherwise. + */ +bool drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj) +{ + if (WARN_ON(!exec->num_objects)) + return false; + + if (exec->prelocked == obj) + return true; + + return dma_resv_trylock_ctx(obj->resv, &exec->ticket); +} +EXPORT_SYMBOL(drm_exec_trylock_obj); + +/** + * drm_exec_keep_trylocked_obj - keep the trylocked obj + * @exec: the drm_exec object with the state + * @obj: the GEM object to trylock + * + * Keep a trylocked object in the drm_exec state object. Grabs a reference to + * the object and adds it to the container of locked objects. + */ +int drm_exec_keep_trylocked_obj(struct drm_exec *exec, + struct drm_gem_object *obj) +{ + int ret; + + ret = drm_exec_obj_locked(exec, obj); + if (ret) { + dma_resv_unlock(obj->resv); + return ret; + } + + if (exec->prelocked == obj) { + drm_gem_object_put(exec->prelocked); + exec->prelocked = NULL; + } + + return ret; +} +EXPORT_SYMBOL(drm_exec_keep_trylocked_obj); + +/** + * drm_exec_drop_trylocked_obj - drop the trylocked obj + * @exec: the drm_exec object with the state + * @obj: the GEM object to trylock + * + * Used to drop a trylocked object in the drm_exec state object, drop the + * reservation lock again and cleanup all references. + */ +void drm_exec_drop_trylocked_obj(struct drm_exec *exec, + struct drm_gem_object *obj) +{ + /* + * We can't drop the reference of prelocked objects since we might still + * be in atomic context. Additionally it makes sense to keep the + * prelocked object around since we might need it again later on. + */ + if (exec->prelocked != obj) + dma_resv_unlock(obj->resv); +} +EXPORT_SYMBOL(drm_exec_drop_trylocked_obj); + MODULE_DESCRIPTION("DRM execution context"); MODULE_LICENSE("Dual MIT/GPL"); diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index aa786b828a0a..a3943057a3e8 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -146,5 +146,10 @@ int drm_exec_prepare_array(struct drm_exec *exec, struct drm_gem_object **objects, unsigned int num_objects, unsigned int num_fences); +bool drm_exec_trylock_obj(struct drm_exec *exec, struct drm_gem_object *obj); +int drm_exec_keep_trylocked_obj(struct drm_exec *exec, + struct drm_gem_object *obj); +void drm_exec_drop_trylocked_obj(struct drm_exec *exec, + struct drm_gem_object *obj); #endif From patchwork Wed Jul 3 13:26:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13722225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B3AEC30653 for ; Wed, 3 Jul 2024 13:26:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F94A10E108; Wed, 3 Jul 2024 13:26:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MV22/wMZ"; dkim-atps=neutral Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 78D7D10E07B for ; Wed, 3 Jul 2024 13:26:09 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-42641dec7c3so3214345e9.0 for ; Wed, 03 Jul 2024 06:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013168; x=1720617968; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R282shfArTU5DaZQ9AOLlIfcQVpoysK5fJHWsZYbRRU=; b=MV22/wMZPwuTtN8pwCFHqwY0DPdwk7ruFu8YoDGcQXIBDiZSiNNGJgWNs3QUxHleq8 zmDEuvA9BqVo2ommnTW0dm//Vu6fPoBodC8+5UEagk2tmkF1dkpv6kjHdWNxCvLB3/aL SZKQt3Lul/fVgahIJpRIgYmEJjYACAUxtKfOVjhWmPxMcAonOPMAdxpdiYogDtIKnJwN i1Sdg07zhKBiT1I0bhuX2Ba6KcnUg/7tF3f7i/m9mssQYJStG3bDboJwpOpnLbfjl+nY KxS+GdrSS0JBdw+13c0AGA+Uu7Lzj5kDk1Xav0X5fqnoTpU7/aYs462JFha2yupeEp86 GHhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013168; x=1720617968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R282shfArTU5DaZQ9AOLlIfcQVpoysK5fJHWsZYbRRU=; b=h8qGFVrTgh5vbdejrHyxj5W0ii1EJQl1Q3CfwOFVSArP3KQteO6C74FeExN99wtj7T 21RImJvvWORGtdo5I3X6mk9S2pl+lg1orcBy9C+ZG+Gt6UeDcfSxh8REme1/lHUY/6J8 zMYxUoXYW4im7Nce4flV90/HFIzhOviLSKKVQ9OIq8iI95dwu7AMSMmO1dnjrxly2S+S y/lRMVIbs2IizdlZ6/COifW8hHXxVmZdmwIlq2QC5QeMQr0+/2cJHS9n3Rrwakrfx51i R0mHj358Z0VCFMp7EkytdIt+yLuTGDy2MnWluLHCSc+9KVdZBlsK8G3Buhewv532HDZ2 ViNg== X-Gm-Message-State: AOJu0YzNvI1blbpWdezFBtKmkjtf1QJHGvijQaZTZGTnFNwjWDvJaGn6 0EOHKWPGjAI6xjmaBiZzlC2kGf55KUVbEP020JnD0rtbytBlS+O6 X-Google-Smtp-Source: AGHT+IFCoszAIpfTDjnKI1bHhhQ+MMfgHHW+XrPkGkT4nAtKgAewlfn4ZsyJcMltxvOlmCemaQeheA== X-Received: by 2002:a05:600c:1c8a:b0:424:aa64:e9a9 with SMTP id 5b1f17b1804b1-4257a04fe59mr87542935e9.26.1720013167263; Wed, 03 Jul 2024 06:26:07 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:1559:9300:5f5d:6303:9414:d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5ba51sm237197665e9.12.2024.07.03.06.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 06:26:06 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/ttm: support using drm_exec during eviction Date: Wed, 3 Jul 2024 15:26:01 +0200 Message-Id: <20240703132602.4756-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703132602.4756-1-christian.koenig@amd.com> References: <20240703132602.4756-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Allow specifying a drm_exec object in TTMs operation context which is used to lock objects during eviction. This allows to handle deadlocks much more gracefully and with that avoid returning -ENOMEM on heavily contended domains. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 75 +++++++++++++++++++++++++++--------- include/drm/ttm/ttm_bo.h | 3 ++ 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 6396dece0db1..785763405b87 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -31,6 +31,8 @@ #define pr_fmt(fmt) "[TTM] " fmt +#include + #include #include #include @@ -529,13 +531,21 @@ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, return false; } - if (bo->base.resv == ctx->resv) { + if (ctx->exec) { + ret = drm_exec_trylock_obj(ctx->exec, &bo->base); + + *locked = false; + if (!ret && busy) + *busy = true; + + } else if (bo->base.resv == ctx->resv) { dma_resv_assert_held(bo->base.resv); if (ctx->allow_res_evict) ret = true; *locked = false; if (busy) *busy = false; + } else { ret = dma_resv_trylock(bo->base.resv); *locked = ret; @@ -545,11 +555,13 @@ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, if (ret && place && (bo->resource->mem_type != place->mem_type || !bo->bdev->funcs->eviction_valuable(bo, place))) { - ret = false; - if (*locked) { + + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); + else if (*locked) dma_resv_unlock(bo->base.resv); - *locked = false; - } + ret = false; + *locked = false; } return ret; @@ -573,21 +585,32 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo, if (!busy_bo || !ticket) return -EBUSY; - if (ctx->interruptible) + if (ctx->exec) + r = drm_exec_lock_obj(ctx->exec, &busy_bo->base); + + else if (ctx->interruptible) r = dma_resv_lock_interruptible(busy_bo->base.resv, ticket); else r = dma_resv_lock(busy_bo->base.resv, ticket); + if (!ctx->exec && r == -EDEADLK) + r = -EBUSY; + + if (r) + return r; + /* * TODO: It would be better to keep the BO locked until allocation is at * least tried one more time, but that would mean a much larger rework * of TTM. */ - if (!r) + if (ctx->exec) + drm_exec_unlock_obj(ctx->exec, &busy_bo->base); + else dma_resv_unlock(busy_bo->base.resv); - return r == -EDEADLK ? -EBUSY : r; + return 0; } int ttm_mem_evict_first(struct ttm_device *bdev, @@ -618,7 +641,10 @@ int ttm_mem_evict_first(struct ttm_device *bdev, bo = res->bo; break; } - if (locked) + + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); + else if (locked) dma_resv_unlock(res->bo->base.resv); } @@ -635,18 +661,30 @@ int ttm_mem_evict_first(struct ttm_device *bdev, if (bo->deleted) { ret = ttm_bo_cleanup_refs(bo, ctx->interruptible, ctx->no_wait_gpu, locked); + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); + ttm_bo_put(bo); return ret; } spin_unlock(&bdev->lru_lock); + if (ctx->exec) { + ret = drm_exec_keep_trylocked_obj(ctx->exec, &bo->base); + if (ret) + goto error_drop; + } + ret = ttm_bo_evict(bo, ctx); - if (locked) + if (ctx->exec) + drm_exec_unlock_obj(ctx->exec, &bo->base); + else if (locked) ttm_bo_unreserve(bo); else ttm_bo_move_to_lru_tail_unlocked(bo); +error_drop: ttm_bo_put(bo); return ret; } @@ -1139,13 +1177,17 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, bo->ttm->page_flags & TTM_TT_FLAG_EXTERNAL || bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED || !ttm_bo_get_unless_zero(bo)) { - if (locked) + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); + else if (locked) dma_resv_unlock(bo->base.resv); return -EBUSY; } if (bo->deleted) { ret = ttm_bo_cleanup_refs(bo, false, false, locked); + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); ttm_bo_put(bo); return ret == -EBUSY ? -ENOSPC : ret; } @@ -1193,13 +1235,10 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, if (ttm_tt_is_populated(bo->ttm)) ret = ttm_tt_swapout(bo->bdev, bo->ttm, gfp_flags); out: - - /* - * Unreserve without putting on LRU to avoid swapping out an - * already swapped buffer. - */ - if (locked) - dma_resv_unlock(bo->base.resv); + if (ctx->exec) + drm_exec_drop_trylocked_obj(ctx->exec, &bo->base); + else if (locked) + ttm_bo_unreserve(bo); ttm_bo_put(bo); return ret == -EBUSY ? -ENOSPC : ret; } diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index ef0f52f56ebc..b9e598ee13d2 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -180,6 +180,8 @@ struct ttm_bo_kmap_obj { * faults. Should only be used by TTM internally. * @resv: Reservation object to allow reserved evictions with. * @bytes_moved: Statistics on how many bytes have been moved. + * @exec: optional drm_exec object to use for locking BOs and tracking which are + * locked. * * Context for TTM operations like changing buffer placement or general memory * allocation. @@ -192,6 +194,7 @@ struct ttm_operation_ctx { bool force_alloc; struct dma_resv *resv; uint64_t bytes_moved; + struct drm_exec *exec; }; /** From patchwork Wed Jul 3 13:26:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13722227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78D6AC2BD09 for ; Wed, 3 Jul 2024 13:26:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F0B9110E117; Wed, 3 Jul 2024 13:26:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="i3triMcp"; dkim-atps=neutral Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 73C3610E0EE for ; Wed, 3 Jul 2024 13:26:10 +0000 (UTC) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42138eadf64so38397385e9.3 for ; Wed, 03 Jul 2024 06:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720013169; x=1720617969; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=umrby2MQnpwBnZqHdFG3/JwLGYUDmvuInXq96jEbSz4=; b=i3triMcp+/cE7i2FS5CTGN0PFiFbBO2rUqiZij+OpGFthiZjm0y+2R5igGCCoT8Yx/ e0nrut8fkCBuLthbsmK96LHZe/GkTRfBoJ4+Qi3hkFxzsyIcgaqWmKLRLBCHrATpsjlb hQBgHwmQeu0fZ7LCVew8jTpdQeC9qOCOIrzGCBw7MEQVB8kUyOePtRzQDjTCZtXDOB0q WPouZ3UCnpz0qEqzqhxiS65qBfWBomTk4Tes5ZjjcngjndeRzbu8Ph5RzVXq+3HDF3rs vLwGRY2PSd0MuHuEKMZpLrHbH9qiJKhGp3/TB7wH6NhIUg8OzDsvmX+tUg0q4S7GzIUX fM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720013169; x=1720617969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=umrby2MQnpwBnZqHdFG3/JwLGYUDmvuInXq96jEbSz4=; b=l0y+vUA6pLhQmbhBh7HYNwm9u3UNK5HpLCCOqZyhH0HTv48gssda7bx67xGAkwREYa H9rZh5MPA9M5OKokLbQ6bZ2UM2tekrFPM+D+uTZ6ES5Kbq3XUPQBzIJ1uizg6LHO+zjl jlQ8HilTXw/T9TNngYFqzrGRblBnVKmKC6TVSYa58l6PfYruTwwFGET202QAnnxB9NY+ K6qDiwuWA7hdXF2h2rJxiCNi6QRd+PGc+fOkazsmg6TaOwuKCY8Kco+efT32GId3j5Wm ik9WmK7qn9YwuI+W/KZ939UJER0NOuCPgGLteDRA9X9BZYFRvl/+/H3KUL9mU43xZawB Cmtg== X-Gm-Message-State: AOJu0Yy9gssDHlYm2/7jKjwQk/2MSDyX/Tyif3ALvQVLBumXXkxA0PYe 387LP8aHIW4OEsWeBek7i+t1yqYpNiFJylLzme5KPzWfAC0bk+/JCAKvKA/mZ4c= X-Google-Smtp-Source: AGHT+IF+aebT6ghtWznbaMa6abj2AESMVteNbaKi9hoeHwOUM1L0+O9di3rbFJTrl5Z1XIW4oOVbQg== X-Received: by 2002:a05:600c:3541:b0:425:62f7:92ea with SMTP id 5b1f17b1804b1-4257a02f7c9mr76978295e9.14.1720013167981; Wed, 03 Jul 2024 06:26:07 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:1559:9300:5f5d:6303:9414:d3d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5ba51sm237197665e9.12.2024.07.03.06.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 06:26:07 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/amdgpu: use drm_exec during BO validation Date: Wed, 3 Jul 2024 15:26:02 +0200 Message-Id: <20240703132602.4756-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240703132602.4756-1-christian.koenig@amd.com> References: <20240703132602.4756-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This allows to detect deadlocks happening because of resource constraints. Especially submissions which want to use all of GDS doesn't result in sporadic -ENOMEM any more. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 86 ++++++++++++++------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index ec888fc6ead8..ff532c8b7a62 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -782,7 +782,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo) struct ttm_operation_ctx ctx = { .interruptible = true, .no_wait_gpu = false, - .resv = bo->tbo.base.resv + .exec = &p->exec, }; uint32_t domain; int r; @@ -834,7 +834,10 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, union drm_amdgpu_cs *cs) { struct amdgpu_fpriv *fpriv = p->filp->driver_priv; - struct ttm_operation_ctx ctx = { true, false }; + struct ttm_operation_ctx ctx = { + .interruptible =true, + .exec = &p->exec + }; struct amdgpu_vm *vm = &fpriv->vm; struct amdgpu_bo_list_entry *e; struct drm_gem_object *obj; @@ -919,50 +922,56 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, if (unlikely(r)) goto out_free_user_pages; } - } - - amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { - struct mm_struct *usermm; - usermm = amdgpu_ttm_tt_get_usermm(e->bo->tbo.ttm); - if (usermm && usermm != current->mm) { - r = -EPERM; - goto out_free_user_pages; - } + amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { + struct mm_struct *usermm; - if (amdgpu_ttm_tt_is_userptr(e->bo->tbo.ttm) && - e->user_invalidated && e->user_pages) { - amdgpu_bo_placement_from_domain(e->bo, - AMDGPU_GEM_DOMAIN_CPU); - r = ttm_bo_validate(&e->bo->tbo, &e->bo->placement, - &ctx); - if (r) + usermm = amdgpu_ttm_tt_get_usermm(e->bo->tbo.ttm); + if (usermm && usermm != current->mm) { + r = -EPERM; goto out_free_user_pages; + } + + if (amdgpu_ttm_tt_is_userptr(e->bo->tbo.ttm) && + e->user_invalidated && e->user_pages) { + amdgpu_bo_placement_from_domain(e->bo, + AMDGPU_GEM_DOMAIN_CPU); + r = ttm_bo_validate(&e->bo->tbo, &e->bo->placement, + &ctx); + drm_exec_retry_on_contention(&p->exec); + if (r) + goto out_free_user_pages; + + amdgpu_ttm_tt_set_user_pages(e->bo->tbo.ttm, + e->user_pages); + } - amdgpu_ttm_tt_set_user_pages(e->bo->tbo.ttm, - e->user_pages); + kvfree(e->user_pages); + e->user_pages = NULL; } - kvfree(e->user_pages); - e->user_pages = NULL; - } + amdgpu_cs_get_threshold_for_moves(p->adev, &p->bytes_moved_threshold, + &p->bytes_moved_vis_threshold); + p->bytes_moved = 0; + p->bytes_moved_vis = 0; - amdgpu_cs_get_threshold_for_moves(p->adev, &p->bytes_moved_threshold, - &p->bytes_moved_vis_threshold); - p->bytes_moved = 0; - p->bytes_moved_vis = 0; + r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL, + amdgpu_cs_bo_validate, p); + drm_exec_retry_on_contention(&p->exec); + if (r) { + DRM_ERROR("amdgpu_vm_validate() failed.\n"); + goto out_free_user_pages; + } - r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL, - amdgpu_cs_bo_validate, p); - if (r) { - DRM_ERROR("amdgpu_vm_validate() failed.\n"); - goto out_free_user_pages; - } + drm_exec_for_each_locked_object(&p->exec, index, obj) { + r = amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj)); + drm_exec_retry_on_contention(&p->exec); + if (unlikely(r)) + goto out_free_user_pages; + } - drm_exec_for_each_locked_object(&p->exec, index, obj) { - r = amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj)); - if (unlikely(r)) - goto out_free_user_pages; + amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved, + p->bytes_moved_vis); } if (p->uf_bo) { @@ -973,9 +982,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->gang_leader->uf_addr += amdgpu_bo_gpu_offset(p->uf_bo); } - amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved, - p->bytes_moved_vis); - for (i = 0; i < p->gang_size; ++i) amdgpu_job_set_resources(p->jobs[i], p->bo_list->gds_obj, p->bo_list->gws_obj,