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: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Date: Thu, 11 Jun 2026 14:58:39 +0200 [thread overview]
Message-ID: <aiqw_74v-1_2D9rJ@pathway.suse.cz> (raw)
In-Reply-To: <aig4smgme6DR8pfs@pathway.suse.cz>
On Tue 2026-06-09 18:00:55, Petr Mladek wrote:
> On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
> I would write something like:
>
> <proposal>
> The practice shows that the current semantic of the patch.replace flag is
> not ideal.
>
> The atomic replace is disabled by default. And the no-replace mode allows
> wild installation of many livepatches in parallel. The author and
> administrator are fully responsible for preventing problems caused
> by producing and installing incompatible livepatches.
>
> The most safe atomic replace mode must be explicitly enabled by
> setting "patch.replace = true". It is all or nothing. The livepatch
> with enabled .replace will always replace all already installed
> livepatches. It makes it very safe but it might be too harsh.
>
> Improve the situation by switching "bool .replace" flag to
> "u32 .replace_set" and and updating its semantic.
>
> Any .replace_set value might be associated with a set of livepatched
> symbols, callbacks, shadow variable and state IDs.
>
> A livepatch with a particular .replace_set number will atomically
> rreplace any already installed livepatch with the same .replace_set
> number. By definition, there can only ever be one active livepatch
> for a given replace_set number.
>
> On the contrary, livepatches with a different .replace_set number
> must not modify the same function, or use the state with the same
> ID [*]. Any attempt to load an incompatible livepatch will be
> rejected.
>
> Summary:
>
> The most safe mode when any livepatch replaces any other livepatch
> will be the default. Note that all livepatches must keep
> .replace_set = 0.
>
> It will be possible to install more livepatches in parallel by
> using different .replace_set numbers. The livepatches might be
> updated independently using the atomic replace feature as long
> as the new version does not break compatibility. The kernel will
> reject a livepatch from a different replace set when it would
> want to modify the same function or livepatch state from
> another replace set.
>
> [*] The compatibility check of callbacks and shadow variables will
> be improved later by reworking their semantic. There is a work
> in progress, see [0]
> </proposal>
>
> > Link: https://github.com/pmladek/linux/tree/klp-state-transfer-v1-iter12 [0]
>
> I have realized that I actually sent "v1-iter12" to the public
> mailing list as the official v1. So we could use:
>
> Link: https://lore.kernel.org/all/20250115082431.5550-1-pmladek@suse.com/ [0]
>
>
> New idea:
>
> I have briefly discussed the new semantic with Miroslav when I met
> him in person. And he was a bit concerned. We as an OS distributor
> might want to be sure that our livepatches can be installed the most
> safe way. So, we still might want to preserve the "replace all"
> semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve
the replace_all functionality.
There were recently reported few serious 0-day vulnerabilities.
We discussed a possibility to ship a quick fix with a livepatch.
Or that customers might want to fix it themself by a livepatch.
Such a livepatch would need to be installed in parallel to
the official livepatch fixing older bugs. But the next official
cumulative livepatch would need to replace it.
The above scenario will not longer work with the current
"replace_set" handling. The hotfix would need to use another
"replace_set" so that it can be installed in parallel.
But the next cumulative livepatch won't be able to replace
it because it would need to modify the same function.
I consulted this with AI (claude-sonet-4.6) and it gave the following
feedback/ideas ;-)
> I though about 4 approaches approaches:
>
> 1. Make .replace_set=0 special so that it will always replace
> everything. Similar to the current .replace=true mode.
>
> Customers will still be able to install custom livepatches
> later with .replace_set != 0. But the "0" livepatch will
> always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
> 2. Use two flags in the livepatch, for example
>
> a. Rename .replace to .replace_all. The livepatch with this
> flag set will always wipe all other livepatches.
>
> b. Add .replace_set which will allow to install more livepatches
> in parallel, replace the livepatches with the same .replace_set
> atomically, and check the compatibility. As described above.
>
> It is a bit more complicated. But it is more compatible with
> the current state. And it removes the special meaning of
> .replace_set == 0.
This looks more straightforward. But the fact that "replace_all"
replaces everything brings back the problem with the original
"replace" flag. So, it makes this whole exercise more or less
pointless.
I had another idea with storing list of fixed bugs/CVEs in each
livepatch. Independent fixes might be fixed by independent
livepatches. Then a cumulative livepatch would replace only
the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct klp_patch {
[...]
unsigned int replace_set;
const unsigned int *supersedes; /* Zero terminated array of replace_set IDs */
[...]
}
So that the cumulative livepatch might optionally define
another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix
are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module
option to the cumulative livepatch, .e.g supersedes=id[,id]*
We could add some support into the kernel for handling the module
parameter a standard way.
It is not trivial. But it is also not horribly complex.
It looks like a good compromise between the requirements and
code complexity.
We really need input from others here.
Best Regards,
Petr
next prev parent reply other threads:[~2026-06-11 12:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 13:16 [PATCH v3 0/7] livepatch: Introduce replace set support Yafang Shao
2026-06-07 13:16 ` [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func() Yafang Shao
2026-06-09 13:27 ` Petr Mladek
2026-06-10 3:00 ` Yafang Shao
2026-06-07 13:16 ` [PATCH v3 2/7] livepatch: Move klp_find_func() into core.h Yafang Shao
2026-06-09 15:28 ` Petr Mladek
2026-06-10 3:01 ` Yafang Shao
2026-06-07 13:16 ` [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set Yafang Shao
2026-06-07 13:33 ` sashiko-bot
2026-06-07 14:00 ` Yafang Shao
2026-06-09 16:00 ` Petr Mladek
2026-06-10 3:24 ` Yafang Shao
2026-06-10 9:48 ` Petr Mladek
2026-06-11 12:58 ` Petr Mladek [this message]
2026-06-10 14:45 ` code review: was: " Petr Mladek
2026-06-11 3:06 ` Yafang Shao
2026-06-07 13:16 ` [PATCH v3 4/7] livepatch: Deprecate stack_order Yafang Shao
2026-06-07 13:31 ` sashiko-bot
2026-06-10 15:11 ` Petr Mladek
2026-06-11 3:21 ` Yafang Shao
2026-06-07 13:16 ` [PATCH v3 5/7] selftests/livepatch: Update tests for replace_set Yafang Shao
2026-06-07 13:29 ` sashiko-bot
2026-06-07 13:16 ` [PATCH v3 6/7] selftests/livepatch: Add test for state ID conflict across replace_sets Yafang Shao
2026-06-12 8:55 ` Petr Mladek
2026-06-07 13:16 ` [PATCH v3 7/7] selftests/livepatch: Add test for function " 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=aiqw_74v-1_2D9rJ@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