From patchwork Thu Aug 1 02:25:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070059 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 8220314DB for ; Thu, 1 Aug 2019 02:25:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756D2271FD for ; Thu, 1 Aug 2019 02:25:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69CD128474; Thu, 1 Aug 2019 02:25:27 +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 2C702271FD for ; Thu, 1 Aug 2019 02:25:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 051106E328; Thu, 1 Aug 2019 02:25:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 35D696E328 for ; Thu, 1 Aug 2019 02:25:25 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id t132so33143587pgb.9 for ; Wed, 31 Jul 2019 19:25:25 -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=IRUFnP4ofqonZexYeBGxV7EVAaZ3+L9vOKlLz0P0sBE=; b=f1MrXjDTtxpZMTS7mxwBVPuu8RlgSrj1FO3RRkV6lH5Ip8hKx/Vni+kN8Ru3q5IEEb rREi8GYo4yt8IyZhfi0Ow3xwLULGKRnPq+XoGVqOyPhaccsjA/eNZG+TovmfBuVS/Jry mZh/VAxJQYFqNZfaq8rMX3pGRhZdAQDIWaArIYi6XR1NDTnQ3jC+suOs8Kmu2te8pxc1 nIoljkqTZaYvs/SqVlmMKKuBH1Psb9FU2KXvj48DqYaZuV1QxviLGTxJiSs6gbOnNGo9 7veNWMBODmJoOwLif8mrB2cMbAVK92YK7Rec8B3doraHFkY2nlggY+/1YpBPlyQ2EuXD T2Tg== X-Gm-Message-State: APjAAAV5j18NakkVPmtP3lCdAzMBYdsfDMihwTzKMbXks38VOvJBSP4R wX3J/fxXz0ZzJAoXu8SdUgyLB78h/nw= X-Google-Smtp-Source: APXvYqxnEf6tanCWOd7XHEZwQLGuokiyY3veACgkT17VoC/OmESe7RwNDr0OwYtYY6g3sEZYcFW4DQ== X-Received: by 2002:a63:784c:: with SMTP id t73mr120019199pgc.268.1564626324589; Wed, 31 Jul 2019 19:25:24 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:24 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 1/6] udmabuf: use cache_sgt_mapping option Date: Wed, 31 Jul 2019 19:25:12 -0700 Message-Id: <20190801022517.1903-2-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=IRUFnP4ofqonZexYeBGxV7EVAaZ3+L9vOKlLz0P0sBE=; b=cOCUiIiQFNLIG5NkhQrvEw3Bke0+QcCd3EPbakpe4elRzFmgsNIiBs7auPFY95B5rM 4YKbT8Wls5WiL/uTkhycV+f+6BjdXVxIQXQTXnyAsQURt21vZCg7ronpYO7viaJ/cdmw fvzJooSHG4tiF3FFE/PelD3z1Btc3FE/ELXdQ= 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 The GEM prime helpers do it, so should we. It's also possible to make it optional later. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 9635897458a0..b345e91d831a 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -108,12 +108,13 @@ static void kunmap_udmabuf(struct dma_buf *buf, unsigned long page_num, } static const struct dma_buf_ops udmabuf_ops = { - .map_dma_buf = map_udmabuf, - .unmap_dma_buf = unmap_udmabuf, - .release = release_udmabuf, - .map = kmap_udmabuf, - .unmap = kunmap_udmabuf, - .mmap = mmap_udmabuf, + .cache_sgt_mapping = true, + .map_dma_buf = map_udmabuf, + .unmap_dma_buf = unmap_udmabuf, + .release = release_udmabuf, + .map = kmap_udmabuf, + .unmap = kunmap_udmabuf, + .mmap = mmap_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK) From patchwork Thu Aug 1 02:25:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070061 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 E1DFE14DB for ; Thu, 1 Aug 2019 02:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4FEE279E0 for ; Thu, 1 Aug 2019 02:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C93072847B; Thu, 1 Aug 2019 02:25:30 +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 7B4C728474 for ; Thu, 1 Aug 2019 02:25:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B69276E32A; Thu, 1 Aug 2019 02:25:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by gabe.freedesktop.org (Postfix) with ESMTPS id D09086E329 for ; Thu, 1 Aug 2019 02:25:27 +0000 (UTC) Received: by mail-pg1-x541.google.com with SMTP id d1so335540pgp.4 for ; Wed, 31 Jul 2019 19:25:27 -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=4/7lPl2rj2poXuP1vja8rgzK2p3rrqxqlKXCKLI5Gto=; b=f3DkMkkFedmTcTw5j5lrrber8iLzXxpsIKXT7bV/eHnTRgE/11UlCK21ZlPO1FyGAg YlBWpCyU6guKiKmtmxr41KCs7q6v4xldFTRyEYaL/ug77kV9rYYg1wV8tKOFxBK8jcJ4 eLY1xmtVMwDgS0kq+S3M4BfVUeyr3WAm29yzh9+uEyrRfx5JJOlr7/LzrREQIXQEn0z9 SrwSmMHdA5+34OOX8a+XhuBM6r6w0uReDRcJ+8a61MGYyghEp90PhEvkkXDDAvPFzmQ7 WtEr4AEGQKLjXArLjSMMlVvpshler4VN0LsvEyqRAJFnLWHtKz0rTPjPeJEBPm3+Znyz qKOw== X-Gm-Message-State: APjAAAWNftO0DBW2iKymk6SOmYWO3JEKEAESXcxQv9AVHQFaTEaMAaBt 9fTx4uG04ZmkAYamiiBQkT9MLtu32JY= X-Google-Smtp-Source: APXvYqyTgNA+YaDJtYUagVkxrlKlk1ovxvcfhMQCeIvTz1aod7hwAMYQ8L9ZUBBr8aIgeWpfm8tinQ== X-Received: by 2002:aa7:957c:: with SMTP id x28mr50375901pfq.42.1564626326973; Wed, 31 Jul 2019 19:25:26 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:26 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 2/6] udmabuf: add ability to set access flags on udmabuf Date: Wed, 31 Jul 2019 19:25:13 -0700 Message-Id: <20190801022517.1903-3-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=4/7lPl2rj2poXuP1vja8rgzK2p3rrqxqlKXCKLI5Gto=; b=IHg6oecjlDp60ex8JeF95PK5CARL4+ekOWZv75Om8ifP8nadS8rErNorIUH/DrDtL5 VWB8Rlt+IRHjOdhVOqYw8hS07D990c44TquhL9M8MjHWA1xxuXJ5p+dZ47z/S4qIl16m sOC0sWbJ3D8t8Oci+RbBBGCN4w/6psn3HBp/A= 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 The main use for udmabuf is sending guest memory pages to the host. It's generally a bad idea to have to separate mappings with different attributes. For example, a WC mapping the guest kernel and cached mapping on the host is problematic. Add creation time flags so the user has responsibility for the specific use case. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 7 ++++++- include/uapi/linux/udmabuf.h | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index b345e91d831a..4ecf2a94fed3 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -186,7 +186,12 @@ static long udmabuf_create(const struct udmabuf_create_list *head, exp_info.ops = &udmabuf_ops; exp_info.size = ubuf->pagecount << PAGE_SHIFT; exp_info.priv = ubuf; - exp_info.flags = O_RDWR; + + if ((head->flags & UDMABUF_FLAGS_PROT_READ) && + (head->flags & UDMABUF_FLAGS_PROT_WRITE)) + exp_info.flags = O_RDWR; + else if (head->flags & UDMABUF_FLAGS_PROT_WRITE) + exp_info.flags = O_WRONLY; buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { diff --git a/include/uapi/linux/udmabuf.h b/include/uapi/linux/udmabuf.h index 46b6532ed855..21290cb9696c 100644 --- a/include/uapi/linux/udmabuf.h +++ b/include/uapi/linux/udmabuf.h @@ -5,7 +5,10 @@ #include #include -#define UDMABUF_FLAGS_CLOEXEC 0x01 +#define UDMABUF_FLAGS_CLOEXEC 0x01 +#define UDMABUF_FLAGS_PROT_NONE 0x02 +#define UDMABUF_FLAGS_PROT_READ 0x04 +#define UDMABUF_FLAGS_PROT_WRITE 0x08 struct udmabuf_create { __u32 memfd; From patchwork Thu Aug 1 02:25:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070063 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 E07641395 for ; Thu, 1 Aug 2019 02:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C1E279E0 for ; Thu, 1 Aug 2019 02:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C50BB2842E; Thu, 1 Aug 2019 02:25:32 +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 824B8279E0 for ; Thu, 1 Aug 2019 02:25:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5CFD16E329; Thu, 1 Aug 2019 02:25:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id A5AD46E329 for ; Thu, 1 Aug 2019 02:25:29 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id f5so24336034pgu.5 for ; Wed, 31 Jul 2019 19:25:29 -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=H9h2eOHI19m4MgM2BOei5v6mTo70vlCQrz3vNu1i0QM=; b=Ob3PHh/dsTJdCRThnm91aQS7QScMUOEJXUnMHhyhuz2MYRmBzEVobC5cs7wMozjMO0 hhTDe8aWQX7M/hwDxTK7mLvUWJg1QT2LeGHfWPJT43ReWi7yPAPlnnnh1dVGOI6cFY69 a0LJBNPz7x5CoBQMMjFf7TBB+xa3KIC1G8lf17xcy6XH8OiFOcX12TwGaDvVAzjnQSvP fguqiJpxT9SLpFM6tVSw62tfxV9WY9d2ecR6SGwCGlrTa1fowK4srb27HDvkyxLDmXWf VCMYTk9lvzzoR4DfVqpIdbul8X0wWqg4vth9nnXggw80ASdDG8AzA6uYYx5vDpINC4Sd uaxw== X-Gm-Message-State: APjAAAXhI5kZTqn9T/e5kn72etjzZ0czBGdkC4OBRDWDCPa80Bk9tvwp MUvcRT8MYVpr+olTjYsnzR66LDK3BL0= X-Google-Smtp-Source: APXvYqyRZkjhTL983RjLEs8pa8qMi9QOutiMIPQTpukWAodsn80ULJtGgESXHCbgbUl3rKBFfkLJqA== X-Received: by 2002:a62:8c81:: with SMTP id m123mr50215315pfd.240.1564626329062; Wed, 31 Jul 2019 19:25:29 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:28 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 3/6] udmabuf: enforce access flags Date: Wed, 31 Jul 2019 19:25:14 -0700 Message-Id: <20190801022517.1903-4-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=H9h2eOHI19m4MgM2BOei5v6mTo70vlCQrz3vNu1i0QM=; b=AIra+EQEpb4wc6gCcFJv9rN3p6XwzOOoD5pQIW06Vzlmm6PTQBmTaiUJqpAyGzSWI5 uIVDQ8aKyYv/6wzEBfZqWE9kEmcHgwGEpcrtIFlkO3s9oVWX4wClstkvlKYP728rPYKh WWFd0wDrmYYSmsPJDC0EGmAV2pf0L+CULBZyk= 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 Enforce the access flags that were added earlier. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 4ecf2a94fed3..134e53d24c2b 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -16,6 +16,7 @@ static const u32 list_limit = 1024; /* udmabuf_create_list->count limit */ static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes */ struct udmabuf { + u32 flags; pgoff_t pagecount; struct page **pages; }; @@ -37,10 +38,17 @@ static const struct vm_operations_struct udmabuf_vm_ops = { static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) { struct udmabuf *ubuf = buf->priv; + pgprot_t pgprot = vm_get_page_prot(vma->vm_flags); if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) return -EINVAL; + if (ubuf->flags & UDMABUF_FLAGS_PROT_NONE) + return -EINVAL; + + if ((ubuf->flags & UDMABUF_FLAGS_PROT_READ) == 0) + vma->vm_page_prot = pgprot_writecombine(pgprot); + vma->vm_ops = &udmabuf_vm_ops; vma->vm_private_data = ubuf; return 0; @@ -193,6 +201,7 @@ static long udmabuf_create(const struct udmabuf_create_list *head, else if (head->flags & UDMABUF_FLAGS_PROT_WRITE) exp_info.flags = O_WRONLY; + ubuf->flags = head->flags; buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { ret = PTR_ERR(buf); From patchwork Thu Aug 1 02:25:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070065 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 E994614DB for ; Thu, 1 Aug 2019 02:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9CF926E4A for ; Thu, 1 Aug 2019 02:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDD8128387; Thu, 1 Aug 2019 02:25:34 +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 8B2D528450 for ; Thu, 1 Aug 2019 02:25:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 04EC36E32B; Thu, 1 Aug 2019 02:25:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id C412C6E32B for ; Thu, 1 Aug 2019 02:25:31 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id f5so24336088pgu.5 for ; Wed, 31 Jul 2019 19:25:31 -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=aqzKKaGa1dMKS5TEWbDe5hgoGbuaIfQmr4ypPKza0bE=; b=TJkt5/HpNmJd0mf8iaeVNMsZlS//azY9z+HZigDpYjEsiEWLmT2jrhnnQZvZsb6FoL Am/DqKAFyev1Lk+7Nq2KL9zpEcRu1b9FhoDJtvdi+2cirSD50uThqRjFMEkITHoDbzgS MkOdkEu47dOcFZgr4cMsoBnFJgoujZuWUWujV5/W7zMEq6/A8sjqKfpLmIoOR7X+DbTn +IN6joUR4+KUhCz8uspZMO9y3uldH7FNl4QBCitXnKSRAQZLY87IU9xRoW6aSqU0/jwa vZSQ6l5/2wqeBrAQ5Gwrg7XCvYPpCEC130rzcDtvB1DvkpQCZ/jziLECU+T9+2fYA3JJ z9hQ== X-Gm-Message-State: APjAAAU3Pdc/cjm80VjQF9sPRapNF73kytglbngTarDadaJZlbqH6yg+ vUWG9F2QtISIGECRndPe7585BLhWyuE= X-Google-Smtp-Source: APXvYqykm4/wbMFEnio1+swJf0kTMDYIAJtKEVV29lUNUbgXTTk0Yamvi0pOaMwRDwodJiYIwv7LaQ== X-Received: by 2002:a17:90b:f0f:: with SMTP id br15mr6016904pjb.101.1564626331018; Wed, 31 Jul 2019 19:25:31 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:30 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 4/6] udmabuf: add a pointer to the miscdevice in dma-buf private data Date: Wed, 31 Jul 2019 19:25:15 -0700 Message-Id: <20190801022517.1903-5-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=aqzKKaGa1dMKS5TEWbDe5hgoGbuaIfQmr4ypPKza0bE=; b=QGzbZnIZlkhzuGiQ7HcGh7FVCpfzJV8UZoZ1QAnRdbzdxhWG1chSVnma22iDqMAmgw N70urbm7YYTVYGb+ACIVrDoTUelX19LFt2UFiegzCO4C3xzmxH5p46llM9jfj0cwW7sq /TkHDFPLvZed9pwsDhwd0NOASpAEJPugha580= 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 Will be used later. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 134e53d24c2b..47003abbf4c2 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 miscdevice *udmabuf_misc; }; static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) @@ -128,7 +129,8 @@ static const struct dma_buf_ops udmabuf_ops = { #define SEALS_WANTED (F_SEAL_SHRINK) #define SEALS_DENIED (F_SEAL_WRITE) -static long udmabuf_create(const struct udmabuf_create_list *head, +static long udmabuf_create(struct miscdevice *udmabuf_misc, + struct udmabuf_create_list *head, const struct udmabuf_create_item *list) { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); @@ -202,6 +204,7 @@ static long udmabuf_create(const struct udmabuf_create_list *head, exp_info.flags = O_WRONLY; ubuf->flags = head->flags; + ubuf->udmabuf_misc = udmabuf_misc; buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { ret = PTR_ERR(buf); @@ -239,7 +242,7 @@ static long udmabuf_ioctl_create(struct file *filp, unsigned long arg) list.offset = create.offset; list.size = create.size; - return udmabuf_create(&head, &list); + return udmabuf_create(filp->private_data, &head, &list); } static long udmabuf_ioctl_create_list(struct file *filp, unsigned long arg) @@ -258,7 +261,7 @@ static long udmabuf_ioctl_create_list(struct file *filp, unsigned long arg) if (IS_ERR(list)) return PTR_ERR(list); - ret = udmabuf_create(&head, list); + ret = udmabuf_create(filp->private_data, &head, list); kfree(list); return ret; } From patchwork Thu Aug 1 02:25:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070067 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 C900F14DB for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBF3C283C5 for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B086A281B7; Thu, 1 Aug 2019 02:25:36 +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 67A4C281B7 for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 22B886E32C; Thu, 1 Aug 2019 02:25:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8B146E32C for ; Thu, 1 Aug 2019 02:25:33 +0000 (UTC) Received: by mail-pl1-x630.google.com with SMTP id i2so31413816plt.1 for ; Wed, 31 Jul 2019 19:25:33 -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=RDvIT98WsFO1A5PQ+Bn6K/2QWwxhiilUGERAplpzShI=; b=R+wBVKCgasscXToa75B4XLI/nMmcyTr6MusOp3wx5NNQbxlUC733Sflp967OtqXZjD arUTS8oaCstehjwOpC50lFUVishPbWXcHOgEJTjrm2QLxCR342e0X86vFFMLbwxCU2rr qjWSOl5HYK7afNRZjE2xujFYmThi8javp+UIbHvBrhTpXj4vNKSQCOtGINoWYT9WAg/V 4trpueL0L/Z5+NZlK1l7+sLydLq+PWXzCg3PaVUkau6ff4Uo7+agS0SkeFZ72FM/pE9o CoDvnZpkicmh/+dxSuvPVREwiemWka/KtsQwh1LoVbEmN1LXT1WaUEea2jiFXofDS7Z4 3dyA== X-Gm-Message-State: APjAAAWO5K6Kr0JY6+eb97L4pWiZDrpuM62O/hN7TIH0+AwFl9jnXtqA VSgogpbEhgJS+5Tn5Sbfs2B1SvSspX4= X-Google-Smtp-Source: APXvYqyqIE6py30J7i0lRa2X7+ywni7gnB0WlXAB74Ovn29umnskJhTjJreAqc3Fya83sxLxQvx61Q== X-Received: by 2002:a17:902:ab83:: with SMTP id f3mr123239894plr.122.1564626332843; Wed, 31 Jul 2019 19:25:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:32 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 5/6] udmabuf: separate out creating/destroying scatter-table Date: Wed, 31 Jul 2019 19:25:16 -0700 Message-Id: <20190801022517.1903-6-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=RDvIT98WsFO1A5PQ+Bn6K/2QWwxhiilUGERAplpzShI=; b=hYQMYIcex1tChcdz+V+2cHB1R1TDYmvDvHaNhx5Wyp9PT21EY8p9RhsUXKWImDT1fo rPQMrxiwwptBMp0p6teXmzMNDHJ7F0xF2/TVo2f/JX/Pki5Sut0vHreHoMlqWE0SGMsS vubg6a0KuANLkCEOdfvIQz1kduBIHUJ3e6D0I= 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 Reused later. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 47003abbf4c2..5f8bee1862de 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -55,10 +55,10 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) return 0; } -static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, - enum dma_data_direction direction) +static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, + enum dma_data_direction direction) { - struct udmabuf *ubuf = at->dmabuf->priv; + struct udmabuf *ubuf = buf->priv; struct sg_table *sg; int ret; @@ -70,7 +70,7 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, GFP_KERNEL); if (ret < 0) goto err; - if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction)) { + if (!dma_map_sg(dev, sg->sgl, sg->nents, direction)) { ret = -EINVAL; goto err; } @@ -82,13 +82,25 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, return ERR_PTR(ret); } +static void put_sg_table(struct device *dev, struct sg_table *sg, + enum dma_data_direction direction) +{ + dma_unmap_sg(dev, sg->sgl, sg->nents, direction); + sg_free_table(sg); + kfree(sg); +} + +static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, + enum dma_data_direction direction) +{ + return get_sg_table(at->dev, at->dmabuf, direction); +} + static void unmap_udmabuf(struct dma_buf_attachment *at, struct sg_table *sg, enum dma_data_direction direction) { - dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction); - sg_free_table(sg); - kfree(sg); + return put_sg_table(at->dev, sg, direction); } static void release_udmabuf(struct dma_buf *buf) 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)