octeontx2-af: npc: Enhancements.
Subsystems (6)
Ratheesh Kannoth
maintainerv3 cover octeontx2-af: npc: Enhancements.
This series adds features in NPC HW block in the OcteonTX2 AF driver for better observability, configuration, and resource management.
Patch 1 adds debugfs enhancements for CN20K: mcam_layout now shows enabled/disabled state per MCAM entry; a new "dstats" entry reports hit counts with delta semantics; and "mismatch" lists entries that are enabled but not explicitly allocated.
Patch 2 (from Saeed) extends devlink with DEVLINK_PARAM_TYPE_U32_ARRAY so params can accept multiple u32 values in a single value. This is used by patch 3 for subbank search order.
Patch 3 adds a devlink parameter "srch_order" for CN20K to control the order in which NPC subbanks are searched during MCAM allocation, allowing users to tune rule priority without firmware changes.
Patch 4 ties default MCAM entries (broadcast, multicast, promisc, ucast) to NIX LF lifetime: they are allocated when a NIX LF is allocated and freed when it is released, improving MCAM utilization. NIX_LF_DONT_FREE_DFT_IDXS lets the kernel PF retain default entries across suspend/resume.
Patch 5 allows loading a custom KPU profile from the filesystem via a module parameter (kpu_profile=), avoiding firmware flashes for profile updates.
Ratheesh Kannoth (4):
octeontx2-af: npc: cn20k: debugfs enhancements
octeontx2-af: npc: cn20k: Add devlink support for search order
octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM
entries
octeontx2-af: Add support for loading custom KPU profile from
filesystem
Saeed Mahameed (1):
devlink: Implement devlink param multi attribute nested data values
Documentation/netlink/specs/devlink.yaml | 4 + .../marvell/octeontx2/af/cn20k/debugfs.c | 120 +++++++- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 192 ++++++++++--- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 9 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 1 + .../net/ethernet/marvell/octeontx2/af/npc.h | 14 + .../net/ethernet/marvell/octeontx2/af/rvu.h | 3 +- .../marvell/octeontx2/af/rvu_devlink.c | 88 +++++- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 14 + .../ethernet/marvell/octeontx2/af/rvu_npc.c | 269 ++++++++++++++---- .../ethernet/marvell/octeontx2/af/rvu_reg.h | 1 + .../marvell/octeontx2/nic/otx2_pf.c | 6 +- include/net/devlink.h | 8 + include/uapi/linux/devlink.h | 1 + net/devlink/netlink_gen.c | 2 + net/devlink/param.c | 78 +++-- 16 files changed, 674 insertions(+), 136 deletions(-)
--
v2 -> v3: Addressed Simon comments.
https://lore.kernel.org/netdev/[email protected]/ v1 -> v2: Addressed Jakub comments. https://lore.kernel.org/netdev/[email protected]/#t
2.43.0
Ratheesh Kannoth
maintainerPATCH v3 1/5 octeontx2-af: npc: cn20k: debugfs enhancements
Improve MCAM visibility and field debugging for CN20K NPC.
- Extend "mcam_layout" to show enabled (+) or disabled state per entry so status can be verified without parsing the full "mcam_entry" dump.
- Add "dstats" debugfs entry: reports recently hit MCAM indices with packet counts; stats are cleared on read so each read shows deltas.
- Add "mismatch" debugfs entry: lists MCAM entries that are enabled but not explicitly allocated, helping diagnose allocation/field issues.
--- .../marvell/octeontx2/af/cn20k/debugfs.c | 126 +++++++++++++++++- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 16 ++- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 7 + 3 files changed, 135 insertions(+), 14 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c +119 -7
@@ -13,6 +13,7 @@#include "struct.h" #include "rvu.h" #include "debugfs.h" +#include "cn20k/reg.h" #include "cn20k/npc.h" static int npc_mcam_layout_show (struct seq_file *s,void *unused)
@@ -58,7 +59,8 @@ static int npc_mcam_layout_show(struct seq_file *s, void *unused) "v:%u", vidx0); } -seq_printf (s,"\t%u(%#x) %s\n" , idx0, pf1, +seq_printf (s,"\t%u(%#x)%c %s\n" , idx0, pf1, +test_bit (idx0, npc_priv->en_map) ?'+' :' ' , map ? buf0 :" " ); } goto next;
@@ -101,9 +103,13 @@ static int npc_mcam_layout_show(struct seq_file *s, void *unused) vidx1); } -seq_printf (s,"%05u(%#x) %s\t\t%05u(%#x) %s\n" , - idx1, pf2, v1 ? buf1 :" " , - idx0, pf1, v0 ? buf0 :" " ); +seq_printf (s,"%05u(%#x)%c %s\t\t%05u(%#x)%c %s\n" , + idx1, pf2, +test_bit (idx1, npc_priv->en_map) ?'+' :' ' , + v1 ? buf1 :" " , + idx0, pf1, +test_bit (idx0, npc_priv->en_map) ?'+' :' ' , + v0 ? buf0 :" " );continue ; }
@@ -120,8 +126,9 @@ static int npc_mcam_layout_show(struct seq_file *s, void *unused) vidx0); } -seq_printf (s,"\t\t \t\t%05u(%#x) %s\n" , idx0, - pf1, map ? buf0 :" " ); +seq_printf (s,"\t\t \t\t%05u(%#x)%c %s\n" , idx0, pf1, +test_bit (idx0, npc_priv->en_map) ?'+' :' ' , + map ? buf0 :" " );continue ; }
@@ -134,7 +141,8 @@ static int npc_mcam_layout_show(struct seq_file *s, void *unused)snprintf (buf1,sizeof (buf1),"v:%05u" , vidx1); } -seq_printf (s,"%05u(%#x) %s\n" , idx1, pf1, +seq_printf (s,"%05u(%#x)%c %s\n" , idx1, pf1, +test_bit (idx1, npc_priv->en_map) ?'+' :' ' , map ? buf1 :" " ); } next:
@@ -145,6 +153,100 @@ static int npc_mcam_layout_show(struct seq_file *s, void *unused)DEFINE_SHOW_ATTRIBUTE (npc_mcam_layout); +static u64 dstats[MAX_NUM_BANKS ][MAX_SUBBANK_DEPTH *MAX_NUM_SUB_BANKS ] = {}; +static int npc_mcam_dstats_show (struct seq_file *s,void *unused) +{ +struct npc_priv_t *npc_priv; +int blkaddr, pf, mcam_idx; +u64 stats, delta; +struct rvu *rvu; +u8 key_type; +void *map; + + npc_priv =npc_priv_get (); + rvu = s->private; + blkaddr =rvu_get_blkaddr (rvu,BLKTYPE_NPC ,0 ); +if (blkaddr <0 ) +return 0 ; + +seq_puts (s,"idx\tpfunc\tstats\n" ); +for (int bank = npc_priv->num_banks -1 ; bank >=0 ; bank--) { +for (int idx = npc_priv->bank_depth -1 ; idx >=0 ; idx--) { + mcam_idx = bank * npc_priv->bank_depth + idx; + +npc_mcam_idx_2_key_type (rvu, mcam_idx, &key_type); +if (key_type ==NPC_MCAM_KEY_X4 && bank !=0 ) +continue ; + +if (!test_bit (mcam_idx, npc_priv->en_map)) +continue ; + + stats =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_STAT_EXT (idx, bank)); +if (!stats) +continue ; +if (stats == dstats[bank][idx]) +continue ; + +if (stats < dstats[bank][idx]) + dstats[bank][idx] =0 ; + + pf =0xFFFF ; + map =xa_load (&npc_priv->xa_idx2pf_map, mcam_idx); +if (map) + pf =xa_to_value (map); + +if (stats > dstats[bank][idx]) + delta = stats - dstats[bank][idx]; +else + delta = stats; + +seq_printf (s,"%u\t%#04x\t%llu\n" , + mcam_idx, pf, delta); + dstats[bank][idx] = stats; + } + } +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (npc_mcam_dstats); + +static int npc_mcam_mismatch_show (struct seq_file *s,void *unused) +{ +struct npc_priv_t *npc_priv; +struct npc_subbank *sb; +int mcam_idx, sb_off; +struct rvu *rvu; +void *map; +int rc; + + npc_priv =npc_priv_get (); + rvu = s->private; + +seq_puts (s,"index\tsb idx\tkw type\n" ); +for (int bank = npc_priv->num_banks -1 ; bank >=0 ; bank--) { +for (int idx = npc_priv->bank_depth -1 ; idx >=0 ; idx--) { + mcam_idx = bank * npc_priv->bank_depth + idx; + +if (!test_bit (mcam_idx, npc_priv->en_map)) +continue ; + + map =xa_load (&npc_priv->xa_idx2pf_map, mcam_idx); +if (map) +continue ; + + rc =npc_mcam_idx_2_subbank_idx (rvu, mcam_idx, + &sb, &sb_off); +if (rc) +continue ; + +seq_printf (s,"%u\t%d\t%u\n" , mcam_idx, sb->idx, + sb->key_type); + } + } +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (npc_mcam_mismatch); +static int npc_mcam_default_show (struct seq_file *s,void *unused) {struct npc_priv_t *npc_priv;
@@ -257,6 +359,16 @@ int npc_cn20k_debugfs_init(struct rvu *rvu)if (!npc_dentry)return -EFAULT ; + npc_dentry =debugfs_create_file ("dstats" ,0444 , rvu->rvu_dbg.npc, rvu, + &npc_mcam_dstats_fops); +if (!npc_dentry) +return -EFAULT ; + + npc_dentry =debugfs_create_file ("mismatch" ,0444 , rvu->rvu_dbg.npc, rvu, + &npc_mcam_mismatch_fops); +if (!npc_dentry) +return -EFAULT ; + npc_dentry =debugfs_create_file ("mcam_default" ,0444 , rvu->rvu_dbg.npc, rvu, &npc_mcam_default_fops);
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +9 -7
@@ -808,6 +808,9 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,u64 cfg, hw_prio;u8 kw_type; + enable ?set_bit (index, npc_priv.en_map) : +clear_bit (index, npc_priv.en_map); +npc_mcam_idx_2_key_type (rvu, index, &kw_type);if (kw_type ==NPC_MCAM_KEY_X2 ) { cfg = rvu_read64(rvu, blkaddr,
@@ -1016,14 +1019,12 @@ static void npc_cn20k_config_kw_x4(struct rvu *rvu, struct npc_mcam *mcam,static void npc_cn20k_set_mcam_bank_cfg (struct rvu *rvu,int blkaddr,int mcam_idx, -int bank,u8 kw_type,bool enable,u8 hw_prio) +int bank,u8 kw_type,u8 hw_prio) {struct npc_mcam *mcam = &rvu->hw->mcam;u64 bank_cfg; bank_cfg = (u64 )hw_prio <<24 ; -if (enable) - bank_cfg |=0x1 ;if (kw_type ==NPC_MCAM_KEY_X2 ) { rvu_write64(rvu, blkaddr,
@@ -1119,7 +1120,8 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,/* TODO: */ /* PF installing VF rule */ npc_cn20k_set_mcam_bank_cfg (rvu, blkaddr, mcam_idx, bank, - kw_type, enable, hw_prio); + kw_type, hw_prio); +npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, enable); }void npc_cn20k_copy_mcam_entry (struct rvu *rvu,int blkaddr,u16 src,u16 dest)
@@ -1735,9 +1737,9 @@ static int npc_subbank_idx_2_mcam_idx(struct rvu *rvu, struct npc_subbank *sb,return 0 ; } -static int npc_mcam_idx_2_subbank_idx (struct rvu *rvu,u16 mcam_idx, -struct npc_subbank **sb, -int *sb_off) +int npc_mcam_idx_2_subbank_idx (struct rvu *rvu,u16 mcam_idx, +struct npc_subbank **sb, +int *sb_off) {int bank_off, sb_id;
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +7 -0
@@ -170,6 +170,7 @@ struct npc_defrag_show_node {* @num_banks: Number of banks. * @num_subbanks: Number of subbanks. * @subbank_depth: Depth of subbank. +* @en_map: Enable/disable status. * @kw: Kex configured key type. * @sb: Subbank array. * @xa_sb_used: Array of used subbanks.
@@ -193,6 +194,9 @@ struct npc_priv_t {const int num_banks;int num_subbanks;int subbank_depth; +DECLARE_BITMAP (en_map,MAX_NUM_BANKS * +MAX_NUM_SUB_BANKS * +MAX_SUBBANK_DEPTH );u8 kw;struct npc_subbank *sb;struct xarray xa_sb_used;
@@ -336,5 +340,8 @@ int npc_mcam_idx_2_key_type(struct rvu *rvu, u16 mcam_idx, u8 *key_type);u16 npc_cn20k_vidx2idx (u16 index);u16 npc_cn20k_idx2vidx (u16 idx);int npc_cn20k_defrag (struct rvu *rvu); +int npc_mcam_idx_2_subbank_idx (struct rvu *rvu,u16 mcam_idx, +struct npc_subbank **sb, +int *sb_off);#endif /* NPC_CN20K_H */
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v3 2/5 devlink: Implement devlink param multi attribute nested data values
In reply to Ratheesh KannothFrom: Saeed Mahameed <[email protected]>
Devlink param value attribute is not defined since devlink is handling the value validating and parsing internally, this allows us to implement multi attribute values without breaking any policies.
Devlink param multi-attribute values are considered to be dynamically sized arrays of u32 values, by introducing a new devlink param type DEVLINK_PARAM_TYPE_U32_ARRAY, driver and user space can set a variable count of u32 values into the DEVLINK_ATTR_PARAM_VALUE_DATA attribute.
Implement get/set parsing and add to the internal value structure passed to drivers.
This is useful for devices that need to configure a list of values for a specific configuration.
example:
$ devlink dev param show pci/... name multi-value-param name multi-value-param type driver-specific values: cmode permanent value: 0,1,2,3,4,5,6,7
$ devlink dev param set pci/... name multi-value-param \ value 4,5,6,7,0,1,2,3 cmode permanent
--- Documentation/netlink/specs/devlink.yaml | 4 ++ include/net/devlink.h | 8 +++ include/uapi/linux/devlink.h | 1 + net/devlink/netlink_gen.c | 2 + net/devlink/param.c | 81 ++++++++++++++++++------ 5 files changed, 78 insertions(+), 18 deletions(-)
Documentation/netlink/specs/devlink.yaml +4 -0
@@ -226,6 +226,10 @@ definitions: value: 10 - name: binary + - + name: u32-array + value: 129 + - name: rate-tc-index-max type: const
include/net/devlink.h +8 -0
@@ -432,6 +432,13 @@ enum devlink_param_type {DEVLINK_PARAM_TYPE_U64 =DEVLINK_VAR_ATTR_TYPE_U64 ,DEVLINK_PARAM_TYPE_STRING =DEVLINK_VAR_ATTR_TYPE_STRING ,DEVLINK_PARAM_TYPE_BOOL =DEVLINK_VAR_ATTR_TYPE_FLAG , + DEVLINK_PARAM_TYPE_U32_ARRAY = DEVLINK_VAR_ATTR_TYPE_U32_ARRAY, +}; + +#define __DEVLINK_PARAM_MAX_ARRAY_SIZE 32 +struct devlink_param_u32_array { +u32 size; +u32 val[__DEVLINK_PARAM_MAX_ARRAY_SIZE]; }; union devlink_param_value {
@@ -441,6 +448,7 @@ union devlink_param_value {u64 vu64;char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];bool vbool; +struct devlink_param_u32_array u32arr; };struct devlink_param_gset_ctx {
include/uapi/linux/devlink.h +1 -0
@@ -404,6 +404,7 @@ enum devlink_var_attr_type {DEVLINK_VAR_ATTR_TYPE_BINARY , __DEVLINK_VAR_ATTR_TYPE_CUSTOM_BASE =0x80 ,/* Any possible custom types, unrelated to NLA_* values go below */ + DEVLINK_VAR_ATTR_TYPE_U32_ARRAY, }; enum devlink_attr {
net/devlink/netlink_gen.c +2 -0
@@ -32,6 +32,8 @@ devlink_attr_param_type_validate(const struct nlattr *attr,case DEVLINK_VAR_ATTR_TYPE_NUL_STRING : fallthrough;case DEVLINK_VAR_ATTR_TYPE_BINARY : + fallthrough; +case DEVLINK_VAR_ATTR_TYPE_U32_ARRAY :return 0 ; }NL_SET_ERR_MSG_ATTR (extack, attr,"invalid enum value" );
net/devlink/param.c +63 -18
155 lines not on this page · raw message
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v3 3/5 octeontx2-af: npc: cn20k: add subbank search order control
In reply to Ratheesh KannothCN20K NPC MCAM is split into 32 subbanks that are searched in a predefined order during allocation. Lower-numbered subbanks have higher priority than higher-numbered ones.
Add a runtime devlink parameter "srch_order" ( DEVLINK_PARAM_TYPE_U32_ARRAY) to control the order in which subbanks are searched during MCAM allocation.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 87 ++++++++++++++++++ .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 2 + .../marvell/octeontx2/af/rvu_devlink.c | 92 +++++++++++++++++-- 3 files changed, 171 insertions(+), 10 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +87 -0
@@ -3809,6 +3809,93 @@ static void npc_unlock_all_subbank(void)mutex_unlock (&npc_priv.sb[i].lock); } +int npc_cn20k_search_order_set (struct rvu *rvu, +u32 arr[MAX_NUM_SUB_BANKS ],int cnt) +{ +struct npc_mcam *mcam = &rvu->hw->mcam; +u32 fslots[MAX_NUM_SUB_BANKS ][2 ]; +u32 uslots[MAX_NUM_SUB_BANKS ][2 ]; +int fcnt =0 , ucnt =0 ; +struct npc_subbank *sb; +int idx, val, rc =0 ; + +unsigned long index; +void *v; + +if (cnt != npc_priv.num_subbanks) { +dev_err (rvu->dev,"Number of entries(%u) != %u\n" , + cnt, npc_priv.num_subbanks); +return -EINVAL ; + } + +mutex_lock (&mcam->lock); +npc_lock_all_subbank (); + restrict_valid = false; + +for (int i =0 ; i < cnt; i++) + subbank_srch_order[i] = arr[i]; + +xa_for_each (&npc_priv.xa_sb_used, index, v) { + val =xa_to_value (v); + uslots[ucnt][0 ] = index; + uslots[ucnt][1 ] = val; +xa_erase (&npc_priv.xa_sb_used, index); + ucnt++; + } + +xa_for_each (&npc_priv.xa_sb_free, index, v) { + val =xa_to_value (v); + fslots[fcnt][0 ] = index; + fslots[fcnt][1 ] = val; +xa_erase (&npc_priv.xa_sb_free, index); + fcnt++; + } + +/* xa_store() is done under lock. If xa_store fails +* ,no rollback is planned as it might also fail. +*/ +for (int i =0 ; i < ucnt; i++) { + idx = uslots[i][1 ]; + sb = &npc_priv.sb[idx]; + sb->arr_idx = subbank_srch_order[sb->idx]; + rc =xa_err (xa_store (&npc_priv.xa_sb_used, sb->arr_idx, +xa_mk_value (sb->idx),GFP_KERNEL )); +if (rc) { +dev_err (rvu->dev, +"Error to insert index to used list %u\n" , + sb->idx); + goto fail_used; + } + } + +for (int i =0 ; i < fcnt; i++) { + idx = fslots[i][1 ]; + sb = &npc_priv.sb[idx]; + sb->arr_idx = subbank_srch_order[sb->idx]; + rc =xa_err (xa_store (&npc_priv.xa_sb_free, sb->arr_idx, +xa_mk_value (sb->idx),GFP_KERNEL )); +if (rc) { +dev_err (rvu->dev, +"Error to insert index to free list %u\n" , + sb->idx); + goto fail_used; + } + } + +fail_used: +npc_unlock_all_subbank (); +mutex_unlock (&mcam->lock); + +return rc; +} + +const u32 *npc_cn20k_search_order_get (bool *restricted_order,u32 *sz) +{ + *restricted_order = restrict_valid; + *sz = npc_priv.num_subbanks; +return subbank_srch_order; +} +/* Only non-ref non-contigous mcam indexes * are picked for defrag process */
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +2 -0
@@ -343,5 +343,7 @@ int npc_cn20k_defrag(struct rvu *rvu);int npc_mcam_idx_2_subbank_idx (struct rvu *rvu,u16 mcam_idx,struct npc_subbank **sb,int *sb_off); +const u32 *npc_cn20k_search_order_get (bool *restricted_order,u32 *sz); +int npc_cn20k_search_order_set (struct rvu *rvu,u32 arr[32 ],int cnt);#endif /* NPC_CN20K_H */
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c +82 -10
131 lines not on this page · raw message
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v3 4/5 octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries
In reply to Ratheesh KannothImprove MCAM utilization by tying default (broadcast, multicast, promisc, ucast) entry lifetime to NIX LF usage.
- On NIX LF alloc (e.g. kernel or DPDK), allocate default MCAM entries if missing; on NIX LF free, release them so they return to the pool.
- Add NIX_LF_DONT_FREE_DFT_IDXS so the kernel PF driver can free the NIX LF without releasing default entries (e.g. across suspend/resume).
- When NIX LF is used by DPDK, default entries are allocated on first use and freed when the LF is released if NIX_LF_DONT_FREE_DFT_IDXS is not set
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 108 +++++++++++---- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 1 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 1 + .../ethernet/marvell/octeontx2/af/rvu_nix.c | 16 ++- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 128 +++++++++++++----- .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 6 +- 6 files changed, 191 insertions(+), 69 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +78 -30
@@ -808,6 +808,11 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,u64 cfg, hw_prio;u8 kw_type; +if (index <0 || index >= mcam->total_entries) { +WARN (1 ,"Wrong mcam index %d\n" , index); +return ; + } + enable ?set_bit (index, npc_priv.en_map) :clear_bit (index, npc_priv.en_map);
@@ -1053,6 +1058,11 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,int kw =0 ;u8 kw_type; +if (index <0 || index >= mcam->total_entries) { +WARN (1 ,"Wrong mcam index %d\n" , index); +return ; + } +/* Disable before mcam entry update */ npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, false);
@@ -1132,6 +1142,11 @@ void npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blkaddr, u16 src, u16 dest)int bank, i, sb, db;int dbank, sbank; +if (src >= mcam->total_entries || dest >= mcam->total_entries) { +WARN (1 ,"Wrong mcam index src=%u dest=%u\n" , src, dest); +return ; + } + dbank =npc_get_bank (mcam, dest); sbank =npc_get_bank (mcam, src);npc_mcam_idx_2_key_type (rvu, src, &src_kwtype);
@@ -1190,11 +1205,24 @@ void npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index,int kw =0 , bank;u8 kw_type; +if (index >= mcam->total_entries) { +WARN (1 ,"Wrong mcam index %u\n" , index); +return ; + } +npc_mcam_idx_2_key_type (rvu, index, &kw_type); bank =npc_get_bank (mcam, index); index &= (mcam->banksize -1 ); + cfg =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index, bank,0 )); + entry->action = cfg; + + cfg =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index, bank,1 )); + entry->vtag_action = cfg; + cfg =rvu_read64 (rvu, blkaddr,NPC_AF_CN20K_MCAMEX_BANKX_CAMX_INTF_EXT (index, bank,1 )) &3 ;
@@ -1244,7 +1272,7 @@ void npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index, bank, 0));npc_cn20k_fill_entryword (entry, kw +3 , cam0, cam1); - goto read_action; +return ; }for (bank =0 ; bank < mcam->banks_per_entry; bank++, kw = kw +4 ) {
@@ -1289,17 +1317,6 @@ void npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index,npc_cn20k_fill_entryword (entry, kw +3 , cam0, cam1); } -read_action: -/* 'action' is set to same value for both bank '0' and '1'. -* Hence, reading bank '0' should be enough. -*/ - cfg =rvu_read64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index,0 ,0 )); - entry->action = cfg; - - cfg =rvu_read64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index,0 ,1 )); - entry->vtag_action = cfg; } int rvu_mbox_handler_npc_cn20k_mcam_write_entry(struct rvu *rvu,
@@ -1671,8 +1688,8 @@ int npc_mcam_idx_2_key_type(struct rvu *rvu, u16 mcam_idx, u8 *key_type)/* mcam_idx should be less than (2 * bank depth) */ if (mcam_idx >= npc_priv.bank_depth *2 ) { -dev_err (rvu->dev,"%s: bad params\n" , - __func__); +dev_err (rvu->dev,"%s: bad params mcam_idx=%u\n" , + __func__, mcam_idx);return -EINVAL ; }
@@ -4024,6 +4041,13 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast,void *val;int i, j; +for (int i =0 ; i <ARRAY_SIZE (ptr); i++) { +if (!ptr[i]) +continue ; + + *ptr[i] =USHRT_MAX ; + } +if (!npc_priv.init_done)return 0 ;
@@ -4039,7 +4063,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, npc_dft_rule_name[NPC_DFT_RULE_PROMISC_ID ], pcifunc); - *ptr[0 ] =USHRT_MAX ;return -ESRCH ; }
@@ -4059,7 +4082,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, npc_dft_rule_name[NPC_DFT_RULE_UCAST_ID ], pcifunc); - *ptr[3 ] =USHRT_MAX ;return -ESRCH ; }
@@ -4079,7 +4101,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, __func__, npc_dft_rule_name[i], pcifunc); - *ptr[j] =USHRT_MAX ;continue ; }
@@ -4174,7 +4195,7 @@ int rvu_mbox_handler_npc_get_dft_rl_idxs(struct rvu *rvu, struct msg_req *req,return 0 ; } -static bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc) +bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc) {return is_pf_cgxmapped (rvu,rvu_get_pf (rvu->pdev, pcifunc)) ||is_lbk_vf (rvu, pcifunc);
@@ -4182,9 +4203,10 @@ static bool npc_is_cgx_or_lbk(struct rvu *rvu, u16 pcifunc)void npc_cn20k_dft_rules_free (struct rvu *rvu,u16 pcifunc) { -struct npc_mcam_free_entry_req free_req = {0 }; +struct npc_mcam *mcam = &rvu->hw->mcam; +struct rvu_npc_mcam_rule *rule, *tmp;unsigned long index; -struct msg_rsp rsp; +int blkaddr;u16 ptr[4 ];int rc, i;void *map;
@@ -4209,7 +4231,7 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) index =NPC_DFT_RULE_ID_MK (pcifunc,NPC_DFT_RULE_PROMISC_ID ); map =xa_erase (&npc_priv.xa_pf2dfl_rmap, index);if (!map) - dev_dbg(rvu->dev, + dev_err(rvu->dev, "%s: Err from delete %s mcam idx from xarray (pcifunc=%#x\n", __func__, npc_dft_rule_name[NPC_DFT_RULE_PROMISC_ID],
@@ -4223,7 +4245,7 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) index =NPC_DFT_RULE_ID_MK (pcifunc,NPC_DFT_RULE_UCAST_ID ); map =xa_erase (&npc_priv.xa_pf2dfl_rmap, index);if (!map) - dev_dbg(rvu->dev, + dev_err(rvu->dev, "%s: Err from delete %s mcam idx from xarray (pcifunc=%#x\n", __func__, npc_dft_rule_name[NPC_DFT_RULE_UCAST_ID],
@@ -4237,21 +4259,47 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) index =NPC_DFT_RULE_ID_MK (pcifunc, i); map =xa_erase (&npc_priv.xa_pf2dfl_rmap, index);if (!map) -dev_dbg (rvu->dev, +dev_err (rvu->dev,"%s: Err from delete %s mcam idx from xarray (pcifunc=%#x\n" , __func__, npc_dft_rule_name[i], pcifunc); } free_rules: + blkaddr =rvu_get_blkaddr (rvu,BLKTYPE_NPC ,0 ); +if (blkaddr <0 ) +return ; - free_req.hdr.pcifunc = pcifunc; - free_req.all =1 ; - rc =rvu_mbox_handler_npc_mcam_free_entry (rvu, &free_req, &rsp); -if (rc) -dev_err (rvu->dev, -"%s: Error deleting default entries (pcifunc=%#x\n" , - __func__, pcifunc); +for (int i =0 ; i <4 ; i++) { +if (ptr[i] ==USHRT_MAX ) +continue ; + +mutex_lock (&mcam->lock); +npc_mcam_clear_bit (mcam, ptr[i]); + mcam->entry2pfvf_map[ptr[i]] =NPC_MCAM_INVALID_MAP ; +npc_cn20k_enable_mcam_entry (rvu, blkaddr, ptr[i], false); + mcam->entry2target_pffunc[ptr[i]] =0x0 ; +mutex_unlock (&mcam->lock); + + rc =npc_cn20k_idx_free (rvu, &ptr[i],1 ); +if (rc) +dev_err (rvu->dev, +"%s:%d Error deleting default entries (pcifunc=%#x) mcam_idx=%u\n" , + __func__, __LINE__, pcifunc, ptr[i]); + } + +mutex_lock (&mcam->lock); +list_for_each_entry_safe (rule, tmp, &mcam->mcam_rules, list) { +for (int i =0 ; i <4 ; i++) { +if (ptr[i] != rule->entry) +continue ; + +list_del (&rule->list); +kfree (rule); +break ; + } + } +mutex_unlock (&mcam->lock); }int npc_cn20k_dft_rules_alloc (struct rvu *rvu,u16 pcifunc)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +1 -0
@@ -345,5 +345,6 @@ int npc_mcam_idx_2_subbank_idx(struct rvu *rvu, u16 mcam_idx, int *sb_off);const u32 *npc_cn20k_search_order_get (bool *restricted_order,u32 *sz);int npc_cn20k_search_order_set (struct rvu *rvu,u32 arr[32 ],int cnt); +bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc);#endif /* NPC_CN20K_H */
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +1 -0
@@ -1009,6 +1009,7 @@ struct nix_lf_free_req {struct mbox_msghdr hdr;#define NIX_LF_DISABLE_FLOWS BIT_ULL(0)#define NIX_LF_DONT_FREE_TX_VTAG BIT_ULL(1) +#define NIX_LF_DONT_FREE_DFT_IDXS BIT_ULL(2)u64 flags; };
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +15 -1
@@ -16,6 +16,7 @@#include "cgx.h" #include "lmac_common.h" #include "rvu_npc_hash.h" +#include "cn20k/npc.h" static void nix_free_tx_vtag_entries (struct rvu *rvu,u16 pcifunc); static int rvu_nix_get_bpid(struct rvu *rvu, struct nix_bp_cfg_req *req,
@@ -1684,10 +1685,16 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu,if (is_sdp_pfvf (rvu, pcifunc)) intf =NIX_INTF_TYPE_SDP ; +if (is_cn20k (rvu->pdev)) { + rc =npc_cn20k_dft_rules_alloc (rvu, pcifunc); +if (rc) + goto free_mem; + } + err =nix_interface_init (rvu, pcifunc, intf, nixlf, rsp, !!(req->flags &NIX_LF_LBK_BLK_SEL ));if (err) - goto free_mem; + goto free_dft;/* Disable NPC entries as NIXLF's contexts are not initialized yet */ rvu_npc_disable_default_entries (rvu, pcifunc, nixlf);
@@ -1699,6 +1706,10 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu, goto exit; +free_dft: +if (is_cn20k (rvu->pdev)) +npc_cn20k_dft_rules_free (rvu, pcifunc); + free_mem:nix_ctx_free (rvu, pfvf); rc = -ENOMEM ;
@@ -1775,6 +1786,9 @@ int rvu_mbox_handler_nix_lf_free(struct rvu *rvu, struct nix_lf_free_req *req,nix_ctx_free (rvu, pfvf); +if (is_cn20k (rvu->pdev) && !(req->flags &NIX_LF_DONT_FREE_DFT_IDXS )) +npc_cn20k_dft_rules_free (rvu, pcifunc); +return 0 ; }
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +94 -34
237 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +2 -4
@@ -1053,7 +1053,6 @@ irqreturn_t otx2_pfaf_mbox_intr_handler(int irq, void *pf_irq)/* Clear the IRQ */ otx2_write64 (pf,RVU_PF_INT ,BIT_ULL (0 )); - mbox_data =otx2_read64 (pf,RVU_PF_PFAF_MBOX0 );if (mbox_data &MBOX_UP_MSG ) {
@@ -1729,7 +1728,7 @@ int otx2_init_hw_resources(struct otx2_nic *pf)mutex_lock (&mbox->lock); free_req =otx2_mbox_alloc_msg_nix_lf_free (mbox);if (free_req) { - free_req->flags =NIX_LF_DISABLE_FLOWS ; + free_req->flags =NIX_LF_DISABLE_FLOWS |NIX_LF_DONT_FREE_DFT_IDXS ;if (otx2_sync_mbox_msg (mbox))dev_err (pf->dev,"%s failed to free nixlf\n" , __func__); }
@@ -1803,7 +1802,7 @@ void otx2_free_hw_resources(struct otx2_nic *pf)/* Reset NIX LF */ free_req =otx2_mbox_alloc_msg_nix_lf_free (mbox);if (free_req) { - free_req->flags =NIX_LF_DISABLE_FLOWS ; + free_req->flags =NIX_LF_DISABLE_FLOWS |NIX_LF_DONT_FREE_DFT_IDXS ;if (!(pf->flags &OTX2_FLAG_PF_SHUTDOWN )) free_req->flags |=NIX_LF_DONT_FREE_TX_VTAG ;if (otx2_sync_mbox_msg (mbox))
@@ -1926,7 +1925,6 @@ int otx2_alloc_queue_mem(struct otx2_nic *pf)struct otx2_qset *qset = &pf->qset;struct otx2_cq_poll *cq_poll; -/* RQ and SQs are mapped to different CQs, * so find out max CQ IRQs (i.e CINTs) needed. */
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v3 5/5 octeontx2-af: Add support for loading custom KPU profile from filesystem
In reply to Ratheesh KannothFlashing updated firmware on deployed devices is cumbersome. Provide a mechanism to load a custom KPU (Key Parse Unit) profile directly from the filesystem at module load time.
When the rvu_af module is loaded with the kpu_profile parameter, the specified profile is read from /lib/firmware/kpu and programmed into the KPU registers. Add npc_kpu_profile_cam2 for the extended cam format used by filesystem-loaded profiles and support ptype/ptype_mask in npc_config_kpucam when profile->from_fs is set.
Usage:
1. Copy the KPU profile file to /lib/firmware/kpu.
2. Build OCTEONTX2_AF as a module.
3. Load: insmod rvu_af.ko kpu_profile=<profile_name>
--- .../net/ethernet/marvell/octeontx2/af/npc.h | 14 ++ .../net/ethernet/marvell/octeontx2/af/rvu.h | 5 +- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 180 +++++++++++++++--- .../ethernet/marvell/octeontx2/af/rvu_reg.h | 1 + 4 files changed, 169 insertions(+), 31 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/npc.h +14 -0
@@ -265,6 +265,19 @@ struct npc_kpu_profile_cam {u16 dp2_mask; } __packed; +struct npc_kpu_profile_cam2 { +u8 state; +u8 state_mask; +u16 dp0; +u16 dp0_mask; +u16 dp1; +u16 dp1_mask; +u16 dp2; +u16 dp2_mask; +u8 ptype; +u8 ptype_mask; +} __packed; +struct npc_kpu_profile_action {u8 errlev;u8 errcode;
@@ -290,6 +303,7 @@ struct npc_kpu_profile {int action_entries;struct npc_kpu_profile_cam *cam;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_cam2 *cam2; };/* NPC KPU register formats */
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +3 -2
@@ -553,8 +553,8 @@ struct npc_kpu_profile_adapter {const char *name;u64 version;const struct npc_lt_def_cfg *lt_def; -const struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ -const struct npc_kpu_profile *kpu;/* array[kpus] */ +struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ +struct npc_kpu_profile *kpu;/* array[kpus] */ union npc_mcam_key_prfl {struct npc_mcam_kex *mkex;/* used for cn9k and cn10k */
@@ -564,6 +564,7 @@ struct npc_kpu_profile_adapter {bool custom;size_t pkinds;size_t kpus; +bool from_fs; };#define RVU_SWITCH_LBK_CHAN 63
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +151 -29
294 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_reg.h +1 -0
@@ -596,6 +596,7 @@#define NPC_AF_INTFX_KEX_CFG (a) (0x01010 | (a) << 8)#define NPC_AF_PKINDX_ACTION0 (a) (0x80000ull | (a) << 6)#define NPC_AF_PKINDX_ACTION1 (a) (0x80008ull | (a) << 6) +#define NPC_AF_PKINDX_TYPE (a) (0x80010ull | (a) << 6)#define NPC_AF_PKINDX_CPI_DEFX (a, b) (0x80020ull | (a) << 6 | (b) << 3)#define NPC_AF_KPUX_ENTRYX_CAMX (a, b, c) \ (0x100000 | (a) << 14 | (b) << 6 | (c) << 3)
Signature · 1 line
2.43.0
Simon Horman
reviewerRe: [v3,net-next,5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
octeontx2-af: Add support for loading custom KPU profile from filesystem
This commit adds functionality to load custom KPU (Key Parse Unit) profiles from the filesystem at module load time, providing an alternative to flashing updated firmware on deployed devices.
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +1
-0@@ -290,6 +303,7 @@ struct npc_kpu_profile {int action_entries;struct npc_kpu_profile_cam *cam;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_cam2 *cam2; };
[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +2
-2@@ -553,8 +553,8 @@ struct npc_kpu_profile_adapter {const char *name;u64 version;const struct npc_lt_def_cfg *lt_def; -const struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ -const struct npc_kpu_profile *kpu;/* array[kpus] */ +struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ +struct npc_kpu_profile *kpu;/* array[kpus] */
[ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +1
-0@@ -564,6 +564,7 @@ struct npc_kpu_profile_adapter {bool custom;size_t pkinds;size_t kpus; +bool from_fs; };
[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0
[ ... ]
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1
-0@@ -1610,6 +1622,7 @@ u64 npc_enable_mask(int count)static void npc_program_kpu_profile (struct rvu *rvu,int blkaddr,int kpu,const struct npc_kpu_profile *profile) { +struct npc_kpu_profile_adapter *adapter = &rvu->kpu;int entry, num_entries, max_entries;u64 entry_mask;@@ -1621,10 +1634,15 @@ static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, max_entries = rvu->hw->npc_kpu_entries;
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, · line 1646
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +5
-0+WARN (profile->cam_entries > max_entries, +"KPU%u: err: hw max entries=%u, input entries=%u\n" , + kpu, rvu->hw->npc_kpu_entries, profile->cam_entries); +/* Program CAM match entries for previous KPU extracted data */ num_entries =min_t (int, profile->cam_entries, max_entries);for (entry =0 ; entry < num_entries; entry++)npc_config_kpucam (rvu, blkaddr, + adapter->from_fs ? (void *)&profile->cam2[entry] : &profile->cam[entry], kpu, entry);
Can this dereference NULL when from_fs is true for KPUs not covered by the filesystem firmware?
Looking at the filesystem loading path in npc_apply_custom_kpu:
for (kpu = 0; kpu < fw->kpus; kpu++) {
...
ret = npc_alloc_kpu_cam2_n_action(rvu, kpu, entries);
...
for (entry = 0; entry < entries; entry++) {
profile->kpu[kpu].cam2[entry] = cam2[entry];
...
}
}The code allocates cam2 and populates entries only for the first fw->kpus KPUs found in the firmware blob.
However, npc_program_kpu_profile is later called for all KPUs in npc_parser_profile_init:
for (idx = 0; idx < num_kpus; idx++)
npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);Since adapter->from_fs is a global flag (not per-KPU), when idx >= fw->kpus, profile->cam2 remains NULL (the default npc_kpu_profiles[] static initializer doesn't include cam2), causing &profile->cam2[entry] to compute an invalid pointer.
Shouldn't there be a check to verify cam2 is non-NULL before dereferencing it, or allocate cam2 for all KPUs when from_fs is true?
Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0/* Program this KPU's actions */
[ ... ]
Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +10
-0@@ -1678,26 +1696,50 @@ static void npc_prepare_default_kpu(struct rvu *rvu,npc_cn20k_update_action_entries_n_flags (rvu, profile); } +static int npc_alloc_kpu_cam2_n_action (struct rvu *rvu,int kpu_num, +int num_entries) +{ +struct npc_kpu_profile_adapter *adapter = &rvu->kpu; +struct npc_kpu_profile *kpu; + + kpu = &adapter->kpu[kpu_num]; + + kpu->cam2 =devm_kcalloc (rvu->dev, num_entries, +sizeof (*kpu->cam2),GFP_KERNEL );
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static void npc_prepare_default_kpu(struct rvu *rvu, · line 1718
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +10
-0+if (!kpu->cam2) +return -ENOMEM ; + + kpu->action =devm_kcalloc (rvu->dev, num_entries, +sizeof (*kpu->action),GFP_KERNEL ); +if (!kpu->action) +return -ENOMEM ; + +return 0 ; +}
Can this permanently corrupt the default profile when the second allocation fails?
The kpu pointer targets the static npc_kpu_profiles[] array (adapter->kpu starts as &npc_kpu_profiles[0]). When the first devm_kcalloc succeeds but the second fails:
kpu->cam2 = devm_kcalloc(...) // succeeds, modifies static array
kpu->action = devm_kcalloc(...) // fails
return -ENOMEM; // kpu->action is now NULL in static arrayThe caller in npc_apply_custom_kpu returns the error without restoring the original action pointer.
Later, npc_parser_profile_init calls npc_program_kpu_profile for all KPUs, which calls npc_config_kpuaction with &profile->action[entry] where action is NULL, causing a crash when dereferencing the NULL pointer.
Should the function restore the original pointers on allocation failure, or use a separate copy of the profile entries for filesystem loading?
Quoted 16 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +6
-2+static int npc_apply_custom_kpu (struct rvu *rvu, -struct npc_kpu_profile_adapter *profile) +struct npc_kpu_profile_adapter *profile, +bool from_fs) {size_t hdr_sz =sizeof (struct npc_kpu_profile_fwdata ), offset =0 ;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_fwdata *sfw;struct npc_kpu_profile_fwdata *fw; +struct npc_kpu_profile_cam2 *cam2;struct npc_kpu_profile_cam *cam;struct npc_kpu_fwdata *fw_kpu; -int entries; +int entries, ret;u16 kpu, entry;
[ ... ]
Quoted 82 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +55
-11@@ -1731,31 +1773,80 @@ static int npc_apply_custom_kpu(struct rvu *rvu,return -EINVAL ; } + sfw =devm_kcalloc (rvu->dev,1 ,sizeof (*sfw),GFP_KERNEL ); +if (!sfw) +return -ENOMEM ; + +memcpy (sfw, fw,sizeof (*sfw)); + profile->custom =1 ; - profile->name = fw->name; + profile->name = sfw->name; profile->version =le64_to_cpu (fw->version); - profile->mcam_kex_prfl.mkex = &fw->mkex; - profile->lt_def = &fw->lt_def; + profile->mcam_kex_prfl.mkex = &sfw->mkex; + profile->lt_def = &sfw->lt_def; + +/* Binary blob contains ikpu actions entries at start of data[0] */ +if (from_fs) { + action = (struct npc_kpu_profile_action *)(fw->data + offset); + +if (rvu->kpu_fwdata_sz < hdr_sz +sizeof (ikpu_action_entries)) +return -ENOMEM ; + +memcpy ((void *)profile->ikpu, action,sizeof (ikpu_action_entries)); + offset +=sizeof (ikpu_action_entries); + }for (kpu =0 ; kpu < fw->kpus; kpu++) { fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset); -if (fw_kpu->entries >KPU_MAX_CST_ENT ) -dev_warn (rvu->dev, -"Too many custom entries on KPU%d: %d > %d\n" , - kpu, fw_kpu->entries,KPU_MAX_CST_ENT ); - entries =min (fw_kpu->entries,KPU_MAX_CST_ENT ); - cam = (struct npc_kpu_profile_cam *)fw_kpu->data; - offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam); +if (!from_fs) { +if (fw_kpu->entries >KPU_MAX_CST_ENT ) +dev_warn (rvu->dev, +"Too many custom entries on KPU%d: %d > %d\n" , + kpu, fw_kpu->entries,KPU_MAX_CST_ENT ); + entries =min (fw_kpu->entries,KPU_MAX_CST_ENT ); + cam = (struct npc_kpu_profile_cam *)fw_kpu->data; + offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam); + action = (struct npc_kpu_profile_action *)(fw->data + offset); + offset += fw_kpu->entries *sizeof (*action); +if (rvu->kpu_fwdata_sz < hdr_sz + offset) { +dev_warn (rvu->dev, +"Profile size mismatch on KPU%i parsing.\n" , + kpu +1 ); +return -EINVAL ; + } +for (entry =0 ; entry < entries; entry++) { + profile->kpu[kpu].cam[entry] = cam[entry]; + profile->kpu[kpu].action[entry] = action[entry]; + } +continue ; + } + entries = fw_kpu->entries; +dev_info (rvu->dev, +"Loading %u entries on KPU%d\n" , entries, kpu); + + cam2 = (struct npc_kpu_profile_cam2 *)fw_kpu->data; + offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam2); action = (struct npc_kpu_profile_action *)(fw->data + offset); offset += fw_kpu->entries *sizeof (*action);if (rvu->kpu_fwdata_sz < hdr_sz + offset) {dev_warn (rvu->dev, -"Profile size mismatch on KPU%i parsing.\n" , +"profile size mismatch on kpu%i parsing.\n" , kpu +1 );return -EINVAL ; } + + profile->kpu[kpu].cam_entries = entries; + profile->kpu[kpu].action_entries = entries; + ret =npc_alloc_kpu_cam2_n_action (rvu, kpu, entries); +if (ret) { + dev_warn(rvu->dev,
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static int npc_apply_custom_kpu(struct rvu *rvu, · line 1851
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +6
-1+"profile entry allocation failed for kpu=%d for %d entries\n" , + kpu, entries); +return -EINVAL ; + } +for (entry =0 ; entry < entries; entry++) { - profile->kpu[kpu].cam[entry] = cam[entry]; + profile->kpu[kpu].cam2[entry] = cam2[entry]; profile->kpu[kpu].action[entry] = action[entry]; }
Could this loop overflow and hang the kernel if firmware specifies more than 65535 entries?
The loop variable 'entry' is declared as u16:
u16 kpu, entry;
while 'entries' is an int:
entries = fw_kpu->entries;
In the from_fs path, 'entries' is read directly from the firmware blob without capping it (unlike the !from_fs path which uses min(fw_kpu->entries, KPU_MAX_CST_ENT)).
If a corrupt or malicious firmware file specifies fw_kpu->entries > 65535, the u16 variable wraps around at 65536:
for (entry = 0; entry < entries; entry++)
When entry reaches 65535, incrementing it produces 0, which is still less than entries, creating an infinite loop that hangs the kernel.
Should the code either cap entries in the from_fs path or use an int-sized loop variable?
Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0}
[ ... ]
Ratheesh Kannoth
maintainerRe: [v3,net-next,5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem
Quoted 108 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
octeontx2-af: Add support for loading custom KPU profile from filesystemThis commit adds functionality to load custom KPU (Key Parse Unit) profiles from the filesystem at module load time, providing an alternative to flashing updated firmware on deployed devices.
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +0
-0[ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +1
-0@@ -290,6 +303,7 @@ struct npc_kpu_profile {int action_entries;struct npc_kpu_profile_cam *cam;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_cam2 *cam2; };[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +0
-0[ ... ]
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +2
-2@@ -553,8 +553,8 @@ struct npc_kpu_profile_adapter {const char *name;u64 version;const struct npc_lt_def_cfg *lt_def; -const struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ -const struct npc_kpu_profile *kpu;/* array[kpus] */ +struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ +struct npc_kpu_profile *kpu;/* array[kpus] */ [ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +1
-0@@ -564,6 +564,7 @@ struct npc_kpu_profile_adapter {bool custom;size_t pkinds;size_t kpus; +bool from_fs; };[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0[ ... ]
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1
-0@@ -1610,6 +1622,7 @@ u64 npc_enable_mask(int count)static void npc_program_kpu_profile (struct rvu *rvu,int blkaddr,int kpu,const struct npc_kpu_profile *profile) { +struct npc_kpu_profile_adapter *adapter = &rvu->kpu;int entry, num_entries, max_entries;u64 entry_mask;@@ -1621,10 +1634,15 @@ static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, max_entries = rvu->hw->npc_kpu_entries;drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, · line 1646
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +5
-0+WARN (profile->cam_entries > max_entries, +"KPU%u: err: hw max entries=%u, input entries=%u\n" , + kpu, rvu->hw->npc_kpu_entries, profile->cam_entries); +/* Program CAM match entries for previous KPU extracted data */ num_entries =min_t (int, profile->cam_entries, max_entries);for (entry =0 ; entry < num_entries; entry++)npc_config_kpucam (rvu, blkaddr, + adapter->from_fs ? (void *)&profile->cam2[entry] : &profile->cam[entry], kpu, entry);Can this dereference NULL when
from_fsis true for KPUs not covered by the filesystem firmware?Looking at the filesystem loading path in
npc_apply_custom_kpu:for (kpu = 0; kpu < fw->kpus; kpu++) { ... ret = npc_alloc_kpu_cam2_n_action(rvu, kpu, entries); ... for (entry = 0; entry < entries; entry++) { profile->kpu[kpu].cam2[entry] = cam2[entry]; ... } }The code allocates cam2 and populates entries only for the first
fw->kpusKPUs found in the firmware blob.However,
npc_program_kpu_profileis later called for all KPUs innpc_parser_profile_init:for (idx = 0; idx < num_kpus; idx++) npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);
Quoted 7 lines
Since
adapter->from_fsis a global flag (not per-KPU), when idx >=fw->kpus,profile->cam2remains NULL (the default npc_kpu_profiles[] static initializer doesn't include cam2), causing &profile->cam2[entry] to compute an invalid pointer.Shouldn't there be a check to verify cam2 is non-NULL before dereferencing it, or allocate cam2 for all KPUs when
from_fsis true?
The filsystem binary contains entries for all KPUs. So we can ignore this case.
Quoted 25 lines
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0/* Program this KPU's actions */ [ ... ]
Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +15
-0@@ -1678,26 +1696,50 @@ static void npc_prepare_default_kpu(struct rvu *rvu,npc_cn20k_update_action_entries_n_flags (rvu, profile); } +static int npc_alloc_kpu_cam2_n_action (struct rvu *rvu,int kpu_num, +int num_entries) +{ +struct npc_kpu_profile_adapter *adapter = &rvu->kpu; +struct npc_kpu_profile *kpu; + + kpu = &adapter->kpu[kpu_num]; + + kpu->cam2 =devm_kcalloc (rvu->dev, num_entries, +sizeof (*kpu->cam2),GFP_KERNEL ); +if (!kpu->cam2) +return -ENOMEM ; + + kpu->action =devm_kcalloc (rvu->dev, num_entries, +sizeof (*kpu->action),GFP_KERNEL );
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static void npc_prepare_default_kpu(struct rvu *rvu, · line 1718
Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +5
-0+if (!kpu->action) +return -ENOMEM ; + +return 0 ; +}Can this permanently corrupt the default profile when the second allocation fails?
Expectation is to load the correct binary. Due to memory constraints, we decided to skip rollback on errors. It is user responsibility to remove the corrupted FW binary and reboot.
Quoted 12 lines
The kpu pointer targets the static npc_kpu_profiles[] array (
adapter->kpustarts as &npc_kpu_profiles[0]). When the firstdevm_kcallocsucceeds but the second fails:kpu->cam2 = devm_kcalloc(...) // succeeds, modifies static array kpu->action = devm_kcalloc(...) // fails return -ENOMEM; // kpu->action is now NULL in static arrayThe caller in
npc_apply_custom_kpureturns the error without restoring the original action pointer.
Quoted 6 lines
Later,
npc_parser_profile_initcallsnpc_program_kpu_profilefor all KPUs, which callsnpc_config_kpuactionwith &profile->action[entry] where action is NULL, causing a crash when dereferencing the NULL pointer.Should the function restore the original pointers on allocation failure, or use a separate copy of the profile entries for filesystem loading?
Same as above.
Quoted 107 lines
Quoted 17 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +6
-2+static int npc_apply_custom_kpu (struct rvu *rvu, -struct npc_kpu_profile_adapter *profile) +struct npc_kpu_profile_adapter *profile, +bool from_fs) {size_t hdr_sz =sizeof (struct npc_kpu_profile_fwdata ), offset =0 ;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_fwdata *sfw;struct npc_kpu_profile_fwdata *fw; +struct npc_kpu_profile_cam2 *cam2;struct npc_kpu_profile_cam *cam;struct npc_kpu_fwdata *fw_kpu; -int entries; +int entries, ret;u16 kpu, entry;[ ... ]
Quoted 87 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +60
-11@@ -1731,31 +1773,80 @@ static int npc_apply_custom_kpu(struct rvu *rvu,return -EINVAL ; } + sfw =devm_kcalloc (rvu->dev,1 ,sizeof (*sfw),GFP_KERNEL ); +if (!sfw) +return -ENOMEM ; + +memcpy (sfw, fw,sizeof (*sfw)); + profile->custom =1 ; - profile->name = fw->name; + profile->name = sfw->name; profile->version =le64_to_cpu (fw->version); - profile->mcam_kex_prfl.mkex = &fw->mkex; - profile->lt_def = &fw->lt_def; + profile->mcam_kex_prfl.mkex = &sfw->mkex; + profile->lt_def = &sfw->lt_def; + +/* Binary blob contains ikpu actions entries at start of data[0] */ +if (from_fs) { + action = (struct npc_kpu_profile_action *)(fw->data + offset); + +if (rvu->kpu_fwdata_sz < hdr_sz +sizeof (ikpu_action_entries)) +return -ENOMEM ; + +memcpy ((void *)profile->ikpu, action,sizeof (ikpu_action_entries)); + offset +=sizeof (ikpu_action_entries); + }for (kpu =0 ; kpu < fw->kpus; kpu++) { fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset); -if (fw_kpu->entries >KPU_MAX_CST_ENT ) -dev_warn (rvu->dev, -"Too many custom entries on KPU%d: %d > %d\n" , - kpu, fw_kpu->entries,KPU_MAX_CST_ENT ); - entries =min (fw_kpu->entries,KPU_MAX_CST_ENT ); - cam = (struct npc_kpu_profile_cam *)fw_kpu->data; - offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam); +if (!from_fs) { +if (fw_kpu->entries >KPU_MAX_CST_ENT ) +dev_warn (rvu->dev, +"Too many custom entries on KPU%d: %d > %d\n" , + kpu, fw_kpu->entries,KPU_MAX_CST_ENT ); + entries =min (fw_kpu->entries,KPU_MAX_CST_ENT ); + cam = (struct npc_kpu_profile_cam *)fw_kpu->data; + offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam); + action = (struct npc_kpu_profile_action *)(fw->data + offset); + offset += fw_kpu->entries *sizeof (*action); +if (rvu->kpu_fwdata_sz < hdr_sz + offset) { +dev_warn (rvu->dev, +"Profile size mismatch on KPU%i parsing.\n" , + kpu +1 ); +return -EINVAL ; + } +for (entry =0 ; entry < entries; entry++) { + profile->kpu[kpu].cam[entry] = cam[entry]; + profile->kpu[kpu].action[entry] = action[entry]; + } +continue ; + } + entries = fw_kpu->entries; +dev_info (rvu->dev, +"Loading %u entries on KPU%d\n" , entries, kpu); + + cam2 = (struct npc_kpu_profile_cam2 *)fw_kpu->data; + offset +=sizeof (*fw_kpu) + fw_kpu->entries *sizeof (*cam2); action = (struct npc_kpu_profile_action *)(fw->data + offset); offset += fw_kpu->entries *sizeof (*action);if (rvu->kpu_fwdata_sz < hdr_sz + offset) {dev_warn (rvu->dev, -"Profile size mismatch on KPU%i parsing.\n" , +"profile size mismatch on kpu%i parsing.\n" , kpu +1 );return -EINVAL ; } + + profile->kpu[kpu].cam_entries = entries; + profile->kpu[kpu].action_entries = entries; + ret =npc_alloc_kpu_cam2_n_action (rvu, kpu, entries); +if (ret) { +dev_warn (rvu->dev, +"profile entry allocation failed for kpu=%d for %d entries\n" , + kpu, entries); +return -EINVAL ; + } +
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static int npc_apply_custom_kpu(struct rvu *rvu, · line 1851
Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1
-1for (entry =0 ; entry < entries; entry++) { - profile->kpu[kpu].cam[entry] = cam[entry]; + profile->kpu[kpu].cam2[entry] = cam2[entry]; profile->kpu[kpu].action[entry] = action[entry]; }Could this loop overflow and hang the kernel if firmware specifies more than 65535 entries?
FW binary is prepared by marvell and tested before delivering to customers. And the entries wont cross u16 limit
Quoted 27 lines
The loop variable 'entry' is declared as u16:
u16 kpu, entry;while 'entries' is an int:
entries = fw_kpu->entries;In the
from_fspath, 'entries' is read directly from the firmware blob without capping it (unlike the !from_fs path which usesmin(fw_kpu->entries, KPU_MAX_CST_ENT)).If a corrupt or malicious firmware file specifies
fw_kpu->entries> 65535, the u16 variable wraps around at 65536:for (entry = 0; entry < entries; entry++)
When entry reaches 65535, incrementing it produces 0, which is still less than entries, creating an infinite loop that hangs the kernel.
Should the code either cap entries in the
from_fspath or use an int-sized loop variable?Quoted 1 line
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0}[ ... ]
Simon Horman
reviewerRe: [v3,net-next,5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem
Quoted 114 lines · Ratheesh Kannoth
Quoted 113 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
octeontx2-af: Add support for loading custom KPU profile from filesystemThis commit adds functionality to load custom KPU (Key Parse Unit) profiles from the filesystem at module load time, providing an alternative to flashing updated firmware on deployed devices.
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +0
-0[ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/npc.h +1
-0@@ -290,6 +303,7 @@ struct npc_kpu_profile {int action_entries;struct npc_kpu_profile_cam *cam;struct npc_kpu_profile_action *action; +struct npc_kpu_profile_cam2 *cam2; };[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +0
-0[ ... ]
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +2
-2@@ -553,8 +553,8 @@ struct npc_kpu_profile_adapter {const char *name;u64 version;const struct npc_lt_def_cfg *lt_def; -const struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ -const struct npc_kpu_profile *kpu;/* array[kpus] */ +struct npc_kpu_profile_action *ikpu;/* array[pkinds] */ +struct npc_kpu_profile *kpu;/* array[kpus] */ [ ... ]
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +1
-0@@ -564,6 +564,7 @@ struct npc_kpu_profile_adapter {bool custom;size_t pkinds;size_t kpus; +bool from_fs; };[ ... ]
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0[ ... ]
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1
-0@@ -1610,6 +1622,7 @@ u64 npc_enable_mask(int count)static void npc_program_kpu_profile (struct rvu *rvu,int blkaddr,int kpu,const struct npc_kpu_profile *profile) { +struct npc_kpu_profile_adapter *adapter = &rvu->kpu;int entry, num_entries, max_entries;u64 entry_mask;@@ -1621,10 +1634,15 @@ static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, max_entries = rvu->hw->npc_kpu_entries;drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu, · line 1646
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +5
-0+WARN (profile->cam_entries > max_entries, +"KPU%u: err: hw max entries=%u, input entries=%u\n" , + kpu, rvu->hw->npc_kpu_entries, profile->cam_entries); +/* Program CAM match entries for previous KPU extracted data */ num_entries =min_t (int, profile->cam_entries, max_entries);for (entry =0 ; entry < num_entries; entry++)npc_config_kpucam (rvu, blkaddr, + adapter->from_fs ? (void *)&profile->cam2[entry] : &profile->cam[entry], kpu, entry);Can this dereference NULL when
from_fsis true for KPUs not covered by the filesystem firmware?Looking at the filesystem loading path in
npc_apply_custom_kpu:for (kpu = 0; kpu < fw->kpus; kpu++) { ... ret = npc_alloc_kpu_cam2_n_action(rvu, kpu, entries); ... for (entry = 0; entry < entries; entry++) { profile->kpu[kpu].cam2[entry] = cam2[entry]; ... } }The code allocates cam2 and populates entries only for the first
fw->kpusKPUs found in the firmware blob.However,
npc_program_kpu_profileis later called for all KPUs innpc_parser_profile_init:for (idx = 0; idx < num_kpus; idx++) npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);Since
adapter->from_fsis a global flag (not per-KPU), when idx >=fw->kpus,profile->cam2remains NULL (the default npc_kpu_profiles[] static initializer doesn't include cam2), causing &profile->cam2[entry] to compute an invalid pointer.
Quoted 5 lines
Quoted 2 lines
Shouldn't there be a check to verify cam2 is non-NULL before dereferencing it, or allocate cam2 for all KPUs when
from_fsis true?The filsystem binary contains entries for all KPUs. So we can ignore this case.
Maybe it is just me. But I don't think it is entirely satisfactory for the kernel to rely on data supplied from the filesystem being well formed. E.g. what if it is corrupted?
I think all the points in the AI generated review hinge on this. So let's try and agree on the basic principles and move on from there.
...
Ratheesh Kannoth
maintainerRe: [v3,net-next,5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem
Quoted 11 lines · Simon Horman
Quoted 3 lines
The filsystem binary contains entries for all KPUs. So we can ignore this case.
Maybe it is just me. But I don't think it is entirely satisfactory for the kernel to rely on data supplied from the filesystem being well formed. E.g. what if it is corrupted?
I think all the points in the AI generated review hinge on this. So let's try and agree on the basic principles and move on from there.
...
ACK.
Ratheesh Kannoth
maintainerRe: [v3,net-next,5/5] octeontx2-af: Add support for loading custom KPU profile from filesystem
In reply to Simon HormanQuoted 18 lines · Simon Horman
Could this loop overflow and hang the kernel if firmware specifies more than 65535 entries?
The loop variable 'entry' is declared as u16:
u16 kpu, entry;while 'entries' is an int:
entries = fw_kpu->entries;In the
from_fspath, 'entries' is read directly from the firmware blob without capping it (unlike the !from_fs path which usesmin(fw_kpu->entries, KPU_MAX_CST_ENT)).If a corrupt or malicious firmware file specifies
fw_kpu->entries> 65535, the u16 variable wraps around at 65536:
Quoted 7 lines
for (entry = 0; entry < entries; entry++)
When entry reaches 65535, incrementing it produces 0, which is still less than entries, creating an infinite loop that hangs the kernel.
Should the code either cap entries in the
from_fspath or use an int-sized loop variable?
Hi Simon, I made some code changes and inadvertently missed addressing this comment in v4. Sorry about that—I will address it in v5.
Quoted 4 lines
Quoted 2 lines
}
[ ... ]