Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1259726pxx; Fri, 30 Oct 2020 06:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6VuvGMN+oEpLBb1cgW9BNsAQQVpt0VB24v9x0+tU4teNlzv3UBWY81qZNlApWFETosaJ0 X-Received: by 2002:a1c:750b:: with SMTP id o11mr2712310wmc.32.1604063353849; Fri, 30 Oct 2020 06:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604063353; cv=none; d=google.com; s=arc-20160816; b=cQR6h4dyay7drJvI1NLS3PSfDIpnt/mKhgL6QP3bgTem1Dbbj526mUyAkaE1Q7G2Vy WnVkT/KoduPKX9iKxAK/Tz3kPprjA9d9ESXUFQQxTieET4nSGnOpkzz82eD9XZjz/Ele WuB1PbbudyGE4cbNrgyKI8vfQcIp7CfigfI513QVXPMVceuC2RzXpkp5kZaR92YGk2a3 PEXs1kB+NCd16Q+thDStIK0XW9q39bhN9dNRlggR4+JarQ/LUeKfy6+wJKvBVM/PTPRY hALzoH0WB92JOlXtz8VVmsslm+bnFnB5a/DpoF7Gp3XFRjFf7NPinqvE5sa1H2dc2rBE 89wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=mSGVu2M/2ewdnHEiTQkaeAmU1VLKdAlX1VZ6G4WeMQ4=; b=wc2kWU86y0pMJ1cmL7qDAG3Rw+B76t1sNkXawYfzlqd0wJ0h0WqoYLCaTa2W49XI5d BR2gshN2C57PfVIRqflgkwWnFAPz9Hv0swQL3bTiWNTUuhtZlzYhquWPVuO7uUIZSckv E3SNxAFxAevHSdRebFgpLHShX4YuhN93Tou9og3MnebPdpVsB42NjxWODx1EtLPwtHUb 92jVAVgoFE901Wi0cIX4DTbvarDFkmZtKXRU6LlP7/MRyoZYKolmMCSmODvly+Cm99ci MDDzmIOygq3sdo8kryv1j/F2xUHa5vm60bp3bF/ghOw64l/IEj4Qd62yLXNpx4nz0Pj0 L1iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 30si4654423edw.225.2020.10.30.06.08.50; Fri, 30 Oct 2020 06:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726549AbgJ3NHO (ORCPT + 99 others); Fri, 30 Oct 2020 09:07:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:58932 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726486AbgJ3NHO (ORCPT ); Fri, 30 Oct 2020 09:07:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 05626ABAE; Fri, 30 Oct 2020 13:07:12 +0000 (UTC) Date: Fri, 30 Oct 2020 14:07:11 +0100 (CET) From: Miroslav Benes To: Steven Rostedt cc: linux-kernel@vger.kernel.org, Masami Hiramatsu , Andrew Morton , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Alexei Starovoitov , Jiri Olsa , Josh Poimboeuf , Jiri Kosina , live-patching@vger.kernel.org Subject: Re: [RFC][PATCH 3/3 v3] livepatching: Use the default ftrace_ops instead of REGS when ARGS is available In-Reply-To: <20201029002253.192388563@goodmis.org> Message-ID: References: <20201029000816.272878754@goodmis.org> <20201029002253.192388563@goodmis.org> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (live-patching ML CCed, keeping the complete email for reference) Hi, a nit concerning the subject. We use just "livepatch:" as a prefix. On Wed, 28 Oct 2020, Steven Rostedt wrote: > From: "Steven Rostedt (VMware)" > > When CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is available, the ftrace call > will be able to set the ip of the calling function. This will improve the > performance of live kernel patching where it does not need all the regs to > be stored just to change the instruction pointer. > > If all archs that support live kernel patching also support > HAVE_DYNAMIC_FTRACE_WITH_ARGS, then the architecture specific function > klp_arch_set_pc() could be made generic. I think this is a nice idea, which could easily lead to removing FTRACE_WITH_REGS altogether. I'm really looking forward to that because every consolidation step is welcome. My only remark is for the config. LIVEPATCH now depends on DYNAMIC_FTRACE_WITH_REGS which is not completely true after this change, so we should probably make it depend on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS, just to reflect the situation better. Anyway, it passed my tests too and the patch looks good to me, so Acked-by: Miroslav Benes M > Signed-off-by: Steven Rostedt (VMware) > --- > arch/powerpc/include/asm/livepatch.h | 4 +++- > arch/s390/include/asm/livepatch.h | 5 ++++- > arch/x86/include/asm/ftrace.h | 3 +++ > arch/x86/include/asm/livepatch.h | 4 ++-- > arch/x86/kernel/ftrace_64.S | 4 ++++ > include/linux/ftrace.h | 7 +++++++ > kernel/livepatch/patch.c | 9 +++++---- > 7 files changed, 28 insertions(+), 8 deletions(-) > > diff --git a/arch/powerpc/include/asm/livepatch.h b/arch/powerpc/include/asm/livepatch.h > index 4a3d5d25fed5..ae25e6e72997 100644 > --- a/arch/powerpc/include/asm/livepatch.h > +++ b/arch/powerpc/include/asm/livepatch.h > @@ -12,8 +12,10 @@ > #include > > #ifdef CONFIG_LIVEPATCH > -static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) > +static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip) > { > + struct pt_regs *regs = ftrace_get_regs(fregs); > + > regs->nip = ip; > } > > diff --git a/arch/s390/include/asm/livepatch.h b/arch/s390/include/asm/livepatch.h > index 818612b784cd..d578a8c76676 100644 > --- a/arch/s390/include/asm/livepatch.h > +++ b/arch/s390/include/asm/livepatch.h > @@ -11,10 +11,13 @@ > #ifndef ASM_LIVEPATCH_H > #define ASM_LIVEPATCH_H > > +#include > #include > > -static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) > +static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip) > { > + struct pt_regs *regs = ftrace_get_regs(fregs); > + > regs->psw.addr = ip; > } > > diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h > index 6b175c2468e6..7042e80941e5 100644 > --- a/arch/x86/include/asm/ftrace.h > +++ b/arch/x86/include/asm/ftrace.h > @@ -62,6 +62,9 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs) > return NULL; > return &fregs->regs; > } > + > +#define ftrace_regs_set_ip(fregs, _ip) \ > + do { (fregs)->regs.ip = (_ip); } while (0) > #endif > > #endif /* CONFIG_DYNAMIC_FTRACE */ > diff --git a/arch/x86/include/asm/livepatch.h b/arch/x86/include/asm/livepatch.h > index 1fde1ab6559e..59a08d5c6f1d 100644 > --- a/arch/x86/include/asm/livepatch.h > +++ b/arch/x86/include/asm/livepatch.h > @@ -12,9 +12,9 @@ > #include > #include > > -static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) > +static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned long ip) > { > - regs->ip = ip; > + ftrace_regs_set_ip(fregs, ip); > } > > #endif /* _ASM_X86_LIVEPATCH_H */ > diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S > index c4177bd00cd2..d00806dd8eed 100644 > --- a/arch/x86/kernel/ftrace_64.S > +++ b/arch/x86/kernel/ftrace_64.S > @@ -157,6 +157,10 @@ SYM_INNER_LABEL(ftrace_caller_op_ptr, SYM_L_GLOBAL) > SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) > call ftrace_stub > > + /* Handlers can change the RIP */ > + movq RIP(%rsp), %rax > + movq %rax, MCOUNT_REG_SIZE(%rsp) > + > restore_mcount_regs > > /* > diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h > index 588ea7023a7a..b4eb962e2be9 100644 > --- a/include/linux/ftrace.h > +++ b/include/linux/ftrace.h > @@ -97,6 +97,13 @@ struct ftrace_regs { > }; > #define arch_ftrace_get_regs(fregs) (&(fregs)->regs) > > +/* > + * ftrace_regs_set_ip() is to be defined by the architecture if > + * to allow setting of the instruction pointer from the ftrace_regs > + * when HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports > + * live kernel patching. > + */ > +#define ftrace_regs_set_ip(fregs, ip) do { } while (0) > #endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ > > static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs) > diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c > index 9af0a7c8a255..722266472903 100644 > --- a/kernel/livepatch/patch.c > +++ b/kernel/livepatch/patch.c > @@ -42,7 +42,6 @@ static void notrace klp_ftrace_handler(unsigned long ip, > struct ftrace_ops *fops, > struct ftrace_regs *fregs) > { > - struct pt_regs *regs = ftrace_get_regs(fregs); > struct klp_ops *ops; > struct klp_func *func; > int patch_state; > @@ -118,7 +117,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, > if (func->nop) > goto unlock; > > - klp_arch_set_pc(regs, (unsigned long)func->new_func); > + klp_arch_set_pc(fregs, (unsigned long)func->new_func); > > unlock: > preempt_enable_notrace(); > @@ -200,8 +199,10 @@ static int klp_patch_func(struct klp_func *func) > return -ENOMEM; > > ops->fops.func = klp_ftrace_handler; > - ops->fops.flags = FTRACE_OPS_FL_SAVE_REGS | > - FTRACE_OPS_FL_DYNAMIC | > + ops->fops.flags = FTRACE_OPS_FL_DYNAMIC | > +#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS > + FTRACE_OPS_FL_SAVE_REGS | > +#endif > FTRACE_OPS_FL_IPMODIFY | > FTRACE_OPS_FL_PERMANENT; > > -- > 2.28.0 > >