mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yichong Chen <chenyichong@uniontech.com>
Cc: Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	David Hildenbrand <david@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hugetlb: evaluate subpool free state while locked
Date: Tue, 21 Jul 2026 17:55:44 -0700	[thread overview]
Message-ID: <20260721175544.11f896c43d2b0fa1cf80c1e9@linux-foundation.org> (raw)
In-Reply-To: <20260721035207.1437935-1-chenyichong@uniontech.com>

On Tue, 21 Jul 2026 11:52:07 +0800 Yichong Chen <chenyichong@uniontech.com> wrote:

> 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.

Retaining the Fixes: would be OK.  It's potentially useful information.

If a patch doesn't fix a user-visible bug then we consider it
inappropriate to backport it (by including Cc:stable).  The -stable
maintainers have been asked not to backport Fixes: patches which lack
the cc:stable.

>
> ...
> --- 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);

OK, better, but the value of `free_subpool' can become out of date as
soon as we drop that lock - some other thread could get in and start
using *spool.  If that subpool is still findable, which it hopefully
isn't.

      parent reply	other threads:[~2026-07-22  0:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  3:52 Yichong Chen
2026-07-21 18:45 ` jane.chu
2026-07-22  0:55 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260721175544.11f896c43d2b0fa1cf80c1e9@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=chenyichong@uniontech.com \
    --cc=david@kernel.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®