Commit 670e4e88 authored by Dave Jiang's avatar Dave Jiang Committed by Dan Williams

cxl: Add checksum verification to CDAT from CXL

A CDAT table is available from a CXL device. The table is read by the
driver and cached in software. With the CXL subsystem needing to parse the
CDAT table, the checksum should be verified. Add checksum verification
after the CDAT table is read from device.
Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarDavidlohr Bueso <dave@stgolabs.net>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/169713682277.2205276.2687265961314933628.stgit@djiang5-mobl3Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 529c0a44
...@@ -595,6 +595,16 @@ static int cxl_cdat_read_table(struct device *dev, ...@@ -595,6 +595,16 @@ static int cxl_cdat_read_table(struct device *dev,
return 0; return 0;
} }
static unsigned char cdat_checksum(void *buf, size_t size)
{
unsigned char sum, *data = buf;
size_t i;
for (sum = 0, i = 0; i < size; i++)
sum += data[i];
return sum;
}
/** /**
* read_cdat_data - Read the CDAT data on this port * read_cdat_data - Read the CDAT data on this port
* @port: Port to read data from * @port: Port to read data from
...@@ -634,15 +644,21 @@ void read_cdat_data(struct cxl_port *port) ...@@ -634,15 +644,21 @@ void read_cdat_data(struct cxl_port *port)
return; return;
rc = cxl_cdat_read_table(dev, cdat_doe, cdat_table, &cdat_length); rc = cxl_cdat_read_table(dev, cdat_doe, cdat_table, &cdat_length);
if (rc) { if (rc)
/* Don't leave table data allocated on error */ goto err;
devm_kfree(dev, cdat_table);
dev_err(dev, "CDAT data read error\n");
return;
}
port->cdat.table = cdat_table + sizeof(__le32); cdat_table = cdat_table + sizeof(__le32);
if (cdat_checksum(cdat_table, cdat_length))
goto err;
port->cdat.table = cdat_table;
port->cdat.length = cdat_length; port->cdat.length = cdat_length;
return;
err:
/* Don't leave table data allocated on error */
devm_kfree(dev, cdat_table);
dev_err(dev, "Failed to read/validate CDAT.\n");
} }
EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL); EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment