Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp559998imw; Fri, 8 Jul 2022 07:44:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uMb3C+6Hpcnoqq1oOUugQckk4dxMNICFHlhsUM8iOtLUx9NfAMgIq21rQI0w40AKTvc1IM X-Received: by 2002:a17:90b:1a88:b0:1ed:5a12:514b with SMTP id ng8-20020a17090b1a8800b001ed5a12514bmr187349pjb.49.1657291492416; Fri, 08 Jul 2022 07:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657291492; cv=none; d=google.com; s=arc-20160816; b=qQyG9EZGaVUHel6dbEzbswgTrvc7/qDz1pfAiDN15lOCKm9cCOIVMqvjL3msJVQHP7 BAvQEeSkGVyNv2ErnV5MbiniMBCL89i21REs6A9vztY2gGsd+3MMle6tdp8JlI9lrt8k CuvlLIT9Qk+UEWPOHSvtRHTgVXUwtTyfXyTnwmR4jRf2VadKm+/FwOSP7e5H4CrN4Cmc J6trc9CqZVT3dEyep4TXrAbrFUThrY143EZmDvS9g/OZ5TYq6dvRv5OCqSnZQFR4V9lY sonq5oUVAHb8va7EKGRtIokF56wbSKDpy+Ik/UF6yEonZhTJNHMsokxN/tN87TutKnEf A+7Q== 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=TP/AeZ70XeQTaeg//+k2+x5hfxrTq7s1zZSJYlkHTrY=; b=V9qEbcttF+HWvN0gtdzZjtf4KjdhgbEPuZv/h53HTp8xqk3Hin98rQ/uXJ6WvmEgjg iwYnJXSywrI7cCEO855PBHdsaWRZQ4qBKaEQ3kW4Dq/76pHE5lfrMHCcQdcuHkaNJxPM kujz0BrjBoLwvae/4WesI83LI/gTBknmPIovNVSsRsbHXK8Rhac5sz/Ao4Gipxi1+oDi HRaSwCfS4Omv1LVmlWd3cSrZWR2Kf04m44aNvnSelStDujkU9rUdEPH55HjhOmwf+DDj d0utUk7o4g+uSuRUs4HpDhqKBzg7O4RtoUY+cjfuv26tBFkOoStaxLziuDyRVHqerr1S GyXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cCBIA7AH; 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 s144-20020a632c96000000b0041160e45f31si4450561pgs.97.2022.07.08.07.44.30; Fri, 08 Jul 2022 07:44:52 -0700 (PDT) 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=cCBIA7AH; 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 S238585AbiGHOnk (ORCPT + 99 others); Fri, 8 Jul 2022 10:43:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238464AbiGHOnO (ORCPT ); Fri, 8 Jul 2022 10:43:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AFD735A466 for ; Fri, 8 Jul 2022 07:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657291392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TP/AeZ70XeQTaeg//+k2+x5hfxrTq7s1zZSJYlkHTrY=; b=cCBIA7AH/0Gmy+g65jnDD7rTTdhGIuh0s9tkXnwg9gDjIS062voa+RNzzlWfQtxuMbRRAx pA8JhdYuSIRnNUc5eT7BFm4qII+TkDSBXwDvf0H2w5aca044uxhFhEaEQP1qb/nFCitdPd PWpgpdPUbh4vpfgCApxCH6FUjUsBaCA= 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-620-H6m9I0JUOxezqOPT9XDDFw-1; Fri, 08 Jul 2022 10:43:01 -0400 X-MC-Unique: H6m9I0JUOxezqOPT9XDDFw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 507A5805B98; Fri, 8 Jul 2022 14:43:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.193.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ECA4492C3B; Fri, 8 Jul 2022 14:42:58 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Anirudh Rayabharam , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 14/25] KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING in setup_vmcs_config() Date: Fri, 8 Jul 2022 16:42:12 +0200 Message-Id: <20220708144223.610080-15-vkuznets@redhat.com> In-Reply-To: <20220708144223.610080-1-vkuznets@redhat.com> References: <20220708144223.610080-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 SECONDARY_EXEC_ENCLS_EXITING is conditionally added to the 'optional' checklist in setup_vmcs_config() but there's little value in doing so. First, as the control is optional, we can always check for its presence, no harm done. Second, the only real value cpu_has_sgx() check gives is that on the CPUs which support SECONDARY_EXEC_ENCLS_EXITING but don't support SGX, the control is not getting enabled. It's highly unlikely such CPUs exist but it's possible that some hypervisors expose broken vCPU models. Preserve cpu_has_sgx() check but filter the result of adjust_vmx_controls() instead of the input. Reviewed-by: Jim Mattson Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index ce54f13d8da1..566be73c6509 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2528,9 +2528,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, SECONDARY_EXEC_PT_CONCEAL_VMX | SECONDARY_EXEC_ENABLE_VMFUNC | SECONDARY_EXEC_BUS_LOCK_DETECTION | - SECONDARY_EXEC_NOTIFY_VM_EXITING; - if (cpu_has_sgx()) - opt2 |= SECONDARY_EXEC_ENCLS_EXITING; + SECONDARY_EXEC_NOTIFY_VM_EXITING | + SECONDARY_EXEC_ENCLS_EXITING; + if (adjust_vmx_controls(min2, opt2, MSR_IA32_VMX_PROCBASED_CTLS2, &_cpu_based_2nd_exec_control) < 0) @@ -2577,6 +2577,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmx_cap->vpid = 0; } + if (!cpu_has_sgx()) + _cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING; + if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_TERTIARY_CONTROLS) { u64 opt3 = TERTIARY_EXEC_IPI_VIRT; -- 2.35.3