Skip to contentSkip to conversation

INDIRECT and NEXT

DISCUSSION Rusty Russell 2 participants 6 messages Oct 19, 2009 – Oct 23, 2009 1 message not in the archive virtio core

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Michael S. Tsirkin

Hi!
I note that chaining INDIRECT descriptors with NEXT currently is broken in lguest, because current ring index gets overwritten.

I agree this should be fixed, but not quite sure what you're referring to.

I could force indirect and reproduce it, but I figure asking you for details would be more efficient :)

Thanks!
Rusty.

#2 lore raw
Quoted 6 lines · Rusty Russell
Quoted 4 lines · Michael S. Tsirkin

Hi!
I note that chaining INDIRECT descriptors with NEXT currently is broken in lguest, because current ring index gets overwritten.

Quoted 7 lines

I agree this should be fixed, but not quite sure what you're referring to.

I could force indirect and reproduce it, but I figure asking you for details would be more efficient :)

Thanks!
Rusty.

I refer to this code in lguest:

	/*
	 * If this is an indirect entry, then this buffer contains a descriptor
	 * table which we handle as if it's any normal descriptor chain.
	 */
	if (desc[i].flags & VRING_DESC_F_INDIRECT) {
		if (desc[i].len % sizeof(struct vring_desc))
			errx(1, "Invalid size for indirect buffer table");

		max = desc[i].len / sizeof(struct vring_desc);
		desc = check_pointer(desc[i].addr, desc[i].len);
		i = 0;
	}

	do {
		/* Grab the first descriptor, and check it's OK. */
		iov[*out_num + *in_num].iov_len = desc[i].len;
		iov[*out_num + *in_num].iov_base
			= check_pointer(desc[i].addr, desc[i].len);
		/* If this is an input descriptor, increment that count. */
		if (desc[i].flags & VRING_DESC_F_WRITE)
			(*in_num)++;
		else {
			/*
			 * If it's an output descriptor, they're all supposed
			 * to come before any input descriptors.
			 */
			if (*in_num)
				errx(1, "Descriptor has out after in");
			(*out_num)++;
		}

		/* If we've got too many, that implies a descriptor loop. */
		if (*out_num + *in_num > max)
			errx(1, "Looped descriptor");
	} while ((i = next_desc(desc, i, max)) != max);

Imagine an indirect entry where NEXT bit is also set. This would be useful for when we can't fit a descriptor in a single indirect entry. This won't work now because we set 'i = 0' above. A solution would be to move handling indirect entry out to a separate function.

Signature · 1 line
MST
#3 lore raw
Quoted 1 line · Michael S. Tsirkin

Imagine an indirect entry where NEXT bit is also set.

Hmm, so it's not obvious whether the kvm userspace code handles it correctly either.

Want to hack something up to use NEXT + INDIRECT, then we can actually test it? If it doesn't work, this will have to be a new feature bit.

Also, we have a limitation that you can't have more descriptors than the ring size, even with indirect, due to overzealous checks...

Thanks,
Rusty.

#4 lore raw
Quoted 5 lines · Rusty Russell
Quoted 1 line · Michael S. Tsirkin

Imagine an indirect entry where NEXT bit is also set.

Hmm, so it's not obvious whether the kvm userspace code handles it correctly either.

You mean qemu? I think it doesn't, either: code there looks basically like lguest.

Quoted 5 lines

Want to hack something up to use NEXT + INDIRECT, then we can actually test it? If it doesn't work, this will have to be a new feature bit.

Also, we have a limitation that you can't have more descriptors than the ring size, even with indirect, due to overzealous checks...

Yes ... so I wonder: do we want to fix all this and add a feature bit, or wait until some guest actually wants to use such descriptors? For vhost, I implemented INDIRECT without this limitation since it looked neater to me to have a separate function for indirect anyway. This is because direct virtqueues are virtually contigious, so I can access them just by copy from user, but indirect can be spread around and so I have to go through extra translations.

Quoted 2 lines

Thanks,
Rusty.

#5 lore raw
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines · Rusty Russell

Also, we have a limitation that you can't have more descriptors than the ring size, even with indirect, due to overzealous checks...

Yes ... so I wonder: do we want to fix all this and add a feature bit, or wait until some guest actually wants to use such descriptors?

Yes, we wait until someone wants it. Then (1) we have a test case, and
(2) we can make sure we don't do those (bogus, frankly) >= ringsize checks.

Thanks,
Rusty.

#6 lore raw
Quoted 10 lines · Rusty Russell
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines · Rusty Russell

Also, we have a limitation that you can't have more descriptors than the ring size, even with indirect, due to overzealous checks...

Yes ... so I wonder: do we want to fix all this and add a feature bit, or wait until some guest actually wants to use such descriptors?

Yes, we wait until someone wants it. Then (1) we have a test case, and
(2) we can make sure we don't do those (bogus, frankly) >= ringsize checks.

OK. But for vhost, there's no reason not to do it right directly, right? guests won't depend on undefined behaviour.

Signature · 1 line
MST