From patchwork Sat Aug 4 09:52:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10555653 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 56D6E6CB for ; Sat, 4 Aug 2018 09:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3642F27853 for ; Sat, 4 Aug 2018 09:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27A882A49B; Sat, 4 Aug 2018 09:52:50 +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 8064C27853 for ; Sat, 4 Aug 2018 09:52:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79C0F6E066; Sat, 4 Aug 2018 09:52:48 +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 D881F6E066 for ; Sat, 4 Aug 2018 09:52:46 +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 12603279-1500050 for multiple; Sat, 04 Aug 2018 10:52:38 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Sat, 4 Aug 2018 10:52:36 +0100 Message-Id: <20180804095236.24584-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.18.0 Subject: [Intel-gfx] [PATCH] drm/i915: Enforce TYPESAFE_BY_RCU vs refcount mb on reinitialisation 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP By using TYPESAFE_BY_RCU, we accept that requests may be swapped out from underneath us, even when using rcu_read_lock(). We use a strong barrier on acquiring the refcount during lookup, but this needs to be paired with a barrier on re-initialising it. Currently we call dma_fence_init, which ultimately does a plain atomic_set(1) on the refcount, not providing any memory barriers. As we inspect some state before even acquiring the refcount in the lookup (by arguing that we can detect inconsistent requests), that state should be initialised before the refcount. Signed-off-by: Chris Wilson Reviewed-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_request.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c index 5c2c93cbab12..04a0b8e75533 100644 --- a/drivers/gpu/drm/i915/i915_request.c +++ b/drivers/gpu/drm/i915/i915_request.c @@ -768,6 +768,13 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx) rq->timeline = ce->ring->timeline; GEM_BUG_ON(rq->timeline == &engine->timeline); + /* + * In order to coordinate with our RCU lookup, + * __i915_gem_active_get_rcu(), we need to ensure that the change + * to rq->engine is visible before acquring the refcount in the lookup. + */ + smp_wmb(); + spin_lock_init(&rq->lock); dma_fence_init(&rq->fence, &i915_fence_ops,