From patchwork Wed Feb 9 18:26:00 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: 12745747 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 2A7E0C433F5 for ; Mon, 14 Feb 2022 15:49:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A25010E243; Mon, 14 Feb 2022 15:48:58 +0000 (UTC) Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 71F1F10E1DC; Wed, 9 Feb 2022 18:26:03 +0000 (UTC) Received: by mail-ed1-x52b.google.com with SMTP id cz16so6878240edb.8; Wed, 09 Feb 2022 10:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=xy1Wl1YpQUBJ+tc0SQw9hpGSoZpQOiQLuW8DVJw6UJg=; b=kJ0XqzVgo4HWwoxJuhT4lXHGSLvV9GTJXnzzyFRjK3FAl7Ni8TCPYKxXeRWPzdWstV 1xO6FcG0MomNvg3+BpvHpo+RCosTkaIl6THWWqgDTX2OOlaoMYEKf6Q8LfaNqAUA9ps8 ZhF5/su5gueN99HLXDMt6GDBSpv3rOJiunonIJdtU5Lr61zXNtgRrQ0aKiYRsM5SkPwM A3qnxYpNOXa2tKc6YcpZomJM4I1x0Q8CWfajqt3wN5z8RpK5RQqOsddHPttPc3wGca09 D075bmE/P5gbfZ50HkV9mrfWREfW1ANenqcI04UW/cqbUlF/LBvMaTYzXXVJPnn9BjCr ITrw== 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:mime-version :content-transfer-encoding; bh=xy1Wl1YpQUBJ+tc0SQw9hpGSoZpQOiQLuW8DVJw6UJg=; b=0BqealjQp98bT5mZRtOizxHcQmsw2fpfW1MwFziGuDwptKd2xynI/gd9yPkMZdf4nb gbD7wDFwyOPddj91GuZyCInBjKzY5zpDMrxBGgpAG/Wt8p6iHwWudlmYoCDAORrxbVoo YjwSxmScS/BsxRYTBdA+/zs/hMXOFTWSN90vThs84oO3jhB9e39tA2IwZBYpm1GxvFji RSny7x9yB8nU79ein2A5rLc5Cm0x8stuKsRqAJHcrF66wQ2LpCfdWkztQI3tikolSaDu 5ANqZocFDpnJ7JmIRo1wW++5NQ2xYBmclBV5ROTc9aHAwZcGjKXNfZH6G1Dzn+XMq2Fr fVvw== X-Gm-Message-State: AOAM531xYW+oZFvDK5K7+2fWJ1k+t1HscIWk+rclxo1iXA48YB1BllXw 3XekWwQ3uATqxomL9PLt6yg1FrRgglI= X-Google-Smtp-Source: ABdhPJzzS7j8gHRMsRxfam2p6eWcjNvR4qSY2heS34HP7/ucko1xgpid3LD+uuBdGqNHo3etUbyGhQ== X-Received: by 2002:aa7:c947:: with SMTP id h7mr3894625edt.447.1644431161780; Wed, 09 Feb 2022 10:26:01 -0800 (PST) Received: from able.fritz.box (p57b0bff8.dip0.t-ipconnect.de. [87.176.191.248]) by smtp.gmail.com with ESMTPSA id k7sm6190066ejp.182.2022.02.09.10.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 10:26:01 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: thomas.hellstrom@linux.intel.com, daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Wed, 9 Feb 2022 19:26:00 +0100 Message-Id: <20220209182600.434803-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 14 Feb 2022 15:48:57 +0000 Subject: [Intel-gfx] [PATCH] drm/syncobj: flatten dma_fence_chains on transfer 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 is illegal to add a dma_fence_chain as timeline point. Flatten out the fences into a dma_fence_array instead. Signed-off-by: Christian König Signed-off-by: Lucas De Marchi --- drivers/gpu/drm/drm_syncobj.c | 61 ++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index c313a5b4549c..7e48dcd1bee4 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -853,12 +853,57 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data, &args->handle); } + +/* + * Try to flatten a dma_fence_chain into a dma_fence_array so that it can be + * added as timeline fence to a chain again. + */ +static int drm_syncobj_flatten_chain(struct dma_fence **f) +{ + struct dma_fence_chain *chain = to_dma_fence_chain(*f); + struct dma_fence *tmp, **fences; + struct dma_fence_array *array; + unsigned int count; + + if (!chain) + return 0; + + count = 0; + dma_fence_chain_for_each(tmp, &chain->base) + ++count; + + fences = kmalloc_array(count, sizeof(*fences), GFP_KERNEL); + if (!fences) + return -ENOMEM; + + count = 0; + dma_fence_chain_for_each(tmp, &chain->base) + fences[count++] = dma_fence_get(tmp); + + array = dma_fence_array_create(count, fences, + dma_fence_context_alloc(1), + 1, false); + if (!array) + goto free_fences; + + dma_fence_put(*f); + *f = &array->base; + return 0; + +free_fences: + while (count--) + dma_fence_put(fences[count]); + + kfree(fences); + return -ENOMEM; +} + static int drm_syncobj_transfer_to_timeline(struct drm_file *file_private, struct drm_syncobj_transfer *args) { struct drm_syncobj *timeline_syncobj = NULL; - struct dma_fence *fence; struct dma_fence_chain *chain; + struct dma_fence *fence; int ret; timeline_syncobj = drm_syncobj_find(file_private, args->dst_handle); @@ -869,16 +914,22 @@ static int drm_syncobj_transfer_to_timeline(struct drm_file *file_private, args->src_point, args->flags, &fence); if (ret) - goto err; + goto err_put_timeline; + + ret = drm_syncobj_flatten_chain(&fence); + if (ret) + goto err_free_fence; + chain = dma_fence_chain_alloc(); if (!chain) { ret = -ENOMEM; - goto err1; + goto err_free_fence; } + drm_syncobj_add_point(timeline_syncobj, chain, fence, args->dst_point); -err1: +err_free_fence: dma_fence_put(fence); -err: +err_put_timeline: drm_syncobj_put(timeline_syncobj); return ret;