Commit 9080517
bpf: Adjust BPF stack helper functions to accommodate skip > 0
commit ee2a098 upstream.
Let's say that the caller has storage for num_elem stack frames. Then,
the BPF stack helper functions walk the stack for only num_elem frames.
This means that if skip > 0, one keeps only 'num_elem - skip' frames.
This is because it sets init_nr in the perf_callchain_entry to the end
of the buffer to save num_elem entries only. I believe it was because
the perf callchain code unwound the stack frames until it reached the
global max size (sysctl_perf_event_max_stack).
However it now has perf_callchain_entry_ctx.max_stack to limit the
iteration locally. This simplifies the code to handle init_nr in the
BPF callstack entries and removes the confusion with the perf_event's
__PERF_SAMPLE_CALLCHAIN_EARLY which sets init_nr to 0.
Also change the comment on bpf_get_stack() in the header file to be
more explicit what the return value means.
Fixes: c195651 ("bpf: add bpf_get_stack helper")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/30a7b5d5-6726-1cc2-eaee-8da2828a9a9c@oracle.com
Link: https://lore.kernel.org/bpf/20220314182042.71025-1-namhyung@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Based-on-patch-by: Eugene Loh <eugene.loh@oracle.com>1 parent 8648949 commit 9080517
2 files changed
Lines changed: 28 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2163 | 2163 | | |
2164 | 2164 | | |
2165 | 2165 | | |
2166 | | - | |
2167 | | - | |
| 2166 | + | |
| 2167 | + | |
2168 | 2168 | | |
2169 | 2169 | | |
2170 | 2170 | | |
| |||
3448 | 3448 | | |
3449 | 3449 | | |
3450 | 3450 | | |
3451 | | - | |
3452 | | - | |
| 3451 | + | |
| 3452 | + | |
3453 | 3453 | | |
3454 | 3454 | | |
3455 | 3455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
373 | | - | |
374 | | - | |
| 372 | + | |
| 373 | + | |
375 | 374 | | |
376 | 375 | | |
377 | 376 | | |
| |||
383 | 382 | | |
384 | 383 | | |
385 | 384 | | |
386 | | - | |
| 385 | + | |
387 | 386 | | |
388 | 387 | | |
389 | 388 | | |
| |||
400 | 399 | | |
401 | 400 | | |
402 | 401 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | 402 | | |
407 | 403 | | |
408 | 404 | | |
409 | 405 | | |
410 | 406 | | |
411 | 407 | | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
| 408 | + | |
418 | 409 | | |
419 | 410 | | |
420 | 411 | | |
421 | | - | |
| 412 | + | |
422 | 413 | | |
423 | | - | |
| 414 | + | |
424 | 415 | | |
425 | 416 | | |
426 | 417 | | |
| |||
477 | 468 | | |
478 | 469 | | |
479 | 470 | | |
480 | | - | |
481 | | - | |
| 471 | + | |
482 | 472 | | |
483 | 473 | | |
484 | 474 | | |
| |||
487 | 477 | | |
488 | 478 | | |
489 | 479 | | |
490 | | - | |
491 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
492 | 486 | | |
493 | 487 | | |
494 | 488 | | |
| |||
579 | 573 | | |
580 | 574 | | |
581 | 575 | | |
582 | | - | |
| 576 | + | |
583 | 577 | | |
584 | 578 | | |
585 | 579 | | |
| |||
604 | 598 | | |
605 | 599 | | |
606 | 600 | | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
611 | 604 | | |
612 | 605 | | |
613 | 606 | | |
614 | 607 | | |
615 | | - | |
| 608 | + | |
616 | 609 | | |
617 | | - | |
618 | | - | |
| 610 | + | |
619 | 611 | | |
620 | 612 | | |
621 | 613 | | |
622 | 614 | | |
623 | | - | |
624 | | - | |
| 615 | + | |
625 | 616 | | |
626 | 617 | | |
627 | | - | |
| 618 | + | |
628 | 619 | | |
629 | 620 | | |
630 | | - | |
| 621 | + | |
| 622 | + | |
631 | 623 | | |
632 | 624 | | |
633 | 625 | | |
| |||
0 commit comments