mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhang warden <zhangwarden@gmail.com>
To: Joe Lawrence <joe.lawrence@redhat.com>
Cc: Petr Mladek <pmladek@suse.com>,
	jpoimboe@kernel.org, mbenes@suse.cz, jikos@kernel.org,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] livepatch: Add KLP_IDLE state
Date: Sat, 6 Apr 2024 15:36:37 +0800	[thread overview]
Message-ID: <EF3BD11E-D4B9-4490-91FC-41066452D32B@gmail.com> (raw)
In-Reply-To: <4506bb59-5524-8b0e-f97c-a0252d4784ad@redhat.com>


Hi Joe and Petr :
> On Apr 5, 2024, at 01:50, Joe Lawrence <joe.lawrence@redhat.com> wrote:
> 
> On 4/4/24 11:17, Petr Mladek wrote:
>> On Tue 2024-04-02 09:52:31, Joe Lawrence wrote:
>>> On Tue, Apr 02, 2024 at 11:09:54AM +0800, zhangwarden@gmail.com wrote:
>>>> From: Wardenjohn <zhangwarden@gmail.com>
>>>> 
>>>> In livepatch, using KLP_UNDEFINED is seems to be confused.
>>>> When kernel is ready, livepatch is ready too, which state is
>>>> idle but not undefined. What's more, if one livepatch process
>>>> is finished, the klp state should be idle rather than undefined.
>>>> 
>>>> Therefore, using KLP_IDLE to replace KLP_UNDEFINED is much better
>>>> in reading and understanding.
>>>> ---
>>>> include/linux/livepatch.h     |  1 +
>>>> kernel/livepatch/patch.c      |  2 +-
>>>> kernel/livepatch/transition.c | 24 ++++++++++++------------
>>>> 3 files changed, 14 insertions(+), 13 deletions(-)
>>>> 
>>>> diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
>>>> index 9b9b38e89563..c1c53cd5b227 100644
>>>> --- a/include/linux/livepatch.h
>>>> +++ b/include/linux/livepatch.h
>>>> @@ -19,6 +19,7 @@
>>>> 
>>>> /* task patch states */
>>>> #define KLP_UNDEFINED -1
>>>> +#define KLP_IDLE       -1
>>> 
>>> Hi Wardenjohn,
>>> 
>>> Quick question, does this patch intend to:
>>> 
>>> - Completely replace KLP_UNDEFINED with KLP_IDLE
>>> - Introduce KLP_IDLE as an added, fourth potential state
>>> - Introduce KLP_IDLE as synonym of sorts for KLP_UNDEFINED under certain
>>>  conditions
>>> 
>>> I ask because this patch leaves KLP_UNDEFINED defined and used in other
>>> parts of the tree (ie, init/init_task.c), yet KLP_IDLE is added and
>>> continues to use the same -1 enumeration.
>> 
>> Having two names for the same state adds more harm than good.
>> 
>> Honestly, neither "task->patch_state == KLP_UNDEFINED" nor "KLP_IDLE"
>> make much sense.
>> 
>> The problem is in the variable name. It is not a state of a patch.
>> It is the state of the transition. The right solution would be
>> something like:
>> 
>>  klp_target_state -> klp_transition_target_state
>>  task->patch_state -> task->klp_transition_state
>>  KLP_UNKNOWN -> KLP_IDLE
>> 
> 
> Yes, this is exactly how I think of these when reading the code.  The
> model starts to make a lot more sense once you look at it thru this lens :)
> 

For Joe's questions:
1. I do want to replace KLP_UNDEFINED with KLP_IDLE for livepatch patch states are all known instead of undefined.
2. The reason why I tried to make “KLP_IDLE" state into the same value of “KLP_UNDEFINED" is to make it compatible to “KLP_UNDEFINE"

Since Petr said that this will break some userspace tools, maybe there may have a chance to fix it in the future? If you think it bring more harm than good.


>> But it would also require renaming:
>> 
>>  /proc/<pid>/patch_state -> klp_transition_state
>> 
>> which might break userspace tools => likely not acceptable.
>> 
>> 
>> My opinion:
>> 
>> It would be nice to clean this up but it does not look worth the
>> effort.
>> 

Maybe we can just fix the code state instead of renaming the proc interface?

> 
> Agreed.  Instead of changing code and the sysfs interface, we could
> still add comments like:
> 
>  /* task patch transition target states */
>  #define KLP_UNDEFINED   -1      /* idle, no transition in progress */
>  #define KLP_UNPATCHED    0      /* transitioning to unpatched state */
>  #define KLP_PATCHED      1      /* transitioning to patched state */
> 
>  /* klp transition target state */
>  static int klp_target_state = KLP_UNDEFINED;
> 
>  struct task_struct = {
>      .patch_state    = KLP_UNDEFINED,   /* klp transition state */
> 
> Maybe just one comment is enough?  Alternatively, we could elaborate in
> Documentation/livepatch/livepatch.rst if it's really confusing.
> 
> Wardenjohn, since you're probably reading this code with fresh(er) eyes,
> would any of the above be helpful?
> 
> -- 
> Joe

Adding comments will help to understand the code logic. If introducing “KLP_IDLE" is not suitable right now, I am still happy to add some comment into the code if you agree.

Best Regards,
Wardenjohn





  reply	other threads:[~2024-04-06  7:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02  3:09 zhangwarden
2024-04-02 13:52 ` Joe Lawrence
2024-04-04 15:17   ` Petr Mladek
2024-04-04 17:50     ` Joe Lawrence
2024-04-06  7:36       ` zhang warden [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-04-02  3:08 zhangwarden

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=EF3BD11E-D4B9-4490-91FC-41066452D32B@gmail.com \
    --to=zhangwarden@gmail.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=pmladek@suse.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

all inboxes | Powered by JetHome®