From nobody Thu Apr 2 09:40:43 2026 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 D9E59319877; Tue, 10 Feb 2026 11:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724200; cv=pass; b=CbcFuW+FZaknDsF2DpdpckhXS2THbneVkLl5QlL/u4IEgbcPWWPc09AhMygypOttxdyD1QlbcsjbXa6kfXB8bWDT+5Ct2lzvnozuVAiQMO+bpveNZHslzFdrLHoWX6XTDlIHBkcvH+k97ltKuZSS+8khDfQzW2WEFYEyg2tWyqI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724200; c=relaxed/simple; bh=2BSn1JChjMXd3ALXSdZJzoHgD3CSG/e1qyGV2a3Mj3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TGEhOMcDVmQE6cnuc5NQepSip99TsG5QZCHogPeZuRAve2myK/Sh95kw4Z7VAMlyN9FUYXKJZy1TkCmOGg2yr7mbxHeQVZlKKWdsRPtfeVgwHApGbH7ESbiUkhOvLLdGKapWx6/tKvH+5y0/aYBYLTDOIxYv81G9TqWmC7ccsSs= 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=Xc/X5wZq; arc=pass smtp.client-ip=136.143.188.94 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="Xc/X5wZq" ARC-Seal: i=1; a=rsa-sha256; t=1770724063; cv=none; d=zohomail.com; s=zohoarc; b=LgsaJgzmxAArEVN0BHAJVb4QLAvEWTpvKaYtn4znmCvcyuk4VX5rfYRFYzMAGEcUn3/BPTkfMn3O3xSK2jiPFPk8ygRf7OFr5OA2FTbWro+qdnHwIHzh+d1NxpuGascCFawbmgAXqyC7u032GTb0AgFwtFFcfGUnX6/6Oao0ymw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770724063; h=Content-Type: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=rKLVpOH4qWtdhXrEWiIGQPOq6XakgqV4AKkcQISb48Y=; b=VkDnLXIIDhhxiH7+LgS3v6PXCfkqngUKJoDks47r9v/DFulBO1vRvoPe8HsvbTuD0/zX5Pbim5fO+aOMAaISTdy7eSWiAUN6NHC4/wP0JIff/GTfFHJigWynWKTZV+UbS+ej5g0B7hFlswrL5WHxsKB0OebCJWDeSj+4ZuzhX9Y= 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=1770724063; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Feedback-ID:Reply-To; bh=rKLVpOH4qWtdhXrEWiIGQPOq6XakgqV4AKkcQISb48Y=; b=Xc/X5wZqgLxjRit42ntdV6KlSbcOc1tiNoBBFeJ+2C0RSyfKTrf34hiWJowt0O6v 03qnBMdYe+3KnJKvfTmyzvbntmKsJoaD5jFXHWUGNaKprJ/oaCDp8g8ftnyfkWVmQkt b41rEeYZDoXiGfSrzhsB0NRjjHFjEEPUt2Ung6Lw= Received: by mx.zohomail.com with SMTPS id 1770724061435744.5603740836011; Tue, 10 Feb 2026 03:47:41 -0800 (PST) From: Li Ming Date: Tue, 10 Feb 2026 19:46:56 +0800 Subject: [PATCH v3 1/3] cxl/port: Introduce port_to_host() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260210-fix-port-enumeration-failure-v3-1-06acce0b9ead@zohomail.com> References: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> In-Reply-To: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770724039; l=1543; i=ming.li@zohomail.com; s=20260210; h=from:subject:message-id; bh=2BSn1JChjMXd3ALXSdZJzoHgD3CSG/e1qyGV2a3Mj3s=; b=q0aCmNdh6uGPBvH4AcR8wvth1sIOJvtPLA48phFQ8zgtv9yfLGa+DdONMCSJIsHHwXjklRjDi Wu5/64nW6tLCY1k56Fi0+MJezndBxV/ymh0DgWmXsxUw1f0R618lvOJ X-Developer-Key: i=ming.li@zohomail.com; a=ed25519; pk=JfhrdHjyYJMXt47Hy8d/fsqZuhGPD4Z3whV5lTfVvhE= Feedback-ID: rr080112280f3a426764f497992f6fec750000eb73f3c869bcf51434c96f4c1ff419e0559ad4edc3d2e1b21c0d:zu08011227046f282e5fcef7863ff5bad3000058d957063f49c19cb7ff41b0174d2d748f51777d06e770fbbf:rf0801122d771ee78e8f832aa2356220b000007c65841ec7fe5b92f42d47b94bde76dbccc117cebfafc8249a3aa87fc06e82:ZohoMail X-ZohoMailClient: External In CXL subsystem, a port has its own host device for the port creation and removal. The host of CXL root and all the first level ports is the platform firmware device, the host of other ports is their parent port's device. Create this new helper to much easier to get the host of a cxl port. A dport_to_host() helper has been introduced, use port_to_host() as the name to align with this naming convention. Signed-off-by: Li Ming Reviewed-by: Dan Williams Tested-by: Alison Schofield --- drivers/cxl/core/core.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 007b8aff0238..5b0570df0fd9 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -152,6 +152,24 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct= access_coordinate *c); int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port, struct access_coordinate *c); =20 +static inline struct device *port_to_host(struct cxl_port *port) +{ + struct cxl_port *parent =3D is_cxl_root(port) ? NULL : + to_cxl_port(port->dev.parent); + + /* + * The host of CXL root port and the first level of ports is + * the platform firmware device, the host of all other ports + * is their parent port. + */ + if (!parent) + return port->uport_dev; + else if (is_cxl_root(parent)) + return parent->uport_dev; + else + return &parent->dev; +} + static inline struct device *dport_to_host(struct cxl_dport *dport) { struct cxl_port *port =3D dport->port; --=20 2.43.0 From nobody Thu Apr 2 09:40:43 2026 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 C892631B80D; Tue, 10 Feb 2026 11:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724214; cv=pass; b=Cs4mB0dCzopc6aYl7ZAXGK/oK3UaDvKK6ojMpQTVwTSZEcerZNl8EdPiSxVsrtJyiN0G1qpuIsho+UFId7uIVxUcm86iAin81YbWCh5yAZBOsZZqfClpunwcYJ8wzQ8Lolj+BNGJG7TpxB/P3rjq0t8DW5iP7g5Xy9xadGSPdLE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724214; c=relaxed/simple; bh=SSnVkzVSropAXZSCmu0ixw4Cij1D6YdUc8DhKgOzrWE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b2tXUnnGquAUo2PeOiLjeasVpzgKGnM/C27aYxdLP1vcoq5L2DoNAvdWulCFGLa9qDpLxLvM/0GfmxZE6wn2nqUeUxNyKN52FXfqG1tihJ9FG4gQRsNi4hFWK9FdSnVaWFR2ZluC7lbUSuL/JCihtRhvJAP0yxu2vfMdejZpl8I= 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=f3TW043Z; arc=pass smtp.client-ip=136.143.188.94 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="f3TW043Z" ARC-Seal: i=1; a=rsa-sha256; t=1770724071; cv=none; d=zohomail.com; s=zohoarc; b=ao45GBYqlvQ++4SFh+/aR+ajJE5PJ3uzNyn12PidtpXlAWPiOincZRzftanXIaWJihXAFBsvFSKit7Syufwy1CNvZWTaET0taDPniI4vvjhbxqWlPaUfr5bnMUHTP2MpxgHtaqwop4kzEBnfSm15TGQnn3Lg8l2qC60WHwE799k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770724071; h=Content-Type: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=CLCMJSIdCBJK8kkdm0K0l2O1r5OcTqNcYjBsQ8aUQyY=; b=TWA282YoNOvP4UPg7UIbSjc2lCv6Jr27/tEyYQptax2ucyd8rV+6MrQSQ4VTdqfcI9jJHOCGEsyOs+FVp0xOXUvA35HTAF2A505rgW5+27YDsyF2BRFFX7z/lKaWWPBDjkcJcsBLSySQ1O0uNBoW+Bv2Gls5Z4OTPxrk1kidLZc= 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=1770724071; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Feedback-ID:Reply-To; bh=CLCMJSIdCBJK8kkdm0K0l2O1r5OcTqNcYjBsQ8aUQyY=; b=f3TW043ZRiXz+/idt/C+RbmBeFSsSMvQ1TPHykLDdwGoWPY/q/vOAKSnb/2XIAoh jMlMuJxSgitqvgPgJKRHLuqerdM49sMao9JzAH1RgGz/MtQR8gGULvs1w/Knq6uKsMT JEwmQLWLHjepYkobTvSXneyImRy8e8o7/0/0Jfn4= Received: by mx.zohomail.com with SMTPS id 1770724068091582.9441928379345; Tue, 10 Feb 2026 03:47:48 -0800 (PST) From: Li Ming Date: Tue, 10 Feb 2026 19:46:57 +0800 Subject: [PATCH v3 2/3] cxl/port: Hold port host lock during dport adding. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260210-fix-port-enumeration-failure-v3-2-06acce0b9ead@zohomail.com> References: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> In-Reply-To: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770724039; l=4221; i=ming.li@zohomail.com; s=20260210; h=from:subject:message-id; bh=SSnVkzVSropAXZSCmu0ixw4Cij1D6YdUc8DhKgOzrWE=; b=5gdW+wyrvDcTHOv1whBnPF9We0lwSeFQFmSQyabhYOuOjEwhZIus2sZW5cKHyVNYdEo/AWkaQ hhogbSpXC+KBbeg7A16N/wmtHhAFRsVl9BO9SsjnjsFObP2SX6ZTfkz X-Developer-Key: i=ming.li@zohomail.com; a=ed25519; pk=JfhrdHjyYJMXt47Hy8d/fsqZuhGPD4Z3whV5lTfVvhE= Feedback-ID: rr080112283198f6dc84b958d6760c31e70000320fac2be414855e92b573365e0421f17c47085f34b2dd600a5e:zu08011227d4a0fdec6c8685d83bfd536400005571b87f17fa6cb201c3f2a99820580552cf76cf3745a2093b:rf0801122da78a5ee33d180eb8558006020000424f52721d32ca6a2e86c68a9224437c82a93856a063dcfee17439a34f3cf1:ZohoMail X-ZohoMailClient: External 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 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. That causes the memdev->endpoint can not be updated. 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 host lock of the target port(the host of CXL root and all cxl host bridge ports is the platform firmware device, the host of all other ports is their parent port). The CXL subsystem already requires holding the host lock while attaching a new port. Therefore, successfully acquiring the host lock guarantees that port attaching has completed. Fixes: 4f06d81e7c6a ("cxl: Defer dport allocation for switch ports") Signed-off-by: Li Ming Reviewed-by: Dan Williams Tested-by: Alison Schofield --- drivers/cxl/core/port.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 5c82e6f32572..9e4abdaf209b 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -1790,7 +1790,16 @@ static struct cxl_dport *find_or_add_dport(struct cx= l_port *port, { struct cxl_dport *dport; =20 - device_lock_assert(&port->dev); + /* + * The port is already visible in CXL hierarchy, but it may still + * be in the process of binding to the CXL port driver at this point. + * + * port creation and driver binding are protected by the port's host + * lock, so acquire the host lock here to ensure the port has completed + * driver binding before proceeding with dport addition. + */ + guard(device)(port_to_host(port)); + guard(device)(&port->dev); dport =3D cxl_find_dport_by_dev(port, dport_dev); if (!dport) { dport =3D probe_dport(port, dport_dev); @@ -1857,13 +1866,11 @@ int devm_cxl_enumerate_ports(struct cxl_memdev *cxl= md) * RP port enumerated by cxl_acpi without dport will * have the dport added here. */ - scoped_guard(device, &port->dev) { - dport =3D find_or_add_dport(port, dport_dev); - if (IS_ERR(dport)) { - if (PTR_ERR(dport) =3D=3D -EAGAIN) - goto retry; - return PTR_ERR(dport); - } + dport =3D find_or_add_dport(port, dport_dev); + if (IS_ERR(dport)) { + if (PTR_ERR(dport) =3D=3D -EAGAIN) + goto retry; + return PTR_ERR(dport); } =20 rc =3D cxl_add_ep(dport, &cxlmd->dev); --=20 2.43.0 From nobody Thu Apr 2 09:40:43 2026 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 CA3C0319877; Tue, 10 Feb 2026 11:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724227; cv=pass; b=PJJwAP0PpwQ1cF++48LLu1FYa0pjHI5Bqur48utN9F2KwC4rlarD2RpNgo9ZYcwNMhncV4cGBQOVfsw9TSRHDGnlWn5PjzIPSIRNEKD4EaJo8Fi/HHyO/dBkXb7fBm7ALTGXTGdtLjYOU9T2NIeEGjaxAKvC5F4BH7nT92MPRKY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770724227; c=relaxed/simple; bh=jrtuRImjEUTr5xX17e1u7Nwuz+W7uVq8j9NCrIKV02w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TCiSUVUnfytUi3Fj7Z9UrlQTCSPNukhomlAG28SXfILk9hGJPap8sl+qyWtzsLhBW45w1YrhoN/KbohLc5YeV1b05vB0jtq9OOdyOqokmOVKQKA5hXV7vJmAMWMn3CptRN7IXsI5kQQM33baQvFFsBrEpLd2WN5QZHDnqx07T1Y= 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=R1RVZAVF; arc=pass smtp.client-ip=136.143.188.94 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="R1RVZAVF" ARC-Seal: i=1; a=rsa-sha256; t=1770724085; cv=none; d=zohomail.com; s=zohoarc; b=oFzPhf3gpaZRzFAPW/0aAApI1fq1cG4f3ZML0yUBv77tNURMPIaw7R3+QwV5zoVUD5jXHeSOB2vrxP/uPh3BcUGExAGUwMzQCN23qgjhRrAVxO/U6llnVv5jDzLTUmaXsdNdxaxiIdL1UoF+tqJqg5UYP9YFWhn+uTqhWAQbaAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770724085; h=Content-Type: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=/sM3rw4letdW5hweiSDCcJVIY9wprZ2MKwMQZXK0xPg=; b=GrquEIlbc7SfrtPmvdliAuqmWCeKMP8J/BivhRzF2+Qv5e+6vp3E3EvnPkqA1d7GhrJe22iYA97XuGDFt1kgFknxKEVLNyD9hhfoSP+o/gNl84Q29nj4JXgBpZrJ32N4uy2r9AwGwpqkwYPXpDMtWqOAQij3K2zRbJ49T+0yXGE= 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=1770724085; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Feedback-ID:Reply-To; bh=/sM3rw4letdW5hweiSDCcJVIY9wprZ2MKwMQZXK0xPg=; b=R1RVZAVFBYdOKHHvq6XZ+AY0WHUgl+dUxgprg7lySLf2K2+L8AcucNxjkla9warq X8BQDVLuGjfx1gkaCBh8ZMcjHfUp4Jw8KtP14C8nIgCbYlLRmdwkStaomke3k8hX5JJ aeiIXFGZKx6EePLMv8wYav/NN5+x71gVg2gu2l9k= Received: by mx.zohomail.com with SMTPS id 1770724083145370.58933083292277; Tue, 10 Feb 2026 03:48:03 -0800 (PST) From: Li Ming Date: Tue, 10 Feb 2026 19:46:58 +0800 Subject: [PATCH v3 3/3] cxl/port: Use port_to_host() to get port host Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260210-fix-port-enumeration-failure-v3-3-06acce0b9ead@zohomail.com> References: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> In-Reply-To: <20260210-fix-port-enumeration-failure-v3-0-06acce0b9ead@zohomail.com> To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770724039; l=2225; i=ming.li@zohomail.com; s=20260210; h=from:subject:message-id; bh=jrtuRImjEUTr5xX17e1u7Nwuz+W7uVq8j9NCrIKV02w=; b=joc4bfiyQ1xCj5x1OOHS1wg6LlaXsmMoISKaLpyIUGpmIf4w6JwCZP04Idquc14ue2bVbBUHv jRKg+T2Xu2EBzveuuOpGlT/FvCHJOl2k5mG3qwgrzaqxWFShE7NMt8c X-Developer-Key: i=ming.li@zohomail.com; a=ed25519; pk=JfhrdHjyYJMXt47Hy8d/fsqZuhGPD4Z3whV5lTfVvhE= Feedback-ID: rr08011228900d802c4ff5a8a6ef7fc686000042be4d3e74393aad9660da4438e4c53059c96dbea0ad6375128c:zu080112274c057a5bc230c725847bdf6000007b9eba8f5134798bb115c2e7917e72fbc5ea0e64d8c837ca9d:rf0801122d36934606d5232717a23e6db40000fbf621542dae993a6982e57f02b5f684deebb7115b0cac7c0dd3a0b2b49f24:ZohoMail X-ZohoMailClient: External port_to_host() has been introduced, use it to replace all places where using open coded to get the host of a port. Remove endpoint_host() as its functionality can be replaced by port_to_host(). Signed-off-by: Li Ming Reviewed-by: Dan Williams Tested-by: Alison Schofield --- drivers/cxl/core/port.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 9e4abdaf209b..a45bbc620b4d 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -615,22 +615,8 @@ struct cxl_port *parent_port_of(struct cxl_port *port) static void unregister_port(void *_port) { struct cxl_port *port =3D _port; - struct cxl_port *parent =3D parent_port_of(port); - struct device *lock_dev; =20 - /* - * CXL root port's and the first level of ports are unregistered - * under the platform firmware device lock, all other ports are - * unregistered while holding their parent port lock. - */ - if (!parent) - lock_dev =3D port->uport_dev; - else if (is_cxl_root(parent)) - lock_dev =3D parent->uport_dev; - else - lock_dev =3D &parent->dev; - - device_lock_assert(lock_dev); + device_lock_assert(port_to_host(port)); port->dead =3D true; device_unregister(&port->dev); } @@ -1427,20 +1413,11 @@ static struct device *grandparent(struct device *de= v) return NULL; } =20 -static struct device *endpoint_host(struct cxl_port *endpoint) -{ - struct cxl_port *port =3D to_cxl_port(endpoint->dev.parent); - - if (is_cxl_root(port)) - return port->uport_dev; - return &port->dev; -} - static void delete_endpoint(void *data) { struct cxl_memdev *cxlmd =3D data; struct cxl_port *endpoint =3D cxlmd->endpoint; - struct device *host =3D endpoint_host(endpoint); + struct device *host =3D port_to_host(endpoint); =20 scoped_guard(device, host) { if (host->driver && !endpoint->dead) { @@ -1456,7 +1433,7 @@ static void delete_endpoint(void *data) =20 int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *end= point) { - struct device *host =3D endpoint_host(endpoint); + struct device *host =3D port_to_host(endpoint); struct device *dev =3D &cxlmd->dev; =20 get_device(host); --=20 2.43.0