LinuxKPI: skbuff: handle dev_alloc_skb() correctly
dev_alloc_skb() comapred to alloc_skb() reserves some headroom at the beginning of the skb which is used by drivers. Split the code for the two cases and reserve NET_SKB_PAD space, which should at least be 32 octets. Sponsored by: The FreeBSD Foundation MFC after: 3 days
This commit is contained in:
parent
7354782698
commit
9df5f29caf
@ -38,6 +38,7 @@
|
||||
#ifndef _LINUXKPI_LINUX_SKBUFF_H
|
||||
#define _LINUXKPI_LINUX_SKBUFF_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/page.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/netdev_features.h>
|
||||
@ -84,7 +85,7 @@ enum sk_buff_pkt_type {
|
||||
PACKET_OTHERHOST,
|
||||
};
|
||||
|
||||
#define NET_SKB_PAD CACHE_LINE_SIZE /* ? */
|
||||
#define NET_SKB_PAD max(CACHE_LINE_SIZE, 32)
|
||||
|
||||
struct sk_buff_head {
|
||||
/* XXX TODO */
|
||||
@ -168,6 +169,7 @@ struct sk_buff {
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
struct sk_buff *linuxkpi_alloc_skb(size_t, gfp_t);
|
||||
struct sk_buff *linuxkpi_dev_alloc_skb(size_t, gfp_t);
|
||||
void linuxkpi_kfree_skb(struct sk_buff *);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -187,7 +189,7 @@ __dev_alloc_skb(size_t len, gfp_t gfp)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = alloc_skb(len, gfp);
|
||||
skb = linuxkpi_dev_alloc_skb(len, gfp);
|
||||
SKB_IMPROVE();
|
||||
SKB_TRACE(skb);
|
||||
return (skb);
|
||||
@ -198,7 +200,7 @@ dev_alloc_skb(size_t len)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = alloc_skb(len, GFP_NOWAIT);
|
||||
skb = __dev_alloc_skb(len, GFP_NOWAIT);
|
||||
SKB_IMPROVE();
|
||||
SKB_TRACE(skb);
|
||||
return (skb);
|
||||
|
@ -80,7 +80,7 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp)
|
||||
skb = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO);
|
||||
if (skb == NULL)
|
||||
return (skb);
|
||||
skb->_alloc_len = size;
|
||||
skb->_alloc_len = len;
|
||||
skb->truesize = size;
|
||||
|
||||
skb->head = skb->data = skb->tail = (uint8_t *)(skb+1);
|
||||
@ -90,7 +90,24 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp)
|
||||
|
||||
skb->shinfo = (struct skb_shared_info *)(skb->end);
|
||||
|
||||
SKB_TRACE_FMT(skb, "data %p size %zu", skb->data, size);
|
||||
SKB_TRACE_FMT(skb, "data %p size %zu", (skb) ? skb->data : NULL, size);
|
||||
return (skb);
|
||||
}
|
||||
|
||||
struct sk_buff *
|
||||
linuxkpi_dev_alloc_skb(size_t size, gfp_t gfp)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
size_t len;
|
||||
|
||||
len = size + NET_SKB_PAD;
|
||||
skb = linuxkpi_alloc_skb(len, gfp);
|
||||
|
||||
if (skb != NULL)
|
||||
skb_reserve(skb, NET_SKB_PAD);
|
||||
|
||||
SKB_TRACE_FMT(skb, "data %p size %zu len %zu",
|
||||
(skb) ? skb->data : NULL, size, len);
|
||||
return (skb);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user