Skip to contentSkip to conversation

ice: convert ice_add_prof() to bitmap

PATCH In review Przemek Kitszel 3 participants 4 messages Jun 18, 2025 – Jul 11, 2025

Subsystems (3)
lore
Share & tools
lore

Przemek Kitszel

author maintainer
#0 lore raw

PATCH 1/1 ice: convert ice_add_prof() to bitmap

From: Jesse Brandeburg <[email protected]>

Previously the ice_add_prof() took an array of u8 and looped over it with for_each_set_bit(), examining each 8 bit value as a bitmap. This was just hard to understand and unnecessary, and was triggering undefined behavior sanitizers with unaligned accesses within bitmap fields (on our internal tools/builds). Since the @ptype being passed in was already declared as a bitmap, refactor this to use native types with the advantage of simplifying the code to use a single loop.

---
 .../net/ethernet/intel/ice/ice_flex_pipe.h    |  7 +-
 .../net/ethernet/intel/ice/ice_flex_pipe.c    | 78 +++++++------------
 drivers/net/ethernet/intel/ice/ice_flow.c     |  4 +-
 3 files changed, 34 insertions(+), 55 deletions(-)
drivers/net/ethernet/intel/ice/ice_flex_pipe.h +4 -3
index 28b0897adf32..ee5d9f9c9d53 100644
@@ -39,9 +39,10 @@ bool ice_hw_ptype_ena(struct ice_hw *hw, u16 ptype);
 
 /* XLT2/VSI group functions */
 int
-ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
-	     const struct ice_ptype_attributes *attr, u16 attr_cnt,
-	     struct ice_fv_word *es, u16 *masks, bool symm, bool fd_swap);
+ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id,
+	     unsigned long *ptypes, const struct ice_ptype_attributes *attr,
+	     u16 attr_cnt, struct ice_fv_word *es, u16 *masks, bool symm,
+	     bool fd_swap);
 struct ice_prof_map *
 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id);
 int
drivers/net/ethernet/intel/ice/ice_flex_pipe.c +28 -50

101 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_flow.c +2 -2
index d97b751052f2..c63e43b8b110 100644
@@ -1421,7 +1421,7 @@ ice_flow_add_prof_sync(struct ice_hw *hw, enum ice_block blk,
 	}
 
 	/* Add a HW profile for this flow profile */
-	status = ice_add_prof(hw, blk, prof_id, (u8 *)params->ptypes,
+	status = ice_add_prof(hw, blk, prof_id, params->ptypes,
 			      params->attr, params->attr_cnt, params->es,
 			      params->mask, symm, true);
 	if (status) {
@@ -1617,7 +1617,7 @@ ice_flow_set_parser_prof(struct ice_hw *hw, u16 dest_vsi, u16 fdir_vsi,
 		break;
 	}
 
-	status = ice_add_prof(hw, blk, id, (u8 *)prof->ptypes,
+	status = ice_add_prof(hw, blk, id, prof->ptypes,
 			      params->attr, params->attr_cnt,
 			      params->es, params->mask, false, false);
 	if (status)
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw

Dear Przemek, dear Jesse,

Thank you for the patch.

Am 18.06.25 um 13:28 schrieb Przemek Kitszel:

Quoted 9 lines

From: Jesse Brandeburg <[email protected]>

Previously the ice_add_prof() took an array of u8 and looped over it with for_each_set_bit(), examining each 8 bit value as a bitmap. This was just hard to understand and unnecessary, and was triggering undefined behavior sanitizers with unaligned accesses within bitmap fields (on our internal tools/builds). Since the @ptype being passed in was already declared as a bitmap, refactor this to use native types with the advantage of simplifying the code to use a single loop.

Any tests to verify no regressions are introduced?

Quoted 11 lines
---
  .../net/ethernet/intel/ice/ice_flex_pipe.h    |  7 +-
  .../net/ethernet/intel/ice/ice_flex_pipe.c    | 78 +++++++------------
  drivers/net/ethernet/intel/ice/ice_flow.c     |  4 +-
  3 files changed, 34 insertions(+), 55 deletions(-)

More removed lines than added ones is always a good diff stat.

Quoted 139 lines
drivers/net/ethernet/intel/ice/ice_flex_pipe.h +4 -3
index 28b0897adf32..ee5d9f9c9d53 100644
@@ -39,9 +39,10 @@ bool ice_hw_ptype_ena(struct ice_hw *hw, u16 ptype);
 
  /* XLT2/VSI group functions */
  int
-ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
-	     const struct ice_ptype_attributes *attr, u16 attr_cnt,
-	     struct ice_fv_word *es, u16 *masks, bool symm, bool fd_swap);
+ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id,
+	     unsigned long *ptypes, const struct ice_ptype_attributes *attr,
+	     u16 attr_cnt, struct ice_fv_word *es, u16 *masks, bool symm,
+	     bool fd_swap);
  struct ice_prof_map *
  ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id);
  int
