Skip to content

[PW_SID:1057504] [v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1495

Open
linux-riscv-bot wants to merge 1 commit intoworkflow__riscv__fixesfrom
pw1057504
Open

[PW_SID:1057504] [v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1495
linux-riscv-bot wants to merge 1 commit intoworkflow__riscv__fixesfrom
pw1057504

Conversation

@linux-riscv-bot
Copy link

PR for series 1057504 applied to workflow__riscv__fixes

Name: [v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1057504
Version: 5

Currently, kvm_arch_vcpu_load() unconditionally restores guest CSRs and
HGATP. 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 are still valid.

This patch optimizes the vcpu_load path by skipping the expensive CSR
writes if all the following conditions are met:
1. It is being reloaded on the same CPU (vcpu->arch.last_exit_cpu == cpu).
2. No other VCPU used this CPU (vcpu == __this_cpu_read(kvm_former_vcpu)).
3. The CSRs are not dirty (!vcpu->arch.csr_dirty).

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.
- A new 'csr_dirty' flag is introduced to track runtime userspace
  interventions. If userspace modifies guest configurations (e.g.,
  hedeleg via KVM_SET_GUEST_DEBUG, or CSRs via KVM_SET_ONE_REG) while
  the VCPU is preempted, the flag is set to skip fast path.

Note that kvm_riscv_vcpu_aia_load() is kept outside the skip logic
to ensure IMSIC/AIA interrupt states are always properly
synchronized.

Signed-off-by: Jinyu Tang <tjytimi@163.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.51 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1047.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1409.46 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 28.03 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 29.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.51 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 85.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
kdoc
Desc: Detects for kdoc errors
Duration: 0.91 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v5] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants