SHARE
TWEET

dweller

a guest Apr 5th, 2014 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. w
  3.  
  4.  
  5. # echo 0000:0c:00.0 > /sys/bus/pci/devices/0000:0c:00.0/driver/unbind
  6. # echo 8086 4232 > /sys/bus/pci/drivers/vfio-pci/new_id
  7.  
  8. passthru_mode=1
  9. ram_size=4608
  10.  
  11. devices="00:1b.0 01:00.0 01:00.1"
  12.  
  13. unbind()
  14. {
  15.     for dev in $@; do
  16.         ## get device driver to rebind it after vm is down
  17.         if [ $1 == '-d' ]; then
  18.             drv="$(lspci -s ${dev} -k | awk '/Kernel driver in use:/ {print($5)}')"
  19.             if [ ${drv} ]; then
  20.                 drv_dev="${drv}=${dev} ${drv_dev}"
  21.             fi
  22.         fi
  23.  
  24.         if [ -e /sys/bus/pci/devices/0000:${dev}/driver/unbind ]; then
  25.             echo 0000:${dev} > /sys/bus/pci/devices/0000:${dev}/driver/unbind || exit 1
  26.             echo "${dev} was unbinded"
  27.         fi
  28.     done
  29. }
  30.  
  31. rebind()
  32. {
  33.  
  34.     for i in ${drv_dev}; do
  35.         drv=$(echo ${i} | awk '{ split($1,a,"="); print(a[1]);}')
  36.         dev=$(echo ${i} | awk '{ split($1,a,"="); print(a[2]);}')
  37.         drv_path=$(find /sys/module -name pci:${drv})
  38.  
  39.         if [[ ( ${dev} ) && ( -e ${drv_path} ) ]]; then
  40.             echo 0000:${dev} > ${drv_path}/bind || echo "${dev} is already binded or device error"
  41.             echo "${dev} was binded to ${drv}"
  42.         fi
  43.         unset drv_dev
  44.     done
  45. }
  46.  
  47. bind_vfio() {
  48.     for dev in $@; do
  49.         echo $(lspci -n | grep ${dev} | awk '{ split($3,a,":"); print(a[1],a[2]);}') > /sys/bus/pci/drivers/vfio-pci/new_id || exit 1
  50.         echo "${dev} was binded to vfio-pci"
  51.     done
  52. }
  53.  
  54. ## DO THE MAGIC
  55.  
  56. if [ $passthru_mode == 1 ]; then
  57.     unbind -d $devices
  58.     bind_vfio $devices
  59.  
  60.     passthru_devices="\
  61.    -vga none -nographic \
  62.    -usb -usbdevice host:046d:c526 \
  63.    -device ioh3420,bus=pcie.0,addr=1a.0,multifunction=on,port=1,chassis=1,id=root.1 \
  64.    -device vfio-pci,host=00:1b.0,bus=pcie.0,addr=1b.0 \
  65.    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on,romfile=./bios/GF106_modded_max.rom \
  66.    -device vfio-pci,host=01:00.1,bus=root.1,addr=00.1"
  67. fi
  68.  
  69. ## clear diskcache
  70. ./scripts/clearcache
  71.  
  72. ## reserve hugepages
  73. current_hugepages=$(cat /proc/sys/vm/nr_hugepages)
  74. echo $(( ${ram_size} / 2 + 8 + $current_hugepages )) > /proc/sys/vm/nr_hugepages
  75.  
  76. ## assign cores 2,3 and ht threads 4,5
  77. taskset 0x0000003c \
  78. nice -n -5 qemu-system-x86_64 \
  79. -enable-kvm -rtc base=localtime,clock=host \
  80. -bios /usr/share/qemu/bios.bin \
  81. -M q35 -cpu host -smp 4,sockets=1,cores=2,threads=2 \
  82. -m $ram_size -mem-path /dev/hugepages \
  83. -monitor stdio \
  84. -boot dc \
  85. -netdev bridge,br=br,id=bridge -device virtio-net-pci,netdev=bridge,id=nic1 \
  86. -drive file='./images/windows.img',if=none,id=disk_windows \
  87. -device virtio-blk-pci,scsi=off,drive=disk_windows,id=disk1 \
  88. -drive file='./images/gamesdata.img.qcow2',if=none,id=disk_games \
  89. -device virtio-blk-pci,scsi=off,drive=disk_games,id=disk4 \
  90. $passthru_devices
  91.  
  92. if [ $passthru_mode == 1 ]; then
  93.     unbind $devices
  94.     rebind
  95. fi
  96.  
  97.  
  98. echo 4 > /proc/sys/vm/nr_hugepages
  99.  
  100. #current_hugepages=$(cat /proc/sys/vm/nr_hugepages)
  101. #echo $(( ${current_hugepages} - ${hugepages} - 4 )) > /proc/sys/vm/nr_hugepages
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top