cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

event-no-pid.tc (2274B)


      1#!/bin/sh
      2# SPDX-License-Identifier: GPL-2.0
      3# description: event tracing - restricts events based on pid notrace filtering
      4# requires: set_event events/sched set_event_pid set_event_notrace_pid
      5# flags: instance
      6
      7do_reset() {
      8    echo > set_event
      9    echo > set_event_pid
     10    echo > set_event_notrace_pid
     11    echo 0 > options/event-fork
     12    echo 0 > events/enable
     13    clear_trace
     14    echo 1 > tracing_on
     15}
     16
     17fail() { #msg
     18    cat trace
     19    do_reset
     20    echo $1
     21    exit_fail
     22}
     23
     24count_pid() {
     25    pid=$@
     26    cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep $pid | wc -l
     27}
     28
     29count_no_pid() {
     30    pid=$1
     31    cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep -v $pid | wc -l
     32}
     33
     34enable_system() {
     35    system=$1
     36
     37    if [ -d events/$system ]; then
     38	echo 1 > events/$system/enable
     39    fi
     40}
     41
     42enable_events() {
     43    echo 0 > tracing_on
     44    # Enable common groups of events, as all events can allow for
     45    # events to be traced via scheduling that we don't care to test.
     46    enable_system syscalls
     47    enable_system rcu
     48    enable_system block
     49    enable_system exceptions
     50    enable_system irq
     51    enable_system net
     52    enable_system power
     53    enable_system signal
     54    enable_system sock
     55    enable_system timer
     56    enable_system thermal
     57    echo 1 > tracing_on
     58}
     59
     60other_task() {
     61    sleep .001 || usleep 1 || sleep 1
     62}
     63
     64echo 0 > options/event-fork
     65
     66do_reset
     67
     68read mypid rest < /proc/self/stat
     69
     70echo $mypid > set_event_notrace_pid
     71grep -q $mypid set_event_notrace_pid
     72
     73enable_events
     74
     75yield
     76
     77echo 0 > tracing_on
     78
     79cnt=`count_pid $mypid`
     80if [ $cnt -ne 0 ]; then
     81    fail "Filtered out task has events"
     82fi
     83
     84cnt=`count_no_pid $mypid`
     85if [ $cnt -eq 0 ]; then
     86    fail "No other events were recorded"
     87fi
     88
     89do_reset
     90
     91echo $mypid > set_event_notrace_pid
     92echo 1 > options/event-fork
     93
     94enable_events
     95
     96yield &
     97child=$!
     98echo "child = $child"
     99wait $child
    100
    101# Be sure some other events will happen for small systems (e.g. 1 core)
    102other_task
    103
    104echo 0 > tracing_on
    105
    106cnt=`count_pid $mypid`
    107if [ $cnt -ne 0 ]; then
    108    fail "Filtered out task has events"
    109fi
    110
    111cnt=`count_pid $child`
    112if [ $cnt -ne 0 ]; then
    113    fail "Child of filtered out taskhas events"
    114fi
    115
    116cnt=`count_no_pid $mypid`
    117if [ $cnt -eq 0 ]; then
    118    fail "No other events were recorded"
    119fi
    120
    121do_reset
    122
    123exit 0