Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3324924pxf; Mon, 15 Mar 2021 07:10:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlJp8XGspOau/BcbtrVPj9Bxk9ZENEaXJaT/Oa+91W+Ra/fuw66OBudidAwlTGSsQX6JPo X-Received: by 2002:aa7:d0cb:: with SMTP id u11mr30104562edo.163.1615817412568; Mon, 15 Mar 2021 07:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817412; cv=none; d=google.com; s=arc-20160816; b=MeXVE77e0woMT4WrN2SagY+qp7/AnVTHaXImrklBSTrXFvm7XD8oCCU8X48cRI6aiM Qq1fLFojZDfNYdzHBotjsgSwWPUE3O+psXgjcZtruXcB/Qp2ZS03/rURIFN+4gmUJVuY gxWxtGqeZ4ZLdqc6zj6D073JFVJdNaRNyecL+vVYm3MgkZfdMORUPGIbqsBnAD9xB5OB fLXe/3DKkjEpEXq/GKGHZWhzavHHIJhRjei31TzVjgD9V0lxbYq4AWD8oMTAn5cge87m G7zMAe/5JeHreXG7/LNq/2FcjAOueK5/CM/hJyWYjT4c4GapA93osiMiMIdbrSbTMG6v A38A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DCW2RO36s98b/a5Lpu/g8xS9L7OKfVFMYQIuoABZgN8=; b=E7E6VJxvM1yCAbAzCKjBVAt8DXU4P4qQ2TsF5kytrJO6Q0M4k2QdabuLPSoDCPvCe5 dCbOY/Aq4GUiWtbD6s1g0Vd8Ngk15AW/stPf844svKYeMRekAwmexV5uEkukJySxXWLi MDC+iGFRfCtAma8h+IvrYn8IJjaiyAE6GQYxyLmXu7UPpLoKlCfnAA6veqDwPb0hH44s hn7JAKXdHl74lPQ5aVrtRzgdk2FnrDy/dOVtg1mdRxJzkvGTH2NWc67dX1eeaBrNndz0 2tk5yY5KXETHaFjJYxiFKoCRg4P/ulblgfPGPChvUhRgkdO82GdxmwK82rOjioH9jSXK /ewA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kvUe8LnC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g20si11699150edy.270.2021.03.15.07.09.50; Mon, 15 Mar 2021 07:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kvUe8LnC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232198AbhCOOH7 (ORCPT + 99 others); Mon, 15 Mar 2021 10:07:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbhCON6L (ORCPT ); Mon, 15 Mar 2021 09:58:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 670D064F40; Mon, 15 Mar 2021 13:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816690; bh=gFKKh/jNpof9s0wxrd+qXEE/YgPV0vgBD/KK5Wq4xts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kvUe8LnCvMpIEwFI3kEUfBeLSfjjNzcK0/ZpSIWfpnU6v41FW/Bmj26opD3pIetbY UwHl8bMo2EH4MtIN+aNtXZeSJ9LiF0NdYYapcdW7FXlks1Y4o0axAgr8bHzUaxwYNj SbJ/u2JgihN5aG+DAqURclk4Dgw97tS0VN7nomcs= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Neil Roberts , Steven Price , Maarten Lankhorst Subject: [PATCH 5.4 049/168] drm/shmem-helper: Dont remove the offset in vm_area_struct pgoff Date: Mon, 15 Mar 2021 14:54:41 +0100 Message-Id: <20210315135551.973574564@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Neil Roberts commit 11d5a4745e00e73745774671dbf2fb07bd6e2363 upstream. 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. This fixes a bug in Panfrost which is using drm_gem_shmem_purge. Without this the mapping for the purged buffer can still be accessed which might mean it would access random pages from other buffers v2: Don't check whether the unsigned page_offset is less than 0. Cc: stable@vger.kernel.org Fixes: 17acb9f35ed7 ("drm/shmem: Add madvise state and purge helpers") Signed-off-by: Neil Roberts Reviewed-by: Steven Price Signed-off-by: Steven Price Link: https://patchwork.freedesktop.org/patch/msgid/20210223155125.199577-3-nroberts@igalia.com Signed-off-by: Maarten Lankhorst Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_gem_shmem_helper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -476,15 +476,19 @@ static vm_fault_t drm_gem_shmem_fault(st loff_t num_pages = obj->size >> PAGE_SHIFT; vm_fault_t ret; struct page *page; + pgoff_t page_offset; + + /* We don't use vmf->pgoff since that has the fake offset */ + page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT; mutex_lock(&shmem->pages_lock); - if (vmf->pgoff >= num_pages || + if (page_offset >= num_pages || WARN_ON_ONCE(!shmem->pages) || shmem->madv < 0) { ret = VM_FAULT_SIGBUS; } else { - page = shmem->pages[vmf->pgoff]; + page = shmem->pages[page_offset]; ret = vmf_insert_page(vma, vmf->address, page); } @@ -559,9 +563,6 @@ int drm_gem_shmem_mmap(struct file *filp vma->vm_flags &= ~VM_PFNMAP; vma->vm_flags |= VM_MIXEDMAP; - /* Remove the fake offset */ - vma->vm_pgoff -= drm_vma_node_start(&shmem->base.vma_node); - return 0; } EXPORT_SYMBOL_GPL(drm_gem_shmem_mmap);