TODO.smpnet revision 1.28
11.28Sozaki$NetBSD: TODO.smpnet,v 1.28 2019/03/26 05:17:17 ozaki-r 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.7Sozaki - vioif(4) 111.7Sozaki - vmx(4) 121.7Sozaki - wm(4) 131.8Sozaki - ixg(4) 141.9Smsaitoh - ixv(4) 151.7Sozaki - Layer 2 161.7Sozaki - Ethernet (if_ethersubr.c) 171.7Sozaki - bridge(4) 181.7Sozaki - STP 191.7Sozaki - Fast forward (ipflow) 201.7Sozaki - Layer 3 211.7Sozaki - All except for items in the below section 221.7Sozaki - Interfaces 231.7Sozaki - gif(4) 241.22Sozaki - ipsecif(4) 251.7Sozaki - l2tp(4) 261.7Sozaki - pppoe(4) 271.7Sozaki - if_spppsubr.c 281.7Sozaki - tun(4) 291.12Sozaki - vlan(4) 301.7Sozaki - Packet filters 311.7Sozaki - npf(7) 321.7Sozaki - Others 331.7Sozaki - bpf(4) 341.12Sozaki - ipsec(4) 351.12Sozaki - opencrypto(9) 361.7Sozaki - pfil(9) 371.2Sozaki 381.2SozakiNon MP-safe components and kernel options 391.2Sozaki========================================= 401.2Sozaki 411.21SozakiThe components and options aren't MP-safe, i.e., requires the big kernel lock, 421.21Sozakiyet. Some of them can be used safely even if NET_MPSAFE is enabled because 431.21Sozakithey're still protected by the big kernel lock. The others aren't protected and 441.21Sozakiso unsafe, e.g, they may crash the kernel. 451.21Sozaki 461.21SozakiProtected ones 471.21Sozaki-------------- 481.21Sozaki 491.7Sozaki - Device drivers 501.7Sozaki - Most drivers other than ones listed in the above section 511.21Sozaki - Layer 4 521.21Sozaki - DCCP 531.21Sozaki - SCTP 541.21Sozaki - TCP 551.21Sozaki - UDP 561.21Sozaki 571.21SozakiUnprotected ones 581.21Sozaki---------------- 591.21Sozaki 601.6Sozaki - Layer 2 611.6Sozaki - ARCNET (if_arcsubr.c) 621.6Sozaki - BRIDGE_IPF 631.6Sozaki - FDDI (if_fddisubr.c) 641.6Sozaki - HIPPI (if_hippisubr.c) 651.6Sozaki - IEEE 1394 (if_ieee1394subr.c) 661.6Sozaki - IEEE 802.11 (ieee80211(4)) 671.6Sozaki - Token ring (if_tokensubr.c) 681.6Sozaki - Layer 3 691.6Sozaki - IPSELSRC 701.6Sozaki - MROUTING 711.6Sozaki - PIM 721.6Sozaki - MPLS (mpls(4)) 731.17Sozaki - IPv6 address selection policy 741.6Sozaki - Interfaces 751.6Sozaki - agr(4) 761.6Sozaki - carp(4) 771.6Sozaki - faith(4) 781.6Sozaki - gre(4) 791.6Sozaki - ppp(4) 801.6Sozaki - sl(4) 811.6Sozaki - stf(4) 821.6Sozaki - strip(4) 831.6Sozaki - if_srt 841.6Sozaki - tap(4) 851.6Sozaki - Packet filters 861.6Sozaki - ipf(4) 871.6Sozaki - pf(4) 881.6Sozaki - Others 891.6Sozaki - AppleTalk (sys/netatalk/) 901.6Sozaki - Bluetooth (sys/netbt/) 911.6Sozaki - altq(4) 921.6Sozaki - CIFS (sys/netsmb/) 931.6Sozaki - kttcp(4) 941.6Sozaki - NFS 951.2Sozaki 961.2SozakiKnow issues 971.2Sozaki=========== 981.1Sozaki 991.15SozakiNOMPSAFE 1001.15Sozaki-------- 1011.15Sozaki 1021.15SozakiWe use "NOMPSAFE" as a mark that indicates that the code around it isn't MP-safe 1031.15Sozakiyet. We use it in comments and also use as part of function names, for example 1041.15Sozakim_get_rcvif_NOMPSAFE. Let's use "NOMPSAFE" to make it easy to find non-MP-safe 1051.15Sozakicodes by grep. 1061.15Sozaki 1071.1Sozakibpf 1081.2Sozaki--- 1091.1Sozaki 1101.1SozakiMP-ification of bpf requires all of bpf_mtap* are called in normal LWP context 1111.1Sozakior softint context, i.e., not in hardware interrupt context. For Tx, all 1121.1Sozakibpf_mtap satisfy the requrement. For Rx, most of bpf_mtap are called in softint. 1131.1SozakiUnfortunately some bpf_mtap on Rx are still called in hardware interrupt context. 1141.1Sozaki 1151.1SozakiThis is the list of the functions that have such bpf_mtap: 1161.1Sozaki 1171.1Sozaki - sca_frame_process() @ sys/dev/ic/hd64570.c 1181.1Sozaki 1191.1SozakiIdeally we should make the functions run in softint somehow, but we don't have 1201.1Sozakiactual devices, no time (or interest/love) to work on the task, so instead we 1211.1Sozakiprovide a deferred bpf_mtap mechanism that forcibly runs bpf_mtap in softint 1221.1Sozakicontext. It's a workaround and once the functions run in softint, we should use 1231.1Sozakithe original bpf_mtap again. 1241.10Sozaki 1251.10SozakiLingering obsolete variables 1261.10Sozaki----------------------------- 1271.10Sozaki 1281.10SozakiSome obsolete global variables and member variables of structures remain to 1291.10Sozakiavoid breaking old userland programs which directly access such variables via 1301.10Sozakikvm(3). 1311.10Sozaki 1321.10SozakiThe following programs still use kvm(3) to get some information related to 1331.10Sozakithe network stack. 1341.10Sozaki 1351.10Sozaki - netstat(1) 1361.10Sozaki - vmstat(1) 1371.10Sozaki - fstat(1) 1381.10Sozaki 1391.10Sozakinetstat(1) accesses ifnet_list, the head of a list of interface objects 1401.10Sozaki(struct ifnet), and traverses each object through ifnet#if_list member variable. 1411.10Sozakiifnet_list and ifnet#if_list is obsoleted by ifnet_pslist and 1421.10Sozakiifnet#if_pslist_entry respectively. netstat also accesses the IP address list 1431.10Sozakiof an interface throught ifnet#if_addrlist. struct ifaddr, struct in_ifaddr 1441.10Sozakiand struct in6_ifaddr are accessed and the following obsolete member variables 1451.10Sozakiare stuck: ifaddr#ifa_list, in_ifaddr#ia_hash, in_ifaddr#ia_list, 1461.10Sozakiin6_ifaddr#ia_next and in6_ifaddr#_ia6_multiaddrs. Note that netstat already 1471.10Sozakiimplements alternative methods to fetch the above information via sysctl(3). 1481.10Sozaki 1491.10Sozakivmstat(1) shows statistics of hash tables created by hashinit(9) in the kernel. 1501.10SozakiThe statistic information is retrieved via kvm(3). The global variables 1511.10Sozakiin_ifaddrhash and in_ifaddrhashtbl, which are for a hash table of IPv4 1521.10Sozakiaddresses and obsoleted by in_ifaddrhash_pslist and in_ifaddrhashtbl_pslist, 1531.10Sozakiare kept for this purpose. We should provide a means to fetch statistics of 1541.10Sozakihash tables via sysctl(3). 1551.10Sozaki 1561.10Sozakifstat(1) shows information of bpf instances. Each bpf instance (struct bpf) is 1571.10Sozakiobtained via kvm(3). bpf_d#_bd_next, bpf_d#_bd_filter and bpf_d#_bd_list 1581.10Sozakimember variables are obsolete but remain. ifnet#if_xname is also accessed 1591.10Sozakivia struct bpf_if and obsolete ifnet#if_list is required to remain to not change 1601.11Sozakithe offset of ifnet#if_xname. The statistic counters (bpf#bd_rcount, 1611.11Sozakibpf#bd_dcount and bpf#bd_ccount) are also victims of this restriction; for 1621.11Sozakiscalability the statistic counters should be per-CPU and we should stop using 1631.11Sozakiatomic operations for them however we have to remain the counters and atomic 1641.11Sozakioperations. 1651.13Sozaki 1661.13SozakiScalability 1671.13Sozaki----------- 1681.13Sozaki 1691.13Sozaki - Per-CPU rtcaches (used in say IP forwarding) aren't scalable on multiple 1701.13Sozaki flows per CPU 1711.13Sozaki - ipsec(4) isn't scalable on the number of SA/SP; the cost of a look-up 1721.13Sozaki is O(n) 1731.14Sknakahar - opencrypto(9)'s crypto_newsession()/crypto_freesession() aren't scalable 1741.14Sknakahar as they are serialized by one mutex 1751.16Sozaki 1761.16Sozakiec_multi* of ethercom 1771.16Sozaki--------------------- 1781.16Sozaki 1791.16Sozakiec_multiaddrs and ec_multicnt of struct ethercom and items listed in 1801.16Sozakiec_multiaddrs must be protected by ec_lock. The core of ethernet subsystem is 1811.16Sozakialready MP-safe, however, device drivers that use the data should also be fixed. 1821.16SozakiA typical change should be to protect manipulations of the data via ETHER_* 1831.16Sozakimacros such as ETHER_FIRST_MULTI by ETHER_LOCK and ETHER_UNLOCK. 1841.18Sozaki 1851.18SozakiALTQ 1861.18Sozaki---- 1871.18Sozaki 1881.18SozakiIf ALTQ is enabled in the kernel, it enforces to use just one Tx queue (if_snd) 1891.18Sozakifor packet transmissions, resulting in serializing all Tx packet processing on 1901.18Sozakithe queue. We should probably design and implement an alternative queuing 1911.18Sozakimechanism that deals with multi-core systems at the first place, not making the 1921.18Sozakiexisting ALTQ MP-safe because it's just annoying. 1931.27Spgoyette 1941.27SpgoyetteUsing kernel modules 1951.27Spgoyette-------------------- 1961.27Spgoyette 1971.27SpgoyettePlease note that if you enable NET_MPSAFE in your kernel, and you use and 1981.27Spgoyetteloadable kernel modules (including compat_xx modules or individual network 1991.27Spgoyetteinterface if_xxx device driver modules), you will need to build custom 2001.27Spgoyettemodules. For each module you will need to add the following line to its 2011.27SpgoyetteMakefile: 2021.27Spgoyette 2031.27Spgoyette CPPFLAGS+= NET_MPSAFE 2041.27Spgoyette 2051.27SpgoyetteFailure to do this may result in unpredictable behavior. 2061.28Sozaki 2071.28SozakiIPv4 address initialization atomicity 2081.28Sozaki------------------------------------- 2091.28Sozaki 2101.28SozakiAn IPv4 address is referenced by several data structures: an associated 2111.28Sozakiinterface, its local route, a connected route (if necessary), the global list, 2121.28Sozakithe global hash table, etc. These data structures are not updated atomically, 2131.28Sozakii.e., there can be inconsistent states on an IPv4 address in the kernel during 2141.28Sozakithe initialization of an IPv4 address. 2151.28Sozaki 2161.28SozakiOne known failure of the issue is that incoming packets destinating to an 2171.28Sozakiinitializing address can loop in the network stack in a short period of time. 2181.28SozakiThe address initialization creates an local route first and then registers an 2191.28Sozakiinitializing address to the global hash table that is used to decide if an 2201.28Sozakiincoming packet destinates to the host by checking the destination of the packet 2211.28Sozakiis registered to the hash table. So, if the host allows forwaring, an incoming 2221.28Sozakipacket can match on a local route of an initializing address at ip_output while 2231.28Sozakiit fails the to-self check described above at ip_input. Because a matched local 2241.28Sozakiroute points a loopback interface as its destination interface, an incoming 2251.28Sozakipacket sends to the network stack (ip_input) again, which results in looping. 2261.28SozakiThe loop stops once an initializing address is registered to the hash table. 2271.28Sozaki 2281.28SozakiOne solution of the issue is to reorder the address initialization instructions, 2291.28Sozakifirst register an address to the hash table then create its routes. Another 2301.28Sozakisolution is to use the routing table for the to-self check instead of using the 2311.28Sozakiglobal hash table, like IPv6. 232