On 8/7/2025 7:42 PM, Jinyu Tang wrote:
The kvm_arch_vcpu_load() function is called in two cases for riscv: 1. When entering KVM_RUN from userspace ioctl. 2. When a preempted VCPU is scheduled back. In the second case, if no other KVM VCPU has run on this CPU since the current VCPU was preempted, the guest CSR values are still valid in the hardware and do not need to be restored. This patch is to skip the CSR write path when: 1. The VCPU was previously preempted (vcpu->scheduled_out == 1). 2. It is being reloaded on the same physical CPU (vcpu->arch.last_exit_cpu == cpu). 3. No other KVM VCPU has used this CPU in the meantime (vcpu == __this_cpu_read(kvm_former_vcpu)). This reduces many CSR writes with frequent preemption on the same CPU. Signed-off-by: Jinyu Tang <tjytimi@xxxxxxx> --- arch/riscv/kvm/vcpu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Reviewed-by: Nutty Liu <nutty.liu@xxxxxxxxxxx> Thanks, Nutty
