From: Nikunj A Dadhania <nikunj@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>, <seanjc@google.com>,
<pbonzini@redhat.com>, <kvm@vger.kernel.org>
Cc: <santosh.shukla@amd.com>, <bp@alien8.de>, <isaku.yamahata@intel.com>
Subject: Re: [PATCH v2 3/4] KVM: SVM: Prevent writes to TSC MSR when Secure TSC is enabled
Date: Tue, 11 Feb 2025 08:24:35 +0000 [thread overview]
Message-ID: <85ed04ubwc.fsf@amd.com> (raw)
In-Reply-To: <8ec1bef9-829d-4370-47f6-c94e794cc5d5@amd.com>
Tom Lendacky <thomas.lendacky@amd.com> writes:
> On 2/10/25 03:22, Nikunj A Dadhania wrote:
>> Disallow writes to MSR_IA32_TSC for Secure TSC enabled SNP guests, as such
>> writes are not expected. Log the error and return #GP to the guest.
>
> Re-word this to make it a bit clearer about why this is needed. It is
> expected that the guest won't write to MSR_IA32_TSC or, if it does, it
> will ignore any writes to it and not exit to the HV. So this is catching
> the case where that behavior is not occurring.
>
Sure, will update.
>>
>> 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 d7a0428aa2ae..929f35a2f542 100644
>> --- a/arch/x86/kvm/svm/svm.c
>> +++ b/arch/x86/kvm/svm/svm.c
>> @@ -3161,6 +3161,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)) {
>
> Does it matter if the VMSA has already been encrypted? Can this just be
>
> if (sev_snp_guest() && snp_secure_tsc_enabled(vcpu->kvm)) {
>
> ?
>
QEMU initializes the IA32_TSC MSR to zero resulting in the below
error if I use the above.
qemu-system-x86_64: error: failed to set MSR 0x10 to 0x0
qemu-system-x86_64: ../target/i386/kvm/kvm.c:3849: kvm_buf_set_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed.
Once the guest state is protected, we do not expect any writes from VMM.
Regards,
Nikunj
next prev parent reply other threads:[~2025-02-11 8:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 9:22 [PATCH v2 0/4] Enable Secure TSC for SEV-SNP Nikunj A Dadhania
2025-02-10 9:22 ` [PATCH v2 1/4] x86/cpufeatures: Add SNP Secure TSC Nikunj A Dadhania
2025-02-11 14:30 ` Borislav Petkov
2025-02-10 9:22 ` [PATCH v2 2/4] KVM: SVM: Add GUEST_TSC_FREQ MSR for Secure TSC enabled guests Nikunj A Dadhania
2025-02-10 9:22 ` [PATCH v2 3/4] KVM: SVM: Prevent writes to TSC MSR when Secure TSC is enabled Nikunj A Dadhania
2025-02-10 20:21 ` Tom Lendacky
2025-02-11 8:24 ` Nikunj A Dadhania [this message]
2025-02-11 14:03 ` Tom Lendacky
2025-02-11 14:42 ` Tom Lendacky
2025-02-12 4:26 ` Nikunj A Dadhania
2025-02-11 22:37 ` Sean Christopherson
2025-02-12 8:37 ` Nikunj A Dadhania
2025-02-12 14:04 ` Sean Christopherson
2025-02-14 5:14 ` Nikunj A. Dadhania
2025-02-14 5:37 ` subscribe list archives
2025-02-10 9:22 ` [PATCH v2 4/4] KVM: SVM: Enable Secure TSC for SNP guests Nikunj A Dadhania
2025-02-10 20:41 ` Tom Lendacky
2025-02-11 8:11 ` Nikunj A Dadhania
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=85ed04ubwc.fsf@amd.com \
--to=nikunj@amd.com \
--cc=bp@alien8.de \
--cc=isaku.yamahata@intel.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.