From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com,
eddyz87@gmail.com, Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH RFC v3 04/10] bpf: Add lock-free cell for NMI-safe async operations
Date: Wed, 7 Jan 2026 19:05:37 +0000 [thread overview]
Message-ID: <e4eee776-e9c7-4186-b239-733f81a9ae4a@gmail.com> (raw)
In-Reply-To: <CAP01T77h5caT6EprhREYMNmjTkbBZ9-OT7HkxdnJUNNME2evQQ@mail.gmail.com>
On 1/7/26 18:30, Kumar Kartikeya Dwivedi wrote:
> On Wed, 7 Jan 2026 at 18:49, Mykyta Yatsenko <mykyta.yatsenko5@gmail.com> wrote:
>> From: Mykyta Yatsenko <yatsenko@meta.com>
>>
>> Introduce mpmc_cell, a lock-free cell primitive designed to support
>> concurrent writes to struct in NMI context (only one writer advances),
>> allowing readers to consume consistent snapshot.
>>
>> Implementation details:
>> Double buffering allows writers run concurrently with readers (read
>> from one cell, write to another)
>>
>> The implementation uses a sequence-number-based protocol to enable
>> exclusive writes.
>> * Bit 0 of seq indicates an active writer
>> * Bits 1+ form a generation counter
>> * (seq & 2) >> 1 selects the read cell, write cell is opposite
>> * Writers atomically set bit 0, write to the inactive cell, then
>> increment seq to publish
>> * Readers snapshot seq, read from the active cell, then validate
>> that seq hasn't changed
>>
>> mpmc_cell expects users to pre-allocate double buffers.
>>
>> Key properties:
>> * Writers never block (fail if lost the race to another writer)
>> * Readers never block writers (double buffering), but may require
>> retries if write updates the snapshot concurrently.
>>
>> This will be used by BPF timer and workqueue helpers to defer NMI-unsafe
>> operations (like hrtimer_start()) to irq_work effectively allowing BPF
>> programs to initiate timers and workqueues from NMI context.
>>
>> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
>> ---
> We already have a dual-versioned concurrency control primitive in the
> kernel (seqcount_latch_t). I would just use that instead of
> reinventing it here. I don't see much of a difference except writer
> serialization, which can be done on top of it. If it was already
> considered and discarded for some reason, please add that reason to
> the commit message.
yes, multiple concurrent writers support would is the main difference
between seqcount_latch_t and my implementation. I'll switch to
seqcount_latch_t and external synchronization for writers.
>> [...]
>>
next prev parent reply other threads:[~2026-01-07 19:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 17:49 [PATCH RFC v3 00/10] bpf: Avoid locks in bpf_timer and bpf_wq Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 01/10] bpf: Refactor __bpf_async_set_callback() Mykyta Yatsenko
2026-01-07 18:22 ` bot+bpf-ci
2026-01-09 22:18 ` Andrii Nakryiko
2026-01-13 13:58 ` Mykyta Yatsenko
2026-01-13 16:14 ` Mykyta Yatsenko
2026-01-09 22:18 ` Andrii Nakryiko
2026-01-12 6:47 ` Kumar Kartikeya Dwivedi
2026-01-12 8:12 ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 02/10] bpf: Factor out timer deletion helper Mykyta Yatsenko
2026-01-12 6:51 ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 03/10] bpf: Simplify bpf_timer_cancel() Mykyta Yatsenko
2026-01-07 18:22 ` bot+bpf-ci
2026-01-09 22:19 ` Andrii Nakryiko
2026-01-12 7:29 ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 04/10] bpf: Add lock-free cell for NMI-safe async operations Mykyta Yatsenko
2026-01-07 18:08 ` bot+bpf-ci
2026-01-07 18:30 ` Kumar Kartikeya Dwivedi
2026-01-07 19:05 ` Mykyta Yatsenko [this message]
2026-01-09 1:18 ` Andrii Nakryiko
2026-01-09 18:22 ` Mykyta Yatsenko
2026-01-09 18:47 ` Andrii Nakryiko
2026-01-09 23:51 ` Alexei Starovoitov
2026-01-10 0:03 ` Andrii Nakryiko
2026-01-09 22:19 ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 05/10] bpf: Enable bpf timer and workqueue use in NMI Mykyta Yatsenko
2026-01-07 18:22 ` bot+bpf-ci
2026-01-09 22:19 ` Andrii Nakryiko
2026-01-14 14:53 ` Mykyta Yatsenko
2026-01-15 18:39 ` Andrii Nakryiko
2026-01-15 18:52 ` Mykyta Yatsenko
2026-01-12 8:10 ` Kumar Kartikeya Dwivedi
2026-01-07 17:49 ` [PATCH RFC v3 06/10] bpf: Add verifier support for bpf_timer argument in kfuncs Mykyta Yatsenko
2026-01-09 22:19 ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 07/10] bpf: Introduce bpf_timer_cancel_async() kfunc Mykyta Yatsenko
2026-01-09 22:19 ` Andrii Nakryiko
2026-01-07 17:49 ` [PATCH RFC v3 08/10] selftests/bpf: Refactor timer selftests Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 09/10] selftests/bpf: Add stress test for timer async cancel Mykyta Yatsenko
2026-01-07 17:49 ` [PATCH RFC v3 10/10] selftests/bpf: Verify bpf_timer_cancel_async works Mykyta Yatsenko
2026-01-09 22:19 ` Andrii Nakryiko
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=e4eee776-e9c7-4186-b239-733f81a9ae4a@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kafai@meta.com \
--cc=kernel-team@meta.com \
--cc=memxor@gmail.com \
--cc=yatsenko@meta.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.