2021-01-18 16:05:28

by Brendan Jackman

[permalink] [raw]
Subject: [PATCH bpf-next v2 0/2] BPF docs fixups

Difference from v1->v2 [1]:

* Split into 2 patches

* Avoided unnecessary ': ::' in .rst source

* Tweaked wording of the -mcpu=v3 bit a little more

[1] https://lore.kernel.org/bpf/CA+i-1C1LVKjfQLBYk6siiqhxfy0jCR7UBcAmJ4jCED0A9aWsxA@mail.gmail.com/T/#t

Brendan Jackman (2):
docs: bpf: Fixup atomics markup
docs: bpf: Clarify -mcpu=v3 requirement for atomic ops

Documentation/networking/filter.rst | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)


base-commit: 232164e041e925a920bfd28e63d5233cfad90b73
--
2.30.0.284.gd98b1dd5eaa7-goog


2021-01-18 16:18:06

by Brendan Jackman

[permalink] [raw]
Subject: [PATCH bpf-next v2 2/2] docs: bpf: Clarify -mcpu=v3 requirement for atomic ops

Alexei pointed out [1] that this wording is pretty confusing. Here's
an attempt to be more explicit and clear.

[1] https://lore.kernel.org/bpf/CAADnVQJVvwoZsE1K+6qRxzF7+6CvZNzygnoBW9tZNWJELk5c=Q@mail.gmail.com/T/#m07264fc18fdc43af02fc1320968afefcc73d96f4

Signed-off-by: Brendan Jackman <[email protected]>
---
Documentation/networking/filter.rst | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index 4c2bb4c6364d..b3f457802836 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1081,9 +1081,10 @@ 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
+Clang can generate atomic instructions by default when ``-mcpu=v3`` is
+enabled. If a lower version for ``-mcpu`` is set, the only atomic instruction
+Clang can generate is ``BPF_ADD`` *without* ``BPF_FETCH``. If you need to enable
+the atomics features, while keeping a lower ``-mcpu`` version, you can use
``-Xclang -target-feature -Xclang +alu32``.

You may encounter ``BPF_XADD`` - this is a legacy name for ``BPF_ATOMIC``,
--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-18 17:42:34

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 2/2] docs: bpf: Clarify -mcpu=v3 requirement for atomic ops



On 1/18/21 7:57 AM, Brendan Jackman wrote:
> Alexei pointed out [1] that this wording is pretty confusing. Here's
> an attempt to be more explicit and clear.
>
> [1] https://lore.kernel.org/bpf/CAADnVQJVvwoZsE1K+6qRxzF7+6CvZNzygnoBW9tZNWJELk5c=Q@mail.gmail.com/T/#m07264fc18fdc43af02fc1320968afefcc73d96f4
>
> Signed-off-by: Brendan Jackman <[email protected]>

Thanks for better description!

Acked-by: Yonghong Song <[email protected]>

2021-01-19 04:46:32

by Brendan Jackman

[permalink] [raw]
Subject: [PATCH bpf-next v2 1/2] docs: bpf: Fixup atomics markup

This fixues up the markup to fix a warning, be more consistent with
use of monospace, and use the correct .rst syntax for <em> (* instead
of _).

NB this conflicts with Lukas' patch at [1], which just fixes the
warning. The scope of this one is a little broader.

[1] https://lore.kernel.org/bpf/CA+i-1C3cEXqxcXfD4sibQfx+dtmmzvOzruhk8J5pAw3g5v=KgA@mail.gmail.com/T/#t

Signed-off-by: Brendan Jackman <[email protected]>
---
Documentation/networking/filter.rst | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
index f6d8f90e9a56..4c2bb4c6364d 100644
--- a/Documentation/networking/filter.rst
+++ b/Documentation/networking/filter.rst
@@ -1048,12 +1048,12 @@ Unlike classic BPF instruction set, eBPF has generic load/store operations::
Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW.

It also includes atomic operations, which use the immediate field for extra
-encoding.
+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:
+The basic atomic operations supported are::

