public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nikunj A Dadhania <nikunj@amd.com>
To: <seanjc@google.com>, <pbonzini@redhat.com>, <kvm@vger.kernel.org>
Cc: <thomas.lendacky@amd.com>, <santosh.shukla@amd.com>,
	<bp@alien8.de>, <ketanch@iitk.ac.in>, <nikunj@amd.com>
Subject: [RFC PATCH 4/5] KVM: SVM: Prevent writes to TSC MSR when Secure TSC is enabled
Date: Thu, 29 Aug 2024 11:07:47 +0530	[thread overview]
Message-ID: <20240829053748.8283-5-nikunj@amd.com> (raw)
In-Reply-To: <20240829053748.8283-1-nikunj@amd.com>

For a Secure TSC enabled SNP guest, writes to MSR_IA32_TSC is not expected.
Log the error and return #GP.

Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
---
 arch/x86/kvm/svm/svm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index bf86410b2f43..f9b2c1956a60 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3151,6 +3151,17 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 
 		svm->tsc_aux = data;
 		break;
+	case MSR_IA32_TSC:
+		/*
+		 * If Secure TSC is enabled, KVM doesn't expect to receive
+		 * a VMEXIT for a TSC write, record the error and return a
+		 * #GP
+		 */
+		if (vcpu->arch.guest_state_protected && snp_secure_tsc_enabled(vcpu->kvm)) {
+			vcpu_unimpl(vcpu, "unimplemented IA32_TSC for secure tsc\n");
+			return 1;
+		}
+		break;
 	case MSR_IA32_DEBUGCTLMSR:
 		if (!lbrv) {
 			kvm_pr_unimpl_wrmsr(vcpu, ecx, data);
-- 
2.34.1


  parent reply	other threads:[~2024-08-29  5:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-29  5:37 [RFC PATCH 0/5] Enable Secure TSC for SEV-SNP Nikunj A Dadhania
2024-08-29  5:37 ` [RFC PATCH 1/5] x86/cpufeatures: Add SNP Secure TSC Nikunj A Dadhania
2024-08-29 13:22   ` Borislav Petkov
2024-09-02  4:16     ` Nikunj A. Dadhania
2024-09-02 16:42       ` Borislav Petkov
2024-09-03  5:43         ` Nikunj A. Dadhania
2024-09-03  7:16           ` Borislav Petkov
2024-08-29  5:37 ` [RFC PATCH 2/5] KVM: SVM: Set TSC frequency for SecureTSC-enabled guests Nikunj A Dadhania
2024-08-29  5:37 ` [RFC PATCH 3/5] KVM: SVM: Add GUEST_TSC_FREQ MSR Nikunj A Dadhania
2024-08-29  5:37 ` Nikunj A Dadhania [this message]
2024-08-29  5:37 ` [RFC PATCH 5/5] KVM: SVM: Add Secure TSC support for SNP Guest Nikunj A Dadhania
2024-11-22  0:41 ` [RFC PATCH 0/5] Enable Secure TSC for SEV-SNP Isaku Yamahata

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=20240829053748.8283-5-nikunj@amd.com \
    --to=nikunj@amd.com \
    --cc=bp@alien8.de \
    --cc=ketanch@iitk.ac.in \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=santosh.shukla@amd.com \
    --cc=seanjc@google.com \
    --cc=thomas.lendacky@amd.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