Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8448065rwi; Tue, 25 Oct 2022 06:54:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Bdp1ltwAtlVkBZOzcB7sIdqLSsd/PbUQkwwvy2C2Cwpg/2hN6RgIhMAV18tN0cC9U0coX X-Received: by 2002:aa7:dd45:0:b0:458:7474:1fbe with SMTP id o5-20020aa7dd45000000b0045874741fbemr36210492edw.334.1666706046957; Tue, 25 Oct 2022 06:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666706046; cv=none; d=google.com; s=arc-20160816; b=n642M9ptXxK/b5Km8z5yYUYre0cvgkQN6yCbDQiZkRYX9kELQB2hEhEobuxXArc9La CKciCKy0bEfm4AiKhUgFTXh/JkqLIrYmo1h1K1zOVCcHeZCbCJu36WzRYZYhaSx8YHsi 2GcF0sG0gaO7T7UEl8GFsH9z8H1vyEuNplRsYg9VoV3fG/PyvqV1b5kQAjG+jWVOA4m8 bbBGlhgO22Dvjtqj473NKVFMLrk6yya3CGUHoqU2ffC5whS26fumugWUjG5KhuqU9eUq 2pADlr1S9OTwSSXbqUQNfl79b7WxOCGM0TWdZ9O26kNFcv5Z0TB4V+TpzgaZhQfpjMHQ s+lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YKqk8JFJPFyZT4uxuIdJDMrDXX3QslvogL56oEpKGVE=; b=pu88iEz3EakXfqvt4reB2LkYp0n93BfZPSqelZfdFtPevgiy4/LeMcZijIDKaoOQxy 5i9AvcfKBM3rh+tHh7KW0ZsBCzHlXgYd+1FepZRJFiVt/i8Zwy3zZjVzz9/UHRsbgOkp qu1UdzlflwkrMuubGbiJ4OggTH3K8jrMw70bwBvtBhgOg3/7UqKR2Ggctn00K5VpIN1e AIjR0pa7BSFif3BBgHRYiQXFNPnqJAciVAM8kFTZHNjkOTx8rKyQ5KCWlIY3UI0UUj8K nwz2YYeUy30Ep9fg7p7WYvr/JzVUdXozu8Sn3KZo11nhPaP9fkFLwO0W5tUZAOrdcJb5 InBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aGdtZjrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020a1709065d0f00b007881b45441asi3095231ejt.721.2022.10.25.06.53.41; Tue, 25 Oct 2022 06:54:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aGdtZjrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbiJYMuQ (ORCPT + 99 others); Tue, 25 Oct 2022 08:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbiJYMtq (ORCPT ); Tue, 25 Oct 2022 08:49:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68DC18BE29 for ; Tue, 25 Oct 2022 05:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666702071; 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=YKqk8JFJPFyZT4uxuIdJDMrDXX3QslvogL56oEpKGVE=; b=aGdtZjrwKLeHD5AYaBwW9VrYi5FU3ehFhs2g1OUfJx4yz+7uc3zwXrDzp1uTnZgeH8OSf5 ABWLPUzszUsAuhc+naPz2BeLVbMlUkfVce78edgE1RuUOYr7XihK9mdD3jvpOGLruNqa6V NXHzQHlBHHaJfAQnmzYHQBJwWUUkMwU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-nkgboKVhNQ6gqyX7rFkv3A-1; Tue, 25 Oct 2022 08:47:47 -0400 X-MC-Unique: nkgboKVhNQ6gqyX7rFkv3A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C9F0857AA0; Tue, 25 Oct 2022 12:47:46 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD31E40C6EC6; Tue, 25 Oct 2022 12:47:42 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Thomas Gleixner , Yang Zhong , x86@kernel.org, Jim Mattson , Vitaly Kuznetsov , Paolo Bonzini , Sean Christopherson , Wanpeng Li , Shuah Khan , Guang Zeng , Joerg Roedel , Maxim Levitsky , linux-kernel@vger.kernel.org, Dave Hansen , Ingo Molnar , linux-kselftest@vger.kernel.org, Kees Cook , "H. Peter Anvin" , Wei Wang , Borislav Petkov Subject: [PATCH RESEND v4 00/23] SMM emulation and interrupt shadow fixes Date: Tue, 25 Oct 2022 15:47:18 +0300 Message-Id: <20221025124741.228045-1-mlevitsk@redhat.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 V4:=0D =0D - rebased on top of patch series from Paolo which=0D allows smm support to be disabled by Kconfig option.=0D =0D - addressed review feedback.=0D =0D I included these patches in the series for reference.=0D =0D Best regards,=0D Maxim Levitsky=0D =0D Maxim Levitsky (15):=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: smm: number of GPRs in the SMRAM image depends on the image=0D format=0D KVM: x86: smm: check for failures on smm entry=0D KVM: x86: smm: add structs for KVM's smram layout=0D KVM: x86: smm: use smram structs in the common code=0D KVM: x86: smm: use smram struct for 32 bit smram load/restore=0D KVM: x86: smm: use smram struct for 64 bit smram load/restore=0D KVM: svm: drop explicit return value of kvm_vcpu_map=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: smm: preserve interrupt shadow in SMRAM=0D =0D Paolo Bonzini (8):=0D KVM: x86: start moving SMM-related functions to new files=0D KVM: x86: move SMM entry to a new file=0D KVM: x86: move SMM exit to a new file=0D KVM: x86: do not go through ctxt->ops when emulating rsm=0D KVM: allow compiling out SMM support=0D KVM: x86: compile out vendor-specific code if SMM is disabled=0D KVM: x86: remove SMRAM address space if SMM is not supported=0D KVM: x86: do not define KVM_REQ_SMI if SMM disabled=0D =0D arch/x86/include/asm/kvm-x86-ops.h | 2 +=0D arch/x86/include/asm/kvm_host.h | 29 +-=0D arch/x86/kvm/Kconfig | 11 +=0D arch/x86/kvm/Makefile | 1 +=0D arch/x86/kvm/emulate.c | 458 +++----------=0D arch/x86/kvm/kvm_cache_regs.h | 5 -=0D arch/x86/kvm/kvm_emulate.h | 47 +-=0D arch/x86/kvm/lapic.c | 14 +-=0D arch/x86/kvm/lapic.h | 7 +-=0D arch/x86/kvm/mmu/mmu.c | 1 +=0D arch/x86/kvm/smm.c | 637 ++++++++++++++++++=0D arch/x86/kvm/smm.h | 160 +++++=0D arch/x86/kvm/svm/nested.c | 3 +=0D arch/x86/kvm/svm/svm.c | 43 +-=0D arch/x86/kvm/vmx/nested.c | 1 +=0D arch/x86/kvm/vmx/vmcs12.h | 5 +-=0D arch/x86/kvm/vmx/vmx.c | 11 +-=0D arch/x86/kvm/x86.c | 353 +---------=0D include/linux/build_bug.h | 9 +=0D tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +=0D 20 files changed, 1031 insertions(+), 768 deletions(-)=0D create mode 100644 arch/x86/kvm/smm.c=0D create mode 100644 arch/x86/kvm/smm.h=0D =0D -- =0D 2.34.3=0D =0D