qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, "Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH RFC 6/9] KVM: Provide helper to sync dirty bitmap from slot to ramblock
Date: Wed, 25 Mar 2020 18:47:07 +0000	[thread overview]
Message-ID: <20200325184707.GE2635@work-vm> (raw)
In-Reply-To: <20200205141749.378044-7-peterx@redhat.com>

* Peter Xu (peterx@redhat.com) wrote:
> kvm_physical_sync_dirty_bitmap() calculates the ramblock offset in an
> awkward way from the MemoryRegionSection that passed in from the
> caller.  The truth is for each KVMSlot the ramblock offset never
> change for the lifecycle.  Cache the ramblock offset for each KVMSlot
> into the structure when the KVMSlot is created.
> 
> With that, we can further simplify kvm_physical_sync_dirty_bitmap()
> with a helper to sync KVMSlot dirty bitmap to the ramblock dirty
> bitmap of a specific KVMSlot.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  accel/kvm/kvm-all.c      | 37 +++++++++++++++++--------------------
>  include/sysemu/kvm_int.h |  2 ++
>  2 files changed, 19 insertions(+), 20 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 608216fd53..f81e7a644b 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -515,15 +515,12 @@ static void kvm_log_stop(MemoryListener *listener,
>  }
>  
>  /* get kvm's dirty pages bitmap and update qemu's */
> -static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
> -                                         unsigned long *bitmap)
> +static void kvm_slot_sync_dirty_pages(KVMSlot *slot)
>  {
> -    ram_addr_t start = section->offset_within_region +
> -                       memory_region_get_ram_addr(section->mr);
> -    ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
> +    ram_addr_t start = slot->ram_start_offset;
> +    ram_addr_t pages = slot->memory_size / qemu_real_host_page_size;
>  
> -    cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
> -    return 0;
> +    cpu_physical_memory_set_dirty_lebitmap(slot->dirty_bmap, start, pages);
>  }
>  
>  #define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
> @@ -582,12 +579,10 @@ static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
>      KVMState *s = kvm_state;
>      KVMSlot *mem;
>      hwaddr start_addr, size;
> -    hwaddr slot_size, slot_offset = 0;
> +    hwaddr slot_size;
>  
>      size = kvm_align_section(section, &start_addr);
>      while (size) {
> -        MemoryRegionSection subsection = *section;
> -
>          slot_size = MIN(kvm_max_slot_size, size);
>          mem = kvm_lookup_matching_slot(kml, start_addr, slot_size);
>          if (!mem) {
> @@ -596,12 +591,7 @@ static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,
>          }
>  
>          kvm_slot_get_dirty_log(s, mem);
> -
> -        subsection.offset_within_region += slot_offset;
> -        subsection.size = int128_make64(slot_size);
> -        kvm_get_dirty_pages_log_range(&subsection, mem->dirty_bmap);
> -
> -        slot_offset += slot_size;
> +        kvm_slot_sync_dirty_pages(mem);
>          start_addr += slot_size;
>          size -= slot_size;
>      }
> @@ -1023,7 +1013,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
>      int err;
>      MemoryRegion *mr = section->mr;
>      bool writeable = !mr->readonly && !mr->rom_device;
> -    hwaddr start_addr, size, slot_size;
> +    hwaddr start_addr, size, slot_size, mr_offset;
> +    ram_addr_t ram_start_offset;
>      void *ram;
>  
>      if (!memory_region_is_ram(mr)) {
> @@ -1041,9 +1032,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
>          return;
>      }
>  
> -    /* use aligned delta to align the ram address */
> -    ram = memory_region_get_ram_ptr(mr) + section->offset_within_region +
> -          (start_addr - section->offset_within_address_space);
> +    /* The offset of the kvmslot within the memory region */
> +    mr_offset = section->offset_within_region + start_addr -
> +        section->offset_within_address_space;
> +
> +    /* use aligned delta to align the ram address and offset */
> +    ram = memory_region_get_ram_ptr(mr) + mr_offset;
> +    ram_start_offset = memory_region_get_ram_addr(mr) + mr_offset;
>  
>      kvm_slots_lock(kml);
>  
> @@ -1082,6 +1077,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
>          mem->as_id = kml->as_id;
>          mem->memory_size = slot_size;
>          mem->start_addr = start_addr;
> +        mem->ram_start_offset = ram_start_offset;
>          mem->ram = ram;
>          mem->flags = kvm_mem_flags(mr);
>          kvm_slot_init_dirty_bitmap(mem);
> @@ -1092,6 +1088,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
>              abort();
>          }
>          start_addr += slot_size;
> +        ram_start_offset += slot_size;
>          ram += slot_size;
>          size -= slot_size;
>      } while (size);
> diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h
> index 4434e15ec7..1a19bfef80 100644
> --- a/include/sysemu/kvm_int.h
> +++ b/include/sysemu/kvm_int.h
> @@ -25,6 +25,8 @@ typedef struct KVMSlot
>      unsigned long *dirty_bmap;
>      /* Cache of the address space ID */
>      int as_id;
> +    /* Cache of the offset in ram address space */
> +    ram_addr_t ram_start_offset;
>  } KVMSlot;
>  
>  typedef struct KVMMemoryListener {
> -- 
> 2.24.1
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2020-03-25 18:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 14:17 [PATCH RFC 0/9] KVM: Dirty ring support (QEMU part) Peter Xu
2020-02-05 14:17 ` [PATCH RFC 1/9] KVM: Fixup kvm_log_clear_one_slot() ioctl return check Peter Xu
2020-03-25 16:34   ` Dr. David Alan Gilbert
2020-03-25 17:43   ` Peter Xu
2020-02-05 14:17 ` [PATCH RFC 2/9] linux-headers: Update Peter Xu
2020-02-05 14:17 ` [PATCH RFC 3/9] memory: Introduce log_sync_global() to memory listener Peter Xu
2020-03-25 16:52   ` Dr. David Alan Gilbert
2020-03-25 17:02     ` Peter Xu
2020-02-05 14:17 ` [PATCH RFC 4/9] KVM: Create the KVMSlot dirty bitmap on flag changes Peter Xu
2020-03-25 17:44   ` Dr. David Alan Gilbert
2020-02-05 14:17 ` [PATCH RFC 5/9] KVM: Provide helper to get kvm dirty log Peter Xu
2020-03-25 17:52   ` Dr. David Alan Gilbert
2020-03-25 18:15     ` Peter Xu
2020-02-05 14:17 ` [PATCH RFC 6/9] KVM: Provide helper to sync dirty bitmap from slot to ramblock Peter Xu
2020-03-25 18:47   ` Dr. David Alan Gilbert [this message]
2020-02-05 14:17 ` [PATCH RFC 7/9] KVM: Cache kvm slot dirty bitmap size Peter Xu
2020-03-25 18:49   ` Dr. David Alan Gilbert
2020-02-05 14:17 ` [PATCH RFC 8/9] KVM: Add dirty-ring-size property Peter Xu
2020-03-25 20:00   ` Dr. David Alan Gilbert
2020-03-25 20:42     ` Peter Xu
2020-03-26 13:41       ` Dr. David Alan Gilbert
2020-03-26 16:03         ` Peter Xu
2020-03-25 20:14   ` Dr. David Alan Gilbert
2020-03-25 20:48     ` Peter Xu
2020-02-05 14:17 ` [PATCH RFC 9/9] KVM: Dirty ring support Peter Xu
2020-03-25 20:41   ` Dr. David Alan Gilbert
2020-03-25 21:32     ` Peter Xu
2020-03-26 14:14       ` Dr. David Alan Gilbert
2020-03-26 16:10         ` Peter Xu
2020-02-05 14:51 ` [PATCH RFC 0/9] KVM: Dirty ring support (QEMU part) no-reply
2020-03-03 17:32 ` Peter Xu

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=20200325184707.GE2635@work-vm \
    --to=dgilbert@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@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).