Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp357717pxb; Wed, 6 Oct 2021 06:32:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrLmtj0VnD6qNLapHnVpJh6fbF9HG/QGpo4QvUmdVDexkOK+VsgBx+Zd8Xu9upn7XdNwkb X-Received: by 2002:a17:90a:191a:: with SMTP id 26mr11036220pjg.118.1633527162590; Wed, 06 Oct 2021 06:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633527162; cv=none; d=google.com; s=arc-20160816; b=eB/KIA6Syqv/S0C5DTexb2u7rNuZqWYPm2E+x+22W6PPOUjoiVBMY5dJnB4uorBCjS aVe5DEHSRAwkPM1M9Zqp/VLUAFVvvZMyTBCjt2MM2ZSct9hMDBjqFm8LU4B7P875wa1J 3ny7yRnN0wXYUYgUnqJxyXP57/eDyctamzuIaMp8d+SvEelYA/5PCE7R9Cttjy/lf1wF 6LsCWJwZr8Q4I9KwRDFgmiehdbx1TMzQwPo3qBOVYaDalpji8qSiNktM5E9RONWGQ4FQ TMkH9rAHShStJheS0T4B2y1zB1lMUp4zbkRSR5A3Sc1iD/BnvHSVznzqy2LFIbkc27Rr jHeA== 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=nR8biERGlOZLYKj+i4+YPSiL/wliWVP8akJ95ANvHxg=; b=Ww0QHb0CJ03iQOvtLpnw+7UYF14VNl/B3VjM4TsQGUXl8pMt8+sQPWrcsar0WjV3I3 803EgoEIefW+mmllsbNs4H6P59N1Qapm9iUgg7ilNXmS/Wy1HDkTWNe/4YRX8dpWYbmD seVW/gAhapVIfOEJOGeWRYVdeKsWxey2VNiCdTGxfILSHtE605AK/DhDWCu8+qwlQ5Nb Db5laYtjwwfewFD11UxMJNgy13S650myTutF/H7ePoPeLAXitrmpZGSgFYHY/jTx4bMv AprbHxMt7JKEHhLjqePJznaFd/G0kRx5bcLj3xrah3y5c+pyHINfjKTGnmmPCXxpmET3 C5dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kD6PsbKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si24095892pls.182.2021.10.06.06.32.24; Wed, 06 Oct 2021 06:32:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kD6PsbKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239109AbhJFNch (ORCPT + 99 others); Wed, 6 Oct 2021 09:32:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238845AbhJFNcV (ORCPT ); Wed, 6 Oct 2021 09:32:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 60AF6610A8; Wed, 6 Oct 2021 13:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633527029; bh=QLZ6t27qJjhlPkoFsEFqVjdFK7qxIrD4AzyNiprhj5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kD6PsbKn72GnPCHwcsflqSoEqLSwcsoX5IfkIddzOnWOTuYQ5Cy3drhn14YFOc/AG eMHbe8MpWiX8PzUigFhSALnUjZkiBMLNvKp4IY4QddSttVImd1/CNK0V1wTwYZ+7MU 9s0L1Ryu85LQpiyfv1G48E9SueDl1mkWX3t/BrxllPk/WX8MVKM58t70IibCv/YLv4 bAT+NSAKiALozqAvy+1jtJ3bNpSTpVsgbqr17vvzbEiCIULa3Zwz+XMbQcahLf9T9Y iKfrnOBxFAflm7628MhKkZKrumrZY48arp/T8qJu2OG+Pu/OXx7Lk4tVfDqvTQKt7F 0zF7AZ19fn+gA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maxim Levitsky , Sean Christopherson , Paolo Bonzini , Sasha Levin , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH MANUALSEL 5.14 5/9] KVM: x86: VMX: synthesize invalid VM exit when emulating invalid guest state Date: Wed, 6 Oct 2021 09:30:17 -0400 Message-Id: <20211006133021.271905-5-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006133021.271905-1-sashal@kernel.org> References: <20211006133021.271905-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Levitsky [ Upstream commit c42dec148b3e1a88835e275b675e5155f99abd43 ] Since no actual VM entry happened, the VM exit information is stale. To avoid this, synthesize an invalid VM guest state VM exit. Suggested-by: Sean Christopherson Signed-off-by: Maxim Levitsky Message-Id: <20210913140954.165665-6-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx/vmx.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 256f8cab4b8b..339116ff236f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6607,10 +6607,21 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->loaded_vmcs->soft_vnmi_blocked)) vmx->loaded_vmcs->entry_time = ktime_get(); - /* Don't enter VMX if guest state is invalid, let the exit handler - start emulation until we arrive back to a valid state */ - if (vmx->emulation_required) + /* + * Don't enter VMX if guest state is invalid, let the exit handler + * start emulation until we arrive back to a valid state. Synthesize a + * consistency check VM-Exit due to invalid guest state and bail. + */ + if (unlikely(vmx->emulation_required)) { + vmx->fail = 0; + vmx->exit_reason.full = EXIT_REASON_INVALID_STATE; + vmx->exit_reason.failed_vmentry = 1; + kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_1); + vmx->exit_qualification = ENTRY_FAIL_DEFAULT; + kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_2); + vmx->exit_intr_info = 0; return EXIT_FASTPATH_NONE; + } trace_kvm_entry(vcpu); -- 2.33.0