From patchwork Tue Nov 26 01:10:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261263 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 69B29138C for ; Tue, 26 Nov 2019 01:11:23 +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 5181C2068F for ; Tue, 26 Nov 2019 01:11:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5181C2068F 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 AA2636E1BE; Tue, 26 Nov 2019 01:11:20 +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 E61146E1BE for ; Tue, 26 Nov 2019 01:11:18 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id 6so3564014pgk.0 for ; Mon, 25 Nov 2019 17:11:18 -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=E/aY1zeifCUazA2R7W+5YbKLA6FIG6CMK8P5lmxEc9w=; b=Okfqe3utiCLPYyIoKBsWYPlkHmp0hXIaeF8sTELVVEelxFhENBsoUATBgehTVsnj8J z1UNVgr7eEg+VYm9pUuCJpBPGiD52lWkFef9iKRwXwe4edsRGjqvJVshjftfMBEtWnb9 Es15qrtLUKst9YhAPrj/xwNkjEsikMCPtHdMJn5vfA+zmcFRc2fZljExB/r7Oae28MeI 30NwZEJkfgA9HEbLpBdeP7DaKF18YsH2+AJaaZERKSkb2o6ZLyDwYTfSmQQGtrycEZiB GQlNWRw/d5avPIk7VtFVWMN7O/685l+jReF3OggOJn8CcdNyZSh7XTXYUeTGhtl9NJyp tudw== X-Gm-Message-State: APjAAAU72DLrhojFpWHR5wIFlpqg3m7q2hVb1PIhJBoaGOZvKB5ZME8v uUCSmTh4/0lHMgtv8QfnK1mEMyToMBA= X-Google-Smtp-Source: APXvYqzU2Mkl6zxLrwxnguxy4Ta6s3lQMXAGyCk8xupI/jtFSu0iy5cbt6SwFCWMAIuzgAbU0lwsIQ== X-Received: by 2002:a62:6086:: with SMTP id u128mr38357762pfb.4.1574730678352; Mon, 25 Nov 2019 17:11:18 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:17 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] udmabuf: use cache_sgt_mapping option Date: Mon, 25 Nov 2019 17:10:52 -0800 Message-Id: <20191126011056.67928-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=E/aY1zeifCUazA2R7W+5YbKLA6FIG6CMK8P5lmxEc9w=; b=noUTO8FLsA53qPu6+gJpr/+Emaxjj5VhyAIk6MPejpNh5pgSldm6/GbSYDE8k5xqzi zuyUMtzTn2c/PZm2DGDHvn/EVPRcVrzZFYlVUWHs1AGkx0ou40FwL02Thvp0DGgptU5O Dtf9GzICEQM4p1Ef65ozZIA2EQRAmJU4j4mbo= 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 | 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 Tue Nov 26 01:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261265 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 443E2138C for ; Tue, 26 Nov 2019 01:11:26 +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 2D71F2068F for ; Tue, 26 Nov 2019 01:11:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D71F2068F 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 CE6EF6E1C0; Tue, 26 Nov 2019 01:11:24 +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 289026E1C0 for ; Tue, 26 Nov 2019 01:11:24 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id q17so8088357pgt.9 for ; Mon, 25 Nov 2019 17:11:24 -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=VYehR7ge0dJ0V5YDxtQHoCeu/4KPNiIoIijqqvVzUv8=; b=T66tdZw9fpKAgYV34IngAJ9cvpKHw6/6aHZx8URaqXbaHoVGnDzjq1ptv9FGrz7yD9 l61zwvt37nGViVX6JLd5+LfosBLV9gSdYFcCMGZPkQIzh+GTeO25P9u0lNoFSDy7YgYz uNUewXncydkqi6CZuPVZBY/taJlLNvaatlcZeD0UO4b40bKxdr4TdX/hwUFZ7LISe6ar UKqGdc3MP6Xw4biKqtIVZ/Q56da96BApszqJ7oF8sWp3Qa1GJq391Uno7YODM5g+Rv0x FZD5pL+nHbk5dGzjScD65Wo/6zD9CeWca2CpnNdWEkZS13xNdwDNYReHDao+uvYTEX5B Fr5A== X-Gm-Message-State: APjAAAXg7rWF/wLC3zJL4trD08Mv3cWRDqZHH1TEWoxegyA55asN9tTW pCvv9gHahsmQ7ykFzoXksMeYlsmdIzE= X-Google-Smtp-Source: APXvYqwAeOkvKOIZ4ckLkUBLHhgHANgpcWDCn9PKQtwRFO09qpK+SXJ8Avj54Cqsbpm146U2USqZmw== X-Received: by 2002:aa7:9151:: with SMTP id 17mr38425576pfi.3.1574730683549; Mon, 25 Nov 2019 17:11:23 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:23 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] udmabuf: allow userspace to set map attributes Date: Mon, 25 Nov 2019 17:10:53 -0800 Message-Id: <20191126011056.67928-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=VYehR7ge0dJ0V5YDxtQHoCeu/4KPNiIoIijqqvVzUv8=; b=Btsg2bW+a8t0gyNaUtUCga87l14wOYfqsaV0lD955X4xE5lxMKbfEJ/lhQRymA7CqU Zenprsh8GUgawbZA8z0Cw/BjeyPQWQ2op80/Weqpx/7r2cdTjVG5IURnBNgYXdtm0Ogl bcAEA9DwEDv7x+NBFADIh2NG8EYjYC5iHkZHI= 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 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. v2: Cache attribute flags instead of read/write flags (kraxel@) --- drivers/dma-buf/udmabuf.c | 12 ++++++++++++ include/uapi/linux/udmabuf.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index b345e91d831a..ce9caaaa9e4b 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,6 +38,12 @@ 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 (ubuf->flags & UDMABUF_FLAGS_WC) + vma->vm_page_prot = pgprot_writecombine(pgprot); + else if (ubuf->flags & UDMABUF_FLAGS_NONCACHED) + vma->vm_page_prot = pgprot_noncached(pgprot); if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) return -EINVAL; @@ -132,6 +139,10 @@ static long udmabuf_create(const struct udmabuf_create_list *head, int seals, ret = -EINVAL; u32 i, flags; + if ((head->flags & UDMABUF_FLAGS_NONCACHED) && + (head->flags & UDMABUF_FLAGS_WC)) + return -EINVAL; + ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL); if (!ubuf) return -ENOMEM; @@ -188,6 +199,7 @@ static long udmabuf_create(const struct udmabuf_create_list *head, exp_info.priv = ubuf; exp_info.flags = O_RDWR; + ubuf->flags = head->flags; buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { ret = PTR_ERR(buf); diff --git a/include/uapi/linux/udmabuf.h b/include/uapi/linux/udmabuf.h index 46b6532ed855..f90831f2bb0d 100644 --- a/include/uapi/linux/udmabuf.h +++ b/include/uapi/linux/udmabuf.h @@ -6,6 +6,8 @@ #include #define UDMABUF_FLAGS_CLOEXEC 0x01 +#define UDMABUF_FLAGS_WC 0x02 +#define UDMABUF_FLAGS_NONCACHED 0x04 struct udmabuf_create { __u32 memfd; From patchwork Tue Nov 26 01:10:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261267 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 00926138C for ; Tue, 26 Nov 2019 01:11:31 +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 DD6972068F for ; Tue, 26 Nov 2019 01:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD6972068F 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 E64E96E1D5; Tue, 26 Nov 2019 01:11:29 +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 95C746E1CD for ; Tue, 26 Nov 2019 01:11:27 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id e6so8084259pgi.11 for ; Mon, 25 Nov 2019 17:11:27 -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=CYXA6kZl83KUkaRjWD+JnO5e82OiZcDqxj3GwOxeRBY=; b=iqEH2cR4dJDe1GObdkyS0FD7aF3sKd4LjStKKRM2ODrRXcn4DRa9rPSe+w6sMEu2Jl yb7Iit8Hf8HtAN36W+2NqVBtd26z7DdyalM4LA8t6TQGysrN0iaH5HoBnKbUAkaeMPxz wPA16Lj/kBLl0bgbYu9jBVi01L+pYV6ELqDwOkVc0drAq1zqkJJwbwgnNxjuOpBxK/5f dFeCAlLYJPXtdqKZd0Svw0l4RG2PmO69C5RkkH41e1/G8YR+iWk5wnj1GyghUh+IatgY UTS/UMj0nc6n9q/p6VYQ3oLloe5c4LWA/koWK/qXG7+gw8j/cBNcJTm7r864At18XfIb Nx7Q== X-Gm-Message-State: APjAAAXUb3jkm0F4sl3D5xgQk3Kw4d3pLlMWK5ift7bsDnDP19KmK1T7 BEmVzN3tNjKTbTnzl1KhskFv4CT/Z54= X-Google-Smtp-Source: APXvYqzlyN/MCu+DrmSpqR7YLQUp4bzlhPY64TLP0MkSXLWhsf/u/1XCaFm0y1S9airAT5joPOJsbQ== X-Received: by 2002:a62:1454:: with SMTP id 81mr37846295pfu.86.1574730687027; Mon, 25 Nov 2019 17:11:27 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:26 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] udmabuf: add a pointer to the miscdevice in dma-buf private data Date: Mon, 25 Nov 2019 17:10:54 -0800 Message-Id: <20191126011056.67928-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=CYXA6kZl83KUkaRjWD+JnO5e82OiZcDqxj3GwOxeRBY=; b=j7iti68QtnuSNuDgccVp4afXbu157fbYcx9OC/PLMkVz6Iq5pgNGbzZ1jGtJl3fOGk dzxTqhAtFVFmun2MK7Q98ovXuqklQZMTvFd7BM/DplHIMeousQKDHK2Gk0caEdV84S/Z t73z4ZdEibBRzwBx55nDIiGKQITUI4tYb4Oy8= 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index ce9caaaa9e4b..9e6fdd2bc979 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 *device; }; static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) @@ -127,8 +128,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; @@ -200,6 +202,8 @@ static long udmabuf_create(const struct udmabuf_create_list *head, exp_info.flags = O_RDWR; ubuf->flags = head->flags; + ubuf->device = device; + buf = dma_buf_export(&exp_info); if (IS_ERR(buf)) { ret = PTR_ERR(buf); @@ -237,7 +241,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) @@ -256,7 +260,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 Nov 26 01:10:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261271 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 878591393 for ; Tue, 26 Nov 2019 01:11:37 +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 703B52068F for ; Tue, 26 Nov 2019 01:11:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 703B52068F 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 D900F6E1E5; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C3D36E1E0 for ; Tue, 26 Nov 2019 01:11:30 +0000 (UTC) Received: by mail-pj1-x1043.google.com with SMTP id bb19so3901666pjb.4 for ; Mon, 25 Nov 2019 17:11:30 -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=ghrwFxO818UoK8VetowCRFQffMjIOkvAfQ3v9xbttnw=; b=HsNSB6ZS9qfX4ouncHRMbiu9a6xwJv6WM6sRJIXGrVMe8cc4CX+OxiQ2KoQ+BTJ34m tgkUeYIOP0Kuuqud+SDM7lWh1CDZmUbrYQDps5vr/4j8u8i5zyLwYT86aExQQGa9xyPx ytoFtSFdR49cfdhTjy61ORw0usW/LOWEsmAtRSjwhCYBOHk7vzngIwQB0R+aiK6wXedI uYPJ+iYMMiukphdzYn923NMsL13wTNopGTWz7BidZNlsYyU8y6LkOMFQ+F/N7zwaHSc6 vyMWrN3bTvtpfPXrNAsdQA6D7lUopjGtEF7FA4MxIa+KRDaMqbS2S/cDe9oq7o5sMkYg jT+g== X-Gm-Message-State: APjAAAXghPgYvp4KJjn4u9au3sSo3QMcaBOxZSojemY86y6XKbt9wxHA YhZowp7aPsoJzh/ykaBLQ80g3XUzdRE= X-Google-Smtp-Source: APXvYqzVL3/E4ZIaU+Kwqbhjk9+5S/H6jnox5RjWJwEk18dpafx3G092uB/gv0Th9142Qsj0mldwwQ== X-Received: by 2002:a17:902:9a8e:: with SMTP id w14mr32578884plp.215.1574730689905; Mon, 25 Nov 2019 17:11:29 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:29 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] udmabuf: separate out creating/destroying scatter-table Date: Mon, 25 Nov 2019 17:10:55 -0800 Message-Id: <20191126011056.67928-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=ghrwFxO818UoK8VetowCRFQffMjIOkvAfQ3v9xbttnw=; b=bjQiRQnkTIJk7xaJAmU3rUsZEwFA9izbk1Nt1r7qkmcdtPgkSmoq+yv51kKezAaR76 Znba5vsISPOkd4WV6umB/7G0uVLSLpFdJMYAsIynemULdwMz3729ksy3mTO+36xPitQ1 UmlB0RqK4wVRfIt92L0ppbMOuPKXSHPQzh4A0= 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 9e6fdd2bc979..67e89bb034c5 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -54,10 +54,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; @@ -69,7 +69,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; } @@ -81,13 +81,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 Nov 26 01:10:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261269 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 11D591393 for ; Tue, 26 Nov 2019 01:11:35 +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 EF2602068F for ; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF2602068F 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 44FAF6E1CD; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by gabe.freedesktop.org (Postfix) with ESMTPS id F18BC6E1CD for ; Tue, 26 Nov 2019 01:11:32 +0000 (UTC) Received: by mail-pl1-x641.google.com with SMTP id o8so2981316pls.5 for ; Mon, 25 Nov 2019 17:11:32 -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=kaPPIWsEF4upG4l+JTslBmj5SeIlIs0u8TXiyS8y8YE=; b=P5a+91HNhaw4l9nrvZVVTfmXFKuh7Ua+fq5corOakgCDJ7N5ixrVwTFmym9Ea8rieQ cBZSv/q9yT1WcLb3hO8rhfF+iPdfZU6+a+6nZmAvjRj2qc4P+yjJAhiutZP0zBnWwuqn +QnGrfB8ujr3odJ/pjVe2I2ljGlYCk3OGlTm1Z9lL4qiJQOpKG5Fep994xl4qcs76zWc reR51fxTV4HjDFg7R8VJPlaFOgBabg+zygc7GmtY8YnZwUJDKJcKjZuFA6SWfeiarBf5 TXZG5lQfatNi+bQp/lZJhWECs3UHTpHyrvDkVlJh7I60jmamwxmPkka2dsbr6UdBOJvH 4W7g== X-Gm-Message-State: APjAAAXZstBv6jbLZBvODI46XmltNpoe9uP4avdkVReYBc6Ki1pfnNyn Gk48h2fhOFz/eCoQ4SkcyERiZAOcn7c= X-Google-Smtp-Source: APXvYqy13Jc8EN+9gue54QDH3UcS2g6yMy02t4IHt328z0ehWIeXCTIH+h+pgNzM/I4cFrODmPsMUg== X-Received: by 2002:a17:902:b68c:: with SMTP id c12mr2947446pls.126.1574730692309; Mon, 25 Nov 2019 17:11:32 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:31 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] udmabuf: implement begin_cpu_access/end_cpu_access hooks Date: Mon, 25 Nov 2019 17:10:56 -0800 Message-Id: <20191126011056.67928-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=kaPPIWsEF4upG4l+JTslBmj5SeIlIs0u8TXiyS8y8YE=; b=U0wBRPFw2/H930x4iZW30rQMMo2mQvK/5uDl+S7FrtZTV4XBj0O3kl2Jp8ytlFe9gG KE6X0YiGz/ZmRV7iXG30Zm2QRjJFWk+zpcFeaNL01XYzAinQ8vJZzag0NeAmp27QJfup xIvFwS09lrxp9yvGsIdATTyI4SENgMLvlE6ow= 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 | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 67e89bb034c5..142444922acd 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 *device; }; @@ -105,8 +106,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->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); @@ -127,6 +132,39 @@ 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->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, @@ -135,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)