Skip to contentSkip to conversation

mm/mincore: handle non-swap entries before !CONFIG_SWAP guard

PATCH Applied Usama Arif 7 participants 10 messages Jun 2 – Jun 8

Subsystems (3)
lore
Share & tools
lore

Usama Arif

author
#0 lore raw

PATCH 1/1 mm/mincore: handle non-swap entries before !CONFIG_SWAP guard

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

---
This was discovered when working on PMD swap entry series
(https://lore.kernel.org/all/[email protected]/)

---
 mm/mincore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/mincore.c +5 -5
index e5d13eea9234..296f2e3922b5 100644
@@ -64,11 +64,6 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	struct folio *folio = NULL;
 	unsigned char present = 0;
 
-	if (!IS_ENABLED(CONFIG_SWAP)) {
-		WARN_ON(1);
-		return 0;
-	}
-
 	/*
 	 * Shmem mapping may contain swapin error entries, which are
 	 * absent. Page table may contain migration or hwpoison
@@ -77,6 +72,11 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	if (!softleaf_is_swap(entry))
 		return !shmem;
 
+	if (!IS_ENABLED(CONFIG_SWAP)) {
+		WARN_ON(1);
+		return 0;
+	}
+
 	/*
 	 * Shmem mapping lookup is lockless, so we need to grab the swap
 	 * device. mincore page table walk locks the PTL, and the swap
Signature · 1 line
2.52.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Quoted 6 lines

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

LGTM, thanks!

Maybe Cc: [email protected] ?

Signature · 1 line
Pedro
author
#2 lore raw
Quoted 12 lines · Pedro Falcato
Quoted 11 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Quoted 9 lines
Quoted 2 lines
Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

LGTM, thanks!

Maybe Cc: [email protected] ?

Ah yes, I have cc-ed stable in the reply to this email, but probably that is not enough?

Thanks

maintainer
#3 lore raw
Quoted 20 lines · Usama Arif
Quoted 17 lines · Pedro Falcato
Quoted 7 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Quoted 6 lines

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

LGTM, thanks!

Quoted 7 lines
Quoted 4 lines

Maybe Cc: [email protected] ?

Ah yes, I have cc-ed stable in the reply to this email, but probably that is not enough?

Yeah I think a Cc: in the body is required, but then again Andrew does add Cc's for Cc'd parties so maybe it'll be automagically sorted out.

Andrew - probably we're good here but just checking to be sure?

Quoted 2 lines

Thanks

Thanks, Lorenzo

maintainer
#4 lore raw
Quoted 7 lines · On Wed, 3 Jun 2026 13:07:04 +0100 Lorenzo Stoakes <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

LGTM, thanks!

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Maybe Cc: [email protected] ?

Ah yes, I have cc-ed stable in the reply to this email, but probably that is not enough?

Yeah I think a Cc: in the body is required,

It's required for MM patches because we've asked the -stable maintainers to not auto-pick everything which has a Fixes:.

Quoted 2 lines

but then again Andrew does add Cc's
for Cc'd parties so maybe it'll be automagically sorted out.

cc stable management is all manual here.
Quoted 1 line

Andrew - probably we're good here but just checking to be sure?

Yep, I'd added it thanks. But please always do check!

Reviewed-by on v1 1/1
#5 lore raw
In reply to Usama Arif
Quoted 49 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.
Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

---
This was discovered when working on PMD swap entry series
(https://lore.kernel.org/all/[email protected]/)

---
 mm/mincore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/mincore.c +5 -6
index e5d13eea9234..296f2e3922b5 100644
@@ -64,11 +64,6 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
        struct folio *folio = NULL;
        unsigned char present = 0;
 
-       if (!IS_ENABLED(CONFIG_SWAP)) {
-               WARN_ON(1);
-               return 0;
-       }
-
        /*
         * Shmem mapping may contain swapin error entries, which are
         * absent. Page table may contain migration or hwpoison
@@ -77,6 +72,11 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
        if (!softleaf_is_swap(entry))
                return !shmem;
 
+       if (!IS_ENABLED(CONFIG_SWAP)) {
+               WARN_ON(1);
+               return 0;
+       }
+
        /*
         * Shmem mapping lookup is lockless, so we need to grab the swap
         * device. mincore page table walk locks the PTL, and the swap
--
Quoted 1 line

2.52.0

Looks good to me, thanks!

maintainer Reviewed-by on v1 1/1
#6 lore raw
In reply to Usama Arif
Quoted 7 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Quoted 6 lines

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

Logic LGTM so:

Small note below but I think not a problem.

Thanks, Lorenzo

Quoted 24 lines

---
This was discovered when working on PMD swap entry series
(https://lore.kernel.org/all/[email protected]/)

---
 mm/mincore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/mincore.c +0 -5
index e5d13eea9234..296f2e3922b5 100644
@@ -64,11 +64,6 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	struct folio *folio = NULL;
 	unsigned char present = 0;
 
-	if (!IS_ENABLED(CONFIG_SWAP)) {
-		WARN_ON(1);
-		return 0;
-	}
-
 	/*
 	 * Shmem mapping may contain swapin error entries, which are
 	 * absent. Page table may contain migration or hwpoison

mm/mincore.c static unsigned char mincore_swap(swp_entry_t entry, bool shmem) · line 74

Quoted 3 lines
mm/mincore.c +0 -0
@@ -77,6 +72,11 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	if (!softleaf_is_swap(entry))
 		return !shmem;
 

I guess fine to do this after software_is_swap() because for !CONFIG_SWAP this will always evaluate false?

Not a big deal therefore I think.

Quoted 11 lines
mm/mincore.c +5 -1
+	if (!IS_ENABLED(CONFIG_SWAP)) {
+		WARN_ON(1);
+		return 0;
+	}
+
 	/*
 	 * Shmem mapping lookup is lockless, so we need to grab the swap
 	 * device. mincore page table walk locks the PTL, and the swap
--

2.52.0

author
#7 lore raw
Quoted 38 lines · Lorenzo Stoakes
Quoted 7 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Quoted 6 lines

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

Logic LGTM so:

Small note below but I think not a problem.

Thanks, Lorenzo

Quoted 15 lines

---
This was discovered when working on PMD swap entry series
(https://lore.kernel.org/all/[email protected]/)

---
 mm/mincore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/mincore.c +0 -0
index e5d13eea9234..296f2e3922b5 100644
@@ -64,11 +64,6 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	struct folio *folio = NULL;
 	unsigned char present = 0;
 
Quoted 15 lines

mm/mincore.c static unsigned char mincore_swap(swp_entry_t entry, bool shmem) · line 74

Quoted 12 lines
mm/mincore.c +0 -5
-	if (!IS_ENABLED(CONFIG_SWAP)) {
-		WARN_ON(1);
-		return 0;
-	}
-
 	/*
 	 * Shmem mapping may contain swapin error entries, which are
 	 * absent. Page table may contain migration or hwpoison
@@ -77,6 +72,11 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)
 	if (!softleaf_is_swap(entry))
 		return !shmem;
 

I guess fine to do this after software_is_swap() because for !CONFIG_SWAP this will always evaluate false?

Yes, thats right. In softleaf_is_swap(), softleaf_type() returns SOFTLEAF_SWAP iff type_num < MAX_SWAPFILES. MAX_SWAPFILES is a compile-time constant independent of CONFIG_SWAP, so softleaf_is_swap() isn't structurally gated, but every producer of real swap entries lives under CONFIG_SWAP.
With !CONFIG_SWAP none of those run, so softleaf_is_swap() is always false.

Quoted 14 lines

Not a big deal therefore I think.

Quoted 11 lines
mm/mincore.c +5 -1
+	if (!IS_ENABLED(CONFIG_SWAP)) {
+		WARN_ON(1);
+		return 0;
+	}
+
 	/*
 	 * Shmem mapping lookup is lockless, so we need to grab the swap
 	 * device. mincore page table walk locks the PTL, and the swap
--

2.52.0

Acked-by on v1 1/1
#8 lore raw
In reply to Usama Arif
Quoted 7 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Quoted 6 lines

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")
Acked-by on v1 1/1
#9 lore raw
In reply to Usama Arif
Quoted 12 lines · Usama Arif

mincore_swap() also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds when CONFIG_MIGRATION or CONFIG_MEMORY_FAILURE is enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, so mincore_pte_range() can spuriously WARN and report these pages nonresident on !CONFIG_SWAP kernels.

Move the guard below the non-swap-entry check so only true swap entries trip the WARN, and migration/hwpoison entries take the existing "uptodate / non-shmem" path.

Quoted 8 lines
Fixes 1f2052755c15 ("mm/mincore: use a helper for checking the swap cache")

---
This was discovered when working on PMD swap entry series
(https://lore.kernel.org/all/[email protected]/)

---
 mm/mincore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)