/* * 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; } tion value='4'>4space:mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-01-29 13:50:06 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2017-01-29 13:50:06 -0800
commit39cb2c9a316e77f6dfba96c543e55b6672d5a37e (patch)
tree98fe974ee4e20121253de7f61fc8d01bdb3821c1 /tools/perf/scripts/perl
parent2c5d9555d6d937966d79d4c6529a5f7b9206e405 (diff)
drm/i915: Check for NULL i915_vma in intel_unpin_fb_obj()
I've seen this trigger twice now, where the i915_gem_object_to_ggtt() call in intel_unpin_fb_obj() returns NULL, resulting in an oops immediately afterwards as the (inlined) call to i915_vma_unpin_fence() tries to dereference it. It seems to be some race condition where the object is going away at shutdown time, since both times happened when shutting down the X server. The call chains were different: - VT ioctl(KDSETMODE, KD_TEXT): intel_cleanup_plane_fb+0x5b/0xa0 [i915] drm_atomic_helper_cleanup_planes+0x6f/0x90 [drm_kms_helper] intel_atomic_commit_tail+0x749/0xfe0 [i915] intel_atomic_commit+0x3cb/0x4f0 [i915] drm_atomic_commit+0x4b/0x50 [drm] restore_fbdev_mode+0x14c/0x2a0 [drm_kms_helper] drm_fb_helper_restore_fbdev_mode_unlocked+0x34/0x80 [drm_kms_helper] drm_fb_helper_set_par+0x2d/0x60 [drm_kms_helper] intel_fbdev_set_par+0x18/0x70 [i915] fb_set_var+0x236/0x460 fbcon_blank+0x30f/0x350 do_unblank_screen+0xd2/0x1a0 vt_ioctl+0x507/0x12a0 tty_ioctl+0x355/0xc30 do_vfs_ioctl+0xa3/0x5e0 SyS_ioctl+0x79/0x90 entry_SYSCALL_64_fastpath+0x13/0x94 - i915 unpin_work workqueue: intel_unpin_work_fn+0x58/0x140 [i915] process_one_work+0x1f1/0x480 worker_thread+0x48/0x4d0 kthread+0x101/0x140 and this patch purely papers over the issue by adding a NULL pointer check and a WARN_ON_ONCE() to avoid the oops that would then generally make the machine unresponsive. Other callers of i915_gem_object_to_ggtt() seem to also check for the returned pointer being NULL and warn about it, so this clearly has happened before in other places. [ Reported it originally to the i915 developers on Jan 8, applying the ugly workaround on my own now after triggering the problem for the second time with no feedback. This is likely to be the same bug reported as https://bugs.freedesktop.org/show_bug.cgi?id=98829 https://bugs.freedesktop.org/show_bug.cgi?id=99134 which has a patch for the underlying problem, but it hasn't gotten to me, so I'm applying the workaround. ] Cc: Daniel Vetter <daniel.vetter@intel.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Imre Deak <imre.deak@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/perf/scripts/perl')