From patchwork Mon Aug 29 07:08:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9303187 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 78FAB607F0 for ; Mon, 29 Aug 2016 07:20:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62B9F287B8 for ; Mon, 29 Aug 2016 07:20:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56E5328811; Mon, 29 Aug 2016 07:20: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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6F78287CD for ; Mon, 29 Aug 2016 07:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756190AbcH2HUv (ORCPT ); Mon, 29 Aug 2016 03:20:51 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34654 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750828AbcH2HUv (ORCPT ); Mon, 29 Aug 2016 03:20:51 -0400 Received: by mail-wm0-f65.google.com with SMTP id q128so8245975wma.1 for ; Mon, 29 Aug 2016 00:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6nBuARNwrf2gL7VLJgRnZ/tCBxt7U97AsKLYWADaqFo=; b=Huj/sWq9sn2XTMYYd7JeEmzJbjTQsrf1AKiz4yD9JSKh+q1AlNJHNZughgrpKwWjxa YPjjaX0uv8erQ7/eTQgtwBnXqKzPNH5AT1U8VitMB9srmeYL7FdQhCoOloL4QMetFFwi LHDQU6lCMvBRTdC2K6NPyzxAUK08znno2CvDAjup3GP2omDg2UIC6UJ6pcOGm58ighbt 516bAXhxKioakli2t28ED67l//vztZUzZoUFQQwK3eKWeF7HOwEPNWkBydTaqxORKQX8 6mSkbSzLY9bE2L3H9/5ubSs0FVK0wHbCTDMXXeLaJzRyeGHjCUl9e906A01nc4HUJFs8 d5MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6nBuARNwrf2gL7VLJgRnZ/tCBxt7U97AsKLYWADaqFo=; b=EQXVFsAMefLsaq0N9tCRc6+ETQEdnYLocMWkUoJmePZU3DbN4J6PV1xXZNTWVhPAyM z+jGWu3IKTdKhDn6rh9ea+cnzfbH+YA9SCqawMx6SxSJMMqiTgqgA7dk2ZGR2W6vOZN7 cVGhxw8cPFsQ0jpaiCPFyRZlDEmQlkwapNw6KTXM8RRFg3ZaqNPItkEzWWvW3W/Nik9f 4+Q6UJl/QBbLzBTGAlpt5f5Zyh9rwu9n7B9Hs2NIQ7VZpl9y1n7AbT0+LZYGQEup75XU rK2nlhPQ9/sFDu1bgOKD+jg8jTp2lAHi5vWUyNZiBukUvTKl7Lfzg0X8xaxsjNlkpo5E ZaKg== X-Gm-Message-State: AE9vXwPgVqo//Nn25KhXBzCctrwdNMvhorEVvWODKBcZN/2x98u2aucTVZYYRkX19/INKg== X-Received: by 10.28.113.20 with SMTP id m20mr8697838wmc.82.1472454532565; Mon, 29 Aug 2016 00:08:52 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v203sm11954826wmv.2.2016.08.29.00.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 00:08:51 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , Sumit Semwal , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 10/11] dma-buf: Use seqlock to close RCU race in test_signaled_single Date: Mon, 29 Aug 2016 08:08:33 +0100 Message-Id: <20160829070834.22296-10-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160829070834.22296-1-chris@chris-wilson.co.uk> References: <20160829070834.22296-1-chris@chris-wilson.co.uk> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the seqlock now extended to cover the lookup of the fence and its testing, we can perform that testing solely under the seqlock guard and avoid the effective locking and serialisation of acquiring a reference to the request. As the fence is RCU protected we know it cannot disappear as we test it, the same guarantee that made it safe to acquire the reference previously. The seqlock tests whether the fence was replaced as we are testing it telling us whether or not we can trust the result (if not, we just repeat the test until stable). Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org --- drivers/dma-buf/reservation.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index e74493e7332b..1ddffa5adb5a 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -442,24 +442,6 @@ unlock_retry: } EXPORT_SYMBOL_GPL(reservation_object_wait_timeout_rcu); - -static inline int -reservation_object_test_signaled_single(struct fence *passed_fence) -{ - struct fence *fence, *lfence = passed_fence; - int ret = 1; - - if (!test_bit(FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) { - fence = fence_get_rcu(lfence); - if (!fence) - return -1; - - ret = !!fence_is_signaled(fence); - fence_put(fence); - } - return ret; -} - /** * reservation_object_test_signaled_rcu - Test if a reservation object's * fences have been signaled. @@ -474,7 +456,7 @@ bool reservation_object_test_signaled_rcu(struct reservation_object *obj, bool test_all) { unsigned seq, shared_count; - int ret; + bool ret; rcu_read_lock(); retry: @@ -494,10 +476,8 @@ retry: for (i = 0; i < shared_count; ++i) { struct fence *fence = rcu_dereference(fobj->shared[i]); - ret = reservation_object_test_signaled_single(fence); - if (ret < 0) - goto retry; - else if (!ret) + ret = fence_is_signaled(fence); + if (!ret) break; } @@ -509,11 +489,7 @@ retry: struct fence *fence_excl = rcu_dereference(obj->fence_excl); if (fence_excl) { - ret = reservation_object_test_signaled_single( - fence_excl); - if (ret < 0) - goto retry; - + ret = fence_is_signaled(fence_excl); if (read_seqcount_retry(&obj->seq, seq)) goto retry; }