summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYichong Chen <chenyichong@uniontech.com>2026-07-21 11:52:07 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-08-06 18:57:23 -0700
commit47f3cecd720f8f8d94ad2f206e3bfe3bc2d3d4e5 (patch)
treea6ada2d8d803305c9bdf7e6f4f7f27212330de9b
parent64a853c9a648be315ba92d50270791cf40ce0708 (diff)
hugetlb: evaluate subpool free state while locked
unlock_or_release_subpool() drops spool->lock before calling subpool_is_free(). However, subpool_is_free() reads fields that are updated under spool->lock, including count, used_hpages and rsv_hpages. Keep the free-state evaluation under the same lock that protects those fields. The reservation accounting and kfree() calls still happen after dropping spool->lock. Link: https://lore.kernel.org/20260721035207.1437935-1-chenyichong@uniontech.com Signed-off-by: Yichong Chen <chenyichong@uniontech.com> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com> Reviewed-by: Jane Chu <jane.chu@oracle.com> Cc: David Hildenbrand <david@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Cc: Oscar Salvador <osalvador@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r--mm/hugetlb.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 6daf831b14c5..79e5c3b3e850 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -141,12 +141,14 @@ static inline bool subpool_is_free(struct hugepage_subpool *spool)
static inline void unlock_or_release_subpool(struct hugepage_subpool *spool,
unsigned long irq_flags)
{
- spin_unlock_irqrestore(&spool->lock, irq_flags);
+ bool free_subpool = subpool_is_free(spool);
/* If no pages are used, and no other handles to the subpool
* remain, give up any reservations based on minimum size and
* free the subpool */
- if (subpool_is_free(spool)) {
+ spin_unlock_irqrestore(&spool->lock, irq_flags);
+
+ if (free_subpool) {
if (spool->min_hpages != -1)
hugetlb_acct_memory(spool->hstate,
-spool->min_hpages);