* [PATCH 1/5] riscv: KVM: Fix hart suspend status check
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
@ 2025-02-17 8:45 ` Andrew Jones
2025-02-17 10:36 ` Anup Patel
2025-02-17 8:45 ` [PATCH 2/5] riscv: KVM: Fix hart suspend_type use Andrew Jones
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2025-02-17 8:45 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-riscv, linux-kernel
Cc: anup, atishp, paul.walmsley, palmer, aou, cleger
"Not stopped" means started or suspended so we need to check for
a single state in order to have a chance to check for each state.
Also, we need to use target_vcpu when checking for the suspend
state.
Fixes: 763c8bed8c05 ("RISC-V: KVM: Implement SBI HSM suspend call")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_hsm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
index dce667f4b6ab..13a35eb77e8e 100644
--- a/arch/riscv/kvm/vcpu_sbi_hsm.c
+++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
@@ -79,12 +79,12 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu)
target_vcpu = kvm_get_vcpu_by_id(vcpu->kvm, target_vcpuid);
if (!target_vcpu)
return SBI_ERR_INVALID_PARAM;
- if (!kvm_riscv_vcpu_stopped(target_vcpu))
- return SBI_HSM_STATE_STARTED;
- else if (vcpu->stat.generic.blocking)
+ if (kvm_riscv_vcpu_stopped(target_vcpu))
+ return SBI_HSM_STATE_STOPPED;
+ else if (target_vcpu->stat.generic.blocking)
return SBI_HSM_STATE_SUSPENDED;
else
- return SBI_HSM_STATE_STOPPED;
+ return SBI_HSM_STATE_STARTED;
}
static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 1/5] riscv: KVM: Fix hart suspend status check
2025-02-17 8:45 ` [PATCH 1/5] riscv: KVM: Fix hart suspend status check Andrew Jones
@ 2025-02-17 10:36 ` Anup Patel
0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-17 10:36 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> "Not stopped" means started or suspended so we need to check for
> a single state in order to have a chance to check for each state.
> Also, we need to use target_vcpu when checking for the suspend
> state.
>
> Fixes: 763c8bed8c05 ("RISC-V: KVM: Implement SBI HSM suspend call")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> arch/riscv/kvm/vcpu_sbi_hsm.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
> index dce667f4b6ab..13a35eb77e8e 100644
> --- a/arch/riscv/kvm/vcpu_sbi_hsm.c
> +++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
> @@ -79,12 +79,12 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu)
> target_vcpu = kvm_get_vcpu_by_id(vcpu->kvm, target_vcpuid);
> if (!target_vcpu)
> return SBI_ERR_INVALID_PARAM;
> - if (!kvm_riscv_vcpu_stopped(target_vcpu))
> - return SBI_HSM_STATE_STARTED;
> - else if (vcpu->stat.generic.blocking)
> + if (kvm_riscv_vcpu_stopped(target_vcpu))
> + return SBI_HSM_STATE_STOPPED;
> + else if (target_vcpu->stat.generic.blocking)
> return SBI_HSM_STATE_SUSPENDED;
> else
> - return SBI_HSM_STATE_STOPPED;
> + return SBI_HSM_STATE_STARTED;
> }
>
> static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/5] riscv: KVM: Fix hart suspend_type use
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
2025-02-17 8:45 ` [PATCH 1/5] riscv: KVM: Fix hart suspend status check Andrew Jones
@ 2025-02-17 8:45 ` Andrew Jones
2025-02-17 10:37 ` Anup Patel
2025-02-17 8:45 ` [PATCH 3/5] riscv: KVM: Fix SBI IPI error generation Andrew Jones
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2025-02-17 8:45 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-riscv, linux-kernel
Cc: anup, atishp, paul.walmsley, palmer, aou, cleger
The spec says suspend_type is 32 bits wide and "In case the data is
defined as 32bit wide, higher privilege software must ensure that it
only uses 32 bit data." Mask off upper bits of suspend_type before
using it.
Fixes: 763c8bed8c05 ("RISC-V: KVM: Implement SBI HSM suspend call")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_hsm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
index 13a35eb77e8e..3070bb31745d 100644
--- a/arch/riscv/kvm/vcpu_sbi_hsm.c
+++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
@@ -9,6 +9,7 @@
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/kvm_host.h>
+#include <linux/wordpart.h>
#include <asm/sbi.h>
#include <asm/kvm_vcpu_sbi.h>
@@ -109,7 +110,7 @@ static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
}
return 0;
case SBI_EXT_HSM_HART_SUSPEND:
- switch (cp->a0) {
+ switch (lower_32_bits(cp->a0)) {
case SBI_HSM_SUSPEND_RET_DEFAULT:
kvm_riscv_vcpu_wfi(vcpu);
break;
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 2/5] riscv: KVM: Fix hart suspend_type use
2025-02-17 8:45 ` [PATCH 2/5] riscv: KVM: Fix hart suspend_type use Andrew Jones
@ 2025-02-17 10:37 ` Anup Patel
0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-17 10:37 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> The spec says suspend_type is 32 bits wide and "In case the data is
> defined as 32bit wide, higher privilege software must ensure that it
> only uses 32 bit data." Mask off upper bits of suspend_type before
> using it.
>
> Fixes: 763c8bed8c05 ("RISC-V: KVM: Implement SBI HSM suspend call")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> arch/riscv/kvm/vcpu_sbi_hsm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
> index 13a35eb77e8e..3070bb31745d 100644
> --- a/arch/riscv/kvm/vcpu_sbi_hsm.c
> +++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
> @@ -9,6 +9,7 @@
> #include <linux/errno.h>
> #include <linux/err.h>
> #include <linux/kvm_host.h>
> +#include <linux/wordpart.h>
> #include <asm/sbi.h>
> #include <asm/kvm_vcpu_sbi.h>
>
> @@ -109,7 +110,7 @@ static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> }
> return 0;
> case SBI_EXT_HSM_HART_SUSPEND:
> - switch (cp->a0) {
> + switch (lower_32_bits(cp->a0)) {
> case SBI_HSM_SUSPEND_RET_DEFAULT:
> kvm_riscv_vcpu_wfi(vcpu);
> break;
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/5] riscv: KVM: Fix SBI IPI error generation
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
2025-02-17 8:45 ` [PATCH 1/5] riscv: KVM: Fix hart suspend status check Andrew Jones
2025-02-17 8:45 ` [PATCH 2/5] riscv: KVM: Fix hart suspend_type use Andrew Jones
@ 2025-02-17 8:45 ` Andrew Jones
2025-02-17 10:43 ` Anup Patel
2025-02-17 8:45 ` [PATCH 4/5] riscv: KVM: Fix SBI TIME " Andrew Jones
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2025-02-17 8:45 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-riscv, linux-kernel
Cc: anup, atishp, paul.walmsley, palmer, aou, cleger
When an invalid function ID of an SBI extension is used we should
return not-supported, not invalid-param. Also, when we see that at
least one hartid constructed from the base and mask parameters is
invalid, then we should return invalid-param. Finally, rather than
relying on overflowing a left shift to result in zero and then using
that zero in a condition which [correctly] skips sending an IPI (but
loops unnecessarily), explicitly check for overflow and exit the loop
immediately.
Fixes: 5f862df5585c ("RISC-V: KVM: Add v0.1 replacement SBI extensions defined in v0.2")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_replace.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
index 9c2ab3dfa93a..74e3a38c6a29 100644
--- a/arch/riscv/kvm/vcpu_sbi_replace.c
+++ b/arch/riscv/kvm/vcpu_sbi_replace.c
@@ -51,9 +51,10 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
unsigned long hmask = cp->a0;
unsigned long hbase = cp->a1;
+ unsigned long hart_bit = 0, sentmask = 0;
if (cp->a6 != SBI_EXT_IPI_SEND_IPI) {
- retdata->err_val = SBI_ERR_INVALID_PARAM;
+ retdata->err_val = SBI_ERR_NOT_SUPPORTED;
return 0;
}
@@ -62,15 +63,23 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
if (hbase != -1UL) {
if (tmp->vcpu_id < hbase)
continue;
- if (!(hmask & (1UL << (tmp->vcpu_id - hbase))))
+ hart_bit = tmp->vcpu_id - hbase;
+ if (hart_bit >= __riscv_xlen)
+ goto done;
+ if (!(hmask & (1UL << hart_bit)))
continue;
}
ret = kvm_riscv_vcpu_set_interrupt(tmp, IRQ_VS_SOFT);
if (ret < 0)
break;
+ sentmask |= 1UL << hart_bit;
kvm_riscv_vcpu_pmu_incr_fw(tmp, SBI_PMU_FW_IPI_RCVD);
}
+done:
+ if (hbase != -1UL && (hmask ^ sentmask))
+ retdata->err_val = SBI_ERR_INVALID_PARAM;
+
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 3/5] riscv: KVM: Fix SBI IPI error generation
2025-02-17 8:45 ` [PATCH 3/5] riscv: KVM: Fix SBI IPI error generation Andrew Jones
@ 2025-02-17 10:43 ` Anup Patel
0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-17 10:43 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> When an invalid function ID of an SBI extension is used we should
> return not-supported, not invalid-param. Also, when we see that at
> least one hartid constructed from the base and mask parameters is
> invalid, then we should return invalid-param. Finally, rather than
> relying on overflowing a left shift to result in zero and then using
> that zero in a condition which [correctly] skips sending an IPI (but
> loops unnecessarily), explicitly check for overflow and exit the loop
> immediately.
>
> Fixes: 5f862df5585c ("RISC-V: KVM: Add v0.1 replacement SBI extensions defined in v0.2")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> arch/riscv/kvm/vcpu_sbi_replace.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
> index 9c2ab3dfa93a..74e3a38c6a29 100644
> --- a/arch/riscv/kvm/vcpu_sbi_replace.c
> +++ b/arch/riscv/kvm/vcpu_sbi_replace.c
> @@ -51,9 +51,10 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
> unsigned long hmask = cp->a0;
> unsigned long hbase = cp->a1;
> + unsigned long hart_bit = 0, sentmask = 0;
>
> if (cp->a6 != SBI_EXT_IPI_SEND_IPI) {
> - retdata->err_val = SBI_ERR_INVALID_PARAM;
> + retdata->err_val = SBI_ERR_NOT_SUPPORTED;
> return 0;
> }
>
> @@ -62,15 +63,23 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> if (hbase != -1UL) {
> if (tmp->vcpu_id < hbase)
> continue;
> - if (!(hmask & (1UL << (tmp->vcpu_id - hbase))))
> + hart_bit = tmp->vcpu_id - hbase;
> + if (hart_bit >= __riscv_xlen)
> + goto done;
> + if (!(hmask & (1UL << hart_bit)))
> continue;
> }
> ret = kvm_riscv_vcpu_set_interrupt(tmp, IRQ_VS_SOFT);
> if (ret < 0)
> break;
> + sentmask |= 1UL << hart_bit;
> kvm_riscv_vcpu_pmu_incr_fw(tmp, SBI_PMU_FW_IPI_RCVD);
> }
>
> +done:
> + if (hbase != -1UL && (hmask ^ sentmask))
> + retdata->err_val = SBI_ERR_INVALID_PARAM;
> +
> return ret;
> }
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/5] riscv: KVM: Fix SBI TIME error generation
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
` (2 preceding siblings ...)
2025-02-17 8:45 ` [PATCH 3/5] riscv: KVM: Fix SBI IPI error generation Andrew Jones
@ 2025-02-17 8:45 ` Andrew Jones
2025-02-17 10:44 ` Anup Patel
2025-02-17 8:45 ` [PATCH 5/5] riscv: KVM: Fix SBI sleep_type use Andrew Jones
2025-02-20 12:17 ` [PATCH 0/5] riscv: KVM: Fix a few SBI issues Anup Patel
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2025-02-17 8:45 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-riscv, linux-kernel
Cc: anup, atishp, paul.walmsley, palmer, aou, cleger
When an invalid function ID of an SBI extension is used we should
return not-supported, not invalid-param.
Fixes: 5f862df5585c ("RISC-V: KVM: Add v0.1 replacement SBI extensions defined in v0.2")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_replace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
index 74e3a38c6a29..5fbf3f94f1e8 100644
--- a/arch/riscv/kvm/vcpu_sbi_replace.c
+++ b/arch/riscv/kvm/vcpu_sbi_replace.c
@@ -21,7 +21,7 @@ static int kvm_sbi_ext_time_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
u64 next_cycle;
if (cp->a6 != SBI_EXT_TIME_SET_TIMER) {
- retdata->err_val = SBI_ERR_INVALID_PARAM;
+ retdata->err_val = SBI_ERR_NOT_SUPPORTED;
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 4/5] riscv: KVM: Fix SBI TIME error generation
2025-02-17 8:45 ` [PATCH 4/5] riscv: KVM: Fix SBI TIME " Andrew Jones
@ 2025-02-17 10:44 ` Anup Patel
0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-17 10:44 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> When an invalid function ID of an SBI extension is used we should
> return not-supported, not invalid-param.
>
> Fixes: 5f862df5585c ("RISC-V: KVM: Add v0.1 replacement SBI extensions defined in v0.2")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> arch/riscv/kvm/vcpu_sbi_replace.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
> index 74e3a38c6a29..5fbf3f94f1e8 100644
> --- a/arch/riscv/kvm/vcpu_sbi_replace.c
> +++ b/arch/riscv/kvm/vcpu_sbi_replace.c
> @@ -21,7 +21,7 @@ static int kvm_sbi_ext_time_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> u64 next_cycle;
>
> if (cp->a6 != SBI_EXT_TIME_SET_TIMER) {
> - retdata->err_val = SBI_ERR_INVALID_PARAM;
> + retdata->err_val = SBI_ERR_NOT_SUPPORTED;
> return 0;
> }
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/5] riscv: KVM: Fix SBI sleep_type use
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
` (3 preceding siblings ...)
2025-02-17 8:45 ` [PATCH 4/5] riscv: KVM: Fix SBI TIME " Andrew Jones
@ 2025-02-17 8:45 ` Andrew Jones
2025-02-17 10:57 ` Anup Patel
2025-02-20 12:17 ` [PATCH 0/5] riscv: KVM: Fix a few SBI issues Anup Patel
5 siblings, 1 reply; 12+ messages in thread
From: Andrew Jones @ 2025-02-17 8:45 UTC (permalink / raw)
To: kvm, kvm-riscv, linux-riscv, linux-kernel
Cc: anup, atishp, paul.walmsley, palmer, aou, cleger
The spec says sleep_type is 32 bits wide and "In case the data is
defined as 32bit wide, higher privilege software must ensure that it
only uses 32 bit data." Mask off upper bits of sleep_type before
using it.
Fixes: 023c15151fbb ("RISC-V: KVM: Add SBI system suspend support")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_system.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_system.c b/arch/riscv/kvm/vcpu_sbi_system.c
index 5d55e08791fa..bc0ebba89003 100644
--- a/arch/riscv/kvm/vcpu_sbi_system.c
+++ b/arch/riscv/kvm/vcpu_sbi_system.c
@@ -4,6 +4,7 @@
*/
#include <linux/kvm_host.h>
+#include <linux/wordpart.h>
#include <asm/kvm_vcpu_sbi.h>
#include <asm/sbi.h>
@@ -19,7 +20,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
switch (funcid) {
case SBI_EXT_SUSP_SYSTEM_SUSPEND:
- if (cp->a0 != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
+ if (lower_32_bits(cp->a0) != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
retdata->err_val = SBI_ERR_INVALID_PARAM;
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 5/5] riscv: KVM: Fix SBI sleep_type use
2025-02-17 8:45 ` [PATCH 5/5] riscv: KVM: Fix SBI sleep_type use Andrew Jones
@ 2025-02-17 10:57 ` Anup Patel
0 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-17 10:57 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> The spec says sleep_type is 32 bits wide and "In case the data is
> defined as 32bit wide, higher privilege software must ensure that it
> only uses 32 bit data." Mask off upper bits of sleep_type before
> using it.
>
> Fixes: 023c15151fbb ("RISC-V: KVM: Add SBI system suspend support")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> arch/riscv/kvm/vcpu_sbi_system.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_system.c b/arch/riscv/kvm/vcpu_sbi_system.c
> index 5d55e08791fa..bc0ebba89003 100644
> --- a/arch/riscv/kvm/vcpu_sbi_system.c
> +++ b/arch/riscv/kvm/vcpu_sbi_system.c
> @@ -4,6 +4,7 @@
> */
>
> #include <linux/kvm_host.h>
> +#include <linux/wordpart.h>
>
> #include <asm/kvm_vcpu_sbi.h>
> #include <asm/sbi.h>
> @@ -19,7 +20,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
>
> switch (funcid) {
> case SBI_EXT_SUSP_SYSTEM_SUSPEND:
> - if (cp->a0 != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
> + if (lower_32_bits(cp->a0) != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
> retdata->err_val = SBI_ERR_INVALID_PARAM;
> return 0;
> }
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] riscv: KVM: Fix a few SBI issues
2025-02-17 8:45 [PATCH 0/5] riscv: KVM: Fix a few SBI issues Andrew Jones
` (4 preceding siblings ...)
2025-02-17 8:45 ` [PATCH 5/5] riscv: KVM: Fix SBI sleep_type use Andrew Jones
@ 2025-02-20 12:17 ` Anup Patel
5 siblings, 0 replies; 12+ messages in thread
From: Anup Patel @ 2025-02-20 12:17 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, atishp, paul.walmsley,
palmer, aou, cleger
On Mon, Feb 17, 2025 at 2:15 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> Fix issues found with kvm-unit-tests[1], which is currently focused
> on SBI.
>
> [1] https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
>
> Andrew Jones (5):
> riscv: KVM: Fix hart suspend status check
> riscv: KVM: Fix hart suspend_type use
> riscv: KVM: Fix SBI IPI error generation
> riscv: KVM: Fix SBI TIME error generation
> riscv: KVM: Fix SBI sleep_type use
Queued these fixes for Linux-6.14-rcX.
Regards,
Anup
>
> arch/riscv/kvm/vcpu_sbi_hsm.c | 11 ++++++-----
> arch/riscv/kvm/vcpu_sbi_replace.c | 15 ++++++++++++---
> arch/riscv/kvm/vcpu_sbi_system.c | 3 ++-
> 3 files changed, 20 insertions(+), 9 deletions(-)
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread