From: Chris J Arges <chris.j.arges@canonical.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Jiri Kosina <jikos@kernel.org>, Jessica Yu <jeyu@redhat.com>,
Miroslav Benes <mbenes@suse.cz>,
linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
Vojtech Pavlik <vojtech@suse.com>
Subject: Re: [RFC PATCH v1.9 08/14] livepatch: separate enabled and patched states
Date: Tue, 12 Apr 2016 12:35:49 -0500 [thread overview]
Message-ID: <20160412173548.GA26049@canonical.com> (raw)
In-Reply-To: <20160412171600.eikmt75i4qapjj2g@treble>
On Tue, Apr 12, 2016 at 12:16:00PM -0500, Josh Poimboeuf wrote:
> On Tue, Apr 12, 2016 at 09:44:43AM -0500, Chris J Arges wrote:
> > On Fri, Mar 25, 2016 at 02:34:55PM -0500, Josh Poimboeuf wrote:
> > > Once we have a consistency model, patches and their objects will be
> > > enabled and disabled at different times. For example, when a patch is
> > > disabled, its loaded objects' funcs can remain registered with ftrace
> > > indefinitely until the unpatching operation is complete and they're no
> > > longer in use.
> > >
> > > It's less confusing if we give them different names: patches can be
> > > enabled or disabled; objects (and their funcs) can be patched or
> > > unpatched:
> > >
> > > - Enabled means that a patch is logically enabled (but not necessarily
> > > fully applied).
> > >
> > > - Patched means that an object's funcs are registered with ftrace and
> > > added to the klp_ops func stack.
> > >
> > > Also, since these states are binary, represent them with booleans
> > > instead of ints.
> > >
> >
> > Josh,
> >
> > Awesome work here first of all!
> >
> > Looking through the patchset a bit I see the following bools:
> > - functions: patched, transitioning
> > - objects: patched
> > - patches: enabled
> >
> > It seems this reflects the following states at a patch level:
> > disabled - module inserted, not yet logically enabled
> > enabled - logically enabled, but not all objects/functions patched
> > transitioning - objects/functions are being applied or reverted
> > patched - all objects/functions patched
> >
> > However each object and function could have the same state and the parent object
> > just reflects the 'aggregate state'. For example if all funcs in an object are
> > patched then the object is also patched.
> >
> > Perhaps we need more states (or maybe there will be more in the future), but
> > wouldn't this just be easier to have something like for each patch, object, and
> > function?
> >
> > enum klp_state{
> > KLP_DISABLED,
> > KLP_ENABLED,
> > KLP_TRANSITION,
> > KLP_PATCHED,
> > }
> >
> >
> > I'm happy to help out too.
>
> Thanks for the comments. First let me try to explain why I chose two
> bools rather than a single state variable.
>
> At a func level, it's always in one of the following states:
>
> patched=0 transition=0: unpatched
> patched=0 transition=1: unpatched, temporary starting state
> patched=1 transition=1: patched, may be visible to some tasks
> patched=1 transition=0: patched, visible to all tasks
>
> And for unpatching, it goes in the reverse order:
>
> patched=1 transition=0: patched, visible to all tasks
> patched=1 transition=1: patched, may be visible to some tasks
> patched=0 transition=1: unpatched, temporary ending state
> patched=0 transition=0: unpatched
>
> (note to self, put the above in a comment somewhere)
>
This is helpful and makes more sense.
> Now, we could convert the states from two bools into a single enum. But
> I think it would complicate the code. Because nowhere in the code does
> it need to access the full state. In some places it accesses
> func->patched and in other places it accesses func->transition, but it
> never needs to access both.
>
> So for example, the following check in klp_ftrace_handler():
>
> if (unlikely(func->transition)) {
>
> would change to:
>
> if (unlikely(func->state == KLP_ENABLED || func->state == KLP_TRANSITION)) {
>
> Sure, we could use a helper function to make that more readable. But
> with the bools its clearer and you don't need a helper function.
>
> As another example, see the following code in klp_complete_transition():
>
> klp_for_each_object(klp_transition_patch, obj)
> klp_for_each_func(obj, func)
> func->transition = false;
>
> The last line would have to be changed to something like:
>
> if (patching...)
> func->state = KLP_PATCHED;
> else /* unpatching */
> func->state = KLP_DISABLED;
>
> So that's why I picked two bools over a single state variable: it seems
> to make the code simpler.
>
> As to the other idea about copying the func states to the object and
> patch level, I get the feeling that would also complicate the code. We
> patch and transition at a function granularity, so the "real" state is
> at the func level. Proliferating that state to objects and patches
> might be tricky to get right, and it could make it harder to understand
> exactly what's going on in the code. And I don't really see a benefit
> to doing that.
>
> --
> Josh
>
I think keeping it simple makes a ton of sense, thanks for the explanation.
I'm also envisioning how to troubleshoot patches that don't converge.
So if someone wanted to check if a function has been fully patched on all tasks
they would check:
/sys/kernel/livepatch/<patch>/transition
/sys/kernel/livepatch/<patch>/patched
And see if patched=1 and transition=0 things are applied.
However if patched=1 and transition=1 then if a user wanted to dig down and see
which pid's we were waiting on we could do:
cat /proc/*/patch_status
and check if any pid's patch_status values still contain KLP_UNIVERSE_OLD.
If we wanted to see which function in the task needs patching we could:
cat /proc/<pid>/stack
and see if anything in that stack contains the functions in question.
Anyway I'll keep looking at this patchset, patching using the samples/livepatch
code works for me without issue so far.
--chris
next prev parent reply other threads:[~2016-04-12 17:36 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-25 19:34 [RFC PATCH v1.9 00/14] livepatch: hybrid consistency model Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 01/14] x86/asm/head: cleanup initial stack variable Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 02/14] x86/asm/head: use a common function for starting CPUs Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 03/14] x86/asm/head: standardize the bottom of the stack for idle tasks Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 04/14] x86: move _stext marker before head code Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 05/14] sched: horrible way to detect whether a task has been preempted Josh Poimboeuf
2016-04-06 13:06 ` Petr Mladek
2016-04-06 16:33 ` Josh Poimboeuf
2016-04-07 9:47 ` Petr Mladek
2016-04-07 14:34 ` Josh Poimboeuf
2016-04-08 8:07 ` Petr Mladek
2016-04-08 14:34 ` Josh Poimboeuf
2016-04-07 21:15 ` Jessica Yu
2016-04-07 21:37 ` Jiri Kosina
2016-04-07 22:35 ` Josh Poimboeuf
2016-04-07 22:53 ` Jiri Kosina
2016-04-07 23:15 ` Jessica Yu
2016-04-08 7:05 ` Jiri Kosina
2016-04-08 8:03 ` Petr Mladek
2016-04-08 14:31 ` Josh Poimboeuf
2016-04-11 8:38 ` Petr Mladek
2016-03-25 19:34 ` [RFC PATCH v1.9 06/14] x86: add error handling to dump_trace() Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 07/14] x86/stacktrace: add function for detecting reliable stack traces Josh Poimboeuf
2016-03-31 13:03 ` Miroslav Benes
2016-04-04 17:54 ` Josh Poimboeuf
2016-04-11 14:16 ` Jiri Slaby
2016-04-12 15:56 ` Josh Poimboeuf
2016-06-09 8:31 ` Jiri Slaby
2016-06-13 21:58 ` Josh Poimboeuf
2016-12-01 20:28 ` Jiri Slaby
2016-12-01 20:59 ` Josh Poimboeuf
2017-01-17 13:08 ` Jiri Slaby
2016-04-04 15:55 ` Petr Mladek
2016-04-04 17:58 ` Josh Poimboeuf
2016-04-07 11:55 ` Petr Mladek
2016-04-07 14:46 ` Josh Poimboeuf
2016-04-08 8:24 ` Petr Mladek
2016-04-11 3:29 ` Jessica Yu
2016-03-25 19:34 ` [RFC PATCH v1.9 08/14] livepatch: separate enabled and patched states Josh Poimboeuf
2016-04-11 3:31 ` Jessica Yu
2016-04-12 14:44 ` [RFC PATCH v1.9 08/14] " Chris J Arges
2016-04-12 17:16 ` Josh Poimboeuf
2016-04-12 17:35 ` Chris J Arges [this message]
2016-04-12 18:25 ` Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 09/14] livepatch: remove unnecessary object loaded check Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 10/14] livepatch: move patching functions into patch.c Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 11/14] livepatch: store function sizes Josh Poimboeuf
2016-03-25 19:34 ` [RFC PATCH v1.9 12/14] livepatch: create per-task consistency model Josh Poimboeuf
2016-03-31 13:12 ` Miroslav Benes
2016-04-04 18:21 ` Josh Poimboeuf
2016-04-04 18:27 ` Vojtech Pavlik
2016-04-04 18:33 ` Josh Poimboeuf
2016-04-05 11:36 ` Vojtech Pavlik
2016-04-05 13:53 ` Josh Poimboeuf
2016-04-05 17:32 ` Minfei Huang
2016-04-05 21:17 ` Josh Poimboeuf
2016-04-14 9:25 ` Miroslav Benes
2016-04-14 16:39 ` Josh Poimboeuf
2016-04-15 9:17 ` Miroslav Benes
2016-03-25 19:35 ` [RFC PATCH v1.9 13/14] livepatch: add /proc/<pid>/patch_status Josh Poimboeuf
2016-03-31 9:33 ` Jiri Slaby
2016-03-31 9:40 ` Jiri Slaby
2016-04-04 16:56 ` Josh Poimboeuf
2016-03-25 19:35 ` [RFC PATCH v1.9 14/14] livepatch: update task universe when exiting kernel Josh Poimboeuf
2016-04-14 8:47 ` Miroslav Benes
2016-04-14 8:50 ` Miroslav Benes
2016-04-14 13:39 ` Josh Poimboeuf
2016-04-18 15:01 ` [RFC PATCH 0/2] s390/klp: s390 support Miroslav Benes
2016-04-18 15:01 ` [RFC PATCH 1/2] s390: livepatch, reorganize TIF bits Miroslav Benes
2016-04-18 15:01 ` [RFC PATCH 2/2] s390/klp: update task universe when exiting kernel Miroslav Benes
2016-04-18 15:17 ` [RFC PATCH 0/2] s390/klp: s390 support Josh Poimboeuf
2016-04-14 13:23 ` [RFC PATCH v1.9 14/14] livepatch: update task universe when exiting kernel Josh Poimboeuf
2016-03-31 12:54 ` [RFC PATCH v1.9 00/14] livepatch: hybrid consistency model Miroslav Benes
2016-04-04 17:03 ` Josh Poimboeuf
2016-04-05 14:24 ` Miroslav Benes
2016-04-05 14:34 ` Josh Poimboeuf
2016-04-05 14:53 ` Miroslav Benes
2016-04-01 13:34 ` Miroslav Benes
2016-04-01 13:39 ` Petr Mladek
2016-04-01 15:38 ` Petr Mladek
2016-04-05 13:44 ` Josh Poimboeuf
2016-04-06 8:15 ` Petr Mladek
2016-04-28 18:53 ` Josh Poimboeuf
2016-06-09 14:20 ` Petr Mladek
2016-04-07 12:10 ` Petr Mladek
2016-04-07 15:08 ` Josh Poimboeuf
2016-04-07 15:47 ` Jiri Kosina
2016-04-07 18:03 ` Josh Poimboeuf
2016-04-07 18:33 ` Jiri Kosina
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=20160412173548.GA26049@canonical.com \
--to=chris.j.arges@canonical.com \
--cc=jeyu@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=vojtech@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
Powered by JetHome