From patchwork Tue Dec 12 07:37:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13488632 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 5B4D7C4332F for ; Tue, 12 Dec 2023 08:01:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77AA16B0294; Tue, 12 Dec 2023 03:01:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72C376B0295; Tue, 12 Dec 2023 03:01:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F1126B0296; Tue, 12 Dec 2023 03:01:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4BF3B6B0294 for ; Tue, 12 Dec 2023 03:01:31 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1D4E8A0959 for ; Tue, 12 Dec 2023 08:01:31 +0000 (UTC) X-FDA: 81557421582.03.2AE1F79 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by imf17.hostedemail.com (Postfix) with ESMTP id 6203140025 for ; Tue, 12 Dec 2023 08:01:27 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=IvXd3iCQ; 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=1702368088; 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:references:dkim-signature; bh=Fn4VrL9PT1xPc09AnfydK817U062UuA+fwc6MWqGemo=; b=b5MFJ8wtV+YlAvYp1XTtQOAA/BrGw48tJUDokahBc6S4T4dhu2l4Catrpctg5JJW3vDVHD Xm13rfoUQ0KnLnpT2mGRQU3Wo+LglDm77ff5aQ9XvYsFLIYBjYe9DQnbgJHsyQRYeN1CLv 7EK9v49Z9AVpqmp2jy2h16SLGVScpT8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=IvXd3iCQ; 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=1702368088; a=rsa-sha256; cv=none; b=d/QeTpQzcGBQ0+4qgTquJyMT7Y8J2W2oxXgYqgIyOSfKSiZ/BqYOgsFsZDBYrofQepP8du 8nPP880EKu0K8Hc2nBJ2to1faSO0MSjl1yYzZoiqGRt3qK84Szadmcoma42FcAy20cs0OE 4je5wcGl94IHXLx+oMVRfRE5Jt3Ksb4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702368087; x=1733904087; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=7Qgh4kMsznhcdHeDs93S+cQ+GO/HtIrx/+OgoDUQ/nc=; b=IvXd3iCQSToOsgU2KgnVhfb9gRzh1qqXSy/XjI51SXCuX5L1w+oeHBLp OI+i1wGHtMY1WMBHleK41f0Z0mZNDcjJrNekSAc0WIco3ty9tPeSe64lW ivX86KL7N7UTzXLizxaiR4+DByDK90HzF1rO+cUbmhMZMg8mvgNBR1CJD i9pfhk8ujJxbs5L5zdx0cDiIKT+0EDp+0OuC+xgKyNWhPSGt26GIXUaV9 PA1NBxSzVWdrhOW9VMTBO9jWuTwyjHY9V2JT9P1UWTamJRHzQ1c1F8qu6 h16TeDtOUzJuCGzZBrtaGe+NEtjm1K0AGGXAeC6b8XN9NKwUWd8HeaMzn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="397553934" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="397553934" 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:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="802376315" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="802376315" 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 , Christoph Hellwig , Daniel Vetter , Mike Kravetz , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v7 0/6] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v7) Date: Mon, 11 Dec 2023 23:37:57 -0800 Message-Id: <20231212073803.3233055-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 6203140025 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 11z7f8r3kcodkaz6obob89jbhjmjtk97 X-HE-Tag: 1702368087-677650 X-HE-Meta: U2FsdGVkX18hb7AWhDOzNmGNxnnYwzddEdLbKbOxWMHpEZzubZKBWHb9WL6d0ND4Y7J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Ld/C/q2CRpqo4WXlsAovs3neLIpqGzssyxHsRfMBMbHnUtF2zHukweCl65KIpYGXMmHOyLeQynJYBwPo0YyNLF7NU1Ds26UwOk735lJJT45sCAibrw/pwAqn9tJIcxxdh4Q2EKhxK8k8z/jKnpFv1HS9GPvn4B/HkAerO1XnyzY5do11iZQvrYsPCUKWJiIs1IP2ctkC6UxQ= 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: The first two patches were previously reviewed but not yet merged. These ones need to be merged first as the fourth patch depends on the changes introduced in them and they also fix bugs seen in very specific scenarios (running Qemu with hugetlb=on, blob=true and rebooting guest VM). The third patch introduces memfd_pin_folios() API and the fourth patch converts udmabuf driver to use folios. The fifth patch shows how the udmabuf driver can make use of the new API to longterm-pin the folios. The last patch adds two new udmabuf selftests to verify data coherency after potential page migration. v2: - Updated the first patch to include review feedback from David and Jason. The main change in this series is the allocation of page in the case of hugetlbfs if it is not found in the page cache. v3: - Made changes to include review feedback from David to improve the comments and readability of code - Enclosed the hugepage alloc code with #ifdef CONFIG_HUGETLB_PAGE v4: - Augmented the commit message of the udmabuf patch that uses pin_user_pages_fd() - Added previously reviewed but unmerged udmabuf patches to this series v5: - Updated the patch that adds pin_user_pages_fd() to include feedback from David to handle simultaneous users trying to add a huge page to the mapping - Replaced find_get_page_flags() with __filemap_get_folio() in the second and third patches to ensure that we only obtain head pages from the mapping v6: (Christoph) - Renamed the new API to memfd_pin_user_pages() - Improved the page cache lookup efficiency by using filemap_get_folios_contig() which uses batches v7: - Rename the new API to memfd_pin_folios() and make it return folios and offsets (David) - Added a new preparatory patch to this series to convert udmabuf driver to use folios This series is tested using following methods: - Run the subtests added in the fifth patch - Run Qemu (master) with the following options and a few additional patches to Spice: qemu-system-x86_64 -m 4096m.... -device virtio-gpu-pci,max_outputs=1,blob=true,xres=1920,yres=1080 -spice port=3001,gl=on,disable-ticketing=on,preferred-codec=gstreamer:h264 -object memory-backend-memfd,hugetlb=on,id=mem1,size=4096M -machine memory-backend=mem1 Cc: David Hildenbrand Cc: Christoph Hellwig Cc: Daniel Vetter Cc: Mike Kravetz Cc: Hugh Dickins Cc: Peter Xu Cc: Jason Gunthorpe Cc: Gerd Hoffmann Cc: Dongwon Kim Cc: Junxiao Chang Vivek Kasireddy (6): udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap udmabuf: Add back support for mapping hugetlb pages (v6) mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v7) udmabuf: Convert udmabuf driver to use folios udmabuf: Pin the pages using memfd_pin_folios() API (v5) selftests/dma-buf/udmabuf: Add tests to verify data after page migration drivers/dma-buf/udmabuf.c | 166 +++++++++++------- include/linux/memfd.h | 5 + include/linux/mm.h | 3 + mm/gup.c | 155 ++++++++++++++++ mm/memfd.c | 34 ++++ .../selftests/drivers/dma-buf/udmabuf.c | 151 +++++++++++++++- 6 files changed, 451 insertions(+), 63 deletions(-)