From patchwork Tue Dec 3 01:36:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8788413B6 for ; Tue, 3 Dec 2019 01:36:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62D6A206E1 for ; Tue, 3 Dec 2019 01:36:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62D6A206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 022106E042; Tue, 3 Dec 2019 01:36:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by gabe.freedesktop.org (Postfix) with ESMTPS id D60E66E042 for ; Tue, 3 Dec 2019 01:36:35 +0000 (UTC) Received: by mail-pj1-x1044.google.com with SMTP id l4so747365pjt.5 for ; Mon, 02 Dec 2019 17:36:35 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=eyMX2jKq1sPFGtoRJAfpFto0SNDC6mF6mb3kZ39tKjo=; b=pzogdz6Yu2Sa/j8vaPos47bQJcBZfPaiMvWxdXXzI1UwilqbMt+/6Eu80aoN3INMvT 9IeW91Hd5UC2SZ1P1b+jCUyRNPo7wSUORzLBD5nvY04/n34Iz0LuRHCrtsV0s1qjtEiz XGgIe8mynjxfZsclJjmQMgXrMaIb50KUjsrzZIQObL2EDcaCzDzBNuBRmjzGuWfhjzG8 MJK0pkFpGcrIIPILKnJ14TagqnjvlW8hkHxAiocuJNSw24WYONqIowpKC+Jf7twr3CFe +8LK/4cVhSCrqvyFPAppl16IhrsjJupSJCyhtSbQtwHB7Pl7CL2uuksUWfHtjIEPmh3D h2eg== X-Gm-Message-State: APjAAAUNyzEt8Yv3+z7wgzDVU9c6zr7mnMcUhalP27e7fEvLye4zPnTg rYwrUcCG7CGTsWHCzonMzM2QpLJmPtY= X-Google-Smtp-Source: APXvYqwaGMHA5NbDfKUFoHH4ANQHr1Y1bjq723bn9RFW476GDxLJC3uYOtkZJGlgQEd1n7JCcbNepg== X-Received: by 2002:a17:902:68:: with SMTP id 95mr2375780pla.117.1575336995095; Mon, 02 Dec 2019 17:36:35 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:34 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/4] udmabuf: use cache_sgt_mapping option Date: Mon, 2 Dec 2019 17:36:24 -0800 Message-Id: <20191203013627.85991-1-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 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:mime-version :content-transfer-encoding; bh=eyMX2jKq1sPFGtoRJAfpFto0SNDC6mF6mb3kZ39tKjo=; b=EQ0wbwx9vwY2J+uurdI+PHBch3oyfTJsCq6Dt8lSeOJYdC4cSeAjfvsCBhHGPNQ91L 1/9NpmuuASlHjrzI2PPM7o2sp05KlDnmd78lbQ9Ny/amY9uQSib1dCPmO8ZKzY5aLGHn rXnnIPLpffPYzUTiG/zNMv5sMZvIQ6Zaa3ZTw= 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: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 9de539c1def4..be15eb6b0586 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -94,10 +94,11 @@ static void release_udmabuf(struct dma_buf *buf) } static const struct dma_buf_ops udmabuf_ops = { - .map_dma_buf = map_udmabuf, - .unmap_dma_buf = unmap_udmabuf, - .release = release_udmabuf, - .mmap = mmap_udmabuf, + .cache_sgt_mapping = true, + .map_dma_buf = map_udmabuf, + .unmap_dma_buf = unmap_udmabuf, + .release = release_udmabuf, + .mmap = mmap_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK) From patchwork Tue Dec 3 01:36:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270137 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A32C921 for ; Tue, 3 Dec 2019 01:36:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6F88206E1 for ; Tue, 3 Dec 2019 01:36:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6F88206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6AD906E12B; Tue, 3 Dec 2019 01:36:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14D046E12B for ; Tue, 3 Dec 2019 01:36:40 +0000 (UTC) Received: by mail-pf1-x443.google.com with SMTP id h14so878165pfe.10 for ; Mon, 02 Dec 2019 17:36:40 -0800 (PST) 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=bFT261wHUPXLo9NFa/I8imKlcZ8J4KpDNRcWS6+ZDqI=; b=IRlY3NTWZpCLumFHdn0ND+6cWFK3XxA/qAQFCdLf6d9ZRMQLfA33AFC3+wOanNlTkK lDRoRhVHXqSiJKw5I7VbdvQxgrLyP5yuLBYu33ssjdxowq7BL81RMuVONds6otDR9dRG QMSg14HIY+u4HLBQzYTiX00j4+Qm9DqvAe8Z6osTCDaOKal0vHpoR7ebUnl/LdST8XYi FUrtt6e9OrrxDn+UTfWOftluCR49tdjvi7TI3S/UENCKRgI11fh7E1Kug8LhpbV7C0YF TklBG0w7T/zJ6nh4jFGP5rIi8NmQpyjf7t789dg4j3UxPsL2qKISo3GlJErSfYynu+I1 oWyA== X-Gm-Message-State: APjAAAWIHB/iJZI2TJwaTFXV86Gy6o0wrdNhQMT3YGguR/v5n9wVpCRN 3XkwhJ6ny4zREzjbi2CFAjYtrrfWZ/Y= X-Google-Smtp-Source: APXvYqzSNlfAM3i+NXvH3zKY4If39GEmxvFkh1nOzlPqefoiqkbJId+D0A7Kb0ey3TTnd3KScAX8XQ== X-Received: by 2002:a63:214e:: with SMTP id s14mr2521727pgm.428.1575336999316; Mon, 02 Dec 2019 17:36:39 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:38 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/4] udmabuf: add a pointer to the miscdevice in dma-buf private data Date: Mon, 2 Dec 2019 17:36:25 -0800 Message-Id: <20191203013627.85991-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203013627.85991-1-gurchetansingh@chromium.org> References: <20191203013627.85991-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=bFT261wHUPXLo9NFa/I8imKlcZ8J4KpDNRcWS6+ZDqI=; b=HOXmlk6dQIN7mVVcmk6BZdb883O3coGOpsncWEhYPOzNGdbiD8z3Q5bJzJLadCDKyR J9N6IkSNG9d36Ngz8xAO7SajKXvtPQdiKFJUcMwwS18Sbc4IUf9B3pUjmggA5EecQka2 MAIi9r2iHVTm68WydVGNscs2mpyFgU2X3R/fk= 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: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Will be used later. v2: rename 'udmabuf_misc' to 'device' (kraxel) Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index be15eb6b0586..f0bf3ba7441e 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -18,6 +18,7 @@ static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes */ struct udmabuf { pgoff_t pagecount; struct page **pages; + struct miscdevice *device; }; static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) @@ -104,8 +105,9 @@ 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, - const struct udmabuf_create_item *list) +static long udmabuf_create(struct miscdevice *device, + struct udmabuf_create_list *head, + struct udmabuf_create_item *list) { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); struct file *memfd = NULL; @@ -172,6 +174,7 @@ static long udmabuf_create(const struct udmabuf_create_list *head, exp_info.priv = ubuf; exp_info.flags = O_RDWR; + ubuf->device = device; buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { ret = PTR_ERR(buf); @@ -209,7 +212,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) @@ -228,7 +231,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 Tue Dec 3 01:36:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63AB9921 for ; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CAD1206E1 for ; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CAD1206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0DAF56E147; Tue, 3 Dec 2019 01:36:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B62E6E25D for ; Tue, 3 Dec 2019 01:36:42 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id ay6so941735plb.0 for ; Mon, 02 Dec 2019 17:36:42 -0800 (PST) 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=LICdhzdPL2HSftzAOCs7MLzTsFAWvzORdwz9P5dMvlA=; b=XG1qgn4uWMkiaxS1c8hTrYV13BAwXhykUQNUebcPsVsod/PweiUzjIp+Er5m3gEleJ 1PZj6jJ4kHaxYsrfQragEXDkJF5kgNuysGHdge7PjGge2IqQ4J4Q7sFpOrOgcYva1Gv8 EAlzYBq6slyJbMqdJ2ZlsMkEe5sZKFYCNn6z5M6P2gjzwC7x1LnJcwxkGMRopev63++5 dxmexVqj5q5ODjl1ym+lbFYE/PP7fg8oVM7Q6rzPFzbyRP1N8yVS8vjfTjXFFHU+cqlZ gGfuX/eXr6pBJfrM/Ap3KOhlyIBKp7oyEa/2CK6jp+8FD/7K8TF5Un2WUWD7kLAWqKBI hq5g== X-Gm-Message-State: APjAAAUtL5dR5SRyiOb25K0ovIZGscVcxWG0gjQA8Kqlnqx8iVMEELI5 xxaa7ptJGAqDgtZC/ryt+2eaREhqJ0g= X-Google-Smtp-Source: APXvYqxDfa5iKKsbrpvlvX8fhBHYdMswm4nGazoq4NlHIq8ZBJKRQMMTPcxGZCscL0e+sbekHGdS3A== X-Received: by 2002:a17:902:7b82:: with SMTP id w2mr2420352pll.92.1575337001558; Mon, 02 Dec 2019 17:36:41 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:41 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] udmabuf: separate out creating/destroying scatter-table Date: Mon, 2 Dec 2019 17:36:26 -0800 Message-Id: <20191203013627.85991-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203013627.85991-1-gurchetansingh@chromium.org> References: <20191203013627.85991-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=LICdhzdPL2HSftzAOCs7MLzTsFAWvzORdwz9P5dMvlA=; b=mS5zaMwU/sZmEUX/WkMrz/LIFmrqQarkFTQtjni4vznUW4G5/V1XLmnXXEOCtEuEKT 46P4Fvj0m5QL0rmq+kikGkBWvCUsEweLUoUOXOOhDGlddeeWa1RvAdopKD6iQtxpa5Mg LgROWS5XR/Z0dKPW/PO7CSMAavNZD6iFzKyek= 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: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" These are nice functions and can be re-used. 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 f0bf3ba7441e..0a610e09ae23 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -47,10 +47,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; @@ -62,7 +62,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; } @@ -74,13 +74,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 Tue Dec 3 01:36:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270141 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 654B1921 for ; Tue, 3 Dec 2019 01:36:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E899206E1 for ; Tue, 3 Dec 2019 01:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E899206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45D826E25D; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by gabe.freedesktop.org (Postfix) with ESMTPS id 50B356E25D for ; Tue, 3 Dec 2019 01:36:44 +0000 (UTC) Received: by mail-pj1-x1042.google.com with SMTP id r11so728200pjp.12 for ; Mon, 02 Dec 2019 17:36:44 -0800 (PST) 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=UC12aMZjZVB0hw5FURRfqe7EjweoFXTZMR/s1F02Qgs=; b=F4ZV9h0fr9oyE+EPRtAduooTnOHguSgOiFoZ7ea5z2/TxvRuzXV6fpz/le9LzaMUuo 1EeQ8r6jgq/x94kUv0uNp2G6eHDyjf+BEiSHAbg5PrgFnVQXz+rr1PifnbM781Fx+fGU t4RQiEca6099lrhlFiy4gVDPQSLGZkIHm/0kjD2Kd7pNFxWdBieGpixqCJhjPIzuyYTj /Sf1FqjC2nQD3BYvr3H/wWu9U18nY0vkHqH7/AC7uEMSCNqeaNnXdNV+shoO9fxxr/O3 fXhMnkY19tz2BvpIX2dbxM2r4eVSXKsRPMX/9qQMVNcDeeT6cCLryL7NAUTXB5UPYClK tu2Q== X-Gm-Message-State: APjAAAVyU0C+X7c/SQ5HzEGa2PDgEf8jN2M02LqBmmQUtAkDTOfTHbbY KWU5690nmOOOtHaoq35MqFy+mXurHCM= X-Google-Smtp-Source: APXvYqwokl7QfCw9qi4P1gu6pROxJy+Fn7i1+joycJVc7sIxc0Oz0YQbc2txYevyMRkUSHjp6yAewQ== X-Received: by 2002:a17:902:b90a:: with SMTP id bf10mr2444763plb.45.1575337003597; Mon, 02 Dec 2019 17:36:43 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:42 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/4] udmabuf: implement begin_cpu_access/end_cpu_access hooks Date: Mon, 2 Dec 2019 17:36:27 -0800 Message-Id: <20191203013627.85991-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203013627.85991-1-gurchetansingh@chromium.org> References: <20191203013627.85991-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=UC12aMZjZVB0hw5FURRfqe7EjweoFXTZMR/s1F02Qgs=; b=fmpA6UfGacoKv242CuqlcAnMVr7Ie44cQh+ijNdlzpPQ70luiLYdsUP4Y7hvIqkGuY 1CyXJiI8BK4lnXtgiczMzKl2DwYOMXFWlSCSKrz0sYdEPcd8lFLDgTjrYZCwv+G5Si6x OCE9NdXoTcGH9jxhpa1kV6EWECYfWoaGOMwjg= 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: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" With the misc device, we should end up using the result of get_arch_dma_ops(..) or dma-direct ops. This can allow us to have WC mappings in the guest after synchronization. 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 0a610e09ae23..61b0a2cff874 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -18,6 +18,7 @@ static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes */ struct udmabuf { pgoff_t pagecount; struct page **pages; + struct sg_table *sg; struct miscdevice *device; }; @@ -98,20 +99,58 @@ 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->device->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); kfree(ubuf); } +static int begin_cpu_udmabuf(struct dma_buf *buf, + enum dma_data_direction direction) +{ + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->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->device->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, .unmap_dma_buf = unmap_udmabuf, .release = release_udmabuf, .mmap = mmap_udmabuf, + .begin_cpu_access = begin_cpu_udmabuf, + .end_cpu_access = end_cpu_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK)