netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, linux-kernel@vger.kernel.org,
	linux-wpan@vger.kernel.org, aar@pengutronix.de,
	pablo@netfilter.org, kaber@trash.net, kadlec@blackhole.kfki.hu,
	pshelar@nicira.com, kuznet@ms2.inr.ac.ru, jmorris@namei.org,
	yoshfuji@linux-ipv6.org, netfilter-devel@vger.kernel.org,
	dev@openvswitch.org, steffen.klassert@secunet.com,
	herbert@gondor.apana.org.au, bsingharora@gmail.com,
	Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [PATCH net-next 9/9] taskstats: use the libnl API to align nlattr on 64-bit
Date: Fri, 22 Apr 2016 17:31:24 +0200	[thread overview]
Message-ID: <1461339084-3849-10-git-send-email-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <1461339084-3849-1-git-send-email-nicolas.dichtel@6wind.com>

Goal of this patch is to use the new libnl API to align netlink attribute
when needed.
The layout of the netlink message will be a bit different after the patch,
because the padattr (TASKSTATS_TYPE_STATS) will be inside the nested
attribute instead of before it.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 kernel/taskstats.c | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 21f82c29c914..b3f05ee20d18 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -357,10 +357,6 @@ static int parse(struct nlattr *na, struct cpumask *mask)
 	return ret;
 }
 
-#if defined(CONFIG_64BIT) && !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
-#define TASKSTATS_NEEDS_PADDING 1
-#endif
-
 static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
 {
 	struct nlattr *na, *ret;
@@ -370,29 +366,6 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
 			? TASKSTATS_TYPE_AGGR_PID
 			: TASKSTATS_TYPE_AGGR_TGID;
 
-	/*
-	 * The taskstats structure is internally aligned on 8 byte
-	 * boundaries but the layout of the aggregrate reply, with
-	 * two NLA headers and the pid (each 4 bytes), actually
-	 * force the entire structure to be unaligned. This causes
-	 * the kernel to issue unaligned access warnings on some
-	 * architectures like ia64. Unfortunately, some software out there
-	 * doesn't properly unroll the NLA packet and assumes that the start
-	 * of the taskstats structure will always be 20 bytes from the start
-	 * of the netlink payload. Aligning the start of the taskstats
-	 * structure breaks this software, which we don't want. So, for now
-	 * the alignment only happens on architectures that require it
-	 * and those users will have to update to fixed versions of those
-	 * packages. Space is reserved in the packet only when needed.
-	 * This ifdef should be removed in several years e.g. 2012 once
-	 * we can be confident that fixed versions are installed on most
-	 * systems. We add the padding before the aggregate since the
-	 * aggregate is already a defined type.
-	 */
-#ifdef TASKSTATS_NEEDS_PADDING
-	if (nla_put(skb, TASKSTATS_TYPE_NULL, 0, NULL) < 0)
-		goto err;
-#endif
 	na = nla_nest_start(skb, aggr);
 	if (!na)
 		goto err;
@@ -401,7 +374,8 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
 		nla_nest_cancel(skb, na);
 		goto err;
 	}
-	ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
+	ret = nla_reserve_64bit(skb, TASKSTATS_TYPE_STATS,
+				sizeof(struct taskstats), TASKSTATS_TYPE_NULL);
 	if (!ret) {
 		nla_nest_cancel(skb, na);
 		goto err;
@@ -500,10 +474,9 @@ static size_t taskstats_packet_size(void)
 	size_t size;
 
 	size = nla_total_size(sizeof(u32)) +
-		nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
-#ifdef TASKSTATS_NEEDS_PADDING
-	size += nla_total_size(0); /* Padding for alignment */
-#endif
+		nla_total_size_64bit(sizeof(struct taskstats)) +
+		nla_total_size(0);
+
 	return size;
 }
 
-- 
2.8.1

  parent reply	other threads:[~2016-04-22 15:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 15:31 [PATCH net-next 0/9] netlink: align attributes when needed (patchset #1) Nicolas Dichtel
2016-04-22 15:31 ` [PATCH net-next 1/9] libnl: fix help of _64bit functions Nicolas Dichtel
2016-04-22 15:31 ` [PATCH net-next 2/9] libnl: nla_put_le64(): align on a 64-bit area Nicolas Dichtel
     [not found]   ` <1461339084-3849-3-git-send-email-nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-22 16:51     ` Eric Dumazet
2016-04-23 17:05       ` Alexander Aring
2016-04-23 17:28         ` Alexander Aring
     [not found]           ` <9d534571-916d-b368-a398-7f03a1f512ec-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-04-25  7:41             ` Nicolas Dichtel
2016-04-22 15:31 ` [PATCH net-next 3/9] libnl: nla_put_be64(): " Nicolas Dichtel
2016-04-22 15:31 ` [PATCH net-next 4/9] libnl: nla_put_net64(): " Nicolas Dichtel
     [not found] ` <1461339084-3849-1-git-send-email-nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-22 15:31   ` [PATCH net-next 5/9] libnl: nla_put_s64(): " Nicolas Dichtel
2016-04-22 15:31   ` [PATCH net-next 6/9] libnl: nla_put_msecs(): " Nicolas Dichtel
2016-04-24  0:13   ` [PATCH net-next 0/9] netlink: align attributes when needed (patchset #1) David Miller
2016-04-22 15:31 ` [PATCH net-next 7/9] libnl: add nla_put_u64_64bit() helper Nicolas Dichtel
2016-04-22 15:31 ` [PATCH net-next 8/9] xfrm: align nlattr properly when needed Nicolas Dichtel
2016-04-22 15:31 ` Nicolas Dichtel [this message]
     [not found]   ` <1461339084-3849-10-git-send-email-nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-27  1:14     ` [PATCH net-next 9/9] taskstats: use the libnl API to align nlattr on 64-bit Balbir Singh
     [not found]       ` <57201287.80002-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-27  7:29         ` Nicolas Dichtel
2016-04-27 12:29           ` Balbir Singh
     [not found]             ` <5720B0A2.1030405-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-27 15:46               ` Nicolas Dichtel
2016-04-27 15:47                 ` [PATCH net-next] taskstats: fix nl parsing in accounting/getdelays.c Nicolas Dichtel
     [not found]                   ` <1461772077-3216-1-git-send-email-nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-27 15:49                     ` Nicolas Dichtel
     [not found]                       ` <5720DFA1.3080503-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-27 15:53                         ` [PATCH net-next v2] " Nicolas Dichtel
     [not found]                           ` <1461772388-3763-1-git-send-email-nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2016-04-27 16:56                             ` David Miller
2016-04-27 16:41             ` [PATCH net-next 9/9] taskstats: use the libnl API to align nlattr on 64-bit 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=1461339084-3849-10-git-send-email-nicolas.dichtel@6wind.com \
    --to=nicolas.dichtel@6wind.com \
    --cc=aar@pengutronix.de \
    --cc=bsingharora@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jmorris@namei.org \
    --cc=kaber@trash.net \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=pshelar@nicira.com \
    --cc=steffen.klassert@secunet.com \
    --cc=yoshfuji@linux-ipv6.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).