Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: replace <pre> in blog post #2

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions src/posts/2020-02-18-cilium-17/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,81 +560,81 @@ programs are updated, the eBPF JIT image is patched to directly jump to the new
To demonstrate this technique, the below example eBPF program implements an eBPF tail
call jump to the constant map index `0`:

<pre>
0: (b7) r3 = 0
1: (18) r2 = map[id:526]
3: (85) call bpf_tail_call#12
4: (b7) r0 = 1
5: (95) exit
</pre>
```
0: (b7) r3 = 0
1: (18) r2 = map[id:526]
3: (85) call bpf_tail_call#12
4: (b7) r0 = 1
5: (95) exit
```

The x86-64 eBPF JITed program would emit a retpoline on older kernels (marked in bold):

<pre>
0xffffffffc076e55c:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff88d95cc82600,%rsi |_map (r2 = map[id:526])
25: mov %edx,%edx | index >= array->map.max_entries check
27: cmp %edx,0x24(%rsi) |
2a: jbe 0x0000000000000066 |_
2c: mov -0x224(%rbp),%eax | tail call limit check
32: cmp $0x20,%eax |
35: ja 0x0000000000000066 |
37: add $0x1,%eax |
3a: mov %eax,-0x224(%rbp) |_
40: mov 0xd0(%rsi,%rdx,8),%rax |_prog = array->ptrs[index]
48: test %rax,%rax | prog == NULL check
4b: je 0x0000000000000066 |_
<b>4d: mov 0x30(%rax),%rax</b> | goto *(prog->bpf_func + prologue_size)
<b>51: add $0x19,%rax</b> |
<b>55: callq 0x0000000000000061</b> | retpoline for indirect jump
<b>5a: pause</b> |
<b>5c: lfence</b> |
<b>5f: jmp 0x000000000000005a</b> |
<b>61: mov %rax,(%rsp)</b> |
<b>65: retq</b> |_
66: mov $0x1,%eax (next instruction, r0 = 1)
[...]
</pre>
```
0xffffffffc076e55c:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff88d95cc82600,%rsi |_map (r2 = map[id:526])
25: mov %edx,%edx | index >= array->map.max_entries check
27: cmp %edx,0x24(%rsi) |
2a: jbe 0x0000000000000066 |_
2c: mov -0x224(%rbp),%eax | tail call limit check
32: cmp $0x20,%eax |
35: ja 0x0000000000000066 |
37: add $0x1,%eax |
3a: mov %eax,-0x224(%rbp) |_
40: mov 0xd0(%rsi,%rdx,8),%rax |_prog = array->ptrs[index]
48: test %rax,%rax | prog == NULL check
4b: je 0x0000000000000066 |_
4d: mov 0x30(%rax),%rax | goto *(prog->bpf_func + prologue_size)
51: add $0x19,%rax |
55: callq 0x0000000000000061 | retpoline for indirect jump
5a: pause |
5c: lfence |
5f: jmp 0x000000000000005a |
61: mov %rax,(%rsp) |
65: retq |_
66: mov $0x1,%eax (next instruction, r0 = 1)
[...]
```

For 5.5 or later kernels, the same program would get optimized into a direct jump
(marked in bold) without the need for a retpoline:

<pre>
0xffffffffc08e8930:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff9d8afd74c000,%rsi |_map (r2 = map[id:526])
25: mov -0x224(%rbp),%eax | tail call limit check
2b: cmp $0x20,%eax |
2e: ja 0x000000000000003e |
30: add $0x1,%eax |
33: mov %eax,-0x224(%rbp) |_
<b>39: jmpq 0xfffffffffffd1785</b> |_[direct] goto *(prog->bpf_func + prologue_size)
3e: mov $0x1,%eax (next instruction, r0 = 1)
[...]
</pre>
```
0xffffffffc08e8930:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff9d8afd74c000,%rsi |_map (r2 = map[id:526])
25: mov -0x224(%rbp),%eax | tail call limit check
2b: cmp $0x20,%eax |
2e: ja 0x000000000000003e |
30: add $0x1,%eax |
33: mov %eax,-0x224(%rbp) |_
39: jmpq 0xfffffffffffd1785 |_[direct] goto *(prog->bpf_func + prologue_size)
3e: mov $0x1,%eax (next instruction, r0 = 1)
[...]
```

Upon program update, the instruction on address `39`, that is `jmpq 0xfffffffffffd1785`,
would be live-updated with the address of the new target eBPF program. Similarly,
if the target eBPF program would get deleted from the tail call map, then the `jmp`
is patched into a same-sized `nop` instruction in order to allow a fall-through:

<pre>
0xffffffffc08e8930:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff9d8afd74c000,%rsi |_map (r2 = map[id:526])
25: mov -0x224(%rbp),%eax |
2b: cmp $0x20,%eax .
2e: ja 0x000000000000003e .
30: add $0x1,%eax .
33: mov %eax,-0x224(%rbp) |_
<b>39: nopl 0x0(%rax,%rax,1)</b> |_ fall-through nop
3e: mov $0x1,%eax (next instruction, r0 = 1)
[...]
</pre>
```
0xffffffffc08e8930:
[...] _
19: xor %edx,%edx |_ index (r3 = 0)
1b: movabs $0xffff9d8afd74c000,%rsi |_map (r2 = map[id:526])
25: mov -0x224(%rbp),%eax |
2b: cmp $0x20,%eax .
2e: ja 0x000000000000003e .
30: add $0x1,%eax .
33: mov %eax,-0x224(%rbp) |_
39: nopl 0x0(%rax,%rax,1) |_ fall-through nop
3e: mov $0x1,%eax (next instruction, r0 = 1)
[...]
```

Thus, instead of redirecting speculation into the `pause/lfence` loop, the kernel
eliminates the need to potentially perform any speculation for the jump given the
Expand Down
6 changes: 3 additions & 3 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
scrollbar-width: none; /* Firefox */
}

/* :not(pre) > code[class*='language-text'] {
@apply border border-gray-3 !px-2 md:!px-2.5 !bg-gray-4 !rounded font-normal;
} */
:not(pre) > code[class*='language-text'] {
@apply border border-gray-3 !px-2 !bg-gray-4 !rounded font-normal;
}

.content-style {
p {
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = {
lineHeight: theme('lineHeight.normal'),
},
code: {
fontWeight: theme('fontWeight.normal'),
'&::before': {
content: '"" !important',
},
Expand Down