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

From: Koichiro Den

Date: Sat Nov 21 2026 - 12:35:47 EST


Check run_delay against last_steal and skip the update if they match.
This avoids looking up the memslot, accessing the SBI STA shared
structure, and marking its page dirty on vCPU loads with no new steal
time to report.

Reviewed-by: Andrew Jones <andrew.jones@xxxxxxxxx>
Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
---
Changes since v1:
- Check run_delay before looking up the memslot. (Andrew)

v1: https://lore.kernel.org/r/20261118062242.2914385-3-den@xxxxxxxxxxxxx/

arch/riscv/kvm/vcpu_sbi_sta.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
index 68d54696dbae..ebdd1435abd4 100644
--- a/arch/riscv/kvm/vcpu_sbi_sta.c
+++ b/arch/riscv/kvm/vcpu_sbi_sta.c
@@ -30,11 +30,16 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
struct sbi_sta_struct __user *st;
unsigned long hva;
bool updated = false;
+ u64 run_delay;
gfn_t gfn;

if (shmem == INVALID_GPA)
return;

+ run_delay = READ_ONCE(current->sched_info.run_delay);
+ if (run_delay == last_steal)
+ return;
+
/*
* shmem is 64-byte aligned (see the enforcement in
* kvm_sbi_sta_steal_time_set_shmem()) and the size of sbi_sta_struct
@@ -61,7 +66,7 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
/* Publish the odd sequence before updating stolen time. */
smp_wmb();
unsafe_get_user(steal, &st->steal, finish_update);
- vcpu->arch.sta.last_steal = READ_ONCE(current->sched_info.run_delay);
+ vcpu->arch.sta.last_steal = run_delay;
le64_add_cpu(&steal, vcpu->arch.sta.last_steal - last_steal);
unsafe_put_user(steal, &st->steal, finish_update);
wrote_steal = true;
--
2.54.0