[RFC PATCH 0/3] cxl: Auto-create a region for Type-2 memdev attach
Richard Cheng <[email protected]> Wed, 5 Aug 2026 15:40:39 +0800
| Newsgroups | org.kernel.vger.linux-cxl,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
A Type-2 accelerator driver calls devm_cxl_probe_mem() to register its memdev and get an HPA range, but today only if FW already committed a region. Real accelerators can have usable memory with no committed decoder, so get nothing. If no FW region is mapped, the core picks the device's unused manual DEVMEM decoder and a compatible x1 Type-2 RAM root, allocates the full volatile DPA and HPA, commits the decoder, and returns the range. Unbind resets and removes it. Strict first cut with single decoder, IW=1, minimum granularity, first-compatible root. The design intent is that the provider F_LOCKs its region against userspace but must reset its own software region on detach. A plain flag would also allow reset on generic kill/delete paths, so we thread a reset context through teardown and commit rollback. devm_cxl_probe_mem() may now commit decoders. Testing result is in the following. - Built clean with clang/LLVM on arm64 - cxl_test, type2_test=1. accel0 takes the unchanged attach path. accel1 drives auto_create -> a committed 512 MB RAM region. The test asserts the 512 MB HPA range. committed state and 256 byte granularity confirmed via sysfs. - Unbind tears the region down with no orphaned decoder, rebind re-creates a fresh committed region. - Mock test only. Real accelerators whose FW commits a decoder take the attach path, and vfio-cxl binds only FW-committed devices, so auto-create has no real-HW caller yet. Best regards, Richard Cheng. Richard Cheng (3): cxl/region: Reset software-created regions on memdev detach cxl/region: Auto-create a region for memdev attach cxl/test: Exercise Type-2 automatic region creation drivers/cxl/core/region.c | 422 +++++++++++++++++++++++++++++---- tools/testing/cxl/test/accel.c | 7 + tools/testing/cxl/test/cxl.c | 61 ++++- 3 files changed, 439 insertions(+), 51 deletions(-) base-commit: 1c6b4ceafc3b994871c29340e0c1ddb0af5800e7 -- 2.43.0