selftests/mm: Fix build break when compiling pkey_util.c
Subsystems (3)
PATCH 1/2 selftests/mm: Fix build break when compiling pkey_util.c
From: Madhavan Srinivasan <[email protected]>
Commit 50910acd6f615 ("selftests/mm: use sys_pkey helpers consistently") added a pkey_util.c to refactor some of the protection_keys functions accessible by other tests. But this broken the build in powerpc in two ways,
pkey-powerpc.h: In function ‘arch_is_powervm’:
pkey-powerpc.h:73:21: error: storage size of ‘buf’ isn’t known
73 | struct stat buf;
| ^~~
pkey-powerpc.h:75:14: error: implicit declaration of function ‘stat’; did you mean ‘strcat’? [-Wimplicit-function-declaration]
75 | if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) &&
| ^~~~
| strcatSince pkey_util.c includes pkeys-helper.h, which in turn includes pkeys-powerpc.h, stat.h including is missing for "struct stat". This is fixed by adding "sys/stat.h" in pkeys-powerpc.h
Secondly,
pkey-powerpc.h:55:18: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘u64’ {aka ‘long unsigned int’} [-Wformat=]
55 | dprintf4("%s() changing %016llx to %016llx\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 | __func__, __read_pkey_reg(), pkey_reg);
| ~~~~~~~~~~~~~~~~~
| |
| u64 {aka long unsigned int}pkey-helpers.h:63:32: note: in definition of macro ‘dprintf_level’
63 | sigsafe_printf(args); \
| ^~~~
These format specifier related warning are removed by adding "__SANE_USERSPACE_TYPES__" to pkeys_utils.c.
--- tools/testing/selftests/mm/pkey-powerpc.h | 2 ++ tools/testing/selftests/mm/pkey_util.c | 1 + 2 files changed, 3 insertions(+)
tools/testing/selftests/mm/pkey-powerpc.h +2 -0
@@ -3,6 +3,8 @@#ifndef _PKEYS_POWERPC_H#define _PKEYS_POWERPC_H +#include <sys/stat.h> +#ifndef SYS_pkey_alloc# define SYS_pkey_alloc 384# define SYS_pkey_free 385
tools/testing/selftests/mm/pkey_util.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only +#define __SANE_USERSPACE_TYPES__#include <sys/syscall.h> #include <unistd.h>
Signature · 1 line
2.47.0
PATCH 2/2 selftests/mm: Fix a build failure on powerpc
The compiler is unaware of the size of code generated by the ".rept" assembler directive. This results in the compiler emitting branch instructions where the offset to branch to exceeds the maximum allowed value, resulting in build failures like the following:
CC protection_keys
/tmp/ccypKWAE.s: Assembler messages:
/tmp/ccypKWAE.s:2073: Error: operand out of range (0x0000000000020158 is not between 0xffffffffffff8000 and 0x0000000000007ffc) /tmp/ccypKWAE.s:2509: Error: operand out of range (0x0000000000020130 is not between 0xffffffffffff8000 and 0x0000000000007ffc)
Fix the issue by manually adding nop instructions using the preprocessor.
--- tools/testing/selftests/mm/pkey-powerpc.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/pkey-powerpc.h +11 -1
@@ -104,8 +104,18 @@ static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)return ; } +#define REPEAT_8 (s) s s s s s s s s +#define REPEAT_64 (s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) \ + REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) +#define REPEAT_512 (s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) \ + REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) +#define REPEAT_4096 (s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) \ + REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) +#define REPEAT_16384 (s) REPEAT_4096(s) REPEAT_4096(s) \ + REPEAT_4096(s) REPEAT_4096(s) +/* 4-byte instructions * 16384 = 64K page */ -#define __page_o_noops () asm(".rept 16384 ; nop; .endr") +#define __page_o_noops () asm(REPEAT_16384("nop\n"))static inline void *malloc_pkey_with_mprotect_subpage (long size,int prot,u16 pkey) {
Signature · 1 line
2.47.0
Re: [PATCH 2/2] selftests/mm: Fix a build failure on powerpc
Quoted 35 lines · Nysal Jan K.A.
The compiler is unaware of the size of code generated by the ".rept" assembler directive. This results in the compiler emitting branch instructions where the offset to branch to exceeds the maximum allowed value, resulting in build failures like the following:
CC
protection_keys
/tmp/ccypKWAE.s: Assembler messages:
/tmp/ccypKWAE.s:2073: Error: operand out of range (0x0000000000020158is not between0xffffffffffff8000and0x0000000000007ffc)/tmp/ccypKWAE.s:2509: Error: operand out of range (0x0000000000020130is not between0xffffffffffff8000and0x0000000000007ffc)Fix the issue by manually adding nop instructions using the preprocessor.
Fixes 46036188ea1f5 ("selftests/mm: build with -O2")Reported-by Madhavan Srinivasan <[email protected]>Signed-off-by Nysal Jan K.A. <[email protected]>--- tools/testing/selftests/mm/pkey-powerpc.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)tools/testing/selftests/mm/pkey-powerpc.h +6
-0@@ -104,8 +104,18 @@ static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)return ; } +#define REPEAT_8 (s) s s s s s s s s +#define REPEAT_64 (s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) \ + REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) +#define REPEAT_512 (s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) \ + REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) +#define REPEAT_4096 (s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) \
tools/testing/selftests/mm/pkey-powerpc.h static inline void expect_fault_on_read_execonly_key(void *p1, int pkey) · line 121
Quoted 10 lines
tools/testing/selftests/mm/pkey-powerpc.h +5
-1+ REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) +#define REPEAT_16384(s) REPEAT_4096(s) REPEAT_4096(s) \ + REPEAT_4096(s) REPEAT_4096(s) +/* 4-byte instructions * 16384 = 64K page */ -#define __page_o_noops () asm(".rept 16384 ; nop; .endr") +#define __page_o_noops () asm(REPEAT_16384("nop\n"))static inline void *malloc_pkey_with_mprotect_subpage (long size,int prot,u16 pkey) {
Tested this patch by applying on top of mainline kernel v6.15-rc4, and it fixes the build issue. Hence,
Without this Patch:
CC protection_keys/tmp/ccG0zLKW.s: Assembler messages:/tmp/ccG0zLKW.s:1694: Error: operand out of range (0x0000000000020138 is not between 0xffffffffffff8000 and 0x0000000000007ffc) /tmp/ccG0zLKW.s:2577: Error: operand out of range (0x0000000000020110 is not between 0xffffffffffff8000 and 0x0000000000007ffc) In file included from pkey_util.c:5:
With this patch:
make -j 33/bin/sh ./check_config.sh gcc
CC cow
CC compaction_test
CC gup_longterm
CC gup_test
CC hmm-tests
CC hugetlb-madvise
CC hugetlb-read-hwpoison
CC hugetlb-soft-offline
CC hugepage-mmap
CC hugepage-mremap
CC hugepage-shm
CC hugepage-vmemmap
CC khugepaged
CC madv_populate
CC map_fixed_noreplace
CC map_hugetlb
CC map_populate
CC migration
CC mkdirty
CC mlock-random-test
CC mlock2-tests
CC mrelease_test
CC mremap_dontunmap
CC mremap_test
CC mseal_test
CC on-fault-limit
CC pagemap_ioctl
CC thuge-gen
CC transhuge-stress
CC uffd-stress
CC uffd-unit-tests
CC uffd-wp-mremap
CC split_huge_page_test
CC ksm_tests
CC ksm_functional_tests
CC hugetlb_fault_after_madv
CC hugetlb_madv_vs_map
CC mdwe_test
CC hugetlb_dio
CC droppable
CC guard-regions
CC soft-dirty
CC protection_keys
CC va_high_addr_switch
CC virtual_address_range
CC write_to_hugetlbfs
CC [M] page_frag_test.o
MODPOST Module.symvers
CC [M] page_frag_test.mod.o
CC [M] .module-common.o
LD [M] page_frag_test.ko
Regards,
Venkat.
Re: [PATCH 2/2] selftests/mm: Fix a build failure on powerpc
In reply to Nysal Jan K.A.Quoted 29 lines · Nysal Jan K.A.
The compiler is unaware of the size of code generated by the ".rept" assembler directive. This results in the compiler emitting branch instructions where the offset to branch to exceeds the maximum allowed value, resulting in build failures like the following:
CC
protection_keys
/tmp/ccypKWAE.s: Assembler messages:
/tmp/ccypKWAE.s:2073: Error: operand out of range (0x0000000000020158is not between0xffffffffffff8000and0x0000000000007ffc)/tmp/ccypKWAE.s:2509: Error: operand out of range (0x0000000000020130is not between0xffffffffffff8000and0x0000000000007ffc)Fix the issue by manually adding nop instructions using the preprocessor.
Fixes 46036188ea1f5 ("selftests/mm: build with -O2")Reported-by Madhavan Srinivasan <[email protected]>Signed-off-by Nysal Jan K.A. <[email protected]>--- tools/testing/selftests/mm/pkey-powerpc.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)tools/testing/selftests/mm/pkey-powerpc.h +0
-0@@ -104,8 +104,18 @@ static inline void expect_fault_on_read_execonly_key(void *p1, int pkey)return ; }
tools/testing/selftests/mm/pkey-powerpc.h static inline void expect_fault_on_read_execonly_key(void *p1, int pkey) · line 116
Quoted 10 lines
tools/testing/selftests/mm/pkey-powerpc.h +10
-0+#define REPEAT_8 (s) s s s s s s s s +#define REPEAT_64 (s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) \ + REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) REPEAT_8(s) +#define REPEAT_512 (s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) \ + REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) REPEAT_64(s) +#define REPEAT_4096 (s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) \ + REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) REPEAT_512(s) +#define REPEAT_16384 (s) REPEAT_4096(s) REPEAT_4096(s) \ + REPEAT_4096(s) REPEAT_4096(s) +
Hi Nysal,
This change looks good to me. I tested in on power and the error is not seen.
CC droppable
CC guard-regions
CC soft-dirty
CC protection_keys
CC va_high_addr_switch
CC virtual_address_range
CC write_to_hugetlbfs
Quoted 6 lines
tools/testing/selftests/mm/pkey-powerpc.h +1
-1/* 4-byte instructions * 16384 = 64K page */ -#define __page_o_noops () asm(".rept 16384 ; nop; .endr") +#define __page_o_noops () asm(REPEAT_16384("nop\n"))static inline void *malloc_pkey_with_mprotect_subpage (long size,int prot,u16 pkey) {
Quoted 61 lines · Nysal Jan K.A.
From: Madhavan Srinivasan <[email protected]>
Commit
50910acd6f615("selftests/mm: usesys_pkeyhelpers consistently") added apkey_util.cto refactor some of theprotection_keysfunctions accessible by other tests. But this broken the build in powerpc in two ways,
pkey-powerpc.h: In function ‘arch_is_powervm’:
pkey-powerpc.h:73:21: error: storage size of ‘buf’ isn’t known73 | struct stat buf; | ^~~ pkey-powerpc.h:75:14: error: implicit declaration of function ‘stat’; did you mean ‘strcat’? [-Wimplicit-function-declaration] 75 | if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) && | ^~~~ | strcatSince
pkey_util.cincludespkeys-helper.h, which in turn includespkeys-powerpc.h,stat.hincluding is missing for "struct stat". This is fixed by adding "sys/stat.h" inpkeys-powerpc.hSecondly,
pkey-powerpc.h:55:18: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘u64’ {aka ‘long unsigned int’} [-Wformat=]
55 | dprintf4("%s() changing %016llx to %016llx\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | __func__, __read_pkey_reg(), pkey_reg); | ~~~~~~~~~~~~~~~~~ | | | u64 {aka long unsigned int} pkey-helpers.h:63:32: note: in definition of macro ‘dprintf_level’ 63 | sigsafe_printf(args); \ | ^~~~These format specifier related warning are removed by adding "
__SANE_USERSPACE_TYPES__" topkeys_utils.c.Fixes 50910acd6f615 ("selftests/mm: use sys_pkey helpers consistently")Signed-off-by Madhavan Srinivasan <[email protected]>Signed-off-by Nysal Jan K.A. <[email protected]>--- tools/testing/selftests/mm/pkey-powerpc.h | 2 ++ tools/testing/selftests/mm/pkey_util.c | 1 + 2 files changed, 3 insertions(+)tools/testing/selftests/mm/pkey-powerpc.h +2
-0@@ -3,6 +3,8 @@#ifndef _PKEYS_POWERPC_H#define _PKEYS_POWERPC_H +#include <sys/stat.h> +#ifndef SYS_pkey_alloc# define SYS_pkey_alloc 384# define SYS_pkey_free 385tools/testing/selftests/mm/pkey_util.c +0
-0
tools/testing/selftests/mm/pkey_util.c line 5
Quoted 5 lines
tools/testing/selftests/mm/pkey_util.c +1
-0@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only +#define __SANE_USERSPACE_TYPES__#include <sys/syscall.h> #include <unistd.h>
Tested this patch by applying on top of mainline kernel v6.15-rc4, and it fixes the build issue. Hence,
Without this Patch:
pkey-powerpc.h: In function ‘arch_is_powervm’:
pkey-powerpc.h:73:21: error: storage size of ‘buf’ isn’t known
73 | struct stat buf;
| ^~~
pkey-powerpc.h:75:14: warning: implicit declaration of function ‘stat’; did you mean ‘strcat’? [-Wimplicit-function-declaration] 75 | if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) &&
| ^~~~
| strcat
With this patch:
make -j 33/bin/sh ./check_config.sh gcc
CC cow
CC compaction_test
CC gup_longterm
CC gup_test
CC hmm-tests
CC hugetlb-madvise
CC hugetlb-read-hwpoison
CC hugetlb-soft-offline
CC hugepage-mmap
CC hugepage-mremap
CC hugepage-shm
CC hugepage-vmemmap
CC khugepaged
CC madv_populate
CC map_fixed_noreplace
CC map_hugetlb
CC map_populate
CC migration
CC mkdirty
CC mlock-random-test
CC mlock2-tests
CC mrelease_test
CC mremap_dontunmap
CC mremap_test
CC mseal_test
CC on-fault-limit
CC pagemap_ioctl
CC thuge-gen
CC transhuge-stress
CC uffd-stress
CC uffd-unit-tests
CC uffd-wp-mremap
CC split_huge_page_test
CC ksm_tests
CC ksm_functional_tests
CC hugetlb_fault_after_madv
CC hugetlb_madv_vs_map
CC mdwe_test
CC hugetlb_dio
CC droppable
CC guard-regions
CC soft-dirty
CC protection_keys
CC va_high_addr_switch
CC virtual_address_range
CC write_to_hugetlbfs
CC [M] page_frag_test.o
MODPOST Module.symvers
CC [M] page_frag_test.mod.o
CC [M] .module-common.o
LD [M] page_frag_test.ko
Regards,
Venkat.