Skip to contentSkip to conversation

hw/cxl: fix Type-3 device reset resource leaks and convert to three-phase

PATCH In review Junjie Cao 4 participants 13 messages Jul 29 – Oct 31

lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

v3 cover hw/cxl: fix Type-3 device reset resource leaks and convert to three-phase

The CXL Type-3 device reset path (ct3d_reset) has several issues:

1) Resource leaks:
- cxl_destroy_cci() never frees the QEMUTimer allocated by cxl_init_cci(), leaking a timer on each destroy/reinit cycle.
- The primary CCI (ct3d->cci) is re-initialized through cxl_device_register_init_t3() without being destroyed first, leaking the timer and leaving the mutex undestroyed on every reset.
- The secondary CCIs are never destroyed at device exit time, leaking their timers and mutexes on device removal.

2) Incomplete state cleanup:
- Background commands do not survive Conventional Resets (CXL r4.0 Section 8.2.9.4), yet the in-flight sanitize state is never freed.
- Scan media results are explicitly invalidated after reset (Section

     8.2.10.9.4.6), yet scan_media_hasrun is never cleared.

- Event interrupt settings shall be reset to 00b on Conventional Reset (Section 8.2.10.2.5), yet irq_enabled is never cleared.
- When "Injects Persistent Poison" is 0 (the QEMU default), injected poison shall be automatically cleared on reset (Table 8-309), yet the poison lists are never drained.
- Stale event records remain in the queues across reset even though the Event Status register (Table 8-203) is non-sticky.

3) Deprecated API usage:
- Uses device_class_set_legacy_reset() instead of the three-phase resettable interface, preventing reset-type-aware behavior.

This series fixes the issues incrementally:
- Patches 1-2: fix resource leaks (deterministic bugs)
- Patch 3: mechanical conversion to three-phase reset
- Patch 4: factor the primary CCI teardown into a cxl_destroy_mailbox_t3() helper pairing cxl_initialize_mailbox_t3()
- Patches 5-7: clean up device state on reset

The state cleanup in patches 6-7 is gated on reset type:
RESET_TYPE_WAKEUP returns early (patch 6) since a resume from S3 is not a Conventional or CXL Reset. The CCI re-initialization and the in-flight sanitize discard run unconditionally regardless of type.

Not addressed here:

- Committed Feature attributes and alert thresholds (Table 8-276 Deepest Reset Persistence = None) are not reverted to defaults. Factoring the realize-time defaults into a reset helper is left for a follow-up.

- Dynamic Capacity extent lifecycle across reset.

- The Media Disabled latch after an interrupted Sanitize (Section

    8.2.10.9.5.1); patch 5 addresses only the resource leak.

Tested: per-commit build clean; cxl qtest passes. Differential LeakSanitizer (5x system_reset): pre-series leaks 720 B / 15 allocs in cxl_init_cci -> timer_new_ms; post-series zero (re-verified on v3). Poison inject -> reset -> re-inject same DPAs succeeds (no stale "Overlap" rejection). 20x inject+reset stress cycles with no crash.

Changes since v2:
- New patch 4: factor the primary CCI teardown into cxl_destroy_mailbox_t3(), the teardown counterpart of cxl_initialize_mailbox_t3(), called from both the reset path and ct3_exit(). [Philippe]
- Patch 5 (was patch 4): discard the in-flight sanitize state from cxl_destroy_mailbox_t3() through a helper shared with the __do_sanitize() completion path, so the whole media_op_sanitize lifecycle stays within cxl-mailbox-utils.c. This also plugs the same leak on device unrealize, which v2 missed. [Philippe]
- Picked up Philippe's Reviewed-by on patches 1 and 3.

Changes since v1:
- Patch 1: reorder cxl_destroy_cci() teardown to reverse cxl_init_cci() order, per Jonathan's review.

v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/

Junjie Cao (7):
hw/cxl: fix timer leak in cxl_destroy_cci()
hw/cxl: destroy primary CCI before re-initialization on reset hw/cxl: convert cxl-type3 to three-phase reset
hw/cxl: add cxl_destroy_mailbox_t3() as the mailbox teardown
counterpart
hw/cxl: discard in-flight sanitize state on mailbox teardown hw/cxl: clear event logs, scan media and interrupt policy on reset hw/cxl: clear poison lists and feature transfer state on reset

 hw/cxl/cxl-mailbox-utils.c  | 24 +++++++++++++--
 hw/mem/cxl_type3.c          | 60 +++++++++++++++++++++++++++++++++----
 include/hw/cxl/cxl_device.h |  3 ++
 3 files changed, 80 insertions(+), 7 deletions(-)

