Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp801267lqj; Mon, 3 Jun 2024 00:36:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0Pa4UmWbj44k/WCcEZ93coMgi40VpbYfGJ85fCG4lFkz58M8b5j9xc261LDGtkgOUxXmWp3oLmTcgw9rRFXDQZMnFRCcTlq0FjJubIA== X-Google-Smtp-Source: AGHT+IFDtAlIl+Ch84ns79fufrpMlk1U2grASJbZX8TYgAX6AqRE4t+Lv8x9fI/x52VzFk961q7t X-Received: by 2002:a05:6214:4882:b0:6af:2a4e:140e with SMTP id 6a1803df08f44-6af2a4e154amr71007216d6.65.1717400203846; Mon, 03 Jun 2024 00:36:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717400203; cv=pass; d=google.com; s=arc-20160816; b=1FqFNpyl9iQIuyNF915CYm5nKjJz+FlKgcD5r3zWojgM47NFuPOPktyYk9ZasAL8tw xTev4zK5xv77JAUXKB6Lj9yqOQHLNO/x6USXzEOVxRb7UvOAGj1/t0GSMednj78Hd6P2 V56KAj09w/sDVLKKGpJ9lNTafReBTATm1Q3JcqW5hu+unf/uy+Xx8Db/Op/pvq61EXbU DsLVjjHw5Ty9n5CLPaVgMRgHFax3M/fzakuGilN2mq7gEF66S9gDq4xrQcUJt03w4hZv ODtB6kELXDXB98hmJMpZXJLafX7AUuBPThzFaOPzQwoAcZ1qbK8ArU+cIVuzr4PxZK35 ZJjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=XvMeJ9qUfGrGWKaPJ6Pt8CRvRqQgsC4DFzaoPHxUBoE=; fh=418OCDRnZXqlRXS/h6tPiuPh7X+EquTl0wlze+B2kSE=; b=Pe0vf97Uzf79nmHV5sUCxBr8M9KmdYOzehJUlDn3FOur2G9B4svPDpaP0kHOIZM3cM iFAVZYYGKph/cqhQTxxuVcpLHKj/diG3XB6xe0bWQD0Uqq6cXEVAaUsnhlyUDuY1qpkO PlyYMgu5uCJq+Y5rqZWPFvXPMDFf90OC1NgLLLkmEyP40ILTKUBgRE99Gc5FEgB63uak swn6A7eset0lRAHJyI3M2Fq+VxvdGF51zQbreurEt9obYbh0sZZ8M4agh6jt21/9fNll mfMl3yWMbMh8L8uegTsJxyeoZQBxNtR4/3fjNyNlin9M7BFRemiA0bmOuuJ2ySR2PUdL NBfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-198719-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4a7393f8si80801966d6.106.2024.06.03.00.36.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 00:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198719-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-198719-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8CC5F1C21EDA for ; Mon, 3 Jun 2024 07:36:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C647247A6C; Mon, 3 Jun 2024 07:36:37 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 7F7995025E for ; Mon, 3 Jun 2024 07:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717400197; cv=none; b=FpM0GSMKWsY4LL0leC9mkBRLpHWqOSzafNLBIXjogYef4aCFZZmaQYn1acNgomSO0iqjIg2LigQlWS4IDuv+6eO5J3ABjYROfx5RiLMdN80n3TSmfUSZnHODVXKWu1EEBivSa76g/nqZLCFGcMOCfsr7z0JPtPSNqtsmcIoFZPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717400197; c=relaxed/simple; bh=G/MXFcAbevnD2OMNzuTpAk/1J7svRArLtuFEReb3Z8w=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=QDLgbx70kL1M/glIe6Wp8NvkPTBcogx70NDuUr/GzQoqt0i7LVW7G189eqfwhG5ioXVwGw30lsz/jSEMcWqFvyTkk16+GIeNz7uGxCxXiMv+RvkiCvdBjTAoCvtBYaHWfEmOcvIikb6nUVdLXldNIeMW9jQMdPn/2yTYBI4D89o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500008.china.huawei.com (7.221.188.139) 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) */ -- 2.34.1