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);