Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/testing/selftests/kselftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
#endif
#define __printf(a, b) __attribute__((format(printf, a, b)))

#ifndef __always_unused
#define __always_unused __attribute__((__unused__))
#endif

#ifndef __maybe_unused
#define __maybe_unused __attribute__((__unused__))
#endif

/* counters */
struct ksft_count {
unsigned int ksft_pass;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ endif
# thus tricking Make (and you!) into believing that All Is Well, in subsequent
# make invocations:
.DELETE_ON_ERROR:

# Avoid accidental wrong builds, due to built-in rules working just a little
# bit too well--but not quite as well as required for our situation here.
#
Expand All @@ -34,6 +33,7 @@ endif
MAKEFLAGS += --no-builtin-rules

CFLAGS = -Wall -O2 -I $(top_srcdir) $(EXTRA_CFLAGS) $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
CFLAGS += -Wunreachable-code -Wunused
LDLIBS = -lrt -lpthread -lm

# Some distributions (such as Ubuntu) configure GCC so that _FORTIFY_SOURCE is
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/compaction_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
return ret;
}

int main(int argc, char **argv)
int main(void)
{
struct rlimit lim;
struct map_list *list = NULL, *entry;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/cow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ static int tests_per_non_anon_test_case(void)
return tests;
}

int main(int argc, char **argv)
int main(void)
{
struct thp_settings default_settings;

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/droppable.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "../kselftest.h"

int main(int argc, char *argv[])
int main(void)
{
size_t alloc_size = 134217728;
size_t page_size = getpagesize();
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/gup_longterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static int tests_per_test_case(void)
return 3 + nr_hugetlbsizes;
}

int main(int argc, char **argv)
int main(void)
{
int i;

Expand Down
5 changes: 2 additions & 3 deletions tools/testing/selftests/mm/hmm-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,11 +2027,10 @@ TEST_F(hmm, hmm_cow_in_device)
if (pid == -1)
ASSERT_EQ(pid, 0);
if (!pid) {
/* Child process waitd for SIGTERM from the parent. */
/* Child process waits for SIGTERM from the parent. */
while (1) {
}
perror("Should not reach this\n");
exit(0);
/* Should not reach this */
}
/* Parent process writes to COW pages(s) and gets a
* new copy in system. In case of device private pages,
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/hugepage-vmemmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static int check_page_flags(unsigned long pfn)
return 0;
}

int main(int argc, char **argv)
int main(void)
{
void *addr;
unsigned long pfn;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/hugetlb-madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void read_fault_pages(void *addr, unsigned long nr_pages)
}
}

int main(int argc, char **argv)
int main(int __always_unused argc, char **argv)
{
unsigned long free_hugepages;
void *addr, *addr2;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/hugetlb-soft-offline.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static void test_soft_offline_common(int enable_soft_offline)
enable_soft_offline);
}

int main(int argc, char **argv)
int main(void)
{
ksft_print_header();
ksft_set_plan(2);
Expand Down
17 changes: 7 additions & 10 deletions tools/testing/selftests/mm/ksm_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ static int ksm_merge_pages(int merge_type, void *addr, size_t size,
return 0;
}

static int ksm_unmerge_pages(void *addr, size_t size,
struct timespec start_time, int timeout)
static int ksm_unmerge_pages(void *addr, size_t size)
{
if (madvise(addr, size, MADV_UNMERGEABLE)) {
perror("madvise");
Expand Down Expand Up @@ -456,7 +455,7 @@ static int get_first_mem_node(void)
return get_next_mem_node(numa_max_node());
}

static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeout,
static int check_ksm_numa_merge(int merge_type, int timeout,
bool merge_across_nodes, size_t page_size)
{
void *numa1_map_ptr, *numa2_map_ptr;
Expand Down Expand Up @@ -520,8 +519,7 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeo
return KSFT_FAIL;
}

static int ksm_merge_hugepages_time(int merge_type, int mapping, int prot,
int timeout, size_t map_size)
static int ksm_merge_hugepages_time(int merge_type, int timeout, size_t map_size)
{
void *map_ptr, *map_ptr_orig;
struct timespec start_time, end_time;
Expand Down Expand Up @@ -656,7 +654,7 @@ static int ksm_unmerge_time(int merge_type, int mapping, int prot, int timeout,
perror("clock_gettime");
goto err_out;
}
if (ksm_unmerge_pages(map_ptr, map_size, start_time, timeout))
if (ksm_unmerge_pages(map_ptr, map_size))
goto err_out;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) {
perror("clock_gettime");
Expand Down Expand Up @@ -884,8 +882,8 @@ int main(int argc, char *argv[])
page_size);
break;
case CHECK_KSM_NUMA_MERGE:
ret = check_ksm_numa_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot,
ksm_scan_limit_sec, merge_across_nodes, page_size);
ret = check_ksm_numa_merge(merge_type, ksm_scan_limit_sec, merge_across_nodes,
page_size);
break;
case KSM_MERGE_TIME:
if (size_MB == 0) {
Expand All @@ -900,8 +898,7 @@ int main(int argc, char *argv[])
printf("Option '-s' is required.\n");
return KSFT_FAIL;
}
ret = ksm_merge_hugepages_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot,
ksm_scan_limit_sec, size_MB);
ret = ksm_merge_hugepages_time(merge_type, ksm_scan_limit_sec, size_MB);
break;
case KSM_UNMERGE_TIME:
if (size_MB == 0) {
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/madv_populate.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int system_has_softdirty(void)
#endif
}

int main(int argc, char **argv)
int main(void)
{
int nr_tests = 16;
int err;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/map_populate.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int child_f(int sock, unsigned long *smap, int fd)
return ksft_cnt.ksft_pass;
}

int main(int argc, char **argv)
int main(void)
{
int sock[2], child, ret;
FILE *ftmp;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/memfd_secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static void prepare(void)

#define NUM_TESTS 6

int main(int argc, char *argv[])
int main(void)
{
int fd;

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/mlock-random-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static void test_mlock_outof_limit(char *p, int alloc_size)
ksft_test_result_pass("%s\n", __func__);
}

int main(int argc, char **argv)
int main(void)
{
char *p = NULL;

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/mlock2-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static void test_mlockall(void)
munlockall();
}

int main(int argc, char **argv)
int main(void)
{
int ret, size = 3 * getpagesize();
void *map;
Expand Down
8 changes: 6 additions & 2 deletions tools/testing/selftests/mm/mseal_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,21 @@ static unsigned int __read_pkey_reg(void)
return pkey_reg;
}

#if defined(__i386__) || defined(__x86_64__) /* arch */
static void __write_pkey_reg(u64 pkey_reg)
{
#if defined(__i386__) || defined(__x86_64__) /* arch */
unsigned int eax = pkey_reg;
unsigned int ecx = 0;
unsigned int edx = 0;

asm volatile(".byte 0x0f,0x01,0xef\n\t"
: : "a" (eax), "c" (ecx), "d" (edx));
#endif
}
#else
static void __write_pkey_reg(u64 __always_unused pkey_reg)
{
}
#endif

static unsigned long pkey_bit_position(int pkey)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/on-fault-limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void test_limit(void)
munlockall();
}

int main(int argc, char **argv)
int main(void)
{
ksft_print_header();
ksft_set_plan(1);
Expand Down
3 changes: 0 additions & 3 deletions tools/testing/selftests/mm/pkey-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ extern void abort_hooks(void);
#ifndef noinline
# define noinline __attribute__((noinline))
#endif
#ifndef __maybe_unused
# define __maybe_unused __attribute__((__unused__))
#endif

int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
int sys_pkey_free(unsigned long pkey);
Expand Down
25 changes: 20 additions & 5 deletions tools/testing/selftests/mm/pkey_sighandler_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,39 @@ static siginfo_t siginfo = {0};
* syscall will attempt to access the PLT in order to call a library function
* which is protected by MPK 0 which we don't have access to.
*/
static inline __always_inline
#ifdef __x86_64__
static __always_inline
long syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
{
unsigned long ret;
#ifdef __x86_64__

register long r10 asm("r10") = a4;
register long r8 asm("r8") = a5;
register long r9 asm("r9") = a6;
asm volatile ("syscall"
: "=a"(ret)
: "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10), "r"(r8), "r"(r9)
: "rcx", "r11", "memory");
return ret;
}
#elif defined __i386__
static __always_inline
long syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long __always_unused a6)
{
unsigned long ret;

asm volatile ("int $0x80"
: "=a"(ret)
: "a"(n), "b"(a1), "c"(a2), "d"(a3), "S"(a4), "D"(a5)
: "memory");
return ret;
}
#elif defined __aarch64__
static __always_inline
long syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
{
unsigned long ret;

register long x0 asm("x0") = a1;
register long x1 asm("x1") = a2;
register long x2 asm("x2") = a3;
Expand All @@ -71,11 +86,11 @@ long syscall_raw(long n, long a1, long a2, long a3, long a4, long a5, long a6)
: "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5), "r"(x8)
: "memory");
ret = x0;
return ret;
}
#else
# error syscall_raw() not implemented
#endif
return ret;
}

