From patchwork Thu Dec 19 10:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 13915198 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 0CBA2E7718C for ; Thu, 19 Dec 2024 16:07:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C68610E4A4; Thu, 19 Dec 2024 16:07:26 +0000 (UTC) Received: from mx1.emlix.com (mx1.emlix.com [178.63.209.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 308BF10E2BB for ; Thu, 19 Dec 2024 10:26:42 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id B17CC5F8DD; Thu, 19 Dec 2024 11:18:36 +0100 (CET) From: Rolf Eike Beer To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] drm/i915/selftests: check the return value of i915_gem_object_trylock() Date: Thu, 19 Dec 2024 11:16:51 +0100 Message-ID: <9379466.CDJkKcVGEf@devpool47.emlix.com> Organization: emlix GmbH In-Reply-To: <7746997.EvYhyI6sBW@devpool47.emlix.com> References: <7746997.EvYhyI6sBW@devpool47.emlix.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 19 Dec 2024 16:07:24 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" A trylock can fail, in which case operating on the object is unsafe and unconditionally unlocking is wrong. Signed-off-by: Rolf Eike Beer --- drivers/gpu/drm/i915/gt/selftest_migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_migrate.c b/drivers/gpu/drm/i915/gt/selftest_migrate.c index ca460cee4f8b..b2cb501febe8 100644 --- a/drivers/gpu/drm/i915/gt/selftest_migrate.c +++ b/drivers/gpu/drm/i915/gt/selftest_migrate.c @@ -822,7 +822,10 @@ create_init_lmem_internal(struct intel_gt *gt, size_t sz, bool try_lmem) return obj; } - i915_gem_object_trylock(obj, NULL); + if (!i915_gem_object_trylock(obj, NULL)) { + i915_gem_object_put(obj); + return ERR_PTR(-EBUSY); + } err = i915_gem_object_pin_pages(obj); if (err) { i915_gem_object_unlock(obj); From patchwork Thu Dec 19 10:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 13915200 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 0EEB4E77184 for ; Thu, 19 Dec 2024 16:07:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 94CCF10E34D; Thu, 19 Dec 2024 16:07:34 +0000 (UTC) X-Greylist: delayed 477 seconds by postgrey-1.36 at gabe; Thu, 19 Dec 2024 10:26:35 UTC Received: from mx1.emlix.com (mx1.emlix.com [178.63.209.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC5F710E2BB for ; Thu, 19 Dec 2024 10:26:35 +0000 (UTC) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 723E35F880; Thu, 19 Dec 2024 11:18:36 +0100 (CET) From: Rolf Eike Beer To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] drm/i915: mark i915_gem_object_trylock() as __must_check Date: Thu, 19 Dec 2024 11:18:08 +0100 Message-ID: <6005320.MhkbZ0Pkbq@devpool47.emlix.com> Organization: emlix GmbH In-Reply-To: <7746997.EvYhyI6sBW@devpool47.emlix.com> References: <7746997.EvYhyI6sBW@devpool47.emlix.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 19 Dec 2024 16:07:24 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" When you don't look at the return code you can't know if you actually got the lock. Signed-off-by: Rolf Eike Beer --- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h index 3dc61cbd2e11..b6da8b561ae0 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h @@ -198,8 +198,8 @@ static inline int i915_gem_object_lock_interruptible(struct drm_i915_gem_object return __i915_gem_object_lock(obj, ww, true); } -static inline bool i915_gem_object_trylock(struct drm_i915_gem_object *obj, - struct i915_gem_ww_ctx *ww) +static inline bool __must_check i915_gem_object_trylock(struct drm_i915_gem_object *obj, + struct i915_gem_ww_ctx *ww) { if (!ww) return dma_resv_trylock(obj->base.resv);