File tree Expand file tree Collapse file tree 4 files changed +20
-0
lines changed
Expand file tree Collapse file tree 4 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
167168struct 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 ;
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 */
629643static 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
637653int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu * vcpu )
You can’t perform that action at this time.
0 commit comments