qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Wei Yang <richardw.yang@linux.intel.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: [PATCH v1 5/5] virito-mem: Implement get_min_alignment()
Date: Wed, 23 Sep 2020 13:39:00 +0200	[thread overview]
Message-ID: <20200923113900.72718-6-david@redhat.com> (raw)
In-Reply-To: <20200923113900.72718-1-david@redhat.com>

This allows auto-assignment of a properly aligned address in guest
physical address space. For example, when specifying a 2GB block size
for a virtio-mem device with 10GB with a memory setup "-m 4G, 20G",
we'll no longer fail when realizing.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Wei Yang <richardw.yang@linux.intel.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/virtio/virtio-mem-pci.c | 14 ++++++++++++++
 hw/virtio/virtio-mem.c     |  8 ++++++++
 2 files changed, 22 insertions(+)

diff --git a/hw/virtio/virtio-mem-pci.c b/hw/virtio/virtio-mem-pci.c
index 590cec041b..2bfa2474fb 100644
--- a/hw/virtio/virtio-mem-pci.c
+++ b/hw/virtio/virtio-mem-pci.c
@@ -75,6 +75,19 @@ static void virtio_mem_pci_fill_device_info(const MemoryDeviceState *md,
     info->type = MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM;
 }
 
+static uint64_t virtio_mem_pci_get_min_alignment(const MemoryDeviceState *md)
+{
+    /*
+     * If no block size was configured, returns the default block size.
+     * Before the device was realized, this might be smaller than the
+     * final block size (because it ignores the page size of the memory region).
+     * However, the alignment of the memory region properly considers the
+     * page size of the memory region.
+     */
+    return object_property_get_uint(OBJECT(md), VIRTIO_MEM_BLOCK_SIZE_PROP,
+                                    &error_abort);
+}
+
 static void virtio_mem_pci_size_change_notify(Notifier *notifier, void *data)
 {
     VirtIOMEMPCI *pci_mem = container_of(notifier, VirtIOMEMPCI,
@@ -109,6 +122,7 @@ static void virtio_mem_pci_class_init(ObjectClass *klass, void *data)
     mdc->get_plugged_size = virtio_mem_pci_get_plugged_size;
     mdc->get_memory_region = virtio_mem_pci_get_memory_region;
     mdc->fill_device_info = virtio_mem_pci_fill_device_info;
+    mdc->get_min_alignment = virtio_mem_pci_get_min_alignment;
 }
 
 static void virtio_mem_pci_instance_init(Object *obj)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 716eddd792..d8222153cf 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -805,6 +805,14 @@ static void virtio_mem_get_block_size(Object *obj, Visitor *v, const char *name,
     const VirtIOMEM *vmem = VIRTIO_MEM(obj);
     uint64_t value = vmem->block_size;
 
+    /*
+     * If not configured by the user (and we're not realized yet), use the
+     * default block size.
+     */
+    if (!value) {
+        value = virtio_mem_default_block_size();
+    }
+
     visit_type_size(v, name, &value, errp);
 }
 
-- 
2.26.2



  parent reply	other threads:[~2020-09-23 11:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 11:38 [PATCH v1 0/5] virtio-mem: block size and address-assignment optimizations David Hildenbrand
2020-09-23 11:38 ` [PATCH v1 1/5] virtio-mem: Probe THP size to determine default block size David Hildenbrand
2020-09-25 13:46   ` Pankaj Gupta
2020-09-28  8:58     ` David Hildenbrand
2020-09-28  9:31       ` Pankaj Gupta
2020-09-28  9:36         ` David Hildenbrand
2020-09-23 11:38 ` [PATCH v1 2/5] virtio-mem: Check that "memaddr" is multiples of the " David Hildenbrand
2020-09-25 13:57   ` Pankaj Gupta
2020-09-23 11:38 ` [PATCH v1 3/5] memory-device: Support big alignment requirements David Hildenbrand
2020-09-25 14:18   ` Pankaj Gupta
2020-09-23 11:38 ` [PATCH v1 4/5] memory-device: Add get_min_alignment() callback David Hildenbrand
2020-09-26 21:07   ` Pankaj Gupta
2020-09-23 11:39 ` David Hildenbrand [this message]
2020-09-26 21:23   ` [PATCH v1 5/5] virito-mem: Implement get_min_alignment() Pankaj Gupta
2020-09-25 10:16 ` [PATCH v1 0/5] virtio-mem: block size and address-assignment optimizations 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=20200923113900.72718-6-david@redhat.com \
    --to=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pankaj.gupta.linux@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richardw.yang@linux.intel.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 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).