mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] hugetlb: evaluate subpool free state while locked
@ 2026-07-21  3:52 Yichong Chen
  2026-07-21 18:45 ` jane.chu
  2026-07-22  0:55 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: Yichong Chen @ 2026-07-21  3:52 UTC (permalink / raw)
  To: Muchun Song, Oscar Salvador
  Cc: Andrew Morton, Joshua Hahn, David Hildenbrand, linux-mm,
	linux-kernel, Yichong Chen

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.

Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
v2:
- Reword the changelog based on Joshua's observation.
- Drop the Fixes tag because this is not known to cause a user-visible bug.
- Add Joshua's Reviewed-by.

 mm/hugetlb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e319c6a00555..46ab702c0fc0 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -140,12 +140,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);
-- 
2.51.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-22  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-21  3:52 [PATCH v2] hugetlb: evaluate subpool free state while locked Yichong Chen
2026-07-21 18:45 ` jane.chu
2026-07-22  0:55 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®