From nobody Wed Dec 17 15:35:01 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E59C11B4232 for ; Mon, 17 Mar 2025 16:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742230365; cv=none; b=WtRqn1UwV1EsjLdntVWKL183SUCfPKU2I9QJTfLLno444lbf3LGZw9Dql+03N0eacICgiOorY9jZj302cwdcoHqzTJtQIZAGV/rx6HfxLVy+teOdxDSh6MumIMDcdLHGqAX9MBu48mbzUz6yiXjxLLnkOguDfTDY5Rktf2otvrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742230365; c=relaxed/simple; bh=g5nCTLUQ7v/dgeHO9ZdiBcj0f1KcnklqusMEc/U04jM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+OR409yLx8SlxvzPK3VF3VBJzEf+BUiAfL5lCbMB6tgNXCHcyoa6F/13DKY5qgDj9al55LaVqkHWX0jR6zQbRpawKi75wDqiRIC/Ro/ETnaeTLN/J3o4tGIm6CQyZEP9pmh9ID32DH1V5rWL46uYb5cPqB5noCD6jZaeXfcYAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lH8HzpyT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b30CgE5a; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lH8HzpyT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b30CgE5a" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742230362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0XG4Vc/qKmqnIpTdZ4sagmxTTKpcTja3KbsV8H2WxcY=; b=lH8HzpyTJRGzZTtJVPipk9ZYX2+2q7lRbXZ/faQjRILORybDUZhFB1xksZEXz9SR6IE7ai a71jwvC53F5CpBk0gGQe6QxfVlDV1LWl1FBXtOERiU2skJPIuh9n6W/VApuWWMt0UaQ8vc 5O8AfK7azZpSQocPRIqtwHAxzHhigwI9+cs3RKpfK/ksQHre/GjiEloPVVnrDpLMdVWIti IU8L0U9O0JpgFimejesoQFOpmXDa33MT+eb/NHERMXpBLDbJU4cce5mfKtXRJ8gX5eQjQt ETrvc8DoYlPHXgunmFyuTBkGFeqpwcA6t5x2CyWvkFmPe9fAAWHbaCxefKf6Yg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742230362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0XG4Vc/qKmqnIpTdZ4sagmxTTKpcTja3KbsV8H2WxcY=; b=b30CgE5a3wh4w7odNYO6VdN82hFC6VhZn5T4jS74yNYnVTlBytaGDSzAqPh8BvyYbWUNXG YDmBnAchWVlqkgAg== To: Ingo Molnar , Dave Hansen , Borislav Petkov Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v2 04/29] x86/cacheinfo: Use CPUID leaf 0x2 parsing helpers Date: Mon, 17 Mar 2025 17:47:20 +0100 Message-ID: <20250317164745.4754-5-darwi@linutronix.de> In-Reply-To: <20250317164745.4754-1-darwi@linutronix.de> References: <20250317164745.4754-1-darwi@linutronix.de> 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" Use the CPUID leaf 0x2 parsing helpers added in previous commits, which queries the CPUID leaf just once. This also makes the same leaf 0x2 parsing logic used by both x86/cacheinfo and x86/cpu intel.c Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 66 +++++++++++++-------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 584811ffca0c..53f51acefac6 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -782,50 +783,35 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) =20 /* Don't use CPUID(2) if CPUID(4) is supported. */ if (!ci->num_leaves && c->cpuid_level > 1) { - /* supports eax=3D2 call */ - int j, n; - unsigned int regs[4]; - unsigned char *dp =3D (unsigned char *)regs; - - /* Number of times to iterate */ - n =3D cpuid_eax(2) & 0xFF; - - for (i =3D 0 ; i < n ; i++) { - cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); - - /* If bit 31 is set, this is an unknown format */ - for (j =3D 0 ; j < 4 ; j++) - if (regs[j] & (1 << 31)) - regs[j] =3D 0; - - /* Byte 0 is level count, not a descriptor */ - for (j =3D 1 ; j < 16 ; j++) { - unsigned char des =3D dp[j]; - unsigned char k =3D 0; - - /* look up this descriptor in the table */ - while (cache_table[k].descriptor !=3D 0) { - if (cache_table[k].descriptor =3D=3D des) { - switch (cache_table[k].cache_type) { - case LVL_1_INST: - l1i +=3D cache_table[k].size; - break; - case LVL_1_DATA: - l1d +=3D cache_table[k].size; - break; - case LVL_2: - l2 +=3D cache_table[k].size; - break; - case LVL_3: - l3 +=3D cache_table[k].size; - break; - } - + union leaf_0x2_regs regs; + u8 *desc; + + cpuid_get_leaf_0x2_regs(®s); + for_each_leaf_0x2_desc(regs, desc) { + unsigned char k =3D 0; + + /* look up this descriptor in the table */ + while (cache_table[k].descriptor !=3D 0) { + if (cache_table[k].descriptor =3D=3D *desc) { + switch (cache_table[k].cache_type) { + case LVL_1_INST: + l1i +=3D cache_table[k].size; + break; + case LVL_1_DATA: + l1d +=3D cache_table[k].size; + break; + case LVL_2: + l2 +=3D cache_table[k].size; + break; + case LVL_3: + l3 +=3D cache_table[k].size; break; } =20 - k++; + break; } + + k++; } } } --=20 2.48.1