All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Marat Khalili <marat.khalili@huawei.com>
Cc: <dev@dpdk.org>
Subject: Re: [PATCH v2 0/7] validate-bpf: add standalone validation debug tool
Date: Mon, 14 Sep 2026 11:42:29 -0700	[thread overview]
Message-ID: <20260914114229.61d5e94c@phoenix.local> (raw)
In-Reply-To: <20260914145418.37353-1-marat.khalili@huawei.com>

On Mon, 14 Sep 2026 15:54:10 +0100
Marat Khalili <marat.khalili@huawei.com> wrote:

> This patchset introduces a new standalone tool for pre-validating eBPF
> programs and debugging validation problems. Its should allow developers
> to trace validator state changes per instruction and understand verifier
> decisions, simplifying the debugging of rejected programs before loading
> them into a real application context.
> 
> v2:
> * for FreeBSD compatibility switched from Linux to DPDK network structs;
> * addressed small AI comments:
>   * clarified patch 1 commit message;
>   * renamed `rte_validate_bpf_logtype` to `validate_bpf_logtype`;
>   * corrected comment to an internal-use-only function to reflect that
>     next-after-last value of the program counter is no longer allowed;
> 
> Marat Khalili (7):
>   bpf/validate: fix finished status on restart
>   bpf/validate: refactor internal step function
>   bpf/validate: formalize call back requirements
>   bpf/validate: add jump notification events
>   bpf/validate: add get current event API
>   app/test: add test for bpf validate debug events
>   app/validate-bpf: add BPF validation application
> 
>  MAINTAINERS                            |    2 +
>  app/meson.build                        |    1 +
>  app/test/test_bpf_validate.c           |  341 +++++++-
>  app/validate-bpf/alloc_list.c          |   53 ++
>  app/validate-bpf/args.c                |  263 ++++++
>  app/validate-bpf/debug.c               | 1099 ++++++++++++++++++++++++
>  app/validate-bpf/debug_command.c       |  383 +++++++++
>  app/validate-bpf/debug_command.h       |   65 ++
>  app/validate-bpf/eal_init_args.c       |   57 ++
>  app/validate-bpf/internal.h            |  151 ++++
>  app/validate-bpf/main.c                |   77 ++
>  app/validate-bpf/meson.build           |   13 +
>  app/validate-bpf/parse_decl.c          |  611 +++++++++++++
>  doc/guides/rel_notes/release_26_11.rst |    5 +
>  doc/guides/tools/index.rst             |    1 +
>  doc/guides/tools/validate_bpf.rst      |   97 +++
>  lib/bpf/bpf_validate.c                 |   49 +-
>  lib/bpf/bpf_validate_debug.c           |   92 +-
>  lib/bpf/bpf_validate_debug.h           |   12 +-
>  lib/bpf/rte_bpf_validate_debug.h       |   42 +-
>  20 files changed, 3348 insertions(+), 66 deletions(-)
>  create mode 100644 app/validate-bpf/alloc_list.c
>  create mode 100644 app/validate-bpf/args.c
>  create mode 100644 app/validate-bpf/debug.c
>  create mode 100644 app/validate-bpf/debug_command.c
>  create mode 100644 app/validate-bpf/debug_command.h
>  create mode 100644 app/validate-bpf/eal_init_args.c
>  create mode 100644 app/validate-bpf/internal.h
>  create mode 100644 app/validate-bpf/main.c
>  create mode 100644 app/validate-bpf/meson.build
>  create mode 100644 app/validate-bpf/parse_decl.c
>  create mode 100644 doc/guides/tools/validate_bpf.rst
> 

Looks good to me, but AI had some nits to pick.

Re: [PATCH v2 0/7] bpf/validate: debug events and validation app

Errors
------

Patch 7/7 (app/validate-bpf: add BPF validation application)

  app/validate-bpf/parse_decl.c:

    +		arg->value.size *= array_length;

  array_length comes from take_number() on the --xsym text with no
  upper bound, and the multiply is not checked for overflow, so a
  large length silently wraps to a small size that is then reported
  to the validator as the object size.  Reproduced:

    dpdk-validate-bpf --xsym='uint64_t[2305843009213693953] v' \
        --section=.text prog.o
    Validation succeeded.

  8 * 2305843009213693953 wraps to 8, so the tool accepts the
  declaration and describes an 8-byte object.  Clamp array_length,
  or check the product, and reject with the usual text error.