drivers/net/ethernet/intel/ice/ice_flex_pipe.c +28 -50
index ed95072ca6e3..363ae79a3620 100644
@@ -3043,16 +3043,16 @@ ice_disable_fd_swap(struct ice_hw *hw, u8 prof_id)
   * the ID value used here.
   */
  int
-ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
-	     const struct ice_ptype_attributes *attr, u16 attr_cnt,
-	     struct ice_fv_word *es, u16 *masks, bool symm, bool fd_swap)
+ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id,
+	     unsigned long *ptypes, const struct ice_ptype_attributes *attr,
+	     u16 attr_cnt, struct ice_fv_word *es, u16 *masks, bool symm,
+	     bool fd_swap)
  {
-	u32 bytes = DIV_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
  	DECLARE_BITMAP(ptgs_used, ICE_XLT1_CNT);
  	struct ice_prof_map *prof;
-	u8 byte = 0;
-	u8 prof_id;
  	int status;
+	u8 prof_id;
+	u16 ptype;
 
  	bitmap_zero(ptgs_used, ICE_XLT1_CNT);
 
@@ -3102,57 +3102,35 @@ ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
  	prof->context = 0;
 
  	/* build list of ptgs */
-	while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
-		u8 bit;
+	for_each_set_bit(ptype, ptypes, ICE_FLOW_PTYPE_MAX) {
+		u8 ptg;
 
-		if (!ptypes[byte]) {
-			bytes--;
-			byte++;
+		/* The package should place all ptypes in a non-zero
+		 * PTG, so the following call should never fail.
+		 */
+		if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
  			continue;
-		}
 
-		/* Examine 8 bits per byte */
-		for_each_set_bit(bit, (unsigned long *)&ptypes[byte],
-				 BITS_PER_BYTE) {
-			u16 ptype;
-			u8 ptg;
-
-			ptype = byte * BITS_PER_BYTE + bit;
-
-			/* The package should place all ptypes in a non-zero
-			 * PTG, so the following call should never fail.
-			 */
-			if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
-				continue;
+		/* If PTG is already added, skip and continue */
+		if (test_bit(ptg, ptgs_used))
+			continue;
 
-			/* If PTG is already added, skip and continue */
-			if (test_bit(ptg, ptgs_used))
-				continue;
+		set_bit(ptg, ptgs_used);
+		/* Check to see there are any attributes for this ptype, and
+		 * add them if found.
+		 */
+		status = ice_add_prof_attrib(prof, ptg, ptype, attr, attr_cnt);
+		if (status == -ENOSPC)
+			break;
+		if (status) {
+			/* This is simple a ptype/PTG with no attribute */
+			prof->ptg[prof->ptg_cnt] = ptg;
+			prof->attr[prof->ptg_cnt].flags = 0;
+			prof->attr[prof->ptg_cnt].mask = 0;
 
-			__set_bit(ptg, ptgs_used);
-			/* Check to see there are any attributes for
-			 * this PTYPE, and add them if found.
-			 */
-			status = ice_add_prof_attrib(prof, ptg, ptype,
-						     attr, attr_cnt);
-			if (status == -ENOSPC)
+			if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
  				break;
-			if (status) {
-				/* This is simple a PTYPE/PTG with no
-				 * attribute
-				 */
-				prof->ptg[prof->ptg_cnt] = ptg;
-				prof->attr[prof->ptg_cnt].flags = 0;
-				prof->attr[prof->ptg_cnt].mask = 0;
-
-				if (++prof->ptg_cnt >=
-				    ICE_MAX_PTG_PER_PROFILE)
-					break;
-			}
  		}
-
-		bytes--;
-		byte++;
  	}
 
  	list_add(&prof->list, &hw->blk[blk].es.prof_map);
drivers/net/ethernet/intel/ice/ice_flow.c +1 -1
index d97b751052f2..c63e43b8b110 100644
@@ -1421,7 +1421,7 @@ ice_flow_add_prof_sync(struct ice_hw *hw, enum ice_block blk,
  	}
 
  	/* Add a HW profile for this flow profile */
-	status = ice_add_prof(hw, blk, prof_id, (u8 *)params->ptypes,
+	status = ice_add_prof(hw, blk, prof_id, params->ptypes,
  			      params->attr, params->attr_cnt, params->es,
  			      params->mask, symm, true);
  	if (status) {

drivers/net/ethernet/intel/ice/ice_flow.c ice_flow_set_parser_prof(struct ice_hw *hw, u16 dest_vsi, u16 fdir_vsi, · line 1623

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_flow.c +1 -1
@@ -1617,7 +1617,7 @@ ice_flow_set_parser_prof(struct ice_hw *hw, u16 dest_vsi, u16 fdir_vsi,
  		break;
  	}
 
-	status = ice_add_prof(hw, blk, id, (u8 *)prof->ptypes,
+	status = ice_add_prof(hw, blk, id, prof->ptypes,
  			      params->attr, params->attr_cnt,
  			      params->es, params->mask, false, false);
  	if (status)

Kind regards,

Paul

author maintainer
#2 lore raw
Quoted 16 lines · Paul Menzel

Dear Przemek, dear Jesse,

Thank you for the patch.

Am 18.06.25 um 13:28 schrieb Przemek Kitszel:

Quoted 9 lines

From: Jesse Brandeburg <[email protected]>

Previously the ice_add_prof() took an array of u8 and looped over it with for_each_set_bit(), examining each 8 bit value as a bitmap. This was just hard to understand and unnecessary, and was triggering undefined behavior sanitizers with unaligned accesses within bitmap fields (on our internal tools/builds). Since the @ptype being passed in was already declared as a bitmap, refactor this to use native types with the advantage of simplifying the code to use a single loop.

Quoted 1 line

Any tests to verify no regressions are introduced?

Hi, nothing specific, and nothing that could not be inferred from the commit message, if our VAL would ask me, the reply would be: please test against FDIR regressions :)

Alexandr has this patch included in a bigger pile of work, which passed many tests, this is also a form we have present in our OOT driver for about 3 years by now.

[...]

Quoted 1 line

Thank you!

Quoted 5 lines

Kind regards,

Paul

Tested-by on v1 1/1
#3 lore raw
In reply to Przemek Kitszel
Quoted 18 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Przemek Kitszel
Sent: 18 June 2025 16:59
To: [email protected]; Nguyen, Anthony L <[email protected]>
Cc: [email protected]; Kitszel, Przemyslaw <[email protected]>; Keller, Jacob E <[email protected]>; Loktionov, Aleksandr <[email protected]>; Brandeburg, Jesse <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-next] ice: convert ice_add_prof() to bitmap

From: Jesse Brandeburg <[email protected]>

Previously the ice_add_prof() took an array of u8 and looped over it with for_each_set_bit(), examining each 8 bit value as a bitmap.
This was just hard to understand and unnecessary, and was triggering undefined behavior sanitizers with unaligned accesses within bitmap fields (on our internal tools/builds). Since the @ptype being passed in was already declared as a bitmap, refactor this to use native types with the advantage of simplifying the code to use a single loop.

Quoted 6 lines

---

.../net/ethernet/intel/ice/ice_flex_pipe.h    |  7 +-
.../net/ethernet/intel/ice/ice_flex_pipe.c    | 78 +++++++------------
drivers/net/ethernet/intel/ice/ice_flow.c     |  4 +-
3 files changed, 34 insertions(+), 55 deletions(-)