Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests:resctrl: Fix build failure on archs without __cpuid_count()

When resctrl is built on architectures without __cpuid_count()
support, build fails. resctrl uses __cpuid_count() defined in
kselftest.h.

Even though the problem is seen while building resctrl on aarch64,
this error can be seen on any platform that doesn't support CPUID.

CPUID is a x86/x86-64 feature and code paths with CPUID asm commands
will fail to build on all other architectures.

All others tests call __cpuid_count() do so from x86/x86_64 code paths
when _i386__ or __x86_64__ are defined. resctrl is an exception.

Fix the problem by defining __cpuid_count() only when __i386__ or
__x86_64__ are defined in kselftest.h and changing resctrl to call
__cpuid_count() only when __i386__ or __x86_64__ are defined.

In file included from resctrl.h:24,
from cat_test.c:11:
In function ‘arch_supports_noncont_cat’,
inlined from ‘noncont_cat_run_test’ at cat_test.c:326:6:
../kselftest.h:74:9: error: impossible constraint in ‘asm’
74 | __asm__ __volatile__ ("cpuid\n\t" \
| ^~~~~~~
cat_test.c:304:17: note: in expansion of macro ‘__cpuid_count’
304 | __cpuid_count(0x10, 1, eax, ebx, ecx, edx);
| ^~~~~~~~~~~~~
../kselftest.h:74:9: error: impossible constraint in ‘asm’
74 | __asm__ __volatile__ ("cpuid\n\t" \
| ^~~~~~~
cat_test.c:306:17: note: in expansion of macro ‘__cpuid_count’
306 | __cpuid_count(0x10, 2, eax, ebx, ecx, edx);

Fixes: ae638551ab64 ("selftests/resctrl: Add non-contiguous CBMs CAT test")
Reported-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Closes: https://lore.kernel.org/lkml/20240809071059.265914-1-usama.anjum@collabora.com/
Reported-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

+7 -2
+2
tools/testing/selftests/kselftest.h
··· 61 61 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 62 62 #endif 63 63 64 + #if defined(__i386__) || defined(__x86_64__) /* arch */ 64 65 /* 65 66 * gcc cpuid.h provides __cpuid_count() since v4.4. 66 67 * Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0. ··· 76 75 : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ 77 76 : "0" (level), "2" (count)) 78 77 #endif 78 + #endif /* end arch */ 79 79 80 80 /* define kselftest exit codes */ 81 81 #define KSFT_PASS 0
+5 -2
tools/testing/selftests/resctrl/cat_test.c
··· 290 290 291 291 static bool arch_supports_noncont_cat(const struct resctrl_test *test) 292 292 { 293 - unsigned int eax, ebx, ecx, edx; 294 - 295 293 /* AMD always supports non-contiguous CBM. */ 296 294 if (get_vendor() == ARCH_AMD) 297 295 return true; 298 296 297 + #if defined(__i386__) || defined(__x86_64__) /* arch */ 298 + unsigned int eax, ebx, ecx, edx; 299 299 /* Intel support for non-contiguous CBM needs to be discovered. */ 300 300 if (!strcmp(test->resource, "L3")) 301 301 __cpuid_count(0x10, 1, eax, ebx, ecx, edx); ··· 305 305 return false; 306 306 307 307 return ((ecx >> 3) & 1); 308 + #endif /* end arch */ 309 + 310 + return false; 308 311 } 309 312 310 313 static int noncont_cat_run_test(const struct resctrl_test *test,