lib: sbi: sbi_ecall: Improve return SBI error
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error.
Also rename the variable returned via a0 to 'out_err' and use SBI_ERR_NOT_SUPPORTED when the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.
--- lib/sbi/sbi_ecall.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
lib/sbi/sbi_ecall.c +9 -9
@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)int sbi_ecall_handler (struct sbi_trap_regs *regs) { -int ret =0 ; +int out_err =0 ; +unsigned long out_val =0 ;struct sbi_ecall_extension *ext;unsigned long extension_id = regs->a7;unsigned long func_id = regs->a6;struct sbi_trap_info trap = {0 }; -unsigned long out_val =0 ;bool is_0_1_spec =0 ; ext =sbi_ecall_find_extension (extension_id);if (ext && ext->handle) { - ret = ext->handle (extension_id, func_id, + out_err = ext->handle (extension_id, func_id, regs, &out_val, &trap);if (extension_id >=SBI_EXT_0_1_SET_TIMER && extension_id <=SBI_EXT_0_1_SHUTDOWN ) is_0_1_spec =1 ; }else { - ret =SBI_ENOTSUPP ; + out_err =SBI_ERR_NOT_SUPPORTED ; } -if (ret ==SBI_ETRAP ) { +if (out_err ==SBI_ETRAP ) { trap.epc = regs->mepc;sbi_trap_redirect (regs, &trap); }else { -if (ret <SBI_LAST_ERR ) { +if (out_err <SBI_LAST_ERR ||SBI_SUCCESS < out_err) {sbi_printf ("%s: Invalid error %d for ext=0x%lx " -"func=0x%lx\n" , __func__, ret, +"func=0x%lx\n" , __func__, out_err, extension_id, func_id); - ret =SBI_ERR_FAILED ; + out_err =SBI_ERR_FAILED ; }/*
@@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)* case should be handled differently. */ regs->mepc +=4 ; - regs->a0 = ret; + regs->a0 = out_err;if (!is_0_1_spec) regs->a1 = out_val; }
Signature · 1 line
2.34.1
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
? 2023-02-21???? 18:47 +0800?Yu Chien Peter Lin???
Quoted 18 lines
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.Signed-off-by Yu Chien Peter Lin <[email protected]>---
?lib/sbi/sbi_ecall.c | 18 +++++++++---------
?1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +0
-0@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)
Quoted 5 lines
?
?intsbi_ecall_handler(struct sbi_trap_regs *regs)?{
-???????int ret = 0;
+???????intout_err= 0;
There is no need to rename ret to out_err because a0 is not always an error code in legacy extensions
Other than the above, it looks good to me.
Quoted 50 lines
+???????unsigned long
out_val= 0;
????????structsbi_ecall_extension*ext;
????????unsigned longextension_id=regs->a7; ????????unsigned longfunc_id=regs->a6;
????????structsbi_trap_infotrap = {0};
-???????unsigned longout_val= 0;
????????boolis_0_1_spec= 0;
?
????????ext =sbi_ecall_find_extension(extension_id); ????????if (ext &&ext->handle) {
-???????????????ret = ext->handle(extension_id,func_id, +???????????????out_err =ext->handle(extension_id, func_id, ????????????????????????????????? regs, &out_val, &trap); ????????????????if (extension_id>=SBI_EXT_0_1_SET_TIMER&& ???????????????????extension_id<=SBI_EXT_0_1_SHUTDOWN) ????????????????????????is_0_1_spec = 1;
????????} else {
-???????????????ret =SBI_ENOTSUPP;
+???????????????out_err =SBI_ERR_NOT_SUPPORTED;
????????}
?
-???????if (ret ==SBI_ETRAP) {
+???????if (out_err==SBI_ETRAP) {
????????????????trap.epc =regs->mepc; ????????????????sbi_trap_redirect(regs, &trap);
????????} else {
-???????????????if (ret <SBI_LAST_ERR) {
+???????????????if (out_err<SBI_LAST_ERR||SBI_SUCCESS<out_err) { ????????????????????????sbi_printf("%s: Invalid error %d for ext=0x%lx " -????????????????????????????????? "func=0x%lx\n",__func__, ret, +????????????????????????????????? "func=0x%lx\n",__func__,out_err, ??????????????????????????????????extension_id,func_id); -???????????????????????ret =SBI_ERR_FAILED; +???????????????????????out_err =SBI_ERR_FAILED; ????????????????}
?
????????????????/*lib/sbi/sbi_ecall.c +0
-0@@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)???????????????? * case should be handled differently. ???????????????? */ ????????????????regs->mepc += 4; -???????????????regs->a0 = ret; +???????????????regs->a0 =
out_err; ????????????????if (!is_0_1_spec) ????????????????????????regs->a1 =out_val; ????????}Signature · 1 line
2.34.1
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
Quoted 28 lines · Xiang W
? 2023-02-21???? 18:47 +0800?Yu Chien Peter Lin???
Quoted 18 lines
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.Signed-off-by Yu Chien Peter Lin <[email protected]>---
?lib/sbi/sbi_ecall.c | 18 +++++++++---------
?1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +0
-0@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)Quoted 5 lines
?
?intsbi_ecall_handler(struct sbi_trap_regs *regs)?{
-???????int ret = 0;
+???????intout_err= 0;There is no need to rename ret to
out_errbecause a0 is not always an error code in legacy extensions
Other than the above, it looks good to me.
Quoted 1 line
Reviewed-by Xiang W <[email protected]>
Hi Xiang, Andrew,
Thanks for the review,
Sure I'll use 'ret' as it is in next patch.
Best regards,
Peter Lin
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
In reply to Yu Chien Peter LinQuoted 7 lines · Yu Chien Peter Lin
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.
It's best to do renames separate from functional changes, and, in this case, the ret -> out_err rename feels like unnecessary churn.
Thanks,
drew
Quoted 70 lines
Signed-off-by Yu Chien Peter Lin <[email protected]>--- lib/sbi/sbi_ecall.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +9
-9@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)int sbi_ecall_handler (struct sbi_trap_regs *regs) { -int ret =0 ; +int out_err =0 ; +unsigned long out_val =0 ;struct sbi_ecall_extension *ext;unsigned long extension_id = regs->a7;unsigned long func_id = regs->a6;struct sbi_trap_info trap = {0 }; -unsigned long out_val =0 ;bool is_0_1_spec =0 ; ext =sbi_ecall_find_extension (extension_id);if (ext && ext->handle) { - ret = ext->handle (extension_id, func_id, + out_err = ext->handle (extension_id, func_id, regs, &out_val, &trap);if (extension_id >=SBI_EXT_0_1_SET_TIMER && extension_id <=SBI_EXT_0_1_SHUTDOWN ) is_0_1_spec =1 ; }else { - ret =SBI_ENOTSUPP ; + out_err =SBI_ERR_NOT_SUPPORTED ; } -if (ret ==SBI_ETRAP ) { +if (out_err ==SBI_ETRAP ) { trap.epc = regs->mepc;sbi_trap_redirect (regs, &trap); }else { -if (ret <SBI_LAST_ERR ) { +if (out_err <SBI_LAST_ERR ||SBI_SUCCESS < out_err) {sbi_printf ("%s: Invalid error %d for ext=0x%lx " -"func=0x%lx\n" , __func__, ret, +"func=0x%lx\n" , __func__, out_err, extension_id, func_id); - ret =SBI_ERR_FAILED ; + out_err =SBI_ERR_FAILED ; }/* @@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)* case should be handled differently. */ regs->mepc +=4 ; - regs->a0 = ret; + regs->a0 = out_err;if (!is_0_1_spec) regs->a1 = out_val; }Signature · 7 lines
2.34.1 -- opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
Quoted 5 lines · Andrew Jones
Quoted 3 lines · Yu Chien Peter Lin
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.
Quoted 7 lines
Quoted 4 lines
Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.It's best to do renames separate from functional changes, and, in this case, the ret ->
out_errrename feels like unnecessary churn.
Maybe we can do something similar to KVM RISC-V ?
Regards,
Anup
Quoted 79 lines
Thanks,
drewQuoted 66 lines
Signed-off-by Yu Chien Peter Lin <[email protected]>--- lib/sbi/sbi_ecall.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +9
-10@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)int sbi_ecall_handler (struct sbi_trap_regs *regs) { -int ret =0 ; +int out_err =0 ; +unsigned long out_val =0 ;struct sbi_ecall_extension *ext;unsigned long extension_id = regs->a7;unsigned long func_id = regs->a6;struct sbi_trap_info trap = {0 }; -unsigned long out_val =0 ;bool is_0_1_spec =0 ; ext =sbi_ecall_find_extension (extension_id);if (ext && ext->handle) { - ret = ext->handle (extension_id, func_id, + out_err = ext->handle (extension_id, func_id, regs, &out_val, &trap);if (extension_id >=SBI_EXT_0_1_SET_TIMER && extension_id <=SBI_EXT_0_1_SHUTDOWN ) is_0_1_spec =1 ; }else { - ret =SBI_ENOTSUPP ; + out_err =SBI_ERR_NOT_SUPPORTED ; } -if (ret ==SBI_ETRAP ) { +if (out_err ==SBI_ETRAP ) { trap.epc = regs->mepc;sbi_trap_redirect (regs, &trap); }else { -if (ret <SBI_LAST_ERR ) { +if (out_err <SBI_LAST_ERR ||SBI_SUCCESS < out_err) {sbi_printf ("%s: Invalid error %d for ext=0x%lx " -"func=0x%lx\n" , __func__, ret, +"func=0x%lx\n" , __func__, out_err, extension_id, func_id); - ret =SBI_ERR_FAILED ; + out_err =SBI_ERR_FAILED ; }/* @@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)* case should be handled differently. */ regs->mepc +=4 ; - regs->a0 = ret; + regs->a0 = out_err;if (!is_0_1_spec) regs->a1 = out_val; } --2.34.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
Quoted 11 lines · Anup Patel
Quoted 10 lines · Andrew Jones
Quoted 7 lines · Yu Chien Peter Lin
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.
Quoted 4 lines
Quoted 2 lines
It's best to do renames separate from functional changes, and, in this case, the ret ->
out_errrename feels like unnecessary churn.Maybe we can do something similar to KVM RISC-V ?
We could if we have three types of return values to manage like we do with KVM. For anyone who isn't familiar with how KVM will manage things, once the PMU patches are merged, it'll work like this:
1. Linux error while emulating an SBI call (e.g. ENOMEM)
2. 'sbiret.error' generated during emulation
3. 'sbiret.value' generated during emulation
(1) is the return value of an SBI emulation function,
int sbi_func(struct kvm_vcpu_sbi_return *retdata)
(2) is kvm_vcpu_sbi_return.out_val
(3) is kvm_vcpu_sbi_return.err_val
But don't we only have (2) and (3) here?
Thanks,
drew
Quoted 83 lines
Regards,
AnupQuoted 79 lines
Thanks,
drewQuoted 66 lines
Signed-off-by Yu Chien Peter Lin <[email protected]>--- lib/sbi/sbi_ecall.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +9
-10@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)int sbi_ecall_handler (struct sbi_trap_regs *regs) { -int ret =0 ; +int out_err =0 ; +unsigned long out_val =0 ;struct sbi_ecall_extension *ext;unsigned long extension_id = regs->a7;unsigned long func_id = regs->a6;struct sbi_trap_info trap = {0 }; -unsigned long out_val =0 ;bool is_0_1_spec =0 ; ext =sbi_ecall_find_extension (extension_id);if (ext && ext->handle) { - ret = ext->handle (extension_id, func_id, + out_err = ext->handle (extension_id, func_id, regs, &out_val, &trap);if (extension_id >=SBI_EXT_0_1_SET_TIMER && extension_id <=SBI_EXT_0_1_SHUTDOWN ) is_0_1_spec =1 ; }else { - ret =SBI_ENOTSUPP ; + out_err =SBI_ERR_NOT_SUPPORTED ; } -if (ret ==SBI_ETRAP ) { +if (out_err ==SBI_ETRAP ) { trap.epc = regs->mepc;sbi_trap_redirect (regs, &trap); }else { -if (ret <SBI_LAST_ERR ) { +if (out_err <SBI_LAST_ERR ||SBI_SUCCESS < out_err) {sbi_printf ("%s: Invalid error %d for ext=0x%lx " -"func=0x%lx\n" , __func__, ret, +"func=0x%lx\n" , __func__, out_err, extension_id, func_id); - ret =SBI_ERR_FAILED ; + out_err =SBI_ERR_FAILED ; }/* @@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)* case should be handled differently. */ regs->mepc +=4 ; - regs->a0 = ret; + regs->a0 = out_err;if (!is_0_1_spec) regs->a1 = out_val; } --2.34.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/1 lib: sbi: sbi_ecall: Improve return SBI error
Quoted 28 lines · Andrew Jones
Quoted 11 lines · Anup Patel
Quoted 10 lines · Andrew Jones
Quoted 7 lines · Yu Chien Peter Lin
We should also check if the return error code is greater than 0 (
SBI_SUCCESS), as this is an invalid error.Also rename the variable returned via a0 to '
out_err' and useSBI_ERR_NOT_SUPPORTEDwhen the extension does not have a handler for consistency with the standard SBI errors defined in Table 1 of the SBI specification.Quoted 4 lines
Quoted 2 lines
It's best to do renames separate from functional changes, and, in this case, the ret ->
out_errrename feels like unnecessary churn.Maybe we can do something similar to KVM RISC-V ?
We could if we have three types of return values to manage like we do with KVM. For anyone who isn't familiar with how KVM will manage things, once the PMU patches are merged, it'll work like this:
1. Linux error while emulating an SBI call (e.g. ENOMEM)
2. 'sbiret.error' generated during emulation
3. 'sbiret.value' generated during emulation(1) is the return value of an SBI emulation function,
Quoted 7 lines
int
sbi_func(struct kvm_vcpu_sbi_return *retdata)(2) is kvm_vcpu_sbi_return.out_val
(3) is kvm_vcpu_sbi_return.err_valBut don't we only have (2) and (3) here?
We do have (1) as well because SBI_Exxx are supposed to be errors internal to OpenSBI whereas SBI_ERR_xxx are standard SBI errors.
Maybe as a separate series we can improve error returned by SBI calls in OpenSBI?
Regards,
Anup
Quoted 87 lines
Thanks,
drewQuoted 83 lines
Regards,
AnupQuoted 79 lines
Thanks,
drewQuoted 66 lines
Signed-off-by Yu Chien Peter Lin <[email protected]>--- lib/sbi/sbi_ecall.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)lib/sbi/sbi_ecall.c +9
-10@@ -97,34 +97,34 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)int sbi_ecall_handler (struct sbi_trap_regs *regs) { -int ret =0 ; +int out_err =0 ; +unsigned long out_val =0 ;struct sbi_ecall_extension *ext;unsigned long extension_id = regs->a7;unsigned long func_id = regs->a6;struct sbi_trap_info trap = {0 }; -unsigned long out_val =0 ;bool is_0_1_spec =0 ; ext =sbi_ecall_find_extension (extension_id);if (ext && ext->handle) { - ret = ext->handle (extension_id, func_id, + out_err = ext->handle (extension_id, func_id, regs, &out_val, &trap);if (extension_id >=SBI_EXT_0_1_SET_TIMER && extension_id <=SBI_EXT_0_1_SHUTDOWN ) is_0_1_spec =1 ; }else { - ret =SBI_ENOTSUPP ; + out_err =SBI_ERR_NOT_SUPPORTED ; } -if (ret ==SBI_ETRAP ) { +if (out_err ==SBI_ETRAP ) { trap.epc = regs->mepc;sbi_trap_redirect (regs, &trap); }else { -if (ret <SBI_LAST_ERR ) { +if (out_err <SBI_LAST_ERR ||SBI_SUCCESS < out_err) {sbi_printf ("%s: Invalid error %d for ext=0x%lx " -"func=0x%lx\n" , __func__, ret, +"func=0x%lx\n" , __func__, out_err, extension_id, func_id); - ret =SBI_ERR_FAILED ; + out_err =SBI_ERR_FAILED ; }/* @@ -136,7 +136,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)* case should be handled differently. */ regs->mepc +=4 ; - regs->a0 = ret; + regs->a0 = out_err;if (!is_0_1_spec) regs->a1 = out_val; } --2.34.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi