From patchwork Wed Jun 22 14:48:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 583965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C447C433EF for ; Wed, 22 Jun 2022 14:48:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357193AbiFVOsw (ORCPT ); Wed, 22 Jun 2022 10:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357336AbiFVOsu (ORCPT ); Wed, 22 Jun 2022 10:48:50 -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 22AB93BFBD for ; Wed, 22 Jun 2022 07:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655909329; 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; bh=BfzGA2BfgEmm4tcaB5rbMih4mJIyv5Ggi+5ejPnvGzs=; b=dce/0J5FNyVc+yIPOMNPhr7hriBEP8Py+Z4ktIbsJLZV6oGXn1VsZEt2hNXqr2lbsP6UCg 3CVlfTMmn3nMAzLLlBHr+BFIVpK69l59dhrcvmlyGHkdXugGOTceXJHSpO+UGzcSIZ16Hl eRXx2/5IlcnLO6abspZ1P96VU1026QU= 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-474-N2RvB7y5NLeqzs-ommWDCA-1; Wed, 22 Jun 2022 10:48:46 -0400 X-MC-Unique: N2RvB7y5NLeqzs-ommWDCA-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 6AE6418A6534; Wed, 22 Jun 2022 14:48:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1365A40E80E1; Wed, 22 Jun 2022 14:48:21 +0000 (UTC) From: Maxim Levitsky To: linux-kernel@vger.kernel.org Cc: "Chang S. Bae" , Jiri Olsa , linux-perf-users@vger.kernel.org, Peter Zijlstra , "H. Peter Anvin" , "David S. Miller" , Borislav Petkov , Kees Cook , Mark Rutland , Alexander Shishkin , Namhyung Kim , Tim Chen , Maxim Levitsky , Pawan Gupta , Herbert Xu , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Jane Malalane , Tony Luck , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , linux-crypto@vger.kernel.org (open list:CRYPTO API), Paolo Bonzini Subject: [PATCH 0/4] x86: cpuid: improve support for broken CPUID configurations Date: Wed, 22 Jun 2022 17:48:16 +0300 Message-Id: <20220622144820.751402-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch series aims to harden the cpuid code against the case when the hypervisor exposes a broken CPUID configuration to the guest, in the form of having a feature disabled but not features that depend on it. This is the more generic way to fix kernel panic in aes-ni kernel driver, which was triggered by CPUID configuration in which AVX is disabled but not AVX2. https://lore.kernel.org/all/20211103145231.GA4485@gondor.apana.org.au/T/ This was tested by booting a guest with AVX disabled and not AVX2, and observing that both a warning is now printed in dmesg, and that avx2 is gone from /proc/cpuinfo. Best regards, Maxim Levitsky Maxim Levitsky (4): perf/x86/intel/lbr: use setup_clear_cpu_cap instead of clear_cpu_cap x86/cpuid: refactor setup_clear_cpu_cap/clear_feature x86/cpuid: move filter_cpuid_features to cpuid-deps.c x86/cpuid: check for dependencies violations in CPUID and attempt to fix them arch/x86/events/intel/lbr.c | 2 +- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/common.c | 50 +----------------- arch/x86/kernel/cpu/cpuid-deps.c | 84 +++++++++++++++++++++++++++---- 4 files changed, 78 insertions(+), 59 deletions(-) Reviewed-by: Kan Liang