From patchwork Fri Apr 12 14:22:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 10898491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC8D1708 for ; Fri, 12 Apr 2019 14:22:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 900051FF40 for ; Fri, 12 Apr 2019 14:22:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 811CB28678; Fri, 12 Apr 2019 14:22:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 29AEF1FF40 for ; Fri, 12 Apr 2019 14:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject: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=Q46OQst5zovmaPgK/G3azOUwrMEvxaoMlWe4liFljiw=; b=pgULjTKcFft+LJ iijGnCwEDJhsBUCoKyX5Hfk+7uZL8ntuoHtqTKACmADOk8V46W9IaHLOHIgB3qdlfdU2OAhZiWbB9 2+n2CzDHH1i6TO+uyf8NIu0b6S+dhxMLCktOLKjEG6sKOBJ3nNKmhdYgWx0efVhOmGU5gMwaSlBAZ Ug02wQCi7xzXaXBTDdv7Q1AU+894DRibiBXzCP9Mg8ItqaCewog1bBpmEDdYG5w8YANzFWqV+Q/vG 6Ej1NxU8M6McRzXVQlHHytndljmwB2Wp9YHNMI8d91AHjFp2PFri6m7eSP0c1v89+/+IbUvex/gyn mZeOoQzziJHGa95sJmdw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEx4M-0001Ga-Ll; Fri, 12 Apr 2019 14:22:18 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEx4J-0001GH-Vs for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2019 14:22:17 +0000 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A96720818; Fri, 12 Apr 2019 14:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555078935; bh=mi+DUCtbq6rqfEJEbag8BIlmPlnfRJ9C7A7zk90Khk0=; h=From:To:Cc:Subject:Date:From; b=PY366o9/zzcJs1ULv8vt780nLvoF18zBPy+DJeDBAqZxhrUJTgS3mSHLmEibQh82s 3XdegsOJXmdF3a+/MdHoPzO01ht5Ed1dZtwM8Jk5KdLeXm/yS3WVmEAwMl3wKphksc t9jmnGoUvGoDwGzQXpFYIisLdkNiHO1CjofeOkf4= From: Masami Hiramatsu To: Catalin Marinas , Will Deacon Subject: [PATCH v2] arm64: ptrace: Add function argument access API Date: Fri, 12 Apr 2019 23:22:01 +0900 Message-Id: <155507892154.27222.12993546518496163452.stgit@devnote2> X-Mailer: git-send-email 2.17.1 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190412_072216_045795_008A35BE X-CRM114-Status: GOOD ( 12.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhiramat@kernel.org, Steven Rostedt , Oleg Nesterov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add regs_get_argument() which returns N th argument of the function call. On arm64, it supports up to 8th argument. Note that this chooses most probably assignment, in some case it can be incorrect (e.g. passing data structure or floating point etc.) This enables ftrace kprobe events to access kernel function arguments via $argN syntax. Signed-off-by: Masami Hiramatsu --- Changes in v2: - Use pt_regs_read_reg() - Update comment for the incorrect corner case. --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ptrace.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7e34b9eba5de..dad972cb8b65 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -148,6 +148,7 @@ config ARM64 select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_REGS_AND_STACK_ACCESS_API + select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_RCU_TABLE_FREE select HAVE_RCU_TABLE_INVALIDATE select HAVE_RSEQ diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index ec60174c8c18..2038dca1e2c2 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -305,6 +305,28 @@ static inline unsigned long regs_return_value(struct pt_regs *regs) return regs->regs[0]; } +/** + * 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 most probably assignment. In very rare case + * this may not return correct data, for example, one of the function + * parameter is 16bytes (128bits) or bigger. In such case, we can not + * get that big parameter correctly, but also register assignment of + * parameters after that will be shifted. + */ +static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, + unsigned int n) +{ +#define NR_REG_ARGUMENTS 8 + if (n < NR_REG_ARGUMENTS) + return pt_regs_read_reg(regs, n); + return 0; +} + /* We must avoid circular header include via sched.h */ struct task_struct; int valid_user_regs(struct user_pt_regs *regs, struct task_struct *task);