Skip to content

Commit e43ae8b

Browse files
committed
Merge tag 'kvm-riscv-6.6-1' of https://github.com/kvm-riscv/linux into HEAD
KVM/riscv changes for 6.6 - Zba, Zbs, Zicntr, Zicsr, Zifencei, and Zihpm support for Guest/VM - Added ONE_REG interface for SATP mode - Added ONE_REG interface to enable/disable multiple ISA extensions - Improved error codes returned by ONE_REG interfaces - Added KVM_GET_REG_LIST ioctl() implementation for KVM RISC-V - Added get-reg-list selftest for KVM RISC-V
2 parents 69fd387 + 4770693 commit e43ae8b

File tree

21 files changed

+2547
-1085
lines changed

21 files changed

+2547
-1085
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,8 @@ Errors:
22592259
EINVAL invalid register ID, or no such register or used with VMs in
22602260
protected virtualization mode on s390
22612261
EPERM (arm64) register access not allowed before vcpu finalization
2262+
EBUSY (riscv) changing register value not allowed after the vcpu
2263+
has run at least once
22622264
====== ============================================================
22632265

22642266
(These error codes are indicative only: do not rely on a specific error
@@ -3499,7 +3501,7 @@ VCPU matching underlying host.
34993501
---------------------
35003502

35013503
:Capability: basic
3502-
:Architectures: arm64, mips
3504+
:Architectures: arm64, mips, riscv
35033505
:Type: vcpu ioctl
35043506
:Parameters: struct kvm_reg_list (in/out)
35053507
:Returns: 0 on success; -1 on error

arch/riscv/include/asm/csr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#ifndef CONFIG_64BIT
5555
#define SATP_PPN _AC(0x003FFFFF, UL)
5656
#define SATP_MODE_32 _AC(0x80000000, UL)
57+
#define SATP_MODE_SHIFT 31
5758
#define SATP_ASID_BITS 9
5859
#define SATP_ASID_SHIFT 22
5960
#define SATP_ASID_MASK _AC(0x1FF, UL)
@@ -62,6 +63,7 @@
6263
#define SATP_MODE_39 _AC(0x8000000000000000, UL)
6364
#define SATP_MODE_48 _AC(0x9000000000000000, UL)
6465
#define SATP_MODE_57 _AC(0xa000000000000000, UL)
66+
#define SATP_MODE_SHIFT 60
6567
#define SATP_ASID_BITS 16
6668
#define SATP_ASID_SHIFT 44
6769
#define SATP_ASID_MASK _AC(0xFFFF, UL)

arch/riscv/include/asm/kvm_host.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
337337

338338
void __kvm_riscv_switch_to(struct kvm_vcpu_arch *vcpu_arch);
339339

340+
void kvm_riscv_vcpu_setup_isa(struct kvm_vcpu *vcpu);
341+
unsigned long kvm_riscv_vcpu_num_regs(struct kvm_vcpu *vcpu);
342+
int kvm_riscv_vcpu_copy_reg_indices(struct kvm_vcpu *vcpu,
343+
u64 __user *uindices);
344+
int kvm_riscv_vcpu_get_reg(struct kvm_vcpu *vcpu,
345+
const struct kvm_one_reg *reg);
346+
int kvm_riscv_vcpu_set_reg(struct kvm_vcpu *vcpu,
347+
const struct kvm_one_reg *reg);
348+
340349
int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq);
341350
int kvm_riscv_vcpu_unset_interrupt(struct kvm_vcpu *vcpu, unsigned int irq);
342351
void kvm_riscv_vcpu_flush_interrupts(struct kvm_vcpu *vcpu);

arch/riscv/include/asm/kvm_vcpu_vector.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ static inline void kvm_riscv_vcpu_free_vector_context(struct kvm_vcpu *vcpu)
7474
#endif
7575

7676
int kvm_riscv_vcpu_get_reg_vector(struct kvm_vcpu *vcpu,
77-
const struct kvm_one_reg *reg,
78-
unsigned long rtype);
77+
const struct kvm_one_reg *reg);
7978
int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu,
80-
const struct kvm_one_reg *reg,
81-
unsigned long rtype);
79+
const struct kvm_one_reg *reg);
8280
#endif

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct kvm_riscv_config {
5555
unsigned long marchid;
5656
unsigned long mimpid;
5757
unsigned long zicboz_block_size;
58+
unsigned long satp_mode;
5859
};
5960

6061
/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -124,6 +125,12 @@ enum KVM_RISCV_ISA_EXT_ID {
124125
KVM_RISCV_ISA_EXT_SSAIA,
125126
KVM_RISCV_ISA_EXT_V,
126127
KVM_RISCV_ISA_EXT_SVNAPOT,
128+
KVM_RISCV_ISA_EXT_ZBA,
129+
KVM_RISCV_ISA_EXT_ZBS,
130+
KVM_RISCV_ISA_EXT_ZICNTR,
131+
KVM_RISCV_ISA_EXT_ZICSR,
132+
KVM_RISCV_ISA_EXT_ZIFENCEI,
133+
KVM_RISCV_ISA_EXT_ZIHPM,
127134
KVM_RISCV_ISA_EXT_MAX,
128135
};
129136

@@ -193,6 +200,15 @@ enum KVM_RISCV_SBI_EXT_ID {
193200

194201
/* ISA Extension registers are mapped as type 7 */
195202
#define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT)
203+
#define KVM_REG_RISCV_ISA_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
204+
#define KVM_REG_RISCV_ISA_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
205+
#define KVM_REG_RISCV_ISA_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
206+
#define KVM_REG_RISCV_ISA_MULTI_REG(__ext_id) \
207+
((__ext_id) / __BITS_PER_LONG)
208+
#define KVM_REG_RISCV_ISA_MULTI_MASK(__ext_id) \
209+
(1UL << ((__ext_id) % __BITS_PER_LONG))
210+
#define KVM_REG_RISCV_ISA_MULTI_REG_LAST \
211+
KVM_REG_RISCV_ISA_MULTI_REG(KVM_RISCV_ISA_EXT_MAX - 1)
196212

197213
/* SBI extension registers are mapped as type 8 */
198214
#define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT)

arch/riscv/kvm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ kvm-y += vcpu_exit.o
1919
kvm-y += vcpu_fp.o
2020
kvm-y += vcpu_vector.o
2121
kvm-y += vcpu_insn.o
22+
kvm-y += vcpu_onereg.o
2223
kvm-y += vcpu_switch.o
2324
kvm-y += vcpu_sbi.o
2425
kvm-$(CONFIG_RISCV_SBI_V01) += vcpu_sbi_v01.o

arch/riscv/kvm/aia.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ int kvm_riscv_vcpu_aia_get_csr(struct kvm_vcpu *vcpu,
176176
struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
177177

178178
if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(unsigned long))
179-
return -EINVAL;
179+
return -ENOENT;
180180

181181
*out_val = 0;
182182
if (kvm_riscv_aia_available())
@@ -192,7 +192,7 @@ int kvm_riscv_vcpu_aia_set_csr(struct kvm_vcpu *vcpu,
192192
struct kvm_vcpu_aia_csr *csr = &vcpu->arch.aia_context.guest_csr;
193193

194194
if (reg_num >= sizeof(struct kvm_riscv_aia_csr) / sizeof(unsigned long))
195-
return -EINVAL;
195+
return -ENOENT;
196196

197197
if (kvm_riscv_aia_available()) {
198198
((unsigned long *)csr)[reg_num] = val;

0 commit comments

Comments
 (0)