linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 0/5] Optimize and bugfix for notifier error
@ 2022-09-09  7:51 Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 1/5] docs: notifier-error-inject: fix non-working usage of negative values Zhao Gongyi
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:51 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

1. Fix non-working usage of negative values
2. Add checking after online or offline
3. Restore memory before exit
4. Correct test's name

Zhao Gongyi (5):
  docs: notifier-error-inject: fix non-working usage of negative values
  selftests/memory-hotplug: Use 'printf' instead of 'echo'
  selftests/memory-hotplug: Add checking after online or offline
  selftests/memory-hotplug: Restore memory before exit
  docs: notifier-error-inject: Correct test's name

 .../fault-injection/notifier-error-inject.rst | 14 ++++---
 .../memory-hotplug/mem-on-off-test.sh         | 37 +++++++++++++++----
 2 files changed, 39 insertions(+), 12 deletions(-)

--
2.17.1


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

* [PATCH -next 1/5] docs: notifier-error-inject: fix non-working usage of negative values
  2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
@ 2022-09-09  7:51 ` Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 2/5] selftests/memory-hotplug: Use 'printf' instead of 'echo' Zhao Gongyi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:51 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

Fault injection uses debugfs in a way that the provided values via
sysfs are interpreted as u64. Providing negative numbers results in
an error:

  # cd sys/kernel/debug/notifier-error-inject/memory
  #  echo -12 > actions/MEM_GOING_ONLINE/error
  -bash: echo: write error: Invalid argument

Update the docs and examples to use "printf %#x <val>" in these cases.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../fault-injection/notifier-error-inject.rst          | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/Documentation/fault-injection/notifier-error-inject.rst b/Documentation/fault-injection/notifier-error-inject.rst
index 1668b6e48d3a..0e2790122166 100644
--- a/Documentation/fault-injection/notifier-error-inject.rst
+++ b/Documentation/fault-injection/notifier-error-inject.rst
@@ -11,6 +11,10 @@ modules that can be used to test the following notifiers.
  * powerpc pSeries reconfig notifier
  * Netdevice notifier

+Note that the interface only accepts unsigned values. So, if you want
+to use a negative errno, you'd better use 'printf' instead of 'echo', e.g.:
+$ printf %#x -12 > actions/PM_SUSPEND_PREPARE/error
+
 PM notifier error injection module
 ----------------------------------
 This feature is controlled through debugfs interface
@@ -26,7 +30,7 @@ Possible PM notifier events to be failed are:
 Example: Inject PM suspend error (-12 = -ENOMEM)::

 	# cd /sys/kernel/debug/notifier-error-inject/pm/
-	# echo -12 > actions/PM_SUSPEND_PREPARE/error
+	# printf %#x -12 > actions/PM_SUSPEND_PREPARE/error
 	# echo mem > /sys/power/state
 	bash: echo: write error: Cannot allocate memory

@@ -44,7 +48,7 @@ Possible memory notifier events to be failed are:
 Example: Inject memory hotplug offline error (-12 == -ENOMEM)::

 	# cd /sys/kernel/debug/notifier-error-inject/memory
-	# echo -12 > actions/MEM_GOING_OFFLINE/error
+	# printf %#x -12 > actions/MEM_GOING_OFFLINE/error
 	# echo offline > /sys/devices/system/memory/memoryXXX/state
 	bash: echo: write error: Cannot allocate memory

@@ -82,7 +86,7 @@ Netdevice notifier events which can be failed are:
 Example: Inject netdevice mtu change error (-22 == -EINVAL)::

 	# cd /sys/kernel/debug/notifier-error-inject/netdev
-	# echo -22 > actions/NETDEV_CHANGEMTU/error
+	# printf %#x -22 > actions/NETDEV_CHANGEMTU/error
 	# ip link set eth0 mtu 1024
 	RTNETLINK answers: Invalid argument

--
2.17.1


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

* [PATCH -next 2/5] selftests/memory-hotplug: Use 'printf' instead of 'echo'
  2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 1/5] docs: notifier-error-inject: fix non-working usage of negative values Zhao Gongyi
@ 2022-09-09  7:51 ` Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 3/5] selftests/memory-hotplug: Add checking after online or offline Zhao Gongyi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:51 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

Fault injection uses debugfs in a way that the provided values via
sysfs are interpreted as u64. Providing negative numbers results
in errors:

  # sh mem-on-off-test.sh
  ...
  mem-on-off-test.sh: line 267: echo: write error: Invalid argument
  ...
  mem-on-off-test.sh: line 283: echo: write error: Invalid argument
  ...
  #

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 tools/testing/selftests/memory-hotplug/mem-on-off-test.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 46a97f318f58..f1a9d81b934c 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -264,7 +264,8 @@ done
 #
 # Test memory hot-add error handling (offline => online)
 #
-echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
+printf %#x $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/erro
+
 for memory in `hotpluggable_offline_memory`; do
 	online_memory_expect_fail $memory
 done
@@ -280,7 +281,7 @@ done
 #
 # Test memory hot-remove error handling (online => offline)
 #
-echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
+printf %#x $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
 for memory in `hotpluggable_online_memory`; do
 	if [ $((RANDOM % 100)) -lt $ratio ]; then
 		offline_memory_expect_fail $memory
--
2.17.1


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

* [PATCH -next 3/5] selftests/memory-hotplug: Add checking after online or offline
  2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 1/5] docs: notifier-error-inject: fix non-working usage of negative values Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 2/5] selftests/memory-hotplug: Use 'printf' instead of 'echo' Zhao Gongyi
@ 2022-09-09  7:51 ` Zhao Gongyi
  2022-09-09  7:51 ` [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit Zhao Gongyi
  2022-09-09  7:52 ` [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name Zhao Gongyi
  4 siblings, 0 replies; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:51 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

Add checking for online_memory_expect_success()/
offline_memory_expect_success()/offline_memory_expect_fail(), or
the test would exit 0 although the functions return 1.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../memory-hotplug/mem-on-off-test.sh          | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index f1a9d81b934c..3bdf3c4d6d06 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -267,7 +267,11 @@ done
 printf %#x $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/erro

 for memory in `hotpluggable_offline_memory`; do
-	online_memory_expect_fail $memory
+	online_memory_expect_fail $memory || {
+		echo "online memory $memory: unexpected success"
+		retval=1
+	}
+
 done

 #
@@ -275,7 +279,11 @@ done
 #
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
 for memory in `hotpluggable_offline_memory`; do
-	online_memory_expect_success $memory
+	online_memory_expect_success $memory || {
+		echo "online memory $memory: unexpected fail"
+		retval=1
+	}
+
 done

 #
@@ -284,7 +292,11 @@ done
 printf %#x $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
 for memory in `hotpluggable_online_memory`; do
 	if [ $((RANDOM % 100)) -lt $ratio ]; then
-		offline_memory_expect_fail $memory
+		offline_memory_expect_fail $memory || {
+			echo "offline memory $memory: unexpected success"
+			retval=1
+		}
+
 	fi
 done

--
2.17.1


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

* [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit
  2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
                   ` (2 preceding siblings ...)
  2022-09-09  7:51 ` [PATCH -next 3/5] selftests/memory-hotplug: Add checking after online or offline Zhao Gongyi
@ 2022-09-09  7:51 ` Zhao Gongyi
  2022-09-09 12:21   ` David Hildenbrand
  2022-09-09  7:52 ` [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name Zhao Gongyi
  4 siblings, 1 reply; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:51 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

Some momory will be left in offline state when calling
offline_memory_expect_fail() failed. Restore it before exit.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../memory-hotplug/mem-on-off-test.sh         | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 3bdf3c4d6d06..259fd8978639 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -134,6 +134,17 @@ offline_memory_expect_fail()
 	return 0
 }

+online_all_hot_pluggable_memory()
+{
+
+	for memory in `hotpluggable_offline_memory`; do
+		online_memory_expect_success $memory || {
+			echo "online memory $memory: unexpected fail"
+			retval=1
+		}
+	done
+}
+
 error=-12
 priority=0
 # Run with default of ratio=2 for Kselftest run
@@ -278,13 +289,7 @@ done
 # Online all hot-pluggable memory
 #
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotpluggable_offline_memory`; do
-	online_memory_expect_success $memory || {
-		echo "online memory $memory: unexpected fail"
-		retval=1
-	}
-
-done
+online_all_hot_pluggable_memory

 #
 # Test memory hot-remove error handling (online => offline)
@@ -303,4 +308,9 @@ done
 echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
 /sbin/modprobe -q -r memory-notifier-error-inject

+#
+# Restore memory before exit
+#
+online_all_hot_pluggable_memory
+
 exit $retval
--
2.17.1


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

* [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name
  2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
                   ` (3 preceding siblings ...)
  2022-09-09  7:51 ` [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit Zhao Gongyi
@ 2022-09-09  7:52 ` Zhao Gongyi
  2022-09-09 12:18   ` David Hildenbrand
  4 siblings, 1 reply; 8+ messages in thread
From: Zhao Gongyi @ 2022-09-09  7:52 UTC (permalink / raw)
  To: linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, david, osalvador, shuah, Zhao Gongyi

Correct test's name for mem-on-off-test.sh/cpu-on-off-test.sh.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 Documentation/fault-injection/notifier-error-inject.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/fault-injection/notifier-error-inject.rst b/Documentation/fault-injection/notifier-error-inject.rst
index 0e2790122166..170c583eb5bc 100644
--- a/Documentation/fault-injection/notifier-error-inject.rst
+++ b/Documentation/fault-injection/notifier-error-inject.rst
@@ -95,8 +95,8 @@ For more usage examples
 There are tools/testing/selftests using the notifier error injection features
 for CPU and memory notifiers.

- * tools/testing/selftests/cpu-hotplug/on-off-test.sh
- * tools/testing/selftests/memory-hotplug/on-off-test.sh
+ * tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
+ * tools/testing/selftests/memory-hotplug/mem-on-off-test.sh

 These scripts first do simple online and offline tests and then do fault
 injection tests if notifier error injection module is available.
--
2.17.1


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

* Re: [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name
  2022-09-09  7:52 ` [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name Zhao Gongyi
@ 2022-09-09 12:18   ` David Hildenbrand
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand @ 2022-09-09 12:18 UTC (permalink / raw)
  To: Zhao Gongyi, linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, osalvador, shuah

On 09.09.22 09:52, Zhao Gongyi wrote:
> Correct test's name for mem-on-off-test.sh/cpu-on-off-test.sh.
> 
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>   Documentation/fault-injection/notifier-error-inject.rst | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/fault-injection/notifier-error-inject.rst b/Documentation/fault-injection/notifier-error-inject.rst
> index 0e2790122166..170c583eb5bc 100644
> --- a/Documentation/fault-injection/notifier-error-inject.rst
> +++ b/Documentation/fault-injection/notifier-error-inject.rst
> @@ -95,8 +95,8 @@ For more usage examples
>   There are tools/testing/selftests using the notifier error injection features
>   for CPU and memory notifiers.
> 
> - * tools/testing/selftests/cpu-hotplug/on-off-test.sh
> - * tools/testing/selftests/memory-hotplug/on-off-test.sh
> + * tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
> + * tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> 
>   These scripts first do simple online and offline tests and then do fault
>   injection tests if notifier error injection module is available.
> --
> 2.17.1
> 
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit
  2022-09-09  7:51 ` [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit Zhao Gongyi
@ 2022-09-09 12:21   ` David Hildenbrand
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand @ 2022-09-09 12:21 UTC (permalink / raw)
  To: Zhao Gongyi, linux-doc, linux-kernel, linux-mm, linux-kselftest
  Cc: akinobu.mita, corbet, osalvador, shuah

On 09.09.22 09:51, Zhao Gongyi wrote:
> Some momory will be left in offline state when calling
> offline_memory_expect_fail() failed. Restore it before exit.
> 
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>   .../memory-hotplug/mem-on-off-test.sh         | 24 +++++++++++++------
>   1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> index 3bdf3c4d6d06..259fd8978639 100755
> --- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> +++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> @@ -134,6 +134,17 @@ offline_memory_expect_fail()
>   	return 0
>   }
> 
> +online_all_hot_pluggable_memory()
> +{
> +
> +	for memory in `hotpluggable_offline_memory`; do
> +		online_memory_expect_success $memory || {
> +			echo "online memory $memory: unexpected fail"
> +			retval=1
> +		}
> +	done
> +}

Maybe call it

"online_all_offline_memory()"

instead?

Note that "removable" as used in hotpluggable_memory() will nowadays 
always return "1" if the kernel supports memory hotunplug, independent 
of the specific memory block.

-- 
Thanks,

David / dhildenb


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

end of thread, other threads:[~2022-09-09 12:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09  7:51 [PATCH -next 0/5] Optimize and bugfix for notifier error Zhao Gongyi
2022-09-09  7:51 ` [PATCH -next 1/5] docs: notifier-error-inject: fix non-working usage of negative values Zhao Gongyi
2022-09-09  7:51 ` [PATCH -next 2/5] selftests/memory-hotplug: Use 'printf' instead of 'echo' Zhao Gongyi
2022-09-09  7:51 ` [PATCH -next 3/5] selftests/memory-hotplug: Add checking after online or offline Zhao Gongyi
2022-09-09  7:51 ` [PATCH -next 4/5] selftests/memory-hotplug: Restore memory before exit Zhao Gongyi
2022-09-09 12:21   ` David Hildenbrand
2022-09-09  7:52 ` [PATCH -next 5/5] docs: notifier-error-inject: Correct test's name Zhao Gongyi
2022-09-09 12:18   ` David Hildenbrand

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