From: Ahmad Wicaksono <supersonix03@gmail.com>
To: bpf@vger.kernel.org
Cc: jakub@cloudflare.com, mhal@rbox.co, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, corbet@lwn.net,
skhan@linuxfoundation.org, rdunlap@infradead.org,
davem@davemloft.net, kuba@kernel.org, hawk@kernel.org,
john.fastabend@gmail.com, sdf@fomichev.me,
linux-doc@vger.kernel.org, netdev@vger.kernel.org,
Ahmad Wicaksono <supersonix03@gmail.com>
Subject: [PATCH bpf-next v2 1/2] Documentation/bpf: Update sockmap docs for mutation restrictions
Date: Mon, 23 Nov 2026 22:51:59 +0700 [thread overview]
Message-ID: <20261123155200.16676-2-supersonix03@gmail.com> (raw)
In-Reply-To: <20261123155200.16676-1-supersonix03@gmail.com>
Commit be39165224d0 ("bpf, sockmap: Disallow update and delete from tc,
xdp, socket_filter and flow_dissector") dropped those program types from
may_update_sockmap(), so tc, tc act, XDP, socket_filter and
flow_dissector programs can no longer call bpf_map_update_elem() or
bpf_map_delete_elem() on a sockmap or sockhash; the verifier rejects
them at load time with "cannot update sockmap in this context".
Commit 18f6c47d1097 ("bpf, sockmap: Restrict iter-context sockmap
updates to iter/sockmap") then narrowed the tracing case to programs
attached to the sockmap iterator. The kernel-side sections of
map_sockmap.rst mention none of this.
Record which program types may still mutate these maps, and note that
sock_ops programs may delete entries but have to use
bpf_sock_map_update() or bpf_sock_hash_update() to add them.
Also drop the reference to
tools/testing/selftests/bpf/progs/test_sockmap_update.c and its link
target. That file was removed by commit 5de7a6eaed89 ("selftests/bpf:
Drop tc/xdp/flow_dissector/socket_filter sockmap mutation tests").
Signed-off-by: Ahmad Wicaksono <supersonix03@gmail.com>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
---
v2: Only sockmap iterator programs (iter/sockmap) may update, after
commit 18f6c47d1097. (Alexei)
Documentation/bpf/map_sockmap.rst | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/Documentation/bpf/map_sockmap.rst b/Documentation/bpf/map_sockmap.rst
index eb466b86d..0b7fdfca3 100644
--- a/Documentation/bpf/map_sockmap.rst
+++ b/Documentation/bpf/map_sockmap.rst
@@ -287,6 +287,16 @@ The flags argument can be one of the following:
Returns 0 on success, or a negative error in case of failure.
+.. note::
+ The verifier only accepts this helper on a sockmap or sockhash from
+ ``BPF_PROG_TYPE_SK_REUSEPORT`` and ``BPF_PROG_TYPE_SK_LOOKUP``
+ programs, and from ``BPF_PROG_TYPE_TRACING`` programs attached to
+ the sockmap iterator (``SEC(iter/sockmap)``). Other program types,
+ such as tc, XDP, socket_filter and flow_dissector, are rejected at
+ load time with "cannot update sockmap in this context".
+ ``BPF_PROG_TYPE_SOCK_OPS`` programs must use
+ ``bpf_sock_map_update()`` or ``bpf_sock_hash_update()`` instead.
+
bpf_map_delete_elem()
^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: c
@@ -297,6 +307,12 @@ Delete a socket entry from a sockmap or a sockhash.
Returns 0 on success, or a negative error in case of failure.
+.. note::
+ The same program type restriction as for ``bpf_map_update_elem()``
+ applies, except that ``BPF_PROG_TYPE_SOCK_OPS`` programs may delete
+ entries. Other program types are rejected at load time with
+ "cannot update sockmap in this context".
+
User space
----------
bpf_map_update_elem()
@@ -351,7 +367,6 @@ Several examples of the use of sockmap APIs can be found in:
- `tools/testing/selftests/bpf/progs/sockmap_parse_prog.c`_
- `tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c`_
- `tools/testing/selftests/bpf/progs/test_sockmap_listen.c`_
-- `tools/testing/selftests/bpf/progs/test_sockmap_update.c`_
The following code snippet shows how to declare a sockmap.
@@ -497,4 +512,3 @@ References
.. _`tools/testing/selftests/bpf/test_sockmap.c`: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/test_sockmap.c
.. _`tools/testing/selftests/bpf/test_maps.c`: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/test_maps.c
.. _`tools/testing/selftests/bpf/progs/test_sockmap_listen.c`: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/progs/test_sockmap_listen.c
-.. _`tools/testing/selftests/bpf/progs/test_sockmap_update.c`: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/progs/test_sockmap_update.c
--
2.43.0
next prev parent reply other threads:[~2026-11-23 15:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:51 [PATCH bpf-next v2 0/2] Documentation/bpf: Fix stale references in map docs Ahmad Wicaksono
2026-11-23 15:51 ` Ahmad Wicaksono [this message]
2026-11-23 15:52 ` [PATCH bpf-next v2 2/2] Documentation/bpf: Fix stale selftests file references Ahmad Wicaksono
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=20261123155200.16676-2-supersonix03@gmail.com \
--to=supersonix03@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mhal@rbox.co \
--cc=netdev@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=sdf@fomichev.me \
--cc=skhan@linuxfoundation.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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