From patchwork Fri Feb 4 10:04:24 2022 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: 12735062 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 01232C433FE for ; Fri, 4 Feb 2022 13:25:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C5DB610EBF3; Fri, 4 Feb 2022 13:25:45 +0000 (UTC) Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by gabe.freedesktop.org (Postfix) with ESMTPS id 78E0510F0F2; Fri, 4 Feb 2022 10:04:39 +0000 (UTC) Received: by mail-ed1-x531.google.com with SMTP id p7so11956004edc.12; Fri, 04 Feb 2022 02:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=nkHC8QZFOIHT45+bm5mbkRLb4msTxzU2f5F+QSxdoAg=; b=aO5j1vpxduryKd+RGFIMJ30cU/mPsvp7GMzZS70owa2r9v428jzlHLLim5ZOiSaR4S 1jxu3wimsgT80a917+7M7LK/PiksuSe8drUzAyHPuSbAfFb2oCBm5GbNfVV3WFg18ksj lOT2STj2CV6uTuxa4GUPytFqtmhrQN5vsHlTjBsvWBTnfOoom/kjURw+rdKXdKDWDqMj fV5MuBmnGAA1ktoRysUY8+HGWJCYKeX3z7Dx8/ZkB1esdCld2lrenLqTIaFVeCT14mwJ dtZQ5wCBf0fp2k1quk8MBMVj/eidysWQIPx9tQUsA+elnVn3R0Z2bWA+A/97b7mI12gK n5vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nkHC8QZFOIHT45+bm5mbkRLb4msTxzU2f5F+QSxdoAg=; b=YDW3iMdaKoJckzLlkiz8TQBVilBju1NixJ/Y68Xdw1QLouajzd3xtTUh1ExKjgZJm8 gj2DdHZ34AFFxkob0xmELTsQQSv5RNwE598yuzeZzBkxvGKewU8gMULfT+KcOAtdwKlY AdZr+t1bbhmCinbYUw0AkupDu685k6WoiSCHwydSHM41TJN8z+PzzsvSwz5qtFkgNdqS zQxNo8PebYokmD820eEkuzz2ZVoxG+VeZTNOkEVWRg4LqyeC+FS1keDDH5rK4+mbQf/t rDeA3I7JsfBdWWmKGYW/3u9kqqPOh0SSsiWbeq4WzYKx61I1Wrtqh2hrudspsHPFRAxt dZmQ== X-Gm-Message-State: AOAM533n21MaEPuwSLiG+bAT9cHpPVplG97CiisX3IJR3u2pEzgtpLA/ DGBaxavCn32+pr956tOqTa+w09KCdSY= X-Google-Smtp-Source: ABdhPJxZcJbhLtg6luNVPToQ3qurqMzcy+Lv2Uyi2KzW6Ius5EGVvfWD4cLsYJJ9yMg4UmDiqQ81qQ== X-Received: by 2002:aa7:db8f:: with SMTP id u15mr2316386edt.36.1643969077869; Fri, 04 Feb 2022 02:04:37 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:37 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:24 +0100 Message-Id: <20220204100429.2049-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 1/6] dma-buf: consolidate dma_fence subclass checking 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" Consolidate the wrapper functions to check for dma_fence subclasses in the dma_fence header. This makes it easier to document and also check the different requirements for fence containers in the subclasses. Signed-off-by: Christian König --- include/linux/dma-fence-array.h | 15 +------------ include/linux/dma-fence-chain.h | 3 +-- include/linux/dma-fence.h | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h index 303dd712220f..fec374f69e12 100644 --- a/include/linux/dma-fence-array.h +++ b/include/linux/dma-fence-array.h @@ -45,19 +45,6 @@ struct dma_fence_array { struct irq_work work; }; -extern const struct dma_fence_ops dma_fence_array_ops; - -/** - * dma_fence_is_array - check if a fence is from the array subsclass - * @fence: fence to test - * - * Return true if it is a dma_fence_array and false otherwise. - */ -static inline bool dma_fence_is_array(struct dma_fence *fence) -{ - return fence->ops == &dma_fence_array_ops; -} - /** * to_dma_fence_array - cast a fence to a dma_fence_array * @fence: fence to cast to a dma_fence_array @@ -68,7 +55,7 @@ static inline bool dma_fence_is_array(struct dma_fence *fence) static inline struct dma_fence_array * to_dma_fence_array(struct dma_fence *fence) { - if (fence->ops != &dma_fence_array_ops) + if (!fence || !dma_fence_is_array(fence)) return NULL; return container_of(fence, struct dma_fence_array, base); diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h index 54fe3443fd2c..ee906b659694 100644 --- a/include/linux/dma-fence-chain.h +++ b/include/linux/dma-fence-chain.h @@ -49,7 +49,6 @@ struct dma_fence_chain { spinlock_t lock; }; -extern const struct dma_fence_ops dma_fence_chain_ops; /** * to_dma_fence_chain - cast a fence to a dma_fence_chain @@ -61,7 +60,7 @@ extern const struct dma_fence_ops dma_fence_chain_ops; static inline struct dma_fence_chain * to_dma_fence_chain(struct dma_fence *fence) { - if (!fence || fence->ops != &dma_fence_chain_ops) + if (!fence || !dma_fence_is_chain(fence)) return NULL; return container_of(fence, struct dma_fence_chain, base); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 1ea691753bd3..775cdc0b4f24 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -587,4 +587,42 @@ struct dma_fence *dma_fence_get_stub(void); struct dma_fence *dma_fence_allocate_private_stub(void); u64 dma_fence_context_alloc(unsigned num); +extern const struct dma_fence_ops dma_fence_array_ops; +extern const struct dma_fence_ops dma_fence_chain_ops; + +/** + * dma_fence_is_array - check if a fence is from the array subclass + * @fence: the fence to test + * + * Return true if it is a dma_fence_array and false otherwise. + */ +static inline bool dma_fence_is_array(struct dma_fence *fence) +{ + return fence->ops == &dma_fence_array_ops; +} + +/** + * dma_fence_is_chain - check if a fence is from the chain subclass + * @fence: the fence to test + * + * Return true if it is a dma_fence_chain and false otherwise. + */ +static inline bool dma_fence_is_chain(struct dma_fence *fence) +{ + return fence->ops == &dma_fence_chain_ops; +} + +/** + * dma_fence_is_container - check if a fence is a container for other fences + * @fence: the fence to test + * + * Return true if this fence is a container for other fences, false otherwise. + * This is important since we can't build up large fence structure or otherwise + * we run into recursion during operation on those fences. + */ +static inline bool dma_fence_is_container(struct dma_fence *fence) +{ + return dma_fence_is_array(fence) || dma_fence_is_chain(fence); +} + #endif /* __LINUX_DMA_FENCE_H */ From patchwork Fri Feb 4 10:04:25 2022 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: 12735065 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 A2A8DC433EF for ; Fri, 4 Feb 2022 13:25:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C3DD10F3EA; Fri, 4 Feb 2022 13:25:52 +0000 (UTC) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3285010F181; Fri, 4 Feb 2022 10:04:40 +0000 (UTC) Received: by mail-ed1-x535.google.com with SMTP id w25so12055702edt.7; Fri, 04 Feb 2022 02:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lua3ndSNkQ4/4Jps3PRoP7cS+stYoWZoem0sckVfZ4Y=; b=J6fLl5aNXVs7I7cJKmW+cvYJYiMnH4xxcXJmbxzwowAzLiVNNfYtym5eqlEXTMbvdO jyqt7VPBNUIC0WU5R2Li2xjq0YdXRtBriRfk5dvtwcvNDINzyp19MCUPG5Ev2HGQ4Vxn g6w7YUeeFRNBndYBK4hDHGdAJYfctaUFYScUuKccdXmC50/2zOWPew6Fx8P5yfMJHM6f Ux2zu4IverpLIQrG/KJy/fJPzg2aC3geRy5jXOUJxzsxCTKvYLCNUN6R+/ArrtSFZc/R 2yDRyM6oLmGRI5AUK3oadxHnZr+q1kOmQqPk/jr/YPq7j1VVtloVt8pyJpZIL893G9IE bx2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lua3ndSNkQ4/4Jps3PRoP7cS+stYoWZoem0sckVfZ4Y=; b=IE8s/9O+4FmkPaed8Z+usvySMwMLqpHq+bykjkgZ36QXU4LVprYPqd11Vua6IZAIlM M0lMeVkagL3pBMxFnJ+J+q4eSdOcHcZbJ2OLV9JG46KI8oexeJ0X0EBShoJAqrbkz5qu 6DugMGZ5+Vv99g/hgRDGMOF/2xvv4DMkoddx5BozavGq1baOm6tCTlZoY10b7aCnlSQK 6V8DnSPT5VYMUAWJq7+inK3+qrOE5/03IjlXjTOIKmJHJv4abygW6mltaoVPnkhSM4+6 ybJ4qNNIrQZ4YS66E0O6eJ9Tgi+6uv3BpXbegkAFZjYY+tSgWbFaPu9L+8CXjegDv894 wmyg== X-Gm-Message-State: AOAM533QPbLctY4ZtDGJDmyqgaxhLIO3LG4fAZf6wc60WOHIs4pIfbaE 4MrVFe4eq06mFrI0dpFhhLE= X-Google-Smtp-Source: ABdhPJz8hCqpmvlhCbMTzHXgtghoGTUiIoV0KxhuC94AUMCYZjdcSIN4UbCV+Z4RoJk32V5kj+6oAQ== X-Received: by 2002:a50:d70e:: with SMTP id t14mr2287416edi.19.1643969078713; Fri, 04 Feb 2022 02:04:38 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:38 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:25 +0100 Message-Id: <20220204100429.2049-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 2/6] dma-buf: warn about dma_fence_array container rules v2 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" It's not allowed to nest another dma_fence container into a dma_fence_array or otherwise we can run into recursion. Warn about that when we create a dma_fence_array. v2: fix comment style and typo in the warning pointed out by Thomas Signed-off-by: Christian König Reviewed-by: Daniel Vetter Reviewed-by: Thomas Hellström --- drivers/dma-buf/dma-fence-array.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index 3e07f961e2f3..cb1bacb5a42b 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -176,6 +176,20 @@ struct dma_fence_array *dma_fence_array_create(int num_fences, array->base.error = PENDING_ERROR; + /* + * dma_fence_array objects should never contain any other fence + * containers or otherwise we run into recursion and potential kernel + * stack overflow on operations on the dma_fence_array. + * + * The correct way of handling this is to flatten out the array by the + * caller instead. + * + * Enforce this here by checking that we don't create a dma_fence_array + * with any container inside. + */ + while (num_fences--) + WARN_ON(dma_fence_is_container(fences[num_fences])); + return array; } EXPORT_SYMBOL(dma_fence_array_create); From patchwork Fri Feb 4 10:04:26 2022 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: 12735063 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 0F06FC433EF for ; Fri, 4 Feb 2022 13:25:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FA6810EDB0; Fri, 4 Feb 2022 13:25:48 +0000 (UTC) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BDC110F181; Fri, 4 Feb 2022 10:04:40 +0000 (UTC) Received: by mail-ej1-x62b.google.com with SMTP id s13so17837787ejy.3; Fri, 04 Feb 2022 02:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OIMpCxdpOEYcnoEMYTLid8nSDucpIJk7Qs0av1g9rGU=; b=kEdyeBND1+sjQQEgBxCKwTD2jfD5hj01xe2rH5ufH1ohwmTGz9JuokXVS2loUz67cR Sgt0CJ88ZsTTlD499CNTbHz7n2mfp45kjtGliVjkRHcf4JFIPh0flrY1XW+1hCSLTGyN a3gssbVWS6MDk7MCK8sC++Gx8N2juQJuJe+RGaYof7Viu0fN41zThohPFYML9aQhT86/ i6BoDpIpea36irSI9yRq+kekYL+auv2MI+iBlqBxZM5KtTDZM+6y6UoNjvORoLTMuurL 0McJxS0QOz8cB/lUJdxfkHcsSzp3z8l6D4iOQI8cJVoHqamzqszYvBCOu6CGzatfOQ4O uShg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OIMpCxdpOEYcnoEMYTLid8nSDucpIJk7Qs0av1g9rGU=; b=ruhhu4MixAwpabi1EgwBhLDQZ9KHY7w39grW9MPQapluV+al2u9KVu7IZz1T1xogfw ym77FFfRDdH8lHoCflOOPNGTvxwxzSkb8zpBEbjlGTHFYWvHPsdz6IeRqifIVnL/9gW4 m2RqgianFKd23iQdV2bW2HWXrK6JT/1PmCyz5Ba3qy3tvWCP3jcXEqAdcQmGqSNNe0B3 7GK1QmiCgd/crxzc51UthOMhlznhpJWxJJUihGxVekNL45rFi6/+/D/ogVRZB/a3QgVg ZA9ggbo1jqkzeVb/FxAsR8k+h4ubYRMme+ZqqzKN/THNXGayf3O8JxwFbxVBtvQtyoNg 8jpQ== X-Gm-Message-State: AOAM533KZxa1aVdZpD3aexNRAvNFQm0+GzSOB7wiqopL+tdkQ2y8X4uC AAaZSDbaUbu0p3TFp0KuOFk= X-Google-Smtp-Source: ABdhPJy/MXdEppNWsn3y2eTv52qm/Awi+bfFn7NIw30r0IajdZozc69ofz3XjihpMxxDUZtMTpsxLA== X-Received: by 2002:a17:907:d20:: with SMTP id gn32mr1914593ejc.55.1643969079533; Fri, 04 Feb 2022 02:04:39 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:39 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:26 +0100 Message-Id: <20220204100429.2049-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 3/6] dma-buf: Warn about dma_fence_chain container rules v2 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" Chaining of dma_fence_chain objects is only allowed through the prev fence and not through the contained fence. Warn about that when we create a dma_fence_chain. v2: fix comment style Signed-off-by: Christian König Reviewed-by: Daniel Vetter Reviewed-by: Thomas Hellström --- drivers/dma-buf/dma-fence-chain.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 1b4cb3e5cec9..084c6927b735 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -254,5 +254,14 @@ void dma_fence_chain_init(struct dma_fence_chain *chain, dma_fence_init(&chain->base, &dma_fence_chain_ops, &chain->lock, context, seqno); + + /* + * Chaining dma_fence_chain container together is only allowed through + * the prev fence and not through the contained fence. + * + * The correct way of handling this is to flatten out the fence + * structure into a dma_fence_array by the caller instead. + */ + WARN_ON(dma_fence_is_chain(fence)); } EXPORT_SYMBOL(dma_fence_chain_init); From patchwork Fri Feb 4 10:04:27 2022 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: 12735064 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 C1DE8C433FE for ; Fri, 4 Feb 2022 13:25:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C575910F3ED; Fri, 4 Feb 2022 13:25:49 +0000 (UTC) Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by gabe.freedesktop.org (Postfix) with ESMTPS id B85B710F253; Fri, 4 Feb 2022 10:04:41 +0000 (UTC) Received: by mail-ed1-x536.google.com with SMTP id l5so12041578edv.3; Fri, 04 Feb 2022 02:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZqHQbmrfkSeH45/mViZpX0rM/1+Zya9JLAfRq+Wk+m8=; b=UTfcjAcYMTX22h1fkYsOiRByUelnx3X3bl0rl1ikR/aJO6QvD61verYKIzZSBf9eVH XMqkOwE5kUkib2ogQLmu9HTN+sqxX1DA8ZPCtSCYN5iqJXLrxhoFmdQ3aNSg/D68jcQv sk+hn2kTdnDJHyibjVdqeJ3b5uXROQUOHxgr/rVe55bsaZEUijn8ZKNW33JUzpRjrlCk yLpLk8j7YMqZmdFpktDAjs/2waxkOlWZ1MBtbrrkfOmigChFnQ0dpfADIXLTo/ahqMOs tb2ROlq3i1TYTKTd8NNDQIXQazEVb/bLBK/xrNsifZJPasNxltUuj2JFQ2/T18LSIdhV Xt8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZqHQbmrfkSeH45/mViZpX0rM/1+Zya9JLAfRq+Wk+m8=; b=1y1AK5EyGPyypAf/oeYZfi1JVMpvNo1ihisO3kkIEaWwqOhy7DVcfru8NiER5rpWnG 7D6txb2uCgN7ZtnCvxwm1cPB7xLDG4XZ+VZrL+8dUm/C1Lj/MHrHNc8r1NiNKGtYZL+C 3ukSt3a45q3mk68BxFPlOe2XtiSncSYMGG7GoCo5jzeoJQBdcsOggE0QsNIrQFEbgboC +IfFcjVLH2mdJvT1C75TlRgqosOxJvbBISs3qjb5G5QSWDh+mxZPSoTGC7/m2pDXnxgN 63LwUySVzqDzMZXWu2uzTkUUfPlUMY2j87i1tjJyVdlffuUOhBN39nDnxzYNqTOsmH77 7LOQ== X-Gm-Message-State: AOAM5314I6gMMtvbVmgdZ3rUOAmVZ7OTtIHY7He1L6k6OujaWmiFA9We /i0rdIoPIYFhNgr0bkjsy1g= X-Google-Smtp-Source: ABdhPJzUVDomn6G0+FigRIR9w/gc5i6WBR+Ya0Sw2HySaEeAG3c5vDogUicENinZmg6AI0M2qES/dQ== X-Received: by 2002:a05:6402:510b:: with SMTP id m11mr2158175edd.203.1643969080332; Fri, 04 Feb 2022 02:04:40 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:40 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:27 +0100 Message-Id: <20220204100429.2049-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 4/6] dma-buf: warn about containers in dma_resv object 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" Drivers should not add containers as shared fences to the dma_resv object, instead each fence should be added individually. Signed-off-by: Christian König Reviewed-by: Daniel Vetter Reviewed-by: Thomas Hellström --- drivers/dma-buf/dma-resv.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c index ee31f15d633a..b51416405e86 100644 --- a/drivers/dma-buf/dma-resv.c +++ b/drivers/dma-buf/dma-resv.c @@ -256,6 +256,11 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence) dma_resv_assert_held(obj); + /* Drivers should not add containers here, instead add each fence + * individually. + */ + WARN_ON(dma_fence_is_container(fence)); + fobj = dma_resv_shared_list(obj); count = fobj->shared_count; From patchwork Fri Feb 4 10:04:28 2022 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: 12735066 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 51AC8C433F5 for ; Fri, 4 Feb 2022 13:25:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FAEB10F880; Fri, 4 Feb 2022 13:25:52 +0000 (UTC) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 936ED10F191; Fri, 4 Feb 2022 10:04:42 +0000 (UTC) Received: by mail-ej1-x62b.google.com with SMTP id a8so17714460ejc.8; Fri, 04 Feb 2022 02:04:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Rx5rKIs1h4pkPPx07vOixo6aKMAm9lXxnCcc7E9V7dU=; b=V4HxWMBwmSqyCzF0puYOm75Pg4LHlZZd73dPSvLtWqQfaGywaL9ENrwR6EEhNWIATA PAE0aikq8WPBTui6YjH5O9t3lZML+wi4Nv5h8iP+mWG7RG5Kh6MOBNXec5UsqlRNpntP qc34PH94usI9h2CCHb6VTnBY/Z8ZtG5+aQU5PPt6kv/RbHa2vNu1my44LwHUTx3OkK2H J3Zm8SwAGRLQRsUr0lBZdiOSg+oGsyPhfpzPgMAL0MR6K+fnuesYR+kLAsjeC1S40k2b PK5gW9WEIUq21kGYU2NPSkxpJA0SMDTafKYAeFKmWAwSxRV5aKYT31ijCHFY/memfmpw +VsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rx5rKIs1h4pkPPx07vOixo6aKMAm9lXxnCcc7E9V7dU=; b=SrihcxnGlGAZ4aEdkzVsCV1T7KsHVY5IscszE1YHW5+hESQCjAxniRUgugitXdeTpd Gcu5cWVhfEMR7upF02mcgXB8jfsbNibkQibl/yjAH8isL430xpaIId/PDRsZapOljP8H j4f4lkQDq8F4nyi71OQ8nl/Eip5Um7toCyrVLokeH5azUuZafBTU4sFarjN0iJJOxOBs CD8ygExmKUCAIN3mEIXs5JF/gVwM2cjQVC05uhyMfUdVvNX2Nwe1/Elzk0gZ1JVglPyl Yi7oVxZBb7YsF/Y089n/6AYdheOdWWRZ5PG9dxpxMA7Xzbw3nSuUVVvdM9Bi3VIjQTRR 4IZQ== X-Gm-Message-State: AOAM5330RTYq9ZwDKfPuaG0vGpprJFatbUhiwY1cRKtLiLurb5aOHEac KpUuIzR9cpHyhpcEJpR52Xo= X-Google-Smtp-Source: ABdhPJztBHmTGU6YkwToxZohDq0/Ut4O8GCLLrmJNsoENbA0aLh4NmlUkJR6QhSWUvCE7XuAmCh5IA== X-Received: by 2002:a17:907:7f8f:: with SMTP id qk15mr1799850ejc.287.1643969081145; Fri, 04 Feb 2022 02:04:41 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:40 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:28 +0100 Message-Id: <20220204100429.2049-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 5/6] dma-buf: add dma_fence_chain_contained helper 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" It's a reoccurring pattern that we need to extract the fence from a dma_fence_chain object. Add a helper for this. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-chain.c | 6 ++---- include/linux/dma-fence-chain.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 084c6927b735..06f8ef97c6e8 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -148,8 +148,7 @@ static bool dma_fence_chain_enable_signaling(struct dma_fence *fence) dma_fence_get(&head->base); dma_fence_chain_for_each(fence, &head->base) { - struct dma_fence_chain *chain = to_dma_fence_chain(fence); - struct dma_fence *f = chain ? chain->fence : fence; + struct dma_fence *f = dma_fence_chain_contained(fence); dma_fence_get(f); if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) { @@ -165,8 +164,7 @@ static bool dma_fence_chain_enable_signaling(struct dma_fence *fence) static bool dma_fence_chain_signaled(struct dma_fence *fence) { dma_fence_chain_for_each(fence, fence) { - struct dma_fence_chain *chain = to_dma_fence_chain(fence); - struct dma_fence *f = chain ? chain->fence : fence; + struct dma_fence *f = dma_fence_chain_contained(fence); if (!dma_fence_is_signaled(f)) { dma_fence_put(fence); diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h index ee906b659694..10d51bcdf7b7 100644 --- a/include/linux/dma-fence-chain.h +++ b/include/linux/dma-fence-chain.h @@ -66,6 +66,21 @@ to_dma_fence_chain(struct dma_fence *fence) return container_of(fence, struct dma_fence_chain, base); } +/** + * dma_fence_chain_contained - return the contained fence + * @fence: the fence to test + * + * If the fence is a dma_fence_chain the function returns the fence contained + * inside the chain object, otherwise it returns the fence itself. + */ +static inline struct dma_fence * +dma_fence_chain_contained(struct dma_fence *fence) +{ + struct dma_fence_chain *chain = to_dma_fence_chain(fence); + + return chain ? chain->fence : fence; +} + /** * dma_fence_chain_alloc * From patchwork Fri Feb 4 10:04:29 2022 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: 12735061 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 BABD4C433EF for ; Fri, 4 Feb 2022 13:25:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01F3610ED82; Fri, 4 Feb 2022 13:25:46 +0000 (UTC) Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6752510F253; Fri, 4 Feb 2022 10:04:43 +0000 (UTC) Received: by mail-ed1-x530.google.com with SMTP id p7so11956379edc.12; Fri, 04 Feb 2022 02:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=32x746+aqRVJfpOzq5mPUyMArnAKR0oshZjP3RNr6L8=; b=Jz+HUiSG7XC9MjED/gcNv0zfCuUYFu9u04aTEsTpnY4EbHbkWKo9dESj6TOix/VqTZ a2WlPyfMfnWgCJDQKyGlhNmo1XcGuTynUbjhCrCLMvnyhcMFQA7EQgea2/zM5WfUtetv 7LU75cwoXcDVBi0SEoMk18kcWX8gl0PfdBULxU7oeIYtgdu7YuYsMYiuaH6VOu+FnIAE tj5OSsML18o7A5+CgTltGSp/x1w7MO1OlrZpb+nc0nMwCZ7Y2gzG62hWXcZFAQsdDUHX QX5Cm+c6bL67tiep+HF5Fw14FBxfiTnkz52F+he6uyg/vKIVS6vepSKw4KE++z3lC9hw PDFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=32x746+aqRVJfpOzq5mPUyMArnAKR0oshZjP3RNr6L8=; b=AdR93I3OqIaFm+zfWe2nP+iBufS9cmbROa+qpy3qjGoA1QW5f2ZW13UuleIwa1TCcf 8oPPuNQIvak8P/aoa5A3S3KezyLyqzc7o/ejBDKuYseGYCQyV4ft27WjkO5g291YH8YQ ow+goF8sIqz1w1LuHlWp+5WFEi+k5RbwxYQre5iiumptc4cPSM/wBkV222mMedKVC0we vcHbhwMpmx1jTyJhrG8ZFsZYCSlKhV1rKPTPihuNSdJ05uT4y7u3iD16pkWtAqVZ5KIy qY0Cf43MR/afB4LQk2611ZFwzDNADJN+Qgtt3rSeOH5WHc5VSQRZfT1hqRkQozGdSSHH V73g== X-Gm-Message-State: AOAM532H9ehxnptmsiEO9jlNyQHu8OILrkrwoDS1O8ERswdIGCccP/XB 7+JZrN51WLOOb94EsQaT5Tc= X-Google-Smtp-Source: ABdhPJyZWf/AMWiDhzdDt7PQoSdF8kB98XCNmcSmAiADBKdZzV3DJeepZ+hSzwe2wALWcX4P1fjOEw== X-Received: by 2002:aa7:d944:: with SMTP id l4mr2239665eds.117.1643969082010; Fri, 04 Feb 2022 02:04:42 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id z10sm633943edl.54.2022.02.04.02.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 02:04:41 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: sumit.semwal@linaro.org, thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Fri, 4 Feb 2022 11:04:29 +0100 Message-Id: <20220204100429.2049-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204100429.2049-1-christian.koenig@amd.com> References: <20220204100429.2049-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 04 Feb 2022 13:25:44 +0000 Subject: [Intel-gfx] [PATCH 6/6] drm/amdgpu: use dma_fence_chain_contained 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" Instead of manually extracting the fence. Signed-off-by: Christian König Reviewed-by: Alex Deucher --- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c index f7d8487799b2..40e06745fae9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c @@ -261,10 +261,9 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, dma_resv_for_each_fence(&cursor, resv, true, f) { dma_fence_chain_for_each(f, f) { - struct dma_fence_chain *chain = to_dma_fence_chain(f); + struct dma_fence *tmp = dma_fence_chain_contained(f); - if (amdgpu_sync_test_fence(adev, mode, owner, chain ? - chain->fence : f)) { + if (amdgpu_sync_test_fence(adev, mode, owner, tmp)) { r = amdgpu_sync_fence(sync, f); dma_fence_put(f); if (r)