stress_code_patching.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. TIMEOUT=30
  4. DEBUFS_DIR=`cat /proc/mounts | grep debugfs | awk '{print $2}'`
  5. if [ ! -e "$DEBUFS_DIR" ]
  6. then
  7. echo "debugfs not found, skipping" 1>&2
  8. exit 4
  9. fi
  10. if [ ! -e "$DEBUFS_DIR/tracing/current_tracer" ]
  11. then
  12. echo "Tracing files not found, skipping" 1>&2
  13. exit 4
  14. fi
  15. echo "Testing for spurious faults when mapping kernel memory..."
  16. if grep -q "FUNCTION TRACING IS CORRUPTED" "$DEBUFS_DIR/tracing/trace"
  17. then
  18. echo "FAILED: Ftrace already dead. Probably due to a spurious fault" 1>&2
  19. exit 1
  20. fi
  21. dmesg -C
  22. START_TIME=`date +%s`
  23. END_TIME=`expr $START_TIME + $TIMEOUT`
  24. while [ `date +%s` -lt $END_TIME ]
  25. do
  26. echo function > $DEBUFS_DIR/tracing/current_tracer
  27. echo nop > $DEBUFS_DIR/tracing/current_tracer
  28. if dmesg | grep -q 'ftrace bug'
  29. then
  30. break
  31. fi
  32. done
  33. echo nop > $DEBUFS_DIR/tracing/current_tracer
  34. if dmesg | grep -q 'ftrace bug'
  35. then
  36. echo "FAILED: Mapping kernel memory causes spurious faults" 1>&2
  37. exit 1
  38. else
  39. echo "OK: Mapping kernel memory does not cause spurious faults"
  40. exit 0
  41. fi