* [bug report] octeontx2-af: Drop rules for NPC MCAM
@ 2022-07-13 11:27 Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-13 11:27 UTC (permalink / raw)
To: rkannoth; +Cc: kernel-janitors
Hello Ratheesh Kannoth,
The patch 3571fe07a090: "octeontx2-af: Drop rules for NPC MCAM" from
Jul 8, 2022, leads to the following Smatch static checker warning:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1232 rvu_npc_exact_del_table_entry_by_id()
error: uninitialized symbol 'drop_mcam_idx'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c
1199 static int rvu_npc_exact_del_table_entry_by_id(struct rvu *rvu, u32 seq_id)
1200 {
1201 struct npc_exact_table_entry *entry = NULL;
1202 struct npc_exact_table *table;
1203 bool disable_cam = false;
1204 u32 drop_mcam_idx;
1205 int *cnt;
1206
1207 table = rvu->hw->table;
1208
1209 mutex_lock(&table->lock);
1210
1211 /* Lookup for entry which needs to be updated */
1212 entry = __rvu_npc_exact_find_entry_by_seq_id(rvu, seq_id);
1213 if (!entry) {
1214 dev_dbg(rvu->dev, "%s: failed to find entry for id=0x%x\n", __func__, seq_id);
1215 mutex_unlock(&table->lock);
1216 return -ENODATA;
1217 }
1218
1219 cnt = (entry->opc_type == NPC_EXACT_OPC_CAM) ? &table->cam_tbl_entry_cnt :
1220 &table->mem_tbl_entry_cnt;
1221
1222 /* delete from lists */
1223 list_del_init(&entry->list);
1224 list_del_init(&entry->glist);
1225
1226 (*cnt)--;
1227
1228 rvu_npc_exact_get_drop_rule_info(rvu, NIX_INTF_TYPE_CGX, entry->cgx_id, entry->lmac_id,
1229 &drop_mcam_idx, NULL, NULL, NULL);
No checks for errors
1230
1231 if (entry->cmd)
--> 1232 __rvu_npc_exact_cmd_rules_cnt_update(rvu, drop_mcam_idx, -1, &disable_cam);
Uninitialized value leads to out of bounds access
1233
1234 /* No dmac filter rules; disable drop on hit rule */
1235 if (disable_cam) {
1236 rvu_npc_enable_mcam_by_entry_index(rvu, drop_mcam_idx, NIX_INTF_RX, false);
1237 dev_dbg(rvu->dev, "%s: Disabling mcam idx %d\n",
1238 __func__, drop_mcam_idx);
1239 }
1240
1241 mutex_unlock(&table->lock);
1242
1243 rvu_npc_exact_dealloc_table_entry(rvu, entry->opc_type, entry->ways, entry->index);
1244
1245 rvu_npc_exact_free_id(rvu, seq_id);
1246
1247 dev_dbg(rvu->dev, "%s: delete entry success for id=0x%x, mca=%pM\n",
1248 __func__, seq_id, entry->mac);
1249 kfree(entry);
1250
1251 return 0;
1252 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* [bug report] octeontx2-af: Drop rules for NPC MCAM
@ 2022-07-13 11:32 Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-13 11:32 UTC (permalink / raw)
To: rkannoth; +Cc: kernel-janitors
Hello Ratheesh Kannoth,
The patch 3571fe07a090: "octeontx2-af: Drop rules for NPC MCAM" from
Jul 8, 2022, leads to the following Smatch static checker warning:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1964 rvu_npc_exact_init()
error: uninitialized symbol 'err'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c
1953
1954 dev_dbg(rvu->dev,
1955 "%s:Drop rule cgx=%d lmac=%d chan(val=0x%llx, mask=0x%llx\n",
1956 __func__, cgx_id, lmac_id, chan_val, chan_mask);
1957
1958 rc = rvu_npc_exact_save_drop_rule_chan_and_mask(rvu, table->num_drop_rules,
1959 chan_val, chan_mask, pcifunc);
1960 if (!rc) {
1961 dev_err(rvu->dev,
1962 "%s: failed to set drop info for cgx=%d, lmac=%d, chan=%llx\n",
1963 __func__, cgx_id, lmac_id, chan_val);
--> 1964 return err;
"err" is uninitialized. This should be return -EINVAL or something.
Let me just send the whole list. The rest are mostly caused by no
error checking. It's possibly deliberate. Hard to tell without knowing
the subsystem more deeply.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1232 rvu_npc_exact_del_table_entry_by_id() error: uninitialized symbol 'drop_mcam_idx'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1312 rvu_npc_exact_add_table_entry() error: uninitialized symbol 'drop_mcam_idx'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1391 rvu_npc_exact_update_table_entry() error: uninitialized symbol 'hash_index'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1428 rvu_npc_exact_promisc_disable() error: uninitialized symbol 'drop_mcam_idx'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1473 rvu_npc_exact_promisc_enable() error: uninitialized symbol 'drop_mcam_idx'.
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1964 rvu_npc_exact_init() error: uninitialized symbol 'err'.
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h:735 otx2_mbox_alloc_msg_npc_get_secret_key() warn: struct type mismatch 'mbox_msghdr vs npc_get_secret_key_req'
drivers/net/ethernet/marvell/octeontx2/nic/otx2_dmac_flt.c:191 otx2_dmacflt_update() error: 'rsp' dereferencing possible ERR_PTR()
drivers/net/ethernet/marvell/octeontx2/nic/otx2_dmac_flt.c:60 otx2_dmacflt_add_pfmac() error: 'rsp' dereferencing possible ERR_PTR()
1965 }
1966
1967 err = npc_install_mcam_drop_rule(rvu, *drop_mcam_idx,
1968 &table->counter_idx[*drop_mcam_idx],
1969 chan_val, chan_mask,
1970 exact_val, exact_mask,
1971 bcast_mcast_val, bcast_mcast_mask);
1972 if (err) {
1973 dev_err(rvu->dev,
1974 "failed to configure drop rule (cgx=%d lmac=%d)\n",
1975 cgx_id, lmac_id);
1976 return err;
1977 }
1978
1979 (*drop_mcam_idx)++;
1980 }
1981
1982 dev_info(rvu->dev, "initialized exact match table successfully\n");
1983 return 0;
1984 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* [bug report] octeontx2-af: Drop rules for NPC MCAM
@ 2024-10-07 6:26 Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-10-07 6:26 UTC (permalink / raw)
To: Ratheesh Kannoth
Cc: Sunil Goutham, Linu Cherian, Geetha sowjanya, Jerin Jacob,
hariprasad, Subbaraya Sundeep, kernel-janitors
Hello Ratheesh Kannoth,
Commit 3571fe07a090 ("octeontx2-af: Drop rules for NPC MCAM") from
Jul 8, 2022 (linux-next), leads to the following Smatch static
checker warning:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c:1973 rvu_npc_exact_init()
warn: potential ! vs ~ typo
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c
1860 int rvu_npc_exact_init(struct rvu *rvu)
1861 {
1862 u64 bcast_mcast_val, bcast_mcast_mask;
1863 struct npc_exact_table *table;
1864 u64 exact_val, exact_mask;
1865 u64 chan_val, chan_mask;
1866 u8 cgx_id, lmac_id;
1867 u32 *drop_mcam_idx;
1868 u16 max_lmac_cnt;
1869 u64 npc_const3;
1870 int table_size;
1871 int blkaddr;
1872 u16 pcifunc;
1873 int err, i;
1874 u64 cfg;
1875 bool rc;
1876
1877 /* Read NPC_AF_CONST3 and check for have exact
1878 * match functionality is present
1879 */
1880 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1881 if (blkaddr < 0) {
1882 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
1883 return -EINVAL;
1884 }
1885
1886 /* Check exact match feature is supported */
1887 npc_const3 = rvu_read64(rvu, blkaddr, NPC_AF_CONST3);
1888 if (!(npc_const3 & BIT_ULL(62)))
1889 return 0;
1890
1891 /* Check if kex profile has enabled EXACT match nibble */
1892 cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(NIX_INTF_RX));
1893 if (!(cfg & NPC_EXACT_NIBBLE_HIT))
1894 return 0;
1895
1896 /* Set capability to true */
1897 rvu->hw->cap.npc_exact_match_enabled = true;
1898
1899 table = kzalloc(sizeof(*table), GFP_KERNEL);
1900 if (!table)
1901 return -ENOMEM;
1902
1903 dev_dbg(rvu->dev, "%s: Memory allocation for table success\n", __func__);
1904 rvu->hw->table = table;
1905
1906 /* Read table size, ways and depth */
1907 table->mem_table.ways = FIELD_GET(GENMASK_ULL(19, 16), npc_const3);
1908 table->mem_table.depth = FIELD_GET(GENMASK_ULL(15, 0), npc_const3);
1909 table->cam_table.depth = FIELD_GET(GENMASK_ULL(31, 24), npc_const3);
1910
1911 dev_dbg(rvu->dev, "%s: NPC exact match 4way_2k table(ways=%d, depth=%d)\n",
1912 __func__, table->mem_table.ways, table->cam_table.depth);
1913
1914 /* Check if depth of table is not a sequre of 2
1915 * TODO: why _builtin_popcount() is not working ?
1916 */
1917 if ((table->mem_table.depth & (table->mem_table.depth - 1)) != 0) {
1918 dev_err(rvu->dev,
1919 "%s: NPC exact match 4way_2k table depth(%d) is not square of 2\n",
1920 __func__, table->mem_table.depth);
1921 return -EINVAL;
1922 }
1923
1924 table_size = table->mem_table.depth * table->mem_table.ways;
1925
1926 /* Allocate bitmap for 4way 2K table */
1927 table->mem_table.bmap = devm_bitmap_zalloc(rvu->dev, table_size,
1928 GFP_KERNEL);
1929 if (!table->mem_table.bmap)
1930 return -ENOMEM;
1931
1932 dev_dbg(rvu->dev, "%s: Allocated bitmap for 4way 2K entry table\n", __func__);
1933
1934 /* Allocate bitmap for 32 entry mcam */
1935 table->cam_table.bmap = devm_bitmap_zalloc(rvu->dev, 32, GFP_KERNEL);
1936
1937 if (!table->cam_table.bmap)
1938 return -ENOMEM;
1939
1940 dev_dbg(rvu->dev, "%s: Allocated bitmap for 32 entry cam\n", __func__);
1941
1942 table->tot_ids = table_size + table->cam_table.depth;
1943 table->id_bmap = devm_bitmap_zalloc(rvu->dev, table->tot_ids,
1944 GFP_KERNEL);
1945
1946 if (!table->id_bmap)
1947 return -ENOMEM;
1948
1949 dev_dbg(rvu->dev, "%s: Allocated bitmap for id map (total=%d)\n",
1950 __func__, table->tot_ids);
1951
1952 /* Initialize list heads for npc_exact_table entries.
1953 * This entry is used by debugfs to show entries in
1954 * exact match table.
1955 */
1956 for (i = 0; i < NPC_EXACT_TBL_MAX_WAYS; i++)
1957 INIT_LIST_HEAD(&table->lhead_mem_tbl_entry[i]);
1958
1959 INIT_LIST_HEAD(&table->lhead_cam_tbl_entry);
1960 INIT_LIST_HEAD(&table->lhead_gbl);
1961
1962 mutex_init(&table->lock);
1963
1964 rvu_exact_config_secret_key(rvu);
1965 rvu_exact_config_search_key(rvu);
1966
1967 rvu_exact_config_table_mask(rvu);
1968 rvu_exact_config_result_ctrl(rvu, table->mem_table.depth);
1969
1970 /* - No drop rule for LBK
1971 * - Drop rules for SDP and each LMAC.
1972 */
--> 1973 exact_val = !NPC_EXACT_RESULT_HIT;
Should this have been "exact_val = ~NPC_EXACT_RESULT_HIT;"?
1974 exact_mask = NPC_EXACT_RESULT_HIT;
1975
1976 /* nibble - 3 2 1 0
1977 * L3B L3M L2B L2M
1978 */
1979 bcast_mcast_val = 0b0000;
1980 bcast_mcast_mask = 0b0011;
1981
1982 /* Install SDP drop rule */
1983 drop_mcam_idx = &table->num_drop_rules;
1984
1985 max_lmac_cnt = rvu->cgx_cnt_max * rvu->hw->lmac_per_cgx +
1986 PF_CGXMAP_BASE;
1987
1988 for (i = PF_CGXMAP_BASE; i < max_lmac_cnt; i++) {
1989 if (rvu->pf2cgxlmac_map[i] == 0xFF)
1990 continue;
1991
1992 rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[i], &cgx_id, &lmac_id);
1993
1994 rc = rvu_npc_exact_calc_drop_rule_chan_and_mask(rvu, NIX_INTF_TYPE_CGX, cgx_id,
1995 lmac_id, &chan_val, &chan_mask);
1996 if (!rc) {
1997 dev_err(rvu->dev,
1998 "%s: failed, info chan_val=0x%llx chan_mask=0x%llx rule_id=%d\n",
1999 __func__, chan_val, chan_mask, *drop_mcam_idx);
2000 return -EINVAL;
2001 }
2002
2003 /* Filter rules are only for PF */
2004 pcifunc = RVU_PFFUNC(i, 0);
2005
2006 dev_dbg(rvu->dev,
2007 "%s:Drop rule cgx=%d lmac=%d chan(val=0x%llx, mask=0x%llx\n",
2008 __func__, cgx_id, lmac_id, chan_val, chan_mask);
2009
2010 rc = rvu_npc_exact_save_drop_rule_chan_and_mask(rvu, table->num_drop_rules,
2011 chan_val, chan_mask, pcifunc);
2012 if (!rc) {
2013 dev_err(rvu->dev,
2014 "%s: failed to set drop info for cgx=%d, lmac=%d, chan=%llx\n",
2015 __func__, cgx_id, lmac_id, chan_val);
2016 return -EINVAL;
2017 }
2018
2019 err = npc_install_mcam_drop_rule(rvu, *drop_mcam_idx,
2020 &table->counter_idx[*drop_mcam_idx],
2021 chan_val, chan_mask,
2022 exact_val, exact_mask,
2023 bcast_mcast_val, bcast_mcast_mask);
2024 if (err) {
2025 dev_err(rvu->dev,
2026 "failed to configure drop rule (cgx=%d lmac=%d)\n",
2027 cgx_id, lmac_id);
2028 return err;
2029 }
2030
2031 (*drop_mcam_idx)++;
2032 }
2033
2034 dev_info(rvu->dev, "initialized exact match table successfully\n");
2035 return 0;
2036 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-07 6:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-13 11:27 [bug report] octeontx2-af: Drop rules for NPC MCAM Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2022-07-13 11:32 Dan Carpenter
2024-10-07 6:26 Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.