From: Petr Mladek <pmladek@suse.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
joe.lawrence@redhat.com, song@kernel.org,
live-patching@vger.kernel.org
Subject: Re: Replace rules: was: Re: [PATCH v7 for-next 3/8] livepatch: Implement replace set for scoped atomic replace
Date: Thu, 3 Sep 2026 11:27:27 +0200 [thread overview]
Message-ID: <apk9f_LsGRYHzN0Z@pathway.suse.cz> (raw)
In-Reply-To: <CALOAHbAb3Hiv5HZ0b0r_GjqCpZRx53Yq-NJo=eo7PxE_tD9asQ@mail.gmail.com>
On Wed 2026-09-02 17:40:02, Yafang Shao wrote:
> On Wed, Sep 2, 2026 at 3:31 PM Petr Mladek <pmladek@suse.com> wrote:
> >
> > On Tue 2026-08-25 19:46:36, Yafang Shao wrote:
> > > The current bool replace flag is too coarse: it is either all or
> > > nothing. A livepatch with .replace=true replaces ALL existing
> > > livepatches, which is safe but inflexible. There is no way to have
> > > multiple independent livepatch sets coexist on the same system.
> > >
> > > Replace it with a more flexible model using two new fields in
> > > struct klp_patch:
> > >
> > > - provides: an unsigned int id identifying the patch replace set.
> > > By default (provides=0), any livepatch replaces any other livepatch.
> > >
> > > - obsoletes: an optional array of unsigned int ids specifying
> > > additional provides ids to be replaced. This allows a new patch
> > > to explicitly obsolete patches from different replace sets.
> >
> > > --- a/include/linux/livepatch.h
> > > +++ b/include/linux/livepatch.h
> > > @@ -123,7 +123,8 @@ struct klp_state {
> > > * @mod: reference to the live patch module
> > > * @objs: object entries for kernel objects to be patched
> > > * @states: system states that can get modified
> > > - * @replace: replace all actively used patches
> > > + * @provides: only one active livepatch per id
> > > + * @obsoletes: replace given livepatch id(s)
> > > * @list: list node for global list of actively used patches
> > > * @kobj: kobject for sysfs resources
> > > * @obj_list: dynamic list of the object entries
> > > @@ -137,7 +138,9 @@ struct klp_patch {
> > > struct module *mod;
> > > struct klp_object *objs;
> > > struct klp_state *states;
> > > - bool replace;
> > > + unsigned int provides;
> > > + unsigned int *obsoletes;
> > > + unsigned int nr_obsoletes;
> >
> > This is a different sematic in compare with the other arrays.
> > I guess that you wanted to allow obsoleting livepatch with '0' ID.
>
> right.
>
> >
> > But '0' is special. It obsoletes anything. Maybe, we could
> > make it even more special and say that it can't obsoleted.
> > Then we would be able to use it as the trailing element
> > in the array...
> >
> > I do not have strong opinion about this. It is just an idea.
>
> Making '0' special is good for backward compatibility, but it
> complicates usage for users. Therefore, I prefer not to treat '0' as a
> special case.
Ah, I have missed that the current code does not treat '0' special.
I was confused by the following sentence in the commit message:
<paste>
By default (provides=0), any livepatch replaces any other livepatch.
</paste>
and this paragraph in the documentation:
<paste>
It should be emphasized that the preferred and most secure way is to always use
the default ``provides = 0``. In this mode, any livepatch replaces any other
livepatch, preventing any unexpected interactions between incompatible
livepatches.
</paste>
I understood it the way that ``provides = 0`` was supposed to be
special and always replace all other livepatches.
I think that I was affected by Miroslav. I had an off-list discussion
with him about this some time ago. My understanding is that Miroslav
would prefer to somehow preserve the original ``replace = true``
when the livepatch patch replaced anything.
It might be useful for OS providers who want to make sure that their
kernel critical fixes can be installed on the user system. Otherwise,
customers might complain that some update failed, ...
Of course, it has a drawback that any livepatch with ``prov ides= 0``
would wipe any 3rd party livepatches, even when they are against 3rd
party modules.
I am not completely sure that this the special handling is a good
idea. A better solution might be an option which might be used when
loading the livepatch. e.g.
insmod livepatch.ko replace_all=y
Any opinions?
Miroslav?
> > Another question:
> >
> > Should we allow to enable a livepatch when its provides id
> > is obsoleted by a currently enabled livepatch?
>
> Good question.
> I believe it's best to refuse to load it, as doing otherwise might
> introduce potential issues. I will update this rule in the next
> version.
>
> >
> > For example, let's have:
> >
> > + Livepatch A: provides:1
> > + Livepatch B: provides:2, obsoletes:1
> >
> > Now, two scenarios:
> >
> > 1. Livepatch A can be replaced by livepatch B. This is easy.
> > 2. Can livepatch B get replaced by livepatch A?
>
> No, I don't believe B should be replaced by A. In this case, if B is
> already enabled, A should fail to load.
This is my preference as well.
> > The current code would allow to replace B with A when there is
> > _no_ real conflict in the livaptched objects, functions, and states.
> >
> > But does it make sense?
> >
> > Reasoning: Livepatch B obsoleted the livepatch A for a reason.
> > It sounds like they should not be enabled at the same time.
> >
> >
> > Special case:
> >
> > Should we allow to install a livepatch with non-zero provides
> > when a livepatch with zero provides is installed.
> >
> > For example, let's have:
> >
> > + Livepatch A: provides:1
> > + Livepatch B: provides:0
> >
> > Now, two scenarios:
> >
> > 1. Livepatch A can be replaced by livepatch B. This is easy.
> > 2. Can livepatch A be installed in parallel with B?
> >
> > Reasoning: The livepatch B replaces everything because it wants
> > to be the only installed livepatch. It sounds weird
> > to "break" it by installing A in parallel later again.
>
> So, let's just not treat '0' as a special case?
I am not sure.
I personally think that '0' should not be special. A better solution
for a forced cleanup is the "replace_all" module option.
The module option would need to be implemented in the livepatch code.
But it will need some support in the livepatch core as well, either
a flag in struct klp_patch or parameter in klp_enable_patch().
IMHO, the flag in struct klp_patch might be more practical.
Best Regards,
Petr
next prev parent reply other threads:[~2026-09-03 9:27 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 11:46 [PATCH v7 for-next 0/8] livepatch: Introduce replace set support Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 1/8] livepatch: Make klp_find_func() non static Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 2/8] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-08-25 12:06 ` sashiko-bot
2026-08-25 12:11 ` Yafang Shao
2026-08-27 23:57 ` Josh Poimboeuf
2026-08-28 2:24 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 3/8] livepatch: Implement replace set for scoped atomic replace Yafang Shao
2026-08-25 11:59 ` sashiko-bot
2026-08-25 12:10 ` Yafang Shao
2026-08-28 0:26 ` Josh Poimboeuf
2026-08-28 3:03 ` Yafang Shao
2026-08-28 3:39 ` Josh Poimboeuf
2026-08-28 5:42 ` Yafang Shao
2026-09-02 7:31 ` Replace rules: was: " Petr Mladek
2026-09-02 9:40 ` Yafang Shao
2026-09-02 11:50 ` Yafang Shao
2026-09-03 10:01 ` Petr Mladek
2026-09-06 2:58 ` Yafang Shao
2026-09-03 9:27 ` Petr Mladek [this message]
2026-09-03 21:18 ` Song Liu
2026-09-02 7:34 ` documentation: " Petr Mladek
2026-09-02 9:50 ` Yafang Shao
2026-09-03 7:30 ` Petr Mladek
2026-09-02 7:37 ` code cleanup: " Petr Mladek
2026-09-02 9:52 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 4/8] livepatch: Deprecate stack_order Yafang Shao
2026-08-28 0:29 ` Josh Poimboeuf
2026-08-28 3:14 ` Yafang Shao
2026-09-02 12:01 ` Petr Mladek
2026-09-02 12:20 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 5/8] selftests/livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-08-28 0:31 ` Josh Poimboeuf
2026-08-28 3:56 ` Yafang Shao
2026-09-02 13:45 ` Petr Mladek
2026-09-03 3:23 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 6/8] selftests/livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-09-02 15:15 ` Petr Mladek
2026-09-03 5:43 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 7/8] selftests/livepatch: Add test for state ID conflict across provides Yafang Shao
2026-09-02 15:25 ` Petr Mladek
2026-09-03 5:44 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 8/8] selftests/livepatch: Add test for function " Yafang Shao
2026-09-02 15:51 ` Petr Mladek
2026-09-03 5:48 ` Yafang Shao
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=apk9f_LsGRYHzN0Z@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=song@kernel.org \
/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