Skip to content

Commit 20af886

Browse files
committed
Merge branch 'octeontx2-debugfs-fixes'
Rakesh Babu Saladi says: ==================== RVU Debugfs fix updates. The following patch series consists of the patch fixes done over rvu_debugfs.c and rvu_nix.c files. Patch 1: Check and return if ipolicers do not exists. Patch 2: Fix rsrc_alloc to print all enabled PF/VF entries with list of LFs allocated for each functional block. Patch 3: Fix possible null pointer dereference. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e8684db + c2d4c54 commit 20af886

File tree

2 files changed

+118
-33
lines changed

2 files changed

+118
-33
lines changed

drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

Lines changed: 115 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,85 @@ static const struct file_operations rvu_dbg_##name##_fops = { \
226226

227227
static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf);
228228

229+
static void get_lf_str_list(struct rvu_block block, int pcifunc,
230+
char *lfs)
231+
{
232+
int lf = 0, seq = 0, len = 0, prev_lf = block.lf.max;
233+
234+
for_each_set_bit(lf, block.lf.bmap, block.lf.max) {
235+
if (lf >= block.lf.max)
236+
break;
237+
238+
if (block.fn_map[lf] != pcifunc)
239+
continue;
240+
241+
if (lf == prev_lf + 1) {
242+
prev_lf = lf;
243+
seq = 1;
244+
continue;
245+
}
246+
247+
if (seq)
248+
len += sprintf(lfs + len, "-%d,%d", prev_lf, lf);
249+
else
250+
len += (len ? sprintf(lfs + len, ",%d", lf) :
251+
sprintf(lfs + len, "%d", lf));
252+
253+
prev_lf = lf;
254+
seq = 0;
255+
}
256+
257+
if (seq)
258+
len += sprintf(lfs + len, "-%d", prev_lf);
259+
260+
lfs[len] = '\0';
261+
}
262+
263+
static int get_max_column_width(struct rvu *rvu)
264+
{
265+
int index, pf, vf, lf_str_size = 12, buf_size = 256;
266+
struct rvu_block block;
267+
u16 pcifunc;
268+
char *buf;
269+
270+
buf = kzalloc(buf_size, GFP_KERNEL);
271+
if (!buf)
272+
return -ENOMEM;
273+
274+
for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
275+
for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
276+
pcifunc = pf << 10 | vf;
277+
if (!pcifunc)
278+
continue;
279+
280+
for (index = 0; index < BLK_COUNT; index++) {
281+
block = rvu->hw->block[index];
282+
if (!strlen(block.name))
283+
continue;
284+
285+
get_lf_str_list(block, pcifunc, buf);
286+
if (lf_str_size <= strlen(buf))
287+
lf_str_size = strlen(buf) + 1;
288+
}
289+
}
290+
}
291+
292+
kfree(buf);
293+
return lf_str_size;
294+
}
295+
229296
/* Dumps current provisioning status of all RVU block LFs */
230297
static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
231298
char __user *buffer,
232299
size_t count, loff_t *ppos)
233300
{
234-
int index, off = 0, flag = 0, go_back = 0, len = 0;
301+
int index, off = 0, flag = 0, len = 0, i = 0;
235302
struct rvu *rvu = filp->private_data;
236-
int lf, pf, vf, pcifunc;
303+
int bytes_not_copied = 0;
237304
struct rvu_block block;
238-
int bytes_not_copied;
239-
int lf_str_size = 12;
305+
int pf, vf, pcifunc;
240306
int buf_size = 2048;
307+
int lf_str_size;
241308
char *lfs;
242309
char *buf;
243310

@@ -249,6 +316,9 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
249316
if (!buf)
250317
return -ENOSPC;
251318

319+
/* Get the maximum width of a column */
320+
lf_str_size = get_max_column_width(rvu);
321+
252322
lfs = kzalloc(lf_str_size, GFP_KERNEL);
253323
if (!lfs) {
254324
kfree(buf);
@@ -262,65 +332,69 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
262332
"%-*s", lf_str_size,
263333
rvu->hw->block[index].name);
264334
}
335+
265336
off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
337+
bytes_not_copied = copy_to_user(buffer + (i * off), buf, off);
338+
if (bytes_not_copied)
339+
goto out;
340+
341+
i++;
342+
*ppos += off;
266343
for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
267344
for (vf = 0; vf <= rvu->hw->total_vfs; vf++) {
345+
off = 0;
346+
flag = 0;
268347
pcifunc = pf << 10 | vf;
269348
if (!pcifunc)
270349
continue;
271350

272351
if (vf) {
273352
sprintf(lfs, "PF%d:VF%d", pf, vf - 1);
274-
go_back = scnprintf(&buf[off],
275-
buf_size - 1 - off,
276-
"%-*s", lf_str_size, lfs);
353+
off = scnprintf(&buf[off],
354+
buf_size - 1 - off,
355+
"%-*s", lf_str_size, lfs);
277356
} else {
278357
sprintf(lfs, "PF%d", pf);
279-
go_back = scnprintf(&buf[off],
280-
buf_size - 1 - off,
281-
"%-*s", lf_str_size, lfs);
358+
off = scnprintf(&buf[off],
359+
buf_size - 1 - off,
360+
"%-*s", lf_str_size, lfs);
282361
}
283362

284-
off += go_back;
285-
for (index = 0; index < BLKTYPE_MAX; index++) {
363+
for (index = 0; index < BLK_COUNT; index++) {
286364
block = rvu->hw->block[index];
287365
if (!strlen(block.name))
288366
continue;
289367
len = 0;
290368
lfs[len] = '\0';
291-
for (lf = 0; lf < block.lf.max; lf++) {
292-
if (block.fn_map[lf] != pcifunc)
293-
continue;
369+
get_lf_str_list(block, pcifunc, lfs);
370+
if (strlen(lfs))
294371
flag = 1;
295-
len += sprintf(&lfs[len], "%d,", lf);
296-
}
297372

298-
if (flag)
299-
len--;
300-
lfs[len] = '\0';
301373
off += scnprintf(&buf[off], buf_size - 1 - off,
302374
"%-*s", lf_str_size, lfs);
303-
if (!strlen(lfs))
304-
go_back += lf_str_size;
305375
}
306-
if (!flag)
307-
off -= go_back;
308-
else
309-
flag = 0;
310-
off--;
311-
off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
376+
if (flag) {
377+
off += scnprintf(&buf[off],
378+
buf_size - 1 - off, "\n");
379+
bytes_not_copied = copy_to_user(buffer +
380+
(i * off),
381+
buf, off);
382+
if (bytes_not_copied)
383+
goto out;
384+
385+
i++;
386+
*ppos += off;
387+
}
312388
}
313389
}
314390

