Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3519329pxf; Mon, 15 Mar 2021 11:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV861qFiscIb/Txl6MpMUvDVIhbapB4TIETD+nG/UK0Fm7qI2AJd9vWd6K+P15RfodmY2E X-Received: by 2002:a05:6402:30b9:: with SMTP id df25mr32061461edb.136.1615832475494; Mon, 15 Mar 2021 11:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832475; cv=none; d=google.com; s=arc-20160816; b=093SgEBUzCAatEZNLyaGzQ8nxinmNak6b3UoMtAIyo9TK/1ciViUB+/WjAYvqfNLRN GHjHI0Ahd1L41md6xt+tt5BEOgT0JKWzRh9tcwZl8v/nJbPzOILX+r1q/+4XptB4KNkV wytoVwE6AsWTpSWdGwjnI9UlvDs6jwl1XMbwO93SnQJLsM1s/bpmb7dZm6hr7G1dRns3 9y6BGJATcPXvbvZ18frevwILa/YfYSjQYi1BezCvokBq61OqMBqgctuRyPGg/lyWthdY T93VbXo9n1LFoYDvxBT+5gVv2qnXCXWXXLAhf+CAbq7TyHJtJx/TN5T82Fc8WLJUrJzO xMUg== 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=OR085wjcJ2xsnpd/Ayc0Q3vSczc+FqdCeseWVf3h1NM=; b=k8cmczxg0IWoIqyERFl/zr0Fkp2bbt5qbYPRQszMRUaZ0CdAAu/mm3c6XflyRd3YBS dpgjniOx0zbT8K0BlxDTlrwT491ZAbxetAxYFEAmrDZk1qq4vpeTirOFP8oeI1GBfaSr 1oSi2wuz+nqxE9d44mG8Uajsl9PTrNR0j+664z8iZclFcgR4Mvp53FprG8j9ejxzKwCh Ls6eQJRFOegawbxbbok10Kwx6Im3YzoFztxxC/Qj3cBTLewBRJCzGwMpqYt+BWlXAJvG RHy+ZCzDVMcClOJY34X/8i9aB+p+N/B11eDCzAMNbJh74hISBCviJehprrTptbnJie30 OBsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dvHPCyvo; 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 b11si11942164edz.197.2021.03.15.11.20.52; Mon, 15 Mar 2021 11:21:15 -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=dvHPCyvo; 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 S229871AbhCOOSB (ORCPT + 99 others); Mon, 15 Mar 2021 10:18:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:34900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232724AbhCON7g (ORCPT ); Mon, 15 Mar 2021 09:59:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0AE8664F5F; Mon, 15 Mar 2021 13:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816756; bh=PutbLPfySmXgGXfCj/xiBvob+lHf6Yw9ssvPM9ZX8mU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dvHPCyvovIzsjxQun6luEPiNjrrMZs957x7CBtiIDlslyhld3Y4Zn+9x3sX2QDFXS zG3GCLFKLaeS6KexqFQK4vJUXioCznY/GB96cn4xPBxrVixuUZScmBQNGNDCuH7kDN t+4UqdEUrlA/1yrlf8xbHeaFmjwh7BM1wcefFgLY= 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.11 106/306] drm/shmem-helper: Dont remove the offset in vm_area_struct pgoff Date: Mon, 15 Mar 2021 14:52:49 +0100 Message-Id: <20210315135511.230816332@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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 @@ -527,15 +527,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); } @@ -591,9 +595,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);