Skip to content

Commit efe3fa4

Browse files
Guojia Liaodavem330
authored andcommitted
net: hns3: fix aRFS FD rules leftover after add a user FD rule
When user had created a FD rule, all the aRFS rules should be clear up. HNS3 process flow as below: 1.get spin lock of fd_ruls_list 2.clear up all aRFS rules 3.release lock 4.get spin lock of fd_ruls_list 5.creat a rules 6.release lock; There is a short period of time between step 3 and step 4, which would creatting some new aRFS FD rules if driver was receiving packet. So refactor the fd_rule_lock to fix it. Fixes: 4412288 ("net: hns3: refine the flow director handle") Signed-off-by: Guojia Liao <[email protected]> Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a6f7bfd commit efe3fa4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5806,9 +5806,9 @@ static int hclge_add_fd_entry(struct hnae3_handle *handle,
58065806
/* to avoid rule conflict, when user configure rule by ethtool,
58075807
* we need to clear all arfs rules
58085808
*/
5809+
spin_lock_bh(&hdev->fd_rule_lock);
58095810
hclge_clear_arfs_rules(handle);
58105811

5811-
spin_lock_bh(&hdev->fd_rule_lock);
58125812
ret = hclge_fd_config_rule(hdev, rule);
58135813

58145814
spin_unlock_bh(&hdev->fd_rule_lock);
@@ -5851,6 +5851,7 @@ static int hclge_del_fd_entry(struct hnae3_handle *handle,
58515851
return ret;
58525852
}
58535853

5854+
/* make sure being called after lock up with fd_rule_lock */
58545855
static void hclge_del_all_fd_entries(struct hnae3_handle *handle,
58555856
bool clear_list)
58565857
{
@@ -5863,7 +5864,6 @@ static void hclge_del_all_fd_entries(struct hnae3_handle *handle,
58635864
if (!hnae3_dev_fd_supported(hdev))
58645865
return;
58655866

5866-
spin_lock_bh(&hdev->fd_rule_lock);
58675867
for_each_set_bit(location, hdev->fd_bmap,
58685868
hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
58695869
hclge_fd_tcam_config(hdev, HCLGE_FD_STAGE_1, true, location,
@@ -5880,8 +5880,6 @@ static void hclge_del_all_fd_entries(struct hnae3_handle *handle,
58805880
bitmap_zero(hdev->fd_bmap,
58815881
hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1]);
58825882
}
5883-
5884-
spin_unlock_bh(&hdev->fd_rule_lock);
58855883
}
58865884

58875885
static int hclge_restore_fd_entries(struct hnae3_handle *handle)
@@ -6263,7 +6261,7 @@ static int hclge_add_fd_entry_by_arfs(struct hnae3_handle *handle, u16 queue_id,
62636261
u16 flow_id, struct flow_keys *fkeys)
62646262
{
62656263
struct hclge_vport *vport = hclge_get_vport(handle);
6266-
struct hclge_fd_rule_tuples new_tuples;
6264+
struct hclge_fd_rule_tuples new_tuples = {};
62676265
struct hclge_dev *hdev = vport->back;
62686266
struct hclge_fd_rule *rule;
62696267
u16 tmp_queue_id;
@@ -6273,19 +6271,17 @@ static int hclge_add_fd_entry_by_arfs(struct hnae3_handle *handle, u16 queue_id,
62736271
if (!hnae3_dev_fd_supported(hdev))
62746272
return -EOPNOTSUPP;
62756273

6276-
memset(&new_tuples, 0, sizeof(new_tuples));
6277-
hclge_fd_get_flow_tuples(fkeys, &new_tuples);
6278-
6279-
spin_lock_bh(&hdev->fd_rule_lock);
6280-
62816274
/* when there is already fd rule existed add by user,
62826275
* arfs should not work
62836276
*/
6277+
spin_lock_bh(&hdev->fd_rule_lock);
62846278
if (hdev->fd_active_type == HCLGE_FD_EP_ACTIVE) {
62856279
spin_unlock_bh(&hdev->fd_rule_lock);
62866280
return -EOPNOTSUPP;
62876281
}
62886282

6283+
hclge_fd_get_flow_tuples(fkeys, &new_tuples);
6284+
62896285
/* check is there flow director filter existed for this flow,
62906286
* if not, create a new filter for it;
62916287
* if filter exist with different queue id, modify the filter;
@@ -6368,6 +6364,7 @@ static void hclge_rfs_filter_expire(struct hclge_dev *hdev)
63686364
#endif
63696365
}
63706366

6367+
/* make sure being called after lock up with fd_rule_lock */
63716368
static void hclge_clear_arfs_rules(struct hnae3_handle *handle)
63726369
{
63736370
#ifdef CONFIG_RFS_ACCEL
@@ -6420,10 +6417,14 @@ static void hclge_enable_fd(struct hnae3_handle *handle, bool enable)
64206417

64216418
hdev->fd_en = enable;
64226419
clear = hdev->fd_active_type == HCLGE_FD_ARFS_ACTIVE;
6423-
if (!enable)
6420+
6421+
if (!enable) {
6422+
spin_lock_bh(&hdev->fd_rule_lock);
64246423
hclge_del_all_fd_entries(handle, clear);
6425-
else
6424+
spin_unlock_bh(&hdev->fd_rule_lock);
6425+
} else {
64266426
hclge_restore_fd_entries(handle);
6427+
}
64276428
}
64286429

64296430
static void hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable)
@@ -6886,8 +6887,9 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
68866887
int i;
68876888

68886889
set_bit(HCLGE_STATE_DOWN, &hdev->state);
6889-
6890+
spin_lock_bh(&hdev->fd_rule_lock);
68906891
hclge_clear_arfs_rules(handle);
6892+
spin_unlock_bh(&hdev->fd_rule_lock);
68916893

68926894
/* If it is not PF reset, the firmware will disable the MAC,
68936895
* so it only need to stop phy here.

0 commit comments

Comments
 (0)