Skip to contentSkip to conversation

mm: Correct guards for non_swap_entry()

PATCH Applied Steven Price 2 participants 3 messages Mar 5, 2020 – Mar 6, 2020 MM swap

lore
Share & tools
lore
#0 lore raw

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.

Fixes 5042db43cc26 ("mm/ZONE_DEVICE: new type of ZONE_DEVICE for unaddressable memory")
---
 include/linux/swapops.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/swapops.h +2 -1
index 877fd239b6ff..3208a520d0be 100644
@@ -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
maintainer
#1 lore raw
Quoted 8 lines · On Thu, 5 Mar 2020 13:05:50 +0000 Steven Price <[email protected]> wrote:

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.

What are the user-visible runtime effects of this change?

Is a cc:stable needed?

#2 lore raw
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_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.

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_DEVICE
ZONE_DEVICE depends on MEMORY_HOTREMOVE
MEMORY_HOTREMOVE depends on MIGRATION

So there's probably no need to back port.

Steve