* [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation
@ 2025-04-11 7:29 WangYuli
2025-04-11 7:32 ` [PATCH v4 1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint() WangYuli
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: WangYuli @ 2025-04-11 7:29 UTC (permalink / raw)
To: paul.walmsley, palmer, aou, alex
Cc: wangyuli, chenhuacai, linux-riscv, linux-kernel, vincent.chen,
palmerdabbelt, samuel.holland, zhanjun, niecheng1, guanwentao
1. The arch_kgdb_breakpoint() function defines the kgdb_compiled_break
symbol using inline assembly.
There's a potential issue where the compiler might inline
arch_kgdb_breakpoint(), which would then define the kgdb_compiled_break
symbol multiple times, leading to fail to link vmlinux.o.
This isn't merely a potential compilation problem. The intent here
is to determine the global symbol address of kgdb_compiled_break,
and if this function is inlined multiple times, it would logically
be a grave error.
2. Remove ".option norvc/.option rvc" to fix a bug that the C extension
would unconditionally enable even if the kernel is being built with
CONFIG_RISCV_ISA_C=n.
WangYuli (2):
riscv: KGDB: Do not inline arch_kgdb_breakpoint()
riscv: KGDB: Remove ".option norvc/.option rvc" for
kgdb_compiled_break
arch/riscv/include/asm/kgdb.h | 9 +--------
arch/riscv/kernel/kgdb.c | 6 ++++++
2 files changed, 7 insertions(+), 8 deletions(-)
--
2.49.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint()
2025-04-11 7:29 [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation WangYuli
@ 2025-04-11 7:32 ` WangYuli
2025-04-11 7:32 ` [PATCH v4 2/2] riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break WangYuli
2025-04-16 18:42 ` [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation patchwork-bot+linux-riscv
2 siblings, 0 replies; 4+ messages in thread
From: WangYuli @ 2025-04-11 7:32 UTC (permalink / raw)
To: wangyuli
Cc: alex, aou, chenhuacai, guanwentao, linux-kernel, linux-riscv,
niecheng1, palmer, palmerdabbelt, paul.walmsley, samuel.holland,
vincent.chen, zhanjun, Huacai Chen
The arch_kgdb_breakpoint() function defines the kgdb_compiled_break
symbol using inline assembly.
There's a potential issue where the compiler might inline
arch_kgdb_breakpoint(), which would then define the kgdb_compiled_break
symbol multiple times, leading to fail to link vmlinux.o.
This isn't merely a potential compilation problem. The intent here
is to determine the global symbol address of kgdb_compiled_break,
and if this function is inlined multiple times, it would logically
be a grave error.
Link: https://lore.kernel.org/all/4b4187c1-77e5-44b7-885f-d6826723dd9a@sifive.com/
Link: https://lore.kernel.org/all/5b0adf9b-2b22-43fe-ab74-68df94115b9a@ghiti.fr/
Link: https://lore.kernel.org/all/23693e7f-4fff-40f3-a437-e06d827278a5@ghiti.fr/
Fixes: fe89bd2be866 ("riscv: Add KGDB support")
Co-developed-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
---
Changelog:
*v1->v2:
1. Add the missing __ASSEMBLY__ check and substitute
".option rvc/norvc" with ".option push/pop".
v2->v3:
1. Remove "extern".
2. Restore the inadvertently deleted .option norvc to prevent
a change in semantics.
v3->v4:
1. Replace kgdb_breakinst into kgdb_compiled_break.
2. Split the origin patch into 2.
---
arch/riscv/include/asm/kgdb.h | 9 +--------
arch/riscv/kernel/kgdb.c | 8 ++++++++
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/arch/riscv/include/asm/kgdb.h b/arch/riscv/include/asm/kgdb.h
index 46677daf708b..cc11c4544cff 100644
--- a/arch/riscv/include/asm/kgdb.h
+++ b/arch/riscv/include/asm/kgdb.h
@@ -19,16 +19,9 @@
#ifndef __ASSEMBLY__
+void arch_kgdb_breakpoint(void);
extern unsigned long kgdb_compiled_break;
-static inline void arch_kgdb_breakpoint(void)
-{
- asm(".global kgdb_compiled_break\n"
- ".option norvc\n"
- "kgdb_compiled_break: ebreak\n"
- ".option rvc\n");
-}
-
#endif /* !__ASSEMBLY__ */
#define DBG_REG_ZERO "zero"
diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c
index 2e0266ae6bd7..5d1ce8dacaf5 100644
--- a/arch/riscv/kernel/kgdb.c
+++ b/arch/riscv/kernel/kgdb.c
@@ -254,6 +254,14 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
regs->epc = pc;
}
+noinline void arch_kgdb_breakpoint(void)
+{
+ asm(".global kgdb_compiled_break\n"
+ ".option norvc\n"
+ "kgdb_compiled_break: ebreak\n"
+ ".option rvc\n");
+}
+
void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
char *remcom_out_buffer)
{
--
2.49.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v4 2/2] riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break
2025-04-11 7:29 [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation WangYuli
2025-04-11 7:32 ` [PATCH v4 1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint() WangYuli
@ 2025-04-11 7:32 ` WangYuli
2025-04-16 18:42 ` [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation patchwork-bot+linux-riscv
2 siblings, 0 replies; 4+ messages in thread
From: WangYuli @ 2025-04-11 7:32 UTC (permalink / raw)
To: wangyuli
Cc: alex, aou, chenhuacai, guanwentao, linux-kernel, linux-riscv,
niecheng1, palmer, palmerdabbelt, paul.walmsley, samuel.holland,
vincent.chen, zhanjun
[ Quoting Samuel Holland: ]
This is a separate issue, but using ".option rvc" here is a bug.
It will unconditionally enable the C extension for the rest of
the file, even if the kernel is being built with CONFIG_RISCV_ISA_C=n.
[ Quoting Palmer Dabbelt: ]
We're just looking at the address of kgdb_compiled_break, so it's
fine if it ends up as a c.ebreak.
[ Quoting Alexandre Ghiti: ]
.option norvc is used to prevent the assembler from using compressed
instructions, but it's generally used when we need to ensure the
size of the instructions that are used, which is not the case here
as noted by Palmer since we only care about the address. So yes
it will work fine with C enabled :)
So let's just remove them all.
Link: https://lore.kernel.org/all/4b4187c1-77e5-44b7-885f-d6826723dd9a@sifive.com/
Link: https://lore.kernel.org/all/mhng-69513841-5068-441d-be8f-2aeebdc56a08@palmer-ri-x1c9a/
Link: https://lore.kernel.org/all/23693e7f-4fff-40f3-a437-e06d827278a5@ghiti.fr/
Fixes: fe89bd2be866 ("riscv: Add KGDB support")
Cc: Samuel Holland <samuel.holland@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
---
arch/riscv/kernel/kgdb.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c
index 5d1ce8dacaf5..9f3db3503dab 100644
--- a/arch/riscv/kernel/kgdb.c
+++ b/arch/riscv/kernel/kgdb.c
@@ -257,9 +257,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
noinline void arch_kgdb_breakpoint(void)
{
asm(".global kgdb_compiled_break\n"
- ".option norvc\n"
- "kgdb_compiled_break: ebreak\n"
- ".option rvc\n");
+ "kgdb_compiled_break: ebreak\n");
}
void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
--
2.49.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation
2025-04-11 7:29 [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation WangYuli
2025-04-11 7:32 ` [PATCH v4 1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint() WangYuli
2025-04-11 7:32 ` [PATCH v4 2/2] riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break WangYuli
@ 2025-04-16 18:42 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-04-16 18:42 UTC (permalink / raw)
To: WangYuli
Cc: linux-riscv, paul.walmsley, palmer, aou, alex, chenhuacai,
linux-kernel, vincent.chen, palmerdabbelt, samuel.holland,
zhanjun, niecheng1, guanwentao
Hello:
This series was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Fri, 11 Apr 2025 15:29:04 +0800 you wrote:
> 1. The arch_kgdb_breakpoint() function defines the kgdb_compiled_break
> symbol using inline assembly.
>
> There's a potential issue where the compiler might inline
> arch_kgdb_breakpoint(), which would then define the kgdb_compiled_break
> symbol multiple times, leading to fail to link vmlinux.o.
>
> [...]
Here is the summary with links:
- [v4,1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint()
https://git.kernel.org/riscv/c/3af4bec9c1db
- [v4,2/2] riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break
https://git.kernel.org/riscv/c/550c2aa787d1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-16 18:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 7:29 [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation WangYuli
2025-04-11 7:32 ` [PATCH v4 1/2] riscv: KGDB: Do not inline arch_kgdb_breakpoint() WangYuli
2025-04-11 7:32 ` [PATCH v4 2/2] riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break WangYuli
2025-04-16 18:42 ` [PATCH v4 0/2] riscv: Rework the arch_kgdb_breakpoint() implementation patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox