From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84058606A322 for ; Thu, 3 Dec 2026 12:29:38 +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=CVEJO8Xn Received: by kanga.kvack.org (Postfix) id BE1E66B05B7; Thu, 3 Dec 2026 07:29:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6C226B05B8; Thu, 3 Dec 2026 07:29:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5A286B05B9; Thu, 3 Dec 2026 07:29:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BBF066B05B7 for ; Thu, 3 Dec 2026 07:29:33 -0500 (EST) Received: from smtpin22.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4CF0016062E for ; Thu, 3 Dec 2026 12:29:33 +0000 (UTC) X-FDA: 85502602626.22.61285FE Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf26.hostedemail.com (Postfix) with ESMTP id 9D1AE140007 for ; Thu, 3 Dec 2026 12:29:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=CVEJO8Xn; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796300971; b=gSulVCsIAe5z3qv4DRWMzSAuLH64d4QlAYG36Iv2m3roQMZ8AKg2gjte0zYZ+ND1jjpi69 IAc943Vy2JBKMs4vj855+fGfUYDdNPIdzA5VZEV/U+3VG2a7zBy60Yp7MHMfrURKb8nuov t9vGY2K2akXy4XU5JhWfm+dh7XRtrkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796300971; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nfKZCPQTTqCktGh7YyNIHsKlaRL1MwVnAdG4Jwk/N2c=; b=JfdDt2jU0PD8ZLp6RWMMS/e0aNh6v64ZWS+tPlFJ3AdnD8x0SrlveiVFCm5F+bt0FYMT1J xtHcteSrlmk1pz2LhQxCZvYncU23YjCP/x6C34sggCBlhA85jXu9s+d0bjCwbkuPEKWBmF LrcgHd+xQp0ArzDfe//fJEldn1aChRo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=CVEJO8Xn; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 3000260DE4; Thu, 3 Dec 2026 12:29:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D65C31F000C1; Thu, 3 Dec 2026 12:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300970; bh=nfKZCPQTTqCktGh7YyNIHsKlaRL1MwVnAdG4Jwk/N2c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CVEJO8XnFHtmhXA358q7F+smvDyyxviyZYUBLt3bznHrL1NEXlvQvB04FLC+yIfED Dp0xHRG5l6GTelxRl32i1nyeO0D9i5SLER/gp7y0FRo+um67RXdh97IJBdtPpUvHUk Y8in55siv7DqqjR0Sk4RYcN8U7rWIpqUwuZkfy/Gu5bueh31vIoSfdsERnTVzWRwhe TvQ9+d7hRRUyq5fkNvo8ZCEfpCDmvZ9tqprlZZ+6X8LmjGjFxqYM76KQzLRhu2oYL4 Y4Z47BUkOQ9mD/RUnhSMXDPyfzm76JmqJ1rKxdEzHeTTVBDkFKqh5OskzR2T2P2UJm RwbMFEsnXqj6A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGF2aWQgSGlsZGVuYnJhbmQgKEFybSk=?= , "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" , =?utf-8?b?U3RldmVuIFJvc3RlZHQgKEdvb2ds?= =?utf-8?b?ZSk=?= , "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, "Gerd Hoffmann" , "Johannes Weiner" , "Chris Mason" , "Jiaqi Yan" In-Reply-To: <20261203-hugetlb_fixes_2-v2-21-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-21-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:29:28 +0000 X-Stat-Signature: 5t6hrf4yewsg3ymwet9dek3bn46imcid X-Rspamd-Queue-Id: 9D1AE140007 X-Rspam-User: X-Rspamd-Server: rspam01 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796300971-655901 X-HE-Meta: U2FsdGVkX1/fWKV33aEbNg2IR5gRR2W9chcyU5lLc/Rut9M2NWDzZUQgIhU88DUZh22dZ9JRHirwBDPsA67RXLUd4Fi4k/ASmzQINvMS13nEfA4OrEuuPAJWWxovSg/4t72BVJFEj5CC8NpzBqsn4OWkw23wsm5icBjzYlG0uo1LpgYB2ipQCxRwjlnsQ90Scb5yGgES6iZ+RA74nXMaocmZQwn4gmLzw/xA89S71ZWTdjaurxCrH4rjwk20hd7DkTAKURtAZv6SHOlwnopD3xp+YMD95H8yfHKxJlEcPy/sm9rTfKpogP0Y6Q4xfGrSqnyGF2VaJn6MR33qZiWQZFfXae8BoVy7w6IQFffQsNKFEWQi24h3mCN4x1rBcTzDfSzjwFa19nki6N2C6UBGS4ZGSdtjbUjyySrxrQ7S2VpFqzguWoqZk5mTCfS8adivjlZjNuluGQtmo6qb7o0McLGec5IOuPKs/Xyb71Upqz/lw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vVZxpBn0xRffwBGrS9Bb52/Gn+XAEulOSlUx2z0u7TzHQ7sPQuI7R8QGe+6G0E0jfoh/6glHqz1KhoIp6XnBAGSZPjT9w79BCTfyraN2v7eh4SzZuwiif2MjxUYaJXEmGo2fA8vyhv0T9fvm/IkoWvl6bV6POgycvxpViAn0I/bhySUxjVHhDP9kN2LfbK8mjyGfD++gsWvgBFE1WmDli0ydg4muOrh6n6ytfrVG4V8j2nuNYX1oib6sUuPOHMFISs47Y8tQYluxf16PQXgGTeIzcbw4Fc8mQBuIVti83yRnRftF7bsC3Hvj3QCng/xixFqSnHao71JFdvcvgPYVToGzVjy7xJQraSbkQ= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] hugetlbfs: skipping private VMA lock in hugetlb_vmdelete_list() races faults -- commit 8e062b4ade15c4eb0dc06a09ad850ccd4f8c9850 Author: David Hildenbrand (Arm) hugetlbfs: don't skip private VMAs when unmapping on truncation This commit changes hugetlb_vmdelete_list() to acquire the hugetlb VMA lock only for VMAs with a shareable lock, so private reservation-owning VMAs are unmapped under i_mmap_rwsem alone instead of being skipped on trylock contention. > 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 =3D __vma_shareable_lock(vma); > unsigned long v_start; > unsigned long v_end; > =20 > - 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; > =20 > v_start =3D vma_offset_start(vma, start); > @@ -493,12 +499,8 @@ hugetlb_vmdelete_list(struct address_space *mapping,= pgoff_t start, > =20 > unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags); > =20 > - /* > - * 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); > } > } [Severity: High] Can skipping resv_map->rw_sema on private reservation-owning VMAs race with concurrent page faults and corrupt h->resv_huge_pages and subpool accounting? Unlike hugetlb_unmap_file_folio(), hugetlb_vmdelete_list() does not hold hugetlb_fault_mutex_table and unmaps anonymous folios via hugetlb_folio_restore_rsv_on_unmap(). Fault paths do not take i_mmap_rwsem and rely on resv_map->rw_sema to exclude concurrent unmaps. With a forked private reservation-owning VMA mapping an anonymous folio F1, a CoW write fault can race with ftruncate() or hole punch: CPU0 (hugetlb_wp) CPU1 (hugetlb_vmdelete_list) hugetlb_vma_lock_read(vma) spin_unlock(vmf->ptl) F2 =3D alloc_hugetlb_folio(...) copy_user_large_folio(F2, F1) unmap_hugepage_range(vma, ...) clear PTE, drop ptl hugetlb_folio_restore_rsv_on_unmap() vma_add_reservation() hugetlb_set_folio_subpool(F1, NULL) h->resv_huge_pages++ spin_lock(vmf->ptl) !pte_same() restore_reserve_on_error(..., F2) vma_del_reservation() <-- leaks h->resv_huge_pages and subpool quota Because F2 was allocated with cow_from_owner set, HPG_restore_reserve is clear on F2. restore_reserve_on_error() sees the entry restored by CPU1 and re-marks it consumed in resv_map without undoing h->resv_huge_pages++ or the subpool charge, so hugetlb_vm_op_close() permanently leaks both. Without resv_map->rw_sema, a concurrent fault during hole punch can also observe vma_add_reservation() before h->resv_huge_pages++ in hugetlb_folio_restore_rsv_on_unmap(), underflowing h->resv_huge_pages to ULONG_MAX or hiding another mapping's reservation. Finally, because hugetlb_unmap_range() clears the PTE before tlb_finish_mmu() restores the reservation and frees the folio, a concurrent fault during hole punch can fail with VM_FAULT_SIGBUS or race with tlb_flush_rmaps() to leave a duplicate reservation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-hugetlb_fi= xes_2-v2-0-9bbeabb555d2@kernel.org?part=3D21