linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Yin Fengwei <fengwei.yin@intel.com>,
	Matthew Wilcox <willy@infradead.org>,
	 Lorenzo Stoakes <lstoakes@gmail.com>,
	Stefan Roesch <shr@devkernel.io>,
	 linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] mm: mlock: avoid folio_within_range() on KSM pages
Date: Mon, 23 Oct 2023 23:38:41 -0700 (PDT)	[thread overview]
Message-ID: <23852f6a-5bfa-1ffd-30db-30c5560ad426@google.com> (raw)

Since mm-hotfixes-stable commit dc68badcede4 ("mm: mlock: update
mlock_pte_range to handle large folio") I've just occasionally seen
VM_WARN_ON_FOLIO(folio_test_ksm) warnings from folio_within_range(),
in a splurge after testing with KSM hyperactive.

folio_referenced_one()'s use of folio_within_vma() is safe because
it checks folio_test_large() first; but allow_mlock_munlock() needs
to do the same to avoid those warnings (or check !folio_test_ksm()
itself? or move either check into folio_within_range()? hard to tell
without more examples of its use).

Fixes: dc68badcede4 ("mm: mlock: update mlock_pte_range to handle large folio")
Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/mlock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/mlock.c b/mm/mlock.c
index aa44456200e3..086546ac5766 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -346,6 +346,10 @@ static inline bool allow_mlock_munlock(struct folio *folio,
 	if (!(vma->vm_flags & VM_LOCKED))
 		return true;
 
+	/* folio_within_range() cannot take KSM, but any small folio is OK */
+	if (!folio_test_large(folio))
+		return true;
+
 	/* folio not in range [start, end), skip mlock */
 	if (!folio_within_range(folio, vma, start, end))
 		return false;
-- 
2.35.3



             reply	other threads:[~2023-10-24  6:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-24  6:38 Hugh Dickins [this message]
2023-10-24  7:09 ` Yin Fengwei

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=23852f6a-5bfa-1ffd-30db-30c5560ad426@google.com \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=fengwei.yin@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=shr@devkernel.io \
    --cc=willy@infradead.org \
    /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