Skip to content

Commit 80df554

Browse files
NicolasDichteldavem330
authored andcommitted
taskstats: use the libnl API to align nlattr on 64-bit
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent de95c4a commit 80df554

1 file changed

Lines changed: 5 additions & 32 deletions

File tree

‎kernel/taskstats.c‎

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,6 @@ static int parse(struct nlattr *na, struct cpumask *mask)
357357
return ret;
358358
}
359359

360-
#if defined(CONFIG_64BIT) && !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
361-
#define TASKSTATS_NEEDS_PADDING 1
362-
#endif
363-
364360
static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
365361
{
366362
struct nlattr *na, *ret;
@@ -370,29 +366,6 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
370366
? TASKSTATS_TYPE_AGGR_PID
371367
: TASKSTATS_TYPE_AGGR_TGID;
372368

373-
/*
374-
* The taskstats structure is internally aligned on 8 byte
375-
* boundaries but the layout of the aggregrate reply, with
376-
* two NLA headers and the pid (each 4 bytes), actually
377-
* force the entire structure to be unaligned. This causes
378-
* the kernel to issue unaligned access warnings on some
379-
* architectures like ia64. Unfortunately, some software out there
380-
* doesn't properly unroll the NLA packet and assumes that the start
381-
* of the taskstats structure will always be 20 bytes from the start
382-
* of the netlink payload. Aligning the start of the taskstats
383-
* structure breaks this software, which we don't want. So, for now
384-
* the alignment only happens on architectures that require it
385-
* and those users will have to update to fixed versions of those
386-
* packages. Space is reserved in the packet only when needed.
387-
* This ifdef should be removed in several years e.g. 2012 once
388-
* we can be confident that fixed versions are installed on most
389-
* systems. We add the padding before the aggregate since the
390-
* aggregate is already a defined type.
391-
*/
392-
#ifdef TASKSTATS_NEEDS_PADDING
393-
if (nla_put(skb, TASKSTATS_TYPE_NULL, 0, NULL) < 0)
394-
goto err;
395-
#endif
396369
na = nla_nest_start(skb, aggr);
397370
if (!na)
398371
goto err;
@@ -401,7 +374,8 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
401374
nla_nest_cancel(skb, na);
402375
goto err;
403376
}
404-
ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
377+
ret = nla_reserve_64bit(skb, TASKSTATS_TYPE_STATS,
378+
sizeof(struct taskstats), TASKSTATS_TYPE_NULL);
405379
if (!ret) {
406380
nla_nest_cancel(skb, na);
407381
goto err;
@@ -500,10 +474,9 @@ static size_t taskstats_packet_size(void)
500474
size_t size;
501475

502476
size = nla_total_size(sizeof(u32)) +
503-
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
504-
#ifdef TASKSTATS_NEEDS_PADDING
505-
size += nla_total_size(0); /* Padding for alignment */
506-
#endif
477+
nla_total_size_64bit(sizeof(struct taskstats)) +
478+
nla_total_size(0);
479+
507480
return size;
508481
}
509482

0 commit comments

Comments
 (0)