Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bonding: Remove support for use_carrier

Remove the implementation of use_carrier, the link monitoring
method that utilizes ethtool or ioctl to determine the link state of an
interface in a bond. Bonding will always behaves as if use_carrier=1,
which relies on netif_carrier_ok() to determine the link state of
interfaces.

To avoid acquiring RTNL many times per second, bonding inspects
link state under RCU, but not under RTNL. However, ethtool
implementations in drivers may sleep, and therefore this strategy is
unsuitable for use with calls into driver ethtool functions.

The use_carrier option was introduced in 2003, to provide
backwards compatibility for network device drivers that did not support
the then-new netif_carrier_ok/on/off system. Device drivers are now
expected to support netif_carrier_*, and the use_carrier backwards
compatibility logic is no longer necessary.

The option itself remains, but when queried always returns 1,
and may only be set to 1.

Link: https://lore.kernel.org/000000000000eb54bf061cfd666a@google.com
Link: https://lore.kernel.org/20240718122017.d2e33aaac43a.I10ab9c9ded97163aef4e4de10985cd8f7de60d28@changeid
Signed-off-by: Jay Vosburgh <jv@jvosburgh.net>
Reported-by: syzbot+b8c48ea38ca27d150063@syzkaller.appspotmail.com
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/2029487.1756512517@famine
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jay Vosburgh and committed by
Jakub Kicinski
23a6037c cd8a4cfa

