diff mbox series

bpf, docs: Correct source of offset for program-local call

Message ID 20230826053258.1860167-1-hawkinsw@obs.cr (mailing list archive)
State Accepted
Commit 2d71a90f7e0fa3cd348602a36f6eb1237ab7cebb
Delegated to: BPF
Headers show
Series bpf, docs: Correct source of offset for program-local call | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16

Commit Message

Will Hawkins Aug. 26, 2023, 5:32 a.m. UTC
The offset to use when calculating the target of a program-local call is
in the instruction's imm field, not its offset field.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
 Documentation/bpf/standardization/instruction-set.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Eduard Zingerman Aug. 26, 2023, 10:20 a.m. UTC | #1
On Sat, 2023-08-26 at 01:32 -0400, Will Hawkins wrote:
> The offset to use when calculating the target of a program-local call is
> in the instruction's imm field, not its offset field.

Indeed, this is the case, e.g. see kernel/bpf/verifier.c:add_subprog_and_kfunc().
Acked-by: Eduard Zingerman <eddyz87@gmail.com>

> 
> Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
> ---
>  Documentation/bpf/standardization/instruction-set.rst | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
> index 4f73e9dc8d9e..c5b0b2011f16 100644
> --- a/Documentation/bpf/standardization/instruction-set.rst
> +++ b/Documentation/bpf/standardization/instruction-set.rst
> @@ -373,7 +373,7 @@ BPF_JNE   0x5    any  PC += offset if dst != src
>  BPF_JSGT  0x6    any  PC += offset if dst > src                    signed
>  BPF_JSGE  0x7    any  PC += offset if dst >= src                   signed
>  BPF_CALL  0x8    0x0  call helper function by address              see `Helper functions`_
> -BPF_CALL  0x8    0x1  call PC += offset                            see `Program-local functions`_
> +BPF_CALL  0x8    0x1  call PC += imm                               see `Program-local functions`_
>  BPF_CALL  0x8    0x2  call helper function by BTF ID               see `Helper functions`_
>  BPF_EXIT  0x9    0x0  return                                       BPF_JMP only
>  BPF_JLT   0xa    any  PC += offset if dst < src                    unsigned
> @@ -424,8 +424,8 @@ Program-local functions
>  ~~~~~~~~~~~~~~~~~~~~~~~
>  Program-local functions are functions exposed by the same BPF program as the
>  caller, and are referenced by offset from the call instruction, similar to
> -``BPF_JA``.  A ``BPF_EXIT`` within the program-local function will return to
> -the caller.
> +``BPF_JA``.  The offset is encoded in the imm field of the call instruction.
> +A ``BPF_EXIT`` within the program-local function will return to the caller.
>  
>  Load and store instructions
>  ===========================
David Vernet Aug. 26, 2023, 5:39 p.m. UTC | #2
On Sat, Aug 26, 2023 at 01:32:54AM -0400, Will Hawkins wrote:
> The offset to use when calculating the target of a program-local call is
> in the instruction's imm field, not its offset field.
> 
> Signed-off-by: Will Hawkins <hawkinsw@obs.cr>

LGTM, thanks for the fix.

Acked-by: David Vernet <void@manifault.com>
patchwork-bot+netdevbpf@kernel.org Aug. 30, 2023, 8 a.m. UTC | #3
Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Sat, 26 Aug 2023 01:32:54 -0400 you wrote:
> The offset to use when calculating the target of a program-local call is
> in the instruction's imm field, not its offset field.
> 
> Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
> ---
>  Documentation/bpf/standardization/instruction-set.rst | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Here is the summary with links:
  - bpf, docs: Correct source of offset for program-local call
    https://git.kernel.org/bpf/bpf/c/2d71a90f7e0f

You are awesome, thank you!
diff mbox series

Patch

diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
index 4f73e9dc8d9e..c5b0b2011f16 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -373,7 +373,7 @@  BPF_JNE   0x5    any  PC += offset if dst != src
 BPF_JSGT  0x6    any  PC += offset if dst > src                    signed
 BPF_JSGE  0x7    any  PC += offset if dst >= src                   signed
 BPF_CALL  0x8    0x0  call helper function by address              see `Helper functions`_
-BPF_CALL  0x8    0x1  call PC += offset                            see `Program-local functions`_
+BPF_CALL  0x8    0x1  call PC += imm                               see `Program-local functions`_
 BPF_CALL  0x8    0x2  call helper function by BTF ID               see `Helper functions`_
 BPF_EXIT  0x9    0x0  return                                       BPF_JMP only
 BPF_JLT   0xa    any  PC += offset if dst < src                    unsigned
@@ -424,8 +424,8 @@  Program-local functions
 ~~~~~~~~~~~~~~~~~~~~~~~
 Program-local functions are functions exposed by the same BPF program as the
 caller, and are referenced by offset from the call instruction, similar to
-``BPF_JA``.  A ``BPF_EXIT`` within the program-local function will return to
-the caller.
+``BPF_JA``.  The offset is encoded in the imm field of the call instruction.
+A ``BPF_EXIT`` within the program-local function will return to the caller.
 
 Load and store instructions
 ===========================