Re: [PATCH RFC] virtio: put last seen used index into ring itself

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Michael S. Tsirkin
Date: Wednesday, May 5, 2010 - 11:19 pm

On Thu, May 06, 2010 at 12:01:34PM +0930, Rusty Russell wrote:

Exactly.


I thought about this really hard and I don't think it's
necessarily racy, as long as (pseudo code):
	guest:
		start:
			disable interrupts
			read(used)
			write(last used)
			enable interrupts
			mb()
			if read(used)
				goto start

	host:
		write used
		mb()
		if (reached(read(last used), used))
			interrupt

IOW, guest does read then write then read, host does write then read.

Now, the only way to miss an interrupt is if we read last used
value before it is written so we think guest is still processing.
But if that happens, this means that host has written used before
guest updated last used, and for this reason peek will see
used value and restart polling.

IOW, to miss an interrupt host must read a stale value.
For this host must read before guest write, then
host write already happened, so second read in
guest will see an updated value host has written.


Now, I also added an mb() in guest between read and write so
that last used index write can not get ahead of used index read.
It does feel good to have it there, but I can not say why
it's helpful. Works fine without it, but then these
subtle races might be hard to trigger. What do you think?


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH RFC] virtio: put last seen used index into ring itself, Michael S. Tsirkin, (Wed May 5, 1:58 pm)
Re: [PATCH RFC] virtio: put last seen used index into ring ..., Michael S. Tsirkin, (Wed May 5, 11:19 pm)
Re: [PATCH RFC] virtio: put last seen used index into ring ..., Michael S. Tsirkin, (Sun May 9, 2:06 pm)
Re: [PATCH RFC] virtio: put last seen used index into ring ..., Michael S. Tsirkin, (Tue May 11, 12:48 pm)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Tue May 11, 12:52 pm)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Wed May 19, 3:33 pm)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Thu May 20, 3:04 am)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Sun May 23, 8:31 am)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Sun May 23, 8:51 am)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Sun May 23, 8:56 am)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Sun May 23, 10:28 am)
Re: [Qemu-devel] [PATCH RFC] virtio: put last seen used in ..., Michael S. Tsirkin, (Mon May 24, 1:05 am)