From patchwork Sat Dec 16 06:05:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13495480 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 09209C4167B for ; Sat, 16 Dec 2023 06:29:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 416296B00A9; Sat, 16 Dec 2023 01:29:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 318766B00A1; Sat, 16 Dec 2023 01:29:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01A086B00A6; Sat, 16 Dec 2023 01:28:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DBCEC6B00A7 for ; Sat, 16 Dec 2023 01:28:59 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AD1A812064B for ; Sat, 16 Dec 2023 06:28:59 +0000 (UTC) X-FDA: 81571703598.20.1A5897B Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf11.hostedemail.com (Postfix) with ESMTP id DB2EB4000A for ; Sat, 16 Dec 2023 06:28:57 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=imxovGJr; spf=pass (imf11.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702708138; 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=OFWxI1i+p4efvmikRdB46knSq10ZwkVaViiQ0SsvQMA=; b=STP2suRRCkuerzzfKdHwoK8Zso2ZgHDP29JsorJAeuxvpCtkwmAvlizRUWAr8dVooyUiy3 tKwqqiLRnN77zUTeij9Af0Msr5QGXZ/VvrY/hISeLVVXGppJBAahqC0AmErV10T9m6icB1 9oS15bSn6yQGom0cXzicol8oRtOfl0U= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=imxovGJr; spf=pass (imf11.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702708138; a=rsa-sha256; cv=none; b=6SFUa0ImMOU47mRZUdkXyMxlGkXKNfaM/WT22V0iphDvWPEv6SbU3Dv/Y7zTy/0l/PB4rH BeDYd3shg3/clIn7q7vyZ+F6IGGeprXK/Rcz6UdKO9VeXlp4ESC+2YU6F45r0sX816oNC5 hbPtEswmJ/WfKJxU1XLLCB12aG4rzo0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702708138; x=1734244138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U5Op4CjhDDAHfKtiDzpe6+9a1b7R8CllBxVTE/TesJE=; b=imxovGJrZxh5oH2QSBvnxFgTkBy2JCYtYaPqDMlYGqPJKmjpaSeRFH3R Q/QWqZixMH9M7jg4Vgm9FZbJ94AbkzGU4NflmmwN22a+mE9x1udJxOAoR yyZ/Y/lRMQuO+sxF9ZQ8H4fil3ziukNrym9q5oQemLAGzb52TxN/OGHK2 PGjQgYv2LNLu1M1MPY2YZUUDQbuIcaLUjndx48kY65S2GOdqOh4GxtxKr tQGD223S0r2B9J7UxlPMndq9hwjGzIih4wF6RV09mbLVk3Bo8c9hCHlC1 CZQvkEOXaN7KGMW3yQRQfuocIMPci8MZXbSgM7eACxzS2sBgOLbBrpf0N Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10925"; a="2186018" X-IronPort-AV: E=Sophos;i="6.04,280,1695711600"; d="scan'208";a="2186018" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 22:28:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10925"; a="751178900" X-IronPort-AV: E=Sophos;i="6.04,280,1695711600"; d="scan'208";a="751178900" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 22:28:54 -0800 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , David Hildenbrand , Daniel Vetter , Mike Kravetz , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v8 1/6] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Fri, 15 Dec 2023 22:05:31 -0800 Message-Id: <20231216060536.3716466-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231216060536.3716466-1-vivek.kasireddy@intel.com> References: <20231216060536.3716466-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DB2EB4000A X-Rspam-User: X-Stat-Signature: k99678aokwi7uo4r7rfk5u5ertx6swfu X-Rspamd-Server: rspam01 X-HE-Tag: 1702708137-821810 X-HE-Meta: U2FsdGVkX18M+/p5JLPfparRFIr77D055KETgXwfGvfGSqOjj+MX4E1cCr8uav8J55kVENQT60KKqNZFxdShQv8sBwkUe2ON9HUBHlLcmkbsm90HEpzHhuSy1bycr4Jyt1oPLA/aKVGToPTB/AhzNcAdNWzaOziokKktAbSoRNibfJFu29gk8vP6nG20dkYk0ZCdy+KchIDBWEzK9AjToRZdp1/cnxpSvLbjftX+0X94/exbw0lV49yDEnYcM13ukIwf1tcKGtekKNcZFaqxtOysYL23n3rea9UbMnesuKWCpK+8apvq+yQBe7ZNmp1QMbJoZ+x8itbMsVFa8VK9KBDALACLnwU3GWaUelssWXuSW/vmh13VmoAt8AC0TPP8eds+bfxYW6+qKEEYbaDxn3OMrsrxodzeEIa5N7Y/5JamJp5DJSTYlbDhcfc42uS9DwzzSH0tD9UUWsXkeAm660RV5v2hECefWgIz9Y+6yZdKSGsuIE9l839DUNE/QN29Af2UOFMFVojYN4thHNNqm9j0Vx1QR2V6zNp5YtmsSjhJJ3zREsGo+i81W5MQkbGedCqtCCTayAIzKUb1REv6T/n3N4nM3NA0G2uBkVRDRymq98/xdA3TNLkmX6dlf0WnqKB+V96ya3cP/HXLP6qKZQyrGgtpc8UXeM3OlN7Lw5ez87ZGtk7xpY95cXeSz8GmKqiohm+qgAZ5QHIazujvpKf4kUKqGAeaJb4/xn/vopGV0rI4+wIo5HFohWgVM9CSPxbxq1DIb1wZlY3lqlLD1pzXWq6PRNmkazxFTnajhOdGFqFcVebGa6NBOPVuvTfdFLdbK6744YVhuEXoRy2dmEAnb6gPwZbjwR1r1Hll+4QZIsS+TCam5B0MLnITVc/pEqfKNluIREdXs/iszoiNUt0ujztzxeNJU/ytmBiS83C75LHJt0O42w== 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: Mike Kravetz 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; }