Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB3ACC433E9 for ; Thu, 18 Feb 2021 15:26:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4D18764EC7 for ; Thu, 18 Feb 2021 15:26:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D18764EC7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 971586E83A; Thu, 18 Feb 2021 15:26:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 0587F6E83A for ; Thu, 18 Feb 2021 15:26:01 +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 364F3ED1; Thu, 18 Feb 2021 07:26:00 -0800 (PST) Received: from [192.168.1.179] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 67D313F73D; Thu, 18 Feb 2021 07:25:59 -0800 (PST) Subject: Re: [PATCH] drm/shmem-helper: Don't remove the offset in vm_area_struct pgoff To: Neil Roberts , Rob Herring , Tomeu Vizoso , Alyssa Rosenzweig References: <20210217165910.3820374-1-nroberts@igalia.com> From: Steven Price Message-ID: <7f80b184-7277-0f6c-1108-cf41189626df@arm.com> Date: Thu, 18 Feb 2021 15:26:28 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210217165910.3820374-1-nroberts@igalia.com> Content-Language: en-GB 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: dri-devel@lists.freedesktop.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 17/02/2021 16:59, Neil Roberts wrote: > When mmapping the shmem, it would previously adjust the pgoff in the > vm_area_struct to remove the fake offset that is added to be able to > identify the buffer. This patch removes the adjustment and makes the > fault handler use the vm_fault address to calculate the page offset > instead. Although using this address is apparently discouraged, several > DRM drivers seem to be doing it anyway. > > The problem with removing the pgoff is that it prevents > drm_vma_node_unmap from working because that searches the mapping tree > by address. That doesn't work because all of the mappings are at offset > 0. drm_vma_node_unmap is being used by the shmem helpers when purging > the buffer. > > It looks like panfrost is using drm_gem_shmem_purge so this might fix a > potential bug there. > > Signed-off-by: Neil Roberts As the test robot points out pgoff_t is unsigned, so the <0 test makes no sense. But apart from that it looks good to me. I think this is worth a "Fixes:" line too - as you point out drm_vma_node_unmap() won't be working correctly - which means we're potentially leaving user space with pages pointing to freed memory - not good! 17acb9f35ed7 is my best guess at the commit that introduced this. Steve > --- > drivers/gpu/drm/drm_gem_shmem_helper.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 9825c378dfa6..4b14157f1962 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -526,11 +526,16 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf) > struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); > loff_t num_pages = obj->size >> PAGE_SHIFT; > struct page *page; > + pgoff_t page_offset; > > - if (vmf->pgoff >= num_pages || WARN_ON_ONCE(!shmem->pages)) > + /* We don't use vmf->pgoff since that has the fake offset */ > + page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT; > + > + if (page_offset < 0 || page_offset >= num_pages || > + WARN_ON_ONCE(!shmem->pages)) > return VM_FAULT_SIGBUS; > > - page = shmem->pages[vmf->pgoff]; > + page = shmem->pages[page_offset]; > > return vmf_insert_page(vma, vmf->address, page); > } > @@ -581,9 +586,6 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) > struct drm_gem_shmem_object *shmem; > int ret; > > - /* Remove the fake offset */ > - vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node); > - > if (obj->import_attach) { > /* Drop the reference drm_gem_mmap_obj() acquired.*/ > drm_gem_object_put(obj); > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel