From nobody Wed Apr 1 21:33:14 2026 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 6EA2120298B for ; Tue, 4 Mar 2025 08:53:39 +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=1741078421; cv=none; b=fHYr+jjw7kaMDxbmT00zNG1PoahZL6DLB4Gns5iVOwUMNqQ31DQ/wE3G33tYmDF85ZpVed9zPRZLWtkOKX/CINZYmTtHtG/zBbXf8l7H9YxQfKI6L+BWanqbJF7GSWlW46QEW1eyR1gluN7pMI1MGWvSwRX/BC8Xc2zE+rd+spg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078421; c=relaxed/simple; bh=lsxhQurcmM196BSH+oL0A4Qd/q/w2Y/kWtlldc1NdRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lut/Y2xk93bwaa8jP2dtwhSnY0wAOpR5Fh7pV2exbiSeIX1ah1XI+/IjCjzVyLvyiSQciROPSt6yDDwSRYTOp9VvmTBBHwp+z6t3aE4C2DNO4Pon8TenGspRvmLAKhP9AwJl0o7FhXKV27GohTcHGT0/jMorlXAoI8a2nIVtPOw= 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=4BvT2ZQd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ELXvKaq8; 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="4BvT2ZQd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ELXvKaq8" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078418; 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=PyaqtxIU8m3/v0+B5MpQxFjLCTwaJUXCAgCjkjGIBQA=; b=4BvT2ZQd2KaFEG7/j9csj17Alf0lhmx2odBQSwdFeK9hawBS6P5gjI9I9ShDY8OqgnSSY5 vWzk+CvQzRJPEKjXeLPBK8uGF5j3dW2tR6dUMXx/1SmE5i6RnOPgrwAiwrUdokohGhkruD tfGSoe7+9YOpLxlRdnXqpruJAhWYyHdtuzh7a+ZC6T5tH06EtDBG44sGIATY5OhY5IeDyN Jv0+/urrJLVk4MmVUGYxAlTXUGGKpNASGQGhNE5W3VrvDBaD3f3817uetXF7B/7WCZqr3Y IURLNFeKzRJqS+jkUoe+Dafy7urnwlV+QIOSMwUXZz1C6hIx5P49fA6bNTE2oA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078418; 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=PyaqtxIU8m3/v0+B5MpQxFjLCTwaJUXCAgCjkjGIBQA=; b=ELXvKaq8NQK7kDQF5xX5aub9QbzKZcGzVntck5qec7Q9LUVmDVT4NDshL729mCp5gHHJdB NKDnjivtKPkLV7CQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 28/40] x86/cacheinfo: Use enums for cache descriptor types Date: Tue, 4 Mar 2025 09:51:39 +0100 Message-ID: <20250304085152.51092-29-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" The leaf 0x2 one-byte cache descriptor types: CACHE_L1_INST CACHE_L1_DATA CACHE_L2 CACHE_L3 are just discriminators to be used within the cache_table[] mapping. Their specific values are irrelevant. Use enums for such types. Make the enum packed and static assert that its values remain within a single byte so that the cache_table[] array size do not go out of hand. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 14 ++++++++++++++ arch/x86/kernel/cpu/cacheinfo.c | 9 ++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 50f6046a57b9..0051d8c2b9ee 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -2,6 +2,8 @@ #ifndef _ASM_X86_CPUID_TYPES_H #define _ASM_X86_CPUID_TYPES_H =20 +#include +#include #include =20 #include @@ -76,4 +78,16 @@ static inline void get_leaf_0x2_regs(union leaf_0x2_regs= *regs) /* Skip the first byte as it is not a descriptor */ \ for (desc =3D &(regs).desc[1]; desc < &(regs).desc[16]; desc++) =20 +/* + * Leaf 0x2 1-byte descriptors' cache types + * To be used for their mappings at cache_table[] + */ +enum _cache_table_type { + CACHE_L1_INST, + CACHE_L1_DATA, + CACHE_L2, + CACHE_L3, +} __packed; +static_assert(sizeof(enum _cache_table_type) =3D=3D 1); + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 9e87321466fe..a7fccbab268d 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -23,11 +23,6 @@ =20 #include "cpu.h" =20 -#define CACHE_L1_INST 1 -#define CACHE_L1_DATA 2 -#define CACHE_L2 3 -#define CACHE_L3 4 - /* Shared last level cache maps */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); =20 @@ -41,7 +36,7 @@ unsigned int memory_caching_control __ro_after_init; =20 struct _cache_table { unsigned char descriptor; - char cache_type; + enum _cache_table_type type; short size; }; =20 @@ -517,7 +512,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) if (!entry) continue; =20 - switch (entry->cache_type) { + switch (entry->type) { case CACHE_L1_INST: l1i +=3D entry->size; break; case CACHE_L1_DATA: l1d +=3D entry->size; break; case CACHE_L2: l2 +=3D entry->size; break; --=20 2.48.1