Skip to content

Commit 9e58c5d

Browse files
committed
Merge branch 'MTU-core-range-checking-more'
Jarod Wilson says: ==================== net: use core MTU range checking everywhere This stack of patches should get absolutely everything in the kernel converted from doing their own MTU range checking to the core MTU range checking. This second spin includes alterations to hopefully fix all concerns raised with the first, as well as including some additional changes to drivers and infrastructure where I completely missed necessary updates. These have all been built through the 0-day build infrastructure via the (rebasing) master branch at https://github.com/jarodwilson/linux-muck, which at the time of the most recent compile across 147 configs, was based on net-next at commit 7b1536e. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 1a61a8f + b96f9af commit 9e58c5d

File tree

117 files changed

+316
-665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+316
-665
lines changed

arch/um/drivers/net_kern.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ static void uml_net_tx_timeout(struct net_device *dev)
256256
netif_wake_queue(dev);
257257
}
258258

259-
static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
260-
{
261-
dev->mtu = new_mtu;
262-
263-
return 0;
264-
}
265-
266259
#ifdef CONFIG_NET_POLL_CONTROLLER
267260
static void uml_net_poll_controller(struct net_device *dev)
268261
{
@@ -374,7 +367,6 @@ static const struct net_device_ops uml_netdev_ops = {
374367
.ndo_set_rx_mode = uml_net_set_multicast_list,
375368
.ndo_tx_timeout = uml_net_tx_timeout,
376369
.ndo_set_mac_address = eth_mac_addr,
377-
.ndo_change_mtu = uml_net_change_mtu,
378370
.ndo_validate_addr = eth_validate_addr,
379371
#ifdef CONFIG_NET_POLL_CONTROLLER
380372
.ndo_poll_controller = uml_net_poll_controller,

drivers/char/pcmcia/synclink_cs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4248,7 +4248,6 @@ static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size)
42484248
static const struct net_device_ops hdlcdev_ops = {
42494249
.ndo_open = hdlcdev_open,
42504250
.ndo_stop = hdlcdev_close,
4251-
.ndo_change_mtu = hdlc_change_mtu,
42524251
.ndo_start_xmit = hdlc_start_xmit,
42534252
.ndo_do_ioctl = hdlcdev_ioctl,
42544253
.ndo_tx_timeout = hdlcdev_tx_timeout,

drivers/firewire/net.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,15 +1349,6 @@ static netdev_tx_t fwnet_tx(struct sk_buff *skb, struct net_device *net)
13491349
return NETDEV_TX_OK;
13501350
}
13511351

1352-
static int fwnet_change_mtu(struct net_device *net, int new_mtu)
1353-
{
1354-
if (new_mtu < 68)
1355-
return -EINVAL;
1356-
1357-
net->mtu = new_mtu;
1358-
return 0;
1359-
}
1360-
13611352
static const struct ethtool_ops fwnet_ethtool_ops = {
13621353
.get_link = ethtool_op_get_link,
13631354
};
@@ -1366,7 +1357,6 @@ static const struct net_device_ops fwnet_netdev_ops = {
13661357
.ndo_open = fwnet_open,
13671358
.ndo_stop = fwnet_stop,
13681359
.ndo_start_xmit = fwnet_tx,
1369-
.ndo_change_mtu = fwnet_change_mtu,
13701360
};
13711361

13721362
static void fwnet_init_dev(struct net_device *net)
@@ -1435,7 +1425,6 @@ static int fwnet_probe(struct fw_unit *unit,
14351425
struct net_device *net;
14361426
bool allocated_netdev = false;
14371427
struct fwnet_device *dev;
1438-
unsigned max_mtu;
14391428
int ret;
14401429
union fwnet_hwaddr *ha;
14411430

@@ -1478,9 +1467,10 @@ static int fwnet_probe(struct fw_unit *unit,
14781467
* Use the RFC 2734 default 1500 octets or the maximum payload
14791468
* as initial MTU
14801469
*/
1481-
max_mtu = (1 << (card->max_receive + 1))
1482-
- sizeof(struct rfc2734_header) - IEEE1394_GASP_HDR_SIZE;
1483-
net->mtu = min(1500U, max_mtu);
1470+
net->max_mtu = (1 << (card->max_receive + 1))
1471+
- sizeof(struct rfc2734_header) - IEEE1394_GASP_HDR_SIZE;
1472+
net->mtu = min(1500U, net->max_mtu);
1473+
net->min_mtu = ETH_MIN_MTU;
14841474

14851475
/* Set our hardware address while we're at it */
14861476
ha = (union fwnet_hwaddr *)net->dev_addr;

drivers/hsi/clients/ssi_protocol.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,15 +960,6 @@ static int ssip_pn_stop(struct net_device *dev)
960960
return 0;
961961
}
962962

963-
static int ssip_pn_set_mtu(struct net_device *dev, int new_mtu)
964-
{
965-
if (new_mtu > SSIP_MAX_MTU || new_mtu < PHONET_MIN_MTU)
966-
return -EINVAL;
967-
dev->mtu = new_mtu;
968-
969-
return 0;
970-
}
971-
972963
static void ssip_xmit_work(struct work_struct *work)
973964
{
974965
struct ssi_protocol *ssi =
@@ -1060,7 +1051,6 @@ static const struct net_device_ops ssip_pn_ops = {
10601051
.ndo_open = ssip_pn_open,
10611052
.ndo_stop = ssip_pn_stop,
10621053
.ndo_start_xmit = ssip_pn_xmit,
1063-
.ndo_change_mtu = ssip_pn_set_mtu,
10641054
};
10651055

10661056
static void ssip_pn_setup(struct net_device *dev)
@@ -1136,6 +1126,10 @@ static int ssi_protocol_probe(struct device *dev)
11361126
goto out1;
11371127
}
11381128

1129+
/* MTU range: 6 - 65535 */
1130+
ssi->netdev->min_mtu = PHONET_MIN_MTU;
1131+
ssi->netdev->max_mtu = SSIP_MAX_MTU;
1132+
11391133
SET_NETDEV_DEV(ssi->netdev, dev);
11401134
netif_carrier_off(ssi->netdev);
11411135
err = register_netdev(ssi->netdev);

drivers/infiniband/hw/nes/nes.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
6565
MODULE_LICENSE("Dual BSD/GPL");
6666
MODULE_VERSION(DRV_VERSION);
6767

68-
int max_mtu = 9000;
6968
int interrupt_mod_interval = 0;
7069

7170
/* Interoperability */

drivers/infiniband/hw/nes/nes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
#define NES_FIRST_QPN 64
8484
#define NES_SW_CONTEXT_ALIGN 1024
8585

86+
#define NES_MAX_MTU 9000
87+
8688
#define NES_NIC_MAX_NICS 16
8789
#define NES_MAX_ARP_TABLE_SIZE 4096
8890

@@ -169,8 +171,6 @@ do { \
169171
#include "nes_cm.h"
170172
#include "nes_mgt.h"
171173

172-
extern int max_mtu;
173-
#define max_frame_len (max_mtu+ETH_HLEN)
174174
extern int interrupt_mod_interval;
175175
extern int nes_if_count;
176176
extern int mpa_version;

drivers/infiniband/hw/nes/nes_nic.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -981,20 +981,16 @@ static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
981981
{
982982
struct nes_vnic *nesvnic = netdev_priv(netdev);
983983
struct nes_device *nesdev = nesvnic->nesdev;
984-
int ret = 0;
985984
u8 jumbomode = 0;
986985
u32 nic_active;
987986
u32 nic_active_bit;
988987
u32 uc_all_active;
989988
u32 mc_all_active;
990989

991-
if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
992-
return -EINVAL;
993-
994990
netdev->mtu = new_mtu;
995991
nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN;
996992

997-
if (netdev->mtu > 1500) {
993+
if (netdev->mtu > ETH_DATA_LEN) {
998994
jumbomode=1;
999995
}
1000996
nes_nic_init_timer_defaults(nesdev, jumbomode);
@@ -1020,7 +1016,7 @@ static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
10201016
nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
10211017
}
10221018

1023-
return ret;
1019+
return 0;
10241020
}
10251021

10261022

@@ -1658,7 +1654,7 @@ struct net_device *nes_netdev_init(struct nes_device *nesdev,
16581654

16591655
netdev->watchdog_timeo = NES_TX_TIMEOUT;
16601656
netdev->irq = nesdev->pcidev->irq;
1661-
netdev->mtu = ETH_DATA_LEN;
1657+
netdev->max_mtu = NES_MAX_MTU;
16621658
netdev->hard_header_len = ETH_HLEN;
16631659
netdev->addr_len = ETH_ALEN;
16641660
netdev->type = ARPHRD_ETHER;

drivers/infiniband/ulp/ipoib/ipoib_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,7 @@ static struct net_device *ipoib_add_port(const char *format,
20172017
/* MTU will be reset when mcast join happens */
20182018
priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu);
20192019
priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu;
2020+
priv->dev->max_mtu = IPOIB_CM_MTU;
20202021

20212022
priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh);
20222023

drivers/message/fusion/mptlan.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -548,16 +548,6 @@ mpt_lan_close(struct net_device *dev)
548548
return 0;
549549
}
550550

551-
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
552-
static int
553-
mpt_lan_change_mtu(struct net_device *dev, int new_mtu)
554-
{
555-
if ((new_mtu < MPT_LAN_MIN_MTU) || (new_mtu > MPT_LAN_MAX_MTU))
556-
return -EINVAL;
557-
dev->mtu = new_mtu;
558-
return 0;
559-
}
560-
561551
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
562552
/* Tx timeout handler. */
563553
static void
@@ -1304,7 +1294,6 @@ static const struct net_device_ops mpt_netdev_ops = {
13041294
.ndo_open = mpt_lan_open,
13051295
.ndo_stop = mpt_lan_close,
13061296
.ndo_start_xmit = mpt_lan_sdu_send,
1307-
.ndo_change_mtu = mpt_lan_change_mtu,
13081297
.ndo_tx_timeout = mpt_lan_tx_timeout,
13091298
};
13101299

@@ -1375,6 +1364,10 @@ mpt_register_lan_device (MPT_ADAPTER *mpt_dev, int pnum)
13751364
dev->netdev_ops = &mpt_netdev_ops;
13761365
dev->watchdog_timeo = MPT_LAN_TX_TIMEOUT;
13771366

1367+
/* MTU range: 96 - 65280 */
1368+
dev->min_mtu = MPT_LAN_MIN_MTU;
1369+
dev->max_mtu = MPT_LAN_MAX_MTU;
1370+
13781371
dlprintk((KERN_INFO MYNAM ": Finished registering dev "
13791372
"and setting initial values\n"));
13801373

drivers/misc/sgi-xp/xpnet.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static DEFINE_SPINLOCK(xpnet_broadcast_lock);
118118
* now, the default is 64KB.
119119
*/
120120
#define XPNET_MAX_MTU (0x800000UL - L1_CACHE_BYTES)
121+
/* 68 comes from min TCP+IP+MAC header */
122+
#define XPNET_MIN_MTU 68
121123
/* 32KB has been determined to be the ideal */
122124
#define XPNET_DEF_MTU (0x8000UL)
123125

@@ -330,22 +332,6 @@ xpnet_dev_stop(struct net_device *dev)
330332
return 0;
331333
}
332334

333-
static int
334-
xpnet_dev_change_mtu(struct net_device *dev, int new_mtu)
335-
{
336-
/* 68 comes from min TCP+IP+MAC header */
337-
if ((new_mtu < 68) || (new_mtu > XPNET_MAX_MTU)) {
338-
dev_err(xpnet, "ifconfig %s mtu %d failed; value must be "
339-
"between 68 and %ld\n", dev->name, new_mtu,
340-
XPNET_MAX_MTU);
341-
return -EINVAL;
342-
}
343-
344-
dev->mtu = new_mtu;
345-
dev_dbg(xpnet, "ifconfig %s mtu set to %d\n", dev->name, new_mtu);
346-
return 0;
347-
}
348-
349335
/*
350336
* Notification that the other end has received the message and
351337
* DMA'd the skb information. At this point, they are done with
@@ -519,7 +505,6 @@ static const struct net_device_ops xpnet_netdev_ops = {
519505
.ndo_open = xpnet_dev_open,
520506
.ndo_stop = xpnet_dev_stop,
521507
.ndo_start_xmit = xpnet_dev_hard_start_xmit,
522-
.ndo_change_mtu = xpnet_dev_change_mtu,
523508
.ndo_tx_timeout = xpnet_dev_tx_timeout,
524509
.ndo_set_mac_address = eth_mac_addr,
525510
.ndo_validate_addr = eth_validate_addr,
@@ -555,6 +540,8 @@ xpnet_init(void)
555540

556541
xpnet_device->netdev_ops = &xpnet_netdev_ops;
557542
xpnet_device->mtu = XPNET_DEF_MTU;
543+
xpnet_device->min_mtu = XPNET_MIN_MTU;
544+
xpnet_device->max_mtu = XPNET_MAX_MTU;
558545

559546
/*
560547
* Multicast assumes the LSB of the first octet is set for multicast

drivers/net/ethernet/alteon/acenic.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ static int acenic_probe_one(struct pci_dev *pdev,
474474
dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
475475

476476
dev->watchdog_timeo = 5*HZ;
477+
dev->min_mtu = 0;
478+
dev->max_mtu = ACE_JUMBO_MTU;
477479

478480
dev->netdev_ops = &ace_netdev_ops;
479481
dev->ethtool_ops = &ace_ethtool_ops;
@@ -2548,9 +2550,6 @@ static int ace_change_mtu(struct net_device *dev, int new_mtu)
25482550
struct ace_private *ap = netdev_priv(dev);
25492551
struct ace_regs __iomem *regs = ap->regs;
25502552

2551-
if (new_mtu > ACE_JUMBO_MTU)
2552-
return -EINVAL;
2553-
25542553
writel(new_mtu + ETH_HLEN + 4, &regs->IfMtu);
25552554
dev->mtu = new_mtu;
25562555

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ static int ena_change_mtu(struct net_device *dev, int new_mtu)
103103
struct ena_adapter *adapter = netdev_priv(dev);
104104
int ret;
105105

106-
if ((new_mtu > adapter->max_mtu) || (new_mtu < ENA_MIN_MTU)) {
107-
netif_err(adapter, drv, dev,
108-
"Invalid MTU setting. new_mtu: %d\n", new_mtu);
109-
110-
return -EINVAL;
111-
}
112-
113106
ret = ena_com_set_dev_mtu(adapter->ena_dev, new_mtu);
114107
if (!ret) {
115108
netif_dbg(adapter, drv, dev, "set MTU to %d\n", new_mtu);
@@ -2755,6 +2748,8 @@ static void ena_set_conf_feat_params(struct ena_adapter *adapter,
27552748
ena_set_dev_offloads(feat, netdev);
27562749

27572750
adapter->max_mtu = feat->dev_attr.max_mtu;
2751+
netdev->max_mtu = adapter->max_mtu;
2752+
netdev->min_mtu = ENA_MIN_MTU;
27582753
}
27592754

27602755
static int ena_rss_init_default(struct ena_adapter *adapter)

drivers/net/ethernet/amd/xgbe/xgbe-drv.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
257257
{
258258
unsigned int rx_buf_size;
259259

260-
if (mtu > XGMAC_JUMBO_PACKET_MTU) {
261-
netdev_alert(netdev, "MTU exceeds maximum supported value\n");
262-
return -EINVAL;
263-
}
264-
265260
rx_buf_size = mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
266261
rx_buf_size = clamp_val(rx_buf_size, XGBE_RX_MIN_BUF_SIZE, PAGE_SIZE);
267262

drivers/net/ethernet/amd/xgbe/xgbe-main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static int xgbe_probe(struct platform_device *pdev)
738738
pdata->netdev_features = netdev->features;
739739

740740
netdev->priv_flags |= IFF_UNICAST_FLT;
741+
netdev->min_mtu = 0;
742+
netdev->max_mtu = XGMAC_JUMBO_PACKET_MTU;
741743

742744
/* Use default watchdog timeout */
743745
netdev->watchdog_timeo = 0;

drivers/net/ethernet/broadcom/sb1250-mac.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,23 +2147,13 @@ static void sbmac_setmulti(struct sbmac_softc *sc)
21472147
}
21482148
}
21492149

