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. Signed-off-by: Junjie Cao <[email protected]> --- hw/mem/cxl_type3.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index a5e6df3033..5bf0cffb72 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1371,6 +1371,23 @@ static void ct3d_reset_hold(Object *obj, ResetType type) */ g_free(ct3d->media_op_sanitize); ct3d->media_op_sanitize = NULL; + + /* + * 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[] = { -- 2.43.0
