From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60113 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWpIx-0002wt-RJ for qemu-devel@nongnu.org; Sun, 26 Dec 2010 07:02:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PWpIv-0006tB-HM for qemu-devel@nongnu.org; Sun, 26 Dec 2010 07:02:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PWpIv-0006sk-1a for qemu-devel@nongnu.org; Sun, 26 Dec 2010 07:02:25 -0500 Date: Sun, 26 Dec 2010 14:01:51 +0200 From: "Michael S. Tsirkin" Message-ID: <20101226120151.GA1926@redhat.com> References: <20101216095140.GB19495@redhat.com> <20101216144010.GA25333@redhat.com> <20101224092710.GA23271@redhat.com> <20101226104919.GB32000@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH 05/21] virtio: modify save/load handler to handle inuse varialble. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Yoshiaki Tamura Cc: aliguori@us.ibm.com, dlaor@redhat.com, ananth@in.ibm.com, kvm@vger.kernel.org, ohmura.kei@lab.ntt.co.jp, Marcelo Tosatti , qemu-devel@nongnu.org, vatsa@linux.vnet.ibm.com, avi@redhat.com, psuriset@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com On Sun, Dec 26, 2010 at 07:57:52PM +0900, Yoshiaki Tamura wrote: > 2010/12/26 Michael S. Tsirkin : > > On Fri, Dec 24, 2010 at 08:42:19PM +0900, Yoshiaki Tamura wrote: > >> 2010/12/24 Michael S. Tsirkin : > >> > On Fri, Dec 17, 2010 at 12:59:58AM +0900, Yoshiaki Tamura wrote: > >> >> 2010/12/16 Michael S. Tsirkin : > >> >> > On Thu, Dec 16, 2010 at 11:28:46PM +0900, Yoshiaki Tamura wrote= : > >> >> >> 2010/12/16 Michael S. Tsirkin : > >> >> >> > On Thu, Dec 16, 2010 at 04:36:16PM +0900, Yoshiaki Tamura wr= ote: > >> >> >> >> 2010/12/3 Yoshiaki Tamura : > >> >> >> >> > 2010/12/2 Michael S. Tsirkin : > >> >> >> >> >> On Wed, Dec 01, 2010 at 05:03:43PM +0900, Yoshiaki Tamur= a wrote: > >> >> >> >> >>> 2010/11/28 Michael S. Tsirkin : > >> >> >> >> >>> > On Sun, Nov 28, 2010 at 08:27:58PM +0900, Yoshiaki Ta= mura wrote: > >> >> >> >> >>> >> 2010/11/28 Michael S. Tsirkin : > >> >> >> >> >>> >> > On Thu, Nov 25, 2010 at 03:06:44PM +0900, Yoshiaki= Tamura wrote: > >> >> >> >> >>> >> >> Modify inuse type to uint16_t, let save/load to h= andle, and revert > >> >> >> >> >>> >> >> last_avail_idx with inuse if there are outstandin= g emulation. > >> >> >> >> >>> >> >> > >> >> >> >> >>> >> >> Signed-off-by: Yoshiaki Tamura > >> >> >> >> >>> >> > > >> >> >> >> >>> >> > This changes migration format, so it will break co= mpatibility with > >> >> >> >> >>> >> > existing drivers. More generally, I think migratin= g internal > >> >> >> >> >>> >> > state that is not guest visible is always a mistak= e > >> >> >> >> >>> >> > as it ties migration format to an internal impleme= ntation > >> >> >> >> >>> >> > (yes, I know we do this sometimes, but we should a= t least > >> >> >> >> >>> >> > try not to add such cases). =A0I think the right t= hing to do in this case > >> >> >> >> >>> >> > is to flush outstanding > >> >> >> >> >>> >> > work when vm is stopped. =A0Then, we are guarantee= d that inuse is 0. > >> >> >> >> >>> >> > I sent patches that do this for virtio net and blo= ck. > >> >> >> >> >>> >> > >> >> >> >> >>> >> Could you give me the link of your patches? =A0I'd l= ike to test > >> >> >> >> >>> >> whether they work with Kemari upon failover. =A0If t= hey do, I'm > >> >> >> >> >>> >> happy to drop this patch. > >> >> >> >> >>> >> > >> >> >> >> >>> >> Yoshi > >> >> >> >> >>> > > >> >> >> >> >>> > Look for this: > >> >> >> >> >>> > stable migration image on a stopped vm > >> >> >> >> >>> > sent on: > >> >> >> >> >>> > Wed, 24 Nov 2010 17:52:49 +0200 > >> >> >> >> >>> > >> >> >> >> >>> Thanks for the info. > >> >> >> >> >>> > >> >> >> >> >>> However, The patch series above didn't solve the issue.= =A0In > >> >> >> >> >>> case of Kemari, inuse is mostly > 0 because it queues t= he > >> >> >> >> >>> output, and while last_avail_idx gets incremented > >> >> >> >> >>> immediately, not sending inuse makes the state inconsis= tent > >> >> >> >> >>> between Primary and Secondary. > >> >> >> >> >> > >> >> >> >> >> Hmm. Can we simply avoid incrementing last_avail_idx? > >> >> >> >> > > >> >> >> >> > I think we can calculate or prepare an internal last_avai= l_idx, > >> >> >> >> > and update the external when inuse is decremented. =A0I'l= l try > >> >> >> >> > whether it work w/ w/o Kemari. > >> >> >> >> > >> >> >> >> Hi Michael, > >> >> >> >> > >> >> >> >> Could you please take a look at the following patch? > >> >> >> > > >> >> >> > Which version is this against? > >> >> >> > >> >> >> Oops. =A0It should be very old. > >> >> >> 67f895bfe69f323b427b284430b6219c8a62e8d4 > >> >> >> > >> >> >> >> commit 36ee7910059e6b236fe9467a609f5b4aed866912 > >> >> >> >> Author: Yoshiaki Tamura > >> >> >> >> Date: =A0 Thu Dec 16 14:50:54 2010 +0900 > >> >> >> >> > >> >> >> >> =A0 =A0 virtio: update last_avail_idx when inuse is decreas= ed. > >> >> >> >> > >> >> >> >> =A0 =A0 Signed-off-by: Yoshiaki Tamura > >> >> >> > > >> >> >> > It would be better to have a commit description explaining w= hy a change > >> >> >> > is made, and why it is correct, not just repeating what can = be seen from > >> >> >> > the diff anyway. > >> >> >> > >> >> >> Sorry for being lazy here. > >> >> >> > >> >> >> >> diff --git a/hw/virtio.c b/hw/virtio.c > >> >> >> >> index c8a0fc6..6688c02 100644 > >> >> >> >> --- a/hw/virtio.c > >> >> >> >> +++ b/hw/virtio.c > >> >> >> >> @@ -237,6 +237,7 @@ void virtqueue_flush(VirtQueue *vq, uns= igned int count) > >> >> >> >> =A0 =A0 =A0wmb(); > >> >> >> >> =A0 =A0 =A0trace_virtqueue_flush(vq, count); > >> >> >> >> =A0 =A0 =A0vring_used_idx_increment(vq, count); > >> >> >> >> + =A0 =A0vq->last_avail_idx +=3D count; > >> >> >> >> =A0 =A0 =A0vq->inuse -=3D count; > >> >> >> >> =A0} > >> >> >> >> > >> >> >> >> @@ -385,7 +386,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQu= eueElement *elem) > >> >> >> >> =A0 =A0 =A0unsigned int i, head, max; > >> >> >> >> =A0 =A0 =A0target_phys_addr_t desc_pa =3D vq->vring.desc; > >> >> >> >> > >> >> >> >> - =A0 =A0if (!virtqueue_num_heads(vq, vq->last_avail_idx)) > >> >> >> >> + =A0 =A0if (!virtqueue_num_heads(vq, vq->last_avail_idx + = vq->inuse)) > >> >> >> >> =A0 =A0 =A0 =A0 =A0return 0; > >> >> >> >> > >> >> >> >> =A0 =A0 =A0/* When we start there are none of either input = nor output. */ > >> >> >> >> @@ -393,7 +394,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQu= eueElement *elem) > >> >> >> >> > >> >> >> >> =A0 =A0 =A0max =3D vq->vring.num; > >> >> >> >> > >> >> >> >> - =A0 =A0i =3D head =3D virtqueue_get_head(vq, vq->last_ava= il_idx++); > >> >> >> >> + =A0 =A0i =3D head =3D virtqueue_get_head(vq, vq->last_ava= il_idx + vq->inuse); > >> >> >> >> > >> >> >> >> =A0 =A0 =A0if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_= INDIRECT) { > >> >> >> >> =A0 =A0 =A0 =A0 =A0if (vring_desc_len(desc_pa, i) % sizeof(= VRingDesc)) { > >> >> >> >> > >> >> >> > > >> >> >> > Hmm, will virtio_queue_empty be wrong now? What about virtqu= eue_avail_bytes? > >> >> >> > >> >> >> I think there are two problems. > >> >> >> > >> >> >> 1. When to update last_avail_idx. > >> >> >> 2. The ordering issue you're mentioning below. > >> >> >> > >> >> >> The patch above is only trying to address 1 because last time = you > >> >> >> mentioned that modifying last_avail_idx upon save may break th= e > >> >> >> guest, which I agree. =A0If virtio_queue_empty and > >> >> >> virtqueue_avail_bytes are only used internally, meaning invisi= ble > >> >> >> to the guest, I guess the approach above can be applied too. > >> >> > > >> >> > So IMHO 2 is the real issue. This is what was problematic > >> >> > with the save patch, otherwise of course changes in save > >> >> > are better than changes all over the codebase. > >> >> > >> >> All right. =A0Then let's focus on 2 first. > >> >> > >> >> >> > Previous patch version sure looked simpler, and this seems f= unctionally > >> >> >> > equivalent, so my question still stands: here it is rephrase= d in a > >> >> >> > different way: > >> >> >> > > >> >> >> > =A0 =A0 =A0 =A0assume that we have in avail ring 2 requests = at start of ring: A and B in this order > >> >> >> > > >> >> >> > =A0 =A0 =A0 =A0host pops A, then B, then completes B and flu= shes > >> >> >> > > >> >> >> > =A0 =A0 =A0 =A0now with this patch last_avail_idx will be 1,= and then > >> >> >> > =A0 =A0 =A0 =A0remote will get it, it will execute B again. = As a result > >> >> >> > =A0 =A0 =A0 =A0B will complete twice, and apparently A will = never complete. > >> >> >> > > >> >> >> > > >> >> >> > This is what I was saying below: assuming that there are > >> >> >> > outstanding requests when we migrate, there is no way > >> >> >> > a single index can be enough to figure out which requests > >> >> >> > need to be handled and which are in flight already. > >> >> >> > > >> >> >> > We must add some kind of bitmask to tell us which is which. > >> >> >> > >> >> >> I should understand why this inversion can happen before solvi= ng > >> >> >> the issue. > >> >> > > >> >> > It's a fundamental thing in virtio. > >> >> > I think it is currently only likely to happen with block, I thi= nk tap > >> >> > currently completes things in order. =A0In any case relying on = this in the > >> >> > frontend is a mistake. > >> >> > > >> >> >> =A0Currently, how are you making virio-net to flush > >> >> >> every requests for live migration? =A0Is it qemu_aio_flush()? > >> >> > > >> >> > Think so. > >> >> > >> >> If qemu_aio_flush() is responsible for flushing the outstanding > >> >> virtio-net requests, I'm wondering why it's a problem for Kemari. > >> >> As I described in the previous message, Kemari queues the > >> >> requests first. =A0So in you example above, it should start with > >> >> > >> >> virtio-net: last_avai_idx 0 inuse 2 > >> >> event-tap: {A,B} > >> >> > >> >> As you know, the requests are still in order still because net > >> >> layer initiates in order. =A0Not about completing. > >> >> > >> >> In the first synchronization, the status above is transferred. =A0= In > >> >> the next synchronization, the status will be as following. > >> >> > >> >> virtio-net: last_avai_idx 1 inuse 1 > >> >> event-tap: {B} > >> > > >> > OK, this answers the ordering question. > >> > >> Glad to hear that! > >> > >> > Another question: at this point we transfer this status: both > >> > event-tap and virtio ring have the command B, > >> > so the remote will have: > >> > > >> > virtio-net: inuse 0 > >> > event-tap: {B} > >> > > >> > Is this right? This already seems to be a problem as when B comple= tes > >> > inuse will go negative? > >> > >> I think state above is wrong. =A0inuse 0 means there shouldn't be > >> any requests in event-tap. =A0Note that the callback is called only > >> when event-tap flushes the requests. > >> > >> > Next it seems that the remote virtio will resubmit B to event-tap.= The > >> > remote will then have: > >> > > >> > virtio-net: inuse 1 > >> > event-tap: {B, B} > >> > > >> > This looks kind of wrong ... will two packets go out? > >> > >> No. =A0Currently, we're just replaying the requests with pio/mmio. > > > > You do? =A0What purpose do the hooks in bdrv/net serve then? > > A placeholder for the future? >=20 > Not only for that reason. The hooks in bdrv/net is the main > function that queues requests and starts synchronization. > pio/mmio hooks are there for recording what initiated the > requests monitored in bdrv/net layer. I would like to remove > pio/mmio part if we could make bdrv/net level replay is possible. >=20 > Yoshi I think I begin see. So when event-tap does a replay, we will probably need to pass the inuse value. But since we generally don't try to support new->old cross-version migrations in qemu, my guess is that it is better not to change the format in anticipation right now. So basically for now we just need to add a comment explaining the reason for moving last_avail_idx back. Does something like the below (completely untested) make sense? Signed-off-by: Michael S. Tsirkin diff --git a/hw/virtio.c b/hw/virtio.c index 07dbf86..d1509f28 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -665,12 +665,20 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) qemu_put_be32(f, i); =20 for (i =3D 0; i < VIRTIO_PCI_QUEUE_MAX; i++) { + /* For regular migration inuse =3D=3D 0 always as + * requests are flushed before save. However,=20 + * event-tap log when enabled introduces an extra + * queue for requests which is not being flushed, + * thus the last inuse requests are left in the event-tap queue. + * Move the last_avail_idx value sent to the remote back + * to make it repeat the last inuse requests. */ + uint16_t last_avail =3D vdev->vq[i].last_avail_idx - vdev->vq[i]= .inuse; if (vdev->vq[i].vring.num =3D=3D 0) break; =20 qemu_put_be32(f, vdev->vq[i].vring.num); qemu_put_be64(f, vdev->vq[i].pa); - qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); + qemu_put_be16s(f, &last_avail); if (vdev->binding->save_queue) vdev->binding->save_queue(vdev->binding_opaque, i, f); }