QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/3] exclude hyperv synic sections from vhost
@ 2020-01-13 17:36 Dr. David Alan Gilbert (git)
  2020-01-13 17:36 ` [PATCH v2 1/3] vhost: Add names to section rounded warning Dr. David Alan Gilbert (git)
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-01-13 17:36 UTC (permalink / raw)
  To: qemu-devel, vkuznets, mst, jasowang, pbonzini

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Hyperv's synic (that we emulate) is a feature that allows the guest
to place some magic (4k) pages of RAM anywhere it likes in GPA.
This confuses vhost's RAM section merging when these pages
land over the top of hugepages.

Since they're not normal RAM, and they shouldn't have vhost DMAing
into them, exclude them from the vhost set.

This v2 is a complete rework after the v1 review; I've now got
a flag on MemoryRegion's that we set.

bz: https://bugzilla.redhat.com/show_bug.cgi?id=1779041


Dr. David Alan Gilbert (3):
  vhost: Add names to section rounded warning
  memory: Allow a MemoryRegion to be marked no_vhost
  hyperv/synic: Mark regions as no vhost

 hw/hyperv/hyperv.c    |  8 ++++++++
 hw/virtio/vhost.c     | 10 ++++++----
 include/exec/memory.h | 21 +++++++++++++++++++++
 memory.c              | 15 +++++++++++++++
 4 files changed, 50 insertions(+), 4 deletions(-)

-- 
2.24.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/3] vhost: Add names to section rounded warning
  2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
@ 2020-01-13 17:36 ` Dr. David Alan Gilbert (git)
  2020-01-13 17:36 ` [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost Dr. David Alan Gilbert (git)
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-01-13 17:36 UTC (permalink / raw)
  To: qemu-devel, vkuznets, mst, jasowang, pbonzini

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Add the memory region names to section rounding/alignment
warnings.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/virtio/vhost.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 4da0d5a6c5..774d87d98e 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -590,9 +590,10 @@ static void vhost_region_add_section(struct vhost_dev *dev,
              * match up in the same RAMBlock if they do.
              */
             if (mrs_gpa < prev_gpa_start) {
-                error_report("%s:Section rounded to %"PRIx64
-                             " prior to previous %"PRIx64,
-                             __func__, mrs_gpa, prev_gpa_start);
+                error_report("%s:Section '%s' rounded to %"PRIx64
+                             " prior to previous '%s' %"PRIx64,
+                             __func__, section->mr->name, mrs_gpa,
+                             prev_sec->mr->name, prev_gpa_start);
                 /* A way to cleanly fail here would be better */
                 return;
             }
-- 
2.24.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost
  2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
  2020-01-13 17:36 ` [PATCH v2 1/3] vhost: Add names to section rounded warning Dr. David Alan Gilbert (git)
@ 2020-01-13 17:36 ` Dr. David Alan Gilbert (git)
  2020-01-14  7:19   ` Michael S. Tsirkin
  2020-01-13 17:36 ` [PATCH v2 3/3] hyperv/synic: Mark regions as no vhost Dr. David Alan Gilbert (git)
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-01-13 17:36 UTC (permalink / raw)
  To: qemu-devel, vkuznets, mst, jasowang, pbonzini

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Allow a memory region to be marked as 'no_vhost' and
exclude that region from vhost's list build.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/virtio/vhost.c     |  3 ++-
 include/exec/memory.h | 21 +++++++++++++++++++++
 memory.c              | 15 +++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 774d87d98e..462498bfe6 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -402,7 +402,8 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
     bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
                      ~(1 << DIRTY_MEMORY_MIGRATION);
     result = memory_region_is_ram(section->mr) &&
-        !memory_region_is_rom(section->mr);
+             !memory_region_is_rom(section->mr) &&
+             !memory_region_get_no_vhost(section->mr);
 
     /* Vhost doesn't handle any block which is doing dirty-tracking other
      * than migration; this typically fires on VGA areas.
diff --git a/include/exec/memory.h b/include/exec/memory.h
index aef8123d48..f475c06d63 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -394,6 +394,7 @@ struct MemoryRegion {
     bool ram_device;
     bool enabled;
     bool warning_printed; /* For reservations */
+    bool no_vhost;
     uint8_t vga_logging_count;
     MemoryRegion *alias;
     hwaddr alias_offset;
@@ -1625,6 +1626,26 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
  */
 void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile);
 
+/**
+ * memory_region_set_no_vhost: Make vhost ignore a memory region
+ *
+ * Makes vhost ignore a memory region, useful if it isn't real
+ * DMAble memory and is at inconvenient addresses
+ *
+ * @mr: the region being updated.
+ * @no_vhost: true to ignore
+ */
+void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost);
+
+/**
+ * memory_region_set_no_vhost: Test if memory region is marked no vhost
+ *
+ * Test if the no_vhost flag is set on the memory region
+ *
+ * @mr: the region being tested.
+ */
+bool memory_region_get_no_vhost(const MemoryRegion *mr);
+
 /**
  * memory_region_rom_device_set_romd: enable/disable ROMD mode
  *
diff --git a/memory.c b/memory.c
index d7b9bb6951..9371998e30 100644
--- a/memory.c
+++ b/memory.c
@@ -2136,6 +2136,21 @@ void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile)
     }
 }
 
+void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost)
+{
+    if (mr->no_vhost != no_vhost) {
+        memory_region_transaction_begin();
+        mr->no_vhost = no_vhost;
+        memory_region_update_pending |= mr->enabled;
+        memory_region_transaction_commit();
+    }
+}
+
+bool memory_region_get_no_vhost(const MemoryRegion *mr)
+{
+    return mr->no_vhost;
+}
+
 void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode)
 {
     if (mr->romd_mode != romd_mode) {
-- 
2.24.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 3/3] hyperv/synic: Mark regions as no vhost
  2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
  2020-01-13 17:36 ` [PATCH v2 1/3] vhost: Add names to section rounded warning Dr. David Alan Gilbert (git)
  2020-01-13 17:36 ` [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost Dr. David Alan Gilbert (git)
@ 2020-01-13 17:36 ` Dr. David Alan Gilbert (git)
  2020-01-13 18:13 ` [PATCH v2 0/3] exclude hyperv synic sections from vhost Paolo Bonzini
  2020-01-15 12:12 ` Roman Kagan
  4 siblings, 0 replies; 13+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-01-13 17:36 UTC (permalink / raw)
  To: qemu-devel, vkuznets, mst, jasowang, pbonzini

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Mark synic regions as novhost; they are splitting huge page memory
and breaking vhost region joining.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/hyperv/hyperv.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
index da8ce82725..5dbbb14fdd 100644
--- a/hw/hyperv/hyperv.c
+++ b/hw/hyperv/hyperv.c
@@ -99,6 +99,14 @@ static void synic_realize(DeviceState *dev, Error **errp)
                            sizeof(*synic->msg_page), &error_abort);
     memory_region_init_ram(&synic->event_page_mr, obj, eventp_name,
                            sizeof(*synic->event_page), &error_abort);
+    /*
+     * The guest can put the synic pages anywhere, including
+     * fragmenting something the host might want to keep as a huge
+     * page.
+     */
+    memory_region_set_no_vhost(&synic->msg_page_mr, true);
+    memory_region_set_no_vhost(&synic->event_page_mr, true);
+
     synic->msg_page = memory_region_get_ram_ptr(&synic->msg_page_mr);
     synic->event_page = memory_region_get_ram_ptr(&synic->event_page_mr);
 
-- 
2.24.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/3] exclude hyperv synic sections from vhost
  2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
                   ` (2 preceding siblings ...)
  2020-01-13 17:36 ` [PATCH v2 3/3] hyperv/synic: Mark regions as no vhost Dr. David Alan Gilbert (git)
@ 2020-01-13 18:13 ` Paolo Bonzini
  2020-01-13 18:58   ` Dr. David Alan Gilbert
  2020-01-17 12:35   ` Dr. David Alan Gilbert
  2020-01-15 12:12 ` Roman Kagan
  4 siblings, 2 replies; 13+ messages in thread
From: Paolo Bonzini @ 2020-01-13 18:13 UTC (permalink / raw)
  To: Dr. David Alan Gilbert (git), qemu-devel, vkuznets, mst, jasowang

On 13/01/20 18:36, Dr. David Alan Gilbert (git) wrote:
> 
> Hyperv's synic (that we emulate) is a feature that allows the guest
> to place some magic (4k) pages of RAM anywhere it likes in GPA.
> This confuses vhost's RAM section merging when these pages
> land over the top of hugepages.

