SKBs and pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have written a small device driver [1] which is used to provide a
virtual NIC to a user-level protocol stack. In order to pass data
between the application process and the kernel a shared pool of page
aligned buffers is used.

When the application process wishes to send a packet it constructs the
packet in one of these shared buffers and then writes the buffer number
to a character device.  After getting a pointer to the page (in buf) the
following code is used to transmit the packet (this works fine).

void *buf <-- the buffer.

skb = dev_alloc_skb(buf_len);
memcpy(skb_put(skb, buf_len), buf, buf_len);
skb->dev = dev;
skb->protocol = eth_type_trans(skb, dev);
skb->ip_summed = CHECKSUM_UNNECESSARY;

netif_rx_ni(skb);

However, since buf is actually a pointer to a page (allocated with
get_free_page) I would like to avoid the extra copy and do something
like the following (which doesn't work):

skb = dev_alloc_skb(buf_len); // This wastes buf_len bytes.
skb_shinfo(skb)->nr_frags = 1;
skb_shinfo(skb)->frags[0].page = buf;
skb_shinfo(skb)->frags[0].page_offset = ETH_HLEN;
skb_shinfo(skb)->frags[0].size = buf_len - ETH_HLEN;
skb->len = buf_len - ETH_HLEN;
skb->data_len = buf_len - ETH_HLEN;
skb->truesize += (buf_len - ETH_HLEN);
skb->dev = dev;
skb->protocol = htons(ETH_P_IP);
skb->ip_summed = CHECKSUM_UNNECESSARY;
netif_rx_ni(skb);

This always dies with the following stack trace (Complete oops in the
form of a PNG screencap of the qemu session is available at
http://www.coverfire.com/tmp/oops.png):

__pskb_pull_tail
ip_rcv
netif_receive_skb
process_backlog
net_rx_action
__do_softirq
do_softirg

Questions:
1) Is it OK if an SKB only contains data in the page frags and no data
in the main buffer?
2) Any clue what I am doing wrong?

The complete code (without the page stuff I'm trying to get going above)
can be found at the below URL.

Any pointers would be greatly appreciated.

Thanks.

[1] - http://projects.coverfire.com/pnet/

-- 
Dan Siemon <dan@xxxxxxxxxxxxx>
OpenPGP: http://www.coverfire.com/files/pubkey.txt
Fingerprint: FB0A 2D8A A1E9 11B6 6CA3  0C53 742A 9EA8 891C BD98


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux