Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5578544img; Wed, 27 Mar 2019 11:03:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxztdb0BMKZh3FgZm0pmOm9XeiTr0ivr1vb1IyMrjWtX+uU2xPmFIIXLztBRGtWPmxIU0w4 X-Received: by 2002:a17:902:b617:: with SMTP id b23mr36341366pls.200.1553709811057; Wed, 27 Mar 2019 11:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553709811; cv=none; d=google.com; s=arc-20160816; b=SmOa468HjcwCp/pCnynM4kZBRIIZM0SUuGWIyy5rIjN/h8QAPXsP4w2co1lpbijx4M tUROypceQtqi/YKQgD6W1cOIUr2SgMXONfZTk5cuWUNV3RBLfJbDVTR8BE71LQNK3AX/ AST8oijyRgU8NDsqgO06pD51cYZIa9vUnHZmtATefO7VpxJiMLsHw6UdJ92pJMmrsNPu jHZJnwwZLSttlk4quXYGGYtUbu69BucLafsWrhK7gl954PiJsKsFRwbvEHUO+rFqE02P JdLJKIfstucmGADy0hpwXpWO810SbtsT7wnZ7PZ6pKsh5RfQd4rxXvIWBkwsuIMHV3s0 3g5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SB9J+BguECDg+yISvPs3EBTQjo9cyirXXnESQQG/+2U=; b=sxU/m5/bZi7wuGItQzRcGjMtG2J+SxZBkj5f7LJ1JQGCviS9QKBdFEDzie9kdJtF9d M2DWxlJmalv793GnI55OvUHqtWFH6Yma4fkiAIl42r99oAvwAI+6KTuaa8NyX6pZa8K2 YD7ZuC8n2LpOIdC8UxoLxr8EqWTPX4Jioh2lzLTRy/PViOH2h+aHiWIn+7+GJPIpmvHq xkMVgeiiYwlVZQyeciIB3+G975sWEfxQQ11of3M1h75J9b7k9c8egBEfa4/HO08ncRBd G+fm4IaQ30F0810RahlHsvlAtg4WMReFEhrlNHSRE4UY0v6CsLHZ7INEqbtt2Mp8xLTK gfDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w24wG7Zu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e25si8988613pgl.514.2019.03.27.11.03.15; Wed, 27 Mar 2019 11:03:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w24wG7Zu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730427AbfC0SCY (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:42156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728329AbfC0SCS (ORCPT ); Wed, 27 Mar 2019 14:02:18 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10B7A2147C; Wed, 27 Mar 2019 18:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709737; bh=0MmBENKnrh8PdvqducibOV4tmbdBBeileypXCNdTiFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w24wG7ZuFXdWsETk+8u+QocW9Uo4cTXzjXMk5peDzrfJfPJBe6ROYVUF8S/lS4OId XpoDvxXj6USU9+1SaC7UBKKZyxoYGkMBNAtZDXNygPW92kgFdM24gii5l4v8w6UlbK xFvSouBZMWo39ijI4dwgWlFqKopw9PPQXN46vDWo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tonghao Zhang , Mohamad Haj Yahia , Saeed Mahameed , Sasha Levin , netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 013/262] net/mlx5: Avoid panic when setting vport rate Date: Wed, 27 Mar 2019 13:57:48 -0400 Message-Id: <20190327180158.10245-13-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tonghao Zhang [ Upstream commit 24319258660a84dd77f4be026a55b10a12524919 ] If we try to set VFs rate on a VF (not PF) net device, the kernel will be crash. The commands are show as below: $ echo 2 > /sys/class/net/$MLX_PF0/device/sriov_numvfs $ ip link set $MLX_VF0 vf 0 max_tx_rate 2 min_tx_rate 1 If not applied the first patch ("net/mlx5: Avoid panic when setting vport mac, getting vport config"), the command: $ ip link set $MLX_VF0 vf 0 rate 100 can also crash the kernel. [ 1650.006388] RIP: 0010:mlx5_eswitch_set_vport_rate+0x1f/0x260 [mlx5_core] [ 1650.007092] do_setlink+0x982/0xd20 [ 1650.007129] __rtnl_newlink+0x528/0x7d0 [ 1650.007374] rtnl_newlink+0x43/0x60 [ 1650.007407] rtnetlink_rcv_msg+0x2a2/0x320 [ 1650.007484] netlink_rcv_skb+0xcb/0x100 [ 1650.007519] netlink_unicast+0x17f/0x230 [ 1650.007554] netlink_sendmsg+0x2d2/0x3d0 [ 1650.007592] sock_sendmsg+0x36/0x50 [ 1650.007625] ___sys_sendmsg+0x280/0x2a0 [ 1650.007963] __sys_sendmsg+0x58/0xa0 [ 1650.007998] do_syscall_64+0x5b/0x180 [ 1650.009438] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: c9497c98901c ("net/mlx5: Add support for setting VF min rate") Cc: Mohamad Haj Yahia Signed-off-by: Tonghao Zhang Reviewed-by: Roi Dayan Acked-by: Saeed Mahameed Signed-off-by: Saeed Mahameed Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 5b492b67f4e1..3e8ed5586821 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -2059,19 +2059,24 @@ static int normalize_vports_min_rate(struct mlx5_eswitch *esw, u32 divider) int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport, u32 max_rate, u32 min_rate) { - u32 fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share); - bool min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) && - fw_max_bw_share >= MLX5_MIN_BW_SHARE; - bool max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit); struct mlx5_vport *evport; + u32 fw_max_bw_share; u32 previous_min_rate; u32 divider; + bool min_rate_supported; + bool max_rate_supported; int err = 0; if (!ESW_ALLOWED(esw)) return -EPERM; if (!LEGAL_VPORT(esw, vport)) return -EINVAL; + + fw_max_bw_share = MLX5_CAP_QOS(esw->dev, max_tsar_bw_share); + min_rate_supported = MLX5_CAP_QOS(esw->dev, esw_bw_share) && + fw_max_bw_share >= MLX5_MIN_BW_SHARE; + max_rate_supported = MLX5_CAP_QOS(esw->dev, esw_rate_limit); + if ((min_rate && !min_rate_supported) || (max_rate && !max_rate_supported)) return -EOPNOTSUPP; -- 2.19.1