[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4] tests/vhost-user-bridge: implement logging o
From: |
Victor Kaplansky |
Subject: |
Re: [Qemu-devel] [PATCH v4] tests/vhost-user-bridge: implement logging of dirty pages |
Date: |
Tue, 17 Nov 2015 13:40:12 +0200 |
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 <address@hidden>
> > ---
> > 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