]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code
authorSean Christopherson <seanjc@google.com>
Thu, 13 Nov 2025 20:51:14 +0000 (12:51 -0800)
committerSean Christopherson <seanjc@google.com>
Mon, 17 Nov 2025 15:50:23 +0000 (07:50 -0800)
Stash apic->lapic_timer in a local "ktimer" variable in
advance_periodic_target_expiration() to eliminate a few unaligned wraps,
and to make the code easier to read overall.

No functional change intended.

Link: https://patch.msgid.link/20251113205114.1647493-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/lapic.c

index 8b6ec3304100fffd4c50087efab9c1a87eab8925..1597dd0b0cc664f87dfb81edb763a32e70b8b753 100644 (file)
@@ -2126,6 +2126,7 @@ static bool set_target_expiration(struct kvm_lapic *apic, u32 count_reg)
 
 static void advance_periodic_target_expiration(struct kvm_lapic *apic)
 {
+       struct kvm_timer *ktimer = &apic->lapic_timer;
        ktime_t now = ktime_get();
        u64 tscl = rdtsc();
        ktime_t delta;
@@ -2137,9 +2138,8 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic)
         * over time as differences in the periods accumulate, e.g. due to
         * differences in the underlying clocks or numerical approximation errors.
         */
-       apic->lapic_timer.target_expiration =
-               ktime_add_ns(apic->lapic_timer.target_expiration,
-                               apic->lapic_timer.period);
+       ktimer->target_expiration = ktime_add_ns(ktimer->target_expiration,
+                                                ktimer->period);
 
        /*
         * If the new expiration is in the past, e.g. because userspace stopped
@@ -2150,17 +2150,17 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic)
         * past will do nothing more than waste host cycles, and can even lead
         * to a hard lockup in extreme cases.
         */
-       if (ktime_before(apic->lapic_timer.target_expiration, now))
-               apic->lapic_timer.target_expiration = now;
+       if (ktime_before(ktimer->target_expiration, now))
+               ktimer->target_expiration = now;
 
        /*
         * Note, ensuring the expiration isn't in the past also prevents delta
         * from going negative, which could cause the TSC deadline to become
         * excessively large due to it an unsigned value.
         */
-       delta = ktime_sub(apic->lapic_timer.target_expiration, now);
-       apic->lapic_timer.tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +
-               nsec_to_cycles(apic->vcpu, delta);
+       delta = ktime_sub(ktimer->target_expiration, now);
+       ktimer->tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +
+                             nsec_to_cycles(apic->vcpu, delta);
 }
 
 static void start_sw_period(struct kvm_lapic *apic)