mm/mincore: handle non-swap entries before !CONFIG_SWAP guard
Subsystems (3)
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.
---
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
@@ -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
Quoted 7 lines · Usama Arif
mincore_swap()also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>
LGTM, thanks!
Maybe Cc: [email protected] ?
Signature · 1 line
Pedro
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 whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>LGTM, thanks!
Reviewed-by Pedro Falcato <[email protected]>Maybe Cc: [email protected] ?
Ah yes, I have cc-ed stable in the reply to this email, but probably that is not enough?
Thanks
Lorenzo Stoakes
maintainerQuoted 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 whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>LGTM, thanks!
Quoted 7 lines
Quoted 4 lines
Reviewed-by Pedro Falcato <[email protected]>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
Andrew Morton
maintainerQuoted 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")Signed-off-by Usama Arif <[email protected]>LGTM, thanks!
Reviewed-by Pedro Falcato <[email protected]>
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.
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!
Quoted 49 lines · Usama Arif
mincore_swap()also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>---
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@@ -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!
Quoted 7 lines · Usama Arif
mincore_swap()also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>
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@@ -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
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 whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>Logic LGTM so:
Reviewed-by Lorenzo Stoakes <[email protected]>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@@ -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
Quoted 7 lines · Usama Arif
mincore_swap()also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>
Quoted 12 lines · Usama Arif
mincore_swap()also fields migration/hwpoison entries (and shmem swapin-error entries), which can exist on !CONFIG_SWAP builds whenCONFIG_MIGRATIONorCONFIG_MEMORY_FAILUREis enabled. The !IS_ENABLED(CONFIG_SWAP) guard ran before the non-swap-entry early return, somincore_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")Signed-off-by Usama Arif <[email protected]>---
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(-)