summaryrefslogtreecommitdiffstats
path: root/tools/guest-diag/guest_kprobes.sh
blob: b8e18a4c4d6e92491da2e8c874576fe8507dd639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# guest_kprobes.sh - (re)install the UVM trace probes used by semfix_watch.py.
# Runs in the guest as root; kprobes do not survive a guest boot, so this must
# run after every VM restart.
#
#   uvmt  uvm_gpu_tracking_semaphore_update_completed_value  sem=%di
#   uvch  __uvm_push_begin_acquire_on_channel_with_info      ch=%di
#   uvbp  uvm_pushbuffer_begin_push                          pb=%di
#   uvpbf uvm_pushbuffer_create                              pb=%si
#
# Tries the plain symbol first (module symbols usually resolve), then the
# module:symbol spelling, then without the fetch argument (fetchargs on some
# symbols are rejected).

TR=/sys/kernel/tracing
[ -d "$TR" ] || TR=/sys/kernel/debug/tracing

# An enabled kprobe event cannot be deleted (EBUSY); disable the group first.
echo 0 > "$TR/events/kprobes/enable" 2>/dev/null || true

add_probe() {
    name=$1; sym=$2; fmt=$3
    echo "-:kprobes/$name" >> "$TR/kprobe_events" 2>/dev/null
    echo "-:$name" >> "$TR/kprobe_events" 2>/dev/null
    if ! grep -qw "$sym" /proc/kallsyms 2>/dev/null; then
        echo "FAIL $name: symbol $sym not in kallsyms"
        return 1
    fi
    if echo "p:$name $sym $fmt" >> "$TR/kprobe_events" 2>/dev/null; then
        if grep -qE "p:[^ ]*[ /]$name( |$)" "$TR/kprobe_events" 2>/dev/null; then
            echo "ok $name $sym"
            return 0
        fi
    fi
    echo "-:kprobes/$name" >> "$TR/kprobe_events" 2>/dev/null
    echo "-:$name" >> "$TR/kprobe_events" 2>/dev/null
    if echo "p:$name nvidia_uvm:$sym $fmt" >> "$TR/kprobe_events" 2>/dev/null; then
        if grep -qE "p:[^ ]*[ /]$name( |$)" "$TR/kprobe_events" 2>/dev/null; then
            echo "ok-module $name $sym"
            return 0
        fi
    fi
    echo "-:kprobes/$name" >> "$TR/kprobe_events" 2>/dev/null
    echo "-:$name" >> "$TR/kprobe_events" 2>/dev/null
    if echo "p:$name $sym" >> "$TR/kprobe_events" 2>/dev/null; then
        if grep -qE "p:[^ ]*[ /]$name( |$)" "$TR/kprobe_events" 2>/dev/null; then
            echo "ok-bare $name $sym"
            return 0
        fi
    fi
    echo "FAIL $name $sym"
    return 1
}

add_probe uvmt uvm_gpu_tracking_semaphore_update_completed_value 'sem=%di val=+16(%di):u32'
add_probe uvch __uvm_push_begin_acquire_on_channel_with_info 'ch=%di'
add_probe uvbp uvm_pushbuffer_begin_push 'pb=%di'
add_probe uvpbf uvm_pushbuffer_create 'pb=%si'
# uvm_tracker_entry_t { uvm_channel_t *channel; NvU64 value; } - the exact
# (channel, value) the client's tracker wait is blocked on.
add_probe uvtw uvm_tracker_wait_for_entry 'chan=+0(%di):u64 value=+8(%di):u64'

echo 1 > "$TR/events/kprobes/enable" 2>/dev/null || true
echo "--- installed probes ---"
grep -E 'uvmt|uvch|uvbp|uvpbf|uvtw' "$TR/kprobe_events" 2>/dev/null || echo "(none)"