From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754768AbbCBO0R (ORCPT ); Mon, 2 Mar 2015 09:26:17 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:4463 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754719AbbCBO0L (ORCPT ); Mon, 2 Mar 2015 09:26:11 -0500 From: Wang Nan To: , , , , CC: , , , Subject: [RFC PATCH v4 29/34] ftrace: x86: call kprobe_int3_handler() in ftrace int3 handler. Date: Mon, 2 Mar 2015 22:25:07 +0800 Message-ID: <1425306312-3437-30-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> References: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.247] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.54F472FE.01B8,ss=1,re=0.001,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 064ad8965a2220fc6bc295336efc26e7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since early kprobes and ftrace both use int3 (ftrace insert int3 to the first byte of ftrace entry, fill other bytes of the inserted 'call' instruction and finally restore the first byte, while kprobe rely on int3 to trigger its actions), it is possible that a breakpoint is shared between ftrace and an early kprobe on it. Let ftrace_int3_handler() deal with this confliction by calling kprobe_int3_handler() before it jump to next instruction to avoid lost event during ftrace inserting 'call' instruction. Signed-off-by: Wang Nan --- arch/x86/kernel/ftrace.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index f200cd4..0a86c7c 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -302,7 +302,17 @@ int ftrace_int3_handler(struct pt_regs *regs) if (!ftrace_location(ip) && !is_ftrace_caller(ip)) return 0; - regs->ip += MCOUNT_INSN_SIZE - 1; + /* + * During converting early kprobes on ftrace to ftrace, it is + * possible to hit a breakpoint belong to both ftrace and + * kprobe. Call kprobe_int3_handler() to avoid missing events. + * Note that even if kprobe is optimized, breakpoint based + * kprobe should still be functional. + */ +#if defined(CONFIG_EARLY_KPROBES) && defined(CONFIG_KPROBES_ON_FTRACE) + if (!kprobe_int3_handler(regs)) +#endif + regs->ip += MCOUNT_INSN_SIZE - 1; return 1; } -- 1.8.4