Skip to content

Commit d0c2c99

Browse files
jarodwilsondavem330
authored andcommitted
net: use core MTU range checking in virt drivers
hyperv_net: - set min/max_mtu, per Haiyang, after rndis_filter_device_add virtio_net: - set min/max_mtu - remove virtnet_change_mtu vmxnet3: - set min/max_mtu xen-netback: - min_mtu = 0, max_mtu = 65517 xen-netfront: - min_mtu = 0, max_mtu = 65535 unisys/visor: - clean up defines a little to not clash with network core or add redundat definitions CC: [email protected] CC: [email protected] CC: "K. Y. Srinivasan" <[email protected]> CC: Haiyang Zhang <[email protected]> CC: "Michael S. Tsirkin" <[email protected]> CC: Shrikrishna Khare <[email protected]> CC: "VMware, Inc." <[email protected]> CC: Wei Liu <[email protected]> CC: Paul Durrant <[email protected]> CC: David Kershner <[email protected]> Signed-off-by: Jarod Wilson <[email protected]> Reviewed-by: Haiyang Zhang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9157208 commit d0c2c99

File tree

8 files changed

+35
-34
lines changed

8 files changed

+35
-34
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ struct nvsp_message {
606606
} __packed;
607607

608608

609-
#define NETVSC_MTU 65536
610-
#define NETVSC_MTU_MIN 68
609+
#define NETVSC_MTU 65535
610+
#define NETVSC_MTU_MIN ETH_MIN_MTU
611611

612612
#define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
613613
#define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */

drivers/net/hyperv/netvsc_drv.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,19 +872,12 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
872872
struct netvsc_device *nvdev = ndevctx->nvdev;
873873
struct hv_device *hdev = ndevctx->device_ctx;
874874
struct netvsc_device_info device_info;
875-
int limit = ETH_DATA_LEN;
876875
u32 num_chn;
877876
int ret = 0;
878877

879878
if (ndevctx->start_remove || !nvdev || nvdev->destroy)
880879
return -ENODEV;
881880

