Am Mittwoch, 11. Juli 2007 schrieb Rusty Russell:
> There will be some internal limit on how many buffers the virtio
> implementation supports, but depends on that implementation.  It could
> be a number of buffers or a total number of descriptors.

I would suggest to implement a limit in the device driver as well. Otherwise 
the network driver could allocate a huge amount of guest memory if the virtio
implementation accepts a large amount of buffers. This memory is not swappable 
and reclaimable by the memory management, so we should be careful. 

So what about something like this:

+       for (;vi->num < MAX_BUFS;) {
+               skb = netdev_alloc_skb(vi->ndev, MAX_PACKET_LEN);
+               if (unlikely(!skb))
+                       break;
+
+               skb_put(skb, MAX_PACKET_LEN);
+               num = skb_to_sgvec(skb, sg, 0, skb->len);
+               skb_queue_head(&vi->recv, skb);
+
+               err = vi->vq_recv->ops->add_buf(vi->vq_recv, sg, 0, num, skb);
+               if (err) {
+                       skb_unlink(skb, &vi->recv);
+                       kfree_skb(skb);
+                       break;
+               }
+               vi->num++
+       }



Christian
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization

Reply via email to