From nobody Tue Dec 16 18:29:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D76FC10F05 for ; Fri, 8 Dec 2023 16:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574217AbjLHQfe (ORCPT ); Fri, 8 Dec 2023 11:35:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbjLHQfY (ORCPT ); Fri, 8 Dec 2023 11:35:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969311995 for ; Fri, 8 Dec 2023 08:35:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3D15C433CA; Fri, 8 Dec 2023 16:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702053322; bh=Z4H+/v658tdpIUS/M5eM4mkmmspGMz1KhbqU6pOZF5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qErDFEmodD4DDHqqZIhdZcw0R/xgNXnvkXsREwRbPKKokGq2qG2xZUkfREtkgqGnA 4g84nEMw28/wbN9hRCzkZPhe6Y5ZKK3qerh7amZTHf9IZt+IiARhqVLNQC5j6Z8LoG F1Smct9Ycj0BSKp8chdrfrR9LExLy9vL0FIz1AvGHUJb4Dw9KnAlIkDzfl+sELiG3+ B43QVHxSh3P4pn4Epgg+Cvx/CPHy4DBXdlZkgSFdGN3u8Q+2DjbVyjdupIX7QmqBdV Z8klsrgLmfc8dE0QjCKTTOeln31fMuYCkbfVP3mZDbMPdKhvUQ89P81GHQAuV2t2HA Vx0ZkALRS12pA== From: Naveen N Rao To: , Cc: Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , Steven Rostedt , Mark Rutland , Florent Revest , Masami Hiramatsu Subject: [RFC PATCH 5/9] powerpc/kprobes: Use ftrace to determine if a probe is at function entry Date: Fri, 8 Dec 2023 22:00:44 +0530 Message-ID: <15f0b3a2e72326423cfb4ce4e89afff540042245.1702045299.git.naveen@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rather than hard-coding the offset into a function to be used to determine if a kprobe is at function entry, use ftrace_location() to determine the ftrace location within the function and categorize all instructions till that offset to be function entry. For functions that cannot be traced, we fall back to using a fixed offset of 8 (two instructions) to categorize a probe as being at function entry for 64-bit elfv2. Signed-off-by: Naveen N Rao Acked-by: Masami Hiramatsu (Google) --- arch/powerpc/kernel/kprobes.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index b20ee72e873a..42665dfab59e 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -105,24 +105,22 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name,= unsigned int offset) return addr; } =20 -static bool arch_kprobe_on_func_entry(unsigned long offset) +static bool arch_kprobe_on_func_entry(unsigned long addr, unsigned long of= fset) { -#ifdef CONFIG_PPC64_ELF_ABI_V2 -#ifdef CONFIG_KPROBES_ON_FTRACE - return offset <=3D 16; -#else - return offset <=3D 8; -#endif -#else + unsigned long ip =3D ftrace_location(addr); + + if (ip) + return offset <=3D (ip - addr); + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) + return offset <=3D 8; return !offset; -#endif } =20 /* XXX try and fold the magic of kprobe_lookup_name() in this */ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long= offset, bool *on_func_entry) { - *on_func_entry =3D arch_kprobe_on_func_entry(offset); + *on_func_entry =3D arch_kprobe_on_func_entry(addr, offset); return (kprobe_opcode_t *)(addr + offset); } =20 --=20 2.43.0