From patchwork Tue Dec 5 05:35:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13479376 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 9CA2DC10DC3 for ; Tue, 5 Dec 2023 05:58:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3875C6B0075; Tue, 5 Dec 2023 00:58:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 337186B0078; Tue, 5 Dec 2023 00:58:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D7B26B007D; Tue, 5 Dec 2023 00:58:56 -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 EC20D6B0078 for ; Tue, 5 Dec 2023 00:58:55 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C575D40197 for ; Tue, 5 Dec 2023 05:58:55 +0000 (UTC) X-FDA: 81531711030.29.F37AD65 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by imf21.hostedemail.com (Postfix) with ESMTP id C260A1C0016 for ; Tue, 5 Dec 2023 05:58:53 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QBlfkewm; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of vivek.kasireddy@intel.com designates 198.175.65.12 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=1701755934; 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=NHjt8xV1nNZWVj+2yJGuK3THMn2jpEi+B3+Pzc9Gc6PmjPKnEaFngeI3rOBR365cEA+c5K eIKA2WGMqzUynJaR/JDqZZ1rR9QVDG+Fy3w1WsaQfc3ljdNXg2yxY3su8jQKSTX5j0RAzd VPbvP41D+/m2MrLRC2z9wAAcgqRxlSw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QBlfkewm; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf21.hostedemail.com: domain of vivek.kasireddy@intel.com designates 198.175.65.12 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701755934; a=rsa-sha256; cv=none; b=b0PsLqxm2TktTWc6ArUpBP7qXebGQhxPBC1rZ8/H+Qhzc1UyWzdeXBfIEaStCMXoAMHeER Ymmq3YDHfv38i1+vSwsOAnvc3UPNDT7dObvGsQnou/VGR13PYMEo60J74P369AQ2SnU+Ne BE04L7UmpyAbcl3n0NTQvOG23tJHcco= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701755934; x=1733291934; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U5Op4CjhDDAHfKtiDzpe6+9a1b7R8CllBxVTE/TesJE=; b=QBlfkewmSkH3F/PRtnMfqDPBP7Fy7qv2m5D4tveuWaeCIWGvJwrwRUMS gtlEyPnDj/VQgksRb6tmSQzhZxWDtfgYOLZBSch+CAVkt1yqN2Mt1RLPn kPc/r9cybOTn8bZREyutjJ8tH2oYkyYHRe4KfJZlit3+d37fDOQ58b7eR tyfCDw9SsIU5be0y1rMt8PRcDLVwcP4lEEAH9UZP60THTFNS8eoIFPl34 vQDbWtscjOYlrsdY6dPR8940r3DvLiUvZ8BRRRZHuONupdje5dcC4PCrV ELS5+3z951FM456YjMRArVmsP/0eUdAY58CFsfecHyD74Ngl7wVmpu63C Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="906305" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="906305" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:58:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="888807724" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="888807724" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:58:50 -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 v6 1/5] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap Date: Mon, 4 Dec 2023 21:35:05 -0800 Message-Id: <20231205053509.2342169-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231205053509.2342169-1-vivek.kasireddy@intel.com> References: <20231205053509.2342169-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C260A1C0016 X-Stat-Signature: hnp549a9415kfjre8zc7f1bqn9xxbkoq X-HE-Tag: 1701755933-577855 X-HE-Meta: U2FsdGVkX18on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VsdrH4ivAPWvG5KDQ8JLJsVxW87QlfdGZ7hwyPJ33J8ilBXTqO5KGZWOeLGz4+7SsLnENcGCFZwMP0e5mVs0Fw+JTSjeiGN8HcmByoUQF4YU8rF1Us7P6nLoz5GoigOokAJQl6XehzbpqCmHskHcQZ2+sjTNM4X/Mbnh8kvCrAQl3B0RQkgb4qK9h1tQB45L7HvDhs= 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; }