Skip to content

Commit 0960a27

Browse files
Marcin Szycikanguy11
authored andcommitted
ice: Add direction metadata
Currently it is possible to create a filter which breaks TX traffic, e.g.: tc filter add dev $PF1 ingress protocol ip prio 1 flower ip_proto udp dst_port $PORT action mirred egress redirect dev $VF1_PR This adds a rule which might match both TX and RX traffic, and in TX path the PF will actually receive the traffic, which breaks communication. To fix this, add a match on direction metadata flag when adding a tc rule. Because of the way metadata is currently handled, a duplicate lookup word would appear if VLAN metadata is also added. The lookup would still work correctly, but one word would be wasted. To prevent it, lookup 0 now always contains all metadata. When any metadata needs to be added, it is added to lookup 0 and lookup count is not incremented. This way, two flags residing in the same word will take up one word, instead of two. Note: the drop action is also affected, i.e. it will now only work in one direction. Signed-off-by: Marcin Szycik <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 505a1fd commit 0960a27

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

drivers/net/ethernet/intel/ice/ice_protocol_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ struct ice_nvgre_hdr {
287287
* M = EVLAN (0x8100) - Outer L2 header has EVLAN (ethernet type 0x8100)
288288
* N = EVLAN (0x9100) - Outer L2 header has EVLAN (ethernet type 0x9100)
289289
*/
290+
#define ICE_PKT_FROM_NETWORK BIT(3)
290291
#define ICE_PKT_VLAN_STAG BIT(12)
291292
#define ICE_PKT_VLAN_ITAG BIT(13)
292293
#define ICE_PKT_VLAN_EVLAN (BIT(14) | BIT(15))

drivers/net/ethernet/intel/ice/ice_switch.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6058,14 +6058,21 @@ ice_adv_add_update_vsi_list(struct ice_hw *hw,
60586058
void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup)
60596059
{
60606060
lkup->type = ICE_HW_METADATA;
6061-
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_TUNNEL] =
6061+
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_TUNNEL] |=
60626062
cpu_to_be16(ICE_PKT_TUNNEL_MASK);
60636063
}
60646064

6065+
void ice_rule_add_direction_metadata(struct ice_adv_lkup_elem *lkup)
6066+
{
6067+
lkup->type = ICE_HW_METADATA;
6068+
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_VLAN] |=
6069+
cpu_to_be16(ICE_PKT_FROM_NETWORK);
6070+
}
6071+
60656072
void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup)
60666073
{
60676074
lkup->type = ICE_HW_METADATA;
6068-
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_VLAN] =
6075+
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_VLAN] |=
60696076
cpu_to_be16(ICE_PKT_VLAN_MASK);
60706077
}
60716078

drivers/net/ethernet/intel/ice/ice_switch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ int ice_share_res(struct ice_hw *hw, u16 type, u8 shared, u16 res_id);
359359

360360
/* Switch/bridge related commands */
361361
void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup);
362+
void ice_rule_add_direction_metadata(struct ice_adv_lkup_elem *lkup);
362363
void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup);
363364
void ice_rule_add_src_vsi_metadata(struct ice_adv_lkup_elem *lkup);
364365
int

drivers/net/ethernet/intel/ice/ice_tc_lib.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "ice_lib.h"
88
#include "ice_protocol_type.h"
99

10+
#define ICE_TC_METADATA_LKUP_IDX 0
11+
1012
/**
1113
* ice_tc_count_lkups - determine lookup count for switch filter
1214
* @flags: TC-flower flags
@@ -19,7 +21,13 @@ static int
1921
ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
2022
struct ice_tc_flower_fltr *fltr)
2123
{
22-
int lkups_cnt = 0;
24+
int lkups_cnt = 1; /* 0th lookup is metadata */
25+
26+
/* Always add metadata as the 0th lookup. Included elements:
27+
* - Direction flag (always present)
28+
* - ICE_TC_FLWR_FIELD_VLAN_TPID (present if specified)
29+
* - Tunnel flag (present if tunnel)
30+
*/
2331

2432
if (flags & ICE_TC_FLWR_FIELD_TENANT_ID)
2533
lkups_cnt++;
@@ -54,10 +62,6 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
5462
if (flags & (ICE_TC_FLWR_FIELD_VLAN | ICE_TC_FLWR_FIELD_VLAN_PRIO))
5563
lkups_cnt++;
5664

57-
/* is VLAN TPID specified */
58-
if (flags & ICE_TC_FLWR_FIELD_VLAN_TPID)
59-
lkups_cnt++;
60-
6165
/* is CVLAN specified? */
6266
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO))
6367
lkups_cnt++;
@@ -84,10 +88,6 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
8488
ICE_TC_FLWR_FIELD_SRC_L4_PORT))
8589
lkups_cnt++;
8690

87-
/* matching for tunneled packets in metadata */
88-
if (fltr->tunnel_type != TNL_LAST)
89-
lkups_cnt++;
90-
9191
return lkups_cnt;
9292
}
9393

@@ -176,10 +176,9 @@ static u16 ice_check_supported_vlan_tpid(u16 vlan_tpid)
176176

177177
static int
178178
ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr,
179-
struct ice_adv_lkup_elem *list)
179+
struct ice_adv_lkup_elem *list, int i)
180180
{
181181
struct ice_tc_flower_lyr_2_4_hdrs *hdr = &fltr->outer_headers;
182-
int i = 0;
183182

184183
if (flags & ICE_TC_FLWR_FIELD_TENANT_ID) {
185184
u32 tenant_id;
@@ -329,8 +328,7 @@ ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr,
329328
}
330329

331330
/* always fill matching on tunneled packets in metadata */
332-
ice_rule_add_tunnel_metadata(&list[i]);
333-
i++;
331+
ice_rule_add_tunnel_metadata(&list[ICE_TC_METADATA_LKUP_IDX]);
334332

335333
return i;
336334
}
@@ -358,13 +356,16 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
358356
struct ice_tc_flower_lyr_2_4_hdrs *headers = &tc_fltr->outer_headers;
359357
bool inner = false;
360358
u16 vlan_tpid = 0;
361-
int i = 0;
359+
int i = 1; /* 0th lookup is metadata */
362360

363361
rule_info->vlan_type = vlan_tpid;
364362

363+
/* Always add direction metadata */
364+
ice_rule_add_direction_metadata(&list[ICE_TC_METADATA_LKUP_IDX]);
365+
365366
rule_info->tun_type = ice_sw_type_from_tunnel(tc_fltr->tunnel_type);
366367
if (tc_fltr->tunnel_type != TNL_LAST) {
367-
i = ice_tc_fill_tunnel_outer(flags, tc_fltr, list);
368+
i = ice_tc_fill_tunnel_outer(flags, tc_fltr, list, i);
368369

369370
headers = &tc_fltr->inner_headers;
370371
inner = true;
@@ -431,8 +432,7 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
431432
rule_info->vlan_type =
432433
ice_check_supported_vlan_tpid(vlan_tpid);
433434

434-
ice_rule_add_vlan_metadata(&list[i]);
435-
i++;
435+
ice_rule_add_vlan_metadata(&list[ICE_TC_METADATA_LKUP_IDX]);
436436
}
437437

438438
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO)) {

0 commit comments

Comments
 (0)