Warnings
--------

Patch 5/7 (bpf/validate: add get current event API)

  lib/bpf/bpf_validate_debug.c:

    +		return -EINVAL;

  in rte_bpf_validate_debug_get_event(), whose return type is
  enum rte_bpf_validate_debug_event.  Every enumerator in that enum
  is non-negative, so the compatible type is unsigned and -EINVAL
  arrives at the caller as 4294967274.  It equals no enumerator,
  including RTE_BPF_VALIDATE_DEBUG_EVENT_END, so a caller cannot
  test for it.  Either return
  RTE_BPF_VALIDATE_DEBUG_EVENT_END for the NULL case and say so in
  the doc comment, or change the signature to return int with the
  event in an out-parameter.

Patch 7/7

  app/validate-bpf/parse_decl.c:

    +	void * const val = calloc(1, RTE_MAX(1u, arg.value.size));
    +	RTE_VERIFY(val != 0);

  arg.value.size is user-supplied, so an allocation failure driven by
  the command line aborts with a core dump instead of an error
  message.  Reproduced:

    dpdk-validate-bpf --xsym='uint64_t[18446744073709551615] v' \
        --section=.text prog.o
    EAL: PANIC in fill_var_xsym():
    line 427	assert "val != 0" failed

  Return an error up through the parse path like the other --xsym
  failures do.

  app/validate-bpf/main.c:

    +	RTE_VERIFY(rte_eal_init(eal_init_argc, eal_init_argv) ==
    +		eal_init_argc - 1);

  rte_eal_init() returns -1 for ordinary environmental failures such
  as a missing runtime directory or insufficient permissions.  For a
  command-line tool that should be a message and a non-zero exit, not
  rte_panic().  Same for

    +	RTE_VERIFY(rte_eal_cleanup() == 0);

  app/validate-bpf/eal_init_args.c:

    +#define RTE_EAL_INIT_ARG_SIZE_MAX sizeof("--log-level=lib.eal:warning")

  and RTE_EAL_INIT_ARGS / RTE_EAL_INIT_ARGC below it.  The RTE_
  prefix is reserved for the libraries; an application should not
  define into it.  Drop the prefix.

Info
----

Patch 5/7

  debug->current_event is set only in debug_send_event().  A
  breakpoint callback reached through debug_trigger_breakpoints()
  therefore sees whatever event fired last.  The doc comment says the
  value is undefined when no event is being processed, so this is
  consistent, but a callback shared between a breakpoint and a
  catchpoint will read a stale event rather than an obviously invalid
  one.

  rte_bpf_validate_debug_get_event() is new public experimental API
  and gets no release note.  7/7 adds a release note, but only for
  the application.

Patch 7/7

  In --debug mode the result is printed twice: debug.c prints
  "Validation succeeded." to stdout from the validation-success
  catchpoint, and main.c prints it again to stderr.

  Array declarations are written as "uint64_t[4] v", not the C
  "uint64_t v[4]".  The C spelling is rejected with

    at offset 10: expect '(' or text end

  which does not point at the real problem.  Worth either accepting
  the C form or naming the expected form in the message.  The
  documented form is in --help, so this is a diagnostics nit.

  "uint64_t[0] v" is accepted and yields value.size 0 while calloc
  still allocates one byte.  Probably worth rejecting a zero length.

Verification
------------

Applied on d55ccd4.  Each of the seven commits builds on its own with
-Dwerror=true, so bisect is safe.  bpf_validate_autotest passes 29/29
and the new bpf_validate_events_autotest passes.  valgrind is clean on
the application's normal paths, with no definite leaks.

Checked and found nothing to report: 2/7 is equivalent at all call
sites, so "No functional changes" holds; 3/7's tightening of the pc
check to ">= nb_ins" is consistent with dropping the past-the-end call
from evaluate_finish(); 4/7's nb_edge > 1 test does select exactly the
conditional jumps.

