From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
fuqiang wang <fuqiang.wng@gmail.com>
Subject: [PATCH v6 2/4] KVM: x86: Explicitly set new periodic hrtimer expiration in apic_timer_fn()
Date: Thu, 13 Nov 2025 12:51:12 -0800 [thread overview]
Message-ID: <20251113205114.1647493-3-seanjc@google.com> (raw)
In-Reply-To: <20251113205114.1647493-1-seanjc@google.com>
From: fuqiang wang <fuqiang.wng@gmail.com>
When restarting an hrtimer to emulate a the guest's APIC timer in periodic
mode, explicitly set the expiration using the target expiration computed
by advance_periodic_target_expiration() instead of adding the period to
the existing timer. This will allow making adjustments to the expiration,
e.g. to deal with expirations far in the past, without having to implement
the same logic in both advance_periodic_target_expiration() and
apic_timer_fn().
Cc: stable@vger.kernel.org
Signed-off-by: fuqiang wang <fuqiang.wng@gmail.com>
[sean: split to separate patch, write changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/lapic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 78b74ba17592..a5c927e7bae6 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2972,7 +2972,7 @@ static enum hrtimer_restart apic_timer_fn(struct hrtimer *data)
if (lapic_is_periodic(apic) && !WARN_ON_ONCE(!apic->lapic_timer.period)) {
advance_periodic_target_expiration(apic);
- hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
+ hrtimer_set_expires(&ktimer->timer, ktimer->target_expiration);
return HRTIMER_RESTART;
} else
return HRTIMER_NORESTART;
--
2.52.0.rc1.455.g30608eb744-goog
next prev parent reply other threads:[~2025-11-13 20:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 20:51 [PATCH v6 0/4] KVM: x86: Fix hard lockup with periodic timer in guest Sean Christopherson
2025-11-13 20:51 ` [PATCH v6 1/4] KVM: x86: WARN if hrtimer callback for periodic APIC timer fires with period=0 Sean Christopherson
2025-11-13 20:51 ` Sean Christopherson [this message]
2025-11-13 20:51 ` [PATCH v6 3/4] KVM: x86: Fix VM hard lockup after prolonged inactivity with periodic HV timer Sean Christopherson
2025-11-13 20:51 ` [PATCH v6 4/4] KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code Sean Christopherson
2025-11-18 23:27 ` [PATCH v6 0/4] KVM: x86: Fix hard lockup with periodic timer in guest Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251113205114.1647493-3-seanjc@google.com \
--to=seanjc@google.com \
--cc=fuqiang.wng@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®