From patchwork Sun Feb 25 07:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13570756 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 777D5C47DD9 for ; Sun, 25 Feb 2024 08:24:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9062B6B00F9; Sun, 25 Feb 2024 03:24:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88F156B00FB; Sun, 25 Feb 2024 03:24:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 707946B00FC; Sun, 25 Feb 2024 03:24:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 50EC16B00F9 for ; Sun, 25 Feb 2024 03:24:18 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 209A61A03F2 for ; Sun, 25 Feb 2024 08:24:18 +0000 (UTC) X-FDA: 81829638996.23.6F61469 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by imf09.hostedemail.com (Postfix) with ESMTP id 5979B140008 for ; Sun, 25 Feb 2024 08:24:16 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=b9+3nzjw; spf=pass (imf09.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.17 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=1708849456; 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=G7Bv7jg6ypbCtXkKx3Gshd1i85VTcQErigj+7qKNZ54=; b=Ei1zKuK3iHwFYUsWmBYQ9NCWxWARIwS26P9zNILfIIA5hmT32AL/canpi5zmyh/CvmZzEV jvpsBxNjM3Fhwza59Fha2svTQHYVplRylxGnN5wRR5C8p1y0hxq04zmKQZCGqUGuv677iv JOrCbgHpE8cTJqzYEb0zdPkFti1kGbY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708849456; a=rsa-sha256; cv=none; b=geuQhuoMg/gZNiwdZegWeaERFMsevyd0KsPytLDf233ZHVBVSvJ9o9Hcb8bTKKfipXVUG0 mQHmtnyfLyGjbS7T7rw77g1R/aNBRDX6Pz9Efw8eNh8MF6iDvy/PxmSCq4FzegW8RtJH21 lXhI5SyYxfDlbzWpFuBrTJ8P0gQFW4Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=b9+3nzjw; spf=pass (imf09.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.17 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708849456; x=1740385456; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tyJeBuptegtLMXafEhsS2DHQW53sLM788gfa3Q0ViXw=; b=b9+3nzjwT2OoBXEhSCbBF7UFxnfY1wHGpxFofBp3aEGHgumqkQ3Tzk9Q TsBPJcDtcpJijuejOiUz69xytwVmizi/suKFxm63xjXCpa/Wez4LvZNXf 26iHlVN7yFz9sKnaLZ26HfudIv8d6m+0GAROxvlInbb8rQQCLGx6uioAU BsnciihX6qGPuXqBcqXxtW9lZQpspJ5C/0E2NYZkua1KsfWhL4iodAWRO 1fRU+6AfU9tWY1NNSFRx9FVDM5eKr9GkOLU0kgMwb6j6D7jxkw0Td8Jay JXKDpFnhUD+PoABDalTLx8HZP90A413hKZzuCZKFJx9E4zPWGSCTgQF+4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10994"; a="2988365" X-IronPort-AV: E=Sophos;i="6.06,183,1705392000"; d="scan'208";a="2988365" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 00:24:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,183,1705392000"; d="scan'208";a="6783255" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 00:24:12 -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 v12 4/8] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Sat, 24 Feb 2024 23:57:00 -0800 Message-ID: <20240225080008.1019653-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225080008.1019653-1-vivek.kasireddy@intel.com> References: <20240225080008.1019653-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Stat-Signature: krorddu5r163uzzksa9x7odpzr11mary X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5979B140008 X-Rspam-User: X-HE-Tag: 1708849456-479639 X-HE-Meta: U2FsdGVkX18v/vSC8CDFWUFH3jCMz75WEqp/JNcPfkphFPmQdGyIooWJS6tpnJSDDK9xVD4LtIL3q4AvEdlor/XanDoppb4rUpMdPRbxUGr1oeGDkImEBG16WLYa1mkJ4Rwe7FlmFSGAYaZLGdEK6tsRTPDxw1YjfC5Y7KKDJ5VNeJrXPWgOeFY9LacAvJGOsRl7Gh7ca0vtG7WLEmWW7Rpv/XGCo6wNcsO/J8k5LnE8xJghag56h8IG/n36Xjsl4EGp1i9zdKc0dww7FM1GvdcAk73QqkeCYbLA+15HzQd282bBSKMfa3hgNUulzlY09gwJc5RK8MiibP43bCTgUis4BEIN4ZVmsZVEIyiB69biYAsaFJWXtFclw8XiEvIxmd5c4jDBYDO4Clmf7gr7apkiawc31S4OuWPu0BHwsez4EE5U7QoVPFbG/hEA9PKy2TAnro+Paj4GQe7L+Y9kWUhytEGEgfhvgAHeHqnxkVTMbfbF8RR0qneSaUM6uXEnCdXCrJFh0NBYyug6/jpSxbtbMdV5uvJK4VdcaUjOCwSuAYaF2qLGXaM+v+OVCepkK4sKh8w0dMADLDfGH7VycKoRitBB1vPQp05sSyeSbyZV8ZqOByRfMxIfd59vzxod2LuBa68ne0G+baZN7KQGWM/JLSJRZsj3V0g+Op03eVVIkw66plEOuv2+tDSb/y2q1ZjGTQvgI2jA4iBakRHdDBGwc41PsHRyqWNjdS7CYypPY0tjPwvVMHvC9UX0YeRkjusGlj6SmZYnslnqbxDQQuyRC0FFx6TJCOery08RBIBikdmysZyjtMSPouKvpQNmOI7BrONQuD0EoTtxClEiHAOyIps05FwbwZWwoBQbqdUoNYbARm+KcO22znbqdoFgM6BnxaSXvT46LMS0spmElQx9hMmbDeyMbwz9ARaCaR0+EoWvAMHP6g== 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; }