[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 06/38] memory-device: Add get_min_alignment() callback
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 06/38] memory-device: Add get_min_alignment() callback |
Date: |
Tue, 3 Nov 2020 23:50:58 -0500 |
From: David Hildenbrand <david@redhat.com>
Add a callback that can be used to express additional alignment
requirements (exceeding the ones from the memory region).
Will be used by virtio-mem to express special alignment requirements due
to manually configured, big block sizes (e.g., 1GB with an ordinary
memory-backend-ram). This avoids failing later when realizing, because
auto-detection wasn't able to assign a properly aligned address.
Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
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>
Message-Id: <20201008083029.9504-6-david@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/mem/memory-device.h | 10 ++++++++++
hw/mem/memory-device.c | 11 +++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 30d7e99f52..48d2611fc5 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -88,6 +88,16 @@ struct MemoryDeviceClass {
*/
MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
+ /*
+ * Optional: Return the desired minimum alignment of the device in guest
+ * physical address space. The final alignment is computed based on this
+ * alignment and the alignment requirements of the memory region.
+ *
+ * Called when plugging the memory device to detect the required alignment
+ * during address assignment.
+ */
+ uint64_t (*get_min_alignment)(const MemoryDeviceState *md);
+
/*
* Translate the memory device into #MemoryDeviceInfo.
*/
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 8a736f1a26..cf0627fd01 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -259,7 +259,7 @@ void memory_device_pre_plug(MemoryDeviceState *md,
MachineState *ms,
{
const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
Error *local_err = NULL;
- uint64_t addr, align;
+ uint64_t addr, align = 0;
MemoryRegion *mr;
mr = mdc->get_memory_region(md, &local_err);
@@ -267,7 +267,14 @@ void memory_device_pre_plug(MemoryDeviceState *md,
MachineState *ms,
goto out;
}
- align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
+ if (legacy_align) {
+ align = *legacy_align;
+ } else {
+ if (mdc->get_min_alignment) {
+ align = mdc->get_min_alignment(md);
+ }
+ align = MAX(align, memory_region_get_alignment(mr));
+ }
addr = mdc->get_addr(md);
addr = memory_device_get_free_addr(ms, !addr ? NULL : &addr, align,
memory_region_size(mr), &local_err);
--
MST
- [PULL v2 00/38] pc,pci,vhost,virtio: fixes, Michael S. Tsirkin, 2020/11/03
- [PULL v2 01/38] pc: comment style fixup, Michael S. Tsirkin, 2020/11/03
- [PULL v2 02/38] virtio-mem: Make sure "addr" is always multiples of the block size, Michael S. Tsirkin, 2020/11/03
- [PULL v2 03/38] virtio-mem: Make sure "usable_region_size" is always multiples of the block size, Michael S. Tsirkin, 2020/11/03
- [PULL v2 04/38] virtio-mem: Probe THP size to determine default block size, Michael S. Tsirkin, 2020/11/03
- [PULL v2 05/38] memory-device: Support big alignment requirements, Michael S. Tsirkin, 2020/11/03
- [PULL v2 07/38] virito-mem: Implement get_min_alignment(), Michael S. Tsirkin, 2020/11/03
- [PULL v2 06/38] memory-device: Add get_min_alignment() callback,
Michael S. Tsirkin <=
- [PULL v2 08/38] hw/acpi : Don't use '#' flag of printf format, Michael S. Tsirkin, 2020/11/03
- [PULL v2 13/38] virtio-iommu: Fix virtio_iommu_mr(), Michael S. Tsirkin, 2020/11/03
- [PULL v2 15/38] virtio-iommu: Add memory notifiers for map/unmap, Michael S. Tsirkin, 2020/11/03
- [PULL v2 17/38] virtio-iommu: Add replay() memory region callback, Michael S. Tsirkin, 2020/11/03
- [PULL v2 19/38] memory: Add interface to set iommu page size mask, Michael S. Tsirkin, 2020/11/03
- [PULL v2 20/38] vfio: Set IOMMU page size as per host supported page size, Michael S. Tsirkin, 2020/11/03
- [PULL v2 21/38] virtio-iommu: Set supported page size mask, Michael S. Tsirkin, 2020/11/03
- [PULL v2 22/38] vfio: Don't issue full 2^64 unmap, Michael S. Tsirkin, 2020/11/03
- [PULL v2 23/38] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup, Michael S. Tsirkin, 2020/11/03
- [PULL v2 09/38] hw/acpi : add space before the open parenthesis '(', Michael S. Tsirkin, 2020/11/03