Skip to contentSkip to conversation

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

PATCH Superseded Ian Rogers 3 participants 5 messages Sep 8, 2025 – Sep 16, 2025 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 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.

Some corrections to the kernel/user sample count test.

---
 tools/perf/tests/shell/amd-ibs-swfilt.sh | 57 +++++++++++++++++-------
 1 file changed, 41 insertions(+), 16 deletions(-)
tools/perf/tests/shell/amd-ibs-swfilt.sh +41 -16
index 7045ec72ba4c..80d5bf8db40c 100755
@@ -1,6 +1,10 @@
 #!/bin/bash
 # AMD IBS software filtering
 
+ParanoidAndNotRoot() {
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
 echo "check availability of IBS swfilt"
 
 # check if IBS PMU is available
@@ -16,6 +20,7 @@ if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
 fi
 
 echo "run perf record with modifier and swfilt"
+err=0
 
 # setting any modifiers should fail
 perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
@@ -31,11 +36,17 @@ if [ $? -ne 0 ]; then
     exit 1
 fi
 
-# setting it with swfilt=1 should be fine
-perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    # setting it with swfilt=1 should be fine
+    perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 
 # check ibs_fetch PMU as well
@@ -46,22 +57,36 @@ if [ $? -ne 0 ]; then
 fi
 
 # check system wide recording
-perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 
 echo "check number of samples with swfilt"
 
-kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
-if [ ${kernel_sample} -ne 0 ]; then
-    echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
-    exit 1
-fi
-
-user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
+user_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^U)
 if [ ${user_sample} -ne 0 ]; then
     echo "[FAIL] unexpected user samples: " ${user_sample}
     exit 1
 fi
+
+if ! ParanoidAndNotRoot 1
+then
+    kernel_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^K)
+    if [ ${kernel_sample} -ne 0 ]; then
+        echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
+fi
+
+exit $err
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
maintainer
#1 lore raw

Hi Ian,

Quoted 3 lines · Ian Rogers

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.

Thanks for the fix!

Quoted 74 lines

Some corrections to the kernel/user sample count test.

---
 tools/perf/tests/shell/amd-ibs-swfilt.sh | 57 +++++++++++++++++-------
 1 file changed, 41 insertions(+), 16 deletions(-)
tools/perf/tests/shell/amd-ibs-swfilt.sh +26 -9
index 7045ec72ba4c..80d5bf8db40c 100755
@@ -1,6 +1,10 @@
 #!/bin/bash
 # AMD IBS software filtering
 
+ParanoidAndNotRoot() {
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
 echo "check availability of IBS swfilt"
 
 # check if IBS PMU is available
@@ -16,6 +20,7 @@ if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
 fi
 
 echo "run perf record with modifier and swfilt"
+err=0
 
 # setting any modifiers should fail
 perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
@@ -31,11 +36,17 @@ if [ $? -ne 0 ]; then
     exit 1
 fi
 
-# setting it with swfilt=1 should be fine
-perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    # setting it with swfilt=1 should be fine
+    perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 
 # check ibs_fetch PMU as well
@@ -46,22 +57,36 @@ if [ $? -ne 0 ]; then
 fi
 
 # check system wide recording
-perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 74

Quoted 10 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +1 -7
 echo "check number of samples with swfilt"
 
-kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
-if [ ${kernel_sample} -ne 0 ]; then
-    echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
-    exit 1
-fi
-
-user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
+user_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^U)

I think it should count kernel samples now (with ^K) as it sets 'u' modifier (exclude_kernel).

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 76

Quoted 2 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +0 -0
 if [ ${user_sample} -ne 0 ]; then
     echo "[FAIL] unexpected user samples: " ${user_sample}

So that it should not have unexpected kernel samples.

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 84

Quoted 8 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +6 -0
     exit 1
 fi
+
+if ! ParanoidAndNotRoot 1
+then
+    kernel_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^K)
+    if [ ${kernel_sample} -ne 0 ]; then
+        echo "[FAIL] unexpected kernel samples: " ${kernel_sample}

Vice versa. It should count unexpected user samples from 'k' modifier.

Thanks,
Namhyung

Quoted 11 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +8 -0
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
+fi
+
+exit $err
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
#2 lore raw
Quoted 8 lines · Namhyung Kim

