s390.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ===================
  2. Testing BPF on s390
  3. ===================
  4. 1. Introduction
  5. ***************
  6. IBM Z are mainframe computers, which are descendants of IBM System/360 from
  7. year 1964. They are supported by the Linux kernel under the name "s390". This
  8. document describes how to test BPF in an s390 QEMU guest.
  9. 2. One-time setup
  10. *****************
  11. The following is required to build and run the test suite:
  12. * s390 GCC
  13. * s390 development headers and libraries
  14. * Clang with BPF support
  15. * QEMU with s390 support
  16. * Disk image with s390 rootfs
  17. Debian supports installing compiler and libraries for s390 out of the box.
  18. Users of other distros may use debootstrap in order to set up a Debian chroot::
  19. sudo debootstrap \
  20. --variant=minbase \
  21. --include=sudo \
  22. testing \
  23. ./s390-toolchain
  24. sudo mount --rbind /dev ./s390-toolchain/dev
  25. sudo mount --rbind /proc ./s390-toolchain/proc
  26. sudo mount --rbind /sys ./s390-toolchain/sys
  27. sudo chroot ./s390-toolchain
  28. Once on Debian, the build prerequisites can be installed as follows::
  29. sudo dpkg --add-architecture s390x
  30. sudo apt-get update
  31. sudo apt-get install \
  32. bc \
  33. bison \
  34. cmake \
  35. debootstrap \
  36. dwarves \
  37. flex \
  38. g++ \
  39. gcc \
  40. g++-s390x-linux-gnu \
  41. gcc-s390x-linux-gnu \
  42. gdb-multiarch \
  43. git \
  44. make \
  45. python3 \
  46. qemu-system-misc \
  47. qemu-utils \
  48. rsync \
  49. libcap-dev:s390x \
  50. libelf-dev:s390x \
  51. libncurses-dev
  52. Latest Clang targeting BPF can be installed as follows::
  53. git clone https://github.com/llvm/llvm-project.git
  54. ln -s ../../clang llvm-project/llvm/tools/
  55. mkdir llvm-project-build
  56. cd llvm-project-build
  57. cmake \
  58. -DLLVM_TARGETS_TO_BUILD=BPF \
  59. -DCMAKE_BUILD_TYPE=Release \
  60. -DCMAKE_INSTALL_PREFIX=/opt/clang-bpf \
  61. ../llvm-project/llvm
  62. make
  63. sudo make install
  64. export PATH=/opt/clang-bpf/bin:$PATH
  65. The disk image can be prepared using a loopback mount and debootstrap::
  66. qemu-img create -f raw ./s390.img 1G
  67. sudo losetup -f ./s390.img
  68. sudo mkfs.ext4 /dev/loopX
  69. mkdir ./s390.rootfs
  70. sudo mount /dev/loopX ./s390.rootfs
  71. sudo debootstrap \
  72. --foreign \
  73. --arch=s390x \
  74. --variant=minbase \
  75. --include=" \
  76. iproute2, \
  77. iputils-ping, \
  78. isc-dhcp-client, \
  79. kmod, \
  80. libcap2, \
  81. libelf1, \
  82. netcat, \
  83. procps" \
  84. testing \
  85. ./s390.rootfs
  86. sudo umount ./s390.rootfs
  87. sudo losetup -d /dev/loopX
  88. 3. Compilation
  89. **************
  90. In addition to the usual Kconfig options required to run the BPF test suite, it
  91. is also helpful to select::
  92. CONFIG_NET_9P=y
  93. CONFIG_9P_FS=y
  94. CONFIG_NET_9P_VIRTIO=y
  95. CONFIG_VIRTIO_PCI=y
  96. as that would enable a very easy way to share files with the s390 virtual
  97. machine.
  98. Compiling kernel, modules and testsuite, as well as preparing gdb scripts to
  99. simplify debugging, can be done using the following commands::
  100. make ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- menuconfig
  101. make ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- bzImage modules scripts_gdb
  102. make ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- \
  103. -C tools/testing/selftests \
  104. TARGETS=bpf \
  105. INSTALL_PATH=$PWD/tools/testing/selftests/kselftest_install \
  106. install
  107. 4. Running the test suite
  108. *************************
  109. The virtual machine can be started as follows::
  110. qemu-system-s390x \
  111. -cpu max,zpci=on \
  112. -smp 2 \
  113. -m 4G \
  114. -kernel linux/arch/s390/boot/compressed/vmlinux \
  115. -drive file=./s390.img,if=virtio,format=raw \
  116. -nographic \
  117. -append 'root=/dev/vda rw console=ttyS1' \
  118. -virtfs local,path=./linux,security_model=none,mount_tag=linux \
  119. -object rng-random,filename=/dev/urandom,id=rng0 \
  120. -device virtio-rng-ccw,rng=rng0 \
  121. -netdev user,id=net0 \
  122. -device virtio-net-ccw,netdev=net0
  123. When using this on a real IBM Z, ``-enable-kvm`` may be added for better
  124. performance. When starting the virtual machine for the first time, disk image
  125. setup must be finalized using the following command::
  126. /debootstrap/debootstrap --second-stage
  127. Directory with the code built on the host as well as ``/proc`` and ``/sys``
  128. need to be mounted as follows::
  129. mkdir -p /linux
  130. mount -t 9p linux /linux
  131. mount -t proc proc /proc
  132. mount -t sysfs sys /sys
  133. After that, the test suite can be run using the following commands::
  134. cd /linux/tools/testing/selftests/kselftest_install
  135. ./run_kselftest.sh
  136. As usual, tests can be also run individually::
  137. cd /linux/tools/testing/selftests/bpf
  138. ./test_verifier
  139. 5. Debugging
  140. ************
  141. It is possible to debug the s390 kernel using QEMU GDB stub, which is activated
  142. by passing ``-s`` to QEMU.
  143. It is preferable to turn KASLR off, so that gdb would know where to find the
  144. kernel image in memory, by building the kernel with::
  145. RANDOMIZE_BASE=n
  146. GDB can then be attached using the following command::
  147. gdb-multiarch -ex 'target remote localhost:1234' ./vmlinux
  148. 6. Network
  149. **********
  150. In case one needs to use the network in the virtual machine in order to e.g.
  151. install additional packages, it can be configured using::
  152. dhclient eth0
  153. 7. Links
  154. ********
  155. This document is a compilation of techniques, whose more comprehensive
  156. descriptions can be found by following these links:
  157. - `Debootstrap <https://wiki.debian.org/EmDebian/CrossDebootstrap>`_
  158. - `Multiarch <https://wiki.debian.org/Multiarch/HOWTO>`_
  159. - `Building LLVM <https://llvm.org/docs/CMake.html>`_
  160. - `Cross-compiling the kernel <https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Cross-compiling_the_kernel>`_
  161. - `QEMU s390x Guest Support <https://wiki.qemu.org/Documentation/Platforms/S390X>`_
  162. - `Plan 9 folder sharing over Virtio <https://wiki.qemu.org/Documentation/9psetup>`_
  163. - `Using GDB with QEMU <https://wiki.osdev.org/Kernel_Debugging#Use_GDB_with_QEMU>`_