From nobody Thu Apr 9 15:01:22 2026 Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) (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 6DEC5430BB1 for ; Mon, 2 Mar 2026 15:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.29 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772465135; cv=none; b=aWYRd+73CD40jAKOBzwKPX1jEVvfsa3vjOoaWeEz+AFTYdDeIKfhdTWdKrI+RZdwTvTZYBbw5QdqMmyUwHm146tMxNL90+oMDpVkhjMo/DNtCTl1OTxZO38x36BmDqcdfE+u3irf6lxAlpZihOA4s9l65xDcTyc+ViGUNnTcIFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772465135; c=relaxed/simple; bh=W/jXrBgIO9+EboueK2sOIcsEv6y1c6w1EYf424tdK4E=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FZ2eFolDQVlaA9GbTn373pxuXqNC0jNSi2bERNJYGO70GOWxm+bYL7qLBqFkw13OZFKFYwiw07xiCvw/tFSoSRkVBhj+cKZOPiK9zlKubOp9C7fXhlFL2/nJU17yCMlygvYroshQ7xDJVQ50fRgGxM/W3lYXFdG3FHxDjiJxIOg= 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=pZwiJQpU; arc=none smtp.client-ip=79.135.106.29 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="pZwiJQpU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1772465126; x=1772724326; bh=lZYJLJYJy9Abdfa0vHX46yngB70wL0ZLZDP7LSihGeA=; 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=pZwiJQpUwk3EzP3H0JVrTi0UG/Iz+PKGe9ea5fLgKtsW0BFIR2a+MVBJXQ512kWy+ 9Yqns4aB5lKVHh0W6ytsfKK78tJGFhxFMWnoN6rCZn6Cb99t0WO8wVs6Or0kpNsTEN FIgwvMFGh5i5C+US//GAS5Mfr/EEFieTkBi0XPq/7st7AUG2CHL/LOTah9ltx3pzN7 TTPnbTLsPtRZg1YtbnHuCq18Gr/vFUXYzv8OHm9pEjaLPLMk9Y9HLx306BN2cE9SoH Vw/yCpEzohxLBDmRCpqHY7kdI/wUzmE4xIliQTx5cQ8hsM/Ponkby1HG+nWHf5uI4n tu5qv5qmEnlBw== Date: Mon, 02 Mar 2026 15:25:23 +0000 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v8 3/3] x86/cpu: Do a sanity check on required feature bits Message-ID: <39306e7e736f76530db62302f1dfa3b94a479861.1772453012.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: cd6dcacf73621a479d64e10bafa30f0c190daa1a 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 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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b60269174d95..cecbd0b95a15 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1996,6 +1996,37 @@ 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 + * the faulty bitmask value. + */ +static void verify_required_features(const struct cpuinfo_x86 *c) +{ + u32 missing[NCAPINTS] =3D REQUIRED_MASK_INITIALIZER; + char cap_buf[16]; + u32 error =3D 0; + unsigned int i; + + for (i =3D 0; i < NCAPINTS; i++) { + missing[i] &=3D ~c->x86_capability[i]; + error |=3D missing[i]; + } + + if (!error) + return; /* All good */ + + /* + * At least one required feature is missing. Print a warning, + * and taint the kernel. + */ + pr_warn("cpu %d: missing required feature(s):", c->cpu_index); + for_each_set_bit(i, (void *)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... */ @@ -2125,6 +2156,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