From patchwork Wed Dec 4 15:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Kalachev X-Patchwork-Id: 848242 Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0931C205E1C; Wed, 4 Dec 2024 15:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.143.211.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733325470; cv=none; b=JEK2HaXbzWFXWLX9fb3+5vRlIoqdkXygLJjSVs+2XmX088W6D/hcyKtcweP9lMN3ymT41JOevn8FKiteoWUdsOe3CM9pyPKqoSfmEUNQy0voCsyQmCQ+8hWwiZZXWAapboocqafAG3ySL0wHcIp5v1Nz4Imz9FvWOVP1mANjitI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733325470; c=relaxed/simple; bh=imTyW5qs4VLxVBzu/Kz01yfJYL47jAGErlyACSyqeFo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MeTsixYBZZW82iAO5kfBfZpYeLa7vsqk4flmyEhtrESg7m4mhitWc6KWG3h4KORqrWaF9KuvSWopmIM9JcAIvjjpyp9X6dyLMBgRifg8r1xf0+NsfUeQYkLCgTsqMbfAdkZ5RC/YMQw2qg5LFAsj4LsOMAFW+Sssdih3jzpzvMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru; spf=pass smtp.mailfrom=swemel.ru; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b=GezznGjh; arc=none smtp.client-ip=95.143.211.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=swemel.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b="GezznGjh" From: Andrey Kalachev DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1733325457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=stfWGS3BClOC/+OPYKfYd33IKMOm/Qu4X4Okloj0fNw=; b=GezznGjhNo2/JXbSl4qJFmrYCJR3E6vHvG9hTFOll3zaVmZ5aUwJXcvmtO1MwHKxlxlinC N9yi7MYwVfxvfhUjMwTK+upuFQfDpuNtpseSHA6P/Hy5xCoMMSyoKER+RoHCABxqKhPqnr tvxtpYHFsGwuOCrNUkHb3WUOWvlqi1A= To: stable@vger.kernel.org Cc: vivek.kasireddy@intel.com, kraxel@redhat.com, sumit.semwal@linaro.org, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, kalachev@swemel.ru, lvc-project@linuxtesting.org Subject: [PATCH v5.4-v6.1] udmabuf: use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Wed, 4 Dec 2024 18:17:35 +0300 Message-Id: <20241204151735.141277-3-kalachev@swemel.ru> In-Reply-To: <20241204151735.141277-1-kalachev@swemel.ru> References: <20241204151735.141277-1-kalachev@swemel.ru> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Vivek Kasireddy [ Upstream commit 7d79cd784470395539bda91bf0b3505ff5b2ab6d ] Add VM_PFNMAP to vm_flags in the mmap handler to ensure that the mappings would be managed without using struct page. And, in the vm_fault handler, use vmf_insert_pfn to share the page's pfn to userspace instead of directly sharing the page (via struct page *). Link: https://lkml.kernel.org/r/20240624063952.1572359-6-vivek.kasireddy@intel.com Signed-off-by: Vivek Kasireddy Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Acked-by: Dave Airlie Acked-by: Gerd Hoffmann Cc: Daniel Vetter Cc: Hugh Dickins Cc: Peter Xu Cc: Jason Gunthorpe Cc: Dongwon Kim Cc: Junxiao Chang Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Christoph Hellwig Cc: Matthew Wilcox (Oracle) Cc: Mike Kravetz Cc: Oscar Salvador Cc: Shuah Khan Signed-off-by: Andrew Morton Reported-by: syzbot+3d218f7b6c5511a83a79@syzkaller.appspotmail.com [ Andrey: Backport required minor change: replace call to vm_flags_set() in mmap_udmabuf() by direct modification of the vma->vm_flags, because the set of vm_flags_*() functions is not in this versions. ] Signed-off-by: Andrey Kalachev --- drivers/dma-buf/udmabuf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 2bcdb935a3ac..e57d57a10bb0 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -33,12 +33,13 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; struct udmabuf *ubuf = vma->vm_private_data; pgoff_t pgoff = vmf->pgoff; + unsigned long pfn; if (pgoff >= ubuf->pagecount) return VM_FAULT_SIGBUS; - vmf->page = ubuf->pages[pgoff]; - get_page(vmf->page); - return 0; + + pfn = page_to_pfn(ubuf->pages[pgoff]); + return vmf_insert_pfn(vma, vmf->address, pfn); } static const struct vm_operations_struct udmabuf_vm_ops = { @@ -54,6 +55,7 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) vma->vm_ops = &udmabuf_vm_ops; vma->vm_private_data = ubuf; + vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; return 0; }