Skip to contentSkip to conversation

bpf, docs: Clarify PC use in instruction-set.rst

PATCH Superseded Dave Thaler 2 participants 4 messages Apr 26, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf, docs: Clarify PC use in instruction-set.rst

This patch elaborates on the use of PC by expanding the PC acronym, explaining the units, and the relative position to which the offset applies.

---
 Documentation/bpf/standardization/instruction-set.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/bpf/standardization/instruction-set.rst +5 -0
index b44bdacd0..5592620cf 100644
@@ -469,6 +469,11 @@ JSLT      0xc    any      PC += offset if dst < src          signed
 JSLE      0xd    any      PC += offset if dst <= src         signed
 ========  =====  =======  =================================  ===================================================
 
+where 'PC' denotes the program counter, and the offset to increment by
+is in units of 64-bit instructions relative to the instruction following
+the jump instruction.  Thus 'PC += 1' results in the next instruction
+to execute being two 64-bit instructions later.
+
 The BPF program needs to store the return value into register R0 before doing an
 ``EXIT``.
 
Signature · 1 line
2.40.1
#1 lore raw
Quoted 15 lines · Dave Thaler

This patch elaborates on the use of PC by expanding the PC acronym, explaining the units, and the relative position to which the offset applies.

---
 Documentation/bpf/standardization/instruction-set.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/bpf/standardization/instruction-set.rst +0 -0
index b44bdacd0..5592620cf 100644

Documentation/bpf/standardization/instruction-set.rst JSLT 0xc any PC += offset if dst < src signed · line 475

Quoted 7 lines
Documentation/bpf/standardization/instruction-set.rst +4 -0
@@ -469,6 +469,11 @@ JSLT      0xc    any      PC += offset if dst < src          signed
 JSLE      0xd    any      PC += offset if dst <= src         signed
 ========  =====  =======  =================================  ===================================================
 
+where 'PC' denotes the program counter, and the offset to increment by
+is in units of 64-bit instructions relative to the instruction following
+the jump instruction.  Thus 'PC += 1' results in the next instruction
+to execute being two 64-bit instructions later.

The last part is confusing.
"two 64-bit instructions later"
I'm struggling to understand that.
Maybe say that 'PC += 1' skips execution of the next insn?

#2 lore raw
Quoted 31 lines

-----Original Message-----
From: Alexei Starovoitov <[email protected]>
Sent: Friday, April 26, 2024 12:22 PM
To: Dave Thaler <[email protected]>
Cc: bpf <[email protected]>; [email protected]; Dave Thaler <[email protected]>
Subject: Re: [PATCH bpf-next] bpf, docs: Clarify PC use in instruction-set.rst

Documentation/bpf/standardization/instruction-set.rst JSLT 0xc any PC += offset if dst < src

Quoted 16 lines · Dave Thaler

This patch elaborates on the use of PC by expanding the PC acronym, explaining the units, and the relative position to which the offset applies.

---
 Documentation/bpf/standardization/instruction-set.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/bpf/standardization/instruction-set.rst +0 -0
index b44bdacd0..5592620cf 100644
@@ -469,6 +469,11 @@ JSLT      0xc    any      PC += offset if dst < src

signed

Quoted 4 lines
Documentation/bpf/standardization/instruction-set.rst +0 -0
 JSLE      0xd    any      PC += offset if dst <= src         signed
 ========  =====  =======  =================================

===================================================

Quoted 9 lines

Documentation/bpf/standardization/instruction-set.rst

Quoted 4 lines
Documentation/bpf/standardization/instruction-set.rst +4 -0
+where 'PC' denotes the program counter, and the offset to increment
+by is in units of 64-bit instructions relative to the instruction
+following the jump instruction.  Thus 'PC += 1' results in the next
+instruction to execute being two 64-bit instructions later.

The last part is confusing.
"two 64-bit instructions later"
I'm struggling to understand that.
Maybe say that 'PC += 1' skips execution of the next insn?

If the next instruction is a 64-bit immediate instruction that spans 128 bits, do you need PC += 1 or PC += 2 to skip it? I assumed you'd need PC += 2, in which case "PC += 1" would not skip execution of "the next instruction" but would try to jump into mid instruction, and fail verification.
Hence my attempt at "64-bit instruction" wording.

Alternate wording suggestions welcome.

Dave

#3 lore raw
Quoted 42 lines · On Fri, Apr 26, 2024 at 12:30 PM <[email protected]> wrote:
Quoted 32 lines

-----Original Message-----
From: Alexei Starovoitov <[email protected]>
Sent: Friday, April 26, 2024 12:22 PM
To: Dave Thaler <[email protected]>
Cc: bpf <[email protected]>; [email protected]; Dave Thaler <[email protected]>
Subject: Re: [PATCH bpf-next] bpf, docs: Clarify PC use in instruction-set.rst

Documentation/bpf/standardization/instruction-set.rst JSLT 0xc any PC += offset if dst < src

Quoted 16 lines · Dave Thaler

This patch elaborates on the use of PC by expanding the PC acronym, explaining the units, and the relative position to which the offset applies.

---
 Documentation/bpf/standardization/instruction-set.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/bpf/standardization/instruction-set.rst +0 -0
index b44bdacd0..5592620cf 100644
@@ -469,6 +469,11 @@ JSLT      0xc    any      PC += offset if dst < src

signed

Quoted 4 lines
Documentation/bpf/standardization/instruction-set.rst +0 -0
 JSLE      0xd    any      PC += offset if dst <= src         signed
 ========  =====  =======  =================================

===================================================

Quoted 9 lines

Documentation/bpf/standardization/instruction-set.rst

Quoted 4 lines
Documentation/bpf/standardization/instruction-set.rst +4 -0
+where 'PC' denotes the program counter, and the offset to increment
+by is in units of 64-bit instructions relative to the instruction
+following the jump instruction.  Thus 'PC += 1' results in the next
+instruction to execute being two 64-bit instructions later.

The last part is confusing.
"two 64-bit instructions later"
I'm struggling to understand that.
Maybe say that 'PC += 1' skips execution of the next insn?

Quoted 5 lines

If the next instruction is a 64-bit immediate instruction that spans 128 bits, do you need PC += 1 or PC += 2 to skip it? I assumed you'd need PC += 2, in which case "PC += 1" would not skip execution of "the next instruction" but would try to jump into mid instruction, and fail verification.

Correct.

Quoted 3 lines

Hence my attempt at "64-bit instruction" wording.

Alternate wording suggestions welcome.

This "jump in the middle" issue is not obvious at all from "two 64-bit instructions" part.
Say that PC +=1 skips execution of the next insn if it's a 64-bit insn and fails verification if the next insn is 128-bit.