From patchwork Thu Nov 23 06:44:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 13465857 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 95317C61D97 for ; Thu, 23 Nov 2023 07:08:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FB036B063F; Thu, 23 Nov 2023 02:08:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A9CF6B0641; Thu, 23 Nov 2023 02:08:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 171486B0643; Thu, 23 Nov 2023 02:08:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 09CA86B063F for ; Thu, 23 Nov 2023 02:08:35 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DF2754034C for ; Thu, 23 Nov 2023 07:08:34 +0000 (UTC) X-FDA: 81488340948.04.90E7D50 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by imf09.hostedemail.com (Postfix) with ESMTP id E2F4E140004 for ; Thu, 23 Nov 2023 07:08:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="jJ/JoVsx"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.20 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=1700723313; 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=zJGPT1E2TB3dfjx34hzWBJ0klRES+U9+HNitxNoh4kc=; b=DQutNk56M0F31+Jk3SpNjAZw/6/KzZlJ3SbkkDmSvmre1g9mMLZLY077HpPfSImrk5j0xV 8odU+R9vunpOh40rYyqnnDqYfVw5m/6UJGJ4lI1UnLxzUQxDpr+JUWTa5lAFetLbuWgv2N joWbvCrPQLxUjPlR8MfgnInSNxRU+TE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="jJ/JoVsx"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of vivek.kasireddy@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700723313; a=rsa-sha256; cv=none; b=qhDHEJ9/G2JwAMKgjkiYKKQu1kFNVV0HN6SE3LcGWobvP67pgCYnbRo4Hai8+++0xgtdo/ t8CSYbzD5+aWN4ggWpnQlprVRU12u8MbPzgVbtENVmW1NrbXnmw30h8T7WyrDcSDr33FVl sYir/p67QTT00/0bKgYZp4q2m+Znzyc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700723313; x=1732259313; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=59vrc5NDkw8wvYj2LEIRQerTqRUGFz+PrpmpY5i0pgo=; b=jJ/JoVsxIBIbrq92LXldyE8JD5A3C2Dji9V8Ut6WFA4qr14OWp1TsOjc cUJgXnirK1fDf1r+kcLGHoDEImzgsKRNkIogCr1O+gUgBVJhDRzWOJLv3 tJHDrRFgn+52Wqb9H0e19tDjGXWWdee0qORq5jIDys3Q8yezOu9SkofvO tzdwNBH5Ufq+PF4cxNmcr0RbbM06Vr9u4XEfK9O7teykYs/W7pQ7QfocB TperIRQik0m0LjQT12aIkM9D/JNEk2rcI7wj89KOzSaECEWgCrHXSb5hJ 4EmMyLrNnHs9SfRrveHrzMeDS8kURsSAH7B5D3Gzk92omV9fn6KQLloVi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="382612310" X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="382612310" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 23:08:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,220,1695711600"; d="scan'208";a="8757711" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2023 23:08:23 -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 v5 0/5] mm/gup: Introduce pin_user_pages_fd() for pinning shmem/hugetlbfs file pages (v5) Date: Wed, 22 Nov 2023 22:44:38 -0800 Message-Id: <20231123064443.1035709-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E2F4E140004 X-Stat-Signature: krxxt63c1naz55oew4q9mo9gy8doj6rd X-Rspam-User: X-HE-Tag: 1700723312-681489 X-HE-Meta: U2FsdGVkX18RcEd2OIZeqqOgTRxJD9Dky7iJaVuUvo1AQRYrY1dnoHAAsS4NGpQ2DnCs1sqgNUY+jNX8mK33c/dri0JwMhW2Whbojl93KCzywQUDU3af/0g0juxjML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W7/+jZyfbYm+T6eGQjGtq8puaURR3yhsbawuZKMGLAEX2Wi7CKuGmBcvq0HHqww= 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 pin_user_pages_fd() API and the fourth patch shows how the udmabuf driver can make use of it to longterm-pin the the pages. 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 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 Vivek Kasireddy (5): udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap udmabuf: Add back support for mapping hugetlb pages (v4) mm/gup: Introduce pin_user_pages_fd() for pinning shmem/hugetlbfs file pages (v5) udmabuf: Pin the pages using pin_user_pages_fd() API (v3) selftests/dma-buf/udmabuf: Add tests to verify data after page migration drivers/dma-buf/udmabuf.c | 96 ++++++++--- include/linux/mm.h | 2 + mm/gup.c | 114 +++++++++++++ .../selftests/drivers/dma-buf/udmabuf.c | 151 +++++++++++++++++- 4 files changed, 334 insertions(+), 29 deletions(-)