Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753321AbbBRVWN (ORCPT ); Wed, 18 Feb 2015 16:22:13 -0500 Received: from mail-wg0-f54.google.com ([74.125.82.54]:35636 "EHLO mail-wg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752731AbbBRVWK (ORCPT ); Wed, 18 Feb 2015 16:22:10 -0500 Date: Wed, 18 Feb 2015 22:22:05 +0100 From: Ingo Molnar To: Petr Mladek Cc: Masami Hiramatsu , Ingo Molnar , "David S. Miller" , Anil S Keshavamurthy , Ananth NMavinakayanahalli , Frederic Weisbecker , Steven Rostedt , Jiri Kosina , linux-kernel@vger.kernel.org, Ingo Molnar Subject: Re: [PATCH v2] kprobes/x86: Use 5-byte NOP when the code might be modified by ftrace Message-ID: <20150218212205.GA26334@gmail.com> References: <1422899338-26399-1-git-send-email-pmladek@suse.cz> <54D07BB3.1020806@hitachi.com> <20150203113828.GD1576@dhcp128.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150203113828.GD1576@dhcp128.suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2794 Lines: 72 * Petr Mladek wrote: > On Tue 2015-02-03 16:41:39, Masami Hiramatsu wrote: > > (2015/02/03 2:48), Petr Mladek wrote: > > > can_probe() checks if the given address points to the beginning of > > > an instruction. It analyzes all the instructions from the beginning > > > of the function until the given address. The code might be modified > > > by another Kprobe. In this case, the current code is read into a buffer, > > > int3 breakpoint is replaced by the saved opcode in the buffer, and > > > can_probe() analyzes the buffer instead. > > > > > > There is a bug that __recover_probed_insn() tries to restore > > > the original code even for Kprobes using the ftrace framework. > > > But in this case, the opcode is not stored. See the difference > > > between arch_prepare_kprobe() and arch_prepare_kprobe_ftrace(). > > > The opcode is stored by arch_copy_kprobe() only from > > > arch_prepare_kprobe(). > > > > > > This patch makes Kprobe to use the ideal 5-byte NOP when the code > > > can be modified by ftrace. It is the original instruction, see > > > ftrace_make_nop() and ftrace_nop_replace(). > > > > > > Note that we always need to use the NOP for ftrace locations. Kprobes > > > do not block ftrace and the instruction might get modified at anytime. > > > It might even be in an inconsistent state because it is modified step > > > by step using the int3 breakpoint. > > > > > > The patch also fixes indentation of the touched comment. > > > > > > Note that I found this problem when playing with Kprobes. I did it > > > on x86_64 with gcc-4.8.3 that supported -mfentry. I modified > > > samples/kprobes/kprobe_example.c and added offset 5 to put > > > the probe right after the fentry area: > > > > > > --- cut --- > > > static struct kprobe kp = { > > > .symbol_name = "do_fork", > > > + .offset = 5, > > > }; > > > --- cut --- > > > > > > Then I was able to load kprobe_example before jprobe_example > > > but not the other way around: > > > > > > $> modprobe jprobe_example > > > $> modprobe kprobe_example > > > modprobe: ERROR: could not insert 'kprobe_example': Invalid or incomplete multibyte or wide character > > > > > > It did not make much sense and debugging pointed to the bug > > > described above. > > > > > > > This looks good to me :) > > > > Acked-by: Masami Hiramatsu > > > > Ingo, could you merge this as an urgent fix? > > Please, wait a bit, see below. Please [re]send the final patch with Masami's Ack added and me Cc:-ed. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/