BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Brendan Jackman <jackmanb@google.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Florent Revest <revest@chromium.org>,
	linux-kernel@vger.kernel.org,
	Brendan Jackman <jackmanb@google.com>
Subject: [PATCH bpf-next v5 11/11] bpf: Document new atomic instructions
Date: Tue, 15 Dec 2020 12:18:16 +0000
Message-ID: <20201215121816.1048557-13-jackmanb@google.com> (raw)
In-Reply-To: <20201215121816.1048557-1-jackmanb@google.com>

Document new atomic instructions.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 Documentation/networking/filter.rst | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 1583d59d806d..26d508a5e038 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1053,6 +1053,32 @@ encoding.
    .imm = BPF_ADD, .code = BPF_ATOMIC | BPF_W  | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg
    .imm = BPF_ADD, .code = BPF_ATOMIC | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg
 
+The basic atomic operations supported (from architecture v4 onwards) are:
+
+    BPF_ADD
+    BPF_AND
+    BPF_OR
+    BPF_XOR
+
+Each having equivalent semantics with the ``BPF_ADD`` example, that is: the
+memory location addresed by ``dst_reg + off`` is atomically modified, with
+``src_reg`` as the other operand. If the ``BPF_FETCH`` flag is set in the
+immediate, then these operations also overwrite ``src_reg`` with the
+value that was in memory before it was modified.
+
+The more special operations are:
+
+    BPF_XCHG
+
+This atomically exchanges ``src_reg`` with the value addressed by ``dst_reg +
+off``.
+
+    BPF_CMPXCHG
+
+This atomically compares the value addressed by ``dst_reg + off`` with
+``R0``. If they match it is replaced with ``src_reg``, The value that was there
+before is loaded back to ``R0``.
+
 Note that 1 and 2 byte atomic operations are not supported.
 
 You may encounter BPF_XADD - this is a legacy name for BPF_ATOMIC, referring to
-- 
2.29.2.684.gfbc64c5ab5-goog


  parent reply index

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 12:18 [PATCH bpf-next v4 00/11] Atomics for eBPF Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 01/11] bpf: x86: Factor out emission of ModR/M for *(reg + off) Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v2] libbpf: Expose libbpf ringbufer epoll_fd Brendan Jackman
2020-12-15 18:35   ` Andrii Nakryiko
2020-12-15 12:18 ` [PATCH bpf-next v5 02/11] bpf: x86: Factor out emission of REX byte Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 03/11] bpf: x86: Factor out a lookup table for some ALU opcodes Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 04/11] bpf: Rename BPF_XADD and prepare to encode other atomics in .imm Brendan Jackman
2020-12-15 14:05   ` Björn Töpel
2020-12-15 12:18 ` [PATCH bpf-next v5 05/11] bpf: Move BPF_STX reserved field check into BPF_STX verifier code Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 06/11] bpf: Add BPF_FETCH field / create atomic_fetch_add instruction Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 07/11] bpf: Add instructions for atomic_[cmp]xchg Brendan Jackman
2020-12-16  6:47   ` Yonghong Song
2020-12-15 12:18 ` [PATCH bpf-next v5 08/11] bpf: Pull out a macro for interpreting atomic ALU operations Brendan Jackman
2020-12-15 12:18 ` [PATCH bpf-next v5 09/11] bpf: Add bitwise atomic instructions Brendan Jackman
2020-12-16  6:53   ` Yonghong Song
2020-12-15 12:18 ` [PATCH bpf-next v5 10/11] bpf: Add tests for new BPF atomic operations Brendan Jackman
2020-12-15 12:18 ` Brendan Jackman [this message]
2020-12-16  7:08   ` [PATCH bpf-next v5 11/11] bpf: Document new atomic instructions Yonghong Song
2020-12-16 11:44     ` Brendan Jackman
2020-12-16 15:25       ` Yonghong Song

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=20201215121816.1048557-13-jackmanb@google.com \
    --to=jackmanb@google.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=revest@chromium.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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git