From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 AA0D7A932 for ; Sat, 21 Mar 2026 00:31:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774053095; cv=none; b=F7Q2URIEr2YAv6oC93th3GMOpjE6XVnl6Sn7mFJDRBKXo44VsmFT4hgcnxMKVhz3CR1/8ypuW3r0BuLF41YuJVGpqgimtTpWe3voY2tToIn5HQMHl+DxU/1vnEvzxJQnPragK6QTiHcYbfgHn9afHaZ4CqpK19uNP3pyBW6oEKE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774053095; c=relaxed/simple; bh=6woDzW3186CeuFPVlybB2TJlk9YXRctq0Tr8W2etQ7M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RDkmNQG6A+xT/+p8fAZXzzfAhZA3GkEacGR2ruKvQzcmZhbTILaQMaatYIGb+zGpDi/99XrynxwBFw60NmgCGipWyhcrT7547Jq//AcaCxlrN+IFsKrv+v62BsXWzcWCtJ8lIHlxsEKQnC48aNyMoxkPF+nHY53bRpLfsBYJm0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Z63/gcMt; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z63/gcMt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774053094; x=1805589094; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=6woDzW3186CeuFPVlybB2TJlk9YXRctq0Tr8W2etQ7M=; b=Z63/gcMtCETchs1kKd94m7HgM8Esf4ycl7MQjukfy+G76s7pBfj1qEOy 9nzi/fl/lmSErH++Qc8kGzA54DTfd5E+4OYUA8Q7I3JukZidl/LIcWo6v SxM3ytEMj8oIGoQTJu523jhO+j8ZoKv/c6HTjlw/GmHmWui7DImjowscO VDXEGQyuP1u8/2RZXHptNORw2YoultzuqLTQbL0HHo0UhEJDRvaG+l0GW 2x9JaQJm9Uto4d5br3n6SaFUgn77tQDGwslojshwW6O8D83UgOyfKCnjG mkEW1340HCdippiB+PhateWD0D0EBFpB9jJKeriVnIgotRnN2UX7IdufW Q==; X-CSE-ConnectionGUID: JGevJMyLSM6bQCz3wJSPKg== X-CSE-MsgGUID: A2t8UhnXS+6Pj+AOD6ceuQ== X-IronPort-AV: E=McAfee;i="6800,10657,11735"; a="74847935" X-IronPort-AV: E=Sophos;i="6.23,132,1770624000"; d="scan'208";a="74847935" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2026 17:31:34 -0700 X-CSE-ConnectionGUID: 3qPH17YtSQKT1UNGNSWy3A== X-CSE-MsgGUID: zm5L20nGS+qLip1Ku9TPmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,132,1770624000"; d="scan'208";a="227920525" Received: from guptapa-desk.jf.intel.com (HELO desk) ([10.165.239.46]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2026 17:31:33 -0700 Date: Fri, 20 Mar 2026 17:31:27 -0700 From: Pawan Gupta To: Maciej Wieczor-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: <20260321003015.4i7wrqmaunbljguw@desk> References: <7312c9f2feab8aea4612ed9a1841e8c22f5f69b1.1774008873.git.m.wieczorretman@pm.me> 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=us-ascii Content-Disposition: inline In-Reply-To: <7312c9f2feab8aea4612ed9a1841e8c22f5f69b1.1774008873.git.m.wieczorretman@pm.me> 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) > return 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) > +{ > + u32 required_features[NCAPINTS] = REQUIRED_MASK_INIT; > + DECLARE_BITMAP(missing, NCAPINTS * 32); > + char cap_buf[X86_CAP_BUF_SIZE]; > + u32 *missing_u32; > + unsigned int i; > + u32 error = 0; > + > + memset(missing, 0, sizeof(missing)); > + missing_u32 = (u32 *)missing; > + > + for (i = 0; i < NCAPINTS; i++) { > + missing_u32[i] = ~c->x86_capability[i] & required_features[i]; > + error |= missing_u32[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, missing, NCAPINTS * 32) > + pr_cont(" %s", x86_cap_name(i, cap_buf)); > + pr_cont("\n"); > + add_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) { u32 required_features[NCAPINTS + 1] = REQUIRED_MASK_INIT; char cap_buf[X86_CAP_BUF_SIZE]; int i, error = 0; for_each_set_bit(i, (unsigned long *)required_features, NCAPINTS * 32) { if (test_bit(i, (unsigned long *)c->x86_capability)) continue; if (!error) pr_warn("CPU %d: missing required feature(s):", c->cpu_index); pr_cont(" %s", x86_cap_name(i, cap_buf)); error = 1; } if (!error) return; pr_cont("\n"); add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); }