* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
@ 2024-04-09 2:24 Pope B.Lei
2024-04-09 2:27 ` Pope B.Lei
2024-04-09 7:44 ` Andreas Schwab
0 siblings, 2 replies; 7+ messages in thread
From: Pope B.Lei @ 2024-04-09 2:24 UTC (permalink / raw)
To: opensbi
Although Mstatus.MPV is set, before executing mret, access to VS mode
registers should use the actual register addresses, not the pseudonyms
of S registers.
Signed-off-by: Pope B.Lei <popeblei@gmail.com>
---
lib/sbi/sbi_hart.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 3d13694..e145cdc 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
csr_write(CSR_MEPC, next_addr);
if (next_mode == PRV_S) {
- csr_write(CSR_STVEC, next_addr);
- csr_write(CSR_SSCRATCH, 0);
- csr_write(CSR_SIE, 0);
- csr_write(CSR_SATP, 0);
+ if (true == next_virt){
+ csr_write(CSR_VSTVEC, next_addr);
+ csr_write(CSR_VSSCRATCH, 0);
+ csr_write(CSR_VSIE, 0);
+ csr_write(CSR_VSATP, 0);
+ } else if (false == next_virt){
+ csr_write(CSR_STVEC, next_addr);
+ csr_write(CSR_SSCRATCH, 0);
+ csr_write(CSR_SIE, 0);
+ csr_write(CSR_SATP, 0);
+ }
} else if (next_mode == PRV_U) {
if (misa_extension('N')) {
csr_write(CSR_UTVEC, next_addr);
--
2.35.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
2024-04-09 2:24 [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode Pope B.Lei
@ 2024-04-09 2:27 ` Pope B.Lei
2024-04-09 7:44 ` Andreas Schwab
1 sibling, 0 replies; 7+ messages in thread
From: Pope B.Lei @ 2024-04-09 2:27 UTC (permalink / raw)
To: opensbi
Dear All:
I discovered a subtle bug during the process of switching to VS
mode. The issue arises because, even though Mstatus.MPV is set, before
executing mret, one should access the VS mode registers using their
actual addresses, rather than using the pseudonyms of the S registers.
Best Regards!
Boswell Lei
On Tue, Apr 9, 2024 at 10:24?AM Pope B.Lei <popeblei@gmail.com> wrote:
>
> Although Mstatus.MPV is set, before executing mret, access to VS mode
> registers should use the actual register addresses, not the pseudonyms
> of S registers.
>
> Signed-off-by: Pope B.Lei <popeblei@gmail.com>
> ---
> lib/sbi/sbi_hart.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 3d13694..e145cdc 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
> csr_write(CSR_MEPC, next_addr);
>
> if (next_mode == PRV_S) {
> - csr_write(CSR_STVEC, next_addr);
> - csr_write(CSR_SSCRATCH, 0);
> - csr_write(CSR_SIE, 0);
> - csr_write(CSR_SATP, 0);
> + if (true == next_virt){
> + csr_write(CSR_VSTVEC, next_addr);
> + csr_write(CSR_VSSCRATCH, 0);
> + csr_write(CSR_VSIE, 0);
> + csr_write(CSR_VSATP, 0);
> + } else if (false == next_virt){
> + csr_write(CSR_STVEC, next_addr);
> + csr_write(CSR_SSCRATCH, 0);
> + csr_write(CSR_SIE, 0);
> + csr_write(CSR_SATP, 0);
> + }
> } else if (next_mode == PRV_U) {
> if (misa_extension('N')) {
> csr_write(CSR_UTVEC, next_addr);
> --
> 2.35.2.windows.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
2024-04-09 2:24 [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode Pope B.Lei
2024-04-09 2:27 ` Pope B.Lei
@ 2024-04-09 7:44 ` Andreas Schwab
1 sibling, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2024-04-09 7:44 UTC (permalink / raw)
To: opensbi
On Apr 09 2024, Pope B.Lei wrote:
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 3d13694..e145cdc 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
> csr_write(CSR_MEPC, next_addr);
>
> if (next_mode == PRV_S) {
> - csr_write(CSR_STVEC, next_addr);
> - csr_write(CSR_SSCRATCH, 0);
> - csr_write(CSR_SIE, 0);
> - csr_write(CSR_SATP, 0);
> + if (true == next_virt){
Never compare a boolean with a constant.
> + csr_write(CSR_VSTVEC, next_addr);
> + csr_write(CSR_VSSCRATCH, 0);
> + csr_write(CSR_VSIE, 0);
> + csr_write(CSR_VSATP, 0);
> + } else if (false == next_virt){
This condition is obviously redundant.
--
Andreas Schwab, SUSE Labs, schwab at suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
@ 2024-04-09 9:23 Pope B.Lei
2024-04-09 10:34 ` Xiang W
2024-04-09 13:34 ` Andrew Jones
0 siblings, 2 replies; 7+ messages in thread
From: Pope B.Lei @ 2024-04-09 9:23 UTC (permalink / raw)
To: opensbi
Although Mstatus.MPV is set, before executing mret, access to VS mode
registers should use the actual register addresses, not the pseudonyms
of S registers.
Signed-off-by: Pope B.Lei <popeblei@gmail.com>
---
V1 -> V2: Simplify the if condition
-
lib/sbi/sbi_hart.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 3d13694..ccdd12f 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
csr_write(CSR_MEPC, next_addr);
if (next_mode == PRV_S) {
- csr_write(CSR_STVEC, next_addr);
- csr_write(CSR_SSCRATCH, 0);
- csr_write(CSR_SIE, 0);
- csr_write(CSR_SATP, 0);
+ if (next_virt) {
+ csr_write(CSR_VSTVEC, next_addr);
+ csr_write(CSR_VSSCRATCH, 0);
+ csr_write(CSR_VSIE, 0);
+ csr_write(CSR_VSATP, 0);
+ } else {
+ csr_write(CSR_STVEC, next_addr);
+ csr_write(CSR_SSCRATCH, 0);
+ csr_write(CSR_SIE, 0);
+ csr_write(CSR_SATP, 0);
+ }
} else if (next_mode == PRV_U) {
if (misa_extension('N')) {
csr_write(CSR_UTVEC, next_addr);
--
2.35.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
2024-04-09 9:23 Pope B.Lei
@ 2024-04-09 10:34 ` Xiang W
2024-04-09 13:34 ` Andrew Jones
1 sibling, 0 replies; 7+ messages in thread
From: Xiang W @ 2024-04-09 10:34 UTC (permalink / raw)
To: opensbi
? 2024-04-09???? 17:23 +0800?Pope B.Lei???
> Although Mstatus.MPV is set, before executing mret, access to VS mode
> registers should use the actual register addresses, not the pseudonyms
> of S registers.
>
> Signed-off-by: Pope B.Lei <popeblei@gmail.com>
> ---
Next time, please remember that v2 is missing from the subject.
otherwise look good to me.
Reviewed-by: Xiang W <wxjstz@126.com>
> V1 -> V2: Simplify the if condition
> -
> ?lib/sbi/sbi_hart.c | 15 +++++++++++----
> ?1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 3d13694..ccdd12f 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
> ? csr_write(CSR_MEPC, next_addr);
> ?
> ? if (next_mode == PRV_S) {
> - csr_write(CSR_STVEC, next_addr);
> - csr_write(CSR_SSCRATCH, 0);
> - csr_write(CSR_SIE, 0);
> - csr_write(CSR_SATP, 0);
> + if (next_virt) {
> + ??? csr_write(CSR_VSTVEC, next_addr);
> + ??? csr_write(CSR_VSSCRATCH, 0);
> + ??? csr_write(CSR_VSIE, 0);
> + ??? csr_write(CSR_VSATP, 0);
> + } else {
> + ??? csr_write(CSR_STVEC, next_addr);
> + ??? csr_write(CSR_SSCRATCH, 0);
> + ??? csr_write(CSR_SIE, 0);
> + ??? csr_write(CSR_SATP, 0);
> + }
> ? } else if (next_mode == PRV_U) {
> ? if (misa_extension('N')) {
> ? csr_write(CSR_UTVEC, next_addr);
> --
> 2.35.2.windows.1
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
2024-04-09 9:23 Pope B.Lei
2024-04-09 10:34 ` Xiang W
@ 2024-04-09 13:34 ` Andrew Jones
1 sibling, 0 replies; 7+ messages in thread
From: Andrew Jones @ 2024-04-09 13:34 UTC (permalink / raw)
To: opensbi
On Tue, Apr 09, 2024 at 05:23:04PM +0800, Pope B.Lei wrote:
> Although Mstatus.MPV is set, before executing mret, access to VS mode
> registers should use the actual register addresses, not the pseudonyms
> of S registers.
>
> Signed-off-by: Pope B.Lei <popeblei@gmail.com>
> ---
> V1 -> V2: Simplify the if condition
> -
> lib/sbi/sbi_hart.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 3d13694..ccdd12f 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
> csr_write(CSR_MEPC, next_addr);
>
> if (next_mode == PRV_S) {
> - csr_write(CSR_STVEC, next_addr);
> - csr_write(CSR_SSCRATCH, 0);
> - csr_write(CSR_SIE, 0);
> - csr_write(CSR_SATP, 0);
> + if (next_virt) {
> + csr_write(CSR_VSTVEC, next_addr);
> + csr_write(CSR_VSSCRATCH, 0);
> + csr_write(CSR_VSIE, 0);
> + csr_write(CSR_VSATP, 0);
> + } else {
> + csr_write(CSR_STVEC, next_addr);
> + csr_write(CSR_SSCRATCH, 0);
> + csr_write(CSR_SIE, 0);
> + csr_write(CSR_SATP, 0);
Indentation should use tabs.
Thanks,
drew
> + }
> } else if (next_mode == PRV_U) {
> if (misa_extension('N')) {
> csr_write(CSR_UTVEC, next_addr);
> --
> 2.35.2.windows.1
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.
@ 2024-04-09 2:18 Pope B.Lei
0 siblings, 0 replies; 7+ messages in thread
From: Pope B.Lei @ 2024-04-09 2:18 UTC (permalink / raw)
To: opensbi
Although Mstatus.MPV is set, before executing mret, access to VS mode
registers should use the actual register addresses, not the pseudonyms
of S registers.
Signed-off-by: Pope B.Lei <popeblei@gmail.com>
---
lib/sbi/sbi_hart.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 3d13694..a6283b5 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
csr_write(CSR_MEPC, next_addr);
if (next_mode == PRV_S) {
- csr_write(CSR_STVEC, next_addr);
- csr_write(CSR_SSCRATCH, 0);
- csr_write(CSR_SIE, 0);
- csr_write(CSR_SATP, 0);
+ if (true == next_virt){
+ csr_write(CSR_VSTVEC, next_addr);
+ csr_write(CSR_VSSCRATCH, 0);
+ csr_write(CSR_VSIE, 0);
+ csr_write(CSR_VSATP, 0);
+ } else if (true == next_virt){
+ csr_write(CSR_STVEC, next_addr);
+ csr_write(CSR_SSCRATCH, 0);
+ csr_write(CSR_SIE, 0);
+ csr_write(CSR_SATP, 0);
+ }
} else if (next_mode == PRV_U) {
if (misa_extension('N')) {
csr_write(CSR_UTVEC, next_addr);
--
2.35.2.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-04-09 13:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 2:24 [PATCH] lib: sbi: Refine the settings for switching to Virtual Supervisor Mode Pope B.Lei
2024-04-09 2:27 ` Pope B.Lei
2024-04-09 7:44 ` Andreas Schwab
-- strict thread matches above, loose matches on Subject: below --
2024-04-09 9:23 Pope B.Lei
2024-04-09 10:34 ` Xiang W
2024-04-09 13:34 ` Andrew Jones
2024-04-09 2:18 Pope B.Lei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox