qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: qemu-devel@nongnu.org, maxime.coquelin@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [RFC 4/7] vhost: update_mem_cb implementation
Date: Wed, 6 Dec 2017 20:09:17 +0000	[thread overview]
Message-ID: <20171206200916.GE2540@work-vm> (raw)
In-Reply-To: <20171130122754.167f424a@redhat.com>

* Igor Mammedov (imammedo@redhat.com) wrote:
> On Wed, 29 Nov 2017 18:50:23 +0000
> "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:
> 
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Add the meat of update_mem_cb;  this is called for each region,
> > to add a region to our temporary list.
> > Our temporary list is in order we look to see if this
> > region can be merged with the current head of list.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> >  hw/virtio/trace-events |  2 ++
> >  hw/virtio/vhost.c      | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 56 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> > index 4a493bcd46..92fadec192 100644
> > --- a/hw/virtio/trace-events
> > +++ b/hw/virtio/trace-events
> > @@ -2,6 +2,8 @@
> >  
> >  # hw/virtio/vhost.c
> >  vhost_section(const char *name, int r) "%s:%d"
> > +vhost_update_mem_cb(const char *name, uint64_t gpa, uint64_t size, uint64_t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64
> > +vhost_update_mem_cb_abut(const char *name, uint64_t new_size) "%s: 0x%"PRIx64
> >  
> >  # hw/virtio/virtio.c
> >  virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index c959a59fb3..7e3c6ae032 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -638,11 +638,64 @@ struct vhost_update_mem_tmp {
> >  /* Called for each MRS from vhost_update_mem */
> >  static int vhost_update_mem_cb(MemoryRegionSection *mrs, void *opaque)
> >  {
> > +    struct vhost_update_mem_tmp *vtmp = opaque;
> > +    struct vhost_memory_region *cur_vmr;
> > +    bool need_add = true;
> > +    uint64_t mrs_size;
> > +    uint64_t mrs_gpa;
> > +    uintptr_t mrs_host;
> > +
> >      if (!vhost_section(mrs)) {
> >          return 0;
> >      }
> > +    mrs_size = int128_get64(mrs->size);
> > +    mrs_gpa  = mrs->offset_within_address_space;
> > +    mrs_host = (uintptr_t)memory_region_get_ram_ptr(mrs->mr) +
> > +                         mrs->offset_within_region;
> > +
> > +    trace_vhost_update_mem_cb(mrs->mr->name, mrs_gpa, mrs_size,
> > +                              (uint64_t)mrs_host);
> > +
> > +    if (vtmp->nregions) {
> What forces you to maintain helper vhost_memory_region array
> instead of MemoryRegionSection array?

I looked at this - neither is nice.
I think I need to keep the real dev->mem->regions to keep vhost
happy.  If I've got to keep that then I've got to produce something
in that format; so producing it here and comparing it at the end
(possibly with your simple memcmp) works nicely.

The other downside of keeping working with the MemoryRegionSections is
that they have the size as an Int128 which is a pain to work with.

Dave

> > +        /* Since we already have at least one region, lets see if
> > +         * this extends it; since we're scanning in order, we only
> > +         * have to look at the last one, and the FlatView that calls
> > +         * us shouldn't have overlaps.
> > +         */
> > +        struct vhost_memory_region *prev_vmr = vtmp->regions +
> > +                                               (vtmp->nregions - 1);
> > +        uint64_t prev_gpa_start = prev_vmr->guest_phys_addr;
> > +        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start,
> > +                                                 prev_vmr->memory_size);
> > +        uint64_t prev_host_start = prev_vmr->userspace_addr;
> > +        uint64_t prev_host_end   = range_get_last(prev_host_start,
> > +                                                  prev_vmr->memory_size);
> > +
> > +        if (prev_gpa_end + 1 == mrs_gpa &&
> > +            prev_host_end + 1 == mrs_host &&
> > +            (!vtmp->dev->vhost_ops->vhost_backend_can_merge ||
> > +                vtmp->dev->vhost_ops->vhost_backend_can_merge(vtmp->dev,
> > +                    mrs_host, mrs_size,
> > +                    prev_host_start, prev_vmr->memory_size))) {
> > +            /* The two regions abut */
> > +            need_add = false;
> > +            mrs_size = mrs_size + prev_vmr->memory_size;
> > +            prev_vmr->memory_size = mrs_size;
> > +            trace_vhost_update_mem_cb_abut(mrs->mr->name, mrs_size);
> > +        }
> > +    }
> > +
> > +    if (need_add) {
> > +        vtmp->nregions++;
> > +        vtmp->regions = g_realloc_n(vtmp->regions, vtmp->nregions,
> > +                                    sizeof(vtmp->regions[0]));
> > +        cur_vmr = &vtmp->regions[vtmp->nregions - 1];
> > +        cur_vmr->guest_phys_addr = mrs_gpa;
> > +        cur_vmr->memory_size     = mrs_size;
> > +        cur_vmr->userspace_addr  = mrs_host;
> > +        cur_vmr->flags_padding = 0;
> > +    }
> >  
> > -    /* TODO */
> >      return 0;
> >  }
> >  
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2017-12-06 20:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29 18:50 [Qemu-devel] [RFC 0/7] Rework vhost memory region updates Dr. David Alan Gilbert (git)
2017-11-29 18:50 ` [Qemu-devel] [RFC 1/7] memory: address_space_iterate Dr. David Alan Gilbert (git)
2017-11-29 18:50 ` [Qemu-devel] [RFC 2/7] vhost: Move log_dirty check Dr. David Alan Gilbert (git)
2017-11-29 18:50 ` [Qemu-devel] [RFC 3/7] vhost: New memory update functions Dr. David Alan Gilbert (git)
2017-11-30 15:48   ` Igor Mammedov
2017-12-05 18:25     ` Dr. David Alan Gilbert
2017-11-29 18:50 ` [Qemu-devel] [RFC 4/7] vhost: update_mem_cb implementation Dr. David Alan Gilbert (git)
2017-11-30 11:27   ` Igor Mammedov
2017-12-06 20:09     ` Dr. David Alan Gilbert [this message]
2017-11-29 18:50 ` [Qemu-devel] [RFC 5/7] vhost: Compare new and old memory lists Dr. David Alan Gilbert (git)
2017-11-29 18:50 ` [Qemu-devel] [RFC 6/7] vhost: Copy updated region data into device state Dr. David Alan Gilbert (git)
2017-11-29 18:50 ` [Qemu-devel] [RFC 7/7] vhost: Remove vhost_set_memory and children Dr. David Alan Gilbert (git)
2017-11-30 11:22 ` [Qemu-devel] [RFC 0/7] Rework vhost memory region updates Igor Mammedov
2017-11-30 12:08   ` Dr. David Alan Gilbert
2017-11-30 12:40     ` Igor Mammedov
2017-11-30 12:47       ` Dr. David Alan Gilbert
2017-11-30 12:58         ` Igor Mammedov
2017-11-30 13:06           ` Dr. David Alan Gilbert
2017-11-30 15:08             ` Igor Mammedov
2017-11-30 15:18               ` Dr. David Alan Gilbert
2017-11-30 15:32                 ` Igor Mammedov
2017-11-30 15:41                   ` Dr. David Alan Gilbert
2017-11-30 16:51               ` Greg Kurz
2017-12-01 10:02 ` Stefan Hajnoczi
2017-12-01 10:19   ` Dr. David Alan Gilbert
2017-12-01 14:22 ` [Qemu-devel] [RFC] vhost: check if ring mapping is still valid when building memmap Igor Mammedov
2017-12-07 18:17   ` Dr. David Alan Gilbert
2017-12-08 14:42     ` Igor Mammedov
2017-12-08 17:51       ` Dr. David Alan Gilbert
2017-12-11  9:37         ` Igor Mammedov
2017-12-11 11:03           ` Dr. David Alan Gilbert
2017-12-11 13:45             ` Igor Mammedov
2017-12-11 15:43               ` Dr. David Alan Gilbert
2017-12-08 20:45   ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171206200916.GE2540@work-vm \
    --to=dgilbert@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).