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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A18C19F28 for ; Wed, 3 Aug 2022 15:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238201AbiHCPud (ORCPT ); Wed, 3 Aug 2022 11:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237860AbiHCPuZ (ORCPT ); Wed, 3 Aug 2022 11:50:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9CF1D26EA for ; Wed, 3 Aug 2022 08:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659541823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/BrQz+CyfVcc2k2vo2CUTQfHHEz6+03jB7eKZ/pazJY=; b=VZa33uCQNyAByARwc28HRf0H8Kg7dmLPmVB6CEMNVFZClPZbFLjExIkL4Jrss5ZY8hocuI bTm5dPzZaYDclYT1Orz/w37AwF0iZ0OTXRSCqwI/mZPcGFGuWNogBSCvk6tj14MkdjqCSO e/uTEPqSoQsNfJlSUtGQJGYsGSqm0Dk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-358-3w-6go72NbWtFWzI4ESLZQ-1; Wed, 03 Aug 2022 11:50:17 -0400 X-MC-Unique: 3w-6go72NbWtFWzI4ESLZQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BDCD2919EAE; Wed, 3 Aug 2022 15:50:17 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id 877F01121314; Wed, 3 Aug 2022 15:50:12 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Borislav Petkov , Dave Hansen , linux-kernel@vger.kernel.org, Wanpeng Li , Maxim Levitsky , Ingo Molnar , Sean Christopherson , x86@kernel.org, Jim Mattson , Kees Cook , Thomas Gleixner , "H. Peter Anvin" , Joerg Roedel , Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH v3 00/13] SMM emulation and interrupt shadow fixes Date: Wed, 3 Aug 2022 18:49:58 +0300 Message-Id: <20220803155011.43721-1-mlevitsk@redhat.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series is a result of long debug work to find out why=0D sometimes guests with win11 secure boot=0D were failing during boot.=0D =0D During writing a unit test I found another bug, turns out=0D that on rsm emulation, if the rsm instruction was done in real=0D or 32 bit mode, KVM would truncate the restored RIP to 32 bit.=0D =0D I also refactored the way we write SMRAM so it is easier=0D now to understand what is going on.=0D =0D The main bug in this series which I fixed is that we=0D allowed #SMI to happen during the STI interrupt shadow,=0D and we did nothing to both reset it on #SMI handler=0D entry and restore it on RSM.=0D =0D V3: addressed most of the review feedback from Sean (thanks!)=0D =0D Best regards,=0D Maxim Levitsky=0D =0D Maxim Levitsky (13):=0D bug: introduce ASSERT_STRUCT_OFFSET=0D KVM: x86: emulator: em_sysexit should update ctxt->mode=0D KVM: x86: emulator: introduce emulator_recalc_and_set_mode=0D KVM: x86: emulator: update the emulation mode after rsm=0D KVM: x86: emulator: update the emulation mode after CR0 write=0D KVM: x86: emulator/smm: number of GPRs in the SMRAM image depends on=0D the image format=0D KVM: x86: emulator/smm: add structs for KVM's smram layout=0D KVM: x86: emulator/smm: use smram structs in the common code=0D KVM: x86: emulator/smm: use smram struct for 32 bit smram load/restore=0D KVM: x86: emulator/smm: use smram struct for 64 bit smram load/restore=0D KVM: x86: SVM: use smram structs=0D KVM: x86: SVM: don't save SVM state to SMRAM when VM is not long mode=0D capable=0D KVM: x86: emulator/smm: preserve interrupt shadow in SMRAM=0D =0D arch/x86/include/asm/kvm_host.h | 11 +-=0D arch/x86/kvm/emulate.c | 305 +++++++++++++++++---------------=0D arch/x86/kvm/kvm_emulate.h | 223 ++++++++++++++++++++++-=0D arch/x86/kvm/svm/svm.c | 30 ++--=0D arch/x86/kvm/vmx/vmcs12.h | 5 +-=0D arch/x86/kvm/vmx/vmx.c | 4 +-=0D arch/x86/kvm/x86.c | 175 +++++++++---------=0D include/linux/build_bug.h | 9 +=0D 8 files changed, 497 insertions(+), 265 deletions(-)=0D =0D -- =0D 2.26.3=0D =0D