BPF_ADD
BPF_AND
@@ -1066,12 +1066,12 @@ memory location addresed by ``dst_reg + off`` is atomically modified, with
immediate, then these operations also overwrite ``src_reg`` with the
value that was in memory before it was modified.

-The more special operations are:
+The more special operations are::

BPF_XCHG

This atomically exchanges ``src_reg`` with the value addressed by ``dst_reg +
-off``.
+off``. ::

BPF_CMPXCHG

@@ -1081,18 +1081,19 @@ 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
+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.
+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.

-eBPF has one 16-byte instruction: BPF_LD | BPF_DW | BPF_IMM which consists
+eBPF has one 16-byte instruction: ``BPF_LD | BPF_DW | BPF_IMM`` which consists
of two consecutive ``struct bpf_insn`` 8-byte blocks and interpreted as single
instruction that loads 64-bit immediate value into a dst_reg.
-Classic BPF has similar instruction: BPF_LD | BPF_W | BPF_IMM which loads
+Classic BPF has similar instruction: ``BPF_LD | BPF_W | BPF_IMM`` which loads
32-bit immediate value into a register.

eBPF verifier
--
2.30.0.284.gd98b1dd5eaa7-goog

2021-01-19 04:50:11

by Lukas Bulwahn

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 1/2] docs: bpf: Fixup atomics markup

On Mon, Jan 18, 2021 at 4:59 PM Brendan Jackman <[email protected]> wrote:
>
> This fixues up the markup to fix a warning, be more consistent with

s/fixues/fixes/ ?

> use of monospace, and use the correct .rst syntax for <em> (* instead
> of _).
>

> NB this conflicts with Lukas' patch at [1], which just fixes the
> warning. The scope of this one is a little broader.
>
> [1] https://lore.kernel.org/bpf/CA+i-1C3cEXqxcXfD4sibQfx+dtmmzvOzruhk8J5pAw3g5v=KgA@mail.gmail.com/T/#t
>
As I wrote in my patch, I did minimal changes. Your bit more extensive
changes make sense.

I suggest dropping this comment above starting from NB and the link;
it is not relevant for the history. You can of course move it below
the "---"; so it is not picked up into the git history.

Other than that:

Reviewed-by: Lukas Bulwahn <[email protected]>


> Signed-off-by: Brendan Jackman <[email protected]>
> ---
> Documentation/networking/filter.rst | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/networking/filter.rst b/Documentation/networking/filter.rst
> index f6d8f90e9a56..4c2bb4c6364d 100644
> --- a/Documentation/networking/filter.rst
> +++ b/Documentation/networking/filter.rst
> @@ -1048,12 +1048,12 @@ Unlike classic BPF instruction set, eBPF has generic load/store operations::
> Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW.
>
> It also includes atomic operations, which use the immediate field for extra
> -encoding.
> +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:
> +The basic atomic operations supported are::
>
> BPF_ADD
> BPF_AND
> @@ -1066,12 +1066,12 @@ memory location addresed by ``dst_reg + off`` is atomically modified, with
> immediate, then these operations also overwrite ``src_reg`` with the
> value that was in memory before it was modified.
>
> -The more special operations are:
> +The more special operations are::
>
> BPF_XCHG
>
> This atomically exchanges ``src_reg`` with the value addressed by ``dst_reg +
> -off``.
> +off``. ::
>
> BPF_CMPXCHG
>
> @@ -1081,18 +1081,19 @@ 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
> +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.
> +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.
>
> -eBPF has one 16-byte instruction: BPF_LD | BPF_DW | BPF_IMM which consists
> +eBPF has one 16-byte instruction: ``BPF_LD | BPF_DW | BPF_IMM`` which consists
> of two consecutive ``struct bpf_insn`` 8-byte blocks and interpreted as single
> instruction that loads 64-bit immediate value into a dst_reg.
> -Classic BPF has similar instruction: BPF_LD | BPF_W | BPF_IMM which loads
> +Classic BPF has similar instruction: ``BPF_LD | BPF_W | BPF_IMM`` which loads
> 32-bit immediate value into a register.
>
> eBPF verifier
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>