提交 42e584ee 编写于 作者: P Peter Xu 提交者: Linus Torvalds

userfaultfd/selftests: unify error handling

Introduce err()/_err() and replace all the different ways to fail the
program, mostly "fprintf" and "perror" with tons of exit() calls.  Always
stop the test program at any failure.

Link: https://lkml.kernel.org/r/20210412232753.1012412-6-peterx@redhat.comSigned-off-by: NPeter Xu <peterx@redhat.com>
Reviewed-by: NAxel Rasmussen <axelrasmussen@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Joe Perches <joe@perches.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Mina Almasry <almasrymina@google.com>
Cc: Oliver Upton <oupton@google.com>
Cc: Shaohua Li <shli@fb.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Wang Qing <wangqing@vivo.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 de3ca8e4
...@@ -140,11 +140,18 @@ static void usage(void) ...@@ -140,11 +140,18 @@ static void usage(void)
exit(1); exit(1);
} }
#define uffd_error(code, fmt, ...) \ #define _err(fmt, ...) \
do { \ do { \
fprintf(stderr, fmt, ##__VA_ARGS__); \ int ret = errno; \
fprintf(stderr, ": %" PRId64 "\n", (int64_t)(code)); \ fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__); \
exit(1); \ fprintf(stderr, " (errno=%d, line=%d)\n", \
ret, __LINE__); \
} while (0)
#define err(fmt, ...) \
do { \
_err(fmt, ##__VA_ARGS__); \
exit(1); \
} while (0) } while (0)
static void uffd_stats_reset(struct uffd_stats *uffd_stats, static void uffd_stats_reset(struct uffd_stats *uffd_stats,
...@@ -193,44 +200,28 @@ static void uffd_stats_report(struct uffd_stats *stats, int n_cpus) ...@@ -193,44 +200,28 @@ static void uffd_stats_report(struct uffd_stats *stats, int n_cpus)
printf("\n"); printf("\n");
} }
static int anon_release_pages(char *rel_area) static void anon_release_pages(char *rel_area)
{ {
int ret = 0; if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED))
err("madvise(MADV_DONTNEED) failed");
if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) {
perror("madvise");
ret = 1;
}
return ret;
} }
static void anon_allocate_area(void **alloc_area) static void anon_allocate_area(void **alloc_area)
{ {
if (posix_memalign(alloc_area, page_size, nr_pages * page_size)) { if (posix_memalign(alloc_area, page_size, nr_pages * page_size))
fprintf(stderr, "out of memory\n"); err("posix_memalign() failed");
*alloc_area = NULL;
}
} }
static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset)
{ {
} }
/* HugeTLB memory */ static void hugetlb_release_pages(char *rel_area)
static int hugetlb_release_pages(char *rel_area)
{ {
int ret = 0;
if (fallocate(huge_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, if (fallocate(huge_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
rel_area == huge_fd_off0 ? 0 : rel_area == huge_fd_off0 ? 0 : nr_pages * page_size,
nr_pages * page_size, nr_pages * page_size))
nr_pages * page_size)) { err("fallocate() failed");
perror("fallocate");
ret = 1;
}
return ret;
} }
static void hugetlb_allocate_area(void **alloc_area) static void hugetlb_allocate_area(void **alloc_area)
...@@ -243,20 +234,16 @@ static void hugetlb_allocate_area(void **alloc_area) ...@@ -243,20 +234,16 @@ static void hugetlb_allocate_area(void **alloc_area)
MAP_HUGETLB, MAP_HUGETLB,
huge_fd, *alloc_area == area_src ? 0 : huge_fd, *alloc_area == area_src ? 0 :
nr_pages * page_size); nr_pages * page_size);
if (*alloc_area == MAP_FAILED) { if (*alloc_area == MAP_FAILED)
perror("mmap of hugetlbfs file failed"); err("mmap of hugetlbfs file failed");
goto fail;
}
if (map_shared) { if (map_shared) {
area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_HUGETLB, MAP_SHARED | MAP_HUGETLB,
huge_fd, *alloc_area == area_src ? 0 : huge_fd, *alloc_area == area_src ? 0 :
nr_pages * page_size); nr_pages * page_size);
if (area_alias == MAP_FAILED) { if (area_alias == MAP_FAILED)
perror("mmap of hugetlb file alias failed"); err("mmap of hugetlb file alias failed");
goto fail_munmap;
}
} }
if (*alloc_area == area_src) { if (*alloc_area == area_src) {
...@@ -267,16 +254,6 @@ static void hugetlb_allocate_area(void **alloc_area) ...@@ -267,16 +254,6 @@ static void hugetlb_allocate_area(void **alloc_area)
} }
if (area_alias) if (area_alias)
*alloc_area_alias = area_alias; *alloc_area_alias = area_alias;
return;
fail_munmap:
if (munmap(*alloc_area, nr_pages * page_size) < 0) {
perror("hugetlb munmap");
exit(1);
}
fail:
*alloc_area = NULL;
} }
static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset)
...@@ -292,33 +269,24 @@ static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset ...@@ -292,33 +269,24 @@ static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset
*start = (unsigned long) area_dst_alias + offset; *start = (unsigned long) area_dst_alias + offset;
} }
/* Shared memory */ static void shmem_release_pages(char *rel_area)
static int shmem_release_pages(char *rel_area)
{ {
int ret = 0; if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE))
err("madvise(MADV_REMOVE) failed");
if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) {
perror("madvise");
ret = 1;
}
return ret;
} }
static void shmem_allocate_area(void **alloc_area) static void shmem_allocate_area(void **alloc_area)
{ {
*alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED, -1, 0); MAP_ANONYMOUS | MAP_SHARED, -1, 0);
if (*alloc_area == MAP_FAILED) { if (*alloc_area == MAP_FAILED)
fprintf(stderr, "shared memory mmap failed\n"); err("mmap of memfd failed");
*alloc_area = NULL;
}
} }
struct uffd_test_ops { struct uffd_test_ops {
unsigned long expected_ioctls; unsigned long expected_ioctls;
void (*allocate_area)(void **alloc_area); void (*allocate_area)(void **alloc_area);
int (*release_pages)(char *rel_area); void (*release_pages)(char *rel_area);
void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset); void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset);
}; };
...@@ -373,11 +341,8 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp) ...@@ -373,11 +341,8 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp)
/* Undo write-protect, do wakeup after that */ /* Undo write-protect, do wakeup after that */
prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0; prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0;
if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) { if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms))
fprintf(stderr, "clear WP failed for address 0x%" PRIx64 "\n", err("clear WP failed: address=0x%"PRIx64, (uint64_t)start);
(uint64_t)start);
exit(1);
}
} }
static void continue_range(int ufd, __u64 start, __u64 len) static void continue_range(int ufd, __u64 start, __u64 len)
...@@ -388,12 +353,9 @@ static void continue_range(int ufd, __u64 start, __u64 len) ...@@ -388,12 +353,9 @@ static void continue_range(int ufd, __u64 start, __u64 len)
req.range.len = len; req.range.len = len;
req.mode = 0; req.mode = 0;
if (ioctl(ufd, UFFDIO_CONTINUE, &req)) { if (ioctl(ufd, UFFDIO_CONTINUE, &req))
fprintf(stderr, err("UFFDIO_CONTINUE failed for address 0x%" PRIx64,
"UFFDIO_CONTINUE failed for address 0x%" PRIx64 "\n", (uint64_t)start);
(uint64_t)start);
exit(1);
}
} }
static void *locking_thread(void *arg) static void *locking_thread(void *arg)
...@@ -412,10 +374,8 @@ static void *locking_thread(void *arg) ...@@ -412,10 +374,8 @@ static void *locking_thread(void *arg)
seed += cpu; seed += cpu;
bzero(&rand, sizeof(rand)); bzero(&rand, sizeof(rand));
bzero(&randstate, sizeof(randstate)); bzero(&randstate, sizeof(randstate));
if (initstate_r(seed, randstate, sizeof(randstate), &rand)) { if (initstate_r(seed, randstate, sizeof(randstate), &rand))
fprintf(stderr, "srandom_r error\n"); err("initstate_r failed");
exit(1);
}
} else { } else {
page_nr = -bounces; page_nr = -bounces;
if (!(bounces & BOUNCE_RACINGFAULTS)) if (!(bounces & BOUNCE_RACINGFAULTS))
...@@ -424,16 +384,12 @@ static void *locking_thread(void *arg) ...@@ -424,16 +384,12 @@ static void *locking_thread(void *arg)
while (!finished) { while (!finished) {
if (bounces & BOUNCE_RANDOM) { if (bounces & BOUNCE_RANDOM) {
if (random_r(&rand, &rand_nr)) { if (random_r(&rand, &rand_nr))
fprintf(stderr, "random_r 1 error\n"); err("random_r failed");
exit(1);
}
page_nr = rand_nr; page_nr = rand_nr;
if (sizeof(page_nr) > sizeof(rand_nr)) { if (sizeof(page_nr) > sizeof(rand_nr)) {
if (random_r(&rand, &rand_nr)) { if (random_r(&rand, &rand_nr))
fprintf(stderr, "random_r 2 error\n"); err("random_r failed");
exit(1);
}
page_nr |= (((unsigned long) rand_nr) << 16) << page_nr |= (((unsigned long) rand_nr) << 16) <<
16; 16;
} }
...@@ -442,12 +398,9 @@ static void *locking_thread(void *arg) ...@@ -442,12 +398,9 @@ static void *locking_thread(void *arg)
page_nr %= nr_pages; page_nr %= nr_pages;
pthread_mutex_lock(area_mutex(area_dst, page_nr)); pthread_mutex_lock(area_mutex(area_dst, page_nr));
count = *area_count(area_dst, page_nr); count = *area_count(area_dst, page_nr);
if (count != count_verify[page_nr]) { if (count != count_verify[page_nr])
fprintf(stderr, err("page_nr %lu memory corruption %llu %llu",
"page_nr %lu memory corruption %Lu %Lu\n", page_nr, count, count_verify[page_nr]);
page_nr, count,
count_verify[page_nr]); exit(1);
}
count++; count++;
*area_count(area_dst, page_nr) = count_verify[page_nr] = count; *area_count(area_dst, page_nr) = count_verify[page_nr] = count;
pthread_mutex_unlock(area_mutex(area_dst, page_nr)); pthread_mutex_unlock(area_mutex(area_dst, page_nr));
...@@ -464,22 +417,21 @@ static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy, ...@@ -464,22 +417,21 @@ static void retry_copy_page(int ufd, struct uffdio_copy *uffdio_copy,
offset); offset);
if (ioctl(ufd, UFFDIO_COPY, uffdio_copy)) { if (ioctl(ufd, UFFDIO_COPY, uffdio_copy)) {
/* real retval in ufdio_copy.copy */ /* real retval in ufdio_copy.copy */
if (uffdio_copy->copy != -EEXIST) { if (uffdio_copy->copy != -EEXIST)
uffd_error(uffdio_copy->copy, err("UFFDIO_COPY retry error: %"PRId64,
"UFFDIO_COPY retry error"); (int64_t)uffdio_copy->copy);
} } else {
} else err("UFFDIO_COPY retry unexpected: %"PRId64,
uffd_error(uffdio_copy->copy, "UFFDIO_COPY retry unexpected"); (int64_t)uffdio_copy->copy);
}
} }
static int __copy_page(int ufd, unsigned long offset, bool retry) static int __copy_page(int ufd, unsigned long offset, bool retry)
{ {
struct uffdio_copy uffdio_copy; struct uffdio_copy uffdio_copy;
if (offset >= nr_pages * page_size) { if (offset >= nr_pages * page_size)
fprintf(stderr, "unexpected offset %lu\n", offset); err("unexpected offset %lu\n", offset);
exit(1);
}
uffdio_copy.dst = (unsigned long) area_dst + offset; uffdio_copy.dst = (unsigned long) area_dst + offset;
uffdio_copy.src = (unsigned long) area_src + offset; uffdio_copy.src = (unsigned long) area_src + offset;
uffdio_copy.len = page_size; uffdio_copy.len = page_size;
...@@ -491,9 +443,10 @@ static int __copy_page(int ufd, unsigned long offset, bool retry) ...@@ -491,9 +443,10 @@ static int __copy_page(int ufd, unsigned long offset, bool retry)
if (ioctl(ufd, UFFDIO_COPY, &uffdio_copy)) { if (ioctl(ufd, UFFDIO_COPY, &uffdio_copy)) {
/* real retval in ufdio_copy.copy */ /* real retval in ufdio_copy.copy */
if (uffdio_copy.copy != -EEXIST) if (uffdio_copy.copy != -EEXIST)
uffd_error(uffdio_copy.copy, "UFFDIO_COPY error"); err("UFFDIO_COPY error: %"PRId64,
(int64_t)uffdio_copy.copy);
} else if (uffdio_copy.copy != page_size) { } else if (uffdio_copy.copy != page_size) {
uffd_error(uffdio_copy.copy, "UFFDIO_COPY unexpected copy"); err("UFFDIO_COPY error: %"PRId64, (int64_t)uffdio_copy.copy);
} else { } else {
if (test_uffdio_copy_eexist && retry) { if (test_uffdio_copy_eexist && retry) {
test_uffdio_copy_eexist = false; test_uffdio_copy_eexist = false;
...@@ -522,11 +475,10 @@ static int uffd_read_msg(int ufd, struct uffd_msg *msg) ...@@ -522,11 +475,10 @@ static int uffd_read_msg(int ufd, struct uffd_msg *msg)
if (ret < 0) { if (ret < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
return 1; return 1;
perror("blocking read error"); err("blocking read error");
} else { } else {
fprintf(stderr, "short read\n"); err("short read");
} }
exit(1);
} }
return 0; return 0;
...@@ -537,10 +489,8 @@ static void uffd_handle_page_fault(struct uffd_msg *msg, ...@@ -537,10 +489,8 @@ static void uffd_handle_page_fault(struct uffd_msg *msg,
{ {
unsigned long offset; unsigned long offset;
if (msg->event != UFFD_EVENT_PAGEFAULT) { if (msg->event != UFFD_EVENT_PAGEFAULT)
fprintf(stderr, "unexpected msg event %u\n", msg->event); err("unexpected msg event %u", msg->event);
exit(1);
}
if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) {
/* Write protect page faults */ /* Write protect page faults */
...@@ -571,10 +521,8 @@ static void uffd_handle_page_fault(struct uffd_msg *msg, ...@@ -571,10 +521,8 @@ static void uffd_handle_page_fault(struct uffd_msg *msg,
stats->minor_faults++; stats->minor_faults++;
} else { } else {
/* Missing page faults */ /* Missing page faults */
if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) { if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE)
fprintf(stderr, "unexpected write fault\n"); err("unexpected write fault");
exit(1);
}
offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst;
offset &= ~(page_size-1); offset &= ~(page_size-1);
...@@ -601,32 +549,20 @@ static void *uffd_poll_thread(void *arg) ...@@ -601,32 +549,20 @@ static void *uffd_poll_thread(void *arg)
for (;;) { for (;;) {
ret = poll(pollfd, 2, -1); ret = poll(pollfd, 2, -1);
if (!ret) { if (ret <= 0)
fprintf(stderr, "poll error %d\n", ret); err("poll error: %d", ret);
exit(1);
}
if (ret < 0) {
perror("poll");
exit(1);
}
if (pollfd[1].revents & POLLIN) { if (pollfd[1].revents & POLLIN) {
if (read(pollfd[1].fd, &tmp_chr, 1) != 1) { if (read(pollfd[1].fd, &tmp_chr, 1) != 1)
fprintf(stderr, "read pipefd error\n"); err("read pipefd error");
exit(1);
}
break; break;
} }
if (!(pollfd[0].revents & POLLIN)) { if (!(pollfd[0].revents & POLLIN))
fprintf(stderr, "pollfd[0].revents %d\n", err("pollfd[0].revents %d", pollfd[0].revents);
pollfd[0].revents);
exit(1);
}
if (uffd_read_msg(uffd, &msg)) if (uffd_read_msg(uffd, &msg))
continue; continue;
switch (msg.event) { switch (msg.event) {
default: default:
fprintf(stderr, "unexpected msg event %u\n", err("unexpected msg event %u\n", msg.event);
msg.event); exit(1);
break; break;
case UFFD_EVENT_PAGEFAULT: case UFFD_EVENT_PAGEFAULT:
uffd_handle_page_fault(&msg, stats); uffd_handle_page_fault(&msg, stats);
...@@ -640,10 +576,8 @@ static void *uffd_poll_thread(void *arg) ...@@ -640,10 +576,8 @@ static void *uffd_poll_thread(void *arg)
uffd_reg.range.start = msg.arg.remove.start; uffd_reg.range.start = msg.arg.remove.start;
uffd_reg.range.len = msg.arg.remove.end - uffd_reg.range.len = msg.arg.remove.end -
msg.arg.remove.start; msg.arg.remove.start;
if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range)) { if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range))
fprintf(stderr, "remove failure\n"); err("remove failure");
exit(1);
}
break; break;
case UFFD_EVENT_REMAP: case UFFD_EVENT_REMAP:
area_dst = (char *)(unsigned long)msg.arg.remap.to; area_dst = (char *)(unsigned long)msg.arg.remap.to;
...@@ -746,9 +680,7 @@ static int stress(struct uffd_stats *uffd_stats) ...@@ -746,9 +680,7 @@ static int stress(struct uffd_stats *uffd_stats)
* UFFDIO_COPY without writing zero pages into area_dst * UFFDIO_COPY without writing zero pages into area_dst
* because the background threads already completed). * because the background threads already completed).
*/ */
if (uffd_test_ops->release_pages(area_src)) uffd_test_ops->release_pages(area_src);
return 1;
finished = 1; finished = 1;
for (cpu = 0; cpu < nr_cpus; cpu++) for (cpu = 0; cpu < nr_cpus; cpu++)
...@@ -758,10 +690,8 @@ static int stress(struct uffd_stats *uffd_stats) ...@@ -758,10 +690,8 @@ static int stress(struct uffd_stats *uffd_stats)
for (cpu = 0; cpu < nr_cpus; cpu++) { for (cpu = 0; cpu < nr_cpus; cpu++) {
char c; char c;
if (bounces & BOUNCE_POLL) { if (bounces & BOUNCE_POLL) {
if (write(pipefd[cpu*2+1], &c, 1) != 1) { if (write(pipefd[cpu*2+1], &c, 1) != 1)
fprintf(stderr, "pipefd write error\n"); err("pipefd write error");
return 1;
}
if (pthread_join(uffd_threads[cpu], if (pthread_join(uffd_threads[cpu],
(void *)&uffd_stats[cpu])) (void *)&uffd_stats[cpu]))
return 1; return 1;
...@@ -861,10 +791,8 @@ static int faulting_process(int signal_test) ...@@ -861,10 +791,8 @@ static int faulting_process(int signal_test)
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
act.sa_sigaction = sighndl; act.sa_sigaction = sighndl;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
if (sigaction(SIGBUS, &act, 0)) { if (sigaction(SIGBUS, &act, 0))
perror("sigaction"); err("sigaction");
return 1;
}
lastnr = (unsigned long)-1; lastnr = (unsigned long)-1;
} }
...@@ -874,10 +802,8 @@ static int faulting_process(int signal_test) ...@@ -874,10 +802,8 @@ static int faulting_process(int signal_test)
if (signal_test) { if (signal_test) {
if (sigsetjmp(*sigbuf, 1) != 0) { if (sigsetjmp(*sigbuf, 1) != 0) {
if (steps == 1 && nr == lastnr) { if (steps == 1 && nr == lastnr)
fprintf(stderr, "Signal repeated\n"); err("Signal repeated");
return 1;
}
lastnr = nr; lastnr = nr;
if (signal_test == 1) { if (signal_test == 1) {
...@@ -902,12 +828,9 @@ static int faulting_process(int signal_test) ...@@ -902,12 +828,9 @@ static int faulting_process(int signal_test)
} }
count = *area_count(area_dst, nr); count = *area_count(area_dst, nr);
if (count != count_verify[nr]) { if (count != count_verify[nr])
fprintf(stderr, err("nr %lu memory corruption %llu %llu\n",
"nr %lu memory corruption %Lu %Lu\n", nr, count, count_verify[nr]);
nr, count,
count_verify[nr]);
}
/* /*
* Trigger write protection if there is by writing * Trigger write protection if there is by writing
* the same value back. * the same value back.
...@@ -923,18 +846,14 @@ static int faulting_process(int signal_test) ...@@ -923,18 +846,14 @@ static int faulting_process(int signal_test)
area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size, area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size,
MREMAP_MAYMOVE | MREMAP_FIXED, area_src); MREMAP_MAYMOVE | MREMAP_FIXED, area_src);
if (area_dst == MAP_FAILED) { if (area_dst == MAP_FAILED)
perror("mremap"); err("mremap");
exit(1);
}
for (; nr < nr_pages; nr++) { for (; nr < nr_pages; nr++) {
count = *area_count(area_dst, nr); count = *area_count(area_dst, nr);
if (count != count_verify[nr]) { if (count != count_verify[nr]) {
fprintf(stderr, err("nr %lu memory corruption %llu %llu\n",
"nr %lu memory corruption %Lu %Lu\n", nr, count, count_verify[nr]);
nr, count,
count_verify[nr]); exit(1);
} }
/* /*
* Trigger write protection if there is by writing * Trigger write protection if there is by writing
...@@ -943,15 +862,11 @@ static int faulting_process(int signal_test) ...@@ -943,15 +862,11 @@ static int faulting_process(int signal_test)
*area_count(area_dst, nr) = count; *area_count(area_dst, nr) = count;
} }
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
for (nr = 0; nr < nr_pages; nr++) { for (nr = 0; nr < nr_pages; nr++)
if (my_bcmp(area_dst + nr * page_size, zeropage, page_size)) { if (my_bcmp(area_dst + nr * page_size, zeropage, page_size))
fprintf(stderr, "nr %lu is not zero\n", nr); err("nr %lu is not zero", nr);
exit(1);
}
}
return 0; return 0;
} }
...@@ -964,13 +879,12 @@ static void retry_uffdio_zeropage(int ufd, ...@@ -964,13 +879,12 @@ static void retry_uffdio_zeropage(int ufd,
uffdio_zeropage->range.len, uffdio_zeropage->range.len,
offset); offset);
if (ioctl(ufd, UFFDIO_ZEROPAGE, uffdio_zeropage)) { if (ioctl(ufd, UFFDIO_ZEROPAGE, uffdio_zeropage)) {
if (uffdio_zeropage->zeropage != -EEXIST) { if (uffdio_zeropage->zeropage != -EEXIST)
uffd_error(uffdio_zeropage->zeropage, err("UFFDIO_ZEROPAGE error: %"PRId64,
"UFFDIO_ZEROPAGE retry error"); (int64_t)uffdio_zeropage->zeropage);
}
} else { } else {
uffd_error(uffdio_zeropage->zeropage, err("UFFDIO_ZEROPAGE error: %"PRId64,
"UFFDIO_ZEROPAGE retry unexpected"); (int64_t)uffdio_zeropage->zeropage);
} }
} }
...@@ -983,10 +897,8 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) ...@@ -983,10 +897,8 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE); has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE);
if (offset >= nr_pages * page_size) { if (offset >= nr_pages * page_size)
fprintf(stderr, "unexpected offset %lu\n", offset); err("unexpected offset %lu", offset);
exit(1);
}
uffdio_zeropage.range.start = (unsigned long) area_dst + offset; uffdio_zeropage.range.start = (unsigned long) area_dst + offset;
uffdio_zeropage.range.len = page_size; uffdio_zeropage.range.len = page_size;
uffdio_zeropage.mode = 0; uffdio_zeropage.mode = 0;
...@@ -994,14 +906,13 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) ...@@ -994,14 +906,13 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
res = uffdio_zeropage.zeropage; res = uffdio_zeropage.zeropage;
if (ret) { if (ret) {
/* real retval in ufdio_zeropage.zeropage */ /* real retval in ufdio_zeropage.zeropage */
if (has_zeropage) { if (has_zeropage)
uffd_error(res, "UFFDIO_ZEROPAGE %s", err("UFFDIO_ZEROPAGE error: %"PRId64, (int64_t)res);
res == -EEXIST ? "-EEXIST" : "error"); else if (res != -EINVAL)
} else if (res != -EINVAL) err("UFFDIO_ZEROPAGE not -EINVAL");
uffd_error(res, "UFFDIO_ZEROPAGE not -EINVAL");
} else if (has_zeropage) { } else if (has_zeropage) {
if (res != page_size) { if (res != page_size) {
uffd_error(res, "UFFDIO_ZEROPAGE unexpected"); err("UFFDIO_ZEROPAGE unexpected size");
} else { } else {
if (test_uffdio_zeropage_eexist && retry) { if (test_uffdio_zeropage_eexist && retry) {
test_uffdio_zeropage_eexist = false; test_uffdio_zeropage_eexist = false;
...@@ -1011,7 +922,7 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) ...@@ -1011,7 +922,7 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry)
return 1; return 1;
} }
} else } else
uffd_error(res, "UFFDIO_ZEROPAGE succeeded"); err("UFFDIO_ZEROPAGE succeeded");
return 0; return 0;
} }
...@@ -1030,8 +941,7 @@ static int userfaultfd_zeropage_test(void) ...@@ -1030,8 +941,7 @@ static int userfaultfd_zeropage_test(void)
printf("testing UFFDIO_ZEROPAGE: "); printf("testing UFFDIO_ZEROPAGE: ");
fflush(stdout); fflush(stdout);
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
if (userfaultfd_open(0)) if (userfaultfd_open(0))
return 1; return 1;
...@@ -1040,25 +950,16 @@ static int userfaultfd_zeropage_test(void) ...@@ -1040,25 +950,16 @@ static int userfaultfd_zeropage_test(void)
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (test_uffdio_wp) if (test_uffdio_wp)
uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure\n"); err("register failure");
exit(1);
}
expected_ioctls = uffd_test_ops->expected_ioctls; expected_ioctls = uffd_test_ops->expected_ioctls;
if ((uffdio_register.ioctls & expected_ioctls) != if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls)
expected_ioctls) { err("unexpected missing ioctl for anon memory");
fprintf(stderr,
"unexpected missing ioctl for anon memory\n");
exit(1);
}
if (uffdio_zeropage(uffd, 0)) { if (uffdio_zeropage(uffd, 0))
if (my_bcmp(area_dst, zeropage, page_size)) { if (my_bcmp(area_dst, zeropage, page_size))
fprintf(stderr, "zeropage is not zero\n"); err("zeropage is not zero");
exit(1);
}
}
close(uffd); close(uffd);
printf("done.\n"); printf("done.\n");
...@@ -1078,8 +979,7 @@ static int userfaultfd_events_test(void) ...@@ -1078,8 +979,7 @@ static int userfaultfd_events_test(void)
printf("testing events (fork, remap, remove): "); printf("testing events (fork, remap, remove): ");
fflush(stdout); fflush(stdout);
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP | features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP |
UFFD_FEATURE_EVENT_REMOVE; UFFD_FEATURE_EVENT_REMOVE;
...@@ -1092,41 +992,28 @@ static int userfaultfd_events_test(void) ...@@ -1092,41 +992,28 @@ static int userfaultfd_events_test(void)
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (test_uffdio_wp) if (test_uffdio_wp)
uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure\n"); err("register failure");
exit(1);
}
expected_ioctls = uffd_test_ops->expected_ioctls; expected_ioctls = uffd_test_ops->expected_ioctls;
if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) { if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls)
fprintf(stderr, "unexpected missing ioctl for anon memory\n"); err("unexpected missing ioctl for anon memory");
exit(1);
}
if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) { if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
perror("uffd_poll_thread create"); err("uffd_poll_thread create");
exit(1);
}
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0)
perror("fork"); err("fork");
exit(1);
}
if (!pid) if (!pid)
exit(faulting_process(0)); exit(faulting_process(0));
waitpid(pid, &err, 0); waitpid(pid, &err, 0);
if (err) { if (err)
fprintf(stderr, "faulting process failed\n"); err("faulting process failed");
exit(1); if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
} err("pipe write");
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) {
perror("pipe write");
exit(1);
}
if (pthread_join(uffd_mon, NULL)) if (pthread_join(uffd_mon, NULL))
return 1; return 1;
...@@ -1151,8 +1038,7 @@ static int userfaultfd_sig_test(void) ...@@ -1151,8 +1038,7 @@ static int userfaultfd_sig_test(void)
printf("testing signal delivery: "); printf("testing signal delivery: ");
fflush(stdout); fflush(stdout);
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
features = UFFD_FEATURE_EVENT_FORK|UFFD_FEATURE_SIGBUS; features = UFFD_FEATURE_EVENT_FORK|UFFD_FEATURE_SIGBUS;
if (userfaultfd_open(features)) if (userfaultfd_open(features))
...@@ -1164,57 +1050,41 @@ static int userfaultfd_sig_test(void) ...@@ -1164,57 +1050,41 @@ static int userfaultfd_sig_test(void)
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (test_uffdio_wp) if (test_uffdio_wp)
uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure\n"); err("register failure");
exit(1);
}
expected_ioctls = uffd_test_ops->expected_ioctls; expected_ioctls = uffd_test_ops->expected_ioctls;
if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) { if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls)
fprintf(stderr, "unexpected missing ioctl for anon memory\n"); err("unexpected missing ioctl for anon memory");
exit(1);
}
if (faulting_process(1)) { if (faulting_process(1))
fprintf(stderr, "faulting process failed\n"); err("faulting process failed");
exit(1);
}
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) { if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
perror("uffd_poll_thread create"); err("uffd_poll_thread create");
exit(1);
}
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0)
perror("fork"); err("fork");
exit(1);
}
if (!pid) if (!pid)
exit(faulting_process(2)); exit(faulting_process(2));
waitpid(pid, &err, 0); waitpid(pid, &err, 0);
if (err) { if (err)
fprintf(stderr, "faulting process failed\n"); err("faulting process failed");
exit(1); if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
} err("pipe write");
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) {
perror("pipe write");
exit(1);
}
if (pthread_join(uffd_mon, (void **)&userfaults)) if (pthread_join(uffd_mon, (void **)&userfaults))
return 1; return 1;
printf("done.\n"); printf("done.\n");
if (userfaults) if (userfaults)
fprintf(stderr, "Signal test failed, userfaults: %ld\n", err("Signal test failed, userfaults: %ld", userfaults);
userfaults);
close(uffd); close(uffd);
return userfaults != 0; return userfaults != 0;
} }
...@@ -1236,8 +1106,7 @@ static int userfaultfd_minor_test(void) ...@@ -1236,8 +1106,7 @@ static int userfaultfd_minor_test(void)
printf("testing minor faults: "); printf("testing minor faults: ");
fflush(stdout); fflush(stdout);
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
if (userfaultfd_open_ext(&features)) if (userfaultfd_open_ext(&features))
return 1; return 1;
...@@ -1251,17 +1120,13 @@ static int userfaultfd_minor_test(void) ...@@ -1251,17 +1120,13 @@ static int userfaultfd_minor_test(void)
uffdio_register.range.start = (unsigned long)area_dst_alias; uffdio_register.range.start = (unsigned long)area_dst_alias;
uffdio_register.range.len = nr_pages * page_size; uffdio_register.range.len = nr_pages * page_size;
uffdio_register.mode = UFFDIO_REGISTER_MODE_MINOR; uffdio_register.mode = UFFDIO_REGISTER_MODE_MINOR;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure\n"); err("register failure");
exit(1);
}
expected_ioctls = uffd_test_ops->expected_ioctls; expected_ioctls = uffd_test_ops->expected_ioctls;
expected_ioctls |= 1 << _UFFDIO_CONTINUE; expected_ioctls |= 1 << _UFFDIO_CONTINUE;
if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) { if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls)
fprintf(stderr, "unexpected missing ioctl(s)\n"); err("unexpected missing ioctl(s)");
exit(1);
}
/* /*
* After registering with UFFD, populate the non-UFFD-registered side of * After registering with UFFD, populate the non-UFFD-registered side of
...@@ -1272,10 +1137,8 @@ static int userfaultfd_minor_test(void) ...@@ -1272,10 +1137,8 @@ static int userfaultfd_minor_test(void)
page_size); page_size);
} }
if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats)) { if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
perror("uffd_poll_thread create"); err("uffd_poll_thread create");
exit(1);
}
/* /*
* Read each of the pages back using the UFFD-registered mapping. We * Read each of the pages back using the UFFD-registered mapping. We
...@@ -1284,26 +1147,19 @@ static int userfaultfd_minor_test(void) ...@@ -1284,26 +1147,19 @@ static int userfaultfd_minor_test(void)
* page's contents, and then issuing a CONTINUE ioctl. * page's contents, and then issuing a CONTINUE ioctl.
*/ */
if (posix_memalign(&expected_page, page_size, page_size)) { if (posix_memalign(&expected_page, page_size, page_size))
fprintf(stderr, "out of memory\n"); err("out of memory");
return 1;
}
for (p = 0; p < nr_pages; ++p) { for (p = 0; p < nr_pages; ++p) {
expected_byte = ~((uint8_t)(p % ((uint8_t)-1))); expected_byte = ~((uint8_t)(p % ((uint8_t)-1)));
memset(expected_page, expected_byte, page_size); memset(expected_page, expected_byte, page_size);
if (my_bcmp(expected_page, area_dst_alias + (p * page_size), if (my_bcmp(expected_page, area_dst_alias + (p * page_size),
page_size)) { page_size))
fprintf(stderr, err("unexpected page contents after minor fault");
"unexpected page contents after minor fault\n");
exit(1);
}
} }
if (write(pipefd[1], &c, sizeof(c)) != sizeof(c)) { if (write(pipefd[1], &c, sizeof(c)) != sizeof(c))
perror("pipe write"); err("pipe write");
exit(1);
}
if (pthread_join(uffd_mon, NULL)) if (pthread_join(uffd_mon, NULL))
return 1; return 1;
...@@ -1321,7 +1177,6 @@ static int userfaultfd_stress(void) ...@@ -1321,7 +1177,6 @@ static int userfaultfd_stress(void)
unsigned long nr; unsigned long nr;
struct uffdio_register uffdio_register; struct uffdio_register uffdio_register;
unsigned long cpu; unsigned long cpu;
int err;
struct uffd_stats uffd_stats[nr_cpus]; struct uffd_stats uffd_stats[nr_cpus];
uffd_test_ops->allocate_area((void **)&area_src); uffd_test_ops->allocate_area((void **)&area_src);
...@@ -1366,10 +1221,8 @@ static int userfaultfd_stress(void) ...@@ -1366,10 +1221,8 @@ static int userfaultfd_stress(void)
} }
} }
if (posix_memalign(&area, page_size, page_size)) { if (posix_memalign(&area, page_size, page_size))
fprintf(stderr, "out of memory\n"); err("out of memory");
return 1;
}
zeropage = area; zeropage = area;
bzero(zeropage, page_size); bzero(zeropage, page_size);
...@@ -1378,7 +1231,6 @@ static int userfaultfd_stress(void) ...@@ -1378,7 +1231,6 @@ static int userfaultfd_stress(void)
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 16*1024*1024); pthread_attr_setstacksize(&attr, 16*1024*1024);
err = 0;
while (bounces--) { while (bounces--) {
unsigned long expected_ioctls; unsigned long expected_ioctls;
...@@ -1407,25 +1259,18 @@ static int userfaultfd_stress(void) ...@@ -1407,25 +1259,18 @@ static int userfaultfd_stress(void)
uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
if (test_uffdio_wp) if (test_uffdio_wp)
uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP; uffdio_register.mode |= UFFDIO_REGISTER_MODE_WP;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure\n"); err("register failure");
return 1;
}
expected_ioctls = uffd_test_ops->expected_ioctls; expected_ioctls = uffd_test_ops->expected_ioctls;
if ((uffdio_register.ioctls & expected_ioctls) != if ((uffdio_register.ioctls & expected_ioctls) !=
expected_ioctls) { expected_ioctls)
fprintf(stderr, err("unexpected missing ioctl for anon memory");
"unexpected missing ioctl for anon memory\n");
return 1;
}
if (area_dst_alias) { if (area_dst_alias) {
uffdio_register.range.start = (unsigned long) uffdio_register.range.start = (unsigned long)
area_dst_alias; area_dst_alias;
if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register)) { if (ioctl(uffd, UFFDIO_REGISTER, &uffdio_register))
fprintf(stderr, "register failure alias\n"); err("register failure alias");
return 1;
}
} }
/* /*
...@@ -1452,8 +1297,7 @@ static int userfaultfd_stress(void) ...@@ -1452,8 +1297,7 @@ static int userfaultfd_stress(void)
* MADV_DONTNEED only after the UFFDIO_REGISTER, so it's * MADV_DONTNEED only after the UFFDIO_REGISTER, so it's
* required to MADV_DONTNEED here. * required to MADV_DONTNEED here.
*/ */
if (uffd_test_ops->release_pages(area_dst)) uffd_test_ops->release_pages(area_dst);
return 1;
uffd_stats_reset(uffd_stats, nr_cpus); uffd_stats_reset(uffd_stats, nr_cpus);
...@@ -1467,33 +1311,22 @@ static int userfaultfd_stress(void) ...@@ -1467,33 +1311,22 @@ static int userfaultfd_stress(void)
nr_pages * page_size, false); nr_pages * page_size, false);
/* unregister */ /* unregister */
if (ioctl(uffd, UFFDIO_UNREGISTER, &uffdio_register.range)) { if (ioctl(uffd, UFFDIO_UNREGISTER, &uffdio_register.range))
fprintf(stderr, "unregister failure\n"); err("unregister failure");
return 1;
}
if (area_dst_alias) { if (area_dst_alias) {
uffdio_register.range.start = (unsigned long) area_dst; uffdio_register.range.start = (unsigned long) area_dst;
if (ioctl(uffd, UFFDIO_UNREGISTER, if (ioctl(uffd, UFFDIO_UNREGISTER,
&uffdio_register.range)) { &uffdio_register.range))
fprintf(stderr, "unregister failure alias\n"); err("unregister failure alias");
return 1;
}
} }
/* verification */ /* verification */
if (bounces & BOUNCE_VERIFY) { if (bounces & BOUNCE_VERIFY)
for (nr = 0; nr < nr_pages; nr++) { for (nr = 0; nr < nr_pages; nr++)
if (*area_count(area_dst, nr) != count_verify[nr]) { if (*area_count(area_dst, nr) != count_verify[nr])
fprintf(stderr, err("error area_count %llu %llu %lu\n",
"error area_count %Lu %Lu %lu\n", *area_count(area_src, nr),
*area_count(area_src, nr), count_verify[nr], nr);
count_verify[nr],
nr);
err = 1;
bounces = 0;
}
}
}
/* prepare next bounce */ /* prepare next bounce */
tmp_area = area_src; tmp_area = area_src;
...@@ -1507,9 +1340,6 @@ static int userfaultfd_stress(void) ...@@ -1507,9 +1340,6 @@ static int userfaultfd_stress(void)
uffd_stats_report(uffd_stats, nr_cpus); uffd_stats_report(uffd_stats, nr_cpus);
} }
if (err)
return err;
close(uffd); close(uffd);
return userfaultfd_zeropage_test() || userfaultfd_sig_test() return userfaultfd_zeropage_test() || userfaultfd_sig_test()
|| userfaultfd_events_test() || userfaultfd_minor_test(); || userfaultfd_events_test() || userfaultfd_minor_test();
...@@ -1560,7 +1390,7 @@ static void set_test_type(const char *type) ...@@ -1560,7 +1390,7 @@ static void set_test_type(const char *type)
test_type = TEST_SHMEM; test_type = TEST_SHMEM;
uffd_test_ops = &shmem_uffd_test_ops; uffd_test_ops = &shmem_uffd_test_ops;
} else { } else {
fprintf(stderr, "Unknown test type: %s\n", type); exit(1); err("Unknown test type: %s", type);
} }
if (test_type == TEST_HUGETLB) if (test_type == TEST_HUGETLB)
...@@ -1568,15 +1398,11 @@ static void set_test_type(const char *type) ...@@ -1568,15 +1398,11 @@ static void set_test_type(const char *type)
else else
page_size = sysconf(_SC_PAGE_SIZE); page_size = sysconf(_SC_PAGE_SIZE);
if (!page_size) { if (!page_size)
fprintf(stderr, "Unable to determine page size\n"); err("Unable to determine page size");
exit(2);
}
if ((unsigned long) area_count(NULL, 0) + sizeof(unsigned long long) * 2 if ((unsigned long) area_count(NULL, 0) + sizeof(unsigned long long) * 2
> page_size) { > page_size)
fprintf(stderr, "Impossible to run this test\n"); err("Impossible to run this test");
exit(2);
}
} }
static void sigalrm(int sig) static void sigalrm(int sig)
...@@ -1593,10 +1419,8 @@ int main(int argc, char **argv) ...@@ -1593,10 +1419,8 @@ int main(int argc, char **argv)
if (argc < 4) if (argc < 4)
usage(); usage();
if (signal(SIGALRM, sigalrm) == SIG_ERR) { if (signal(SIGALRM, sigalrm) == SIG_ERR)
fprintf(stderr, "failed to arm SIGALRM"); err("failed to arm SIGALRM");
exit(1);
}
alarm(ALARM_INTERVAL_SECS); alarm(ALARM_INTERVAL_SECS);
set_test_type(argv[1]); set_test_type(argv[1]);
...@@ -1605,13 +1429,13 @@ int main(int argc, char **argv) ...@@ -1605,13 +1429,13 @@ int main(int argc, char **argv)
nr_pages_per_cpu = atol(argv[2]) * 1024*1024 / page_size / nr_pages_per_cpu = atol(argv[2]) * 1024*1024 / page_size /
nr_cpus; nr_cpus;
if (!nr_pages_per_cpu) { if (!nr_pages_per_cpu) {
fprintf(stderr, "invalid MiB\n"); _err("invalid MiB");
usage(); usage();
} }
bounces = atoi(argv[3]); bounces = atoi(argv[3]);
if (bounces <= 0) { if (bounces <= 0) {
fprintf(stderr, "invalid bounces\n"); _err("invalid bounces");
usage(); usage();
} }
nr_pages = nr_pages_per_cpu * nr_cpus; nr_pages = nr_pages_per_cpu * nr_cpus;
...@@ -1620,16 +1444,10 @@ int main(int argc, char **argv) ...@@ -1620,16 +1444,10 @@ int main(int argc, char **argv)
if (argc < 5) if (argc < 5)
usage(); usage();
huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755); huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755);
if (huge_fd < 0) { if (huge_fd < 0)
fprintf(stderr, "Open of %s failed", argv[3]); err("Open of %s failed", argv[4]);
perror("open"); if (ftruncate(huge_fd, 0))
exit(1); err("ftruncate %s to size 0 failed", argv[4]);
}
if (ftruncate(huge_fd, 0)) {
fprintf(stderr, "ftruncate %s to size 0 failed", argv[3]);
perror("ftruncate");
exit(1);
}
} }
printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n",
nr_pages, nr_pages_per_cpu); nr_pages, nr_pages_per_cpu);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册