mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <zhoushuling@huawei.com>
To: <seanjc@google.com>, <pbonzini@redhat.com>
Cc: <weiqi4@huawei.com>, <zhoushuling@huawei.com>,
	<wanpengli@tencent.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] KVM: LAPIC: Fix an inversion error when a negative value assigned to lapic_timer.timer_advance_ns
Date: Mon, 20 May 2024 19:53:34 +0800	[thread overview]
Message-ID: <20240520115334.852510-1-zhoushuling@huawei.com> (raw)

From: Shuling Zhou <zhoushuling@huawei.com>

After 'commit 0e6edceb8f18 ("KVM: LAPIC: Fix lapic_timer_advance_ns
parameter overflow")',a negative value can be assigned to
lapic_timer_advance_ns, when it is '-1', the kvm_create_lapic()
will judge it and turns on adaptive tuning of timer advancement.
However, when lapic_timer_advance_ns=-2, it will be assigned to
an uint variable apic->lapic_timer.timer_advance_ns, the
apic->lapic_timer.timer_advance_ns of each vCPU will become a huge
value. When a VM is started, the VM is stuck in the
"
[    2.669717] ACPI: Core revision 20130517
[    2.672378] ACPI: All ACPI Tables successfully acquired
[    2.673309] ftrace: allocating 29651 entries in 116 pages
[    2.698797] Enabling x2apic
[    2.699431] Enabled x2apic
[    2.700160] Switched APIC routing to physical x2apic.
[    2.701644] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[    2.702575] smpboot: CPU0: Intel(R) Xeon(R) Platinum 8378A CPU @ 3.00GHz (fam: 06, model: 6a, stepping: 06)
..........
"

'Fixes: 0e6edceb8f18 ("KVM: LAPIC: Fix lapic_timer_advance_ns
parameter overflow")'

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Shuling Zhou<zhoushuling@huawei.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 ebf41023be38..5feeb889ddb6 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2848,7 +2848,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu, int timer_advance_ns)
 	if (timer_advance_ns == -1) {
 		apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
 		lapic_timer_advance_dynamic = true;
-	} else {
+	} else if (timer_advance_ns >= 0) {
 		apic->lapic_timer.timer_advance_ns = timer_advance_ns;
 		lapic_timer_advance_dynamic = false;
 	}
-- 
2.27.0


             reply	other threads:[~2024-05-20 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 11:53 zhoushuling [this message]
2024-05-20 14:28 ` Sean Christopherson
2024-05-21 12:33   ` zhoushuling
2024-05-21 15:02     ` 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=20240520115334.852510-1-zhoushuling@huawei.com \
    --to=zhoushuling@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=wanpengli@tencent.com \
    --cc=weiqi4@huawei.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®