Date: Thu, 14 Apr 2016 14:10:40 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297967 - head/sys/ofed/drivers/net/mlx4 Message-ID: <201604141410.u3EEAeCL005165@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Thu Apr 14 14:10:40 2016 New Revision: 297967 URL: https://svnweb.freebsd.org/changeset/base/297967 Log: 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 MFC after: 1 week Modified: head/sys/ofed/drivers/net/mlx4/en_rx.c head/sys/ofed/drivers/net/mlx4/mlx4_en.h Modified: head/sys/ofed/drivers/net/mlx4/en_rx.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/en_rx.c Thu Apr 14 14:01:28 2016 (r297966) +++ head/sys/ofed/drivers/net/mlx4/en_rx.c Thu Apr 14 14:10:40 2016 (r297967) @@ -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", dev->if_mtu); Modified: head/sys/ofed/drivers/net/mlx4/mlx4_en.h ============================================================================== --- head/sys/ofed/drivers/net/mlx4/mlx4_en.h Thu Apr 14 14:01:28 2016 (r297966) +++ head/sys/ofed/drivers/net/mlx4/mlx4_en.h Thu Apr 14 14:10:40 2016 (r297967) @@ -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?201604141410.u3EEAeCL005165>