Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752523AbbBMFth (ORCPT ); Fri, 13 Feb 2015 00:49:37 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:23702 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752488AbbBMFtg (ORCPT ); Fri, 13 Feb 2015 00:49:36 -0500 From: Wang Nan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , Subject: [RFC PATCH v3 23/26] early kprobes: x86: arch_restore_optimized_kprobe(). Date: Fri, 13 Feb 2015 13:41:13 +0800 Message-ID: <1423806073-62441-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1423805941-61407-1-git-send-email-wangnan0@huawei.com> References: <1423805941-61407-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.0A020205.54DD9013.0025,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: 3ea98d1836d39e2f9a816b2ad5e5bb4d Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2193 Lines: 73 arch_restore_optimized_kprobe() can be used to temporarily restore probed instruction. It will actually disable optimized kprobe, but keep the relatived data structure. It uses stop_machine() to enforce atimicity. Signed-off-by: Wang Nan --- arch/x86/kernel/kprobes/opt.c | 26 ++++++++++++++++++++++++++ include/linux/kprobes.h | 1 + 2 files changed, 27 insertions(+) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index f3ea954..12332c2 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -486,4 +487,29 @@ void arch_fix_ftrace_early_kprobe(struct optimized_kprobe *op) memcpy(&list_p->opcode, correct_nop5, sizeof(kprobe_opcode_t)); } + +static int do_restore_kprobe(void *p) +{ + struct optimized_kprobe *op = p; + u8 insn_buf[RELATIVEJUMP_SIZE]; + + memcpy(insn_buf, &op->kp.opcode, sizeof(kprobe_opcode_t)); + memcpy(insn_buf + INT3_SIZE, + op->optinsn.copied_insn, + RELATIVE_ADDR_SIZE); + text_poke(op->kp.addr, insn_buf, RELATIVEJUMP_SIZE); + return 0; +} + +void arch_restore_optimized_kprobe(struct optimized_kprobe *op) +{ + u32 mask = KPROBE_FLAG_EARLY | + KPROBE_FLAG_OPTIMIZED | + KPROBE_FLAG_FTRACE; + + if ((op->kp.flags & mask) != mask) + return; + + stop_machine(do_restore_kprobe, op, NULL); +} #endif diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index e483f1b..e615402 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -462,6 +462,7 @@ extern int arch_prepare_kprobe_ftrace(struct kprobe *p); #ifdef CONFIG_EARLY_KPROBES extern void arch_fix_ftrace_early_kprobe(struct optimized_kprobe *p); +extern void arch_restore_optimized_kprobe(struct optimized_kprobe *p); #endif #endif -- 1.8.4 -- 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/