From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5D2BC2B9F4 for ; Mon, 28 Jun 2021 10:44:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9ED761C47 for ; Mon, 28 Jun 2021 10:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232753AbhF1KrD (ORCPT ); Mon, 28 Jun 2021 06:47:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52342 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbhF1KrB (ORCPT ); Mon, 28 Jun 2021 06:47:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624877076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kkyZUt9nND83AIpLRJe3+5UbB9XD72UfzYzdBlyp7l8=; b=eW+uwYYah59ZF/w/UWURsKV+uod+9hLbAlQPBDLObyZDXw9fyusA9QNFBvC3h4XOHArRE1 iuJClF/aPgaDA25kiz7DSoK9ZjLROk0KTG01cCnQtcSbnhI8g38ZPHztYuZDu6YZw30A5i /lE5kXjUNWLZSc2xn/BmfuDm3q47iv0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-271-YTeA5EsSPvGS7rYIMrJnug-1; Mon, 28 Jun 2021 06:44:32 -0400 X-MC-Unique: YTeA5EsSPvGS7rYIMrJnug-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF1AF804146; Mon, 28 Jun 2021 10:44:30 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id C188C5C1CF; Mon, 28 Jun 2021 10:44:26 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , Cathy Avery , Emanuele Giuseppe Esposito , Tom Lendacky , Michael Roth , linux-kernel@vger.kernel.org Subject: [PATCH 0/6] KVM: nSVM: Fix issues when SMM is entered from L2 Date: Mon, 28 Jun 2021 12:44:19 +0200 Message-Id: <20210628104425.391276-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a continuation of "[PATCH RFC] KVM: nSVM: Fix L1 state corruption upon return from SMM". VMCB split commit 4995a3685f1b ("KVM: SVM: Use a separate vmcb for the nested L2 guest") broke return from SMM when we entered there from guest (L2) mode. Gen2 WS2016/Hyper-V is known to do this on boot. The problem appears to be that VMCB01 gets irreversibly destroyed during SMM execution. Previously, we used to have 'hsave' VMCB where regular (pre-SMM) L1's state was saved upon nested_svm_vmexit() but now we just switch to VMCB01 from VMCB02. While writing a selftest for the issue, I've noticed that 'svm->nested.ctl' doesn't get restored after KVM_GET_NESTED_STATE/KVM_SET_NESTED_STATE cycle when guest happens to be in SMM triggered from L2. "KVM: nSVM: Restore nested control upon leaving SMM" is aimed to fix that. First two patches of the series add missing sanity checks for MSR_VM_HSAVE_PA which has to be page aligned and not zero. Vitaly Kuznetsov (6): KVM: nSVM: Check the value written to MSR_VM_HSAVE_PA KVM: nSVM: Check that VM_HSAVE_PA MSR was set before VMRUN KVM: nSVM: Introduce svm_copy_nonvmloadsave_state() KVM: nSVM: Fix L1 state corruption upon return from SMM KVM: nSVM: Restore nested control upon leaving SMM KVM: selftests: smm_test: Test SMM enter from L2 arch/x86/kvm/svm/nested.c | 45 +++++++----- arch/x86/kvm/svm/svm.c | 51 +++++++++++++- arch/x86/kvm/svm/svm.h | 4 ++ tools/testing/selftests/kvm/x86_64/smm_test.c | 70 +++++++++++++++++-- 4 files changed, 144 insertions(+), 26 deletions(-) -- 2.31.1