From patchwork Mon Jun 24 06:36:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13709045 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 56071C30653 for ; Mon, 24 Jun 2024 07:05:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ED6C6B00EA; Mon, 24 Jun 2024 03:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09CB06B00EF; Mon, 24 Jun 2024 03:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF40F6B00ED; Mon, 24 Jun 2024 03:05:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B67F76B00EA for ; Mon, 24 Jun 2024 03:05:30 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 799D8120B19 for ; Mon, 24 Jun 2024 07:05:30 +0000 (UTC) X-FDA: 82264896420.25.B07189B Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by imf22.hostedemail.com (Postfix) with ESMTP id 5F78AC0006 for ; Mon, 24 Jun 2024 07:05:28 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iQK3XgPf; spf=pass (imf22.hostedemail.com: domain of vivek.kasireddy@intel.com designates 198.175.65.21 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=1719212715; 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=BRJfBTOc9Ht9AfvNPFbDMpild2soCLLjG6LLdkG7QSI=; b=8Uzc8MoyPFDaH/LEbEUhmtO9NGUPCQ9HGt+KTSpgEwe+1PXodFpo/if3nfArSKz90lkioF /bJYvDDKGsFRx+DEL/ltmbmPJ3ot7xkb7Jkig+s3bB9JYjjV3Kd+IR28FWGTWFxgFvfU7+ SAvuq7Hgp1YqWKDTAz0wbIPLB/aIrNg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719212715; a=rsa-sha256; cv=none; b=jUQo1/ZuJmK6cMRfh5kibgWiNZct7xxDufN0bJ5lh/nI38LXkClJjkRzmYKdjjrhlMNWPc 7Q/pwqBe4hJ3hh8KS1hQ4LQr4CFiwIhPFhZRMQxoSjxgGWmr2ZJsrVo0jJt/LAJjq+iSl6 nya/psSZiraLOhqGvHsX7vb2Grne2gQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iQK3XgPf; spf=pass (imf22.hostedemail.com: domain of vivek.kasireddy@intel.com designates 198.175.65.21 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=1719212729; x=1750748729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aVFPbZFzfDCXaBzmiLs1+yJntIbEwJ7MP8W2MkHw1Uk=; b=iQK3XgPfaRW8Qtmqr/gtam0FevNlTbig6birwwP3Vf0MpvEHkrAeE1F/ mzd7nLyRzb8ucRnA4uw3nvn6uDfH+n4T7G1PbwrbCIsREYI5boaaV29AB 5bmcPYY2IMlFT9yXA87dxw2eRetuezOLsAt9o34cNX4gUmvxUtLdti8U8 NtLrcqbNDb2UOtFwjDkjX/Rswew3GeSRE5e46aCujM7wgMXrLXYpiLx2e dCyZzuzaa8NQLs2sT9Lul/vCYUQz0Ssfes4cbmqM7XKy4pRNmlVWe9vl7 TSa64peNON6rj9YPDGztvx64LLBml6S2UmW7Mh3zNJ7ml4JxrZkqDI5W5 A==; X-CSE-ConnectionGUID: 7xRSQR/zStqTQASgbA5vEg== X-CSE-MsgGUID: tSgpcoHDQn+/6ECUaIxfwA== X-IronPort-AV: E=McAfee;i="6700,10204,11112"; a="16134957" X-IronPort-AV: E=Sophos;i="6.08,261,1712646000"; d="scan'208";a="16134957" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2024 00:05:25 -0700 X-CSE-ConnectionGUID: bDS8QcQBSLyPl2PCd4l4fA== X-CSE-MsgGUID: OggPT056QIuRPgnNIz8lBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,261,1712646000"; d="scan'208";a="73955875" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2024 00:05:25 -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 , Dave Airlie Subject: [PATCH v16 5/9] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Sun, 23 Jun 2024 23:36:13 -0700 Message-ID: <20240624063952.1572359-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240624063952.1572359-1-vivek.kasireddy@intel.com> References: <20240624063952.1572359-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Stat-Signature: r9w65xypfk5mdjib1743ij8s8h9uabqs X-Rspamd-Queue-Id: 5F78AC0006 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719212728-989097 X-HE-Meta: U2FsdGVkX1+1jE9J9T1JbbLJb6ila0t810efYajaJYxe+hI7MCsAeabUFyOszQAmpyaWBhac9lnCQObJe0WJWJMrCcpG35gH9UikwUspejZ7t26Bky+6rltQA1HCQilK0ovYftFJ1OTBULdIsQ1ODDoflRgtrVxooCNpisyfReMR3iMHVgebhY+iR/REcGH+A5C06o7BAS+WuRt3goVWzR3E+oaiR2X8C9b+X5sXnKQdgz6ObeGR1tlV4exoLTvCQVxnG46SdsnC20sAZpPFcJNINKXi5pOL93HgxEdatW/slUWnhADgl96GlETsYowDrpHxl1zxDSq6vq4CFqVTxKQ8x8bg08nlCm5Kpyy0c1DsUYSf+CHgNRm5s4EeqzfazeZ8VIV/1xljaDsk3cV1z9QhYUZ162H/ME90aQZ6kerwgY0iQUVUHRs4UX4zAmkuq9Gcfu/p/iPzlElSLgbgeTK7EPG/4WwUAZ5wqu5pP7HLCSH4y8mdNDLljTXm3ET81sNYc9OhC01Lc9JNwUlzsTkkxmYrhR6dAx+FctNF0xBQpef+jSr399QCyEWk39d3ZdeH11UJh3Egx8dM7u+o/oQFuQ4qIvDGDeHLTym+ovSiidfMURFOneJcwluusQ3muA2xhZkqLJI3k3rHhSGzjUBxCoxzr2X03wCIqqAILEfOSKKfTDLyNIcuoRq4vfqCfvWDUvcR9xs7iaMMApsTYUAtgQ0Qec+025H/rlu/ER9FB8sTQ/AKf212xROv3Q9qpXztya3I1Wc7iO1Tqp84RTGnx2SeUoIWscMIKVM9yQAivdgKE1U54kZkU2mAyGoYkoiElfaYbPY5pHW2YLsZnUTyugbSQY4cWAvc9YYJSjS+J51K+k8JENfLJxNM2ajUwWBj8h4kqmEafrgEoikvNhE3FnrgStzD5M7pbvAUeJxwhgywNytCcny4VEAOsw8jym7+F2PapIZNmbeGDfz XcAQSdQd fI4MYh+4jSW7CtTv68bnDP+4aVnRDQUM4ClCWgpz1ZNl2HSSaAcVP2XNWIrUEf0/LH2lF8mimwm1FZyURaxvd5OWlIbyKEnOFtD6y6O4I1lkXT2J6040ywZx85ijypb86Qg9PDdhvYXNtIQtyHG8oy0A/cG/tEgNUAaw35+s/nn3aD6wXFKbAkX+P6LMNIiWmSbRwfdf1NmrdK7Imu84TfBkf4moEJ15Od3wGL3l6HGdwYD8OjMl+0gAJcYnVD4XNSqvvBT00MZ98+QE= 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 Acked-by: Dave Airlie Acked-by: Gerd Hoffmann 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; }