设为首页 收藏本站
查看: 1179|回复: 0

[经验分享] GPU pass-through on KVM with Windows 7 Guest

[复制链接]

尚未签到

发表于 2017-6-25 12:53:05 | 显示全部楼层 |阅读模式
  2015年1月13日 发布
  OS: CentOS 6.5
  Graphic Cards: Embedded Graphic Card, Grid K1, Grid K2
  Hypervisor: KVM
  Benchmark tool: Specviewperf 11
  
1. kernel recompile using linux-3.18.2
  Download link:
  https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.2.tar.gz
  
Before compiling kernel, install needed packages:

  • yum install ncurses-devel hmaccalc zlib-devel binutils-devel elfutils-libelf-devel qt-devel
  • yum groupinstall "Development Tools"
  Extract to /usr/scr/ directory

  • tar -xvzf linux-3.18.2
  • cd linux-3.18.2
  • make mrproper
  • make clean
  • cp /boot/config-'uname -r' ./.config
  • make menuconfig
  There are 3 big options to check and modify:

  • Bus Options (PCI etc.)

    • <*> PCI Stub driver

  • Networking support (changing kernel from 2.x version to 3.x version)

    • Networking options

      • Network packet filtering framework(Netfilter)

        • IP: Netfilter Configuration

          • <M> IPv4 NAT

        • IPv6: Netfilter Configuration

          • <M> IPv6 NAT




  • Device Drivers


    • IOMMU Hardware Support


      • Support for IOMMU using DMA Remapping Devices

      • Enable DMA Remapping Devices by default


  • <*> VFIO Non-Privileged userspace driver framework

    • <*> VFIO support for PCI devices

    • VFIO PCI support for VGA devices

  Continue to recompile kernel

  • make all // only when you first recompile kernel, after that, use make command
  • make modules_install
  • make install
  • vi /boot/grub/grub.conf
  Here modify kernel booting priority: default =0
  Add intel_iommu=on to kernel line

  
(If you are using an intel IGP on your host, you need the i915 vga arbiter patch)
  i915 vga arbiter fixes file: https://lkml.org/lkml/2014/5/9/517
  
Continue to recompile kernel

  • reboot
  Check if your host is ready to PCI device pass-through using follow commands:

  • dmesg | grep -e DMAR -e IOMMU

  ACPI: DMAR 0x00000000BD3346F4 000158 (v01 DELL   PE_SC3   00000001 DELL 00000001)

  Intel-IOMMU: enabled

  dmar: IOMMU 0: reg_base_addr d5000000 ver 1:0 cap d2078c106f0466 ecap f020de

  dmar: IOMMU 1: reg_base_addr df900000 ver 1:0 cap d2078c106f0466 ecap f020de

  IOAPIC id 2 under DRHD base  0xd5000000 IOMMU 0

  IOAPIC id 0 under DRHD base  0xdf900000 IOMMU 1

  IOAPIC id 1 under DRHD base  0xdf900000 IOMMU 1

  IOMMU 0 0xd5000000: using Queued invalidation

  IOMMU 1 0xdf900000: using Queued invalidation

  IOMMU: Setting RMRR:

  IOMMU: Setting identity map for device 0000:00:1d.0 [0xbf452000 - 0xbf452fff]

  IOMMU: Setting identity map for device 0000:00:1a.0 [0xbf450000 - 0xbf450fff]

  IOMMU: Setting identity map for device 0000:00:1a.0 [0xbf458000 - 0xbf46ffff]

  IOMMU: Setting identity map for device 0000:00:1d.0 [0xbf458000 - 0xbf46ffff]

  IOMMU: Prepare 0-16MiB unity mapping for LPC

  IOMMU: Setting identity map for device 0000:00:1f.0 [0x0 - 0xffffff]
  
2. Install kvm

  • yum install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools
  (or)

  • yum groupinstall "Virtualisation Tools" "Virtualization Platform“
  • yum install python-virtins
  Start kvm:

  • chkconfig libvirtd on
  • service libvirtd start
  3. Create Windows 7 guest

  • ISO image file download link: Click Here
  • VirtIO drivers for windows guest download link: Click Here
  Run virt-manager

  • virt-manager //when using vnc to access, use dbus-launch virt-manager command
  Network bridge setup
  Edit->Connection Detail->Network Interface
  Ad br0 (bridge) connect to em1

Edit /etc/sysconfig/network-scripts/ifcfg-br0

