From patchwork Sat Dec 3 00:37:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 2563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1142526wrr; Fri, 2 Dec 2022 16:41:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf7edLvsFxi1WcRjxG+B3s5y/V/BfhNdxwasL+nWmDtVigJlsOuFp/6Wln7XhXuDYxcoHOfP X-Received: by 2002:a17:907:a093:b0:7bc:876b:4c6d with SMTP id hu19-20020a170907a09300b007bc876b4c6dmr32612525ejc.338.1670028074414; Fri, 02 Dec 2022 16:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670028074; cv=none; d=google.com; s=arc-20160816; b=dwMTLQ29RyiWERczGcq26Uelkt+3pelT5BpNv5PH9ngKehriJWwl6sS4OYY1VyvIKw EFX0FmQ8jtQ48az8eh3/vEOGHAj4vmxfh/Ql+bbZ6B6TmYpc0GCWGsMB3rb+qt3nryCb 7m82c8FEbIWWbLfGRJZqGWdi7qKY6kh6ndi1lQf1TywvcQMn9J5Jxd2uSux+6OR6qHY0 hueJx8FqhKgVc+u4W2gOgH0YV2l37s1EfzU7oBZIhnTZHHkTtpjUG79KbQFQWWnWlYG0 xVNgAZn31S/4f8NaKl6oWhBkwQ9c/lvkLGDrMD9oEfsO+o5K7f4QBItTIyLA8pvKyo0C pjGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=5cHO8TZ/NgQcG2/A3zvYgffqJLlGYe3zpPYcN2k37Z8=; b=F0kYdrEVWa5+mCel+pLfJntA82/9UmZV3IVVt+RV4ty7HQe6uw1C5mDz2sCzvppLKG eawNatjOCnjncuLAmctS5/nONw790qmRRpBrYkqS0vRv/UpzV+7gn7nVAk44oS2iqxE+ ylZpTWxgWNcGzBJOJuzO+EHGHw15evyLj3xPWrRRUS2YO6iwztwWlB6/RbBjdkm0XHuh C6rlag3cXRHMC3w/LsMydDrvzQiy4k2RhpElIYMrEyQ9o/4EYxGPA7/oiFCYL9W59FBu I3Oo+jBXrr+izKZrKerUOlXHeGjIiIcA/Kan+65mZeqjo3PuY9uy1Xk/fHR6XIeHSlgK tWpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=pJ5S5cEu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l25-20020a170906231900b0078dcfe6a000si5517712eja.727.2022.12.02.16.40.49; Fri, 02 Dec 2022 16:41:14 -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=@google.com header.s=20210112 header.b=pJ5S5cEu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235131AbiLCAkX (ORCPT + 99 others); Fri, 2 Dec 2022 19:40:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234955AbiLCAkE (ORCPT ); Fri, 2 Dec 2022 19:40:04 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 566A41E702 for ; Fri, 2 Dec 2022 16:37:49 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id o8-20020a170902d4c800b001898ea5e030so8022267plg.13 for ; Fri, 02 Dec 2022 16:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=5cHO8TZ/NgQcG2/A3zvYgffqJLlGYe3zpPYcN2k37Z8=; b=pJ5S5cEuTvr85SuayQOIMCDdKWDVpy5OfbTE8O7P7h6XgCY255xnijRFmkiZ6EEcfK 0lvECxqT6/3GkdRxF/jHKq5xohT1ObE6VE0Eibrb61uGMu6SUgQDwJD5BuPCdzjGOn9q w8WhVgihJlIX8q2tXFA/U3boujzOhTlnSt7t24WoG1kH8y5WTsMub2143mrSyJaF1X6l mC5lwHiuvETDepkPUjzzNhWRnRMTvjaZGwHXXtOJReduP/6a2VVdSn9f2Ujf2Bk4ahPE Yy2xn+kT64NeaqpZCY6OxKsq6xl3GXNm/57OWtp2FfrcJS4USF+4PvWMehUxpEoBYyFU UI0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5cHO8TZ/NgQcG2/A3zvYgffqJLlGYe3zpPYcN2k37Z8=; b=xQeu1zJSE1VNcz00gGtAvUws/bMC5kIPy3xxVOIxu8GWnGM23n1gXt1eU60h6N5Hhz DkvPzQtlNOUdGWLv/T4sW7bwdabjToKAx2RJoIYqj+fDJhUYGBj+IAcoAgTFvU+Q7ZiW gl3NqTLMImfUbOInOFIzchjCyhEnm9LWgwrWu5CKaXjMPlgAGpokVxQti2X+tFxOc7W4 PRpzDn2UtoxxwFk8cQGpOl3s9/6fowAVHEhwUdMqXGeq/xDhkgvaEyMikdwNJ0KdcLkx etuWl8/TyFepmGIRaxNEAER5XKFfG1FB/x5o2100+oxOdKbfl9KitfNTJ0QCInO9AbA9 1R6A== X-Gm-Message-State: ANoB5pkypEU282zX7twDeAO1akr/VwvSJhxKBuFBy9ZEJiB9jNpq8zbQ FeJk0/C8x8qbUQOZe/V0n0biJY+GIc4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:4946:0:b0:477:7c87:1087 with SMTP id y6-20020a634946000000b004777c871087mr52392327pgk.452.1670027868906; Fri, 02 Dec 2022 16:37:48 -0800 (PST) Reply-To: Sean Christopherson Date: Sat, 3 Dec 2022 00:37:42 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221203003745.1475584-1-seanjc@google.com> Subject: [PATCH 0/3] x86/cpu: KVM: Make SGX and VMX depend on FEAT_CTL From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751151358064152835?= X-GMAIL-MSGID: =?utf-8?q?1751151358064152835?= "Officially" make SGX and VMX depend on X86_FEATURE_MSR_IA32_FEAT_CTL, and drop manual checks on X86_FEATURE_MSR_IA32_FEAT_CTL when querying VMX support. To make dependencies on MSR_IA32_FEAT_CTL work as expected, process all CPUID dependencies at the end of CPU indentification. Because MSR_IA32_FEAT_CTL is a synthetic flag, it is effectively off-by-default, and thus may never be unset via clear_cpu_cap(), i.e. never triggers processing of its dependents. The obvious alternative would be to explicitly clear MSR_IA32_FEAT_CTL if the MSR is unsupported, but that ends up being rather ugly as it would require clearing the flag in default_init() to handle the scenario where hardware supports the MSR, but the kernel was built without support for the CPU vendor. E.g. running on an Intel CPU with CPU_SUP_INTEL=n. This edge case is also why the existing manual checks in KVM are necessary; KVM_INTEL effectively depends on any of CPU_SUP_{INTEL,CENATUR,ZHAOXIN}. Processing all dependencies also seems like the correct thing to do across the board, e.g. if the kernel ends up with more synthetic features with dependents. The placement of the call to apply_cpuid_deps() isn't super scientific. I placed it after, AFAICT, the overwhelming majority of cpu cap updates had already been done, but before anything was likely to want the dependencies to be processed. Specifically, I couldn't find any set_cpu_caps() in the machine check code, but there are definitely cpu_has() calls under mcheck_cpu_init(). Last thought, patch 3 will conflict with at least one in-flight KVM series[*]. The conflict should be straightfoward to resolve, but at the same time this is far from urgent, i.e. kicking this series down the road until KVM settles down is totally ok. [*] https://lore.kernel.org/all/20221130230934.1014142-1-seanjc@google.com Sean Christopherson (3): x86/cpu: Process all CPUID dependencies after identifying CPU info x86/cpu: Mark SGX and VMX as being dependent on MSR_IA32_FEAT_CTL KVM: VMX: Drop manual checks on X86_FEATURE_MSR_IA32_FEAT_CTL arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/bugs.c | 3 +-- arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kernel/cpu/cpuid-deps.c | 12 ++++++++++++ arch/x86/kernel/cpu/feat_ctl.c | 3 +-- arch/x86/kvm/vmx/vmx.c | 6 ++---- 6 files changed, 23 insertions(+), 8 deletions(-) base-commit: d800169041c0e035160c8b81f30d4b7e8f8ef777