base-commit: e1705a25aff35635c360bbaba4c2731d019a422a

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/7 hw/cxl: fix timer leak in cxl_destroy_cci()

cxl_init_cci() allocates a QEMUTimer via timer_new_ms() but cxl_destroy_cci() never frees it. This leaks a timer object on every device exit path and, more critically, on every device reset cycle since the secondary CCIs (vdm_fm_owned_ld_mctp_cci, ld0_cci) are destroyed and re-initialized each time ct3d_reset() runs.

Tear the CCI down in the reverse of cxl_init_cci()'s setup order:
destroy the mutex, then free the timer. timer_free() cancels any pending expiry via timer_del() internally and tolerates a NULL pointer; clear the field afterwards so that a repeated timer_free() on the same CCI is a safe no-op.
(The function as a whole is still not idempotent: qemu_mutex_destroy() asserts on an already-destroyed mutex. Callers must not invoke cxl_destroy_cci() twice; the .initialized guard added in the next patch enforces that.)

Fixes 98cbac128f1c ("hw/cxl: Support aborting background commands")
---
 hw/cxl/cxl-mailbox-utils.c | 2 ++
 1 file changed, 2 insertions(+)
hw/cxl/cxl-mailbox-utils.c +2 -0
index ec18338b42..603677a97b 100644
@@ -4795,6 +4795,8 @@ void cxl_init_cci(CXLCCI *cci, size_t payload_max)
 void cxl_destroy_cci(CXLCCI *cci)
 {
     qemu_mutex_destroy(&cci->bg.lock);
+    timer_free(cci->bg.timer);
+    cci->bg.timer = NULL;
     cci->initialized = false;
 }
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v3 2/7 hw/cxl: destroy primary CCI before re-initialization on reset

In reply to Junjie Cao

ct3d_reset() re-initializes the primary CCI through the call chain cxl_device_register_init_t3() -> cxl_initialize_mailbox_t3() -> cxl_init_cci(), but never calls cxl_destroy_cci() first. Each reset cycle therefore leaks the old timer and leaves the old mutex undestroyed while silently overwriting the CCI state.

Per CXL r4.0, the "Mailbox Interfaces Ready" bit in the Memory Device Status register (Table 8-212) is set after a Conventional Reset or CXL Reset once the device has re-initialized its mailbox interfaces. The CCI is the software abstraction of these interfaces and must be properly torn down before re-initialization.

The secondary CCIs (vdm_fm_owned_ld_mctp_cci, ld0_cci) already follow the correct destroy-before-reinit pattern in the same function; apply the same discipline to the primary CCI.

Also destroy the secondary CCIs in ct3_exit() where they were previously leaked at device removal time. Guard the primary CCI teardown there with the same .initialized check used for the secondary
CCIs: the primary CCI is only brought up from the reset path (cxl_device_register_init_t3()), so a device that is unrealized before its first reset would otherwise tear down a never-initialized CCI.

Fixes cac36a8faffc ("hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState")
---
 hw/mem/cxl_type3.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
hw/mem/cxl_type3.c +12 -1
index 28f41fa623..d730a25645 100644
@@ -1076,7 +1076,15 @@ static void ct3_exit(PCIDevice *pci_dev)
     cxl_doe_cdat_release(cxl_cstate);
     msix_uninit_exclusive_bar(pci_dev);
     g_free(regs->special_ops);
-    cxl_destroy_cci(&ct3d->cci);
+    if (ct3d->cci.initialized) {
+        cxl_destroy_cci(&ct3d->cci);
+    }
+    if (ct3d->vdm_fm_owned_ld_mctp_cci.initialized) {
+        cxl_destroy_cci(&ct3d->vdm_fm_owned_ld_mctp_cci);
+    }
+    if (ct3d->ld0_cci.initialized) {
+        cxl_destroy_cci(&ct3d->ld0_cci);
+    }
     if (ct3d->dc.host_dc) {
         cxl_destroy_dc_regions(ct3d);
         address_space_destroy(&ct3d->dc.host_dc_as);
@@ -1331,6 +1339,9 @@ static void ct3d_reset(DeviceState *dev)
                               ct3d->flitmode);
     cxl_component_register_init_common(reg_state, write_msk,
                                        CXL2_TYPE3_DEVICE, ct3d->hdmdb);
