/* * Copyright 2014, Michael Ellerman, IBM Corp. * Licensed under GPLv2. */ #define _GNU_SOURCE /* For CPU_ZERO etc. */ #include #include #include #include #include #include "utils.h" #include "lib.h" int bind_to_cpu(int cpu) { cpu_set_t mask; printf("Binding to cpu %d\n", cpu); CPU_ZERO(&mask); CPU_SET(cpu, &mask); return sched_setaffinity(0, sizeof(mask), &mask); } #define PARENT_TOKEN 0xAA #define CHILD_TOKEN 0x55 int sync_with_child(union pipe read_pipe, union pipe write_pipe) { char c = PARENT_TOKEN; FAIL_IF(write(write_pipe.write_fd, &c, 1) != 1); FAIL_IF(read(read_pipe.read_fd, &c, 1) != 1); if (c != CHILD_TOKEN) /* sometimes expected */ return 1; return 0; } int wait_for_parent(union pipe read_pipe) { char c; FAIL_IF(read(read_pipe.read_fd, &c, 1) != 1); FAIL_IF(c != PARENT_TOKEN); return 0; } int notify_parent(union pipe write_pipe) { char c = CHILD_TOKEN; FAIL_IF(write(write_pipe.write_fd, &c, 1) != 1); return 0; } int notify_parent_of_error(union pipe write_pipe) { char c = ~CHILD_TOKEN; FAIL_IF(write(write_pipe.write_fd, &c, 1) != 1); return 0; } int wait_for_child(pid_t child_pid) { int rc; if (waitpid(child_pid, &rc, 0) == -1) { perror("waitpid"); return 1; } if (WIFEXITED(rc)) rc = WEXITSTATUS(rc); else rc = 1; /* Signal or other */ return rc; } int kill_child_and_wait(pid_t child_pid) { kill(child_pid, SIGTERM); return wait_for_child(child_pid); } static int eat_cpu_child(union pipe read_pipe, union pipe write_pipe) { volatile int i = 0; /* * We are just here to eat cpu and die. So make sure we can be killed, * and also don't do any custom SIGTERM handling. */ signal(SIGTERM, SIG_DFL); notify_parent(write_pipe); wait_for_parent(read_pipe); /* Soak up cpu forever */ while (1) i++; return 0; } pid_t eat_cpu(int (test_function)(void)) { union pipe read_pipe, write_pipe; int cpu, rc; pid_t pid; cpu = pick_online_cpu(); FAIL_IF(cpu < 0); FAIL_IF(bind_to_cpu(cpu)); if (pipe(read_pipe.fds) == -1) return -1; if (pipe(write_pipe.fds) == -1) return -1; pid = fork(); if (pid == 0) exit(eat_cpu_child(write_pipe, read_pipe)); if (sync_with_child(read_pipe, write_pipe)) { rc = -1; goto out; } printf("main test running as pid %d\n", getpid()); rc = test_function(); out: kill(pid, SIGKILL); return rc; } struct addr_range libc, vdso; int parse_proc_maps(void) { unsigned long start, end; char execute, name[128]; FILE *f; int rc; f = fopen("/proc/self/maps", "r"); if (!f) { perror("fopen"); return -1; } do { /* This skips line with no executable which is what we want */ rc = fscanf(f, "%lx-%lx %*c%*c%c%*c %*x %*d:%*d %*d %127s\n", &start, &end, &execute, name); if (rc <= 0) break; if (execute != 'x') continue; if (strstr(name, "libc")) { libc.first = start; libc.last = end - 1; } else if (strstr(name, "[vdso]")) { vdso.first = start; vdso.last = end - 1; } } while(1); fclose(f); return 0; } #define PARANOID_PATH "/proc/sys/kernel/perf_event_paranoid" bool require_paranoia_below(int level) { long current; char *end, buf[16]; FILE *f; bool rc; rc = false; f = fopen(PARANOID_PATH, "r"); if (!f) { perror("fopen"); goto out; } if (!fgets(buf, sizeof(buf), f)) { printf("Couldn't read " PARANOID_PATH "?\n"); goto out_close; } current = strtol(buf, &end, 10); if (end == buf) { printf("Couldn't parse " PARANOID_PATH "?\n"); goto out_close; } if (current >= level) goto out_close; rc = true; out_close: fclose(f); out: return rc; } fccf2eb0cc8d8082f65c0a4286'/>
context:
space:
mode:
authorLaura Abbott <labbott@redhat.com>2016-12-21 12:32:54 -0800
committerHerbert Xu <herbert@gondor.apana.org.au>2016-12-27 17:32:11 +0800
commit02608e02fbec04fccf2eb0cc8d8082f65c0a4286 (patch)
tree37ff0410d130cfe77185f591b07cd6403f207f0c /tools/testing/selftests/powerpc/include
parent7ce7d89f48834cefece7804d38fc5d85382edf77 (diff)
crypto: testmgr - Use heap buffer for acomp test input
Christopher Covington reported a crash on aarch64 on recent Fedora kernels: kernel BUG at ./include/linux/scatterlist.h:140! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 2 PID: 752 Comm: cryptomgr_test Not tainted 4.9.0-11815-ge93b1cc #162 Hardware name: linux,dummy-virt (DT) task: ffff80007c650080 task.stack: ffff800008910000 PC is at sg_init_one+0xa0/0xb8 LR is at sg_init_one+0x24/0xb8 ... [<ffff000008398db8>] sg_init_one+0xa0/0xb8 [<ffff000008350a44>] test_acomp+0x10c/0x438 [<ffff000008350e20>] alg_test_comp+0xb0/0x118 [<ffff00000834f28c>] alg_test+0x17c/0x2f0 [<ffff00000834c6a4>] cryptomgr_test+0x44/0x50 [<ffff0000080dac70>] kthread+0xf8/0x128 [<ffff000008082ec0>] ret_from_fork+0x10/0x50 The test vectors used for input are part of the kernel image. These inputs are passed as a buffer to sg_init_one which eventually blows up with BUG_ON(!virt_addr_valid(buf)). On arm64, virt_addr_valid returns false for the kernel image since virt_to_page will not return the correct page. Fix this by copying the input vectors to heap buffer before setting up the scatterlist. Reported-by: Christopher Covington <cov@codeaurora.org> Fixes: d7db7a882deb ("crypto: acomp - update testmgr with support for acomp") Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'tools/testing/selftests/powerpc/include')