From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 587F623395B for ; Fri, 26 Jun 2026 00:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782434311; cv=none; b=PljpjZ3QmNiVzdpHJE4ZBBOzANKOPGnNXZy13DPXSC0VScKb/ctYHQvpyPgd0W9nGNz4ud9CclYEtUv86wuVuIw2s2g4mE9eKKDke+VqiChTPdaG8ETm1WlMsUnSPvmvWt5mWM7Mn0K/4jKOc/Hp3wlXTZcvXII8sDlaBtqWLSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782434311; c=relaxed/simple; bh=S9hODJAlYUjK9uvaKP7PWmJVTmv+5u96tKUd4ZvoC9o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=on0XxYHC2Nu/be9XRu4oiqbowMnxTc8EyhPqwe+Zhv2xYH1ZNDV/1ZJC5pQTevbQgki4/BSNnx6bx42JvZ32Sn5dRzWhmO+VAOxOPFBJYNswPkovQWLA7piRVa8otRNC/CkBi89nAwW3w3xn6qH1JDeH0m4cUfSrs/JxpOsfgyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=S1DIjrlo; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="S1DIjrlo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=fh MsE8p2jCW4RlLJRbmQMBJQkSynZgS27q7zCiyCi7E=; b=S1DIjrloG4wcapJ/Ck S8XF5Hi2d0fEDbQtGcN/nvgGhDFs28m9MRj9uQi8WHVAw+LP4fZiOUa+xXWarR0d GvtysxvlojFPmMKvGZ0HAJj8D/rx18fGeRuQy6SQC/a7TGUsyWB4OuAPL993kdvc MvnobBdQFcTjIBy/nK7LpJOhU= Received: from Ubuntu.. (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wCHL9rQyT1qSV_8Fw--.51376S2; Fri, 26 Jun 2026 08:37:37 +0800 (CST) From: Xiaofeng Yuan To: pjw@kernel.org Cc: palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Xiaofeng Yuan Subject: [PATCH] riscv: probes: simulate c.jal instruction Date: Fri, 26 Jun 2026 00:37:35 +0000 Message-ID: <20260626003735.9066-1-xiaofengmian@163.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wCHL9rQyT1qSV_8Fw--.51376S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFW5tw15WF1DZFWkJw1DZFb_yoW5Aw13pF Z0k3Zxtrs8WF4kCr9xJrs5ur48Kws5K3ya9F4xtayFgr4agryfZwn2ga13AFsxtrySgryx G3sIqrykZa43JrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRLjjgUUUUU= X-CM-SenderInfo: p0ld0w5hqjzxldq6il2tof0z/xtbC5RGQk2o9ydEw7QAA3l The c.jal instruction is currently marked REJECTED in kprobes instruction decoding, but it should be SIMULATED like other compressed jump instructions. Add simulate_c_jal() which saves the return address to x1 (ra) and sets the program counter to the target offset, matching the behavior of c.j (which is already simulated) plus the link register write that distinguishes c.jal from c.j. Signed-off-by: Xiaofeng Yuan --- arch/riscv/kernel/probes/decode-insn.c | 2 +- arch/riscv/kernel/probes/simulate-insn.c | 16 ++++++++++++++++ arch/riscv/kernel/probes/simulate-insn.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/probes/decode-insn.c b/arch/riscv/kernel/probes/decode-insn.c index 65d9590bf..8506470e9 100644 --- a/arch/riscv/kernel/probes/decode-insn.c +++ b/arch/riscv/kernel/probes/decode-insn.c @@ -29,7 +29,7 @@ riscv_probe_decode_insn(probe_opcode_t *addr, struct arch_probe_insn *api) * TODO: the REJECTED ones below need to be implemented */ #ifdef CONFIG_RISCV_ISA_C - RISCV_INSN_REJECTED(c_jal, insn); + RISCV_INSN_SET_SIMULATE(c_jal, insn); RISCV_INSN_REJECTED(c_ebreak, insn); RISCV_INSN_SET_SIMULATE(c_j, insn); diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/probes/simulate-insn.c index fa581590c..9bf22b868 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -163,6 +163,22 @@ bool __kprobes simulate_c_j(u32 opcode, unsigned long addr, struct pt_regs *regs return true; } +bool __kprobes simulate_c_jal(u32 opcode, unsigned long addr, struct pt_regs *regs) +{ + bool ret; + s32 imm; + + ret = rv_insn_reg_set_val(regs, 1, addr + 2); + if (!ret) + return ret; + + imm = RVC_EXTRACT_JTYPE_IMM(opcode); + + instruction_pointer_set(regs, addr + imm); + + return ret; +} + static bool __kprobes simulate_c_jr_jalr(u32 opcode, unsigned long addr, struct pt_regs *regs, bool is_jalr) { diff --git a/arch/riscv/kernel/probes/simulate-insn.h b/arch/riscv/kernel/probes/simulate-insn.h index 44ebbc444..b89e1bb01 100644 --- a/arch/riscv/kernel/probes/simulate-insn.h +++ b/arch/riscv/kernel/probes/simulate-insn.h @@ -25,6 +25,7 @@ bool simulate_branch(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_jal(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_jalr(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_c_j(u32 opcode, unsigned long addr, struct pt_regs *regs); +bool simulate_c_jal(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_c_jr(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_c_jalr(u32 opcode, unsigned long addr, struct pt_regs *regs); bool simulate_c_bnez(u32 opcode, unsigned long addr, struct pt_regs *regs); -- 2.43.0