Commit f01f5559 authored by Jian Shen's avatar Jian Shen Committed by David S. Miller

net: hns3: don't allow vf to enable promisc mode

VF can receive packets of other functions when in promisc
mode. It's not safe, so don't allow VF to enable promisc
mode.
Signed-off-by: default avatarJian Shen <shenjian15@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b7b585c2
...@@ -203,12 +203,11 @@ static int hclge_map_unmap_ring_to_vf_vector(struct hclge_vport *vport, bool en, ...@@ -203,12 +203,11 @@ static int hclge_map_unmap_ring_to_vf_vector(struct hclge_vport *vport, bool en,
static int hclge_set_vf_promisc_mode(struct hclge_vport *vport, static int hclge_set_vf_promisc_mode(struct hclge_vport *vport,
struct hclge_mbx_vf_to_pf_cmd *req) struct hclge_mbx_vf_to_pf_cmd *req)
{ {
bool en_uc = req->msg[1] ? true : false; bool en_bc = req->msg[1] ? true : false;
bool en_mc = req->msg[2] ? true : false;
struct hclge_promisc_param param; struct hclge_promisc_param param;
/* always enable broadcast promisc bit */ /* vf is not allowed to enable unicast/multicast broadcast */
hclge_promisc_param_init(&param, en_uc, en_mc, true, vport->vport_id); hclge_promisc_param_init(&param, false, false, en_bc, vport->vport_id);
return hclge_cmd_set_promisc_mode(vport->back, &param); return hclge_cmd_set_promisc_mode(vport->back, &param);
} }
......
...@@ -969,33 +969,29 @@ static int hclgevf_put_vector(struct hnae3_handle *handle, int vector) ...@@ -969,33 +969,29 @@ static int hclgevf_put_vector(struct hnae3_handle *handle, int vector)
} }
static int hclgevf_cmd_set_promisc_mode(struct hclgevf_dev *hdev, static int hclgevf_cmd_set_promisc_mode(struct hclgevf_dev *hdev,
bool en_uc_pmc, bool en_mc_pmc) bool en_bc_pmc)
{ {
struct hclge_mbx_vf_to_pf_cmd *req; struct hclge_mbx_vf_to_pf_cmd *req;
struct hclgevf_desc desc; struct hclgevf_desc desc;
int status; int ret;
req = (struct hclge_mbx_vf_to_pf_cmd *)desc.data; req = (struct hclge_mbx_vf_to_pf_cmd *)desc.data;
hclgevf_cmd_setup_basic_desc(&desc, HCLGEVF_OPC_MBX_VF_TO_PF, false); hclgevf_cmd_setup_basic_desc(&desc, HCLGEVF_OPC_MBX_VF_TO_PF, false);
req->msg[0] = HCLGE_MBX_SET_PROMISC_MODE; req->msg[0] = HCLGE_MBX_SET_PROMISC_MODE;
req->msg[1] = en_uc_pmc ? 1 : 0; req->msg[1] = en_bc_pmc ? 1 : 0;
req->msg[2] = en_mc_pmc ? 1 : 0;
status = hclgevf_cmd_send(&hdev->hw, &desc, 1); ret = hclgevf_cmd_send(&hdev->hw, &desc, 1);
if (status) if (ret)
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Set promisc mode fail, status is %d.\n", status); "Set promisc mode fail, status is %d.\n", ret);
return status; return ret;
} }
static int hclgevf_set_promisc_mode(struct hnae3_handle *handle, static int hclgevf_set_promisc_mode(struct hclgevf_dev *hdev, bool en_bc_pmc)
bool en_uc_pmc, bool en_mc_pmc)
{ {
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle); return hclgevf_cmd_set_promisc_mode(hdev, en_bc_pmc);
return hclgevf_cmd_set_promisc_mode(hdev, en_uc_pmc, en_mc_pmc);
} }
static int hclgevf_tqp_enable(struct hclgevf_dev *hdev, int tqp_id, static int hclgevf_tqp_enable(struct hclgevf_dev *hdev, int tqp_id,
...@@ -2382,6 +2378,15 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev) ...@@ -2382,6 +2378,15 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
if (ret) if (ret)
goto err_config; goto err_config;
/* vf is not allowed to enable unicast/multicast promisc mode.
* For revision 0x20, default to disable broadcast promisc mode,
* firmware makes sure broadcast packets can be accepted.
* For revision 0x21, default to enable broadcast promisc mode.
*/
ret = hclgevf_set_promisc_mode(hdev, true);
if (ret)
goto err_config;
/* Initialize RSS for this VF */ /* Initialize RSS for this VF */
ret = hclgevf_rss_init_hw(hdev); ret = hclgevf_rss_init_hw(hdev);
if (ret) { if (ret) {
...@@ -2646,7 +2651,6 @@ static const struct hnae3_ae_ops hclgevf_ops = { ...@@ -2646,7 +2651,6 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.get_vector = hclgevf_get_vector, .get_vector = hclgevf_get_vector,
.put_vector = hclgevf_put_vector, .put_vector = hclgevf_put_vector,
.reset_queue = hclgevf_reset_tqp, .reset_queue = hclgevf_reset_tqp,
.set_promisc_mode = hclgevf_set_promisc_mode,
.get_mac_addr = hclgevf_get_mac_addr, .get_mac_addr = hclgevf_get_mac_addr,
.set_mac_addr = hclgevf_set_mac_addr, .set_mac_addr = hclgevf_set_mac_addr,
.add_uc_addr = hclgevf_add_uc_addr, .add_uc_addr = hclgevf_add_uc_addr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment