Skip to content

Commit eebd3fa

Browse files
committed
Merge branch 'nfp-improve-the-new-rtsym-helpers'
Jakub Kicinski says: ==================== nfp: improve the new rtsym helpers This set fixes a bug in ABS rtsym handling I added in net-next, it expands the error checking and reporting on the rtsym accesses. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9e7e6ca + e84b2f2 commit eebd3fa

File tree

1 file changed

+60
-15
lines changed

1 file changed

+60
-15
lines changed

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* Espen Skoglund <[email protected]>
4040
* Francois H. Theron <[email protected]>
4141
*/
42+
43+
#include <asm/unaligned.h>
4244
#include <linux/kernel.h>
4345
#include <linux/module.h>
4446
#include <linux/slab.h>
@@ -237,10 +239,10 @@ u64 nfp_rtsym_size(const struct nfp_rtsym *sym)
237239
{
238240
switch (sym->type) {
239241
case NFP_RTSYM_TYPE_NONE:
240-
pr_err("rtsym type NONE\n");
242+
pr_err("rtsym '%s': type NONE\n", sym->name);
241243
return 0;
242244
default:
243-
pr_warn("Unknown rtsym type: %d\n", sym->type);
245+
pr_warn("rtsym '%s': unknown type: %d\n", sym->name, sym->type);
244246
/* fall through */
245247
case NFP_RTSYM_TYPE_OBJECT:
246248
case NFP_RTSYM_TYPE_FUNCTION:
@@ -255,7 +257,8 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
255257
u8 action, u8 token, u64 off, u32 *cpp_id, u64 *addr)
256258
{
257259
if (sym->type != NFP_RTSYM_TYPE_OBJECT) {
258-
nfp_err(cpp, "Direct access attempt to non-object rtsym\n");
260+
nfp_err(cpp, "rtsym '%s': direct access to non-object rtsym\n",
261+
sym->name);
259262
return -EINVAL;
260263
}
261264

@@ -270,8 +273,8 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
270273
*cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU, action, token,
271274
sym->domain);
272275
} else if (sym->target < 0) {
273-
nfp_err(cpp, "Unhandled RTsym target encoding: %d\n",
274-
sym->target);
276+
nfp_err(cpp, "rtsym '%s': unhandled target encoding: %d\n",
277+
sym->name, sym->target);
275278
return -EINVAL;
276279
} else {
277280
*cpp_id = NFP_CPP_ISLAND_ID(sym->target, action, token,
@@ -284,15 +287,23 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
284287
int __nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
285288
u8 action, u8 token, u64 off, void *buf, size_t len)
286289
{
290+
u64 sym_size = nfp_rtsym_size(sym);
287291
u32 cpp_id;
288292
u64 addr;
289293
int err;
290294

295+
if (off > sym_size) {
296+
nfp_err(cpp, "rtsym '%s': read out of bounds: off: %lld + len: %zd > size: %lld\n",
297+
sym->name, off, len, sym_size);
298+
return -ENXIO;
299+
}
300+
len = min_t(size_t, len, sym_size - off);
301+
291302
if (sym->type == NFP_RTSYM_TYPE_ABS) {
292-
__le64 tmp = cpu_to_le64(sym->addr);
303+
u8 tmp[8];
293304

294-
len = min(len, sizeof(tmp));
295-
memcpy(buf, &tmp, len);
305+
put_unaligned_le64(sym->addr, tmp);
306+
memcpy(buf, &tmp[off], len);
296307

297308
return len;
298309
}
@@ -317,6 +328,12 @@ int __nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
317328
u64 addr;
318329
int err;
319330

331+
if (off + 4 > nfp_rtsym_size(sym)) {
332+
nfp_err(cpp, "rtsym '%s': readl out of bounds: off: %lld + 4 > size: %lld\n",
333+
sym->name, off, nfp_rtsym_size(sym));
334+
return -ENXIO;
335+
}
336+
320337
err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
321338
if (err)
322339
return err;
@@ -337,8 +354,16 @@ int __nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
337354
u64 addr;
338355
int err;
339356

340-
if (sym->type == NFP_RTSYM_TYPE_ABS)
341-
return sym->addr;
357+
if (off + 8 > nfp_rtsym_size(sym)) {
358+
nfp_err(cpp, "rtsym '%s': readq out of bounds: off: %lld + 8 > size: %lld\n",
359+
sym->name, off, nfp_rtsym_size(sym));
360+
return -ENXIO;
361+
}
362+
363+
if (sym->type == NFP_RTSYM_TYPE_ABS) {
364+
*value = sym->addr;
365+
return 0;
366+
}
342367

343368
err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
344369
if (err)
@@ -356,10 +381,18 @@ int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
356381
int __nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
357382
u8 action, u8 token, u64 off, void *buf, size_t len)
358383
{
384+
u64 sym_size = nfp_rtsym_size(sym);
359385
u32 cpp_id;
360386
u64 addr;
361387
int err;
362388

389+
if (off > sym_size) {
390+
nfp_err(cpp, "rtsym '%s': write out of bounds: off: %lld + len: %zd > size: %lld\n",
391+
sym->name, off, len, sym_size);
392+
return -ENXIO;
393+
}
394+
len = min_t(size_t, len, sym_size - off);
395+
363396
err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
364397
if (err)
365398
return err;
@@ -380,6 +413,12 @@ int __nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
380413
u64 addr;
381414
int err;
382415

416+
if (off + 4 > nfp_rtsym_size(sym)) {
417+
nfp_err(cpp, "rtsym '%s': writel out of bounds: off: %lld + 4 > size: %lld\n",
418+
sym->name, off, nfp_rtsym_size(sym));
419+
return -ENXIO;
420+
}
421+
383422
err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
384423
if (err)
385424
return err;
@@ -400,6 +439,12 @@ int __nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
400439
u64 addr;
401440
int err;
402441

442+
if (off + 8 > nfp_rtsym_size(sym)) {
443+
nfp_err(cpp, "rtsym '%s': writeq out of bounds: off: %lld + 8 > size: %lld\n",
444+
sym->name, off, nfp_rtsym_size(sym));
445+
return -ENXIO;
446+
}
447+
403448
err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
404449
if (err)
405450
return err;
@@ -449,7 +494,7 @@ u64 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name,
449494
break;
450495
default:
451496
nfp_err(rtbl->cpp,
452-
"rtsym '%s' unsupported or non-scalar size: %lld\n",
497+
"rtsym '%s': unsupported or non-scalar size: %lld\n",
453498
name, nfp_rtsym_size(sym));
454499
err = -EINVAL;
455500
break;
@@ -495,7 +540,7 @@ int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name,
495540
break;
496541
default:
497542
nfp_err(rtbl->cpp,
498-
"rtsym '%s' unsupported or non-scalar size: %lld\n",
543+
"rtsym '%s': unsupported or non-scalar size: %lld\n",
499544
name, nfp_rtsym_size(sym));
500545
err = -EINVAL;
501546
break;
@@ -521,18 +566,18 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, const char *id,
521566
err = nfp_rtsym_to_dest(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0,
522567
&cpp_id, &addr);
523568
if (err) {
524-
nfp_err(rtbl->cpp, "Symbol %s mapping failed\n", name);
569+
nfp_err(rtbl->cpp, "rtsym '%s': mapping failed\n", name);
525570
return (u8 __iomem *)ERR_PTR(err);
526571
}
527572

528573
if (sym->size < min_size) {
529-
nfp_err(rtbl->cpp, "Symbol %s too small\n", name);
574+
nfp_err(rtbl->cpp, "rtsym '%s': too small\n", name);
530575
return (u8 __iomem *)ERR_PTR(-EINVAL);
531576
}
532577

533578
mem = nfp_cpp_map_area(rtbl->cpp, id, cpp_id, addr, sym->size, area);
534579
if (IS_ERR(mem)) {
535-
nfp_err(rtbl->cpp, "Failed to map symbol %s: %ld\n",
580+
nfp_err(rtbl->cpp, "rtysm '%s': failed to map: %ld\n",
536581
name, PTR_ERR(mem));
537582
return mem;
538583
}

0 commit comments

Comments
 (0)