xv6˥ͥåȥǽ
̳˰ܹԤƤ1Ⱦۤɷвᤷޤ̶ФȤǰǤǸ椫ưǤ褦ˤʤä @pandax381 Ǥ
ե륹åǼ TCP/IP ץȥ륹å xv6 Ȥ߹ߡ̤εǽư褦ˤʤޤ
I publish the implementation of TCP/IP network stack on xv6. I ported my user-mode TCP/IP stack, which was originally developed for learning, and added the e1000 driver and socket system calls. Some parts are still not enough, but they are working.https://t.co/nht9JDMVbl
— YAMAMOTO Masaya (@pandax381) March 11, 2020
а
줳78ǯ餤ФĤǤɡ饤եȤƤٶѤTCP/IPץȥ륹åγȯۤܤ³Ƥޤ
Ūˡץȥ륹åOSεǽΰȤƥͥ¸ߤƤΤǤμץȥ륹åϡ䤹Ż뤷Թǥ桼֤ΥץꥱѤΥ饤֥ȤƼƤޤ
Dzؤ˰֤٥Ϥ PF_PACKET / BPF / TAP Ѥ뤪ڻͤǡ˥ѥåȽǰǤ褦ˤʤäƤޤ
꤬Ƥʬ⤢ޤEthernetե졼TCPȤΤޤƤǽƤޤ֥ץȥ륹åäƤɤʺˤʤäƤפȶ̣äͤФʷϵϤΤ٤餤Υܥ塼ˤʤäƤʤȻפޤ
ʪǥХեݲȤʤ˺ǤΤạ̇̄ä饳ɸƤ
ǯåפ˾Ƥơδĥˤä DHCP饤ȵǽѥåžǽˤDPDKݡȤȤäɤä줤ޤ12֤Ȥû֤̤ФƤޤ
ήǡƤˤ KLab Expert Camp Ȥɥ٥ȤŤޤ
KLab Expert Camp ŷꡪ1ơޤϡTCP/IPץȥ륹åȯפǡֻդͤôޤ 8/2629 4֤Ǥγš KLab ôޤץȥ륹å˶̣ΤΤߤʤ˳ڤƤᤴޤ礦https://t.co/SVyMOzaeq8
— YAMAMOTO Masaya (@pandax381) April 26, 2019
4֡Ҥץȥ륹åȯȤޥ˥åʹɥ٥Ȥˤ⤫餺餿γäƤ졢̤ƴŪʻȤߤؤꡢ̸ؤΰܿ䵡ǽɲä˼ȤǤޤ
üԤΥեɥХåɤƺŪ˳ŤʤȻפǡǶưƤȡּCPUưƤ뼫ѥǥӥɤOS˼ץȥ륹åȤ߹ߤפȤХͤиǽ⽽ʬꤽʵƤޤ
ʤȤ⡢桼֤ǤưȤƤ饤֥ξ֤OSΥͥȤ߹⤦Ȥݤˤɤ櫤Ǥ뤫İƤʤȤˤϡʬ˥ݡȤƤʤȤܤ˸Ƥޤʤ櫓ǡ֤ޤϼʬǤäƤߤ뤫פȤΤμȤߤΤ⤽ưǤ
꺢OS
Ѥʤ顢ͤOSϤǤ餺ּʬOSפͭƤޤ30OSܤ֤Ĥɤ⤦פѤǤʤΤǡOSϤƤȻ֤ݤꤹƤޤޤȸä Linux BSD ȡ١ˤˤϵϤ礭ޤ
äӤˤϡѥȤ xv6 Ƥʵޤ
CPUϢǤˤо줷ƤޤޤޤǤʤȻפޤxv6 Version 6 UNIX (V6) x86ʥޥץåĶ˸˺ƼΤǤMITڥ졼ƥƥιֵѤ˳ȯMITʳˤ¿ζ鵡ؤȤƺѤƤޤ
̤10,000٤ǡOSμˤۤɾܤʤƤΤϤȤǤܥ塼Ǥ¤ɥȤͤƤƤ˭٤ˤΤ⿴Ǥ
Ƕ RISC-V μ˰ܹԤ褦ǡMITιֵǿΤΤ RISC-V Ǥ١ˤʤäƤޤx86 Ǥ 2018 ǯٰΥ֤Ȥޤ礦
ɤϤ뤫
xv6 ˤϥͥåȥǽڴޤޤƤʤᡢNICΥɥ饤Фɬפޤץȥ륹åǤϥOSεǽPF_PACKET BPFˤѤƤƥɥ饤ФˤϥΡåäΤǡ⤦ʲعߤ뤳Ȥˤʤޤ
xv6 QEMU ưʤ鳫ȯʤ뤳ȤˤʤΤǡNIC QEMU ǻȤƾ˭٤ e1000 (Intel 8254x) åȤˤΤɤǤ
ޤϡɥ饤ФΥȥݥȤΥߡѰդ Hello, World! ǤϤ褦ʥɤPCI ǥХΥɥ饤ФΥꥹȤɲäƤȤϤɤ ...ȻפäΤǤ õƤ⤽äݤɤޤ
Ϥxv6 PCI ݡȤƤʤΤǤ
ä xv6 NIC ˤ
- PCIХ
- ³ƤǥХ
- бɥ饤ФƤӽФ
ȤϢνɬפꡢˤ⤦ʲعߤ뤳Ȥˤʤ櫓ǤȾ徺٤ʤꤽǤ͡
PCIν
PCIХΥ ȤȤʤʹޤI/OݡȤáƾɤࡢȤη֤ǤơդOSΤߤʤ餷ƤƤޤ
ե졼ΰäƤʤȤ֤Ǥ uchan λɤ PCI ޤʤƤޤˡ
ʲ Linux Kernel ⤷ɥȤ⻲ͤˤʤޤ
βɤߤʤ龯ŤĿʤƤ PCI ХƥǥХФ륳ɤΤϤۤʤȻפޤʤxv6-net Ǥ PCI κǽŪʥɤ JOS Ȥ̤ OS Ҽڤ뤳Ȥˤޤ
- https://pdos.csail.mit.edu/6.828/2018/jos.git
JOS ϡxv6 Ʊͤ MIT ڥ졼ƥƥιֵǻȤ˳ȯƤ OS ǤJOS ϰտŪ˺Ƥ̤OSǤꡢxv6 βʹȤˡJOS μʤƴȤΤ褦Ǥޤxv6 ΥꥷåʥͥǤΤФ JOS ϥޥͥȤ㤤⤢褦Ǥ
ɤ٤Ƥߤ JOS Ƥƥ쥤˽Ƥ뵤ΤΡΤʷϵϤʤƤޤơJOS ˤ PCI Υɤ e1000 ɥ饤ФΥȥʤۤܤʤˤƤʤäݤΥեˤѰդƤ뤿ᡢȤ碌Ƥ餦Ȥˤޤ
嵭 pci.c JOS ΥɤΤΤǤxv6 ˼ФͤϹΨ JOS ΥɤɤǤϤǡǤͤ餫ɤ JOS ΥɤȤ碌Ƥäۤɤͤ䤹ȹ̤ͤǤʥɤΤޤȤ߹िᡢ碌˾֤ݤƤꤷޤˡ
pciinit() main() 椫ƤǤȡư PCI Х³ƤǥХФޤ
PCI: 0:0.0: 8086:1237: class: 6.0 (Bridge device) irq: 0 PCI: 0:1.0: 8086:7000: class: 6.1 (Bridge device) irq: 0 PCI: 0:1.1: 8086:7010: class: 1.1 (Storage controller) irq: 0 PCI: 0:1.3: 8086:7113: class: 6.80 (Bridge device) irq: 9 PCI: 0:2.0: 1234:1111: class: 3.0 (Display controller) irq: 0 PCI: 0:3.0: 8086:100e: class: 2.0 (Network controller) irq: 11
٥IDȥǥХID˥ɥ饤ФΥȥݥȤƤȡǥХлˤáƤޤ
struct pci_driver pci_attach_vendor[] = { { 0x8086, 0x100e, &e1000_init }, { 0, 0, 0 }, };
NICΥɥ饤
PCI ΥǥХФǤ褦ˤʤä顢 NIC Υɥ饤Фޤ
JOS Υˤ kernel/e1000.c kernel/e1000.h ޤޤƤޤɤäݤǡIntel ΥɥȤɤȤäƤޤ
ͤˤʤꤽʥɤʤõƤߤȡxv6 RISC-V ǤΥݥȥˤ NIC νޤǽ줿ɥ饤ФοޤͤˤĤġإåեϤΤޤѤƤ餤ޤ
- https://github.com/mit-pdos/xv6-riscv-fall19/blob/net/kernel/e1000.c
- https://github.com/mit-pdos/xv6-riscv-fall19/blob/net/kernel/e1000_dev.h
ޤ Ƥܤ㤯狼䤹ƽޤPCIξܤƤơʾɤޤƤäɤΤ...ȴưʤ e1000 ޤʤƤޤˡEPUBǤǤ㤤ޤ
OSDev.org ǾҲ𤵤ƤʲΥɤ⻲ͤˤޤ
¾ˤ⡢ˤ xv6 e1000 ɥ饤ФƤͤΤǡgithub Ǥ⤤ĤץȤĤ뤳ȤǤޤɤݡǡߤư֤ΤΤϸĤޤǤ
ϢκȤǰֶ路Τѥåȼ˳ߤȯ뤳Ȥǡ1֤餤ϥޤäƤޤȽĤǤʤʤߤȯʤޤ줽ˤʤäƤΤǡưȤϤ㤯äǤ
ʤ֤ǻȤDMAѤΥХåե꤬ޤǤƤʤưƤʤäʤȻפäƤޤ
xv6 Ѥ e1000 ɥ饤ФưǼץȥ륹å xv6 غܤ뤿νä💪https://t.co/nht9JDMVbl pic.twitter.com/TJYkWVAKAV
— YAMAMOTO Masaya (@pandax381) February 29, 2020
դξܤȤϡޤ̤εܤǤʤȻפäƤޤ
ץȥ륹åΤΰܿ
NIC Υɥ饤ФưΤǡ褤Υץȥ륹åΤΰܿ˼ݤΤǤޤȤʤäܿǤƤޤޤäΤǡޤȤʤäꤷޤ
pthread ȤäƤΤ mutex spinlock ֤ꡢcond sleep/wakeup ֤ꤷ餤ǤȡޡȤƤʤΤǡTCPκȤޡ˰¸ϤޤưƤޤ
ޤARP ˱Ǥ褦ˤʤä
ARP˱Ǥ褦ˤʤä#ץȥ륹å#xv6 pic.twitter.com/zjBszDkK6t
— YAMAMOTO Masaya (@pandax381) March 2, 2020
ICMP ˱Ǥ褦ˤʤä
Ĵ˿ʤ ping ˱Ǥ褦ˤʤä#ץȥ륹å#xv6 https://t.co/I7BGOz4jVw pic.twitter.com/0xBivGA9LZ
— YAMAMOTO Masaya (@pandax381) March 3, 2020
UDP ̿Ǥ褦ˤʤ
ץȥ륹å on xv6 οĽ餷 UDP ̿🎉🎉🎉ʻ˼åΥƥॳ̤ƥ桼֤ΥץꥱͥΥץȥ륹åѤ̿Ƥ pic.twitter.com/VUbbeWr0TO
— YAMAMOTO Masaya (@pandax381) March 6, 2020
ǽŪ TCP ư褦ˤʤޤ
TCP ưȤȥ桼֤ưǤ館ץȥ륹å xv6 Υ֤ͥǴưƤ롪 https://t.co/juL0ntccyY pic.twitter.com/5tDU1T0B8K
— YAMAMOTO Masaya (@pandax381) March 6, 2020
å
ͥǥץȥ륹åư褦ˤʤäƤ⥽åȤʤХ桼֤̿ץꥱȤǤޤ
ץȥ륹åˤϥåAPI⤢ΤǤñʤ饤֥ؿʤΤǥץȥ륹åͥȤ߹֤Ǥϥ桼֤ΥץꥱƤӤޤ
ʤ櫓ǡå ǤϤʤΥåȡʴϢΥƥॳˤޤ
ƥॳɲäˤäƤϡxv6 δ¸Υƥॳ椫褦ʥץȥפΤΤõƱ褦˼Ƥޤ
socket() ǺǥץϡȤ¸ߤƤեǥץȸߴĤ褦˺äƤΤǡåȤΥǥץ close() Ĥꡢrecv() / senc() read() / write() ȤȤޤ
ñʥå̿ΥץǤСLinux Ѥ˽ɤΤޤư٤ˤϤȺäƤޤ
ץȥ륹å on xv6 ˻ž夬äåȴϢΥƥॳܤ˼ΤǤ褯뤳ʥɤΤޤư褦ˤʤäȥեǥץɳŤƤΤ read/write ȤäƤư fork Ƥסhttps://t.co/nht9JDMVbl pic.twitter.com/LQNvWwOpj9
— YAMAMOTO Masaya (@pandax381) March 10, 2020
ifconfig ޥ
뤫饤եξ֤ǧIPɥ쥹ꤹ뤿ˡŬʥޥɡifget / ifset / ifup / ifdownˤб륷ƥॳäơξΤǤޤ
ʥƥॳƥޥɤǥͥåȥեǤ褦ˤʤä💪#xv6#ץȥ륹å pic.twitter.com/T6LZNEtwOK
— YAMAMOTO Masaya (@pandax381) March 5, 2020
ȤäȥΤǡǽŪ ifconfig ޥɤޤip ޥɤʤΤ NETLINK μϤ˸ȤͳǤ
ֻ ifconfig äư褦ˤʤäʤ֤˽ľȻפɤȤꤢ push #xv6#networking https://t.co/TEbKeGWe3m pic.twitter.com/2mh5tVGiuy
— YAMAMOTO Masaya (@pandax381) March 30, 2020
ifconfig ioctl() ̤ƥեξ/ꤷƤΤǡioctl ΥƥॳɲäSIOCGXXX SIOCSXXX ҤǤޤ
⤳ȺǤּץȥ륹å xv6 ˰ܿפȤϡxv6 ˥ͥåȥǽפȤˤʤäΤǡΤ褦ʥȥˤʤޤ
ȡ;ä reddit ǥӥ塼⤷ޤ
reddit ǥȤ줿μOSäƤƴưΤǾҲ𤷤Ƥޤ
ޤͽΩƤΤǤ٥ȤŤǤ褦ʾˤʤä顢ޤ KLab Expert Camp ǥץȥ륹åιɤꤿȻפäƤޤκݤϼOSؤȤ߹ߤ⥵ݡȤǤ褦˽ƤޤΤdzڤߤˤƤƤ
@pandax381