Re: [PATCH 2/2] RISC-V: KVM: Skip steal-time updates when run_delay is unchanged

From: Andrew Jones

Date: Fri Nov 20 2026 - 11:46:02 EST


On Wed, Nov 18, 2026 at 03:22:42PM +0900, Koichiro Den wrote:
> Check run_delay against last_steal and skip the update if they match.
> This avoids accessing the SBI STA shared structure and marking its page
> dirty on vCPU loads with no new steal time to report.
>
> Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
> ---
> arch/riscv/kvm/vcpu_sbi_sta.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
> index cfc6f22c3e33..8b2499876fb4 100644
> --- a/arch/riscv/kvm/vcpu_sbi_sta.c
> +++ b/arch/riscv/kvm/vcpu_sbi_sta.c
> @@ -31,7 +31,7 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
> __le32 sequence_le;
> __le64 steal_le;
> u32 sequence;
> - u64 steal;
> + u64 steal, run_delay;
> unsigned long hva;
> bool dirty = false, success = false;
> gfn_t gfn;
> @@ -52,6 +52,10 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
> return;
> }
>
> + run_delay = READ_ONCE(current->sched_info.run_delay);
> + if (run_delay == last_steal)
> + return;
> +

If we move the new check to just below the 'if (shmem == INVALID_GPA)'
check then we also avoid a memslot lookup.

> st = (struct sbi_sta_struct __user *)(hva + offset_in_page(shmem));
> might_fault();
> if (WARN_ON(!user_access_begin(st, sizeof(*st))))
> @@ -66,7 +70,7 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
> smp_wmb();
> unsafe_get_user(steal_le, &st->steal, update_sequence);
> steal = le64_to_cpu(steal_le);
> - vcpu->arch.sta.last_steal = READ_ONCE(current->sched_info.run_delay);
> + vcpu->arch.sta.last_steal = run_delay;
> steal += vcpu->arch.sta.last_steal - last_steal;
> unsafe_put_user(cpu_to_le64(steal), &st->steal, update_sequence);
> success = true;
> --
> 2.54.0
>

Otherwise,

Reviewed-by: Andrew Jones <andrew.jones@xxxxxxxxx>