315-
bytes_not_copied = copy_to_user(buffer, buf, off);
391+
out:
316392
kfree(lfs);
317393
kfree(buf);
318-
319394
if (bytes_not_copied)
320395
return -EFAULT;
321396

322-
*ppos = off;
323-
return off;
397+
return *ppos;
324398
}
325399

326400
RVU_DEBUG_FOPS(rsrc_status, rsrc_attach_status, NULL);
@@ -504,7 +578,7 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
504578
if (cmd_buf)
505579
ret = -EINVAL;
506580

507-
if (!strncmp(subtoken, "help", 4) || ret < 0) {
581+
if (ret < 0 || !strncmp(subtoken, "help", 4)) {
508582
dev_info(rvu->dev, "Use echo <%s-lf > qsize\n", blk_string);
509583
goto qsize_write_done;
510584
}
@@ -1719,6 +1793,10 @@ static int rvu_dbg_nix_band_prof_ctx_display(struct seq_file *m, void *unused)
17191793
u16 pcifunc;
17201794
char *str;
17211795

1796+
/* Ingress policers do not exist on all platforms */
1797+
if (!nix_hw->ipolicer)
1798+
return 0;
1799+
17221800
for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {
17231801
if (layer == BAND_PROF_INVAL_LAYER)
17241802
continue;
@@ -1768,6 +1846,10 @@ static int rvu_dbg_nix_band_prof_rsrc_display(struct seq_file *m, void *unused)
17681846
int layer;
17691847
char *str;
17701848

1849+
/* Ingress policers do not exist on all platforms */
1850+
if (!nix_hw->ipolicer)
1851+
return 0;
1852+
17711853
seq_puts(m, "\nBandwidth profile resource free count\n");
17721854
seq_puts(m, "=====================================\n");
17731855
for (layer = 0; layer < BAND_PROF_NUM_LAYERS; layer++) {

drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,9 @@ static void nix_free_tx_vtag_entries(struct rvu *rvu, u16 pcifunc)
25072507
return;
25082508

25092509
nix_hw = get_nix_hw(rvu->hw, blkaddr);
2510+
if (!nix_hw)
2511+
return;
2512+
25102513
vlan = &nix_hw->txvlan;
25112514

25122515
mutex_lock(&vlan->rsrc_lock);

0 commit comments

Comments
 (0)