linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: BPF: Add support for SKF_AD_HATYPE
@ 2017-03-10 22:14 David Daney
  2017-03-13 10:56 ` James Hogan
  0 siblings, 1 reply; 3+ messages in thread
From: David Daney @ 2017-03-10 22:14 UTC (permalink / raw)
  To: linux-mips, ralf, James Hogan; +Cc: linux-kernel, Steven J. Hill, David Daney

This let's us pass some additional "modprobe test-bpf" tests.

Reuse the code for SKF_AD_IFINDEX, but substitute the offset and size
of the "type" field.

Signed-off-by: David Daney <david.daney@cavium.com>
---
 arch/mips/net/bpf_jit.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index 49a2e22..f613708 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -1111,6 +1111,7 @@ static int build_body(struct jit_ctx *ctx)
 			emit_load(r_A, 28, off, ctx);
 			break;
 		case BPF_ANC | SKF_AD_IFINDEX:
+		case BPF_ANC | SKF_AD_HATYPE:
 			/* A = skb->dev->ifindex */
 			ctx->flags |= SEEN_SKB | SEEN_A;
 			off = offsetof(struct sk_buff, dev);
@@ -1120,10 +1121,15 @@ static int build_body(struct jit_ctx *ctx)
 			emit_bcond(MIPS_COND_EQ, r_s0, r_zero,
 				   b_imm(prog->len, ctx), ctx);
 			emit_reg_move(r_ret, r_zero, ctx);
-			BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
-						  ifindex) != 4);
-			off = offsetof(struct net_device, ifindex);
-			emit_load(r_A, r_s0, off, ctx);
+			if (code == (BPF_ANC | SKF_AD_IFINDEX)) {
+				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
+				off = offsetof(struct net_device, ifindex);
+				emit_load(r_A, r_s0, off, ctx);
+			} else { /* (code == (BPF_ANC | SKF_AD_HATYPE) */
+				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
+				off = offsetof(struct net_device, type);
+				emit_half_load(r_A, r_s0, off, ctx);
+			}
 			break;
 		case BPF_ANC | SKF_AD_MARK:
 			ctx->flags |= SEEN_SKB | SEEN_A;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: BPF: Add support for SKF_AD_HATYPE
  2017-03-10 22:14 [PATCH] MIPS: BPF: Add support for SKF_AD_HATYPE David Daney
@ 2017-03-13 10:56 ` James Hogan
  2017-03-13 16:45   ` David Daney
  0 siblings, 1 reply; 3+ messages in thread
From: James Hogan @ 2017-03-13 10:56 UTC (permalink / raw)
  To: David Daney
  Cc: linux-mips, ralf, linux-kernel, Steven J. Hill,
	Alexei Starovoitov, netdev

[-- Attachment #1: Type: text/plain, Size: 1941 bytes --]

On Fri, Mar 10, 2017 at 02:14:05PM -0800, David Daney wrote:
> This let's us pass some additional "modprobe test-bpf" tests.
> 
> Reuse the code for SKF_AD_IFINDEX, but substitute the offset and size
> of the "type" field.
> 
> Signed-off-by: David Daney <david.daney@cavium.com>

I think the BPF maintainers should probably be Cc'd on this patch.
Cc'ing now.

> ---
>  arch/mips/net/bpf_jit.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
> index 49a2e22..f613708 100644
> --- a/arch/mips/net/bpf_jit.c
> +++ b/arch/mips/net/bpf_jit.c
> @@ -1111,6 +1111,7 @@ static int build_body(struct jit_ctx *ctx)
>  			emit_load(r_A, 28, off, ctx);
>  			break;
>  		case BPF_ANC | SKF_AD_IFINDEX:
> +		case BPF_ANC | SKF_AD_HATYPE:
>  			/* A = skb->dev->ifindex */

this comment should probably be updated.

>  			ctx->flags |= SEEN_SKB | SEEN_A;
>  			off = offsetof(struct sk_buff, dev);
> @@ -1120,10 +1121,15 @@ static int build_body(struct jit_ctx *ctx)
>  			emit_bcond(MIPS_COND_EQ, r_s0, r_zero,
>  				   b_imm(prog->len, ctx), ctx);
>  			emit_reg_move(r_ret, r_zero, ctx);
> -			BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
> -						  ifindex) != 4);
> -			off = offsetof(struct net_device, ifindex);
> -			emit_load(r_A, r_s0, off, ctx);
> +			if (code == (BPF_ANC | SKF_AD_IFINDEX)) {
> +				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
> +				off = offsetof(struct net_device, ifindex);
> +				emit_load(r_A, r_s0, off, ctx);
> +			} else { /* (code == (BPF_ANC | SKF_AD_HATYPE) */
> +				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
> +				off = offsetof(struct net_device, type);
> +				emit_half_load(r_A, r_s0, off, ctx);

Technically net_device::type is unsigned, and emit_half_load uses LH
which sign extends. Does that matter in practice.

Cheers
James

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: BPF: Add support for SKF_AD_HATYPE
  2017-03-13 10:56 ` James Hogan
