All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nitesh Narayan Lal <nitesh@redhat.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, virtio-dev@lists.oasis-open.org,
	pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com,
	wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com,
	david@redhat.com, mst@redhat.com, dodgen@google.com,
	konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com,
	alexander.duyck@gmail.com, john.starks@microsoft.com,
	dave.hansen@intel.com, mhocko@suse.com, cohuck@redhat.com
Subject: [QEMU Patch 2/2] virtio-balloon: support for handling page reporting
Date: Mon, 12 Aug 2019 09:13:57 -0400	[thread overview]
Message-ID: <20190812131357.27312-2-nitesh@redhat.com> (raw)
In-Reply-To: <20190812131357.27312-1-nitesh@redhat.com>

Page reporting is a feature which enables the virtual machine to report
chunk of free pages to the hypervisor.
This patch enables QEMU to process these reports from the VM and discard the
unused memory range.

Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
---
 hw/virtio/virtio-balloon.c         | 41 ++++++++++++++++++++++++++++++
 include/hw/virtio/virtio-balloon.h |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 25de154307..1132e47ee0 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -320,6 +320,39 @@ static void balloon_stats_set_poll_interval(Object *obj, Visitor *v,
     balloon_stats_change_timer(s, 0);
 }
 
+static void virtio_balloon_handle_reporting(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtQueueElement *elem;
+
+    while ((elem = virtqueue_pop(vq, sizeof(VirtQueueElement)))) {
+        unsigned int i;
+
+        for (i = 0; i < elem->in_num; i++) {
+            void *gaddr = elem->in_sg[i].iov_base;
+            size_t size = elem->in_sg[i].iov_len;
+            ram_addr_t ram_offset;
+            size_t rb_page_size;
+	    RAMBlock *rb;
+
+            if (qemu_balloon_is_inhibited())
+                continue;
+
+            rb = qemu_ram_block_from_host(gaddr, false, &ram_offset);
+            rb_page_size = qemu_ram_pagesize(rb);
+
+            /* For now we will simply ignore unaligned memory regions */
+            if ((ram_offset | size) & (rb_page_size - 1))
+                continue;
+
+            ram_block_discard_range(rb, ram_offset, size);
+        }
+
+        virtqueue_push(vq, elem, 0);
+        virtio_notify(vdev, vq);
+        g_free(elem);
+    }
+}
+
 static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
@@ -792,6 +825,12 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
     s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
 
