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: code cleanup: was: Re: [PATCH v7 for-next 3/8] livepatch: Implement replace set for scoped atomic replace
Date: Wed, 2 Sep 2026 09:37:20 +0200 [thread overview]
Message-ID: <apfSMN5a9PTxTTsW@pathway.suse.cz> (raw)
In-Reply-To: <20260825114641.80452-4-laoar.shao@gmail.com>
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/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -448,13 +449,32 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
> return count;
> }
>
> -static ssize_t replace_show(struct kobject *kobj,
> +static ssize_t provides_show(struct kobject *kobj,
> struct kobj_attribute *attr, char *buf)
> {
> struct klp_patch *patch;
>
> patch = container_of(kobj, struct klp_patch, kobj);
> - return sysfs_emit(buf, "%d\n", patch->replace);
> + return sysfs_emit(buf, "%u\n", patch->provides);
> +}
> +
> +static ssize_t obsoletes_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct klp_patch *patch;
> + unsigned int i;
> + int len = 0;
> +
> + patch = container_of(kobj, struct klp_patch, kobj);
> + if (!patch->obsoletes || !patch->nr_obsoletes)
> + return sysfs_emit(buf, "\n");
> +
> + for (i = 0; i < patch->nr_obsoletes; i++)
> + len += sysfs_emit_at(buf, len, "%u%s", patch->obsoletes[i],
> + i < patch->nr_obsoletes - 1 ? "," : "");
It would be easier if we swithed the oder of %u and %s:
len += sysfs_emit_at(buf, len, "%s%u", patch->obsoletes[i],
i == 0, "" : ",");
> +
> + len += sysfs_emit_at(buf, len, "\n");
> + return len;
> }
>
> static ssize_t stack_order_show(struct kobject *kobj,
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
> @@ -498,7 +498,7 @@ void klp_try_complete_transition(void)
> */
> if (!patch->enabled)
> klp_free_patch_async(patch);
> - else if (patch->replace)
> + else
> klp_free_replaced_patches_async(patch);
Nit: I would use this opportunity and invert the logic.
Positive checks are always easier to read.
I mean to use:
if (patch->enabled)
klp_free_replaced_patches_async(patch);
else
klp_free_patch_async(patch);
> }
>
Best Regards,
Petr
next prev parent reply other threads:[~2026-09-02 7:37 UTC|newest]
Thread overview: 53+ 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-09-08 14:24 ` Miroslav Benes
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-09-08 14:24 ` Miroslav Benes
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
2026-09-03 21:18 ` Song Liu
2026-09-06 8:34 ` Yafang Shao
2026-09-09 12:32 ` Miroslav Benes
2026-09-09 18:45 ` Song Liu
2026-09-10 8:31 ` Miroslav Benes
2026-09-10 9:17 ` Yafang Shao
2026-09-10 21:59 ` 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 ` Petr Mladek [this message]
2026-09-02 9:52 ` code cleanup: " 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=apfSMN5a9PTxTTsW@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.