From nobody Wed Dec 17 08:51:03 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 957DA22ACD1 for ; Wed, 14 May 2025 09:38:58 +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=1747215540; cv=none; b=Pk74ERAQk09VecD2mAc4UXSvllRr2P2MV8+j1+/UD/vOQKu2tTyzzo55NulrStUGfsvPRRvM8AlIekkDfjFDwxeoXYNl+IfZc2h4eeHkvxXkVUwa5Tnot/QiU5NBzsMxIktQkcYq4fwAMMhnDjPM7V5V51FSfO88aoF4A4hKEsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215540; c=relaxed/simple; bh=kEV8Q/fHzV+OSPWamn8wcUhJzJayh85b3Bmt/16tMq0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TzbD5vYPr8ONN2cOU7j5QJV1vI8UoU/DqWow4LxpQSZ/8XBawSpRNXCi/bcPWnfwo+QLhTDPmtw8qtUjEFE6Z0XeDdx4Ka+a3JaDa3apEXjJlUjDJysi1p3CtsgSf5icPqhEiyKo2SCWlupLGuh7JajKAWoN6Siq1pJ0xO55sa0= 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=efv2uWjt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HOc7v3q0; 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="efv2uWjt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HOc7v3q0" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215536; 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=vc7hFN2UqqM5rL7Gk36K+iB7d3AnRHAfrGO+aBpYAbA=; b=efv2uWjtPfvjaXUpGVsRwNAfTGMqfj2p+X46OY3UwsRmp4vQRvFmgCitAJpWQdX8yW3QQc jIpI7OrjFWP6/togPpFhu90NfDL3PbODybFCcL6sNG22rqwkGWAMS+xBFg20dgWEn5L8Ht sT+CsaCdYRfnR3+2acR4snS7Cyk3rtzCbyUWuP0Nh9HQjOwBGFhDHnkz91rKWvrOOrGr70 oP6q9VDqoJfDqoaiEKu9zGS3LAyPAwEU/j3/55RObcczCZav9fLx9vJe4gfn288z3e4JZ8 7Lo1Jy6zB0Qr4sjiw2clzLjBGvoEY13lqrZ9GAE2r1KL2rkbffPcHsaS+qp30Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215536; 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=vc7hFN2UqqM5rL7Gk36K+iB7d3AnRHAfrGO+aBpYAbA=; b=HOc7v3q09eAvQ4EwOjaF0mpWHZX7RoikzXVwKmIM97Tlf45X3InmsIVNEoDkdOwatowuZa 3Uc0ej2t4BAAF2DQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 01/11] riscv: kprobes: Move branch_rs2_idx to insn.h Date: Wed, 14 May 2025 11:38:40 +0200 Message-Id: <107d4a6c1818bf169be2407b273a0483e6d55bbb.1747215274.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. Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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 7c65fc8baeed..4a26cef3b5c0 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 */ @@ -450,6 +451,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 c= ode) ({typeof(x) x_ =3D (x); \ (RV_X_mask(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) =20 +#define RV_EXTRACT_RS2_REG(x) \ + ({typeof(x) x_ =3D (x); \ + (RV_X_mask(x_, RVG_RS2_OPOFF, RVG_RS2_MASK)); }) + #define RV_EXTRACT_RD_REG(x) \ ({typeof(x) x_ =3D (x); \ (RV_X_mask(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:51:03 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 444BF22AE6B for ; Wed, 14 May 2025 09:38:58 +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=1747215540; cv=none; b=fEm55o7oMPxSoCgKhXDzAzbbUDQtFOwXJKGXr8ySs+ztEK+p6YGQGlsPQoHY1NWzTxSymOFT9T1yp2lT35NU5z11zqmyScYKRi57bqUZ/3Zj+q5gpZDJsV3tnp2AdkCcEsUxkybExRVgUqdfhF0pzsNAWH65116/eC+eZPdgOxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215540; c=relaxed/simple; bh=hjvascFnyqhoz+kSc+/5iaVSkW01jdwzHyYmEuvun40=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gNDgPCdQhCQiBOAvN861CKhJucJMUH4PnoWvi2Z4ekplsU2qYBVComzELDlvnRr/brq7xp5n2IE8OFEHGDsD9+u46+eFWFPIoUa6KSwTYLn7yCnuidAnIiNFbRl8PAuiG07xr5mchCmq6Nsd2GYldjfgHTM5YAbLijzCJ/cE8aE= 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=oEsrci97; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=H6se27k+; 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="oEsrci97"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="H6se27k+" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215537; 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=DmkEGbAndeVtTbYn7tYJisQDekeRo3+P4y3HvGXWKIM=; b=oEsrci97PKBvmdtdmHuqf7heP96ZSnfAv/FhNq1ZSZ2osSholKRJ8B67leodBEv54EP68f BmXPWDhMs6q8tsxFsdp8WQCqkYsqYXnQMrTEXjnGMyixJ7kOCVSW28fFHdCH1TOFjaGw3g EHE1/F/MskzjUlf+A/14eV5gY0bvk+37yRtG6r69mt+h1ry6IY9epMmyvKWkZkm5D58CpG WIGqAKasps2aPe8I6N4MqCgDmegA2NxysGtaeg+lKRUFMG25ZAUHv+VKh36oFcjgDubwWc ubW2J0fhDN2fGqdytLHnTUL2M9zcSLIjHWJfnLBMXgeIritrmluIrWwu7ROJbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215537; 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=DmkEGbAndeVtTbYn7tYJisQDekeRo3+P4y3HvGXWKIM=; b=H6se27k+mkC0UIQE18mLREaCc8vwNjoFyKRTm+Xxq25ozHqVReL/PM+l6y23QlAm+S4Kd/ JFWvwQErrw9+kCBg== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 02/11] riscv: kprobes: Move branch_funct3 to insn.h Date: Wed, 14 May 2025 11:38:41 +0200 Message-Id: <200c29a26338f19d09963fa02562787e8cfa06f2.1747215274.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. Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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 4a26cef3b5c0..ca9628c61885 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -447,6 +447,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 c= ode) #define RVC_RS2(insn) RV_X(insn, SH_RS2C, 5) #define RVC_X(X, s, mask) RV_X_mask(X, s, mask) =20 +#define RV_EXTRACT_FUNCT3(x) \ + ({typeof(x) x_ =3D (x); \ + (RV_X_mask(x_, RV_INSN_FUNCT3_OPOFF, RV_INSN_FUNCT3_MASK >> RV_INSN_FUNCT= 3_OPOFF)); }) + #define RV_EXTRACT_RS1_REG(x) \ ({typeof(x) x_ =3D (x); \ (RV_X_mask(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:51:03 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 9FB9922AE7A for ; Wed, 14 May 2025 09:38:59 +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=1747215541; cv=none; b=g/LZxgobSeOfaDvsA/nV2FwGLlT4AnfWy+eGav40LAS1G2wMV1RPRO7hxFCnxtnBjlgHKzeW/t2nJTlZkTL814Yx8BAEP+qKRtQbax4EKP3ZrWQS3WhC5ryLw8OacHE3Q4cUk8MKX0AQW3h17c9Q05DUlhllCMjQeaAo3a1QeW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215541; c=relaxed/simple; bh=pp8rXHmAAbML37R1XE9nWT97fOfbqMxBcQMy5qEtWuw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mOZrPTgYU7oGul0/7hnsDFjr2hYvw8/1nCrzEbANc8xYlha6rGtKWCmfbDWwkdZKK0Qj+/NXVhq1Ktp1fcqcAGwrrmYxQNze0Z5Md0nZiCOgkAlM1NFZiUxIgLZRULjIrAsABGbo/0Dr73rA9AEbWjHqF2IBihwTN9nOd9Lrxd4= 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=CjNOLa0k; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MREWsN+e; 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="CjNOLa0k"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MREWsN+e" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215537; 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=LK+Og6CgstdynsfQmcoHpOPeAtyjebuHccUKvOXx7QM=; b=CjNOLa0k4B30MmTLnXdLk3vjDzqeMwucYzVXriRYkskWy3Lx6AkhGPSMBz2sUka3u67E2r QpCrGj1/ZcLI+GiMVBmyYw8pUGBRHHBRfAfLjFg3QvJ0bup0J/HMbkQKPrVe2sFODu1cpB EQzigHl93WFISnE0JxMv4JlMwcwFjs18bgzjsMs1CI9bqTAxlVAYuQeOSsqTZxvUE0pc5q 0WN5uWelwOSlc7FJl21fGOGz+0uW2sdis0EjcqHsZM9iM37R5pFn1pjEtbzH8Tv2zpbb/b +ePW8jwhhOs39cXAizEIbzj4wBnYGsjIs0m/AKhivUcrYxS5NUpoo+mYdLCxRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215537; 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=LK+Og6CgstdynsfQmcoHpOPeAtyjebuHccUKvOXx7QM=; b=MREWsN+eYcLWH45438eJ/TnM+IWRxtCMgbkxzsoS+xk3eUCQcnN7LOcxS40DEE7f5AYitS 0rg3tQ9Q65Kk8CCQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 03/11] riscv: kprobes: Remove duplication of RV_EXTRACT_JTYPE_IMM Date: Wed, 14 May 2025 11:38:42 +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_JTYPE_IMM, instead of reimplementing it in simulate_jal(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 CDEE422B8D4 for ; Wed, 14 May 2025 09:39:00 +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=1747215542; cv=none; b=As47cOCh4oRPk6aNk4SLTmbcx6+3FomeMvJtnDKlaUCZFh4ikWlRhJwbkbmQU1AqHJAPl5P7HbhfdJs0N1YTvtFSnRMxKRkLWDvMIJgcPq/0nmMyipJ9Sc0PlLSX0DIQlFijMY7fnrb8uBWaiEraoMr7ZtCkNjZilDAtVdARN3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215542; c=relaxed/simple; bh=bAf1KeQgY+S4odA+zjDMDASFtXQ3F/v+Z+z9pyisvBI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=On0y+8qbHB0wvREWKFqFSS13TqyfDSwAkyNl9HFE1vV2wnLQD4WUKbMlJTOB4JDKBNrMsk12FuivUS26DDoJY5OwkGWXtqmBy075bd2bS4uFvkXgqYlryfEw5KvLnvcz8YC38t7xfhQIyTeJnZGA5FaXMZCO3lhfq38Nam5aktU= 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=Cab2874f; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k6wzvEby; 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="Cab2874f"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k6wzvEby" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215538; 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=yu9ObJyfNpp1PZ2rXY3qx0bjof6NU76pzsErYsbGgBo=; b=Cab2874fldAN3ra0e1pMc6uH6YhYOkMAwYo3z/w2R7k0yplAtAXUAhc4YNrXPeNZoWCdLX c6jmzzsfirM6B3JYyTGZ/FFoj6mEsr1NBtksf/c6UlQ6A555CEB7P0FLMTrepais4ab5ne QD3zkkzV8pCP1Z0DbxvF3tMzIFxXS0ktb1EDDAjp7fSkM2H4Jr6pYh+errNwMjrtcDy+ZE aL6WqarJ4PRZBDfJhCmzQtbnHNQp8blqUujp2kU0ZJD1CZVmfjd60CIupWxnPDAktMV3O5 UEd4rDGA7xYVW7JGfZYu5oYI2EyQ+ZamCr9el4ijL15kGK7U41sW7bync4oNlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215538; 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=yu9ObJyfNpp1PZ2rXY3qx0bjof6NU76pzsErYsbGgBo=; b=k6wzvEbyUSNIta1mdsVubFmN6ByhJLT6afy2aP4N7pZC4OgPjMw3BoN9QYDvmgBNtAvDAk ymX7B3MGb46v0ZDw== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 04/11] riscv: kprobes: Remove duplication of RV_EXTRACT_RS1_REG Date: Wed, 14 May 2025 11:38:43 +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_RS1_REG instead of reimplementing its code. Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 ECA7022D784 for ; Wed, 14 May 2025 09:39:01 +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=1747215543; cv=none; b=WshwX60vbhPxcofWQhn6NZjmAee8PTA7Gu+8ygXgjVb8pAMmgIHWkojxlapTPg9Kgt/pypLqSZPoeBUjl6Oke2IK++4Kn6gDVQJcAGpD2mwx9BdLCiUBO1gszQxpKKkDaPoNhLR48BXolIjoGK2oRnd7en9H1v2swSggtYJNYHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215543; c=relaxed/simple; bh=M1/D7MPNnjQjcqk8Eg9AFDFwi2xFP5mANRY2RmGfnqc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I82Ta3EuGhl/BWXcBt2T7AIlyN0Xo8pXgnI5PIWmCoEjpcQ9XCzj2IdymjLbQefNt0iJaJRHcUU4GlDUt1LSI2wKnlfYFnSxK6cyPONZbZVDwZPa8d/gX/t3LZmII6bsidEtQLOqomoS2ZEs/r9KIVj9tuv5H+ezPADSctWyb2A= 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=paBgdSFY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=brfBO61t; 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="paBgdSFY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="brfBO61t" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215539; 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=Bm9s++xQZUZyxfYID6OTBZXCHHY8y7W2MffQViKq4mg=; b=paBgdSFYfK7Y9o9pL9dp6Lh+/FJqZUM+RY14bCqNjjf7Hyp6GlHcgLkD6W8UX69OE3Xchk +u0D5op0cT2KyDmfbyW+ttQ+5KM6KcHPnvVsSEv6WBJTZ+DVtRYeJVGgnBfGV8Rk0b3Mh1 RrTWRdid8lNaSN3dqCNl2ZSO0PO1mjW9xTFIqcomzUfWCae7rYJqcrba//aVukyzDULRLG 2kbWHTzC5VBjBZFvkdgHkzahC6LAT8nNu6l5tDrhPJwaoQlzqZlpu/ZOGtyaM99sYWqa6r GxVMfxFIirq5ELM9bbbWaLYxFgG2ONltn+Fu5psObrRMM60uYWifEQ1sR80vPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215539; 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=Bm9s++xQZUZyxfYID6OTBZXCHHY8y7W2MffQViKq4mg=; b=brfBO61tAlr4TWR74+1t9HuFTaJnEhHy1EBa5WqxKMd4KVw4DeJbWwqNDs/MidtnwxvetA zIV+mc39//S3PzDA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 05/11] riscv: kprobes: Remove duplication of RV_EXTRACT_BTYPE_IMM Date: Wed, 14 May 2025 11:38:44 +0200 Message-Id: <07dde8313b787261f07ae25240c97c514cd02d11.1747215274.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(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 95E5122D4C4 for ; Wed, 14 May 2025 09:39:01 +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=1747215543; cv=none; b=UxjDJAQtk6c64FFvXoSAtMkoDJyoA+QBEyCtqqKLzWs82RMoJ/bO+0YtakpLfuKoR8HAfobtQmkO7WheR1IySS12hjSAcnHTS2BnJ5q6QE7pKKCb8yU4noSiqhNH2PQcQiSyVAwqmwsPUjmMbeBj58j64qfXlYAJsZkOM5SdqYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215543; c=relaxed/simple; bh=DIlIKAA3FTmrmkxh6MhK7D7f7OYAOaBEW9iov3Fhu+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O3i1Nr8lzFd13A2K9T00nfyLCKzLSVlbf3NdBlkhWVnzuMuBBnmdW0/j2qKKrIFgmaSd+OR8vw7gNCPPypUO/55bfyA6yD5XlI+AfqQ9CF9x/aRk0+qUjJX6Te6NsZRcS13k7VsHyIhI4J1jIeE7kuWNW7RHCfWj+AcVTnYBkl0= 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=0ljJnqd6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2ONDfHYd; 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="0ljJnqd6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2ONDfHYd" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215539; 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=k5zozQgL8hNfvDHr+6QpG+zfi9XouqRvI/psbV6Onzs=; b=0ljJnqd69eHsdExLWZE2Q0Z59kmesYbIMgxUkOSRtQb4VsNQpNnQnei7XvPZ11YVx6ofIq R0b0KfINrR3UX+bjFNdT8SsjAnE6/TNYp648636ag/1YLJp5c0a9OvQ1fOAi3Fq9db0qai x1cNZak6dI5IDk5LTMT+CKWbZ3Jwihy3b/Lf1pOd1LcWll1bBG7VfQEa9GLZOYnao8l8hU d+qTo5qPVX2E5cDdsHyQaxJsko9z2mA5WeISNFzjJ6DbndPkCz4oCsGeu9+8fsx3bFHAa+ X0jyPg8OI12Lw1dcm4sDP7s9oiAhwefA5O9AeYHc2XjkOUh+ai050v7s6L5eLQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215539; 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=k5zozQgL8hNfvDHr+6QpG+zfi9XouqRvI/psbV6Onzs=; b=2ONDfHYdBi3haCF5NDkeQvJSZUHBABqWTIDCyimkgJ+ByFxm++9pmMUkamj+RabqBULu7r BAfEYndGuB4xX/Aw== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 06/11] riscv: kproves: Remove duplication of RVC_EXTRACT_JTYPE_IMM Date: Wed, 14 May 2025 11:38:45 +0200 Message-Id: <24497deaab06d6b12cb84923606ec26f67e25424.1747215274.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(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 ECAEA22D789 for ; Wed, 14 May 2025 09:39:01 +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=1747215543; cv=none; b=XOMgRlX5GNGEXm+MWGF5f5D2PEHB9WjHUukBQpWxQFKAPAcHrg7FX1QR0dCr3NgCFe8Q5PzXpMquSbdYWXhyh536VLR7C+/wmE565i0i2n+A4T3DhIA1gGk3Q7Vx5OsHxbv1w6owPwejynGH9kQ8NS3jmE3rKU4aAs+94SO4jzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215543; c=relaxed/simple; bh=AubDRqfkPRHxBp7SUrQ2lcZs1wpYfs5RlqD8dw6LGIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HhfMd/dkI9MUMHtwvmhGFhX/ztm2W9B+SH25PDG+SXb9JQkGO5qvaB8hZCs9WWanaIwl35vKHRfa/c3zNgoCinXwC2Nb6eLUUGNT8FcyBVZaE46rXNl4e/7Av31Tpb8vTRyQT1clHR/h0vFfIhbXhX3nYDkc0/1+6sYCft/cjHw= 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=RyufCY3k; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ibtVUyaV; 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="RyufCY3k"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ibtVUyaV" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215539; 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=OfgQRDO7AB6uETq0DU5GYjI7YmKL4k2E304qWHHoNUk=; b=RyufCY3k//eNjv7tWeK1662ub2Z1eNq9TjWH1G8DQK4D6b8QfLj8WHd9EU6AIz25PNz3KV gjFDj1dWabJE9+kk7WBAlxgezpJSyahavni5xgGhb1RcWu2G4lZtCZgwdvpUdSj04ZnKdA 1qy4FBB8x78xGuRvSMvITyc1G4azGitqZaRZatOgtL1afnB7XZp8KuCyfSK7jEtkE2AdyK YRNocxKLzf0hwRcQK6JmfZIl+LRuH4lH9vJEip9gf8bK+EYOl6GHkQhQaj1fsgfaLYD3vX /U9BBLtNFi9Bbb6B4ev/v/qi9LvEEk5uYBg+2H8Z1Xmlzvbr/TfHKKKYMfhE9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215539; 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=OfgQRDO7AB6uETq0DU5GYjI7YmKL4k2E304qWHHoNUk=; b=ibtVUyaVu6qhfG/3XG4o82j7JacZZzxQp03SCi18+9zGlP8MgkBLnsK2EsFCVg/Zf6nSvK ZmyRew9ruVmob8BA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 07/11] riscv: kprobes: Remove duplication of RVC_EXTRACT_C2_RS1_REG Date: Wed, 14 May 2025 11:38:46 +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_C2_RS1_REG, instead of reimplementing it in simulate_c_jr_jalr(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 A6D5722D4DA for ; Wed, 14 May 2025 09:39:01 +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=1747215543; cv=none; b=VkO7I5fwkbDPIm05nnmEf6q2eTiGpqfcr/CIgHPf3uSVQHPsXea7g4H2f+ik/yE7Jv+cFLS6pfR+oC3JPvMWmUjZJzue0KCXBJVpfjY/E9nA8TdDxDO5Wa25Lo8IhXGUeWu0h3X0l8BKTpfbRH5cFEw2UwlqQnSgdQuphBas0GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215543; c=relaxed/simple; bh=r5hPhpC1GQ6SEgltegt9K/1SJ5+8vaXWcQjlQm5YELc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y1RUDLFjHH0mIzrDD9zj8RCF8101Oj9kbzvu2l4kkd9K4RTy1Ey/+opwA44gf3rg60sZO558M+9Y0NkrKCoHp26U2PSbtv32oFwY/G/jlGdC/YmZ++zt+zueXEpb6S7DdH+1x9T6QyZGOoxmfyUWoMMZ77dOKR/qznBmQVg1SBA= 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=NG6681rr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CkBVkwXf; 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="NG6681rr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CkBVkwXf" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215540; 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=KXzuHHlv6vCMZTxsn57Dyo4HmF+FRIx0y/mPLwDhWDc=; b=NG6681rr3N6qsdJvQl8R0k8Cxji29Zvu6cMLF5+HemAByizo6iFP5p59IsPg1tjnQf2Byy dI8m3wTM8iYbHKpssw/5neDMZIdXZI7MJHrqACe1HVGqgp91t82yLKc0smlZW6Ax+STRo9 cy5XAwokypHhHeokqY8A+xAqNYjtZ43TU3qcVG0a/B9YkOe2ULwaJJlso0lPeUkcdvfRL0 ZlWiWSXu/pL5tLR4gqSVjU8WPupjBW5K+10WAtBW/cudGQmAtpk6+XFe9tS0gvqmbOleo3 VNiwCg6NE92RjR5MJfUbx8XrdRClmOs3JAkf6VJEaMLwiBSy98h1H7doLwpXhA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215540; 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=KXzuHHlv6vCMZTxsn57Dyo4HmF+FRIx0y/mPLwDhWDc=; b=CkBVkwXfZ408sLldQe42mDAtMW4btZ/H0/yh2VHbMOiRmnwGu5fCKGBwrjvcTpGgbk08RO +xRPFdd4M8pZfHCA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 08/11] riscv: kprobes: Remove duplication of RVC_EXTRACT_BTYPE_IMM Date: Wed, 14 May 2025 11:38:47 +0200 Message-Id: <8a8ed970f279fa5f24c90d840c2130e37bc6d16e.1747215274.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_BTYPE_IMM, instead of reimplementing it in simulate_c_bnez_beqz(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 952DF22D7B7 for ; Wed, 14 May 2025 09:39:02 +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=1747215544; cv=none; b=MqhKXiQBbmhKHpM+Nj4iyCh3mn7n+U4pPhX0813qTerSvutrhTPVMhPfcqLzN5ytD+NEj6cdXg++KkwmMWyFsYnSjws7UPVK9B+R6OefQwJwFdkdmjW36IHiw6wejgOD+2hPumm2TQ+93LlxEwEsGciaynGPIaRuzGTxEVqMbm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215544; c=relaxed/simple; bh=2gM43omb8x6mSTqYiUz/2moBg01FcZhf0F+9slbotVs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AUmKpEtjmo+JIUO6hv67m/erCQ2ViT2YYMxsmFihOAz4ccWTiOsI+b1xAR0+oioNJ4m4AjREASKx16qo3raPjxwB2oibkOQ38Dx7UhfUzB8tc6VsMk5Gm51fL0RsOErC9Wy30JdXHzUR5kIYz1PgaaYKWeYUAqu4/70y8/0vv6k= 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=LkcgnH8c; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rXSEls3N; 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="LkcgnH8c"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rXSEls3N" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215540; 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=lDp33p40Fs1LitBtjBZir0UwSJ9OxuzJPP9MYbv6Fc8=; b=LkcgnH8cWHAmLFA4pMJkssj8pMMZACHqx4p5AjiUS9IiINzmH8+09AS29UnKZRbq8iimyf oLDu32l7xViCJAkc60RGG1AGbO9ZHNO1n/81dDv+zyG27Q+PBFQg/gMN8/yMgxw366JvKc xxOEImHJBw5E5upnU4Qss6zpAlwQE6lLmSU7HDaa3Zbq3u8F63b3B27Zf0DcYv69ayzpf3 TR+jkjUF5xYJacdAtdNnlhoPcwa+AE891+ObrkmY7jJlTFmpG2qHpsMFghnVvROTKU+Qvm tW/VJ9whm2/0nKS+Z4zd5mv/rgv3TFrhkKivi98FM+zHbdSBrvPNf/+tqm7TCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215540; 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=lDp33p40Fs1LitBtjBZir0UwSJ9OxuzJPP9MYbv6Fc8=; b=rXSEls3Ngno0szaoJwN4237PfBnnJgQ6yeAC/E36Vrahzxi+Wfsg2+hMkDXSqHjx4CT2RC sTsJhDPy3O+VVNDA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 09/11] riscv: kprobes: Remove duplication of RV_EXTRACT_RD_REG Date: Wed, 14 May 2025 11:38:48 +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_RD_REG, instead of reimplementing its code. Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 9534622D7B9 for ; Wed, 14 May 2025 09:39:02 +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=1747215544; cv=none; b=fl28V5SdhUOFz6dOYVqjCB/FzRQPhBmSD0zdP8fcrcPMlZVRWjNC5vYBcqh3IaVY8nOf8xJ3tiZXAkYo8fYkBgkibVagcktdI3/Sr51rO4yD3YC3P0MN45pTBzuzZRahaCAcDfCIOykXAAd9PoXdV7x8yhkEBsmCP7JGrvcV+JE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215544; c=relaxed/simple; bh=/Q9q/Al+zyku3gbniwLW13b/ret1Q4U4BiyV4vH3nbo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BBAksFHdBHaNxUUUiRnGPHz8Ma5NhmE1+Zvt9AYbHpEnRFlt8xEpvc1+XnzaH09aKZkz+XJtNDrxgAVUAcdzBQ4/qGQ3jFjKE+IcpLFE55cPKnw7okAV5SySZd2/jzSU/WyJEqQyyS7yRz9gbz8N9Dl1fnwZcg/zrTEzTHeWi9Y= 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=LKdT+UaQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hID/EosP; 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="LKdT+UaQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hID/EosP" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215540; 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=/HYROmeEdoYy7d9D9b1rSDF4X+kejBdVkRgxHg9uSSE=; b=LKdT+UaQjok9K6cAoxFHq6JRad8HL1SbzGffapUhJsnl8z+Em7APOJY4S+AkH+X91D1dxy Rq4TLIEg2F1RUqQsM57Ec/b/66Et+22IQbsnh38K9xOVL84IfQlbH5wX6Sl6i5/mkLoD5+ bObKa4ajpzqdkFLB8XgUPMu/ksRGdfD/EagieB+UwzpWHPmFxgNjtMH50aiAd/DIGZ30E7 DIQguFjxXjNsInTL5mhwZgndzfR5culv1aL+0fYvcfqOMAy0NPJ9cvCG2MFKcPVf+0A6lC 3llx8TKhrVVh8Huvoq3dPyikRIXwJKwAkAbG/c0KkyoMKBrOMVJgOtRYJftP0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215540; 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=/HYROmeEdoYy7d9D9b1rSDF4X+kejBdVkRgxHg9uSSE=; b=hID/EosP3UGjeC7eJHpk72qwU2yauIAJ3UY6yDJrd2Uu1+uiSQ55L/DOi6MrmptEZGkHJZ 3S3Z06bMPsP23RAA== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 10/11] riscv: kprobes: Remove duplication of RV_EXTRACT_UTYPE_IMM Date: Wed, 14 May 2025 11:38:49 +0200 Message-Id: <8f0defce9f1f23f1b44bb9750ed083cfc124213c.1747215274.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_UTYPE_IMM, instead of reimplementing it in simulate_auipc(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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:51:03 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 B431B22D9FF for ; Wed, 14 May 2025 09:39:02 +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=1747215544; cv=none; b=Z5KIQcQWbwQK8Dvp2LZ0SwmWO1Hr2dq7krWpK+cnBEEfyBFAB5ppqH6QdHgXP5A4JdPi8TT1iIgyUXnftzjSPfrrvF3p1qOfGR3TdeH5ACyUKfJUSNMDZpW/L2do99cO8pAICzTpIc7eeAgbz5TgcQRHhng/LhZSNhQn1Fg6fAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747215544; c=relaxed/simple; bh=bTLzb+Ezuh7TwlU6p0BQuHaTpUzDUWvpnpKsbIn10+4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rjrCRpyX/y9sKQl/XQZmEUy/hHzBWp0ukwrdeLERKmpMCFhQRp5Zp8bzFJUYVZL/uRZJV/JScSZQY3tNYK5RYSz/bCx6gaHUc7Klpp5lXccCSDn6MMpKTB3V41exj0inTII1X7wnbjzY9oN6rfKCn2oqY0Fy4bbdg/NF8g7g/4s= 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=DRvvYk6c; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=d38MzEbN; 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="DRvvYk6c"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d38MzEbN" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747215541; 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=K31BZ+j3XRd8vHo0dCxUnqdgWHJZ/Z7V6F2CPRYuCbE=; b=DRvvYk6c/U8XNuYzayAq7PxEtAYweKvWNdyc99uyL2joXAAABOHAdOI3pRm5eOFVFVEgUR MBSQGF63KB8eFq01XLppGYCSkBPzzqfCj+cW6DoMORslUFgaGCoun0dZ6MMqp4s2fTCfGi lZCbLz9fvn6wBNTCo8nwHe5CHpIqtBhqnzndo3heuQ7DiKYXdXaC/PWgqAKODAodptbU0C g/kf5t8cStoeBHG6ACz6Xt69cz0H86uA+sXA97VNFmDztTp39TzoxT+8w+f+HLpWzlftAl +Gt4CkXT6orIZ+ShHxBVnoNb9hp7K1SRA+DZpQaLSWVaflO9dCtalG4FghwZlQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747215541; 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=K31BZ+j3XRd8vHo0dCxUnqdgWHJZ/Z7V6F2CPRYuCbE=; b=d38MzEbN7AJxqLXq5RdEhXH154Ne6BMPE07o2CY8WmsywLpE0O7fi9iezjGRtFewNvDqXO 26244oroFV8C+HAw== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao , Alexandre Ghiti Subject: [PATCH v2 11/11] riscv: kprobes: Remove duplication of RV_EXTRACT_ITYPE_IMM Date: Wed, 14 May 2025 11:38:50 +0200 Message-Id: <8ae34e966c312ae5cf6c09a35ddc290cce942208.1747215274.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(). Reviewed-by: Alexandre Ghiti Signed-off-by: Nam Cao --- 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