From patchwork Tue Jun 21 15:08:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12889378 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 5E320C433EF for ; Tue, 21 Jun 2022 15:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233490AbiFUPJ0 (ORCPT ); Tue, 21 Jun 2022 11:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352232AbiFUPJV (ORCPT ); Tue, 21 Jun 2022 11:09:21 -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 3E9551C10F for ; Tue, 21 Jun 2022 08:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655824159; 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=v6i2sWSli48GTHsEDuVBdZ0meIchicF21PFUgvtM/2Q=; b=BDx8/RQFWl+l9pgQUBrMNCooRlfrZv87vZjh2mrZQ/BTNPwunIW3WBN6Rhq/RjW9PE83og toUPo/YrnN55/Wknqp1joygWg5LiYVc9GZxfvk1Noityp5oIJZLsvDTXRuyMkhIU/Bvzwx cLxglG/R6T386Jtopl/AIDLl4/zuPsU= 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-38-D6fPNifgP9eHTJqlob27rQ-1; Tue, 21 Jun 2022 11:09:08 -0400 X-MC-Unique: D6fPNifgP9eHTJqlob27rQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4C30803520; Tue, 21 Jun 2022 15:09:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 679EB9D7F; Tue, 21 Jun 2022 15:09:03 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Sean Christopherson , x86@kernel.org, Kees Cook , Dave Hansen , linux-kernel@vger.kernel.org, "H. Peter Anvin" , Borislav Petkov , Joerg Roedel , Ingo Molnar , Paolo Bonzini , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Maxim Levitsky Subject: [PATCH v2 00/11] SMM emulation and interrupt shadow fixes Date: Tue, 21 Jun 2022 18:08:51 +0300 Message-Id: <20220621150902.46126-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch series is a result of long debug work to find out why sometimes guests with win11 secure boot were failing during boot. During writing a unit test I found another bug, turns out that on rsm emulation, if the rsm instruction was done in real or 32 bit mode, KVM would truncate the restored RIP to 32 bit. I also refactored the way we write SMRAM so it is easier now to understand what is going on. The main bug in this series which I fixed is that we allowed #SMI to happen during the STI interrupt shadow, and we did nothing to both reset it on #SMI handler entry and restore it on RSM. Best regards, Maxim Levitsky Maxim Levitsky (11): KVM: x86: emulator: em_sysexit should update ctxt->mode KVM: x86: emulator: introduce update_emulation_mode KVM: x86: emulator: remove assign_eip_near/far KVM: x86: emulator: update the emulation mode after rsm KVM: x86: emulator: update the emulation mode after CR0 write KVM: x86: emulator/smm: number of GPRs in the SMRAM image depends on the image format KVM: x86: emulator/smm: add structs for KVM's smram layout KVM: x86: emulator/smm: use smram struct for 32 bit smram load/restore KVM: x86: emulator/smm: use smram struct for 64 bit smram load/restore KVM: x86: SVM: use smram structs KVM: x86: emulator/smm: preserve interrupt shadow in SMRAM arch/x86/include/asm/kvm_host.h | 6 - arch/x86/kvm/emulate.c | 305 ++++++++++++++++---------------- arch/x86/kvm/kvm_emulate.h | 146 +++++++++++++++ arch/x86/kvm/svm/svm.c | 28 +-- arch/x86/kvm/x86.c | 162 ++++++++--------- 5 files changed, 394 insertions(+), 253 deletions(-)