From patchwork Tue Jun 21 07:04:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9189613 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 7DD5A60756 for ; Tue, 21 Jun 2016 07:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6473427F8C for ; Tue, 21 Jun 2016 07:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57A0827FAC; Tue, 21 Jun 2016 07:04:23 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7103627F8C for ; Tue, 21 Jun 2016 07:04:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C54B6E204; Tue, 21 Jun 2016 07:04:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lb0-x241.google.com (mail-lb0-x241.google.com [IPv6:2a00:1450:4010:c04::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 263A36E224 for ; Tue, 21 Jun 2016 07:04:17 +0000 (UTC) Received: by mail-lb0-x241.google.com with SMTP id ur4so685949lbc.3 for ; Tue, 21 Jun 2016 00:04:17 -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; bh=zJk0SPp1GQeyHdhzk30SZvpPZVF0NzwvKQZoSpHW0cw=; b=cehfNIoVcObxx5XCXozBVdrrboJS2iABycaOSexfTVqCJXP290U618Y9Lh2Hl6voQh 2n5hihlpPEfWMDiRDHqBwxODdmZ4Bp0rzuowAqujH9eR6OMFtWjblrjes2s8mJ7erudF h+jJb+lQzTcWXUWZ2d8ii/Mnpn/PVo3NWBVS1FD1wnolzHFo/kXYPs5AHHPplIH+R88h h3FFtH3wfWBqxVY8EVzC5mOh8vDqj2J5JTeebOfgHNO6fmo8IJvdnd0+np2KXnVEHnYm pfockJkrwDtXboWzD/4OY12Tg3hxjgFukzG9zAnBFz6ZBrKkmeML4Y7wJ4V10kN78wXs 02Sg== 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; bh=zJk0SPp1GQeyHdhzk30SZvpPZVF0NzwvKQZoSpHW0cw=; b=EtI8op76TdtpNROXFP4ICxJB6DN1TK6bzQCv3NZ/g6yLMd5ulNc+cgkuFBmcIoOr+6 JujdRCvEnQoZm/mE29vQtTippavqIuwRSJK75AidSbUV+gAjr1ECvvd4UFiKJkmB5KUO naM7RAC0AzeH43WoZdpn+c7IXD/VAqP5jCCxwpENJ1gckghzS8b4tLiIhHAN4uxZZY/z 8JmoY/gpbNd3JBxNjwk+xp7xTu6I2OjduTfW1m88l2WBaqr4eSHQJol1hCP7PBI/U8qj icW0WN3xAo4iI9PdAF6PSkJIfHVQSWm+6zxcuoEXVQjCXHvE4yPUNJ8v9FJ9bCNaRXv0 6Ypw== X-Gm-Message-State: ALyK8tKjNnNpy+coT2RM7juYV4ZzNi9sSI8KFnx13G0GTX1156gWQxeIY5lYF7N+qpeJUQ== X-Received: by 10.194.55.136 with SMTP id s8mr17399925wjp.134.1466492655156; Tue, 21 Jun 2016 00:04:15 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id t198sm1415947wmt.16.2016.06.21.00.04.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 00:04:13 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] dma-buf: Wait on the reservation object when sync'ing before CPU access Date: Tue, 21 Jun 2016 08:04:00 +0100 Message-Id: <1466492640-12551-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 Cc: Daniel Vetter , linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.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 Rendering operations to the dma-buf are tracked implicitly via the reservation_object (dmabuf->resv). This is used to allow poll() to wait upon outstanding rendering (or just query the current status of rendering). The dma-buf sync ioctl allows userspace to prepare the dma-buf for CPU access, which should include waiting upon rendering. (Some drivers may need to do more work to ensure that the dma-buf mmap is coherent as well as complete.) Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: Daniel Vetter Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Cc: linux-kernel@vger.kernel.org --- I'm wondering whether it makes sense just to always do the wait first. It is one of the first operations every driver has to make. A driver that wants to implement it differently (e.g. they can special case native waits) will still require a wait on the reservation object to finish external rendering. -Chris --- drivers/dma-buf/dma-buf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index ddaee60ae52a..123f14b8e882 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -586,6 +586,22 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, } EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment); +static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + bool write = (direction == DMA_BIDIRECTIONAL || + direction == DMA_TO_DEVICE); + struct reservation_object *resv = dma_buf->resv; + long ret; + + /* Wait on any implicit rendering fences */ + ret = reservation_object_wait_timeout_rcu(resv, write, true, + MAX_SCHEDULE_TIMEOUT); + if (ret < 0) + return ret; + + return 0; +} /** * dma_buf_begin_cpu_access - Must be called before accessing a dma_buf from the @@ -607,6 +623,8 @@ int dma_buf_begin_cpu_access(struct dma_buf *dmabuf, if (dmabuf->ops->begin_cpu_access) ret = dmabuf->ops->begin_cpu_access(dmabuf, direction); + else + ret = __dma_buf_begin_cpu_access(dmabuf, direction); return ret; }