Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4861836pjb; Mon, 27 Jul 2020 07:05:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiogdsXgi6R/G0DdsYQ6/JPXLUANd8fwJBW1PVZs9UZfrJ/M4aPQqMNxAUR0NsKVSd2+jI X-Received: by 2002:a05:6402:b45:: with SMTP id bx5mr5746226edb.22.1595858731514; Mon, 27 Jul 2020 07:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595858731; cv=none; d=google.com; s=arc-20160816; b=NB9UqDaIAj/mp/zozkC/Dnhwj+UjrRl+S/g2gXjXxDA32lvWO67LjKwOfTuerenpqO PykqNpi3eLWM1DTDJ1Kg5dZ4bn+nR6kxfqkwhKH6Mo2RLXLtOUuU8AA/6YH4vk4NnRAH 7ADeqLYRp3qhGkf0MzKhnNAHcFqbpG6tR8Mbx5xDvP+ImlrnRIw0HJtZA83LHYAkaN6o TfX+EfhJtf2pTywXUYVOPYvPalACqYwScFSaXSZfzuZaiF++AtmFe8nrA9pXgSYQG8eT eH855ldVQJXTo7zWfJtltcNFhz64B9HVq6rAq3aSrU8CuRtcoI1uUS61JKX8WPzgL/gu FXwA== 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=nwTYyQnrz6N9bLEoXnCl1nK/nqbsl7rSwitB1lj8ILs=; b=qmK0wKFrSUSX1H0dHCr1QkdyD39mhNEV+3jQtAR0pWZ0fp5flrgEQu7ngRB2E+lNsp 8k7qxrQWyLnEIp3JcUsbUs4GUPbOe1ySEc9RhRe097gP9puMgHBh+SdgKpllhDjruxd+ 20tCPKYtm+X95lZI18iljQinH9wfK02JUAWP7GWVOef9OGTJCaB61Zd4olIKW1nqLWhw +r9RQpJwjhVda3D7VqkGUZWFYupvskWE2vMBQeLJ2HVRhnnBuVXpsyikd6obC/VXrknv NBmrFduky9l9XfufjWEV0jyBZc5L++8EGoqLP/mCny5eQqDr28QDvbgyTwSSt2241sRM OijA== 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 u24si3861777edx.408.2020.07.27.07.05.08; Mon, 27 Jul 2020 07:05:31 -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 S1728508AbgG0NxK (ORCPT + 99 others); Mon, 27 Jul 2020 09:53:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:45812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727784AbgG0NxK (ORCPT ); Mon, 27 Jul 2020 09:53:10 -0400 Received: from oasis.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 1D508206E7; Mon, 27 Jul 2020 13:53:09 +0000 (UTC) Date: Mon, 27 Jul 2020 09:53:06 -0400 From: Steven Rostedt To: Oscar Carter Cc: Ingo Molnar , Kees Cook , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Jann Horn Subject: Re: [PATCH v2 2/2] kernel/trace: Remove function callback casts Message-ID: <20200727095306.7f369949@oasis.local.home> In-Reply-To: <20200726155148.GA9341@ubuntu> References: <20200719155033.24201-3-oscar.carter@gmx.com> <20200721140545.445f0258@oasis.local.home> <20200724161921.GA3123@ubuntu> <20200724123528.36ea9c9e@oasis.local.home> <20200724171418.GB3123@ubuntu> <20200724133656.76c75629@oasis.local.home> <20200724134020.3160dc7c@oasis.local.home> <20200724175500.GD3123@ubuntu> <20200724143457.27755412@oasis.local.home> <20200725150914.GA3362@ubuntu> <20200726155148.GA9341@ubuntu> 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 Sun, 26 Jul 2020 17:52:42 +0200 Oscar Carter wrote: > > If I try to do this I will need some help. Some info that point me to the > > right direction would be greatly appreciated. Some advice about what > > functions I will need to implement would be really helpfull. Or point me > > to the right piece of code that I can pick as base point. > > I've been searching and reading the code as much as possible. I've found > two patches that I think can be useful to guide me. One [1] adds support > for ftrace_ops to the riscv architecture. The other one [2] adds support > for ftrace_ops to the parisc architecture. > > [1] commit 71e736a7d655 ("riscv/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support") > [2] commit d562aca37a54 ("parisc/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support") > > Due to powerpc arch calls the needed functions from assembly, I based my > idea on the patch for the RISCV arch. > > Can something like the following work? > > diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h > index bc76970b6ee5..1c51ff5afae1 100644 > --- a/arch/powerpc/include/asm/ftrace.h > +++ b/arch/powerpc/include/asm/ftrace.h > @@ -61,9 +61,8 @@ struct dyn_arch_ftrace { > }; > #endif /* __ASSEMBLY__ */ > > -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > #define ARCH_SUPPORTS_FTRACE_OPS 1 > -#endif > + > #endif /* CONFIG_FUNCTION_TRACER */ > > #ifndef __ASSEMBLY__ > diff --git a/arch/powerpc/kernel/trace/ftrace_32.S b/arch/powerpc/kernel/trace/ftrace_32.S > index e023ae59c429..e69a4e945986 100644 > --- a/arch/powerpc/kernel/trace/ftrace_32.S > +++ b/arch/powerpc/kernel/trace/ftrace_32.S > @@ -29,6 +29,10 @@ _GLOBAL(ftrace_caller) > MCOUNT_SAVE_FRAME > /* r3 ends up with link register */ > subi r3, r3, MCOUNT_INSN_SIZE > + > + /* Set ftrace_ops (r5) to the global variable function_trace_op */ > + /* Set pt_regs (r6) to NULL */ > + > .globl ftrace_call > ftrace_call: > bl ftrace_stub > diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.S b/arch/powerpc/kernel/trace/ftrace_64_pg.S > index 6708e24db0ab..a741448b1df9 100644 > --- a/arch/powerpc/kernel/trace/ftrace_64_pg.S > +++ b/arch/powerpc/kernel/trace/ftrace_64_pg.S > @@ -22,6 +22,10 @@ _GLOBAL_TOC(ftrace_caller) > std r3, 128(r1) > ld r4, 16(r11) > subi r3, r3, MCOUNT_INSN_SIZE > + > + /* Set ftrace_ops (r5) to the global variable function_trace_op */ > + /* Set pt_regs (r6) to NULL */ I'm guessing you are going to do the above here. If so, this looks correct. > + > .globl ftrace_call > ftrace_call: > bl ftrace_stub > > To add support for ftrace_ops to the powerpc architecture is only necessary > to fill the r5 and r6 registers before the call to ftrace_stub in all the > cases. The register r5 is a pointer to ftrace_ops struct and the register > r6 is a pointer to pt_regs struct. These registers are the third and fourth > parameters of a function with the following prototype. The first and second > ones are yet set. I guess you mean that the first and second ones are already set. But, yeah, you are on the correct path here! > > void func(unsigned long ip, unsigned long parent_ip, > struct ftrace_ops *ops, struct pt_regs *regs); > > Am I in the right direction? or am I totally wrong? No, you don't look wrong. But the true test is to try it out :-) Don't forget to update ftrace_32.S as well. > > Thanks for your time and patience. My pleasure. Thanks for doing this. The more people that understand all this, the better! -- Steve