]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RISC-V: KVM: Fix sbiret init before forwarding to userspace
authorAndrew Jones <ajones@ventanamicro.com>
Wed, 7 Aug 2024 15:49:44 +0000 (17:49 +0200)
committerAnup Patel <anup@brainfault.org>
Mon, 19 Aug 2024 03:02:10 +0000 (08:32 +0530)
When forwarding SBI calls to userspace ensure sbiret.error is
initialized to SBI_ERR_NOT_SUPPORTED first, in case userspace
neglects to set it to anything. If userspace neglects it then we
can't be sure it did anything else either, so we just report it
didn't do or try anything. Just init sbiret.value to zero, which is
the preferred value to return when nothing special is specified.

KVM was already initializing both sbiret.error and sbiret.value, but
the values used appear to come from a copy+paste of the __sbi_ecall()
implementation, i.e. a0 and a1, which don't apply prior to the call
being executed, nor at all when forwarding to userspace.

Fixes: dea8ee31a039 ("RISC-V: KVM: Add SBI v0.1 support")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240807154943.150540-2-ajones@ventanamicro.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu_sbi.c

index 62f409d4176e41fd1e79d530256ebfc38131cc4c..7de128be8db9bcb68d2b990c4ee23ab9126c0218 100644 (file)
@@ -127,8 +127,8 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run)
        run->riscv_sbi.args[3] = cp->a3;
        run->riscv_sbi.args[4] = cp->a4;
        run->riscv_sbi.args[5] = cp->a5;
-       run->riscv_sbi.ret[0] = cp->a0;
-       run->riscv_sbi.ret[1] = cp->a1;
+       run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
+       run->riscv_sbi.ret[1] = 0;
 }
 
 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,