mm: Correct guards for non_swap_entry()
PATCH 1/1 mm: Correct guards for non_swap_entry()
If CONFIG_DEVICE_PRIVATE is defined, but neither CONFIG_MEMORY_FAILURE nor CONFIG_MIGRATION, then non_swap_entry() will return 0, meaning that the condition (non_swap_entry(entry) && is_device_private_entry(entry)) in zap_pte_range() will never be true even if the entry is a device private one.
Equally any other code depending on non_swap_entry() will not function as expected.
--- include/linux/swapops.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/swapops.h +2 -1
@@ -348,7 +348,8 @@ static inline void num_poisoned_pages_inc(void) }#endif -#if defined(CONFIG_MEMORY_FAILURE ) || defined(CONFIG_MIGRATION ) +#if defined(CONFIG_MEMORY_FAILURE ) || defined(CONFIG_MIGRATION ) || \ + defined(CONFIG_DEVICE_PRIVATE )static inline int non_swap_entry (swp_entry_t entry) {return swp_type (entry) >=MAX_SWAPFILES ;
Signature · 1 line
2.20.1
Andrew Morton
maintainerQuoted 8 lines · On Thu, 5 Mar 2020 13:05:50 +0000 Steven Price <[email protected]> wrote:
If
CONFIG_DEVICE_PRIVATEis defined, but neitherCONFIG_MEMORY_FAILUREnorCONFIG_MIGRATION, thennon_swap_entry()will return 0, meaning that the condition (non_swap_entry(entry)&&is_device_private_entry(entry)) inzap_pte_range()will never be true even if the entry is a device private one.Equally any other code depending on
non_swap_entry()will not function as expected.
What are the user-visible runtime effects of this change?
Is a cc:stable needed?
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Thu, 5 Mar 2020 13:05:50 +0000 Steven Price <[email protected]> wrote:
If
CONFIG_DEVICE_PRIVATEis defined, but neitherCONFIG_MEMORY_FAILUREnorCONFIG_MIGRATION, thennon_swap_entry()will return 0, meaning that the condition (non_swap_entry(entry)&&is_device_private_entry(entry)) inzap_pte_range()will never be true even if the entry is a device private one.
Quoted 7 lines
Quoted 2 lines
Equally any other code depending on
non_swap_entry()will not function as expected.What are the user-visible runtime effects of this change?
Is a cc:stable needed?
I originally spotted this just by looking at the code, I haven't actually observed any problems.
Looking a bit more closely it appears that actually this situation (currently at least) cannot occur:
DEVICE_PRIVATE depends on ZONE_DEVICEZONE_DEVICE depends on MEMORY_HOTREMOVEMEMORY_HOTREMOVE depends on MIGRATION
So there's probably no need to back port.
Steve