Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp700669iog; Wed, 29 Jun 2022 08:30:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1th5ygWuUNfGtzCAcFVzHnYl5HTr4AzIowYMeRj53Q0xN1D0DL3Tp10caFsyrP/78xFEtkU X-Received: by 2002:a17:907:3e94:b0:726:3b46:ba20 with SMTP id hs20-20020a1709073e9400b007263b46ba20mr3880029ejc.314.1656516631672; Wed, 29 Jun 2022 08:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656516631; cv=none; d=google.com; s=arc-20160816; b=f4Xb5sTAzTQDfhMYohq5Y5Qoh7MgUSV/Og48XLzQNT1/yz+0adXSsoTTP90DCb3o/V f51kBoMViaaQ6hW6JMJCqInhSNbJKFbP11/qvBZ0eSodgJnsaTNsZTxNlI01CKmXI4iL 1eKxY6hSFXblNxYpwiGOMdH90xRKyx43v78/WQuUkg/B022wSna75c2GV2AYQJZN/a7D DZKpD3BfBkyHBJBTcH3UgSrXG9bKk1UnYSlt9AQWb9t3WXcF4itxlWtZ+WmC+jMWAiaQ Wpk2cS8l+j6J9qJkonFQ5gOxVRG9HiGd8d5WTOYlmBNOSJMp7gqhLx3TvNi+hpvwV7GG WJaQ== 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=WQgwHNQVbY9iueFvIs1j6B0uxKz2W6rluANlmHKqrqk=; b=uT8X29/rq4hJvhwqPwXwnMJJPqZu8IowTL2/evWttb7Y9DKoUQNopNSpfj2aZPvUmS Rajg4KaxRMP2ih0+pYHjhlOgqE5SZc2+c8esOS7hH1rc8cr+iKJlhJ9URgp7m+7EDATP 6FfpnjXBV+2nHQuXmLBDAElC/ZkMxgA7moWJZRdz/GARWubrlR/DyyvdGPK0RZiCsRKJ tvd8Wr9ZdEfIZW04tqQpG0pL9aqPwbPIQHkMc1uqiPtzn68E0Qc7absM2zDbe+PHPBpE gfdjFZwK0t0fo6x+KYuHr+0qEFh+g1fVb+fdsqrYssYQFdLg15gySgNvagMhyAx9S1kZ q6EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wy24IeGg; 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 e7-20020a170906748700b006feb0e0856dsi16954047ejl.653.2022.06.29.08.30.05; Wed, 29 Jun 2022 08:30:31 -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=Wy24IeGg; 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 S234085AbiF2PII (ORCPT + 99 others); Wed, 29 Jun 2022 11:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233935AbiF2PHL (ORCPT ); Wed, 29 Jun 2022 11:07:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFCBE2CC9B for ; Wed, 29 Jun 2022 08:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656515230; 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=WQgwHNQVbY9iueFvIs1j6B0uxKz2W6rluANlmHKqrqk=; b=Wy24IeGg9BvV54JA4hL4iHNPR8yFZPWpeWACAQVLzQ914gLDHcRFEomUDMUpiqzkLKoMf4 R11MoMip0E1cx6E95M7TQYYXAmF3AvCyH8IOz9hHyLuar8kyQ9V8Q3UC8nvU7dInXtUK9S /oEkBpb0nMd6KgDbfZpucnjk5dqRJ/8= 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-403-ahpxlXC4Pc27GNKa6cmIOQ-1; Wed, 29 Jun 2022 11:07:06 -0400 X-MC-Unique: ahpxlXC4Pc27GNKa6cmIOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B879101A586; Wed, 29 Jun 2022 15:07:06 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id E650340EC004; Wed, 29 Jun 2022 15:07:03 +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 v2 16/28] KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING in setup_vmcs_config() Date: Wed, 29 Jun 2022 17:06:13 +0200 Message-Id: <20220629150625.238286-17-vkuznets@redhat.com> In-Reply-To: <20220629150625.238286-1-vkuznets@redhat.com> References: <20220629150625.238286-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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. 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 89a3bbafa5af..e32d91006b80 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