mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: fuqiang wang <fuqiang.wng@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, Marcelo Tosatti <mtosatti@redhat.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Maxim Levitsky <mlevitsk@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: fuqiang wang <fuqiang.wng@gmail.com>,
	yu chen <yuchen33988979@163.com>,
	dongxu zhang <dongxuzhangxu910121@sina.com>
Subject: [PATCH v4 0/1] KVM: x86: fix some kvm period timer BUG
Date: Wed,  5 Nov 2025 21:53:37 +0800	[thread overview]
Message-ID: <20251105135340.33335-1-fuqiang.wng@gmail.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 2718 bytes --]

This patch fixes two issues with the period timer:

=======
issue 1
=======

If the next period has already expired, e.g. due to the period being
smaller than the delay in processing the timer, the hv timer will switch to
the software timer and never switch back.

=======
issue 2
=======

Resuming a virtual machine after it has been suspended for a long time may
trigger a hard lockup. 

Marcelo also talks about this issue in link [2], but I don't think it can
actually reproduce the problem. Because of commit [3], as long as the KVM
timer is running, target_expiration will keep catching up to now (unless
every single delay from timer virtualization is longer than the period,
which is a pretty extreme case). Also, this patch is based on the patch of
link [2], but with some differences: In link [2], target_expiration is
updated to "now - period"(I'm not sure why it doesn't just catch up to now
-- maybe I'm missing something?). In this patch, I set target_expiration to
catch up to now.

=========================================================================
other questions -- Should the two issues be fixed together or separately?
=========================================================================

In the v3 version, I split it into two patches, but since in this patch, if
it is found that the advanced target_expiration is still less than the
current time, target_expiration is updated to now.(If target_expiration is
updated to 'now - period', splitting it into two patches would look better)
This would cause a reversion of the code in patch 1, so in this version of
the patch, the two patches are merged into one.

But keeping them separate helps clearly show the two different problems
we're fixing. So, I still don’t know what the best approach is. Please give
me some advice.

Changes in v4:
- merge two patch into one

Changes in v3:
- Fix: advanced SW timer (hrtimer) expiration does not catch up to current
  time.
- optimize the commit message of patch 2
- link to v2: https://lore.kernel.org/all/20251021154052.17132-1-fuqiang.wng@gmail.com/

Changes in v2:
- Added a bugfix for hardlockup in v2
- link to v1: https://lore.kernel.org/all/20251013125117.87739-1-fuqiang.wng@gmail.com/

[1]: https://github.com/cai-fuqiang/kernel_test/tree/master/period_timer_test
[2]: https://lore.kernel.org/kvm/YgahsSubOgFtyorl@fuller.cnet/
[3]: d8f2f498d9ed ("x86/kvm: fix LAPIC timer drift when guest uses periodic mode")
[4]: https://github.com/cai-fuqiang/md/tree/master/case/intel_kvm_period_timer

fuqiang wang (1):
  fix hardlockup when waking VM after long suspend

 arch/x86/kvm/lapic.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

--
2.47.0

             reply	other threads:[~2025-11-05 13:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05 13:53 fuqiang wang [this message]
2025-11-05 13:53 ` [PATCH v4 1/1] fix hardlockup when waking VM after long suspend fuqiang wang

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=20251105135340.33335-1-fuqiang.wng@gmail.com \
    --to=fuqiang.wng@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dongxuzhangxu910121@sina.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mlevitsk@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yuchen33988979@163.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®