16c00db4bb
Pull AFS fixes from David Howells: "Here's a set of patches that fix a number of bugs in the in-kernel AFS client, including: - Fix directory locking to not use individual page locks for directory reading/scanning but rather to use a semaphore on the afs_vnode struct as the directory contents must be read in a single blob and data from different reads must not be mixed as the entire contents may be shuffled about between reads. - Fix address list parsing to handle port specifiers correctly. - Only give up callback records on a server if we actually talked to that server (we might not be able to access a server). - Fix some callback handling bugs, including refcounting, whole-volume callbacks and when callbacks actually get broken in response to a CB.CallBack op. - Fix some server/address rotation bugs, including giving up if we can't probe a server; giving up if a server says it doesn't have a volume, but there are more servers to try. - Fix the decoding of fetched statuses to be OpenAFS compatible. - Fix the handling of server lookups in Cache Manager ops (such as CB.InitCallBackState3) to use a UUID if possible and to handle no server being found. - Fix a bug in server lookup where not all addresses are compared. - Fix the non-encryption of calls that prevents some servers from being accessed (this also requires an AF_RXRPC patch that has already gone in through the net tree). There's also a patch that adds tracepoints to log Cache Manager ops that don't find a matching server, either by UUID or by address" * tag 'afs-fixes-20180514' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: afs: Fix the non-encryption of calls afs: Fix CB.CallBack handling afs: Fix whole-volume callback handling afs: Fix afs_find_server search loop afs: Fix the handling of an unfound server in CM operations afs: Add a tracepoint to record callbacks from unlisted servers afs: Fix the handling of CB.InitCallBackState3 to find the server by UUID afs: Fix VNOVOL handling in address rotation afs: Fix AFSFetchStatus decoder to provide OpenAFS compatibility afs: Fix server rotation's handling of fileserver probe failure afs: Fix refcounting in callback registration afs: Fix giving up callbacks on server destruction afs: Fix address list parsing afs: Fix directory page locking
180 lines
3.3 KiB
C
180 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <linux/types.h>
|
|
#include "perf.h"
|
|
#include "debug.h"
|
|
#include "tests/tests.h"
|
|
#include "cloexec.h"
|
|
#include "util.h"
|
|
#include "arch-tests.h"
|
|
|
|
static u64 rdpmc(unsigned int counter)
|
|
{
|
|
unsigned int low, high;
|
|
|
|
asm volatile("rdpmc" : "=a" (low), "=d" (high) : "c" (counter));
|
|
|
|
return low | ((u64)high) << 32;
|
|
}
|
|
|
|
static u64 rdtsc(void)
|
|
{
|
|
unsigned int low, high;
|
|
|
|
asm volatile("rdtsc" : "=a" (low), "=d" (high));
|
|
|
|
return low | ((u64)high) << 32;
|
|
}
|
|
|
|
static u64 mmap_read_self(void *addr)
|
|
{
|
|
struct perf_event_mmap_page *pc = addr;
|
|
u32 seq, idx, time_mult = 0, time_shift = 0;
|
|
u64 count, cyc = 0, time_offset = 0, enabled, running, delta;
|
|
|
|
do {
|
|
seq = pc->lock;
|
|
barrier();
|
|
|
|
enabled = pc->time_enabled;
|
|
running = pc->time_running;
|
|
|
|
if (enabled != running) {
|
|
cyc = rdtsc();
|
|
time_mult = pc->time_mult;
|
|
time_shift = pc->time_shift;
|
|
time_offset = pc->time_offset;
|
|
}
|
|
|
|
idx = pc->index;
|
|
count = pc->offset;
|
|
if (idx)
|
|
count += rdpmc(idx - 1);
|
|
|
|
barrier();
|
|
} while (pc->lock != seq);
|
|
|
|
if (enabled != running) {
|
|
u64 quot, rem;
|
|
|
|
quot = (cyc >> time_shift);
|
|
rem = cyc & (((u64)1 << time_shift) - 1);
|
|
delta = time_offset + quot * time_mult +
|
|
((rem * time_mult) >> time_shift);
|
|
|
|
enabled += delta;
|
|
if (idx)
|
|
running += delta;
|
|
|
|
quot = count / running;
|
|
rem = count % running;
|
|
count = quot * enabled + (rem * enabled) / running;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
/*
|
|
* If the RDPMC instruction faults then signal this back to the test parent task:
|
|
*/
|
|
static void segfault_handler(int sig __maybe_unused,
|
|
siginfo_t *info __maybe_unused,
|
|
void *uc __maybe_unused)
|
|
{
|
|
exit(-1);
|
|
}
|
|
|
|
static int __test__rdpmc(void)
|
|
{
|
|
volatile int tmp = 0;
|
|
u64 i, loops = 1000;
|
|
int n;
|
|
int fd;
|
|
void *addr;
|
|
struct perf_event_attr attr = {
|
|
.type = PERF_TYPE_HARDWARE,
|
|
.config = PERF_COUNT_HW_INSTRUCTIONS,
|
|
.exclude_kernel = 1,
|
|
};
|
|
u64 delta_sum = 0;
|
|
struct sigaction sa;
|
|
char sbuf[STRERR_BUFSIZE];
|
|
|
|
sigfillset(&sa.sa_mask);
|
|
sa.sa_sigaction = segfault_handler;
|
|
sa.sa_flags = 0;
|
|
sigaction(SIGSEGV, &sa, NULL);
|
|
|
|
fd = sys_perf_event_open(&attr, 0, -1, -1,
|
|
perf_event_open_cloexec_flag());
|
|
if (fd < 0) {
|
|
pr_err("Error: sys_perf_event_open() syscall returned "
|
|
"with %d (%s)\n", fd,
|
|
str_error_r(errno, sbuf, sizeof(sbuf)));
|
|
return -1;
|
|
}
|
|
|
|
addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
|
|
if (addr == (void *)(-1)) {
|
|
pr_err("Error: mmap() syscall returned with (%s)\n",
|
|
str_error_r(errno, sbuf, sizeof(sbuf)));
|
|
goto out_close;
|
|
}
|
|
|
|
for (n = 0; n < 6; n++) {
|
|
u64 stamp, now, delta;
|
|
|
|
stamp = mmap_read_self(addr);
|
|
|
|
for (i = 0; i < loops; i++)
|
|
tmp++;
|
|
|
|
now = mmap_read_self(addr);
|
|
loops *= 10;
|
|
|
|
delta = now - stamp;
|
|
pr_debug("%14d: %14Lu\n", n, (long long)delta);
|
|
|
|
delta_sum += delta;
|
|
}
|
|
|
|
munmap(addr, page_size);
|
|
pr_debug(" ");
|
|
out_close:
|
|
close(fd);
|
|
|
|
if (!delta_sum)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test__rdpmc(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
int status = 0;
|
|
int wret = 0;
|
|
int ret;
|
|
int pid;
|
|
|
|
pid = fork();
|
|
if (pid < 0)
|
|
return -1;
|
|
|
|
if (!pid) {
|
|
ret = __test__rdpmc();
|
|
|
|
exit(ret);
|
|
}
|
|
|
|
wret = waitpid(pid, &status, 0);
|
|
if (wret < 0 || status)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|