Skip to content

RFC RFC: add Type2 device support

[email protected] linux-cxl 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest13 patches 33 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13cxl: move header files for absolute referencesdrivers/cxl/acpi.c drivers/cxl/core/cdat.c drivers/cxl/core/hdm.c +27 more+50 -5010 replies
2/13cxl: add type2 device basic supportdrivers/cxl/core/memdev.c include/linux/cxlmem.h tools/testing/cxl/Kbuild +2 more+105 -08 replies
3/13cxl: export core function for type2 devicesdrivers/cxl/pci.c include/linux/cxlpci.h tools/testing/cxl/type2/pci_type2.c+35 -12 replies
4/13cxl: allow devices without mailbox capabilitydrivers/cxl/core/regs.c+2 -32 replies
5/13cxl: fix check about pmem resourcedrivers/cxl/core/hdm.c drivers/cxl/core/memdev.c drivers/cxl/mem.c+7 -72 replies
6/13cxl: support type2 memdev creationdrivers/cxl/core/cdat.c drivers/cxl/core/memdev.c drivers/cxl/mem.c +1 more+29 -60 replies
7/13cxl: add functions for exclusive access to endpoint port topologydrivers/cxl/core/memdev.c include/linux/cxlmem.h tools/testing/cxl/type2/pci_type2.c+54 -01 reply
8/13cxl: add cxl_get_hpa_freespacedrivers/cxl/core/region.c include/linux/cxl.h include/linux/cxlmem.h +1 more+195 -11 reply
9/13cxl: add cxl_request_dpadrivers/cxl/core/core.h drivers/cxl/core/hdm.c include/linux/cxlmem.h +1 more+145 -261 reply
10/13cxl: make region type based on endpoint typedrivers/cxl/core/region.c+9 -50 replies
11/13cxl: allow automatic region creation by type2 driversdrivers/cxl/core/region.c include/linux/cxlmem.h tools/testing/cxl/type2/pci_type2.c+228 -561 reply
12/13cxl: preclude device memory to be used for daxdrivers/cxl/core/region.c+3 -00 replies
13/13cxl: test type2 private mappingtools/testing/cxl/type2/pci_type2.c+26 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 00/13] RFC: add Type2 device support

From: Alejandro Lucero <[email protected]>

I need to start this RFC explaining not what the patchset does, but what we expected to obtain and currently is under doubt: to configure a CXL memory range advertised by our CXL network device and to use it "privately".

The main reason behind that privacy, but not the only one, is to avoid any arbitrary use by any user-space "client" with enough privileges for using a public interface to map the device memory and use it as regular memory. The reason is obvious: the device expects writes to such a memory in a specific format.

The doubt comes from the fact that after implementing the functionality exposed in this patchset, we realized the current expectation seems to be a BIOS/UEFI configuring HDM decoders or HPA ranges and passing memory ranges to the kernel, and with the kernel having a default action on that memory range based on the flag EFI_MEMORY_SP being set or not. If it is not set, the memory range will be part of the kernel memory management, what we do not want for sure. If the flag is set, a DAX device will be created which allows an user-space client to map such a memory through the DAX device API, what we also prefer to avoid. I know this is likely going to face opposition, but we see this RFC as the opportunity for discussing the matter and, if it turns out to be the case, to be guided towards the proper solution accepted by the maintainers/community. This patchset does not tackle this default kernel behaviour although we already have some ideas and workarounds for the short term. We'll be happy to discuss this openly.

So, this patchset assumes a BIOS/UEFI not programming the HDM decoder or HPA ranges for a CXL Type2 device. Although maybe a weird assumption as explained above, a Type2 device added after boot, that is hotplugged, will likely need the changes added here. Exporting some of the CXL core for vendor drivers is also required for avoiding code duplication when reading DVSEC or decoder registers. Finally if there is no such HPA range assigned, whatever the reason, this patchset offers some way of obtaining one and/or finding out what is the problem behind the lack of such HPA range.

Current CXL kernel code is focused on supporting Type3 CXL devices, aka memory expanders. Type2 CXL devices, aka device accelerators, share some functionalities but require some special handling.

First of all, Type2 are by definition specific to vendor designs and a specific vendor driver is expected to work with the CXL specifics. This implies the CXL setup needs to be done by such a driver instead of by a generic CXL PCI driver as for memory expanders. Most of such setup needs to use current CXL core code and therefore needs to be accessible to those vendor drivers. This is accomplished with the first patch and with extensions to the exported functions in subsequent patches.

Keeping with kernel rules of having a client using any new functionality added, a CXL type2 driver is increasingly added. This is not a driver supporting a real device but an emulated one in QEMU, with the QEMU patch following this patchset.

The reason for adding such a Type2 driver instead of changes to a current kernel driver or a new driver is threefold:

1) the expected kernel driver to use the functionality added is a netdev one. Current internal CXL support is a codesign effort, therefore software and hardware evolving in lockstep. Adding changes to a netdev driver requires the full functionality and doing things following the netdev standard which is not the best option for this development stage.

