From patchwork Thu Nov 17 14:32:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 21690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp433779wrr; Thu, 17 Nov 2022 06:36:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf6eKwXpozzTDlQAHNzoiP52RtticxlcvxOoaeMY04XzhzBaTXD4Z7s9m8PvgWs9jyY60BCA X-Received: by 2002:a17:903:4094:b0:186:7fce:5ec9 with SMTP id z20-20020a170903409400b001867fce5ec9mr2965224plc.48.1668695779494; Thu, 17 Nov 2022 06:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668695779; cv=none; d=google.com; s=arc-20160816; b=nMxn70FRrPtpjBj2k/A1+tUp2Wil6tkiu5dyND4Ndnc+zGniTju/WkShJ7gTgAYiu6 k6H9F9TL+MJibkkrfxIagmPhxKTUPnPRIeqsCIXYpiMbyFKGzqb8JTaC1SMOrRjBAQfE ezEm1OPoXxhJi4TR0EGiUmYpVbUb/lbovjrjNPdmNdMnQL3SSjfdxuhMkYbJa+YpsVIq fs6CgoTLHkEFOKyGYwwU+xc2X+sBZESa0FsXj75V2HZqT1QqvqnJKH1u5Rb1xiZ+vMhv zadVyRbIbDwEtmwNKd6UsztnaKwCCmKSgb3oIrKxL70srApDSrYdJJPLQRJFZG1Bv7Rj tuGA== 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=BudyXha3IcL4zFH4dWy8hg4aRuVxU+goAgJkX7rkDuY=; b=umO0zMemmWED4Ns52Nblr8mBCgW4f9xsxZUlGARFv7bY1e0XJXgOdOXBwSE50PpJ+H 3mEC8lozMFv8hR8yCuCpJkdfjK9CYoFvBG9epWIz+yTe5NuXzokKPObBTLbLEWx4oy5i wSTVMmIP3GLZMT2BtWPK1EWEWLNf+5mk4XiGMk/QMe5bMyPZUlPQtQCPNOzP+eqDFF6Y k2lv21YFIcJFZgA0ZKY0fNZu2+MuQc3YsocBvZcwmQlrhcuUdjpd9HB7wXnNow0+a+Lk PmnzDupoIZyTU19ZP7ZA+sj1qbjTm0lN5De+Bs5YRIRFjCChzmuKgDjY5OZ5vaDyUrn/ YrPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YFAX9kRh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a635815000000b00476c2178227si1090084pgb.246.2022.11.17.06.36.06; Thu, 17 Nov 2022 06:36:19 -0800 (PST) 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=YFAX9kRh; 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 S240512AbiKQOfL (ORCPT + 99 others); Thu, 17 Nov 2022 09:35:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240409AbiKQOe0 (ORCPT ); Thu, 17 Nov 2022 09:34:26 -0500 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 747CB1B9 for ; Thu, 17 Nov 2022 06:33:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668695602; 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=BudyXha3IcL4zFH4dWy8hg4aRuVxU+goAgJkX7rkDuY=; b=YFAX9kRhAny7g9DdrlJLZyIXDN7jXdjtHc6qayO8Yy+iPtOmyZ1jO0l2HacaKkdMYqZQYv RGPR/kf6wHVUBgD6+2KAvSYNQyWDtWaViCR5qUOyN2ZFb/vo/uiSciGBU4td8x6rfTJ1u5 yvCnrgijT8vEeuYboNGC80CtVky2Ozs= 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-621-Us5Zwb9hM2abFqYnaijUSQ-1; Thu, 17 Nov 2022 09:33:18 -0500 X-MC-Unique: Us5Zwb9hM2abFqYnaijUSQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34EF2185A78B; Thu, 17 Nov 2022 14:33:17 +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 AD9872166B29; Thu, 17 Nov 2022 14:33:13 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Ingo Molnar , "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , Sandipan Das , Daniel Sneddon , Jing Liu , Josh Poimboeuf , Wyes Karny , Borislav Petkov , Babu Moger , Pawan Gupta , Sean Christopherson , Jim Mattson , x86@kernel.org, Maxim Levitsky , Santosh Shukla Subject: [PATCH 08/13] KVM: SVM: Report NMI not allowed when Guest busy handling VNMI Date: Thu, 17 Nov 2022 16:32:37 +0200 Message-Id: <20221117143242.102721-9-mlevitsk@redhat.com> In-Reply-To: <20221117143242.102721-1-mlevitsk@redhat.com> References: <20221117143242.102721-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749754345767985988?= X-GMAIL-MSGID: =?utf-8?q?1749754345767985988?= From: Santosh Shukla In the VNMI case, Report NMI is not allowed when V_NMI_PENDING is set which mean virtual NMI already pended for Guest to process while the Guest is busy handling the current virtual NMI. The Guest will first finish handling the current virtual NMI and then it will take the pended event w/o vmexit. Maxim: - disable NMI window unconditionally for now. Signed-off-by: Santosh Shukla Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 6 ++++++ arch/x86/kvm/svm/svm.h | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index c16f68f6c4f7d7..cfec4c98bb589b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3595,6 +3595,9 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu) if (is_guest_mode(vcpu) && nested_exit_on_nmi(svm)) return false; + if (is_vnmi_enabled(svm) && is_vnmi_pending_set(svm)) + return true; + ret = (vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) || (vcpu->arch.hflags & HF_NMI_MASK); @@ -3732,6 +3735,9 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (is_vnmi_enabled(svm)) + return; + if ((vcpu->arch.hflags & (HF_NMI_MASK | HF_IRET_MASK)) == HF_NMI_MASK) return; /* IRET will cause a vm exit */ diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index bf7f4851dee204..5f2ee72c6e3125 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -583,6 +583,17 @@ static inline void clear_vnmi_mask(struct vcpu_svm *svm) vmcb->control.int_ctl &= ~V_NMI_MASK; } + +static inline bool is_vnmi_pending_set(struct vcpu_svm *svm) +{ + struct vmcb *vmcb = get_vnmi_vmcb(svm); + + if (vmcb) + return !!(vmcb->control.int_ctl & V_NMI_PENDING); + else + return false; +} + /* svm.c */ #define MSR_INVALID 0xffffffffU