From: Sean Christopherson <seanjc@google.com>
To: Maxim Levitsky <mlevitsk@redhat.com>
Cc: kvm@vger.kernel.org, x86@kernel.org,
Kees Cook <keescook@chromium.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Borislav Petkov <bp@alien8.de>, Joerg Roedel <joro@8bytes.org>,
Ingo Molnar <mingo@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH v2 09/11] KVM: x86: emulator/smm: use smram struct for 64 bit smram load/restore
Date: Thu, 21 Jul 2022 00:38:24 +0000 [thread overview]
Message-ID: <YtigALu4ccTi4/v0@google.com> (raw)
In-Reply-To: <20220621150902.46126-10-mlevitsk@redhat.com>
On Tue, Jun 21, 2022, Maxim Levitsky wrote:
> Use kvm_smram_state_64 struct to save/restore the 64 bit SMM state
> (used when X86_FEATURE_LM is present in the guest CPUID,
> regardless of 32-bitness of the guest).
>
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> @@ -9814,7 +9805,7 @@ static void enter_smm(struct kvm_vcpu *vcpu)
> memset(buf, 0, 512);
> #ifdef CONFIG_X86_64
> if (guest_cpuid_has(vcpu, X86_FEATURE_LM))
> - enter_smm_save_state_64(vcpu, buf);
> + enter_smm_save_state_64(vcpu, (struct kvm_smram_state_64 *)buf);
> else
> #endif
> enter_smm_save_state_32(vcpu, (struct kvm_smram_state_32 *)buf);
Hrm, I _love_ the approach overall, but I really dislike having to cast an
arbitrary buffer, especially in the SVM code.
Aha! Rather than keeping a buffer and casting, create a union to hold everything:
union kvm_smram {
struct kvm_smram_state_64 smram64;
struct kvm_smram_state_32 smram32;
u8 bytes[512];
};
and then enter_smm() becomes:
static void enter_smm(struct kvm_vcpu *vcpu)
{
struct kvm_segment cs, ds;
struct desc_ptr dt;
unsigned long cr0;
union kvm_smram smram;
BUILD_BUG_ON(sizeof(smram) != 512);
memset(smram.bytes, 0, sizeof(smram));
#ifdef CONFIG_X86_64
if (guest_cpuid_has(vcpu, X86_FEATURE_LM))
enter_smm_save_state_64(vcpu, &smram.smram64);
else
#endif
enter_smm_save_state_32(vcpu, &smram.smram32);
/*
* Give enter_smm() a chance to make ISA-specific changes to the vCPU
* state (e.g. leave guest mode) after we've saved the state into the
* SMM state-save area.
*/
static_call(kvm_x86_enter_smm)(vcpu, &smram);
kvm_smm_changed(vcpu, true);
kvm_vcpu_write_guest(vcpu, vcpu->arch.smbase + 0xfe00, smram.bytes, sizeof(smram));
and em_rsm() gets similar treatment. Then the vendor code doesn't have to cast,
e.g. SVM can do:
smram->smram64.svm_guest_flag = 1;
smram->smram64.svm_guest_vmcb_gpa = svm->nested.vmcb12_gpa;
That way we don't have to refactor this all again if we want to use SMRAM to save
something on Intel for VMX (though I agree with Jim that that's probably a bad idea).
next prev parent reply other threads:[~2022-07-21 0:38 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 15:08 [PATCH v2 00/11] SMM emulation and interrupt shadow fixes Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 01/11] KVM: x86: emulator: em_sysexit should update ctxt->mode Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 02/11] KVM: x86: emulator: introduce update_emulation_mode Maxim Levitsky
2022-07-20 23:44 ` Sean Christopherson
2022-07-21 11:52 ` Maxim Levitsky
2022-07-21 14:23 ` Sean Christopherson
2022-06-21 15:08 ` [PATCH v2 03/11] KVM: x86: emulator: remove assign_eip_near/far Maxim Levitsky
2022-07-20 23:51 ` Sean Christopherson
2022-07-21 11:52 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 04/11] KVM: x86: emulator: update the emulation mode after rsm Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 05/11] KVM: x86: emulator: update the emulation mode after CR0 write Maxim Levitsky
2022-07-20 23:50 ` Sean Christopherson
2022-07-21 11:53 ` Maxim Levitsky
2022-07-21 14:11 ` Sean Christopherson
2022-07-21 14:57 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 06/11] KVM: x86: emulator/smm: number of GPRs in the SMRAM image depends on the image format Maxim Levitsky
2022-07-21 0:06 ` Sean Christopherson
2022-07-21 0:09 ` Sean Christopherson
2022-06-21 15:08 ` [PATCH v2 07/11] KVM: x86: emulator/smm: add structs for KVM's smram layout Maxim Levitsky
2022-07-21 0:40 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:08 ` [PATCH v2 08/11] KVM: x86: emulator/smm: use smram struct for 32 bit smram load/restore Maxim Levitsky
2022-06-21 15:09 ` [PATCH v2 09/11] KVM: x86: emulator/smm: use smram struct for 64 " Maxim Levitsky
2022-07-21 0:38 ` Sean Christopherson [this message]
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:09 ` [PATCH v2 10/11] KVM: x86: SVM: use smram structs Maxim Levitsky
2022-07-21 0:18 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-07-21 0:39 ` Sean Christopherson
2022-07-21 11:54 ` Maxim Levitsky
2022-06-21 15:09 ` [PATCH v2 11/11] KVM: x86: emulator/smm: preserve interrupt shadow in SMRAM Maxim Levitsky
2022-06-29 16:31 ` Jim Mattson
2022-06-30 6:00 ` Maxim Levitsky
2022-06-30 16:00 ` Jim Mattson
2022-07-05 13:38 ` Maxim Levitsky
2022-07-05 13:40 ` Maxim Levitsky
2022-07-05 13:51 ` Maxim Levitsky
2022-07-06 18:13 ` Jim Mattson
2022-07-06 20:00 ` Maxim Levitsky
2022-07-06 20:38 ` Jim Mattson
2022-07-10 16:05 ` Maxim Levitsky
2022-06-29 7:21 ` [PATCH v2 00/11] SMM emulation and interrupt shadow fixes Maxim Levitsky
2022-07-14 11:06 ` Maxim Levitsky
2022-07-20 8:47 ` Maxim Levitsky
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=YtigALu4ccTi4/v0@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/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