Skip to content

Commit db3c01c

Browse files
mdchitaleavpatel
authored andcommitted
RISCV: KVM: Add senvcfg context save/restore
Add senvcfg context save/restore for guest VCPUs and also add it to the ONE_REG interface to allow its access from user space. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent d21b5d3 commit db3c01c

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

arch/riscv/include/asm/csr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
#define CSR_SIE 0x104
288288
#define CSR_STVEC 0x105
289289
#define CSR_SCOUNTEREN 0x106
290+
#define CSR_SENVCFG 0x10a
290291
#define CSR_SSCRATCH 0x140
291292
#define CSR_SEPC 0x141
292293
#define CSR_SCAUSE 0x142

arch/riscv/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct kvm_vcpu_csr {
162162
unsigned long hvip;
163163
unsigned long vsatp;
164164
unsigned long scounteren;
165+
unsigned long senvcfg;
165166
};
166167

167168
struct kvm_vcpu_config {
@@ -188,6 +189,7 @@ struct kvm_vcpu_arch {
188189
unsigned long host_sscratch;
189190
unsigned long host_stvec;
190191
unsigned long host_scounteren;
192+
unsigned long host_senvcfg;
191193

192194
/* CPU context of Host */
193195
struct kvm_cpu_context host_context;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct kvm_riscv_csr {
8080
unsigned long sip;
8181
unsigned long satp;
8282
unsigned long scounteren;
83+
unsigned long senvcfg;
8384
};
8485

8586
/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */

arch/riscv/kvm/vcpu.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,20 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
619619
kvm_riscv_vcpu_aia_update_hvip(vcpu);
620620
}
621621

622+
static __always_inline void kvm_riscv_vcpu_swap_in_guest_state(struct kvm_vcpu *vcpu)
623+
{
624+
struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr;
625+
626+
vcpu->arch.host_senvcfg = csr_swap(CSR_SENVCFG, csr->senvcfg);
627+
}
628+
629+
static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *vcpu)
630+
{
631+
struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr;
632+
633+
csr->senvcfg = csr_swap(CSR_SENVCFG, vcpu->arch.host_senvcfg);
634+
}
635+
622636
/*
623637
* Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
624638
* the vCPU is running.
@@ -628,10 +642,12 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
628642
*/
629643
static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu)
630644
{
645+
kvm_riscv_vcpu_swap_in_guest_state(vcpu);
631646
guest_state_enter_irqoff();
632647
__kvm_riscv_switch_to(&vcpu->arch);
633648
vcpu->arch.last_exit_cpu = vcpu->cpu;
634649
guest_state_exit_irqoff();
650+
kvm_riscv_vcpu_swap_in_host_state(vcpu);
635651
}
636652

637653
int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)