14
PCIe & SRIOV in virtual PCIe & SR IOV in virtual environment environment 海老澤 健太郎 海老澤 健太郎 Twitter: @ebiken [email protected]

20111015 勉強会 (PCIe / SR-IOV)

Embed Size (px)

DESCRIPTION

2011年10月15日勉強会@武蔵小杉PCIe SR-IOV

Citation preview

Page 1: 20111015 勉強会 (PCIe / SR-IOV)

PCIe & SR‐IOV in virtualPCIe & SR IOV in virtual environmentenvironment

海老澤 健太郎海老澤 健太郎

Twitter: @[email protected]

Page 2: 20111015 勉強会 (PCIe / SR-IOV)

PCI コンフィグレーション空間

• デバイス上のFunction毎に存在するメモリ空間• ドライバはここにアクセスすることによりデバイスを操作

• アクセス方法– IO Port:起動時 or Legacy

d– MMIO : Memory Mapped IO

• フォーマットは3タイプ– Type 0 : non‐bridge functionype 0 : o b dge u ct o

• 一般的なデバイスはこちら(NIC, DISK)

– Type 1 : PCI‐to PCI Bridge• PCIe Switch で Packet Routing するための情報を含む

– Type 2 : CardBus Bridgeyp g

• サイズ・配置– PCIe = 4KByte (そのうち PCI 共通=256 Byte)

64 B t コンフィグレ ション空間ヘッダ部分(PCI共通部)– 64 Byte : コンフィグレーション空間ヘッダ部分(PCI共通部)– 192 Byte :デバイス固有の領域(PCI共通部)

2

Page 3: 20111015 勉強会 (PCIe / SR-IOV)

PCI コンフィグレーション空間:配置

物理メモリ空間 SDRAM PCIメモリ空間

メインメモリ

システムBIOS4GB

メインメモリ

PCI用MMIO3GB

PCIデバイス

メインメモリ メインメモリ

予約1MB

シャドウRAM

VGAビデオ

コンベンショナルメモリ(640KB)0MB

0xa0000

メインメモリ

VGAビデオ

3

(640KB)0MB

Page 4: 20111015 勉強会 (PCIe / SR-IOV)

Type 031 - 24 23 - 16 15 - 8 7 - 0

1 00h Device ID Vendor ID1 00h Device ID Vendor ID

2 04h Status Command

3 08h Class code Subclass Prog IF Revision ID

4 0Ch BIST Header type Latency Timer Cache Line Size4 0Ch BIST Header type Latency Timer Cache Line Size

5 10h Base address #0 (BAR0)

6 14h Base address #1 (BAR1)

7 18h Base address #2 (BAR2)7 18h Base address #2 (BAR2)

8 1Ch Base address #3 (BAR3)

9 20h Base address #4 (BAR4)

10 24h Base address #5 (BAR5)10 24h Base address #5 (BAR5)

11 28h Cardbus CIS Pointer

12 2Ch Subsystem ID Subsystem Vendor ID

13 30h Expansion ROM base address13 30h Expansion ROM base address

14 34h ReservedCapabilities

Pointer

15 38h Reserved

16 3Ch M l t Mi G t I t t PIN I t t Li

4

16 3Ch Max latency Min Grant Interrupt PIN Interrupt Line

Page 5: 20111015 勉強会 (PCIe / SR-IOV)

コンフィグレーション空間 … PF on Host[root@dut 0000:03:00.1]# lspci –x03:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01)

Vendor ID = 8086 (Intel)Device ID = 151c (82599EB 10 Gigabit TN Network Connection)

Command = 0407bit 0 : IO enable

Header Type = 80bit 7 : Multi functionbit 6‐0 : non‐bridge function

00: 86 80 1c 15 07 04 10 00 01 00 00 02 10 00 80 00

bit 1 : Mem enable

Status = 0010Revision ID = 01 Class code = 02 (Network Controller)

10: 04 00 20 df 00 00 00 00 c1 ec 00 00 00 00 00 0020: 04 80 1f df 00 00 00 00 00 00 00 00 86 80 2c a030: 00 00 00 00 40 00 00 00 00 00 00 00 0e 02 00 00

BAR#01 = 0000 0000 df20 0004 (Mem, 64bit) 

BAR#45 0000 0000 df1f 8004 (M 64bi )

