From patchwork Mon Aug 15 15:42:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9281473 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 6083260467 for ; Mon, 15 Aug 2016 15:42:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52ABB28D49 for ; Mon, 15 Aug 2016 15:42:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4758228D5B; Mon, 15 Aug 2016 15:42:44 +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=unavailable 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 7BCCA28D49 for ; Mon, 15 Aug 2016 15:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753023AbcHOPm1 (ORCPT ); Mon, 15 Aug 2016 11:42:27 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36072 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752927AbcHOPm0 (ORCPT ); Mon, 15 Aug 2016 11:42:26 -0400 Received: by mail-wm0-f65.google.com with SMTP id i138so11696282wmf.3; Mon, 15 Aug 2016 08:42:25 -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=jYBoMREPmDcSoVP7LKu6JAo12sLvlL3R6mSJjpTZ68o=; b=aEJVCWDKyaalQPg4HsqcWVMZF/WsPyvqDZpzcEFQsBV2+fkKKmE1lDHM209lIbNeb9 iVqPI1EaLZ2XNiVZsMEjcV9j6G6ipXSsVbQY1QRrdSv/P/6PIYlX9+5zupKQbwpssKOn mDTZHA4rOOPTK6bH7crWRcZUP30Gp3Gx/1ZhA0DJKpjtAQzcqF4f2m22+AiPJjuSxFy1 ilC8b52097rsGUExNM3g6rAB03BAClZ3y/L5tKYlLwtTzKp1uRi0NrOEyyzU7LeTU79T lUqZFCsfaKzXQn25FHu38KEvovbOiLfxj22qk50zbbidIWLkH8tCJcmNk7f17beVULrA 4Khg== 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=jYBoMREPmDcSoVP7LKu6JAo12sLvlL3R6mSJjpTZ68o=; b=B0DBYsKQsuDXcKWfcZkfrTxyBl8OBIxzSQv+YAasoyalLiIrejeQlhCf+ZpstAYc9C XsIGItRhKqZiGGDqsDEA2nuSX35de6tku1VFaDSjqY+Jy+6I98fG6xNa7ay+xo4a/O3N OTIPZC/U/zI9kQH6LmjggGCFaeazFYMCYM/vLiQQf6M6cfaqJbNEN2NgdoXqYAiJwSDw Wuort0TQs786T1rB0fkzp4fuQgTwc+cze1KZMdsL9ULi16YuHz+N2QJBZNxdNQwimas/ +bza7FjcxtlrcPeO+x61qVcrgNvf8cGCJTGiL1exGC98eu6qZC3XVuCZzeUbHimTQfql hH9Q== X-Gm-Message-State: AEkoouvrO2ETiPwfQu8w5GhxJyTkGImAzlMzSVW67JWTVF2P3xdhIRyJr08MSl8eY9782Q== X-Received: by 10.194.105.201 with SMTP id go9mr31644611wjb.177.1471275744558; Mon, 15 Aug 2016 08:42:24 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id w129sm17138969wmd.9.2016.08.15.08.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Aug 2016 08:42:23 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , Sumit Semwal , Daniel Vetter , Eric Anholt , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] dma-buf: Wait on the reservation object when sync'ing before CPU access Date: Mon, 15 Aug 2016 16:42:18 +0100 Message-Id: <1471275738-31994-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466492640-12551-1-git-send-email-chris@chris-wilson.co.uk> References: <1466492640-12551-1-git-send-email-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 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.) v2: Always wait upon the reservation object implicitly. We choose to do it after the native handler in case it can do so more efficiently. Testcase: igt/prime_vgem Testcase: igt/gem_concurrent_blit # *vgem* Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: Daniel Vetter Cc: Eric Anholt 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 Reviewed-by: Daniel Vetter --- drivers/dma-buf/dma-buf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index ddaee60ae52a..cf04d249a6a4 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 = dmabuf->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 @@ -608,6 +624,13 @@ int dma_buf_begin_cpu_access(struct dma_buf *dmabuf, if (dmabuf->ops->begin_cpu_access) ret = dmabuf->ops->begin_cpu_access(dmabuf, direction); + /* Ensure that all fences are waited upon - but we first allow + * the native handler the chance to do so more efficiently if it + * chooses. A double invocation here will be reasonably cheap no-op. + */ + if (ret == 0) + ret = __dma_buf_begin_cpu_access(dmabuf, direction); + return ret; } EXPORT_SYMBOL_GPL(dma_buf_begin_cpu_access);