Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4911422pxv; Tue, 6 Jul 2021 12:12:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSI+Mj+IECDS7NqmSRNXT5G9d05Ut+4lZHZuwzp9dZA9oaPTsOW+WUkm7xJ0BfOCoXARNf X-Received: by 2002:a17:906:edc9:: with SMTP id sb9mr5074987ejb.99.1625598729239; Tue, 06 Jul 2021 12:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625598729; cv=none; d=google.com; s=arc-20160816; b=uy2Wn/D5l5q1Qs5pbxoK03lGEze4WJFFUKgfK18i+zA2rkJZN1zo+oB4/CgYIhbhwA Q2BAm8adPECuHDr3JxB03TSwg2n48me/ZC1lvJgsdCT/el61MTKIJUvIMdXdp1gyBSs/ 64qs+Nx1DDlI4K9tZe8nwxbUMkpuh9B/Ao4RX7QNQR/UvqYQvWBJcnT3R9GGBuv3ROb5 wt7s8W6wxrkp/S3SIXl6Rx4msrkGL7zNHz7FxnlVVUNZPOMHffYsCrGzPowJy54Eaayy jsiYuQeybICaNbrfsSP76tKQjKbCSp7tc6sXubCVqorv5atiOFZJ37U5yuXrXbOsFOZa Vxfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=7oV0ZSYNnlAyW14j31IWfCZB8bVAKuRWNWStdCvUjXk=; b=lNmhQA9OQdnfTM8VnOy+gG5TBAuFlYdhR/U1gxh7b3w7y4DBwkVxH2/JTnaffr/4KK C/krlU8231/dOZzdJwWeaceiJjhUK38OL+16jTR70tBAbkmvlDto7CWOfoWkzOG937gI 43+g+z4zllVlG1m5WB8meLvMK+E7kRKULHYHfqCD2Y8w/Oz1xE35o1kkpfqH0oCzzGtG /c3UYa1e3o5oOjVm4l5hLj5hJPU2lKGhsrtjviZ+kXtTIxw0ZTlGm1fOyYVWJk7b77Je mtn3ojAjh9geQQ9/jYKkvQ/VaEy+aAKwZxh/TNG5dXfTwZQcIfw5ejbw9mP0xE2xH+G0 KrLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=UMIqyKcc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l24si15121595eds.399.2021.07.06.12.11.45; Tue, 06 Jul 2021 12:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=UMIqyKcc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbhGFTNR (ORCPT + 99 others); Tue, 6 Jul 2021 15:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbhGFTNQ (ORCPT ); Tue, 6 Jul 2021 15:13:16 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18540C061574 for ; Tue, 6 Jul 2021 12:10:38 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id c15so12561832pls.13 for ; Tue, 06 Jul 2021 12:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=7oV0ZSYNnlAyW14j31IWfCZB8bVAKuRWNWStdCvUjXk=; b=UMIqyKccdlLQQtwLZRueSGdJSYkBbZanLIGTHewjAej8JLIdemHkSMMy5gMgXk/m/b Jp+mPza1E9qaXU5/iw7h5FpCuEmNQ9L4qh8LK4ngKQfT9L5vukiPi/0R/k2Q+I2x0D6S DxIHQW3R3NmTu8lkxTo5kGdEqfbYWwAuBLIrGCQ++Y7OPyEns/A0naSezlybAftna0l4 NmEKIqCyBWNe3O3/4UTYG/cVBmUT1v2ZG15N2dEI+PqDB5O0VNRWOKhAesA4b2TBlTXW gajNoBI94sPMsm3h1o3ykAJvvg9fGao+uqxKACvZKqm/4bVVVkBcwzK8TlVIn82dzG+H 3YNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=7oV0ZSYNnlAyW14j31IWfCZB8bVAKuRWNWStdCvUjXk=; b=C0fPUyyRR1YcF4e90WPg9h4JrEWPiihmptZMPq51xruKH9PbyPky5rrB/UpZPAhevy CLcEg4Ckfr2tDtEhxhV83Aq+Ekr6GpNYRxoOFTp01GnQfCMo37k2hsp5N6gIsNlu6URZ UUsLwr3/+gqAuwHQhmew+I7yEI5UaqDhv/uhl20vNSBOCth750jokElhlnZfdCHcQLHd P+W/vcOcMTqfPRfTcAm9TejCD6znQN/lNZvqPUgbxCJifYIx3gA/fZIHXxQfctZiQIwM zYF9lDVFLqq468dSF4OmPATAHxnlXkHo/dW9EOOy6wcHlFdNM+cQzTB2MDtPZQjlQw+D XCrw== X-Gm-Message-State: AOAM5312TctGrATBc+ri8yeuO4lmcuY15Ww2fqZSN+RSvPPxX7OnuAqh OR4dJlv7x9Fg+uMIeuZriyeR1g== X-Received: by 2002:a17:902:da85:b029:129:b7a8:6ef8 with SMTP id j5-20020a170902da85b0290129b7a86ef8mr2201073plx.77.1625598637479; Tue, 06 Jul 2021 12:10:37 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id 30sm4311085pgq.31.2021.07.06.12.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 12:10:36 -0700 (PDT) Date: Tue, 06 Jul 2021 12:10:36 -0700 (PDT) X-Google-Original-Date: Mon, 05 Jul 2021 20:54:20 PDT (-0700) Subject: Re: [PATCH] riscv: ptrace: add argn syntax In-Reply-To: <20210620120151.17860-1-huan.xie@suse.com> CC: oleg@redhat.com, Paul Walmsley , caou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, chongguiguzi@gmail.com, huan.xie@suse.com From: Palmer Dabbelt To: chongguiguzi@gmail.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 20 Jun 2021 05:01:51 PDT (-0700), chongguiguzi@gmail.com wrote: > This enables ftrace kprobe events to access kernel function > arguments via $argN syntax. > > Signed-off-by: Jeff Xie > --- > arch/riscv/Kconfig | 1 + > arch/riscv/include/asm/ptrace.h | 31 +++++++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 18ec0f9bb8d5..f9246a7d0a31 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -88,6 +88,7 @@ config RISCV > 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_STACKPROTECTOR > select HAVE_SYSCALL_TRACEPOINTS > select IRQ_DOMAIN > diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h > index 09ad4e923510..fdb59ee405ee 100644 > --- a/arch/riscv/include/asm/ptrace.h > +++ b/arch/riscv/include/asm/ptrace.h > @@ -141,6 +141,37 @@ static inline unsigned long regs_get_register(struct pt_regs *regs, > > return *(unsigned long *)((unsigned long)regs + offset); > } > + > +/** > + * 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 you can get the parameter correctly if the function has no > + * more than eight arguments. > + */ > +static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, > + unsigned int n) > +{ > +#define NR_REG_ARGUMENTS 8 > + static const unsigned int argument_offs[] = { > + offsetof(struct pt_regs, a0), > + offsetof(struct pt_regs, a1), > + offsetof(struct pt_regs, a2), > + offsetof(struct pt_regs, a3), > + offsetof(struct pt_regs, a4), > + offsetof(struct pt_regs, a5), > + offsetof(struct pt_regs, a6), > + offsetof(struct pt_regs, a7), > + }; > + > + if (n < NR_REG_ARGUMENTS) > + return regs_get_register(regs, argument_offs[n]); > + return 0; > +} > + > #endif /* __ASSEMBLY__ */ > > #endif /* _ASM_RISCV_PTRACE_H */ This is on for-next. I cleaned it up a bit to avoid leaking that #define.