From patchwork Mon Aug 29 07:08:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9303193 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 84C5B607F0 for ; Mon, 29 Aug 2016 07:22:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E082287C7 for ; Mon, 29 Aug 2016 07:22:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A2E28811; Mon, 29 Aug 2016 07:22:35 +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 58740287C7 for ; Mon, 29 Aug 2016 07:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756136AbcH2HWd (ORCPT ); Mon, 29 Aug 2016 03:22:33 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34874 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756135AbcH2HWc (ORCPT ); Mon, 29 Aug 2016 03:22:32 -0400 Received: by mail-wm0-f65.google.com with SMTP id i5so8250480wmg.2 for ; Mon, 29 Aug 2016 00:22:01 -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 :mime-version:content-transfer-encoding; bh=ggf/rVhDt5H1flZ75klY3yMZpGyK9iXnglCVH2257rY=; b=qpxiKSEnXBAMTnj5+2UNTRrBcUQsYXdiO0zp6VDupPF0oSPRbzDbvIP0fgimKW4Ufn S05m07YcjwOf9DCuQUosOtGI/BO5wMSC4SROkq8ONPW29mLibQrt3RsTaKbOjNAs1DDL ktu8LfrMOHeYxb/ppgWxFB2qmn8j2TCyNzs83trwpzQ0il0t/Nd/P+j49KtpLiXU53H0 buLhZiYaRIXnGtusD4s7tQZ4uupOE7/VrrgQHXTHRkNRgKmCV716/eKQMlzDvd0uLv1t 3Dsgum/6DSorDxonxcJ//RxHP1w/vzANZb3C8ARmmMQCXjWjdXAQGOB/s7Nj6p9dF41k VY0g== 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:mime-version:content-transfer-encoding; bh=ggf/rVhDt5H1flZ75klY3yMZpGyK9iXnglCVH2257rY=; b=Gwl56tOwwk2X/9t/2GF02Cu85g6uO1ZHXKwNQxGmaNjmArqIRNxMGLE2mT+GjOpx5P 48fPtIm6MiUoIazey6+GCw109GiSjcyZm6sYXXyOb6RZ+bFE6nNAuY8OC84wSYam7/AA 3rMszio+VGn0XfcebgBeCUIaPXVv/b1l9n0+U1quLj3uDZSGcjZaEGf2wYLdGpl87hqq NtqEryG0pkX5jRxZF6cH8sWqW3oEE3b0LoIwPwLO5CYJcjHW6VDRapKjHnl3fDqNdj0D z67Tj3h/soHJOkAuX6QsqVtBt2p2A9ljolRHktwKm+vGTJ2lAW/Q58doq7ZAz5qDrg5L WnzA== X-Gm-Message-State: AE9vXwNixxCLIRUmJuvQBG7jwK8Luap7es39VrjvwKbARHS4xKsp0rz0Py2Jil7EVZkB1w== X-Received: by 10.28.197.129 with SMTP id v123mr8703824wmf.70.1472454530128; Mon, 29 Aug 2016 00:08:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Aug 2016 00:08:49 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , Daniel Vetter , Maarten Lankhorst , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Sumit Semwal , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 08/11] dma-buf: Restart reservation_object_wait_timeout_rcu() after writes Date: Mon, 29 Aug 2016 08:08:31 +0100 Message-Id: <20160829070834.22296-8-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> MIME-Version: 1.0 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 In order to be completely generic, we have to double check the read seqlock after acquiring a reference to the fence. If the driver is allocating fences from a SLAB_DESTROY_BY_RCU, or similar freelist, then within an RCU grace period a fence may be freed and reallocated. The RCU read side critical section does not prevent this reallocation, instead we have to inspect the reservation's seqlock to double check if the fences have been reassigned as we were acquiring our reference. Signed-off-by: Chris Wilson Cc: Daniel Vetter Cc: Maarten Lankhorst Cc: Christian König Cc: Alex Deucher Cc: Sumit Semwal Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Reviewed-by: Daniel Vetter --- drivers/dma-buf/reservation.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 10fd441dd4ed..3369e4668e96 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -388,9 +388,6 @@ retry: if (fobj) shared_count = fobj->shared_count; - if (read_seqcount_retry(&obj->seq, seq)) - goto unlock_retry; - for (i = 0; i < shared_count; ++i) { struct fence *lfence = rcu_dereference(fobj->shared[i]); @@ -413,9 +410,6 @@ retry: if (!shared_count) { struct fence *fence_excl = rcu_dereference(obj->fence_excl); - if (read_seqcount_retry(&obj->seq, seq)) - goto unlock_retry; - if (fence_excl && !test_bit(FENCE_FLAG_SIGNALED_BIT, &fence_excl->flags)) { if (!fence_get_rcu(fence_excl)) @@ -430,6 +424,11 @@ retry: rcu_read_unlock(); if (fence) { + if (read_seqcount_retry(&obj->seq, seq)) { + fence_put(fence); + goto retry; + } + ret = fence_wait_timeout(fence, intr, ret); fence_put(fence); if (ret > 0 && wait_all && (i + 1 < shared_count))