From patchwork Thu Jan 4 07:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13510849 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 B6F10C4706F for ; Thu, 4 Jan 2024 07:49:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D85506B03B0; Thu, 4 Jan 2024 02:49:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C49F56B03B1; Thu, 4 Jan 2024 02:49:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FF666B03B2; Thu, 4 Jan 2024 02:49:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 624596B03B1 for ; Thu, 4 Jan 2024 02:49:00 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3A4DF1C09A1 for ; Thu, 4 Jan 2024 07:49:00 +0000 (UTC) X-FDA: 81640852440.27.655CAC6 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf12.hostedemail.com (Postfix) with ESMTP id 40E634000D for ; Thu, 4 Jan 2024 07:48:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gFYeQ6BK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.43 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=1704354538; 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=YlUTd2Z+cHH6Q5yW6B+ya3zZryoGjaU/IVuz0hL+x3ARbWUVMZ30jVkNRsWMlxlGcxlkmf Vs6JyKRbb3c2dhpYKhfo9WVGkrUPRMSbqSBuLYPrbJ/eAJ5liLd/A06anhlq5Jw1AL9HN2 +ge3YjekF4dDxDFrzU/LGRV+Q1sQioY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gFYeQ6BK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704354538; a=rsa-sha256; cv=none; b=j4gtw8KvwlUdfzY0tlK8WPSqqY/E2nKWvXTlZWUpqt/nWGYsnMEmzSiGH837/LHQHzV99l wnzFh6G2G7g2W6tyjWcNhfvq42hZGJ46KH9cOUtNn28L+zr6PbVN2cE1LfJvWmlh8wJCl8 zDiX9oWTnEcadyJqLU6BBS//xzfewCQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704354538; x=1735890538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U5Op4CjhDDAHfKtiDzpe6+9a1b7R8CllBxVTE/TesJE=; b=gFYeQ6BKPLLHTYZwlHyJaISaTN022SeeTGXd9N/eW5zS/T+Z9H2J8xJW 3eGPUIKSJW9IqOrGvjSjhiO5wrlJv9IiWRVCn/9EXpT0gRiAFGJuePDKx rKa7o3a01HpPbBQwu7UsB4Y1VfAD+KdYF+bFBLGBBJOLxh0Pjp/FuvLON Szhi+vh5oj/eF/HABprsjKPqyNq6CsNYzeIVoPbw0SUbBoongCzQckpy8 e79mOYujERExktuLPkyIqNLVorIvEIAgBWxJSgkhwm4Sfdv0Nvt7MfqRg sEsmzeEZpT8FGENWQ0dbDyG0vIyCu4fsE2EZLEge+LTEdc9idMqpHW1G6 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10942"; a="483331095" X-IronPort-AV: E=Sophos;i="6.04,330,1695711600"; d="scan'208";a="483331095" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2024 23:48:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,330,1695711600"; d="scan'208";a="14776719" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2024 23:48:47 -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 v10 1/8] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Wed, 3 Jan 2024 23:25:11 -0800 Message-Id: <20240104072518.807950-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104072518.807950-1-vivek.kasireddy@intel.com> References: <20240104072518.807950-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 40E634000D X-Stat-Signature: k74rz57hcbp9p4jaufm1dd1tezfajzuf X-Rspam-User: X-HE-Tag: 1704354538-838865 X-HE-Meta: U2FsdGVkX194P4A0h9rWlHO5+Ore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unZ+iLNpVRmM8t4jQmFFCBHTz+WAL2WEN4yQMFC701+Tk3SH2s0s2D+7Jisaepb0VGStU7v+zkfPFBe9M7J0OQTOIo96dyvcq9m6R8WnhUPrUAPAXMbBWYEY+uSPu4Yt0CLg8H3DGA318YLXZIGA5UzUfbYRlpV3e2UQ8SxS/cVgrLDF7huAlT5yTAmPxrzbfZRcU5IFo= 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; }