From patchwork Wed Aug 7 13:53:12 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: 11085943 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 37BA91395 for ; Fri, 9 Aug 2019 09:18:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2894128BBC for ; Fri, 9 Aug 2019 09:18:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ADE528C3E; Fri, 9 Aug 2019 09:18:56 +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 C450228BBC for ; Fri, 9 Aug 2019 09:18:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2788A6EDC0; Fri, 9 Aug 2019 09:18:39 +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 E44406E6F2; Wed, 7 Aug 2019 13:53:17 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id s15so125911wmj.3; Wed, 07 Aug 2019 06:53:17 -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=d8jxvxkDjIwnMjhFTSMRgIlDZ9fe5+CUfRdDQUfjjTk=; b=guOtJIVPHlK5kElhWKglHIxNrCkpVycoMXXNb9pkoeQak51au/tQ78+M2vn81oOg+I xJhHdzF0UQA/KS/b5sD1T2qwHGUZmZ/PmT6YEhkCo598FqDAI17lO+6jeHy5SaKrPlEA +0NFuBXMRptjFlZ7WfkpwH2AumSnPafc9MCNwoJuBA9pyybaXBWrxFmSxYZSOWxaQiVE iqb9zskkclver2T0lEq8fd2rgqRexQzHigBRSaGktRnzNME1GTACo0x/AsyebidOX0r7 3ojmzTtnJP4Dbm9eoeqTbziXJ44dF+g9hjo3nEnhKFKHy3LQ5r+esWo5F7uz2UGxliB3 uGfg== X-Gm-Message-State: APjAAAWD4gVy/jnlT9iRyIAhkQM38BVGUhaQFPFO9HvwRV1VqO/5stxd p5ja8hMH5XLZ+tioZXWAM2F7yolG X-Google-Smtp-Source: APXvYqx1KiSb9cYKBbrhej0Vgz0jnW2VjWvV6uIAlyHQqbIHWZaUNxdeATR3xgB8lWmnJ0j95IYz6A== X-Received: by 2002:a1c:c14b:: with SMTP id r72mr100474wmf.166.1565185996096; Wed, 07 Aug 2019 06:53:16 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:645a:5b76:280d:27be]) by smtp.gmail.com with ESMTPSA id o11sm33095wmh.37.2019.08.07.06.53.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 06:53:15 -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: Wed, 7 Aug 2019 15:53:12 +0200 Message-Id: <20190807135312.1730-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190807135312.1730-1-christian.koenig@amd.com> References: <20190807135312.1730-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=d8jxvxkDjIwnMjhFTSMRgIlDZ9fe5+CUfRdDQUfjjTk=; b=l6OK5z62ltfC1P3dB6qeIuXpK6RqmJIHkQUvgjcBSF1fmhHGS7kL5BDOLPnoYDs3d1 KWfbh5hb3LeYG+b3amKoxASddIKvRfUfCs4YKmxlDB2V75YE24ibf4fvzoubIG9vrALM bDOeZtsNIMeXxZFoGO/0J08FnSh3wUTCmrHS/mQ4oHaAQVbqcfPGDmNFPXmPOA3Z/z8B 1GhQdoAEKjQl2/7BXvpasLh4Yli6pMyLtlT7dEgbuxjds8ur8tgeKEYfFBox7crw4T5/ rY93oItJ/ronaQLnWozsFXhLRv72jPjOJbOc2NRxOQpU99sy1tKBE6vr0WHTbSNHjB9k SPkw== Subject: [Intel-gfx] [PATCH 4/4] 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. v2: switch setting excl fence to rcu_assign_pointer Signed-off-by: Christian König --- drivers/dma-buf/reservation.c | 24 +++++------------------- include/linux/reservation.h | 9 ++------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 90bc6ef03598..f7f4a0858c2a 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); + rcu_assign_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 */ @@ -368,11 +357,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_excl, new); + 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 044a5cd4af50..fd29baad0be3 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; @@ -156,14 +153,12 @@ reservation_object_fences(struct reservation_object *obj, struct reservation_object_list **list, u32 *shared_count) { - unsigned int seq; - do { - seq = read_seqcount_begin(&obj->seq); *excl = rcu_dereference(obj->fence_excl); *list = rcu_dereference(obj->fence); *shared_count = *list ? (*list)->shared_count : 0; - } while (read_seqcount_retry(&obj->seq, seq)); + smp_rmb(); /* See reservation_object_add_excl_fence */ + } while (rcu_access_pointer(obj->fence_excl) != *excl); } /**