+26 -190
+10 -65
Documentation/networking/bonding.rst
··· 582 582 This determines how often the link state of each slave is 583 583 inspected for link failures. A value of zero disables MII 584 584 link monitoring. A value of 100 is a good starting point. 585 - The use_carrier option, below, affects how the link state is 586 - determined. See the High Availability section for additional 587 - information. The default value is 100 if arp_interval is not 588 - set. 585 + 586 + The default value is 100 if arp_interval is not set. 589 587 590 588 min_links 591 589 ··· 894 896 895 897 use_carrier 896 898 897 - Specifies whether or not miimon should use MII or ETHTOOL 898 - ioctls vs. netif_carrier_ok() to determine the link 899 - status. The MII or ETHTOOL ioctls are less efficient and 900 - utilize a deprecated calling sequence within the kernel. The 901 - netif_carrier_ok() relies on the device driver to maintain its 902 - state with netif_carrier_on/off; at this writing, most, but 903 - not all, device drivers support this facility. 899 + Obsolete option that previously selected between MII / 900 + ETHTOOL ioctls and netif_carrier_ok() to determine link 901 + state. 904 902 905 - If bonding insists that the link is up when it should not be, 906 - it may be that your network device driver does not support 907 - netif_carrier_on/off. The default state for netif_carrier is 908 - "carrier on," so if a driver does not support netif_carrier, 909 - it will appear as if the link is always up. In this case, 910 - setting use_carrier to 0 will cause bonding to revert to the 911 - MII / ETHTOOL ioctl method to determine the link state. 903 + All link state checks are now done with netif_carrier_ok(). 912 904 913 - A value of 1 enables the use of netif_carrier_ok(), a value of 914 - 0 will use the deprecated MII / ETHTOOL ioctls. The default 915 - value is 1. 905 + For backwards compatibility, this option's value may be inspected 906 + or set. The only valid setting is 1. 916 907 917 908 xmit_hash_policy 918 909 ··· 2023 2036 querying the device's MII registers, or by making an ethtool query to 2024 2037 the device. 2025 2038 2026 - If the use_carrier module parameter is 1 (the default value), 2027 - then the MII monitor will rely on the driver for carrier state 2028 - information (via the netif_carrier subsystem). As explained in the 2029 - use_carrier parameter information, above, if the MII monitor fails to 2030 - detect carrier loss on the device (e.g., when the cable is physically 2031 - disconnected), it may be that the driver does not support 2032 - netif_carrier. 2033 - 2034 - If use_carrier is 0, then the MII monitor will first query the 2035 - device's (via ioctl) MII registers and check the link state. If that 2036 - request fails (not just that it returns carrier down), then the MII 2037 - monitor will make an ethtool ETHTOOL_GLINK request to attempt to obtain 2038 - the same information. If both methods fail (i.e., the driver either 2039 - does not support or had some error in processing both the MII register 2040 - and ethtool requests), then the MII monitor will assume the link is 2041 - up. 2039 + The MII monitor relies on the driver for carrier state information (via 2040 + the netif_carrier subsystem). 2042 2041 2043 2042 8. Potential Sources of Trouble 2044 2043 =============================== ··· 2107 2134 This will load tg3 and e1000 modules before loading the bonding one. 2108 2135 Full documentation on this can be found in the modprobe.d and modprobe 2109 2136 manual pages. 2110 - 2111 - 8.3. Painfully Slow Or No Failed Link Detection By Miimon 2112 - --------------------------------------------------------- 2113 - 2114 - By default, bonding enables the use_carrier option, which 2115 - instructs bonding to trust the driver to maintain carrier state. 2116 - 2117 - As discussed in the options section, above, some drivers do 2118 - not support the netif_carrier_on/_off link state tracking system. 2119 - With use_carrier enabled, bonding will always see these links as up, 2120 - regardless of their actual state. 2121 - 2122 - Additionally, other drivers do support netif_carrier, but do 2123 - not maintain it in real time, e.g., only polling the link state at 2124 - some fixed interval. In this case, miimon will detect failures, but 2125 - only after some long period of time has expired. If it appears that 2126 - miimon is very slow in detecting link failures, try specifying 2127 - use_carrier=0 to see if that improves the failure detection time. If 2128 - it does, then it may be that the driver checks the carrier state at a 2129 - fixed interval, but does not cache the MII register values (so the 2130 - use_carrier=0 method of querying the registers directly works). If 2131 - use_carrier=0 does not improve the failover, then the driver may cache 2132 - the registers, or the problem may be elsewhere. 2133 - 2134 - Also, remember that miimon only checks for the device's 2135 - carrier state. It has no way to determine the state of devices on or 2136 - beyond other ports of a switch, or if a switch is refusing to pass 2137 - traffic while still maintaining carrier on. 2138 2137 2139 2138 9. SNMP agents 2140 2139 ===============
+7 -106
drivers/net/bonding/bond_main.c
··· 142 142 MODULE_PARM_DESC(downdelay, "Delay before considering link down, " 143 143 "in milliseconds"); 144 144 module_param(use_carrier, int, 0); 145 - MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; " 146 - "0 for off, 1 for on (default)"); 145 + MODULE_PARM_DESC(use_carrier, "option obsolete, use_carrier cannot be disabled"); 147 146 module_param(mode, charp, 0); 148 147 MODULE_PARM_DESC(mode, "Mode of operation; 0 for balance-rr, " 149 148 "1 for active-backup, 2 for balance-xor, " ··· 827 828 default: 828 829 return "unknown"; 829 830 } 830 - } 831 - 832 - /* if <dev> supports MII link status reporting, check its link status. 833 - * 834 - * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(), 835 - * depending upon the setting of the use_carrier parameter. 836 - * 837 - * Return either BMSR_LSTATUS, meaning that the link is up (or we 838 - * can't tell and just pretend it is), or 0, meaning that the link is 839 - * down. 840 - * 841 - * If reporting is non-zero, instead of faking link up, return -1 if 842 - * both ETHTOOL and MII ioctls fail (meaning the device does not 843 - * support them). If use_carrier is set, return whatever it says. 844 - * It'd be nice if there was a good way to tell if a driver supports 845 - * netif_carrier, but there really isn't. 846 - */ 847 - static int bond_check_dev_link(struct bonding *bond, 848 - struct net_device *slave_dev, int reporting) 849 - { 850 - const struct net_device_ops *slave_ops = slave_dev->netdev_ops; 851 - struct mii_ioctl_data *mii; 852 - struct ifreq ifr; 853 - int ret; 854 - 855 - if (!reporting && !netif_running(slave_dev)) 856 - return 0; 857 - 858 - if (bond->params.use_carrier) 859 - return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0; 860 - 861 - /* Try to get link status using Ethtool first. */ 862 - if (slave_dev->ethtool_ops->get_link) { 863 - netdev_lock_ops(slave_dev); 864 - ret = slave_dev->ethtool_ops->get_link(slave_dev); 865 - netdev_unlock_ops(slave_dev); 866 - 867 - return ret ? BMSR_LSTATUS : 0; 868 - } 869 - 870 - /* Ethtool can't be used, fallback to MII ioctls. */ 871 - if (slave_ops->ndo_eth_ioctl) { 872 - /* TODO: set pointer to correct ioctl on a per team member 873 - * bases to make this more efficient. that is, once 874 - * we determine the correct ioctl, we will always 875 - * call it and not the others for that team 876 - * member. 877 - */ 878 - 879 - /* We cannot assume that SIOCGMIIPHY will also read a 880 - * register; not all network drivers (e.g., e100) 881 - * support that. 882 - */ 883 - 884 - /* Yes, the mii is overlaid on the ifreq.ifr_ifru */ 885 - strscpy_pad(ifr.ifr_name, slave_dev->name, IFNAMSIZ); 886 - mii = if_mii(&ifr); 887 - 888 - if (dev_eth_ioctl(slave_dev, &ifr, SIOCGMIIPHY) == 0) { 889 - mii->reg_num = MII_BMSR; 890 - if (dev_eth_ioctl(slave_dev, &ifr, SIOCGMIIREG) == 0) 891 - return mii->val_out & BMSR_LSTATUS; 892 - } 893 - } 894 - 895 - /* If reporting, report that either there's no ndo_eth_ioctl, 896 - * or both SIOCGMIIREG and get_link failed (meaning that we 897 - * cannot report link status). If not reporting, pretend 898 - * we're ok. 899 - */ 900 - return reporting ? -1 : BMSR_LSTATUS; 901 831 } 902 832 903 833 /*----------------------------- Multicast list ------------------------------*/ ··· 1894 1966 const struct net_device_ops *slave_ops = slave_dev->netdev_ops; 1895 1967 struct slave *new_slave = NULL, *prev_slave; 1896 1968 struct sockaddr_storage ss; 1897 - int link_reporting; 1898 1969 int res = 0, i; 1899 1970 1900 1971 if (slave_dev->flags & IFF_MASTER && ··· 1901 1974 BOND_NL_ERR(bond_dev, extack, 1902 1975 "Device type (master device) cannot be enslaved"); 1903 1976 return -EPERM; 1904 - } 1905 - 1906 - if (!bond->params.use_carrier && 1907 - slave_dev->ethtool_ops->get_link == NULL && 1908 - slave_ops->ndo_eth_ioctl == NULL) { 1909 - slave_warn(bond_dev, slave_dev, "no link monitoring support\n"); 1910 1977 } 1911 1978 1912 1979 /* already in-use? */ ··· 2116 2195 2117 2196 new_slave->last_tx = new_slave->last_rx; 2118 2197 2119 - if (bond->params.miimon && !bond->params.use_carrier) { 2120 - link_reporting = bond_check_dev_link(bond, slave_dev, 1); 2121 - 2122 - if ((link_reporting == -1) && !bond->params.arp_interval) { 2123 - /* miimon is set but a bonded network driver 2124 - * does not support ETHTOOL/MII and 2125 - * arp_interval is not set. Note: if 2126 - * use_carrier is enabled, we will never go 2127 - * here (because netif_carrier is always 2128 - * supported); thus, we don't need to change 2129 - * the messages for netif_carrier. 2130 - */ 2131 - slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n"); 2132 - } else if (link_reporting == -1) { 2133 - /* unable get link status using mii/ethtool */ 2134 - slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n"); 2135 - } 2136 - } 2137 - 2138 2198 /* check for initial state */ 2139 2199 new_slave->link = BOND_LINK_NOCHANGE; 2140 2200 if (bond->params.miimon) { 2141 - if (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS) { 2201 + if (netif_carrier_ok(slave_dev)) { 2142 2202 if (bond->params.updelay) { 2143 2203 bond_set_slave_link_state(new_slave, 2144 2204 BOND_LINK_BACK, ··· 2661 2759 bond_for_each_slave_rcu(bond, slave, iter) { 2662 2760 bond_propose_link_state(slave, BOND_LINK_NOCHANGE); 2663 2761 2664 - link_state = bond_check_dev_link(bond, slave->dev, 0); 2762 + link_state = netif_carrier_ok(slave->dev); 2665 2763 2666 2764 switch (slave->link) { 2667 2765 case BOND_LINK_UP: ··· 6159 6257 downdelay = 0; 6160 6258 } 6161 6259 6162 - if ((use_carrier != 0) && (use_carrier != 1)) { 6163 - pr_warn("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n", 6164 - use_carrier); 6165 - use_carrier = 1; 6260 + if (use_carrier != 1) { 6261 + pr_err("Error: invalid use_carrier parameter (%d)\n", 6262 + use_carrier); 6263 + return -EINVAL; 6166 6264 } 6167 6265 6168 6266 if (num_peer_notif < 0 || num_peer_notif > 255) { ··· 6409 6507 params->updelay = updelay; 6410 6508 params->downdelay = downdelay; 6411 6509 params->peer_notif_delay = 0; 6412 - params->use_carrier = use_carrier; 6413 6510 params->lacp_active = 1; 6414 6511 params->lacp_fast = lacp_fast; 6415 6512 params->primary[0] = 0;
+6 -8
drivers/net/bonding/bond_netlink.c
··· 259 259 return err; 260 260 } 261 261 if (data[IFLA_BOND_USE_CARRIER]) { 262 - int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]); 263 - 264 - bond_opt_initval(&newval, use_carrier); 265 - err = __bond_opt_set(bond, BOND_OPT_USE_CARRIER, &newval, 266 - data[IFLA_BOND_USE_CARRIER], extack); 267 - if (err) 268 - return err; 262 + if (nla_get_u8(data[IFLA_BOND_USE_CARRIER]) != 1) { 263 + NL_SET_ERR_MSG_ATTR(extack, data[IFLA_BOND_USE_CARRIER], 264 + "option obsolete, use_carrier cannot be disabled"); 265 + return -EINVAL; 266 + } 269 267 } 270 268 if (data[IFLA_BOND_ARP_INTERVAL]) { 271 269 int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]); ··· 686 688 bond->params.peer_notif_delay * bond->params.miimon)) 687 689 goto nla_put_failure; 688 690 689 - if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier)) 691 + if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, 1)) 690 692 goto nla_put_failure; 691 693 692 694 if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
+1 -6
drivers/net/bonding/bond_options.c
··· 187 187 }; 188 188 189 189 static const struct bond_opt_value bond_use_carrier_tbl[] = { 190 - { "off", 0, 0}, 191 190 { "on", 1, BOND_VALFLAG_DEFAULT}, 192 191 { NULL, -1, 0} 193 192 }; ··· 418 419 [BOND_OPT_USE_CARRIER] = { 419 420 .id = BOND_OPT_USE_CARRIER, 420 421 .name = "use_carrier", 421 - .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon", 422 + .desc = "option obsolete, use_carrier cannot be disabled", 422 423 .values = bond_use_carrier_tbl, 423 424 .set = bond_option_use_carrier_set 424 425 }, ··· 1090 1091 static int bond_option_use_carrier_set(struct bonding *bond, 1091 1092 const struct bond_opt_value *newval) 1092 1093 { 1093 - netdev_dbg(bond->dev, "Setting use_carrier to %llu\n", 1094 - newval->value); 1095 - bond->params.use_carrier = newval->value; 1096 - 1097 1094 return 0; 1098 1095 } 1099 1096
+2 -4
drivers/net/bonding/bond_sysfs.c
··· 467 467 static DEVICE_ATTR(primary_reselect, 0644, 468 468 bonding_show_primary_reselect, bonding_sysfs_store_option); 469 469 470 - /* Show the use_carrier flag. */ 470 + /* use_carrier is obsolete, but print value for compatibility */ 471 471 static ssize_t bonding_show_carrier(struct device *d, 472 472 struct device_attribute *attr, 473 473 char *buf) 474 474 { 475 - struct bonding *bond = to_bond(d); 476 - 477 - return sysfs_emit(buf, "%d\n", bond->params.use_carrier); 475 + return sysfs_emit(buf, "1\n"); 478 476 } 479 477 static DEVICE_ATTR(use_carrier, 0644, 480 478 bonding_show_carrier, bonding_sysfs_store_option);
-1
include/net/bonding.h
··· 126 126 int arp_interval; 127 127 int arp_validate; 128 128 int arp_all_targets; 129 - int use_carrier; 130 129 int fail_over_mac; 131 130 int updelay; 132 131 int downdelay;