2150-
static int sb1250_change_mtu(struct net_device *_dev, int new_mtu)
2151-
{
2152-
if (new_mtu > ENET_PACKET_SIZE)
2153-
return -EINVAL;
2154-
_dev->mtu = new_mtu;
2155-
pr_info("changing the mtu to %d\n", new_mtu);
2156-
return 0;
2157-
}
2158-
21592150
static const struct net_device_ops sbmac_netdev_ops = {
21602151
.ndo_open = sbmac_open,
21612152
.ndo_stop = sbmac_close,
21622153
.ndo_start_xmit = sbmac_start_tx,
21632154
.ndo_set_rx_mode = sbmac_set_rx_mode,
21642155
.ndo_tx_timeout = sbmac_tx_timeout,
21652156
.ndo_do_ioctl = sbmac_mii_ioctl,
2166-
.ndo_change_mtu = sb1250_change_mtu,
21672157
.ndo_validate_addr = eth_validate_addr,
21682158
.ndo_set_mac_address = eth_mac_addr,
21692159
#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -2229,6 +2219,8 @@ static int sbmac_init(struct platform_device *pldev, long long base)
22292219

22302220
dev->netdev_ops = &sbmac_netdev_ops;
22312221
dev->watchdog_timeo = TX_TIMEOUT;
2222+
dev->max_mtu = 0;
2223+
dev->max_mtu = ENET_PACKET_SIZE;
22322224

22332225
netif_napi_add(dev, &sc->napi, sbmac_poll, 16);
22342226

drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,8 +2531,6 @@ static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
25312531
struct adapter *adapter = pi->adapter;
25322532
int ret;
25332533

2534-
if (new_mtu < 81) /* accommodate SACK */
2535-
return -EINVAL;
25362534
if ((ret = t3_mac_set_mtu(&pi->mac, new_mtu)))
25372535
return ret;
25382536
dev->mtu = new_mtu;
@@ -3295,6 +3293,8 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
32953293

32963294
netdev->netdev_ops = &cxgb_netdev_ops;
32973295
netdev->ethtool_ops = &cxgb_ethtool_ops;
3296+
netdev->min_mtu = 81;
3297+
netdev->max_mtu = ETH_MAX_MTU;
32983298
}
32993299

33003300
pci_set_drvdata(pdev, adapter);

0 commit comments

Comments
 (0)