882-
if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
883-
limit = NETVSC_MTU - ETH_HLEN;
884-
885-
if (mtu < NETVSC_MTU_MIN || mtu > limit)
886-
return -EINVAL;
887-
888881
ret = netvsc_close(ndev);
889882
if (ret)
890883
goto out;
@@ -1402,6 +1395,13 @@ static int netvsc_probe(struct hv_device *dev,
14021395
netif_set_real_num_tx_queues(net, nvdev->num_chn);
14031396
netif_set_real_num_rx_queues(net, nvdev->num_chn);
14041397

1398+
/* MTU range: 68 - 1500 or 65521 */
1399+
net->min_mtu = NETVSC_MTU_MIN;
1400+
if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
1401+
net->max_mtu = NETVSC_MTU - ETH_HLEN;
1402+
else
1403+
net->max_mtu = ETH_DATA_LEN;
1404+
14051405
ret = register_netdev(net);
14061406
if (ret != 0) {
14071407
pr_err("Unable to register netdev.\n");

drivers/net/virtio_net.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,25 +1419,13 @@ static const struct ethtool_ops virtnet_ethtool_ops = {
14191419
.set_settings = virtnet_set_settings,
14201420
};
14211421

1422-
#define MIN_MTU 68
1423-
#define MAX_MTU 65535
1424-
1425-
static int virtnet_change_mtu(struct net_device *dev, int new_mtu)
1426-
{
1427-
if (new_mtu < MIN_MTU || new_mtu > MAX_MTU)
1428-
return -EINVAL;
1429-
dev->mtu = new_mtu;
1430-
return 0;
1431-
}
1432-
14331422
static const struct net_device_ops virtnet_netdev = {
14341423
.ndo_open = virtnet_open,
14351424
.ndo_stop = virtnet_close,
14361425
.ndo_start_xmit = start_xmit,
14371426
.ndo_validate_addr = eth_validate_addr,
14381427
.ndo_set_mac_address = virtnet_set_mac_address,
14391428
.ndo_set_rx_mode = virtnet_set_rx_mode,
1440-
.ndo_change_mtu = virtnet_change_mtu,
14411429
.ndo_get_stats64 = virtnet_stats,
14421430
.ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
14431431
.ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
@@ -1748,6 +1736,9 @@ static bool virtnet_validate_features(struct virtio_device *vdev)
17481736
return true;
17491737
}
17501738

1739+
#define MIN_MTU ETH_MIN_MTU
1740+
#define MAX_MTU ETH_MAX_MTU
1741+
17511742
static int virtnet_probe(struct virtio_device *vdev)
17521743
{
17531744
int i, err;
@@ -1821,6 +1812,10 @@ static int virtnet_probe(struct virtio_device *vdev)
18211812

18221813
dev->vlan_features = dev->features;
18231814

1815+
/* MTU range: 68 - 65535 */
1816+
dev->min_mtu = MIN_MTU;
1817+
dev->max_mtu = MAX_MTU;
1818+
18241819
/* Configuration may specify what MAC to use. Otherwise random. */
18251820
if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
18261821
virtio_cread_bytes(vdev,
@@ -1875,8 +1870,10 @@ static int virtnet_probe(struct virtio_device *vdev)
18751870
mtu = virtio_cread16(vdev,
18761871
offsetof(struct virtio_net_config,
18771872
mtu));
1878-
if (virtnet_change_mtu(dev, mtu))
1873+
if (mtu < dev->min_mtu || mtu > dev->max_mtu)
18791874
__virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
1875+
else
1876+
dev->mtu = mtu;
18801877
}
18811878

18821879
if (vi->any_header_sg)

drivers/net/vmxnet3/vmxnet3_drv.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,9 +2969,6 @@ vmxnet3_change_mtu(struct net_device *netdev, int new_mtu)
29692969
struct vmxnet3_adapter *adapter = netdev_priv(netdev);
29702970
int err = 0;
29712971

2972-
if (new_mtu < VMXNET3_MIN_MTU || new_mtu > VMXNET3_MAX_MTU)
2973-
return -EINVAL;
2974-
29752972
netdev->mtu = new_mtu;
29762973

29772974
/*
@@ -3428,6 +3425,10 @@ vmxnet3_probe_device(struct pci_dev *pdev,
34283425
vmxnet3_set_ethtool_ops(netdev);
34293426
netdev->watchdog_timeo = 5 * HZ;
34303427

3428+
/* MTU range: 60 - 9000 */
3429+
netdev->min_mtu = VMXNET3_MIN_MTU;
3430+
netdev->max_mtu = VMXNET3_MAX_MTU;
3431+
34313432
INIT_WORK(&adapter->work, vmxnet3_reset_work);
34323433
set_bit(VMXNET3_STATE_BIT_QUIESCED, &adapter->state);
34333434

drivers/net/xen-netback/interface.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static int xenvif_close(struct net_device *dev)
302302
static int xenvif_change_mtu(struct net_device *dev, int mtu)
303303
{
304304
struct xenvif *vif = netdev_priv(dev);
305-
int max = vif->can_sg ? 65535 - VLAN_ETH_HLEN : ETH_DATA_LEN;
305+
int max = vif->can_sg ? ETH_MAX_MTU - VLAN_ETH_HLEN : ETH_DATA_LEN;
306306

307307
if (mtu > max)
308308
return -EINVAL;
@@ -471,6 +471,9 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
471471

472472
dev->tx_queue_len = XENVIF_QUEUE_LENGTH;
473473

474+
dev->min_mtu = 0;
475+
dev->max_mtu = ETH_MAX_MTU - VLAN_ETH_HLEN;
476+
474477
/*
475478
* Initialise a dummy MAC address. We choose the numerically
476479
* largest non-broadcast address to prevent the address getting

drivers/net/xen-netfront.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)
13291329
netdev->features |= netdev->hw_features;
13301330

13311331
netdev->ethtool_ops = &xennet_ethtool_ops;
1332+
netdev->min_mtu = 0;
1333+
netdev->max_mtu = XEN_NETIF_MAX_TX_SIZE;
13321334
SET_NETDEV_DEV(netdev, &dev->dev);
13331335

13341336
np->netdev = netdev;

drivers/staging/unisys/include/iochannel.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ enum net_types {
113113

114114
};
115115

116-
#define ETH_HEADER_SIZE 14 /* size of ethernet header */
117-
118116
#define ETH_MIN_DATA_SIZE 46 /* minimum eth data size */
119-
#define ETH_MIN_PACKET_SIZE (ETH_HEADER_SIZE + ETH_MIN_DATA_SIZE)
117+
#define ETH_MIN_PACKET_SIZE (ETH_HLEN + ETH_MIN_DATA_SIZE)
120118

121-
#define ETH_MAX_MTU 16384 /* maximum data size */
119+
#define VISOR_ETH_MAX_MTU 16384 /* maximum data size */
122120

123121
#ifndef MAX_MACADDR_LEN
124122
#define MAX_MACADDR_LEN 6 /* number of bytes in MAC address */
@@ -288,7 +286,7 @@ struct net_pkt_xmt {
288286
int len; /* full length of data in the packet */
289287
int num_frags; /* number of fragments in frags containing data */
290288
struct phys_info frags[MAX_PHYS_INFO]; /* physical page information */
291-
char ethhdr[ETH_HEADER_SIZE]; /* the ethernet header */
289+
char ethhdr[ETH_HLEN]; /* the ethernet header */
292290
struct {
293291
/* these are needed for csum at uisnic end */
294292
u8 valid; /* 1 = struct is valid - else ignore */
@@ -323,7 +321,7 @@ struct net_pkt_xmtdone {
323321
*/
324322
#define RCVPOST_BUF_SIZE 4032
325323
#define MAX_NET_RCV_CHAIN \
326-
((ETH_MAX_MTU + ETH_HEADER_SIZE + RCVPOST_BUF_SIZE - 1) \
324+
((VISOR_ETH_MAX_MTU + ETH_HLEN + RCVPOST_BUF_SIZE - 1) \
327325
/ RCVPOST_BUF_SIZE)
328326

329327
struct net_pkt_rcvpost {

drivers/staging/unisys/visornic/visornic_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
791791
* pointing to
792792
*/
793793
firstfraglen = skb->len - skb->data_len;
794-
if (firstfraglen < ETH_HEADER_SIZE) {
794+
if (firstfraglen < ETH_HLEN) {
795795
spin_unlock_irqrestore(&devdata->priv_lock, flags);
796796
devdata->busy_cnt++;
797797
dev_err(&netdev->dev,
@@ -864,7 +864,7 @@ visornic_xmit(struct sk_buff *skb, struct net_device *netdev)
864864
/* copy ethernet header from first frag into ocmdrsp
865865
* - everything else will be pass in frags & DMA'ed
866866
*/
867-
memcpy(cmdrsp->net.xmt.ethhdr, skb->data, ETH_HEADER_SIZE);
867+
memcpy(cmdrsp->net.xmt.ethhdr, skb->data, ETH_HLEN);
868868
/* copy frags info - from skb->data we need to only provide access
869869
* beyond eth header
870870
*/

0 commit comments

Comments
 (0)