Skip to contentSkip to conversation

selftests/livepatch: push and pop dynamic debug config

PATCH Applied Joe Lawrence 3 participants 6 messages Jul 18, 2019 – Jul 30, 2019

Subsystems (2)
lore
Share & tools
lore

Joe Lawrence

author maintainer
#0 lore raw

PATCH 1/1 selftests/livepatch: push and pop dynamic debug config

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests. Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

Note this functionality needs to keep in sync with:
- dynamic_debug input/output formatting
- functions affected by set_dynamic_debug()

For example, push_dynamic_debug() transforms:
kernel/livepatch/transition.c:530 [livepatch]klp_init_transition =_ "'%s': initializing %s transition\012"
to:
file kernel/livepatch/transition.c line 530 =_

---
 .../testing/selftests/livepatch/functions.sh  | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
tools/testing/selftests/livepatch/functions.sh +20 -6
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {
 	exit 1
 }
 
-# set_dynamic_debug() - setup kernel dynamic debug
-#	TODO - push and pop this config?
+function push_dynamic_debug() {
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
+}
+
+function pop_dynamic_debug() {
+	if [[ -n "$DYNAMIC_DEBUG" ]]; then
+		echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
+	fi
+}
+
+# set_dynamic_debug() - save the current dynamic debug config and tweak
+# 			it for the self-tests.  Set a script exit trap
+#			that restores the original config.
 function set_dynamic_debug() {
-	cat << EOF > /sys/kernel/debug/dynamic_debug/control
-file kernel/livepatch/* +p
-func klp_try_switch_task -p
-EOF
+        push_dynamic_debug
+        trap pop_dynamic_debug EXIT INT TERM HUP
+        cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
+		file kernel/livepatch/* +p
+		func klp_try_switch_task -p
+		EOF
 }
 
 # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
Signature · 1 line
2.21.0
author maintainer
#1 lore raw
Quoted 47 lines · Joe Lawrence

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests. Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

Note this functionality needs to keep in sync with:
- dynamic_debug input/output formatting
- functions affected by set_dynamic_debug()

For example, push_dynamic_debug() transforms:
kernel/livepatch/transition.c:530 [livepatch]klp_init_transition =_ "'%s': initializing %s transition\012"
to:
file kernel/livepatch/transition.c line 530 =_

---
  .../testing/selftests/livepatch/functions.sh  | 26 ++++++++++++++-----
  1 file changed, 20 insertions(+), 6 deletions(-)
tools/testing/selftests/livepatch/functions.sh +14 -5
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {
  	exit 1
  }
 
-# set_dynamic_debug() - setup kernel dynamic debug
-#	TODO - push and pop this config?
+function push_dynamic_debug() {
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
+}
+
+function pop_dynamic_debug() {
+	if [[ -n "$DYNAMIC_DEBUG" ]]; then
+		echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
+	fi
+}
+
+# set_dynamic_debug() - save the current dynamic debug config and tweak
+# 			it for the self-tests.  Set a script exit trap
+#			that restores the original config.
  function set_dynamic_debug() {
-	cat << EOF > /sys/kernel/debug/dynamic_debug/control
-file kernel/livepatch/* +p
-func klp_try_switch_task -p

tools/testing/selftests/livepatch/functions.sh function die() { · line 55

Quoted 10 lines
tools/testing/selftests/livepatch/functions.sh +6 -1
-EOF
+        push_dynamic_debug
+        trap pop_dynamic_debug EXIT INT TERM HUP
+        cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
+		file kernel/livepatch/* +p
+		func klp_try_switch_task -p
+		EOF
  }
 
  # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,

I took a stab as this while working on "[PATCH v2] selftests/livepatch: add test skip handling​", which this applies on top of.

It works for me, though I feel that the /sys/kernel/debug/dynamic_debug/control output to input translation is brittle. It would be nice to have some kind of mass export/import capability for that interface.

-- Joe

maintainer Tested-by
#2 lore raw
Quoted 15 lines · Joe Lawrence
Quoted 14 lines · Joe Lawrence

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests. Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

tools/testing/selftests/livepatch/functions.sh +1 -2
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {
  	exit 1
  }
-# set_dynamic_debug() - setup kernel dynamic debug
-#	TODO - push and pop this config?
+function push_dynamic_debug() {
Quoted 8 lines

tools/testing/selftests/livepatch/functions.sh function die() { · line 35

Quoted 3 lines
tools/testing/selftests/livepatch/functions.sh +3 -0
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
+}

It works for me, though I feel that the /sys/kernel/debug/dynamic_debug/control output to input translation is brittle. It would be nice to have some kind of mass export/import capability for that interface.

I believe that the format is pretty stable. We could always reconsider it when it breaks.

I could confirm that it restores the original state, so:

Best Regards,
Petr

author maintainer
#3 lore raw
Quoted 28 lines · Petr Mladek
Quoted 15 lines · Joe Lawrence
Quoted 14 lines · Joe Lawrence

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests. Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

tools/testing/selftests/livepatch/functions.sh +1 -2
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {
   	exit 1
   }
-# set_dynamic_debug() - setup kernel dynamic debug
-#	TODO - push and pop this config?
+function push_dynamic_debug() {
Quoted 8 lines

tools/testing/selftests/livepatch/functions.sh function die() { · line 35

Quoted 3 lines
tools/testing/selftests/livepatch/functions.sh +3 -0
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
+}

It works for me, though I feel that the /sys/kernel/debug/dynamic_debug/control output to input translation is brittle. It would be nice to have some kind of mass export/import capability for that interface.

I believe that the format is pretty stable. We could always reconsider it when it breaks.

Quoted 7 lines

I could confirm that it restores the original state, so:

Best Regards,
Petr

Hi Shuah,

Can you review and route this patch through your tree as well?

Thanks,

-- Joe

maintainer
#4 lore raw
Quoted 34 lines · Joe Lawrence
Quoted 33 lines · Petr Mladek
Quoted 16 lines · Joe Lawrence
Quoted 15 lines · Joe Lawrence

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests.  Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

tools/testing/selftests/livepatch/functions.sh +0 -0
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {

       exit 1
   }

tools/testing/selftests/livepatch/functions.sh +2 -2
-# set_dynamic_debug() - setup kernel dynamic debug
-#    TODO - push and pop this config?
+function push_dynamic_debug() {
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' 
Quoted 8 lines
Quoted 3 lines

/sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}') +}

It works for me, though I feel that the /sys/kernel/debug/dynamic_debug/control output to input translation is brittle.  It would be nice to have some kind of mass export/import capability for that interface.

I believe that the format is pretty stable. We could always reconsider it when it breaks.

I could confirm that it restores the original state, so:

Quoted 8 lines
Quoted 3 lines

Best Regards,
Petr

Hi Shuah,

Can you review and route this patch through your tree as well?

Looks good to me. Thanks for doing this. I will pick this up

thanks,
-- Shuah

maintainer Applied
#5 lore raw
Quoted 39 lines · shuah
Quoted 38 lines · Joe Lawrence
Quoted 36 lines · Petr Mladek
Quoted 16 lines · Joe Lawrence
Quoted 15 lines · Joe Lawrence

The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests.  Enhance set_dynamic_debug() so that the config changes are restored when the script exits.

tools/testing/selftests/livepatch/functions.sh +0 -0
index de5a504ffdbc..860f27665ebd 100644
@@ -29,13 +29,27 @@ function die() {

       exit 1
   }

tools/testing/selftests/livepatch/functions.sh +2 -2
-# set_dynamic_debug() - setup kernel dynamic debug
-#    TODO - push and pop this config?
+function push_dynamic_debug() {
+        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' 
Quoted 8 lines
Quoted 3 lines

/sys/kernel/debug/dynamic_debug/control | \
+                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}') +}

It works for me, though I feel that the /sys/kernel/debug/dynamic_debug/control output to input translation is brittle.  It would be nice to have some kind of mass export/import capability for that interface.

I believe that the format is pretty stable. We could always reconsider it when it breaks.

I could confirm that it restores the original state, so:

Best Regards,
Petr

Quoted 7 lines
Quoted 4 lines

Hi Shuah,

Can you review and route this patch through your tree as well?

Looks good to me. Thanks for doing this. I will pick this up

Applied it with minor change to commit log to correct checkpatch error on

---
to the following:
file kernel/livepatch/transition.c line 530 =_
---

WARNING: Do not use whitespace before To:
#72:
to:

WARNING: Use a single space after To:
#72:
to:

ERROR: Unrecognized email address: ''
#72:
to:

I changed it to:

---
to the following:
file kernel/livepatch/transition.c line 530 =_
---

I will send this in for rc4

thanks,
-- Shuah