Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6423045yba; Wed, 1 May 2019 12:00:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsymi+Y96Xb6ldqzVYtga6WoTs1myTJunNGsEEiNGx1k0E0oVHGGvG/nMFy3ojqm1qPd7f X-Received: by 2002:a65:4b88:: with SMTP id t8mr1942374pgq.374.1556737213327; Wed, 01 May 2019 12:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556737213; cv=none; d=google.com; s=arc-20160816; b=wfnqnbszL8kGzmSZEv+Mi1mYFA6r/nI2kDlSIr3fr1Ii/lDxJiCOLrvAJdtriop2jb UTsPW8V/h4XAMb3JMxPjiHktKQi+mdiMThWwPCN5HV14w5NXti0X3Zz1LWWm5dcgspwc 0tM7LP11+aY/+oYcBZA7cUH1KlFdBccK7q6plNx7zVC5d1AOFDL22lTXOZwt3UbuAPtq 6taowZfznOv9S1ZtW6javaH2u+u95Xu7KH9H5Ntf2lZSuUe6LyESumKVd4Ick3wI9e5v daiZQUnjQaFdyzM0T1rdRjXPou5yLHtWlYDhJWSv7mPlvZSQr7uix4wsSPspUlzW77NE lTkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=Gu37A9ncEqDJ1rvUbbHOgcjp+aIEU2qdJdVLsbWIU9Y=; b=KZRgWd//ZHPCCrxzihM+vW2JothqacjJufhcWdXKfr2D/9+vB8f8P8QwsK+KVFvQWg dduMjafhBICBTf+49fWJf4EU+3W6766MF0uNNDyMbnMC9Jj43RE3ukrnvzQqh/ui2XM3 4l9ozF65leVAl8YmUP5S/2FBJDyHMbuglSkhs2IMjig6LpRp3MbHxpTxhawCm1I7TuMD P/Cav2WPpOk3cZMQ+6Xjj1YFhVMayU+J52GnwSaw/NtBNzMxU9/Zs6AUmEzn5/VeISbZ UT0bzLreMoU+oZ6M40SG7MTQBelQGBiVkEr5dGhkV+iB/Thm4263NAWkZlYgC3JbyXbp sL/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si43836912pld.269.2019.05.01.11.59.58; Wed, 01 May 2019 12:00:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbfEAS6a (ORCPT + 99 others); Wed, 1 May 2019 14:58:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:32810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726019AbfEAS63 (ORCPT ); Wed, 1 May 2019 14:58:29 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D793420675; Wed, 1 May 2019 18:58:25 +0000 (UTC) Date: Wed, 1 May 2019 14:58:24 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: Linus Torvalds , Andy Lutomirski , Nicolai Stange , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , the arch/x86 maintainers , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Konrad Rzeszutek Wilk , Tim Chen , Sebastian Andrzej Siewior , Mimi Zohar , Juergen Gross , Nick Desaulniers , Nayna Jain , Masahiro Yamada , Joerg Roedel , Linux List Kernel Mailing , live-patching@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" Subject: Re: [RFC][PATCH] ftrace/x86: Emulate call function while updating in breakpoint handler Message-ID: <20190501145824.08aed43a@gandalf.local.home> In-Reply-To: <20190501131117.GW2623@hirez.programming.kicks-ass.net> References: <20190430135602.GD2589@hirez.programming.kicks-ass.net> <20190430130359.330e895b@gandalf.local.home> <20190430132024.0f03f5b8@gandalf.local.home> <20190430134913.4e29ce72@gandalf.local.home> <20190501131117.GW2623@hirez.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 1 May 2019 15:11:17 +0200 Peter Zijlstra wrote: > On Tue, Apr 30, 2019 at 11:33:21AM -0700, Linus Torvalds wrote: > > Anyway, since Andy really likes the entry code change, can we have > > that patch in parallel and judge the difference that way? Iirc, that > > was x86-64 specific too. > > Here goes, compile tested only... > > It obviously needs a self-test, but that shoulnd't be too hard to > arrange. > I was able to get it applied (with slight tweaking) but it then crashed. But that was due to incorrect updates in the ftrace_int3_handler(). > --- > arch/x86/entry/entry_32.S | 7 +++++++ > arch/x86/entry/entry_64.S | 14 ++++++++++++-- > arch/x86/include/asm/text-patching.h | 20 ++++++++++++++++++++ > arch/x86/kernel/ftrace.c | 24 +++++++++++++++++++----- > 4 files changed, 58 insertions(+), 7 deletions(-) > #endif /* _ASM_X86_TEXT_PATCHING_H */ > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > index ef49517f6bb2..90d319687d7e 100644 > --- a/arch/x86/kernel/ftrace.c > +++ b/arch/x86/kernel/ftrace.c > @@ -29,6 +29,7 @@ > #include > #include > #include > +#include > > #ifdef CONFIG_DYNAMIC_FTRACE > > @@ -231,6 +232,7 @@ int ftrace_modify_call(struct dyn_ftrace *rec, > unsigned long old_addr, } > > static unsigned long ftrace_update_func; > +static unsigned long ftrace_update_func_call; > > static int update_ftrace_func(unsigned long ip, void *new) > { > @@ -259,6 +261,8 @@ int ftrace_update_ftrace_func(ftrace_func_t func) > unsigned char *new; > int ret; > > + ftrace_update_func_call = (unsigned long)func; > + > new = ftrace_call_replace(ip, (unsigned long)func); > ret = update_ftrace_func(ip, new); > > @@ -295,12 +299,19 @@ int ftrace_int3_handler(struct pt_regs *regs) > return 0; > > ip = regs->ip - 1; > - if (!ftrace_location(ip) && !is_ftrace_caller(ip)) > - return 0; > - > - regs->ip += MCOUNT_INSN_SIZE - 1; > + if (ftrace_location(ip)) { > + int3_emulate_call(regs, ftrace_update_func_call); Should be: int3_emulate_call(regs, (unsigned long)ftrace_regs_caller); > + return 1; > + } else if (is_ftrace_caller(ip)) { > + if (!ftrace_update_func_call) { > + int3_emulate_jmp(regs, regs->ip - INT3_INSN_SIZE + CALL_INSN_SIZE); I see what you did here, but I think: int3_emulate_jmp(regs, ip + CALL_INSN_SIZE); looks better. But that said, we could in the beginning do: ip = regs->ip - INT3_INSN_SIZE; instead of ip = regs->ip - 1; I made these updates and posted them to Linus. -- Steve > + return 1; > + } > + int3_emulate_call(regs, ftrace_update_func_call); > + return 1; > + } > > - return 1; > + return 0; > } > NOKPROBE_SYMBOL(ftrace_int3_handler); > > @@ -859,6 +870,8 @@ void arch_ftrace_update_trampoline(struct > ftrace_ops *ops) > func = ftrace_ops_get_func(ops); > > + ftrace_update_func_call = (unsigned long)func; > + > /* Do a safe modify in case the trampoline is executing */ > new = ftrace_call_replace(ip, (unsigned long)func); > ret = update_ftrace_func(ip, new); > @@ -960,6 +973,7 @@ static int ftrace_mod_jmp(unsigned long ip, void > *func) { > unsigned char *new; > > + ftrace_update_func_call = 0UL; > new = ftrace_jmp_replace(ip, (unsigned long)func); > > return update_ftrace_func(ip, new);