From patchwork Thu Apr 4 07:26: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: 13617394 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 305ECCD129B for ; Thu, 4 Apr 2024 07:54:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C93856B0092; Thu, 4 Apr 2024 03:54:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE45D6B0098; Thu, 4 Apr 2024 03:54:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CE5F6B0093; Thu, 4 Apr 2024 03:54:37 -0400 (EDT) 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 6C2FC6B0092 for ; Thu, 4 Apr 2024 03:54:37 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 39F18A151A for ; Thu, 4 Apr 2024 07:54:37 +0000 (UTC) X-FDA: 81971087394.30.CA95212 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by imf14.hostedemail.com (Postfix) with ESMTP id 209DE100005 for ; Thu, 4 Apr 2024 07:54:34 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="C/ur8kxV"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf14.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.13 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712217275; a=rsa-sha256; cv=none; b=8GG2rE1FXOjhh9DDZDJJsRuvJ9JVDoWctxl0EjYdHctc4ShZwRHzaNmQfmu5qY9E1HqcNe Q0JA9yKvU2R+NCKQX0AiCQfVYiI7ID9tl03pLaWxoN8o8oyRUCDD3SpnIu+rTVHWAK54x4 C5i8D511ReAlqgpApSvq7Sdzql3HiOw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="C/ur8kxV"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf14.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.13 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=1712217275; 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=m4dkpHJdcTaEHM6m0K7qqdPIqo1xBYzZLmcspcWdxuZgkdSdliGFsv02UarvKY3ZI5FbSE htfsbUl3V7yzEmzOFprYuikqyuKNfata9nJ7/3uyfedvqd3MwEvgNYIEjBg/QvklVDv/Bi 41/T91vbSxFVPfyG5ot6Xj54fI1Nx40= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712217275; x=1743753275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tyJeBuptegtLMXafEhsS2DHQW53sLM788gfa3Q0ViXw=; b=C/ur8kxVqN72dCnS6w3cRXNlc3H86EZqFCejCRdPM6h4HHSxt6c0F5Wy 5pEX+SugXnY0u4YkMDwDgJvfI/dGF/i8T0GBuAj/o+JZH+nShOjBGHyfn shz8OddtYMIW9BTiRhRqJCmZCvsVgS9IANQEIJLfuqQmPP9SvfiRJgnQP BjsC4YWp7BLKHpIqsZ6TgLIk9GO2si/jnW1/BjzJXP//hLPbTZSGgh74t gUTu8eZnq2aUTIOXEjo/jgGJ+hpivG3sYVkOJE8qOjWq2fyx+swkQNMcV t+j1fGJCk2l6AxLiOGVfvqlodG/17xGmZvcKYcW8+rp/17v7wQDQMIkIR w==; X-CSE-ConnectionGUID: d+WEnkonQ5OuezsXxWgspQ== X-CSE-MsgGUID: aNliYFyYSS2rac3s91Qr7w== X-IronPort-AV: E=McAfee;i="6600,9927,11033"; a="10450801" X-IronPort-AV: E=Sophos;i="6.07,178,1708416000"; d="scan'208";a="10450801" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 00:54:28 -0700 X-CSE-ConnectionGUID: jnjQ46gVQ52yJhGu0ZLl8Q== X-CSE-MsgGUID: 7Z2c6NZ1SzKO78d3Nx6ccQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,178,1708416000"; d="scan'208";a="19298766" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 00:54:28 -0700 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 v13 4/8] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Thu, 4 Apr 2024 00:26:11 -0700 Message-ID: <20240404073053.3073706-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404073053.3073706-1-vivek.kasireddy@intel.com> References: <20240404073053.3073706-1-vivek.kasireddy@intel.com> MIME-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lvhkUlCOwElGQF14E42nlO6cQeO13 S9CmQNqQ ACDw6oAD7mdEaD0zFubwpFwT69o7v+SUgpHPINDMeQJ0qSuJl+eJ+bPY/Z89GtvR7bDUqwoZkzS1Bfr0YVKxD9wm01juqdEpNFCoWMTdptEBIIMsBr8RVSTLMuGobxoJZlTG24Bw5sTNEQ995t0sQT7nKTNSDve5WjE6WSXQ3ZbEdxEO2Q/t1VQ47JJGlOo486pp10N1gvefTcME0VhPScVKif0XCNuBCRz3QjiKQz42GLqWltGENjc3IszsEMpRzMTyPMgYvExJJFWlrZAKiGNNE5J0Mw1hifgPDUmhEZEwHFNY= 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; }