From patchwork Wed Dec 27 07:38:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13505181 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 9BEC6C46CD2 for ; Wed, 27 Dec 2023 08:02:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DB2F8D0005; Wed, 27 Dec 2023 03:02:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 214138D0001; Wed, 27 Dec 2023 03:02:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B5D88D0005; Wed, 27 Dec 2023 03:02:43 -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 E67778D0001 for ; Wed, 27 Dec 2023 03:02:42 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C1239A0557 for ; Wed, 27 Dec 2023 08:02:42 +0000 (UTC) X-FDA: 81611856564.16.C788B6A Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by imf05.hostedemail.com (Postfix) with ESMTP id 1652F10000F for ; Wed, 27 Dec 2023 08:02:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EoVHTK0n; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.43 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=1703664161; 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=pA5iLvhilbhOAEt8oJo/bRTduwqtYU/GB5uxSX+4/bQ=; b=yZDndpe65XbbQu3Ol48Y1/2b2DcwBVvFOUdUpxoXC8dD/Yi8Onv9H1A7+OdaVhF6a3N6lf xAqr3epzgeU+YSjAMPbJw+gDavo/Wh5QVTMJx1fHETmY6zXSVcqB6axZznRhqOT94AlZ4w Reqgbech9gwNDGT5qALi4xcOy2CH6VA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EoVHTK0n; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703664161; a=rsa-sha256; cv=none; b=q6TfRR0a6g5alQmyhqjlHJsTU5jaYabZj+m69MOfb43tfWlhRFsnuPQHV2cHM0t2/Gc0qB +qJ4osXRjD4zq3mh8DbK9DGs+3JajVJEI0GERsMisUTJgDrGcOZY5gSMjccKfGhPFTA4U1 W+5Ya5v380LvpMpKC8qDGhVlom7ATd0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703664160; x=1735200160; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BoUO2t60imgNA79MCSCVHWfoTCeaSw2o+h7770LXnEM=; b=EoVHTK0nY3ei5Dh85hpJsE871rAlc0DJvuEuZx9eoQeusfgf8wrUYHO6 Vgv+rHMI0/nfbIoQGm5W+hiTl1ZVQKhOl8fkuUx2GBjArZNGaXAUQjtgQ hYtM3EUXtMnSPvuHB1vzqTrMxHA9vHGwpVu2R5IOWv0WW+43o5uyxRUO6 XGGxF43L8aiNiuM7H+2+w0P4XU496exm7NStRuY6efcgpGqN30sEkBdBk MeWvEW3ZmsZcsufIHeQAXxgjsQC1fuTUF3NBqfEtEG3pInewlVdM27PkZ BYZbYjX+7LK56MEBBjb/SCaP48K8q4sdODWQlbNstZHwrBFmfZhGe5/Lu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="482604275" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="482604275" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2023 00:02:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="781668178" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="781668178" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2023 00:02:36 -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 v9 0/6] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios (v9) Date: Tue, 26 Dec 2023 23:38:16 -0800 Message-Id: <20231227073822.390518-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1652F10000F X-Stat-Signature: smu9kwhetk7r7mgrsyraim8anxwxc4tq X-HE-Tag: 1703664159-809111 X-HE-Meta: U2FsdGVkX18FpQMe8ryJkHm1Dog22FVsdLDpC+bHDyz6ERhuwVOyFSyiR0+OhXNUfPbxXI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Bo8+t30pzyyCvrp9sop9esAXLaTTZaQawTkwCSzggFUcqaVX4oGId5A2Kx3jq6j/6prRZD8AQpRxpDmIehlP/4nsnjKc1Ko/NtGjcRx1qeChfXypsVYN6dA+8b6n8ilL/AbqgNMrowONo/qFjGGsGHzYjL1abtm6bKSnNYkvIMqMTPruk2WxaWMaJDTRhqgpWDJ8XbLk= 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) v9: - Drop the extern and fix the return type in the declaration of memfd_alloc_folio() (Matthew) - Use a list to track the folios that need to be unpinned (patch 5) 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 (Oracle) 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 (v9) udmabuf: Convert udmabuf driver to use folios (v2) udmabuf: Pin the pages using memfd_pin_folios() API (v7) selftests/dma-buf/udmabuf: Add tests to verify data after page migration drivers/dma-buf/udmabuf.c | 231 +++++++++++++----- 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, 509 insertions(+), 64 deletions(-)