From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Denis Kirjanov <kirjanov@gmail.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Daniel Borkmann <dborkman@redhat.com>,
Eric Dumazet <edumazet@google.com>,
Denis Kirjanov <kda@linux-powerpc.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Markos Chandras <markos.chandras@imgtec.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: Re: [PATCH v2 net-next] net: filter: export pkt_type_offset() helper
Date: Thu, 04 Sep 2014 15:40:10 +0200 [thread overview]
Message-ID: <1409838010.23465.16.camel@localhost> (raw)
In-Reply-To: <1409836154.26422.101.camel@edumazet-glaptop2.roam.corp.google.com>
On Do, 2014-09-04 at 06:09 -0700, Eric Dumazet wrote:
> On Thu, 2014-09-04 at 13:50 +0200, Hannes Frederic Sowa wrote:
>
> >
> > Denis, I thought about something like this, you can incorperate this in
> > your patch if you can give it a test and check for other architectures,
> > thanks!
> >
>
>
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index 02529fc..87b86aa 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -548,6 +548,10 @@ struct sk_buff {
> > ip_summed:2,
> > nohdr:1,
> > nfctinfo:3;
> > + /* __pkt_type_offset marks the offset of the bitfield pkt_type
> > + * contains, so bpf can relatively address it
> > + */
> > + int __pkt_type_offset[0];
>
> Why is it 'int', while the following uses __u8 ?
The type does not matter at all. Actually I wanted to use an empty
struct but was afraid it might not work on older compilers and didn't
want to check that with each version.
> This means pkt_type has to stay at this bit offset, and nothing will
> detect at compile time or execution time if someone did a reorg or added
> a new field (it seems to be the trend lately)
>
> __u8 bar:4,
> pkt_type:3,
> ...
That would be fine, one just has to adapt the PKT_TYPE_MAX macros in
case on reorders, __pkt_type_offset only needs to stay just in front of
the bitfield pkt_type is located in. I think we should move them up into
struct sk_buff, so they belong together and people see that they need to
change those in case they reorder fields.
I still think about using anonymous unions, they might let us compute
the pkt_type mask at compiletime, I think.
Also, maybe we can compute offset at compiletime if we switch to
anonymous union.
static inline unsigned int skb_pkt_type_offset(void)
{
unsigned int mask;
struct sk_buff skb = {.pkt_type = ~0U};
mask = skb.__flags2;
BUILD_BUG_ON(!__builtin_constant_p(mask));
return mask;
}
something like that, haven't checked if that works.
>
>
>
> > __u8 pkt_type:3,
> > fclone:2,
> > ipvs_property:1,
> > @@ -647,6 +651,17 @@ struct sk_buff {
> > #define SKB_ALLOC_FCLONE 0x01
> > #define SKB_ALLOC_RX 0x02
> >
>
> > +#ifdef __BIG_ENDIAN_BITFIELD
> > +#define PKT_TYPE_MAX (7 << 5)
> > +#else
> > +#define PKT_TYPE_MAX 7
> > +#endif
>
> It had a sense right before static int pkt_type_offset(void), but here,
> a casual reader might be lost.
Do you think we should just move PKT_TYPE_MAX macros right to the
definition of __pkt_type_offset?
> I am saying this because a reorder of the bit fields is probably needed
> to speedup __copy_skb_header() : Grouping together bit fields could
> allow optimized word copies instead of bit field manipulations.
Yes, I agree with you. It should be obvious to adapt the macros in case
someones reorders sk_buff. Either BUILD_BUG_ON or very obvious comments
+ declarations.
Thanks,
Hannes
next prev parent reply other threads:[~2014-09-04 13:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-03 21:08 [PATCH v2 net-next] net: filter: export pkt_type_offset() helper Denis Kirjanov
2014-09-03 22:01 ` Daniel Borkmann
2014-09-03 23:14 ` Alexei Starovoitov
2014-09-04 1:08 ` Eric Dumazet
2014-09-04 1:25 ` Hannes Frederic Sowa
2014-09-04 2:05 ` Eric Dumazet
2014-09-04 2:43 ` Alexei Starovoitov
[not found] ` <CAHj3AVn8q-JS0Eq0QrfpBo-WfJ+-wXumhNoeDAdkPZC7LSeB5g@mail.gmail.com>
2014-09-04 11:50 ` Hannes Frederic Sowa
2014-09-04 13:09 ` Eric Dumazet
2014-09-04 13:40 ` Hannes Frederic Sowa [this message]
2014-09-04 14:11 ` Eric Dumazet
2014-09-04 14:22 ` Hannes Frederic Sowa
2014-09-04 14:23 ` David Laight
2014-09-04 14:32 ` Eric Dumazet
2014-09-04 14:33 ` Hannes Frederic Sowa
2014-09-04 14:35 ` Eric Dumazet
2014-09-04 14:41 ` Hannes Frederic Sowa
2014-09-04 20:51 ` Alexei Starovoitov
2014-09-04 22:45 ` Hannes Frederic Sowa
2014-09-12 4:01 ` Alexei Starovoitov
[not found] ` <CAOJe8K2eQ9ejhBTk7MzJJK5EB4D62U4uKDiFFQFh+T16E7=S3A@mail.gmail.com>
2014-09-12 8:25 ` Hannes Frederic Sowa
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=1409838010.23465.16.camel@localhost \
--to=hannes@stressinduktion.org \
--cc=alexei.starovoitov@gmail.com \
--cc=dborkman@redhat.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kda@linux-powerpc.org \
--cc=kirjanov@gmail.com \
--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).