cxl/mbox: Support Media Operation
Davidlohr Bueso
maintainerPATCH 1/1 cxl/mbox: Support Media Operation
Add support for the Media Operation command (opcode 4402h) which enables targeted sanitize and zero operations on specific DPA ranges, as defined in CXL 4.0 Section 8.2.10.9.5.3.
Operations are only allowed on DPA ranges that do not overlap any hardware-committed endpoint decoder to ensure not corrupting active mappings.
Following the path that we currently impose for background cmds, where users are left with the responsibility of breaking up work sanely, this implementation imposes an arbitrary limit of 1Gb range to avoid hogging locks (ie: dpa cannot change while media op is on going) and resource monopolization such as mbox. As such, background commands are processed synchronously, and currently, per spec, there is no optional abort it either, nor a way for the device to inform how long the op could take, ala Scan Media. The observation is that this differs in semantics regarding the sanitize case, which for whole-device continues to be handled asynchronously, as a special case.
Run Discovery during probe to get the device's DPA range granularity and which operations are supported, and expose to sysfs accordingly:
o 'security/sanitize' is multiplexed to allow single ranged input.
o 'security/zero' is added, also with single ranged input.
o 'security/range_limit' is added so users can see the max range supported.
---
Changes from rfc (https://lore.kernel.org/all/[email protected]/):
- Dropped rfc (kept synchronous approach)
- Simplified discovery payload in/out (Jonathan)
- Use __free when possible (Jonathan)
- Added __counted_by_le to the payload structs (Jonathan)
- Document cache flushing semantics in 'zero'
- Added 'range_limit' set to 1Gb (Jonathan)
- Hardened granularity checks from hw.
Documentation/ABI/testing/sysfs-bus-cxl | 64 +++++-- drivers/cxl/core/mbox.c | 240 ++++++++++++++++++++++++ drivers/cxl/core/memdev.c | 66 ++++++- drivers/cxl/cxlmem.h | 67 +++++++ drivers/cxl/pci.c | 4 + 5 files changed, 429 insertions(+), 12 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +53 -11
@@ -117,10 +117,12 @@ Contact: [email protected] Description: (RO) Reading this file will display the CXL security state for that device. Such states can be: 'disabled', 'sanitize', when - a sanitization is currently underway; or those available only - for persistent memory: 'locked', 'unlocked' or 'frozen'. This - sysfs entry is select/poll capable from userspace to notify - upon completion of a sanitize operation. + a whole-device sanitization is currently underway; or those + available only for persistent memory: 'locked', 'unlocked' or + 'frozen'. This sysfs entry is select/poll capable from + userspace to notify upon completion of a sanitize operation. + Targeted range sanitize via Media Operation does not affect + this state as it completes synchronously. What: /sys/bus/cxl/devices/memX/security/sanitize
@@ -129,17 +131,25 @@ KernelVersion: v6.5 Contact: [email protected] Description: (WO) Write a boolean 'true' string value to this attribute to - sanitize the device to securely re-purpose or decommission it. + sanitize the entire device, to securely re-purpose or + decommission it. If the device supports the Media Operation + command with the sanitize operation, a DPA range may be written + as 'start length' in bytes to sanitize a targeted region of + media. The start address and length must be aligned to the + device's media operation granularity, and the length must not + exceed the value reported in 'range_limit'. The sanitize method + applied to the range is the same as for whole-device sanitize. + This is done by ensuring that all user data and meta-data, whether it resides in persistent capacity, volatile capacity, or the LSA, is made permanently unavailable by whatever means is appropriate for the media type. This functionality requires - the device to be disabled, that is, not actively decoding any - HPA ranges. This permits avoiding explicit global CPU cache - management, relying instead for it to be done when a region - transitions between software programmed and hardware committed - states. If this file is not present, then there is no hardware - support for the operation. + the device or relevant range to be disabled, that is, not + actively decoding any HPA ranges. This permits avoiding explicit + global CPU cache management, relying instead for it to be done + when a region transitions between software programmed and + hardware committed states. If this file is not present, then + there is no hardware support for the operation. What /sys/bus/cxl/devices/memX/security/erase
@@ -158,6 +168,38 @@ Description: support for the operation. +What: /sys/bus/cxl/devices/memX/security/zero +Date: April, 2026 +KernelVersion: v7.2 +Contact: [email protected] +Description: + (WO) Write a DPA range as 'start length' in bytes to this + attribute to zero a specific region of device media via the + Media Operation command. The start address and length must be + aligned to the device's media operation granularity, and the + length must not exceed the value reported in 'range_limit'. + This functionality requires the range to be disabled, that is, + not actively decoding any HPA ranges. This permits avoiding + explicit global CPU cache management, relying instead for it + to be done when a region transitions between software + programmed and hardware committed states. After completion and + onlining, reads from the specified range will return zero. If + this file is not present, then the device does not support the + Media Operation zero command. + + +What: /sys/bus/cxl/devices/memX/security/range_limit +Date: April, 2026 +KernelVersion: v7.2 +Contact: [email protected] +Description: + (RO) Maximum DPA range length in bytes that may be specified + for a single Media Operation (sanitize or zero). Userspace + must break larger operations into chunks no larger than this + limit. If this file is not present, the device does not support + Media Operations. + + What: /sys/bus/cxl/devices/memX/firmware/ Date: April, 2023 KernelVersion: v6.5
drivers/cxl/core/mbox.c +240 -0
258 lines not on this page · raw message
drivers/cxl/core/memdev.c +65 -1
100 lines not on this page · raw message
drivers/cxl/cxlmem.h +67 -0
97 lines not on this page · raw message
drivers/cxl/pci.c +4 -0
@@ -878,6 +878,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)dev_dbg (&pdev->dev,"No CXL Features discovered\n" ); + rc =cxl_media_op_discover (mds); +if (rc) +dev_dbg (&pdev->dev,"No Media Operation discovered\n" ); + cxlmd =devm_cxl_add_memdev (cxlds,NULL );if (IS_ERR (cxlmd))return PTR_ERR (cxlmd);
Signature · 1 line
2.39.5
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Davidlohr,
kernel test robot noticed the following build errors:
[auto build test ERROR on cxl/next]
[also build test ERROR on linus/master v7.1-rc1 next-20260430] [cannot apply to cxl/pending]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Davidlohr-Bueso/cxl-mbox-Support-Media-Operation/20260429-230352 base: https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git next patch link: https://lore.kernel.org/r/20260428000220.587249-1-dave%40stgolabs.net patch subject: [PATCH] cxl/mbox: Support Media Operation config: i386-randconfig-016-20260321 (https://download.01.org/0day-ci/archive/20260501/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260501/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
ld: drivers/cxl/core/mbox.o: in function `cxl_media_op_discover':
>> drivers/cxl/core/mbox.c:973:(.text+0x2718): undefined reference to `__umoddi3'
vim +973 drivers/cxl/core/mbox.c
901
902 /**
903 * cxl_media_op_discover() - Discover supported media operation
904 * @mds: The device data for the operation
905 *
906 * Discover any available Media Operations.
907 *
908 * Return: 0 on success or if Media Operation is not supported,
909 * negative error code on failure.
910 */
911 int cxl_media_op_discover(struct cxl_memdev_state *mds)
912 {
913 int rc, i;
914 u16 num_returned;
915 u64 granularity;
916 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
917 struct cxl_mbox_media_op_discovery_out *disc_out __free(kfree) = NULL;
918 struct cxl_mbox_media_op_discovery_in *disc_in __free(kfree) = NULL;
919
920 if (!test_bit(CXL_SEC_ENABLED_MEDIA_OPERATIONS,
921 mds->security.enabled_cmds))
922 return 0;
923
924 disc_in = kzalloc_obj(*disc_in);
925 if (!disc_in)
926 return -ENOMEM;
927
928 disc_in->class = CXL_MEDIA_OP_CLASS_GENERAL;
929 disc_in->subclass = CXL_MEDIA_OP_GENERAL_DISCOVERY;
930 disc_in->dpa_range_count = 0;
931 disc_in->start_index = 0;
932 disc_in->num_ops = cpu_to_le16(CXL_MEDIA_OP_MAX_OPS);
933
934 disc_out = kzalloc_flex(*disc_out, ops, CXL_MEDIA_OP_MAX_OPS);
935 if (!disc_out)
936 return -ENOMEM;
937
938 struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd) {
939 .opcode = CXL_MBOX_OP_MEDIA_OPERATION,
940 .payload_in = disc_in,
941 .size_in = sizeof(*disc_in),
942 .payload_out = disc_out,
943 .size_out = struct_size(disc_out, ops, CXL_MEDIA_OP_MAX_OPS),
944 .min_out = sizeof(*disc_out),
945 .poll_count = 1,
946 .poll_interval_ms = 1000,
947 };
948
949 rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
950 if (rc < 0) {
951 dev_dbg(cxl_mbox->host,
952 "Media Operation Discovery failed: %d\n", rc);
953 return rc;
954 }
955
956 num_returned = le16_to_cpu(disc_out->num_returned);
957 if (num_returned > CXL_MEDIA_OP_MAX_OPS) {
958 dev_dbg(cxl_mbox->host,
959 "Discovery returned %u ops, expected max %u\n",
960 num_returned, CXL_MEDIA_OP_MAX_OPS);
961 return -EINVAL;
962 }
963
964 granularity = le64_to_cpu(disc_out->granularity);
965 /* spec requires granularity to be a power of 2 and a multiple of 0x40 */
966 if (!is_power_of_2(granularity) || !IS_ALIGNED(granularity, SZ_64)) {
967 dev_dbg(cxl_mbox->host,
968 "Discovery returned invalid granularity: %llu\n",
969 granularity);
970 return -EINVAL;
971 }
972 mds->media_op.granularity = granularity;
> 973 mds->media_op.range_limit = rounddown(SZ_1G, granularity);
974
975 for (i = 0; i < num_returned; i++) {
976 u8 cls = disc_out->ops[i].class;
977 u8 sub = disc_out->ops[i].subclass;
978
979 if (cls == CXL_MEDIA_OP_CLASS_SANITIZE &&
980 sub == CXL_MEDIA_OP_SANITIZE_SANITIZE)
981 mds->media_op.sanitize_supported = true;
982 if (cls == CXL_MEDIA_OP_CLASS_SANITIZE &&
983 sub == CXL_MEDIA_OP_SANITIZE_ZERO)
984 mds->media_op.zero_supported = true;
985 }
986
987 dev_dbg(cxl_mbox->host,
988 "Media Operation: granularity=%llu sanitize=%d zero=%d\n",
989 mds->media_op.granularity,
990 mds->media_op.sanitize_supported,
991 mds->media_op.zero_supported);
992
993 return 0;
994 }
995 EXPORT_SYMBOL_NS_GPL(cxl_media_op_discover, "CXL");
996
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki