From patchwork Thu Aug 1 02:25:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6BB81395 for ; Thu, 1 Aug 2019 02:25:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A976626E4A for ; Thu, 1 Aug 2019 02:25:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DC6A27F8C; Thu, 1 Aug 2019 02:25:38 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 5186328420 for ; Thu, 1 Aug 2019 02:25:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46C906E32D; Thu, 1 Aug 2019 02:25:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id 55C756E32D for ; Thu, 1 Aug 2019 02:25:35 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id c14so31321260plo.0 for ; Wed, 31 Jul 2019 19:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QvbbRut7SYudiOsU2n2lA4sGJ4wUL896ZrZu2J1BsIE=; b=s1hd8K9q0LtOVNsqZ7JbhpwqnOFlSqVaMSFD7AWvvl9H7XikUqOqH03nTdfLMOsvrk gDvITRb0Geik3oBP+v6gTvsaKD0fbu0MzTUbU4GAz3JTfvRhB3uCeULAPhxqzACPGHoB mg5KpV7xCrtC61RADm5enzMIyib8SnTabHWydy/HTSuPry/j/zfjxIjcMjWPXS9I50xR LdM9DO3o1LwSsGiW1p3HZC4P89KZzJec9nMMNeeAGOX8HxpWeeLui8v/PQtbRvg84opl i5I9nnKrTuPiQ42/dHQrFvs96xMfP7r5Ss15ws7mM2wwuQ7YnomVZJyaqYh1txReR+DR QH5A== X-Gm-Message-State: APjAAAUCJJXcuKM3jOiozwq0xhOYqhApaH/ox8upVyduCMieMO4evM+g KpSYapZSpfK5KVdkSyqM2rH940ycFG4= X-Google-Smtp-Source: APXvYqx9EQ/iEridVSbs0VaWuU/mPMV71Wkv5KtiuINAgmBf1jnESf72OXp8uprn2SGBCr3WrG1xaQ== X-Received: by 2002:a17:902:6b07:: with SMTP id o7mr120195283plk.180.1564626334404; Wed, 31 Jul 2019 19:25:34 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id v184sm64911342pgd.34.2019.07.31.19.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:33 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 6/6] udmabuf: implement begin_cpu_access/end_cpu_access hooks Date: Wed, 31 Jul 2019 19:25:17 -0700 Message-Id: <20190801022517.1903-7-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190801022517.1903-1-gurchetansingh@chromium.org> References: <20190801022517.1903-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QvbbRut7SYudiOsU2n2lA4sGJ4wUL896ZrZu2J1BsIE=; b=BEJ7kE6w6LUAMMFaU6XouTcalHjLQYWb3f0DILkf0ZEss4IGxMoefamHAxI7UuKcN8 yKsyjHpPgV3tsIShO/uL94feNTy0Q49X9TcdhhasXhejdMKsTva7uKnZjQm0DNoTtYBz a9QM+bFH5UduqoOv/71JgM/u8Csha8+381myI= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, Gurchetan Singh Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the misc device, we should end up using dma direct ops. This can allow us to have WC mappings in the guest after some synchronization, if we disallow cached mappings in the host. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 5f8bee1862de..52de7ba1e712 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -19,6 +19,7 @@ struct udmabuf { u32 flags; pgoff_t pagecount; struct page **pages; + struct sg_table *sg; struct miscdevice *udmabuf_misc; }; @@ -106,8 +107,12 @@ static void unmap_udmabuf(struct dma_buf_attachment *at, static void release_udmabuf(struct dma_buf *buf) { struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->udmabuf_misc->this_device; pgoff_t pg; + if (ubuf->sg) + put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); + for (pg = 0; pg < ubuf->pagecount; pg++) put_page(ubuf->pages[pg]); kfree(ubuf->pages); @@ -128,6 +133,38 @@ static void kunmap_udmabuf(struct dma_buf *buf, unsigned long page_num, kunmap(vaddr); } +static int begin_cpu_udmabuf(struct dma_buf *buf, + enum dma_data_direction direction) +{ + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->udmabuf_misc->this_device; + + if (!ubuf->sg) { + ubuf->sg = get_sg_table(dev, buf, direction); + if (IS_ERR(ubuf->sg)) + return PTR_ERR(ubuf->sg); + } else { + dma_sync_sg_for_device(dev, ubuf->sg->sgl, + ubuf->sg->nents, + direction); + } + + return 0; +} + +static int end_cpu_udmabuf(struct dma_buf *buf, + enum dma_data_direction direction) +{ + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->udmabuf_misc->this_device; + + if (!ubuf->sg) + return -EINVAL; + + dma_sync_sg_for_cpu(dev, ubuf->sg->sgl, ubuf->sg->nents, direction); + return 0; +} + static const struct dma_buf_ops udmabuf_ops = { .cache_sgt_mapping = true, .map_dma_buf = map_udmabuf, @@ -136,6 +173,8 @@ static const struct dma_buf_ops udmabuf_ops = { .map = kmap_udmabuf, .unmap = kunmap_udmabuf, .mmap = mmap_udmabuf, + .begin_cpu_access = begin_cpu_udmabuf, + .end_cpu_access = end_cpu_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK)