Re: [PATCH RFC] virtio_net: fix refill related races

From: Michael S. Tsirkin
Date: Sun Dec 11 2011 - 09:42:51 EST


On Thu, Dec 08, 2011 at 03:07:29PM +1030, Rusty Russell wrote:
> On Wed, 7 Dec 2011 17:21:22 +0200, "Michael S. Tsirkin" <mst@xxxxxxxxxx> wrote:
> > Fix theoretical races related to refill work:
> > 1. After napi is disabled by ndo_stop, refill work
> > can run and re-enable it.
> > 2. Refill can reschedule itself, if this happens
> > it can run after cancel_delayed_work_sync,
> > and will access device after it is destroyed.
> >
> > As a solution, add flags to track napi state and
> > to disable refill, and toggle them on start, stop
> > and remove; check these flags on refill.
>
> Why isn't a "dont-readd" flag sufficient?
>
> Cheers,
> Rusty.

I started with that, but here's the problem I wanted to
address:

- we run out of descriptors and schedule refill work
- ndo_close runs
- refill work runs
- ndo_open runs


Now if we just disable refill, refill work will not add buffers and will
not reschedule. Now we'll never get more buffers.
We can try starting refill work from ndo_open but overall
this seems to me more risky than just splitting flags.


--
MST
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/