Skip to content

[PW_SID:1058945] [v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1517

Closed
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1058945
Closed

[PW_SID:1058945] [v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1517
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1058945

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

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

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>
@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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: 1050.45 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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: 1411.58 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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: 26.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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: 27.71 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

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

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v7] 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.29 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot deleted the pw1058945 branch March 7, 2026 01:19
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