From: Petr Mladek <pmladek@suse.com>
To: zhang warden <zhangwarden@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Jiri Kosina <jikos@kernel.org>,
Joe Lawrence <joe.lawrence@redhat.com>,
live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] livepatch: Add using attribute to klp_func for using function show
Date: Thu, 15 Aug 2024 11:20:37 +0200 [thread overview]
Message-ID: <Zr3IZTGnY-e-SHPy@pathway.suse.cz> (raw)
In-Reply-To: <0BFE862C-BD2B-43D1-B926-11A48BBC8C1B@gmail.com>
On Wed 2024-08-14 22:23:21, zhang warden wrote:
>
>
> > On Aug 14, 2024, at 00:05, Petr Mladek <pmladek@suse.com> wrote:
> >
> > Alternative solution would be to store the pointer of struct klp_ops
> > *ops into struct klp_func. Then using_show() could just check if
> > the related struct klp_func in on top of the stack.
> >
> > It would allow to remove the global list klp_ops and all the related
> > code. klp_find_ops() would instead do:
> >
> > for_each_patch
> > for_each_object
> > for_each_func
> >
> > The search would need more code. But it would be simple and
> > straightforward. We do this many times all over the code.
> >
> > IMHO, it would actually remove some complexity and be a win-win solution.
>
> Hi Peter!
>
> With your suggestions, it seems that you suggest move the klp_ops pinter into struct klp_func.
>
> I may do this operation:
>
> struct klp_func {
>
> /* internal */
> void *old_func;
> struct kobject kobj;
> struct list_head node;
> struct list_head stack_node;
> + struct klp_ops *ops;
> unsigned long old_size, new_size;
> bool nop;
> bool patched;
> bool transition;
> };
Yes.
> With this operation, klp_ops global list will no longer needed. And if we want the ftrace_ops of a function, we just need to get the ops member of klp_func eg, func->ops.
>
> And klp_find_ops() will be replaced by `ops = func->ops`, which is more easy.
func->ops will work only when it is already assigned, for example, in
+ klp_check_stack_func()
+ klp_unpatch_func()
+ using_show() /* the new sysfs callback */
But we will still need klp_find_ops() in klp_patch_func() to find
whether an already registered livepatch has already attached
the ftrace handled for the same function (func->old_func).
The new version would need to go through all registred patches,
something like:
struct klp_ops *klp_find_ops(void *old_func)
{
struct klp_patch *patch;
struct klp_object *obj;
struct klp_func *func;
klp_for_each_patch(patch) {
klp_for_each_object(patch, obj) {
klp_for_each_func(obj, func) {
/*
* Ignore entry where func->ops has not been
* assigned yet. It is most likely the one
* which is about to be created/added.
*/
if (func->old_func == old_func && func->ops)
return func->ops
}
}
}
return NULL;
}
BTW: It really looks useful. klp_check_stack_func() is called for_each_func()
also during task transition, even from the scheduler:
+ klp_cond_resched()
+ __klp_sched_try_switch()
+ klp_try_switch_task()
+ klp_check_and_switch_task()
+ klp_check_stack()
+ klp_for_each_object()
+ klp_for_each_func()
+ klp_find_ops()
It would newly just use func->ops. It might be even noticeable
speedup.
Please, implement this in a separate patch:
+ 1st patch adds func->ops
+ 2nd patch adds "using" sysfs interface.
Best Regards,
Petr
prev parent reply other threads:[~2024-08-15 9:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 6:46 [PATCH v2 0/1] livepatch: Add using attribute to klp_func for using function zhangyongde.zyd
2024-08-05 6:46 ` [PATCH v2 1/1] livepatch: Add using attribute to klp_func for using function show zhangyongde.zyd
2024-08-06 15:21 ` zhang warden
2024-08-13 3:53 ` zhang warden
2024-08-13 16:05 ` Petr Mladek
2024-08-14 2:32 ` zhang warden
2024-08-14 14:23 ` zhang warden
2024-08-15 9:20 ` Petr Mladek [this message]
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=Zr3IZTGnY-e-SHPy@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=zhangwarden@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).