Mellanox, mlx5 fixes 2019-04-19
Subsystems (5)
Hi Dave,
This series introduces some fixes to mlx5 driver.
Please pull and let me know if there is any problem.
For -stable v4.7:
('net/mlx5e: ethtool, Remove unsupported SFP EEPROM high pages query')
For -stable v4.19:
('net/mlx5e: Fix the max MTU check in case of XDP')
For -stable v5.0:
('net/mlx5e: Fix use-after-free after xdp_return_frame')
Thanks,
Saeed.
---
The following changes since commit 36ad7022536e0c65f8baeeaa5efde11dec44808a:
of_net: Fix residues after of_get_nvmem_mac_address removal (2019-04-19 11:58:30 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-fixes-2019-04-19
for you to fetch changes up to ace329f4ab3ba434be2adf618073c752d083b524:
net/mlx5e: ethtool, Remove unsupported SFP EEPROM high pages query (2019-04-19 13:55:37 -0700)
----------------------------------------------------------------
mlx5-fixes-2019-04-19
----------------------------------------------------------------
Erez Alfasi (1):
net/mlx5e: ethtool, Remove unsupported SFP EEPROM high pages query
Maxim Mikityanskiy (2):
net/mlx5e: Fix use-after-free after xdp_return_frame net/mlx5e: Fix the max MTU check in case of XDP
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 24 ++++++++++++++++++++-- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h | 3 +-- .../net/ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 5 +++-- drivers/net/ethernet/mellanox/mlx5/core/port.c | 4 ---- 5 files changed, 27 insertions(+), 11 deletions(-)
PATCH 1/3 net/mlx5e: Fix use-after-free after xdp_return_frame
From: Maxim Mikityanskiy <[email protected]>
xdp_return_frame releases the frame. It leads to releasing the page, so it's not allowed to access xdpi.xdpf->len after that, because xdpi.xdpf is at xdp->data_hard_start after convert_to_xdp_frame. This patch moves the memory access to precede the return of the frame.
--- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +2 -2
@@ -304,9 +304,9 @@ bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq, struct mlx5e_rq *rq)mlx5e_xdpi_fifo_pop (xdpi_fifo);if (is_redirect) { -xdp_return_frame (xdpi.xdpf);dma_unmap_single (sq->pdev, xdpi.dma_addr, xdpi.xdpf->len,DMA_TO_DEVICE ); +xdp_return_frame (xdpi.xdpf); }else {/* Recycle RX page */ mlx5e_page_release (rq, &xdpi.di, true);
@@ -345,9 +345,9 @@ void mlx5e_free_xdpsq_descs(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq)mlx5e_xdpi_fifo_pop (xdpi_fifo);if (is_redirect) { -xdp_return_frame (xdpi.xdpf);dma_unmap_single (sq->pdev, xdpi.dma_addr, xdpi.xdpf->len,DMA_TO_DEVICE ); +xdp_return_frame (xdpi.xdpf); }else {/* Recycle RX page */ mlx5e_page_release (rq, &xdpi.di, false);
Signature · 1 line
2.20.1
PATCH 2/3 net/mlx5e: Fix the max MTU check in case of XDP
In reply to Saeed MahameedFrom: Maxim Mikityanskiy <[email protected]>
MLX5E_XDP_MAX_MTU was calculated incorrectly. It didn't account for NET_IP_ALIGN and MLX5E_HW2SW_MTU, and it also misused MLX5_SKB_FRAG_SZ. This commit fixes the calculations and adds a brief explanation for the formula used.
--- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 20 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 3 +-- .../net/ethernet/mellanox/mlx5/core/en_main.c | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +20 -0
@@ -33,6 +33,26 @@#include <linux/bpf_trace.h> #include "en/xdp.h" +int mlx5e_xdp_max_mtu (struct mlx5e_params *params) +{ +int hr =NET_IP_ALIGN +XDP_PACKET_HEADROOM ; + +/* Let S := SKB_DATA_ALIGN(sizeof(struct skb_shared_info)). +* The condition checked in mlx5e_rx_is_linear_skb is: +* SKB_DATA_ALIGN(sw_mtu + hard_mtu + hr) + S <= PAGE_SIZE (1) +* (Note that hw_mtu == sw_mtu + hard_mtu.) +* What is returned from this function is: +* max_mtu = PAGE_SIZE - S - hr - hard_mtu (2) +* After assigning sw_mtu := max_mtu, the left side of (1) turns to +* SKB_DATA_ALIGN(PAGE_SIZE - S) + S, which is equal to PAGE_SIZE, +* because both PAGE_SIZE and S are already aligned. Any number greater +* than max_mtu would make the left side of (1) greater than PAGE_SIZE, +* so max_mtu is the maximum MTU allowed. +*/ + +return MLX5E_HW2SW_MTU (params,SKB_MAX_HEAD (hr)); +} +static inline bool mlx5e_xmit_xdp_buff (struct mlx5e_xdpsq *sq,struct mlx5e_dma_info *di,struct xdp_buff *xdp)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +1 -2
@@ -34,13 +34,12 @@#include "en.h" -#define MLX5E_XDP_MAX_MTU ((int)(PAGE_SIZE - \ - MLX5_SKB_FRAG_SZ(XDP_PACKET_HEADROOM)))#define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)#define MLX5E_XDP_TX_EMPTY_DS_COUNT \ (sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) #define MLX5E_XDP_TX_DS_COUNT (MLX5E_XDP_TX_EMPTY_DS_COUNT + 1 /* SG DS */) +int mlx5e_xdp_max_mtu (struct mlx5e_params *params);bool mlx5e_xdp_handle (struct mlx5e_rq *rq,struct mlx5e_dma_info *di,void *va,u16 *rx_headroom,u32 *len);bool mlx5e_poll_xdpsq_cq (struct mlx5e_cq *cq,struct mlx5e_rq *rq);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -2
@@ -3777,7 +3777,7 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,if (params->xdp_prog && !mlx5e_rx_is_linear_skb (priv->mdev, &new_channels.params)) {netdev_err (netdev,"MTU(%d) > %d is not allowed while XDP enabled\n" , - new_mtu,MLX5E_XDP_MAX_MTU ); + new_mtu,mlx5e_xdp_max_mtu (params)); err = -EINVAL ; goto out; }
@@ -4212,7 +4212,8 @@ static int mlx5e_xdp_allowed(struct mlx5e_priv *priv, struct bpf_prog *prog)if (!mlx5e_rx_is_linear_skb (priv->mdev, &new_channels.params)) {netdev_warn (netdev,"XDP is not allowed with MTU(%d) > %d\n" , - new_channels.params.sw_mtu,MLX5E_XDP_MAX_MTU ); + new_channels.params.sw_mtu, +mlx5e_xdp_max_mtu (&new_channels.params));return -EINVAL ; }
Signature · 1 line
2.20.1
PATCH 3/3 net/mlx5e: ethtool, Remove unsupported SFP EEPROM high pages query
In reply to Saeed MahameedFrom: Erez Alfasi <[email protected]>
Querying EEPROM high pages data for SFP module is currently not supported by our driver and yet queried, resulting in invalid FW queries.
Set the EEPROM ethtool data length to 256 for SFP module will limit the reading for page 0 only and prevent invalid FW queries.
--- drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/port.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -1
@@ -1586,7 +1586,7 @@ static int mlx5e_get_module_info(struct net_device *netdev,break ;case MLX5_MODULE_ID_SFP : modinfo->type =ETH_MODULE_SFF_8472 ; - modinfo->eeprom_len =ETH_MODULE_SFF_8472_LEN ; + modinfo->eeprom_len =MLX5_EEPROM_PAGE_LENGTH ;break ;default : netdev_err(priv->netdev, "%s: cable type not recognized:0x%x\n",
drivers/net/ethernet/mellanox/mlx5/core/port.c +0 -4
@@ -317,10 +317,6 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, size -= offset + size -MLX5_EEPROM_PAGE_LENGTH ; i2c_addr =MLX5_I2C_ADDR_LOW ; -if (offset >=MLX5_EEPROM_PAGE_LENGTH ) { - i2c_addr =MLX5_I2C_ADDR_HIGH ; - offset -=MLX5_EEPROM_PAGE_LENGTH ; - }MLX5_SET (mcia_reg, in, l,0 );MLX5_SET (mcia_reg, in, module, module_num);
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Saeed Mahameed <[email protected]>
Date: Fri, 19 Apr 2019 14:03:09 -0700
Quoted 3 lines
This series introduces some fixes to mlx5 driver.
Please pull and let me know if there is any problem.
Pulled.
Quoted 8 lines
For -stable v4.7:
('net/mlx5e: ethtool, Remove unsupported SFP EEPROM high pages query')For -stable v4.19:
('net/mlx5e: Fix the max MTU check in case of XDP')For -stable v5.0:
('net/mlx5e: Fix use-after-free afterxdp_return_frame')
And queued up, thank you.