From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 5C59F3D666A for ; Wed, 1 Jul 2026 08:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782893498; cv=none; b=qWeRm2YmaoGkPkQCdko9x4FBxjLc221e/oVsV0P1xbv01xdJSKqujGJkJ7HVAMaFHF0eOzDrX+9IOETsoBYBNaum5dRvmcWy/B/6kgo+oIG/KCN33ZPnxv5bCjG9ATNJs74YbtYKcOt2io+uO8CieXstYV2/q1dRuKdekmIvdSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782893498; c=relaxed/simple; bh=+QLOLetQqWOfo38TzZa8lMogc4xu9b5D7H1CTl3J49Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=crKZXXHHncwghqycVuwbfcsus1p1rNUEBZGtt6RdArmOHr/4HvF522FC6Jiz/u9QfIuPZIs456n5o+rSdWSYu1Y9lDiN0vHiJZTkIwMldoW3rgnmrSqSULcKFVthjq2/RaqpCFsNT1fbkFzLamW9AlLzIEeFM1mRodOS/FHyrS4= 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=gfbxho+i; arc=none smtp.client-ip=220.197.31.5 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="gfbxho+i" 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=85 WdK5a0G3ftqPEwXololIbO2+LxNvhlBoJUoxbyghk=; b=gfbxho+iXxFhoVVxGm 7ndkwX7JnUoLBNEGS/Y25+xx5mF/bxjdrm2q0wnE3kQMv6X92YM0hBQqf3DrMDCL XTYcDDJHtJDHcV73Gve1k3MGRm+ET9b+nwEcztChd9gFcdvJUpJ8uybQPXpDvrP9 YC6YbY2aTIQp4myhaIFKfnrvA= Received: from Ubuntu.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgBHa+Z5y0Rqn4gyFA--.16458S3; Wed, 01 Jul 2026 16:10:35 +0800 (CST) From: Xiaofeng Yuan To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Charlie Jenkins , Nam Cao , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, xiaofengmian@163.com Subject: [PATCH v6 1/2] riscv: probes: simulate c.jal instruction Date: Wed, 1 Jul 2026 08:10:32 +0000 Message-ID: <20260701081033.49871-2-xiaofengmian@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260701081033.49871-1-xiaofengmian@163.com> References: <20260701081033.49871-1-xiaofengmian@163.com> 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:PygvCgBHa+Z5y0Rqn4gyFA--.16458S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFWruF47Xw17tF1fZFyfXrb_yoW5ZrW5pF s0k3Zxtrs8uF4kCr9xJrn3ur48Kws5K3ya9a1xta1Fgw4agryfZwn2qanxJFsrtrySgryx G3s0qrykA3y3A37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piF4EtUUUUU= X-CM-SenderInfo: p0ld0w5hqjzxldq6il2tof0z/xtbC5Ru8v2pEy3vHkwAA33 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 RA and sets the program counter to the target offset, reusing simulate_c_j for the common jump logic. Although c.jal is RV32-only, the function compiles unconditionally. On RV64, riscv_insn_is_c_jal() always returns 0, so the simulation code is never invoked and the small overhead in kernel size is acceptable. Signed-off-by: Xiaofeng Yuan --- arch/riscv/kernel/probes/decode-insn.c | 2 +- arch/riscv/kernel/probes/simulate-insn.c | 7 +++++++ arch/riscv/kernel/probes/simulate-insn.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/probes/decode-insn.c b/arch/riscv/kernel/probes/decode-insn.c index 65d9590bf..433d9035b 100644 --- a/arch/riscv/kernel/probes/decode-insn.c +++ b/arch/riscv/kernel/probes/decode-insn.c @@ -29,12 +29,12 @@ 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_REJECTED(c_ebreak, insn); RISCV_INSN_SET_SIMULATE(c_j, insn); RISCV_INSN_SET_SIMULATE(c_jr, insn); RISCV_INSN_SET_SIMULATE(c_jalr, insn); + RISCV_INSN_SET_SIMULATE(c_jal, insn); RISCV_INSN_SET_SIMULATE(c_beqz, insn); RISCV_INSN_SET_SIMULATE(c_bnez, insn); #endif diff --git a/arch/riscv/kernel/probes/simulate-insn.c b/arch/riscv/kernel/probes/simulate-insn.c index fa581590c..f8a2f6857 100644 --- a/arch/riscv/kernel/probes/simulate-insn.c +++ b/arch/riscv/kernel/probes/simulate-insn.c @@ -163,6 +163,13 @@ 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) +{ + regs->ra = addr + 2; + + return simulate_c_j(opcode, addr, regs); +} + 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