Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp68399pxb; Tue, 15 Feb 2022 08:35:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAKGJ+rUtq9rGtV9hrU2LEud06YgoMlQ45NtU/7GjyIMRxGj1o65WrgDVXb/UZn5hqToOr X-Received: by 2002:a05:6402:885:: with SMTP id e5mr4792101edy.61.1644942951103; Tue, 15 Feb 2022 08:35:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644942951; cv=none; d=google.com; s=arc-20160816; b=UiQi1Ns9gbyA3Fe6BXpLzfVn4nGAnXwy2lFXbsQDq0d9h0rWqHG+7cNWnf7jl+A0sV hetyJkuSaL+xVJ6/rmbOTgWi64qPpJDk/el1V6WtH1eug8oaqHAD3hlhkcSXOc2u9JNK Lazk+s5k/OpRmPwW8NDBMcyH9YSEzfjg/3vVc39A9q6pGBGPsyop8GjssuL99bWsG2UG 9pSEbNBOsMl1+ETnN36TXA//JHGayqr8qcAhFxthOMe8FykeyVPKdIBMYfBNTlHEtVlm FoOUYfyFMcJf3q1LkLR2v+fF3v26WCUFD/pSPbIBuwopGbHNcdjSb8wlYYQW8iUmMPrj I5cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=LoeNfqeXHZpw22Uq/3imGMD+iHu3vmdMmCYzm8O/0HE=; b=P0PMLhaMdvomqUtcBUFkhCoZRthpDoIVUSiL9N1EWtiU6ovwcsKBupEWkqTgg58DAU 2GL54ZA4xUO+EY7RGpnCV8Q0TZb7FeBSkLOYesdCtLnR2hiIpzNeB0YVoFwDHXXH2QfV ka/CXFuIRICmbDOh0cdaLnM72Wav3K3Rhz8xK5Vgfd6pZeF5vFzdlW+2gSOa9LtTD/vn AuDZ4j/iIcy6PPgIeFK15VNLiOsvbBGkLtZsqctdCx2ga8nU5FTu2JdRyk5fhDDP+IG0 I3BdU/clvijlZRb+4Trx22yuqmUA7Mf383OMSCO0S+qg0giVWmMnYqaJqMhbCZTqmgt8 yDmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=SHn+0P0f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ek10si144436edb.569.2022.02.15.08.35.25; Tue, 15 Feb 2022 08:35:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=SHn+0P0f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236544AbiBOLFX (ORCPT + 99 others); Tue, 15 Feb 2022 06:05:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234362AbiBOLFW (ORCPT ); Tue, 15 Feb 2022 06:05:22 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A61B21074F0; Tue, 15 Feb 2022 03:05:11 -0800 (PST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4JydXd6l0yz4xNq; Tue, 15 Feb 2022 22:05:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1644923107; bh=LoeNfqeXHZpw22Uq/3imGMD+iHu3vmdMmCYzm8O/0HE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=SHn+0P0fQHdthvYLHYFnoJt36LFHdIy60E+1+cApL4Qd3fRJ74pBCS79bFEQcIupt vwupGcmCdq48K88sDm5KgEcS5aHkfeTfrotLL9p1pU6yi3vVdwxxeiqjZCp3iOiDSo m8DyTQZKgC9cdIptSy7lGlVKcCH1lijaQoTFOZkodTrsxQnjlMF1pA9meNMLieskBv 24pHnMbAznFtrmC0gnqmVbn7E0ilcKPVgV88T3HxI/wSrVWI6lxav60uqi2mVrDtTZ L54uDc4vn4/B/kV9YAv1+nOlse4K36BMU/DPR6ElvtOmkUNDcKrk8529uvKFOoib/W gDLYqvVXRIB2A== From: Michael Ellerman To: Christophe Leroy , "Naveen N. Rao" , Jiri Kosina , Joe Lawrence , Josh Poimboeuf , Miroslav Benes , Ingo Molnar , Petr Mladek , Steven Rostedt Cc: "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "live-patching@vger.kernel.org" Subject: Re: [PATCH v2 09/13] powerpc/ftrace: Implement CONFIG_DYNAMIC_FTRACE_WITH_ARGS In-Reply-To: <1b28f52a-f8b7-6b5c-e726-feac4123517d@csgroup.eu> References: <5831f711a778fcd6eb51eb5898f1faae4378b35b.1640017960.git.christophe.leroy@csgroup.eu> <1644852011.qg7ud9elo2.naveen@linux.ibm.com> <1b28f52a-f8b7-6b5c-e726-feac4123517d@csgroup.eu> Date: Tue, 15 Feb 2022 22:05:04 +1100 Message-ID: <875ypgo0f3.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe Leroy writes: > Le 14/02/2022 =C3=A0 16:25, Naveen N. Rao a =C3=A9crit=C2=A0: >> Christophe Leroy wrote: >>> Implement CONFIG_DYNAMIC_FTRACE_WITH_ARGS. It accelerates the call >>> of livepatching. >>> >>> Also note that powerpc being the last one to convert to >>> CONFIG_DYNAMIC_FTRACE_WITH_ARGS, it will now be possible to remove >>> klp_arch_set_pc() on all architectures. >>> >>> Signed-off-by: Christophe Leroy >>> --- >>> =C2=A0arch/powerpc/Kconfig=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 1 + >>> =C2=A0arch/powerpc/include/asm/ftrace.h=C2=A0=C2=A0=C2=A0 | 17 ++++++++= +++++++++ >>> =C2=A0arch/powerpc/include/asm/livepatch.h |=C2=A0 4 +--- >>> =C2=A03 files changed, 19 insertions(+), 3 deletions(-) >>> >>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig >>> index cdac2115eb00..e2b1792b2aae 100644 >>> --- a/arch/powerpc/Kconfig >>> +++ b/arch/powerpc/Kconfig >>> @@ -210,6 +210,7 @@ config PPC >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_DEBUG_KMEMLEAK >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_DEBUG_STACKOVERFLOW >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_DYNAMIC_FTRACE >>> +=C2=A0=C2=A0=C2=A0 select HAVE_DYNAMIC_FTRACE_WITH_ARGS=C2=A0=C2=A0=C2= =A0 if MPROFILE_KERNEL || PPC32 >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_DYNAMIC_FTRACE_WITH_REGS=C2=A0=C2= =A0=C2=A0 if MPROFILE_KERNEL || PPC32 >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_EBPF_JIT >>> =C2=A0=C2=A0=C2=A0=C2=A0 select HAVE_EFFICIENT_UNALIGNED_ACCESS=C2=A0= =C2=A0=C2=A0 if !(CPU_LITTLE_ENDIAN=20 >>> && POWER7_CPU) >>> diff --git a/arch/powerpc/include/asm/ftrace.h=20 >>> b/arch/powerpc/include/asm/ftrace.h >>> index b3f6184f77ea..45c3d6f11daa 100644 >>> --- a/arch/powerpc/include/asm/ftrace.h >>> +++ b/arch/powerpc/include/asm/ftrace.h >>> @@ -22,6 +22,23 @@ static inline unsigned long=20 >>> ftrace_call_adjust(unsigned long addr) >>> =C2=A0struct dyn_arch_ftrace { >>> =C2=A0=C2=A0=C2=A0=C2=A0 struct module *mod; >>> =C2=A0}; >>> + >>> +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS >>> +struct ftrace_regs { >>> +=C2=A0=C2=A0=C2=A0 struct pt_regs regs; >>> +}; >>> + >>> +static __always_inline struct pt_regs *arch_ftrace_get_regs(struct=20 >>> ftrace_regs *fregs) >>> +{ >>> +=C2=A0=C2=A0=C2=A0 return &fregs->regs; >>> +} >>=20 >> I think this is wrong. We need to differentiate between ftrace_caller()= =20 >> and ftrace_regs_caller() here, and only return pt_regs if coming in=20 >> through ftrace_regs_caller() (i.e., FL_SAVE_REGS is set). > > Not sure I follow you. > > This is based on 5740a7c71ab6 ("s390/ftrace: add=20 > HAVE_DYNAMIC_FTRACE_WITH_ARGS support") > > It's all the point of HAVE_DYNAMIC_FTRACE_WITH_ARGS, have the regs also=20 > with ftrace_caller(). > > Sure you only have the params, but that's the same on s390, so what did=20 > I miss ? I already have this series in next, I can pull it out, but I'd rather not. I'll leave it in for now, hopefully you two can agree overnight my time whether this is a big problem or something we can fix with a fixup patch. >>> +static __always_inline void ftrace_instruction_pointer_set(struct=20 >>> ftrace_regs *fregs, >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long ip) >>> +{ >>> +=C2=A0=C2=A0=C2=A0 regs_set_return_ip(&fregs->regs, ip); >>=20 >> Should we use that helper here? regs_set_return_ip() also updates some=20 >> other state related to taking interrupts and I don't think it makes=20 >> sense for use with ftrace. > > > Today we have: > > static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned=20 > long ip) > { > struct pt_regs *regs =3D ftrace_get_regs(fregs); > > regs_set_return_ip(regs, ip); > } > > > Which like x86 and s390 becomes: > > static inline void klp_arch_set_pc(struct ftrace_regs *fregs, unsigned=20 > long ip) > { > ftrace_instruction_pointer_set(fregs, ip); > } > > > > That's the reason why I've been using regs_set_return_ip(). Do you think= =20 > it was wrong to use regs_set_return_ip() in klp_arch_set_pc() ? > > That was added by 59dc5bfca0cb ("powerpc/64s: avoid reloading (H)SRR=20 > registers if they are still valid") It's not wrong, but I think it's unnecessary. We need to use regs_set_return_ip() if we're changing the regs->ip of an interrupt frame, so that the interrupt return code will reload it. But AIUI in this case we're not doing that, we're changing the regs->ip of a pt_regs provided by ftrace, which shouldn't ever be an interrupt frame. So it's not a bug to use regs_set_return_ip(), but it is unncessary and means we'll reload the interrupt state unnecessarily on the next interrupt return. cheers