Hi all,
During "make kselftest" there is an error in selftest/vm/cow.c compilation on
platform:
- Lenovo desktop 10TX000VCR (LENOVO_MT_10TX_BU_Lenovo_FM_V530S-07ICB)
- AlmaLinux 8.7 (CentOS fork)
- gcc 8.5.0 20210514 (Red Hat 8.5.0-15)
- vanilla kernel 6.2-rc2 from the torvalds mainline tree.
Compilation fails to find "#define MADV_PAGEOUT":
[root@pc-mtodorov vm]# make
gcc -Wall -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c vm_util.c -lrt -lpthread -o /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm/cow
cow.c: In function ‘do_run_with_base_page’:
cow.c:755:26: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
madvise(mem, pagesize, MADV_PAGEOUT);
^~~~~~~~~~~~
MADV_RANDOM
cow.c:755:26: note: each undeclared identifier is reported only once for each function it appears in
cow.c: In function ‘do_run_with_thp’:
cow.c:914:22: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
madvise(mem, size, MADV_PAGEOUT);
^~~~~~~~~~~~
MADV_RANDOM
make: *** [../lib.mk:145: /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm/cow] Error 1
[root@pc-mtodorov vm]#
MADV_PAGEOUT is defined in #include <asm-generic/mman-common.h> :
[root@pc-mtodorov vm]# grep MADV_PAGEOUT -r /usr/include
/usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
[root@pc-mtodorov vm]# grep MADV_PAGEOUT -r ../../../../usr/include
../../../../usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
[root@pc-mtodorov vm]#
However, gcc -E shows that asm-generic/mman-common.h is somehow never included:
---------------------------------------------------------------------------------------------
[root@pc-mtodorov vm]# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | cat -s | less
# 1 "/usr/include/sys/mman.h" 1 3 4
# 25 "/usr/include/sys/mman.h" 3 4
# 1 "/usr/lib/gcc/x86_64-redhat-linux/8/include/stddef.h" 1 3 4
# 26 "/usr/include/sys/mman.h" 2 3 4
# 41 "/usr/include/sys/mman.h" 3 4
# 1 "/usr/include/bits/mman.h" 1 3 4
# 49 "/usr/include/bits/mman.h" 3 4
# 1 "/usr/include/bits/mman-linux.h" 1 3 4
# 117 "/usr/include/bits/mman-linux.h" 3 4
# 1 "/usr/include/bits/mman-shared.h" 1 3 4
# 42 "/usr/include/bits/mman-shared.h" 3 4
int memfd_create (const char *__name, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__));
int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__));
int pkey_alloc (unsigned int __flags, unsigned int __access_rights) __attribute__ ((__nothrow__ , __leaf__));
int pkey_set (int __key, unsigned int __access_rights) __attribute__ ((__nothrow__ , __leaf__));
int pkey_get (int __key) __attribute__ ((__nothrow__ , __leaf__));
int pkey_free (int __key) __attribute__ ((__nothrow__ , __leaf__));
int pkey_mprotect (void *__addr, size_t __len, int __prot, int __pkey) __attribute__ ((__nothrow__ , __leaf__));
# 117 "/usr/include/bits/mman-linux.h" 2 3 4
# 49 "/usr/include/bits/mman.h" 2 3 4
# 42 "/usr/include/sys/mman.h" 2 3 4
# 57 "/usr/include/sys/mman.h" 3 4
extern void *mmap (void *__addr, size_t __len, int __prot,
int __flags, int __fd, __off_t __offset) __attribute__ ((__nothrow__ , __leaf__));
# 70 "/usr/include/sys/mman.h" 3 4
extern void *mmap64 (void *__addr, size_t __len, int __prot,
int __flags, int __fd, __off64_t __offset) __attribute__ ((__nothrow__ , __leaf__));
extern int munmap (void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
extern int mprotect (void *__addr, size_t __len, int __prot) __attribute__ ((__nothrow__ , __leaf__));
extern int msync (void *__addr, size_t __len, int __flags);
extern int madvise (void *__addr, size_t __len, int __advice) __attribute__ ((__nothrow__ , __leaf__));
extern int posix_madvise (void *__addr, size_t __len, int __advice) __attribute__ ((__nothrow__ , __leaf__));
extern int mlock (const void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
extern int munlock (const void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
extern int mlockall (int __flags) __attribute__ ((__nothrow__ , __leaf__));
extern int munlockall (void) __attribute__ ((__nothrow__ , __leaf__));
extern int mincore (void *__start, size_t __len, unsigned char *__vec)
__attribute__ ((__nothrow__ , __leaf__));
# 133 "/usr/include/sys/mman.h" 3 4
extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
int __flags, ...) __attribute__ ((__nothrow__ , __leaf__));
extern int remap_file_pages (void *__start, size_t __size, int __prot,
size_t __pgoff, int __flags) __attribute__ ((__nothrow__ , __leaf__));
extern int shm_open (const char *__name, int __oflag, mode_t __mode);
extern int shm_unlink (const char *__name);
-------------------------------------------------------------------------------------------------------
FYI:
On the platform:
- Ubuntu 22.10 kinetic kudu
- gcc 12.2.0
- same 6.2-rc2
, MADV_PAGEOUT is also defined in bits/mmap-linux.h, so the compile passes.
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# grep MADV_PAGEOUT -r /usr/include
/usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
/usr/include/x86_64-linux-gnu/bits/mman-linux.h:# define MADV_PAGEOUT 21 /* Reclaim these pages. */
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# grep MADV_PAGEOUT -r ../../../../usr/include
../../../../usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm#
However, mman-common.h from ../../../../usr/include/asm-generic/mman-common.h is also not included,
as of "gcc -E", but only bits/mman-linux.h:
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | grep mman-common.h
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | grep mman-linux.h
# 1 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 1 3 4
# 119 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 3 4
# 120 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 2 3 4
root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm#
I hope this is enough information for you to debug the issue.
I am standing by for any additional diagnostics needed.
Regards,
Mirsad
--
Mirsad Goran Todorovac
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb, Republic of Croatia
The European Union
On 08.01.23 11:58, Mirsad Goran Todorovac wrote:
> Hi all,
>
> During "make kselftest" there is an error in selftest/vm/cow.c compilation on
> platform:
>
> - Lenovo desktop 10TX000VCR (LENOVO_MT_10TX_BU_Lenovo_FM_V530S-07ICB)
> - AlmaLinux 8.7 (CentOS fork)
> - gcc 8.5.0 20210514 (Red Hat 8.5.0-15)
> - vanilla kernel 6.2-rc2 from the torvalds mainline tree.
>
> Compilation fails to find "#define MADV_PAGEOUT":
>
> [root@pc-mtodorov vm]# make
> gcc -Wall -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c vm_util.c -lrt -lpthread -o /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm/cow
> cow.c: In function ‘do_run_with_base_page’:
> cow.c:755:26: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
> madvise(mem, pagesize, MADV_PAGEOUT);
> ^~~~~~~~~~~~
> MADV_RANDOM
> cow.c:755:26: note: each undeclared identifier is reported only once for each function it appears in
> cow.c: In function ‘do_run_with_thp’:
> cow.c:914:22: error: ‘MADV_PAGEOUT’ undeclared (first use in this function); did you mean ‘MADV_RANDOM’?
> madvise(mem, size, MADV_PAGEOUT);
> ^~~~~~~~~~~~
> MADV_RANDOM
> make: *** [../lib.mk:145: /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm/cow] Error 1
> [root@pc-mtodorov vm]#
>
> MADV_PAGEOUT is defined in #include <asm-generic/mman-common.h> :
>
> [root@pc-mtodorov vm]# grep MADV_PAGEOUT -r /usr/include
> /usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
> [root@pc-mtodorov vm]# grep MADV_PAGEOUT -r ../../../../usr/include
> ../../../../usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
> [root@pc-mtodorov vm]#
>
> However, gcc -E shows that asm-generic/mman-common.h is somehow never included:
>
> ---------------------------------------------------------------------------------------------
> [root@pc-mtodorov vm]# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | cat -s | less
> # 1 "/usr/include/sys/mman.h" 1 3 4
> # 25 "/usr/include/sys/mman.h" 3 4
> # 1 "/usr/lib/gcc/x86_64-redhat-linux/8/include/stddef.h" 1 3 4
> # 26 "/usr/include/sys/mman.h" 2 3 4
> # 41 "/usr/include/sys/mman.h" 3 4
> # 1 "/usr/include/bits/mman.h" 1 3 4
> # 49 "/usr/include/bits/mman.h" 3 4
> # 1 "/usr/include/bits/mman-linux.h" 1 3 4
> # 117 "/usr/include/bits/mman-linux.h" 3 4
> # 1 "/usr/include/bits/mman-shared.h" 1 3 4
> # 42 "/usr/include/bits/mman-shared.h" 3 4
>
> int memfd_create (const char *__name, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__));
> int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__));
> int pkey_alloc (unsigned int __flags, unsigned int __access_rights) __attribute__ ((__nothrow__ , __leaf__));
> int pkey_set (int __key, unsigned int __access_rights) __attribute__ ((__nothrow__ , __leaf__));
> int pkey_get (int __key) __attribute__ ((__nothrow__ , __leaf__));
> int pkey_free (int __key) __attribute__ ((__nothrow__ , __leaf__));
> int pkey_mprotect (void *__addr, size_t __len, int __prot, int __pkey) __attribute__ ((__nothrow__ , __leaf__));
>
> # 117 "/usr/include/bits/mman-linux.h" 2 3 4
> # 49 "/usr/include/bits/mman.h" 2 3 4
> # 42 "/usr/include/sys/mman.h" 2 3 4
>
> # 57 "/usr/include/sys/mman.h" 3 4
> extern void *mmap (void *__addr, size_t __len, int __prot,
> int __flags, int __fd, __off_t __offset) __attribute__ ((__nothrow__ , __leaf__));
> # 70 "/usr/include/sys/mman.h" 3 4
> extern void *mmap64 (void *__addr, size_t __len, int __prot,
> int __flags, int __fd, __off64_t __offset) __attribute__ ((__nothrow__ , __leaf__));
>
> extern int munmap (void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
> extern int mprotect (void *__addr, size_t __len, int __prot) __attribute__ ((__nothrow__ , __leaf__));
> extern int msync (void *__addr, size_t __len, int __flags);
> extern int madvise (void *__addr, size_t __len, int __advice) __attribute__ ((__nothrow__ , __leaf__));
> extern int posix_madvise (void *__addr, size_t __len, int __advice) __attribute__ ((__nothrow__ , __leaf__));
> extern int mlock (const void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
> extern int munlock (const void *__addr, size_t __len) __attribute__ ((__nothrow__ , __leaf__));
> extern int mlockall (int __flags) __attribute__ ((__nothrow__ , __leaf__));
> extern int munlockall (void) __attribute__ ((__nothrow__ , __leaf__));
> extern int mincore (void *__start, size_t __len, unsigned char *__vec)
> __attribute__ ((__nothrow__ , __leaf__));
>
> # 133 "/usr/include/sys/mman.h" 3 4
>
> extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
> int __flags, ...) __attribute__ ((__nothrow__ , __leaf__));
> extern int remap_file_pages (void *__start, size_t __size, int __prot,
> size_t __pgoff, int __flags) __attribute__ ((__nothrow__ , __leaf__));
> extern int shm_open (const char *__name, int __oflag, mode_t __mode);
> extern int shm_unlink (const char *__name);
> -------------------------------------------------------------------------------------------------------
>
> FYI:
>
> On the platform:
>
> - Ubuntu 22.10 kinetic kudu
> - gcc 12.2.0
> - same 6.2-rc2
>
> , MADV_PAGEOUT is also defined in bits/mmap-linux.h, so the compile passes.
>
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# grep MADV_PAGEOUT -r /usr/include
> /usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
> /usr/include/x86_64-linux-gnu/bits/mman-linux.h:# define MADV_PAGEOUT 21 /* Reclaim these pages. */
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# grep MADV_PAGEOUT -r ../../../../usr/include
> ../../../../usr/include/asm-generic/mman-common.h:#define MADV_PAGEOUT 21 /* reclaim these pages */
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm#
>
> However, mman-common.h from ../../../../usr/include/asm-generic/mman-common.h is also not included,
> as of "gcc -E", but only bits/mman-linux.h:
>
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | grep mman-common.h
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm# gcc -Wall -E -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../.. -I /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -isystem /home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/../../../usr/include -no-pie cow.c | grep mman-linux.h
> # 1 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 1 3 4
> # 119 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 3 4
> # 120 "/usr/include/x86_64-linux-gnu/bits/mman-linux.h" 2 3 4
> root@marvin-IdeaPad-3-15ITL6:/home/marvin/linux/kernel/linux_torvalds/tools/testing/selftests/vm#
>
> I hope this is enough information for you to debug the issue.
>
> I am standing by for any additional diagnostics needed.
Won't userfaultfd.c fail in a similar way?
Anyhow, khugepaged.c jas
#ifndef MADV_PAGEOUT
#define MADV_PAGEOUT 21
#endif
So most probably we should do the same.
--
Thanks,
David / dhildenb
On 1/9/2023 5:42 PM, David Hildenbrand wrote:
Hi, thank you for your reply.
>> I hope this is enough information for you to debug the issue.
>>
>> I am standing by for any additional diagnostics needed.
>
> Won't userfaultfd.c fail in a similar way?
>
> Anyhow, khugepaged.c jas
>
> #ifndef MADV_PAGEOUT
> #define MADV_PAGEOUT 21
> #endif
>
> So most probably we should do the same.
Actually, David, it turned out that userfaultfd.c compiled
out-of-the-box, and side-by-side comparison showed that it also included
"/home/marvin/linux/kernel/linux_torvalds/usr/include/asm-generic/mman-common.h"
The only remaining difference was including <linux/mman.h>, which fixed
the issue w/o #ifdef ... #endif
Hope this helps.
Please find the following diff.
Regards,
Mirsad
------------------------------------------------------------------------------
diff --git a/tools/testing/selftests/vm/cow.c
b/tools/testing/selftests/vm/cow.c
index 26f6ea3079e2..dd8cf12c6776 100644
--- a/tools/testing/selftests/vm/cow.c
+++ b/tools/testing/selftests/vm/cow.c
@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <assert.h>
+#include <linux/mman.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
--
Mirsad Todorovac
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu
--
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb, Republic of Croatia
tel. +385 (0)1 3711 451
mob. +385 91 57 88 355
On 09.01.23 22:41, Mirsad Goran Todorovac wrote:
> On 1/9/2023 5:42 PM, David Hildenbrand wrote:
>
> Hi, thank you for your reply.
>
>>> I hope this is enough information for you to debug the issue.
>>>
>>> I am standing by for any additional diagnostics needed.
>>
>> Won't userfaultfd.c fail in a similar way?
>>
>> Anyhow, khugepaged.c jas
>>
>> #ifndef MADV_PAGEOUT
>> #define MADV_PAGEOUT 21
>> #endif
>>
>> So most probably we should do the same.
>
> Actually, David, it turned out that userfaultfd.c compiled
> out-of-the-box, and side-by-side comparison showed that it also included
> "/home/marvin/linux/kernel/linux_torvalds/usr/include/asm-generic/mman-common.h"
>
> The only remaining difference was including <linux/mman.h>, which fixed
> the issue w/o #ifdef ... #endif
>
> Hope this helps.
>
> Please find the following diff.
>
> Regards,
> Mirsad
>
> ------------------------------------------------------------------------------
> diff --git a/tools/testing/selftests/vm/cow.c
> b/tools/testing/selftests/vm/cow.c
> index 26f6ea3079e2..dd8cf12c6776 100644
> --- a/tools/testing/selftests/vm/cow.c
> +++ b/tools/testing/selftests/vm/cow.c
> @@ -16,6 +16,7 @@
> #include <fcntl.h>
> #include <dirent.h>
> #include <assert.h>
> +#include <linux/mman.h>
> #include <sys/mman.h>
> #include <sys/ioctl.h>
> #include <sys/wait.h>
>
I already sent a different fix [1]. I suspect when including
linux/mman.h, it would still be problematic with older kernel
headers that lack MADV_PAGEOUT (< v5.4).
But yeah, I saw that userfaultfd.c was fixed that way:
commit b773827e361952b3f53ac6fa4c4e39ccd632102e
Author: Chengming Zhou <[email protected]>
Date: Fri Mar 4 20:29:04 2022 -0800
kselftest/vm: fix tests build with old libc
The error message when I build vm tests on debian10 (GLIBC 2.28):
userfaultfd.c: In function `userfaultfd_pagemap_test':
userfaultfd.c:1393:37: error: `MADV_PAGEOUT' undeclared (first use
in this function); did you mean `MADV_RANDOM'?
if (madvise(area_dst, test_pgsize, MADV_PAGEOUT))
^~~~~~~~~~~~
MADV_RANDOM
This patch includes these newer definitions from UAPI linux/mman.h, is
useful to fix tests build on systems without these definitions in glibc
sys/mman.h.
[1] https://lkml.kernel.org/r/[email protected]
--
Thanks,
David / dhildenb
On 1/10/23 11:05, David Hildenbrand wrote:
> On 09.01.23 22:41, Mirsad Goran Todorovac wrote:
>> On 1/9/2023 5:42 PM, David Hildenbrand wrote:
>>
>> Hi, thank you for your reply.
>>
>>>> I hope this is enough information for you to debug the issue.
>>>>
>>>> I am standing by for any additional diagnostics needed.
>>>
>>> Won't userfaultfd.c fail in a similar way?
>>>
>>> Anyhow, khugepaged.c jas
>>>
>>> #ifndef MADV_PAGEOUT
>>> #define MADV_PAGEOUT 21
>>> #endif
>>>
>>> So most probably we should do the same.
>>
>> Actually, David, it turned out that userfaultfd.c compiled
>> out-of-the-box, and side-by-side comparison showed that it also included
>> "/home/marvin/linux/kernel/linux_torvalds/usr/include/asm-generic/mman-common.h"
>>
>> The only remaining difference was including <linux/mman.h>, which fixed
>> the issue w/o #ifdef ... #endif
>>
>> Hope this helps.
>>
>> Please find the following diff.
>>
>> Regards,
>> Mirsad
>>
>> ------------------------------------------------------------------------------
>> diff --git a/tools/testing/selftests/vm/cow.c
>> b/tools/testing/selftests/vm/cow.c
>> index 26f6ea3079e2..dd8cf12c6776 100644
>> --- a/tools/testing/selftests/vm/cow.c
>> +++ b/tools/testing/selftests/vm/cow.c
>> @@ -16,6 +16,7 @@
>> #include <fcntl.h>
>> #include <dirent.h>
>> #include <assert.h>
>> +#include <linux/mman.h>
>> #include <sys/mman.h>
>> #include <sys/ioctl.h>
>> #include <sys/wait.h>
>>
>
> I already sent a different fix [1]. I suspect when including
> linux/mman.h, it would still be problematic with older kernel
> headers that lack MADV_PAGEOUT (< v5.4).
I see your point.
> But yeah, I saw that userfaultfd.c was fixed that way:
>
> commit b773827e361952b3f53ac6fa4c4e39ccd632102e
> Author: Chengming Zhou <[email protected]>
> Date: Fri Mar 4 20:29:04 2022 -0800
>
> kselftest/vm: fix tests build with old libc
> The error message when I build vm tests on debian10 (GLIBC 2.28):
> userfaultfd.c: In function `userfaultfd_pagemap_test':
> userfaultfd.c:1393:37: error: `MADV_PAGEOUT' undeclared (first use
> in this function); did you mean `MADV_RANDOM'?
> if (madvise(area_dst, test_pgsize, MADV_PAGEOUT))
> ^~~~~~~~~~~~
> MADV_RANDOM
> This patch includes these newer definitions from UAPI linux/mman.h, is
> useful to fix tests build on systems without these definitions in
> glibc
> sys/mman.h.
>
>
> [1] https://lkml.kernel.org/r/[email protected]
You're the boss :)
However, IMHO, having MADV_PAGEOUT defined in three or four places could
make like miserable. OK, it is unlikely to change value, but something
tells me that the right way to do it is to guarantee that the macro
definition is unique.
I don't know what would be the right thing to do in pre-5.4 kernels
w/o MADV_PAGEOUT defined.
Probably then the "(madvise(area_dst, test_pgsize, MADV_PAGEOUT)" gives
EINVAL or is undefined?
--
Mirsad Goran Todorovac
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu
System engineer
Faculty of Graphic Arts | Academy of Fine Arts
University of Zagreb, Republic of Croatia