memory-hotplug: fix store_mem_state() return value
Subsystems (3)
PATCH v2 1/1 memory-hotplug: fix store_mem_state() return value
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.
--- drivers/base/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/memory.c +1 -1
@@ -359,7 +359,7 @@ store_mem_state(struct device *dev, err:unlock_device_hotplug (); -if (ret) +if (ret <0 )return ret;return count; }
Signature · 1 line
1.8.3.1
Hi Greg,
Quoted 4 lines · Reza Arbab
$ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argumentFix the return value of
store_mem_state()so this doesn't happen.
I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
Signature · 1 line
Reza Arbab
Greg Kroah-Hartman
maintainerQuoted 10 lines · Reza Arbab
Hi Greg,
Quoted 4 lines · Reza Arbab
$ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argumentFix the return value of
store_mem_state()so this doesn't happen.I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
You ignored my patch review that asked for this patch to be changed for some reason, which is why it was never applied.
greg k-h
Greg Kroah-Hartman
maintainerQuoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · Reza Arbab
Hi Greg,
Quoted 3 lines · Reza Arbab
$ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argument
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Fix the return value of
store_mem_state()so this doesn't happen.I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
You ignored my patch review that asked for this patch to be changed for some reason, which is why it was never applied.
Ah nevermind, this was v2, yes, it's in my queue, looking in my wrong mbox. Please be patient.
Greg Kroah-Hartman
maintainerQuoted 10 lines · Reza Arbab
Hi Greg,
Quoted 4 lines · Reza Arbab
$ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argumentFix the return value of
store_mem_state()so this doesn't happen.I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
I think it fell through, can you resend it and cc: all of the people involved in this subsystem, like you did for your other patch series?
thanks,
greg k-h
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line
I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
I think it fell through, can you resend it and cc: all of the people involved in this subsystem, like you did for your other patch series?
I can resend, but I'm not sure what you mean by the rest--this was a singleton patch, and you're the only one listed by get_maintainer.pl:
$ scripts/get_maintainer.pl drivers/base/memory.c Greg Kroah-Hartman <[email protected]> (supporter:DRIVER CORE, KOBJECTS, DEBUGFS, KERNFS AND SYSFS) [email protected] (open list)
Signature · 1 line
Reza Arbab
Greg Kroah-Hartman
maintainerQuoted 7 lines · Reza Arbab
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines
I can't find where this might have been committed. Am I being impatient, or did it slip through the cracks?
I think it fell through, can you resend it and cc: all of the people involved in this subsystem, like you did for your other patch series?
Quoted 6 lines
I can resend, but I'm not sure what you mean by the rest--this was a singleton patch, and you're the only one listed by get_maintainer.pl:
$ scripts/get_maintainer.pl drivers/base/memory.c Greg Kroah-Hartman <[email protected]> (supporter:DRIVER CORE, KOBJECTS, DEBUGFS, KERNFS AND SYSFS) [email protected] (open list)
You sent in other memory-hotplug patches that got merged through the -mm tree. I suggest doing that here as well, as those developers know this code much better than I do.
thanks,
greg k-h
PATCH RESEND v2 1/1 memory-hotplug: fix store_mem_state() return value
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.
---
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(-)
drivers/base/memory.c +1 -1
@@ -359,7 +359,7 @@ store_mem_state(struct device *dev, err:unlock_device_hotplug (); -if (ret) +if (ret <0 )return ret;return count; }
Signature · 1 line
1.8.3.1
Andrew Morton
maintainerQuoted 9 lines · On Wed, 31 Aug 2016 10:44:01 -0500 Reza Arbab <[email protected]> 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
Quoted 8 lines
Example:
$ cat /sys/devices/system/memory/memory0/state online $ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argumentFix 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 16 lines · Andrew Morton
Quoted 16 lines
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-EINVALExample:
$ cat /sys/devices/system/memory/memory0/state online $ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argument
Quoted 6 lines
Quoted 1 line
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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 1 line · David Rientjes
The correct fix is for
store_mem_state()to return-EINVALwhendevice_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.
Signature · 7 lines
Reza Arbab -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Reza Arbab
Quoted 2 lines
The correct fix is for
store_mem_state()to return-EINVALwhendevice_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 $? 0or
Quoted 9 lines
# cd /sys/devices/system/memory/memory0 # cat state online # echo online > state; echo $? -bash: echo: write error: Invalid argument 1One 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · David Rientjes
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.
Signature · 7 lines
Reza Arbab -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Reza Arbab
Quoted 2 lines
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.
Quoted 2 lines
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.
Quoted 3 lines
2.
store_mem_state()still needs a tweak, right? It was only returning-EINVALby 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · David Rientjes
Quoted 1 line
2.
store_mem_state()still needs a tweak, right? It was only returning-EINVALby accident, due to the convoluted sequence I listed in the patch.Yes, absolutely. It returning
-EINVALfor "nline" is what is accidently preserving it's backwards compatibility :) Note thatdevice_online()returns 1 if already online andmemory_subsys_online()returns 0 if online in this case. So we wantstore_mem_state()to return-EINVALifdevice_online()returns non-zero (this was in my first email).
I'll spin a v3 patch to do this.
Thank you for your review!
Signature · 1 line
Reza Arbab
PATCH RESEND v2 1/1 memory-hotplug: fix store_mem_state() return value
In reply to Greg Kroah-HartmanAttempting 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.
--- drivers/base/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/memory.c +1 -1
@@ -359,7 +359,7 @@ store_mem_state(struct device *dev, err:unlock_device_hotplug (); -if (ret) +if (ret <0 )return ret;return count; }
Signature · 1 line
1.8.3.1