From patchwork Thu Jun 20 18:54:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen N Rao X-Patchwork-Id: 13706260 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558311B3732; Thu, 20 Jun 2024 18:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718909882; cv=none; b=OV1Pzx8rx7w5VMpjNEGNnKp6bmsk8xOOiou+p0BvsO3Vnw6kz8O8SsUis/KPHKU+Cy3E+Nr+Cuc3iqjvAMSBqObVn9idZoc+37sGXVJSgwb0mf2c2DU5jdycZZguHv0pKZsNe+06Ten8hm03ENQwiY3Y85QbZL1rGvcjGUnfDk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718909882; c=relaxed/simple; bh=Yw7BK5ZSzIqUwdH+xzRKsshvO4agK2xzXRxs7K0POPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOppXVWISrqmRZjnwbwTjxp4Y7YKpRSErmhW4ooNTsKwfXaSpbCmRiR6x5hnbGk0+sTPi/yOQGLLyGJdAWC47AO/LnZ6jm7OxQ1BkQoRP2F0VHImr6t3wHltlSdwYCsGPFPdTDl+Ukc37YY+FwS/yc0ao3QM5y0VYSFZniuy1cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p1/NCBMc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p1/NCBMc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7EF4C4AF09; Thu, 20 Jun 2024 18:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718909881; bh=Yw7BK5ZSzIqUwdH+xzRKsshvO4agK2xzXRxs7K0POPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1/NCBMcuf/tiIh5gQk0Z85r5aUjqLpNZZ765M6Okolc7A93+jEPXB7AfALdGz1Ne 2XgZbk5OTCZNP/cENXOoSWg9uwdIPAdkXhzmjL5HfcAicFmeqWZ1ePbOV9nVTCKXPz 5IFG0AKL70bRleX/YyT9dk0M+ha2g15MFBrJhHynCbIqLwcyXP1+9vF36Qf13jvmEH WTv53hh7KgBgYfXU6ycII0iF4/2r1yhceMvr5VZiGrTmdnDscIKWd5MAQyd5zhntlg OFgKp28QyKNbsYcam1Gshy3qK8CIBZKADmPTmv6x29EqiFOgRoybN8Ek7XujTULHCF D1VtBIJYobqQA== From: Naveen N Rao To: , , Cc: Michael Ellerman , Steven Rostedt , Masami Hiramatsu , Nicholas Piggin , Christophe Leroy , Masahiro Yamada , Mark Rutland , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Song Liu , Jiri Olsa Subject: [RFC PATCH v3 01/11] powerpc/kprobes: Use ftrace to determine if a probe is at function entry Date: Fri, 21 Jun 2024 00:24:04 +0530 Message-ID: <2cd04be69e90adc34bcf98d405ab6b21f268cb6a.1718908016.git.naveen@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-State: RFC 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, unless we are using pcrel. Acked-by: Masami Hiramatsu (Google) Signed-off-by: Naveen N Rao --- 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 14c5ddec3056..ca204f4f21c1 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; } -static bool arch_kprobe_on_func_entry(unsigned long offset) +static bool arch_kprobe_on_func_entry(unsigned long addr, unsigned long offset) { -#ifdef CONFIG_PPC64_ELF_ABI_V2 -#ifdef CONFIG_KPROBES_ON_FTRACE - return offset <= 16; -#else - return offset <= 8; -#endif -#else + unsigned long ip = ftrace_location(addr); + + if (ip) + return offset <= (ip - addr); + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && !IS_ENABLED(CONFIG_PPC_KERNEL_PCREL)) + return offset <= 8; return !offset; -#endif } /* 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 = arch_kprobe_on_func_entry(offset); + *on_func_entry = arch_kprobe_on_func_entry(addr, offset); return (kprobe_opcode_t *)(addr + offset); }