Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp166907iob; Mon, 2 May 2022 16:06:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYH1Ks52/IEHVl4qOXckhx5e/X70nL76bdz2kPIIk+xV/qi22XLFDk5EMWgJ1zLKOQvs9s X-Received: by 2002:a65:6051:0:b0:39d:1b00:e473 with SMTP id a17-20020a656051000000b0039d1b00e473mr11289388pgp.578.1651532799472; Mon, 02 May 2022 16:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651532799; cv=none; d=google.com; s=arc-20160816; b=uKCHXGJwQGMscun984jb0nbtw4Y/ic7Yx6NL3y6/2kPO1n9DuvUOHYrfMAk/2g7Mfp g7x3Dzwraq7CDx1/7I1u3TZIswzj1WASFQ2SlCF8cUsRdbcMMcJA6/gr/h76aVJF5UqE jtXTCw9twfxzC/SMuPbQ4hvcDJeojfIfKuycXzCuTMnOcDjyi8e3HkiSe6vMHO4G4KGW VyXenAZkwKA8Afads50qgysC3u9esDZFbL6iBEQxJ7HLLiUnEwzccXWdVyCc5DGC50dh 4jimrukNT/G701/7H8kw+zymI4UJiiqhH47IQ7Cjc10ZapJQoJB7CwGv1t5V+EVTRdqC 6Auw== 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; bh=M9dy8bCp86UEcRvYXfttZCk0rC9oluOZP3mSCEAMD1U=; b=Z261v+XVVeyt2T2Z37qhjl+JEVTPebX97nfF7vPXLmDNfbAl7LkQaHRMcSN5hMkJQQ v/JTqZB9iBEvRFl9qZdhtsoAVbNGJljiNuz3oAHnQCmy23xx4/Gj5KvibfQrxB5TlMo5 pbKLuRB6xYXUh6uG9MhJnPoerF/0BVnIlxii1q1CV/+BbBV+gppX3AvR64mAQWMUcOKm EMDTSSijxY+7E+3NBHJcJ2NiOLITA8rGq6WwV7PUnGkzJwyEUwFBr2aKXtF4cZamN2ke DFpCfcETCB3DyNCKZIYDcrl8xvpu21N2eFkO3xbpNVQI2/MWlCGft9CfpChHuuwIzDGj 1Y1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z7-20020aa79587000000b0050a49c21b85si14486241pfj.50.2022.05.02.16.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 16:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9B832B268; Mon, 2 May 2022 16:06:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377379AbiEAWM6 (ORCPT + 99 others); Sun, 1 May 2022 18:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377835AbiEAWMj (ORCPT ); Sun, 1 May 2022 18:12:39 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CD625EBED; Sun, 1 May 2022 15:08:53 -0700 (PDT) Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nlHkE-0008Pw-09; Mon, 02 May 2022 00:08:46 +0200 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Maxim Levitsky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/12] KVM: nSVM: Drop support for CPUs without NRIPS (NextRIP Save) support Date: Mon, 2 May 2022 00:07:36 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Sean Christopherson Drop nested support for CPUs without NRIPS, as requiring NRIPS simplifies a handful of paths in KVM. NRIPS was introduced in 2009, i.e. every AMD-based CPU released in the last decade should support NRIPS. Suggested-by: Paolo Bonzini Not-signed-off-by: Sean Christopherson [MSS: Just drop nested support for these CPUs instead of SVM support in general] Signed-off-by: Maciej S. Szmigiero --- arch/x86/kvm/svm/nested.c | 14 +++++--------- arch/x86/kvm/svm/svm.c | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 2cf92c12706a..e5c05e3427ae 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -691,14 +691,13 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, /* * next_rip is consumed on VMRUN as the return address pushed on the * stack for injected soft exceptions/interrupts. If nrips is exposed - * to L1, take it verbatim from vmcb12. If nrips is supported in - * hardware but not exposed to L1, stuff the actual L2 RIP to emulate - * what a nrips=0 CPU would do (L1 is responsible for advancing RIP - * prior to injecting the event). + * to L1, take it verbatim from vmcb12. If nrips is not exposed to L1, + * stuff the actual L2 RIP to emulate what an nrips=0 CPU would do (L1 + * is responsible for advancing RIP prior to injecting the event). */ if (svm->nrips_enabled) vmcb02->control.next_rip = svm->nested.ctl.next_rip; - else if (boot_cpu_has(X86_FEATURE_NRIPS)) + else vmcb02->control.next_rip = vmcb12_rip; svm->nmi_l1_to_l2 = is_evtinj_nmi(vmcb02->control.event_inj); @@ -706,10 +705,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, svm->soft_int_injected = true; svm->soft_int_csbase = svm->vmcb->save.cs.base; svm->soft_int_old_rip = vmcb12_rip; - if (svm->nrips_enabled) - svm->soft_int_next_rip = svm->nested.ctl.next_rip; - else - svm->soft_int_next_rip = vmcb12_rip; + svm->soft_int_next_rip = vmcb02->control.next_rip; } vmcb02->control.virt_ext = vmcb01->control.virt_ext & diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 88eacbbe9348..dc980fa0daa8 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4330,9 +4330,7 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu, break; } - /* TODO: Advertise NRIPS to guest hypervisor unconditionally */ - if (static_cpu_has(X86_FEATURE_NRIPS)) - vmcb->control.next_rip = info->next_rip; + vmcb->control.next_rip = info->next_rip; vmcb->control.exit_code = icpt_info.exit_code; vmexit = nested_svm_exit_handled(svm); @@ -4961,6 +4959,16 @@ static __init int svm_hardware_setup(void) pause_filter_thresh = 0; } + if (nrips) { + if (!boot_cpu_has(X86_FEATURE_NRIPS)) + nrips = false; + } + + if (!nrips && nested) { + pr_notice("kvm: Nested Virtualization requires NRIPS (NextRIP Save)\n"); + nested = false; + } + if (nested) { printk(KERN_INFO "kvm: Nested Virtualization enabled\n"); kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE); @@ -4995,11 +5003,6 @@ static __init int svm_hardware_setup(void) goto err; } - if (nrips) { - if (!boot_cpu_has(X86_FEATURE_NRIPS)) - nrips = false; - } - enable_apicv = avic = avic && npt_enabled && (boot_cpu_has(X86_FEATURE_AVIC) || force_avic); if (enable_apicv) {