Skip to contentSkip to conversation

ice: offload not fragmented ip packets

PATCH New Michal Swiatkowski 1 participant 3 messages Oct 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ice: offload not fragmented ip packets

Hi,

OVS in default mode adds tc flower filters with "ip_flags nofrag". ice rejects any match on control flags, so these flows can't be offloaded and all IP traffic goes through the slow path.

HW has a metadata flag that says whether a packet is fragmented (IPv4 or IPv6). Use it to offload the "not fragmented" case. Matching on fragments isn't supported, because it would need different training packets and would break L4 matching. Tunneled filters are also rejected, as the flag can come from either the outer or the inner IP header.

The first patch is a preparation: all 32 bits of the tc flower flags are already used, so the field is extended to u64 and the defines use BIT_ULL(). The second patch adds the nofrag match.

Example:

$ tc filter add dev $VF_PR ingress protocol ip prio 1 flower \
    src_mac 0a:7a:c1:6b:8e:1c dst_mac be:9d:68:58:51:d8 \
    ip_flags nofrag skip_sw \
    action mirred egress redirect dev $VF2_PR

Tested with iperf traffic between OVS bridge ports in switchdev mode. All packets are offloaded.

Michal Swiatkowski (2):
ice: extend tc flags field to u64
ice: allow matching on no_frag ip packets

 drivers/net/ethernet/intel/ice/ice_main.c     |  2 +-
 .../ethernet/intel/ice/ice_protocol_type.h    |  1 +
 drivers/net/ethernet/intel/ice/ice_switch.c   |  7 ++
 drivers/net/ethernet/intel/ice/ice_switch.h   |  1 +
 drivers/net/ethernet/intel/ice/ice_tc_lib.c   | 51 +++++++++++---
 drivers/net/ethernet/intel/ice/ice_tc_lib.h   | 67 ++++++++++---------
 6 files changed, 85 insertions(+), 44 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/2 ice: extend tc flags field to u64

There is no more space for tc flags. Change u32 to u64. Use BIT_ULL instead of BIT.

Assisted-by Copilot:claude-opus-5
---
 drivers/net/ethernet/intel/ice/ice_main.c   |  2 +-
 drivers/net/ethernet/intel/ice/ice_tc_lib.c | 16 ++---
 drivers/net/ethernet/intel/ice/ice_tc_lib.h | 66 ++++++++++-----------
 3 files changed, 42 insertions(+), 42 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
