From patchwork Tue Dec 12 07:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13488634 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 68476C4332F for ; Tue, 12 Dec 2023 08:01:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECF286B0297; Tue, 12 Dec 2023 03:01:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E57A96B0299; Tue, 12 Dec 2023 03:01:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C82DE6B029A; Tue, 12 Dec 2023 03:01:33 -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 AB31E6B0297 for ; Tue, 12 Dec 2023 03:01:33 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7A8C4C094B for ; Tue, 12 Dec 2023 08:01:33 +0000 (UTC) X-FDA: 81557421666.29.FFF8519 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by imf17.hostedemail.com (Postfix) with ESMTP id 56B8140023 for ; Tue, 12 Dec 2023 08:01:31 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TfsS5uFq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf17.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.24 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=1702368091; 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=TqxidEFtgI3NW5d/YBUZlyfU42qkeV59ysUFrDhe/5cPQiagFxawFpbFvxRQkLxBQWb5Oc DPZuoXb8VrSWCllJmTA/s7SBIb65jeCZjUq59AX98eiBN+l+bFKekFVJH4JLfwp6fZQyPQ dijbkVNwy19RcFBkhMMEbbPK2jWAjz8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TfsS5uFq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf17.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702368091; a=rsa-sha256; cv=none; b=pdIB2Vfrsm9ZcBf+2sTlDhDoYg7UcYCXyTZbBgwcdMm9W8Cu6ANtZMYrQcO1La1JHLtUgD nFrdWIkqaaJS3cp2nnGCgSYpQyVhAbvy58RdkFG58XG3P+Zjh7TzrMvx25vwvvMRIbGmPV XPcEE13fEclXTWH6mOy4NEvEZMFFq5g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702368091; x=1733904091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U5Op4CjhDDAHfKtiDzpe6+9a1b7R8CllBxVTE/TesJE=; b=TfsS5uFq7tEyN3ePyQXjeD33QWotSFNT03n4HmKzCrd64N2QhMr6LiqJ qATkhdeY2M4feMFKmK/+Sn/tn6if5p5l9DV3/ipvIQWvWaPnSISkVOsng 3s3ZD32JA41RN6oiVargvsHV4pRlRC6PIRztnSlqJBevGFv1irSu966PY UTwaAZt5Z24rZA1W7CyQe9O9JNaz56MRB6cBr+bHwQOlEZei7vhlOSjEz yMBuoFo4epf6YRtiB02AdD6mOGsTbVnPDslfjklExBsm4rVJqANCnHtY5 +zrPidcr7ol70q+PM6b4EgigtoUoM1e3CJQ33nGb1UtEg2OTuviZqeID2 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="397553943" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="397553943" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 00:01:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="802376320" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="802376320" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 00:01:24 -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 v7 1/6] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Mon, 11 Dec 2023 23:37:58 -0800 Message-Id: <20231212073803.3233055-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231212073803.3233055-1-vivek.kasireddy@intel.com> References: <20231212073803.3233055-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 56B8140023 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: orh7eqw3be4s9hzm8rmz4gmahm8u4ye4 X-HE-Tag: 1702368091-262880 X-HE-Meta: U2FsdGVkX18UtgbG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tH1QotPBCkpmZ5PZRFnYfZEp+AtB7d/rrF3vdppYY1/uv6/frcYHEBl9tDYL556nYuJeIaogDVcT3R44I097MNAFUFe7wkTCmUIt7r84dFnXh2eHzvxpU+mNt+qe//zIuQD9nsHFqNBUe+wTINXJ/3AsKItsrrfjrXNWNHBgMJALmnjVzOQ/6wvPlUX3TT3Rv3Bf3I= 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; }