Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2139159rwb; Thu, 17 Nov 2022 07:04:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FBHGIgmgYBr8wwmw4XRuGgeutLb4ozUJkMO/DN6pe1OmycnG4aAzNP45HRuU4FUGQYwQ2 X-Received: by 2002:a17:906:ef1:b0:78d:260d:a6e4 with SMTP id x17-20020a1709060ef100b0078d260da6e4mr2435489eji.93.1668697488704; Thu, 17 Nov 2022 07:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668697488; cv=none; d=google.com; s=arc-20160816; b=R/dV2E82k0Gb3/7hyeVdD3x4CGysvax4GWL137GmCSBQI44toaSEY/mZ1ioQ+o7SPe HQaRTWfiPrkjZK7jWGubVdlsCoeDV4Gk2aQMy//lbdp8SGLaZesLkPePou8Om7tQv5az apFOVpekDsJjr+2NiV5wJMrcrm8eofxbqUM3c41Vmdhu3U+H/Poy8OWKsQVjyoLv0Ios R+blWgWiwN9A+plAOwuUArZpdmsf5pDJMyVBIPAFZuvK76cK/VHIMvGKGz8/I+3LagPl TjQY50flUj3d1MZOZqLIfPUfyYjLYCwiqRvaVwe3V++G4gipH3ydYdFZZx7G3txOlHTB 8YUQ== 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=0NbPeRaUPQnIvE6A7O9ncqZS6q4+SDogd6fxFg3zlt8=; b=UI3ViGVU7ixJDv+c1T/AzsacRLo9LcGZkNGK3FXmLu+slvjxLGXuaI+S2fS4SYs/ue 3Z86BLqbUoRCdNHXI1faKyr7N25W0er/unWlCZXGEM5U7hKCxHiwV6eyo1v4xlCNvEDT FFgVOqoSDtPy2fRk9MC2jWUt62tVsDYpedW6R2Ag7qjs2ZEuQ5q6ZNnRuttVlOenV/hM OSY1bZniZw7Xn9T6/ywvHd6z54/BLtkzc146rKFOTM0HlbfyEKgSkUCDPRAm/eRz06fr S9iuVKMKg03TZI9yK1GL8TylY1E/MnU9oX+Ji3p6yeUbwZaWD1yHSNDTnOkB1tnQdQDZ bbrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A8gt8S6W; 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 y8-20020a056402358800b00462764a8b8esi1134215edc.592.2022.11.17.07.04.24; Thu, 17 Nov 2022 07:04:48 -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=A8gt8S6W; 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 S240469AbiKQOeq (ORCPT + 92 others); Thu, 17 Nov 2022 09:34:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239779AbiKQOeO (ORCPT ); Thu, 17 Nov 2022 09:34:14 -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 607D479E2F for ; Thu, 17 Nov 2022 06:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668695596; 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=0NbPeRaUPQnIvE6A7O9ncqZS6q4+SDogd6fxFg3zlt8=; b=A8gt8S6WxMv22XMHo2a+tvnIHry92bt8mDd7QDA7qGj8Q16u3e2gy59EDQZ3HrEofKONkT stvReFYMoCKpHtmSSk7ktQPWPslEa6FbB4FexaRur866OV5lEg8+mEVF8+mXZB46ypG+uC FMdAQyMPtOE7AcqyU+EXoIg+MmsSbCY= 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-317-ZmooXrPtPsqU5Gw-hcQlzQ-1; Thu, 17 Nov 2022 09:33:11 -0500 X-MC-Unique: ZmooXrPtPsqU5Gw-hcQlzQ-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 906C1381495C; Thu, 17 Nov 2022 14:33:09 +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 15BD42166B29; Thu, 17 Nov 2022 14:33:05 +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 06/13] KVM: SVM: Add VNMI bit definition Date: Thu, 17 Nov 2022 16:32:35 +0200 Message-Id: <20221117143242.102721-7-mlevitsk@redhat.com> In-Reply-To: <20221117143242.102721-1-mlevitsk@redhat.com> References: <20221117143242.102721-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=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 From: Santosh Shukla VNMI exposes 3 capability bits (V_NMI, V_NMI_MASK, and V_NMI_ENABLE) to virtualize NMI and NMI_MASK, Those capability bits are part of VMCB::intr_ctrl - V_NMI(11) - Indicates whether a virtual NMI is pending in the guest. V_NMI_MASK(12) - Indicates whether virtual NMI is masked in the guest. V_NMI_ENABLE(26) - Enables the NMI virtualization feature for the guest. When Hypervisor wants to inject NMI, it will set V_NMI bit, Processor will clear the V_NMI bit and Set the V_NMI_MASK which means the Guest is handling NMI, After the guest handled the NMI, The processor will clear the V_NMI_MASK on the successful completion of IRET instruction Or if VMEXIT occurs while delivering the virtual NMI. To enable the VNMI capability, Hypervisor need to program V_NMI_ENABLE bit 1. Reviewed-by: Maxim Levitsky Signed-off-by: Santosh Shukla --- arch/x86/include/asm/svm.h | 7 +++++++ arch/x86/kvm/svm/svm.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 4352b46dd20c90..d8474e4b04ac05 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -198,6 +198,13 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define X2APIC_MODE_SHIFT 30 #define X2APIC_MODE_MASK (1 << X2APIC_MODE_SHIFT) +#define V_NMI_PENDING_SHIFT 11 +#define V_NMI_PENDING (1 << V_NMI_PENDING_SHIFT) +#define V_NMI_MASK_SHIFT 12 +#define V_NMI_MASK (1 << V_NMI_MASK_SHIFT) +#define V_NMI_ENABLE_SHIFT 26 +#define V_NMI_ENABLE (1 << V_NMI_ENABLE_SHIFT) + #define LBR_CTL_ENABLE_MASK BIT_ULL(0) #define VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK BIT_ULL(1) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 03acbe8ff34edb..08a7b2a0a29f3a 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -230,6 +230,8 @@ module_param(dump_invalid_vmcb, bool, 0644); bool intercept_smi = true; module_param(intercept_smi, bool, 0444); +bool vnmi = true; +module_param(vnmi, bool, 0444); static bool svm_gp_erratum_intercept = true; @@ -5029,6 +5031,10 @@ static __init int svm_hardware_setup(void) svm_x86_ops.vcpu_get_apicv_inhibit_reasons = NULL; } + vnmi = vnmi && boot_cpu_has(X86_FEATURE_AMD_VNMI); + if (vnmi) + pr_info("Virtual NMI enabled\n"); + if (vls) { if (!npt_enabled || !boot_cpu_has(X86_FEATURE_V_VMSAVE_VMLOAD) || -- 2.34.3