TODO.smpnet revision 1.41
11.41Smrg$NetBSD: TODO.smpnet,v 1.41 2021/08/02 23:49:26 mrg Exp $ 21.1Sozaki 31.2SozakiMP-safe components 41.2Sozaki================== 51.1Sozaki 61.21SozakiThey work without the big kernel lock (KERNEL_LOCK), i.e., with NET_MPSAFE 71.21Sozakikernel option. Some components scale up and some don't. 81.21Sozaki 91.7Sozaki - Device drivers 101.30Smsaitoh - aq(4) 111.41Smrg - bcmgenet(4) 121.41Smrg - iavf(4) 131.41Smrg - ixg(4) 141.41Smrg - ixgbe(4) 151.41Smrg - ixl(4) 161.41Smrg - ixv(4) 171.41Smrg - mcx(4) 181.41Smrg - rge(4) 191.41Smrg - se(4) 201.41Smrg - sunxi_emac(4) 211.7Sozaki - vioif(4) 221.7Sozaki - vmx(4) 231.7Sozaki - wm(4) 241.41Smrg - xennet(4) 251.41Smrg - usbnet(4) based adapters: 261.41Smrg - axe(4) 271.41Smrg - axen(4) 281.41Smrg - cdce(4) 291.41Smrg - cue(4) 301.41Smrg - kue(4) 311.41Smrg - mos(4) 321.41Smrg - mue(4) 331.41Smrg - smsc(4) 341.41Smrg - udav(4) 351.41Smrg - upl(4) 361.41Smrg - ure(4) 371.41Smrg - url(4) 381.41Smrg - urndis(4) 391.7Sozaki - Layer 2 401.7Sozaki - Ethernet (if_ethersubr.c) 411.7Sozaki - bridge(4) 421.7Sozaki - STP 431.7Sozaki - Fast forward (ipflow) 441.7Sozaki - Layer 3 451.7Sozaki - All except for items in the below section 461.7Sozaki - Interfaces 471.7Sozaki - gif(4) 481.22Sozaki - ipsecif(4) 491.7Sozaki - l2tp(4) 501.7Sozaki - pppoe(4) 511.7Sozaki - if_spppsubr.c 521.40Snia - tap(4) 531.7Sozaki - tun(4) 541.12Sozaki - vlan(4) 551.7Sozaki - Packet filters 561.7Sozaki - npf(7) 571.7Sozaki - Others 581.7Sozaki - bpf(4) 591.12Sozaki - ipsec(4) 601.12Sozaki - opencrypto(9) 611.7Sozaki - pfil(9) 621.2Sozaki 631.2SozakiNon MP-safe components and kernel options 641.2Sozaki========================================= 651.2Sozaki 661.21SozakiThe components and options aren't MP-safe, i.e., requires the big kernel lock, 671.21Sozakiyet. Some of them can be used safely even if NET_MPSAFE is enabled because 681.21Sozakithey're still protected by the big kernel lock. The others aren't protected and 691.21Sozakiso unsafe, e.g, they may crash the kernel. 701.21Sozaki 711.21SozakiProtected ones 721.21Sozaki-------------- 731.21Sozaki 741.7Sozaki - Device drivers 751.7Sozaki - Most drivers other than ones listed in the above section 761.21Sozaki - Layer 4 771.21Sozaki - DCCP 781.21Sozaki - SCTP 791.21Sozaki - TCP 801.21Sozaki - UDP 811.21Sozaki 821.21SozakiUnprotected ones 831.21Sozaki---------------- 841.21Sozaki 851.6Sozaki - Layer 2 861.6Sozaki - ARCNET (if_arcsubr.c) 871.6Sozaki - IEEE 1394 (if_ieee1394subr.c) 881.6Sozaki - IEEE 802.11 (ieee80211(4)) 891.6Sozaki - Layer 3 901.6Sozaki - IPSELSRC 911.6Sozaki - MROUTING 921.6Sozaki - PIM 931.6Sozaki - MPLS (mpls(4)) 941.17Sozaki - IPv6 address selection policy 951.6Sozaki - Interfaces 961.6Sozaki - agr(4) 971.6Sozaki - carp(4) 981.6Sozaki - faith(4) 991.6Sozaki - gre(4) 1001.6Sozaki - ppp(4) 1011.6Sozaki - sl(4) 1021.6Sozaki - stf(4) 1031.6Sozaki - if_srt 1041.6Sozaki - Packet filters 1051.6Sozaki - ipf(4) 1061.6Sozaki - pf(4) 1071.6Sozaki - Others 1081.6Sozaki - AppleTalk (sys/netatalk/) 1091.6Sozaki - Bluetooth (sys/netbt/) 1101.6Sozaki - altq(4) 1111.6Sozaki - kttcp(4) 1121.6Sozaki - NFS 1131.2Sozaki 1141.2SozakiKnow issues 1151.2Sozaki=========== 1161.1Sozaki 1171.15SozakiNOMPSAFE 1181.15Sozaki-------- 1191.15Sozaki 1201.15SozakiWe use "NOMPSAFE" as a mark that indicates that the code around it isn't MP-safe 1211.15Sozakiyet. We use it in comments and also use as part of function names, for example 1221.15Sozakim_get_rcvif_NOMPSAFE. Let's use "NOMPSAFE" to make it easy to find non-MP-safe 1231.15Sozakicodes by grep. 1241.15Sozaki 1251.1Sozakibpf 1261.2Sozaki--- 1271.1Sozaki 1281.1SozakiMP-ification of bpf requires all of bpf_mtap* are called in normal LWP context 1291.1Sozakior softint context, i.e., not in hardware interrupt context. For Tx, all 1301.1Sozakibpf_mtap satisfy the requrement. For Rx, most of bpf_mtap are called in softint. 1311.1SozakiUnfortunately some bpf_mtap on Rx are still called in hardware interrupt context. 1321.1Sozaki 1331.1SozakiThis is the list of the functions that have such bpf_mtap: 1341.1Sozaki 1351.1Sozaki - sca_frame_process() @ sys/dev/ic/hd64570.c 1361.1Sozaki 1371.1SozakiIdeally we should make the functions run in softint somehow, but we don't have 1381.1Sozakiactual devices, no time (or interest/love) to work on the task, so instead we 1391.1Sozakiprovide a deferred bpf_mtap mechanism that forcibly runs bpf_mtap in softint 1401.1Sozakicontext. It's a workaround and once the functions run in softint, we should use 1411.1Sozakithe original bpf_mtap again. 1421.10Sozaki 1431.35Sjdolecekif_mcast_op() - SIOCADDMULTI/SIOCDELMULTI 1441.35Sjdolecek----------------------------------------- 1451.35SjdolecekHelper function is called to add or remove multicast addresses for 1461.35Sjdolecekinterface. When called via ioctl it takes IFNET_LOCK(), when called 1471.35Sjdolecekvia sosetopt() it doesn't. 1481.35Sjdolecek 1491.35SjdolecekVarious network drivers can't assert IFNET_LOCKED() in their if_ioctl 1501.35Sjdolecekbecause of this. Generally drivers still take care to splnet() even 1511.35Sjdolecekwith NET_MPSAFE before calling ether_ioctl(), but they do not take 1521.35SjdolecekKERNEL_LOCK(), so this is actually unsafe. 1531.35Sjdolecek 1541.10SozakiLingering obsolete variables 1551.10Sozaki----------------------------- 1561.10Sozaki 1571.10SozakiSome obsolete global variables and member variables of structures remain to 1581.10Sozakiavoid breaking old userland programs which directly access such variables via 1591.10Sozakikvm(3). 1601.10Sozaki 1611.10SozakiThe following programs still use kvm(3) to get some information related to 1621.10Sozakithe network stack. 1631.10Sozaki 1641.10Sozaki - netstat(1) 1651.10Sozaki - vmstat(1) 1661.10Sozaki - fstat(1) 1671.10Sozaki 1681.10Sozakinetstat(1) accesses ifnet_list, the head of a list of interface objects 1691.10Sozaki(struct ifnet), and traverses each object through ifnet#if_list member variable. 1701.10Sozakiifnet_list and ifnet#if_list is obsoleted by ifnet_pslist and 1711.10Sozakiifnet#if_pslist_entry respectively. netstat also accesses the IP address list 1721.10Sozakiof an interface throught ifnet#if_addrlist. struct ifaddr, struct in_ifaddr 1731.10Sozakiand struct in6_ifaddr are accessed and the following obsolete member variables 1741.10Sozakiare stuck: ifaddr#ifa_list, in_ifaddr#ia_hash, in_ifaddr#ia_list, 1751.10Sozakiin6_ifaddr#ia_next and in6_ifaddr#_ia6_multiaddrs. Note that netstat already 1761.10Sozakiimplements alternative methods to fetch the above information via sysctl(3). 1771.10Sozaki 1781.10Sozakivmstat(1) shows statistics of hash tables created by hashinit(9) in the kernel. 1791.10SozakiThe statistic information is retrieved via kvm(3). The global variables 1801.10Sozakiin_ifaddrhash and in_ifaddrhashtbl, which are for a hash table of IPv4 1811.10Sozakiaddresses and obsoleted by in_ifaddrhash_pslist and in_ifaddrhashtbl_pslist, 1821.10Sozakiare kept for this purpose. We should provide a means to fetch statistics of 1831.10Sozakihash tables via sysctl(3). 1841.10Sozaki 1851.10Sozakifstat(1) shows information of bpf instances. Each bpf instance (struct bpf) is 1861.10Sozakiobtained via kvm(3). bpf_d#_bd_next, bpf_d#_bd_filter and bpf_d#_bd_list 1871.10Sozakimember variables are obsolete but remain. ifnet#if_xname is also accessed 1881.10Sozakivia struct bpf_if and obsolete ifnet#if_list is required to remain to not change 1891.11Sozakithe offset of ifnet#if_xname. The statistic counters (bpf#bd_rcount, 1901.11Sozakibpf#bd_dcount and bpf#bd_ccount) are also victims of this restriction; for 1911.11Sozakiscalability the statistic counters should be per-CPU and we should stop using 1921.11Sozakiatomic operations for them however we have to remain the counters and atomic 1931.11Sozakioperations. 1941.13Sozaki 1951.13SozakiScalability 1961.13Sozaki----------- 1971.13Sozaki 1981.13Sozaki - Per-CPU rtcaches (used in say IP forwarding) aren't scalable on multiple 1991.13Sozaki flows per CPU 2001.13Sozaki - ipsec(4) isn't scalable on the number of SA/SP; the cost of a look-up 2011.13Sozaki is O(n) 2021.14Sknakahar - opencrypto(9)'s crypto_newsession()/crypto_freesession() aren't scalable 2031.14Sknakahar as they are serialized by one mutex 2041.16Sozaki 2051.18SozakiALTQ 2061.18Sozaki---- 2071.18Sozaki 2081.18SozakiIf ALTQ is enabled in the kernel, it enforces to use just one Tx queue (if_snd) 2091.18Sozakifor packet transmissions, resulting in serializing all Tx packet processing on 2101.18Sozakithe queue. We should probably design and implement an alternative queuing 2111.18Sozakimechanism that deals with multi-core systems at the first place, not making the 2121.18Sozakiexisting ALTQ MP-safe because it's just annoying. 2131.27Spgoyette 2141.27SpgoyetteUsing kernel modules 2151.27Spgoyette-------------------- 2161.27Spgoyette 2171.27SpgoyettePlease note that if you enable NET_MPSAFE in your kernel, and you use and 2181.27Spgoyetteloadable kernel modules (including compat_xx modules or individual network 2191.27Spgoyetteinterface if_xxx device driver modules), you will need to build custom 2201.27Spgoyettemodules. For each module you will need to add the following line to its 2211.27SpgoyetteMakefile: 2221.27Spgoyette 2231.27Spgoyette CPPFLAGS+= NET_MPSAFE 2241.27Spgoyette 2251.27SpgoyetteFailure to do this may result in unpredictable behavior. 2261.28Sozaki 2271.28SozakiIPv4 address initialization atomicity 2281.28Sozaki------------------------------------- 2291.28Sozaki 2301.28SozakiAn IPv4 address is referenced by several data structures: an associated 2311.28Sozakiinterface, its local route, a connected route (if necessary), the global list, 2321.28Sozakithe global hash table, etc. These data structures are not updated atomically, 2331.28Sozakii.e., there can be inconsistent states on an IPv4 address in the kernel during 2341.28Sozakithe initialization of an IPv4 address. 2351.28Sozaki 2361.28SozakiOne known failure of the issue is that incoming packets destinating to an 2371.28Sozakiinitializing address can loop in the network stack in a short period of time. 2381.28SozakiThe address initialization creates an local route first and then registers an 2391.28Sozakiinitializing address to the global hash table that is used to decide if an 2401.28Sozakiincoming packet destinates to the host by checking the destination of the packet 2411.28Sozakiis registered to the hash table. So, if the host allows forwaring, an incoming 2421.28Sozakipacket can match on a local route of an initializing address at ip_output while 2431.28Sozakiit fails the to-self check described above at ip_input. Because a matched local 2441.28Sozakiroute points a loopback interface as its destination interface, an incoming 2451.28Sozakipacket sends to the network stack (ip_input) again, which results in looping. 2461.28SozakiThe loop stops once an initializing address is registered to the hash table. 2471.28Sozaki 2481.28SozakiOne solution of the issue is to reorder the address initialization instructions, 2491.28Sozakifirst register an address to the hash table then create its routes. Another 2501.28Sozakisolution is to use the routing table for the to-self check instead of using the 2511.28Sozakiglobal hash table, like IPv6. 2521.29Sozaki 2531.29Sozakiif_flags 2541.29Sozaki-------- 2551.29Sozaki 2561.29SozakiTo avoid data race on if_flags it should be protected by a lock (currently it's 2571.29SozakiIFNET_LOCK). Thus, if_flags should not be accessed on packet processing to 2581.29Sozakiavoid performance degradation by lock contentions. Traditionally IFF_RUNNING, 2591.29SozakiIFF_UP and IFF_OACTIVE flags of if_flags are checked on packet processing. If 2601.29Sozakiyou make a driver MP-safe you must remove such checks. 2611.29Sozaki 2621.29SozakiIFF_ALLMULTI can be set/unset via if_mcast_op. To protect updates of the flag, 2631.29Sozakiwe had added IFNET_LOCK around if_mcast_op. However that was not a good 2641.29Sozakiapproach because if_mcast_op is typically called in the middle of a call path 2651.29Sozakiand holding IFNET_LOCK such places is problematic. Actually a deadlock is 2661.29Sozakiobserved. Probably we should remove IFNET_LOCK and manage IFF_ALLMULTI 2671.29Sozakisomewhere other than if_flags, for example ethercom or driver itself (or a 2681.29Sozakicommon driver framework once it appears). Such a change is feasible because 2691.29SozakiIFF_ALLMULTI is only set/unset by a driver and not accessed from any common 2701.29Sozakicomponents such as network protocols. 2711.29Sozaki 2721.29SozakiAlso IFF_PROMISC is checked in ether_input and we should get rid of it somehow. 273