Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8440293rwi; Tue, 25 Oct 2022 06:48:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/KSDmQnlsZubs63pDuMaMR6o/HpG1F9SsGwXtPKpKZjL41VhcS7IU5norjb8+gIX42fI+ X-Received: by 2002:a17:907:60c6:b0:7ad:2dc4:574a with SMTP id hv6-20020a17090760c600b007ad2dc4574amr50330ejc.312.1666705679831; Tue, 25 Oct 2022 06:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666705679; cv=none; d=google.com; s=arc-20160816; b=SBZOURqbhms0vszsRByqs1IkEy9MK2uasE3f9SRXzMyYW9dNKZ6ILgXyR4O6IIgVkw ekgGEmeZj9vpYQyDdeBis60uudMCpdCp9hV2EV9PZlm1ZnMH2/nOyY/hiSzOUwpLcSj9 RKhOm99ljjm82N2KwCRB608IBGRRd7CBMzqstoP+1ABN5vIzhjZVxo34Bq1TWOTSLmXs 0inElXZ/niDMmxeu2P2fJ65cGdMh3dcX5godtI49UN3ngyUzTScxNKp1+aAHGpqJOR26 v0plGL+wkorDVNzAElRCCxc+L+JXaFCvLWjRqsjh8Gu205MVPD0LULRQTBvEOJggvWrp SOtQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IkrTzU5rG8TBDhJXggqu3Ho3+X8GGbZwRVqLpyPTTs0=; b=F7Jh73W1+pziYBP9nTnYvEiCOG1jyuOplca7zEJCSOBe1ljuOEid1dH7wAhLHxxIyR ZCja82keXkcFGFb/6PC9ufbe4a1IykgM7Myd7EzQ7Hgpqyj7lQ9d9U4ddOsd8t/xvflq gzBCECoQmLXLLcSPDVLVFFA6QSGGNSBptm0praJ2CJD9q5dSse6IBsGxveKhyKq+0dHc Fv1QP7ttebBKckHif1C0YPWIf34J2/TSOLmO61+Fti5Pe5psL4dW9mniTSrRwOjZ9ClQ p0DuUH3HGtciOncSaBh5+VrRpsqowUH46uoJekuUphJKbeLwtT5CwNajRpoUp5IW3sbR fR4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J6RtLjcY; 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 b9-20020a50ccc9000000b004585e0f44fesi2621894edj.60.2022.10.25.06.47.32; Tue, 25 Oct 2022 06:47:59 -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=J6RtLjcY; 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 S231864AbiJYMwD (ORCPT + 99 others); Tue, 25 Oct 2022 08:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232226AbiJYMve (ORCPT ); Tue, 25 Oct 2022 08:51:34 -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 ESMTPS id 2F900196B78 for ; Tue, 25 Oct 2022 05:48:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666702123; 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: in-reply-to:in-reply-to:references:references; bh=IkrTzU5rG8TBDhJXggqu3Ho3+X8GGbZwRVqLpyPTTs0=; b=J6RtLjcYgBzCVupzebD3LWyXnEf2B+lxKFW5+m2OG1RRptB9CEakW0Z5oV2OzY8LYQognB 5XSbVgBrEevZgFC9UKu0Hv4WSFJYxeXWqqV9UJBCVOMtvpnoG3B9xVb1D0buRx8zq3Wn4O 3tWnolmriJ5zm2BD0+UZ2huzWJ9kdzo= 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-588-Bihkr0zeOZ2yMhRp5klk3Q-1; Tue, 25 Oct 2022 08:48:37 -0400 X-MC-Unique: Bihkr0zeOZ2yMhRp5klk3Q-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 1955580252C; Tue, 25 Oct 2022 12:48:36 +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 B8BBE40C6EC6; Tue, 25 Oct 2022 12:48:32 +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 12/23] KVM: x86: emulator: update the emulation mode after rsm Date: Tue, 25 Oct 2022 15:47:30 +0300 Message-Id: <20221025124741.228045-13-mlevitsk@redhat.com> In-Reply-To: <20221025124741.228045-1-mlevitsk@redhat.com> References: <20221025124741.228045-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Update the emulation mode after RSM so that RIP will be correctly written back, because the RSM instruction can switch the CPU mode from 32 bit (or less) to 64 bit. This fixes a guest crash in case the #SMI is received while the guest runs a code from an address > 32 bit. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/emulate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index c65f57b6da9bf1..2c56d08b426065 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2315,7 +2315,7 @@ static int em_rsm(struct x86_emulate_ctxt *ctxt) if (ctxt->ops->leave_smm(ctxt)) ctxt->ops->triple_fault(ctxt); - return X86EMUL_CONTINUE; + return emulator_recalc_and_set_mode(ctxt); } static void -- 2.34.3