From: "Björn Töpel" <bjorn@kernel.org>
To: Chen Guokai <chenguokai17@mails.ucas.ac.cn>,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, rostedt@goodmis.org, mingo@redhat.com,
sfr@canb.auug.org.au
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
liaochang1@huawei.com,
Chen Guokai <chenguokai17@mails.ucas.ac.cn>,
Heiko Stuebner <heiko.stuebner@vrull.eu>
Subject: Re: [PATCH v6 04/13] riscv/kprobe: Add common RVI and RVC instruction decoder code
Date: Wed, 01 Feb 2023 14:29:44 +0100 [thread overview]
Message-ID: <87y1phtsxj.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20230127130541.1250865-5-chenguokai17@mails.ucas.ac.cn>
Chen Guokai <chenguokai17@mails.ucas.ac.cn> writes:
> From: Liao Chang <liaochang1@huawei.com>
>
> These RVI and RVC instruction decoder are used in the free register
> searching algorithm, each instruction of instrumented function needs to
> decode and test if it contains a free register to form AUIPC/JALR.
>
> For RVI instruction format, the position and length of rs1/rs2/rd/opcode
> parts are uniform [1], but RVC instruction formats are complicated, so
> it addresses a series of functions to decode rs1/rs2/rd for RVC [1].
>
> [1] https://github.com/riscv/riscv-isa-manual/releases
>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Co-developed-by: Chen Guokai <chenguokai17@mails.ucas.ac.cn>
> Signed-off-by: Chen Guokai <chenguokai17@mails.ucas.ac.cn>
> ---
> arch/riscv/include/asm/bug.h | 5 +-
> arch/riscv/kernel/probes/decode-insn.h | 148 +++++++++++++++++++++++
> arch/riscv/kernel/probes/simulate-insn.h | 42 +++++++
> 3 files changed, 194 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
> index 1aaea81fb141..9c33d3b58225 100644
> --- a/arch/riscv/include/asm/bug.h
> +++ b/arch/riscv/include/asm/bug.h
> @@ -19,11 +19,14 @@
> #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
> #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
>
> +#define RVI_INSN_LEN 4UL
> +#define RVC_INSN_LEN 2UL
> +
> #define GET_INSN_LENGTH(insn) \
> ({ \
> unsigned long __len; \
> __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
> - 4UL : 2UL; \
> + RVI_INSN_LEN : RVC_INSN_LEN; \
> __len; \
> })
>
> diff --git a/arch/riscv/kernel/probes/decode-insn.h b/arch/riscv/kernel/probes/decode-insn.h
> index 42269a7d676d..785b023a62ea 100644
> --- a/arch/riscv/kernel/probes/decode-insn.h
> +++ b/arch/riscv/kernel/probes/decode-insn.h
> @@ -3,6 +3,7 @@
> #ifndef _RISCV_KERNEL_KPROBES_DECODE_INSN_H
> #define _RISCV_KERNEL_KPROBES_DECODE_INSN_H
>
> +#include <linux/bitops.h>
> #include <asm/sections.h>
> #include <asm/kprobes.h>
>
> @@ -15,4 +16,151 @@ enum probe_insn {
> enum probe_insn __kprobes
> riscv_probe_decode_insn(probe_opcode_t *addr, struct arch_probe_insn *asi);
>
> +#ifdef CONFIG_KPROBES
No reason to hide the static inlines behind an ifdef; Leave it out, so
it's less likely that code breaks slip through.
I wonder if these functions below would make more sense in the
asm/insn.h, where riscv_insn_is_##name live (which you're using in later
patches). Heiko (Cc'd) recently did a big clean up there, which probably
apply to the code below.
> +
> +static inline u16 rvi_rs1(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 15) & 0x1f);
> +}
> +
> +static inline u16 rvi_rs2(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 20) & 0x1f);
> +}
> +
> +static inline u16 rvi_rd(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 7) & 0x1f);
> +}
> +
> +static inline s32 rvi_branch_imme(kprobe_opcode_t opcode)
> +{
> + u32 imme = 0;
> +
> + imme |= (((opcode >> 8) & 0xf) << 1) |
> + (((opcode >> 25) & 0x3f) << 5) |
> + (((opcode >> 7) & 0x1) << 11) |
> + (((opcode >> 31) & 0x1) << 12);
> +
> + return sign_extend32(imme, 13);
> +}
> +
> +static inline s32 rvi_jal_imme(kprobe_opcode_t opcode)
> +{
> + u32 imme = 0;
> +
> + imme |= (((opcode >> 21) & 0x3ff) << 1) |
> + (((opcode >> 20) & 0x1) << 11) |
> + (((opcode >> 12) & 0xff) << 12) |
> + (((opcode >> 31) & 0x1) << 20);
> +
> + return sign_extend32(imme, 21);
> +}
> +
> +#ifdef CONFIG_RISCV_ISA_C
Dito. Just get rid of the ifdef clutter.
Björn
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: "Björn Töpel" <bjorn@kernel.org>
To: Chen Guokai <chenguokai17@mails.ucas.ac.cn>,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, rostedt@goodmis.org, mingo@redhat.com,
sfr@canb.auug.org.au
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
liaochang1@huawei.com,
Chen Guokai <chenguokai17@mails.ucas.ac.cn>,
Heiko Stuebner <heiko.stuebner@vrull.eu>
Subject: Re: [PATCH v6 04/13] riscv/kprobe: Add common RVI and RVC instruction decoder code
Date: Wed, 01 Feb 2023 14:29:44 +0100 [thread overview]
Message-ID: <87y1phtsxj.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20230127130541.1250865-5-chenguokai17@mails.ucas.ac.cn>
Chen Guokai <chenguokai17@mails.ucas.ac.cn> writes:
> From: Liao Chang <liaochang1@huawei.com>
>
> These RVI and RVC instruction decoder are used in the free register
> searching algorithm, each instruction of instrumented function needs to
> decode and test if it contains a free register to form AUIPC/JALR.
>
> For RVI instruction format, the position and length of rs1/rs2/rd/opcode
> parts are uniform [1], but RVC instruction formats are complicated, so
> it addresses a series of functions to decode rs1/rs2/rd for RVC [1].
>
> [1] https://github.com/riscv/riscv-isa-manual/releases
>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Co-developed-by: Chen Guokai <chenguokai17@mails.ucas.ac.cn>
> Signed-off-by: Chen Guokai <chenguokai17@mails.ucas.ac.cn>
> ---
> arch/riscv/include/asm/bug.h | 5 +-
> arch/riscv/kernel/probes/decode-insn.h | 148 +++++++++++++++++++++++
> arch/riscv/kernel/probes/simulate-insn.h | 42 +++++++
> 3 files changed, 194 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
> index 1aaea81fb141..9c33d3b58225 100644
> --- a/arch/riscv/include/asm/bug.h
> +++ b/arch/riscv/include/asm/bug.h
> @@ -19,11 +19,14 @@
> #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
> #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
>
> +#define RVI_INSN_LEN 4UL
> +#define RVC_INSN_LEN 2UL
> +
> #define GET_INSN_LENGTH(insn) \
> ({ \
> unsigned long __len; \
> __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
> - 4UL : 2UL; \
> + RVI_INSN_LEN : RVC_INSN_LEN; \
> __len; \
> })
>
> diff --git a/arch/riscv/kernel/probes/decode-insn.h b/arch/riscv/kernel/probes/decode-insn.h
> index 42269a7d676d..785b023a62ea 100644
> --- a/arch/riscv/kernel/probes/decode-insn.h
> +++ b/arch/riscv/kernel/probes/decode-insn.h
> @@ -3,6 +3,7 @@
> #ifndef _RISCV_KERNEL_KPROBES_DECODE_INSN_H
> #define _RISCV_KERNEL_KPROBES_DECODE_INSN_H
>
> +#include <linux/bitops.h>
> #include <asm/sections.h>
> #include <asm/kprobes.h>
>
> @@ -15,4 +16,151 @@ enum probe_insn {
> enum probe_insn __kprobes
> riscv_probe_decode_insn(probe_opcode_t *addr, struct arch_probe_insn *asi);
>
> +#ifdef CONFIG_KPROBES
No reason to hide the static inlines behind an ifdef; Leave it out, so
it's less likely that code breaks slip through.
I wonder if these functions below would make more sense in the
asm/insn.h, where riscv_insn_is_##name live (which you're using in later
patches). Heiko (Cc'd) recently did a big clean up there, which probably
apply to the code below.
> +
> +static inline u16 rvi_rs1(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 15) & 0x1f);
> +}
> +
> +static inline u16 rvi_rs2(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 20) & 0x1f);
> +}
> +
> +static inline u16 rvi_rd(kprobe_opcode_t opcode)
> +{
> + return (u16)((opcode >> 7) & 0x1f);
> +}
> +
> +static inline s32 rvi_branch_imme(kprobe_opcode_t opcode)
> +{
> + u32 imme = 0;
> +
> + imme |= (((opcode >> 8) & 0xf) << 1) |
> + (((opcode >> 25) & 0x3f) << 5) |
> + (((opcode >> 7) & 0x1) << 11) |
> + (((opcode >> 31) & 0x1) << 12);
> +
> + return sign_extend32(imme, 13);
> +}
> +
> +static inline s32 rvi_jal_imme(kprobe_opcode_t opcode)
> +{
> + u32 imme = 0;
> +
> + imme |= (((opcode >> 21) & 0x3ff) << 1) |
> + (((opcode >> 20) & 0x1) << 11) |
> + (((opcode >> 12) & 0xff) << 12) |
> + (((opcode >> 31) & 0x1) << 20);
> +
> + return sign_extend32(imme, 21);
> +}
> +
> +#ifdef CONFIG_RISCV_ISA_C
Dito. Just get rid of the ifdef clutter.
Björn
next prev parent reply other threads:[~2023-02-01 13:30 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 13:05 [PATCH v6 00/13] Add OPTPROBES feature on RISCV Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 01/13] riscv/kprobe: Prepare the skeleton to implement RISCV OPTPROBES Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 02/13] riscv/kprobe: Allocate detour buffer from module region Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 03/13] riscv/kprobe: Add skeleton for preparing optimized kprobe Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 04/13] riscv/kprobe: Add common RVI and RVC instruction decoder code Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:29 ` Björn Töpel [this message]
2023-02-01 13:29 ` Björn Töpel
2023-02-02 10:16 ` Conor Dooley
2023-02-02 10:16 ` Conor Dooley
2023-01-27 13:05 ` [PATCH v6 05/13] riscv/kprobe: Introduce free register(s) searching algorithm Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 06/13] riscv/kprobe: Add code to check if kprobe can be optimized Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:30 ` Björn Töpel
2023-02-01 13:30 ` Björn Töpel
2023-01-27 13:05 ` [PATCH v6 07/13] riscv/kprobe: Prepare detour buffer for optimized kprobe Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:30 ` Björn Töpel
2023-02-01 13:30 ` Björn Töpel
2023-01-27 13:05 ` [PATCH v6 08/13] riscv/kprobe: Patch AUIPC/JALR pair to optimize kprobe Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:31 ` Björn Töpel
2023-02-01 13:31 ` Björn Töpel
2023-01-27 13:05 ` [PATCH v6 09/13] riscv/kprobe: Search free registers from unused caller-saved ones Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:31 ` Björn Töpel
2023-02-01 13:31 ` Björn Töpel
2023-02-02 9:08 ` Conor Dooley
2023-02-02 9:08 ` Conor Dooley
2023-01-27 13:05 ` [PATCH v6 10/13] riscv/kprobe: Add instruction boundary check for RVI/RVC hybrid kernel Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-27 13:05 ` [PATCH v6 11/13] riscv/kprobe: Fix instruction simulation of JALR Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-31 12:51 ` Björn Töpel
2023-01-31 12:51 ` Björn Töpel
2023-01-27 13:05 ` [PATCH v6 12/13] riscv/kprobe: Move exception related symbols to .kprobe_blacklist Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-02-01 13:30 ` Björn Töpel
2023-02-01 13:30 ` Björn Töpel
2023-01-27 13:05 ` [PATCH v6 13/13] selftest/kprobes: Add testcase for kprobe SYM[+offs] Chen Guokai
2023-01-27 13:05 ` Chen Guokai
2023-01-30 12:31 ` [PATCH v6 00/13] Add OPTPROBES feature on RISCV Björn Töpel
2023-01-30 12:31 ` Björn Töpel
2023-01-30 14:38 ` Xim
2023-01-30 14:38 ` Xim
2023-04-26 18:01 ` Palmer Dabbelt
2023-04-26 18:01 ` Palmer Dabbelt
2023-02-01 13:29 ` Björn Töpel
2023-02-01 13:29 ` Björn Töpel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y1phtsxj.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=chenguokai17@mails.ucas.ac.cn \
--cc=heiko.stuebner@vrull.eu \
--cc=liaochang1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rostedt@goodmis.org \
--cc=sfr@canb.auug.org.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.