From nobody Sat Feb 7 08:27:23 2026 Received: from sender4-pp-o90.zoho.com (sender4-pp-o90.zoho.com [136.143.188.90]) (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 EF13F42A96; Sun, 1 Feb 2026 09:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.90 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769938275; cv=pass; b=n+Ge5XBmW7/Aq0eOMdIf/z4aEsYIQVvo+9WbeW5HdolF7IqXSJY773ZM7C6QJw/k1UFashCL3JTwYz0K+UqoEUpD1HatuSodscZBIuq2QJP3D3qJgqCG/VRoboxoorv8haY5UFymKFeAEGQ4PIy8gP/ZrkL1SZStOhSXYQBnIQ4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769938275; c=relaxed/simple; bh=hsKZ9DzJafLyDdRycM2Ee6tppkb6X9Sas8yeTi5vc74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RlPQpbW3PWgsGfh3QYPIfD+mdBlg0jsxceHJfOhDmCJQDTPKtOpTOVNyntwKYhzneEHE5LF2HImXN9fSSWcS2BYubNH+VwS/Ag9qhKuqQYblta61LI/mEef8m9rng+nUaXYruTpRJ3Tz+hI1OD2SIo4pmoGJXbiudVZMQskM6q8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=Jkp5uhae; arc=pass smtp.client-ip=136.143.188.90 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="Jkp5uhae" ARC-Seal: i=1; a=rsa-sha256; t=1769938261; cv=none; d=zohomail.com; s=zohoarc; b=lunWI9eMu7IOTsWRUIbxA4qnKtLadokPrvzx8xXEMrAeJzXnszLvJbczyPHlV2lDcRItrW86306+hGtQm5ucuzbbQdScGcI9QaAGrD/hVayY6EsKuC1sxd/LafmuHxseNZA8/X8dAJL1i/ZQQ7yCLAeGFmLrWKKmFYeMK49M0KU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769938261; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=hibxExN37Y2J4xiEbPjvTudzX+CS65krB5RcbciB+5E=; b=Vgz1QY8Y5OAz6r5PgfeZj3BSshtHo7fXvmYZIuexbIm1zKpSQRld9EWqlX8g4y7lQZZsghDuqi0ct3U9wvHtRuG0OfkV5wB31TU5jox3YkEiV7F7kb3/izrdqFjbTWQi7aAouSBekWhhr83c1EseW1vJk59CoVGTIBxPxe0LCNI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1769938261; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Message-Id:Reply-To; bh=hibxExN37Y2J4xiEbPjvTudzX+CS65krB5RcbciB+5E=; b=Jkp5uhaeIVXqTeMRgIGH49U8G0Bexr89hAcQftQd3oak3n4+gvAGBZmwooToGVKW hejQsmA0rQ2gGTEIkGQFSlC51NdYjFR84DclY1aydhgYillnJMgnU2eo4A3oszF8mCH k0h18rLWMw5NuoQ/5NA2eO0yDlO7vOKcI9+f38+0= Received: by mx.zohomail.com with SMTPS id 1769938259821602.5139285541802; Sun, 1 Feb 2026 01:30:59 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming Subject: [PATCH 1/2] cxl/core: Set cxlmd->endpoint to NULL by default Date: Sun, 1 Feb 2026 17:30:01 +0800 Message-ID: <20260201093002.1281858-2-ming.li@zohomail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260201093002.1281858-1-ming.li@zohomail.com> References: <20260201093002.1281858-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Feedback-ID: rr0801122c411b09ef1fb4ee7f94413acf0000697a04a5620573b12ff06473ac3f0749b459dabb256658c55281bd1da3d1:zu080112278b7c9ab791961eb52563e3df000009965e6129cfe0e78302f79844d85cd3d086d36e310bb6d965:rf0801123270ba928561fc2df255162c670000405606c646f0593a246365c2696a558240fd345629d0887fc304483a33240de7e222a9ea:ZohoMail Content-Type: text/plain; charset="utf-8" CXL testing environment can trigger following trace Oops: general protection fault, probably for non-canonical address 0xdffff= c0000000092: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000490-0x0000000000000497] RIP: 0010:cxl_dpa_to_region+0x105/0x1f0 [cxl_core] Call Trace: cxl_event_trace_record+0xd1/0xa70 [cxl_core] __cxl_event_trace_record+0x12f/0x1e0 [cxl_core] cxl_mem_get_records_log+0x261/0x500 [cxl_core] cxl_mem_get_event_records+0x7c/0xc0 [cxl_core] cxl_mock_mem_probe+0xd38/0x1c60 [cxl_mock_mem] platform_probe+0x9d/0x130 really_probe+0x1c8/0x960 __driver_probe_device+0x187/0x3e0 driver_probe_device+0x45/0x120 __device_attach_driver+0x15d/0x280 commit 29317f8dc6ed ("cxl/mem: Introduce cxl_memdev_attach for CXL-dependen= t operation") initializes cxlmd->endpoint to ERR_PTR(-ENXIO) in cxl_memdev_alloc(). However, cxl_dpa_to_region() treats a non-NULL cxlmd->endpoint as a valid endpoint. Across the CXL core, endpoint availability is generally determined by checking whether it is NULL. Align with this convention by initializing cxlmd->endpoint to NULL by default. Fixes: 29317f8dc6ed ("cxl/mem: Introduce cxl_memdev_attach for CXL-dependen= t operation") Signed-off-by: Li Ming Reviewed-by: Gregory Price Reviewed-by: Jonathan Cameron --- drivers/cxl/core/memdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index af3d0cc65138..41a507b5daa4 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -675,7 +675,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_d= ev_state *cxlds, cxlmd->id =3D rc; cxlmd->depth =3D -1; cxlmd->attach =3D attach; - cxlmd->endpoint =3D ERR_PTR(-ENXIO); + cxlmd->endpoint =3D NULL; =20 dev =3D &cxlmd->dev; device_initialize(dev); --=20 2.43.0 From nobody Sat Feb 7 08:27:23 2026 Received: from sender4-pp-o90.zoho.com (sender4-pp-o90.zoho.com [136.143.188.90]) (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 EB9E32DFF1D; Sun, 1 Feb 2026 09:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.90 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769938282; cv=pass; b=e+f4QNec1R52nHw7OJ72T+OIHiFkPgJepnjQliqOdUqq97f0TiSUJXCTyuOklMbib9uEa5fyYbSVzQNTf6/cmRDbXAUQZlkzzMvtaVzajoTf9c5FXT46cTtSFF5ZQtzmfZpDjAyBtQeV1WeZgVhbjDVoZatF5lRLyJzhA2EmtHw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769938282; c=relaxed/simple; bh=nBOj+eZ31XIz3fTU5R51cCceiBldGbHgQS/NmDS9ZPU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qTgy+Ii2X2N0WszwykUS6P4BgEZmSYoQM5cVh9Kr2ZvNzidMBJXPWgAgXnbuCF7nyqrnIM5xsmjRnd7NDf6ktgs6sxVWt9v+nyCYg43BGGiRBJG41DVUEsCOO93uSpm2K6ccY2/bXHNxRBchd+rG3w03zmAxu6DQ4sD3dHwRVFc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=HUA9/SGN; arc=pass smtp.client-ip=136.143.188.90 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="HUA9/SGN" ARC-Seal: i=1; a=rsa-sha256; t=1769938269; cv=none; d=zohomail.com; s=zohoarc; b=T2kMW1azUzO2DFetEktwVqJxrnz7YRgFC/xFDy2auhVo96hxlWKMh33VfqBGJ6YImHdV+FvBjx5aR2jnB6TaBx3fq6Bc98zEhM7vTYssTBIf/g048mDx7zbXsOw1zrRSgUkdQm1p2uw9DLDzzJxRWDQc7MfMYxwt1i8VaL+J7Mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769938269; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=um7Rwl3nc2rUGCVeCqO6PMOLQM0nAbnAPJ2AKqKDL7Q=; b=Sff/7SsB3gFIWrCVgtQdHNkpt7zUVZx15TdIR+5EaWeXxxX1D25rorjIeAZSt475wBH82Uu9cuAWd71qplTATvZu9s7mHCZarq4rjiozoUOOY7p2YYWsr3TmaIAXKAsXlNLQJwMxXpM3AE3aaoB03VtsuHm6G7gDjyIf0p01jSo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1769938269; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Message-Id:Reply-To; bh=um7Rwl3nc2rUGCVeCqO6PMOLQM0nAbnAPJ2AKqKDL7Q=; b=HUA9/SGND/4r+BAJuCfrqA3K9JGfYps4tAFB+JVlulLdqSAyd28xiU+LMEyznzB2 WkP1sTNQrJaquGPISWeOUZ8c2e5BEYUqR+nyCZ/qLpfU2fGpq9Zt9AYvGvic5X4n573 FGnHkRmdr4OEcm+F5xkojDuqF+OFF6QqrBtA4018= Received: by mx.zohomail.com with SMTPS id 1769938268428264.52491364859065; Sun, 1 Feb 2026 01:31:08 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming Subject: [PATCH 2/2] cxl/core: Hold grandparent port lock while dport adding Date: Sun, 1 Feb 2026 17:30:02 +0800 Message-ID: <20260201093002.1281858-3-ming.li@zohomail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260201093002.1281858-1-ming.li@zohomail.com> References: <20260201093002.1281858-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Feedback-ID: rr0801122c5220c7f99190c00eb1a9215200002f2cf8a702a7d37c8715e358734040ba9ff9dec2ef7f7733f4b57b3b5dfa:zu08011227a62bdce4bd80fbbd4dae56b2000014f64478291be40dd36af877ace544630a1534a74992238e88:rf08011232c4003c64a836c36016f1a338000055538e8bfeeec9f42e89d9298eebd99129d854a94ffe5194ece7b7b028fb6285472217d5:ZohoMail Content-Type: text/plain; charset="utf-8" When CXL subsystem adds a cxl port to a hierarchy, there is a small window where the new port becomes visible before it is bound to a driver. This happens because device_add() adds a device to bus device list before bus_probe_device() binds it to a driver. So if two cxl memdevs are trying to add a dport to a same port via devm_cxl_enumerate_ports(), the second cxl memdev may observe the port and attempt to add a dport, but fails because the port has not yet been attached to cxl port driver. the sequence is like: CPU 0 CPU 1 devm_cxl_enumerate_ports() # port not found, add it add_port_attach_ep() # hold the parent port lock # to add the new port devm_cxl_create_port() device_add() # Add dev to bus devs list bus_add_device() devm_cxl_enumerate_ports() # found the port find_cxl_port_by_uport() # hold port lock to add a dport device_lock(the port) find_or_add_dport() cxl_port_add_dport() return -ENXIO because port->dev.driver is NULL device_unlock(the port) bus_probe_device() # hold the port lock # for attaching device_lock(the port) attaching the new port device_unlock(the port) To fix this race, require that dport addition holds the parent port lock of the target port. The CXL subsystem already requires holding the parent port lock while attaching a new port. Therefore, successfully acquiring the parent port lock ganrantees that port attaching has completed. Fixes: 4f06d81e7c6a ("cxl: Defer dport allocation for switch ports") Signed-off-by: Li Ming --- drivers/cxl/core/port.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 54f72452fb06..fef2fe913e1f 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -1817,8 +1817,12 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxlm= d) /* * RP port enumerated by cxl_acpi without dport will * have the dport added here. + * + * Hold the parent port lock here to in case that the + * port can be observed but has not been attached yet. */ - scoped_guard(device, &port->dev) { + scoped_guard(device, &parent_port_of(port)->dev) { + guard(device)(&port->dev); dport =3D find_or_add_dport(port, dport_dev); if (IS_ERR(dport)) { if (PTR_ERR(dport) =3D=3D -EAGAIN) --=20 2.43.0