linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
       [not found] <20160831150105.GB26702@kroah.com>
@ 2016-08-31 15:44 ` Reza Arbab
  2016-08-31 20:25   ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: Reza Arbab @ 2016-08-31 15:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Andrew Morton, Vlastimil Babka,
	Vitaly Kuznetsov, David Rientjes, Yaowei Bai, Joonsoo Kim,
	Dan Williams, Xishi Qiu, David Vrabel, Chen Yucong,
	Andrew Banman, linux-mm, linux-kernel

Attempting to online memory which is already online will cause this:

1. store_mem_state() called with buf="online"
2. device_online() returns 1 because device is already online
3. store_mem_state() returns 1
4. calling code interprets this as 1-byte buffer read
5. store_mem_state() called again with buf="nline"
6. store_mem_state() returns -EINVAL

Example:

$ cat /sys/devices/system/memory/memory0/state
online
$ echo online > /sys/devices/system/memory/memory0/state
-bash: echo: write error: Invalid argument

Fix the return value of store_mem_state() so this doesn't happen.

Signed-off-by: Reza Arbab <arbab@linux.vnet.ibm.com>
---
Andrew et al, Greg asked that this come in through the -mm tree, as
you know this code better than him.

 drivers/base/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 1cea0ba..8e385ea 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -359,7 +359,7 @@ store_mem_state(struct device *dev,
 err:
 	unlock_device_hotplug();
 
-	if (ret)
+	if (ret < 0)
 		return ret;
 	return count;
 }
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-08-31 15:44 ` [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value Reza Arbab
@ 2016-08-31 20:25   ` Andrew Morton
  2016-08-31 21:06     ` David Rientjes
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2016-08-31 20:25 UTC (permalink / raw)
  To: Reza Arbab
  Cc: Greg Kroah-Hartman, Vlastimil Babka, Vitaly Kuznetsov,
	David Rientjes, Yaowei Bai, Joonsoo Kim, Dan Williams, Xishi Qiu,
	David Vrabel, Chen Yucong, Andrew Banman, linux-mm, linux-kernel

On Wed, 31 Aug 2016 10:44:01 -0500 Reza Arbab <arbab@linux.vnet.ibm.com> wrote:

> Attempting to online memory which is already online will cause this:
> 
> 1. store_mem_state() called with buf="online"
> 2. device_online() returns 1 because device is already online
> 3. store_mem_state() returns 1
> 4. calling code interprets this as 1-byte buffer read
> 5. store_mem_state() called again with buf="nline"
> 6. store_mem_state() returns -EINVAL
> 
> Example:
> 
> $ cat /sys/devices/system/memory/memory0/state
> online
> $ echo online > /sys/devices/system/memory/memory0/state
> -bash: echo: write error: Invalid argument
> 
> Fix the return value of store_mem_state() so this doesn't happen.

So..  what *does* happen after the patch?  Is some sort of failure still
reported?  Or am I correct in believing that the operation will appear
to have succeeded?  If so, is that desirable?


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-08-31 20:25   ` Andrew Morton
@ 2016-08-31 21:06     ` David Rientjes
  2016-08-31 23:38       ` Reza Arbab
  0 siblings, 1 reply; 8+ messages in thread
From: David Rientjes @ 2016-08-31 21:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Reza Arbab, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman, linux-mm,
	linux-kernel

On Wed, 31 Aug 2016, Andrew Morton wrote:

> > Attempting to online memory which is already online will cause this:
> > 
> > 1. store_mem_state() called with buf="online"
> > 2. device_online() returns 1 because device is already online
> > 3. store_mem_state() returns 1
> > 4. calling code interprets this as 1-byte buffer read
> > 5. store_mem_state() called again with buf="nline"
> > 6. store_mem_state() returns -EINVAL
> > 
> > Example:
> > 
> > $ cat /sys/devices/system/memory/memory0/state
> > online
> > $ echo online > /sys/devices/system/memory/memory0/state
> > -bash: echo: write error: Invalid argument
> > 
> > Fix the return value of store_mem_state() so this doesn't happen.
> 
> So..  what *does* happen after the patch?  Is some sort of failure still
> reported?  Or am I correct in believing that the operation will appear
> to have succeeded?  If so, is that desirable?
> 

It's not desirable, before commit 4f3549d72 this would have returned 
EINVAL since __memory_block_change_state() does not see the state as 
MEM_OFFLINE when the write is done.  The correct fix is for 
store_mem_state() to return -EINVAL when device_online() returns non-zero.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-08-31 21:06     ` David Rientjes
@ 2016-08-31 23:38       ` Reza Arbab
  2016-09-01  0:03         ` David Rientjes
  0 siblings, 1 reply; 8+ messages in thread
From: Reza Arbab @ 2016-08-31 23:38 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman, linux-mm,
	linux-kernel

On Wed, Aug 31, 2016 at 02:06:14PM -0700, David Rientjes wrote:
>The correct fix is for store_mem_state() to return -EINVAL when 
>device_online() returns non-zero.

Let me put it to you this way--which one of these sysfs operations is 
behaving correctly?

	# cd /sys/devices/system/memory/memory0
	# cat online
	1
	# echo 1 > online; echo $?
	0

or

	# cd /sys/devices/system/memory/memory0
	# cat state
	online
	# echo online > state; echo $?
	-bash: echo: write error: Invalid argument
	1

One of them should change to match the other.

-- 
Reza Arbab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-08-31 23:38       ` Reza Arbab
@ 2016-09-01  0:03         ` David Rientjes
  2016-09-01  0:17           ` Reza Arbab
  0 siblings, 1 reply; 8+ messages in thread
From: David Rientjes @ 2016-09-01  0:03 UTC (permalink / raw)
  To: Reza Arbab
  Cc: Andrew Morton, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman,
	Seth Jennings, linux-mm, linux-kernel

On Wed, 31 Aug 2016, Reza Arbab wrote:

> > The correct fix is for store_mem_state() to return -EINVAL when
> > device_online() returns non-zero.
> 
> Let me put it to you this way--which one of these sysfs operations is behaving
> correctly?
> 
> 	# cd /sys/devices/system/memory/memory0
> 	# cat online
> 	1
> 	# echo 1 > online; echo $?
> 	0
> 
> or
> 
> 	# cd /sys/devices/system/memory/memory0
> 	# cat state
> 	online
> 	# echo online > state; echo $?
> 	-bash: echo: write error: Invalid argument
> 	1
> 
> One of them should change to match the other.
> 

Nope, the return value of changing state from online to online was 
established almost 11 years ago in commit 3947be1969a9.  This was broken 
by commit fa2be40fe7c0 ("drivers: base: use standard device online/offline 
for state change") which was not intended to introduce a functional 
change, but it did (memory_block_change_state() would have returned 
EINVAL, device_online() does not).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-09-01  0:03         ` David Rientjes
@ 2016-09-01  0:17           ` Reza Arbab
  2016-09-01  0:28             ` David Rientjes
  0 siblings, 1 reply; 8+ messages in thread
From: Reza Arbab @ 2016-09-01  0:17 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman,
	Seth Jennings, linux-mm, linux-kernel

On Wed, Aug 31, 2016 at 05:03:25PM -0700, David Rientjes wrote:
>Nope, the return value of changing state from online to online was
>established almost 11 years ago in commit 3947be1969a9.

Fair enough. So if online-to-online is -EINVAL, 

1. Shouldn't 'echo 1 > online' then also return -EINVAL?

2. store_mem_state() still needs a tweak, right? It was only returning 
-EINVAL by accident, due to the convoluted sequence I listed in the 
patch.

-- 
Reza Arbab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-09-01  0:17           ` Reza Arbab
@ 2016-09-01  0:28             ` David Rientjes
  2016-09-01  1:57               ` Reza Arbab
  0 siblings, 1 reply; 8+ messages in thread
From: David Rientjes @ 2016-09-01  0:28 UTC (permalink / raw)
  To: Reza Arbab
  Cc: Andrew Morton, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman,
	Seth Jennings, linux-mm, linux-kernel

On Wed, 31 Aug 2016, Reza Arbab wrote:

> > Nope, the return value of changing state from online to online was
> > established almost 11 years ago in commit 3947be1969a9.
> 
> Fair enough. So if online-to-online is -EINVAL, 

online-to-online for state is -EINVAL, it has been since 2005.

> 1. Shouldn't 'echo 1 > online' then also return -EINVAL?
> 

No, it's a different tunable.  There's no requirement that two different 
tunables that do a similar thing have the same return values: the former 
existed long before device_online() and still exists for backwards 
compatibility.

> 2. store_mem_state() still needs a tweak, right? It was only returning -EINVAL
> by accident, due to the convoluted sequence I listed in the patch.
> 

Yes, absolutely.  It returning -EINVAL for "nline" is what is accidently 
preserving it's backwards compatibility :)  Note that device_online() 
returns 1 if already online and memory_subsys_online() returns 0 if online 
in this case.  So we want store_mem_state() to return -EINVAL if 
device_online() returns non-zero (this was in my first email).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value
  2016-09-01  0:28             ` David Rientjes
@ 2016-09-01  1:57               ` Reza Arbab
  0 siblings, 0 replies; 8+ messages in thread
From: Reza Arbab @ 2016-09-01  1:57 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Greg Kroah-Hartman, Vlastimil Babka,
	Vitaly Kuznetsov, Yaowei Bai, Joonsoo Kim, Dan Williams,
	Xishi Qiu, David Vrabel, Chen Yucong, Andrew Banman,
	Seth Jennings, linux-mm, linux-kernel

On Wed, Aug 31, 2016 at 05:28:26PM -0700, David Rientjes wrote:
>> 2. store_mem_state() still needs a tweak, right? It was only 
>> returning -EINVAL by accident, due to the convoluted sequence I 
>> listed in the patch.
>
>Yes, absolutely.  It returning -EINVAL for "nline" is what is accidently
>preserving it's backwards compatibility :)  Note that device_online()
>returns 1 if already online and memory_subsys_online() returns 0 if online
>in this case.  So we want store_mem_state() to return -EINVAL if
>device_online() returns non-zero (this was in my first email).

I'll spin a v3 patch to do this.

Thank you for your review!

-- 
Reza Arbab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2016-09-01  1:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20160831150105.GB26702@kroah.com>
2016-08-31 15:44 ` [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value Reza Arbab
2016-08-31 20:25   ` Andrew Morton
2016-08-31 21:06     ` David Rientjes
2016-08-31 23:38       ` Reza Arbab
2016-09-01  0:03         ` David Rientjes
2016-09-01  0:17           ` Reza Arbab
2016-09-01  0:28             ` David Rientjes
2016-09-01  1:57               ` Reza Arbab

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).