public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace
@ 2024-08-07 15:49 Andrew Jones
  2024-08-09 13:29 ` Anup Patel
  2024-10-01 11:35 ` patchwork-bot+linux-riscv
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Jones @ 2024-08-07 15:49 UTC (permalink / raw)
  To: kvm, kvm-riscv, linux-riscv; +Cc: anup, atishp, cade.richard, jamestiotio

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>
---
 arch/riscv/kvm/vcpu_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
index 62f409d4176e..7de128be8db9 100644
--- a/arch/riscv/kvm/vcpu_sbi.c
+++ b/arch/riscv/kvm/vcpu_sbi.c
@@ -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,
-- 
2.45.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace
  2024-08-07 15:49 [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace Andrew Jones
@ 2024-08-09 13:29 ` Anup Patel
  2024-10-01 11:35 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: Anup Patel @ 2024-08-09 13:29 UTC (permalink / raw)
  To: Andrew Jones
  Cc: kvm, kvm-riscv, linux-riscv, anup, atishp, cade.richard,
	jamestiotio

On Wed, Aug 7, 2024 at 9:19 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> 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>

Queued this patch for Linux-6.11 fixes.

Thanks,
Anup

> ---
>  arch/riscv/kvm/vcpu_sbi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
> index 62f409d4176e..7de128be8db9 100644
> --- a/arch/riscv/kvm/vcpu_sbi.c
> +++ b/arch/riscv/kvm/vcpu_sbi.c
> @@ -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,
> --
> 2.45.2
>
>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace
  2024-08-07 15:49 [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace Andrew Jones
  2024-08-09 13:29 ` Anup Patel
@ 2024-10-01 11:35 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-10-01 11:35 UTC (permalink / raw)
  To: Andrew Jones
  Cc: linux-riscv, kvm, kvm-riscv, anup, atishp, cade.richard,
	jamestiotio

Hello:

This patch was applied to riscv/linux.git (fixes)
by Anup Patel <anup@brainfault.org>:

On Wed,  7 Aug 2024 17:49:44 +0200 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - RISC-V: KVM: Fix sbiret init before forwarding to userspace
    https://git.kernel.org/riscv/c/6b7b282e6bae

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-01 11:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-07 15:49 [PATCH] RISC-V: KVM: Fix sbiret init before forwarding to userspace Andrew Jones
2024-08-09 13:29 ` Anup Patel
2024-10-01 11:35 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox