From: Florian Westphal <fw@strlen.de>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Florian Westphal' <fw@strlen.de>,
'Pablo Neira Ayuso' <pablo@netfilter.org>,
"netfilter-devel@vger.kernel.org"
<netfilter-devel@vger.kernel.org>,
"davem@davemloft.net" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 16/17] netfilter: nft_byteorder: provide 64bit le/be conversion
Date: Fri, 8 Jan 2016 17:55:36 +0100 [thread overview]
Message-ID: <20160108165536.GE26058@breakpoint.cc> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CCC05A4@AcuExch.aculab.com>
David Laight <David.Laight@ACULAB.COM> wrote:
> From: Florian Westphal
> > Sent: 08 January 2016 16:24
> > To: David Laight
> > David Laight <David.Laight@ACULAB.COM> wrote:
> > > From: Pablo Neira Ayuso
> > > > Sent: 08 January 2016 14:02
> > > > From: Florian Westphal <fw@strlen.de>
> > > >
> > > > Needed to convert the (64bit) conntrack counters to BE ordering.
> > > >
> > > ...
> > > > switch (priv->size) {
> > > > + case 8: {
> > > > + u64 src64;
> > > > +
> > > > + switch (priv->op) {
> > > > + case NFT_BYTEORDER_NTOH:
> > > > + for (i = 0; i < priv->len / 8; i++) {
> > > > + src64 = get_unaligned_be64(&src[i]);
> > > > + src64 = be64_to_cpu((__force __be64)src64);
> > > > + put_unaligned_be64(src64, &dst[i]);
> > > > + }
> > > > + break;
> > > > + case NFT_BYTEORDER_HTON:
> > > > + for (i = 0; i < priv->len / 8; i++) {
> > > > + src64 = get_unaligned_be64(&src[i]);
> > > > + src64 = (__force u64)cpu_to_be64(src64);
> > > > + put_unaligned_be64(src64, &dst[i]);
> > > > + }
> > > > + break;
> > > > + }
> > > > + break;
> > >
> > > That is horrid.
> >
> > Yes, sorry for this, however ...
> >
> > > On a little-endian system you are byteswapping the data 3 times.
> > > Image the code on a cpu that doesn't support misaligned transfers
> > > and doesn't have a byteswap instruction.
> >
> > diff --git a/net/netfilter/nft_byteorder.c b/net/netfilter/nft_byteorder.c
> > --- a/net/netfilter/nft_byteorder.c
> > +++ b/net/netfilter/nft_byteorder.c
> > @@ -46,16 +46,16 @@ static void nft_byteorder_eval(const struct nft_expr *expr,
> > switch (priv->op) {
> > case NFT_BYTEORDER_NTOH:
> > for (i = 0; i < priv->len / 8; i++) {
> > - src64 = get_unaligned_be64(&src[i]);
> > + src64 = get_unaligned((u64 *)&src[i]);
> > src64 = be64_to_cpu((__force __be64)src64);
> > - put_unaligned_be64(src64, &dst[i]);
> > + put_unaligned(src64, (u64 *)&dst[i]);
>
> Why not just:
> src64 = get_unaligned_be64(&src[i]);
> put_unaligned(src64, (u64 *)&dst[i]);
Sure.
next prev parent reply other threads:[~2016-01-08 16:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 14:02 [PATCH 00/17] Netfilter updates for net-next Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 01/17] netfilter: nf_tables: release objects on netns destruction Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 02/17] netfilter: nf_tables: destroy basechain and rules on netdevice removal Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 03/17] netfilter: nf_tables: remove check against removal of inactive objects Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 04/17] netfilter: nfnetlink: pass down netns pointer to call() and call_rcu() Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 05/17] netfilter: nfnetlink: pass down netns pointer to commit() and abort() callbacks Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 06/17] netfilter: nft_limit: allow to invert matching criteria Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 07/17] netfilter: nf_tables: add packet duplication to the netdev family Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 08/17] netfilter: nf_tables: add forward expression " Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 09/17] netfilter: nf_ct_helper: define pr_fmt() Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 10/17] netfilter: nfnetlink_queue: validate dependencies to avoid breaking atomicity Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 11/17] netfilter: nfnetlink_queue: don't handle options after unbind Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 12/17] netfilter: nfnetlink_queue: just returns error for unknown command Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 13/17] netfilter: nfnetlink_queue: autoload nf_conntrack_netlink module NFQA_CFG_F_CONNTRACK config flag Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 14/17] netfilter: nfnetlink_log: just returns error for unknown command Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 15/17] netfilter: nf_tables: Add new attributes into nft_set to store user data Pablo Neira Ayuso
2016-01-08 14:02 ` [PATCH 16/17] netfilter: nft_byteorder: provide 64bit le/be conversion Pablo Neira Ayuso
2016-01-08 14:26 ` David Laight
2016-01-08 16:23 ` Florian Westphal
2016-01-08 16:41 ` David Laight
2016-01-08 16:55 ` Florian Westphal [this message]
2016-01-08 14:02 ` [PATCH 17/17] netfilter: nft_ct: add byte/packet counter support Pablo Neira Ayuso
2016-01-09 2:24 ` [PATCH 00/17] Netfilter updates for net-next 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=20160108165536.GE26058@breakpoint.cc \
--to=fw@strlen.de \
--cc=David.Laight@ACULAB.COM \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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).