2012年6月22日 星期五

Intel SR-IOV在 RHEL6上面的實行


因為RHEL5到RHEL6,整個架構有大改。 Virtual的module也從xen變成KVM,所以有些東西要update一下。


以步驟來說.....................


0. 因為SR-IOV是包含在VT-d裡的function,所以如果要在guest OS使用的話,別忘了到BIOS把VT-d的選項打開


1. 再來,當然要先確認要使用的NIC有支援



Verify if the PCI device with SR-IOV capabilities are detected. This example lists an Intel 82576 network interface card which supports SR-IOV. Use the lspci command to verify if the device was detected.
# lspci
03:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
03:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)






2. 然後安裝新的Driver (此例是igb)


3. 怎麼啟用SR-IOV呢?


其實就只是在modprobe後面,加上max_vfs的參數,後面接著的數字就是一個port要延伸出vf的數量。上限因卡而異。如果有兩個port以上,數字之間用逗號隔開即可。



The max_vfs parameter of the igb module allocates the maximum number of Virtual Functions. The max_vfsparameter causes the driver to spawn, up to the value of the parameter in, Virtual Functions. For this particular card the valid range is 0 to 7.
Remove the module to change the variable.
# modprobe -r igb
Restart the module with the max_vfs set to 1 or any number of Virtual Functions up to the maximum supported by your device.
# modprobe igb max_vfs=7


順道一提,由於RHEL6不再有modprobe.conf這個檔案。所以要讓vf自動掛載的話,要在 /etc/modprobe.d/ 下面,新增一個igb.conf的檔案(檔名自訂即可),然後填入 options igb max_vfs=7 。這樣就跟以前的modprobe.conf的方法一樣了。

4. 怎麼確定有沒有啟用?

很簡單,lspci
# lspci | grep 82576
0b:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0b:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0b:10.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.3 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.5 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.6 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:10.7 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.0 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.1 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.2 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.3 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.4 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
0b:11.5 Ethernet controller: Intel Corporation 82576 Virtual Function (rev 01)
頭兩個是原本的Physical port,後面就是新增出來的VF囉。



再來就是跟RHEL 的document不太一樣的地方。

由於這時候創造出來的VF也可以被host OS所使用(就當作有16個port咩),而host OS跟guest OS之間,同時只能有一個人可以使用VF,所以我們要先讓host把VF的使用權交出來。

如果剛剛有手癢檢查一下的話會發現,VF跟PF所使用的driver是不一樣的。在這裡PF是使用igb,VF則是使用igbvf,所以我們只要讓host不要去load igbvf即可。

6. Block igbvf

這沒什麼難度,修改 /etc/modprobe.d/blacklist.conf ,把igbvf加進blacklist.conf即可


7.開啟kernel的iommu

這邊要回頭開啟OS的iommu支援的功能
我們可以修改grub.conf,並把下面這個option加入kernel這一行
 intel_iommu=on   for Intel based systems
 amd_iommu=on for AMD based systems
Intel跟AMD都有支援喔,就看你的platfrom是哪個,就怎麼修改

8. 在VM中使用VF

怎麼create VM這個問題,因為現在都有圖形介面,沒什麼難度,就不作介紹。
剛剛產生出來的VF,因為是要讓guest OS直接控制,所以作法是,在VM的設定那邊,直接加入PCI device (不是加入NIC裝置喔)。要加入哪一個VF,可以用lspci去確認PCI位置,然後在VM manager這邊加入對應的PCI device。這樣在VM中,guest OS就可以直接用igbvf這支driver去存取VF了。