From mboxrd@z Thu Jan 1 00:00:00 1970 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 26922C25B7A for ; Thu, 16 May 2024 06:44:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BACB010E604; Thu, 16 May 2024 06:44:50 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="TJ9kpUS0"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B7D610E638 for ; Thu, 16 May 2024 06:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715841872; x=1747377872; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=kIbCgfsnJqyWE46yS4a6QVTc2cK35spNOUGCUPBYEAM=; b=TJ9kpUS0cra+JSkVeu5sdBMue0r1ZVdVHzzzf423tc7j/M/ebLaEarbg ulD/myanyzQuJlldN2bKiRC/OpnPOWSBnKKOf1uPzEnBHLOunWuZJCldI hgZrpx2MhaCqEgk/8TyXpWFhGRaT3L6QkvwHfvjypB5Nd/pex3Cnr5ncy B63d5koAxTHmCjTuSJurrflBCOLs6Z/Fjl/qenibus6qtps+ISk+tCHUz bLtSTXf43s9NAdPMeQDbARPc3uBe6DPuBcTrfdds6Is6f0XlURkcQAmgf jP1r3LZdGNfKxDTbfUWzFfEyZY858ueN+oI7bWTEsYrsyQbghUyfw7gxz g==; X-CSE-ConnectionGUID: IUakiUz4TK+YswO5GbR6Gg== X-CSE-MsgGUID: M4goTekQT2uhJl8zX+bLDg== X-IronPort-AV: E=McAfee;i="6600,9927,11074"; a="11878105" X-IronPort-AV: E=Sophos;i="6.08,163,1712646000"; d="scan'208";a="11878105" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 23:44:32 -0700 X-CSE-ConnectionGUID: ATJIdk0uT7evgR9VX5jkvw== X-CSE-MsgGUID: PYMVAO//QOmMEm1xF7mrfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,163,1712646000"; d="scan'208";a="35880823" Received: from mklonows-mobl1.ger.corp.intel.com (HELO fedora..) ([10.245.246.188]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 23:44:31 -0700 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Subject: [CI v2 13/21] dma-buf/dma-resv: Introduce dma_resv_trylock_ctx() Date: Thu, 16 May 2024 08:44:01 +0200 Message-ID: <20240516064410.22151-14-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240516064410.22151-1-thomas.hellstrom@linux.intel.com> References: <20240516064410.22151-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" 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. 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); } /** -- 2.44.0