Skip to content

Commit 267214a

Browse files
committed
cxl/port: Fix port to pci device assumptions in read_cdat_data()
Not all endpoint CXL ports are associated with PCI devices. The cxl_test infrastructure models 'struct cxl_port' instances hosted by platform devices. Teach read_cdat_data() to be careful about non-pci hosted cxl_memdev instances. Otherwise, cxl_test crashes with this signature: RIP: 0010:xas_start+0x6d/0x290 [..] Call Trace: <TASK> xas_load+0xa/0x50 xas_find+0x25b/0x2f0 xa_find+0x118/0x1d0 pci_find_doe_mailbox+0x51/0xc0 read_cdat_data+0x45/0x190 [cxl_core] cxl_port_probe+0x10a/0x1e0 [cxl_port] cxl_bus_probe+0x17/0x50 [cxl_core] Some other cleanups are included like removing the single-use @uport variable, and removing the indirection through 'struct cxl_dev_state' to lookup the device that registered the memdev and may be a pci device. Fixes: af0a6c3 ("cxl/pci: Use CDAT DOE mailbox created by PCI core") Reviewed-by: Lukas Wunner <lukas@wunner.de> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/168213190748.708404.16215095414060364800.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent f960e57 commit 267214a

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/cxl/core/pci.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,18 @@ static int cxl_cdat_read_table(struct device *dev,
536536
*/
537537
void read_cdat_data(struct cxl_port *port)
538538
{
539-
struct pci_doe_mb *cdat_doe;
539+
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport);
540+
struct device *host = cxlmd->dev.parent;
540541
struct device *dev = &port->dev;
541-
struct device *uport = port->uport;
542-
struct cxl_memdev *cxlmd = to_cxl_memdev(uport);
543-
struct cxl_dev_state *cxlds = cxlmd->cxlds;
544-
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
542+
struct pci_doe_mb *cdat_doe;
545543
size_t cdat_length;
546544
void *cdat_table;
547545
int rc;
548546

549-
cdat_doe = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL,
547+
if (!dev_is_pci(host))
548+
return;
549+
cdat_doe = pci_find_doe_mailbox(to_pci_dev(host),
550+
PCI_DVSEC_VENDOR_ID_CXL,
550551
CXL_DOE_PROTOCOL_TABLE_ACCESS);
551552
if (!cdat_doe) {
552553
dev_dbg(dev, "No CDAT mailbox\n");

0 commit comments

Comments
 (0)