BPF List
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <chenyuan_fl@163.com>, <bpf@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
	"Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Shuah Khan" <shuah@kernel.org>,
	"Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>,
	"Yuan Chen" <chenyuan@kylinos.cn>
Subject: Re: [PATCH bpf-next v3 0/4] bpf: Cancel special fields in resizable hashtab on recycle
Date: Fri, 04 Sep 2026 12:49:42 +0200	[thread overview]
Message-ID: <DL6H2DO8O3BZ.3CU50815EL05A@gmail.com> (raw)
In-Reply-To: <20260901062845.1379760-1-chenyuan_fl@163.com>

On Tue Sep 1, 2026 at 8:28 AM CEST, chenyuan_fl wrote:
> From: Yuan Chen <chenyuan@kylinos.cn>
>
> v3 addresses Mykyta's review of v2 [3]. Both comments concern patch 1:
>
>   1. "Could you please double check if this is needed at all? I think
>      bpf_map_free_internal_structs() going to reset special fields to 0,
>      so immediate reuse by __bpf_async_init(), bpf_task_work_schedule()
>      correctly identifies fresh fields."
>      -> Correct: bpf_obj_cancel_fields() resets the timer/workqueue/
>      task_work slots in place (xchg to NULL in bpf_async_cancel_and_free()
>      and bpf_task_work_cancel_and_free()), so no re-initialization is
>      needed on reuse. rhtab_init_map_value() is dropped entirely; the
>      element alloc path now matches htab's non-prealloc path
>      (alloc_htab_elem()), which also performs no explicit init.
>
>   2. "Let's directly call bpf_obj_cancel_fields() here and below, so it
>      is consistent with htab."
>      -> Done: the rhtab_cancel_fields() wrapper is removed and
>      rhtab_delete_elem()/rhtab_map_update_existing() call
>      bpf_obj_cancel_fields() directly.
>

I split out two fixes from this, given Nuoqi's patch was already acked before, I
decided to take that one with Mykyta's ack, and also rewrote commit log and
simplified tests where possible. The remaining issue should be th BTF related
problem, please send that separately, but also simplify it.

The current fix is too convoluted. Just taking extra map BTF refcount for the
dtor record should hopefully suffice.

