Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3517741pxf; Mon, 15 Mar 2021 11:18:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlqwOrhJyIAl9koMi6ar8otuNxWSdO+On1jZHgzIxEJrgIzlwnjnJ38ibMFdAV7XyUttGT X-Received: by 2002:a17:907:aa2:: with SMTP id bz2mr25548748ejc.239.1615832319557; Mon, 15 Mar 2021 11:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832319; cv=none; d=google.com; s=arc-20160816; b=nA/mg34TgHhZ0A2gq9bwRVl0OeTvOYlV3eM90koH2fA28qDyKtIQPpaDQYI0gD6uG3 kNagasevcrypAXdMvCMWMMcnLyAq3y3ZmQL03iSzit+JFTFiA0e0yihhYOdc2fXRzf2Q 1LrUlsU8GvJTQgoJ9aRUoGNPDSLie3rNkGjENXchcgzcFF1pZERJEONKkciMorUJEDni vSzZlny5dEKR2DEBtW/G2fpCSshBtuNTrU/KQfz6x9st8hPQgbeGMxIMqChcbzEgxLT7 cGVIHxDJxHwqyOXtV6jr/pLFjr18dIdwxGxNNJiB5QSuvuEOc9hXYV1cu2HfXIkImG/Q 2IwA== 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=aCXBw3I+OWeKhhJ2SVx0GtEdhJtaJauRx4u/p08ny5A=; b=yGIaL7GP3LKQf/lJBeaD5A/sacjg/o3wCgLezqH86xFaplDhG7mWqe5Qryx9tp9fMp a/gQM4oc4+a1TiCcrGo4nl/phQZVUeJzAgyad+N4uGgkkWB969xrFcRvvV4/zoWii0lC 7gN8jFqC7yKk07IHpwPkfnac6hn0pOgPfgBmKKmRqLYeO1mRtL3ZkTenS9DcARY7zqSf gX38SVFYMLKITCcU7a6nKw/r/jlKhmCrB4Y06YZwIiVdarQeDJe5h72j5S+WYCeXdSFC EfuDoMDXlm6y649gUs0HdHfyplB/04wpEqU+8NEIYi//H8ouXHWy7/gh22lUS9Z5BB6R SvFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T0f2dPDw; 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 oz17si12128652ejb.205.2021.03.15.11.18.17; Mon, 15 Mar 2021 11:18:39 -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=T0f2dPDw; 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 S237105AbhCOORT (ORCPT + 99 others); Mon, 15 Mar 2021 10:17:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231851AbhCON7e (ORCPT ); Mon, 15 Mar 2021 09:59:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9292C64F42; Mon, 15 Mar 2021 13:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816750; bh=+dLMDR0iclzPgzx6Mrlb2Nb8EtxTaZNFwxyzdorgccc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0f2dPDwrBgPOjN2eax70b5nOCtDm6OrpiG813EgPD06pMjwIItE3bKuEcFL87y+4 XumyHSTxWomtFEgbITKDUq5WZCtCvLIN6s1uc2rnO9doxvSCA+ZX7f6LK15uTmqKT4 5H4dLcs28Pu9G7OIiNPuPAxxkng/fBJbEyubVaCQ= 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.10 093/290] drm/shmem-helper: Dont remove the offset in vm_area_struct pgoff Date: Mon, 15 Mar 2021 14:53:06 +0100 Message-Id: <20210315135545.067178724@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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 @@ -536,15 +536,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); } @@ -600,9 +604,6 @@ int drm_gem_shmem_mmap(struct drm_gem_ob 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);