From nobody Wed Apr 8 04:48:38 2026 Received: from mail-244122.protonmail.ch (mail-244122.protonmail.ch [109.224.244.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23126292B2E for ; Tue, 10 Mar 2026 18:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165815; cv=none; b=mRZOZnyzUq4AcKPEvCNPXQKlM4VrGqplu73rvCupljGCBm5/jV7eB4oDTuOFijEY4J1ldN+nGYrUw1lKgpJOZQ6sTKWTkdj1N2dAvUJLBdeof4QZZIR487opkkjPWpQtKDzRMMrlYHmUFf837TAv0Lc7m6mwVx0YrQsL2+CBPCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165815; c=relaxed/simple; bh=q2MDgSUhNgUkJWl0OF4q99nNet2JDkWEWmxIE81LWTc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HRYXrxD7tfcg68gGGM2TQSSHQZHcYGD9fP25DfeA/Jq53PidUhKEhybGERCf/MKPCawIZuhxrsx56oDuoH2hcuqI+To1bENvGFJZCcMnFDjYntWnHyDdnRbrGsvJDDIjaYb4w8U690A2+p8scc9KwhnDj+r6vcmRBZNHaFvCyYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=mbSTgu4C; arc=none smtp.client-ip=109.224.244.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="mbSTgu4C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1773165811; x=1773425011; bh=4emI8WiqH2G2mud2Mslt0Qs3z6vaRupkYs24oZDMoGw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=mbSTgu4CCeHpmCq+hp4tRLLFbcr9/eauLcWt8hMt2aM5Dtuo39Edya2is8FTmRYPl BQmTGGpXSmt0aAFrkmVfcksNqdAXUDVd8mPeK2CZQY9TPuR8J25LCAYtaxzJIPzhOI yN65JYEXd2X7Exbh6iknHy6DgFznKasUAUCYlI+E2vWbL2twYQc51oZXDYYHGtBAoq wGjmwJA14RMFmram0Dg4jYQHu1Hm6Sz+pkhiZ81VihabsR2diwfP/GVXG97sN0Nmod W8dzsSMbwF/77A5t+HXMhJyNnAsju72qI32AguPl1Q1p/p9saA4J7O3YbGmsj2SQNR DHjfeKE8N8SFg== Date: Tue, 10 Mar 2026 18:03:28 +0000 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" From: Maciej Wieczor-Retman Cc: sohil.mehta@intel.com, m.wieczorretman@pm.me, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v9 3/3] x86/cpu: Do a sanity check on required feature bits Message-ID: <6e64ffe2aef6d87b0f43835b958566035f99865d.1773165421.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 700adce2e333f08aad844d40e41300b05085ccc1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman After CPU identification concludes, do a sanity check by comparing the final x86_capability bitmask with the pre-defined required feature bits. Signed-off-by: Maciej Wieczor-Retman Acked-by: H. Peter Anvin (Intel) --- Changelog v9: - REQUIRED_MASK_INITIALIZER -> REQUIRED_MASK_INIT - Redo the comments. - Fix reverse xmas order. - Inside for_each_set_bit: (void *) -> (unsigned long *). - 16 -> X86_CAP_BUF_SIZE. Changelog v6: - Add Peter's acked-by tag. - Rename patch subject to imperative form. - Add a char buffer to the x86_cap_name() call. arch/x86/kernel/cpu/common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index cfffbbda3d95..43ee2d55a708 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2003,6 +2003,34 @@ const char *x86_cap_name(unsigned int bit, char *buf) return buf; } =20 +/* + * As a sanity check compare the final x86_capability bitmask with the ini= tial + * predefined required feature bits. In case of a mismatch emit a warning = with + * all the missing feature names or X86_FEATURE_* numerals. + */ +static void verify_required_features(const struct cpuinfo_x86 *c) +{ + u32 missing[NCAPINTS] =3D REQUIRED_MASK_INIT; + char cap_buf[X86_CAP_BUF_SIZE]; + unsigned int i; + u32 error =3D 0; + + for (i =3D 0; i < NCAPINTS; i++) { + missing[i] &=3D ~c->x86_capability[i]; + error |=3D missing[i]; + } + + if (!error) + return; + + /* At least one required feature is missing */ + pr_warn("cpu %d: missing required feature(s):", c->cpu_index); + for_each_set_bit(i, (unsigned long *)missing, NCAPINTS << 5) + pr_cont(" %s", x86_cap_name(i, cap_buf)); + pr_cont("\n"); + add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); +} + /* * This does the hard work of actually picking apart the CPU stuff... */ @@ -2132,6 +2160,8 @@ static void identify_cpu(struct cpuinfo_x86 *c) mcheck_cpu_init(c); =20 numa_add_cpu(smp_processor_id()); + + verify_required_features(c); } =20 /* --=20 2.53.0