Skip to content

Commit 86d6a86

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
KVM: riscv: Support guest wrs.nto
When a guest traps on wrs.nto, call kvm_vcpu_on_spin() to attempt to yield to the lock holding VCPU. Also extend the KVM ISA extension ONE_REG interface to allow KVM userspace to detect and enable the Zawrs extension for the Guest/VM. Signed-off-by: Andrew Jones <[email protected]> Acked-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 244c18f commit 86d6a86

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

arch/riscv/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct kvm_vcpu_stat {
6969
struct kvm_vcpu_stat_generic generic;
7070
u64 ecall_exit_stat;
7171
u64 wfi_exit_stat;
72+
u64 wrs_exit_stat;
7273
u64 mmio_exit_user;
7374
u64 mmio_exit_kernel;
7475
u64 csr_exit_user;

arch/riscv/include/uapi/asm/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ enum KVM_RISCV_ISA_EXT_ID {
167167
KVM_RISCV_ISA_EXT_ZFA,
168168
KVM_RISCV_ISA_EXT_ZTSO,
169169
KVM_RISCV_ISA_EXT_ZACAS,
170+
KVM_RISCV_ISA_EXT_ZAWRS,
170171
KVM_RISCV_ISA_EXT_MAX,
171172
};
172173

arch/riscv/kvm/vcpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
2525
KVM_GENERIC_VCPU_STATS(),
2626
STATS_DESC_COUNTER(VCPU, ecall_exit_stat),
2727
STATS_DESC_COUNTER(VCPU, wfi_exit_stat),
28+
STATS_DESC_COUNTER(VCPU, wrs_exit_stat),
2829
STATS_DESC_COUNTER(VCPU, mmio_exit_user),
2930
STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
3031
STATS_DESC_COUNTER(VCPU, csr_exit_user),

arch/riscv/kvm/vcpu_insn.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#define INSN_MASK_WFI 0xffffffff
1717
#define INSN_MATCH_WFI 0x10500073
1818

19+
#define INSN_MASK_WRS 0xffffffff
20+
#define INSN_MATCH_WRS 0x00d00073
21+
1922
#define INSN_MATCH_CSRRW 0x1073
2023
#define INSN_MASK_CSRRW 0x707f
2124
#define INSN_MATCH_CSRRS 0x2073
@@ -203,6 +206,13 @@ static int wfi_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
203206
return KVM_INSN_CONTINUE_NEXT_SEPC;
204207
}
205208

209+
static int wrs_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
210+
{
211+
vcpu->stat.wrs_exit_stat++;
212+
kvm_vcpu_on_spin(vcpu, vcpu->arch.guest_context.sstatus & SR_SPP);
213+
return KVM_INSN_CONTINUE_NEXT_SEPC;
214+
}
215+
206216
struct csr_func {
207217
unsigned int base;
208218
unsigned int count;
@@ -378,6 +388,11 @@ static const struct insn_func system_opcode_funcs[] = {
378388
.match = INSN_MATCH_WFI,
379389
.func = wfi_insn,
380390
},
391+
{
392+
.mask = INSN_MASK_WRS,
393+
.match = INSN_MATCH_WRS,
394+
.func = wrs_insn,
395+
},
381396
};
382397

383398
static int system_opcode_insn(struct kvm_vcpu *vcpu, struct kvm_run *run,

arch/riscv/kvm/vcpu_onereg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static const unsigned long kvm_isa_ext_arr[] = {
4141
KVM_ISA_EXT_ARR(SVNAPOT),
4242
KVM_ISA_EXT_ARR(SVPBMT),
4343
KVM_ISA_EXT_ARR(ZACAS),
44+
KVM_ISA_EXT_ARR(ZAWRS),
4445
KVM_ISA_EXT_ARR(ZBA),
4546
KVM_ISA_EXT_ARR(ZBB),
4647
KVM_ISA_EXT_ARR(ZBC),
@@ -120,6 +121,7 @@ static bool kvm_riscv_vcpu_isa_disable_allowed(unsigned long ext)
120121
case KVM_RISCV_ISA_EXT_SVINVAL:
121122
case KVM_RISCV_ISA_EXT_SVNAPOT:
122123
case KVM_RISCV_ISA_EXT_ZACAS:
124+
case KVM_RISCV_ISA_EXT_ZAWRS:
123125
case KVM_RISCV_ISA_EXT_ZBA:
124126
case KVM_RISCV_ISA_EXT_ZBB:
125127
case KVM_RISCV_ISA_EXT_ZBC:

0 commit comments

Comments
 (0)