Re: [PATCH] virtio_net: Fix queue full check

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Michael S. Tsirkin
Date: Thursday, November 4, 2010 - 5:24 am

On Tue, Nov 02, 2010 at 06:17:30PM +0200, Michael S. Tsirkin wrote:

I thought about this some more.  I think the original
code is actually correct in returning ENOSPC: indirect
buffers are nice, but it's a mistake
to rely on them as a memory allocation might fail.

And if you look at virtio-net, it is dropping packets
under memory pressure which is not really a happy outcome:
the packet will get freed, reallocated and we get another one,
adding pressure on the allocator instead of releasing it
until we free up some buffers.

So I now think we should calculate the capacity
assuming non-indirect entries, and if we manage to
use indirect, all the better.

So below is what I propose now - as a replacement for
my original patch.  Krishna Kumar, Rusty, what do you think?

Separately I'm also considering moving the
	if (vq->num_free < out + in)
check earlier in the function to keep all users honest,
but need to check what the implications are for e.g. block.
Thoughts on this?

---->

virtio: return correct capacity to users

We can't rely on indirect buffers for capacity
calculations because they need a memory allocation
which might fail.

So return the number of buffers we can guarantee users.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 1475ed6..cc2f73e 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -230,9 +230,6 @@ add_head:
 	pr_debug("Added buffer head %i to %p\n", head, vq);
 	END_USE(vq);
 
-	/* If we're indirect, we can fit many (assuming not OOM). */
-	if (vq->indirect)
-		return vq->num_free ? vq->vring.num : 0;
 	return vq->num_free;
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp);
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] virtio_net: Fix queue full check, Krishna Kumar, (Wed Oct 27, 10:10 pm)
Re: [PATCH] virtio_net: Fix queue full check, Rusty Russell, (Fri Oct 29, 2:47 am)
Re: [PATCH] virtio_net: Fix queue full check, Krishna Kumar2, (Fri Oct 29, 3:55 am)
Re: [PATCH] virtio_net: Fix queue full check, Rusty Russell, (Fri Oct 29, 4:28 am)
Re: [PATCH] virtio_net: Fix queue full check, Michael S. Tsirkin, (Tue Nov 2, 9:17 am)
Re: [PATCH] virtio_net: Fix queue full check, Michael S. Tsirkin, (Thu Nov 4, 5:24 am)
Re: [PATCH] virtio_net: Fix queue full check, Krishna Kumar2, (Thu Nov 4, 9:17 am)
Re: [PATCH] virtio_net: Fix queue full check, Michael S. Tsirkin, (Thu Nov 4, 9:45 am)
Re: [PATCH] virtio_net: Fix queue full check, Rusty Russell, (Sun Nov 7, 4:08 pm)
Re: [PATCH] virtio_net: Fix queue full check, Krishna Kumar2, (Mon Nov 8, 9:26 pm)
Re: [PATCH] virtio_net: Fix queue full check, Michael S. Tsirkin, (Tue Nov 9, 6:15 am)
Re: [PATCH] virtio_net: Fix queue full check, Michael S. Tsirkin, (Tue Nov 9, 8:30 am)
Re: [PATCH] virtio_net: Fix queue full check, Krishna Kumar2, (Tue Nov 9, 8:30 am)