Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp308166rwi; Wed, 26 Oct 2022 00:52:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41KgrLcRnmBrRCRDLJ2PliS0eWnl3jBfi89XidT0KPTqgumpiCA7A8ZbsAn5vhjH/M1oCd X-Received: by 2002:a05:6402:5c9:b0:446:fb0:56bb with SMTP id n9-20020a05640205c900b004460fb056bbmr40481917edx.173.1666770727278; Wed, 26 Oct 2022 00:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666770727; cv=none; d=google.com; s=arc-20160816; b=bKfaAQ4xIVwMf6Oz24OKP4y/JB0ZweGtMBV9+DvxWHjo8r0TgDB3dPOSytLNsrnhvJ +8mOg39T+v0KGwfsZaoOFgdNvl4fq6fPLUBqqFMJN5yiphPmiJmcbnRt89Bho1uKBMMJ hFSk3loSMOrUK39PBLks2K9XwxaXbPLsTmiDFMp5dv5BALsXrTbAn9iQOyrJt5AQgxjj 1jGfbqrvmtX+lGxI59X3nRs5xg9dhTzuRbrb6zSD6dDsMr73TE6wBmTbTJExaNb+xLQ1 xNa+MXudm8SJFZD4CIkKHluQvV68Rhxi0oLTsmElf30MiNX05SW9SbNADw6GER3OzK+o wNhA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=/57zO14tKIKGiNB71iEufewLL5Xzf0HGWHVNOYYvEjw=; b=fuQPf5kig66qFmgPm6TiwYIcFjceLRwLqXcTqXArVXvAvcPtnQcvUCREtht9f+1gF9 lUKmxEg89aTpj6jUzRMbV13YzgzLPLXL38uoN1UTgb+U9ISlv8pZKYdsWAcmVNwOTbyQ Ti/O21n0Sa/WiJB9Ec+nvE9ORAvbqnvHgjaaaGz2keSMgDzUgLQ6vzVCQj7ktP4/lXLb Cl+1tMhUoysjTICLrKblR91KXyvdUgA9jxpswoSxWFp489ngiXz7ikPf3mieTMOQ/dDE TBFPCr2PnJyUKsHUG2DfwbBvOZCNGJgEr2q08wLttV0wa2C0L0OcBkb3qJX9kgfCyUiw dhlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XCcoAZug; 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 z15-20020a509e0f000000b00456964d3369si3924878ede.230.2022.10.26.00.51.41; Wed, 26 Oct 2022 00:52:07 -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=XCcoAZug; 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 S232966AbiJZHXx (ORCPT + 99 others); Wed, 26 Oct 2022 03:23:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232924AbiJZHXv (ORCPT ); Wed, 26 Oct 2022 03:23:51 -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 ESMTPS id 459EFAC393 for ; Wed, 26 Oct 2022 00:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666769030; 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; bh=/57zO14tKIKGiNB71iEufewLL5Xzf0HGWHVNOYYvEjw=; b=XCcoAZug2vieLz6h+70bbuFudRcm3uu9D32qV+Fhh30xxi6O/bXI0P27v/b6tX38CIgHEK ydn82OoeAn+gDzclPPWkhhpjf0jtfD9NhTYRYGBOwtckoy+uPpDO1Uab0oZHJehBo+ee/O 5n7LAedVM3XXAWjap+psJzKq2hJqY4s= 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-500-ZNgQvMONPnewK8x-4MJpNg-1; Wed, 26 Oct 2022 03:23:44 -0400 X-MC-Unique: ZNgQvMONPnewK8x-4MJpNg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43FDC185A7AF; Wed, 26 Oct 2022 07:23:37 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7BB9111F3B6; Wed, 26 Oct 2022 07:23:32 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Bandan Das , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito , stable@vger.kernel.org Subject: [PATCH v3] KVM: nVMX: Advertise ENCLS_EXITING to L1 iff SGX is fully supported Date: Wed, 26 Oct 2022 03:23:30 -0400 Message-Id: <20221026072330.2248336-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.6 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 Clear enable_sgx if ENCLS-exiting is not supported, i.e. if SGX cannot be virtualized. This fixes a bug where KVM would advertise ENCLS-exiting to L1 and propagate the control from vmcs12 to vmcs02 even if ENCLS-exiting isn't supported in secondary execution controls, e.g. because SGX isn't fully enabled, and thus induce an unexpected VM-Fail in L1. Not updating enable_sgx is responsible for a second bug: vmx_set_cpu_caps() doesn't clear the SGX bits when hardware support is unavailable. This is a much less problematic bug as it only pops up if SGX is soft-disabled (the case being handled by cpu_has_sgx()) or if SGX is supported for bare metal but not in the VMCS (will never happen when running on bare metal, but can theoertically happen when running in a VM). Last but not least, KVM should ideally have module params reflect KVM's actual configuration. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2127128 Fixes: 72add915fbd5 ("KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC") Cc: stable@vger.kernel.org Suggested-by: Sean Christopherson Suggested-by: Bandan Das Signed-off-by: Emanuele Giuseppe Esposito --- arch/x86/kvm/vmx/vmx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 9dba04b6b019..ea0c65d3c08a 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8263,6 +8263,11 @@ static __init int hardware_setup(void) if (!cpu_has_virtual_nmis()) enable_vnmi = 0; + #ifdef CONFIG_X86_SGX_KVM + if (!cpu_has_vmx_encls_vmexit()) + enable_sgx = false; + #endif + /* * set_apic_access_page_addr() is used to reload apic access * page upon invalidation. No need to do anything if not -- 2.31.1