riscv: vector: only enable interrupts in the first-use trap
PATCH 1/1 riscv: vector: only enable interrupts in the first-use trap
The function irqentry_exit_to_user_mode() must be called with interrupt disabled. The caller of do_trap_insn_illegal() also assumes running without interrupts. So, we should turn off interrupts after riscv_v_first_use_handler() returns.
--- arch/riscv/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/riscv/kernel/traps.c +7 -1
@@ -149,12 +149,18 @@ DO_ERROR_INFO(do_trap_insn_fault, asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs) { +bool handled; +if (user_mode (regs)) {irqentry_enter_from_user_mode (regs);local_irq_enable (); -if (!riscv_v_first_use_handler (regs)) + handled =riscv_v_first_use_handler (regs); + +local_irq_disable (); + +if (!handled)do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" );
Signature · 7 lines
2.17.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 7 lines · Andy Chiu
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>
Good catch,
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 19 lines · Andy Chiu
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>--- arch/riscv/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/riscv/kernel/traps.c +0
-0@@ -149,12 +149,18 @@ DO_ERROR_INFO(do_trap_insn_fault, asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs)
arch/riscv/kernel/traps.c DO_ERROR_INFO(do_trap_insn_fault, · line 159
Quoted 10 lines
arch/riscv/kernel/traps.c +3
-1{ +bool handled; +if (user_mode (regs)) {irqentry_enter_from_user_mode (regs);local_irq_enable (); -if (!riscv_v_first_use_handler (regs)) + handled =riscv_v_first_use_handler (regs);
How about making riscv_v_first_use_handler irq_disable safe?
--------
arch/riscv/kernel/traps.c +0 -0
@@ -153,8 +153,6 @@ asmlinkage __visible __trap_section void
do_trap_insn_illegal(struct pt_regs *re
if (user_mode(regs)) {
irqentry_enter_from_user_mode(regs);- local_irq_enable();
-
if (!riscv_v_first_use_handler(regs))
do_trap_error(regs, SIGILL, ILL_ILLOPC, regs->epc,
"Oops - illegal instruction");arch/riscv/kernel/vector.c +1 -2
@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; - datap =kzalloc (riscv_v_vsize,GFP_KERNEL ); + datap =kzalloc (riscv_v_vsize,GFP_KERNEL |GFP_ATOMIC );if (!datap)return -ENOMEM ; ---------
Quoted 10 lines
arch/riscv/kernel/traps.c +4
-1+ +local_irq_disable (); + +if (!handled)do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" ); --2.17.1
Signature · 7 lines
Best Regards Guo Ren _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Another one:
arch/riscv/kernel/vector.c +3 -4
@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; datap =kzalloc (riscv_v_vsize,GFP_KERNEL );if (!datap)return -ENOMEM ;
@@ -162,10 +162,9 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)* context where VS has been off. So, try to allocate the user's V * context and resume execution. */ -if (riscv_v_thread_zalloc ()) { -force_sig (SIGBUS ); -return true; - } +if (riscv_v_thread_zalloc ()) +return false; +riscv_v_vstate_on (regs);return true; }
--------
Your force_sig throws the debug info away, and the standard one is enough for us.
Quoted 76 lines · Guo Ren
Quoted 19 lines · Andy Chiu
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>--- arch/riscv/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/riscv/kernel/traps.c +0
-0@@ -149,12 +149,18 @@ DO_ERROR_INFO(do_trap_insn_fault, asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs)arch/riscv/kernel/traps.c DO_ERROR_INFO(do_trap_insn_fault, · line 159
Quoted 10 lines
arch/riscv/kernel/traps.c +3
-1{ +bool handled; +if (user_mode (regs)) {irqentry_enter_from_user_mode (regs);local_irq_enable (); -if (!riscv_v_first_use_handler (regs)) + handled =riscv_v_first_use_handler (regs);How about making
riscv_v_first_use_handlerirq_disablesafe?
--------arch/riscv/kernel/traps.c +0
-0@@ -153,8 +153,6 @@ asmlinkage __visible __trap_section voiddo_trap_insn_illegal(struct
pt_regs*reif (user_mode(regs)) { irqentry_enter_from_user_mode(regs);arch/riscv/kernel/traps.c +0
-2-local_irq_enable (); -if (!riscv_v_first_use_handler (regs))do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" );arch/riscv/kernel/vector.c +1
-2@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; - datap =kzalloc (riscv_v_vsize,GFP_KERNEL ); + datap =kzalloc (riscv_v_vsize,GFP_KERNEL |GFP_ATOMIC );if (!datap)return -ENOMEM ; ---------Quoted 11 lines
arch/riscv/kernel/traps.c +4
-1+ +local_irq_disable (); + +if (!handled)do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" ); --2.17.1
--
Best Regards
Guo Ren
Signature · 7 lines
Best Regards Guo Ren _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Hi Guo,
Quoted 30 lines · Guo Ren
Another one:
arch/riscv/kernel/vector.c +3
-5@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; datap =kzalloc (riscv_v_vsize,GFP_KERNEL );if (!datap)return -ENOMEM ;@@ -162,10 +162,9 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)* context where VS has been off. So, try to allocate the user's V * context and resume execution. */ -if (riscv_v_thread_zalloc ()) { -force_sig (SIGBUS ); -return true; - } +if (riscv_v_thread_zalloc ()) +return false; +riscv_v_vstate_on (regs);return true; } --------
Quoted 2 lines
Your
force_sigthrows the debug info away, and the standard one is enough for us.
Could you help me to understand more on how this throws debug info away? Do you mean the pr_info() print in the do_trap() function? If we'd want to use the standard one then we should instead return a signal number in riscv_v_first_use_handler(). Because we want to send SIGBUS instead of SIGILL.
Quoted 81 lines · Guo Ren
Quoted 68 lines · Andy Chiu
Quoted 19 lines
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>--- arch/riscv/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/riscv/kernel/traps.c +0
-0@@ -149,12 +149,18 @@ DO_ERROR_INFO(do_trap_insn_fault, asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs)arch/riscv/kernel/traps.c DO_ERROR_INFO(do_trap_insn_fault, · line 159
Quoted 10 lines
arch/riscv/kernel/traps.c +3
-1{ +bool handled; +if (user_mode (regs)) {irqentry_enter_from_user_mode (regs);local_irq_enable (); -if (!riscv_v_first_use_handler (regs)) + handled =riscv_v_first_use_handler (regs);How about making
riscv_v_first_use_handlerirq_disablesafe?
--------arch/riscv/kernel/traps.c +0
-0@@ -153,8 +153,6 @@ asmlinkage __visible __trap_section voiddo_trap_insn_illegal(struct
pt_regs*reif (user_mode(regs)) { irqentry_enter_from_user_mode(regs);arch/riscv/kernel/traps.c +0
-2-local_irq_enable (); -if (!riscv_v_first_use_handler (regs))do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" );arch/riscv/kernel/vector.c +1
-2@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; - datap =kzalloc (riscv_v_vsize,GFP_KERNEL ); + datap =kzalloc (riscv_v_vsize,GFP_KERNEL |GFP_ATOMIC );if (!datap)return -ENOMEM ; ---------Quoted 8 lines
arch/riscv/kernel/traps.c +4
-0+ +local_irq_disable (); + +if (!handled)do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" );Quoted 8 lines
Quoted 3 lines
--
2.17.1--
Best Regards
Guo Ren
Quoted 3 lines
--
Best Regards
Guo Ren
Thanks,
Andy
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 34 lines · Andy Chiu
Hi Guo,
Quoted 30 lines · Guo Ren
Another one:
arch/riscv/kernel/vector.c +3
-5@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; datap =kzalloc (riscv_v_vsize,GFP_KERNEL );if (!datap)return -ENOMEM ;@@ -162,10 +162,9 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)* context where VS has been off. So, try to allocate the user's V * context and resume execution. */ -if (riscv_v_thread_zalloc ()) { -force_sig (SIGBUS ); -return true; - } +if (riscv_v_thread_zalloc ()) +return false; +riscv_v_vstate_on (regs);return true; } --------
Quoted 5 lines
Quoted 2 lines
Your
force_sigthrows the debug info away, and the standard one is enough for us.Could you help me to understand more on how this throws debug info away? Do you mean the
pr_info()print in thedo_trap()function? If
Yes, you code just send a sig, but no debug info.
Quoted 3 lines
we'd want to use the standard one then we should instead return a signal number in
riscv_v_first_use_handler(). Because we want to send SIGBUS instead of SIGILL.
Do we really need a SIGBUS here?
When we can't handle this instruction, treat it as a invalid one. SIGILL - invalid program image, such as invalid instruction SIGBUS - abbreviation for “Bus Error”.
Quoted 82 lines
Quoted 82 lines · Guo Ren
Quoted 76 lines · Andy Chiu
Quoted 19 lines
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>--- arch/riscv/kernel/traps.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/riscv/kernel/traps.c +0
-0@@ -149,12 +149,18 @@ DO_ERROR_INFO(do_trap_insn_fault, asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *regs)arch/riscv/kernel/traps.c DO_ERROR_INFO(do_trap_insn_fault, · line 159
Quoted 10 lines
arch/riscv/kernel/traps.c +3
-1{ +bool handled; +if (user_mode (regs)) {irqentry_enter_from_user_mode (regs);local_irq_enable (); -if (!riscv_v_first_use_handler (regs)) + handled =riscv_v_first_use_handler (regs);How about making
riscv_v_first_use_handlerirq_disablesafe?
--------arch/riscv/kernel/traps.c +0
-0@@ -153,8 +153,6 @@ asmlinkage __visible __trap_section voiddo_trap_insn_illegal(struct
pt_regs*reif (user_mode(regs)) { irqentry_enter_from_user_mode(regs);arch/riscv/kernel/traps.c +0
-2-local_irq_enable (); -if (!riscv_v_first_use_handler (regs))do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" );arch/riscv/kernel/vector.c +1
-2@@ -84,7 +84,7 @@ static int riscv_v_thread_zalloc(void) {void *datap; - datap =kzalloc (riscv_v_vsize,GFP_KERNEL ); + datap =kzalloc (riscv_v_vsize,GFP_KERNEL |GFP_ATOMIC );if (!datap)return -ENOMEM ; ---------Quoted 11 lines
arch/riscv/kernel/traps.c +4
-1+ +local_irq_disable (); + +if (!handled)do_trap_error (regs,SIGILL ,ILL_ILLOPC , regs->epc,"Oops - illegal instruction" ); --2.17.1
--
Best Regards
Guo Ren
Quoted 6 lines
Quoted 3 lines
--
Best Regards
Guo RenThanks,
Andy
--
Best Regards
Guo Ren
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
AppliedQuoted 6 lines · Andy Chiu
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.
Applied, thanks!
[1/1] riscv: vector: only enable interrupts in the first-use trap
https://git.kernel.org/palmer/c/26c38cd802c9
Best regards,
Signature · 7 lines
Palmer Dabbelt <[email protected]> _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Quoted 9 lines · On Sun, 25 Jun 2023 15:54:15 +0000 you wrote:
The function
irqentry_exit_to_user_mode()must be called with interrupt disabled. The caller ofdo_trap_insn_illegal()also assumes running without interrupts. So, we should turn off interrupts afterriscv_v_first_use_handler()returns.Fixes cd054837243b ("riscv: Allocate user's vector context in the first-use trap")Signed-off-by Andy Chiu <[email protected]>[...]
Here is the summary with links:
- riscv: vector: only enable interrupts in the first-use trap
https://git.kernel.org/riscv/c/26c38cd802c9
You are awesome, thank you!
Signature · 9 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv