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: [RFC PATCH 6/6] livepatch: Support replace_set in shadow variable API
Date: Tue, 26 May 2026 15:04:47 +0200 [thread overview]
Message-ID: <ahWaby45THrzbwDK@pathway.suse.cz> (raw)
In-Reply-To: <20260513143321.26185-7-laoar.shao@gmail.com>
On Wed 2026-05-13 22:33:21, Yafang Shao wrote:
> To support more complex livepatching scenarios where multiple
> replacement sets might coexist, extend the klp_shadow API to
> include a 'replace_set' identifier.
>
> To maintain compatibility with the existing 64-bit storage in
> 'struct klp_shadow', the internal @id is now treated as a composite
> value. The 64-bit identifier is constructed by packing two 32-bit
> values:
>
> MSB (63-32) LSB (31-0)
> +--------------------+--------------------+
> | replace_set | original @id |
> +--------------------+--------------------+
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
> include/linux/livepatch.h | 12 ++++---
> kernel/livepatch/shadow.c | 70 ++++++++++++++++++++++++---------------
> kernel/livepatch/state.c | 3 +-
> 3 files changed, 52 insertions(+), 33 deletions(-)
>
> diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
> index 221f176f1f51..2dd9fca8c01c 100644
> --- a/include/linux/livepatch.h
> +++ b/include/linux/livepatch.h
> @@ -195,15 +195,17 @@ static inline bool klp_have_reliable_stack(void)
> IS_ENABLED(CONFIG_HAVE_RELIABLE_STACKTRACE);
> }
>
> -void *klp_shadow_get(void *obj, unsigned long id);
> -void *klp_shadow_alloc(void *obj, unsigned long id,
> +void *klp_shadow_get(void *obj, unsigned int replace_set, unsigned int id);
> +void *klp_shadow_alloc(void *obj, unsigned int replace_set, unsigned int id,
> size_t size, gfp_t gfp_flags,
> klp_shadow_ctor_t ctor, void *ctor_data);
> -void *klp_shadow_get_or_alloc(void *obj, unsigned long id,
> +void *klp_shadow_get_or_alloc(void *obj, unsigned int replace_set, unsigned int id,
> size_t size, gfp_t gfp_flags,
> klp_shadow_ctor_t ctor, void *ctor_data);
> -void klp_shadow_free(void *obj, unsigned long id, klp_shadow_dtor_t dtor);
> -void klp_shadow_free_all(unsigned long id, klp_shadow_dtor_t dtor);
> +void klp_shadow_free(void *obj, unsigned int replace_set, unsigned int id,
> + klp_shadow_dtor_t dtor);
> +void klp_shadow_free_all(unsigned int replace_set, unsigned int id,
> + klp_shadow_dtor_t dtor);
>
> struct klp_state *klp_get_state(struct klp_patch *patch, unsigned long id);
> struct klp_state *klp_get_prev_state(unsigned long id);
> diff --git a/kernel/livepatch/shadow.c b/kernel/livepatch/shadow.c
> index c2e724d97ddf..35e507fae445 100644
> --- a/kernel/livepatch/shadow.c
> +++ b/kernel/livepatch/shadow.c
> @@ -48,7 +48,8 @@ static DEFINE_SPINLOCK(klp_shadow_lock);
> * @node: klp_shadow_hash hash table node
> * @rcu_head: RCU is used to safely free this structure
> * @obj: pointer to parent object
> - * @id: data identifier
> + * @id: combined data identifier
> + * higher 32 bits: replace_set, lower 32 bits: resource ID
I am not sure if this is worth the complexity.
The 2nd patch allows to associate klp state ID with klp shadow ID.
People should really use it because it helps to maintain the lifetime
of shadow variables and makes it safe.
Then we could refuse loading livepatches with a shadow/state ID when
it is already being used by another livepatch with another "replace_set".
> * @data: data area
> */
> struct klp_shadow {
Best Regards,
Petr
next prev parent reply other threads:[~2026-05-26 13:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 14:33 [RFC PATCH 0/6] livepatch: Introduce replace set support Yafang Shao
2026-05-13 14:33 ` [RFC PATCH 1/6] livepatch: Support scoped atomic replace using replace set Yafang Shao
2026-05-14 20:54 ` sashiko-bot
2026-05-17 13:32 ` Yafang Shao
2026-05-18 21:25 ` Song Liu
2026-05-26 10:35 ` Petr Mladek
2026-05-26 18:27 ` Song Liu
2026-05-27 2:17 ` Yafang Shao
2026-05-26 12:52 ` Petr Mladek
2026-05-27 2:37 ` Yafang Shao
2026-05-13 14:33 ` [RFC PATCH 2/6] livepatch: Add callbacks for introducing and removing states Yafang Shao
2026-05-13 14:33 ` [RFC PATCH 3/6] livepatch: Allow to handle lifetime of shadow variables using the livepatch state Yafang Shao
2026-05-14 22:07 ` sashiko-bot
2026-05-18 3:24 ` [PATCH] " Yafang Shao
2026-05-13 14:33 ` [RFC PATCH 4/6] livepatch: Remove "data" from struct klp_state Yafang Shao
2026-05-14 22:22 ` sashiko-bot
2026-05-13 14:33 ` [RFC PATCH 5/6] livepatch: Remove obsolete per-object callbacks Yafang Shao
2026-05-14 22:40 ` sashiko-bot
2026-05-19 6:46 ` Yafang Shao
2026-05-13 14:33 ` [RFC PATCH 6/6] livepatch: Support replace_set in shadow variable API Yafang Shao
2026-05-14 23:01 ` sashiko-bot
2026-05-19 6:56 ` Yafang Shao
2026-05-26 13:04 ` Petr Mladek [this message]
2026-05-26 13:13 ` [RFC PATCH 0/6] livepatch: Introduce replace set support Petr Mladek
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=ahWaby45THrzbwDK@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