Linux CXL
 help / color / mirror / Atom feed
From: Junjie Cao <junjie.cao@intel.com>
To: qemu-devel@nongnu.org
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-cxl@vger.kernel.org, junjie.cao@intel.com
Subject: [PATCH 4/6] hw/cxl: free in-flight sanitize state on reset
Date: Fri, 26 Jun 2026 14:21:47 +0800	[thread overview]
Message-ID: <20260626062149.1844334-5-junjie.cao@intel.com> (raw)
In-Reply-To: <20260626062149.1844334-1-junjie.cao@intel.com>

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

Free it unconditionally at the end of the reset hold phase.  The timer
that advances the operation lives in the CCI that was just destroyed and
re-initialized, so the operation can never complete after a reset of any
type; preserving the heap state across reset has no benefit and would
leak it the next time media_op_sanitize is assigned.

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.

Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
 hw/mem/cxl_type3.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index b842e71c66..a5e6df3033 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -1361,6 +1361,16 @@ 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 */
+
+    /*
+     * Free any in-flight sanitize state unconditionally.  The background
+     * timer that would advance it lives in the CCI just torn down and
+     * re-initialized above, so the operation can never complete after this
+     * point regardless of the reset type; keeping the heap state would only
+     * leak it on the next allocation.
+     */
+    g_free(ct3d->media_op_sanitize);
+    ct3d->media_op_sanitize = NULL;
 }
 
 static const Property ct3_props[] = {
-- 
2.43.0


  parent reply	other threads:[~2026-06-26  6:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  6:21 [PATCH 0/6] hw/cxl: fix Type-3 device reset resource leaks and convert to three-phase Junjie Cao
2026-06-26  6:21 ` [PATCH 1/6] hw/cxl: fix timer leak in cxl_destroy_cci() Junjie Cao
2026-07-21  1:03   ` Jonathan Cameron
2026-06-26  6:21 ` [PATCH 2/6] hw/cxl: destroy primary CCI before re-initialization on reset Junjie Cao
2026-06-26  6:21 ` [PATCH 3/6] hw/cxl: convert cxl-type3 to three-phase reset Junjie Cao
2026-06-26  6:21 ` Junjie Cao [this message]
2026-06-26  6:21 ` [PATCH 5/6] hw/cxl: clear event logs, scan media and interrupt policy on reset Junjie Cao
2026-06-26  6:21 ` [PATCH 6/6] hw/cxl: clear poison lists and feature transfer state " Junjie Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260626062149.1844334-5-junjie.cao@intel.com \
    --to=junjie.cao@intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox