From patchwork Thu Apr 11 06:59:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13625510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E155BCD128A for ; Thu, 11 Apr 2024 07:26:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B94C6B0088; Thu, 11 Apr 2024 03:26:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56B786B008C; Thu, 11 Apr 2024 03:26:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4097B6B0092; Thu, 11 Apr 2024 03:26:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1D1146B0088 for ; Thu, 11 Apr 2024 03:26:26 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D1D29C0A8A for ; Thu, 11 Apr 2024 07:26:25 +0000 (UTC) X-FDA: 81996417930.26.2B2B16F Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by imf10.hostedemail.com (Postfix) with ESMTP id DE06AC0006 for ; Thu, 11 Apr 2024 07:26:23 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UTrztSU1; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf10.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712820384; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fahG2thEVcPex80d2G3uCTOF5N5hyXCrixaFMbZYeY4=; b=Jdlzagr5Adbq63B7TPWcicImn8IIHN4SvsjylgKEaQyQBBBtGCSiWSiXMeBdxjSAeSAf4i PvWSMVjzj4vYhoTZRyJEldgqC4oyMBeD0IBIhksyfsEV4oyL9ozVt4sCzjj2kRVyAqrNFB DYcrCatvfofE/pattqXdxal0DVNbmcE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UTrztSU1; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf10.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712820384; a=rsa-sha256; cv=none; b=jIz+uZX1G4EhNfYQMrQVYPIjvzME5+VbSGEVC2uCRBVzB31XliGiAvlG17y7z2eJtkBobc cgrpPWdReMQ8DQA2aut9hAPiAIBDEA9TfalpniBAK1CLVkIAO4hWrGSfvRWgvzSzi7TqAF PSapTHm/NyA/fNIbwbvjhZJsl3i+Z7Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712820384; x=1744356384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4juM3xfivhaGo2McCt1eiAUdmharbNFcAc8goqvqufM=; b=UTrztSU1ZcHTxHADgZMX2NPtRa0xAQQiFS9UzDPgpmXaXUppwrFZiZP+ hqa4ly8OjCgqEUAXDmV+a/N0LA0zbfRe1sXfl2cXbXr9suBfQZbZPsUJI Dw23ItDnBER/X6+eodtgvm0aYkcPDQWEdukMnsy1PaMRE8fyse+HQKns4 gMPCyY6bz4M+LsGqPRFwxqC7xFeo80ZvMAjd3W2PHfpB00hpt+mqKx8B0 RJEIHYz3MinNHhbIDcpjzF0soZ/kSYlNTRAuaPKo2Kqb7evFLPbFJZWoh wVNQ2ac8RyaVyCoqP4rF0RH8B4olQM2DK93Nufj5t+v6H30qOvaiAGGPY Q==; X-CSE-ConnectionGUID: fbVQkXcKQcm62ZwYc0LrUQ== X-CSE-MsgGUID: 5u/xj+wXRYaMk19LPnpn2g== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8074366" X-IronPort-AV: E=Sophos;i="6.07,192,1708416000"; d="scan'208";a="8074366" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 00:26:03 -0700 X-CSE-ConnectionGUID: HbYAmvT8SDy6an56H48FKw== X-CSE-MsgGUID: laxu6XeDR0Cq6Dz9keXnMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,192,1708416000"; d="scan'208";a="20848543" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 00:26:03 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , David Hildenbrand , Daniel Vetter , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v14 4/8] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Wed, 10 Apr 2024 23:59:40 -0700 Message-ID: <20240411070157.3318425-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411070157.3318425-1-vivek.kasireddy@intel.com> References: <20240411070157.3318425-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: cqngshksyn9o5tm159yf7qmthrbshffy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DE06AC0006 X-HE-Tag: 1712820383-634937 X-HE-Meta: U2FsdGVkX19aQZoS9lTYsqujuEqxRVQhrqtAXoVF9zwqs/TMIkUYe/Aamvbu356fz8wbrJmmngGiSiUTsyoSBUWahgH//R1cLXiK+ZmpHt12IFCoZRgwecW9MY4wm77O884+NM/lORgi1HoO6aZp3DxNnCiVC2o1Nx4vx5LuSKZJ/KP+Ps0KZuL3vT9k7FVs5JDyrv6DImtF/pr6pkpL3n4jE9E7tbGQiJegtOEUSy/fHpotiYbExVCtop5WBwFV0Xg6/rzW5eEakzijZXcFtHx+X+I5cgxg/1OTxQZDC+8kDKpHz6wVwmdJ8SPZo22+62jXGBW3DkfTYu4ZKDaBejA/v3xv0ByGPWnUElReRzwho8vp65gYo8qhhU1H127FzxaTI0q6gHXdlb84etiLsAVL/mJq2vAoBTupf+D4Ets4g2gTj6bCsNzKuzxrw41ijEbVAq833sbT9AGOHtLvo7J7dkhoYGfXHfoNJjFKy2VBxoJ/PayvbL89r1eyetXSETFMmUzP5g4pQlOyD+OLXrUVaCqis5regKpYOTK7oxDK5298G+tqY8hL59Ke8O6weTzInCg+grQG5+i9zKGPMTy4m9lbgoXVvVpB6POMkoJZe2ISuw5pzQE8Ud6nU/IFCBF1SgkWSRw+fiHEA73beDwx/KnL6CFISvQQLU+U81mPUNxpnJB4OSgYDi7gacQZ7TugOGOPuylnsTyAelGfH2k47/L5OV6P54E8rRCgVtduZIo/1JStkQz4iZ2sCC1VmyrQdsicC67enf5Yd677pLnXrPBGxsIUkXamDPygHcHLwdQxKvJ5nZZ5qr0yXDIiORCWDqypN6tjg5CKE4Skz8BGUbbQozfdk+MzmlETScH1fryGMbHDT7QEuiuOEDOos1z2HU8IsADCi6qsyHsOqTe1J7TvYIWA9VI6+dE5TrIg2XE75xUQAA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 *). Cc: David Hildenbrand Cc: Daniel Vetter Cc: Hugh Dickins Cc: Peter Xu Cc: Jason Gunthorpe Cc: Gerd Hoffmann Cc: Dongwon Kim Cc: Junxiao Chang Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Signed-off-by: Vivek Kasireddy --- 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 c40645999648..820c993c8659 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -35,12 +35,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 = { @@ -56,6 +57,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; + vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); return 0; }