Add GATEWAY and DNS1

Restart network service



  • service network restart
Create qcow2 Image Disk



  • cd /home/'username'/images/
  • qemu-img create -f qcow2-o preallocation=metadata win7.qcow2 60G
  (image convert command is like this:



  • qemu-img convert -f raw -O qcow2 win7.dsk win7.qcow2
  • qemu-img convert -f vmdk -O raw win7.vmdk win7.img     )
  
Create new virtual machine (windows 7)

Add Windows 7 ISO file and virtIO driver file(Load VirtIO driver)



Setup public ip to virtual machine


Setup remote access with port 2222(course there is no DVI output on GridK1,K2)

My Computer(Right Click) -> Option -> Remote Setup -> Access All

Control Panel -> Windows Firewall -> Advanced Setting -> Inbound Rule -> New Rule -> Port -> TCP and Special Port(?): 2222 -> Named "Remote Poart 2222"




run->regedit



  • HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Control -> Terminal server -> Wds -> rdpwd -> Tds -> tcp ->PortNumber
  • HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Control -> Terminal server -> WinStations -> RDP-Tcp -> PortNumber
  Edit 10 value as 2222


we can use xxx.xxx.xxx.x:2222 to remote access.



3. Install Needed Softwares



  • GPU-Z Click here to Download
  • Specviewperf 11 Click Here to Download
4. Bind PCI device to virtual machine using pci-stub driver



  • lspci -nn | grep VGA
07:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107GL [GRID K1] [10de:0ff2] (rev a1)
08:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107GL [GRID K1] [10de:0ff2] (rev a1)
09:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107GL [GRID K1] [10de:0ff2] (rev a1)
0a:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107GL [GRID K1] [10de:0ff2] (rev a1)

10:00.0 VGA compatible controller [0300]: Matrox Electronics Systems Ltd. G200eR2 [102b:0534]

  • vi /usr/bin/pci-bind

  -----------------------------------------------------------------------------------

  #!/bin/bash


  #modprobe pci-stub


  for dev in "$@"; do

  vendor=$(cat /sys/bus/pci/devices/$dev/vendor)

  device=$(cat /sys/bus/pci/devices/$dev/device)

  if [ -e /sys/bus/pci/devices/$dev/driver ]; then

  echo $dev > /sys/bus/pci/devices/$dev/driver/unbind

  fi

  echo $vendor $device > /sys/bus/pci/drivers/pci-stub/new_id

  done

  ------------------------------------------------------------------------------------

  • chmod 755 /usr/bin/pci-bind
  • pci-bind 0000:07:00.0
  • lspci -v -s 07:00.0
  ------------------------------------------------------------------------------------
  07:00.0 VGA compatible controller: NVIDIA Corporation GK107GL [GRID K1] (rev a1) (prog-if 00 [VGA controller])
  Subsystem: NVIDIA Corporation Device 1012
  Flags: bus master, fast devsel, latency 0, IRQ 33
  Memory at d4000000 (32-bit, non-prefetchable) [size=16M]
  Memory at 3fff8000000 (64-bit, prefetchable) [size=128M]
  Memory at 3fff6000000 (64-bit, prefetchable) [size=32M]
  I/O ports at <ignored> [disabled]
  Expansion ROM at d5800000 [disabled] [size=512K]
  Capabilities: [60] Power Management version 3
  Capabilities: [68] MSI: Enable- Count=1/1 Maskable- 64bit+
  Capabilities: [78] Express Endpoint, MSI 00
  Capabilities: [b4] Vendor Specific Information: Len=14 <?>
  Capabilities: [100] Virtual Channel
  Capabilities: [128] Power Budgeting <?>
  Capabilities: [420] Advanced Error Reporting
  Capabilities: [600] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
  Capabilities: [900] #19
  Kernel driver in use: pci-stub

  ------------------------------------------------------------------------------------

  
  5. Attach PCI device to virtual machine

  • virt-manager
  Add Hardware -> PCI Host Device -> 0000:07:00.0 GK107GL [GRID K1]



  • Start win7 (virtual machine)
  • Install NVIDIA graphic driver 341.21
  6. Accecc to Virtual Machine by Remote Desktop



  • xxx.xxx.xxx.x:2222
  • Run GPU-Z



  • Run Specviewperf 11

  


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-387974-1-1.html 上篇帖子: KVM之vnc图形界面安装虚拟机 下篇帖子: 2017.4.28 KVM 内存虚拟化及其实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表