linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / 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,
	"Björn Töpel" <bjorn.topel@gmail.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Yonghong Song" <yhs@fb.com>,
	"Brendan Jackman" <jackmanb@google.com>
Subject: [PATCH bpf-next v6 11/11] bpf: Document new atomic instructions
Date: Tue, 12 Jan 2021 15:42:35 +0000	[thread overview]
Message-ID: <20210112154235.2192781-12-jackmanb@google.com> (raw)
In-Reply-To: <20210112154235.2192781-1-jackmanb@google.com>

Document new atomic instructions.

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

diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 1583d59d806d..f6d8f90e9a56 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1053,8 +1053,39 @@ 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 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.
 
+Except ``BPF_ADD`` _without_ ``BPF_FETCH`` (for legacy reasons), all 4 byte
+atomic operations require alu32 mode. Clang enables this mode by default in
+architecture v3 (``-mcpu=v3``). For older versions it can be enabled with
+``-Xclang -target-feature -Xclang +alu32``.
+
 You may encounter BPF_XADD - this is a legacy name for BPF_ATOMIC, referring to
 the exclusive-add operation encoded when the immediate field is zero.
 
-- 
2.30.0.284.gd98b1dd5eaa7-goog


  parent reply	other threads:[~2021-01-12 15:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 15:42 [PATCH bpf-next v6 00/11] Atomics for eBPF Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 01/11] bpf: x86: Factor out emission of ModR/M for *(reg + off) Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 02/11] bpf: x86: Factor out emission of REX byte Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 03/11] bpf: x86: Factor out a lookup table for some ALU opcodes Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 04/11] bpf: Rename BPF_XADD and prepare to encode other atomics in .imm Brendan Jackman
2021-01-13  2:20   ` kernel test robot
2021-01-12 15:42 ` [PATCH bpf-next v6 05/11] bpf: Move BPF_STX reserved field check into BPF_STX verifier code Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 06/11] bpf: Add BPF_FETCH field / create atomic_fetch_add instruction Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 07/11] bpf: Add instructions for atomic_[cmp]xchg Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 08/11] bpf: Pull out a macro for interpreting atomic ALU operations Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 09/11] bpf: Add bitwise atomic instructions Brendan Jackman
2021-01-12 15:42 ` [PATCH bpf-next v6 10/11] bpf: Add tests for new BPF atomic operations Brendan Jackman
2021-01-12 15:42 ` Brendan Jackman [this message]
2021-01-14  3:22 ` [PATCH bpf-next v6 00/11] Atomics for eBPF Alexei Starovoitov
2021-01-14  8:09 ` John Fastabend

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=20210112154235.2192781-12-jackmanb@google.com \
    --to=jackmanb@google.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=revest@chromium.org \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).