[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 04/61] hw/cxl: Check for multiple mappings of memory backends.
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 04/61] hw/cxl: Check for multiple mappings of memory backends. |
Date: |
Tue, 23 Jul 2024 06:55:28 -0400 |
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Similar protection to that provided for -numa memdev=x
to make sure that memory used to back a type3 device is not also mapped
as normal RAM, or for multiple type3 devices.
This is an easy footgun to remove and seems multiple people have
run into it.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20240705113956.941732-4-Jonathan.Cameron@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/mem/cxl_type3.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index 35ac59883a..e7fbbb4d51 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -737,6 +737,11 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error
**errp)
error_setg(errp, "volatile memdev must have backing device");
return false;
}
+ if (host_memory_backend_is_mapped(ct3d->hostvmem)) {
+ error_setg(errp, "memory backend %s can't be used multiple times.",
+ object_get_canonical_path_component(OBJECT(ct3d->hostvmem)));
+ return false;
+ }
memory_region_set_nonvolatile(vmr, false);
memory_region_set_enabled(vmr, true);
host_memory_backend_set_mapped(ct3d->hostvmem, true);
@@ -760,6 +765,11 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error
**errp)
error_setg(errp, "persistent memdev must have backing device");
return false;
}
+ if (host_memory_backend_is_mapped(ct3d->hostpmem)) {
+ error_setg(errp, "memory backend %s can't be used multiple times.",
+ object_get_canonical_path_component(OBJECT(ct3d->hostpmem)));
+ return false;
+ }
memory_region_set_nonvolatile(pmr, true);
memory_region_set_enabled(pmr, true);
host_memory_backend_set_mapped(ct3d->hostpmem, true);
@@ -790,6 +800,11 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error
**errp)
return false;
}
+ if (host_memory_backend_is_mapped(ct3d->dc.host_dc)) {
+ error_setg(errp, "memory backend %s can't be used multiple times.",
+ object_get_canonical_path_component(OBJECT(ct3d->dc.host_dc)));
+ return false;
+ }
/*
* Set DC regions as volatile for now, non-volatile support can
* be added in the future if needed.
--
MST
- [PULL v2 00/61] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/23
- [PULL v2 01/61] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session, Michael S. Tsirkin, 2024/07/23
- [PULL v2 02/61] MAINTAINERS: add Stefano Garzarella as vhost/vhost-user reviewer, Michael S. Tsirkin, 2024/07/23
- [PULL v2 03/61] hw/cxl/cxl-mailbox-utils: remove unneeded mailbox output payload space zeroing, Michael S. Tsirkin, 2024/07/23
- [PULL v2 05/61] hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property, Michael S. Tsirkin, 2024/07/23
- [PULL v2 06/61] hw/cxl: Add get scan media capabilities cmd support, Michael S. Tsirkin, 2024/07/23
- [PULL v2 07/61] hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled(), Michael S. Tsirkin, 2024/07/23
- [PULL v2 04/61] hw/cxl: Check for multiple mappings of memory backends.,
Michael S. Tsirkin <=
- [PULL v2 08/61] hw/cxl/events: discard all event records during sanitation, Michael S. Tsirkin, 2024/07/23
- [PULL v2 09/61] hw/cxl: Add get scan media results cmd support, Michael S. Tsirkin, 2024/07/23
- [PULL v2 10/61] cxl/mailbox: move mailbox effect definitions to a header, Michael S. Tsirkin, 2024/07/23
- [PULL v2 11/61] hw/cxl/cxl-mailbox-utils: Add support for feature commands (8.2.9.6), Michael S. Tsirkin, 2024/07/23
- [PULL v2 12/61] hw/cxl/cxl-mailbox-utils: Add device patrol scrub control feature, Michael S. Tsirkin, 2024/07/23
- [PULL v2 13/61] hw/cxl/cxl-mailbox-utils: Add device DDR5 ECS control feature, Michael S. Tsirkin, 2024/07/23
- [PULL v2 14/61] hw/cxl: Support firmware updates, Michael S. Tsirkin, 2024/07/23
- [PULL v2 15/61] MAINTAINERS: Add myself as a VT-d reviewer, Michael S. Tsirkin, 2024/07/23
- [PULL v2 16/61] virtio-snd: add max size bounds check in input cb, Michael S. Tsirkin, 2024/07/23
- [PULL v2 17/61] virtio-snd: check for invalid param shift operands, Michael S. Tsirkin, 2024/07/23