From patchwork Tue Aug 13 20:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11092797 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 9AF77746 for ; Tue, 13 Aug 2019 20:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83EE628736 for ; Tue, 13 Aug 2019 20:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77FCB28737; Tue, 13 Aug 2019 20:09:17 +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,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 1E88F28736 for ; Tue, 13 Aug 2019 20:09:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D67AD89F69; Tue, 13 Aug 2019 20:09:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id A4C6189F69 for ; Tue, 13 Aug 2019 20:09:14 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 18027969-1500050 for multiple; Tue, 13 Aug 2019 21:09:07 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 13 Aug 2019 21:09:05 +0100 Message-Id: <20190813200905.11369-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.23.0.rc1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/i915: Serialise read/write of the barrier's engine 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 use the request pointer inside the i915_active_node as the indicator of the barrier's status; we mark it as used during i915_request_add_active_barriers(), and search for an available barrier in reuse_idle_barrier(). That check must be carefully serialised to ensure we do use an engine for the barrier and not just a random pointer. (Along the other reuse path, we are fully serialised by the timeline->mutex.) The acquisition of the barrier itself is ordered through the strong memory barrier in llist_del_all(). Fixes: d8af05ff38ae ("drm/i915: Allow sharing the idle-barrier from other kernel requests") Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_active.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_active.c b/drivers/gpu/drm/i915/i915_active.c index 7698fcaa648a..2439c4f62ad8 100644 --- a/drivers/gpu/drm/i915/i915_active.c +++ b/drivers/gpu/drm/i915/i915_active.c @@ -52,11 +52,17 @@ static inline struct llist_node *barrier_to_ll(struct active_node *node) return (struct llist_node *)&node->base.link; } +static inline struct intel_engine_cs * +__barrier_to_engine(struct active_node *node) +{ + return (struct intel_engine_cs *)READ_ONCE(node->base.link.prev); +} + static inline struct intel_engine_cs * barrier_to_engine(struct active_node *node) { GEM_BUG_ON(!is_barrier(&node->base)); - return (struct intel_engine_cs *)node->base.link.prev; + return __barrier_to_engine(node); } static inline struct active_node *barrier_from_ll(struct llist_node *x) @@ -239,10 +245,11 @@ void __i915_active_init(struct drm_i915_private *i915, __mutex_init(&ref->mutex, "i915_active", key); } -static bool __active_del_barrier(struct i915_active *ref, - struct active_node *node) +static bool ____active_del_barrier(struct i915_active *ref, + struct active_node *node, + struct intel_engine_cs *engine) + { - struct intel_engine_cs *engine = barrier_to_engine(node); struct llist_node *head = NULL, *tail = NULL; struct llist_node *pos, *next; @@ -280,6 +287,12 @@ static bool __active_del_barrier(struct i915_active *ref, return !node; } +static bool +__active_del_barrier(struct i915_active *ref, struct active_node *node) +{ + return ____active_del_barrier(ref, node, barrier_to_engine(node)); +} + int i915_active_ref(struct i915_active *ref, u64 timeline, struct i915_request *rq) @@ -517,6 +530,7 @@ static struct active_node *reuse_idle_barrier(struct i915_active *ref, u64 idx) for (p = prev; p; p = rb_next(p)) { struct active_node *node = rb_entry(p, struct active_node, node); + struct intel_engine_cs *engine; if (node->timeline > idx) break; @@ -534,7 +548,10 @@ static struct active_node *reuse_idle_barrier(struct i915_active *ref, u64 idx) * the barrier before we claim it, so we have to check * for success. */ - if (is_barrier(&node->base) && __active_del_barrier(ref, node)) + engine = __barrier_to_engine(node); + smp_rmb(); /* serialise with add_active_barriers */ + if (is_barrier(&node->base) && + ____active_del_barrier(ref, node, engine)) goto match; } @@ -674,6 +691,7 @@ void i915_request_add_active_barriers(struct i915_request *rq) */ llist_for_each_safe(node, next, llist_del_all(&engine->barrier_tasks)) { RCU_INIT_POINTER(barrier_from_ll(node)->base.request, rq); + smp_wmb(); /* serialise with reuse_idle_barrier */ list_add_tail((struct list_head *)node, &rq->active_list); } }