]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: KVM: Fix SBI sleep_type use
authorAndrew Jones <ajones@ventanamicro.com>
Mon, 17 Feb 2025 08:45:12 +0000 (09:45 +0100)
committerAnup Patel <anup@brainfault.org>
Mon, 17 Feb 2025 10:58:28 +0000 (16:28 +0530)
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>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20250217084506.18763-12-ajones@ventanamicro.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu_sbi_system.c

index 5d55e08791fa13bfe74161c94eca30f2c2244e85..bc0ebba890037e40597fcded86cf4c4d24993d4c 100644 (file)
@@ -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;
                }