index ff2d6d4f942a..005fb77ef7fd 100644
@@ -8973,7 +8973,7 @@ static void ice_rem_all_chnl_fltrs(struct ice_pf *pf)
 		} else if (fltr->dest_vsi) {
 			/* update advanced switch filter count */
 			if (fltr->dest_vsi->type == ICE_VSI_CHNL) {
-				u32 flags = fltr->flags;
+				u64 flags = fltr->flags;
 
 				fltr->dest_vsi->num_chnl_fltr--;
 				if (flags & (ICE_TC_FLWR_FIELD_DST_MAC |
drivers/net/ethernet/intel/ice/ice_tc_lib.c +8 -8
index 628b2184df00..560d939b2008 100644
@@ -16,7 +16,7 @@
  *
  * Return: lookup count based on TC flower input for a switch filter.
  */
-static int ice_tc_count_lkups(u32 flags, struct ice_tc_flower_fltr *fltr)
+static int ice_tc_count_lkups(u64 flags, struct ice_tc_flower_fltr *fltr)
 {
 	int lkups_cnt = 1; /* 0th lookup is metadata */
 
@@ -182,7 +182,7 @@ static u16 ice_check_supported_vlan_tpid(u16 vlan_tpid)
 }
 
 static int
-ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr,
+ice_tc_fill_tunnel_outer(u64 flags, struct ice_tc_flower_fltr *fltr,
 			 struct ice_adv_lkup_elem *list, int i)
 {
 	struct ice_tc_flower_lyr_2_4_hdrs *hdr = &fltr->outer_headers;
@@ -369,7 +369,7 @@ ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr,
  * advance filter in hardware.
  */
 static int
-ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
+ice_tc_fill_rules(struct ice_hw *hw, u64 flags,
 		  struct ice_tc_flower_fltr *tc_fltr,
 		  struct ice_adv_lkup_elem *list,
 		  struct ice_adv_rule_info *rule_info,
@@ -932,7 +932,7 @@ ice_eswitch_add_tc_fltr(struct ice_vsi *vsi, struct ice_tc_flower_fltr *fltr)
 	struct ice_rule_query_data rule_added;
 	struct ice_hw *hw = &vsi->back->hw;
 	struct ice_adv_lkup_elem *list;
-	u32 flags = fltr->flags;
+	u64 flags = fltr->flags;
 	int lkups_cnt;
 	int ret;
 	int i;
@@ -1161,7 +1161,7 @@ ice_add_tc_flower_adv_fltr(struct ice_vsi *vsi,
 	struct ice_adv_lkup_elem *list;
 	struct ice_pf *pf = vsi->back;
 	struct ice_hw *hw = &pf->hw;
-	u32 flags = tc_fltr->flags;
+	u64 flags = tc_fltr->flags;
 	struct ice_vsi *dest_vsi;
 	struct device *dev;
 	u16 lkups_cnt = 0;
@@ -1279,19 +1279,19 @@ ice_add_tc_flower_adv_fltr(struct ice_vsi *vsi,
 	}
 	switch (tc_fltr->action.fltr_act) {
 	case ICE_FWD_TO_VSI:
-		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%x), action is forward to TC %u, rid %u, rule_id %u, vsi_idx %u\n",
+		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%llx), action is forward to TC %u, rid %u, rule_id %u, vsi_idx %u\n",
 			lkups_cnt, flags,
 			tc_fltr->action.fwd.tc.tc_class, rule_added.rid,
 			rule_added.rule_id, rule_added.vsi_handle);
 		break;
 	case ICE_FWD_TO_Q:
-		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%x), action is forward to queue: %u (HW queue %u)     , rid %u, rule_id %u\n",
+		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%llx), action is forward to queue: %u (HW queue %u)     , rid %u, rule_id %u\n",
 			lkups_cnt, flags, tc_fltr->action.fwd.q.queue,
 			tc_fltr->action.fwd.q.hw_queue, rule_added.rid,
 			rule_added.rule_id);
 		break;
 	case ICE_DROP_PACKET:
-		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%x), action is drop, rid %u, rule_id %u\n",
+		dev_dbg(dev, "added switch rule (lkups_cnt %u, flags 0x%llx), action is drop, rid %u, rule_id %u\n",
 			lkups_cnt, flags, rule_added.rid, rule_added.rule_id);
 		break;
 	default:
drivers/net/ethernet/intel/ice/ice_tc_lib.h +33 -33

78 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw

PATCH 2/2 ice: allow matching on no_frag ip packets

In reply to Michal Swiatkowski

There is a metadata flag telling whether a packet is fragmented. It covers both ipv4 and ipv6 fragments. Use it to offload the "not fragmented" case.

Offloading the fragmented case isn't that simple, as it needs changes in the training packets. For ipv4 a bit has to be set in the header, but for ipv6 an additional header is needed. A packet fragmented like that results in an incorrect parser result for L4 matching. Because of that, leave only support for no_frag.

The flag is set for a fragment in either the outer or the inner header and there is no way to tell the two apart. Reject the match on tunneled filters then, so that there is always one IP header. PFCP is excluded from that, as it is considered non-tunneled and its headers aren't swapped.

Non-tunneled filters are programmed with ICE_NON_TUN, so encapsulated traffic is matched by tunnel profiles only and can't reach these rules.

Example tc command:

$ tc filter add dev ens786f1r1 ingress protocol ip prio 1 flower \
    src_mac 0a:7a:c1:6b:8e:1c \
    dst_mac be:9d:68:58:51:d8 \
    ip_flags nofrag \
    skip_sw \
    action mirred egress redirect dev ens786f1r0

OVS in default mode is adding this kind of filter, so without this match the ip flows weren't offloaded to HW. With this change, running iperf traffic between OVS bridge ports results in offloading all packets.

Assisted-by Copilot:claude-opus-5
---
 .../ethernet/intel/ice/ice_protocol_type.h    |  1 +
 drivers/net/ethernet/intel/ice/ice_switch.c   |  7 ++++
 drivers/net/ethernet/intel/ice/ice_switch.h   |  1 +
 drivers/net/ethernet/intel/ice/ice_tc_lib.c   | 35 +++++++++++++++++--
 drivers/net/ethernet/intel/ice/ice_tc_lib.h   |  1 +
 5 files changed, 43 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_protocol_type.h +1 -0
index 725167d557a8..3a3b66a8ec1a 100644
@@ -356,6 +356,7 @@ struct ice_nvgre_hdr {
 #define ICE_PKT_TUNNEL_MAC	BIT(6)
 #define ICE_PKT_TUNNEL_VLAN	BIT(7)
 #define ICE_PKT_TUNNEL_MASK	(ICE_PKT_TUNNEL_MAC | ICE_PKT_TUNNEL_VLAN)
+#define ICE_PKT_IS_FRAG		BIT(8)
 
 /* MDID 22
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
drivers/net/ethernet/intel/ice/ice_switch.c +7 -0
index 4daee252e2a6..060a271be0f5 100644
@@ -6009,6 +6009,13 @@ void ice_rule_add_direction_metadata(struct ice_adv_lkup_elem *lkup)
 		cpu_to_be16(ICE_PKT_FROM_NETWORK);
 }
 
+void ice_rule_add_nofrag_metadata(struct ice_adv_lkup_elem *lkup)
+{
+	lkup->type = ICE_HW_METADATA;
+	lkup->m_u.metadata.flags[ICE_PKT_FLAGS_MDID21] |=
+		cpu_to_be16(ICE_PKT_IS_FRAG);
+}
+
 void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup)
 {
 	lkup->type = ICE_HW_METADATA;
drivers/net/ethernet/intel/ice/ice_switch.h +1 -0
index 671d7a5f359f..b282c476d6b2 100644
@@ -347,6 +347,7 @@ int ice_share_res(struct ice_hw *hw, u16 type, u8 shared, u16 res_id);
 /* Switch/bridge related commands */
 void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup);
 void ice_rule_add_direction_metadata(struct ice_adv_lkup_elem *lkup);
+void ice_rule_add_nofrag_metadata(struct ice_adv_lkup_elem *lkup);
 void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup);
 void ice_rule_add_src_vsi_metadata(struct ice_adv_lkup_elem *lkup);
 int
