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;