Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2870552ybl; Sun, 8 Dec 2019 02:34:10 -0800 (PST) X-Google-Smtp-Source: APXvYqyo9R8OHhFktpBlKN3M0rVcfQKnPN1A2002X9MnqJZj2/IykXNTmCGIpJFiZaGR+1gCyX/A X-Received: by 2002:a05:6830:1af8:: with SMTP id c24mr17164274otd.362.1575801250848; Sun, 08 Dec 2019 02:34:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575801250; cv=none; d=google.com; s=arc-20160816; b=bowj3rh8OLBifHKg0iMWAZQVRJFn/7YIbxQHl3KrZs5wLjmT5qysDaxyuyOo03nUbz UQNTvQGUgQvYMAdnTCpkOgC8d/3mqjqJC25VSwUOH/C6fvqnSihGwgBml7KRBHV7RFfl doV7EP65bW6oRovUujTolWRltoaTs7mqeYtNgFLN5OC9t6xdWZwiDfjDYk2bQGbnGZv7 3W2gMcx8klPGon8AyiW7/mlKmGdkNcUlm5vasaGTe76YYegBDNROU1d0WLrbvQ9c8Nrp TEfXZxCGUZoxIOYpz5QsT/2kcmcvK3JsRXpq6VIMcimVAOqc8yC+mLRIfidNPRHqizZJ 3EQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=m/XMm08gR2sjLP1gEIf1XClkapbPvq6gpn+AbMcpJ+I=; b=MaC5b8db2vNPYADP+IOd5Ie/J6zDq4VCPDxX/WAl3+unhu91J73SFAxdxYO8LfVdzY ysYdsY1H3sy1PchbBktNONPB93PDJMInr3mV9bhBvIXea4eDDjxmn4CfIu+Ld8ZRp9xe k6FSR4FwqK25DvKS4QCp1WS9eqYAVqcNUH/NOqIpqAgpv2fDIsz4xO1iLUG7kzFM9CW3 JrTBZ9P+zT5S/4x0DAGkFpIncY3JcKqXwYlD8yiVQQa6SVPFcy4uF8ocyOGpo6xnmvVG jyipvjWlnSx9TVMwzzlAozRGCqyyUbFznOKdVruGFUXA6N9OabmOLQHB7eyGWwFDGlve bq8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p129si10079255oig.118.2019.12.08.02.33.57; Sun, 08 Dec 2019 02:34:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726453AbfLHKd0 (ORCPT + 99 others); Sun, 8 Dec 2019 05:33:26 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:43356 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbfLHKd0 (ORCPT ); Sun, 8 Dec 2019 05:33:26 -0500 Received: by mail-oi1-f196.google.com with SMTP id x14so3796033oic.10; Sun, 08 Dec 2019 02:33:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m/XMm08gR2sjLP1gEIf1XClkapbPvq6gpn+AbMcpJ+I=; b=Um+/KhIzVFAq2vKsJqrvV6jYnzMvw1U5d6TWczosi7KTPjD3cLnwbO7cf6zqVsFyBj 6aaSsK5Oi99Jx3z1+f7HixOFVUJfB5Wv03tm77I8kQGq2dvpE9zn4KT7W+Ofp0eU6MSA swMkpsM+ZF0imXs+bxZYNYCN3uUa3hDrc0GrV18HSGKDGZL4b4tt/x8/ZV7s1JHmfnP6 8uNn9Ug2Mcurz2v2VX85DGLn4F57vC8f1V4YoBletw86pU3RN/PP4KXb1BPbvHuM5H8Y GkNTmTFql42a+PFQwftuJDReOTJGncNnerXtXOMANRXnZK4hOukCdNAn8qkgomHWvw+p cxhQ== X-Gm-Message-State: APjAAAUDAADFuiUgJDVathLWDubGdgZbxFmiNwWUrn++sHFDXjGFaXzX p5tvu/4YuBS8FnyB1tzJd7dXVxk6J4gB3iP0LuadWQ== X-Received: by 2002:aca:4e87:: with SMTP id c129mr19360701oib.153.1575801205174; Sun, 08 Dec 2019 02:33:25 -0800 (PST) MIME-Version: 1.0 References: <20191121183404.6e183d06@canb.auug.org.au> <20191207164111.fpnpoipaiadaxyde@salvia> In-Reply-To: <20191207164111.fpnpoipaiadaxyde@salvia> From: Geert Uytterhoeven Date: Sun, 8 Dec 2019 11:33:13 +0100 Message-ID: Subject: Re: nf_flow on big-endian (was: Re: linux-next: build warning after merge of the net-next tree) To: Pablo Neira Ayuso Cc: Stephen Rothwell , David Miller , Networking , Linux Next Mailing List , Linux Kernel Mailing List , NetFilter , Jiri Pirko , Jozsef Kadlecsik , Florian Westphal Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pablo, On Sat, Dec 7, 2019 at 5:41 PM Pablo Neira Ayuso wrote: > On Tue, Nov 26, 2019 at 12:06:03PM +0100, Geert Uytterhoeven wrote: > > On Thu, Nov 21, 2019 at 8:36 AM Stephen Rothwell wrote: > > > After merging the net-next tree, today's linux-next build (powerpc > > > allyesconfig) produced this warning: > > > > > > net/netfilter/nf_flow_table_offload.c: In function 'nf_flow_rule_match': > > > net/netfilter/nf_flow_table_offload.c:80:21: warning: unsigned conversion from 'int' to '__be16' {aka 'short unsigned int'} changes value from '327680' to '0' [-Woverflow] > > > 80 | mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN; > > > | ^~~~~~~~~~~~ > > > > > > Introduced by commit > > > > > > c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support") > > > > This is now upstream, and must be completely broken on big-endian > > platforms. > > > > The other user of the flags field looks buggy, too > > (net/core/flow_dissector.c:__skb_flow_dissect_tcp()[*]): > > > > key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF)); > > > > Disclaimer: I'm not familiar with the code or protocol, so below are just > > my gut feelings. > > > > struct flow_dissector_key_tcp { > > __be16 flags; > > }; > > > > Does this have to be __be16, i.e. does it go over the wire? > > If not, this should probably be __u16, and set using > > "be32_to_cpu(flags) >> 16"? > > If yes, "cpu_to_be16(be32_to_cpu(flags) >> 16)"? > > (Ugh, needs convenience macros) > > > > [*] ac4bb5de27010e41 ("net: flow_dissector: add support for dissection > > of tcp flags") > > I'm attaching a tentative patch, please let me know this is fixing up > this issue there. Thanks, this looks good to me, and fixes the build warning. For this localized change (not for the global interaction), with the nits below fixed: Reviewed-by: Geert Uytterhoeven > --- a/include/net/flow_dissector.h > +++ b/include/net/flow_dissector.h > @@ -189,10 +189,17 @@ struct flow_dissector_key_eth_addrs { > > /** > * struct flow_dissector_key_tcp: > - * @flags: flags > + * @flags: TCP flags (16-bit, including the initial Data offset field bits) @pad? > + * @word: Data offset + reserved bits + TCP flags + window flag_word > */ > struct flow_dissector_key_tcp { > - __be16 flags; > + union { > + struct { > + __be16 flags; > + __be16 __pad; > + }; > + __be32 flag_word; > + }; > }; > > /** > diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c > index ca871657a4c4..83af4633f306 100644 > --- a/net/core/flow_dissector.c > +++ b/net/core/flow_dissector.c > @@ -756,7 +756,7 @@ __skb_flow_dissect_tcp(const struct sk_buff *skb, > key_tcp = skb_flow_dissector_target(flow_dissector, > FLOW_DISSECTOR_KEY_TCP, > target_container); > - key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF)); > + key_tcp->flag_word = tcp_flag_word(th); > } > > static void > diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c > index c94ebad78c5c..30205d57226d 100644 > --- a/net/netfilter/nf_flow_table_offload.c > +++ b/net/netfilter/nf_flow_table_offload.c > @@ -87,8 +87,8 @@ static int nf_flow_rule_match(struct nf_flow_match *match, > > switch (tuple->l4proto) { > case IPPROTO_TCP: > - key->tcp.flags = 0; > - mask->tcp.flags = TCP_FLAG_RST | TCP_FLAG_FIN; > + key->tcp.flag_word = 0; > + mask->tcp.flag_word = TCP_FLAG_RST | TCP_FLAG_FIN; > match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_TCP); > break; > case IPPROTO_UDP: Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds