linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Correct guards for non_swap_entry()
@ 2020-03-05 13:05 Steven Price
  2020-03-06  3:44 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Price @ 2020-03-05 13:05 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Steven Price, linux-kernel, Jérôme Glisse,
	Arnd Bergmann, Dan Williams

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")
Signed-off-by: Steven Price <steven.price@arm.com>
---
 include/linux/swapops.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 877fd239b6ff..3208a520d0be 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Correct guards for non_swap_entry()
  2020-03-05 13:05 [PATCH] mm: Correct guards for non_swap_entry() Steven Price
@ 2020-03-06  3:44 ` Andrew Morton
  2020-03-06  9:41   ` Steven Price
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2020-03-06  3:44 UTC (permalink / raw)
  To: Steven Price
  Cc: linux-kernel, Jérôme Glisse, Arnd Bergmann, Dan Williams

On Thu,  5 Mar 2020 13:05:50 +0000 Steven Price <steven.price@arm.com> 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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Correct guards for non_swap_entry()
  2020-03-06  3:44 ` Andrew Morton
@ 2020-03-06  9:41   ` Steven Price
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Price @ 2020-03-06  9:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Jérôme Glisse, Arnd Bergmann, Dan Williams

On 06/03/2020 03:44, Andrew Morton wrote:
> On Thu,  5 Mar 2020 13:05:50 +0000 Steven Price <steven.price@arm.com> 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?
> 

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-06  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 13:05 [PATCH] mm: Correct guards for non_swap_entry() Steven Price
2020-03-06  3:44 ` Andrew Morton
2020-03-06  9:41   ` Steven Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).