From nobody Sun Apr 5 16:33:01 2026 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (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 048E9344025 for ; Fri, 20 Feb 2026 12:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591498; cv=none; b=SsU58QdHk+o7wfM/3JzfybDttqSgaaqPM8IeDqI85vscLSBSlE+yhtHLHadrPAP9B+a0bkurAMJEwDXAlsU4QerGCtGGXJ1Q2prEHXSUh5NrJ/F23UR3kSu0qB/9cjFmgPcy+KdhLbH2PNo04XExYhDuFNV00GDnjaeZcQA2ybw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771591498; c=relaxed/simple; bh=dbjZTnfZRabrqXMuDiYj7pgwuLM+EfqyVTQdUldYx7g=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LVQNxoB+5hgNSWLB2Hu5S5k/gJhwlh7K0deRBjsnO7xMfsPJjTdKCFytbU8x1gTfGuKBCg4NDDm4uwnPxmhxdCUES1878ogzT9ioDiwF1J+3ugiQLC3uM1OaH3kw9XF/jvVonxov501by3ViVIXGarZGIWwAO0YujzyTsald5w8= 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=mE4I9xV2; arc=none smtp.client-ip=185.70.43.22 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="mE4I9xV2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1771591494; x=1771850694; bh=4ljThCglF/lbdPGhFUHkatPf+49DQpPk0pS/0ohUeDc=; 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=mE4I9xV2KytWku1+AlNiDyIh5O/hmLLq6elukT/6EuUT65yqdJ2rI+pUHJclr/btk 9oCSmZzRE0doIgJym2GXyJw+vcHZbusu3tOlLoCkn7PWgoyumGdBsX7linKbm7r8GN Il8Sm0CRjFxbDtDVQH/Qt/JJBlws0LCWlw2gmwQ0TUeOivkunb5LdJWevi/Dg+wtCs m1kG0ZHMfOR1V/4XhjCvhAG0m2e071ewhmtV9GM5tAwhvh/J4R8iVqhszCVeiFyMVU ISOqvbWBLeJYHP5cp+muDOXKD7/dWs5K1J0FeDSQprXvvads656ZuXbKYAQCTynXUX viJKlGUEye6Ew== Date: Fri, 20 Feb 2026 12:44:53 +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 v6 3/3] x86/cpu: Do a sanity check on required feature bits Message-ID: <522f333abb9d66af9afcad7d3e1836dd33dc3046.1771590895.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: a72699783a20f32bbccad767051298b063d90c4d 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 44ae2f936395..f4d4a4c17106 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1988,6 +1988,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... */ @@ -2117,6 +2148,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