rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] objtool/LoongArch: Decode more instructions
@ 2025-09-16 12:25 Tiezhu Yang
  2025-09-16 12:25 ` [PATCH v2 1/2] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type Tiezhu Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tiezhu Yang @ 2025-09-16 12:25 UTC (permalink / raw)
  To: Huacai Chen, Miguel Ojeda, Josh Poimboeuf, Peter Zijlstra
  Cc: WANG Rui, rust-for-linux, loongarch, linux-kernel

v2: Add patch #2 suggested by WANG Rui.

Tiezhu Yang (2):
  objtool/LoongArch: Mark special atomic instruction as INSN_BUG type
  objtool/LoongArch: Mark types based on break immediate code

 tools/arch/loongarch/include/asm/inst.h | 12 +++++++++
 tools/objtool/arch/loongarch/decode.c   | 33 ++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type
  2025-09-16 12:25 [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Tiezhu Yang
@ 2025-09-16 12:25 ` Tiezhu Yang
  2025-09-16 12:25 ` [PATCH v2 2/2] objtool/LoongArch: Mark types based on break immediate code Tiezhu Yang
  2025-09-18  9:17 ` [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2025-09-16 12:25 UTC (permalink / raw)
  To: Huacai Chen, Miguel Ojeda, Josh Poimboeuf, Peter Zijlstra
  Cc: WANG Rui, rust-for-linux, loongarch, linux-kernel

When compiling with LLVM and CONFIG_RUST is set, there exists the
following objtool warning:

  rust/compiler_builtins.o: warning: objtool: __rust__unordsf2(): unexpected end of section .text.unlikely.

objdump shows that the end of section .text.unlikely is a atomic
instruction:

  amswap.w        $zero, $ra, $zero

According to the LoongArch Reference Manual, if the amswap.w atomic
memory access instruction has the same register number as rd and rj,
the execution will trigger an Instruction Non-defined Exception, so
mark the above instruction as INSN_BUG type to fix the warning.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/arch/loongarch/include/asm/inst.h | 12 ++++++++++++
 tools/objtool/arch/loongarch/decode.c   | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/tools/arch/loongarch/include/asm/inst.h b/tools/arch/loongarch/include/asm/inst.h
index c25b5853181d..d68fad63c8b7 100644
--- a/tools/arch/loongarch/include/asm/inst.h
+++ b/tools/arch/loongarch/include/asm/inst.h
@@ -51,6 +51,10 @@ enum reg2i16_op {
 	bgeu_op		= 0x1b,
 };
 
+enum reg3_op {
+	amswapw_op	= 0x70c0,
+};
+
 struct reg0i15_format {
 	unsigned int immediate : 15;
 	unsigned int opcode : 17;
@@ -96,6 +100,13 @@ struct reg2i16_format {
 	unsigned int opcode : 6;
 };
 
+struct reg3_format {
+	unsigned int rd : 5;
+	unsigned int rj : 5;
+	unsigned int rk : 5;
+	unsigned int opcode : 17;
+};
+
 union loongarch_instruction {
 	unsigned int word;
 	struct reg0i15_format	reg0i15_format;
@@ -105,6 +116,7 @@ union loongarch_instruction {
 	struct reg2i12_format	reg2i12_format;
 	struct reg2i14_format	reg2i14_format;
 	struct reg2i16_format	reg2i16_format;
+	struct reg3_format	reg3_format;
 };
 
 #define LOONGARCH_INSN_SIZE	sizeof(union loongarch_instruction)
diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c
index b6fdc68053cc..707f339b1840 100644
--- a/tools/objtool/arch/loongarch/decode.c
+++ b/tools/objtool/arch/loongarch/decode.c
@@ -278,6 +278,25 @@ static bool decode_insn_reg2i16_fomat(union loongarch_instruction inst,
 	return true;
 }
 
+static bool decode_insn_reg3_fomat(union loongarch_instruction inst,
+				   struct instruction *insn)
+{
+	switch (inst.reg3_format.opcode) {
+	case amswapw_op:
+		if (inst.reg3_format.rd == LOONGARCH_GPR_ZERO &&
+		    inst.reg3_format.rk == LOONGARCH_GPR_RA &&
+		    inst.reg3_format.rj == LOONGARCH_GPR_ZERO) {
+			/* amswap.w $zero, $ra, $zero */
+			insn->type = INSN_BUG;
+		}
+		break;
+	default:
+		return false;
+	}
+
+	return true;
+}
+
 int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
 			    unsigned long offset, unsigned int maxlen,
 			    struct instruction *insn)
@@ -309,6 +328,8 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 		return 0;
 	if (decode_insn_reg2i16_fomat(inst, insn))
 		return 0;
+	if (decode_insn_reg3_fomat(inst, insn))
+		return 0;
 
 	if (inst.word == 0)
 		insn->type = INSN_NOP;
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] objtool/LoongArch: Mark types based on break immediate code
  2025-09-16 12:25 [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Tiezhu Yang
  2025-09-16 12:25 ` [PATCH v2 1/2] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type Tiezhu Yang
@ 2025-09-16 12:25 ` Tiezhu Yang
  2025-09-18  9:17 ` [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2025-09-16 12:25 UTC (permalink / raw)
  To: Huacai Chen, Miguel Ojeda, Josh Poimboeuf, Peter Zijlstra
  Cc: WANG Rui, rust-for-linux, loongarch, linux-kernel

If the break immediate code is 0, it should mark the type
as INSN_TRAP. If the break immediate code is 1, it should
mark the type as INSN_BUG.

While at it, format the code style and add the code comment
for nop.

Suggested-by: WANG Rui <wangrui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/arch/loongarch/decode.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c
index 707f339b1840..2e555c4060c5 100644
--- a/tools/objtool/arch/loongarch/decode.c
+++ b/tools/objtool/arch/loongarch/decode.c
@@ -331,10 +331,16 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 	if (decode_insn_reg3_fomat(inst, insn))
 		return 0;
 
-	if (inst.word == 0)
+	if (inst.word == 0) {
+		/* andi $zero, $zero, 0x0 */
 		insn->type = INSN_NOP;
-	else if (inst.reg0i15_format.opcode == break_op) {
-		/* break */
+	} else if (inst.reg0i15_format.opcode == break_op &&
+		   inst.reg0i15_format.immediate == 0x0) {
+		/* break 0x0 */
+		insn->type = INSN_TRAP;
+	} else if (inst.reg0i15_format.opcode == break_op &&
+		   inst.reg0i15_format.immediate == 0x1) {
+		/* break 0x1 */
 		insn->type = INSN_BUG;
 	} else if (inst.reg2_format.opcode == ertn_op) {
 		/* ertn */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] objtool/LoongArch: Decode more instructions
  2025-09-16 12:25 [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Tiezhu Yang
  2025-09-16 12:25 ` [PATCH v2 1/2] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type Tiezhu Yang
  2025-09-16 12:25 ` [PATCH v2 2/2] objtool/LoongArch: Mark types based on break immediate code Tiezhu Yang
@ 2025-09-18  9:17 ` Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Huacai Chen @ 2025-09-18  9:17 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Miguel Ojeda, Josh Poimboeuf, Peter Zijlstra, WANG Rui,
	rust-for-linux, loongarch, linux-kernel

Applied if no objections, thanks.

Huacai

On Tue, Sep 16, 2025 at 8:25 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> v2: Add patch #2 suggested by WANG Rui.
>
> Tiezhu Yang (2):
>   objtool/LoongArch: Mark special atomic instruction as INSN_BUG type
>   objtool/LoongArch: Mark types based on break immediate code
>
>  tools/arch/loongarch/include/asm/inst.h | 12 +++++++++
>  tools/objtool/arch/loongarch/decode.c   | 33 ++++++++++++++++++++++---
>  2 files changed, 42 insertions(+), 3 deletions(-)
>
> --
> 2.42.0
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-18  9:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-16 12:25 [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Tiezhu Yang
2025-09-16 12:25 ` [PATCH v2 1/2] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type Tiezhu Yang
2025-09-16 12:25 ` [PATCH v2 2/2] objtool/LoongArch: Mark types based on break immediate code Tiezhu Yang
2025-09-18  9:17 ` [PATCH v2 0/2] objtool/LoongArch: Decode more instructions Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).