Skip to contentSkip to conversation

bpf, x86: remove unnecessary handling of BPF_SUB atomic op

PATCH Applied Hou Tao 5 participants 5 messages Jan 27, 2022 – Jan 28, 2022

Subsystems (5)
Networking Network drivers x86 BPF +1 more subsystems
lore
Share & tools
lore

Hou Tao

author
#0 lore raw

PATCH 1/1 bpf, x86: remove unnecessary handling of BPF_SUB atomic op

According to the LLVM commit (https://reviews.llvm.org/D72184),
sync_fetch_and_sub() is implemented as a negation followed by sync_fetch_and_add(), so there will be no BPF_SUB op and just remove it.

---
 arch/x86/net/bpf_jit_comp.c | 1 -
 1 file changed, 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +0 -1
index ce1f86f245c9..5d643ebb1e56 100644
@@ -787,7 +787,6 @@ static int emit_atomic(u8 **pprog, u8 atomic_op,
 	/* emit opcode */
 	switch (atomic_op) {
 	case BPF_ADD:
-	case BPF_SUB:
 	case BPF_AND:
 	case BPF_OR:
 	case BPF_XOR:
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw

Yep - BPF_SUB is also excluded in Documentation/networking/filter.rst, plus the interpreter and verifier don't support it.

Thanks,

Quoted 26 lines · Hou Tao

According to the LLVM commit (https://reviews.llvm.org/D72184),
sync_fetch_and_sub() is implemented as a negation followed by sync_fetch_and_add(), so there will be no BPF_SUB op and just remove it.

---
 arch/x86/net/bpf_jit_comp.c | 1 -
 1 file changed, 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +0 -2
index ce1f86f245c9..5d643ebb1e56 100644
@@ -787,7 +787,6 @@ static int emit_atomic(u8 **pprog, u8 atomic_op,
        /* emit opcode */
        switch (atomic_op) {
        case BPF_ADD:
-       case BPF_SUB:
        case BPF_AND:
        case BPF_OR:
        case BPF_XOR:
--

2.29.2

maintainer
#2 lore raw
Quoted 6 lines · Brendan Jackman

Yep - BPF_SUB is also excluded in Documentation/networking/filter.rst, plus the interpreter and verifier don't support it.

Thanks,

I was wondering about verifier specifically as well. Added a note to the commit log that verifier rejects BPF_SUB while applying, thanks!

Quoted 27 lines · Hou Tao
Quoted 26 lines

According to the LLVM commit (https://reviews.llvm.org/D72184),
sync_fetch_and_sub() is implemented as a negation followed by sync_fetch_and_add(), so there will be no BPF_SUB op and just remove it.

---
  arch/x86/net/bpf_jit_comp.c | 1 -
  1 file changed, 1 deletion(-)
arch/x86/net/bpf_jit_comp.c +0 -2
index ce1f86f245c9..5d643ebb1e56 100644
@@ -787,7 +787,6 @@ static int emit_atomic(u8 **pprog, u8 atomic_op,
         /* emit opcode */
         switch (atomic_op) {
         case BPF_ADD:
-       case BPF_SUB:
         case BPF_AND:
         case BPF_OR:
         case BPF_XOR:
--

2.29.2

#3 lore raw
Quoted 11 lines · Daniel Borkmann
Quoted 6 lines · Brendan Jackman

Yep - BPF_SUB is also excluded in Documentation/networking/filter.rst, plus the interpreter and verifier don't support it.

Thanks,

I was wondering about verifier specifically as well. Added a note to the commit log that verifier rejects BPF_SUB while applying, thanks!

Thanks for the follow up Hou/Brendan LGTM as well. After its been merged, but ACK from me as well.

#4 lore raw
In reply to Hou Tao
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Thu, 27 Jan 2022 16:32:40 +0800 you wrote:

According to the LLVM commit (https://reviews.llvm.org/D72184),
sync_fetch_and_sub() is implemented as a negation followed by sync_fetch_and_add(), so there will be no BPF_SUB op and just remove it.

[...]

Here is the summary with links:
- [bpf-next] bpf, x86: remove unnecessary handling of BPF_SUB atomic op

    https://git.kernel.org/bpf/bpf-next/c/b6ec79518ef0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html