From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyecX-0007Hq-AU for qemu-devel@nongnu.org; Tue, 17 Nov 2015 06:40:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyecW-0000Oi-2w for qemu-devel@nongnu.org; Tue, 17 Nov 2015 06:40:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyecV-0000Nx-M9 for qemu-devel@nongnu.org; Tue, 17 Nov 2015 06:40:19 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id A687AA3B70 for ; Tue, 17 Nov 2015 11:40:18 +0000 (UTC) Date: Tue, 17 Nov 2015 13:40:12 +0200 From: Victor Kaplansky Message-ID: <20151117133456-mutt-send-email-victork@redhat.com> References: <1447754588-31605-1-git-send-email-victork@redhat.com> <20151117130042-mutt-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151117130042-mutt-send-email-mst@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4] tests/vhost-user-bridge: implement logging of dirty pages List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Marc-Andre Lureau , qemu-devel@nongnu.org, peterx@redhat.com On Tue, Nov 17, 2015 at 01:04:33PM +0200, Michael S. Tsirkin wrote: > On Tue, Nov 17, 2015 at 12:04:06PM +0200, Victor Kaplansky wrote: > > During migration devices continue writing to the guest's memory. > > The writes has to be reported to QEMU. This change implements > > minimal support in vhost-user-bridge required for successful > > migration of a guest with virtio-net device. > > > > Signed-off-by: Victor Kaplansky > > --- > > v4: > > - implement set_vring_enable() > > - stop the device on vubr_get_vring_base_exec() and > > start on setting kick_fd as a work-around to QEMU bug > > enabling vrings too early. > > You do want to address that FIXME but at least it's > a documented bug. > > > v3: > > - Get rid of vhost_log_chunk_t. Just use uint8_t. > > - Implement vubr_set_log_fd_exec(). > > - Kick the log if log_call_fd has been set up. > > - Mark bits in log table atomically to enable more then one > > simultaneous vhost-user backend. > > - Fix the calculations of required log table size in an > > assert. > > - Fix the coding style: only single space before assignment > > operator. > > - Add a comment on the hack to determine that queues are > > ready for processing. > > - Other minor cosmetic fixes. > > v2: > > - use log_guest_addr for used ring reported by qemu instead of > > translating. > > - use mmap_size and mmap_offset defined in new > > VHOST_USER_SET_LOG_BASE interface. See the patch > > "vhost-user: modify SET_LOG_BASE to pass mmap size and > > offset". > > - start logging dirty pages only after the appropriate feature > > is set by a VHOST_USER_GET_PROTOCOL_FEATURES request. > > - updated TODO list. > > > > tests/vhost-user-bridge.c | 220 ++++++++++++++++++++++++++++++++++++++++------ > > 1 file changed, 195 insertions(+), 25 deletions(-) > > > > diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c > > index 864f69e..7bdfc98 100644 > > --- a/tests/vhost-user-bridge.c > > +++ b/tests/vhost-user-bridge.c > > @@ -466,11 +507,39 @@ vubr_virtqueue_kick(VubrVirtq *vq) > > } > > > > static void > > +vubr_log_page(uint8_t *log_table, uint64_t page) > > +{ > > + DPRINT("Logged dirty guest page: %"PRId64"\n", page); > > + atomic_or(&log_table[page / 8], 1 << (page % 8)); > > One thing you definitely want here is a check > against log size. > Otherwise it's a security hole: > remote can corrupt your memory by making you > set random bits outside the mapped buffer. > > What to do on error? Probably abort. > vubr_log_write() has an assert checking the address. In the next version I'll replace if by an if statement. > > +} > > + > > +static void > > +vubr_log_write(VubrDev *dev, uint64_t address, uint64_t length) > > +{ > > + uint64_t page; > > + > > + if (!(dev->features & (1ULL << VHOST_F_LOG_ALL)) || > > + !dev->log_table || !length) { > > + return; > > + } > > + > > + assert(dev->log_size > ((address + length - 1) / VHOST_LOG_PAGE / 8)); > > + > > + page = address / VHOST_LOG_PAGE; > > + while (page * VHOST_LOG_PAGE < address + length) { > > + vubr_log_page(dev->log_table, page); > > + page += VHOST_LOG_PAGE; > > + } > > + vubr_log_kick(dev); > > +} > > + -- Victor