[PW_SID:1058945] [v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1517
[PW_SID:1058945] [v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1517linux-riscv-bot wants to merge 1 commit into
Conversation
Currently, kvm_arch_vcpu_load() unconditionally restores guest CSRs, HGATP, and AIA state. However, when a VCPU is loaded back on the same physical CPU, and no other KVM VCPU has run on this CPU since it was last put, the hardware CSRs and AIA registers are still valid. This patch optimizes the vcpu_load path by skipping the expensive CSR and AIA writes if all the following conditions are met: 1. It is being reloaded on the same CPU (vcpu->arch.last_exit_cpu == cpu). 2. The CSRs are not dirty (!vcpu->arch.csr_dirty). 3. No other VCPU used this CPU (vcpu == __this_cpu_read(kvm_former_vcpu)). To ensure this fast-path doesn't break corner cases: - Live migration and VCPU reset are naturally safe. KVM initializes last_exit_cpu to -1, which guarantees the fast-path won't trigger. - The 'csr_dirty' flag tracks runtime userspace interventions. If userspace modifies guest configurations (e.g., hedeleg via KVM_SET_GUEST_DEBUG, or CSRs including AIA via KVM_SET_ONE_REG), the flag is set to skip the fast path. With the 'csr_dirty' safeguard proven effective, it is safe to include kvm_riscv_vcpu_aia_load() inside the skip logic now. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
PR for series 1058945 applied to workflow__riscv__fixes
Name: [v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1058945
Version: 7