Re: [PATCH v2 18/29] x86/cacheinfo: Use enums for cache descriptor types

From: Ahmed S. Darwish
Date: Wed Mar 19 2025 - 12:10:00 EST


Hi,

On Wed, 19 Mar 2025, kernel test robot wrote:
>
> arch/x86/include/asm/cpuid/types.h:56:1: sparse: sparse:
> static assertion failed: "sizeof(enum _cache_table_type) == 1"
>

I've checked the error report and reproduced it on my machine:

https://download.01.org/0day-ci/archive/20250319/202503192150.Vhannmnp-lkp@xxxxxxxxx/reproduce

After cloning sparse git repo and playing around with its validation test
suite, I've realized that it does not understand __attribiute__((packed))
on enums.

Namely, applying below diff on top of sparse's git repo:

| diff --git a/validation/enum-min-size.c b/validation/enum-min-size.c
| index e8bd9fb1..e691b332 100644
| --- a/validation/enum-min-size.c
| +++ b/validation/enum-min-size.c
| @@ -1,5 +1,9 @@
| enum i { I = 1 };
| _Static_assert(sizeof(enum i) == sizeof(int), "int");
| +
| +enum k { X = 0} __attribute__((packed));
| +_Static_assert(sizeof(enum k) == sizeof(char), "char");
| +
| enum u { U = 1U };
| _Static_assert(sizeof(enum u) == sizeof(int), "uint");

Then running the modified test:

sparse/$ cd validation
sparse/validation$ ./test-suite enum-min-size.c

leads to the same error:

TEST enum-min-size (enum-min-size.c)
+enum-min-size.c:5:31: error: static assertion failed: "char"
error: FAIL: test 'enum-min-size.c' failed

After checking other kernel code which have __packed on enums, I found
this at <linux/rw_hint.h>, which is included by core SCSI code:

/* Sparse ignores __packed annotations on enums, hence the #ifndef below. */
#ifndef __CHECKER__
static_assert(sizeof(enum rw_hint) == 1);
#endif

So I'll add a similar CPP guard (in v4, since I've already posted v3.)

Thanks!

--
Ahmed S. Darwish
Linutronix GmbH