BAR#23 = 0000 0000 0000 ecc1(IO, 32bit)

IRQ Line = 0eIRQ PIN = INTB#

BAR#45 = 0000 0000 df1f 8004 (Mem, 64bit)

Subsystem ID = a02c (***********)

Subsystem Vendor ID = 8086 (Intel)

PCI IDs = Vendor ID + Device IDhttp://pciids.sourceforge.net/

5

!!PCIはリトルエンディアン!!p p g

http://pci‐ids.ucw.cz/read/PC/8086

Page 6: 20111015 勉強会 (PCIe / SR-IOV)

コンフィグレーション空間 … VF on Host[root@dut 0000:03:00.1]# lspci –x03:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01)

/Vendor ID = ffff (n/a)Device ID = ffff (n/a)

Command = 0004bit 0 : IO disable

Header Type = 80bit 7 : Single functionbit 6‐0 : non‐bridge function

00: ff ff ff ff 04 00 10 00 01 00 00 02 00 00 00 00

bit 1 : Mem disable

Status = 0010Revision ID = 01 Class code = 02 (Network Controller)

10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0020: 00 00 00 00 00 00 00 00 00 00 00 00 86 80 2c a030: 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00

BAR#01 = 0000 0000 0000 0000

BAR#45 = 0000 0000 0000 0000

BAR#23 = 0000 0000 0000 0000 IRQ Line = 00IRQ PIN = n/a

BAR#45 = 0000 0000 0000 0000

Subsystem ID = a02c (***********)

Subsystem Vendor ID = 8086 (Intel)

PCI IDs = Vendor ID + Device IDhttp://pciids.sourceforge.net/

6

p p ghttp://pci‐ids.ucw.cz/read/PC/8086 !!PCIはリトルエンディアン!!

Page 7: 20111015 勉強会 (PCIe / SR-IOV)

コンフィグレーション空間 … VF on Guest[root@dutvm‐sriov ~]# lspci ‐ x00:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01)

Vendor ID = 8086 (Intel)Device ID = 10ed (82559 Ethernet Controller Virtual Function)

Command = 0407 bit 0 : IO enable

Header Type = 80bit 7 : Single functionbit 6‐0 : non‐bridge function

00: 86 80 ed 10 07 04 10 00 01 00 00 02 00 00 00 00

bit 1 : Mem enable

Status = 0010Revision ID = 01 Class code = 02 (Network Controller)

10: 00 00 02 f2 00 00 00 00 00 00 00 00 00 40 02 f220: 00 00 00 00 00 00 00 00 00 00 00 00 86 80 2c a030: 00 00 00 00 a0 00 00 00 00 00 00 00 00 00 00 00

BAR#0 = f202 0000 (Mem, 32bit)

BAR#45 = 0000 0000 0000 0000

BAR#3 = f202 4000 (Mem, 32bit) IRQ Line = 00IRQ PIN = n/a

BAR#45 = 0000 0000 0000 0000

Subsystem ID = a02c (***********)

Subsystem Vendor ID = 8086 (Intel)

PCI IDs = Vendor ID + Device IDhttp://pciids.sourceforge.net/

7

p p ghttp://pci‐ids.ucw.cz/read/PC/8086 !!PCIはリトルエンディアン!!

Page 8: 20111015 勉強会 (PCIe / SR-IOV)

PF on Host[root@dut ~]# lspci ‐v ‐s 03:00.003:00.0 Ethernet controller: Intel Corporation 82599EB 10 Gigabit TN Network Connection (rev 01)

b l i iSubsystem: Intel Corporation Device a02cFlags: bus master, fast devsel, latency 0, IRQ 45Memory at df200000 (64‐bit, non‐prefetchable) [size=2M]I/O ports at ecc0 [size=32]Memory at df1f8000 (64‐bit, non‐prefetchable) [size=16K]Capabilities: [40] Power Management version 3Capabilities: [50] MSI: Enable‐ Count=1/1 Maskable+ 64bit+Capabilities: [70] MSI‐X: Enable+ Count=64 Masked‐Capabilities: [70] MSI X: Enable  Count 64 MaskedCapabilities: [a0] Express Endpoint, MSI 00Capabilities: [e0] Vital Product DataCapabilities: [100] Advanced Error ReportingCapabilities: [140] Device Serial Number 00 1b 21 ff ff ce 51 c4Capabilities: [140] Device Serial Number 00‐1b‐21‐ff‐ff‐ce‐51‐c4Capabilities: [150] Alternative Routing‐ID Interpretation (ARI)Capabilities: [160] Single Root I/O Virtualization (SR‐IOV)Kernel driver in use: ixgbe

