]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/lam: Move cpu_has_la57() to use cpuinfo flag
authorMaciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Mon, 27 Jan 2025 15:31:55 +0000 (16:31 +0100)
committerIngo Molnar <mingo@kernel.org>
Sat, 22 Feb 2025 12:17:07 +0000 (13:17 +0100)
In current form cpu_has_la57() reports platform's support for LA57
through reading the output of cpuid. A much more useful information is
whether 5-level paging is actually enabled on the running system.

Check whether 5-level paging is enabled by trying to map a page in the
high linear address space.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/8b1ca51b13e6d94b5a42b6930d81b692cbb0bcbb.1737990375.git.maciej.wieczor-retman@intel.com
tools/testing/selftests/x86/lam.c

index 4d4a76532dc9a4f1fc5be4092bf42dfd2e25b180..60170a31aa6967787266863229d373ef6c82c383 100644 (file)
@@ -124,14 +124,18 @@ static inline int cpu_has_lam(void)
        return (cpuinfo[0] & (1 << 26));
 }
 
-/* Check 5-level page table feature in CPUID.(EAX=07H, ECX=00H):ECX.[bit 16] */
-static inline int cpu_has_la57(void)
+static inline int la57_enabled(void)
 {
-       unsigned int cpuinfo[4];
+       int ret;
+       void *p;
+
+       p = mmap((void *)HIGH_ADDR, PAGE_SIZE, PROT_READ | PROT_WRITE,
+                MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
 
-       __cpuid_count(0x7, 0, cpuinfo[0], cpuinfo[1], cpuinfo[2], cpuinfo[3]);
+       ret = p == MAP_FAILED ? 0 : 1;
 
-       return (cpuinfo[2] & (1 << 16));
+       munmap(p, PAGE_SIZE);
+       return ret;
 }
 
 /*
@@ -322,7 +326,7 @@ static int handle_mmap(struct testcases *test)
                   flags, -1, 0);
        if (ptr == MAP_FAILED) {
                if (test->addr == HIGH_ADDR)
-                       if (!cpu_has_la57())
+                       if (!la57_enabled())
                                return 3; /* unsupport LA57 */
                return 1;
        }