linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Miroslav Benes <mbenes@suse.cz>
Cc: Jessica Yu <jeyu@redhat.com>, Jiri Kosina <jikos@kernel.org>,
	Petr Mladek <pmladek@suse.com>,
	linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
	Michael Ellerman <mpe@ellerman.id.au>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	x86@kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-s390@vger.kernel.org, Vojtech Pavlik <vojtech@suse.com>,
	Jiri Slaby <jslaby@suse.cz>,
	Chris J Arges <chris.j.arges@canonical.com>,
	Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>,
	Balbir Singh <bsingharora@gmail.com>
Subject: Re: [PATCH v5 13/15] livepatch: change to a per-task consistency model
Date: Tue, 21 Feb 2017 15:21:10 -0600	[thread overview]
Message-ID: <20170221212110.y2pstgeluwrmxjie@treble> (raw)
In-Reply-To: <alpine.LSU.2.20.1702170940420.4107@pobox.suse.cz>

On Fri, Feb 17, 2017 at 09:51:29AM +0100, Miroslav Benes wrote:
> On Thu, 16 Feb 2017, Josh Poimboeuf wrote:
> > What do you think about the following?  I tried to put the logic in
> > klp_complete_transition(), so the module_put()'s would be in one place.
> > But it was too messy, so I put it in klp_cancel_transition() instead.
> >
> > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> > index e96346e..bd1c1fd 100644
> > --- a/kernel/livepatch/transition.c
> > +++ b/kernel/livepatch/transition.c
> > @@ -121,8 +121,28 @@ static void klp_complete_transition(void)
> >   */
> >  void klp_cancel_transition(void)
> >  {
> > +	bool immediate_func = false;
> > +
> >  	klp_target_state = !klp_target_state;
> >  	klp_complete_transition();
> > +
> > +	if (klp_target_state == KLP_PATCHED)
> > +		return;
> 
> This is not needed, I think. We call klp_cancel_transition() in 
> __klp_enable_patch() only. klp_target_state is set to KLP_PATCHED there 
> (through klp_init_transition()) and negated here. We know it must be 
> KLP_UNPATCHED.

Yeah, I was trying to hedge against the possibility of future code
calling this function in the disable path.  But that probably won't
happen and it would probably be cleaner to just add a warning if
klp_target_state isn't KLP_PATCHED.

> Moreover, due to klp_complete_transition() klp_target_state is always 
> KLP_UNDEFINED after it.
> 
> > +
> > +	/*
> > +	 * In the enable error path, even immediate patches can be safely
> > +	 * removed because the transition hasn't been started yet.
> > +	 *
> > +	 * klp_complete_transition() doesn't have a module_put() for immediate
> > +	 * patches, so do it here.
> > +	 */
> > +	klp_for_each_object(klp_transition_patch, obj)
> > +		klp_for_each_func(obj, func)
> > +			if (func->immediate)
> > +				immediate_func = true;
> > +
> > +	if (klp_transition_patch->immediate || immediate_func)
> > +		module_put(klp_transition_patch->mod);
> 
> Almost correct. The only problem is that klp_transition_patch is NULL at 
> this point. klp_complete_transition() does that and it should stay there 
> in my opinion to keep it simple.
> 
> So we could either move all this to __klp_enable_patch(), where patch 
> variable is defined, or we could store klp_transition_patch to a local 
> variable here in klp_cancel_transition() before klp_complete_transition() 
> is called. That should be safe. I like the latter more, because it keeps 
> the code in klp_cancel_transition() where it belongs.

Good points.  Here's another try:

diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index e96346e..a23c63c 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -121,8 +121,31 @@ static void klp_complete_transition(void)
  */
 void klp_cancel_transition(void)
 {
-	klp_target_state = !klp_target_state;
+	struct klp_patch *patch = klp_transition_patch;
+	struct klp_object *obj;
+	struct klp_func *func;
+	bool immediate_func = false;
+
+	if (WARN_ON_ONCE(klp_target_state != KLP_PATCHED))
+		return;
+
+	klp_target_state = KLP_UNPATCHED;
 	klp_complete_transition();
+
+	/*
+	 * In the enable error path, even immediate patches can be safely
+	 * removed because the transition hasn't been started yet.
+	 *
+	 * klp_complete_transition() doesn't have a module_put() for immediate
+	 * patches, so do it here.
+	 */
+	klp_for_each_object(patch, obj)
+		klp_for_each_func(obj, func)
+			if (func->immediate)
+				immediate_func = true;
+
+	if (patch->immediate || immediate_func)
+		module_put(patch->mod);
 }
 
 /*

  reply	other threads:[~2017-02-21 21:21 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14  1:42 [PATCH v5 00/15] livepatch: hybrid consistency model Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 01/15] stacktrace/x86: add function for detecting reliable stack traces Josh Poimboeuf
2017-02-15 12:18   ` Miroslav Benes
2017-02-15 14:40     ` Josh Poimboeuf
2017-03-07  6:50   ` Balbir Singh
2017-03-07 16:12     ` Josh Poimboeuf
2017-03-08  9:47       ` Balbir Singh
2017-04-10 15:40   ` Petr Mladek
2017-02-14  1:42 ` [PATCH v5 02/15] x86/entry: define _TIF_ALLWORK_MASK flags explicitly Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 03/15] livepatch: create temporary klp_update_patch_state() stub Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 04/15] livepatch/x86: add TIF_PATCH_PENDING thread flag Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 05/15] livepatch/powerpc: " Josh Poimboeuf
2017-03-07  6:46   ` Balbir Singh
2017-03-08  4:02   ` Michael Ellerman
2017-02-14  1:42 ` [PATCH v5 06/15] livepatch/s390: reorganize TIF thread flag bits Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 07/15] livepatch/s390: add TIF_PATCH_PENDING thread flag Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 08/15] livepatch: separate enabled and patched states Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 09/15] livepatch: remove unnecessary object loaded check Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 10/15] livepatch: move patching functions into patch.c Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 11/15] livepatch: use kstrtobool() in enabled_store() Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 12/15] livepatch: store function sizes Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 13/15] livepatch: change to a per-task consistency model Josh Poimboeuf
2017-02-16 14:33   ` Miroslav Benes
2017-02-16 20:31     ` Josh Poimboeuf
2017-02-17  8:51       ` Miroslav Benes
2017-02-21 21:21         ` Josh Poimboeuf [this message]
2017-02-22  9:03           ` Miroslav Benes
2017-03-07 14:16   ` Miroslav Benes
2017-04-11 12:35   ` Petr Mladek
2018-01-25  9:04   ` Peter Zijlstra
2018-01-25 10:24     ` Petr Mladek
2018-01-25 10:38       ` Peter Zijlstra
2018-01-25 12:13         ` Petr Mladek
2018-01-25 12:44           ` Peter Zijlstra
2017-02-14  1:42 ` [PATCH v5 14/15] livepatch: add /proc/<pid>/patch_state Josh Poimboeuf
2017-02-14  1:42 ` [PATCH v5 15/15] livepatch: allow removal of a disabled patch Josh Poimboeuf
2017-03-06 17:20   ` [PATCH v5.1 " Josh Poimboeuf
2017-03-07 14:50     ` Miroslav Benes
2017-02-17  8:55 ` [PATCH v5 00/15] livepatch: hybrid consistency model Miroslav Benes
2017-03-07  8:53 ` Ingo Molnar
2017-03-08  9:06 ` 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=20170221212110.y2pstgeluwrmxjie@treble \
    --to=jpoimboe@redhat.com \
    --cc=bsingharora@gmail.com \
    --cc=chris.j.arges@canonical.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=jeyu@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jslaby@suse.cz \
    --cc=kamalesh@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=live-patching@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mingo@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=vojtech@suse.com \
    --cc=x86@kernel.org \
    /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).