From patchwork Fri May 25 13:42:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10427443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B49A6025B for ; Fri, 25 May 2018 13:43:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3091F2968A for ; Fri, 25 May 2018 13:43:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2455D296A6; Fri, 25 May 2018 13:43:02 +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 D5F592968A for ; Fri, 25 May 2018 13:43:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D67E6E1D0; Fri, 25 May 2018 13:42:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 889C06E1CA for ; Fri, 25 May 2018 13:42:57 +0000 (UTC) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1fMCzf-0007AB-D8; Fri, 25 May 2018 15:42:55 +0200 From: Lucas Stach To: Tomi Valkeinen Subject: [PATCH 2/2] drm/etnaviv: properly implement mmaping of imported buffers Date: Fri, 25 May 2018 15:42:54 +0200 Message-Id: <20180525134254.30686-2-l.stach@pengutronix.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180525134254.30686-1-l.stach@pengutronix.de> References: <20180525134254.30686-1-l.stach@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: dri-devel@lists.freedesktop.org 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: Julien Boulnois , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The intention of the existing code was to deflect the actual work of mmaping a dma-buf to the exporter, as that one probably knows best how to handle the buffer. Unfortunately the call to drm_gem_mmap did more than what etnaviv needs in this case by actually setting up the mapping. Move mapping setup to the shm buffer type mmap implementation so we only need to look up the BO and call the buffer type mmap function from the handler. Fixes mmap behavior with dma-buf imported and userptr buffers. Signed-off-by: Lucas Stach --- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index fcc969fa0e69..f38989960d7f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -138,6 +138,13 @@ static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object *etnaviv_obj, struct vm_area_struct *vma) { pgprot_t vm_page_prot; + int ret; + + ret = drm_gem_mmap_obj(&etnaviv_obj->base, + drm_vma_node_size(&etnaviv_obj->base.vma_node) << PAGE_SHIFT, + vma); + if (ret) + return ret; vma->vm_flags &= ~VM_PFNMAP; vma->vm_flags |= VM_MIXEDMAP; @@ -167,17 +174,26 @@ static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object *etnaviv_obj, int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma) { - struct etnaviv_gem_object *obj; + struct drm_file *priv = filp->private_data; + struct etnaviv_gem_object *etnaviv_obj; + struct drm_gem_object *obj; int ret; - ret = drm_gem_mmap(filp, vma); - if (ret) { - DBG("mmap failed: %d", ret); - return ret; + obj = drm_gem_bo_vm_lookup(filp, vma); + if (!obj) + return -EINVAL; + + if (!drm_vma_node_is_allowed(&obj->vma_node, priv)) { + drm_gem_object_put_unlocked(obj); + return -EACCES; } - obj = to_etnaviv_bo(vma->vm_private_data); - return obj->ops->mmap(obj, vma); + etnaviv_obj = to_etnaviv_bo(obj); + + ret = etnaviv_obj->ops->mmap(etnaviv_obj, vma); + drm_gem_object_put_unlocked(obj); + + return ret; } int etnaviv_gem_fault(struct vm_fault *vmf)