l d l i bKernel modules: ixgbe

8

Page 9: 20111015 勉強会 (PCIe / SR-IOV)

VF on Host / Guest 比較[root@dut ~]# lspci ‐v ‐s 03:10.003:10.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller Virtual Function (rev 01)

Subsystem: Intel Corporation Device a02cSubsystem: Intel Corporation Device a02cFlags: bus master, fast devsel, latency 0[virtual] Memory at d0000000 (64‐bit, prefetchable) [size=16K][virtual] Memory at d0100000 (64‐bit, prefetchable) [size=16K]Capabilities: [70] MSI‐X: Enable+ Count=3 Masked‐p [ ]Capabilities: [a0] Express Endpoint, MSI 00Capabilities: [100] Advanced Error ReportingCapabilities: [150] Alternative Routing‐ID Interpretation (ARI)Kernel driver in use: pci‐stub

l d l b fKernel modules: ixgbevf

[root@dutvm‐sriov ~]# lspci ‐v ‐s 00:03.000:03.0 Ethernet controller: Intel Corporation 82559 Ethernet Controller Virtual Function (rev 01)

Subsystem: Intel Corporation Device a02cSubsystem: Intel Corporation Device a02cPhysical Slot: 3Flags: bus master, fast devsel, latency 0Memory at f2020000 (32‐bit, non‐prefetchable) [size=16K]Memory at f2024000 (32‐bit, non‐prefetchable) [size=16K]y ( , p ) [ ]Capabilities: [a0] Express Endpoint, MSI 00Capabilities: [70] MSI‐x: Enable+ Count=3 Masked‐Kernel driver in use: ixgbevfKernel modules: ixgbevf

9

Page 10: 20111015 勉強会 (PCIe / SR-IOV)

IO v.s. Memory ‐Mapped IO• IO Mapped IO

– IO port (IO空間) を利用– IO空間のアドレス=IOポートアドレス、ポート番号– 1,2,4 Byte単位でのRead/Write– IO Port専用のニーモニックがある。asm/io.h

• MMIO : Memory Mapped IO– IO Portの代わりにメモリアクセスをハードウェアレベルでのデバイスへのアクセスに置換

– デバイスに割当られたアドレス範囲にメモリアクセスをすることにより、ドライバからデバイスのレジスタRead/Write可能のレジスタRead/Write可能

– ドライバが動作する「仮想メモリアドレス」と、MMIO確保された「物理メモリアドレス」の違いに注意

PCI L (PCI R B id D i ) は共通• PCIe Layer (PCIe Root Bridge <‐> Device) は共通– Config TLP (Transaction Layer Packet) でアクセス

• 共通の抽象的なインターフェース有り共通の抽象的なインタ フェ ス有り– asm/iomap.h– void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max len);

10

Page 11: 20111015 勉強会 (PCIe / SR-IOV)

IO v.s. Memory ‐Mapped IO• IO Ports, MMIO割当確認方法

– [root@hwn01 ~]# ls /proc/ | grep ^io– iomem– ioports[root@hwn01 ~]# cat /proc/ioports0000‐0cf7 : PCI Bus 0000:000000‐001f : dma10020‐0021 : pic10040‐0043 : timer00050‐0053 : timer10050‐0053 : timer10060‐0060 : keyboard

[root@hwn01 ~]# cat /proc/iomem00000000 0000ffff d00000000‐0000ffff : reserved00010000‐0009f7ff : System RAM…f4000000‐f7ffffff : PCI MMCONFIG 0000 [bus 00‐3f]f4000000‐f7ffffff : reservedf4000000‐f7ffffff : pnp 00:0a

fb400000‐fb7fffff : 0000:00:02.0

11

Page 12: 20111015 勉強会 (PCIe / SR-IOV)

メモ

• MSI, MSI‐X の Configuration 空間パラメーターと、/proc/interruptで見える割り込み番号の関係で見える割り込み番号の関係– ???

