Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761701AbZFPTvv (ORCPT ); Tue, 16 Jun 2009 15:51:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756401AbZFPTvn (ORCPT ); Tue, 16 Jun 2009 15:51:43 -0400 Received: from BISCAYNE-ONE-STATION.MIT.EDU ([18.7.7.80]:48398 "EHLO biscayne-one-station.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752647AbZFPTvm (ORCPT ); Tue, 16 Jun 2009 15:51:42 -0400 Date: Tue, 16 Jun 2009 15:50:52 -0400 (EDT) From: Tim Abbott X-X-Sender: tabbott@vinegar-pot.mit.edu To: Masami Hiramatsu cc: Ingo Molnar , Ananth N Mavinakayanahalli , lkml , "H. Peter Anvin" , Frederic Weisbecker , Jim Keniston , Srikar Dronamraju , Christoph Hellwig , Steven Rostedt , Anders Kaseorg , systemtap , DLE Subject: Re: [RFC][ PATCH -tip 0/6] kprobes: Kprobes jump optimization support In-Reply-To: <20090612224925.17825.49637.stgit@localhost.localdomain> Message-ID: References: <20090612224925.17825.49637.stgit@localhost.localdomain> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Flag: NO X-Spam-Score: 0.00 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3220 Lines: 84 On Fri, 12 Jun 2009, Masami Hiramatsu wrote: > - Safety check [...] > Next, Kprobes decodes whole body of probed function and checks there is > NO indirect jump, and near jump which jumps into the optimized region (except > the 1st byte of jump), because if some jump instruction jumps into the middle > of another instruction, it causes unexpected results too. Hi Masami, I think your safety check algorithm is wrong. There are several ways in which the kernel might jump into the optimized region that cannot be detected by examining just the probed function: (1) The compiler is allowed to do cross-function optimization within a compilation unit where code in one function jumps into the middle of another function. (2) If you have a switch statement that looks like: switch (foo) { case 1: printk("a1"); break; case 2: printk("a2"); break; case 3: printk("a3"); break; case 4: printk("a4"); break; case 5: printk("a5"); break; } (i.e. a large number of cases indexed by a small range of integers; depending on your compiler you may need more cases), gcc will implement it using a jump table in the .rodata section. On x86_32, the generated assembly for the switch will read from the jump table at an offset of 4 * (foo - 1) and then jump to that address to reach the code for the appropriate case. These jump tables can result in jumps from within the probed function into the optimized region in a way that your algorithm would not detect. (3) If the code that you're overwriting can throw an exception, it might be that that there is a jump from the .fixup section back into the probed function that overlaps the optimized region. The other comment I have about this approach is that it seems you've written a completely new x86 disassembler in order to do binary code analysis in the kernel. Ksplice has been using the udis86 disassembler for this purpose: . udis86 is intended for binary code analysis and is designed to be embedded into kernels and other applications. udis86 generates all its instruction table data from an XML opcode file, which is I think what H. Peter Anvin was suggesting you should do in this previous thread on your instruction decoder: Compared to e.g. libopcodes it is still quite small -- there's a total of about 3000 lines of C, plus some instruction tables that are automatically generated from an XML description of the instructions. The upstream developer has merged patches from Anders Kaseorg and myself that make it build as part of the core Linux kernel without any changes other than adding a kernel Makefile. I think if we're going to putting an x86 disassembler into the kernel, it might be better to use something like udis86 that provides a little more information about the instructions being disassembled and is more data-driven. -Tim Abbott -- 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/