mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shannon Zhao <shannon.zhao@linux.alibaba.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com, seanjc@google.com
Cc: linux-kernel@vger.kernel.org, yijunzhu@linux.alibaba.com
Subject: [PATCH] KVM: SVM: Set HWCR[TscFreqSel] to host's value
Date: Tue, 10 May 2022 15:53:47 +0800	[thread overview]
Message-ID: <1652169227-38383-1-git-send-email-shannon.zhao@linux.alibaba.com> (raw)

KVM sets CPUID.80000007H:EDX[8] to 1, but not set HWCR[TscFreqSel].
This will cause guest kernel printing below log on AMD platform even
though the hardware TSC exactly counts with P0 frequency.
"[Firmware Bug]: TSC doesn't count with P0 frequency!"

Fix it by setting HWCR[TscFreqSel] to host's value to indicate whether
the TSC increments at the P0 frequency.

Signed-off-by: Shannon Zhao <shannon.zhao@linux.alibaba.com>
---
 arch/x86/kvm/svm/svm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 7e45d03..fb4bb51 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1139,6 +1139,11 @@ static void __svm_vcpu_reset(struct kvm_vcpu *vcpu)
 	svm_init_osvw(vcpu);
 	vcpu->arch.microcode_version = 0x01000065;
 	svm->tsc_ratio_msr = kvm_default_tsc_scaling_ratio;
+	/* 
+	 * TSC frequency select is HWCR[24], set it to host's value to indicate
+	 * whether the TSC increments at the P0 frequency. 
+	 */
+	vcpu->arch.msr_hwcr = native_read_msr(MSR_K7_HWCR) & BIT_ULL(24); 
 
 	if (sev_es_guest(vcpu->kvm))
 		sev_es_vcpu_reset(svm);
-- 
1.8.3.1


             reply	other threads:[~2022-05-10  7:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10  7:53 Shannon Zhao [this message]
2022-05-10 23:45 ` 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=1652169227-38383-1-git-send-email-shannon.zhao@linux.alibaba.com \
    --to=shannon.zhao@linux.alibaba.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=yijunzhu@linux.alibaba.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®