From patchwork Thu Nov 17 14:32:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 21698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp444712wrr; Thu, 17 Nov 2022 07:00:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5IeCF4xCVsNOfEcSBQJphO6nHACH1Itk9Gnc83QYQwaFl4bGHIKUlP5ytCzm2Wov4fEF3K X-Received: by 2002:a17:906:114b:b0:7ab:1b4c:ac6e with SMTP id i11-20020a170906114b00b007ab1b4cac6emr2484409eja.669.1668697216144; Thu, 17 Nov 2022 07:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668697216; cv=none; d=google.com; s=arc-20160816; b=CqKw43L8zgw19ypROVStkfFZQRnMnZWeItuO8HagUo7AowoAAMHg94+g9dQFstnaN8 tNJRejwaeBTl2gup1uHN3cboKSqk05z0wDp9MGR0hNgdmL9rw/Y0+GhDclVZOJGpPrdW 6FsVjKHtnpguMzgZUIJYeX2ssCN81Q26Lv/BL+2qRd3NSqB3B5mCtXU7VxzU9IrwtQ5u s/04eEuYJfaXFVihxP4NR2UsMYrqXMIMTWO+rtfepF584C+xAmNMSgjRJLdsVkVVhmEg 8esrkPAAI4y0ZXNBZO1Hf32J1qOBh19JIq2JKK9h53ZVDIrIJ8NAQHrc4D5vPNapU2Qa hyRA== 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=1k8xZrOm8P1dLuASAaP3xDdrnCi2/FFVUPRDCzjye6I=; b=AbNSKlbuZ4BTUP7NdnOxjLdIQ2kRPECDXjUJHVn+Ejg5EFsJpmOvSPAbQJR7sa+2gn SJg/CUPL7692JzmXnxcL5CBCAzcZv4NrsL8h5BFVGsXws4Dnb6HzkvfE+Z6Hc8wrxqer 8FXDnmliRikj7kpmuW+ACQBcFgMDCg1hhZYqIiusBh76mlgNNwHLVgu7uxHQ24VkWX7e lQSmlNjoTuksNaP7sYhS/Aluvls7Tv0Q4+ZURNsKy/1gzvE/u+RwOx5gOAcez+P8R8Wq ASDRh0Fg1cLBK6drMOTDjOl7VRsImSDhLwga5CHDbjp3W3v5Bvnl/cV5qe9CYfQ/gNR8 uVGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DuPtPvlm; 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 qq18-20020a17090720d200b0078db89b526asi629348ejb.108.2022.11.17.06.59.52; Thu, 17 Nov 2022 07:00:16 -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=DuPtPvlm; 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 S240392AbiKQOfy (ORCPT + 99 others); Thu, 17 Nov 2022 09:35:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240421AbiKQOej (ORCPT ); Thu, 17 Nov 2022 09:34:39 -0500 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 5CE0C17A9D for ; Thu, 17 Nov 2022 06:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668695616; 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=1k8xZrOm8P1dLuASAaP3xDdrnCi2/FFVUPRDCzjye6I=; b=DuPtPvlm8GQgbPtLvCglrR6JCUhUYoSnDBujXcyXFeOdchapttoorx8QVanjrs9QfXcFBP zknI+Do19kJ7ICNW2wB8AtTExCrP2Tasy2O5Noym6GYagcmDqrDz3O3Vg0EIlq4U1JHRmx BYKkJTn0AdpIF/SoEaBA2MQRMEGq2qw= 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-42-qx5GWSDkPoGBYLKq62dSJQ-1; Thu, 17 Nov 2022 09:33:33 -0500 X-MC-Unique: qx5GWSDkPoGBYLKq62dSJQ-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 4E32788F452; Thu, 17 Nov 2022 14:33:32 +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 C6B0D2166B29; Thu, 17 Nov 2022 14:33:28 +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 12/13] KVM: nSVM: emulate VMEXIT_INVALID case for nested VNMI Date: Thu, 17 Nov 2022 16:32:41 +0200 Message-Id: <20221117143242.102721-13-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?1749755852373618889?= X-GMAIL-MSGID: =?utf-8?q?1749755852373618889?= From: Santosh Shukla If NMI virtualization enabled and NMI_INTERCEPT is unset then next vm entry will exit with #INVALID exit reason. In order to emulate above (VMEXIT(#INVALID)) scenario for nested environment, extending check for V_NMI_ENABLE, NMI_INTERCEPT bit in func __nested_vmcb_check_controls. Signed-off-by: Santosh Shukla Reviewed-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index c9fcdd691bb5a1..3ef7e1971a4709 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -275,6 +275,11 @@ static bool __nested_vmcb_check_controls(struct kvm_vcpu *vcpu, if (CC(!nested_svm_check_tlb_ctl(vcpu, control->tlb_ctl))) return false; + if (CC((control->int_ctl & V_NMI_ENABLE) && + !vmcb12_is_intercept(control, INTERCEPT_NMI))) { + return false; + } + return true; }