Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5275018CBE1 for ; Thu, 23 Jul 2026 01:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784769441; cv=none; b=GDOYgE3c2z2fTzd+DmR6L6bPZ2yrmGwWkYVcFb977Bj9D9GnF4wkf9B+GdsMzC14aFso8HsByYxL6tdhaeWIIYgflgg+gk35lbC/hb1ADWiU+kBmL9R7ZpZYFIn7VX8CgQke2M8x59d3EGAdmsxlf3xC8B5iZNhfZKv5XZWSHq8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784769441; c=relaxed/simple; bh=hBO3fzaslaoxTxxwV/97htR4gR1dlBLu3SsAm+it1ik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOrfkhesvkLDFOoN4f0b/ov9CTCh0gNggUB4PNOgCZ3ml038fbcQVewDHbwjKt/bnYFOJ7/3NQRSVc5Z7K4M5esVBB0LW4DsQc5YzOt3ObyS2ib3pJUN8nuXJVkOi7KltI5qEQQD8s+iX+AebHN9zcF/c/R92OPQq/vvjwQJBjQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UV87/Zs+; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UV87/Zs+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1784769439; x=1816305439; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hBO3fzaslaoxTxxwV/97htR4gR1dlBLu3SsAm+it1ik=; b=UV87/Zs+N65Qxj0br3FEgF0kDMhfN/6SeTZTEc1OFjVjP2Kfv+fIO5cy /L39xY1Ilxi9gxQFVw+tC5C6WlsFpNYHFVzsVOl/LtkgAzBBXvGaknUpM /eRuvMIJ9syAmkySwj7F6V8RtjX5aFbRGvJjkvZT5CKFPAMgG7/viNUQZ BpQ7XbklhSDyN+sQc0qMN7OCRQdxaQ8BBiTPIGBq4MYVxlMvVH6eeHCAX YBAhoPjybwe/aGaxJcm2jyugrLljL6FR6P1tkn0yFn1G5tPCIYdpDVU2M gDOcwPP3R3pgQMoeOpDV50oqUiZDBiBUFDu9H46UmGggJZEk3cmHneT+H Q==; X-CSE-ConnectionGUID: jUCAk2C4RcSVABAeXyk/Mg== X-CSE-MsgGUID: 0q6cIsIUSZKLSP8RT0ysNg== X-IronPort-AV: E=McAfee;i="6800,10657,11854"; a="96074837" X-IronPort-AV: E=Sophos;i="6.25,179,1779174000"; d="scan'208";a="96074837" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2026 18:17:19 -0700 X-CSE-ConnectionGUID: v6T75PnGRjaJSURpZP4Kfw== X-CSE-MsgGUID: nZ3kjDMaT3WZdOpqn0jw8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,179,1779174000"; d="scan'208";a="251943349" Received: from junjie-desk-dev.bj.intel.com (HELO junjie-desk-dev.tail2c02c1.ts.net) ([10.238.152.71]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2026 18:17:18 -0700 From: Junjie Cao To: Jonathan Cameron Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, qemu-stable@nongnu.org Subject: [PATCH v2 2/6] hw/cxl: destroy primary CCI before re-initialization on reset Date: Thu, 23 Jul 2026 09:16:21 +0800 Message-ID: <20260723011625.1117034-3-junjie.cao@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260723011625.1117034-1-junjie.cao@intel.com> References: <20260723011625.1117034-1-junjie.cao@intel.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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") Cc: qemu-stable@nongnu.org Signed-off-by: Junjie Cao --- hw/mem/cxl_type3.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index cba05ec57d..4ac6eaa950 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1073,7 +1073,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); @@ -1328,6 +1336,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); /* -- 2.43.0