Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp406654imn; Wed, 3 Aug 2022 08:54:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6WwR0G8w3C3A+mxyPiJB/F+y/gYbuKAVTjnN4rtmSvIxDuZIhTtTSyYw5TK4CDjnEJ7u6X X-Received: by 2002:a17:902:cf4b:b0:16d:3b47:d2d9 with SMTP id e11-20020a170902cf4b00b0016d3b47d2d9mr26275949plg.96.1659542050508; Wed, 03 Aug 2022 08:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659542050; cv=none; d=google.com; s=arc-20160816; b=vVDgJgalkiKQZzLPy6PGM7/NJsgCDQWYpfUiwpiaNaYvJiLufWRpqcy3S/cPqxDQJq ZlaZhJpFGRm+MLR2DUM/qYBtiYlKZkAPtN1kurM24H2lEhhmIttf5N3ggbr36Z5kiGUW JDRKyxVb8MBgs6urajXhsxzKI8Rtc9VRRZM3zzlyJ5xzgE24bzyBe2U3n2rjs9SD20Lf 4kLDaIfnIhHCxWsCxGmhjRDc41vQvJlg6U4u45c4B8b9gMETsdxBWfBSDXF6OPJbtRaB ZYA7NaM+rytJYWHu72bw0lfYyDW3876+DyYvRaRtlqFV/5u926TJ3LBpYBnFmBXCHbjQ F76g== 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=/BrQz+CyfVcc2k2vo2CUTQfHHEz6+03jB7eKZ/pazJY=; b=O46uE4oCwg2F+J0v8mxjQjyR+lkQ/dtUbTiAEQ3DnEsjDQWjXVLYz1hMqPczafeS4m qt4OTxXaKNFwYyONDoALSPJny0+VTxYWXsGiJUBkSGwRFBeEducJsdWLC/9hMucm7Lvx ZRyZfnJFg/5ALafd+yxgxO5h33c1Vdf4Lh9cJcMQyC3GwDj505XyBSv+KF92pcKH3yAt af7PYZQbF3SI5TakK2m5CMdQAoePAdNc6djNm3ta5/bwPx+UoVVT+62M2iGaeFd5YM+H 8OYDWEbGyCRKcPEAZw54kKOdAeKQgi7trSehkZm04+3vqD9T0WvoEA5JBJqC7o/dUPmG eTpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VZa33uCQ; 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 d129-20020a633687000000b0041c79773440si4284564pga.283.2022.08.03.08.53.56; Wed, 03 Aug 2022 08:54:10 -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=VZa33uCQ; 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 S236624AbiHCPub (ORCPT + 99 others); Wed, 3 Aug 2022 11:50:31 -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 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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