ietf-wg-bpf / ebpf-docs

eBPF Standard Documentation
37 stars 5 forks source link

ISA: Clarify 64-bit immediate instructions #75

Closed dthaler closed 4 months ago

dthaler commented 5 months ago

The spec defines:

As discussed below in 64-bit immediate instructions_, a 64-bit immediate instruction uses a 64-bit immediate value that is constructed as follows. The 64 bits following the basic instruction contain a pseudo instruction using the same format but with opcode, dst_reg, src_reg, and offset all set to zero, and imm containing the high 32 bits of the immediate value. [...] imm64 = (next_imm << 32) | imm

The 64-bit immediate instructions section then says:

Instructions with the BPF_IMM 'mode' modifier use the wide instruction encoding defined in Instruction encoding_, and use the 'src' field of the basic instruction to hold an opcode subtype.

Some instructions then nicely state how to use the full 64 bit immediate value, such as

BPF_IMM | BPF_DW | BPF_LD 0x18 0x0 dst = imm64 integer integer BPF_IMM | BPF_DW | BPF_LD 0x18 0x2 dst = map_val(map_by_fd(imm)) + next_imm map fd data pointer BPF_IMM | BPF_DW | BPF_LD 0x18 0x6 dst = map_val(map_by_idx(imm)) + next_imm map index data pointer

Others don't:

BPF_IMM | BPF_DW | BPF_LD 0x18 0x1 dst = map_by_fd(imm) map fd map BPF_IMM | BPF_DW | BPF_LD 0x18 0x3 dst = var_addr(imm) variable id data pointer BPF_IMM | BPF_DW | BPF_LD 0x18 0x4 dst = code_addr(imm) integer code pointer BPF_IMM | BPF_DW | BPF_LD 0x18 0x5 dst = map_by_idx(imm) map index map

How is next_imm used in those four? Must it be 0? Or can it be anything and it's ignored? Or is it used for something?

dthaler commented 5 months ago

Question posted to the list: https://mailarchive.ietf.org/arch/msg/bpf/a3mPMDnp6Y_yREfRj6OMtvFJy3o/

dthaler commented 5 months ago

In response, Yonghong wrote:

The other four must have next_imm to be 0. No use of next_imm in thee four insns kindly implies this. See uapi bpf.h for details (search BPF_PSEUDO_MAP_FD).

dthaler commented 5 months ago

Section 2 says "Note that most instructions do not use all of the fields. Unused fields shall be cleared to zero." So this is already implied in the document.

dthaler commented 5 months ago

Yonghong posted proposed text in https://mailarchive.ietf.org/arch/msg/bpf/JixGnHEotgo1Arql9FLXruIlqiY/

dthaler commented 4 months ago

Fixed in draft -01