+    if (ct3d->cci.initialized) {
+        cxl_destroy_cci(&ct3d->cci);
+    }
     cxl_device_register_init_t3(ct3d, CXL_T3_MSIX_MBOX);
 
     /*
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v3 3/7 hw/cxl: convert cxl-type3 to three-phase reset

In reply to Junjie Cao

Replace the deprecated device_class_set_legacy_reset() registration with the three-phase resettable interface, following the pattern already established by the CXL root port (cxl_rp_reset_hold).

Only the hold phase is needed; enter and exit are left NULL. The parent hold phase is chained for correctness: TYPE_PCI_DEVICE installs no hold phase today, so parent_phases.hold is currently NULL and the chained call is a no-op, but capturing and invoking it is the correct forward-compatible pattern and mirrors cxl_rp_reset_hold().

No functional change — the reset body is identical; only the registration path and function signature change.

---
 hw/mem/cxl_type3.c          | 16 ++++++++++++----
 include/hw/cxl/cxl_device.h |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)
hw/mem/cxl_type3.c +12 -4
index d730a25645..ce2cb6558c 100644
@@ -1329,13 +1329,18 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     return address_space_write(as, dpa_offset, attrs, &data, size);
 }
 
-static void ct3d_reset(DeviceState *dev)
+static void ct3d_reset_hold(Object *obj, ResetType type)
 {
-    CXLType3Dev *ct3d = CXL_TYPE3(dev);
+    CXLType3Dev *ct3d = CXL_TYPE3(obj);
+    CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(obj);
     uint32_t *reg_state = ct3d->cxl_cstate.crb.cache_mem_registers;
     uint32_t *write_msk = ct3d->cxl_cstate.crb.cache_mem_regs_write_mask;
 
-    pcie_cap_fill_link_ep_usp(PCI_DEVICE(dev), ct3d->width, ct3d->speed,
+    if (cvc->parent_phases.hold) {
+        cvc->parent_phases.hold(obj, type);
+    }
+
+    pcie_cap_fill_link_ep_usp(PCI_DEVICE(obj), ct3d->width, ct3d->speed,
                               ct3d->flitmode);
     cxl_component_register_init_common(reg_state, write_msk,
                                        CXL2_TYPE3_DEVICE, ct3d->hdmdb);
@@ -2467,6 +2472,7 @@ static void ct3_class_init(ObjectClass *oc, const void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc);
     CXLType3Class *cvc = CXL_TYPE3_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
 
     pc->realize = ct3_realize;
     pc->exit = ct3_exit;
@@ -2480,9 +2486,11 @@ static void ct3_class_init(ObjectClass *oc, const void *data)
 
     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
     dc->desc = "CXL Memory Device (Type 3)";
-    device_class_set_legacy_reset(dc, ct3d_reset);
     device_class_set_props(dc, ct3_props);
 
+    resettable_class_set_parent_phases(rc, NULL, ct3d_reset_hold, NULL,
+                                       &cvc->parent_phases);
+
     cvc->get_lsa_size = get_lsa_size;
     cvc->get_lsa = get_lsa;
     cvc->set_lsa = set_lsa;
include/hw/cxl/cxl_device.h +2 -0
index ba551fa5f9..b7e20e3fe4 100644
@@ -805,6 +805,8 @@ struct CXLType3Class {
     /* Private */
     PCIDeviceClass parent_class;
 
+    ResettablePhases parent_phases;
+
     /* public */
     uint64_t (*get_lsa_size)(CXLType3Dev *ct3d);
 
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v3 4/7 hw/cxl: add cxl_destroy_mailbox_t3() as the mailbox teardown counterpart

In reply to Junjie Cao

The primary CCI teardown is open-coded, guarded by .initialized, at the two places that need it: the reset path (before cxl_device_register_init_t3() brings the mailbox back up) and ct3_exit().

Factor it into cxl_destroy_mailbox_t3(), the teardown counterpart of cxl_initialize_mailbox_t3(), keeping the .initialized guard inside the
helper: the primary CCI is only brought up from the reset path, so the first reset after realize and an unrealize before any reset must both skip the teardown.

No functional change.

