Re: selftests/vm madv_populate.c test

From: David Hildenbrand
Date: Sat Sep 18 2021 - 03:41:41 EST


On 18.09.21 00:45, Shuah Khan wrote:
Hi David,

I am running into the following warning when try to build this test:

madv_populate.c:334:2: warning: #warning "missing MADV_POPULATE_READ or MADV_POPULATE_WRITE definition" [-Wcpp]
334 | #warning "missing MADV_POPULATE_READ or MADV_POPULATE_WRITE definition"
| ^~~~~~~


I see that the following handling is in place. However there is no
other information to explain why the check is necessary.

#if defined(MADV_POPULATE_READ) && defined(MADV_POPULATE_WRITE)

#else /* defined(MADV_POPULATE_READ) && defined(MADV_POPULATE_WRITE) */

#warning "missing MADV_POPULATE_READ or MADV_POPULATE_WRITE definition"

I do see these defined in:

include/uapi/asm-generic/mman-common.h:#define MADV_POPULATE_READ 22
include/uapi/asm-generic/mman-common.h:#define MADV_POPULATE_WRITE 23

Is this the case of missing include from madv_populate.c?

Hi Shuan,

note that we're including "#include <sys/mman.h>", which in my
understanding maps to the version installed on your system instead
of the one in our build environment.ing.

So as soon as you have a proper kernel + the proper headers installed
and try to build, it would pick up MADV_POPULATE_READ and
MADV_POPULATE_WRITE from the updated headers. That makes sense: you
annot run any MADV_POPULATE_READ/MADV_POPULATE_WRITE tests on a kernel
that doesn't support it.

See vm/userfaultfd.c where we do something similar.


As soon as we have a proper environment, it seems to work just fine:

Linux vm-0 5.15.0-0.rc1.20210915git3ca706c189db.13.fc36.x86_64 #1 SMP Thu Sep 16 11:32:54 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@vm-0 linux]# cat /etc/redhat-release
Fedora release 36 (Rawhide)
[root@vm-0 linux]# cd tools/testing/selftests/vm/
[root@vm-0 vm]# make
make --no-builtin-rules ARCH=x86 -C ../../../.. headers_install
make[1]: Entering directory '/mnt/linux'
INSTALL ./usr/include
make[1]: Leaving directory '/mnt/linux'
gcc -Wall -I ../../../../usr/include -no-pie gup_test.c ../../../../mm/gup_test.h -lrt -lpthread -o /mnt/linux/tools/testing/selftests/vm/gup_test
gcc -Wall -I ../../../../usr/include -no-pie hmm-tests.c local_config.h -lrt -lpthread -o /mnt/linux/tools/testing/selftests/vm/hmm-tests
gcc -Wall -I ../../../../usr/include -no-pie khugepaged.c -lrt -lpthread -o /mnt/linux/tools/testing/selftests/vm/khugepaged
gcc -Wall -I ../../../../usr/include -no-pie madv_populate.c -lrt -lpthread -o /mnt/linux/tools/testing/selftests/vm/madv_populate
...
[root@vm-0 vm]# ./madv_populate
TAP version 13
1..21
# [RUN] test_prot_read
ok 1 MADV_POPULATE_READ with PROT_READ
ok 2 MADV_POPULATE_WRITE with PROT_READ
# [RUN] test_prot_write
ok 3 MADV_POPULATE_READ with PROT_WRITE
ok 4 MADV_POPULATE_WRITE with PROT_WRITE
# [RUN] test_holes
ok 5 MADV_POPULATE_READ with holes in the middle
ok 6 MADV_POPULATE_WRITE with holes in the middle
ok 7 MADV_POPULATE_READ with holes at the end
ok 8 MADV_POPULATE_WRITE with holes at the end
ok 9 MADV_POPULATE_READ with holes at the beginning
ok 10 MADV_POPULATE_WRITE with holes at the beginning
# [RUN] test_populate_read
ok 11 range initially not populated
ok 12 MADV_POPULATE_READ
ok 13 range is populated
# [RUN] test_populate_write
ok 14 range initially not populated
ok 15 MADV_POPULATE_WRITE
ok 16 range is populated
# [RUN] test_softdirty
ok 17 range is not softdirty
ok 18 MADV_POPULATE_READ
ok 19 range is not softdirty
ok 20 MADV_POPULATE_WRITE
ok 21 range is softdirty
# Totals: pass:21 fail:0 xfail:0 xpass:0 skip:0 error:0


Note: I can see that we are generating an /usr/include, but
I think <sys/mman.h> will default to the installed system headers.

--
Thanks,

David / dhildenb