linux/drivers/cxl
Lukas Wunner f960e57dca cxl/pci: Rightsize CDAT response allocation
Jonathan notes that cxl_cdat_get_length() and cxl_cdat_read_table()
allocate 32 dwords for the DOE response even though it may be smaller.

In the case of cxl_cdat_get_length(), only the second dword of the
response is of interest (it contains the length).  So reduce the
allocation to 2 dwords and let DOE discard the remainder.

In the case of cxl_cdat_read_table(), a correctly sized allocation for
the full CDAT already exists.  Let DOE write each table entry directly
into that allocation.  There's a snag in that the table entry is
preceded by a Table Access Response Header (1 dword, CXL 3.0 table 8-14).
Save the last dword of the previous table entry, let DOE overwrite it
with the header of the next entry and restore it afterwards.

The resulting CDAT is preceded by 4 unavoidable useless bytes.  Increase
the allocation size accordingly.

The buffer overflow check in cxl_cdat_read_table() becomes unnecessary
because the remaining bytes in the allocation are tracked in "length",
which is passed to DOE and limits how many bytes it writes to the
allocation.  Additionally, cxl_cdat_read_table() bails out if the DOE
response is truncated due to insufficient space.

Tested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/7a4e1f86958a79a70f29b96a92199522f08f8322.1678543498.git.lukas@wunner.de
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-04-18 10:36:58 -07:00
..
core cxl/pci: Rightsize CDAT response allocation 2023-04-18 10:36:58 -07:00
acpi.c Merge branch 'for-6.3/cxl-ram-region' into cxl/next 2023-02-10 18:11:01 -08:00
cxl.h cxl/port: Fix find_cxl_root() for RCDs and simplify it 2023-04-04 15:34:34 -07:00
cxlmem.h cxl/pci: Use CDAT DOE mailbox created by PCI core 2023-04-18 10:36:58 -07:00
cxlpci.h cxl/pci: Handle truncated CDAT entries 2023-04-03 16:16:34 -07:00
Kconfig Merge branch 'for-6.3/cxl-ram-region' into cxl/next 2023-02-10 18:11:01 -08:00
Makefile cxl/pmem: Introduce nvdimm_security_ops with ->get_flags() operation 2022-11-30 16:30:47 -08:00
mem.c cxl/port: Add RCD endpoint port enumeration 2022-12-05 10:32:26 -08:00
pci.c cxl/pci: Use CDAT DOE mailbox created by PCI core 2023-04-18 10:36:58 -07:00
pmem.c cxl/pmem: Fix nvdimm registration races 2023-02-13 17:01:05 -08:00
port.c cxl/port: Fix find_cxl_root() for RCDs and simplify it 2023-04-04 15:34:34 -07:00
security.c cxl/mbox: Enable cxl_mbox_send_cmd() users to validate output size 2022-12-06 14:36:02 -08:00