Skip to content

Commit e93d78e

Browse files
committed
Merge tag 'kvm-riscv-fixes-6.14-1' of https://github.com/kvm-riscv/linux into HEAD
KVM/riscv fixes for 6.14, take #1 - Fix hart status check in SBI HSM extension - Fix hart suspend_type usage in SBI HSM extension - Fix error returned by SBI IPI and TIME extensions for unsupported function IDs - Fix suspend_type usage in SBI SUSP extension - Remove unnecessary vcpu kick after injecting interrupt via IMSIC guest file
2 parents 4647c82 + d252435 commit e93d78e

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

arch/riscv/kvm/aia_imsic.c

-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,6 @@ int kvm_riscv_vcpu_aia_imsic_inject(struct kvm_vcpu *vcpu,
974974

975975
if (imsic->vsfile_cpu >= 0) {
976976
writel(iid, imsic->vsfile_va + IMSIC_MMIO_SETIPNUM_LE);
977-
kvm_vcpu_kick(vcpu);
978977
} else {
979978
eix = &imsic->swfile->eix[iid / BITS_PER_TYPE(u64)];
980979
set_bit(iid & (BITS_PER_TYPE(u64) - 1), eix->eip);

arch/riscv/kvm/vcpu_sbi_hsm.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/errno.h>
1010
#include <linux/err.h>
1111
#include <linux/kvm_host.h>
12+
#include <linux/wordpart.h>
1213
#include <asm/sbi.h>
1314
#include <asm/kvm_vcpu_sbi.h>
1415

@@ -79,12 +80,12 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu)
7980
target_vcpu = kvm_get_vcpu_by_id(vcpu->kvm, target_vcpuid);
8081
if (!target_vcpu)
8182
return SBI_ERR_INVALID_PARAM;
82-
if (!kvm_riscv_vcpu_stopped(target_vcpu))
83-
return SBI_HSM_STATE_STARTED;
84-
else if (vcpu->stat.generic.blocking)
83+
if (kvm_riscv_vcpu_stopped(target_vcpu))
84+
return SBI_HSM_STATE_STOPPED;
85+
else if (target_vcpu->stat.generic.blocking)
8586
return SBI_HSM_STATE_SUSPENDED;
8687
else
87-
return SBI_HSM_STATE_STOPPED;
88+
return SBI_HSM_STATE_STARTED;
8889
}
8990

9091
static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
@@ -109,7 +110,7 @@ static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
109110
}
110111
return 0;
111112
case SBI_EXT_HSM_HART_SUSPEND:
112-
switch (cp->a0) {
113+
switch (lower_32_bits(cp->a0)) {
113114
case SBI_HSM_SUSPEND_RET_DEFAULT:
114115
kvm_riscv_vcpu_wfi(vcpu);
115116
break;

arch/riscv/kvm/vcpu_sbi_replace.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int kvm_sbi_ext_time_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
2121
u64 next_cycle;
2222

2323
if (cp->a6 != SBI_EXT_TIME_SET_TIMER) {
24-
retdata->err_val = SBI_ERR_INVALID_PARAM;
24+
retdata->err_val = SBI_ERR_NOT_SUPPORTED;
2525
return 0;
2626
}
2727

@@ -51,9 +51,10 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
5151
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
5252
unsigned long hmask = cp->a0;
5353
unsigned long hbase = cp->a1;
54+
unsigned long hart_bit = 0, sentmask = 0;
5455

5556
if (cp->a6 != SBI_EXT_IPI_SEND_IPI) {
56-
retdata->err_val = SBI_ERR_INVALID_PARAM;
57+
retdata->err_val = SBI_ERR_NOT_SUPPORTED;
5758
return 0;
5859
}
5960

@@ -62,15 +63,23 @@ static int kvm_sbi_ext_ipi_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
6263
if (hbase != -1UL) {
6364
if (tmp->vcpu_id < hbase)
6465
continue;
65-
if (!(hmask & (1UL << (tmp->vcpu_id - hbase))))
66+
hart_bit = tmp->vcpu_id - hbase;
67+
if (hart_bit >= __riscv_xlen)
68+
goto done;
69+
if (!(hmask & (1UL << hart_bit)))
6670
continue;
6771
}
6872
ret = kvm_riscv_vcpu_set_interrupt(tmp, IRQ_VS_SOFT);
6973
if (ret < 0)
7074
break;
75+
sentmask |= 1UL << hart_bit;
7176
kvm_riscv_vcpu_pmu_incr_fw(tmp, SBI_PMU_FW_IPI_RCVD);
7277
}
7378

79+
done:
80+
if (hbase != -1UL && (hmask ^ sentmask))
81+
retdata->err_val = SBI_ERR_INVALID_PARAM;
82+
7483
return ret;
7584
}
7685

arch/riscv/kvm/vcpu_sbi_system.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/kvm_host.h>
7+
#include <linux/wordpart.h>
78

89
#include <asm/kvm_vcpu_sbi.h>
910
#include <asm/sbi.h>
@@ -19,7 +20,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
1920

2021
switch (funcid) {
2122
case SBI_EXT_SUSP_SYSTEM_SUSPEND:
22-
if (cp->a0 != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
23+
if (lower_32_bits(cp->a0) != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
2324
retdata->err_val = SBI_ERR_INVALID_PARAM;
2425
return 0;
2526
}

0 commit comments

Comments
 (0)