+    if (virtio_has_feature(s->host_features,
+                           VIRTIO_BALLOON_F_REPORTING)) {
+        s->reporting_vq = virtio_add_queue(vdev, 16,
+					   virtio_balloon_handle_reporting);
+    }
+
     if (virtio_has_feature(s->host_features,
                            VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
         s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
@@ -912,6 +951,8 @@ static Property virtio_balloon_properties[] = {
      * is disabled, resulting in QEMU 3.1 migration incompatibility.  This
      * property retains this quirk for QEMU 4.1 machine types.
      */
+    DEFINE_PROP_BIT("free-page-reporting", VirtIOBalloon, host_features,
+                    VIRTIO_BALLOON_F_REPORTING, true),
     DEFINE_PROP_BOOL("qemu-4-0-config-size", VirtIOBalloon,
                      qemu_4_0_config_size, false),
     DEFINE_PROP_LINK("iothread", VirtIOBalloon, iothread, TYPE_IOTHREAD,
diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index d1c968d237..15a05e6435 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -42,7 +42,7 @@ enum virtio_balloon_free_page_report_status {
 
 typedef struct VirtIOBalloon {
     VirtIODevice parent_obj;
-    VirtQueue *ivq, *dvq, *svq, *free_page_vq;
+    VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq;
     uint32_t free_page_report_status;
     uint32_t num_pages;
     uint32_t actual;
-- 
2.21.0


WARNING: multiple messages have this Message-ID (diff)
From: Nitesh Narayan Lal <nitesh@redhat.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, virtio-dev@lists.oasis-open.org,
	pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com,
	wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com,
	david@redhat.com, mst@redhat.com, dodgen@google.com,
	konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com,
	alexander.duyck@gmail.com, john.starks@microsoft.com,
	dave.hansen@intel.com, mhocko@suse.com, cohuck@redhat.com
Subject: [virtio-dev] [QEMU Patch 2/2] virtio-balloon: support for handling page reporting
Date: Mon, 12 Aug 2019 09:13:57 -0400	[thread overview]
Message-ID: <20190812131357.27312-2-nitesh@redhat.com> (raw)
In-Reply-To: <20190812131357.27312-1-nitesh@redhat.com>

Page reporting is a feature which enables the virtual machine to report
chunk of free pages to the hypervisor.
This patch enables QEMU to process these reports from the VM and discard the
unused memory range.

Signed-off-by: Nitesh Narayan Lal <nitesh@redhat.com>
---
 hw/virtio/virtio-balloon.c         | 41 ++++++++++++++++++++++++++++++
 include/hw/virtio/virtio-balloon.h |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 25de154307..1132e47ee0 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -320,6 +320,39 @@ static void balloon_stats_set_poll_interval(Object *obj, Visitor *v,
     balloon_stats_change_timer(s, 0);
 }
 
+static void virtio_balloon_handle_reporting(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtQueueElement *elem;
+
+    while ((elem = virtqueue_pop(vq, sizeof(VirtQueueElement)))) {
+        unsigned int i;
+
+        for (i = 0; i < elem->in_num; i++) {
+            void *gaddr = elem->in_sg[i].iov_base;
+            size_t size = elem->in_sg[i].iov_len;
+            ram_addr_t ram_offset;
+            size_t rb_page_size;
+	    RAMBlock *rb;
+
+            if (qemu_balloon_is_inhibited())
+                continue;
+
+            rb = qemu_ram_block_from_host(gaddr, false, &ram_offset);
+            rb_page_size = qemu_ram_pagesize(rb);
+
+            /* For now we will simply ignore unaligned memory regions */
+            if ((ram_offset | size) & (rb_page_size - 1))
+                continue;
+
+            ram_block_discard_range(rb, ram_offset, size);
+        }
+
+        virtqueue_push(vq, elem, 0);
+        virtio_notify(vdev, vq);
+        g_free(elem);
+    }
+}
+
 static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
@@ -792,6 +825,12 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
     s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
 
+    if (virtio_has_feature(s->host_features,
+                           VIRTIO_BALLOON_F_REPORTING)) {
+        s->reporting_vq = virtio_add_queue(vdev, 16,
+					   virtio_balloon_handle_reporting);
+    }
+
     if (virtio_has_feature(s->host_features,
                            VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
         s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
@@ -912,6 +951,8 @@ static Property virtio_balloon_properties[] = {
      * is disabled, resulting in QEMU 3.1 migration incompatibility.  This
      * property retains this quirk for QEMU 4.1 machine types.
      */
+    DEFINE_PROP_BIT("free-page-reporting", VirtIOBalloon, host_features,
+                    VIRTIO_BALLOON_F_REPORTING, true),
     DEFINE_PROP_BOOL("qemu-4-0-config-size", VirtIOBalloon,
                      qemu_4_0_config_size, false),
     DEFINE_PROP_LINK("iothread", VirtIOBalloon, iothread, TYPE_IOTHREAD,
diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index d1c968d237..15a05e6435 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -42,7 +42,7 @@ enum virtio_balloon_free_page_report_status {
 
 typedef struct VirtIOBalloon {
     VirtIODevice parent_obj;
-    VirtQueue *ivq, *dvq, *svq, *free_page_vq;
+    VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq;
     uint32_t free_page_report_status;
     uint32_t num_pages;
     uint32_t actual;
-- 
2.21.0


---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org


  reply	other threads:[~2019-08-12 13:14 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 13:12 [RFC][PATCH v12 0/2] mm: Support for page reporting Nitesh Narayan Lal
2019-08-12 13:12 ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 13:12 ` [RFC][Patch v12 1/2] mm: page_reporting: core infrastructure Nitesh Narayan Lal
2019-08-12 13:12   ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 18:47   ` Alexander Duyck
2019-08-12 18:47     ` [virtio-dev] " Alexander Duyck
2019-08-12 18:47     ` Alexander Duyck
2019-08-12 20:04     ` Nitesh Narayan Lal
2019-08-12 20:04       ` [virtio-dev] " Nitesh Narayan Lal
2019-08-20 14:11       ` Nitesh Narayan Lal
2019-08-20 14:11         ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 20:05     ` David Hildenbrand
2019-08-12 20:05       ` [virtio-dev] " David Hildenbrand
2019-08-13 10:30       ` Nitesh Narayan Lal
2019-08-13 10:30         ` [virtio-dev] " Nitesh Narayan Lal
2019-08-13 10:34         ` David Hildenbrand
2019-08-13 10:34           ` [virtio-dev] " David Hildenbrand
2019-08-13 10:42           ` Nitesh Narayan Lal
2019-08-13 10:42             ` [virtio-dev] " Nitesh Narayan Lal
2019-08-13 10:44             ` David Hildenbrand
2019-08-13 10:44               ` [virtio-dev] " David Hildenbrand
2019-08-13 23:14           ` Alexander Duyck
2019-08-13 23:14             ` [virtio-dev] " Alexander Duyck
2019-08-13 23:14             ` Alexander Duyck
2019-08-14  7:07             ` David Hildenbrand
2019-08-14  7:07               ` [virtio-dev] " David Hildenbrand
2019-08-14 12:49               ` Nitesh Narayan Lal
2019-08-14 12:49                 ` Nitesh Narayan Lal
2019-08-14 15:49     ` Nitesh Narayan Lal
2019-08-14 15:49       ` [virtio-dev] " Nitesh Narayan Lal
2019-08-14 16:11       ` Alexander Duyck
2019-08-14 16:11         ` [virtio-dev] " Alexander Duyck
2019-08-14 16:11         ` Alexander Duyck
2019-08-15 13:15         ` Nitesh Narayan Lal
2019-08-15 13:15           ` [virtio-dev] " Nitesh Narayan Lal
2019-08-15 19:22           ` Nitesh Narayan Lal
2019-08-15 19:22             ` [virtio-dev] " Nitesh Narayan Lal
2019-08-15 23:00             ` Alexander Duyck
2019-08-15 23:00               ` [virtio-dev] " Alexander Duyck
2019-08-15 23:00               ` Alexander Duyck
2019-08-16 18:35               ` Nitesh Narayan Lal
2019-08-16 18:35                 ` [virtio-dev] " Nitesh Narayan Lal
2019-08-30 15:15     ` Nitesh Narayan Lal
2019-08-30 15:15       ` [virtio-dev] " Nitesh Narayan Lal
2019-08-30 15:31       ` Alexander Duyck
2019-08-30 15:31         ` [virtio-dev] " Alexander Duyck
2019-08-30 15:31         ` Alexander Duyck
2019-08-30 16:05         ` Nitesh Narayan Lal
2019-08-30 16:05           ` [virtio-dev] " Nitesh Narayan Lal
2019-09-04  8:40           ` David Hildenbrand
2019-09-04  8:40             ` David Hildenbrand
2019-10-10 20:36   ` Alexander Duyck
2019-10-10 20:36     ` [virtio-dev] " Alexander Duyck
2019-10-10 20:36     ` Alexander Duyck
2019-10-11 11:02     ` Nitesh Narayan Lal
2019-10-11 11:02       ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 13:12 ` [RFC][Patch v12 2/2] virtio-balloon: interface to support free page reporting Nitesh Narayan Lal
2019-08-12 13:12   ` [virtio-dev] " Nitesh Narayan Lal
2019-08-14 10:29   ` Cornelia Huck
2019-08-14 10:29     ` [virtio-dev] " Cornelia Huck
2019-08-14 11:47     ` Nitesh Narayan Lal
2019-08-14 11:47       ` [virtio-dev] " Nitesh Narayan Lal
2019-08-14 13:42       ` Cornelia Huck
2019-08-14 13:42         ` [virtio-dev] " Cornelia Huck
2019-08-14 14:01         ` Nitesh Narayan Lal
2019-08-14 14:01           ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 13:13 ` [QEMU Patch 1/2] virtio-balloon: adding bit for page reporting support Nitesh Narayan Lal
2019-08-12 13:13   ` [virtio-dev] " Nitesh Narayan Lal
2019-08-12 13:13   ` Nitesh Narayan Lal [this message]
2019-08-12 13:13     ` [virtio-dev] [QEMU Patch 2/2] virtio-balloon: support for handling page reporting Nitesh Narayan Lal
2019-08-12 15:18     ` Alexander Duyck
2019-08-12 15:18       ` [virtio-dev] " Alexander Duyck
2019-08-12 15:18       ` Alexander Duyck
2019-08-12 15:26       ` Nitesh Narayan Lal
2019-08-12 15:26         ` [virtio-dev] " Nitesh Narayan Lal
2019-09-11 12:30 ` [RFC][PATCH v12 0/2] mm: Support for " David Hildenbrand
2019-09-11 12:30   ` [virtio-dev] " David Hildenbrand

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=20190812131357.27312-2-nitesh@redhat.com \
    --to=nitesh@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=alexander.duyck@gmail.com \
    --cc=cohuck@redhat.com \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=dhildenb@redhat.com \
    --cc=dodgen@google.com \
    --cc=john.starks@microsoft.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=lcapitulino@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mst@redhat.com \
    --cc=pagupta@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=riel@surriel.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=wei.w.wang@intel.com \
    --cc=yang.zhang.wz@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.