Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id EFD55C433FE for ; Thu, 24 Nov 2022 11:11:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D869410E6E1; Thu, 24 Nov 2022 11:11:33 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id E762110E6E1 for ; Thu, 24 Nov 2022 11:11:30 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1096323A; Thu, 24 Nov 2022 03:11:37 -0800 (PST) Received: from [10.57.71.118] (unknown [10.57.71.118]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3ECCF3F587; Thu, 24 Nov 2022 03:11:29 -0800 (PST) Message-ID: <49605c31-be89-d0f9-b4e1-577aaaaf259a@arm.com> Date: Thu, 24 Nov 2022 11:11:21 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] drm/dma-helpers: Don't change vma flags Content-Language: en-GB To: Daniel Vetter , DRI Development References: <20221123172802.1049424-1-daniel.vetter@ffwll.ch> From: Robin Murphy In-Reply-To: <20221123172802.1049424-1-daniel.vetter@ffwll.ch> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Pinchart , =?UTF-8?Q?Christian_K=c3=b6nig?= , Thomas Zimmermann , Dave Airlie , Daniel Vetter , Sumit Semwal Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 2022-11-23 17:28, Daniel Vetter wrote: > This code was added in b65e64f7ccd4 ("drm/cma: Use > dma_mmap_writecombine() to mmap buffer"), but does not explain why > it's needed. > > It should be entirely unnecessary, because remap_pfn_range(), which is > what the various dma_mmap functiosn are built on top of, does already > unconditionally adjust the vma flags: Not all dma_mmap_*() implementations use remap_pfn_range() though. For instance on ARM where one set of DMA ops uses vm_map_pages(), but AFAICS not all the relevant drivers would set VM_MIXEDMAP to prevent reaching the BUG_ON(vma->vm_flags & VM_PFNMAP) in there. Robin. > https://elixir.bootlin.com/linux/v6.1-rc6/source/mm/memory.c#L2518 > > More importantly, it does uncondtionally set VM_PFNMAP, so clearing > that does not make much sense. > > Patch motived by discussions around enforcing VM_PFNMAP semantics for > all dma-buf users, where Thomas asked why dma helpers will work with > that dma_buf_mmap() contract. > > References: https://lore.kernel.org/dri-devel/5c3c8d4f-2c06-9210-b00a-4d0ff6f6fbb7@suse.de/ > Cc: Laurent Pinchart > Cc: Dave Airlie > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Thomas Zimmermann > Cc: Sumit Semwal > Cc: "Christian König" > Signed-off-by: Daniel Vetter > --- > drivers/gpu/drm/drm_gem_dma_helper.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c > index 1e658c448366..637a5cc62457 100644 > --- a/drivers/gpu/drm/drm_gem_dma_helper.c > +++ b/drivers/gpu/drm/drm_gem_dma_helper.c > @@ -525,13 +525,10 @@ int drm_gem_dma_mmap(struct drm_gem_dma_object *dma_obj, struct vm_area_struct * > int ret; > > /* > - * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the > - * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map > - * the whole buffer. > + * Set the vm_pgoff (used as a fake buffer offset by DRM) to 0 as we > + * want to map the whole buffer. > */ > vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node); > - vma->vm_flags &= ~VM_PFNMAP; > - vma->vm_flags |= VM_DONTEXPAND; > > if (dma_obj->map_noncoherent) { > vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);