---
 hw/cxl/cxl-mailbox-utils.c  | 7 +++++++
 hw/mem/cxl_type3.c          | 8 ++------
 include/hw/cxl/cxl_device.h | 1 +
 3 files changed, 10 insertions(+), 6 deletions(-)
hw/cxl/cxl-mailbox-utils.c +7 -0
index 603677a97b..bc00fec9f8 100644
@@ -4843,6 +4843,13 @@ void cxl_initialize_mailbox_t3(CXLCCI *cci, DeviceState *d, size_t payload_max)
     cxl_init_cci(cci, payload_max);
 }
 
+void cxl_destroy_mailbox_t3(CXLType3Dev *ct3d)
+{
+    if (ct3d->cci.initialized) {
+        cxl_destroy_cci(&ct3d->cci);
+    }
+}
+
 static const struct cxl_cmd cxl_cmd_set_t3_ld[256][256] = {
     [INFOSTAT][IS_IDENTIFY] = { "IDENTIFY", cmd_infostat_identify, 0, 0 },
     [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0,
hw/mem/cxl_type3.c +2 -6
index ce2cb6558c..3a5eea76f2 100644
@@ -1076,9 +1076,7 @@ static void ct3_exit(PCIDevice *pci_dev)
     cxl_doe_cdat_release(cxl_cstate);
     msix_uninit_exclusive_bar(pci_dev);
     g_free(regs->special_ops);
-    if (ct3d->cci.initialized) {
-        cxl_destroy_cci(&ct3d->cci);
-    }
+    cxl_destroy_mailbox_t3(ct3d);
     if (ct3d->vdm_fm_owned_ld_mctp_cci.initialized) {
         cxl_destroy_cci(&ct3d->vdm_fm_owned_ld_mctp_cci);
     }
@@ -1344,9 +1342,7 @@ static void ct3d_reset_hold(Object *obj, ResetType type)
                               ct3d->flitmode);
     cxl_component_register_init_common(reg_state, write_msk,
                                        CXL2_TYPE3_DEVICE, ct3d->hdmdb);
-    if (ct3d->cci.initialized) {
-        cxl_destroy_cci(&ct3d->cci);
-    }
+    cxl_destroy_mailbox_t3(ct3d);
     cxl_device_register_init_t3(ct3d, CXL_T3_MSIX_MBOX);
 
     /*
include/hw/cxl/cxl_device.h +1 -0
index b7e20e3fe4..608d05165a 100644
@@ -325,6 +325,7 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE,
                                           CXL_DEVICE_CAP_REG_SIZE * 2)
 
 void cxl_initialize_mailbox_t3(CXLCCI *cci, DeviceState *d, size_t payload_max);
+void cxl_destroy_mailbox_t3(CXLType3Dev *ct3d);
 void cxl_initialize_mailbox_swcci(CXLCCI *cci, DeviceState *intf,
                                   DeviceState *d, size_t payload_max);
 void cxl_init_cci(CXLCCI *cci, size_t payload_max);
Signature · 1 line
2.43.0
Reviewed-by on v3 4/7
#5 lore raw

Re: [PATCH v3 4/7] hw/cxl: add cxl_destroy_mailbox_t3() as the mailbox teardown counterpart

Quoted 13 lines · Junjie Cao

The primary CCI teardown is open-coded, guarded by .initialized, at the two places that need it: the reset path (before cxl_device_register_init_t3() brings the mailbox back up) and ct3_exit().

Factor it into cxl_destroy_mailbox_t3(), the teardown counterpart of cxl_initialize_mailbox_t3(), keeping the .initialized guard inside the
helper: the primary CCI is only brought up from the reset path, so the first reset after realize and an unrealize before any reset must both skip the teardown.

No functional change.

Quoted 7 lines
---
  hw/cxl/cxl-mailbox-utils.c  | 7 +++++++
  hw/mem/cxl_type3.c          | 8 ++------
  include/hw/cxl/cxl_device.h | 1 +
  3 files changed, 10 insertions(+), 6 deletions(-)
author
#6 lore raw

PATCH v3 5/7 hw/cxl: discard in-flight sanitize state on mailbox teardown

In reply to Junjie Cao

Per CXL r4.0 Section 8.2.9.4, "Background commands do not continue to execute across Conventional Resets." If a Media Operations sanitize is in progress when the device is reset, the background timer is cancelled and freed via cxl_destroy_cci(), but the per-operation state (media_op_sanitize) is heap-allocated separately and would be leaked.

Free it from cxl_destroy_mailbox_t3(): the timer that advances the operation lives in the CCI torn down there, so the operation can never complete once the mailbox is gone; preserving the heap state has no benefit and would leak it the next time media_op_sanitize is assigned. Routing the discard through the mailbox teardown also covers device unrealize, where ct3_exit() previously leaked an in-flight sanitize.

The completion path in __do_sanitize() frees the same state; factor the free into a cxl_discard_media_op_sanitize() helper used by both places, so the whole media_op_sanitize lifecycle now stays within cxl-mailbox-utils.c.

Note that Section 8.2.10.9.5.1 additionally requires a device whose Sanitize was interrupted by reset to remain in the Media Disabled state until a successful Sanitize completes. That latch is not modelled here (reset re-enables media via memdev_reg_init_common()) and is left for future work; this patch only addresses the resource leak.

---
 hw/cxl/cxl-mailbox-utils.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
hw/cxl/cxl-mailbox-utils.c +13 -2
index bc00fec9f8..cbd6ebf9fe 100644
@@ -2636,6 +2636,12 @@ static int sanitize_range(CXLType3Dev *ct3d, uint64_t dpa_addr, size_t length,
     return address_space_set(as, dpa_addr, fill_value, length, mem_attrs);
 }
 
+static void cxl_discard_media_op_sanitize(CXLType3Dev *ct3d)
+{
+    g_free(ct3d->media_op_sanitize);
+    ct3d->media_op_sanitize = NULL;
+}
+
 /* Perform the actual device zeroing */
 static void __do_sanitize(CXLType3Dev *ct3d)
 {
@@ -2653,8 +2659,7 @@ static void __do_sanitize(CXLType3Dev *ct3d)
         }
     }
 exit:
