[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <50D042EF.7000109@6wind.com>
Date: Tue, 18 Dec 2012 11:18:23 +0100
From: Nicolas Dichtel <nicolas.dichtel@...nd.com>
To: David Laight <David.Laight@...LAB.COM>
CC: bhutchings@...arflare.com, tgraf@...g.ch, netdev@...r.kernel.org,
davem@...emloft.net
Subject: Re: [PATCH v2] netlink: align attributes on 64-bits
Le 18/12/2012 10:19, David Laight a écrit :
>> Le 17/12/2012 18:06, David Laight a écrit :
>>>> int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
>>>> {
>>>> - if (unlikely(skb_tailroom(skb) < nla_total_size(attrlen)))
>>>> + int align = IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8) ? 0 : 4;
>>>
>>> I've just realised where you are adding this!
>>> You only want to add pad if the attribute is a single 64bit item,
>>> not whenever the destination is misaligned.
>> As said in the commit log, I want to align all attributes. An attribute can be
>> like this:
>>
>> struct foo {
>> __u32 bar1;
>> __u32 bar2;
>> __u64 bar3;
>> }
>>
>> nla_put() don't know what is contained in the attribute.
>
> Put there is no need to 8-byte align something whose size isn't a
> multiple of 8 bytes.
Even if you cast the structure in a buffer and read bar3 (without any memcpy
before)?
>
>>> ...
>>>> + if (align) {
>>>> + /* Goal is to add an attribute with size 4. We know that
>>>> + * NLA_HDRLEN is 4, hence payload is 0.
>>>> + */
>>>> + __nla_reserve(skb, 0, 0);
>>>
>>> One of those zeros should be 'align - 4', then the comment
>>> can be more descriptive.
>
>> I thought if you were to research why we use 0, you would know that the first 0
>> is the type and the second is the payload size...
>
> I can tell that one is the type and the other the size, you've
> implied that the 'type+size' actually total 4 bytes.
> I don't need to find out which is which!
> Now you've told me I'd have written:
> _nla_reserve(skb, 0, align - NLA_HDRLEN);
>
> The compiler could well have tracked the value - so know it is 4.
> OTOH you might want to generate the size of 'align' without
> using a conditional.
Yes, it is the goal ;-)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists