Skip to contentSkip to conversation

hw/cxl: Round up of fixes.

PATCH In review Jonathan Cameron 2 participants 10 messages Oct 14, 2024 – Nov 6, 2024

lore
Share & tools
lore
#0 lore raw

cover hw/cxl: Round up of fixes.

A mixed bag of fixes that have all been on the list already with the exception of:
"hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded" (so that's the one that needs more eyes).

I've tweaked the others to fix typos and correct Fixes tags (adding them where missing and fixing formatting), but they are fundamentally the same that has been reviewed on list.

Ajay Joshi (1):
hw/cxl: Fix background completion percentage calculation

Dmitry Frolov (1):
hw/cxl: Fix uint32 overflow cxl-mailbox-utils.c

Fan Ni (1):
hw/mem/cxl_type3: Fix More flag setting for dynamic capacity event
records

Jonathan Cameron (2):
hw/cxl: Fix indent of structure member
hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded

Shiju Jose (1):
hw/cxl/cxl-mailbox-utils: Fix for device DDR5 ECS control feature
tables

Yao Xingtao (1):
mem/cxl_type3: Fix overlapping region validation error

 include/hw/cxl/cxl_device.h         | 36 ++++++++++++++++++-----------
 hw/cxl/cxl-mailbox-utils.c          | 31 +++++++++++--------------
 hw/mem/cxl_type3.c                  | 15 +++++-------
 hw/pci-bridge/pci_expander_bridge.c | 13 +++++++----
 4 files changed, 49 insertions(+), 46 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/7 hw/cxl: Fix uint32 overflow cxl-mailbox-utils.c

From: Dmitry Frolov <[email protected]>

The sum offset + length may overflow uint32. Since this sum is compared with uint64_t return value of get_lsa_size(), it makes sense to choose uint64_t type for offset and length.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 3ebe676a3463 ("hw/cxl/device: Implement get/set Label Storage Area (LSA)")
---
 hw/cxl/cxl-mailbox-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cxl/cxl-mailbox-utils.c +1 -1
index 9258e48f95..9f794e4655 100644
@@ -1445,7 +1445,7 @@ static CXLRetCode cmd_ccls_get_lsa(const struct cxl_cmd *cmd,
     } QEMU_PACKED *get_lsa;
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
-    uint32_t offset, length;
+    uint64_t offset, length;
 
     get_lsa = (void *)payload_in;
     offset = get_lsa->offset;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/7 hw/cxl: Fix background completion percentage calculation

In reply to Jonathan Cameron

From: Ajay Joshi <[email protected]>

The current completion percentage calculation does not account for the relative time since the start of the background activity, this leads to showing incorrect start percentage vs what has actually been completed.

This patch calculates the percentage based on the actual elapsed time since the start of the operation.

Fixes 221d2cfbdb53 ("hw/cxl/mbox: Add support for background operations")
---
 hw/cxl/cxl-mailbox-utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/cxl/cxl-mailbox-utils.c +2 -1
index 9f794e4655..3a93966e77 100644
@@ -2879,7 +2879,8 @@ static void bg_timercb(void *opaque)
         }
     } else {
         /* estimate only */
-        cci->bg.complete_pct = 100 * now / total_time;
+        cci->bg.complete_pct =
+            100 * (now - cci->bg.starttime) / cci->bg.runtime;
         timer_mod(cci->bg.timer, now + CXL_MBOX_BG_UPDATE_FREQ);
     }
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/7 mem/cxl_type3: Fix overlapping region validation error

In reply to Jonathan Cameron

From: Yao Xingtao <[email protected]>

When injecting a new poisoned region through qmp_cxl_inject_poison(), the newly injected region should not overlap with existing poisoned regions.

The current validation method does not consider the following overlapping region:

┌───┬───────┬───┐
│a  │  b(a) │a  │
└───┴───────┴───┘

(a is a newly added region, b is an existing region, and b is a
subregion of a)

Fixes 9547754f40ee ("hw/cxl: QMP based poison injection support")
---
 hw/mem/cxl_type3.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mem/cxl_type3.c +1 -3
index 44d491d8f6..16c60b9b0d 100644
@@ -1381,9 +1381,7 @@ void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t length,
     ct3d = CXL_TYPE3(obj);
 
     QLIST_FOREACH(p, &ct3d->poison_list, node) {
-        if (((start >= p->start) && (start < p->start + p->length)) ||
-            ((start + length > p->start) &&
-             (start + length <= p->start + p->length))) {
+        if ((start < p->start + p->length) && (start + length > p->start)) {
             error_setg(errp,
                        "Overlap with existing poisoned region not supported");
             return;
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/7 hw/mem/cxl_type3: Fix More flag setting for dynamic capacity event records

In reply to Jonathan Cameron

From: Fan Ni <[email protected]>

Per cxl spec r3.1, for multiple dynamic capacity event records grouped via the More flag, the last record in the sequence should clear the More flag.

Before the change, the More flag of the event record is cleared before the loop of inserting records into the event log, which will leave the flag always set once it is set in the loop.

Fixes d0b9b28a5b9f ("hw/cxl/events: Add qmp interfaces to add/release dynamic capacity extents")
---
 hw/mem/cxl_type3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mem/cxl_type3.c +1 -1
index 16c60b9b0d..6911d13fe6 100644
@@ -2064,11 +2064,11 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
     stw_le_p(&dCap.host_id, hid);
     /* only valid for DC_REGION_CONFIG_UPDATED event */
     dCap.updated_region_id = 0;
-    dCap.flags = 0;
     for (i = 0; i < num_extents; i++) {
         memcpy(&dCap.dynamic_capacity_extent, &extents[i],
                sizeof(CXLDCExtentRaw));
 
+        dCap.flags = 0;
         if (i < num_extents - 1) {
             /* Set "More" flag */
             dCap.flags |= BIT(0);
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/7 hw/cxl/cxl-mailbox-utils: Fix for device DDR5 ECS control feature tables

In reply to Jonathan Cameron

From: Shiju Jose <[email protected]>

CXL spec 3.1 section 8.2.9.9.11.2 describes the DDR5 Error Check Scrub (ECS) control feature.

ECS log capabilities field in following ECS tables, which is common for all memory media FRUs in a CXL device.

Fix struct CXLMemECSReadAttrs and struct CXLMemECSWriteAttrs to make log entry type field common.

Fixes 2d41ce38fb9a ("hw/cxl/cxl-mailbox-utils: Add device DDR5 ECS control feature")
---
 include/hw/cxl/cxl_device.h | 36 ++++++++++++++++++++++--------------
 hw/cxl/cxl-mailbox-utils.c  | 24 +++++++++---------------
 hw/mem/cxl_type3.c          |  9 ++++-----
 3 files changed, 35 insertions(+), 34 deletions(-)
include/hw/cxl/cxl_device.h +22 -14
index e14e56ae4b..561b375dc8 100644
@@ -463,18 +463,6 @@ typedef struct CXLMemPatrolScrubWriteAttrs {
 #define CXL_MEMDEV_PS_ENABLE_DEFAULT    0
 
 /* CXL memory device DDR5 ECS control attributes */
-typedef struct CXLMemECSReadAttrs {
-        uint8_t ecs_log_cap;
-        uint8_t ecs_cap;
-        uint16_t ecs_config;
-        uint8_t ecs_flags;
-} QEMU_PACKED CXLMemECSReadAttrs;
-
-typedef struct CXLMemECSWriteAttrs {
-   uint8_t ecs_log_cap;
-    uint16_t ecs_config;
-} QEMU_PACKED CXLMemECSWriteAttrs;
-
 #define CXL_ECS_GET_FEATURE_VERSION    0x01
 #define CXL_ECS_SET_FEATURE_VERSION    0x01
 #define CXL_ECS_LOG_ENTRY_TYPE_DEFAULT    0x01
@@ -483,6 +471,26 @@ typedef struct CXLMemECSWriteAttrs {
 #define CXL_ECS_MODE_DEFAULT    0
 #define CXL_ECS_NUM_MEDIA_FRUS   3 /* Default */
 
+typedef struct CXLMemECSFRUReadAttrs {
+    uint8_t ecs_cap;
+    uint16_t ecs_config;
+    uint8_t ecs_flags;
+} QEMU_PACKED CXLMemECSFRUReadAttrs;
+
+typedef struct CXLMemECSReadAttrs {
+    uint8_t ecs_log_cap;
+    CXLMemECSFRUReadAttrs fru_attrs[CXL_ECS_NUM_MEDIA_FRUS];
+} QEMU_PACKED CXLMemECSReadAttrs;
+
+typedef struct CXLMemECSFRUWriteAttrs {
+    uint16_t ecs_config;
+} QEMU_PACKED CXLMemECSFRUWriteAttrs;
+
+typedef struct CXLMemECSWriteAttrs {
+    uint8_t ecs_log_cap;
+    CXLMemECSFRUWriteAttrs fru_attrs[CXL_ECS_NUM_MEDIA_FRUS];
+} QEMU_PACKED CXLMemECSWriteAttrs;
+
 #define DCD_MAX_NUM_REGION 8
 
 typedef struct CXLDCExtentRaw {
@@ -575,8 +583,8 @@ struct CXLType3Dev {
     CXLMemPatrolScrubReadAttrs patrol_scrub_attrs;
     CXLMemPatrolScrubWriteAttrs patrol_scrub_wr_attrs;
     /* ECS control attributes */
-    CXLMemECSReadAttrs ecs_attrs[CXL_ECS_NUM_MEDIA_FRUS];
-    CXLMemECSWriteAttrs ecs_wr_attrs[CXL_ECS_NUM_MEDIA_FRUS];
+    CXLMemECSReadAttrs ecs_attrs;
+    CXLMemECSWriteAttrs ecs_wr_attrs;
 
     struct dynamic_capacity {
         HostMemoryBackend *host_dc;
hw/cxl/cxl-mailbox-utils.c +9 -15
index 3a93966e77..67041f45d3 100644
@@ -1133,10 +1133,8 @@ static CXLRetCode cmd_features_get_supported(const struct cxl_cmd *cmd,
                          (struct CXLSupportedFeatureEntry) {
                 .uuid = ecs_uuid,
                 .feat_index = index,
-                .get_feat_size = CXL_ECS_NUM_MEDIA_FRUS *
-                                    sizeof(CXLMemECSReadAttrs),
-                .set_feat_size = CXL_ECS_NUM_MEDIA_FRUS *
-                                    sizeof(CXLMemECSWriteAttrs),
+                .get_feat_size = sizeof(CXLMemECSReadAttrs),
+                .set_feat_size = sizeof(CXLMemECSWriteAttrs),
                 .attr_flags = CXL_FEAT_ENTRY_ATTR_FLAG_CHANGABLE,
                 .get_feat_version = CXL_ECS_GET_FEATURE_VERSION,
                 .set_feat_version = CXL_ECS_SET_FEATURE_VERSION,
@@ -1204,13 +1202,10 @@ static CXLRetCode cmd_features_get_feature(const struct cxl_cmd *cmd,
                (uint8_t *)&ct3d->patrol_scrub_attrs + get_feature->offset,
                bytes_to_copy);
     } else if (qemu_uuid_is_equal(&get_feature->uuid, &ecs_uuid)) {
-        if (get_feature->offset >=  CXL_ECS_NUM_MEDIA_FRUS *
-                                sizeof(CXLMemECSReadAttrs)) {
+        if (get_feature->offset >= sizeof(CXLMemECSReadAttrs)) {
             return CXL_MBOX_INVALID_INPUT;
         }
-        bytes_to_copy = CXL_ECS_NUM_MEDIA_FRUS *
-                        sizeof(CXLMemECSReadAttrs) -
-                            get_feature->offset;
+        bytes_to_copy = sizeof(CXLMemECSReadAttrs) - get_feature->offset;
         bytes_to_copy = MIN(bytes_to_copy, get_feature->count);
         memcpy(payload_out,
                (uint8_t *)&ct3d->ecs_attrs + get_feature->offset,
@@ -1299,18 +1294,17 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
 
         ecs_set_feature = (void *)payload_in;
         ecs_write_attrs = ecs_set_feature->feat_data;
-        memcpy((uint8_t *)ct3d->ecs_wr_attrs + hdr->offset,
+        memcpy((uint8_t *)&ct3d->ecs_wr_attrs + hdr->offset,
                ecs_write_attrs,
                bytes_to_copy);
         set_feat_info->data_size += bytes_to_copy;
 
         if (data_transfer_flag == CXL_SET_FEATURE_FLAG_FULL_DATA_TRANSFER ||
             data_transfer_flag ==  CXL_SET_FEATURE_FLAG_FINISH_DATA_TRANSFER) {
+            ct3d->ecs_attrs.ecs_log_cap = ct3d->ecs_wr_attrs.ecs_log_cap;
             for (count = 0; count < CXL_ECS_NUM_MEDIA_FRUS; count++) {
-                ct3d->ecs_attrs[count].ecs_log_cap =
-                                  ct3d->ecs_wr_attrs[count].ecs_log_cap;
-                ct3d->ecs_attrs[count].ecs_config =
-                                  ct3d->ecs_wr_attrs[count].ecs_config & 0x1F;
+                ct3d->ecs_attrs.fru_attrs[count].ecs_config =
+                        ct3d->ecs_wr_attrs.fru_attrs[count].ecs_config & 0x1F;
             }
         }
     } else {
@@ -1324,7 +1318,7 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
         if (qemu_uuid_is_equal(&hdr->uuid, &patrol_scrub_uuid)) {
             memset(&ct3d->patrol_scrub_wr_attrs, 0, set_feat_info->data_size);
         } else if (qemu_uuid_is_equal(&hdr->uuid, &ecs_uuid)) {
-            memset(ct3d->ecs_wr_attrs, 0, set_feat_info->data_size);
+            memset(&ct3d->ecs_wr_attrs, 0, set_feat_info->data_size);
         }
         set_feat_info->data_transfer_flag = 0;
         set_feat_info->data_saved_across_reset = false;
hw/mem/cxl_type3.c +4 -5
index 6911d13fe6..5cf754b38f 100644
@@ -920,16 +920,15 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
     ct3d->patrol_scrub_attrs.scrub_flags = CXL_MEMDEV_PS_ENABLE_DEFAULT;
 
     /* Set default value for DDR5 ECS read attributes */
+    ct3d->ecs_attrs.ecs_log_cap = CXL_ECS_LOG_ENTRY_TYPE_DEFAULT;
     for (count = 0; count < CXL_ECS_NUM_MEDIA_FRUS; count++) {
-        ct3d->ecs_attrs[count].ecs_log_cap =
-                            CXL_ECS_LOG_ENTRY_TYPE_DEFAULT;
-        ct3d->ecs_attrs[count].ecs_cap =
+        ct3d->ecs_attrs.fru_attrs[count].ecs_cap =
                             CXL_ECS_REALTIME_REPORT_CAP_DEFAULT;
-        ct3d->ecs_attrs[count].ecs_config =
+        ct3d->ecs_attrs.fru_attrs[count].ecs_config =
                             CXL_ECS_THRESHOLD_COUNT_DEFAULT |
                             (CXL_ECS_MODE_DEFAULT << 3);
         /* Reserved */
-        ct3d->ecs_attrs[count].ecs_flags = 0;
+        ct3d->ecs_attrs.fru_attrs[count].ecs_flags = 0;
     }
 
     return;
Signature · 1 line
2.43.0
#6 lore raw

PATCH 6/7 hw/cxl: Fix indent of structure member

In reply to Jonathan Cameron

Add missing 4 spaces of indent to structure element.

---
 hw/cxl/cxl-mailbox-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cxl/cxl-mailbox-utils.c +1 -1
index 67041f45d3..5f63099724 100644
@@ -374,7 +374,7 @@ static CXLRetCode cmd_infostat_identify(const struct cxl_cmd *cmd,
         uint16_t pcie_subsys_vid;
         uint16_t pcie_subsys_id;
         uint64_t sn;
-    uint8_t max_message_size;
+        uint8_t max_message_size;
         uint8_t component_type;
     } QEMU_PACKED *is_identify;
     QEMU_BUILD_BUG_ON(sizeof(*is_identify) != 18);
Signature · 1 line
2.43.0
#7 lore raw

PATCH 7/7 hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded

In reply to Jonathan Cameron

For the CXL PXB there is additional code after pxb_dev_realize_common() is called. If that realize failed (e.g. due to an out of range numa_node) we will get a segfault. Return a bool so the caller can check if the pxb_dev_realize_common() succeeded or not without having to poke around in the errp.

Fixes 4f8db8711cbd ("hw/pxb: Allow creation of a CXL PXB (host bridge)")
---
 hw/pci-bridge/pci_expander_bridge.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
hw/pci-bridge/pci_expander_bridge.c +8 -5
index 4578e03024..07d411cff5 100644
@@ -330,7 +330,7 @@ static gint pxb_compare(gconstpointer a, gconstpointer b)
            0;
 }
 
-static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type,
+static bool pxb_dev_realize_common(PCIDevice *dev, enum BusType type,
                                    Error **errp)
 {
     PXBDev *pxb = PXB_DEV(dev);
@@ -342,13 +342,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type,
 
     if (ms->numa_state == NULL) {
         error_setg(errp, "NUMA is not supported by this machine-type");
-        return;
+        return false;
     }
 
     if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
         pxb->numa_node >= ms->numa_state->num_nodes) {
         error_setg(errp, "Illegal numa node %d", pxb->numa_node);
-        return;
+        return false;
     }
 
     if (dev->qdev.id && *dev->qdev.id) {
@@ -394,12 +394,13 @@ static void pxb_dev_realize_common(PCIDevice *dev, enum BusType type,
     pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);
 
     pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
-    return;
+    return true;
 
 err_register_bus:
     object_unref(OBJECT(bds));
     object_unparent(OBJECT(bus));
     object_unref(OBJECT(ds));
+    return false;
 }
 
 static void pxb_dev_realize(PCIDevice *dev, Error **errp)
@@ -500,7 +501,9 @@ static void pxb_cxl_dev_realize(PCIDevice *dev, Error **errp)
         return;
     }
 
-    pxb_dev_realize_common(dev, CXL, errp);
+    if (!pxb_dev_realize_common(dev, CXL, errp)) {
+        return;
+    }
     pxb_cxl_dev_reset(DEVICE(dev));
 }
 
Signature · 1 line
2.43.0
#8 lore raw
In reply to Jonathan Cameron
Quoted 8 lines · On Mon, 14 Oct 2024 13:18:55 +0100 Jonathan Cameron…

A mixed bag of fixes that have all been on the list already with the exception of:
"hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded" (so that's the one that needs more eyes).

I've tweaked the others to fix typos and correct Fixes tags (adding them where missing and fixing formatting), but they are fundamentally the same that has been reviewed on list.

Oops. This should have been
[PATCH qemu 0/7]...
to match the additions to the patch title for the others.
Note for qemu people, we do this for CXL patches to that it is easier to manage the patchwork instance on linux-cxl as that is only currently used to track kernel patches and hence these should be excluded.

Jonathan

Quoted 28 lines

Ajay Joshi (1):
hw/cxl: Fix background completion percentage calculation

Dmitry Frolov (1):
hw/cxl: Fix uint32 overflow cxl-mailbox-utils.c

Fan Ni (1):
hw/mem/cxl_type3: Fix More flag setting for dynamic capacity event
records

Jonathan Cameron (2):
hw/cxl: Fix indent of structure member
hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded

Shiju Jose (1):
hw/cxl/cxl-mailbox-utils: Fix for device DDR5 ECS control feature
tables

Yao Xingtao (1):
mem/cxl_type3: Fix overlapping region validation error

 include/hw/cxl/cxl_device.h         | 36 ++++++++++++++++++-----------
 hw/cxl/cxl-mailbox-utils.c          | 31 +++++++++++--------------
 hw/mem/cxl_type3.c                  | 15 +++++-------
 hw/pci-bridge/pci_expander_bridge.c | 13 +++++++----
 4 files changed, 49 insertions(+), 46 deletions(-)
#9 lore raw
In reply to Jonathan Cameron
Quoted 23 lines · Jonathan Cameron via

A mixed bag of fixes that have all been on the list already with the exception of:
"hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded" (so that's the one that needs more eyes).

I've tweaked the others to fix typos and correct Fixes tags (adding them where missing and fixing formatting), but they are fundamentally the same that has been reviewed on list.

Ajay Joshi (1):
hw/cxl: Fix background completion percentage calculation

Dmitry Frolov (1):
hw/cxl: Fix uint32 overflow cxl-mailbox-utils.c

Fan Ni (1):
hw/mem/cxl_type3: Fix More flag setting for dynamic capacity event
records

Jonathan Cameron (2):
hw/cxl: Fix indent of structure member
hw/pci-bridge: Make pxb_dev_realize_common() return if it succeeded

Quoted 6 lines

Shiju Jose (1):
hw/cxl/cxl-mailbox-utils: Fix for device DDR5 ECS control feature
tables

Yao Xingtao (1):
mem/cxl_type3: Fix overlapping region validation error

Is anything in there for qemu-stable?

Thanks,

/mjt

Quoted 6 lines
  include/hw/cxl/cxl_device.h         | 36 ++++++++++++++++++-----------
  hw/cxl/cxl-mailbox-utils.c          | 31 +++++++++++--------------
  hw/mem/cxl_type3.c                  | 15 +++++-------
  hw/pci-bridge/pci_expander_bridge.c | 13 +++++++----
  4 files changed, 49 insertions(+), 46 deletions(-)
Signature · 4 lines
GPG Key transition (from rsa2048 to rsa4096) since 2024-04-24.
New key: rsa4096/61AD3D98ECDF2C8E  9D8B E14E 3F2A 9DD7 9199  28F1 61AD 3D98 ECDF 2C8E
Old key: rsa2048/457CE0A0804465C5  6EE1 95D1 886E 8FFB 810D  4324 457C E0A0 8044 65C5
Transition statement: http://www.corpit.ru/mjt/gpg-transition-2024.txt