From patchwork Wed Nov 2 17:00:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9409535 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 A7684601C2 for ; Wed, 2 Nov 2016 17:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 969262A49A for ; Wed, 2 Nov 2016 17:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 897FC2A49C; Wed, 2 Nov 2016 17:00:40 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 96C402A49A for ; Wed, 2 Nov 2016 17:00:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18F236E5B6; Wed, 2 Nov 2016 17:00:39 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5F056E5B6 for ; Wed, 2 Nov 2016 17:00:36 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id 68so3981913wmz.2 for ; Wed, 02 Nov 2016 10:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=CTFaCOtkwy6RlV3crLxwhlCp9LuArq+ilVbf2biYtGE=; b=Mg8ONp2gtEImMibW+ZsAPNQxKFVjMRsQn6Punb8gcJ5VTBWlFBMuCH91wy7zxf+l69 aXljxSokYiK8U1CkRJSQ+3XjtQ2zeB6p5zz4v8cBwqTG30vwCyvlBLSBx/4ZKc1yCw+G m/+C2srcakDG9Cy2N/XaGijrIKTtgPCCdJNxhoc6S+gFMxDsUsiuFEufo1k5CLmyaxz4 3aoMu8sxaZODcozjajU526ZYm7kmAtovfUwAvjix6zmnZ6HJUJupx0mu9SGvzD6QODIH V34QnqTwwMgqoVfoA8s8+urTcZI4P4iyAac0fTz00NQ2Htn6K64yDaSU74TPasg7NO+2 En3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CTFaCOtkwy6RlV3crLxwhlCp9LuArq+ilVbf2biYtGE=; b=GPSBL/7zKhBaWnjWPabQli3PGm1gw0jzdzrCJPk+z5TNA9IftfTqEXpeIRcomALYPd SRfz3sbWLrLcaOFpBkhdD5qZ21HGqTD4gUBQ6hlwFH8WbVxeQ5BDSfTie3AWYKjFULCh cQAf9/Yt3x4bXQRCHx6iZdJeV1FBea4PlnY+ZgDVeNATuKS9eJYb1vwm2xfrLa1YWafa Jid0JRLEJiwVnGfDZ8BK7Pube0czVHTkQA5EVJtrq8sJ12LLEbSX0iAsSuad+mwPGMsw XmkefS7M09FhrAkpsukGMkuufx8j2sbCGErgOMeQ6d+VcLMmvepxleMqE1mM/39gpEHX upZQ== X-Gm-Message-State: ABUngvfGxyqNoTOldqJ5Q2/Xp4N88+bvvOY5ntjesx2ak2SMvi+IN3g4PeEttiQut1wlFw== X-Received: by 10.28.209.139 with SMTP id i133mr4027377wmg.53.1478106035142; Wed, 02 Nov 2016 10:00:35 -0700 (PDT) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id k17sm37464367wmd.8.2016.11.02.10.00.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 10:00:34 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 2 Nov 2016 17:00:28 +0000 Message-Id: <1478106028-27602-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 Subject: [Intel-gfx] [PATCH] drm/i915/sw_fence: Replace private use of wq->flags with bit zero in wq->private X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 From: Tvrtko Ursulin Use of an un-allocated bit in flags is making me nervous so I thought to use the bit zero of the private pointer instead. That should be safer against the core kernel changes and safe since I can't imagine we can get a fence at the odd address. Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson --- drivers/gpu/drm/i915/i915_sw_fence.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_sw_fence.c b/drivers/gpu/drm/i915/i915_sw_fence.c index 95f2f12e0917..cd4d6b915848 100644 --- a/drivers/gpu/drm/i915/i915_sw_fence.c +++ b/drivers/gpu/drm/i915/i915_sw_fence.c @@ -13,7 +13,8 @@ #include "i915_sw_fence.h" -#define I915_SW_FENCE_FLAG_ALLOC BIT(3) /* after WQ_FLAG_* for safety */ +#define I915_SW_FENCE_FLAG_ALLOC (1) +#define I915_SW_FENCE_PRIVATE_MASK ~(I915_SW_FENCE_FLAG_ALLOC) static DEFINE_SPINLOCK(i915_sw_fence_lock); @@ -132,12 +133,17 @@ void i915_sw_fence_commit(struct i915_sw_fence *fence) i915_sw_fence_put(fence); } +#define wq_to_i915_sw_fence(wq) (struct i915_sw_fence *) \ + ((unsigned long)(wq)->private & I915_SW_FENCE_PRIVATE_MASK) + static int i915_sw_fence_wake(wait_queue_t *wq, unsigned mode, int flags, void *key) { + struct i915_sw_fence *fence = wq_to_i915_sw_fence(wq); + list_del(&wq->task_list); - __i915_sw_fence_complete(wq->private, key); - i915_sw_fence_put(wq->private); - if (wq->flags & I915_SW_FENCE_FLAG_ALLOC) + __i915_sw_fence_complete(fence, key); + i915_sw_fence_put(fence); + if ((unsigned long)wq->private & I915_SW_FENCE_FLAG_ALLOC) kfree(wq); return 0; } @@ -157,7 +163,8 @@ static bool __i915_sw_fence_check_if_after(struct i915_sw_fence *fence, if (wq->func != i915_sw_fence_wake) continue; - if (__i915_sw_fence_check_if_after(wq->private, signaler)) + if (__i915_sw_fence_check_if_after(wq_to_i915_sw_fence(wq), + signaler)) return true; } @@ -175,7 +182,7 @@ static void __i915_sw_fence_clear_checked_bit(struct i915_sw_fence *fence) if (wq->func != i915_sw_fence_wake) continue; - __i915_sw_fence_clear_checked_bit(wq->private); + __i915_sw_fence_clear_checked_bit(wq_to_i915_sw_fence(wq)); } } @@ -221,13 +228,14 @@ static int __i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence, return 0; } - pending |= I915_SW_FENCE_FLAG_ALLOC; + pending = I915_SW_FENCE_FLAG_ALLOC; } INIT_LIST_HEAD(&wq->task_list); - wq->flags = pending; wq->func = i915_sw_fence_wake; wq->private = i915_sw_fence_get(fence); + BUG_ON((unsigned long)wq->private & I915_SW_FENCE_FLAG_ALLOC); + wq->private = (void *)((unsigned long)wq->private | pending); i915_sw_fence_await(fence);