From patchwork Thu Oct 24 19:18:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 177603 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2625618ill; Thu, 24 Oct 2019 12:19:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwceZteNx5k5vq++Z34G8XutUERaA19LfmKCzgtBP3XiiolFvJVd36FZYw8ktb5+BehbVjY X-Received: by 2002:a17:902:b095:: with SMTP id p21mr5878857plr.159.1571944748666; Thu, 24 Oct 2019 12:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571944748; cv=none; d=google.com; s=arc-20160816; b=RGaAoAVsGyjsU6PHvpfVOpEuZEoWOvRXhMDDqxTEvt6LsGwwWEgDd/e79Qma1ZYrXL E62YVDTy/ri1x/R7scS6jqDEH+UVNjMQfj4VHY3Kar9BSvlliJCrIkiI4JrgzcOeFhSG gmYvLpI4+NyAE3g7/XafDumelXTfYsSDdbS7/bUMaWAWSDh67uXhihIxmQX0+c8UPIJd YS+jkBVtOub2Iykf8qQwt4CCDViLSN+SMfuZzMKBCHsqmuqMnl/MPqR/TbKVkjHqhVbb BHRxm+bY5UWj+IW6h89yBmQa5OuBzTZigoxPleRXnkESL/bI92c3p7zLuvrXaz8+CEEr IFqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :delivered-to; bh=GH9XVW7cAhhli1rjxURVXsMhsUQdD/fho9lBa46eQA8=; b=eogH11cT9+1Mwy5SmKY/vt4n+R5T6OdzEq86VkVCCQOR06fGEGlL4x2HuD6mfpxE2C iVf5G7uhb3+iB8AdIy95KkIOzwRR+5liqopHJVXWZJxqe1d8kCkkTFoB46MnmxkrBKfO 7wEB7FEcoW1NK2iYjKZfNUVEMHvQdWbr7keFIjj+RY6cPjM2DT8aAzNHp+zi/bPnaLzh Lvf5kzqECVe89q4B+fcN77HaH/ntB1MymmYO52SqfQOVLs8WHah0U3uIxkg12V7q/4Mq T+uq04mfkv34l33hoH9fYyiaRDb4w2OptD0B57uON2EK7bq3oSjMrmIgEEzmt/nFq6jb DHwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id ev16si3490916pjb.35.2019.10.24.12.19.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2019 12:19:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B87346E618; Thu, 24 Oct 2019 19:19:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E5746E618 for ; Thu, 24 Oct 2019 19:19:05 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id 41so21667332oti.12 for ; Thu, 24 Oct 2019 12:19:05 -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:mime-version :content-transfer-encoding; bh=gAAObhkDlnacnREGE/ca1ihLZNxkCic+471mcU+shVc=; b=IKA9U2wKWyX1yVkwyJfLiojIVzjBwFwFFThGbwlSlQZjcgMZ+Ojb90pFWYtzyGTzxz 0sc0EMIWweKmFrH5chfiC3pspHKdCPeLhzRcfFg9jtmO9IXv+CsYQ8DnAk7MEtSf5ieT 6XlT7+cadthqr+029woLnsaSfcSjN1hlXYII2m0z5yYkZx9h/c+Nu+bsPQ2wnjIoYVX6 LYy00G+lz1Ns7gb4239UPJLUmJ5AAKE3doqipHqjo/3u3oBfHffT5uqm/cqjLC/G3onz om9Qf/zBS4WaMm5/1AZi8yLaqitT59eS8xdJmdJeruCCXunXYi65Nmt6v3M53lAfFqNF PQgw== X-Gm-Message-State: APjAAAXK+VfUs1U0Fnzn66fKCErt2zS5lqKQJNXtQVNyEre3BDeOQQO/ PMYNGtKCu73UftRLlH37Sh5hKtA= X-Received: by 2002:a05:6830:18e3:: with SMTP id d3mr12395102otf.168.1571944744016; Thu, 24 Oct 2019 12:19:04 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id n18sm3166867otq.25.2019.10.24.12.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 12:19:02 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org, Gerd Hoffmann Subject: [PATCH v2] drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap Date: Thu, 24 Oct 2019 14:18:59 -0500 Message-Id: <20191024191859.31700-1-robh@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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: Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Commit c40069cb7bd6 ("drm: add mmap() to drm_gem_object_funcs") introduced a GEM object mmap() hook which is expected to subtract the fake offset from vm_pgoff. However, for mmap() on dmabufs, there is not a fake offset. To fix this, let's always call mmap() object callback with an offset of 0, and leave it up to drm_gem_mmap_obj() to remove the fake offset. TTM still needs the fake offset, so we have to add it back until that's fixed. Fixes: c40069cb7bd6 ("drm: add mmap() to drm_gem_object_funcs") Cc: Gerd Hoffmann Cc: Daniel Vetter Signed-off-by: Rob Herring Acked-by: Gerd Hoffmann Reviewed-by: Daniel Vetter --- v2: - Move subtracting the fake offset out of mmap() obj callbacks. I've tested shmem, but not ttm. Hopefully, I understood what's needed for TTM. Rob drivers/gpu/drm/drm_gem.c | 3 +++ drivers/gpu/drm/drm_gem_shmem_helper.c | 3 --- drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 +++++++ include/drm/drm_gem.h | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 56f42e0f2584..2f2b889096b0 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1106,6 +1106,9 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, return -EINVAL; if (obj->funcs && obj->funcs->mmap) { + /* Remove the fake offset */ + vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node); + ret = obj->funcs->mmap(obj, vma); if (ret) return ret; diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index a878c787b867..e8061c64c480 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -542,9 +542,6 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); vma->vm_ops = &drm_gem_shmem_vm_ops; - /* Remove the fake offset */ - vma->vm_pgoff -= drm_vma_node_start(&shmem->base.vma_node); - return 0; } EXPORT_SYMBOL_GPL(drm_gem_shmem_mmap); diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c index 1a9db691f954..08902c7290a5 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -482,6 +482,13 @@ EXPORT_SYMBOL(ttm_bo_mmap); int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo) { ttm_bo_get(bo); + + /* + * FIXME: &drm_gem_object_funcs.mmap is called with the fake offset + * removed. Add it back here until the rest of TTM works without it. + */ + vma->vm_pgoff += drm_vma_node_start(&bo->base.vma_node); + ttm_bo_mmap_vma_setup(bo, vma); return 0; } diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index e71f75a2ab57..c56cbb3509e0 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -159,7 +159,9 @@ struct drm_gem_object_funcs { * * The callback is used by by both drm_gem_mmap_obj() and * drm_gem_prime_mmap(). When @mmap is present @vm_ops is not - * used, the @mmap callback must set vma->vm_ops instead. + * used, the @mmap callback must set vma->vm_ops instead. The @mmap + * callback is always called with a 0 offset. The caller will remove + * the fake offset as necessary. * */ int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);