From: Maxim Levitsky <mlevitsk@redhat.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>,
kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
Cathy Avery <cavery@redhat.com>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/6] KVM: selftests: smm_test: Test SMM enter from L2
Date: Wed, 07 Jul 2021 13:35:52 +0300 [thread overview]
Message-ID: <6fecea5161f17614f1ca745041243332de45fafb.camel@redhat.com> (raw)
In-Reply-To: <20210628104425.391276-7-vkuznets@redhat.com>
On Mon, 2021-06-28 at 12:44 +0200, Vitaly Kuznetsov wrote:
> Two additional tests are added:
> - SMM triggered from L2 does not currupt L1 host state.
> - Save/restore during SMM triggered from L2 does not corrupt guest/host
> state.
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
> tools/testing/selftests/kvm/x86_64/smm_test.c | 70 +++++++++++++++++--
> 1 file changed, 64 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c
> index c1f831803ad2..d0fe2fdce58c 100644
> --- a/tools/testing/selftests/kvm/x86_64/smm_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c
> @@ -53,15 +53,28 @@ static inline void sync_with_host(uint64_t phase)
> : "+a" (phase));
> }
>
> -void self_smi(void)
> +static void self_smi(void)
> {
> x2apic_write_reg(APIC_ICR,
> APIC_DEST_SELF | APIC_INT_ASSERT | APIC_DM_SMI);
> }
>
> -void guest_code(void *arg)
> +static void l2_guest_code(void)
> {
> + sync_with_host(8);
> +
> + sync_with_host(10);
> +
> + vmcall();
> +}
> +
> +static void guest_code(void *arg)
> +{
> + #define L2_GUEST_STACK_SIZE 64
> + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
> uint64_t apicbase = rdmsr(MSR_IA32_APICBASE);
> + struct svm_test_data *svm = arg;
> + struct vmx_pages *vmx_pages = arg;
>
> sync_with_host(1);
>
> @@ -74,21 +87,50 @@ void guest_code(void *arg)
> sync_with_host(4);
>
> if (arg) {
> - if (cpu_has_svm())
> - generic_svm_setup(arg, NULL, NULL);
> - else
> - GUEST_ASSERT(prepare_for_vmx_operation(arg));
> + if (cpu_has_svm()) {
> + generic_svm_setup(svm, l2_guest_code,
> + &l2_guest_stack[L2_GUEST_STACK_SIZE]);
> + } else {
> + GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
> + GUEST_ASSERT(load_vmcs(vmx_pages));
> + prepare_vmcs(vmx_pages, l2_guest_code,
> + &l2_guest_stack[L2_GUEST_STACK_SIZE]);
> + }
>
> sync_with_host(5);
>
> self_smi();
>
> sync_with_host(7);
> +
> + if (cpu_has_svm()) {
> + run_guest(svm->vmcb, svm->vmcb_gpa);
> + svm->vmcb->save.rip += 3;
> + run_guest(svm->vmcb, svm->vmcb_gpa);
> + } else {
> + vmlaunch();
> + vmresume();
> + }
> +
> + /* Stages 8-11 are eaten by SMM (SMRAM_STAGE reported instead) */
> + sync_with_host(12);
> }
>
> sync_with_host(DONE);
> }
>
> +void inject_smi(struct kvm_vm *vm)
> +{
> + struct kvm_vcpu_events events;
> +
> + vcpu_events_get(vm, VCPU_ID, &events);
> +
> + events.smi.pending = 1;
> + events.flags |= KVM_VCPUEVENT_VALID_SMM;
> +
> + vcpu_events_set(vm, VCPU_ID, &events);
> +}
> +
> int main(int argc, char *argv[])
> {
> vm_vaddr_t nested_gva = 0;
> @@ -147,6 +189,22 @@ int main(int argc, char *argv[])
> "Unexpected stage: #%x, got %x",
> stage, stage_reported);
>
> + /*
> + * Enter SMM during L2 execution and check that we correctly
> + * return from it. Do not perform save/restore while in SMM yet.
> + */
> + if (stage == 8) {
> + inject_smi(vm);
> + continue;
> + }
> +
> + /*
> + * Perform save/restore while the guest is in SMM triggered
> + * during L2 execution.
> + */
> + if (stage == 10)
> + inject_smi(vm);
> +
> state = vcpu_save_state(vm, VCPU_ID);
> kvm_vm_release(vm);
> kvm_vm_restart(vm, O_RDWR);
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Best regards,
Maxim Levitsky
next prev parent reply other threads:[~2021-07-07 10:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-28 10:44 [PATCH 0/6] KVM: nSVM: Fix issues when SMM is entered from L2 Vitaly Kuznetsov
2021-06-28 10:44 ` [PATCH 1/6] KVM: nSVM: Check the value written to MSR_VM_HSAVE_PA Vitaly Kuznetsov
2021-07-07 10:28 ` Maxim Levitsky
2021-07-08 17:27 ` Paolo Bonzini
2021-07-09 6:08 ` Maxim Levitsky
2021-06-28 10:44 ` [PATCH 2/6] KVM: nSVM: Check that VM_HSAVE_PA MSR was set before VMRUN Vitaly Kuznetsov
2021-07-07 10:28 ` Maxim Levitsky
2021-06-28 10:44 ` [PATCH 3/6] KVM: nSVM: Introduce svm_copy_nonvmloadsave_state() Vitaly Kuznetsov
2021-07-05 12:08 ` Paolo Bonzini
2021-07-07 10:29 ` Maxim Levitsky
2021-06-28 10:44 ` [PATCH 4/6] KVM: nSVM: Fix L1 state corruption upon return from SMM Vitaly Kuznetsov
2021-07-07 10:32 ` Maxim Levitsky
2021-06-28 10:44 ` [PATCH 5/6] KVM: nSVM: Restore nested control upon leaving SMM Vitaly Kuznetsov
2021-07-07 10:35 ` Maxim Levitsky
2021-06-28 10:44 ` [PATCH 6/6] KVM: selftests: smm_test: Test SMM enter from L2 Vitaly Kuznetsov
2021-07-07 10:35 ` Maxim Levitsky [this message]
2021-07-08 17:40 ` [PATCH 0/6] KVM: nSVM: Fix issues when SMM is entered " Paolo Bonzini
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=6fecea5161f17614f1ca745041243332de45fafb.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=cavery@redhat.com \
--cc=eesposit@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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;
as well as URLs for NNTP newsgroup(s).