-    g_free(ct3d->media_op_sanitize);
-    ct3d->media_op_sanitize = NULL;
+    cxl_discard_media_op_sanitize(ct3d);
     return;
 }
 
@@ -4848,6 +4853,12 @@ void cxl_destroy_mailbox_t3(CXLType3Dev *ct3d)
     if (ct3d->cci.initialized) {
         cxl_destroy_cci(&ct3d->cci);
     }
+    /*
+     * An in-flight Media Operations sanitize is only advanced by this CCI's
+     * background timer; with the CCI gone the operation can never complete,
+     * so its state would otherwise be leaked (CXL r4.0 Section 8.2.9.4).
+     */
+    cxl_discard_media_op_sanitize(ct3d);
 }
 
 static const struct cxl_cmd cxl_cmd_set_t3_ld[256][256] = {
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v3 6/7 hw/cxl: clear event logs, scan media and interrupt policy on reset

In reply to Junjie Cao

Event records, scan media results and event interrupt settings are device-internal dynamic state that should not survive a device reset.

Per CXL r4.0 Section 8.2.10.9.4.6 (Get Scan Media Results), "If the Scan Media command has not been called since the last Conventional Reset, the device shall return the Unsupported return code." This explicitly invalidates scan media results across reset, so clear the scan_media_hasrun flag.

Per CXL r4.0 Section 8.2.10.2.5 (Set Event Interrupt Policy), "All event log interrupt settings shall be reset to 00b (No Interrupts) by the device on Conventional Reset." Clear irq_enabled for every event log accordingly.

For the event records there is no direct spec mandate to drop the stored records on reset; the Event Status register (Table 8-203) is non-sticky and resets to zero per Section 9.7, and no reset flavor requires the already-reported records to persist. Draining the queues is therefore a reasonable modelling choice that keeps the records consistent with the freshly-reset status register, rather than a spec requirement. Call the existing cxl_discard_all_event_records() helper to drain all event queues. The event log infrastructure itself (mutexes, IRQ vectors) remains intact as it is initialized once during device realize.

This is also where reset-type gating begins: a wakeup from suspend-to-RAM (RESET_TYPE_WAKEUP) is not a Conventional or CXL Reset and must retain device-internal state, so the hold phase returns early for that type before discarding any records. This mirrors the RESET_TYPE_WAKEUP shortcut in virtio-mem and virtio-balloon. Only the unconditional mailbox interface re-initialization and the in-flight sanitize free (whose backing timer was already destroyed) run on a wakeup.

---
 hw/mem/cxl_type3.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/mem/cxl_type3.c +17 -0
index 3a5eea76f2..2392358071 100644
@@ -1360,6 +1360,23 @@ static void ct3d_reset_hold(Object *obj, ResetType type)
     }
     cxl_initialize_t3_ld_cci(&ct3d->ld0_cci, DEVICE(ct3d), DEVICE(ct3d),
                              512); /* Max payload made up */