2) Waiting for completing the development will delay the required Type2 support, and most of the required changes are unrelated to specific CXL usage by any vendor driver.

3) Type2 support will need some testing infrastructure, unit tests for ensuring Type2 devices are working, and module tests for ensuring CXL core changes do not affect Type2 support.

I hope these reasons are convincing enough.

I have decided to follow a gradual approach for adding such a driver using the exported CXL functions and structs. I think it is easier to review the driver when the new funcionality is added than to add the driver at the end, but not a big deal if my approach is not liked.

The patches are based on a patchset sent by Dan Williams [1] which was just partially integrated, most related to making things ready for Type2 but none related to specific Type2 support. Those patches based on Dan´s work have Dan´s signing, so Dan, tell me if you do not want me to add you.

Type2 implies, I think, only the related driver to manage the CXL specifics. This means no user space intervention and therefore no sysfs files. This makes easy to avoid the current problem of most of the sysfs related code expecting Type3 devices. If I´m wrong in this regard, such a code will need further changes.

A final note about CXL.cache is needed. This patchset does not cover it at all, although the emulated Type2 device advertises it. From the kernel point of view supporting CXL.cache will imply to be sure the CXL path supports what the Type2 device needs. A device accelerator will likely be connected to a Root Switch, but other configurations can not be discarded. Therefore the kernel will need to check not just HPA, DPA, interleave and granularity, but also the available CXL.cache support and resources in each switch in the CXL path to the Type2 device. I expect to contribute to this support in the following months, and it would be good to discuss about it when possible.

Alejandro.

[1] https://lore.kernel.org/linux-cxl/[email protected]/T/

Alejandro Lucero (13):
cxl: move header files for absolute references
cxl: add type2 device basic support
cxl: export core function for type2 devices
cxl: allow devices without mailbox capability
cxl: fix check about pmem resource
cxl: support type2 memdev creation
cxl: add functions for exclusive access to endpoint port topology
cxl: add cxl_get_hpa_freespace
cxl: add cxl_request_dpa
cxl: make region type based on endpoint type
cxl: allow automatic region creation by type2 drivers
cxl: preclude device memory to be used for dax
cxl: test type2 private mapping

 drivers/cxl/acpi.c                      |   4 +-
 drivers/cxl/core/cdat.c                 |   9 +-
 drivers/cxl/core/core.h                 |   1 -
 drivers/cxl/core/hdm.c                  | 159 +++++++--
 drivers/cxl/core/mbox.c                 |   6 +-
 drivers/cxl/core/memdev.c               |  75 +++-
 drivers/cxl/core/pci.c                  |   6 +-
 drivers/cxl/core/pmem.c                 |   4 +-
 drivers/cxl/core/pmu.c                  |   4 +-
 drivers/cxl/core/port.c                 |   6 +-
 drivers/cxl/core/region.c               | 446 ++++++++++++++++++++----
 drivers/cxl/core/regs.c                 |   9 +-
 drivers/cxl/core/suspend.c              |   2 +-
 drivers/cxl/core/trace.c                |   2 +-
 drivers/cxl/core/trace.h                |   4 +-
 drivers/cxl/mem.c                       |  23 +-
 drivers/cxl/pci.c                       |   9 +-
 drivers/cxl/pmem.c                      |   4 +-
 drivers/cxl/port.c                      |   4 +-
 drivers/cxl/security.c                  |   4 +-
 drivers/dax/cxl.c                       |   2 +-
 drivers/perf/cxl_pmu.c                  |   4 +-
 {drivers/cxl => include/linux}/cxl.h    |   5 +
 {drivers/cxl => include/linux}/cxlmem.h |  22 +-
 {drivers/cxl => include/linux}/cxlpci.h |   2 +
 tools/testing/cxl/Kbuild                |   1 +
 tools/testing/cxl/cxl_core_exports.c    |   2 +-
 tools/testing/cxl/mock_acpi.c           |   2 +-
 tools/testing/cxl/test/cxl.c            |   2 +-
 tools/testing/cxl/test/mem.c            |   2 +-
 tools/testing/cxl/test/mock.c           |   4 +-
 tools/testing/cxl/test/mock.h           |   2 +-
 tools/testing/cxl/type2/Kbuild          |   7 +
 tools/testing/cxl/type2/pci_type2.c     | 201 +++++++++++
 34 files changed, 886 insertions(+), 153 deletions(-)
 rename {drivers/cxl => include/linux}/cxl.h (99%)
 rename {drivers/cxl => include/linux}/cxlmem.h (97%)
 rename {drivers/cxl => include/linux}/cxlpci.h (97%)
 create mode 100644 tools/testing/cxl/type2/Kbuild
 create mode 100644 tools/testing/cxl/type2/pci_type2.c
Signature · 1 line
2.17.1