Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752379AbbBWPL0 (ORCPT ); Mon, 23 Feb 2015 10:11:26 -0500 Received: from collab.rosalab.ru ([195.19.76.181]:45947 "EHLO collab.rosalab.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752143AbbBWPLY (ORCPT ); Mon, 23 Feb 2015 10:11:24 -0500 X-Greylist: delayed 391 seconds by postgrey-1.27 at vger.kernel.org; Mon, 23 Feb 2015 10:11:24 EST Message-ID: <54EB4194.7040901@rosalab.ru> Date: Mon, 23 Feb 2015 18:04:52 +0300 From: Eugene Shatokhin Organization: ROSA User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Masami Hiramatsu CC: linux-kernel@vger.kernel.org Subject: Kprobes: pre-handler with interrupts enabled - is it possible? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2050 Lines: 55 Hi, First of all, many thanks to the developers of Kprobes! I use both Kprobes and parts of their code a lot in my projects these days. As far as I can see, the pre-handlers of Kprobes run with interrupts and preemption disabled on the given CPU, at least on x86 without Kprobe optimization. Is it possible, however, to use Kprobes to somehow execute my code before a given instruction but with the same restrictions as the original instruction, at least, w.r.t. the interrupts? I mean, if the instruction is executed with interrupts enabled, my code would also execute with interrupts enabled, etc. If it is possible, how would you recommend to do that? Without patching the implementation of Kprobes, I mean. Same for preemption, but, it seems, Kprobes really need it disabled, at least to be able to use kprobe_running() and other per-cpu data. In RaceHound project I am now working on (https://github.com/winnukem/racehound/tree/rh_rework), the breakpoints are used to detect data races in the kernel code in runtime. Software breakpoints for the code, hardware breakpoints for the data that is about to be accessed. However, to make it all work, the detector introduces delays before the instructions of interest. I could do this in Kprobes' pre-handlers but the interrupts would always be disabled on the current CPU during the delays, which is no good. So far, I implemented it using software breakpoints directly, without Kprobes. The pre-handlers are executed then in the same context as the original instructions. Still the implementation becomes more and more like Kprobes in some places over time. If there is a way to avoid reinventing the wheel and just use Kprobes, I would do that. So, any ideas? Regards, Eugene -- Eugene Shatokhin, ROSA www.rosalab.com -- 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/