Skip to contentSkip to conversation

powerpc: bpf: Use correct mask while accessing the VLAN tag

PATCH Applied Denis Kirjanov 4 participants 9 messages Jun 25, 2014 – Jun 27, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 powerpc: bpf: Use correct mask while accessing the VLAN tag

To get a full tag (and not just a VID) we should access the TCI except the VLAN_TAG_PRESENT field (which means that 802.1q header is present). Also ensure that the VLAN_TAG_PRESENT stay on its place

---
 arch/powerpc/net/bpf_jit_comp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/net/bpf_jit_comp.c +3 -1
index 6dcdade..892167b 100644
@@ -390,10 +390,12 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
 		case BPF_ANC | SKF_AD_VLAN_TAG:
 		case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
 			BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
+			BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
+
 			PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
 							  vlan_tci));
 			if (code == (BPF_ANC | SKF_AD_VLAN_TAG))
-				PPC_ANDI(r_A, r_A, VLAN_VID_MASK);
+				PPC_ANDI(r_A, r_A, ~VLAN_TAG_PRESENT);
 			else
 				PPC_ANDI(r_A, r_A, VLAN_TAG_PRESENT);
 			break;
Signature · 1 line
2.0.0
#1 lore raw

PATCH v2 2/2 powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)
---
 arch/powerpc/net/bpf_jit_comp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/net/bpf_jit_comp.c +4 -2
index 892167b..82e82ca 100644
@@ -394,10 +394,12 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
 
 			PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
 							  vlan_tci));
-			if (code == (BPF_ANC | SKF_AD_VLAN_TAG))
+			if (code == (BPF_ANC | SKF_AD_VLAN_TAG)) {
 				PPC_ANDI(r_A, r_A, ~VLAN_TAG_PRESENT);
-			else
+			} else {
 				PPC_ANDI(r_A, r_A, VLAN_TAG_PRESENT);
+				PPC_SRWI(r_A, r_A, 12);
+			}
 			break;
 		case BPF_ANC | SKF_AD_QUEUE:
 			BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
Signature · 1 line
2.0.0
#2 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

Quoted 7 lines · Denis Kirjanov

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)

Hi Denis,

Is this the same version of test_bpf that is in Linus' tree?

I don't see any fails with that version, am I missing something?

  [  187.690640] test_bpf: #18 LD_VLAN_TAG_PRESENT 46 50 PASS

cheers

#3 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

Quoted 9 lines · Michael Ellerman
Quoted 7 lines · Denis Kirjanov

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)
Quoted 7 lines

Hi Denis,

Is this the same version of test_bpf that is in Linus' tree?

I don't see any fails with that version, am I missing something?

   [  187.690640] test_bpf: #18 LD_VLAN_TAG_PRESENT 46 50 PASS

Did you try to modprobe test_bpf after enabling JIT, i.e. :

echo 1 > /proc/sys/net/core/bpf_jit_enable

Last time I tested with ppc64, I saw the interpreter passing while JIT failed, which the fix above should address.

Cheers,

Daniel

#6 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

In reply to Michael Ellerman
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Denis Kirjanov

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

Quoted 8 lines
Quoted 4 lines
[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)

Hi Denis,

Is this the same version of test_bpf that is in Linus' tree?

You didn't enable the JIT.

Quoted 8 lines

I don't see any fails with that version, am I missing something?

  [  187.690640] test_bpf: #18 LD_VLAN_TAG_PRESENT 46 50 PASS

cheers

#4 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

In reply to Daniel Borkmann
Quoted 16 lines · Daniel Borkmann
Quoted 15 lines · Michael Ellerman
Quoted 7 lines · Denis Kirjanov

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)

Hi Denis,

Is this the same version of test_bpf that is in Linus' tree?

I don't see any fails with that version, am I missing something?

Quoted 8 lines
Quoted 1 line
   [  187.690640] test_bpf: #18 LD_VLAN_TAG_PRESENT 46 50 PASS

Did you try to modprobe test_bpf after enabling JIT, i.e. :

echo 1 > /proc/sys/net/core/bpf_jit_enable

Last time I tested with ppc64, I saw the interpreter passing while JIT failed, which the fix above should address.

Right, I thought CONFIG_BPF_JIT=y was sufficient.

But that just makes it available, I need to *also* enable it at runtime.

cheers

#5 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

Quoted 21 lines · Michael Ellerman
Quoted 20 lines · Daniel Borkmann
Quoted 9 lines · Michael Ellerman
Quoted 7 lines · Denis Kirjanov

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)
Quoted 7 lines

Hi Denis,

Is this the same version of test_bpf that is in Linus' tree?

I don't see any fails with that version, am I missing something?

    [  187.690640] test_bpf: #18 LD_VLAN_TAG_PRESENT 46 50 PASS

Did you try to modprobe test_bpf after enabling JIT, i.e. :

Quoted 8 lines
Quoted 4 lines

echo 1 > /proc/sys/net/core/bpf_jit_enable

Last time I tested with ppc64, I saw the interpreter passing while JIT failed, which the fix above should address.

Right, I thought CONFIG_BPF_JIT=y was sufficient.

But that just makes it available, I need to *also* enable it at runtime.

Yes, it's an extra runtime knob which still needs to be enabled by the admin for security reasons. This knob also allows you to enable the debugging interface echo 2 >/proc/sys/net/core/bpf_jit_enable where the disassembly can be read out via: tools/net/bpf_jit_disasm.c

maintainer Applied
#7 lore raw

Re: [PATCH v2 2/2] powerpc: bpf: Fix the broken LD_VLAN_TAG_PRESENT test

In reply to Denis Kirjanov

From: Denis Kirjanov <[email protected]>
Date: Wed, 25 Jun 2014 21:34:57 +0400

Quoted 9 lines

We have to return the boolean here if the tag presents or not, not just ANDing the TCI with the mask which results to:

[  709.412097] test_bpf: #18 LD_VLAN_TAG_PRESENT
[  709.412245] ret 4096 != 1
[  709.412332] ret 4096 != 1
[  709.412333] FAIL (2 times)

Applied.