From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-106118.protonmail.ch (mail-106118.protonmail.ch [79.135.106.118]) (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 20D2233F8CA for ; Sat, 21 Mar 2026 05:58:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774072717; cv=none; b=ubIAij30ARC+j8bwdd2HiAVsT0a6tLzRuUSWzAqp1vFZ/DNFI/WKpxwxH9/8w7w0vInn550dEXg3C0Zo3WQDsBAQu1/qRQCxVfzugrG+OQkqeQ8GYzi0IiOYqsIv2sDw5YviVtl7DdxvR/TPggRD5TiwW8ZJ9UyN7bKMTqAQrAI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774072717; c=relaxed/simple; bh=CZG7KW2tZin3Lfnt+7IM3D3cs71uR43wWtEVqZcNSyY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fuNgWM3NUIcqYKOzV+P2Icb3nYfWNy4N5YQgb5gR3fCutbuz5tWUyQeG48OIXeqWObvfYLw7fCcngQkjufaz7QfXpAe6+tm8hQtrYJLiHK1NBdDdKduMA0glT8ur/pr5P84g1LltVsLXPmaYQVBfJ+lEd1yvP0BUN9eCsXdAEuo= 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=VHPUj67h; arc=none smtp.client-ip=79.135.106.118 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="VHPUj67h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1774072705; x=1774331905; bh=tlkCr7403v4PWDOz1tTboWPQFw81z355xrHzotw90pg=; 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=VHPUj67hvCymAZ/4WzHRNgvZ9c9kNM0RthUydhnnBdiNuIuGi+dpVPKvgbbOKxgFf KzLPjffEopwXcXG8oOUzzZaVC4/2JZLO9CGmK0jeduuNBwM6sLkuI1cXAfA1oCw2tn 4AuBmNka2cwP+mJ4LUzKdUeManf/qYhg7u3F+scWV21PdUobZEp/Ql4nRkw3ai7Wwz z2Mi9yILm19utSvCf+DIO5Y8UYwddYmlxieSbJmHcBBYTj+XUNlrDBpY9N58MPTCrw 8tySubtN1PFE2inWvd7id2ogBB0ZO5UqXQqtC3iBS+sk01y0qxb9vqkFrSmPvwRACT eat3eaem/wEjw== Date: Sat, 21 Mar 2026 05:58:18 +0000 To: Pawan Gupta From: =?utf-8?Q?Maciej_Wiecz=C3=B3r-Retman?= Cc: tglx@kernel.org, peterz@infradead.org, xin@zytor.com, maciej.wieczor-retman@intel.com, babu.moger@amd.com, chang.seok.bae@intel.com, sohil.mehta@intel.com, dave.hansen@linux.intel.com, jpoimboe@kernel.org, elena.reshetova@intel.com, hpa@zytor.com, ak@linux.intel.com, darwi@linutronix.de, bp@alien8.de, mingo@redhat.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v11 3/4] x86/cpu: Do a sanity check on required feature bits Message-ID: In-Reply-To: <20260321003015.4i7wrqmaunbljguw@desk> References: <7312c9f2feab8aea4612ed9a1841e8c22f5f69b1.1774008873.git.m.wieczorretman@pm.me> <20260321003015.4i7wrqmaunbljguw@desk> Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 859e0312afe4f1656fbb00a730d0c1a0b8c42bd0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2026-03-20 at 17:31:27 -0700, Pawan Gupta wrote: >On Fri, Mar 20, 2026 at 12:50:25PM +0000, Maciej Wieczor-Retman wrote: >... >> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c >> index 0e318f3d56cb..92159a0963c8 100644 >> --- a/arch/x86/kernel/cpu/common.c >> +++ b/arch/x86/kernel/cpu/common.c >> @@ -2005,6 +2005,38 @@ const char *x86_cap_name(unsigned int bit, char *= buf) >> =09return buf; >> } >> >> +/* >> + * As a sanity check compare the final x86_capability bitmask with the = initial >> + * predefined required feature bits. >> + */ >> +static void verify_required_features(const struct cpuinfo_x86 *c) >> +{ >> +=09u32 required_features[NCAPINTS] =3D REQUIRED_MASK_INIT; >> +=09DECLARE_BITMAP(missing, NCAPINTS * 32); >> +=09char cap_buf[X86_CAP_BUF_SIZE]; >> +=09u32 *missing_u32; >> +=09unsigned int i; >> +=09u32 error =3D 0; >> + >> +=09memset(missing, 0, sizeof(missing)); >> +=09missing_u32 =3D (u32 *)missing; >> + >> +=09for (i =3D 0; i < NCAPINTS; i++) { >> +=09=09missing_u32[i] =3D ~c->x86_capability[i] & required_features[i]; >> +=09=09error |=3D missing_u32[i]; >> +=09} >> + >> +=09if (!error) >> +=09=09return; >> + >> +=09/* At least one required feature is missing */ >> +=09pr_warn("CPU %d: missing required feature(s):", c->cpu_index); >> +=09for_each_set_bit(i, missing, NCAPINTS * 32) >> +=09=09pr_cont(" %s", x86_cap_name(i, cap_buf)); >> +=09pr_cont("\n"); >> +=09add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); >> +} > >Do we need 2 loops? Can this be simplified as below: > >static void verify_required_features(const struct cpuinfo_x86 *c) >{ >=09u32 required_features[NCAPINTS + 1] =3D REQUIRED_MASK_INIT; >=09char cap_buf[X86_CAP_BUF_SIZE]; >=09int i, error =3D 0; > >=09for_each_set_bit(i, (unsigned long *)required_features, NCAPINTS * 32) = { >=09=09if (test_bit(i, (unsigned long *)c->x86_capability)) >=09=09=09continue; >=09=09if (!error) >=09=09=09pr_warn("CPU %d: missing required feature(s):", c->cpu_index); >=09=09pr_cont(" %s", x86_cap_name(i, cap_buf)); >=09=09error =3D 1; >=09} > >=09if (!error) >=09=09return; > >=09pr_cont("\n"); >=09add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); >} I'll have to test it but one concern I'd have is the pr_cont() in this context? Since it can technically have asynchronous problems I would think putting more code between subsequent calls to pr_cont() can increase the chance of some race condition. But perhaps these two if checks are not nearly enough for that to happen. Otherwise I liked in the previous approach the steps of setting up a bitmask with simple bitwise logic operations, then checking the results later. But the above code also works and I think it is easier to read. So if there is no opposition I'll test it and switch to it for the next version, thanks :) --=20 Kind regards Maciej Wiecz=C3=B3r-Retman