From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A8FAC4360F for ; Wed, 3 Apr 2019 12:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 036F02084B for ; Wed, 3 Apr 2019 12:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbfDCMGy (ORCPT ); Wed, 3 Apr 2019 08:06:54 -0400 Received: from foss.arm.com ([217.140.101.70]:38776 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbfDCMGy (ORCPT ); Wed, 3 Apr 2019 08:06:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 803C880D; Wed, 3 Apr 2019 05:06:53 -0700 (PDT) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C2213F59C; Wed, 3 Apr 2019 05:06:52 -0700 (PDT) Date: Wed, 3 Apr 2019 13:06:49 +0100 From: Will Deacon To: Masami Hiramatsu Cc: Catalin Marinas , Steven Rostedt , Oleg Nesterov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: ptrace: Add function argument access API Message-ID: <20190403120649.GB29409@fuggles.cambridge.arm.com> References: <155289594227.10570.1879705446198840331.stgit@devnote2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155289594227.10570.1879705446198840331.stgit@devnote2> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 18, 2019 at 04:59:02PM +0900, Masami Hiramatsu wrote: > 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 > --- > arch/arm64/Kconfig | 1 + > arch/arm64/include/asm/ptrace.h | 18 ++++++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 117b2541ef3d..6ba0da4be73c 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..cfa1bc9b8b70 100644 > --- a/arch/arm64/include/asm/ptrace.h > +++ b/arch/arm64/include/asm/ptrace.h > @@ -305,6 +305,24 @@ 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 some case > + * it can be incorrect. In which cases would it be incorrect? I can imagine varargs causing problems, but are there others? > +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 regs_get_register(regs, n << 3); You can use pt_regs_read_reg() to avoid the shift here. Will From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF71C4360F for ; Wed, 3 Apr 2019 12:07:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1A21220830 for ; Wed, 3 Apr 2019 12:07:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PhN+l0Yr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A21220830 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=asnXv9IBa8V8YjXoSsfIlaq+RRtQXCGq/6sSVfEF7p0=; b=PhN+l0YrSrlUt5 8JXDQ5sMCXmLzYPw+UZ2cACGOHIssJfrjITTOzCYykt2ykYBoEhVyXewnQXTKvWUVxjw+pUIoHEZS eRrauZiALpyOAuXRkcCt4PttQnAdWu4spEkSebG2g/HD/5dZBb6kb8RYQBDn+dRH2xINPk9DoAgEQ wi9W/ghnBbyay/TKphIdYTgY613ZUhIo0HAuax2fx7y+jnfeKgwUG0T5US9wTdCpLJd9SE9mqBrKz /NfLVPSIDYdrMenW5tPoIcQ+Je+3YkbkDgkz4fqm7//j7FhVRBwROYNcfGneGlZclBchvo3zUUGHi 0wHGcTHDWnd9w2jX5jLg==; 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 1hBefS-00015m-Nm; Wed, 03 Apr 2019 12:06:58 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBefQ-00015J-2C for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2019 12:06:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 803C880D; Wed, 3 Apr 2019 05:06:53 -0700 (PDT) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C2213F59C; Wed, 3 Apr 2019 05:06:52 -0700 (PDT) Date: Wed, 3 Apr 2019 13:06:49 +0100 From: Will Deacon To: Masami Hiramatsu Subject: Re: [PATCH] arm64: ptrace: Add function argument access API Message-ID: <20190403120649.GB29409@fuggles.cambridge.arm.com> References: <155289594227.10570.1879705446198840331.stgit@devnote2> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <155289594227.10570.1879705446198840331.stgit@devnote2> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_050656_110808_1AACE56B X-CRM114-Status: GOOD ( 19.91 ) 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, Catalin Marinas , Oleg Nesterov , Steven Rostedt , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Mar 18, 2019 at 04:59:02PM +0900, Masami Hiramatsu wrote: > 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 > --- > arch/arm64/Kconfig | 1 + > arch/arm64/include/asm/ptrace.h | 18 ++++++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 117b2541ef3d..6ba0da4be73c 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..cfa1bc9b8b70 100644 > --- a/arch/arm64/include/asm/ptrace.h > +++ b/arch/arm64/include/asm/ptrace.h > @@ -305,6 +305,24 @@ 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 some case > + * it can be incorrect. In which cases would it be incorrect? I can imagine varargs causing problems, but are there others? > +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 regs_get_register(regs, n << 3); You can use pt_regs_read_reg() to avoid the shift here. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel