]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ice: convert ice_add_prof() to bitmap
authorJesse Brandeburg <jesse.brandeburg@intel.com>
Wed, 18 Jun 2025 11:28:53 +0000 (13:28 +0200)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Fri, 18 Jul 2025 16:02:28 +0000 (09:02 -0700)
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.

Co-developed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
CC: Jesse Brandeburg <jbrandeburg@cloudflare.com>
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Tested-by: Rinitha S <sx.rinitha@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_flex_pipe.c
drivers/net/ethernet/intel/ice/ice_flex_pipe.h
drivers/net/ethernet/intel/ice/ice_flow.c

index ed95072ca6e3168833844ff4db245b0947c4bf34..363ae79a3620cdf8126a9a431208eee93ac7dda6 100644 (file)
@@ -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);
index 28b0897adf32f00283a1d89729c3b97c6e05f17a..ee5d9f9c9d53a17c97082be5f4393f096dc77c76 100644 (file)
@@ -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
index 278e576862740e150c49c8b0d0897fd1f777b62d..6d5c939dc8a515c252cd2b77d155b69fa264ee92 100644 (file)
@@ -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)