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;