Hi Ian,

Quoted 3 lines · Ian Rogers

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.

Thanks for the fix!

I'm taking this as an Acked-by, ok?

- Arnaldo

Quoted 121 lines
Quoted 74 lines

Some corrections to the kernel/user sample count test.

---
 tools/perf/tests/shell/amd-ibs-swfilt.sh | 57 +++++++++++++++++-------
 1 file changed, 41 insertions(+), 16 deletions(-)
tools/perf/tests/shell/amd-ibs-swfilt.sh +26 -9
index 7045ec72ba4c..80d5bf8db40c 100755
@@ -1,6 +1,10 @@
 #!/bin/bash
 # AMD IBS software filtering
 
+ParanoidAndNotRoot() {
+  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
+}
+
 echo "check availability of IBS swfilt"
 
 # check if IBS PMU is available
@@ -16,6 +20,7 @@ if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
 fi
 
 echo "run perf record with modifier and swfilt"
+err=0
 
 # setting any modifiers should fail
 perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
@@ -31,11 +36,17 @@ if [ $? -ne 0 ]; then
     exit 1
 fi
 
-# setting it with swfilt=1 should be fine
-perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    # setting it with swfilt=1 should be fine
+    perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 
 # check ibs_fetch PMU as well
@@ -46,22 +57,36 @@ if [ $? -ne 0 ]; then
 fi
 
 # check system wide recording
-perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
-if [ $? -ne 0 ]; then
-    echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
-    exit 1
+if ! ParanoidAndNotRoot 1
+then
+    perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
+    if [ $? -ne 0 ]; then
+        echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
 fi
 

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 74

Quoted 10 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +1 -7
 echo "check number of samples with swfilt"
 
-kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
-if [ ${kernel_sample} -ne 0 ]; then
-    echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
-    exit 1
-fi
-
-user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
+user_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^U)

I think it should count kernel samples now (with ^K) as it sets 'u' modifier (exclude_kernel).

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 76

Quoted 2 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +0 -0
 if [ ${user_sample} -ne 0 ]; then
     echo "[FAIL] unexpected user samples: " ${user_sample}

So that it should not have unexpected kernel samples.

tools/perf/tests/shell/amd-ibs-swfilt.sh if [ $? -ne 0 ]; then · line 84

Quoted 8 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +6 -0
     exit 1
 fi
+
+if ! ParanoidAndNotRoot 1
+then
+    kernel_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^K)
+    if [ ${kernel_sample} -ne 0 ]; then
+        echo "[FAIL] unexpected kernel samples: " ${kernel_sample}

Vice versa. It should count unexpected user samples from 'k' modifier.

Thanks,
Namhyung

Quoted 11 lines
tools/perf/tests/shell/amd-ibs-swfilt.sh +8 -0
+        exit 1
+    fi
+else
+    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
+    err=2
+fi
+
+exit $err
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
author reviewer
#3 lore raw
Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 2 lines · Namhyung Kim

Hi Ian,

Quoted 8 lines
Quoted 6 lines · Ian Rogers
Quoted 3 lines

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.

Thanks for the fix!

I'm taking this as an Acked-by, ok?

I have a new version but I'm discovering quite a few other issues on the way. There are 7 patches on top of this here:
https://github.com/googleprodkernel/linux-perf/commits/google_tools_master/
I'll send the new version now, but I'd been tardy as it wasn't clear I was done with fixes yet.

Thanks,
Ian

#4 lore raw
Quoted 11 lines · Ian Rogers
Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 7 lines · Namhyung Kim

Hi Ian,

Quoted 3 lines · Ian Rogers

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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks for the fix!

I'm taking this as an Acked-by, ok?

I have a new version but I'm discovering quite a few other issues on the way. There are 7 patches on top of this here:
https://github.com/googleprodkernel/linux-perf/commits/google_tools_master/

I just checked and b4 picked the latest version of this patch as what I have now in perf-tools-next is the same as in:

https://github.com/googleprodkernel/linux-perf/blob/google_tools_master/tools/perf/tests/shell/amd-ibs-swfilt.sh

- Arnaldo

Quoted 5 lines

I'll send the new version now, but I'd been tardy as it wasn't clear I was done with fixes yet.

Thanks,
Ian