From patchwork Sat Dec 16 06:05:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13495479 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 87D6EC46CA2 for ; Sat, 16 Dec 2023 06:29:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 107736B00A7; Sat, 16 Dec 2023 01:29:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 092176B00A1; Sat, 16 Dec 2023 01:29:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E09CB6B00A8; Sat, 16 Dec 2023 01:28:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C81A76B00A1 for ; Sat, 16 Dec 2023 01:28:59 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9D1F7A05AB for ; Sat, 16 Dec 2023 06:28:59 +0000 (UTC) X-FDA: 81571703598.19.CE1994A Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf13.hostedemail.com (Postfix) with ESMTP id 8BD9B2000A for ; Sat, 16 Dec 2023 06:28:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AFsEfOI5; spf=pass (imf13.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702708137; a=rsa-sha256; cv=none; b=tXvV8lwbmgRO2e9a7MhT8uEdoGNdTx067sVtYgK4MbzHf3PKfY08l+7974BIFdtyJ6faqH 5Ry9rbwkKcA5RULrDj7udrMRLtJihtftuvnvX5xvjQNAhK1cmBP8QkXm6mIZGI64sV97fH XuFLMVGdIREGz383KTLNIvLXFnEmhKw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AFsEfOI5; spf=pass (imf13.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.11 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=1702708137; 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=YdDyqO2gZ7zfdXsiZfgd7XBXhiV0+WtanwsthU8IETM=; b=3l+FjI3JIFWTpNBRBOYSZVlthNiUV2UP27nkkuEAlIzMt/cXeHkN/a2hpfKRmV04WzfOI2 wfsmI4D5FWqUw0NYhG7pf/VpcIsSYOJzrHxMaNVAACVWUk+9nz/1Rh8OFGX6NzyRQIv+pG sXOoCZaZDxopmDuWYs3exbv3fvjvFdQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702708136; x=1734244136; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LAUQJgirBbVoAgA51mnGR2BuxxwiV8llGq6SORxHtq4=; b=AFsEfOI5Ke8k/myDCGmg8cyGQaVSM26oadeb4aphwTyY2OeYCzOrroTo KY7roQYhph1GlTFZzsK/dXV5ab3zMzvGqrv+trU7lMuxEq0fmEPfC2eUS MkDJQssHKr4tsUf10+437K2AIgZkPjri8FUBkd4Jm/Jba4MvTYX9uPhA0 8dxT7hqSX3S7LQr+5QDLz6kUIfq03i7frf29R6MFU9+EWFElwtZC0bSXw 68GxnMP1TN4lHxtUiKspsaRNE099R41resodyyP2eIsfqSAU0ZkE0MaJg egdllPeeoHDPraslirS+nyC5SjXO27aFQdVgw4feXZyWUrp+lAIMEQVOH g==; X-IronPort-AV: E=McAfee;i="6600,9927,10925"; a="2186009" X-IronPort-AV: E=Sophos;i="6.04,280,1695711600"; d="scan'208";a="2186009" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 22:28:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10925"; a="751178895" X-IronPort-AV: E=Sophos;i="6.04,280,1695711600"; d="scan'208";a="751178895" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 22:28:54 -0800 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , David Hildenbrand , Matthew Wilcox , Christoph Hellwig , Daniel Vetter , Mike Kravetz , Hugh Dickins , Peter Xu , Jason Gunthorpe , Gerd Hoffmann , Dongwon Kim , Junxiao Chang Subject: [PATCH v8 0/6] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v8) Date: Fri, 15 Dec 2023 22:05:30 -0800 Message-Id: <20231216060536.3716466-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8BD9B2000A X-Stat-Signature: pnmbxjukd6gmw7ykobjuc3u44tpux5g1 X-Rspam-User: X-HE-Tag: 1702708136-38738 X-HE-Meta: U2FsdGVkX19Cd7ln4FDnp02/7g+3ZvKAz5B+KrdWfcmbZn7aaP5Aw/FlB+eGbGFF70F6p0lxf1E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8vbZ0MpYXdAZPX8vhN3i3sGAy7qkHHT/sHsqgOW6GVTnVJBxnDAOZbe92AVWXNfBCCN6rFc9vJXYZj+FIni5SLnN7izS6epmnRrPh0WpcU5xb79t3kKba/mB2aOzlKrCBafF9Utgz6tENbB8ucJdrm2EGLLNARCLY22ltXlH30f7tg6RkQ36I2GqM/MeXxGXUMp6vj/WA= 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 v8: - Addressed review comments from Matthew in patches 4 and 5 - Included David's suggestions to have the caller of memfd_pin_folios() pass a range [stard, end], max_folios instead of start, nr_pages - Ensured that a folio is pinned and unpinned only once (David) 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: Matthew Wilcox 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 (v8) udmabuf: Convert udmabuf driver to use folios (v2) udmabuf: Pin the pages using memfd_pin_folios() API (v6) selftests/dma-buf/udmabuf: Add tests to verify data after page migration drivers/dma-buf/udmabuf.c | 202 ++++++++++++------ include/linux/memfd.h | 5 + include/linux/mm.h | 3 + mm/gup.c | 149 +++++++++++++ mm/memfd.c | 34 +++ .../selftests/drivers/dma-buf/udmabuf.c | 151 ++++++++++++- 6 files changed, 480 insertions(+), 64 deletions(-)