linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/livepatch: push and pop dynamic debug config
@ 2019-07-18 20:29 Joe Lawrence
  2019-07-18 20:42 ` Joe Lawrence
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Lawrence @ 2019-07-18 20:29 UTC (permalink / raw)
  To: live-patching, linux-kselftest

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 =_

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
 .../testing/selftests/livepatch/functions.sh  | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index de5a504ffdbc..860f27665ebd 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -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,
-- 
2.21.0


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

* Re: [PATCH] selftests/livepatch: push and pop dynamic debug config
  2019-07-18 20:29 [PATCH] selftests/livepatch: push and pop dynamic debug config Joe Lawrence
@ 2019-07-18 20:42 ` Joe Lawrence
  2019-07-19 10:46   ` Petr Mladek
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Lawrence @ 2019-07-18 20:42 UTC (permalink / raw)
  To: live-patching, linux-kselftest

On 7/18/19 4:29 PM, Joe Lawrence wrote:
> 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 =_
> 
> Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
> ---
>   .../testing/selftests/livepatch/functions.sh  | 26 ++++++++++++++-----
>   1 file changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
> index de5a504ffdbc..860f27665ebd 100644
> --- a/tools/testing/selftests/livepatch/functions.sh
> +++ b/tools/testing/selftests/livepatch/functions.sh
> @@ -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,
> 

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

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

* Re: [PATCH] selftests/livepatch: push and pop dynamic debug config
  2019-07-18 20:42 ` Joe Lawrence
@ 2019-07-19 10:46   ` Petr Mladek
  2019-07-30 17:31     ` Joe Lawrence
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Mladek @ 2019-07-19 10:46 UTC (permalink / raw)
  To: Joe Lawrence; +Cc: linux-kselftest, live-patching

On Thu 2019-07-18 16:42:25, Joe Lawrence wrote:
> On 7/18/19 4:29 PM, Joe Lawrence wrote:
> > 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.
> > 
> > diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
> > index de5a504ffdbc..860f27665ebd 100644
> > --- a/tools/testing/selftests/livepatch/functions.sh
> > +++ b/tools/testing/selftests/livepatch/functions.sh
> > @@ -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}')
> > +}
> 
> 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:

Tested-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

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

* Re: [PATCH] selftests/livepatch: push and pop dynamic debug config
  2019-07-19 10:46   ` Petr Mladek
@ 2019-07-30 17:31     ` Joe Lawrence
  2019-07-30 21:26       ` shuah
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Lawrence @ 2019-07-30 17:31 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, live-patching

On 7/19/19 6:46 AM, Petr Mladek wrote:
> On Thu 2019-07-18 16:42:25, Joe Lawrence wrote:
>> On 7/18/19 4:29 PM, Joe Lawrence wrote:
>>> 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.
>>>
>>> diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
>>> index de5a504ffdbc..860f27665ebd 100644
>>> --- a/tools/testing/selftests/livepatch/functions.sh
>>> +++ b/tools/testing/selftests/livepatch/functions.sh
>>> @@ -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}')
>>> +}
>>
>> 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:
> 
> Tested-by: Petr Mladek <pmladek@suse.com>
> 
> Best Regards,
> Petr
> 

Hi Shuah,

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

Thanks,

-- Joe

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

* Re: [PATCH] selftests/livepatch: push and pop dynamic debug config
  2019-07-30 17:31     ` Joe Lawrence
@ 2019-07-30 21:26       ` shuah
  2019-07-30 21:52         ` shuah
  0 siblings, 1 reply; 6+ messages in thread
From: shuah @ 2019-07-30 21:26 UTC (permalink / raw)
  To: Joe Lawrence; +Cc: linux-kselftest, live-patching, shuah

On 7/30/19 11:31 AM, Joe Lawrence wrote:
> On 7/19/19 6:46 AM, Petr Mladek wrote:
>> On Thu 2019-07-18 16:42:25, Joe Lawrence wrote:
>>> On 7/18/19 4:29 PM, Joe Lawrence wrote:
>>>> 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.
>>>>
>>>> diff --git a/tools/testing/selftests/livepatch/functions.sh 
>>>> b/tools/testing/selftests/livepatch/functions.sh
>>>> index de5a504ffdbc..860f27665ebd 100644
>>>> --- a/tools/testing/selftests/livepatch/functions.sh
>>>> +++ b/tools/testing/selftests/livepatch/functions.sh
>>>> @@ -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}')
>>>> +}
>>>
>>> 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:
>>
>> Tested-by: Petr Mladek <pmladek@suse.com>
>>
>> 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


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

* Re: [PATCH] selftests/livepatch: push and pop dynamic debug config
  2019-07-30 21:26       ` shuah
@ 2019-07-30 21:52         ` shuah
  0 siblings, 0 replies; 6+ messages in thread
From: shuah @ 2019-07-30 21:52 UTC (permalink / raw)
  To: Joe Lawrence; +Cc: linux-kselftest, live-patching, shuah

On 7/30/19 3:26 PM, shuah wrote:
> On 7/30/19 11:31 AM, Joe Lawrence wrote:
>> On 7/19/19 6:46 AM, Petr Mladek wrote:
>>> On Thu 2019-07-18 16:42:25, Joe Lawrence wrote:
>>>> On 7/18/19 4:29 PM, Joe Lawrence wrote:
>>>>> 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.
>>>>>
>>>>> diff --git a/tools/testing/selftests/livepatch/functions.sh 
>>>>> b/tools/testing/selftests/livepatch/functions.sh
>>>>> index de5a504ffdbc..860f27665ebd 100644
>>>>> --- a/tools/testing/selftests/livepatch/functions.sh
>>>>> +++ b/tools/testing/selftests/livepatch/functions.sh
>>>>> @@ -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}')
>>>>> +}
>>>>
>>>> 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:
>>>
>>> Tested-by: Petr Mladek <pmladek@suse.com>
>>>
>>> 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
> 

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


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

end of thread, other threads:[~2019-07-30 21:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18 20:29 [PATCH] selftests/livepatch: push and pop dynamic debug config Joe Lawrence
2019-07-18 20:42 ` Joe Lawrence
2019-07-19 10:46   ` Petr Mladek
2019-07-30 17:31     ` Joe Lawrence
2019-07-30 21:26       ` shuah
2019-07-30 21:52         ` shuah

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