From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Miroslav Benes <mbenes@suse.cz>
Cc: Seth Jennings <sjenning@redhat.com>,
Jiri Kosina <jkosina@suse.cz>, Vojtech Pavlik <vojtech@suse.cz>,
Steven Rostedt <rostedt@goodmis.org>,
Petr Mladek <pmladek@suse.cz>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Jiri Slaby <jslaby@suse.cz>,
Christoph Hellwig <hch@infradead.org>,
Greg KH <gregkh@linuxfoundation.org>,
Andy Lutomirski <luto@amacapital.net>,
live-patching@vger.kernel.org, x86@kernel.org, kpatch@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCHv6 2/3] kernel: add support for live patching
Date: Sat, 13 Dec 2014 14:06:15 -0600 [thread overview]
Message-ID: <20141213200615.GA21557@treble.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1412121737280.6587@pobox.suse.cz>
On Fri, Dec 12, 2014 at 05:58:19PM +0100, Miroslav Benes wrote:
>
> Hi,
>
> I think we are really close (or I hope so). I found few suspicious things
> or nitpicks though. They might have applied also to v5, but I didn't
> manage to look at that. Sorry about that.
>
> On Wed, 10 Dec 2014, Josh Poimboeuf wrote:
>
> > +/* klp_mutex must be held by caller */
> > +static bool klp_patch_is_registered(struct klp_patch *patch)
>
> Maybe klp_is_patch_registered is more appropriate name (consistent with
> other predicates in the file).
Ok.
> > +static int klp_disable_func(struct klp_func *func)
> > +{
> > + int ret;
> > +
> > + if (WARN_ON(func->state != KLP_ENABLED))
> > + return -EINVAL;
> > +
> > + if (WARN_ON(!func->old_addr))
> > + return -EINVAL;
> > +
> > + ret = unregister_ftrace_function(func->fops);
> > + if (ret) {
> > + pr_err("failed to unregister ftrace handler for function '%s' (%d)\n",
> > + func->old_name, ret);
> > + return ret;
> > + }
> > +
> > + ret = ftrace_set_filter_ip(func->fops, func->old_addr, 1, 0);
> > + if (ret)
> > + pr_warn("function unregister succeeded but failed to clear the filter\n");
> > +
> > + func->state = KLP_DISABLED;
> > +
> > + return 0;
> > +}
> > +
> > +static int klp_enable_func(struct klp_func *func)
> > +{
> > + int ret;
> > +
> > + if (WARN_ON(!func->old_addr))
> > + return -EINVAL;
> > +
> > + if (WARN_ON(func->state != KLP_DISABLED))
> > + return -EINVAL;
> > +
> > + ret = ftrace_set_filter_ip(func->fops, func->old_addr, 0, 0);
> > + if (ret) {
> > + pr_err("failed to set ftrace filter for function '%s' (%d)\n",
> > + func->old_name, ret);
> > + return ret;
> > + }
> > +
> > + ret = register_ftrace_function(func->fops);
> > + if (ret) {
> > + pr_err("failed to register ftrace handler for function '%s' (%d)\n",
> > + func->old_name, ret);
> > + ftrace_set_filter_ip(func->fops, func->old_addr, 1, 0);
> > + } else {
> > + func->state = KLP_ENABLED;
> > + }
> > +
> > + return ret;
> > +}
>
> Just to be sure about our policy. We want to be stricter during enabling
> than in disabling process. Is that correct? Otherwise there is
> inconsistency in pr_* macros and return values. Also fops could be
> hypothetically registered back when ftrace_set_filter_ip fails in
> klp_disable_func. I just want to be sure that we didn't overlook
> anything...
The asymmetry in the enable/disable error handling is intentional. In
klp_disable_func(), a ftrace_set_filter_ip() failure isn't a fatal
condition because we've already unregistered the fops and thus removed
the patch.
> > +static int klp_init_func(struct klp_object *obj, struct klp_func *func)
> > +{
> > + struct ftrace_ops *ops;
> > + int ret;
> > +
> > + func->state = KLP_DISABLED;
> > +
> > + ops = kzalloc(sizeof(*ops), GFP_KERNEL);
> > + if (!ops)
> > + ret = -ENOMEM;
>
> There should be return -ENOMEM.
Agreed.
> > +static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
> > +{
> > + struct klp_func *func;
> > + int ret;
> > + const char *name;
> > +
> > + if (!obj->funcs)
> > + return -EINVAL;
> > +
> > + obj->state = KLP_DISABLED;
> > +
> > + klp_find_object_module(obj);
> > +
> > + name = klp_is_module(obj) ? obj->name : "vmlinux";
> > + obj->kobj = kobject_create_and_add(name, &patch->kobj);
> > + if (!obj->kobj)
> > + return -ENOMEM;
> > +
> > + for (func = obj->funcs; func->old_name; func++) {
> > + ret = klp_init_func(obj, func);
> > + if (ret)
> > + goto free;
> > + }
> > +
> > + if (klp_is_object_loaded(obj)) {
> > + ret = klp_init_object_loaded(patch, obj);
> > + if (ret)
> > + goto free;
> > + }
> > +
> > + return 0;
> > +
> > +free:
> > + klp_free_funcs_limited(obj, func);
> > + return ret;
> > +}
>
> Shouldn't we call kobject_put(obj->kobj) in free branch? If I am not wrong
> it is not freed anywhere else. We free only already initialized functions
> and already initialized objects later in klp_init_patch, but not the
> kobject of the currently failing object.
Agreed.
> And that is everything. I like it, it has improved a lot. I hope that
> there are no other problems. I am getting blind looking at it all the
> time :)
Thanks! I'll send out the next patch set soon, maybe Monday.
--
Josh
next prev parent reply other threads:[~2014-12-13 20:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-10 22:21 [PATCHv6 0/3] Kernel Live Patching Josh Poimboeuf
2014-12-10 22:21 ` [PATCHv6 1/3] kernel: add TAINT_LIVEPATCH Josh Poimboeuf
2014-12-10 22:21 ` [PATCHv6 2/3] kernel: add support for live patching Josh Poimboeuf
2014-12-12 16:58 ` Miroslav Benes
2014-12-13 20:06 ` Josh Poimboeuf [this message]
2014-12-10 22:21 ` [PATCHv6 3/3] samples: add sample live patching module Josh Poimboeuf
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=20141213200615.GA21557@treble.redhat.com \
--to=jpoimboe@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=jkosina@suse.cz \
--cc=jslaby@suse.cz \
--cc=kpatch@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.cz \
--cc=rostedt@goodmis.org \
--cc=sjenning@redhat.com \
--cc=vojtech@suse.cz \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.