From patchwork Tue Aug 6 15:01:27 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: 11085835 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 62D1118A6 for ; Fri, 9 Aug 2019 09:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 537C728B38 for ; Fri, 9 Aug 2019 09:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 479CE28C40; Fri, 9 Aug 2019 09:17:11 +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=unavailable 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 10A1A28C56 for ; Fri, 9 Aug 2019 09:17:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F4BA6EDCB; Fri, 9 Aug 2019 09:15:58 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 C21BB6E3AC; Tue, 6 Aug 2019 15:01:37 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id c2so85014853wrm.8; Tue, 06 Aug 2019 08:01:37 -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=rLPPYENgOoc631NZg5ylujQ9Ww/Oy03mgWH9mA4Vfho=; b=nUbeTTo31Q3JF4VIRfixPvjym5cT1gYTgM7CY9FLUcA2VIsjytrgEhoqISBEGAPhtI YMD1ZUKduo+YHtC/sx73Dl5PdVQhpOGu+jxsSvzebfW85b+K2E7EvPz6KbTFGLLuyUZ4 Yn2s6CSc0DLraToSkY7z/TQaLbnZjmW7/JIOboq8+EOAbWJ4S6ACMn5Ao3tFqcpIEOgH ZNIMZ97xCGWTEnjX3+2KucVO+5kIqc4eLy31xgh1qXAP8A8fb9zLGGk2v7EkVAdeU5RY 0dRkpTeNs2+qS56Ra4wYuer46DebPZ5rmTdSh2hNQAdJVKidBH1BnaUjWw8uYc6Ci6eg bsTg== X-Gm-Message-State: APjAAAW/lk29bUT4gMumt3I4ECu6ij/mVCW6bKgH/iGYLBF2VAb5EbD8 /bwgbzg3Hz65cf2S5oTGnubRZi1Y X-Google-Smtp-Source: APXvYqz6AcKhVWvcz+ipDVWpv+mwv6WdHOfeRXlIqGfRphZR2R8yUytCJlZ5FKlnzx8bJIHeQOnH1Q== X-Received: by 2002:a5d:6583:: with SMTP id q3mr5698550wru.184.1565103696222; Tue, 06 Aug 2019 08:01:36 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:35 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:27 +0200 Message-Id: <20190806150134.104222-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=rLPPYENgOoc631NZg5ylujQ9Ww/Oy03mgWH9mA4Vfho=; b=NLJEnCXtzyj6NYFf4+43Y6hYJ2KP82uwMjCZ6yEtCz3cMQRTmyASFSYgo7phqMiuDU 7R1kLPssX/Fm66DJlACPHRKwnj2jaNWdusHDZ6Wq+ioa7ATRg+byQw4Rv54g5Pv6RtyM f0TJM1wNYX5G5F46WPmMjlBLcOYJ630RS5xapz/7MVjvwFkdpZt7KtkFtAwyjom3Dxbr Ux2Z2ncX+upxYhAqXggRaoCh8dYCEgkNu6MIm/32Px85iL6i6FB9Xqp20jxEH7HbKdok xMTmLrreLYSDu0L2PYvNe6V5DT6fM2ZaI4poKTOwZLvpNHl4q/4W+VTdPt4rE956+AYi j+TQ== Subject: [Intel-gfx] [PATCH 1/8] dma-buf: fix busy wait for new shared fences X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP When reservation_object_add_shared_fence is replacing an old fence with a new one we should not drop the old one before the new one is in place. Otherwise other cores can busy wait for the new one to appear. Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index c71b85c8c159..d59207ca72d2 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -196,6 +196,7 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, struct dma_fence *fence) { struct reservation_object_list *fobj; + struct dma_fence *old; unsigned int i, count; dma_fence_get(fence); @@ -209,18 +210,16 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, write_seqcount_begin(&obj->seq); for (i = 0; i < count; ++i) { - struct dma_fence *old_fence; - old_fence = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(obj)); - if (old_fence->context == fence->context || - dma_fence_is_signaled(old_fence)) { - dma_fence_put(old_fence); + old = rcu_dereference_protected(fobj->shared[i], + reservation_object_held(obj)); + if (old->context == fence->context || + dma_fence_is_signaled(old)) goto replace; - } } BUG_ON(fobj->shared_count >= fobj->shared_max); + old = NULL; count++; replace: @@ -230,6 +229,7 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, write_seqcount_end(&obj->seq); preempt_enable(); + dma_fence_put(old); } EXPORT_SYMBOL(reservation_object_add_shared_fence); From patchwork Tue Aug 6 15:01:28 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: 11085983 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 7C64A1395 for ; Fri, 9 Aug 2019 09:21:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A7BB28961 for ; Fri, 9 Aug 2019 09:21:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EB5928C47; Fri, 9 Aug 2019 09:21:37 +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=unavailable 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 0C63128961 for ; Fri, 9 Aug 2019 09:21:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0268A6EDE0; Fri, 9 Aug 2019 09:21:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id D847A6E3AC; Tue, 6 Aug 2019 15:01:38 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id n9so63166191wrr.4; Tue, 06 Aug 2019 08:01:38 -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=iygOewm8tSkT172r4bWrbjM8Y7R1HsBfIZtC5P+jXJs=; b=ICaLxMHzv7g8wFpRD8Pxxp2jwwFHe5fv2j1AvDa823dkqphNBNE+qmRx4WXa8lLs2x l3CXB/2gyIO1zE6L6tyhTSCgJUlaLA3EXFb1ZwnJeCnZ+Q1bNUnAqKEfhQFJfKnj6n+a dufaT75vYDMwa48vZt19rtpdETzDKd2k/aIHlk56dKGCReu/UaYZE766O4c3hq8FdmEI h4Hc8UX6g0EDy/tjrLhZEt34ZyWzKOraSfZvsgnMlBlu/HUdtsn3tjq3oGQnDY5DMCfs x8p8gOA2pMPUKCLlXtfiyKJOoIiqlY+AJp6/E2ITUF84w3RAVCbfg7ipq3FrWC7gqaMX h0rA== X-Gm-Message-State: APjAAAWYs49rFcd1GNk7+ET1aaGN6kje3vuUhkvO9Q5xBdg5/G3UGEo0 5RZQsYrwRF2BhUhz3joMSWf4zlGM X-Google-Smtp-Source: APXvYqzy2Kgz+9jPZPS+CzJD1Vr2OThygCavWLHFRvHw8JOOmHMQXdC5hdEXm8RgUR8n2nXfs2/8pQ== X-Received: by 2002:adf:a344:: with SMTP id d4mr5285047wrb.237.1565103697141; Tue, 06 Aug 2019 08:01:37 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:36 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:28 +0200 Message-Id: <20190806150134.104222-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=iygOewm8tSkT172r4bWrbjM8Y7R1HsBfIZtC5P+jXJs=; b=D3TV3+KBThN+SxHpvUbrEo0rLzptGNEz/ZTVHUI5FC0EIYgTvaubUxWpQNGpWQGSVP CYrd2NoH8VoOcX+JpS9zgo0kO2CruEW2cMJcSzKohj2dIzGKGZjw37YvoQYGNWF2bSOW o+Znb73FC3/TxelbyHTQF7SIxBKO8H4FhfavE/HNLXhytFmCeXIjZM5zgWZ7yg3jjIbY fUf8aNKeM7j5mXmU0qiR3ku/upYqOxm0OqRcalfTDd0GFsShIpYxDyYOZNE3KiXfmp43 OirjW64GtkfzXBKBlM2NofKsNIQ4fHYmt+7x23S+QLgmI39Ig4dysOAu+OK7q6FBMiKC uGyQ== Subject: [Intel-gfx] [PATCH 2/8] dma-buf: fix shared fence list handling in reservation_object_copy_fences X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Add some helpers to correctly allocate/free reservation_object_lists. Otherwise we might forget to drop dma_fence references on list destruction. Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 65 +++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index d59207ca72d2..c0ba05936ab6 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -55,6 +55,47 @@ EXPORT_SYMBOL(reservation_seqcount_class); const char reservation_seqcount_string[] = "reservation_seqcount"; EXPORT_SYMBOL(reservation_seqcount_string); +/** + * reservation_object_list_alloc - allocate fence list + * @shared_max: number of fences we need space for + * + * Allocate a new reservation_object_list and make sure to correctly initialize + * shared_max. + */ +static struct reservation_object_list * +reservation_object_list_alloc(unsigned int shared_max) +{ + struct reservation_object_list *list; + + list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL); + if (!list) + return NULL; + + list->shared_max = (ksize(list) - offsetof(typeof(*list), shared)) / + sizeof(*list->shared); + + return list; +} + +/** + * reservation_object_list_free - free fence list + * @list: list to free + * + * Free a reservation_object_list and make sure to drop all references. + */ +static void reservation_object_list_free(struct reservation_object_list *list) +{ + unsigned int i; + + if (!list) + return; + + for (i = 0; i < list->shared_count; ++i) + dma_fence_put(rcu_dereference_protected(list->shared[i], true)); + + kfree_rcu(list, rcu); +} + /** * reservation_object_init - initialize a reservation object * @obj: the reservation object @@ -76,7 +117,6 @@ EXPORT_SYMBOL(reservation_object_init); */ void reservation_object_fini(struct reservation_object *obj) { - int i; struct reservation_object_list *fobj; struct dma_fence *excl; @@ -89,13 +129,7 @@ void reservation_object_fini(struct reservation_object *obj) dma_fence_put(excl); fobj = rcu_dereference_protected(obj->fence, 1); - if (fobj) { - for (i = 0; i < fobj->shared_count; ++i) - dma_fence_put(rcu_dereference_protected(fobj->shared[i], 1)); - - kfree(fobj); - } - + reservation_object_list_free(fobj); ww_mutex_destroy(&obj->lock); } EXPORT_SYMBOL(reservation_object_fini); @@ -132,7 +166,7 @@ int reservation_object_reserve_shared(struct reservation_object *obj, max = 4; } - new = kmalloc(offsetof(typeof(*new), shared[max]), GFP_KERNEL); + new = reservation_object_list_alloc(max); if (!new) return -ENOMEM; @@ -153,9 +187,6 @@ int reservation_object_reserve_shared(struct reservation_object *obj, RCU_INIT_POINTER(new->shared[j++], fence); } new->shared_count = j; - new->shared_max = - (ksize(new) - offsetof(typeof(*new), shared)) / - sizeof(*new->shared); /* * We are not changing the effective set of fences here so can @@ -286,7 +317,6 @@ int reservation_object_copy_fences(struct reservation_object *dst, { struct reservation_object_list *src_list, *dst_list; struct dma_fence *old, *new; - size_t size; unsigned i; reservation_object_assert_held(dst); @@ -298,10 +328,9 @@ int reservation_object_copy_fences(struct reservation_object *dst, if (src_list) { unsigned shared_count = src_list->shared_count; - size = offsetof(typeof(*src_list), shared[shared_count]); rcu_read_unlock(); - dst_list = kmalloc(size, GFP_KERNEL); + dst_list = reservation_object_list_alloc(shared_count); if (!dst_list) return -ENOMEM; @@ -313,7 +342,6 @@ int reservation_object_copy_fences(struct reservation_object *dst, } dst_list->shared_count = 0; - dst_list->shared_max = shared_count; for (i = 0; i < src_list->shared_count; ++i) { struct dma_fence *fence; @@ -323,7 +351,7 @@ int reservation_object_copy_fences(struct reservation_object *dst, continue; if (!dma_fence_get_rcu(fence)) { - kfree(dst_list); + reservation_object_list_free(dst_list); src_list = rcu_dereference(src->fence); goto retry; } @@ -353,8 +381,7 @@ int reservation_object_copy_fences(struct reservation_object *dst, write_seqcount_end(&dst->seq); preempt_enable(); - if (src_list) - kfree_rcu(src_list, rcu); + reservation_object_list_free(src_list); dma_fence_put(old); return 0; From patchwork Tue Aug 6 15:01:29 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: 11085755 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 567D414F7 for ; Fri, 9 Aug 2019 09:16:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45F8C28B38 for ; Fri, 9 Aug 2019 09:16:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38DE328C3E; Fri, 9 Aug 2019 09:16:32 +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=unavailable 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 045E028B38 for ; Fri, 9 Aug 2019 09:16:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D98A86ED50; Fri, 9 Aug 2019 09:15:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8CCA36E3AC; Tue, 6 Aug 2019 15:01:39 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id g17so88234166wrr.5; Tue, 06 Aug 2019 08:01:39 -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=AWEQZoXJ7Lv+PikX4O1dFQhLFUVrnvufpDvNejlOGH4=; b=uCMmmV8QGKuWyCI3cyyQIEJ+f0xBMUDeuufnAVApVPQtn/UPCMzJqYScrLJXGJBGSD +0+MHoUYkkjmN4xQqn2wBBHDwPqBKcS7bq2gK3hcdF5aUWE70SVQppmOLCS85+vahOO/ JG+T3Q4+GOFtR91RYwfR3J20KthQf4Vy1/AigXBaMx0r9EYBmcc5wGQJGKNzyfgfuVrl vLlaqWfHFyJYGohbJLCvwbeGDz8ob9Gfu2B/LIMBWGwcZMahV5d8qlBNTIg/HYR6Itzb FL6TOU2I9vi6eK8U7VGqY74ykfTJm4nqpyVS/4Zi7DgNyev6zOEYMaf6SQFFoqa6444y YllQ== X-Gm-Message-State: APjAAAU76do5EArAcImzD5XSz/s7O+b2MHDxlelvjpYapMysIX5UwcPI YuHGs7DpUpFDKP+xPrx0CfaSPBPi X-Google-Smtp-Source: APXvYqxNUff5gRQUSR6MwQ8LIyUILMM1JJ8O1BxsAgqVbIbytaK1nsDoScmjjGF/QXYzyCBYt4MTXA== X-Received: by 2002:adf:ed8a:: with SMTP id c10mr5498627wro.33.1565103697985; Tue, 06 Aug 2019 08:01:37 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:37 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:29 +0200 Message-Id: <20190806150134.104222-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=AWEQZoXJ7Lv+PikX4O1dFQhLFUVrnvufpDvNejlOGH4=; b=QSSKRK0YOzRwPGq1YzIWAguTcnw7OhIcQcyqCKmiHYpmwSVWFIrv+lrbf1YxJnnWbe JsXunHpz6nKlVc4Tv71LkWiYfkQhSAIVkWbZWiXVyOwLmNaNpEEHVST9rxG8jOnaN/D+ uP5HD5RnMQFb4i0l7DYjY2kL8lk9T9awNVoTqCC0+IW363dOroQrAt+Y6K9l+byfXdn4 t5WTCFCBxCEW/BGLJQrM3DCP7vab5eLK0doKPSYGV8zcPvNu1dyTMC5+sCifBpejX0AL blq6AsVVZ/xM4Ughu/67wSj9lv2NBtpg927g08AXYT07LRkjdBGH1elGZRL0VOhT8KOx stIA== Subject: [Intel-gfx] [PATCH 3/8] drm/i915: stop using seqcount for fenc pruning X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP After waiting for a reservation object use reservation_object_test_signaled_rcu to opportunistically prune the fences on the object. This allows removal of the seqcount handling in the reservation object. Signed-off-by: Christian König --- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_wait.c b/drivers/gpu/drm/i915/gem/i915_gem_wait.c index 26ec6579b7cd..fa46a54bcbe7 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_wait.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_wait.c @@ -35,7 +35,6 @@ i915_gem_object_wait_reservation(struct reservation_object *resv, unsigned int flags, long timeout) { - unsigned int seq = __read_seqcount_begin(&resv->seq); struct dma_fence *excl; bool prune_fences = false; @@ -83,15 +82,12 @@ i915_gem_object_wait_reservation(struct reservation_object *resv, /* * Opportunistically prune the fences iff we know they have *all* been - * signaled and that the reservation object has not been changed (i.e. - * no new fences have been added). + * signaled. */ - if (prune_fences && !__read_seqcount_retry(&resv->seq, seq)) { - if (reservation_object_trylock(resv)) { - if (!__read_seqcount_retry(&resv->seq, seq)) - reservation_object_add_excl_fence(resv, NULL); - reservation_object_unlock(resv); - } + if (prune_fences && reservation_object_trylock(resv)) { + if (reservation_object_test_signaled_rcu(resv, true)) + reservation_object_add_excl_fence(resv, NULL); + reservation_object_unlock(resv); } return timeout; From patchwork Tue Aug 6 15:01:30 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: 11085735 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 8106E14F7 for ; Fri, 9 Aug 2019 09:16:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7288B28B38 for ; Fri, 9 Aug 2019 09:16:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 673E028C54; Fri, 9 Aug 2019 09:16:18 +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=unavailable 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 3056728B38 for ; Fri, 9 Aug 2019 09:16:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D487D6EDA1; Fri, 9 Aug 2019 09:15:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 9CE1D6E3C1; Tue, 6 Aug 2019 15:01:40 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id z1so88237780wru.13; Tue, 06 Aug 2019 08:01:40 -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=Y/VgpN9KQ1OYN1RgMfMvxyKwysupVNNwVRv17BQOI18=; b=kS1HuSpgAR02f1tEubztaop9eAuUYUSRBTV/rDlRoOEocYapmzlgdXcjkEbVugldU5 WxU4kjRqf6a/J40iqURJXVk5Vc0dAC9WK0DBsRgVag3n/NYg9xgBYCjIh+iu2RGCHYvR F4CsUu0xG2iyCoGdeKVltDD90W8tG2pKWK0mBS9vqFUG78lHt7odW82w+F5JwZHaAVkh Gb+3OTPdx7CG9ebcxTAQa86dg6eIgFFYeFqqv57Evn+GJlZFQSiDEuUM6wNTufxVHKiN Uho+hnivgaREVprv92ghSTnoogaQQPh1krLXWTlZ1CBGko0FOt0rf32++EI9lXOURTTf 4vmw== X-Gm-Message-State: APjAAAXSRkGGuyHMtriy0Xje6Y5atKEJP/zBMFJlIffbR9Sj544REyuu TSN2sJ8m3ZS+UBQRbMlWu0C8LFgN X-Google-Smtp-Source: APXvYqySrehuax4d3UPx8f93fBn9dGfOVrfTSM3PKhCJVqFgq0+DDODLByQU0CF6Xj/N/Z0oG3Jptw== X-Received: by 2002:a5d:4041:: with SMTP id w1mr5377756wrp.199.1565103699074; Tue, 06 Aug 2019 08:01:39 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:38 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:30 +0200 Message-Id: <20190806150134.104222-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=Y/VgpN9KQ1OYN1RgMfMvxyKwysupVNNwVRv17BQOI18=; b=K5gHGuknqyvj012sUTfbv23M2dYCJGSg6gEE1ySc73LWtbguGo/uqRGNzeaFwz1A8W t7pQhYrOc/VQVq8Bp/OXGF92PlrRSYHBU3LHMRuy80gFO+30QEjqllxALk+D7hT7JFpu G5IcKGbuAn28uPBL8JZGIhEadAn5HjCAJkyNGXaDBYZ3E6+cUDl2BpI/beC/Yc8NaG24 YYW96Xhy9lvZIAgMCA5AYwGmBLOsFj54RvfkayH35NiBtBWt6uz8lzWsJ+41WNxjqh/V VoiBHqHogvlOvrEF+64DzbmkVvLXqnNLWeWgIiF9XolMmHNHI9UDhZNNBDnfk8b+Ibjk HEEg== Subject: [Intel-gfx] [PATCH 4/8] drm/i915: use new reservation_object_fences helper X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Instead of open coding the sequence loop use the new helper. Signed-off-by: Christian König --- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_busy.c b/drivers/gpu/drm/i915/gem/i915_gem_busy.c index 6ad93a09968c..8da0594eda88 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_busy.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_busy.c @@ -83,7 +83,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, struct drm_i915_gem_busy *args = data; struct drm_i915_gem_object *obj; struct reservation_object_list *list; - unsigned int seq; + struct dma_fence *excl; int err; err = -ENOENT; @@ -109,15 +109,12 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, * to report the overall busyness. This is what the wait-ioctl does. * */ -retry: - seq = raw_read_seqcount(&obj->base.resv->seq); + reservation_object_fences(obj->base.resv, &excl, &list); /* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = - busy_check_writer(rcu_dereference(obj->base.resv->fence_excl)); + args->busy = busy_check_writer(excl); /* Translate shared fences to READ set of engines */ - list = rcu_dereference(obj->base.resv->fence); if (list) { unsigned int shared_count = list->shared_count, i; @@ -129,9 +126,6 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, } } - if (args->busy && read_seqcount_retry(&obj->base.resv->seq, seq)) - goto retry; - err = 0; out: rcu_read_unlock(); From patchwork Tue Aug 6 15:01:31 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: 11085751 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 07EC614F7 for ; Fri, 9 Aug 2019 09:16:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92DD28B38 for ; Fri, 9 Aug 2019 09:16:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDC3F28C3E; Fri, 9 Aug 2019 09:16:30 +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=unavailable 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 A5C9D28C1E for ; Fri, 9 Aug 2019 09:16:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1557C6ED5F; Fri, 9 Aug 2019 09:15:49 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 003D76E3BB; Tue, 6 Aug 2019 15:01:41 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id p17so88224964wrf.11; Tue, 06 Aug 2019 08:01:41 -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=e09g/esR6Gc/6veKI4tptZ2siOvKJFGhd59QLPFyqW4=; b=ajsnRlvkyF5Ek7/ckfgBOPNEd9NDNJAOcehfPHQtok2TqIVvYRAdLVLAQoasIxCvFY XiZdihXMdW5+QQbYUIsaxb5LGDtG5405Rei0NjfaYzWHGCoONUq0ioYggX37KJLrUDkg Cy5zsF617kR4DGY4xdl6SFbA3sazbjIUfZfkFtHenC+td2DrDeBJtxe74RE3Bf2UdWRf atKbV0qxCVB3kgspB8ccXnl4H1U08RBcHeYF9IWhIFCdEwXvsv16gBPmDMIY0n35MvVL UTmFojCQyxXdEVZBjlq+V5AqQdw+srRGm88JnME8/UkBrmpF9kKMEdze8H8SjvVDhdaP sdXA== X-Gm-Message-State: APjAAAXAYTskv1ud1xeCUbPNbrGOapMrSNUvYvC5y3QqBN3Lxf070gsH 20WB5g0Jlno1/+tzKJegWUMV0ZGm X-Google-Smtp-Source: APXvYqxKVmwwaUkn9/+Ffdy8aAG3yGbikgU2djIIvoaLAmTQLo3pQr2c0LuucLBpvEKnEuOoSutCEw== X-Received: by 2002:a05:6000:112:: with SMTP id o18mr5520412wrx.153.1565103699969; Tue, 06 Aug 2019 08:01:39 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:39 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:31 +0200 Message-Id: <20190806150134.104222-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=e09g/esR6Gc/6veKI4tptZ2siOvKJFGhd59QLPFyqW4=; b=fpcKxPtS0XqaSscchhZzfKShzEYp2CXEXkpNM3xgvfd0gYScSfd1ebPFxlAZ8n00an JEOf5YYhrMtgIMiS8uQY1IY6bQZF0SKw77BpdcSK5sPC7iz8QZ+6po6sOL2tHfz7zVgi rQ4c7u+/m8Dlnym45AfqwQ2r5uU1mM9KLpfQT+qdyNVYxpXvpNhsuXrP2R/oaJYM49to ytR0v24YUPxTsc1U1nK1M7y/+gFzRrtF6aBBk/fx+zoOMiG9iAxgnH5m+UKWjgd7HWKT dxgLpgZrM+d2t4jGyxURXtS2Z3ghOlOPKOTHwHSYmhB0TM6jSAftcGhvb3JmAwHUoE+Y IsxQ== Subject: [Intel-gfx] [PATCH 5/8] dma-buf: further relax reservation_object_add_shared_fence X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Other cores don't busy wait any more and we removed the last user of checking the seqno for changes. Drop updating the number for shared fences altogether. Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 6 ------ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 +------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index c0ba05936ab6..944d962ddddf 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -237,9 +237,6 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, fobj = reservation_object_get_list(obj); count = fobj->shared_count; - preempt_disable(); - write_seqcount_begin(&obj->seq); - for (i = 0; i < count; ++i) { old = rcu_dereference_protected(fobj->shared[i], @@ -257,9 +254,6 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, RCU_INIT_POINTER(fobj->shared[i], fence); /* pointer update must be visible before we extend the shared_count */ smp_store_mb(fobj->shared_count, count); - - write_seqcount_end(&obj->seq); - preempt_enable(); dma_fence_put(old); } EXPORT_SYMBOL(reservation_object_add_shared_fence); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index fe062b76ec91..a4640ddc24d1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -251,12 +251,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, new->shared_max = old->shared_max; new->shared_count = k; - /* Install the new fence list, seqcount provides the barriers */ - preempt_disable(); - write_seqcount_begin(&resv->seq); - RCU_INIT_POINTER(resv->fence, new); - write_seqcount_end(&resv->seq); - preempt_enable(); + rcu_assign_pointer(resv->fence, new); /* Drop the references to the removed fences or move them to ef_list */ for (i = j, k = 0; i < old->shared_count; ++i) { From patchwork Tue Aug 6 15:01:32 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: 11085805 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 8BFF614F7 for ; Fri, 9 Aug 2019 09:16:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77DAE28B38 for ; Fri, 9 Aug 2019 09:16:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6873F28C3E; Fri, 9 Aug 2019 09:16:53 +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=unavailable 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 285CA28B38 for ; Fri, 9 Aug 2019 09:16:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2F0E6EDB7; Fri, 9 Aug 2019 09:15:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 02BDB6E3C4; Tue, 6 Aug 2019 15:01:42 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id a15so78545049wmj.5; Tue, 06 Aug 2019 08:01:42 -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=kQ9oFDS/I3lsIGSETmAE0qxXzfKIwv2YeSX45z+1rwU=; b=fQVuM/A64JTGGcNOsoZ2kPEo/0ARoMoNO3jN6rijXilF0BcmyfVogqFXf6X/CAeF2m Lgdpn/ZWTF6+KTdGy/kLUKKsNO4zNbkYiGCEctaRoHR1xNuJ9Kp6T27KZzPBE0nMARMR BxVIKGNbDvBd4NMSPPMR+ADxBKw3c7/k/dwICdXpmBmyqo2wfX+se0H1C2l8rKCFs7Sn FJVdwbOXKcDvUb+x03Cho0fM+6JgG0yVSeZtjdSq2My3gWDNrnhVZyXMmD4sHj/YH0G6 9PWKAfvoJTPxQBp32/8i0Jd7Rw9wwxgKRU9RCR7HTHnHMNghJiCX20+hAXtPDC+XAVs7 iIow== X-Gm-Message-State: APjAAAUdrfmAil9K9eWAR2kowDB6JbAma5g8r1R8Dd4R/F3Yklua3GDR 9HvP8bwFfB0cNwcciyy9Bxk0kMp/ X-Google-Smtp-Source: APXvYqwFCBO5hyfet3W1WHFKzyIH4Ndd/neVuTx3uu0wvJrvR5qA7G120GL5TnfpgpjOWpp47xu6aA== X-Received: by 2002:a1c:7fc3:: with SMTP id a186mr5558656wmd.151.1565103700841; Tue, 06 Aug 2019 08:01:40 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:40 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:32 +0200 Message-Id: <20190806150134.104222-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=kQ9oFDS/I3lsIGSETmAE0qxXzfKIwv2YeSX45z+1rwU=; b=i1cBb1BQCN0p4oigi/iL1jY9Ho82kwhliVr37bv5pVNV4lGHfgGAO5e2tp5LGhYirK GvjTL6iApeucBvKG2kg9ztQn5mKyjAw6BbGw6+gAadNS1A2mI4ni4s71DWfo3KQMNk85 CKVlnqevx663JQodzTby2c5zziquL5r6oRgVQI+HL7tzMidOg2OVWIq6G4ISmVO9zPS1 Yx+VET6ZJjOI7ICsip6/V1CYpAFrluAZEHvZq9HqFlni9TFeFVKQGcuXzTLOljSxvkJa IePV1EXoXoaPQXBfzhknFWitwHOMID+06JCPJMA6VmlYLMgEj5dBrjUWjsxI4jwBoT7P HLEw== Subject: [Intel-gfx] [PATCH 6/8] dma-buf: simplify reservation_object_get_fences_rcu a bit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP We can add the exclusive fence to the list after making sure we got a consistent state. Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 944d962ddddf..7505eb289023 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -453,13 +453,6 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, 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)) { @@ -474,6 +467,11 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, rcu_read_unlock(); } while (ret); + if (pfence_excl) + *pfence_excl = fence_excl; + else if (fence_excl) + shared[++shared_count] = fence_excl; + if (!shared_count) { kfree(shared); shared = NULL; @@ -481,9 +479,6 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, *pshared_count = shared_count; *pshared = shared; - if (pfence_excl) - *pfence_excl = fence_excl; - return ret; } EXPORT_SYMBOL_GPL(reservation_object_get_fences_rcu); From patchwork Tue Aug 6 15:01:33 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: 11085815 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 6E994912 for ; Fri, 9 Aug 2019 09:16:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CCBE28B38 for ; Fri, 9 Aug 2019 09:16:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50DC828C3E; Fri, 9 Aug 2019 09:16:58 +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=unavailable 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 AF72F28B38 for ; Fri, 9 Aug 2019 09:16:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 697B86EDA5; Fri, 9 Aug 2019 09:15:54 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA24A6E3BB; Tue, 6 Aug 2019 15:01:43 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id c2so85015224wrm.8; Tue, 06 Aug 2019 08:01:43 -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=zalB8gq1beSq4ta9XAvlbVYYxDTmwakxB9DRHWgejUg=; b=bKiHkqzBzPoVTOW9oEHqhYcZKI7EDvRC6qasEhxWo6ZcG6+mSt1HtYKi85gu2+znlZ CJeUH7KH0wdsuMfmeEgpGV2jCTQe3T0ZE6YfhM0xuGRR/KCN77YQHD5FNTF2skKt+S2D 4LzXs/FygbEqKAoZum+qPDmvyaqLrjkfZkvL75oo9/uJuJqATNYNbiIYSsWVab7UIC7Z QdydSn6cXBfnxU4KrEATTFUUOxQeWOB0qAYu7+FMVKGidnQroZXRifioE/OruF6C3AOk cP++eqjnlZdlNpcwxmnJWgnRvv3elfDM5ctbetvWUMIavx1sUMAXnm4oCBpJ19fqrAnJ hknA== X-Gm-Message-State: APjAAAXcbV9bZ1MPO/vPycEbD4ZSDdLmFvGLgfTNm6PRY4h7X04nccet mLDRtDfZwAbJViva0YABRi+wvtap X-Google-Smtp-Source: APXvYqxNjBUNUdlpAUZmAps4Mc7pazvmhMfBuAZ95n4cdBgcJvyHIK/6o9C2G5roYiFhLj2ePURWiA== X-Received: by 2002:adf:ea4c:: with SMTP id j12mr5533215wrn.75.1565103701601; Tue, 06 Aug 2019 08:01:41 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:41 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:33 +0200 Message-Id: <20190806150134.104222-7-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=zalB8gq1beSq4ta9XAvlbVYYxDTmwakxB9DRHWgejUg=; b=ZXS6v3F4t9G3Rblrcns1QtgET1Hg2p7hBG07F6V3LP5C7NQeSz04+/Zgp+SZezBKJr DSnzCvd+qTjpOw9SwkOYGHjdsrGR88Qh3B/VYjQMkS7J5U6NYw3/rYoGvNc3CpLMOmUf SSNGZHu0+l62OEJfyfA3kHm4F5ECdEeNs50LZQUhr16xSVnT03Q+Yp6dsaBe4WYVKCs5 MTHXxBQSwfJqP00LCwbD05ZQoqsqM+pp1cf+BsFrRAfOrDm6+SUgszfyW6WOyG3yunoz aSVuH6dKhRE57qQR0VABlNK/wn+7/7tKHSMCrDeXr/aH1vtBc6AqfJLvp/Dj04RaztiU 0JWw== Subject: [Intel-gfx] [PATCH 7/8] dma-buf: add reservation_object_fences helper X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP Add a new helper to get a consistent set of pointers from the reservation object. While at it group all access helpers together in the header file. Signed-off-by: Christian König --- drivers/dma-buf/dma-buf.c | 27 ++------ drivers/dma-buf/reservation.c | 60 ++++++------------ include/linux/reservation.h | 113 ++++++++++++++++++++-------------- 3 files changed, 94 insertions(+), 106 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index f45bfb29ef96..0d11b3cc961e 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -199,7 +199,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) struct reservation_object_list *fobj; struct dma_fence *fence_excl; __poll_t events; - unsigned shared_count, seq; + unsigned shared_count; dmabuf = file->private_data; if (!dmabuf || !dmabuf->resv) @@ -213,20 +213,12 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) if (!events) return 0; -retry: - seq = read_seqcount_begin(&resv->seq); rcu_read_lock(); - - fobj = rcu_dereference(resv->fence); + reservation_object_fences(resv, &fence_excl, &fobj); if (fobj) shared_count = fobj->shared_count; else shared_count = 0; - fence_excl = rcu_dereference(resv->fence_excl); - if (read_seqcount_retry(&resv->seq, seq)) { - rcu_read_unlock(); - goto retry; - } if (fence_excl && (!(events & EPOLLOUT) || shared_count == 0)) { struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_excl; @@ -1157,7 +1149,6 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) struct reservation_object *robj; struct reservation_object_list *fobj; struct dma_fence *fence; - unsigned seq; int count = 0, attach_count, shared_count, i; size_t size = 0; @@ -1188,16 +1179,10 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->name ?: ""); robj = buf_obj->resv; - while (true) { - seq = read_seqcount_begin(&robj->seq); - rcu_read_lock(); - fobj = rcu_dereference(robj->fence); - shared_count = fobj ? fobj->shared_count : 0; - fence = rcu_dereference(robj->fence_excl); - if (!read_seqcount_retry(&robj->seq, seq)) - break; - rcu_read_unlock(); - } + rcu_read_lock(); + reservation_object_fences(robj, &fence, &fobj); + shared_count = fobj ? fobj->shared_count : 0; + rcu_read_unlock(); if (fence) seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 7505eb289023..839d72af7ad8 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -316,9 +316,9 @@ int reservation_object_copy_fences(struct reservation_object *dst, reservation_object_assert_held(dst); rcu_read_lock(); - src_list = rcu_dereference(src->fence); retry: + reservation_object_fences(src, &new, &src_list); if (src_list) { unsigned shared_count = src_list->shared_count; @@ -329,7 +329,7 @@ int reservation_object_copy_fences(struct reservation_object *dst, return -ENOMEM; rcu_read_lock(); - src_list = rcu_dereference(src->fence); + reservation_object_fences(src, &new, &src_list); if (!src_list || src_list->shared_count > shared_count) { kfree(dst_list); goto retry; @@ -346,7 +346,6 @@ int reservation_object_copy_fences(struct reservation_object *dst, if (!dma_fence_get_rcu(fence)) { reservation_object_list_free(dst_list); - src_list = rcu_dereference(src->fence); goto retry; } @@ -361,7 +360,10 @@ int reservation_object_copy_fences(struct reservation_object *dst, dst_list = NULL; } - new = dma_fence_get_rcu_safe(&src->fence_excl); + if (new && !dma_fence_get_rcu(new)) { + reservation_object_list_free(dst_list); + goto retry; + } rcu_read_unlock(); src_list = reservation_object_get_list(dst); @@ -407,19 +409,17 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, do { struct reservation_object_list *fobj; - unsigned int i, seq; + unsigned int i; size_t sz = 0; shared_count = i = 0; rcu_read_lock(); - seq = read_seqcount_begin(&obj->seq); + reservation_object_fences(obj, &fence_excl, &fobj); - fence_excl = rcu_dereference(obj->fence_excl); if (fence_excl && !dma_fence_get_rcu(fence_excl)) goto unlock; - fobj = rcu_dereference(obj->fence); if (fobj) sz += sizeof(*shared) * fobj->shared_max; @@ -455,7 +455,7 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj, } } - if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) { + if (i != shared_count) { while (i--) dma_fence_put(shared[i]); dma_fence_put(fence_excl); @@ -499,18 +499,18 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj, bool wait_all, bool intr, unsigned long timeout) { + struct reservation_object_list *fobj; struct dma_fence *fence; - unsigned seq, shared_count; + unsigned shared_count; long ret = timeout ? timeout : 1; int i; retry: shared_count = 0; - seq = read_seqcount_begin(&obj->seq); rcu_read_lock(); i = -1; - fence = rcu_dereference(obj->fence_excl); + reservation_object_fences(obj, &fence, &fobj); if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { if (!dma_fence_get_rcu(fence)) goto unlock_retry; @@ -525,9 +525,6 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj, } if (wait_all) { - struct reservation_object_list *fobj = - rcu_dereference(obj->fence); - if (fobj) shared_count = fobj->shared_count; @@ -553,11 +550,6 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj, rcu_read_unlock(); if (fence) { - if (read_seqcount_retry(&obj->seq, seq)) { - dma_fence_put(fence); - goto retry; - } - ret = dma_fence_wait_timeout(fence, intr, ret); dma_fence_put(fence); if (ret > 0 && wait_all && (i + 1 < shared_count)) @@ -602,21 +594,20 @@ reservation_object_test_signaled_single(struct dma_fence *passed_fence) bool reservation_object_test_signaled_rcu(struct reservation_object *obj, bool test_all) { - unsigned seq, shared_count; + struct reservation_object_list *fobj; + struct dma_fence *fence_excl; + unsigned shared_count; int ret; rcu_read_lock(); retry: ret = true; shared_count = 0; - seq = read_seqcount_begin(&obj->seq); + reservation_object_fences(obj, &fence_excl, &fobj); if (test_all) { unsigned i; - struct reservation_object_list *fobj = - rcu_dereference(obj->fence); - if (fobj) shared_count = fobj->shared_count; @@ -629,23 +620,12 @@ bool reservation_object_test_signaled_rcu(struct reservation_object *obj, else if (!ret) break; } - - if (read_seqcount_retry(&obj->seq, seq)) - goto retry; } - if (!shared_count) { - struct dma_fence *fence_excl = rcu_dereference(obj->fence_excl); - - if (fence_excl) { - ret = reservation_object_test_signaled_single( - fence_excl); - if (ret < 0) - goto retry; - - if (read_seqcount_retry(&obj->seq, seq)) - goto retry; - } + if (!shared_count && fence_excl) { + ret = reservation_object_test_signaled_single(fence_excl); + if (ret < 0) + goto retry; } rcu_read_unlock(); diff --git a/include/linux/reservation.h b/include/linux/reservation.h index 56b782fec49b..b8b8273eef00 100644 --- a/include/linux/reservation.h +++ b/include/linux/reservation.h @@ -81,6 +81,51 @@ struct reservation_object { #define reservation_object_assert_held(obj) \ lockdep_assert_held(&(obj)->lock.base) +/** + * reservation_object_get_excl - get the reservation object's + * exclusive fence, with update-side lock held + * @obj: the reservation object + * + * Returns the exclusive fence (if any). Does NOT take a + * reference. Writers must hold obj->lock, readers may only + * hold a RCU read side lock. + * + * RETURNS + * The exclusive fence or NULL + */ +static inline struct dma_fence * +reservation_object_get_excl(struct reservation_object *obj) +{ + return rcu_dereference_protected(obj->fence_excl, + reservation_object_held(obj)); +} + +/** + * reservation_object_get_excl_rcu - get the reservation object's + * exclusive fence, without lock held. + * @obj: the reservation object + * + * If there is an exclusive fence, this atomically increments it's + * reference count and returns it. + * + * RETURNS + * The exclusive fence or NULL if none + */ +static inline struct dma_fence * +reservation_object_get_excl_rcu(struct reservation_object *obj) +{ + struct dma_fence *fence; + + if (!rcu_access_pointer(obj->fence_excl)) + return NULL; + + rcu_read_lock(); + fence = dma_fence_get_rcu_safe(&obj->fence_excl); + rcu_read_unlock(); + + return fence; +} + /** * reservation_object_get_list - get the reservation object's * shared fence list, with update-side lock held @@ -96,6 +141,29 @@ reservation_object_get_list(struct reservation_object *obj) reservation_object_held(obj)); } +/** + * reservation_object_fences - read consistent fence pointers + * @obj: reservation object where we get the fences from + * @excl: pointer for the exclusive fence + * @list: pointer for the shared fence list + * + * Make sure we have a consisten exclusive fence and shared fence list. + * Must be called with rcu read side lock held. + */ +static inline void +reservation_object_fences(struct reservation_object *obj, + struct dma_fence **excl, + struct reservation_object_list **list) +{ + unsigned int seq; + + do { + seq = read_seqcount_begin(&obj->seq); + *excl = rcu_dereference(obj->fence_excl); + *list = rcu_dereference(obj->fence); + } while (read_seqcount_retry(&obj->seq, seq)); +} + /** * reservation_object_lock - lock the reservation object * @obj: the reservation object @@ -239,51 +307,6 @@ reservation_object_unlock(struct reservation_object *obj) ww_mutex_unlock(&obj->lock); } -/** - * reservation_object_get_excl - get the reservation object's - * exclusive fence, with update-side lock held - * @obj: the reservation object - * - * Returns the exclusive fence (if any). Does NOT take a - * reference. Writers must hold obj->lock, readers may only - * hold a RCU read side lock. - * - * RETURNS - * The exclusive fence or NULL - */ -static inline struct dma_fence * -reservation_object_get_excl(struct reservation_object *obj) -{ - return rcu_dereference_protected(obj->fence_excl, - reservation_object_held(obj)); -} - -/** - * reservation_object_get_excl_rcu - get the reservation object's - * exclusive fence, without lock held. - * @obj: the reservation object - * - * If there is an exclusive fence, this atomically increments it's - * reference count and returns it. - * - * RETURNS - * The exclusive fence or NULL if none - */ -static inline struct dma_fence * -reservation_object_get_excl_rcu(struct reservation_object *obj) -{ - struct dma_fence *fence; - - if (!rcu_access_pointer(obj->fence_excl)) - return NULL; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&obj->fence_excl); - rcu_read_unlock(); - - return fence; -} - void reservation_object_init(struct reservation_object *obj); void reservation_object_fini(struct reservation_object *obj); int reservation_object_reserve_shared(struct reservation_object *obj, From patchwork Tue Aug 6 15:01:34 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: 11085789 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 A22B614F7 for ; Fri, 9 Aug 2019 09:16:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9283028B38 for ; Fri, 9 Aug 2019 09:16:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 863E728C3E; Fri, 9 Aug 2019 09:16:46 +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=unavailable 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 3D44F28B38 for ; Fri, 9 Aug 2019 09:16:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C82EE6ED5D; Fri, 9 Aug 2019 09:15:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EB1A6E3CB; Tue, 6 Aug 2019 15:01:44 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id v15so78568317wml.0; Tue, 06 Aug 2019 08:01:44 -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=D94FqstqyitIQXHeEQsOPjB7sJ7kjAHDkqtPAZA0I+c=; b=dct6UAyh3vbJoclyZY4pUdqh/DCpK7qo6GECq0PQ8+11sap4xUAlzz7/OzxmWtjO2X RqM6ku7OzF/QARKZRuM2Eeh2yInb9olB3Ov+D0s6qaU4pqW7hy1PGRTGiX4azDnVEQcx pRhmW+jTvS+a0YY8QdkqD7T5/pMFgwu04ta/kqu2BbP88jnbNTZmGE6X3wB7/bLl45bE gjnLnhl/7i/NaiRKI5/IM6ra6+V0LBcQGhQ2mfqKiMfj0xA73MjS032as1ikfA3a+LD8 6t8FgsF1DHJAy13ecg4ulJ/nYuY2pmvJCeHieFZghBxgm2euYAp/IWWTfcP63sJSDbj1 YEwQ== X-Gm-Message-State: APjAAAUmvdktdmYqQ1bgR9Jn7/vD1F2sT/KPVY2TJZHrAzId4oQNeINE 6R9mXnR3KwT7xjREqvbhO/NpYK6h X-Google-Smtp-Source: APXvYqxVBfSBzWr806NXfxriD36Qyrcq50LCUciaqzuU1GpHszpLqFGl7aaAig4jn/oBkn9mupsKrg== X-Received: by 2002:a05:600c:20c1:: with SMTP id y1mr5463840wmm.10.1565103702622; Tue, 06 Aug 2019 08:01:42 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d1e0:fffc:b0e3:c66d]) by smtp.gmail.com with ESMTPSA id g2sm78766828wmh.0.2019.08.06.08.01.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 08:01:41 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk Date: Tue, 6 Aug 2019 17:01:34 +0200 Message-Id: <20190806150134.104222-8-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806150134.104222-1-christian.koenig@amd.com> References: <20190806150134.104222-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Aug 2019 09:15:44 +0000 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=D94FqstqyitIQXHeEQsOPjB7sJ7kjAHDkqtPAZA0I+c=; b=Jo7LZ0mEPDJXyAIZ6sBJ5tR9F/lQmWIKR2ELB0DuExXdm13zXgXAol1XjMsLH+NY4v FzPP77jOfHKPgZfuUdvFBvYNilFsayxwmTvHo8Key3ombSEUz3X2KjUQxZoTRQ4lV5gI KTWygsFQdZlKzKhoEU9xyn6mi0/f/nBZAyBEcWjYin4YNiS2bg0y1iS6fuJ2yWS4A/// uevOjWsE5vZLQgDoc4/Buzq0Z6L8jCR5bu1yxiYwU9d9ULyUKaM2SDSMcbnRZwRabBmK 6mvKAxK1C0vEoBDLCBs9r36iIyQ2ERg4Gumlhr+RZqjvkHQ9YdRkEbLFgiGu2tiwxEMV lHsQ== Subject: [Intel-gfx] [PATCH 8/8] dma-buf: nuke reservation_object seq number X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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" X-Virus-Scanned: ClamAV using ClamSMTP The only remaining use for this is to protect against setting a new exclusive fence while we grab both exclusive and shared. That can also be archived by looking if the exclusive fence has changed or not after completing the operation. Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 20 +++----------------- include/linux/reservation.h | 9 ++------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 839d72af7ad8..43549a4d6658 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -49,12 +49,6 @@ DEFINE_WD_CLASS(reservation_ww_class); EXPORT_SYMBOL(reservation_ww_class); -struct lock_class_key reservation_seqcount_class; -EXPORT_SYMBOL(reservation_seqcount_class); - -const char reservation_seqcount_string[] = "reservation_seqcount"; -EXPORT_SYMBOL(reservation_seqcount_string); - /** * reservation_object_list_alloc - allocate fence list * @shared_max: number of fences we need space for @@ -103,9 +97,6 @@ static void reservation_object_list_free(struct reservation_object_list *list) void reservation_object_init(struct reservation_object *obj) { ww_mutex_init(&obj->lock, &reservation_ww_class); - - __seqcount_init(&obj->seq, reservation_seqcount_string, - &reservation_seqcount_class); RCU_INIT_POINTER(obj->fence, NULL); RCU_INIT_POINTER(obj->fence_excl, NULL); } @@ -282,12 +273,10 @@ void reservation_object_add_excl_fence(struct reservation_object *obj, dma_fence_get(fence); preempt_disable(); - write_seqcount_begin(&obj->seq); - /* write_seqcount_begin provides the necessary memory barrier */ RCU_INIT_POINTER(obj->fence_excl, fence); + /* pointer update must be visible before we modify the shared_count */ if (old) - old->shared_count = 0; - write_seqcount_end(&obj->seq); + smp_store_mb(old->shared_count, 0); preempt_enable(); /* inplace update, no shared fences */ @@ -370,11 +359,8 @@ int reservation_object_copy_fences(struct reservation_object *dst, old = reservation_object_get_excl(dst); 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); + rcu_assign_pointer(dst->fence, dst_list); preempt_enable(); reservation_object_list_free(src_list); diff --git a/include/linux/reservation.h b/include/linux/reservation.h index b8b8273eef00..1dfaf7b1f1da 100644 --- a/include/linux/reservation.h +++ b/include/linux/reservation.h @@ -46,8 +46,6 @@ #include extern struct ww_class reservation_ww_class; -extern struct lock_class_key reservation_seqcount_class; -extern const char reservation_seqcount_string[]; /** * struct reservation_object_list - a list of shared fences @@ -71,7 +69,6 @@ struct reservation_object_list { */ struct reservation_object { struct ww_mutex lock; - seqcount_t seq; struct dma_fence __rcu *fence_excl; struct reservation_object_list __rcu *fence; @@ -155,13 +152,11 @@ reservation_object_fences(struct reservation_object *obj, struct dma_fence **excl, struct reservation_object_list **list) { - unsigned int seq; - do { - seq = read_seqcount_begin(&obj->seq); *excl = rcu_dereference(obj->fence_excl); *list = rcu_dereference(obj->fence); - } while (read_seqcount_retry(&obj->seq, seq)); + smp_rmb(); /* See reservation_object_add_excl_fence */ + } while (rcu_access_pointer(obj->fence_excl) != *excl); } /**