129e3ea8cSJordan Niethe#!/bin/bash 229e3ea8cSJordan Niethe# SPDX-License-Identifier: GPL-2.0-or-later 329e3ea8cSJordan Niethe 429e3ea8cSJordan NietheTIMEOUT=30 529e3ea8cSJordan Niethe 629e3ea8cSJordan NietheDEBUFS_DIR=`cat /proc/mounts | grep debugfs | awk '{print $2}'` 729e3ea8cSJordan Nietheif [ ! -e "$DEBUFS_DIR" ] 829e3ea8cSJordan Niethethen 929e3ea8cSJordan Niethe echo "debugfs not found, skipping" 1>&2 1029e3ea8cSJordan Niethe exit 4 1129e3ea8cSJordan Niethefi 1229e3ea8cSJordan Niethe 1329e3ea8cSJordan Nietheif [ ! -e "$DEBUFS_DIR/tracing/current_tracer" ] 1429e3ea8cSJordan Niethethen 1529e3ea8cSJordan Niethe echo "Tracing files not found, skipping" 1>&2 1629e3ea8cSJordan Niethe exit 4 1729e3ea8cSJordan Niethefi 1829e3ea8cSJordan Niethe 1929e3ea8cSJordan Niethe 2029e3ea8cSJordan Nietheecho "Testing for spurious faults when mapping kernel memory..." 2129e3ea8cSJordan Niethe 2229e3ea8cSJordan Nietheif grep -q "FUNCTION TRACING IS CORRUPTED" "$DEBUFS_DIR/tracing/trace" 2329e3ea8cSJordan Niethethen 2429e3ea8cSJordan Niethe echo "FAILED: Ftrace already dead. Probably due to a spurious fault" 1>&2 2529e3ea8cSJordan Niethe exit 1 2629e3ea8cSJordan Niethefi 2729e3ea8cSJordan Niethe 2829e3ea8cSJordan Niethedmesg -C 2929e3ea8cSJordan NietheSTART_TIME=`date +%s` 3029e3ea8cSJordan NietheEND_TIME=`expr $START_TIME + $TIMEOUT` 3129e3ea8cSJordan Niethewhile [ `date +%s` -lt $END_TIME ] 3229e3ea8cSJordan Niethedo 3329e3ea8cSJordan Niethe echo function > $DEBUFS_DIR/tracing/current_tracer 3429e3ea8cSJordan Niethe echo nop > $DEBUFS_DIR/tracing/current_tracer 3529e3ea8cSJordan Niethe if dmesg | grep -q 'ftrace bug' 3629e3ea8cSJordan Niethe then 3729e3ea8cSJordan Niethe break 3829e3ea8cSJordan Niethe fi 3929e3ea8cSJordan Niethedone 4029e3ea8cSJordan Niethe 4129e3ea8cSJordan Nietheecho nop > $DEBUFS_DIR/tracing/current_tracer 4229e3ea8cSJordan Nietheif dmesg | grep -q 'ftrace bug' 4329e3ea8cSJordan Niethethen 4429e3ea8cSJordan Niethe echo "FAILED: Mapping kernel memory causes spurious faults" 1>&2 4529e3ea8cSJordan Niethe exit 1 4629e3ea8cSJordan Nietheelse 4729e3ea8cSJordan Niethe echo "OK: Mapping kernel memory does not cause spurious faults" 4829e3ea8cSJordan Niethe exit 0 4929e3ea8cSJordan Niethefi 50