lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <a967d7d00712201712m6981373ife9a333be7d343e0@mail.gmail.com>
Date:	Thu, 20 Dec 2007 17:12:12 -0800
From:	"Keyur Chudgar" <kchudgar.linux@...il.com>
To:	netdev@...r.kernel.org
Subject: skbuff data pointer alignment requirement

Hi,

I would like to ask/suggest some requirements for memory alignment in
Linux memory allocation. Is there any way, in Linux kernel socket
buffer allocation scheme, particularly the data pointer of the skb and
not the skb itself, that, if I want to have the address of allocated
data block to be 256 bytes aligned? If there is any way, can you
please let me know about it?

Based on my review of memory allocation for data pointer of skb, in
the __alloc_skb function, file skbuff.c, the data pointer is allocated
based on the size specified. It is allocated by kmalloc.

The kmalloc is allocating from one of the fixed sized pools, for which
the size will be in power of 2. So, for example, if the size specified
is 100, I will get the buffer of size 128 bytes, and for which the
address will also be 128 bytes aligned.

If some hardware requirements, for example is, they need to have 256
bytes aligned address for them to do the DMA, no matter what the
packet size is. In this kind of cases, can you guide me what should I
do? Is there any way already in Linux I can do this?

If there is no way we can do it as of now, can I propose to have some
implementation in __alloc_skb function, so that, if one has defined a
flag, specifying the minimum alignment requirement for data pointer,
kmalloc will give the pointer with the specified alignment? I have
done this change in
the __alloc_skb function as folloing:

#if defined SKB_ADDR_MIN_ALIGN
                size+=SKB_ADDR_MIN_ALIGN;
#endif

Just before following code:
        size = SKB_DATA_ALIGN(size);

        data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info),
                        gfp_mask, node);

In the above specified situation, I can define SKB_ADDR_MIN_ALIGN =
256 in my Makefile or I don't define it at all if I am okay with
default alignment size.

Similarly, if one wants to reserve a specific amount of data as soon
as the data pointer is allocated in __alloc_skb, he/she can define
flag for this. We can add following code in the same function
__alloc_skb,

#if defined SKB_RESERVE_MIN
        skb_reserve(skb,SKB_RESERVE_MIN);
#endif

Just after following code:
        memset(skb, 0, offsetof(struct sk_buff, truesize));
        skb->truesize = size + sizeof(struct sk_buff);
        atomic_set(&skb->users, 1);
        skb->head = data;
        skb->data = data;
        skb->tail = data;
        skb->end  = data + size;

By doing it this way, others will not get impacted if they have not
defined these flags. But, people who need to have some requirements
like this, they can define these flags.

Would you please kindly advice on the suggested implenentation or let
me know if you think Linux can already provide some means of
fulfilling these requirements? I would really appreciate your
feedback.

Sincerely,
Keyur Chudgar

View attachment "skbuff.c" of type "text/plain" (52143 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