# Re: \[PATCH v7 for-next 8/8\] selftests/livepatch: Add test for function conflict across provides

- From: Petr Mladek \<pmladek@suse.com\>
- Date: 2026-09-02 15:51:50 
- List: live-patching
- Page: https://ratatoskr.run/live-patching/2026/09/17499277
- Thread: https://ratatoskr.run/live-patching/2026/08/17458637/t.md

```text
On Tue 2026-08-25 19:46:41, Yafang Shao wrote:
> Livepatches with different provides ids must not modify the same
> function. If a second livepatch attempts to modify a function that
> has already been modified by a loaded livepatch with a different
> provides id, the loading will fail. If the second livepatch shares
> the same provides id, or if its obsoletes list contains the first
> livepatch's provides id, it will load successfully and replace the
> first one.
> 
> Add a new test module test_klp_provides.c that patches meminfo_proc_show
> (the same function as test_klp_atomic_replace) so that the two modules
> can be loaded with different provides ids to test the function conflict
> detection.
> 
> Add three test scenarios to test-provides.sh:
> 
> 1. Function conflict across provides: load test_klp_atomic_replace with
>    provides=1, then attempt to load test_klp_provides with provides=2.
>    The second livepatch is rejected because livepatches with different
>    provides ids and no obsoletes must not modify the same function.
> 
> 2. Function replace within same provides: load test_klp_atomic_replace
>    with provides=1, then load test_klp_provides with provides=1. The
>    second livepatch loads successfully and replaces the first one
>    because they share the same provides id.
> 
> 3. Function replace across provides with obsoletes: load
>    test_klp_atomic_replace with provides=1, then load test_klp_provides
>    with provides=2 and obsoletes=[1]. The second livepatch loads
>    successfully and replaces the first one because the obsoletes list
>    allows it to replace a livepatch with a different provides id.
> 
> Assisted-by: Comagic:DeepSeek-V4-Flash
> Signed-off-by: Yafang Shao <redacted>
> ---
>  .../livepatch/test-provides-obsoletes.sh      | 110 ++++++++++++++++++
>  .../selftests/livepatch/test_modules/Makefile |   1 +
>  .../test_modules/test_klp_provides.c          |  72 ++++++++++++
>  3 files changed, 183 insertions(+)
>  create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_provides.c
> 
> diff --git a/tools/testing/selftests/livepatch/test-provides-obsoletes.sh b/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
> index f9a9f9b28490..be54e8d2c889 100755
> --- a/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
> +++ b/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
> @@ -8,6 +8,7 @@ MOD_ATOMIC=test_klp_atomic_replace
>  MOD_LIVEPATCH=test_klp_livepatch
>  MOD_STATE=test_klp_state
>  MOD_STATE2=test_klp_state2
> +MOD_PROVIDES=test_klp_provides

The new module duplicates test_klp_atomic_replace.c. We want to avoid
this. Please, create the copy module by using

    #include <original_module.c>

Also it would really help to use a better naming. As I suggeted in
the review of the 6th patch:

   + test_klp_proc_meminfo_livepatch
   + test_klp_proc_meminfo_livepatch2

or

   + test_klp_meminfo_lp
   + test_klp_meminfo_lp2

Then it will be clear that these are liveapatches and they modify
the same function.

Then it would be more obvious when they should succeed and
when fails:

# same function, replaced by provides
load_lp $MOD_MEMINFO_LP provides=1
load_lp $MOD_MEMINFO_LP2 provides=1

# same function, can't be loaded  in parallel
load_lp $MOD_MEMINFO_LP provides=1
load_failing_mod $MOD_MEMINFO_LP2 provides=2

# different functions, atomic replace works (nops)
load_lp $MOD_MEMINFO_LP provides=1
load_lp $MOD_CMDLINE_LP provides=1

# different functions, install in parallel
load_lp $MOD_MEMINFO_LP provides=1
load_lp $MOD_CMDLINE_LP provides=2

Best Regards,
Petr
```
