Date: Fri, 29 Apr 2016 11:14:03 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r298775 - stable/10/sys/ofed/drivers/net/mlx4 Message-ID: <201604291114.u3TBE32J040076@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Fri Apr 29 11:14:02 2016 New Revision: 298775 URL: https://svnweb.freebsd.org/changeset/base/298775 Log: MFC r297967: Ensure the received IP header gets 32-bits aligned. The FreeBSD's TCP/IP stack assumes that the IP-header is 32-bits aligned when decoding it. Else unaligned 32-bit memory access can happen, which not all processor architectures support. Sponsored by: Mellanox Technologies Modified: stable/10/sys/ofed/drivers/net/mlx4/en_rx.c stable/10/sys/ofed/drivers/net/mlx4/mlx4_en.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/ofed/drivers/net/mlx4/en_rx.c ============================================================================== --- stable/10/sys/ofed/drivers/net/mlx4/en_rx.c Fri Apr 29 11:10:43 2016 (r298774) +++ stable/10/sys/ofed/drivers/net/mlx4/en_rx.c Fri Apr 29 11:14:02 2016 (r298775) @@ -55,7 +55,7 @@ static void mlx4_en_init_rx_desc(struct int i; /* Set size and memtype fields */ - rx_desc->data[0].byte_count = cpu_to_be32(priv->rx_mb_size); + rx_desc->data[0].byte_count = cpu_to_be32(priv->rx_mb_size - MLX4_NET_IP_ALIGN); rx_desc->data[0].lkey = cpu_to_be32(priv->mdev->mr.key); /* @@ -87,7 +87,10 @@ mlx4_en_alloc_buf(struct mlx4_en_rx_ring if (unlikely(mb == NULL)) return (-ENOMEM); /* setup correct length */ - mb->m_len = ring->rx_mb_size; + mb->m_pkthdr.len = mb->m_len = ring->rx_mb_size; + + /* make sure IP header gets aligned */ + m_adj(mb, MLX4_NET_IP_ALIGN); /* load spare mbuf into BUSDMA */ err = -bus_dmamap_load_mbuf_sg(ring->dma_tag, ring->spare.dma_map, @@ -117,7 +120,10 @@ mlx4_en_alloc_buf(struct mlx4_en_rx_ring goto use_spare; /* setup correct length */ - mb->m_len = ring->rx_mb_size; + mb->m_pkthdr.len = mb->m_len = ring->rx_mb_size; + + /* make sure IP header gets aligned */ + m_adj(mb, MLX4_NET_IP_ALIGN); err = -bus_dmamap_load_mbuf_sg(ring->dma_tag, mb_list->dma_map, mb, segs, &nsegs, BUS_DMA_NOWAIT); @@ -249,7 +255,8 @@ static void mlx4_en_free_rx_buf(struct m void mlx4_en_calc_rx_buf(struct net_device *dev) { struct mlx4_en_priv *priv = netdev_priv(dev); - int eff_mtu = dev->if_mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN; + int eff_mtu = dev->if_mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN + + MLX4_NET_IP_ALIGN; if (eff_mtu > MJUM16BYTES) { en_err(priv, "MTU(%d) is too big\n", (int)dev->if_mtu); Modified: stable/10/sys/ofed/drivers/net/mlx4/mlx4_en.h ============================================================================== --- stable/10/sys/ofed/drivers/net/mlx4/mlx4_en.h Fri Apr 29 11:10:43 2016 (r298774) +++ stable/10/sys/ofed/drivers/net/mlx4/mlx4_en.h Fri Apr 29 11:14:02 2016 (r298775) @@ -69,6 +69,7 @@ #define MLX4_EN_PAGE_SHIFT 12 #define MLX4_EN_PAGE_SIZE (1 << MLX4_EN_PAGE_SHIFT) +#define MLX4_NET_IP_ALIGN 2 /* bytes */ #define DEF_RX_RINGS 16 #define MAX_RX_RINGS 128 #define MIN_RX_RINGS 4
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604291114.u3TBE32J040076>