static inline long clone_raw(unsigned long flags, void *stack,
int *parent_tid, int *child_tid)
Expand Down Expand Up @@ -528,7 +543,7 @@ static void (*pkey_tests[])(void) = {
test_pkru_sigreturn
};

int main(int argc, char *argv[])
int main(void)
{
int i;

Expand Down
6 changes: 2 additions & 4 deletions tools/testing/selftests/mm/protection_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,11 @@ int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
int nr_iterations = random() % 100;
int ret;

while (0) {
while (nr_iterations-- >= 0) {
int rpkey = alloc_random_pkey();
ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey);
dprintf1("sys_mprotect_pkey(%p, %zx, prot=0x%lx, pkey=%ld) ret: %d\n",
ptr, size, orig_prot, pkey, ret);
if (nr_iterations-- < 0)
break;

dprintf1("%s()::%d, ret: %d pkey_reg: 0x%016llx"
" shadow: 0x%016llx\n",
Expand Down Expand Up @@ -1304,7 +1302,7 @@ static void test_mprotect_with_pkey_0(int *ptr, u16 pkey)

static void test_ptrace_of_child(int *ptr, u16 pkey)
{
__attribute__((__unused__)) int peek_result;
int __always_unused peek_result;
pid_t child_pid;
void *ignored = 0;
long ret;
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/mm/soft-dirty.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void test_vma_reuse(int pagemap_fd, int pagesize)
munmap(map2, pagesize);
}

static void test_hugepage(int pagemap_fd, int pagesize)
static void test_hugepage(int pagemap_fd)
{
char *map;
int i, ret;
Expand Down Expand Up @@ -194,7 +194,7 @@ static void test_mprotect_file(int pagemap_fd, int pagesize)
test_mprotect(pagemap_fd, pagesize, false);
}

int main(int argc, char **argv)
int main(void)
{
int pagemap_fd;
int pagesize;
Expand All @@ -210,7 +210,7 @@ int main(int argc, char **argv)

test_simple(pagemap_fd, pagesize);
test_vma_reuse(pagemap_fd, pagesize);
test_hugepage(pagemap_fd, pagesize);
test_hugepage(pagemap_fd);
test_mprotect_anon(pagemap_fd, pagesize);
test_mprotect_file(pagemap_fd, pagesize);

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/mm/split_huge_page_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void split_file_backed_thp(int order)

status = snprintf(testfile, INPUT_MAX, "%s/thp_file", tmpfs_loc);
if (status >= INPUT_MAX) {
ksft_exit_fail_msg("Fail to create file-backed THP split testing file\n");
ksft_print_msg("Fail to create file-backed THP split testing file\n");
goto cleanup;
}

Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/mm/uffd-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static void continue_range(int ufd, __u64 start, __u64 len, bool wp)
ret, (int64_t) req.mapped);
}

int uffd_read_msg(int ufd, struct uffd_msg *msg)
int uffd_read_msg(struct uffd_msg *msg)
{
int ret = read(uffd, msg, sizeof(*msg));

Expand Down Expand Up @@ -537,7 +537,7 @@ void *uffd_poll_thread(void *arg)
}
if (!(pollfd[0].revents & POLLIN))
err("pollfd[0].revents %d", pollfd[0].revents);
if (uffd_read_msg(uffd, &msg))
if (uffd_read_msg(&msg))
continue;
switch (msg.event) {
default:
Expand Down
Loading
Loading