From patchwork Mon Aug 7 21:32:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 9886245 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 C3852602CC for ; Mon, 7 Aug 2017 21:32:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B57B62870F for ; Mon, 7 Aug 2017 21:32:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA7BE28711; Mon, 7 Aug 2017 21:32:40 +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=-2.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, 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 5F9B928702 for ; Mon, 7 Aug 2017 21:32:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F01789FA7; Mon, 7 Aug 2017 21:32:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-it0-x244.google.com (mail-it0-x244.google.com [IPv6:2607:f8b0:4001:c0b::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 68C4C89FA5; Mon, 7 Aug 2017 21:32:36 +0000 (UTC) Received: by mail-it0-x244.google.com with SMTP id m34so1230971iti.0; Mon, 07 Aug 2017 14:32:36 -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=dTE3R5R4zfvQ/KoDA+5aMDi2i0knCM14mD/qIJkakbk=; b=dsJNwBA/YPGfvDYaZYpv1UdEGtfAwQf9nwxY5tRLSdH5/a9CP20c1jEtRrDGoYEhNp K9QMWBQUHV463MO/J0ITh9piMPmfMGyVjIYWzqsSS9hIAicu7XW8opeCqzx2Xxtu/nQr J7uduYHlR+PUdB+tLl/XkzFSr/klSpCernnafldSxqx5VN/azOtbVO5P+gdm3guIr13+ ugaSBfTg0nBMb4pa33JlmoZWn1uCQcOo1ZW4sNtQZOO2ZjzSefg5bYwgyId9oGU144XP e4eyLxL3JT8VpFPBgDz6t76iEAI+yadD3juw+2PP5JavLb0KmPEqjFkr2wdUa0yf+WMD pBxA== 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=dTE3R5R4zfvQ/KoDA+5aMDi2i0knCM14mD/qIJkakbk=; b=oxv8qASEB2lNmE3/YMc0dwjgLDejL1PGeCenCrJSSxei03PiTjZxmZutGfudwRShc0 J5RVLGFQs/ct+T826zat8HFzEdQwLV4tPsacROytqBFaOPdxoiYfEQrRUYkC0WKAg5ab f/gWBxdcIlhkTC7fcfIGvFusCAxGfYQmvi979H7ODscTslDRX46MRQO+vAn00B+1IsOr 5DKmL+rMs5qtXvzmXGrY1WwEeV+XeUJvudMR3h26JgPM8UvKae05Yfq1GjBuytCw0Oqb VCV3YG0Jg8w2RNyIxnlFgVnQgkzLRButY4NVTuBEdNLTOlEXUnuAjiNPe6g6yhXM7Ye6 4Dkw== X-Gm-Message-State: AHYfb5i9IzOX+fn4hmjoSQgGLYCDldBFJSdeJ8zoGJ0GAEle6dVVByp3 wlc6lonlf+z3+CXf X-Received: by 10.36.76.10 with SMTP id a10mr2108064itb.96.1502141555461; Mon, 07 Aug 2017 14:32:35 -0700 (PDT) Received: from cm.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id x131sm24302itf.17.2017.08.07.14.32.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2017 14:32:35 -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 2/3] dma-buf: add reservation_object_copy_fences Date: Mon, 7 Aug 2017 17:32:22 -0400 Message-Id: <1502141543-13455-3-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1502141543-13455-1-git-send-email-alexander.deucher@amd.com> References: <1502141543-13455-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. Signed-off-by: Christian König Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher --- drivers/dma-buf/reservation.c | 58 +++++++++++++++++++++++++++++++++++++++++++ include/linux/reservation.h | 3 +++ 2 files changed, 61 insertions(+) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 87f8f57..e2eff86 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -262,6 +262,64 @@ 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); + + /* + * resize dst->fence or allocate if it doesn't exist, + * noop if already correct size + */ + size = offsetof(typeof(*src_list), shared[src_list->shared_count]); + dst_list = kmalloc(size, GFP_KERNEL); + if (!dst_list) + return -ENOMEM; + + kfree(dst->staged); + dst->staged = NULL; + + 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]); + + 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);