+
+    /*
+     * A wakeup from suspend-to-RAM is not a Conventional or CXL Reset.  The
+     * device-internal dynamic state cleared below (event logs, scan media
+     * results, and the poison/feature-transfer state cleared in subsequent
+     * patches) must be preserved across resume, so stop here for a wakeup.
+     * virtio-mem and virtio-balloon take the same RESET_TYPE_WAKEUP shortcut.
+     */
+    if (type == RESET_TYPE_WAKEUP) {
+        return;
+    }
+
+    cxl_discard_all_event_records(&ct3d->cxl_dstate);
+    for (int i = 0; i < CXL_EVENT_TYPE_MAX; i++) {
+        ct3d->cxl_dstate.event_logs[i].irq_enabled = false;
+    }
+    ct3d->scan_media_hasrun = false;
 }
 
 static const Property ct3_props[] = {
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH v3 7/7 hw/cxl: clear poison lists and feature transfer state on reset

In reply to Junjie Cao

The poison lists (active, backup, and scan-media results), their associated overflow tracking, and the Set Feature partial-transfer state are all device-internal dynamic state that accumulates during the device's lifetime.

Per CXL r4.0 Table 8-309 (Identify Memory Device), the "Injects Persistent Poison" capability bit (offset 41h, Bit[0]) controls poison retention across reset. When cleared — the QEMU default — "a Conventional Reset or CXL Reset shall automatically clear the injected poison." Clear all poison lists accordingly, reusing the existing cxl_clear_poison_list_overflowed() helper for the overflow tracking.

For the Set Feature transfer state, CXL r4.0 Section 8.2.10.6.3 (Set Feature) requires: "If the Feature data transfer is interrupted by a Conventional Reset or a CXL Reset, the Feature data transfer shall be aborted by the device [...] the device shall require the Feature data transfer to be started from the beginning." Zero set_feat_info on reset so any partially transferred Set Feature is abandoned and must restart from the beginning.

Both clears run after the RESET_TYPE_WAKEUP early-return added in the previous patch, so this state is preserved across a suspend-to-RAM wakeup.

---
 hw/mem/cxl_type3.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
hw/mem/cxl_type3.c +18 -0
index 2392358071..0b36485344 100644
@@ -1327,6 +1327,16 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     return address_space_write(as, dpa_offset, attrs, &data, size);
 }
 
+static void ct3d_clear_poison_list(CXLPoisonList *list)
+{
+    CXLPoison *ent, *next;
+
+    QLIST_FOREACH_SAFE(ent, list, node, next) {
+        QLIST_REMOVE(ent, node);
+        g_free(ent);
+    }
+}
+
 static void ct3d_reset_hold(Object *obj, ResetType type)
 {
     CXLType3Dev *ct3d = CXL_TYPE3(obj);
@@ -1377,6 +1387,14 @@ static void ct3d_reset_hold(Object *obj, ResetType type)
         ct3d->cxl_dstate.event_logs[i].irq_enabled = false;
     }
     ct3d->scan_media_hasrun = false;
+
+    ct3d_clear_poison_list(&ct3d->poison_list);
+    ct3d_clear_poison_list(&ct3d->poison_list_bkp);
+    ct3d_clear_poison_list(&ct3d->scan_media_results);
+    ct3d->poison_list_cnt = 0;
+    cxl_clear_poison_list_overflowed(ct3d);
+
+    memset(&ct3d->set_feat_info, 0, sizeof(ct3d->set_feat_info));
 }
 
 static const Property ct3_props[] = {
Signature · 1 line
2.43.0
author
#9 lore raw
In reply to Junjie Cao

Hi Jonathan,

Ping -- still applies clean on master, cxl-test passes. 1/7 and 3/7 have Philippe's R-b.

Adding Michael given your note on Haotian's CDAT fix that a staging tree is a while off.

Many thanks,
Junjie

#10 lore raw
In reply to Junjie Cao
Quoted 13 lines · Junjie Cao

The CXL Type-3 device reset path (ct3d_reset) has several issues:

1) Resource leaks:
2) Incomplete state cleanup:
3) Deprecated API usage:

