From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298185; b=lmUxs+7bd+OPW+cBiqfsA/Oci9qGZGJJI6DxHs1KqzFkOzrgbQ8DVrRa09iXX1aCq8M8 ULxmWJGP5DE8OTvYALmra7d7T2Ifb2oeCukCSgDVG+cWiAYE/kzasIFZ9mUgjOGIl7vBy 21y7Foha2FuHSJWjQHalF4l/DcDmGa46x73SLlaMpBX8Er7B5d5IH1n1UhWBIeF760xNr sZO35RKOEginaQy9aVpOOrT1bTx0upqLIzd4gBzUsFqEpEdYSVOIaD2BdZT4yP2unTA8E GyNSlEWdS9F8xQMHjmGg/izt+EIOyKvz0tQkntidXwvCISk394JFSz247ea6wgW610Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298185; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=l4TqGYrdZ6evUmoYPNlGhqw9lbdVDjVSAgtBuOc+0j8=; b=ZBGRvO2LyF0m77SbLwSoxWuoSAp51NWkv9qaxh3h/ukKhh8ZXOmIq/Q8imma5XchDswE 4ufn3+/Np39RLal+v6MZnY5yqkfVUmxz5ycANZXOY6m2iMB9VkGEVSvkFJypw1dGBVYzZ WP9qRrEZ499THmgJX6n0YrfwLROyaHOVAkOJn2pgx01lxC/EAyHx5wGq25O7loLqZQjNL FsIy27UDC531fRu1QLfNeYVYZJUtxgTMgTnPB2AtdrNzyK4hc5HxI+InCZQYQZ6xkjg0B T+WXKVcgW3ovobTaGnJBGwrQv4UBzoqQSnmusAQraKRZOrR0mlCj24boCqNIyRA7akw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ovBIxlHx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1D5606A32C; Thu, 3 Dec 2026 11:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ovBIxlHx Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEA731F0089A; Thu, 3 Dec 2026 11:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298184; bh=l4TqGYrdZ6evUmoYPNlGhqw9lbdVDjVSAgtBuOc+0j8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ovBIxlHx2YhrvCkGH5P4/BALB8JH51jGhdcsEsy4sm4SiJDd5InkOXjtCozZ8uY42 DQnmOcBLfa1eBOHmI27SZQlDvRLaevYr3duNVZWxy8OpBdTSCm69B+uHVOlUZOHMJn 8o3uQo8ZuKUdxB9WbhPEwM2tDUOSo8eDs/H/9SGo+o+djCabXbh0ehq3N9qCkSsrbx AZa9R16pGBNH1/1p78mO3UyCgtDW+cUnnZ3LwYgWgZhC90NMELeipCfESGDTKbK1oX IA28nPk5azwG4lsY2AuXfiO/S9vr8yfU98esowMYHqZsABCgRb7hCMhH6WVvdi7wSt Bh8PUr1wd1ndg== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 12:37:44 +0100 Subject: [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-hugetlb_fixes_2-v2-21-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> In-Reply-To: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> To: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan , Sashiko , stable@vger.kernel.org, "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2695; i=david@kernel.org; h=from:subject:message-id; bh=SRHrtP+/b9WpT6VnwJrTRBOmMzoFr+i7FdKz2IZqK/8=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFQ2qCS4R6u5lT1h7/nprw16f1ZPkn1XV8rQr9Qp7HV zUuetHZUcrCIMbBICumyBIUfN/g5ct1tdVufMwwc1iZQIYwcHEKwETy/zL8L365cZeP55Hekz0c 8f7RkRFKAp0mjgs+dtzkddQWCI1QYmS4nh58P3GKw/PYR682zHxUutev6YN/0c6l0lKxX3bGtCt wAwA= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A When truncating a file or punching a hole, hugetlb_vmdelete_list() unmaps the range from all VMAs that map the file. It skips VMAs whose VMA lock it cannot trylock, which is fine for shared VMAs: remove_inode_hugepages() unmaps their page cache folios later. However, private VMAs that own their reservations have a VMA lock as well, so, for example, a concurrent page fault or MADV_DONTNEED in such a VMA makes us skip that VMA, and nobody unmaps its anonymous folios or, on truncation, its uffd-wp markers later. Consequently, they stay mapped beyond EOF after a truncation, or inside a punched hole. We only need the VMA lock here for PMD table sharing, which synchronizes on the shareable lock. We already hold the i_mmap lock in write mode. Let's fix it like commit da48afefa78d ("hugetlbfs: fix unmapping folios from private VMAs") did for hugetlb_unmap_file_folio(): only take the VMA lock for VMAs with a shareable lock, and always unmap other VMAs only under i_mmap lock. This has low urgency, as it requires racing with e.g., a page fault in the private VMA. Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs") Reported-by: Sashiko Cc: stable@vger.kernel.org Signed-off-by: David Hildenbrand (Arm) --- fs/hugetlbfs/inode.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index db2af960ee7dc..5f44236785b5a 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -482,10 +482,16 @@ hugetlb_vmdelete_list(struct address_space *mapping, pgoff_t start, */ mapping_rmap_tree_foreach(vma, mapping, start, end ? end - 1 : ULONG_MAX) { + const bool need_vma_lock = __vma_shareable_lock(vma); unsigned long v_start; unsigned long v_end; - if (!hugetlb_vma_trylock_write(vma)) + /* + * We only need additional VMA locking here for PMD table + * sharing, which synchronizes on the shareable lock. Other VMAs + * never share PMD tables, so we can unmap them without it. + */ + if (need_vma_lock && !hugetlb_vma_trylock_write(vma)) continue; v_start = vma_offset_start(vma, start); @@ -493,12 +499,8 @@ hugetlb_vmdelete_list(struct address_space *mapping, pgoff_t start, unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags); - /* - * Note that vma lock only exists for shared/non-private - * vmas. Therefore, lock is not held when calling - * unmap_hugepage_range for private vmas. - */ - hugetlb_vma_unlock_write(vma); + if (need_vma_lock) + hugetlb_vma_unlock_write(vma); } } -- 2.56.1