From patchwork Thu Aug 10 17:01:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 9894261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8B61460384 for ; Thu, 10 Aug 2017 17:02:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7985528B71 for ; Thu, 10 Aug 2017 17:02:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E79B28B23; Thu, 10 Aug 2017 17:02:07 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 D517028B23 for ; Thu, 10 Aug 2017 17:02:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 642E06E5D9; Thu, 10 Aug 2017 17:02:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0DDA66E576; Thu, 10 Aug 2017 17:02:01 +0000 (UTC) Received: by mail-qk0-x244.google.com with SMTP id q66so1237283qki.1; Thu, 10 Aug 2017 10:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ytTF6weeUkHSuaKTmdsuFOhqV21d5+omrIW4OqwwRs4=; b=fym/5S5z1pYfBJTE/lRyGyzPwQraZYohIXcunP1j3s+HovwxDFkfziUS3ckvafIgnm kh87/Abuby1aiMsd5P/lE44BNzzhEEkDZFuh1kEAVf48DuTOKJUTUKbi0yIiTdPKfPP6 6HJ9PWrA+N+fo7Z6oKJ6mkR0tUk/siXkp/1fKNKuvkRIb1JKtCRCfwtMTfNHVfvUkvPs emaPVtEFqcL+LALPWHAMuAmA6tm6nZb1tbWh9s2pyqJ+TN6aszd2qjV0fV6wLBROmuev WvenpRJ1j1fvJfJ2t6wR6n59YB6TLqinnaPE2sgrZWOvY+YK/2Lxkm3CEgbN8FtxUreE 3ZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ytTF6weeUkHSuaKTmdsuFOhqV21d5+omrIW4OqwwRs4=; b=KGcmsTR9gd9hx9kX04jj+yoprwxYIZURcypimYVpLtveFstrpzqsrof7ZmwML4Tezw vWhdCjzNe3DF7vCuwu9pffMfWEwlQHTzom3SxjDEu3gRy+4+nCJRP0OKJIzQqspqgQa1 mgzOqt55ktxOyXQcx+/VgMV7YnNugGHj3rKyy870bFnRnjoEj+Cg6E7pXtiwr5Spq5Pn 5UUZGuZ8ReuKqRbxzDjYprArG5vUVjXrVih7rMVY1NEuFXtdHmr6DJGKQxFv8z8Ej+Wc 930MKdkyIAh0Jv/g225Tc7qNySBsMedaY6ThV2Bafhd3hTWMO81G/jZ1T17FSYN3hQCk J+CQ== X-Gm-Message-State: AHYfb5iFEtHr37R0ElNdk8M+jig5ISxxQJDWWtDNyK5/RCNefeESRcpr SFhYuCcAGYj953kj X-Received: by 10.55.161.23 with SMTP id k23mr15044551qke.345.1502384520914; Thu, 10 Aug 2017 10:02:00 -0700 (PDT) Received: from cm.localdomain (va-67-233-122-109.dhcp.embarqhsd.net. [67.233.122.109]) by smtp.gmail.com with ESMTPSA id s22sm4174653qte.92.2017.08.10.10.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Aug 2017 10:02:00 -0700 (PDT) From: Alex Deucher X-Google-Original-From: Alex Deucher To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, sumit.semwal@linaro.org, christian.koenig@amd.com Subject: [PATCH 1/2] dma-buf: add reservation_object_copy_fences (v2) Date: Thu, 10 Aug 2017 13:01:48 -0400 Message-Id: <1502384509-10465-2-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1502384509-10465-1-git-send-email-alexander.deucher@amd.com> References: <1502384509-10465-1-git-send-email-alexander.deucher@amd.com> MIME-Version: 1.0 Cc: Alex Deucher X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 From: Christian König Allows us to copy all the fences in a reservation object to another one. v2: handle NULL src_list Signed-off-by: Christian König Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher --- drivers/dma-buf/reservation.c | 60 +++++++++++++++++++++++++++++++++++++++++++ include/linux/reservation.h | 3 +++ 2 files changed, 63 insertions(+) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 87f8f57..d4881f9 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -262,6 +262,66 @@ void reservation_object_add_excl_fence(struct reservation_object *obj, EXPORT_SYMBOL(reservation_object_add_excl_fence); /** +* reservation_object_copy_fences - Copy all fences from src to dst. +* @dst: the destination reservation object +* @src: the source reservation object +* +* Copy all fences from src to dst. Both src->lock as well as dst-lock must be +* held. +*/ +int reservation_object_copy_fences(struct reservation_object *dst, + struct reservation_object *src) +{ + struct reservation_object_list *src_list, *dst_list; + struct dma_fence *old, *new; + size_t size; + unsigned i; + + src_list = reservation_object_get_list(src); + + if (src_list) { + size = offsetof(typeof(*src_list), + shared[src_list->shared_count]); + dst_list = kmalloc(size, GFP_KERNEL); + if (!dst_list) + return -ENOMEM; + + dst_list->shared_count = src_list->shared_count; + dst_list->shared_max = src_list->shared_count; + for (i = 0; i < src_list->shared_count; ++i) + dst_list->shared[i] = + dma_fence_get(src_list->shared[i]); + } else { + dst_list = NULL; + } + + kfree(dst->staged); + dst->staged = NULL; + + src_list = reservation_object_get_list(dst); + + old = reservation_object_get_excl(dst); + new = reservation_object_get_excl(src); + + dma_fence_get(new); + + preempt_disable(); + write_seqcount_begin(&dst->seq); + /* write_seqcount_begin provides the necessary memory barrier */ + RCU_INIT_POINTER(dst->fence_excl, new); + RCU_INIT_POINTER(dst->fence, dst_list); + write_seqcount_end(&dst->seq); + preempt_enable(); + + if (src_list) + kfree_rcu(src_list, rcu); + dma_fence_put(old); + + return 0; +} +EXPORT_SYMBOL(reservation_object_copy_fences); + +/** * reservation_object_get_fences_rcu - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object diff --git a/include/linux/reservation.h b/include/linux/reservation.h index 156cfd3..21fc84d 100644 --- a/include/linux/reservation.h +++ b/include/linux/reservation.h @@ -254,6 +254,9 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, unsigned *pshared_count, struct dma_fence ***pshared); +int reservation_object_copy_fences(struct reservation_object *dst, + struct reservation_object *src); + long reservation_object_wait_timeout_rcu(struct reservation_object *obj, bool wait_all, bool intr, unsigned long timeout);