diff mbox series

[v5] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific sbi.

Message ID 20240422112437.11079-1-alexei.filippov@syntacore.com (mailing list archive)
State New, archived
Headers show
Series [v5] target/riscv/kvm/kvm-cpu.c: kvm_riscv_handle_sbi() fail with vendor-specific sbi. | expand

Commit Message

Aleksei Filippov April 22, 2024, 11:24 a.m. UTC
kvm_riscv_handle_sbi() may return not supported return code to not
trigger qemu abort with vendor-specific sbi.

Add new error path to provide proper error in case of
qemu_chr_fe_read_all() may not return sizeof(ch).

Added SBI related return code's defines.

Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
---
 target/riscv/kvm/kvm-cpu.c         | 9 +++++----
 target/riscv/sbi_ecall_interface.h | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Aleksei Filippov April 22, 2024, 11:40 a.m. UTC | #1
On 22.04.2024 14:24, Alexei Filippov wrote:
> kvm_riscv_handle_sbi() may return not supported return code to not
> trigger qemu abort with vendor-specific sbi.
> 
> Add new error path to provide proper error in case of
> qemu_chr_fe_read_all() may not return sizeof(ch).
> 
> Added SBI related return code's defines.
> 
> Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com>
> ---
>   target/riscv/kvm/kvm-cpu.c         | 9 +++++----
>   target/riscv/sbi_ecall_interface.h | 1 +
>   2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index aeca1e3e83..5bb7b74d03 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1173,17 +1173,18 @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
>           ret = qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch));
>           if (ret == sizeof(ch)) {
>               run->riscv_sbi.ret[0] = ch;
> -        } else {
> +            ret = 0;
> +        } else if (ret == 0) {
>               run->riscv_sbi.ret[0] = SBI_ERR_FAILURE;
> +        } else {
> +            ret = -1;
>           }
> -        ret = 0;
>           break;
>       default:
>           qemu_log_mask(LOG_UNIMP,
> -                      "%s: un-handled SBI EXIT, specific reasons is %lu\n",
> +                      "%s: Unhandled SBI exit with extension-id %lu\n"
>                         __func__, run->riscv_sbi.extension_id);
>           run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
> -        ret = 0;
>           break;
>       }
>       return ret;
> diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
> index 0279e92a36..a2e21d9b8c 100644
> --- a/target/riscv/sbi_ecall_interface.h
> +++ b/target/riscv/sbi_ecall_interface.h
> @@ -79,5 +79,6 @@
>   #define SBI_ERR_ALREADY_AVAILABLE   -6
>   #define SBI_ERR_ALREADY_STARTED     -7
>   #define SBI_ERR_ALREADY_STOPPED     -8
> +#define SBI_ERR_NO_SHMEM            -9
>   
>   #endif

Oh, my bad, wrong patch. Will resend properly.
diff mbox series

Patch

diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index aeca1e3e83..5bb7b74d03 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1173,17 +1173,18 @@  static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
         ret = qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch));
         if (ret == sizeof(ch)) {
             run->riscv_sbi.ret[0] = ch;
-        } else {
+            ret = 0;
+        } else if (ret == 0) {
             run->riscv_sbi.ret[0] = SBI_ERR_FAILURE;
+        } else {
+            ret = -1;
         }
-        ret = 0;
         break;
     default:
         qemu_log_mask(LOG_UNIMP,
-                      "%s: un-handled SBI EXIT, specific reasons is %lu\n",
+                      "%s: Unhandled SBI exit with extension-id %lu\n"
                       __func__, run->riscv_sbi.extension_id);
         run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
-        ret = 0;
         break;
     }
     return ret;
diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h
index 0279e92a36..a2e21d9b8c 100644
--- a/target/riscv/sbi_ecall_interface.h
+++ b/target/riscv/sbi_ecall_interface.h
@@ -79,5 +79,6 @@ 
 #define SBI_ERR_ALREADY_AVAILABLE   -6
 #define SBI_ERR_ALREADY_STARTED     -7
 #define SBI_ERR_ALREADY_STOPPED     -8
+#define SBI_ERR_NO_SHMEM            -9
 
 #endif