From patchwork Sat Feb 23 20:49:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 222746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ECA7A2C0299 for ; Sun, 24 Feb 2013 07:49:51 +1100 (EST) Received: from localhost ([::1]:41451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9M2Y-00069G-5J for incoming@patchwork.ozlabs.org; Sat, 23 Feb 2013 15:49:50 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9M2J-00068W-6S for qemu-devel@nongnu.org; Sat, 23 Feb 2013 15:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9M2C-0002wW-4K for qemu-devel@nongnu.org; Sat, 23 Feb 2013 15:49:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9M2B-0002ux-Sm for qemu-devel@nongnu.org; Sat, 23 Feb 2013 15:49:28 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1NKnP8Q027123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 23 Feb 2013 15:49:25 -0500 Received: from redhat.com (vpn1-7-149.ams2.redhat.com [10.36.7.149]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r1NKnNvV007213; Sat, 23 Feb 2013 15:49:24 -0500 Date: Sat, 23 Feb 2013 22:49:29 +0200 From: "Michael S. Tsirkin" To: Jason Wang Message-ID: <20130223204929.GA19233@redhat.com> References: <2881193.PTWX93cU7x@jason-thinkpad-t430s> <20130220142352.GA22189@redhat.com> <20130220164859.GA26265@redhat.com> <5125EF70.2000902@redhat.com> <20130221112305.GA23116@redhat.com> <51278FE1.5060509@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <51278FE1.5060509@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, avi.kivity@gmail.com Subject: Re: [Qemu-devel] scp during migration with vhost fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Fri, Feb 22, 2013 at 11:33:53PM +0800, Jason Wang wrote: > On 02/21/2013 07:23 PM, Michael S. Tsirkin wrote: > > On Thu, Feb 21, 2013 at 05:57:04PM +0800, Jason Wang wrote: > >> On 02/21/2013 12:48 AM, Michael S. Tsirkin wrote: > >>> On Wed, Feb 20, 2013 at 04:23:52PM +0200, Michael S. Tsirkin wrote: > >>>> On Fri, Feb 01, 2013 at 06:03:32PM +0800, Jason Wang wrote: > >>>>> Hello all: > >>>>> > >>>>> During testing, I find doing scp during migration with vhost fails with > >>>>> warnings in guest like: > >>>>> > >>>>> Corrupted MAC on input. > >>>>> Disconnecting: Packet corrupt. > >>>>> lost connection > >>>>> > >>>>> Here's the bisect result: > >>>>> > >>>>> Commit a01672d3968cf91208666d371784110bfde9d4f8 kvm: convert to MemoryListener > >>>>> API is the last commit that works well. > >>>>> > >>>>> With commit 04097f7c5957273c578f72b9bd603ba6b1d69e33 vhost: convert to > >>>>> MemoryListener API, guest network is unusable with warning of "bad gso type" > >>>>> > >>>>> With commit d743c382861eaa1e13f503b05aba5a382a7e7f7c vhost: fix incorrect > >>>>> userspace address, guest network is available, but scp during migration may > >>>>> fail. > >>>>> > >>>>> Looks like the issue is related to memory api, any thoughts? > >>>>> > >>>>> Thanks > >>>> Tried to reproduce this for a while without success. > >>>> Which command line was used? > >>>> > >>>> > >>>> -- > >>>> MST > >>> Could be we are not syncing all that we should? > >>> Does the following hack make the problem go away? > >>> > >>> diff --git a/hw/vhost.c b/hw/vhost.c > >>> index 8d41fdb..a7a0412 100644 > >>> --- a/hw/vhost.c > >>> +++ b/hw/vhost.c > >>> @@ -69,6 +69,8 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev, > >>> hwaddr end_addr) > >>> { > >>> int i; > >>> + start_addr = 0x0; > >>> + end_addr = ~0x0ull; > >>> > >>> if (!dev->log_enabled || !dev->started) { > >>> return 0; > >>> > >> Still can reproduce with this. From the bisect result, the vhost dirty > >> bitmap sync itself looks ok but something wrong when converting to > >> memory listener. > > Reading the code carefully, I found two bugs introduced during > > this conversion. Patch below, could you please try? > > > > vhost: memory sync fixes > > > > This fixes two bugs related to memory sync during > > migration: > > - ram address calculation was missing the chunk > > address, so the wrong page was dirtied > > - one after last was used instead of the > > end address of a region, which might overflow to 0 > > and cause us to skip the region when the region ends at > > ~0x0ull. > > > > Signed-off-by: Michael S. Tsirkin > > > > --- > > > > diff --git a/hw/vhost.c b/hw/vhost.c > > index 8d41fdb..dbf6b46 100644 > > --- a/hw/vhost.c > > +++ b/hw/vhost.c > > @@ -55,7 +55,7 @@ static void vhost_dev_sync_region(struct vhost_dev *dev, > > ffsll(log) : ffs(log))) { > > ram_addr_t ram_addr; > > bit -= 1; > > - ram_addr = section->offset_within_region + bit * VHOST_LOG_PAGE; > > + ram_addr = section->offset_within_region + addr + bit * VHOST_LOG_PAGE; > > memory_region_set_dirty(section->mr, ram_addr, VHOST_LOG_PAGE); > > log &= ~(0x1ull << bit); > > } > > @@ -94,7 +94,7 @@ static void vhost_log_sync(MemoryListener *listener, > > struct vhost_dev *dev = container_of(listener, struct vhost_dev, > > memory_listener); > > hwaddr start_addr = section->offset_within_address_space; > > - hwaddr end_addr = start_addr + section->size; > > + hwaddr end_addr = start_addr + section->size - 1; > > > > vhost_sync_dirty_bitmap(dev, section, start_addr, end_addr); > > } > > > > I can still reproduce the issue with this patch. Yes it's still wrong. We need the following on top. Could you try please? diff --git a/hw/vhost.c b/hw/vhost.c index dbf6b46..c324903 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -29,7 +29,7 @@ static void vhost_dev_sync_region(struct vhost_dev *dev, uint64_t end = MIN(mlast, rlast); vhost_log_chunk_t *from = dev->log + start / VHOST_LOG_CHUNK; vhost_log_chunk_t *to = dev->log + end / VHOST_LOG_CHUNK + 1; - uint64_t addr = (start / VHOST_LOG_CHUNK) * VHOST_LOG_CHUNK; + uint64_t addr = 0; if (end < start) { return;