Re: [RFC PATCH v2 13/18] livepatch: separate enabled and patched states

Josh Poimboeuf
2016-05-03T13:49:03Z

On Tue, May 03, 2016 at 11:30:12AM +0200, Petr Mladek wrote:
> On Thu 2016-04-28 15:44:44, 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.
> >
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> > include/linux/livepatch.h | 17 ++++-------
> > kernel/livepatch/core.c | 72 +++++++++++++++++++++++------------------------
> > 2 files changed, 42 insertions(+), 47 deletions(-)
> >
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index 6ea6880..2b59230 100644
> > --- a/kernel/livepatch/core.c
> > +++ b/kernel/livepatch/core.c
> > @@ -622,20 +622,20 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr,
> > if (ret)
> > return -EINVAL;
> >
> > - if (val != KLP_DISABLED && val != KLP_ENABLED)
> > + if (val > 1)
> > return -EINVAL;
>
> It would be cleaner to get "val" via kstrtobool(). It guarantees that
> the value is true or false. Another nice win is that it accepts
> Y/y/1/N/n/0 as the input.
>
> > patch = container_of(kobj, struct klp_patch, kobj);
> >
> > mutex_lock(&klp_mutex);
> >
> > - if (val == patch->state) {
> > + if (patch->enabled == val) {
>
> Also this check will be cleaner if "val" is a boolean.

Good idea, thanks.

--
Josh