Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: AMD IBS swfilt skip kernel tests if paranoia is >1

If not root and the perf_event_paranoid is set >1 swfilt will fail to
open the event failing the test. Add check to skip the test in that
case.

Fixes: 0e71bcdcf1f0b10b ("perf test: Add AMD IBS sw filter test")
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Collin Funk <collin.funk1@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20250913000350.1306948-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
2e350121 54a7685f

+38 -13
+38 -13
tools/perf/tests/shell/amd-ibs-swfilt.sh
··· 1 1 #!/bin/bash 2 2 # AMD IBS software filtering 3 3 4 + ParanoidAndNotRoot() { 5 + [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 6 + } 7 + 4 8 echo "check availability of IBS swfilt" 5 9 6 10 # check if IBS PMU is available ··· 20 16 fi 21 17 22 18 echo "run perf record with modifier and swfilt" 19 + err=0 23 20 24 21 # setting any modifiers should fail 25 22 perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null ··· 36 31 exit 1 37 32 fi 38 33 39 - # setting it with swfilt=1 should be fine 40 - perf record -B -e ibs_op/swfilt=1/k -o /dev/null true 41 - if [ $? -ne 0 ]; then 42 - echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user" 43 - exit 1 34 + if ! ParanoidAndNotRoot 1 35 + then 36 + # setting it with swfilt=1 should be fine 37 + perf record -B -e ibs_op/swfilt=1/k -o /dev/null true 38 + if [ $? -ne 0 ]; then 39 + echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user" 40 + exit 1 41 + fi 42 + else 43 + echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" 44 + err=2 44 45 fi 45 46 46 47 # check ibs_fetch PMU as well ··· 57 46 fi 58 47 59 48 # check system wide recording 60 - perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true 61 - if [ $? -ne 0 ]; then 62 - echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode" 63 - exit 1 49 + if ! ParanoidAndNotRoot 0 50 + then 51 + perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true 52 + if [ $? -ne 0 ]; then 53 + echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode" 54 + exit 1 55 + fi 56 + else 57 + echo "[SKIP] not root and perf_event_paranoid too high for system-wide/exclude_user" 58 + err=2 64 59 fi 65 60 66 61 echo "check number of samples with swfilt" ··· 77 60 exit 1 78 61 fi 79 62 80 - user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U) 81 - if [ ${user_sample} -ne 0 ]; then 82 - echo "[FAIL] unexpected user samples: " ${user_sample} 83 - exit 1 63 + if ! ParanoidAndNotRoot 1 64 + then 65 + user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U) 66 + if [ ${user_sample} -ne 0 ]; then 67 + echo "[FAIL] unexpected user samples: " ${user_sample} 68 + exit 1 69 + fi 70 + else 71 + echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" 72 + err=2 84 73 fi 74 + 75 + exit $err