From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0B463AD5E for ; Sun, 11 May 2025 21:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998293; cv=none; b=Lg8v9oZaeqJGoBaaiP1rTvED6wTG/YiYj30t+B7FNaCfzMDOCqChv9S9axV6rb0AdxW5ZlGXzKcQArwSL1zx26TU20UKI2uXIKbuS5w7t0poIOVGXyMtmWGdEquR+IFR183TxAVaIBtlC0uhhdRr4uHNxfvdlUVz9jnKNxai524= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998293; c=relaxed/simple; bh=AT0dkOt/V1S66J9dhOa+5gRvtd4XTG+pS1fF9RBhuvY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C4LRGLcT5RYmb80efxivnu9JvJ7XgHQn6HL5h7asRLz9cEHh43gSyODfCa+RlyC4hbe7pzZZkARV07CtiW99oIEOlh4BTP8sM/vcJamfIqOqlGlVjf3XZ1nHpkAjHAL9iR4vWHi6HK3ZGEba1vZkmvOtw3Og1fVoctRkM2yxNu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LVjSERZI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=X6YpUcis; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LVjSERZI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X6YpUcis" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwAuKW9kYlwuhZ5fc51sK5eAF9d1ZLTlSnKrLdUvZZk=; b=LVjSERZIAXGi22PyvdSZ4AXHI3XMv7ggJRB2peVblR9jQ1xAMGR752ODWGl1DkIseOHZke 1DmjgWIITxKkjtOUc+21cTY9nlTU1YXpHYvjeBJBmZohCwfY2pgTwitBcwNss0WBkfZvbI maV6N7U1dRuaBW0g9gxv3lZz1Y6e5FZtAwLqpI/6r5/thQLh1q1jFpdTRbop8E5/6vs8jz 7T4g/2A2x/reCHXOgWP+iZz9z2YA0BRcJqmp061s+VSIvTYX2+zyBY+5nd29T6p9coqRiP 3ev+MQqT1IgkY/vfRpWOSFxgdS0SikmH75qNGcTBtJoR+/m73oF1P9n2iny3jQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwAuKW9kYlwuhZ5fc51sK5eAF9d1ZLTlSnKrLdUvZZk=; b=X6YpUcismhvYvjjnS46wn+ipr1NoAFmJQmte/QBn4TYKLoWWOX/I47cAm9Z2ka2mwX5zVf /FKEZDpSjaB8ZJBQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 01/11] riscv: kprobes: Move branch_rs2_idx to insn.h Date: Sun, 11 May 2025 23:17:53 +0200 Message-Id: <9b528d3c1de5291d1540b3617e63d40b9889c88f.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Similar to other instruction-processing macros/functions, branch_rs2_idx should be in insn.h. Move it into insn.h as RV_EXTRACT_RS2_REG. This new name matches the style in insn.h. Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/insn.h | 5 +++++ arch/riscv/kernel/probes/simulate-insn.c | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index 09fde95a5e8f..debac13a3476 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -64,6 +64,7 @@ #define RVG_RS2_OPOFF 20 #define RVG_RD_OPOFF 7 #define RVG_RS1_MASK GENMASK(4, 0) +#define RVG_RS2_MASK GENMASK(4, 0) #define RVG_RD_MASK GENMASK(4, 0) =20 /* The bit field of immediate value in RVC J instruction */ @@ -295,6 +296,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 c= ode) ({typeof(x) x_ =3D (x); \ (RV_X(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) =20 +#define RV_EXTRACT_RS2_REG(x) \ + ({typeof(x) x_ =3D (x); \ + (RV_X(x_, RVG_RS2_OPOFF, RVG_RS2_MASK)); }) + #define RV_EXTRACT_RD_REG(x) \ ({typeof(x) x_ =3D (x); \ (RV_X(x_, RVG_RD_OPOFF, RVG_RD_MASK)); }) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 6c166029079c..77be381bb8b4 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -121,9 +121,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long= addr, struct pt_regs *re #define branch_rs1_idx(opcode) \ (((opcode) >> 15) & 0x1f) =20 -#define branch_rs2_idx(opcode) \ - (((opcode) >> 20) & 0x1f) - #define branch_funct3(opcode) \ (((opcode) >> 12) & 0x7) =20 @@ -157,7 +154,7 @@ bool __kprobes simulate_branch(u32 opcode, unsigned lon= g addr, struct pt_regs *r unsigned long rs2_val; =20 if (!rv_insn_reg_get_val(regs, branch_rs1_idx(opcode), &rs1_val) || - !rv_insn_reg_get_val(regs, branch_rs2_idx(opcode), &rs2_val)) + !rv_insn_reg_get_val(regs, RV_EXTRACT_RS2_REG(opcode), &rs2_val)) return false; =20 offset_tmp =3D branch_offset(opcode); --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0B4BD18E050 for ; Sun, 11 May 2025 21:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998293; cv=none; b=Lk73jGED4QUnoi6zw4b0iz2wLQz6lU6VQJMu44nNuHk1kHShuw/QeqDomnzhVzeFA/Vk64V0wzCqzx2+Gku8gjWmQNnTTvRMe0StnEMGzfRskD1CUZipvwtB7Bxk0bufNcfEwKq3udGuRB4MHWnLANeaxnlaeZTsZv6twHNw/jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998293; c=relaxed/simple; bh=mNT5Bq+QZxOSTBdgVRIYyBAGQoBjIS3WObapx8ALvzI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pxm+XKkTYqh8+NszLVSwUaMIPH3xTycqz6eXHQUtSbQ+aw7RxwBKQ1MP+QMP2kmeixs32ut1UXKTyl9qnWnsxNyDw8SJy2jlmB0HAgeDGtsVMLoeAHJjWoP8HFsCRsmpSbdCQbBKS5WgXCLhos/S1vOZ3wloarivvOvCth3SK+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mmcyJI9F; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Pl7w8vku; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mmcyJI9F"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Pl7w8vku" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cxxjh0b5jumKoKypnaWi9zZMzSNoHhSBLqb0wOUfsZM=; b=mmcyJI9Fd+mOyzbsckx1w2mioDoRsrF0PpkrTiXA1dRBc1zyMH1djc/h3AysVv49tHMDzT PaK1pjydlNl1t7xHQkeeoo2vR0nKlZInRO5rD5b33axd07HPRoR9BA+ljCior3p+0kOiWU Wcz5RrMe8CrUKFk2sp80jZuj7dnXUTCYd7NIIE5239Mk0EW3mKw8ntMj3O+fu4qkevAx10 rZx7TLvpfK0Ls7l1yQzHpoDhltfhcwcmpJKUKJSmlj/ByAWlfDSuYgrVneKSoTVIM7knnt v1eu5v5GSu6Jd+hCVDDfCfUffuK8bN7oDHnWAJqAKHBTQA2l8s8c95wsjuVs1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cxxjh0b5jumKoKypnaWi9zZMzSNoHhSBLqb0wOUfsZM=; b=Pl7w8vkujNyPkohfv2Sf83rZWH+JUDJYZ4cpoMV2OdNODA9n5AWEoHqsC2+kKfzlEmcOFL zfhC4y5wi1huzYAw== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 02/11] riscv: kprobes: Move branch_funct3 to insn.h Date: Sun, 11 May 2025 23:17:54 +0200 Message-Id: <71c57502962d8b2663fd2fb74738374e1ead740d.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Similar to other instruction-processing macros/functions, branch_funct3 should be in insn.h. Move it into insn.h as RV_EXTRACT_FUNCT3. This new name matches the style in insn.h. Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/insn.h | 4 ++++ arch/riscv/kernel/probes/simulate-insn.c | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index debac13a3476..80901b36fd22 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -292,6 +292,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 c= ode) #define RV_X(X, s, mask) (((X) >> (s)) & (mask)) #define RVC_X(X, s, mask) RV_X(X, s, mask) =20 +#define RV_EXTRACT_FUNCT3(x) \ + ({typeof(x) x_ =3D (x); \ + (RV_X(x_, RV_INSN_FUNCT3_OPOFF, RV_INSN_FUNCT3_MASK >> RV_INSN_FUNCT3_OPO= FF)); }) + #define RV_EXTRACT_RS1_REG(x) \ ({typeof(x) x_ =3D (x); \ (RV_X(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 77be381bb8b4..d5f74fadbc3a 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -121,9 +121,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long= addr, struct pt_regs *re #define branch_rs1_idx(opcode) \ (((opcode) >> 15) & 0x1f) =20 -#define branch_funct3(opcode) \ - (((opcode) >> 12) & 0x7) - #define branch_imm(opcode) \ (((((opcode) >> 8) & 0xf ) << 1) | \ ((((opcode) >> 25) & 0x3f) << 5) | \ @@ -158,7 +155,7 @@ bool __kprobes simulate_branch(u32 opcode, unsigned lon= g addr, struct pt_regs *r return false; =20 offset_tmp =3D branch_offset(opcode); - switch (branch_funct3(opcode)) { + switch (RV_EXTRACT_FUNCT3(opcode)) { case RVG_FUNCT3_BEQ: offset =3D (rs1_val =3D=3D rs2_val) ? offset_tmp : 4; break; --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9DD0F19C578 for ; Sun, 11 May 2025 21:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998294; cv=none; b=f40IWVGK4/rg+O7vVWWhMA/O/HSDXNtyrgBqdNdczZA266jwOq9JdA/6A1mIkqyBAFiS7L0Ngscn5gSAPMNPlOY0iPDGwRIiJxE3PBxaueiiDa53vUfixTLBSufIQzSnkY4KC2fzc8LcnFvK7YA3FyHXg7mG/vTiMCHiBwP1ZzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998294; c=relaxed/simple; bh=7m/qqnL0PAK7Y0tfHeOZaCUGqWyUTDJAqIsQ4KnxLb0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i7GWixBEb2VL1BxBvZj0lKCYLBP/TprJ3jLbW+UgEiYadvT51wRUA/C7qhwojjgKo94M1NbVNlNQ9VbP63lxg8jH2yKQrno6cJFV5kjqFeRrKmx9l8Pcupa4HaX1wcr8cmJhjaR1YKv+QP5r06vgz0SDGu9+la89lIMc2WfDDQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VOmvd4Ek; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uOOI5eog; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VOmvd4Ek"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uOOI5eog" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GsddRiOpi8XPygRa69KJPJp3ShvkCz7BnK7OzU9yZH0=; b=VOmvd4EkuOEEmkpZTBoebEM+0zppjg1sQy6OS4LIJ94ImG1Mhzv0n1cs+fMPsOM8OSLuRx SxkR0vxY6z9x6hh7BVIJwrNq2SbnNvJWpu3LpBndS36oCTzlek94Ao+J3MrpGwRNYqhPxd 60W+RSTl8Kg+fgSps9gWUTv9QrIT44cn91//RkZsXR67Le0sebQQFZpv3US5WrWeIF0rnW jp9YbpLhDjvtPQXZqFdUra2Mb+ekO8eulfSxeekeDqOZ1MxVVEwptIyKEAiIPPGH58rzzM Gphc3KIE3LFzJM3/FT8AWsTKlTuqKH+7LlJqCmRGsI1X6qAIp+pUcJGsyCnTaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GsddRiOpi8XPygRa69KJPJp3ShvkCz7BnK7OzU9yZH0=; b=uOOI5eogQWrO2bwxjPHhV6QHYKorOMnN8McHcLSSYB1FBZWgQ7nYW1RiHrEJZWwb6yqBjB GFIkJxMH3UyP5dDQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 03/11] riscv: kprobes: Remove duplication of RV_EXTRACT_JTYPE_IMM Date: Sun, 11 May 2025 23:17:55 +0200 Message-Id: <10dd59c17c7c6f4700d92f988292ee3bdcaad71b.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_JTYPE_IMM, instead of reimplementing it in simulate_jal(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index d5f74fadbc3a..b76a691d0d9a 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -41,19 +41,16 @@ bool __kprobes simulate_jal(u32 opcode, unsigned long a= ddr, struct pt_regs *regs * 1 10 1 8 5 JAL/J */ bool ret; - u32 imm; + s32 imm; u32 index =3D (opcode >> 7) & 0x1f; =20 ret =3D rv_insn_reg_set_val(regs, index, addr + 4); if (!ret) return ret; =20 - imm =3D ((opcode >> 21) & 0x3ff) << 1; - imm |=3D ((opcode >> 20) & 0x1) << 11; - imm |=3D ((opcode >> 12) & 0xff) << 12; - imm |=3D ((opcode >> 31) & 0x1) << 20; + imm =3D RV_EXTRACT_JTYPE_IMM(opcode); =20 - instruction_pointer_set(regs, addr + sign_extend32((imm), 20)); + instruction_pointer_set(regs, addr + imm); =20 return ret; } --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9DCB61917F9 for ; Sun, 11 May 2025 21:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998294; cv=none; b=mnsOTAR39E0C5Baty0HoP8Z0F5FzwfrNcAnN+z5MjsfvyIw3S1OqCY2pPSHIN8mvvkdUJ5Z+/XZ/puOILSD3GOgozNMZ9Fsioj7h0V4iziQ+7myFrn3luI0nZ3xcdxBKguMBpktzvhjVfJampVasuTFPJVlSkj15MzfNMb+QGD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998294; c=relaxed/simple; bh=bCd4WxovOxu6jIn0P0BMOxj7qEYqaxkyzqHS+tdq100=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gOn03ssXa2iTOxM7hQM4UZ61RP0dOsAkAlxfWllItwzp/VGROa56jXkkAiTwnexCsZiht1bnaEiIpdJa7Kb+1oWjwzjwswxyEUWtyOyhdiOtff/DBhn3ujNyV4/54UBnIbio6oFXtESkZmr1VHS8/gDQRe4n6IsXT3w2dDypFss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=C8n56BwQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Wx2X3fXd; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C8n56BwQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wx2X3fXd" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+ZSGPGR1f44374iB4VtgRiL39ZDvHo9xWVozgwsi6A=; b=C8n56BwQkdOcM2T/ujlGMwbhhVjja4cdRNIJfbUNpfxyeTVhV7ZOg/LkrrEziEznjuPdbn mZV43gA1D/Y7+oVN6nsJcBm57XJDOWzYKBYrUbRI5ncqZj/AHnzr3S636va3MvkvgsGoqx wbBxy4dksn8Qe/gRhd5C8EBcUJergrCEVn6wxcQrsoCD59GkVIEMR/MMzJNZItYrOatuug zD//vHfFb7mHmEFpcuT2HhVt82IuKYKZ/220+lKpx+8u1c8Wh74JjRD3/TAU0DN40XokFW tkXIJX7gNN7sk6ULQhUhJrMluereYg4fQl/SLdiffvaP5mwzSAES5r7uhc4Vjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+ZSGPGR1f44374iB4VtgRiL39ZDvHo9xWVozgwsi6A=; b=Wx2X3fXdRGH2Qz8zFXmmXNC9GnAg+b6EZ282vCoOxESZxHB5AyUlLSjYaK3HbaG+UQG/mU 5lKB7hbXt9P0KxCQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 04/11] riscv: kprobes: Remove duplication of RV_EXTRACT_RS1_REG Date: Sun, 11 May 2025 23:17:56 +0200 Message-Id: <0b74924c188537b7834c9aa98aeab7c4d76dee0b.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_RS1_REG instead of reimplementing its code. Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index b76a691d0d9a..625d514c4ada 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -66,7 +66,7 @@ bool __kprobes simulate_jalr(u32 opcode, unsigned long ad= dr, struct pt_regs *reg unsigned long base_addr; u32 imm =3D (opcode >> 20) & 0xfff; u32 rd_index =3D (opcode >> 7) & 0x1f; - u32 rs1_index =3D (opcode >> 15) & 0x1f; + u32 rs1_index =3D RV_EXTRACT_RS1_REG(opcode); =20 ret =3D rv_insn_reg_get_val(regs, rs1_index, &base_addr); if (!ret) @@ -115,9 +115,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long= addr, struct pt_regs *re return true; } =20 -#define branch_rs1_idx(opcode) \ - (((opcode) >> 15) & 0x1f) - #define branch_imm(opcode) \ (((((opcode) >> 8) & 0xf ) << 1) | \ ((((opcode) >> 25) & 0x3f) << 5) | \ @@ -147,7 +144,7 @@ bool __kprobes simulate_branch(u32 opcode, unsigned lon= g addr, struct pt_regs *r unsigned long rs1_val; unsigned long rs2_val; =20 - if (!rv_insn_reg_get_val(regs, branch_rs1_idx(opcode), &rs1_val) || + if (!rv_insn_reg_get_val(regs, RV_EXTRACT_RS1_REG(opcode), &rs1_val) || !rv_insn_reg_get_val(regs, RV_EXTRACT_RS2_REG(opcode), &rs2_val)) return false; =20 --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 93B99263898 for ; Sun, 11 May 2025 21:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; cv=none; b=aJMJuWSZjRdazww52k5Z2KrpZcQzjjk7R2BcUVyLaOAlLtylMWjrIeFoXhB3HKn0I1L1W6fZf2lOTQCbqts3VPC6KY5GoPye+1HyawFgMDGQ2vy+rpUhAWadpuyGNsHtM9jWbi/Gqf3YvJWaijNoTJT7X5uTkRS2P7xQIznwduo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; c=relaxed/simple; bh=0+/um2kJNRDLk3EFkIOR6EKeAhQZ5jg8wpzCgOrkVzQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k3W9EzuBe+Lu2O49SlP8F+N+SI8dnKcD9GiqdqP2NxlruG8Wagit2UIUAVtn6+UdtNgE4AL8Rlj5BJOyPxxSwU1NwYlXpcfXAJWMnYDmobgM4YM4nyJkoFIP+zA6EgdiWXF3QB72xQRxovadz7jrr9NzIZ1xudrFYpdyZASXIjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gKj7ol7G; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5BgFKKgs; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gKj7ol7G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5BgFKKgs" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kuh4owOv0RzlQSco6IKhRzdD1qqjlGpYcTbO1rvk8z0=; b=gKj7ol7G2ufttDRdEfBOlzR3Rgz1xvGVIjLBseZ8MKCYDjyL29s3FhWiq5ZyWEU8q9QpOg Y+PPVAI7xdcATY6Y2kW8eviGXhW18HY45XTqPQ5gQaL6bcAvo/jn4JghhBtBZih6ibRg2s fCAPTQuNypEHo4lia8iI1tdWBc+eAmH+l2cwYmx3UMallu16o8AJQZPWAZ2fKNjzvV7oy6 d7zZvgCcDiz8MjuLkoZRL/+CwEhOC7daHUJyvR8DjSPDKLW8Z7PWOY/d5goHB2LHo1iyJB lXCpy1++IesTGCOOu39OaPD7GW7aWtA4fmOEFqkawGvzqAoX35jKL7n5jLz3Cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kuh4owOv0RzlQSco6IKhRzdD1qqjlGpYcTbO1rvk8z0=; b=5BgFKKgsItCzaNlFc0kSoIIaSJmfKjK/9eYHN8xJmdDWDIkWrrKfDCtkvb5A+j1yMGPp8W cuhkpD6qJgoMxeBg== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 05/11] riscv: kprobes: Remove duplication of RV_EXTRACT_BTYPE_IMM Date: Sun, 11 May 2025 23:17:57 +0200 Message-Id: <1510a1a9674e84c9ba9a5a57e21d0f2aed3a3f48.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_BTYPE_IMM, instead of reimplementing it in simulate_branch(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 625d514c4ada..3ba97e79a2a3 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -115,15 +115,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned lon= g addr, struct pt_regs *re return true; } =20 -#define branch_imm(opcode) \ - (((((opcode) >> 8) & 0xf ) << 1) | \ - ((((opcode) >> 25) & 0x3f) << 5) | \ - ((((opcode) >> 7) & 0x1 ) << 11) | \ - ((((opcode) >> 31) & 0x1 ) << 12)) - -#define branch_offset(opcode) \ - sign_extend32((branch_imm(opcode)), 12) - bool __kprobes simulate_branch(u32 opcode, unsigned long addr, struct pt_r= egs *regs) { /* @@ -148,7 +139,7 @@ bool __kprobes simulate_branch(u32 opcode, unsigned lon= g addr, struct pt_regs *r !rv_insn_reg_get_val(regs, RV_EXTRACT_RS2_REG(opcode), &rs2_val)) return false; =20 - offset_tmp =3D branch_offset(opcode); + offset_tmp =3D RV_EXTRACT_BTYPE_IMM(opcode); switch (RV_EXTRACT_FUNCT3(opcode)) { case RVG_FUNCT3_BEQ: offset =3D (rs1_val =3D=3D rs2_val) ? offset_tmp : 4; --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2EC29261594 for ; Sun, 11 May 2025 21:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998295; cv=none; b=Kxe+u0qbqrYzFMN67Cg35abUzadoE1rppuzox59t61iGpPURxlngRGiuvkwrJPYR8ryuxkRSM6XdrFtNAmJkrToSX/XlloiTV/e4MrfeOpAVwdnympt6ep3miWJKv1BUS9ev2M3IiHJfGz2Mt/QTG35wA3+JyuvX2IGxNc5RmzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998295; c=relaxed/simple; bh=STVmF42kLVmoDkOiA2IdeI9QL+pCOmCowxDQiKg+Mcw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HLL8A/rS1BxNcAbMP8bUn6x9ZcVd7CCngefKmVk7hwxXglYFAditZrLatEtCMGw50pZPhyesap4Rds/qiytNWHTlwyjgcMkvxZ/vwCxNMQyzHV7wIEcq6NIkpOxevwn0z9LIKDS76aef483Ql/njIqoycZ7aGQafVoR3qar1QLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K9edcgy2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0wQUYP/7; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K9edcgy2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0wQUYP/7" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z1LlZOoLaS1B4vzBVZP0EbbDkdO6N0U0HywBnUrr4mA=; b=K9edcgy2AqS6myyr8osxsH/m4ft3ZfK51MHm6QBJV7NqlDms9fM2z2UCCcKLKCI0+/4wRR KL8TlSzPZlrkJlvVqo52dKnNGx2VoRI4l6t/43jUe4PWqq/WIHt6tsA1dQe6ZDW4Zy4IW4 f7WnEsCZjeb808ODmTUKjUBkHV56wf/HFLSwoQu0qS0ufGAMWp6bdRLliKeZe3tT30Bi8n bOaFEeqq/QWWn+aUNqNwwJCrXg4AbOuzVVxBW9kBVg8r2J4WrZnU+UtjS52tigmxAO+eNH MmWz9p9MlswKCwLm+wsklKs3bGBO5+4WpaXWp9K/7RMh41qMsnMeoEnUVVEdMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z1LlZOoLaS1B4vzBVZP0EbbDkdO6N0U0HywBnUrr4mA=; b=0wQUYP/7DRKfmnvIEK+XjjotpML9prs2X8tQzmteXC1Zehb0qD1MQQ1oCeUaej5Q2mw4fV HhSaAfV28a873fAQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 06/11] riscv: kproves: Remove duplication of RVC_EXTRACT_JTYPE_IMM Date: Sun, 11 May 2025 23:17:58 +0200 Message-Id: <64739c38b3b22633cf76b392720028821f4c5a74.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RVC_EXTRACT_JTYPE_IMM, instead of reimplementing it in simulate_c_j(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 3ba97e79a2a3..5defbde4dd50 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -170,24 +170,9 @@ bool __kprobes simulate_branch(u32 opcode, unsigned lo= ng addr, struct pt_regs *r =20 bool __kprobes simulate_c_j(u32 opcode, unsigned long addr, struct pt_regs= *regs) { - /* - * 15 13 12 2 1 0 - * | funct3 | offset[11|4|9:8|10|6|7|3:1|5] | opcode | - * 3 11 2 - */ - - s32 offset; - - offset =3D ((opcode >> 3) & 0x7) << 1; - offset |=3D ((opcode >> 11) & 0x1) << 4; - offset |=3D ((opcode >> 2) & 0x1) << 5; - offset |=3D ((opcode >> 7) & 0x1) << 6; - offset |=3D ((opcode >> 6) & 0x1) << 7; - offset |=3D ((opcode >> 9) & 0x3) << 8; - offset |=3D ((opcode >> 8) & 0x1) << 10; - offset |=3D ((opcode >> 12) & 0x1) << 11; + s32 offset =3D RVC_EXTRACT_JTYPE_IMM(opcode); =20 - instruction_pointer_set(regs, addr + sign_extend32(offset, 11)); + instruction_pointer_set(regs, addr + offset); =20 return true; } --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 00A25263F3C for ; Sun, 11 May 2025 21:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; cv=none; b=lWo0909yAOhdl4WrnojJfSoR7l6l9ToNXE0oj3F/UkzoHIzAOWD0w+Ohk5hSqYCySaCDPiUfrNG5w7sa0e4WfwX6xe1WkqACr35ocRoTY4huE9d1EDwCzjmVVEodSALl2C7w1sXBCkQaezKjrHnXBdwF7t6hwG4PtGYAsly526A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; c=relaxed/simple; bh=QsTzxUopKKXbnTEdlpuz6mx4BzuWawlvZVsLdLy4dnw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bHQm0y0wvmp1TCpgfsXcCEP5WhSccuqoLHKzUL/XYXXDz9osSbV8gIvAiRQ79KJulPMmc1KvHKg17Dh04AXOZmYorYq6p3WU1BiV1RqL8UA/J48/sdYQz3IMlBO6gye7GCvUc7I492YjOkH24jR8bCbjkEpOazrtTGvP9TT9O3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bX57btfV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ikqp5HGK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bX57btfV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ikqp5HGK" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQXO+2w86UaaANetpNDoYy9jOymgZL7O24AgGpF2SFk=; b=bX57btfVcuydNfuyd0bS+isHMlT5cqHTKRypA/k7l6x9dBqH4eyrM+w8WqsWco0GoWhFWl 6MBeEp1zYVc1uVqVwOdW6W/FGwbnJm8VmGiYlZZdGE4C12IQwoSv9TEm5qCFrQoV/9lVqD tRu/bpF1TcE/S40evqg6EkhdkiwCgUlAhS0R2m7w5r7flhrtJYxiQCzwe2/szgT1TcB76L 1dXNoWb4BtSnkVHbd/hvQmITA57EYdFJB5mU9AGnjp6Zx8o6VI9VdjeHtGh2sfFn/J2aDb e152pyFc774gu/ziSSMSYrNPOoXQLTDwUZQNW99qnCXD2rsWFc0GeUw6siJkgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQXO+2w86UaaANetpNDoYy9jOymgZL7O24AgGpF2SFk=; b=ikqp5HGKRJ5owMaPvaVESfntKsc2pbQcG1oKyxOIFpFdkz94WXYMcmFsiSvUDgsDVl2CWd wxjnnjxrIBz+8zDQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 07/11] riscv: kprobes: Remove duplication of RVC_EXTRACT_C2_RS1_REG Date: Sun, 11 May 2025 23:17:59 +0200 Message-Id: <0c07ff8c9c61511e30200aa997d93612676d1a07.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RVC_EXTRACT_C2_RS1_REG, instead of reimplementing it in simulate_c_jr_jalr(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 5defbde4dd50..f5d64613dab5 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -188,7 +188,7 @@ static bool __kprobes simulate_c_jr_jalr(u32 opcode, un= signed long addr, struct =20 unsigned long jump_addr; =20 - u32 rs1 =3D (opcode >> 7) & 0x1f; + u32 rs1 =3D RVC_EXTRACT_C2_RS1_REG(opcode); =20 if (rs1 =3D=3D 0) /* C.JR is only valid when rs1 !=3D x0 */ return false; --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4BFAF2641FC for ; Sun, 11 May 2025 21:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; cv=none; b=TOQKFW2Ivy/uwgFa/rjZBrvwptdeMU2G+B/jNsTimPGHrkknHojdgz8jsaSwopXXmVmI7IARZ3LNxlXcFIXrB5WfzmFASIa3/UD9ELHqU7ZxMacBk2luKDA+AKlMVT+fKcgnFxVl7yg/jQZ65UB3QNPBoNAy3iYxQ4wd0Dywt3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; c=relaxed/simple; bh=no4qakD4nxljmSj0dNsH7cHTRGfko3yxxNeYW0VDHXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WyhYQFGNCJofPf3TvE3tgdlmhrEp0BA/NOCOpbXB6N5PlFSPjI5jay+FW+dNF+x76f492pegG+lG6kljyB3JICVBp1Gx4XFg1OECn9Q4N60n0ls2tkazGWKTHhj5QCWXqEC0PMh8WFb9VNpPq+GmGZ7GqBhdvLnCN0be9+x99TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tPRJhreh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eyG41UCA; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tPRJhreh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eyG41UCA" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E7nRg54MLFX0wtJKb5RifAgoyTmks+tvfzWz8EaXC+I=; b=tPRJhrehBPcmassI4U6hQ+6Hdpv9rxGcGNrQJirTHwzDfsrdCwUgu1sjMtAwWAWj967XL3 NPJkg9F2+CbJLbRnlWVKQf3SFVdTZSNsOl71R4G5wGIJXdIZAbtbDto+lvdGpmDcoHIp3F j/nDpgmezlvFIWck+//t/Sg03WFdmMdpsdfW5nHJOim7NGw7lYCsozyN6cUc+0wOxtyao+ MVHoFIPLkXd8XadAu5jVxP1Ikf/NDgJUV4p639ybA5iup8oGq/tGt0EVMEpFSEnM7Yc2bN n++vMbSHO8/XbKN/vq+fmiS9rp45cVkLp5kjXs2pzE2ZYjmaT1LdKCaBpFrE8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E7nRg54MLFX0wtJKb5RifAgoyTmks+tvfzWz8EaXC+I=; b=eyG41UCA5GOgr6jB0HFIk7/4ZIzC8VjG+m2YtoWBEGjkRvhqXmWnPrPkGsG39JCdE9XsZX cTwKh1rcOE1ZuFBA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 08/11] riscv: kprobes: Remove duplication of RVC_EXTRACT_BTYPE_IMM Date: Sun, 11 May 2025 23:18:00 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RVC_EXTRACT_BTYPE_IMM, instead of reimplementing it in simulate_c_bnez_beqz(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index f5d64613dab5..e670e55954d2 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -232,16 +232,10 @@ static bool __kprobes simulate_c_bnez_beqz(u32 opcode= , unsigned long addr, struc if (!rv_insn_reg_get_val(regs, rs1, &rs1_val)) return false; =20 - if ((rs1_val !=3D 0 && is_bnez) || (rs1_val =3D=3D 0 && !is_bnez)) { - offset =3D ((opcode >> 3) & 0x3) << 1; - offset |=3D ((opcode >> 10) & 0x3) << 3; - offset |=3D ((opcode >> 2) & 0x1) << 5; - offset |=3D ((opcode >> 5) & 0x3) << 6; - offset |=3D ((opcode >> 12) & 0x1) << 8; - offset =3D sign_extend32(offset, 8); - } else { + if ((rs1_val !=3D 0 && is_bnez) || (rs1_val =3D=3D 0 && !is_bnez)) + offset =3D RVC_EXTRACT_BTYPE_IMM(opcode); + else offset =3D 2; - } =20 instruction_pointer_set(regs, addr + offset); =20 --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 48D742641F8 for ; Sun, 11 May 2025 21:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; cv=none; b=qfc3Lcd9iZmio+s5fnb0nhz7TTb2v/m2lEzZWc00axFmxv51/x9sYAlWDq36fsUOYKH0ddYV39W9+ACmPYKxGW+C6IVuxNQh/IbnO9Q671Sx3qHReP5fzhcwJDrKV7QzSyCopRrV/XS427NtSsi2J2OV0CwHaVj372mEpQ1TDmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; c=relaxed/simple; bh=Ws2nDVvQopR6wx2xDaiXWVZ9L9hlwAgMsqyPuGIrmp8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YR3lxyDpECRk1mpdn+lyJ5hcXbBMCZFTJ4wAj/P2U57o7cdJv+mAOnVxSN7sibivy3MXq3A3SeE06BCzsxZw//Db2Wov56HAiSFXdJ//KLnzjSZAlOFd4oLEcaKjhWgOISp86Y++G6sKapwTKIDPq3XH5HP49QwY/iBqoIevmvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q9/Tx3hJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pHSxmLgt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q9/Tx3hJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pHSxmLgt" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ofRlSkfoMczDkVEQIfQIC8RlTmO5xBys4uCekN9vBRo=; b=Q9/Tx3hJUILpIEp06fQma9qN1+iMs9Sa/7Z5shRXrMIKOQzz0bV39ArEZo+onXxGUfvtvN EuNmPLT04T/FhYA1EHyX/IvK4Fl3l9cZ5Za9ZSc1ii8WrLfW2Mi9cJ4w46x9gVF5TtJ0yL 5wVL/NO4dSK8iQo8JT0N43ykYoE5lpBls/CymSXANfFz/l9jh/wLOAQN7xsjOZ8a9x8je1 IwEnKjgoN8V+iTdjBa32loLmQUOgITR2yMS2EEKoaqbO0+Q/KACE1l6YiHxsEX79vaJyL9 1S0bPNscwlqxKW2Xy9HRQbtPC8yNDfvoNYaHdBqmQz6Tszj3wZyy7cRJXrv2tQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ofRlSkfoMczDkVEQIfQIC8RlTmO5xBys4uCekN9vBRo=; b=pHSxmLgtOBB4FsYEQvh1sDzt8EOQL/+YXiOKHnUtIun3i12yJ03x1iQQOpECZF8Iih4Blp LIj42Ii3e28q8vDQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 09/11] riscv: kprobes: Remove duplication of RV_EXTRACT_RD_REG Date: Sun, 11 May 2025 23:18:01 +0200 Message-Id: <710026e5113b9929fd9fca2cdd5d5cd86aa6b447.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_RD_REG, instead of reimplementing its code. Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index e670e55954d2..1717df780409 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -42,7 +42,7 @@ bool __kprobes simulate_jal(u32 opcode, unsigned long add= r, struct pt_regs *regs */ bool ret; s32 imm; - u32 index =3D (opcode >> 7) & 0x1f; + u32 index =3D RV_EXTRACT_RD_REG(opcode); =20 ret =3D rv_insn_reg_set_val(regs, index, addr + 4); if (!ret) @@ -65,7 +65,7 @@ bool __kprobes simulate_jalr(u32 opcode, unsigned long ad= dr, struct pt_regs *reg bool ret; unsigned long base_addr; u32 imm =3D (opcode >> 20) & 0xfff; - u32 rd_index =3D (opcode >> 7) & 0x1f; + u32 rd_index =3D RV_EXTRACT_RD_REG(opcode); u32 rs1_index =3D RV_EXTRACT_RS1_REG(opcode); =20 ret =3D rv_insn_reg_get_val(regs, rs1_index, &base_addr); @@ -81,9 +81,6 @@ bool __kprobes simulate_jalr(u32 opcode, unsigned long ad= dr, struct pt_regs *reg return ret; } =20 -#define auipc_rd_idx(opcode) \ - ((opcode >> 7) & 0x1f) - #define auipc_imm(opcode) \ ((((opcode) >> 12) & 0xfffff) << 12) =20 @@ -104,7 +101,7 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long= addr, struct pt_regs *re * 20 5 7 */ =20 - u32 rd_idx =3D auipc_rd_idx(opcode); + u32 rd_idx =3D RV_EXTRACT_RD_REG(opcode); unsigned long rd_val =3D addr + auipc_offset(opcode); =20 if (!rv_insn_reg_set_val(regs, rd_idx, rd_val)) --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4A6C62641FB for ; Sun, 11 May 2025 21:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; cv=none; b=l2+MzcMbEblb3yAb/i66pSLDcC18jvwvJlfsAwySw1pyedx6AZ+zoB5IWimeYkx88uR5ZOiAcPlBOURz6dSNamqzB1wl2YjEQFrXcSMzQEJBu1yD18lvpZ+1qZ6S6tBcJRKlFEgl0TnZJCTbaRffrPlXE02zNDw4k/Q7ibmizqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998296; c=relaxed/simple; bh=mnvYMX5AgX/+YGXJjtOtVwrFHsHIWxFK98GYj03OCUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cG5zEmtfqM9Rfwq7Yn+BXI0AdqgLvXI2zFDKTGCAVzO1LDd97utJjzbXxXBs7AwQXq6SULvEwjPLdwFzVqVS9psSj1tjt0Ne7dwqcaA7Q6fstYXHKMlAe5Y4rMxmX+v2HV+5tNLBKJ4BBTmCkLmVyPoE6txMx1X5XL4Nk2wrY5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iv0xgamO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wEzs5iLY; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iv0xgamO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wEzs5iLY" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4YToDIER8H6nwFDI0QIaa0HWbI2B/uQuBCnhyXETH8=; b=iv0xgamOdlWgoRLYIquiePlF1sRtPhuhM8ks2maPBrgysF+5o7bViA516VlTG5u7f29QLl QWpKziOIyYHPU1V8iu/XCSmwd9lYAY6zvJ8VX6VAdMIlcRwXvJjR1Ycgb/IB/FfOme0aVu SWnHiJp6xBg4s9qrzXyyC+IuN3HMKUP/h6mfnbe9okvVPo01X/0A3raLzLAYOjn7zWTdWP DXkvQ1fWUIn6aCtWI+EKEb1KCkhnPEy/FKfTcUud+htZEyF2OVg9EDWPUBhLPGMOpVZo5O jRahUpdr/Dm7/FW6QkzWTr0XVRBuzj0Y6iL65LBQVjtE/qHy9Vz1htqUO9jkdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s4YToDIER8H6nwFDI0QIaa0HWbI2B/uQuBCnhyXETH8=; b=wEzs5iLYHFw2oTfS/sZ/KT/gPE2ygLqG1lQ6V3ParOCPIp9HVi3ZN0sjeUa+BLCtapVBub Z4E+KEN1lp+JtlDA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 10/11] riscv: kprobes: Remove duplication of RV_EXTRACT_UTYPE_IMM Date: Sun, 11 May 2025 23:18:02 +0200 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_UTYPE_IMM, instead of reimplementing it in simulate_auipc(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 1717df780409..2b3cd69d6f8e 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -81,17 +81,6 @@ bool __kprobes simulate_jalr(u32 opcode, unsigned long a= ddr, struct pt_regs *reg return ret; } =20 -#define auipc_imm(opcode) \ - ((((opcode) >> 12) & 0xfffff) << 12) - -#if __riscv_xlen =3D=3D 64 -#define auipc_offset(opcode) sign_extend64(auipc_imm(opcode), 31) -#elif __riscv_xlen =3D=3D 32 -#define auipc_offset(opcode) auipc_imm(opcode) -#else -#error "Unexpected __riscv_xlen" -#endif - bool __kprobes simulate_auipc(u32 opcode, unsigned long addr, struct pt_re= gs *regs) { /* @@ -102,7 +91,7 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long = addr, struct pt_regs *re */ =20 u32 rd_idx =3D RV_EXTRACT_RD_REG(opcode); - unsigned long rd_val =3D addr + auipc_offset(opcode); + unsigned long rd_val =3D addr + (s32)RV_EXTRACT_UTYPE_IMM(opcode); =20 if (!rv_insn_reg_set_val(regs, rd_idx, rd_val)) return false; --=20 2.39.5 From nobody Wed Dec 17 08:48:52 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 DD204264A6E for ; Sun, 11 May 2025 21:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; cv=none; b=ZG5VmkrPckUlzZhtSsqdZuDlylh/RcjU4JmzpozyFF15XVtaA0ON2AaLVZOh8B0wJ4n2M21i5gUulHrXG2nYefauXbDbVpfVjevPFUyc8Ns9tZgyO6uaGT/FgPkpZ7zAeWl4085WJDW9j9fYuuXzAIJAByXWDmA7+zmaBImutLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746998297; c=relaxed/simple; bh=j1DioIwVOiyApHB2qerSx2O5NWoG+WaJcUbS8nbLoe8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d/fiZe3wGA3eCmRKU1LH9J6e9DWcGgkprogOQIcSUeFgzoB9B487ufi5kpnsoW3J9XafOolWvQu77hdxbD4ujobhNicZbme6MKpvwvX7FzrnsH5BUPCRvX/gUH3shXCeSdT0HLh/BjugD8l6JfG0Zw1WzX1TTIdDD2D3BlGqvNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HjhXIJUW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8dMpZIAP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HjhXIJUW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8dMpZIAP" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1746998293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+YuprVJ8dctdiMrh0XyEl1XTvNDpL+VEXZc49r4qPy8=; b=HjhXIJUWdi8O9Rjb+lJg29OUgeDPdJWXzI99fJq+fOrfdfQZaoT8hiYI7HgVH1BUjrGhVY lkbKGy7kzWhUgHyru7UkTQu3Rrb8qiYZB8hojXg2zpn8QYX7lJec0W1/mzLJn/6fKMFmxP zAVtCRhVBjFS/5MfUhTwaiOb5JBhyvb0nboHu3fzUmK02yS9RqgolSjiJgngFwElWaJm7C koHdoTUQx5pWd1wblFNiEPYj2MoHIwTFUzeMKKXPRefoGui8iWMapD/iZm5XJ5Tt0pcmB9 MYybPxNM5F8F38d1qCQBQslYe+mtijglSRdfN21Cz3fkRVDRSG5YxG4zruq5Tw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1746998293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+YuprVJ8dctdiMrh0XyEl1XTvNDpL+VEXZc49r4qPy8=; b=8dMpZIAPEiO5C/lMba+ZSdSkzzwVmpOhUMWmswW2C1y6tXcJkn3B5wZmKEQ6W8VA2tm2bk CsxYeXtYrUpJJGBA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 11/11] riscv: kprobes: Remove duplication of RV_EXTRACT_ITYPE_IMM Date: Sun, 11 May 2025 23:18:03 +0200 Message-Id: <2a2d138d1a5c011a00ba2a9eb84d5226304d7b48.1746997351.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use RV_EXTRACT_ITYPE_IMM, instead of re-implementing it in simulate_jalr(). Signed-off-by: Nam Cao Reviewed-by: Alexandre Ghiti --- arch/riscv/kernel/probes/simulate-insn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/p= robes/simulate-insn.c index 2b3cd69d6f8e..fa581590c1f8 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -64,7 +64,7 @@ bool __kprobes simulate_jalr(u32 opcode, unsigned long ad= dr, struct pt_regs *reg */ bool ret; unsigned long base_addr; - u32 imm =3D (opcode >> 20) & 0xfff; + u32 imm =3D RV_EXTRACT_ITYPE_IMM(opcode); u32 rd_index =3D RV_EXTRACT_RD_REG(opcode); u32 rs1_index =3D RV_EXTRACT_RS1_REG(opcode); =20 --=20 2.39.5