drivers/net/ethernet/intel/ice/ice_tc_lib.c +33 -2
index 560d939b2008..d90a9b52cd5b 100644
@@ -24,6 +24,7 @@ static int ice_tc_count_lkups(u64 flags, struct ice_tc_flower_fltr *fltr)
 	 * - Direction flag (always present)
 	 * - ICE_TC_FLWR_FIELD_VLAN_TPID (present if specified)
 	 * - Tunnel flag (present if tunnel)
+	 * - ICE_TC_FLWR_FIELD_NOFRAG (present if specified)
 	 */
 	if (fltr->direction == ICE_ESWITCH_FLTR_EGRESS)
 		lkups_cnt++;
@@ -385,6 +386,9 @@ ice_tc_fill_rules(struct ice_hw *hw, u64 flags,
 	/* Always add direction metadata */
 	ice_rule_add_direction_metadata(&list[ICE_TC_METADATA_LKUP_IDX]);
 
+	if (flags & ICE_TC_FLWR_FIELD_NOFRAG)
+		ice_rule_add_nofrag_metadata(&list[ICE_TC_METADATA_LKUP_IDX]);
+
 	if (tc_fltr->direction == ICE_ESWITCH_FLTR_EGRESS) {
 		ice_rule_add_src_vsi_metadata(&list[i]);
 		i++;
@@ -1876,9 +1880,36 @@ ice_parse_cls_flower(struct net_device *filter_dev, struct ice_vsi *vsi,
 
 		addr_type = match.key->addr_type;
 
-		if (flow_rule_has_control_flags(match.mask->flags,
-						fltr->extack))
+		if (!flow_rule_is_supp_control_flags(FLOW_DIS_IS_FRAGMENT,
+						     match.mask->flags,
+						     fltr->extack))
 			return -EOPNOTSUPP;
+
+		if (match.mask->flags & FLOW_DIS_IS_FRAGMENT) {
+			/* HW can only match on the "not fragmented" metadata
+			 * flag, there is no way to match fragments.
+			 */
+			if (match.key->flags & FLOW_DIS_IS_FRAGMENT) {
+				NL_SET_ERR_MSG_MOD(fltr->extack,
+						   "Match on fragmented packets is not supported");
+				return -EOPNOTSUPP;
+			}
+
+			/* The metadata flag is set for a fragment in either
+			 * the outer or the inner header, without a way to
+			 * tell which one. Allow the match only when there is
+			 * one IP header and one ip_flags, so the meaning is
+			 * unambiguous. PFCP is considered non-tunneled.
+			 */
+			if (fltr->tunnel_type != TNL_LAST &&
+			    fltr->tunnel_type != TNL_PFCP) {
+				NL_SET_ERR_MSG_MOD(fltr->extack,
+						   "Match on fragmentation of tunneled packets is not supported");
+				return -EOPNOTSUPP;
+			}
+
+			fltr->flags |= ICE_TC_FLWR_FIELD_NOFRAG;
+		}
 	}
 
 	if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
drivers/net/ethernet/intel/ice/ice_tc_lib.h +1 -0
index 234cc9bafc41..326358cc5884 100644
@@ -39,6 +39,7 @@
 #define ICE_TC_FLWR_FIELD_VLAN_TPID		BIT_ULL(29)
 #define ICE_TC_FLWR_FIELD_PFCP_OPTS		BIT_ULL(30)
 #define ICE_TC_FLWR_FIELD_IP_PROTO		BIT_ULL(31)
+#define ICE_TC_FLWR_FIELD_NOFRAG		BIT_ULL(32)
 
 #define ICE_TC_FLOWER_MASK_32   0xFFFFFFFF
 
Signature · 1 line
2.49.0