From patchwork Mon Jun 3 07:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13683361 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87957C25B75 for ; Mon, 3 Jun 2024 07:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=+7ClB9IMkzPtWwx4EwiNes/LA8KBhGVNc87RToKM2vE=; b=P4UlJjZCI9gEzT I1TwDv5VlYLGm7q+d7fF+LMlpKOLz1cyfIg1/ZNSrkhC1y1m3tiH4D1CcWCrY3tiOf74zRDELWJPs wuQbZksi0UnhC93yr0Cf4MVHhNZ/skmkmGqq9BMTAbSfszmHVQn7c7bwM+XBvVrsMozyuapvqyhHS lMKTQiMLbNc3TNRN/VS+zvU+IV0Az/vh3HKhPvedxRhGkrIM5Mqv5ehnXXh6HR56DE0Lb/+813aRH CMC5pB8jHgU87t+3HuiPRR7XXrqpi3WmOFFyRL0OTqW6bXjYlXs8oZFC4vltvXzGTgO/e9WM0rxmz Wpqr1+fG6F0AcL0B/llQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE2FC-0000000Fuda-3l7I; Mon, 03 Jun 2024 07:36:38 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE2F9-0000000Fua4-1bWm for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 07:36:37 +0000 Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Vt5691BQkz1JC47; Mon, 3 Jun 2024 15:32:33 +0800 (CST) Received: from kwepemi500008.china.huawei.com (unknown [7.221.188.139]) by mail.maildlp.com (Postfix) with ESMTPS id CD2D91400D7; Mon, 3 Jun 2024 15:36:26 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 15:36:26 +0800 From: Jinjie Ruan To: , , , , , , , , , , CC: Subject: [PATCH] ARM: Add HAVE_FUNCTION_ARG_ACCESS_API support Date: Mon, 3 Jun 2024 15:37:51 +0800 Message-ID: <20240603073751.2282024-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500008.china.huawei.com (7.221.188.139) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_003635_606631_890A47AA X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, kprobe on ARM32 can not use the '$argx' syntax available on other architecture. So implement regs_get_kernel_argument() and add HAVE_FUNCTION_ARG_ACCESS_API support. Before there is a following error: echo 'p:kprobe_submit_bio submit_bio bio=$arg1' > kprobe_events sh: write error: Invalid argument After: # echo 'p:kprobe_submit_bio submit_bio bio=$arg1' > kprobe_events # echo 1 > events/kprobes/enable # echo 1 > events/kprobes/kprobe_submit_bio/enable # echo 0 > tracing_on # echo > trace # echo 1 > tracing_on # cat trace kworker/u19:0-36 [002] d.... 54.175322: kprobe_submit_bio: (submit_bio+0x0/0xf8) bio=0xc24e6000 Signed-off-by: Jinjie Ruan --- arch/arm/Kconfig | 1 + arch/arm/include/asm/ptrace.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index ee5115252aac..4ed504139763 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -102,6 +102,7 @@ config ARM select HAVE_EXIT_THREAD select HAVE_GUP_FAST if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL + select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_FUNCTION_ERROR_INJECTION select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 6eb311fb2da0..da5dd4cd0324 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -52,6 +52,28 @@ struct svc_pt_regs { #define fast_interrupts_enabled(regs) \ (!((regs)->ARM_cpsr & PSR_F_BIT)) +/** + * regs_get_kernel_argument() - get Nth function argument in kernel + * @regs: pt_regs of that context + * @n: function argument number (start from 0) + * + * regs_get_argument() returns @n th argument of the function call. + * + * Note that this chooses the most likely register mapping. In very rare + * cases this may not return correct data, for example, if one of the + * function parameters is 16 bytes or bigger. In such cases, we cannot + * get access the parameter correctly and the register assignment of + * subsequent parameters will be shifted. + */ +static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, + unsigned int n) +{ +#define NR_REG_ARGUMENTS 4 + if (n < NR_REG_ARGUMENTS) + return regs->uregs[n]; + return 0; +} + /* Are the current registers suitable for user mode? * (used to maintain security in signal handlers) */