This series fixes the issues incrementally:
- Patches 1-2: fix resource leaks (deterministic bugs)
- Patch 3: mechanical conversion to three-phase reset
- Patch 4: factor the primary CCI teardown into a cxl_destroy_mailbox_t3() helper pairing cxl_initialize_mailbox_t3()
- Patches 5-7: clean up device state on reset

Quoted 9 lines

Junjie Cao (7):
hw/cxl: fix timer leak in cxl_destroy_cci()
hw/cxl: destroy primary CCI before re-initialization on reset hw/cxl: convert cxl-type3 to three-phase reset
hw/cxl: add cxl_destroy_mailbox_t3() as the mailbox teardown
counterpart
hw/cxl: discard in-flight sanitize state on mailbox teardown hw/cxl: clear event logs, scan media and interrupt policy on reset hw/cxl: clear poison lists and feature transfer state on reset

Hi!

This patch series has been Cc'ed to qemu-stable@. It is interesting how it's been Cc'ed, and I think there's some error here. From whole series, only patch 2 (destroy primary CCI before re-initialization on reset) is tagged for-stable. Patch 1, which is a fix, is not tagged, and not Cc'ed to qemu-stable@ either. The rest - patches 3-7 - has been Cc'ed to the qemu-stable mailing list, but are not tagged for-stable.

From this list, I'm only picking up patch 2, and only for 11.1.x series. The other active stable series, 10.0.x, - apparently it's not needed there.

FWIW.

Thanks,

/mjt

#11 lore raw

Hi Michael,

Quoted 6 lines · Michael Tokarev

This patch series has been Cc'ed to qemu-stable@. It is interesting how it's been Cc'ed, and I think there's some error here. From whole series, only patch 2 (destroy primary CCI before re-initialization on reset) is tagged for-stable. Patch 1, which is a fix, is not tagged, and not Cc'ed to qemu-stable@ either. The rest - patches 3-7 - has been Cc'ed to the qemu-stable mailing list, but are not tagged for-stable.

Thanks for pointing this out. Only patches 1 and 2 were intended for stable; I copied qemu-stable@ on the whole series. I'll keep the stable Cc limited to the relevant patches in future.

Patch 1 carries the tag both on the list and in 259b877eac, and you already have it as 4a39c7d61e in 11.1.2. So for 11.1.x patch 2 is indeed the only one left.

Quoted 2 lines

From this list, I'm only picking up patch 2, and only for 11.1.x series. The other active stable series, 10.0.x, - apparently it's not needed there.

Neither applies to 10.0 as-is since cxl_destroy_cci() only exists from 10.1, but the leak is there too: ct3d_reset() re-runs cxl_init_cci() on all three CCIs, allocating a new timer each time. I've just sent a 10.0 version, "[PATCH stable-10.0] hw/cxl: free the CCI background timer on Type-3 reset and exit".

Thanks,
Junjie

#12 lore raw
Quoted 18 lines · Junjie Cao

Hi Michael,

Quoted 6 lines · Michael Tokarev

This patch series has been Cc'ed to qemu-stable@. It is interesting how it's been Cc'ed, and I think there's some error here. From whole series, only patch 2 (destroy primary CCI before re-initialization on reset) is tagged for-stable. Patch 1, which is a fix, is not tagged, and not Cc'ed to qemu-stable@ either. The rest - patches 3-7 - has been Cc'ed to the qemu-stable mailing list, but are not tagged for-stable.

Thanks for pointing this out. Only patches 1 and 2 were intended for stable; I copied qemu-stable@ on the whole series. I'll keep the stable Cc limited to the relevant patches in future.

Patch 1 carries the tag both on the list and in 259b877eac, and you already have it as 4a39c7d61e in 11.1.2. So for 11.1.x patch 2 is indeed the only one left.

Quoted 8 lines
Quoted 2 lines

From this list, I'm only picking up patch 2, and only for 11.1.x series.
The other active stable series, 10.0.x, - apparently it's not needed there.

Neither applies to 10.0 as-is since cxl_destroy_cci() only exists from 10.1, but the leak is there too: ct3d_reset() re-runs cxl_init_cci() on all three CCIs, allocating a new timer each time. I've just sent a 10.0 version, "[PATCH stable-10.0] hw/cxl: free the CCI background timer on Type-3 reset and exit".

Thank you very much for the explanation and for writing the fix for 10.0.x. I thought the prob actually doesn't exist there ;)

/mjt