From patchwork Tue Jul 30 12:15:53 2019 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: 11065649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78AC2112C for ; Tue, 30 Jul 2019 12:15:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67CD223E64 for ; Tue, 30 Jul 2019 12:15:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AB0727FC0; Tue, 30 Jul 2019 12:15:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EDBE823E64 for ; Tue, 30 Jul 2019 12:15:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5546C89AEE; Tue, 30 Jul 2019 12:15:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id A413D89AEE for ; Tue, 30 Jul 2019 12:15:57 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id 31so65554676wrm.1 for ; Tue, 30 Jul 2019 05:15:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=17yR+yiz4UDrMGoAoG+ThNckI0pZP3Wdt4bZ+sruBl8=; b=Ar6xJCu2f8tKVAKm9hFklQ+DB0sr7nRUHcIdV02Y9WIQ8pgpSkxOrCR4/ID1Y/Fw4z wF9eo53Dji+oBazmSKSMha4AF5unyTYvqK2O4CTxIwp4YvCHAzGzHzDRIF5vQACyZamL k8tM4zXGImLh45f9Fa11ck8iWhp7Tjga8IIgydT1MDgNcQP78BmZUe4mhdnN4eW6Agmr EDjjw8nCjNcTNe19ZnvgpPOs9hn65sHpg0mmuyvHFNfNkFlAaTqs723UtSGrSnnqC7HF PZ3GIZh+7jfVb6Bxc57vSIFH0FfiDljkeh/HJsDLM7SZF/lq4/stIRg68UH6P35E9rUw HM6g== X-Gm-Message-State: APjAAAWjsFoYXxp7MY+sjYRJWAltG8g1J0buis23iBvpeULSNS/6kGnd 4SEprB0+ECPuW09SAArTBn0= X-Google-Smtp-Source: APXvYqylFC2DLXsZ4JZ/n9DA0uv6e9S9sp7t3zhYITwsMJbwhcnUCsEd+rEUEyzoSgI1VHx34NVo0g== X-Received: by 2002:adf:eacf:: with SMTP id o15mr5502024wrn.171.1564488956350; Tue, 30 Jul 2019 05:15:56 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:30e2:d562:3041:c580]) by smtp.gmail.com with ESMTPSA id u1sm60416390wml.14.2019.07.30.05.15.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 05:15:55 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: lionel.g.landwerlin@intel.com, david1.zhou@amd.com, dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] dma-buf: add dma_fence_chain_for_each_unwrap helper Date: Tue, 30 Jul 2019 14:15:53 +0200 Message-Id: <20190730121554.105600-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=17yR+yiz4UDrMGoAoG+ThNckI0pZP3Wdt4bZ+sruBl8=; b=nd/OzQksk9FdWGtwgQTHJFssHdo//X0x1a7hi12U9mvlJ46p5X55Oz6MhlWAUSc58+ LRItsh9q8lncIvXyihrLDTEFtTESkd+Q7bZJm9A2KHcUc8i5CAb6Ktoqy/oPW+r+kVR5 xJjGyCNa72/YgcUd37HhelzZMecvQWwEni5XyOm3Aidzj2NaJmD/7OZ/X57gknjS/M1a VcFSWtUXWRlgRFlNj/bDcIh6ck7FrImHKIPtBGLFWpHp6vfd8JH41V2HejTp3KpeVOOm evSP5ye/OzLYUeKhTfjSaV5VhjK+MEZ2Xr9loI3XqMeN641j2Y8QCzoJjqccCGVc3fiC 0Pvw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Add another for_each helper to iterate over all the fences in a chain with unwrapping each chain node. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-chain.c | 11 ++++------ include/linux/dma-fence-chain.h | 34 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 93c42078cb57..6c3a615731b4 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -151,12 +151,10 @@ static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb) static bool dma_fence_chain_enable_signaling(struct dma_fence *fence) { struct dma_fence_chain *head = to_dma_fence_chain(fence); + struct dma_fence *f; 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; - + dma_fence_chain_for_each_unwrap(f, fence, &head->base) { dma_fence_get(f); if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) { dma_fence_put(fence); @@ -170,10 +168,9 @@ 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_for_each_unwrap(f, fence, fence) { if (!dma_fence_is_signaled(f)) { dma_fence_put(fence); return false; diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h index 934a442db8ac..7466d7b8837e 100644 --- a/include/linux/dma-fence-chain.h +++ b/include/linux/dma-fence-chain.h @@ -59,6 +59,24 @@ to_dma_fence_chain(struct dma_fence *fence) return container_of(fence, struct dma_fence_chain, base); } +/** + * dma_fence_chain_unwrap - unwrap chain node + * @fence: fence which could be a chain node + * + * If the paramter is a chain node return the cotained fence, otherwise return + * the parameter itself. + */ +static inline struct dma_fence * +dma_fence_chain_unwrap(struct dma_fence *fence) +{ + struct dma_fence_chain *chain = to_dma_fence_chain(fence); + + if (!chain) + return fence; + + return chain->fence; +} + /** * dma_fence_chain_for_each - iterate over all fences in chain * @iter: current fence @@ -71,6 +89,22 @@ to_dma_fence_chain(struct dma_fence *fence) for (iter = dma_fence_get(head); iter; \ iter = dma_fence_chain_walk(iter)) +/** + * dma_fence_chain_for_each_unwrap - iterate over all unwrapped fences in chain + * @fence: the unwrapped fence + * @iter: current fence + * @head: starting point + * + * Iterate over all fences in the chain with unwrapping. We keep a reference to + * the current fence while inside the loop which must be dropped when breaking + * out. + */ +#define dma_fence_chain_for_each_unwrap(fence, iter, head) \ + for (iter = dma_fence_get(head), \ + fence = dma_fence_chain_unwrap(iter); \ + iter; iter = dma_fence_chain_walk(iter), \ + fence = dma_fence_chain_unwrap(iter)) + struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence); int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno); void dma_fence_chain_init(struct dma_fence_chain *chain, From patchwork Tue Jul 30 12:15:54 2019 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: 11065651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D73F8112C for ; Tue, 30 Jul 2019 12:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6C1123E64 for ; Tue, 30 Jul 2019 12:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BADB52818E; Tue, 30 Jul 2019 12:16:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6249F2624D for ; Tue, 30 Jul 2019 12:16:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CCCB389BD4; Tue, 30 Jul 2019 12:15:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6AEA689BCD for ; Tue, 30 Jul 2019 12:15:58 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id n9so40443243wrr.4 for ; Tue, 30 Jul 2019 05:15:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K6xrCpMU4JO5tVAsw3gwIdw9Mgb2l+3m2FwDKVA99Gc=; b=au1kgII2WoitUPaAbx9WEDDpZu5b+Ba3vMYaYOdpPJy72B8cZl4PRX7vtUcEXLRK7n S8ihV3W9nea5rYDEc8ZpVP3T0Z1yG8m1VwcUDR0SWtmRU0NfVqLTz1Dy8mgQXIUcNu4I JgkCCQ/azx2Q3YFAP5EyFgLmaFmwKYR8edEaxu9qNkXJIiUd0NKTK5NWi5Jihp/KdbQx nmdLSa8pdu33THRB0fqfoaXixPX3yyJ/UU61EA7H+Pdm1sQjDWmmrSkgSUSOECnseqpQ fOCJ1LveTdi0WV5R5k92ujA1AYmANwD5AjahR3l9rt8Hc0mh4C2plt0j+0a4SoQPzG2Y 2ncA== X-Gm-Message-State: APjAAAXnNrbt9NmH6TNs1fJ1z1QhyOLDAzLMwc5J9JSnN3mAz6Eiuufg wOPnktUgzYY2YkN8bm/8tqOzr3CU X-Google-Smtp-Source: APXvYqzsX+6niAWLJN5p2J6Xhof5BlniPbBjGG/TIYMDGqefZ0ZDGX2mx21VHD6DLbHYqKqYMuwDfg== X-Received: by 2002:a5d:4ec1:: with SMTP id s1mr119454305wrv.19.1564488957110; Tue, 30 Jul 2019 05:15:57 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:30e2:d562:3041:c580]) by smtp.gmail.com with ESMTPSA id u1sm60416390wml.14.2019.07.30.05.15.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 05:15:56 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: lionel.g.landwerlin@intel.com, david1.zhou@amd.com, dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] dma-buf: add dma_fence_chain_(alloc|free) Date: Tue, 30 Jul 2019 14:15:54 +0200 Message-Id: <20190730121554.105600-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190730121554.105600-1-christian.koenig@amd.com> References: <20190730121554.105600-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=K6xrCpMU4JO5tVAsw3gwIdw9Mgb2l+3m2FwDKVA99Gc=; b=AqdK4WzTlh3oapo+Yx2Li742UZrx71hdLSIupji0G62HfylOxD6wpFygcfSpGjoLdf JOh+LrF1eWfNcQmVy0XG5RJf8mzb2+vpeF/dkJwZA84b8a/1UNVjssxkEGSJRL3ZalQH CnOfwa6jnuKCxTUNmy2uSOPHeAdfwwtPlhPmn38RPp/gvhwWbpUpDfrMdlN5Ujhxxn/+ ZteGWU4olpOmnz7Uoowvnvz8JSZ7iG0x5FZ+VxfgILHcsHNoCE5mya66fe/b0urkEuuH VSr+dMM/+h6WGabmIVcWbO/2EordwF+iL/TeO6H6wsdTb+uMYCKekWMe5jCur/po980z mFRw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Wrap kmalloc/kfree to allow switching to a slab allocator later on. Signed-off-by: Christian König --- drivers/dma-buf/dma-fence-chain.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +++--- drivers/gpu/drm/drm_syncobj.c | 2 +- include/linux/dma-fence-chain.h | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c index 6c3a615731b4..56183dc9f787 100644 --- a/drivers/dma-buf/dma-fence-chain.c +++ b/drivers/dma-buf/dma-fence-chain.c @@ -186,7 +186,7 @@ static void dma_fence_chain_release(struct dma_fence *fence) dma_fence_put(rcu_dereference_protected(chain->prev, true)); dma_fence_put(chain->fence); - dma_fence_free(fence); + dma_fence_chain_free(chain); } const struct dma_fence_ops dma_fence_chain_ops = { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index def029ab5657..4b1e4b321999 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -758,7 +758,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error, for (i = 0; i < parser->num_post_deps; i++) { drm_syncobj_put(parser->post_deps[i].syncobj); - kfree(parser->post_deps[i].chain); + dma_fence_chain_free(parser->post_deps[i].chain); } kfree(parser->post_deps); @@ -1187,7 +1187,7 @@ static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p dep->chain = NULL; if (syncobj_deps[i].point) { - dep->chain = kmalloc(sizeof(*dep->chain), GFP_KERNEL); + dep->chain = dma_fence_chain_alloc(); if (!dep->chain) return -ENOMEM; } @@ -1195,7 +1195,7 @@ static int amdgpu_cs_process_syncobj_timeline_out_dep(struct amdgpu_cs_parser *p dep->syncobj = drm_syncobj_find(p->filp, syncobj_deps[i].handle); if (!dep->syncobj) { - kfree(dep->chain); + dma_fence_chain_free(dep->chain); return -EINVAL; } dep->point = syncobj_deps[i].point; diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index cecff2e447b1..fc73f398e738 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -696,7 +696,7 @@ static int drm_syncobj_transfer_to_timeline(struct drm_file *file_private, &fence); if (ret) goto err; - chain = kzalloc(sizeof(struct dma_fence_chain), GFP_KERNEL); + chain = dma_fence_chain_alloc(); if (!chain) { ret = -ENOMEM; goto err1; diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h index 7466d7b8837e..b84e28661d48 100644 --- a/include/linux/dma-fence-chain.h +++ b/include/linux/dma-fence-chain.h @@ -18,6 +18,7 @@ #ifndef __LINUX_DMA_FENCE_CHAIN_H #define __LINUX_DMA_FENCE_CHAIN_H +#include #include #include @@ -43,6 +44,29 @@ struct dma_fence_chain { extern const struct dma_fence_ops dma_fence_chain_ops; +/** + * dma_fence_chain_alloc - wrapper to allocate a dma_fence_chain + * + * Wrap the kmalloc for now to easier switch to a slub allocator. + * + * Returns an allocated dma_fence_chain or NULL. + */ +static inline struct dma_fence_chain *dma_fence_chain_alloc(void) +{ + return kmalloc(sizeof(struct dma_fence_chain), GFP_KERNEL); +} + +/** + * dma_fence_chain_free - wrapper to free a dma_fence_chain + * @chain: the chain we need to free. + * + * Wrap the dma_fence_free for now to easier switch to a slub allocator. + */ +static inline void dma_fence_chain_free(struct dma_fence_chain *chain) +{ + dma_fence_free(&chain->base); +} + /** * to_dma_fence_chain - cast a fence to a dma_fence_chain * @fence: fence to cast to a dma_fence_array