From: Miroslav Benes <mbenes@suse.cz>
To: Jason Baron <jbaron@akamai.com>
Cc: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org,
pmladek@suse.com, lpechacek@suse.cz, pavel@ucw.cz,
live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4.1 2/2] livepatch: force transition to finish
Date: Mon, 18 Dec 2017 14:23:40 +0100 (CET) [thread overview]
Message-ID: <alpine.LSU.2.21.1712181418560.15020@pobox.suse.cz> (raw)
In-Reply-To: <70454f58-3d33-f305-e1df-5f9dc43222c7@akamai.com>
On Fri, 15 Dec 2017, Jason Baron wrote:
> On 11/22/2017 05:29 AM, Miroslav Benes wrote:
> > If a task sleeps in a set of patched functions uninterruptedly, it could
> > block the whole transition indefinitely. Thus it may be useful to clear
> > its TIF_PATCH_PENDING to allow the process to finish.
> >
> > Admin can do that now by writing to force sysfs attribute in livepatch
> > sysfs directory. TIF_PATCH_PENDING is then cleared for all tasks and the
> > transition can finish successfully.
> >
> > Important note! Administrator should not use this feature without a
> > clearance from a patch distributor. It must be checked that by doing so
> > the consistency model guarantees are not violated. Removal (rmmod) of
> > patch modules is permanently disabled when the feature is used. It
> > cannot be guaranteed there is no task sleeping in such module.
> >
> > Signed-off-by: Miroslav Benes <mbenes@suse.cz>
> > Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > Reviewed-by: Petr Mladek <pmladek@suse.com>
> > ---
> > Documentation/ABI/testing/sysfs-kernel-livepatch | 14 ++++++++++
> > Documentation/livepatch/livepatch.txt | 18 ++++++++++--
> > kernel/livepatch/core.c | 30 ++++++++++++++++++++
> > kernel/livepatch/transition.c | 35 +++++++++++++++++++++++-
> > kernel/livepatch/transition.h | 1 +
> > 5 files changed, 95 insertions(+), 3 deletions(-)
>
> ....
>
> > +
> > +/*
> > + * Drop TIF_PATCH_PENDING of all tasks on admin's request. This forces an
> > + * existing transition to finish.
> > + *
> > + * NOTE: klp_update_patch_state(task) requires the task to be inactive or
> > + * 'current'. This is not the case here and the consistency model could be
> > + * broken. Administrator, who is the only one to execute the
> > + * klp_force_transitions(), has to be aware of this.
> > + */
> > +void klp_force_transition(void)
> > +{
> > + struct task_struct *g, *task;
> > + unsigned int cpu;
> > +
> > + pr_warn("forcing remaining tasks to the patched state\n");
> > +
> > + read_lock(&tasklist_lock);
> > + for_each_process_thread(g, task)
> > + klp_update_patch_state(task);
> > + read_unlock(&tasklist_lock);
> > +
> > + for_each_possible_cpu(cpu)
> > + klp_update_patch_state(idle_task(cpu));
> > +
> > + klp_forced = true;
> > +}
>
> I had a question on this bit. If say cpu 0 executes
> klp_force_transition(void), right up until klp_forced is set to true,
> and then cpu 1 does klp_complete_transition() (since all threads have
> the correct state), wouldn't it be possible then for
> klp_complete_transition() to not see klp_forced set to true, and thus
> the module could be potentially removed even though it was forced?
Yes, you're right. That could happen.
> If so, I think that the force path just needs to be set before the
> threads are updated (as below). I don't think that the
> klp_complete_transition() needs the corresponding rmb, b/c there is
> sufficient ordering there already (although it would deserve a comment).
Or we can take klp_mutex in force_store() (kernel/livepatch/core.c) and be
done with it once and for all. The problem is exactly what Petr predicted
and I refused to have klp_mutex here just because it may have fixed
theoretical issue.
Petr, Josh, what do you think?
Miroslav
> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index be5bfa5..cca6a3a 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
> @@ -671,6 +671,15 @@ void klp_force_transition(void)
>
> pr_warn("forcing remaining tasks to the patched state\n");
>
> + klp_forced = true;
> +
> + /*
> + * ensure that if klp_complete_transition() sees that all
> + * the threads have been updated to desired task->patch_state
> + * that we also see klp_forced = true;
> + */
> + smp_wmb();
> +
> read_lock(&tasklist_lock);
> for_each_process_thread(g, task)
> klp_update_patch_state(task);
> @@ -678,6 +687,4 @@ void klp_force_transition(void)
>
> for_each_possible_cpu(cpu)
> klp_update_patch_state(idle_task(cpu));
> -
> - klp_forced = true;
> }
>
next prev parent reply other threads:[~2017-12-18 13:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 13:50 [PATCH v4 0/2] livepatch: Introduce signal and force sysfs attributes Miroslav Benes
2017-11-15 13:50 ` [PATCH v4 1/2] livepatch: send a fake signal to all blocking tasks Miroslav Benes
2017-11-30 21:53 ` Jiri Kosina
2017-12-01 10:13 ` Michael Ellerman
2017-11-15 13:50 ` [PATCH v4 2/2] livepatch: force transition to finish Miroslav Benes
2017-11-20 15:57 ` Miroslav Benes
2017-11-20 23:02 ` Josh Poimboeuf
2017-11-20 23:09 ` Jiri Kosina
2017-11-20 23:11 ` Jiri Kosina
2017-11-20 23:14 ` Josh Poimboeuf
2017-11-22 10:29 ` [PATCH v4.1 " Miroslav Benes
2017-12-15 18:04 ` Jason Baron
2017-12-18 13:23 ` Miroslav Benes [this message]
2017-12-18 19:30 ` Josh Poimboeuf
2017-12-19 13:27 ` Petr Mladek
2017-11-20 23:14 ` [PATCH v4 " Pavel Machek
2017-11-20 23:17 ` Jiri Kosina
2017-11-21 10:04 ` Petr Mladek
2017-11-16 1:16 ` [PATCH v4 0/2] livepatch: Introduce signal and force sysfs attributes Josh Poimboeuf
2017-12-04 21:37 ` Jiri Kosina
2017-12-07 12:23 ` 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=alpine.LSU.2.21.1712181418560.15020@pobox.suse.cz \
--to=mbenes@suse.cz \
--cc=jbaron@akamai.com \
--cc=jeyu@kernel.org \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=lpechacek@suse.cz \
--cc=pavel@ucw.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®