mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-14 06:22:34 +02:00
The test was not being run by the selftest framework so it was never noticed that it would fail with an assertion failure on configs without support for MAP_DROPPABLE. Update the test so that it is skipped instead when MAP_DROPPABLE is not supported, and add it to the mmap category so that the test is run by the framework. Link: https://lore.kernel.org/20260416033939.49981-4-anthony.yznaga@oracle.com Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: Jason A. Donenfeld <jason@zx2c4.com> Cc: Liam Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pedro Falcato <pfalcato@suse.de> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Mark Brown <broonie@kernel.org> Cc: Vlastimil Babka (SUSE) <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
61 lines
1.3 KiB
C
61 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2024 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <sys/mman.h>
|
|
#include <linux/mman.h>
|
|
|
|
#include "kselftest.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
size_t alloc_size = 134217728;
|
|
size_t page_size = getpagesize();
|
|
void *alloc;
|
|
pid_t child;
|
|
|
|
ksft_print_header();
|
|
ksft_set_plan(1);
|
|
|
|
alloc = mmap(0, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_DROPPABLE, -1, 0);
|
|
if (alloc == MAP_FAILED) {
|
|
if ((errno == EOPNOTSUPP) || (errno == EINVAL)) {
|
|
ksft_test_result_skip("MAP_DROPPABLE not supported\n");
|
|
exit(KSFT_SKIP);
|
|
}
|
|
ksft_test_result_fail("mmap error: %s\n", strerror(errno));
|
|
exit(KSFT_FAIL);
|
|
}
|
|
memset(alloc, 'A', alloc_size);
|
|
for (size_t i = 0; i < alloc_size; i += page_size)
|
|
assert(*(uint8_t *)(alloc + i));
|
|
|
|
child = fork();
|
|
assert(child >= 0);
|
|
if (!child) {
|
|
for (;;)
|
|
*(char *)malloc(page_size) = 'B';
|
|
}
|
|
|
|
for (bool done = false; !done;) {
|
|
for (size_t i = 0; i < alloc_size; i += page_size) {
|
|
if (!*(uint8_t *)(alloc + i)) {
|
|
done = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
kill(child, SIGTERM);
|
|
|
|
ksft_test_result_pass("MAP_DROPPABLE: PASS\n");
|
|
exit(KSFT_PASS);
|
|
}
|