Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1612890rwi; Thu, 3 Nov 2022 07:15:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qDVdfY+8py2T1qK9oIwzyfGYQDEbJriOMXbm+Wb3NhWJ290QQh1f0IKGCZYm9ShE9HrUH X-Received: by 2002:a05:6a00:234d:b0:561:ec04:e77e with SMTP id j13-20020a056a00234d00b00561ec04e77emr31044288pfj.14.1667484948507; Thu, 03 Nov 2022 07:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667484948; cv=none; d=google.com; s=arc-20160816; b=xt4zp/WofBT1yQghfb3pH6s1DnDtZWUhnzh5D6anRtEq4mPYhZJpNvbI0kAXmpe0VE wQQpzruNwwgSLzzXmi7sLOA6k3d5Iz7P10MTnNQ9S7JDsdFWUKEEIaou/u3psT5hZ99q f7/4K16lrpC4pgkHbC92Bn11T3Vhl8zTSwkkboF6Jf0CEkdnsDOfkGPbev1gLKO5DPSL /521GQL4SBGQuoDKCavWj8wgMHIbbv1jvQ70WZyu01Wa3ylf/GXh9h4a/C0BWYLahOe8 6rv87QRuImMRy00J8tpEF4M5aQZk8sUjLxL658FkM6CzambAX4HwduqgOf03p4UwlkKD fwsw== 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=PcvbZGqx/pbGysS7eWOgjCD7HbL3pDHBihn3geMPwgo=; b=bY5JsX3zJvhyCK674inlR4oDU34zJB61aVO0dAc0tkjoxeN3bH2LlrZ15x5AkmlyrO Iz1tB6DLjedmaa0lzJLemmjaga+BowQ2in87R7JWwL6u00lWIz9zM9Ndb+qy4PwFS6ZB zHOlkkh/NbDL5p/QvBNzXKiI31FtsXihG4d5FNIx0lptgeOE9jvgX5/S6GYLqw73Gphr 66NmETT48W2O39PT35435f8sRB5CROJ8R6A2BsTXnQUjgD+eA0yPUBSTT4XLInPCZH1d SMbkRIbVAzP/kiImsOQBZm4NJ2oxJMUS1WqZS9iu58ydTo9QmrAap55lgAoOfVX19vk5 11pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fnmxuFst; 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 i8-20020a636d08000000b0043c05df34c0si1409651pgc.411.2022.11.03.07.15.32; Thu, 03 Nov 2022 07:15:48 -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=fnmxuFst; 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 S229770AbiKCN7w (ORCPT + 97 others); Thu, 3 Nov 2022 09:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbiKCN7T (ORCPT ); Thu, 3 Nov 2022 09:59:19 -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 4CE3D15719 for ; Thu, 3 Nov 2022 06:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667483894; 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=PcvbZGqx/pbGysS7eWOgjCD7HbL3pDHBihn3geMPwgo=; b=fnmxuFstjEPzJ2hPpFxnHEcGL53xvxg7tQhJKDjtxF0+FnMT4PKx8qNOjlbd4NP9/J68/9 1ID3TxDT/JMRZCHGrt0otJKQAceJM6tmPqu/1PPUWxm+TqVU/mGdN5sF8JeOofC6CD2dLw x+zLTZUjUY1/NVFZwwiVbfQa4NLbA2k= 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-61-7RUDoIwgNuizMCmzPY9Xug-1; Thu, 03 Nov 2022 09:58:08 -0400 X-MC-Unique: 7RUDoIwgNuizMCmzPY9Xug-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5013B3C0DDD4; Thu, 3 Nov 2022 13:58:07 +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 0E4AA40C2087; Thu, 3 Nov 2022 13:58:03 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , "H. Peter Anvin" , Shuah Khan , Yang Zhong , Wei Wang , Colton Lewis , Sean Christopherson , Jim Mattson , Chenyi Qiang , Borislav Petkov , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Dave Hansen , Ingo Molnar , David Matlack , Peter Xu , Maxim Levitsky , linux-kselftest@vger.kernel.org Subject: [PATCH 7/9] KVM: x86: allow L1 to not intercept triple fault Date: Thu, 3 Nov 2022 15:57:34 +0200 Message-Id: <20221103135736.42295-8-mlevitsk@redhat.com> In-Reply-To: <20221103135736.42295-1-mlevitsk@redhat.com> References: <20221103135736.42295-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-3.1 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=ham 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 is SVM correctness fix - although a sane L1 would intercept SHUTDOWN event, it doesn't have to, so we have to honour this. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 6 ++++++ arch/x86/kvm/vmx/nested.c | 1 + arch/x86/kvm/x86.c | 11 ++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index bcc4f6620f8aec..3aa9184d1e4ed7 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1092,6 +1092,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) static void nested_svm_triple_fault(struct kvm_vcpu *vcpu) { + struct vcpu_svm *svm = to_svm(vcpu); + + if (!vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_SHUTDOWN)) + return; + + kvm_clear_request(KVM_REQ_TRIPLE_FAULT, vcpu); nested_svm_simple_vmexit(to_svm(vcpu), SVM_EXIT_SHUTDOWN); } diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1ebe141a0a015f..7924dea9367813 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4855,6 +4855,7 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, static void nested_vmx_triple_fault(struct kvm_vcpu *vcpu) { + kvm_clear_request(KVM_REQ_TRIPLE_FAULT, vcpu); nested_vmx_vmexit(vcpu, EXIT_REASON_TRIPLE_FAULT, 0, 0); } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3fd900504e683b..f0a0102a78f5c3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9741,7 +9741,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu) int kvm_check_nested_events(struct kvm_vcpu *vcpu) { - if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { + if (kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { kvm_x86_ops.nested_ops->triple_fault(vcpu); return 1; } @@ -10255,15 +10255,16 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r = 0; goto out; } - if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { - if (is_guest_mode(vcpu)) { + if (kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { + if (is_guest_mode(vcpu)) kvm_x86_ops.nested_ops->triple_fault(vcpu); - } else { + + if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) { vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN; vcpu->mmio_needed = 0; r = 0; - goto out; } + goto out; } if (kvm_check_request(KVM_REQ_APF_HALT, vcpu)) { /* Page is swapped out. Do synthetic halt */ -- 2.34.3