From: Petr Mladek <pmladek@suse.com>
To: Michael Vetter <mvetter@suse.com>
Cc: linux-kselftest@vger.kernel.org, live-patching@vger.kernel.org
Subject: Re: [PATCH v2] selftests: livepatch: test livepatching a kprobed function
Date: Thu, 19 Sep 2024 09:40:22 +0200 [thread overview]
Message-ID: <ZuvVZneTT7SY76wP@pathway.suse.cz> (raw)
In-Reply-To: <20240917135059.73346-1-mvetter@suse.com>
On Tue 2024-09-17 15:50:53, Michael Vetter wrote:
> The test proves that a function that is being kprobed and uses a
> post_handler cannot be livepatched.
>
> Only one ftrace_ops with FTRACE_OPS_FL_IPMODIFY set may be registered
> to any given function at a time.
>
> --- /dev/null
> +++ b/tools/testing/selftests/livepatch/test-kprobe.sh
> @@ -0,0 +1,65 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 SUSE
> +# Author: Michael Vetter <mvetter@suse.com>
> +
> +. $(dirname $0)/functions.sh
> +
> +MOD_LIVEPATCH=test_klp_livepatch
> +MOD_KPROBE=test_klp_kprobe
> +
> +setup_config
> +
> +# Kprobe a function and verify that we can't livepatch that same function
> +# when it uses a post_handler since only one IPMODIFY maybe be registered
> +# to any given function at a time.
> +
> +start_test "livepatch interaction with kprobed function with post_handler"
> +
> +STATE=$(cat /sys/kernel/debug/kprobes/enabled)
> +echo 1 > /sys/kernel/debug/kprobes/enabled
> +
> +load_mod $MOD_KPROBE has_post_handler=true
> +load_failing_mod $MOD_LIVEPATCH
> +unload_mod $MOD_KPROBE
[...]
> +echo $STATE > /sys/kernel/debug/kprobes/enabled
The original state won't get restored when the test fails.
A better solution would be to integrate this into setup_config()
and cleanup() in /tools/testing/selftests/livepatch/functions.sh
Also it would be great to avoid hard-coding /sys/kernel/debug.
See KLP_SYSFS_DIR="/sys/kernel/livepatch" in
/tools/testing/selftests/livepatch/functions.sh
I would replace it with:
KERNEL_SYSFS_DIR="/sys/kernel"
KLP_SYSFS_DIR="$KERNEL_SYSFS_DIR/livepatch"
DEBUG_SYSFS_DIR="$KERNEL_SYSFS_DIR/debug"
KPROBES_SYSFS_DIR="$DEBUG_SYSFS_DIR/kprobes"
It would actually look better with switched ordering:
SYSFS_KERNEL_DIR="/sys/kernel"
SYSFS_KLP_DIR="$SYSFS_KERNEL_DIR/livepatch"
SYSFS_DEBUG_DIR="$SYSFS_KERNEL_DIR/debug"
SYSFS_KPROBES_DIR="$SYSFS_DEBUG_DIR/kprobes"
But this would require renaming KLP_SYSFS_DIR everywhere in
a separate (prerequisite) patch. It would be nice but
I do not want to force you to do it ;-)
> --- a/tools/testing/selftests/livepatch/test_modules/Makefile
> +++ b/tools/testing/selftests/livepatch/test_modules/Makefile
> @@ -11,7 +11,8 @@ obj-m += test_klp_atomic_replace.o \
> test_klp_state2.o \
> test_klp_state3.o \
> test_klp_shadow_vars.o \
> - test_klp_syscall.o
> + test_klp_syscall.o \
> + test_klp_kprobe.o
Nit: Please, put it in alphabetical order. It is not a big deal.
The ordering helps searching. The list already is almost sorted.
And the patch needs to be updated anyway.
> # Ensure that KDIR exists, otherwise skip the compilation
> modules:
> diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_kprobe.c b/tools/testing/selftests/livepatch/test_modules/test_klp_kprobe.c
> new file mode 100644
> index 000000000000..49b579ea1054
> --- /dev/null
> +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_kprobe.c
> @@ -0,0 +1,38 @@
[...]
> +module_init(kprobe_init)
> +module_exit(kprobe_exit)
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Michael Vetter <mvetter@suse.com>");
> +MODULE_DESCRIPTION("Livepatch test: livepatch kprobed function");
Nit: The module adds a kprobe. I would invert the logic:
MODULE_DESCRIPTION("Livepatch test: kprobe livepatched function");
Best Regards,
Petr
prev parent reply other threads:[~2024-09-19 7:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 13:50 [PATCH v2] selftests: livepatch: test livepatching a kprobed function Michael Vetter
2024-09-19 7:40 ` Petr Mladek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZuvVZneTT7SY76wP@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mvetter@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).