@ 2017-03-13 16:45   ` David Daney
  0 siblings, 0 replies; 3+ messages in thread
From: David Daney @ 2017-03-13 16:45 UTC (permalink / raw)
  To: James Hogan, David Daney
  Cc: linux-mips, ralf, linux-kernel, Steven J. Hill,
	Alexei Starovoitov, netdev

On 03/13/2017 03:56 AM, James Hogan wrote:
> On Fri, Mar 10, 2017 at 02:14:05PM -0800, David Daney wrote:
>> This let's us pass some additional "modprobe test-bpf" tests.
>>
>> Reuse the code for SKF_AD_IFINDEX, but substitute the offset and size
>> of the "type" field.
>>
>> Signed-off-by: David Daney <david.daney@cavium.com>
>
> I think the BPF maintainers should probably be Cc'd on this patch.
> Cc'ing now.
>

Good point.

Since there are some corrections needed, I will send another version and 
CC the proper people.


>> ---
>>  arch/mips/net/bpf_jit.c | 14 ++++++++++----
>>  1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
>> index 49a2e22..f613708 100644
>> --- a/arch/mips/net/bpf_jit.c
>> +++ b/arch/mips/net/bpf_jit.c
>> @@ -1111,6 +1111,7 @@ static int build_body(struct jit_ctx *ctx)
>>  			emit_load(r_A, 28, off, ctx);
>>  			break;
>>  		case BPF_ANC | SKF_AD_IFINDEX:
>> +		case BPF_ANC | SKF_AD_HATYPE:
>>  			/* A = skb->dev->ifindex */
>
> this comment should probably be updated.

Right.

>
>>  			ctx->flags |= SEEN_SKB | SEEN_A;
>>  			off = offsetof(struct sk_buff, dev);
>> @@ -1120,10 +1121,15 @@ static int build_body(struct jit_ctx *ctx)
>>  			emit_bcond(MIPS_COND_EQ, r_s0, r_zero,
>>  				   b_imm(prog->len, ctx), ctx);
>>  			emit_reg_move(r_ret, r_zero, ctx);
>> -			BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
>> -						  ifindex) != 4);
>> -			off = offsetof(struct net_device, ifindex);
>> -			emit_load(r_A, r_s0, off, ctx);
>> +			if (code == (BPF_ANC | SKF_AD_IFINDEX)) {
>> +				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
>> +				off = offsetof(struct net_device, ifindex);
>> +				emit_load(r_A, r_s0, off, ctx);
>> +			} else { /* (code == (BPF_ANC | SKF_AD_HATYPE) */
>> +				BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
>> +				off = offsetof(struct net_device, type);
>> +				emit_half_load(r_A, r_s0, off, ctx);
>
> Technically net_device::type is unsigned, and emit_half_load uses LH
> which sign extends. Does that matter in practice.

The next version will use LHU.


>
> Cheers
> James
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-13 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 22:14 [PATCH] MIPS: BPF: Add support for SKF_AD_HATYPE David Daney
2017-03-13 10:56 ` James Hogan
2017-03-13 16:45   ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).