ietf-wg-bpf / ebpf-docs

eBPF Standard Documentation
42 stars 5 forks source link

ISA: clarify sign extension of 64-bit use of 32-bit imm #136

Closed dthaler closed 4 months ago

dthaler commented 4 months ago

imm is defined as a 32-bit signed integer.

{MOV, K, ALU64} says it does "dst = src" (where src is 'imm') but that's not precisely true, since it does not sign extend, unlike movsx. Instead it does dst = (u32)src The "Jump instructions" section has "unsigned" by some instructions, but the "Arithmetic instructions" section has no such note about the MOV instruction.

{JLE, K, JMP} says it does "PC += offset if dst <= src" (where src is 'imm', and the comparison is unsigned). This is ambiguous to some readers as to whether it means: dst <= (u64)(u32)imm or dst <= (u64)(s64)imm where the latter is intended. That would be the default assumption based on imm being signed, except that the mov instruction above doesn't follow that rule and so the reader doesn't know the rule here as a result.

dthaler commented 4 months ago

Proposed patch poste at https://mailarchive.ietf.org/arch/msg/bpf/hdq2f6aJWKIkx8f6GI8oLI87QMY/

dthaler commented 4 months ago

Updated patch posted at https://mailarchive.ietf.org/arch/msg/bpf/0n7nSlGJAi-bxxvoMQ05K8iNxKw/

dthaler commented 4 months ago

Fixed in draft-03