From patchwork Fri Jan 12 09:47:27 2018 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: 10160145 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 52253602D8 for ; Fri, 12 Jan 2018 09:47:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53B802897D for ; Fri, 12 Jan 2018 09:47:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47687289A1; Fri, 12 Jan 2018 09:47:39 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC2702897D for ; Fri, 12 Jan 2018 09:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754483AbeALJrg (ORCPT ); Fri, 12 Jan 2018 04:47:36 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:41668 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932414AbeALJrc (ORCPT ); Fri, 12 Jan 2018 04:47:32 -0500 Received: by mail-wm0-f65.google.com with SMTP id g75so10894176wme.0 for ; Fri, 12 Jan 2018 01:47:32 -0800 (PST) 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=OKvpffX9U72YfqwzpHs6F3SSCGjcUqYrokkuOd7yJAo=; b=UTEr8EoOFP33xbxls/RTGKpI7dp8X8RpYGNlyP+ahGrBWAbEJH/iHoIRr8jlLqCNYf vf3OLk7Ewt91VVA6et7lk2HKkEnIUfvN5DTH9vqZfKOXyEMUFQKQEvzuGv9/naWUQwnO Ap22jTmwNLomHjSTqmEupa7knhOLpIKLm9xn3vz+aFmQt4SbFP5qD6khWKa2iDpFUP7o iO3+Yv7UxkR9PzF8MQ/I8uOcObycVfyurnHF/hHCHAuK92nf4x/5kQ+QqHqypqP2ia57 X/5d6UXkmvu/iTba+jBz4GGsJ8mqh3996vFpOQDwK/dxk24EEGKnsJzN8GDampjY7a0F 3Ukw== 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=OKvpffX9U72YfqwzpHs6F3SSCGjcUqYrokkuOd7yJAo=; b=pZsNin/BKOu2Y/kmsmCvNaOmr/tdrz5g+6SjVjhr5q3zHthvsMneLPa+c09/zDEI2u jnHKHjmzrXPZDvtvk5d6mMnSDcX57D9L30nB7uo+nSfHK82wqlET0vCYsnz6adoxjvGW WfRx7soAMKfTMfyr13831n7kFNo8clhgeNPWEvE2JxVe9Js9MHkBfpzwPbYZoZ9fPD/L HPM1Ek8hlN/wKq5qCs38wz2J4os4vnzpagDNKQARLGHpo4sVDdFQDm/qxDUqctFcXGxm MQmYSEAdT2Hh3dJa8vA37gvFKl1IfZFosUbVPXW/zWr++fUQH1sy2c0E/qc4erLjd1zU sJ7Q== X-Gm-Message-State: AKwxytc9vrr8rK9yZLCM2b/cGi4gzcdpMeRlVC5Jdj+zCvRqGovUATnq 1yzoxU6LUfnUT9AhJ+x/fu3CfQ== X-Google-Smtp-Source: ACJfBotry05blM0yNMbEcG+3KZceYak1R6WZGalDTp+Ri60wBW7QhvhaCCB+T+DxEuIpIq0uDnK1cA== X-Received: by 10.28.55.146 with SMTP id e140mr3307340wma.4.1515750451599; Fri, 12 Jan 2018 01:47:31 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:6d3c:530f:8e94:9257]) by smtp.gmail.com with ESMTPSA id p10sm16616345wrh.61.2018.01.12.01.47.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 01:47:30 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, gustavo@padovan.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 1/3] dma-buf: make returning the exclusive fence optional Date: Fri, 12 Jan 2018 10:47:27 +0100 Message-Id: <20180112094729.17491-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change reservation_object_get_fences_rcu to make the exclusive fence pointer optional. If not specified the exclusive fence is put into the fence array as well. This is helpful for a couple of cases where we need all fences in a single array. Signed-off-by: Christian König Acked-by: Daniel Vetter --- drivers/dma-buf/reservation.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index b759a569b7b8..461afa9febd4 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -374,8 +374,9 @@ EXPORT_SYMBOL(reservation_object_copy_fences); * @pshared: the array of shared fence ptrs returned (array is krealloc'd to * the required size, and must be freed by caller) * - * RETURNS - * Zero or -errno + * Retrieve all fences from the reservation object. If the pointer for the + * exclusive fence is not specified the fence is put into the array of the + * shared fences as well. Returns either zero or -ENOMEM. */ int reservation_object_get_fences_rcu(struct reservation_object *obj, struct dma_fence **pfence_excl, @@ -389,8 +390,8 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, do { struct reservation_object_list *fobj; - unsigned seq; - unsigned int i; + unsigned int i, seq; + size_t sz = 0; shared_count = i = 0; @@ -402,9 +403,14 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, goto unlock; fobj = rcu_dereference(obj->fence); - if (fobj) { + if (fobj) + sz += sizeof(*shared) * fobj->shared_max; + + if (!pfence_excl && fence_excl) + sz += sizeof(*shared); + + if (sz) { struct dma_fence **nshared; - size_t sz = sizeof(*shared) * fobj->shared_max; nshared = krealloc(shared, sz, GFP_NOWAIT | __GFP_NOWARN); @@ -420,13 +426,19 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, break; } shared = nshared; - shared_count = fobj->shared_count; - + shared_count = fobj ? fobj->shared_count : 0; for (i = 0; i < shared_count; ++i) { shared[i] = rcu_dereference(fobj->shared[i]); if (!dma_fence_get_rcu(shared[i])) break; } + + if (!pfence_excl && fence_excl) { + shared[i] = fence_excl; + fence_excl = NULL; + ++i; + ++shared_count; + } } if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) { @@ -448,7 +460,8 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, *pshared_count = shared_count; *pshared = shared; - *pfence_excl = fence_excl; + if (pfence_excl) + *pfence_excl = fence_excl; return ret; }