TODO.smpnet revision 1.40
11.40Snia$NetBSD: TODO.smpnet,v 1.40 2021/01/20 10:26:43 nia 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.7Sozaki - vioif(4) 121.7Sozaki - vmx(4) 131.7Sozaki - wm(4) 141.8Sozaki - ixg(4) 151.30Smsaitoh - ixl(4) 161.9Smsaitoh - ixv(4) 171.7Sozaki - Layer 2 181.7Sozaki - Ethernet (if_ethersubr.c) 191.7Sozaki - bridge(4) 201.7Sozaki - STP 211.7Sozaki - Fast forward (ipflow) 221.7Sozaki - Layer 3 231.7Sozaki - All except for items in the below section 241.7Sozaki - Interfaces 251.7Sozaki - gif(4) 261.22Sozaki - ipsecif(4) 271.7Sozaki - l2tp(4) 281.7Sozaki - pppoe(4) 291.7Sozaki - if_spppsubr.c 301.40Snia - tap(4) 311.7Sozaki - tun(4) 321.12Sozaki - vlan(4) 331.7Sozaki - Packet filters 341.7Sozaki - npf(7) 351.7Sozaki - Others 361.7Sozaki - bpf(4) 371.12Sozaki - ipsec(4) 381.12Sozaki - opencrypto(9) 391.7Sozaki - pfil(9) 401.2Sozaki 411.2SozakiNon MP-safe components and kernel options 421.2Sozaki========================================= 431.2Sozaki 441.21SozakiThe components and options aren't MP-safe, i.e., requires the big kernel lock, 451.21Sozakiyet. Some of them can be used safely even if NET_MPSAFE is enabled because 461.21Sozakithey're still protected by the big kernel lock. The others aren't protected and 471.21Sozakiso unsafe, e.g, they may crash the kernel. 481.21Sozaki 491.21SozakiProtected ones 501.21Sozaki-------------- 511.21Sozaki 521.7Sozaki - Device drivers 531.7Sozaki - Most drivers other than ones listed in the above section 541.21Sozaki - Layer 4 551.21Sozaki - DCCP 561.21Sozaki - SCTP 571.21Sozaki - TCP 581.21Sozaki - UDP 591.21Sozaki 601.21SozakiUnprotected ones 611.21Sozaki---------------- 621.21Sozaki 631.6Sozaki - Layer 2 641.6Sozaki - ARCNET (if_arcsubr.c) 651.6Sozaki - IEEE 1394 (if_ieee1394subr.c) 661.6Sozaki - IEEE 802.11 (ieee80211(4)) 671.6Sozaki - Layer 3 681.6Sozaki - IPSELSRC 691.6Sozaki - MROUTING 701.6Sozaki - PIM 711.6Sozaki - MPLS (mpls(4)) 721.17Sozaki - IPv6 address selection policy 731.6Sozaki - Interfaces 741.6Sozaki - agr(4) 751.6Sozaki - carp(4) 761.6Sozaki - faith(4) 771.6Sozaki - gre(4) 781.6Sozaki - ppp(4) 791.6Sozaki - sl(4) 801.6Sozaki - stf(4) 811.6Sozaki - if_srt 821.6Sozaki - Packet filters 831.6Sozaki - ipf(4) 841.6Sozaki - pf(4) 851.6Sozaki - Others 861.6Sozaki - AppleTalk (sys/netatalk/) 871.6Sozaki - Bluetooth (sys/netbt/) 881.6Sozaki - altq(4) 891.6Sozaki - kttcp(4) 901.6Sozaki - NFS 911.2Sozaki 921.2SozakiKnow issues 931.2Sozaki=========== 941.1Sozaki 951.15SozakiNOMPSAFE 961.15Sozaki-------- 971.15Sozaki 981.15SozakiWe use "NOMPSAFE" as a mark that indicates that the code around it isn't MP-safe 991.15Sozakiyet. We use it in comments and also use as part of function names, for example 1001.15Sozakim_get_rcvif_NOMPSAFE. Let's use "NOMPSAFE" to make it easy to find non-MP-safe 1011.15Sozakicodes by grep. 1021.15Sozaki 1031.1Sozakibpf 1041.2Sozaki--- 1051.1Sozaki 1061.1SozakiMP-ification of bpf requires all of bpf_mtap* are called in normal LWP context 1071.1Sozakior softint context, i.e., not in hardware interrupt context. For Tx, all 1081.1Sozakibpf_mtap satisfy the requrement. For Rx, most of bpf_mtap are called in softint. 1091.1SozakiUnfortunately some bpf_mtap on Rx are still called in hardware interrupt context. 1101.1Sozaki 1111.1SozakiThis is the list of the functions that have such bpf_mtap: 1121.1Sozaki 1131.1Sozaki - sca_frame_process() @ sys/dev/ic/hd64570.c 1141.1Sozaki 1151.1SozakiIdeally we should make the functions run in softint somehow, but we don't have 1161.1Sozakiactual devices, no time (or interest/love) to work on the task, so instead we 1171.1Sozakiprovide a deferred bpf_mtap mechanism that forcibly runs bpf_mtap in softint 1181.1Sozakicontext. It's a workaround and once the functions run in softint, we should use 1191.1Sozakithe original bpf_mtap again. 1201.10Sozaki 1211.35Sjdolecekif_mcast_op() - SIOCADDMULTI/SIOCDELMULTI 1221.35Sjdolecek----------------------------------------- 1231.35SjdolecekHelper function is called to add or remove multicast addresses for 1241.35Sjdolecekinterface. When called via ioctl it takes IFNET_LOCK(), when called 1251.35Sjdolecekvia sosetopt() it doesn't. 1261.35Sjdolecek 1271.35SjdolecekVarious network drivers can't assert IFNET_LOCKED() in their if_ioctl 1281.35Sjdolecekbecause of this. Generally drivers still take care to splnet() even 1291.35Sjdolecekwith NET_MPSAFE before calling ether_ioctl(), but they do not take 1301.35SjdolecekKERNEL_LOCK(), so this is actually unsafe. 1311.35Sjdolecek 1321.10SozakiLingering obsolete variables 1331.10Sozaki----------------------------- 1341.10Sozaki 1351.10SozakiSome obsolete global variables and member variables of structures remain to 1361.10Sozakiavoid breaking old userland programs which directly access such variables via 1371.10Sozakikvm(3). 1381.10Sozaki 1391.10SozakiThe following programs still use kvm(3) to get some information related to 1401.10Sozakithe network stack. 1411.10Sozaki 1421.10Sozaki - netstat(1) 1431.10Sozaki - vmstat(1) 1441.10Sozaki - fstat(1) 1451.10Sozaki 1461.10Sozakinetstat(1) accesses ifnet_list, the head of a list of interface objects 1471.10Sozaki(struct ifnet), and traverses each object through ifnet#if_list member variable. 1481.10Sozakiifnet_list and ifnet#if_list is obsoleted by ifnet_pslist and 1491.10Sozakiifnet#if_pslist_entry respectively. netstat also accesses the IP address list 1501.10Sozakiof an interface throught ifnet#if_addrlist. struct ifaddr, struct in_ifaddr 1511.10Sozakiand struct in6_ifaddr are accessed and the following obsolete member variables 1521.10Sozakiare stuck: ifaddr#ifa_list, in_ifaddr#ia_hash, in_ifaddr#ia_list, 1531.10Sozakiin6_ifaddr#ia_next and in6_ifaddr#_ia6_multiaddrs. Note that netstat already 1541.10Sozakiimplements alternative methods to fetch the above information via sysctl(3). 1551.10Sozaki 1561.10Sozakivmstat(1) shows statistics of hash tables created by hashinit(9) in the kernel. 1571.10SozakiThe statistic information is retrieved via kvm(3). The global variables 1581.10Sozakiin_ifaddrhash and in_ifaddrhashtbl, which are for a hash table of IPv4 1591.10Sozakiaddresses and obsoleted by in_ifaddrhash_pslist and in_ifaddrhashtbl_pslist, 1601.10Sozakiare kept for this purpose. We should provide a means to fetch statistics of 1611.10Sozakihash tables via sysctl(3). 1621.10Sozaki 1631.10Sozakifstat(1) shows information of bpf instances. Each bpf instance (struct bpf) is 1641.10Sozakiobtained via kvm(3). bpf_d#_bd_next, bpf_d#_bd_filter and bpf_d#_bd_list 1651.10Sozakimember variables are obsolete but remain. ifnet#if_xname is also accessed 1661.10Sozakivia struct bpf_if and obsolete ifnet#if_list is required to remain to not change 1671.11Sozakithe offset of ifnet#if_xname. The statistic counters (bpf#bd_rcount, 1681.11Sozakibpf#bd_dcount and bpf#bd_ccount) are also victims of this restriction; for 1691.11Sozakiscalability the statistic counters should be per-CPU and we should stop using 1701.11Sozakiatomic operations for them however we have to remain the counters and atomic 1711.11Sozakioperations. 1721.13Sozaki 1731.13SozakiScalability 1741.13Sozaki----------- 1751.13Sozaki 1761.13Sozaki - Per-CPU rtcaches (used in say IP forwarding) aren't scalable on multiple 1771.13Sozaki flows per CPU 1781.13Sozaki - ipsec(4) isn't scalable on the number of SA/SP; the cost of a look-up 1791.13Sozaki is O(n) 1801.14Sknakahar - opencrypto(9)'s crypto_newsession()/crypto_freesession() aren't scalable 1811.14Sknakahar as they are serialized by one mutex 1821.16Sozaki 1831.18SozakiALTQ 1841.18Sozaki---- 1851.18Sozaki 1861.18SozakiIf ALTQ is enabled in the kernel, it enforces to use just one Tx queue (if_snd) 1871.18Sozakifor packet transmissions, resulting in serializing all Tx packet processing on 1881.18Sozakithe queue. We should probably design and implement an alternative queuing 1891.18Sozakimechanism that deals with multi-core systems at the first place, not making the 1901.18Sozakiexisting ALTQ MP-safe because it's just annoying. 1911.27Spgoyette 1921.27SpgoyetteUsing kernel modules 1931.27Spgoyette-------------------- 1941.27Spgoyette 1951.27SpgoyettePlease note that if you enable NET_MPSAFE in your kernel, and you use and 1961.27Spgoyetteloadable kernel modules (including compat_xx modules or individual network 1971.27Spgoyetteinterface if_xxx device driver modules), you will need to build custom 1981.27Spgoyettemodules. For each module you will need to add the following line to its 1991.27SpgoyetteMakefile: 2001.27Spgoyette 2011.27Spgoyette CPPFLAGS+= NET_MPSAFE 2021.27Spgoyette 2031.27SpgoyetteFailure to do this may result in unpredictable behavior. 2041.28Sozaki 2051.28SozakiIPv4 address initialization atomicity 2061.28Sozaki------------------------------------- 2071.28Sozaki 2081.28SozakiAn IPv4 address is referenced by several data structures: an associated 2091.28Sozakiinterface, its local route, a connected route (if necessary), the global list, 2101.28Sozakithe global hash table, etc. These data structures are not updated atomically, 2111.28Sozakii.e., there can be inconsistent states on an IPv4 address in the kernel during 2121.28Sozakithe initialization of an IPv4 address. 2131.28Sozaki 2141.28SozakiOne known failure of the issue is that incoming packets destinating to an 2151.28Sozakiinitializing address can loop in the network stack in a short period of time. 2161.28SozakiThe address initialization creates an local route first and then registers an 2171.28Sozakiinitializing address to the global hash table that is used to decide if an 2181.28Sozakiincoming packet destinates to the host by checking the destination of the packet 2191.28Sozakiis registered to the hash table. So, if the host allows forwaring, an incoming 2201.28Sozakipacket can match on a local route of an initializing address at ip_output while 2211.28Sozakiit fails the to-self check described above at ip_input. Because a matched local 2221.28Sozakiroute points a loopback interface as its destination interface, an incoming 2231.28Sozakipacket sends to the network stack (ip_input) again, which results in looping. 2241.28SozakiThe loop stops once an initializing address is registered to the hash table. 2251.28Sozaki 2261.28SozakiOne solution of the issue is to reorder the address initialization instructions, 2271.28Sozakifirst register an address to the hash table then create its routes. Another 2281.28Sozakisolution is to use the routing table for the to-self check instead of using the 2291.28Sozakiglobal hash table, like IPv6. 2301.29Sozaki 2311.29Sozakiif_flags 2321.29Sozaki-------- 2331.29Sozaki 2341.29SozakiTo avoid data race on if_flags it should be protected by a lock (currently it's 2351.29SozakiIFNET_LOCK). Thus, if_flags should not be accessed on packet processing to 2361.29Sozakiavoid performance degradation by lock contentions. Traditionally IFF_RUNNING, 2371.29SozakiIFF_UP and IFF_OACTIVE flags of if_flags are checked on packet processing. If 2381.29Sozakiyou make a driver MP-safe you must remove such checks. 2391.29Sozaki 2401.29SozakiIFF_ALLMULTI can be set/unset via if_mcast_op. To protect updates of the flag, 2411.29Sozakiwe had added IFNET_LOCK around if_mcast_op. However that was not a good 2421.29Sozakiapproach because if_mcast_op is typically called in the middle of a call path 2431.29Sozakiand holding IFNET_LOCK such places is problematic. Actually a deadlock is 2441.29Sozakiobserved. Probably we should remove IFNET_LOCK and manage IFF_ALLMULTI 2451.29Sozakisomewhere other than if_flags, for example ethercom or driver itself (or a 2461.29Sozakicommon driver framework once it appears). Such a change is feasible because 2471.29SozakiIFF_ALLMULTI is only set/unset by a driver and not accessed from any common 2481.29Sozakicomponents such as network protocols. 2491.29Sozaki 2501.29SozakiAlso IFF_PROMISC is checked in ether_input and we should get rid of it somehow. 251