Can you explain what is the confusion like?  The memory API should just
tell vhost to treat it as three sections (RAM before synIC, synIC
region, RAM after synIC) and it's not clear to me why postcopy breaks
either.

Paolo

> Since they're not normal RAM, and they shouldn't have vhost DMAing
> into them, exclude them from the vhost set.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/3] exclude hyperv synic sections from vhost
  2020-01-13 18:13 ` [PATCH v2 0/3] exclude hyperv synic sections from vhost Paolo Bonzini
@ 2020-01-13 18:58   ` Dr. David Alan Gilbert
  2020-01-14  7:17     ` Michael S. Tsirkin
  2020-01-17 12:35   ` Dr. David Alan Gilbert
  1 sibling, 1 reply; 13+ messages in thread
From: Dr. David Alan Gilbert @ 2020-01-13 18:58 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: jasowang, vkuznets, qemu-devel, mst

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 13/01/20 18:36, Dr. David Alan Gilbert (git) wrote:
> > 
> > Hyperv's synic (that we emulate) is a feature that allows the guest
> > to place some magic (4k) pages of RAM anywhere it likes in GPA.
> > This confuses vhost's RAM section merging when these pages
> > land over the top of hugepages.
> 
> Can you explain what is the confusion like?  The memory API should just
> tell vhost to treat it as three sections (RAM before synIC, synIC
> region, RAM after synIC) and it's not clear to me why postcopy breaks
> either.

There's two separate problems:
  a) For vhost-user there's a limited size for the 'mem table' message
     containing the number of regions to send; that's small - so an
     attempt is made to coalesce regions that all refer to the same
     underlying RAMblock.  If things split the region up you use more
     slots. (it's why the coalescing code was originally there.)

  b) With postcopy + vhost-user life gets more complex because of
     userfault.  We require that the vhost-user client can mmap the
     memory areas on host page granularity (i.e. hugepage granularity
     if it's hugepage backed).  To do that we tweak the aggregation code
     to align the blocks to page size boundaries and then perform
     aggregation - as long as nothing else important gets in the way
     we're OK.
     In this case the guest is programming synic to land at the 512k
     boundary (in 16 separate 4k pages next to each other).  So we end
     up with 0-512k (stretched to 0..2MB alignment) - then we see
     synic (512k-+4k ...) then we see RAM at 640k - and when we try
     to align that we error because we realise the synic mapping is in
     the way and we can't merge the 640k ram chunk with the base 0-512k
     aligned chunk.

Note the reported failure here is kernel vhost, not vhost-user;
so actually it probably doesn't need the alignment, and vhost-user would
probably filter out the synic mappings anyway due to the fact they've
not got an fd ( vhost_user_mem_section_filter ).  But the alignment
code always runs.

Dave



> Paolo
> 
> > Since they're not normal RAM, and they shouldn't have vhost DMAing
> > into them, exclude them from the vhost set.
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/3] exclude hyperv synic sections from vhost
  2020-01-13 18:58   ` Dr. David Alan Gilbert
@ 2020-01-14  7:17     ` Michael S. Tsirkin
  0 siblings, 0 replies; 13+ messages in thread
From: Michael S. Tsirkin @ 2020-01-14  7:17 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: jasowang, Paolo Bonzini, vkuznets, qemu-devel

