From patchwork Mon Jun 17 09:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawan Gupta X-Patchwork-Id: 805140 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 26AFB191485; Mon, 17 Jun 2024 09:12:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718615525; cv=none; b=JvTrbc/bxsz1LQZCQCYpbnoRrbAa82vETEpMuzQMFUtIDNBEI4nrrymaOpiCL7XHfgHWaZpz5lBU018pSTNd9LKdoudxJms8X0TBNkeWvrog3I4d+zYhtPgMmwgwDJB+3lo3tpCN8j5vg7Xz0VjWC1snhSpPSYdDvpQq1bKsEpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718615525; c=relaxed/simple; bh=53iR0oJoFrK/mVOBbPtm8xBtCnOjOri/vZYCc4QFK40=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cp2qWde6s5KWw+FBcWh+9Y/Sqla/Em8X76nzsEM/OexUo8kpD9umwwIYj211zViQLkXsMLQJZxcbHEZZ+hj8bXurnBkjnhfXLnLpFQuLyRx0gT9j2qmjGzT1H0BPDVtWbJrAvspC3z0pAePJtTcZIDhvVg4MzOhSfLs+6ijjz1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DeRW3VhB; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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="DeRW3VhB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718615524; x=1750151524; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=53iR0oJoFrK/mVOBbPtm8xBtCnOjOri/vZYCc4QFK40=; b=DeRW3VhBaQIuoyS6pvbVooooOp6Go2cSGWu3x9pDAjDvrNhP6m+VshDz 2TdbNCaCtcQbTJhR7HhpGOCiw7bI8j+Po4WrrF/Em6UnnDmHpKQGPnDZQ iUdTLusWjJFg6T+ffhkg4109eRiMxkfxe4QcEfKj3r2ejXZRyrcYg86Qp vtaxJQqLG3fn+ytkqMjomgJQudgjG3Qyv7P993oX/Hav28IpeoJ18WRLG viPtKwUTS85y919cQC84Widr7o9FL6r627/18Zd+4OjY4mlwbr/7wFrnh vUTuMs3hQ4H1zh27sHBiKjgYoACNP1f8qh0dNziydj/5nIV9UKoVo3dR4 A==; X-CSE-ConnectionGUID: WD53lD0rTme+SA+ySgUPTQ== X-CSE-MsgGUID: SYgAFKySTMmsmGLAOk/Big== X-IronPort-AV: E=McAfee;i="6700,10204,11105"; a="32902571" X-IronPort-AV: E=Sophos;i="6.08,244,1712646000"; d="scan'208";a="32902571" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2024 02:12:04 -0700 X-CSE-ConnectionGUID: 2wQt2KXiS6qjeOzcmFUUeg== X-CSE-MsgGUID: s7sessOjR5ioPWz8WZE9ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,244,1712646000"; d="scan'208";a="72339312" Received: from mshehzad-mobl.amr.corp.intel.com (HELO desk) ([10.209.21.13]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2024 02:12:02 -0700 Date: Mon, 17 Jun 2024 02:12:01 -0700 From: Pawan Gupta To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: daniel.sneddon@linux.intel.com, tony.luck@intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-perf-users@vger.kernel.org, Josh Poimboeuf , Srinivas Pandruvada , "Rafael J. Wysocki" , Ricardo Neri , "Liang, Kan" , Andrew Cooper Subject: [PATCH PATCH 7/9] x86/cpu: Update x86_match_cpu() to also use cpu-type Message-ID: <20240617-add-cpu-type-v1-7-b88998c01e76@linux.intel.com> X-Mailer: b4 0.12.3 References: <20240617-add-cpu-type-v1-0-b88998c01e76@linux.intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240617-add-cpu-type-v1-0-b88998c01e76@linux.intel.com> Non-hybrid CPU variants that share the same Family/Model could be differentiated by their cpu-type. x86_match_cpu() currently does not use cpu-type for CPU matching. Dave Hansen suggested to use below conditions to match CPU-type: 1. If CPU_TYPE_ANY (the wildcard), then matched 2. If hybrid, then matched 3. If !hybrid, look at the boot CPU and compare the cpu-type to determine if it is a match. This special case for hybrid systems allows more compact vulnerability list. Imagine that "Haswell" CPUs might or might not be hybrid and that only Atom cores are vulnerable to Meltdown. That means there are three possibilities: 1. P-core only 2. Atom only 3. Atom + P-core (aka. hybrid) One might be tempted to code up the vulnerability list like this: MATCH( HASWELL, X86_FEATURE_HYBRID, MELTDOWN) MATCH_TYPE(HASWELL, ATOM, MELTDOWN) Logically, this matches #2 and #3. But that's a little silly. You would only ask for the "ATOM" match in cases where there *WERE* hybrid cores in play. You shouldn't have to _also_ ask for hybrid cores explicitly. In short, assume that processors that enumerate Hybrid==1 have a vulnerable core type. Update x86_match_cpu() to also match cpu-type. Also treat hybrid systems as special, and match them to any cpu-type. Suggested-by: Dave Hansen Signed-off-by: Pawan Gupta --- arch/x86/kernel/cpu/match.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/kernel/cpu/match.c b/arch/x86/kernel/cpu/match.c index 8e7de733320a..ca15e74596d7 100644 --- a/arch/x86/kernel/cpu/match.c +++ b/arch/x86/kernel/cpu/match.c @@ -5,6 +5,26 @@ #include #include +/** + * x86_match_cpu - helper function to match the cpu-type for a single + * entry in the x86_cpu_id table. + * @c: Pointer to the cpuinfo_x86 structure of the CPU to match. + * @m: Pointer to the x86_cpu_id entry to match against. + * + * Return: true if the cpu-type matches, false otherwise. + */ +static bool x86_match_cpu_type(struct cpuinfo_x86 *c, const struct x86_cpu_id *m) +{ + if (m->cpu_type == X86_CPU_TYPE_ANY) + return true; + + /* Hybrid CPUs are special, they are assumed to match all cpu-types */ + if (boot_cpu_has(X86_FEATURE_HYBRID_CPU)) + return true; + + return c->topo.cpu_type == m->cpu_type; +} + /** * x86_match_cpu - match current CPU again an array of x86_cpu_ids * @match: Pointer to array of x86_cpu_ids. Last entry terminated with @@ -50,6 +70,8 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) continue; if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature)) continue; + if (!x86_match_cpu_type(c, m)) + continue; return m; } return NULL;