Review-Result: ERROR

  parent reply	other threads:[~2026-09-14 18:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 10:39 [PATCH 0/7] validate-bpf: add standalone validation debug tool Marat Khalili
2026-09-11 10:39 ` [PATCH 1/7] bpf/validate: fix finished status on restart Marat Khalili
2026-09-11 10:40 ` [PATCH 2/7] bpf/validate: refactor internal step function Marat Khalili
2026-09-11 10:40 ` [PATCH 3/7] bpf/validate: formalize call back requirements Marat Khalili
2026-09-11 10:40 ` [PATCH 4/7] bpf/validate: add jump notification events Marat Khalili
2026-09-11 10:40 ` [PATCH 5/7] bpf/validate: add get current event API Marat Khalili
2026-09-11 10:40 ` [PATCH 6/7] app/test: add test for bpf validate debug events Marat Khalili
2026-09-11 10:40 ` [PATCH 7/7] app/validate-bpf: add BPF validation application Marat Khalili
2026-09-14 14:54 ` [PATCH v2 0/7] validate-bpf: add standalone validation debug tool Marat Khalili
2026-09-14 14:54   ` [PATCH v2 1/7] bpf/validate: fix finished status on restart Marat Khalili
2026-09-14 14:54   ` [PATCH v2 2/7] bpf/validate: refactor internal step function Marat Khalili
2026-09-14 14:54   ` [PATCH v2 3/7] bpf/validate: formalize call back requirements Marat Khalili
2026-09-14 14:54   ` [PATCH v2 4/7] bpf/validate: add jump notification events Marat Khalili
2026-09-14 14:54   ` [PATCH v2 5/7] bpf/validate: add get current event API Marat Khalili
2026-09-14 14:54   ` [PATCH v2 6/7] app/test: add test for bpf validate debug events Marat Khalili
2026-09-14 14:54   ` [PATCH v2 7/7] app/validate-bpf: add BPF validation application Marat Khalili
2026-09-14 18:41     ` Stephen Hemminger
2026-09-15 13:13     ` Stephen Hemminger
2026-09-14 18:42   ` Stephen Hemminger [this message]
2026-09-15 19:27     ` [PATCH v2 0/7] validate-bpf: add standalone validation debug tool Marat Khalili
2026-09-15 19:26   ` [PATCH v3 " Marat Khalili
2026-09-15 19:26     ` [PATCH v3 1/7] bpf/validate: fix finished status on restart Marat Khalili
2026-09-15 19:26     ` [PATCH v3 2/7] bpf/validate: refactor internal step function Marat Khalili
2026-09-15 19:26     ` [PATCH v3 3/7] bpf/validate: formalize call back requirements Marat Khalili
2026-09-15 19:26     ` [PATCH v3 4/7] bpf/validate: add jump notification events Marat Khalili
2026-09-15 19:26     ` [PATCH v3 5/7] bpf/validate: add get current event API Marat Khalili
2026-09-15 19:26     ` [PATCH v3 6/7] app/test: add test for bpf validate debug events Marat Khalili
2026-09-15 19:26     ` [PATCH v3 7/7] app/validate-bpf: add BPF validation application Marat Khalili
2026-09-16 16:36       ` Konstantin Ananyev
2026-09-17 14:35     ` [PATCH v4 0/7] validate-bpf: add standalone validation debug tool Marat Khalili
2026-09-17 14:35       ` [PATCH v4 1/7] bpf/validate: fix finished status on restart Marat Khalili
2026-09-17 14:35       ` [PATCH v4 2/7] bpf/validate: refactor internal step function Marat Khalili
2026-09-17 14:35       ` [PATCH v4 3/7] bpf/validate: formalize call back requirements Marat Khalili
2026-09-17 14:35       ` [PATCH v4 4/7] bpf/validate: add jump notification events Marat Khalili
2026-09-17 14:35       ` [PATCH v4 5/7] bpf/validate: add get current event API Marat Khalili
2026-09-17 14:35       ` [PATCH v4 6/7] app/test: add test for bpf validate debug events Marat Khalili
2026-09-17 14:35       ` [PATCH v4 7/7] app/validate-bpf: add BPF validation application Marat Khalili
2026-09-17 16:16       ` [PATCH v4 0/7] validate-bpf: add standalone validation debug tool Konstantin Ananyev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260914114229.61d5e94c@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=marat.khalili@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.