From patchwork Wed Jan 4 14:12:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9496971 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 9AEE8606B5 for ; Wed, 4 Jan 2017 14:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BED427F94 for ; Wed, 4 Jan 2017 14:12:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E90F27FA5; Wed, 4 Jan 2017 14:12:43 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 0568527F94 for ; Wed, 4 Jan 2017 14:12:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D42446E733; Wed, 4 Jan 2017 14:12:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x242.google.com (mail-wj0-x242.google.com [IPv6:2a00:1450:400c:c01::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id E43E86E26D; Wed, 4 Jan 2017 14:12:29 +0000 (UTC) Received: by mail-wj0-x242.google.com with SMTP id j10so75817374wjb.3; Wed, 04 Jan 2017 06:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=FBHZlwlbZpDvZl9ETq9Yh2RI+EwGzN1dIibJ3U2Jqow=; b=AE/7zgVAse3QwDoZe3D3Rf1y16NSzvbt+nlVVO/qAXJj4OMM4P9hbrwT7D1/XxUmhW nbFYSINObF+8WO+IcgwEtrvP0A+1jIHFZvqZUpPNN56OBE/SFOdqTInFT1yMju657+u5 LVYPfYKDoX922tRuxOWaj00QqwMkninIRkHWSiWu36yRxICV1Ik8XCjDUfcJqGmTMJFv 0h7OhE6M5nE1ytb49R0KwAG+wMKzYgEWcQKdI/yfEnaRLwApk34hWsi5N5RfJ5YOOj+C uiG/GmAs/WDRDY/SiVxNtkzygk5RswLyZfVr7+7BKctBIfRvKJh31HfKsKYXZiL+szIl mpHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=FBHZlwlbZpDvZl9ETq9Yh2RI+EwGzN1dIibJ3U2Jqow=; b=g7ErRG6LVfPk9Z63QIChMr/SBQ9Jsv6Zt2F4wE+yFxFgQqfeLL8lD1si955ZwRKNPw 9UrVqY88hrqnwkZB2GIP+XFW1BlMlu7nQtabNzdHlR1LmFWaare7Arju6sq3ATxPmm2j kzcVvdY20qYLJu/adP8N64iVpCKxC9QoHR+uIcZK+PcASM+gsKrlwgncyhxip7eLI1hp R/5Oxwc/uW+N2mX7gusSjUBG/GTQcqeaCvCl37zLFTEOoIZZrVWyD24TVjvhVHo+f5Y1 yOhLXF74EK69py0rchel6d/omcD78kYV0SlThdTpMuYiFQOoAcQL4/PaL6nXXizpAOJk RXog== X-Gm-Message-State: AIkVDXKx7Eqhp1JnFtUIPJqTFHkqL9TKph9O8z7QzQd6f6PRJWuyIxiUaAuCJbX/D6t6kg== X-Received: by 10.194.158.100 with SMTP id wt4mr71255864wjb.148.1483539147890; Wed, 04 Jan 2017 06:12:27 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id y4sm98658888wjp.0.2017.01.04.06.12.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 06:12:27 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] dma-fence: Introduce drm_fence_set_error() helper Date: Wed, 4 Jan 2017 14:12:22 +0000 Message-Id: <20170104141222.6992-3-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170104141222.6992-1-chris@chris-wilson.co.uk> References: <20170104141222.6992-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The dma_fence.error field (formerly known as dma_fence.status) is an optional field that may be set by drivers before calling dma_fence_signal(). The field can be used to indicate that the fence was completed in err rather than with success, and is visible to other consumers of the fence and to userspace via sync_file. This patch renames the field from status to error so that its meaning is hopefully more clear (and distinct from dma_fence_get_status() which is a composite between the error state and signal state) and adds a helper that validates the preconditions of when it is suitable to adjust the error field. Signed-off-by: Chris Wilson --- drivers/dma-buf/dma-fence.c | 2 +- include/linux/dma-fence.h | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 7d936d19e659..ee82f36cb25e 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -559,7 +559,7 @@ dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, fence->context = context; fence->seqno = seqno; fence->flags = 0UL; - fence->status = 0; + fence->error = 0; trace_dma_fence_init(fence); } diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 19f7af905182..6048fa404e57 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -47,7 +47,7 @@ struct dma_fence_cb; * can be compared to decide which fence would be signaled later. * @flags: A mask of DMA_FENCE_FLAG_* defined below * @timestamp: Timestamp when the fence was signaled. - * @status: Optional, only valid if < 0, must be set before calling + * @error: Optional, only valid if < 0, must be set before calling * dma_fence_signal, indicates that the fence has completed with an error. * * the flags member must be manipulated and read using the appropriate @@ -79,7 +79,7 @@ struct dma_fence { unsigned seqno; unsigned long flags; ktime_t timestamp; - int status; + int error; }; enum dma_fence_flag_bits { @@ -133,7 +133,7 @@ struct dma_fence_cb { * or some failure occurred that made it impossible to enable * signaling. True indicates successful enabling. * - * fence->status may be set in enable_signaling, but only when false is + * fence->error may be set in enable_signaling, but only when false is * returned. * * Calling dma_fence_signal before enable_signaling is called allows @@ -145,7 +145,7 @@ struct dma_fence_cb { * the second time will be a noop since it was already signaled. * * Notes on signaled: - * May set fence->status if returning true. + * May set fence->error if returning true. * * Notes on wait: * Must not be NULL, set to dma_fence_default_wait for default implementation. @@ -395,13 +395,33 @@ static inline struct dma_fence *dma_fence_later(struct dma_fence *f1, static inline int dma_fence_get_status_locked(struct dma_fence *fence) { if (dma_fence_is_signaled_locked(fence)) - return fence->status < 0 ? fence->status : 1; + return fence->error ?: 1; else return 0; } int dma_fence_get_status(struct dma_fence *fence); +/** + * dma_fence_set_error - flag an error condition on the fence + * @fence: [in] the dma_fence + * @error: [in] the error to store + * + * Drivers can supply an optional error status condition before they signal + * the fence, to indicate that the fence was completed due to an error + * rather than success. This must be set before signaling (so that the value + * is visible before any waiters on the signal callback are woken). This + * helper exists to help catching erroneous setting of #dma_fence.error. + */ +static inline void dma_fence_set_error(struct dma_fence *fence, + int error) +{ + BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)); + BUG_ON(error >= 0 || error < -MAX_ERRNO); + + fence->error = error; +} + signed long dma_fence_wait_timeout(struct dma_fence *, bool intr, signed long timeout); signed long dma_fence_wait_any_timeout(struct dma_fence **fences,