[PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash

Marcos Paulo de Souza posted 2 patches 1 month, 1 week ago
[PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Marcos Paulo de Souza 1 month, 1 week ago
When running current selftests on older distributions like SLE12-SP5 that
contains an older bash trips over heredoc. Convert it to plain echo
calls, which ends up with the same result.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 tools/testing/selftests/livepatch/functions.sh | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 8ec0cb64ad94..45ed04c6296e 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -96,10 +96,8 @@ function pop_config() {
 }
 
 function set_dynamic_debug() {
-        cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
-		file kernel/livepatch/* +p
-		func klp_try_switch_task -p
-		EOF
+	echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
+	echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
 }
 
 function set_ftrace_enabled() {

-- 
2.52.0
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Petr Mladek 3 weeks, 6 days ago
On Fri 2026-02-20 11:12:34, Marcos Paulo de Souza wrote:
> When running current selftests on older distributions like SLE12-SP5 that
> contains an older bash trips over heredoc. Convert it to plain echo
> calls, which ends up with the same result.
> 
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>

JFYI, the patch has been committed into livepatch.git,
branch for-7.1/ftrace-test.

I have fixed the typo reported by Joe, see
https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/commit/?h=for-7.1/ftrace-test&id=920e5001f4beb38685d5b8cac061cb1d2760eeab

Best Regards,
Petr
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Petr Mladek 3 weeks, 6 days ago
On Fri 2026-03-06 15:30:20, Petr Mladek wrote:
> On Fri 2026-02-20 11:12:34, Marcos Paulo de Souza wrote:
> > When running current selftests on older distributions like SLE12-SP5 that
> > contains an older bash trips over heredoc. Convert it to plain echo
> > calls, which ends up with the same result.
> > 
> > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> 
> JFYI, the patch has been committed into livepatch.git,
> branch for-7.1/ftrace-test.
> 
> I have fixed the typo reported by Joe, see
> https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/commit/?h=for-7.1/ftrace-test&id=920e5001f4beb38685d5b8cac061cb1d2760eeab

Grr, the above was meant for the 1st patch.
This 2nd patch was _not_ committed.

Best Regards,
Petr
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by David Laight 1 month, 1 week ago
On Fri, 20 Feb 2026 11:12:34 -0300
Marcos Paulo de Souza <mpdesouza@suse.com> wrote:

> When running current selftests on older distributions like SLE12-SP5 that
> contains an older bash trips over heredoc. Convert it to plain echo
> calls, which ends up with the same result.
> 
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
>  tools/testing/selftests/livepatch/functions.sh | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
> index 8ec0cb64ad94..45ed04c6296e 100644
> --- a/tools/testing/selftests/livepatch/functions.sh
> +++ b/tools/testing/selftests/livepatch/functions.sh
> @@ -96,10 +96,8 @@ function pop_config() {
>  }
>  
>  function set_dynamic_debug() {
> -        cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> -		file kernel/livepatch/* +p
> -		func klp_try_switch_task -p
> -		EOF
> +	echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> +	echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"

Use printf so you can write both lines in one command.

	David

>  }
>  
>  function set_ftrace_enabled() {
>
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Joe Lawrence 1 month, 1 week ago
On Fri, Feb 20, 2026 at 11:12:34AM -0300, Marcos Paulo de Souza wrote:
> When running current selftests on older distributions like SLE12-SP5 that
> contains an older bash trips over heredoc. Convert it to plain echo
> calls, which ends up with the same result.
> 

Acked-by: Joe Lawrence <joe.lawrence@redhat.com>

Just curious, what's the bash/heredoc issue?  All I could find via
google search was perhaps something to do with the temporary file
implementation under the hood.

--
Joe

> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
>  tools/testing/selftests/livepatch/functions.sh | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
> index 8ec0cb64ad94..45ed04c6296e 100644
> --- a/tools/testing/selftests/livepatch/functions.sh
> +++ b/tools/testing/selftests/livepatch/functions.sh
> @@ -96,10 +96,8 @@ function pop_config() {
>  }
>  
>  function set_dynamic_debug() {
> -        cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> -		file kernel/livepatch/* +p
> -		func klp_try_switch_task -p
> -		EOF
> +	echo "file kernel/livepatch/* +p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> +	echo "func klp_try_switch_task -p" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
>  }
>  
>  function set_ftrace_enabled() {
> 
> -- 
> 2.52.0
>
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Marcos Paulo de Souza 1 month, 1 week ago
On Mon, 2026-02-23 at 10:42 -0500, Joe Lawrence wrote:
> On Fri, Feb 20, 2026 at 11:12:34AM -0300, Marcos Paulo de Souza
> wrote:
> > When running current selftests on older distributions like SLE12-
> > SP5 that
> > contains an older bash trips over heredoc. Convert it to plain echo
> > calls, which ends up with the same result.
> > 
> 
> Acked-by: Joe Lawrence <joe.lawrence@redhat.com>

Thanks for the review Joe!

> 
> Just curious, what's the bash/heredoc issue?  All I could find via
> google search was perhaps something to do with the temporary file
> implementation under the hood.

# ./test-ftrace.sh 
cat: -: No such file or directory
TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU:
Terminated

Somehow it doesn't understand the heredoc, but maybe I'm wrong...
either way, the change has the same outcome, so I believe that it
wasn't bad if we could change the cat for two echoes :)

Either way, if Petr or you think that this should be left as it is,
it's fine by me as well, I was just testing the change with an older
rootfs/kernels.

> 
> --
> Joe
> 
> > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> > ---
> >  tools/testing/selftests/livepatch/functions.sh | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/livepatch/functions.sh
> > b/tools/testing/selftests/livepatch/functions.sh
> > index 8ec0cb64ad94..45ed04c6296e 100644
> > --- a/tools/testing/selftests/livepatch/functions.sh
> > +++ b/tools/testing/selftests/livepatch/functions.sh
> > @@ -96,10 +96,8 @@ function pop_config() {
> >  }
> >  
> >  function set_dynamic_debug() {
> > -        cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> > -		file kernel/livepatch/* +p
> > -		func klp_try_switch_task -p
> > -		EOF
> > +	echo "file kernel/livepatch/* +p" >
> > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> > +	echo "func klp_try_switch_task -p" >
> > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
> >  }
> >  
> >  function set_ftrace_enabled() {
> > 
> > -- 
> > 2.52.0
> > 
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Miroslav Benes 1 month ago
Hi,

On Mon, 23 Feb 2026, Marcos Paulo de Souza wrote:

> On Mon, 2026-02-23 at 10:42 -0500, Joe Lawrence wrote:
> > On Fri, Feb 20, 2026 at 11:12:34AM -0300, Marcos Paulo de Souza
> > wrote:
> > > When running current selftests on older distributions like SLE12-
> > > SP5 that
> > > contains an older bash trips over heredoc. Convert it to plain echo
> > > calls, which ends up with the same result.
> > > 
> > 
> > Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
> 
> Thanks for the review Joe!
> 
> > 
> > Just curious, what's the bash/heredoc issue?  All I could find via
> > google search was perhaps something to do with the temporary file
> > implementation under the hood.
> 
> # ./test-ftrace.sh 
> cat: -: No such file or directory
> TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU:
> Terminated

I cannot reproduce it locally on SLE12-SP5. The patched test-ftrace.sh 
runs smoothly without 2/2.

linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh 
TEST: livepatch interaction with ftrace_enabled sysctl ... ok
TEST: trace livepatched function and check that the live patch remains in effect ... ok
TEST: livepatch a traced function and check that the live patch remains in effect ... ok

GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)

Does "set -x" in the script give you anything interesting?

Miroslav
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Marcos Paulo de Souza 1 month ago
On Thu, 2026-02-26 at 13:40 +0100, Miroslav Benes wrote:
> Hi,
> 
> On Mon, 23 Feb 2026, Marcos Paulo de Souza wrote:
> 
> > On Mon, 2026-02-23 at 10:42 -0500, Joe Lawrence wrote:
> > > On Fri, Feb 20, 2026 at 11:12:34AM -0300, Marcos Paulo de Souza
> > > wrote:
> > > > When running current selftests on older distributions like
> > > > SLE12-
> > > > SP5 that
> > > > contains an older bash trips over heredoc. Convert it to plain
> > > > echo
> > > > calls, which ends up with the same result.
> > > > 
> > > 
> > > Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
> > 
> > Thanks for the review Joe!
> > 
> > > 
> > > Just curious, what's the bash/heredoc issue?  All I could find
> > > via
> > > google search was perhaps something to do with the temporary file
> > > implementation under the hood.
> > 
> > # ./test-ftrace.sh 
> > cat: -: No such file or directory
> > TEST: livepatch interaction with ftrace_enabled sysctl ... ^CQEMU:
> > Terminated
> 
> I cannot reproduce it locally on SLE12-SP5. The patched test-
> ftrace.sh 
> runs smoothly without 2/2.
> 
> linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh 
> TEST: livepatch interaction with ftrace_enabled sysctl ... ok
> TEST: trace livepatched function and check that the live patch
> remains in effect ... ok
> TEST: livepatch a traced function and check that the live patch
> remains in effect ... ok
> 
> GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
> 
> Does "set -x" in the script give you anything interesting?

Nope:

boot_livepatch:/mnt/tools/testing/selftests/livepatch # ./test-trace.sh
+ cat     
cat: -: No such file or directory            
+ set_ftrace_enabled 1                                     
+ local can_fail=0


Same version here:
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)

I'm using virtme-ng, so I'm not sure if this is related. At the same
time it works on SLE15-SP4, using the same virtme-ng, but with a
different bash:
GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)

So I was blaming bash for this issue...

> 
> Miroslav
Re: [PATCH 2/2] selftests: livepatch: functions.sh: Workaround heredoc on older bash
Posted by Marcos Paulo de Souza 1 month ago
On Thu, 2026-02-26 at 11:34 -0300, Marcos Paulo de Souza wrote:
> On Thu, 2026-02-26 at 13:40 +0100, Miroslav Benes wrote:
> > Hi,
> > 
> > On Mon, 23 Feb 2026, Marcos Paulo de Souza wrote:
> > 
> > > On Mon, 2026-02-23 at 10:42 -0500, Joe Lawrence wrote:
> > > > On Fri, Feb 20, 2026 at 11:12:34AM -0300, Marcos Paulo de Souza
> > > > wrote:
> > > > > When running current selftests on older distributions like
> > > > > SLE12-
> > > > > SP5 that
> > > > > contains an older bash trips over heredoc. Convert it to
> > > > > plain
> > > > > echo
> > > > > calls, which ends up with the same result.
> > > > > 
> > > > 
> > > > Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
> > > 
> > > Thanks for the review Joe!
> > > 
> > > > 
> > > > Just curious, what's the bash/heredoc issue?  All I could find
> > > > via
> > > > google search was perhaps something to do with the temporary
> > > > file
> > > > implementation under the hood.
> > > 
> > > # ./test-ftrace.sh 
> > > cat: -: No such file or directory
> > > TEST: livepatch interaction with ftrace_enabled sysctl ...
> > > ^CQEMU:
> > > Terminated
> > 
> > I cannot reproduce it locally on SLE12-SP5. The patched test-
> > ftrace.sh 
> > runs smoothly without 2/2.
> > 
> > linux:~/linux/tools/testing/selftests/livepatch # ./test-ftrace.sh 
> > TEST: livepatch interaction with ftrace_enabled sysctl ... ok
> > TEST: trace livepatched function and check that the live patch
> > remains in effect ... ok
> > TEST: livepatch a traced function and check that the live patch
> > remains in effect ... ok
> > 
> > GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
> > 
> > Does "set -x" in the script give you anything interesting?
> 
> Nope:
> 
> boot_livepatch:/mnt/tools/testing/selftests/livepatch # ./test-
> trace.sh
> + cat     
> cat: -: No such file or directory            
> + set_ftrace_enabled 1                                     
> + local can_fail=0
> 
> 
> Same version here:
> GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
> 
> I'm using virtme-ng, so I'm not sure if this is related. At the same
> time it works on SLE15-SP4, using the same virtme-ng, but with a
> different bash:
> GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)
> 
> So I was blaming bash for this issue...

This patch can be skipped. For the record, I discovered that it only
happens when vng is called using --rw, making it to fail on older bash
since it doesn't create overlays for /tmp. If the overlay is added the
issue is gone.

So, this patch can be skipped. Thanks Miroslav for testing!

> 
> > 
> > Miroslav