netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Hannes Frederic Sowa <hannes@stressinduktion.org>
Cc: netdev@vger.kernel.org, Eric Dumazet <eric.dumazet@gmail.com>,
	Markos Chandras <markos.chandras@imgtec.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Denis Kirjanov <kda@linux-powerpc.org>
Subject: Re: [PATCH net-next] net: filter: constify detection of pkt_type_offset
Date: Fri, 12 Sep 2014 12:55:15 +0200	[thread overview]
Message-ID: <5412D113.6000700@redhat.com> (raw)
In-Reply-To: <09acea1aba100a62551605ba52ae8541e816d1e6.1410517225.git.hannes@stressinduktion.org>

On 09/12/2014 12:22 PM, Hannes Frederic Sowa wrote:
> Currently we have 2 pkt_type_offset functions doing the same thing and
> spread across the architecture files. Remove those and replace them
> with a PKT_TYPE_OFFSET macro helper which gets the constant value from a
> zero sized sk_buff member right in front of the bitfield with offsetof.
> This new offset marker does not change size of struct sk_buff.
>
> Cc: Eric Dumazet <eric.dumazet@gmail.com>
> Cc: Markos Chandras <markos.chandras@imgtec.com>
> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
> Cc: Daniel Borkmann <dborkman@redhat.com>
> Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>

Thanks for doing this, Hannes!
...
>   static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
>   {
>   	return skb_get_poff((struct sk_buff *)(unsigned long) ctx);
> @@ -191,7 +167,7 @@ static bool convert_bpf_extensions(struct sock_filter *fp,
>
>   	case SKF_AD_OFF + SKF_AD_PKTTYPE:
>   		*insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
> -				    pkt_type_offset());
> +				    PKT_TYPE_OFFSET());
>   		if (insn->off < 0)
>   			return false;
>   		insn++;

I think this can now be rewritten as ...

	case SKF_AD_OFF + SKF_AD_PKTTYPE:
		*insn++ = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
				      PKT_TYPE_OFFSET());
		*insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX);

... since we are guaranteed to have always >0 insn->off and despite the
__s16 type in off we might be able to safely assume that sk_buff will
never get extended so far w/o fist fights first, where this could wrap
around. ;) Alternatively, perhaps a BUILD_BUG_ON() for really being
paranoid?

  reply	other threads:[~2014-09-12 10:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 10:22 [PATCH net-next] net: filter: constify detection of pkt_type_offset Hannes Frederic Sowa
2014-09-12 10:55 ` Daniel Borkmann [this message]
2014-09-12 11:18   ` Hannes Frederic Sowa
2014-09-12 11:32     ` Daniel Borkmann
2014-09-12 12:04       ` [PATCH net-next v2] " Hannes Frederic Sowa
2014-09-12 16:06         ` Alexei Starovoitov
2014-09-12 17:06           ` Cong Wang
2014-09-12 17:09             ` Hannes Frederic Sowa
2014-09-12 17:12               ` Cong Wang
2014-09-12 17:17                 ` Hannes Frederic Sowa
2014-09-12 17:47                   ` Cong Wang
2014-09-12 20:13                     ` David Miller
2014-09-12 17:11             ` Daniel Borkmann
2014-09-12 20:48         ` Daniel Borkmann
2014-09-13 21:08         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5412D113.6000700@redhat.com \
    --to=dborkman@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=eric.dumazet@gmail.com \
    --cc=hannes@stressinduktion.org \
    --cc=kda@linux-powerpc.org \
    --cc=markos.chandras@imgtec.com \
    --cc=netdev@vger.kernel.org \
    --cc=schwidefsky@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).