> The resizable hashtab still eagerly calls bpf_obj_free_fields() on
> element delete/replace, which runs kptr destructors from the caller's
> execution context (unsafe in NMI). This follows the existing discussion
> on RHash special-field recycling (Nuoqi Gui's series [2] and the review
> [1]): patch 1 applies the cancel semantics like hash/array maps
> (a3a81d247651); patch 2 fixes a program-BTF use-after-free in the
> mem-alloc destructor found while testing; patches 3-4 add regression
> tests (NMI update, and per-field delete/re-insert cycles).
>
> Changes since v2 (all from Mykyta's review [3]):
>
>   * Drop rhtab_init_map_value(): bpf_obj_cancel_fields() resets the
>     timer/workqueue/task_work slots to zero on delete, fresh elements
>     come zeroed from the bpf mem allocator, and kptr slots must stay
>     untouched, so no re-initialization is needed (matching htab's
>     non-prealloc path).
>   * Call bpf_obj_cancel_fields() directly instead of a rhtab-specific
>     wrapper, consistent with htab.
>
> [1] https://lore.kernel.org/bpf/DKEVG8ZVJDDQ.2G40FTOIZKU57@gmail.com/
> [2] https://lore.kernel.org/bpf/20260726-f01-23-rhash-cancel-bpf-next-v1-0-6e5e1131d885@mails.tsinghua.edu.cn/
> [3] https://lore.kernel.org/bpf/0560a24d-2cf9-4e5b-aa61-580af1e56de1@gmail.com/
>
> Yuan Chen (4):
>   bpf: Cancel special fields in resizable hashtab on recycle
>   bpf: Fix use-after-free of program BTF in mem-alloc destructor
>   selftests/bpf: Test rhtab kptr recycle from NMI context
>   selftests/bpf: Test rhtab special-field combinations
>
>  kernel/bpf/hashtab.c                               |  98 +++++-
>  .../selftests/bpf/prog_tests/rhtab_fields.c        | 337 ++++++++++++++++++
>  .../testing/selftests/bpf/prog_tests/rhtab_kptr.c  | 184 ++++++++++
>  tools/testing/selftests/bpf/progs/rhtab_fields.c   | 378 +++++++++++++++++++++
>  tools/testing/selftests/bpf/progs/rhtab_kptr.c     | 146 ++++++++
>  tools/testing/selftests/bpf/rhtab_fields_common.h  |  19 ++
>  tools/testing/selftests/bpf/rhtab_kptr_common.h    |   6 +
>  7 files changed, 1152 insertions(+), 16 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/rhtab_fields.c
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/rhtab_kptr.c
>  create mode 100644 tools/testing/selftests/bpf/progs/rhtab_fields.c
>  create mode 100644 tools/testing/selftests/bpf/progs/rhtab_kptr.c
>  create mode 100644 tools/testing/selftests/bpf/rhtab_fields_common.h
>  create mode 100644 tools/testing/selftests/bpf/rhtab_kptr_common.h
>
> --
> 2.54.0


  parent reply	other threads:[~2026-09-04 10:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11  9:55 [PATCH bpf-next 0/2] bpf: Cancel special fields in resizable hashtab on recycle chenyuan_fl
2026-08-11  9:55 ` [PATCH bpf-next 1/2] " chenyuan_fl
2026-08-11 10:50   ` bot+bpf-ci
2026-08-11  9:55 ` [PATCH bpf-next 2/2] selftests/bpf: Test rhtab kptr recycle from NMI context chenyuan_fl
2026-08-11 11:08   ` bot+bpf-ci
2026-08-11 14:22 ` [PATCH bpf-next 0/2] bpf: Cancel special fields in resizable hashtab on recycle Kumar Kartikeya Dwivedi
2026-08-24 14:36   ` [PATCH bpf-next v2 0/4] " chenyuan_fl
2026-08-24 14:36     ` [PATCH 1/4] " chenyuan_fl
2026-08-24 15:00       ` sashiko-bot
2026-08-24 15:42       ` bot+bpf-ci
2026-08-24 16:15       ` Mykyta Yatsenko
2026-09-01  6:28         ` [PATCH bpf-next v3 0/4] " chenyuan_fl
2026-09-01  6:28           ` [PATCH bpf-next v3 1/4] " chenyuan_fl
2026-09-01  6:49             ` sashiko-bot
2026-09-01  7:37             ` bot+bpf-ci
2026-09-01 16:57             ` Mykyta Yatsenko
2026-09-01  6:28           ` [PATCH bpf-next v3 2/4] bpf: Fix use-after-free of program BTF in mem-alloc destructor chenyuan_fl
2026-09-01 17:10             ` Mykyta Yatsenko
2026-09-01  6:28           ` [PATCH bpf-next v3 3/4] selftests/bpf: Test rhtab kptr recycle from NMI context chenyuan_fl
2026-09-01  6:40             ` sashiko-bot
2026-09-01  7:37             ` bot+bpf-ci
2026-09-01  6:28           ` [PATCH bpf-next v3 4/4] selftests/bpf: Test rhtab special-field combinations chenyuan_fl
2026-09-01  6:41             ` sashiko-bot
2026-09-01  7:37             ` bot+bpf-ci
2026-09-04 10:49           ` Kumar Kartikeya Dwivedi [this message]
2026-08-24 14:36     ` [PATCH 2/4] bpf: Fix use-after-free of program BTF in mem-alloc destructor chenyuan_fl
2026-08-24 15:17       ` sashiko-bot
2026-08-24 15:42       ` bot+bpf-ci
2026-08-24 14:36     ` [PATCH 3/4] selftests/bpf: Test rhtab kptr recycle from NMI context chenyuan_fl
2026-08-24 15:28       ` sashiko-bot
2026-08-24 15:42       ` bot+bpf-ci
2026-08-24 14:36     ` [PATCH 4/4] selftests/bpf: Test rhtab special-field combinations chenyuan_fl
2026-08-24 15:40       ` sashiko-bot
2026-08-24 15:42       ` bot+bpf-ci

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=DL6H2DO8O3BZ.3CU50815EL05A@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyuan@kylinos.cn \
    --cc=chenyuan_fl@163.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=gnq25@mails.tsinghua.edu.cn \
    --cc=ihor.solodrai@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=shuah@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox