Message ID | 20221117143242.102721-7-mlevitsk@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp433724wrr; Thu, 17 Nov 2022 06:36:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UvLOr3zWqqbKx1GTvdw9z2QHcrcB2WKMRqeUjvt7/l1cUyndMlQZ1D/vt6SNq46gdnW77 X-Received: by 2002:a17:902:d38c:b0:186:8c19:d436 with SMTP id e12-20020a170902d38c00b001868c19d436mr3039483pld.96.1668695771479; Thu, 17 Nov 2022 06:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668695771; cv=none; d=google.com; s=arc-20160816; b=TBS8XqAT+cbZCG14KqBrkcBYK1H6E2DdBwSB7aCiUmApb+WaCX7ewHjXInkM4aCVjM H1mpNXybu8xcZMOTtcM5Ml8WoCkWYt2t/2+e4/+RUy5cH/Luj2Zy0MIn/pLq17dggqla zAaPjHmujwN7/ZomMGswLTUIzGTwfmTegKXCH+lrGw+qDI4mbHiW4CGw8DjjFRT+45EX oFt320cxRXvdM5RQMFIYayqmFmZas84jQQMXr7NyVt65S/Yjyo3fENU0nONMH9kWFTRA JExY21OlG/cSRg3OwyI73XyJJs49A8obIPV8RpZeSkjzafKTpaqwUyxKP2Cogaewoy19 eqhA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a63d54e000000b0046fb44b3525si1096023pgi.115.2022.11.17.06.35.57; Thu, 17 Nov 2022 06:36:11 -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 <rfc822;a1648639935@gmail.com> + 99 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <mlevitsk@redhat.com> To: kvm@vger.kernel.org Cc: Paolo Bonzini <pbonzini@redhat.com>, Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>, Dave Hansen <dave.hansen@linux.intel.com>, linux-kernel@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Sandipan Das <sandipan.das@amd.com>, Daniel Sneddon <daniel.sneddon@linux.intel.com>, Jing Liu <jing2.liu@intel.com>, Josh Poimboeuf <jpoimboe@kernel.org>, Wyes Karny <wyes.karny@amd.com>, Borislav Petkov <bp@alien8.de>, Babu Moger <babu.moger@amd.com>, Pawan Gupta <pawan.kumar.gupta@linux.intel.com>, Sean Christopherson <seanjc@google.com>, Jim Mattson <jmattson@google.com>, x86@kernel.org, Maxim Levitsky <mlevitsk@redhat.com>, Santosh Shukla <santosh.shukla@amd.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749754337057969091?= X-GMAIL-MSGID: =?utf-8?q?1749754337057969091?= |
Series |
SVM: vNMI (with my fixes)
|
|
Commit Message
Maxim Levitsky
Nov. 17, 2022, 2:32 p.m. UTC
From: Santosh Shukla <santosh.shukla@amd.com> 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 <mlevitsk@redhat.com> Signed-off-by: Santosh Shukla <santosh.shukla@amd.com> --- arch/x86/include/asm/svm.h | 7 +++++++ arch/x86/kvm/svm/svm.c | 6 ++++++ 2 files changed, 13 insertions(+)
Comments
On Thu, Nov 17, 2022 at 04:32:35PM +0200, Maxim Levitsky wrote: > @@ -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); s/boot_cpu_has/cpu_feature_enabled/
On Thu, Nov 17, 2022, Borislav Petkov wrote: > On Thu, Nov 17, 2022 at 04:32:35PM +0200, Maxim Levitsky wrote: > > @@ -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); > > s/boot_cpu_has/cpu_feature_enabled/ Why? This is rarely run code, won't cpu_feature_enabled() unnecessarily require patching? And while we're on the topic... https://lore.kernel.org/all/Y22IzA9DN%2FxYWgWN@google.com
On Thu, Nov 17, 2022 at 04:42:57PM +0000, Sean Christopherson wrote: > Why? This is rarely run code, won't cpu_feature_enabled() > unnecessarily require patching? Because we want one single interface to test X86_FEATURE flags. And there's no need for the users to know whether it wants patching or not - we simply patch *everywhere* and that's it. > And while we're on the topic... https://lore.kernel.org/all/Y22IzA9DN%2FxYWgWN@google.com Because static_ or boot_ is not relevant to the user - all she wants to know is whether a cpu feature has been enabled. Thus cpu_feature_enabled(). And yes, at the time I protested a little about unnecessary patching. And tglx said "Why not?". And I had no good answer to that. So we can just as well patch *everywhere*. And patching is soo not a big deal anymore considering all the other things we do to kernel code at build time and runtime. objdump output compared to what's actually running has in some cases no resemblance whatsoever. Thx.
On Thu, Nov 17, 2022, Maxim Levitsky wrote: > 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; This can be __ro_after_init, e.g. see https://lore.kernel.org/all/20221110013003.1421895-4-seanjc@google.com > +module_param(vnmi, bool, 0444); The exposure of "vnmi" to userspace belongs in the last patch. E.g. this patch should only stub in vnmi: bool __ro_after_init vnmi; and then the last patch that actually enables it can default it to true and expose the param to users. It obviously doesn't matter in the end, but it technically makes this series broken, e.g. nested_sync_int_ctl_from_vmcb02() pivots on "vnmi" without the extra V_NMI_ENABLE check, and advertising the vnmi is enabled when it actually isn't is wrong/misleading.
On Thu, Nov 17, 2022, Borislav Petkov wrote: > On Thu, Nov 17, 2022 at 04:42:57PM +0000, Sean Christopherson wrote: > > Why? This is rarely run code, won't cpu_feature_enabled() > > unnecessarily require patching? > > Because we want one single interface to test X86_FEATURE flags. And > there's no need for the users to know whether it wants patching or not - > we simply patch *everywhere* and that's it. > > > And while we're on the topic... https://lore.kernel.org/all/Y22IzA9DN%2FxYWgWN@google.com > > Because static_ or boot_ is not relevant to the user - all she > wants to know is whether a cpu feature has been enabled. Thus > cpu_feature_enabled(). > > And yes, at the time I protested a little about unnecessary patching. > And tglx said "Why not?". And I had no good answer to that. So we can > just as well patch *everywhere*. Ah, I missed that memo. Paolo, Since it sounds like static_cpu_has() is going the way of the dodo, and ditto for boot_cpu_has() except for flows that don't play nice with patching (none of which are in KVM), should we do a KVM-wide conversion to cpu_feature_enabled() at some point in the near future?
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) ||