hugetlbfs: release subpool on fill_super failure
Subsystems (2)
PATCH 1/1 hugetlbfs: release subpool on fill_super failure
hugetlbfs_fill_super() allocates a hugepage subpool when size or min_size mount options are specified. hugepage_new_subpool() may also reserve huge pages for min_size.
If root dentry creation fails after the subpool is created, the failure path frees the subpool with kfree(). This bypasses hugepage_put_subpool() and can leave min_size reservations charged.
Use hugepage_put_subpool() on the failure path, matching the normal put_super path.
--- fs/hugetlbfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/hugetlbfs/inode.c +2 -1
@@ -1419,7 +1419,8 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) goto out_free;return 0 ; out_free: -kfree (sbinfo->spool); +if (sbinfo->spool) +hugepage_put_subpool (sbinfo->spool);kfree (sbinfo);return -ENOMEM ; }
Signature · 1 line
2.51.0
Andrew Morton
maintainerQuoted 10 lines · On Mon, 20 Jul 2026 10:18:59 +0800 Yichong Chen <[email protected]>…
hugetlbfs_fill_super()allocates a hugepage subpool when size ormin_sizemount options are specified.hugepage_new_subpool()may also reserve huge pages formin_size.If root dentry creation fails after the subpool is created, the failure path frees the subpool with
kfree(). This bypasseshugepage_put_subpool()and can leavemin_sizereservations charged.Use
hugepage_put_subpool()on the failure path, matching the normalput_superpath.
lgtm, thanks.
This might have led AI review to find a pre-existing bug in mm/hugetlb.c:unlock_or_release_subpool():
https://sashiko.dev/#/patchset/[email protected]
fs/hugetlbfs/inode.c hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) · line 1423
Quoted 9 lines
fs/hugetlbfs/inode.c +2
-1@@ -1419,7 +1419,8 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) goto out_free;return 0 ; out_free: -kfree (sbinfo->spool); +if (sbinfo->spool) +hugepage_put_subpool (sbinfo->spool);
Both callers of hugepage_put_subpool do this NULL check. We could move that check into hugepage_put_subpool().
Quoted 3 lines
fs/hugetlbfs/inode.c +0
-0kfree (sbinfo);return -ENOMEM ; }
Thanks, Andrew.
Yes, moving the NULL check into hugepage_put_subpool() makes sense. I'll send a follow-up cleanup patch for that.
The Sashiko comment about unlock_or_release_subpool() also looks like a separate pre-existing race to me, so I'll look at that as an independent fix.
Thanks,
Yichong
PATCH 1/1 hugetlb: make hugepage_put_subpool() tolerate NULL
In reply to Andrew MortonBoth callers of hugepage_put_subpool() check whether the subpool pointer is NULL before calling it. Move the NULL check into hugepage_put_subpool() so callers can use the helper unconditionally.
This is a follow-up cleanup after using hugepage_put_subpool() from the hugetlbfs_fill_super() failure path.
--- fs/hugetlbfs/inode.c | 6 ++---- mm/hugetlb.c | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-)
fs/hugetlbfs/inode.c +2 -4
@@ -1129,8 +1129,7 @@ static void hugetlbfs_put_super(struct super_block *sb)if (sbi) { sb->s_fs_info =NULL ; -if (sbi->spool) -hugepage_put_subpool (sbi->spool); +hugepage_put_subpool (sbi->spool);kfree (sbi); }
@@ -1419,8 +1418,7 @@ hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc) goto out_free;return 0 ; out_free: -if (sbinfo->spool) -hugepage_put_subpool (sbinfo->spool); +hugepage_put_subpool (sbinfo->spool);kfree (sbinfo);return -ENOMEM ; }
mm/hugetlb.c +3 -0
@@ -181,6 +181,9 @@ void hugepage_put_subpool(struct hugepage_subpool *spool) {unsigned long flags; +if (!spool) +return ; +spin_lock_irqsave (&spool->lock, flags);BUG_ON (!spool->count); spool->count--;
Signature · 1 line
2.51.0
Re: [PATCH] hugetlb: make hugepage_put_subpool() tolerate NULL
Quoted 12 lines · Yichong Chen
Both callers of
hugepage_put_subpool()check whether the subpool pointer is NULL before calling it. Move the NULL check intohugepage_put_subpool()so callers can use the helper unconditionally.This is a follow-up cleanup after using
hugepage_put_subpool()from thehugetlbfs_fill_super()failure path.Signed-off-by Yichong Chen <[email protected]>