On Mon, Jan 13, 2020 at 06:58:30PM +0000, Dr. David Alan Gilbert wrote:
> * Paolo Bonzini (pbonzini@redhat.com) wrote:
> > On 13/01/20 18:36, Dr. David Alan Gilbert (git) wrote:
> > > 
> > > Hyperv's synic (that we emulate) is a feature that allows the guest
> > > to place some magic (4k) pages of RAM anywhere it likes in GPA.
> > > This confuses vhost's RAM section merging when these pages
> > > land over the top of hugepages.
> > 
> > Can you explain what is the confusion like?  The memory API should just
> > tell vhost to treat it as three sections (RAM before synIC, synIC
> > region, RAM after synIC) and it's not clear to me why postcopy breaks
> > either.
> 
> There's two separate problems:
>   a) For vhost-user there's a limited size for the 'mem table' message
>      containing the number of regions to send; that's small - so an
>      attempt is made to coalesce regions that all refer to the same
>      underlying RAMblock.  If things split the region up you use more
>      slots. (it's why the coalescing code was originally there.)
> 
>   b) With postcopy + vhost-user life gets more complex because of
>      userfault.  We require that the vhost-user client can mmap the
>      memory areas on host page granularity (i.e. hugepage granularity
>      if it's hugepage backed).  To do that we tweak the aggregation code
>      to align the blocks to page size boundaries and then perform
>      aggregation - as long as nothing else important gets in the way
>      we're OK.
>      In this case the guest is programming synic to land at the 512k
>      boundary (in 16 separate 4k pages next to each other).  So we end
>      up with 0-512k (stretched to 0..2MB alignment) - then we see
>      synic (512k-+4k ...) then we see RAM at 640k - and when we try
>      to align that we error because we realise the synic mapping is in
>      the way and we can't merge the 640k ram chunk with the base 0-512k
>      aligned chunk.
> 
> Note the reported failure here is kernel vhost, not vhost-user;
> so actually it probably doesn't need the alignment,

Yea vhost in the kernel just does copy from/to user. No alignment
requirements.

> and vhost-user would
> probably filter out the synic mappings anyway due to the fact they've
> not got an fd ( vhost_user_mem_section_filter ).  But the alignment
> code always runs.
> 
> Dave
> 
> 
> 
> > Paolo
> > 
> > > Since they're not normal RAM, and they shouldn't have vhost DMAing
> > > into them, exclude them from the vhost set.
> > 
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost
  2020-01-13 17:36 ` [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost Dr. David Alan Gilbert (git)
@ 2020-01-14  7:19   ` Michael S. Tsirkin
  2020-01-14 11:26     ` Dr. David Alan Gilbert
  2020-01-14 15:02     ` Alex Williamson
  0 siblings, 2 replies; 13+ messages in thread
From: Michael S. Tsirkin @ 2020-01-14  7:19 UTC (permalink / raw)
  To: Dr. David Alan Gilbert (git); +Cc: jasowang, pbonzini, vkuznets, qemu-devel

On Mon, Jan 13, 2020 at 05:36:46PM +0000, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Allow a memory region to be marked as 'no_vhost' and
> exclude that region from vhost's list build.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

I thought we agreed vfio needs this as well?
I'd rather this had some meaning not just "no vhost" ...
no_dma?

> ---
>  hw/virtio/vhost.c     |  3 ++-
>  include/exec/memory.h | 21 +++++++++++++++++++++
>  memory.c              | 15 +++++++++++++++
>  3 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 774d87d98e..462498bfe6 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -402,7 +402,8 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
>      bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
>                       ~(1 << DIRTY_MEMORY_MIGRATION);
>      result = memory_region_is_ram(section->mr) &&
> -        !memory_region_is_rom(section->mr);
> +             !memory_region_is_rom(section->mr) &&
> +             !memory_region_get_no_vhost(section->mr);
>  
>      /* Vhost doesn't handle any block which is doing dirty-tracking other
>       * than migration; this typically fires on VGA areas.
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index aef8123d48..f475c06d63 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -394,6 +394,7 @@ struct MemoryRegion {
>      bool ram_device;
>      bool enabled;
>      bool warning_printed; /* For reservations */
> +    bool no_vhost;
>      uint8_t vga_logging_count;
>      MemoryRegion *alias;
>      hwaddr alias_offset;
> @@ -1625,6 +1626,26 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
>   */
>  void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile);
>  
> +/**
> + * memory_region_set_no_vhost: Make vhost ignore a memory region
> + *
> + * Makes vhost ignore a memory region, useful if it isn't real
> + * DMAble memory and is at inconvenient addresses
> + *
> + * @mr: the region being updated.
> + * @no_vhost: true to ignore
> + */
> +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost);
> +
> +/**
> + * memory_region_set_no_vhost: Test if memory region is marked no vhost
> + *
> + * Test if the no_vhost flag is set on the memory region
> + *
> + * @mr: the region being tested.
> + */
> +bool memory_region_get_no_vhost(const MemoryRegion *mr);
> +
>  /**
>   * memory_region_rom_device_set_romd: enable/disable ROMD mode
>   *
> diff --git a/memory.c b/memory.c
> index d7b9bb6951..9371998e30 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2136,6 +2136,21 @@ void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile)
>      }
>  }
>  
> +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost)
> +{
> +    if (mr->no_vhost != no_vhost) {
> +        memory_region_transaction_begin();
> +        mr->no_vhost = no_vhost;
> +        memory_region_update_pending |= mr->enabled;
> +        memory_region_transaction_commit();
> +    }
> +}
> +
> +bool memory_region_get_no_vhost(const MemoryRegion *mr)
> +{
> +    return mr->no_vhost;
> +}
> +
>  void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode)
>  {
>      if (mr->romd_mode != romd_mode) {
> -- 
> 2.24.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost
  2020-01-14  7:19   ` Michael S. Tsirkin
@ 2020-01-14 11:26     ` Dr. David Alan Gilbert
  2020-01-14 14:52       ` Michael S. Tsirkin
  2020-01-14 15:02     ` Alex Williamson
  1 sibling, 1 reply; 13+ messages in thread
From: Dr. David Alan Gilbert @ 2020-01-14 11:26 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: jasowang, pbonzini, vkuznets, qemu-devel

* Michael S. Tsirkin (mst@redhat.com) wrote:
> On Mon, Jan 13, 2020 at 05:36:46PM +0000, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Allow a memory region to be marked as 'no_vhost' and
> > exclude that region from vhost's list build.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 
> I thought we agreed vfio needs this as well?
> I'd rather this had some meaning not just "no vhost" ...
> no_dma?

VFIO tends to be unplugged on migration anyway (at the moment);
but I'm happy to change the name if everyone is happy with the rest of
the series and we can agree on the new name,

Dave

> > ---
> >  hw/virtio/vhost.c     |  3 ++-
> >  include/exec/memory.h | 21 +++++++++++++++++++++
> >  memory.c              | 15 +++++++++++++++
> >  3 files changed, 38 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index 774d87d98e..462498bfe6 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -402,7 +402,8 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
> >      bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
> >                       ~(1 << DIRTY_MEMORY_MIGRATION);
> >      result = memory_region_is_ram(section->mr) &&
> > -        !memory_region_is_rom(section->mr);
> > +             !memory_region_is_rom(section->mr) &&
> > +             !memory_region_get_no_vhost(section->mr);
> >  
> >      /* Vhost doesn't handle any block which is doing dirty-tracking other
> >       * than migration; this typically fires on VGA areas.
> > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > index aef8123d48..f475c06d63 100644
> > --- a/include/exec/memory.h
> > +++ b/include/exec/memory.h
> > @@ -394,6 +394,7 @@ struct MemoryRegion {
> >      bool ram_device;
> >      bool enabled;
> >      bool warning_printed; /* For reservations */
> > +    bool no_vhost;
> >      uint8_t vga_logging_count;
> >      MemoryRegion *alias;
> >      hwaddr alias_offset;
> > @@ -1625,6 +1626,26 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
> >   */
> >  void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile);
> >  
> > +/**
> > + * memory_region_set_no_vhost: Make vhost ignore a memory region
> > + *
> > + * Makes vhost ignore a memory region, useful if it isn't real
> > + * DMAble memory and is at inconvenient addresses
> > + *
> > + * @mr: the region being updated.
> > + * @no_vhost: true to ignore
> > + */
> > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost);
> > +
> > +/**
> > + * memory_region_set_no_vhost: Test if memory region is marked no vhost
> > + *
> > + * Test if the no_vhost flag is set on the memory region
> > + *
> > + * @mr: the region being tested.
> > + */
> > +bool memory_region_get_no_vhost(const MemoryRegion *mr);
> > +
> >  /**
> >   * memory_region_rom_device_set_romd: enable/disable ROMD mode
> >   *
> > diff --git a/memory.c b/memory.c
> > index d7b9bb6951..9371998e30 100644
> > --- a/memory.c
> > +++ b/memory.c
> > @@ -2136,6 +2136,21 @@ void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile)
> >      }
> >  }
> >  
> > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost)
> > +{
> > +    if (mr->no_vhost != no_vhost) {
> > +        memory_region_transaction_begin();
> > +        mr->no_vhost = no_vhost;
> > +        memory_region_update_pending |= mr->enabled;
> > +        memory_region_transaction_commit();
> > +    }
> > +}
> > +
> > +bool memory_region_get_no_vhost(const MemoryRegion *mr)
> > +{
> > +    return mr->no_vhost;
> > +}
> > +
> >  void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode)
> >  {
> >      if (mr->romd_mode != romd_mode) {
> > -- 
> > 2.24.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost
  2020-01-14 11:26     ` Dr. David Alan Gilbert
@ 2020-01-14 14:52       ` Michael S. Tsirkin
  0 siblings, 0 replies; 13+ messages in thread
From: Michael S. Tsirkin @ 2020-01-14 14:52 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: jasowang, pbonzini, vkuznets, qemu-devel

On Tue, Jan 14, 2020 at 11:26:08AM +0000, Dr. David Alan Gilbert wrote:
> * Michael S. Tsirkin (mst@redhat.com) wrote:
> > On Mon, Jan 13, 2020 at 05:36:46PM +0000, Dr. David Alan Gilbert (git) wrote:
> > > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > > 
> > > Allow a memory region to be marked as 'no_vhost' and
> > > exclude that region from vhost's list build.
> > > 
> > > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > 
> > I thought we agreed vfio needs this as well?
> > I'd rather this had some meaning not just "no vhost" ...
> > no_dma?
> 
> VFIO tends to be unplugged on migration anyway (at the moment);

But it still should ignore synic, right?

> but I'm happy to change the name if everyone is happy with the rest of
> the series and we can agree on the new name,
> 
> Dave
> 
> > > ---
> > >  hw/virtio/vhost.c     |  3 ++-
> > >  include/exec/memory.h | 21 +++++++++++++++++++++
> > >  memory.c              | 15 +++++++++++++++
> > >  3 files changed, 38 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > > index 774d87d98e..462498bfe6 100644
> > > --- a/hw/virtio/vhost.c
> > > +++ b/hw/virtio/vhost.c
> > > @@ -402,7 +402,8 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
> > >      bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
> > >                       ~(1 << DIRTY_MEMORY_MIGRATION);
> > >      result = memory_region_is_ram(section->mr) &&
> > > -        !memory_region_is_rom(section->mr);
> > > +             !memory_region_is_rom(section->mr) &&
> > > +             !memory_region_get_no_vhost(section->mr);
> > >  
> > >      /* Vhost doesn't handle any block which is doing dirty-tracking other
> > >       * than migration; this typically fires on VGA areas.
> > > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > > index aef8123d48..f475c06d63 100644
> > > --- a/include/exec/memory.h
> > > +++ b/include/exec/memory.h
> > > @@ -394,6 +394,7 @@ struct MemoryRegion {
> > >      bool ram_device;
> > >      bool enabled;
> > >      bool warning_printed; /* For reservations */
> > > +    bool no_vhost;
> > >      uint8_t vga_logging_count;
> > >      MemoryRegion *alias;
> > >      hwaddr alias_offset;
> > > @@ -1625,6 +1626,26 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
> > >   */
> > >  void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile);
> > >  
> > > +/**
> > > + * memory_region_set_no_vhost: Make vhost ignore a memory region
> > > + *
> > > + * Makes vhost ignore a memory region, useful if it isn't real
> > > + * DMAble memory and is at inconvenient addresses
> > > + *
> > > + * @mr: the region being updated.
> > > + * @no_vhost: true to ignore
> > > + */
> > > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost);
> > > +
> > > +/**
> > > + * memory_region_set_no_vhost: Test if memory region is marked no vhost
> > > + *
> > > + * Test if the no_vhost flag is set on the memory region
> > > + *
> > > + * @mr: the region being tested.
> > > + */
> > > +bool memory_region_get_no_vhost(const MemoryRegion *mr);
> > > +
> > >  /**
> > >   * memory_region_rom_device_set_romd: enable/disable ROMD mode
> > >   *
> > > diff --git a/memory.c b/memory.c
> > > index d7b9bb6951..9371998e30 100644
> > > --- a/memory.c
> > > +++ b/memory.c
> > > @@ -2136,6 +2136,21 @@ void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile)
> > >      }
> > >  }
> > >  
> > > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost)
> > > +{
> > > +    if (mr->no_vhost != no_vhost) {
> > > +        memory_region_transaction_begin();
> > > +        mr->no_vhost = no_vhost;
> > > +        memory_region_update_pending |= mr->enabled;
> > > +        memory_region_transaction_commit();
> > > +    }
> > > +}
> > > +
> > > +bool memory_region_get_no_vhost(const MemoryRegion *mr)
> > > +{
> > > +    return mr->no_vhost;
> > > +}
> > > +
> > >  void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode)
> > >  {
> > >      if (mr->romd_mode != romd_mode) {
> > > -- 
> > > 2.24.1
> > 
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost
  2020-01-14  7:19   ` Michael S. Tsirkin
  2020-01-14 11:26     ` Dr. David Alan Gilbert
@ 2020-01-14 15:02     ` Alex Williamson
  1 sibling, 0 replies; 13+ messages in thread
From: Alex Williamson @ 2020-01-14 15:02 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: qemu-devel, pbonzini, jasowang, Dr. David Alan Gilbert \(git\), vkuznets

On Tue, 14 Jan 2020 02:19:39 -0500
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Mon, Jan 13, 2020 at 05:36:46PM +0000, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Allow a memory region to be marked as 'no_vhost' and
> > exclude that region from vhost's list build.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>  
> 
> I thought we agreed vfio needs this as well?
> I'd rather this had some meaning not just "no vhost" ...
> no_dma?

Sorry, why does vfio need this?  Are we intending to disallow
peer-to-peer DMA?  A vfio device MMIO range could certainly be a DMA
target, but we need to stick to basic CPU operations to access it (ie.
no multimedia extensions like used in memcpy), that's what brought
about the ram device memory region type.  Thanks,

Alex

> > ---
> >  hw/virtio/vhost.c     |  3 ++-
> >  include/exec/memory.h | 21 +++++++++++++++++++++
> >  memory.c              | 15 +++++++++++++++
> >  3 files changed, 38 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index 774d87d98e..462498bfe6 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -402,7 +402,8 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section)
> >      bool log_dirty = memory_region_get_dirty_log_mask(section->mr) &
> >                       ~(1 << DIRTY_MEMORY_MIGRATION);
> >      result = memory_region_is_ram(section->mr) &&
> > -        !memory_region_is_rom(section->mr);
> > +             !memory_region_is_rom(section->mr) &&
> > +             !memory_region_get_no_vhost(section->mr);
> >  
> >      /* Vhost doesn't handle any block which is doing dirty-tracking other
> >       * than migration; this typically fires on VGA areas.
> > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > index aef8123d48..f475c06d63 100644
> > --- a/include/exec/memory.h
> > +++ b/include/exec/memory.h
> > @@ -394,6 +394,7 @@ struct MemoryRegion {
> >      bool ram_device;
> >      bool enabled;
> >      bool warning_printed; /* For reservations */
> > +    bool no_vhost;
> >      uint8_t vga_logging_count;
> >      MemoryRegion *alias;
> >      hwaddr alias_offset;
> > @@ -1625,6 +1626,26 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
> >   */
> >  void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile);
> >  
> > +/**
> > + * memory_region_set_no_vhost: Make vhost ignore a memory region
> > + *
> > + * Makes vhost ignore a memory region, useful if it isn't real
> > + * DMAble memory and is at inconvenient addresses
> > + *
> > + * @mr: the region being updated.
> > + * @no_vhost: true to ignore
> > + */
> > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost);
> > +
> > +/**
> > + * memory_region_set_no_vhost: Test if memory region is marked no vhost
> > + *
> > + * Test if the no_vhost flag is set on the memory region
> > + *
> > + * @mr: the region being tested.
> > + */
> > +bool memory_region_get_no_vhost(const MemoryRegion *mr);
> > +
> >  /**
> >   * memory_region_rom_device_set_romd: enable/disable ROMD mode
> >   *
> > diff --git a/memory.c b/memory.c
> > index d7b9bb6951..9371998e30 100644
> > --- a/memory.c
> > +++ b/memory.c
> > @@ -2136,6 +2136,21 @@ void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile)
> >      }
> >  }
> >  
> > +void memory_region_set_no_vhost(MemoryRegion *mr, bool no_vhost)
> > +{
> > +    if (mr->no_vhost != no_vhost) {
> > +        memory_region_transaction_begin();
> > +        mr->no_vhost = no_vhost;
> > +        memory_region_update_pending |= mr->enabled;
> > +        memory_region_transaction_commit();
> > +    }
> > +}
> > +
> > +bool memory_region_get_no_vhost(const MemoryRegion *mr)
> > +{
> > +    return mr->no_vhost;
> > +}
> > +
> >  void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode)
> >  {
> >      if (mr->romd_mode != romd_mode) {
> > -- 
> > 2.24.1  
> 
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/3] exclude hyperv synic sections from vhost
  2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
                   ` (3 preceding siblings ...)
  2020-01-13 18:13 ` [PATCH v2 0/3] exclude hyperv synic sections from vhost Paolo Bonzini
@ 2020-01-15 12:12 ` Roman Kagan
  4 siblings, 0 replies; 13+ messages in thread
From: Roman Kagan @ 2020-01-15 12:12 UTC (permalink / raw)
  To: Dr. David Alan Gilbert (git)
  Cc: jasowang, pbonzini, vkuznets, qemu-devel, mst

On Mon, Jan 13, 2020 at 05:36:44PM +0000, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Hyperv's synic (that we emulate) is a feature that allows the guest
> to place some magic (4k) pages of RAM anywhere it likes in GPA.
> This confuses vhost's RAM section merging when these pages
> land over the top of hugepages.
> 
> Since they're not normal RAM, and they shouldn't have vhost DMAing
> into them, exclude them from the vhost set.

I still don't think this is correct assessment.  These pages are normal
RAM, perfectly eligible for DMA and what not.

It was a thinko to implement them this way, taking the Hyper-V spec too
literally.  Among the downsides is the excessive consumption of KVM
memslots, and unnecessary large page splits or conflicts with
unsplittable ones.  I'm working on an alternative approach that doesn't
suffer from these issues; struggling to preserve compatibility ATM.

Thanks,
Roman.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/3] exclude hyperv synic sections from vhost
  2020-01-13 18:13 ` [PATCH v2 0/3] exclude hyperv synic sections from vhost Paolo Bonzini
  2020-01-13 18:58   ` Dr. David Alan Gilbert
@ 2020-01-17 12:35   ` Dr. David Alan Gilbert
  1 sibling, 0 replies; 13+ messages in thread
From: Dr. David Alan Gilbert @ 2020-01-17 12:35 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: jasowang, vkuznets, qemu-devel, mst

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 13/01/20 18:36, Dr. David Alan Gilbert (git) wrote:
> > 
> > Hyperv's synic (that we emulate) is a feature that allows the guest
> > to place some magic (4k) pages of RAM anywhere it likes in GPA.
> > This confuses vhost's RAM section merging when these pages
> > land over the top of hugepages.
> 
> Can you explain what is the confusion like?  The memory API should just
> tell vhost to treat it as three sections (RAM before synIC, synIC
> region, RAM after synIC) and it's not clear to me why postcopy breaks
> either.

See my v3 I posted yesterday; I've made this a lot simpler by just
turning the alignment off for vhost-kernel and only enabling it for
vhost-user;  vhost-user skips any section without a backing fd anyway,
so the synic problem goes away, as does another problem reported by
Peter Lieven that he was seeing that seemed like one of the VGA regions
getting in the way (which I'd not seen before).

Dave

> Paolo
> 
> > Since they're not normal RAM, and they shouldn't have vhost DMAing
> > into them, exclude them from the vhost set.
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 17:36 [PATCH v2 0/3] exclude hyperv synic sections from vhost Dr. David Alan Gilbert (git)
2020-01-13 17:36 ` [PATCH v2 1/3] vhost: Add names to section rounded warning Dr. David Alan Gilbert (git)
2020-01-13 17:36 ` [PATCH v2 2/3] memory: Allow a MemoryRegion to be marked no_vhost Dr. David Alan Gilbert (git)
2020-01-14  7:19   ` Michael S. Tsirkin
2020-01-14 11:26     ` Dr. David Alan Gilbert
2020-01-14 14:52       ` Michael S. Tsirkin
2020-01-14 15:02     ` Alex Williamson
2020-01-13 17:36 ` [PATCH v2 3/3] hyperv/synic: Mark regions as no vhost Dr. David Alan Gilbert (git)
2020-01-13 18:13 ` [PATCH v2 0/3] exclude hyperv synic sections from vhost Paolo Bonzini
2020-01-13 18:58   ` Dr. David Alan Gilbert
2020-01-14  7:17     ` Michael S. Tsirkin
2020-01-17 12:35   ` Dr. David Alan Gilbert
2020-01-15 12:12 ` Roman Kagan

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git