• PCIe MSI, MSI‐X の処理方法NICからアドレス0xfeeに対しメモリ書き込み(DWORD MemWrite– NICからアドレス0xfeeに対しメモリ書き込み(DWORD Mem Write Transaction)

• アドレスは初期化時 MSI Capability Registerにソフトウェア(BIOS??)がセット• 0xfeeはLocal APIC のレジスタへMemory Mapされている0xfeeはLocal APIC のレジスタ Memory Mapされている

– LAPICがCPUへ割り込み通知(INTR)– CPU⇒ LAPICへAck(INTA)– LAPIC⇒CPU:Vectorを返すLAPIC⇒CPU:Vectorを返す

• VFのBAR– VFのメモリ空間にはBARはない

PFのSR IOV C bilit R i t に設定– PFのSR‐IOV Capability Registerに設定– Host の lspci ‐v はそちらを表示

12

Page 13: 20111015 勉強会 (PCIe / SR-IOV)

メモ

• 空の PCI スロットのベ ンダ ID とデバイス ID を読み取ろうとしたときは、0xFFFFFFFF というエラー メッセージが返るラ メッセ ジが返る

• BARは起動時にBIOSが割り当て

– http://www.mnc.co.jp/intime/user/intimedev.phphttp://www.mnc.co.jp/intime/user/intimedev.php?PCI%A5%B3%A5%F3%A5%D5%A5%A3%A5%B0%A5%EC%A1%BC%A5%B7%A5%E7%A5%F3%A5%ECA5%EC%A1%BC%A5%B7%A5%E7%A5%F3%A5%EC%A5%B8%A5%B9%A5%BF

13

Page 14: 20111015 勉強会 (PCIe / SR-IOV)

割り込み一覧(/proc/interrupts)[root@hwn01 ~]# cat /proc/interrupts

CPU0 CPU1 CPU2 CPU30: 144 1 0 0 IO-APIC-edge timer1: 3 0 1 2 IO-APIC-edge i80424 0 1 1 0 d4: 0 1 1 0 IO-APIC-edge8: 33 58 31 57 IO-APIC-edge rtc09: 0 0 0 0 IO-APIC-fasteoi acpi

16: 0 0 0 0 IO-APIC-fasteoi ahci, uhci_hcd:usb3, uhci_hcd:usb917: 115 3 1 1 IO-APIC-fasteoi pata_jmicron, firewire_ohci18: 2150 3669 117 284 IO-APIC-fasteoi ehci_hcd:usb1, uhci_hcd:usb5, uhci_hcd:usb819: 51447 1305 39191 1307 IO-APIC-fasteoi ata_piix, ata_piix, uhci_hcd:usb721: 0 0 0 0 IO-APIC-fasteoi uhci_hcd:usb423: 0 0 0 0 IO-APIC-fasteoi ehci_hcd:usb2, uhci_hcd:usb641: 58395 289 3073 269 PCI-MSI-edge i915@pci:0000:00:02.042: 47 50 47 52 PCI-MSI-edge hda_intel43: 2710 6576 3336 3655 PCI-MSI-edge eth044: 0 0 0 1 PCI-MSI-edge xhci_hcd45: 0 0 0 0 PCI-MSI-edge xhci_hcd46: 0 0 0 0 PCI-MSI-edge xhci_hcd47: 0 0 0 0 PCI-MSI-edge xhci_hcd48: 0 0 0 0 PCI-MSI-edge xhci_hcd49: 2985 6 648 5 PCI-MSI-edge eth1NMI: 13 34 95 28 Non-maskable interruptsLOC: 332011 170933 296037 190006 Local timer interruptsSPU: 0 0 0 0 Spurious interruptsPMI: 13 34 95 28 Performance monitoring interruptsIWI: 0 0 0 0 IRQ work interruptsRES: 452195 37148 103501 14434 Rescheduling interruptsg pCAL: 812 6027 1044 7911 Function call interruptsTLB: 1077 644 2068 824 TLB shootdownsTRM: 0 0 0 0 Thermal event interruptsTHR: 0 0 0 0 Threshold APIC interruptsMCE: 0 0 0 0 Machine check exceptionsMCP: 29 28 28 28 Machine check pollsMCP: 29 28 28 28 Machine check pollsERR: 0MIS: 0

14