Skip to contentSkip to conversation

DCD: Remove support for sparse regions & add tags

RFC PATCH Superseded Anisa Su 5 participants 30 messages Apr 11 – Apr 23

Subsystems (2)

v1 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Anisa Su

author
#0 lore raw

cover DCD: Remove support for sparse regions & add tags

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

This patchset was tested with Ali's QEMU patchset adding tag support:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Details:

Topology: '-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=12G \
     -object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1G \
     -device usb-ehci,id=ehci \
     -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
     -device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
     -device cxl-type3,bus=cxl_rp_port0,id=cxl-dcd0,dc-regions-total-size=12G,num-dc-regions=1,sn=99 \
     -device usb-cxl-mctp,bus=ehci.0,id=usb1,target=cxl-dcd0\
     -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=12G,cxl-fmw.0.interleave-granularity=1k'

1. Start VM (12GB)
2. Issue QMP to add tagged backend (8GB):
{ "execute": "qmp_capabilities" }

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 8589934592,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
3. Create region on the VM: cxl create-region -m -d decoder0.0 -w 1 -s 8G mem0 -t dynamic_ram_a
4. Issue QMP to add an 8GB extent:
{ "execute": "qmp_capabilities" }
{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-dcd0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 8589934592
            }
        ]
    }
}
5. Verify with sysfs:
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/offset
0x0
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/length
0x200000000
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/uuid
5be13bce-ae34-4a77-b6c3-16df975fcf1a

6. daxctl create-device -r region0
[

  {
    "chardev":"dax0.1",
    "size":8589934592,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"

}
]
created 1 device

Currently, QEMU only supports sending 1 extent in an add/release request, which limits what I can test. However, I was able to verify that once extent(s) have been added to a region, it can't be added to again (size cannot be increased).

Up to this point is what I test with this patchset. Then below is the additional famfs tests for the version applied on famfs.
================================================================================
7. Install famfs userspace tool:
https://github.com/cxl-micron-reskit/famfs

8.mkfs.famfs --v /dev/dax0.1 output:
devsize: 8589934592
Famfs Superblock:

  Filesystem UUID:   c33b4525-a2c7-4d64-9204-e8ed273b4ffb
  Device UUID:       ae887e6b-f886-45f9-bc55-f0696f3cd91d
  System UUID:       da314140-12e7-45c2-98b2-753d3bfe4f46

role of this node: Owner
alloc_unit: 0x200000
OMF major version: 2
OMF minor version: 1
sizeof superblock: 200
log size (bytes): 8388608
primary: /dev/dax0.1 8589934592

Log stats:

  # of log entries in use: 0 of 15420
  Log size in use:          48
  Log size (total bytes)    8388608
  No allocation errors found

Capacity:

  Device capacity:        8.00G
  Bitmap capacity:        8.00G
  Sum of file sizes:      0.00G
  Allocated space:        0.01G
  Free space:             7.99G

Space amplification: inf
Percent used: 0.1%

Famfs log:
0 of 15420 entries used
0 bad log entries detected
0 files
0 directories

9. famfs smoke tests also succeed. The smoke tests include some fio tests, which run some simulated workloads

:== Test Timing Summary :==-------------------------------------------------------------------

:==  prepare              0:10
:==  test0                0:07
:==  test_shadow_yaml     0:04
:==  test1                0:22
:==  test2                0:12
:==  test3                0:03
:==  test4                0:10
:==  test_errors          0:01
:==  stripe_test          0:58
:==  test_pcq             1:26
:==  test_fio             0:34

:==-------------------------------------------------------------------
:== TOTAL 4:27
:==------------------------------------------------------------------- :==run_smoke completed successfully (Thu Apr 9 10:33:28 PM UTC 2026)

Anisa Su (1):
dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

Ira Weiny (19):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/cdat: Gather DSMAS data for DCD partitions cxl/core: Enforce partition order/simplify partition calls cxl/mem: Expose dynamic ram A partition in sysfs cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode cxl/region: Add sparse DAX region support
cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/mem: Configure dynamic capacity interrupts cxl/core: Return endpoint decoder information from region search cxl/extent: Process dynamic partition events and realize region
extents
cxl/region/extent: Expose region extent information in sysfs dax/bus: Factor out dev dax resize logic
dax/region: Create resources on DAX regions cxl/region: Read existing extents on region creation cxl/mem: Trace Dynamic capacity Event Record tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

 Documentation/ABI/testing/sysfs-bus-cxl |  100 ++-
 drivers/cxl/core/Makefile               |    2 +-
 drivers/cxl/core/cdat.c                 |   11 +
 drivers/cxl/core/core.h                 |   47 +-
 drivers/cxl/core/extent.c               |  471 +++++++++++
 drivers/cxl/core/hdm.c                  |   13 +-
 drivers/cxl/core/mbox.c                 |  770 ++++++++++++++++-
 drivers/cxl/core/memdev.c               |   87 +-
 drivers/cxl/core/port.c                 |    5 +
 drivers/cxl/core/region.c               |   43 +-
 drivers/cxl/core/region_dax.c           |    6 +
 drivers/cxl/core/trace.h                |   65 ++
 drivers/cxl/cxl.h                       |   60 +-
 drivers/cxl/cxlmem.h                    |  124 ++-
 drivers/cxl/mem.c                       |    2 +-
 drivers/cxl/pci.c                       |  115 ++-
 drivers/dax/bus.c                       |  360 ++++++--
 drivers/dax/bus.h                       |    4 +-
 drivers/dax/cxl.c                       |   71 +-
 drivers/dax/dax-private.h               |   40 +
 drivers/dax/hmem/hmem.c                 |    2 +-
 drivers/dax/pmem.c                      |    2 +-
 include/cxl/cxl.h                       |    6 +
 include/cxl/event.h                     |   39 +
 include/linux/ioport.h                  |    3 +
 tools/testing/cxl/Kbuild                |    5 +-
 tools/testing/cxl/test/mem.c            | 1018 ++++++++++++++++++++---
 27 files changed, 3210 insertions(+), 261 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/20 cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)

From: Ira Weiny <[email protected]>

Per the CXL 3.1 specification software must check the Command Effects Log (CEL) for dynamic capacity command support.

Detect support for the DCD commands while reading the CEL, including:

Get DC Config
Get DC Extent List
Add DC Response
Release DC

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/core/mbox.c | 43 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 15 ++++++++++++++
 2 files changed, 58 insertions(+)
drivers/cxl/core/mbox.c +43 -0
index aaa5c6277ebf..7ef5708bf210 100644
@@ -165,6 +165,42 @@ static void cxl_set_security_cmd_enabled(struct cxl_security_state *security,
 	}
 }
 
+static bool cxl_is_dcd_command(u16 opcode)
+{
+#define CXL_MBOX_OP_DCD_CMDS 0x48
+
+	return (opcode >> 8) == CXL_MBOX_OP_DCD_CMDS;
+}
+
+static void cxl_set_dcd_cmd_enabled(struct cxl_memdev_state *mds, u16 opcode,
+				    unsigned long *cmd_mask)
+{
+	switch (opcode) {
+	case CXL_MBOX_OP_GET_DC_CONFIG:
+		set_bit(CXL_DCD_ENABLED_GET_CONFIG, cmd_mask);
+		break;
+	case CXL_MBOX_OP_GET_DC_EXTENT_LIST:
+		set_bit(CXL_DCD_ENABLED_GET_EXTENT_LIST, cmd_mask);
+		break;
+	case CXL_MBOX_OP_ADD_DC_RESPONSE:
+		set_bit(CXL_DCD_ENABLED_ADD_RESPONSE, cmd_mask);
+		break;
+	case CXL_MBOX_OP_RELEASE_DC:
+		set_bit(CXL_DCD_ENABLED_RELEASE, cmd_mask);
+		break;
+	default:
+		break;
+	}
+}
+
+static bool cxl_verify_dcd_cmds(struct cxl_memdev_state *mds, unsigned long *cmds_seen)
+{
+	DECLARE_BITMAP(all_cmds, CXL_DCD_ENABLED_MAX);
+
+	bitmap_fill(all_cmds, CXL_DCD_ENABLED_MAX);
+	return bitmap_equal(cmds_seen, all_cmds, CXL_DCD_ENABLED_MAX);
+}
+
 static bool cxl_is_poison_command(u16 opcode)
 {
 #define CXL_MBOX_OP_POISON_CMDS 0x43
@@ -757,6 +793,7 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
 	struct cxl_cel_entry *cel_entry;
 	const int cel_entries = size / sizeof(*cel_entry);
+	DECLARE_BITMAP(dcd_cmds, CXL_DCD_ENABLED_MAX);
 	struct device *dev = mds->cxlds.dev;
 	int i, ro_cmds = 0, wr_cmds = 0;
 
@@ -785,11 +822,17 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)
 			enabled++;
 		}
 
+		if (cxl_is_dcd_command(opcode)) {
+			cxl_set_dcd_cmd_enabled(mds, opcode, dcd_cmds);
+			enabled++;
+		}
+
 		dev_dbg(dev, "Opcode 0x%04x %s\n", opcode,
 			enabled ? "enabled" : "unsupported by driver");
 	}
 
 	set_features_cap(cxl_mbox, ro_cmds, wr_cmds);
+	mds->dcd_supported = cxl_verify_dcd_cmds(mds, dcd_cmds);
 }
 
 static struct cxl_mbox_get_supported_logs *cxl_get_gsl(struct cxl_memdev_state *mds)
drivers/cxl/cxlmem.h +15 -0
index 776c50d1db51..53444af448d7 100644
@@ -230,6 +230,15 @@ struct cxl_event_state {
 	struct mutex log_lock;
 };
 
+/* Device enabled DCD commands */
+enum dcd_cmd_enabled_bits {
+	CXL_DCD_ENABLED_GET_CONFIG,
+	CXL_DCD_ENABLED_GET_EXTENT_LIST,
+	CXL_DCD_ENABLED_ADD_RESPONSE,
+	CXL_DCD_ENABLED_RELEASE,
+	CXL_DCD_ENABLED_MAX
+};
+
 /* Device enabled poison commands */
 enum poison_cmd_enabled_bits {
 	CXL_POISON_ENABLED_LIST,
@@ -405,6 +414,7 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)
  * @partition_align_bytes: alignment size for partition-able capacity
  * @active_volatile_bytes: sum of hard + soft volatile
  * @active_persistent_bytes: sum of hard + soft persistent
+ * @dcd_supported: all DCD commands are supported
  * @event: event log driver state
  * @poison: poison driver state info
  * @security: security driver state info
@@ -424,6 +434,7 @@ struct cxl_memdev_state {
 	u64 partition_align_bytes;
 	u64 active_volatile_bytes;
 	u64 active_persistent_bytes;
+	bool dcd_supported;
 
 	struct cxl_event_state event;
 	struct cxl_poison_state poison;
@@ -485,6 +496,10 @@ enum cxl_opcode {
 	CXL_MBOX_OP_UNLOCK		= 0x4503,
 	CXL_MBOX_OP_FREEZE_SECURITY	= 0x4504,
 	CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE	= 0x4505,
+	CXL_MBOX_OP_GET_DC_CONFIG	= 0x4800,
+	CXL_MBOX_OP_GET_DC_EXTENT_LIST	= 0x4801,
+	CXL_MBOX_OP_ADD_DC_RESPONSE	= 0x4802,
+	CXL_MBOX_OP_RELEASE_DC		= 0x4803,
 	CXL_MBOX_OP_MAX			= 0x10000
 };
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/20 cxl/mem: Read dynamic capacity configuration from the device

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Devices which optionally support Dynamic Capacity (DC) are configured via mailbox commands. CXL 3.2 section 9.13.3 requires the host to issue the Get DC Configuration command in order to properly configure DCDs. Without the Get DC Configuration command DCD can't be supported.

Implement the DC mailbox commands as specified in CXL 3.2 section 8.2.10.9.9 (opcodes 48XXh) to read and store the DCD configuration information. Disable DCD if an invalid configuration is found.

Linux has no support for more than one dynamic capacity partition. Read and validate all the partitions but configure only the first partition as 'dynamic ram A'. Additional partitions can be added in the future if such a device ever materializes. Additionally is it anticipated that no skips will be present from the end of the pmem partition. Check for an disallow this configuration as well.

Linux has no use for the trailing fields of the Get Dynamic Capacity Configuration Output Payload (Total number of supported extents, number of available extents, total number of supported tags, and number of available tags). Avoid defining those fields to use the more useful dynamic C array.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/core/hdm.c  |   2 +
 drivers/cxl/core/mbox.c | 182 ++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    |  45 ++++++++++
 drivers/cxl/pci.c       |   3 +
 include/cxl/cxl.h       |   2 +
 5 files changed, 234 insertions(+)
drivers/cxl/core/hdm.c +2 -0
index 3930e130d6b6..28974adaab75 100644
@@ -453,6 +453,8 @@ static const char *cxl_mode_name(enum cxl_partition_mode mode)
 		return "ram";
 	case CXL_PARTMODE_PMEM:
 		return "pmem";
+	case CXL_PARTMODE_DYNAMIC_RAM_A:
+		return "dynamic_ram_a";
 	default:
 		return "";
 	};
drivers/cxl/core/mbox.c +182 -0

194 lines not on this page · raw message

drivers/cxl/cxlmem.h +45 -0

68 lines not on this page · raw message

drivers/cxl/pci.c +3 -0
index bace662dc988..60f9fa05d9ef 100644
@@ -870,6 +870,9 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (rc)
 		return rc;
 
+	if (cxl_dcd_supported(mds))
+		cxl_configure_dcd(mds, &range_info);
+
 	rc = cxl_dpa_setup(cxlds, &range_info);
 	if (rc)
 		return rc;
include/cxl/cxl.h +2 -0
index fa7269154620..0d3f144016f2 100644
@@ -133,6 +133,7 @@ struct cxl_dpa_perf {
 enum cxl_partition_mode {
 	CXL_PARTMODE_RAM,
 	CXL_PARTMODE_PMEM,
+	CXL_PARTMODE_DYNAMIC_RAM_A
 };
 
 /**
@@ -148,6 +149,7 @@ struct cxl_dpa_partition {
 };
 
 #define CXL_NR_PARTITIONS_MAX 2
+#define CXL_MAX_DC_PARTITIONS 8
 
 /**
  * struct cxl_dev_state - The driver device state
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 3/20 cxl/cdat: Gather DSMAS data for DCD partitions

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Additional DCD partition (AKA region) information is contained in the DSMAS CDAT tables, including performance, read only, and shareable attributes.

Match DCD partitions with DSMAS tables and store the meta data.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/core/cdat.c | 11 +++++++++++
 drivers/cxl/core/mbox.c |  7 +++++++
 drivers/cxl/cxlmem.h    |  2 ++
 include/cxl/cxl.h       |  4 ++++
 4 files changed, 24 insertions(+)
drivers/cxl/core/cdat.c +11 -0
index 5c9f07262513..c5f3d2ebea55 100644
@@ -17,6 +17,7 @@ struct dsmas_entry {
 	struct access_coordinate cdat_coord[ACCESS_COORDINATE_MAX];
 	int entries;
 	int qos_class;
+	bool shareable;
 };
 
 static u32 cdat_normalize(u16 entry, u64 base, u8 type)
@@ -74,6 +75,7 @@ static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg,
 		return -ENOMEM;
 
 	dent->handle = dsmas->dsmad_handle;
+	dent->shareable = dsmas->flags & ACPI_CDAT_DSMAS_SHAREABLE;
 	dent->dpa_range.start = le64_to_cpu((__force __le64)dsmas->dpa_base_address);
 	dent->dpa_range.end = le64_to_cpu((__force __le64)dsmas->dpa_base_address) +
 			      le64_to_cpu((__force __le64)dsmas->dpa_length) - 1;
@@ -244,6 +246,7 @@ static void update_perf_entry(struct device *dev, struct dsmas_entry *dent,
 		dpa_perf->coord[i] = dent->coord[i];
 		dpa_perf->cdat_coord[i] = dent->cdat_coord[i];
 	}
+	dpa_perf->shareable = dent->shareable;
 	dpa_perf->dpa_range = dent->dpa_range;
 	dpa_perf->qos_class = dent->qos_class;
 	dev_dbg(dev,
@@ -266,13 +269,21 @@ static void cxl_memdev_set_qos_class(struct cxl_dev_state *cxlds,
 		bool found = false;
 
 		for (int i = 0; i < cxlds->nr_partitions; i++) {
+			enum cxl_partition_mode mode = cxlds->part[i].mode;
 			struct resource *res = &cxlds->part[i].res;
+			u8 handle = cxlds->part[i].handle;
 			struct range range = {
 				.start = res->start,
 				.end = res->end,
 			};
 
 			if (range_contains(&range, &dent->dpa_range)) {
+				if (mode == CXL_PARTMODE_DYNAMIC_RAM_A &&
+				    dent->handle != handle)
+					dev_warn(dev,
+						"Dynamic RAM perf mismatch; %pra (%u) vs %pra (%u)\n",
+						&range, handle, &dent->dpa_range, dent->handle);
+
 				update_perf_entry(dev, dent,
 						  &cxlds->part[i].perf);
 				found = true;
drivers/cxl/core/mbox.c +7 -0
index 71b29cd6abfe..f9a5e21f5d09 100644
@@ -1356,10 +1356,16 @@ static int cxl_dc_check(struct device *dev, struct cxl_dc_partition_info *part_a
 {
 	size_t blk_size = le64_to_cpu(dev_part->block_size);
 	size_t len = le64_to_cpu(dev_part->length);
+	u32 handle = le32_to_cpu(dev_part->dsmad_handle);
 
 	part_array[index].start = le64_to_cpu(dev_part->base);
 	part_array[index].size = le64_to_cpu(dev_part->decode_length);
 	part_array[index].size *= CXL_CAPACITY_MULTIPLIER;
+	if (handle & ~0xFF) {
+		dev_warn(dev, "DSMAD handle 0x%x has non-zero reserved bits\n", handle);
+		return -EINVAL;
+	}
+	part_array[index].handle = handle;
 
 	/* Check partitions are in increasing DPA order */
 	if (index > 0) {
@@ -1494,6 +1500,7 @@ int cxl_dev_dc_identify(struct cxl_mailbox *mbox,
 	/* Return 1st partition */
 	dc_info->start = partitions[0].start;
 	dc_info->size = partitions[0].size;
+	dc_info->handle = partitions[0].handle;
 	dev_dbg(dev, "Returning partition 0 %zu size %zu\n",
 		dc_info->start, dc_info->size);
 
drivers/cxl/cxlmem.h +2 -0
index 2fef6bb373b9..314d37ca9bdb 100644
@@ -118,6 +118,7 @@ struct cxl_dpa_info {
 	struct cxl_dpa_part_info {
 		struct range range;
 		enum cxl_partition_mode mode;
+		u8 handle;
 	} part[CXL_NR_PARTITIONS_MAX];
 	int nr_partitions;
 };
@@ -816,6 +817,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds);
 struct cxl_dc_partition_info {
 	size_t start;
 	size_t size;
+	u8 handle;
 };
 
 int cxl_dev_dc_identify(struct cxl_mailbox *mbox,
include/cxl/cxl.h +4 -0
index 0d3f144016f2..91964272f392 100644
@@ -122,12 +122,14 @@ struct cxl_register_map {
  * @coord: QoS performance data (i.e. latency, bandwidth)
  * @cdat_coord: raw QoS performance data from CDAT
  * @qos_class: QoS Class cookies
+ * @shareable: Is the range sharable
  */
 struct cxl_dpa_perf {
 	struct range dpa_range;
 	struct access_coordinate coord[ACCESS_COORDINATE_MAX];
 	struct access_coordinate cdat_coord[ACCESS_COORDINATE_MAX];
 	int qos_class;
+	bool shareable;
 };
 
 enum cxl_partition_mode {
@@ -141,11 +143,13 @@ enum cxl_partition_mode {
  * @res: shortcut to the partition in the DPA resource tree (cxlds->dpa_res)
  * @perf: performance attributes of the partition from CDAT
  * @mode: operation mode for the DPA capacity, e.g. ram, pmem, dynamic...
+ * @handle: DSMAS handle intended to represent this partition
  */
 struct cxl_dpa_partition {
 	struct resource res;
 	struct cxl_dpa_perf perf;
 	enum cxl_partition_mode mode;
+	u8 handle;
 };
 
 #define CXL_NR_PARTITIONS_MAX 2
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 4/20 cxl/core: Enforce partition order/simplify partition calls

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Device partitions have an implied order which is made more complex by the addition of a dynamic partition.

Remove the ram special case information calls in favor of generic calls with a check ahead of time to ensure the preservation of the implied partition order.

---
Changes::
[anisa: rebase]

---
 drivers/cxl/core/hdm.c    | 11 ++++++++++-
 drivers/cxl/core/memdev.c | 32 +++++++++-----------------------
 drivers/cxl/cxlmem.h      |  9 +++------
 drivers/cxl/mem.c         |  2 +-
 4 files changed, 23 insertions(+), 31 deletions(-)
drivers/cxl/core/hdm.c +10 -1
index 28974adaab75..7a5812971f8f 100644
@@ -464,6 +464,7 @@ static const char *cxl_mode_name(enum cxl_partition_mode mode)
 int cxl_dpa_setup(struct cxl_dev_state *cxlds, const struct cxl_dpa_info *info)
 {
 	struct device *dev = cxlds->dev;
+	int i;
 
 	guard(rwsem_write)(&cxl_rwsem.dpa);
 
@@ -476,9 +477,17 @@ int cxl_dpa_setup(struct cxl_dev_state *cxlds, const struct cxl_dpa_info *info)
 		return 0;
 	}
 
+	/* Verify partitions are in expected order. */
+	for (i = 1; i < info->nr_partitions; i++) {
+		if (cxlds->part[i].mode < cxlds->part[i-1].mode) {
+			dev_err(dev, "Partition order mismatch\n");
+			return -EINVAL;
+		}
+	}
+
 	cxlds->dpa_res = DEFINE_RES_MEM(0, info->size);
 
-	for (int i = 0; i < info->nr_partitions; i++) {
+	for (i = 0; i < info->nr_partitions; i++) {
 		const struct cxl_dpa_part_info *part = &info->part[i];
 		int rc;
 
drivers/cxl/core/memdev.c +9 -23
index 80e65690eb77..71602820f896 100644
@@ -75,20 +75,12 @@ static ssize_t label_storage_size_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(label_storage_size);
 
-static resource_size_t cxl_ram_size(struct cxl_dev_state *cxlds)
-{
-	/* Static RAM is only expected at partition 0. */
-	if (cxlds->part[0].mode != CXL_PARTMODE_RAM)
-		return 0;
-	return resource_size(&cxlds->part[0].res);
-}
-
 static ssize_t ram_size_show(struct device *dev, struct device_attribute *attr,
 			     char *buf)
 {
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
-	unsigned long long len = cxl_ram_size(cxlds);
+	unsigned long long len = cxl_part_size(cxlds, CXL_PARTMODE_RAM);
 
 	return sysfs_emit(buf, "%#llx\n", len);
 }
@@ -101,7 +93,7 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,
 {
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
-	unsigned long long len = cxl_pmem_size(cxlds);
+	unsigned long long len = cxl_part_size(cxlds, CXL_PARTMODE_PMEM);
 
 	return sysfs_emit(buf, "%#llx\n", len);
 }
@@ -424,10 +416,11 @@ static struct attribute *cxl_memdev_attributes[] = {
 	NULL,
 };
 
-static struct cxl_dpa_perf *to_pmem_perf(struct cxl_dev_state *cxlds)
+static struct cxl_dpa_perf *part_perf(struct cxl_dev_state *cxlds,
+				      enum cxl_partition_mode mode)
 {
 	for (int i = 0; i < cxlds->nr_partitions; i++)
-		if (cxlds->part[i].mode == CXL_PARTMODE_PMEM)
+		if (cxlds->part[i].mode == mode)
 			return &cxlds->part[i].perf;
 	return NULL;
 }
@@ -438,7 +431,7 @@ static ssize_t pmem_qos_class_show(struct device *dev,
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
 
-	return sysfs_emit(buf, "%d\n", to_pmem_perf(cxlds)->qos_class);
+	return sysfs_emit(buf, "%d\n", part_perf(cxlds, CXL_PARTMODE_PMEM)->qos_class);
 }
 
 static struct device_attribute dev_attr_pmem_qos_class =
@@ -450,20 +443,13 @@ static struct attribute *cxl_memdev_pmem_attributes[] = {
 	NULL,
 };
 
-static struct cxl_dpa_perf *to_ram_perf(struct cxl_dev_state *cxlds)
-{
-	if (cxlds->part[0].mode != CXL_PARTMODE_RAM)
-		return NULL;
-	return &cxlds->part[0].perf;
-}
-
 static ssize_t ram_qos_class_show(struct device *dev,
 				  struct device_attribute *attr, char *buf)
 {
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
 
-	return sysfs_emit(buf, "%d\n", to_ram_perf(cxlds)->qos_class);
+	return sysfs_emit(buf, "%d\n", part_perf(cxlds, CXL_PARTMODE_RAM)->qos_class);
 }
 
 static struct device_attribute dev_attr_ram_qos_class =
@@ -499,7 +485,7 @@ static umode_t cxl_ram_visible(struct kobject *kobj, struct attribute *a, int n)
 {
 	struct device *dev = kobj_to_dev(kobj);
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
-	struct cxl_dpa_perf *perf = to_ram_perf(cxlmd->cxlds);
+	struct cxl_dpa_perf *perf = part_perf(cxlmd->cxlds, CXL_PARTMODE_RAM);
 
 	if (a == &dev_attr_ram_qos_class.attr &&
 	    (!perf || perf->qos_class == CXL_QOS_CLASS_INVALID))
@@ -518,7 +504,7 @@ static umode_t cxl_pmem_visible(struct kobject *kobj, struct attribute *a, int n
 {
 	struct device *dev = kobj_to_dev(kobj);
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
-	struct cxl_dpa_perf *perf = to_pmem_perf(cxlmd->cxlds);
+	struct cxl_dpa_perf *perf = part_perf(cxlmd->cxlds, CXL_PARTMODE_PMEM);
 
 	if (a == &dev_attr_pmem_qos_class.attr &&
 	    (!perf || perf->qos_class == CXL_QOS_CLASS_INVALID))
drivers/cxl/cxlmem.h +3 -6
index 314d37ca9bdb..a933b6f5454f 100644
@@ -381,14 +381,11 @@ struct cxl_security_state {
 	struct kernfs_node *sanitize_node;
 };
 
-static inline resource_size_t cxl_pmem_size(struct cxl_dev_state *cxlds)
+static inline resource_size_t cxl_part_size(struct cxl_dev_state *cxlds,
+					    enum cxl_partition_mode mode)
 {
-	/*
-	 * Static PMEM may be at partition index 0 when there is no static RAM
-	 * capacity.
-	 */
 	for (int i = 0; i < cxlds->nr_partitions; i++)
-		if (cxlds->part[i].mode == CXL_PARTMODE_PMEM)
+		if (cxlds->part[i].mode == mode)
 			return resource_size(&cxlds->part[i].res);
 	return 0;
 }
drivers/cxl/mem.c +1 -1
index fcffe24dcb42..f19e08279ec7 100644
@@ -114,7 +114,7 @@ static int cxl_mem_probe(struct device *dev)
 		return -ENXIO;
 	}
 
-	if (cxl_pmem_size(cxlds) && IS_ENABLED(CONFIG_CXL_PMEM)) {
+	if (cxl_part_size(cxlds, CXL_PARTMODE_PMEM) && IS_ENABLED(CONFIG_CXL_PMEM)) {
 		rc = devm_cxl_add_nvdimm(dev, parent_port, cxlmd);
 		if (rc) {
 			if (rc == -ENODEV)
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 5/20 cxl/mem: Expose dynamic ram A partition in sysfs

In reply to Anisa Su

From: Ira Weiny <[email protected]>

To properly configure CXL regions user space will need to know the details of the dynamic ram partition.

Expose the first dynamic ram partition through sysfs.

---
Changes:
[anisa: Update kernel version to 7.0] [davidlohr: Remove "persistent" from description of /sys/bus/cxl/devices/memX/dynamic_ram_a/qos_class]

---
 Documentation/ABI/testing/sysfs-bus-cxl | 24 +++++++++++
 drivers/cxl/core/memdev.c               | 57 +++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +24 -0
index 16a9b3d2e2c0..3d95c325f6e0 100644
@@ -89,6 +89,30 @@ Description:
 		and there are platform specific performance related
 		side-effects that may result. First class-id is displayed.
 
+What:		/sys/bus/cxl/devices/memX/dynamic_ram_a/size
+Date:		May, 2025
+KernelVersion:	v7.0
+Contact:	[email protected]
+Description:
+		(RO) The first Dynamic RAM partition capacity as bytes.
+
+
+What:		/sys/bus/cxl/devices/memX/dynamic_ram_a/qos_class
+Date:		May, 2025
+KernelVersion:	v7.0
+Contact:	[email protected]
+Description:
+		(RO) For CXL host platforms that support "QoS Telemmetry"
+		this attribute conveys a comma delimited list of platform
+		specific cookies that identifies a QoS performance class
+		for the partition of the CXL mem device. These
+		class-ids can be compared against a similar "qos_class"
+		published for a root decoder. While it is not required
+		that the endpoints map their local memory-class to a
+		matching platform class, mismatches are not recommended
+		and there are platform specific performance related
+		side-effects that may result. First class-id is displayed.
+
 
 What:		/sys/bus/cxl/devices/memX/serial
 Date:		January, 2022
drivers/cxl/core/memdev.c +57 -0

87 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#6 lore raw

PATCH 6/20 cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Endpoints can now support a single dynamic ram partition following the persistent memory partition.

Expand the mode to allow a decoder to point to the first dynamic ram partition.

---
Changes:
[anisa: rebase]

---
 Documentation/ABI/testing/sysfs-bus-cxl | 18 +++++++++---------
 drivers/cxl/core/port.c                 |  4 ++++
 2 files changed, 13 insertions(+), 9 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +9 -9
index 3d95c325f6e0..c604c7ca6432 100644
@@ -358,22 +358,22 @@ Description:
 
 
 What:		/sys/bus/cxl/devices/decoderX.Y/mode
-Date:		May, 2022
-KernelVersion:	v6.0
+Date:		May, 2022, May 2025
+KernelVersion:	v6.0, v6.16 (dynamic_ram_a)
 Contact:	[email protected]
 Description:
 		(RW) When a CXL decoder is of devtype "cxl_decoder_endpoint" it
 		translates from a host physical address range, to a device
 		local address range. Device-local address ranges are further
-		split into a 'ram' (volatile memory) range and 'pmem'
-		(persistent memory) range. The 'mode' attribute emits one of
-		'ram', 'pmem', or 'none'. The 'none' indicates the decoder is
-		not actively decoding, or no DPA allocation policy has been
-		set.
+		split into a 'ram' (volatile memory) range, 'pmem' (persistent
+		memory), and 'dynamic_ram_a' (first Dynamic RAM) range. The
+		'mode' attribute emits one of 'ram', 'pmem', 'dynamic_ram_a' or
+		'none'. The 'none' indicates the decoder is not actively
+		decoding, or no DPA allocation policy has been set.
 
 		'mode' can be written, when the decoder is in the 'disabled'
-		state, with either 'ram' or 'pmem' to set the boundaries for the
-		next allocation.
+		state, with either 'ram', 'pmem', or 'dynamic_ram_a' to set the
+		boundaries for the next allocation.
 
 
 What:		/sys/bus/cxl/devices/decoderX.Y/dpa_resource
drivers/cxl/core/port.c +4 -0
index 0c5957d1d329..a7f71f36531f 100644
@@ -128,6 +128,7 @@ static DEVICE_ATTR_RO(name)
 
 CXL_DECODER_FLAG_ATTR(cap_pmem, CXL_DECODER_F_PMEM);
 CXL_DECODER_FLAG_ATTR(cap_ram, CXL_DECODER_F_RAM);
+CXL_DECODER_FLAG_ATTR(cap_dynamic_ram_a, CXL_DECODER_F_RAM);
 CXL_DECODER_FLAG_ATTR(cap_type2, CXL_DECODER_F_TYPE2);
 CXL_DECODER_FLAG_ATTR(cap_type3, CXL_DECODER_F_TYPE3);
 CXL_DECODER_FLAG_ATTR(locked, CXL_DECODER_F_LOCK);
@@ -222,6 +223,8 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr,
 		mode = CXL_PARTMODE_PMEM;
 	else if (sysfs_streq(buf, "ram"))
 		mode = CXL_PARTMODE_RAM;
+	else if (sysfs_streq(buf, "dynamic_ram_a"))
+		mode = CXL_PARTMODE_DYNAMIC_RAM_A;
 	else
 		return -EINVAL;
 
@@ -327,6 +330,7 @@ static struct attribute_group cxl_decoder_base_attribute_group = {
 static struct attribute *cxl_decoder_root_attrs[] = {
 	&dev_attr_cap_pmem.attr,
 	&dev_attr_cap_ram.attr,
+	&dev_attr_cap_dynamic_ram_a.attr,
 	&dev_attr_cap_type2.attr,
 	&dev_attr_cap_type3.attr,
 	&dev_attr_target_list.attr,
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH 7/20 cxl/region: Add sparse DAX region support

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic Capacity CXL regions must allow memory to be added or removed dynamically. In addition to the quantity of memory available the location of the memory within a DC partition is dynamic based on the extents offered by a device. CXL DAX regions must accommodate the sparseness of this memory in the management of DAX regions and devices.

Introduce the concept of a sparse DAX region. Introduce create_dynamic_ram_a_region() sysfs entry to create such regions. Special case dynamic capable regions to create a 0 sized seed DAX device to maintain compatibility which requires a default DAX device to hold a region reference.

Indicate 0 byte available capacity until such time that capacity is added.

Sparse regions complicate the range mapping of dax devices. There is no known use case for range mapping on sparse regions. Avoid the complication by preventing range mapping of dax devices on sparse regions.

Interleaving is deferred for now. Add checks.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: rebase]
[fan: fix return logic when validating DCD mode in store_targetN]

---
 Documentation/ABI/testing/sysfs-bus-cxl | 22 ++++++++---------
 drivers/cxl/core/core.h                 | 11 +++++++++
 drivers/cxl/core/port.c                 |  1 +
 drivers/cxl/core/region.c               | 33 +++++++++++++++++++++++--
 drivers/dax/bus.c                       | 10 ++++++++
 drivers/dax/bus.h                       |  1 +
 drivers/dax/cxl.c                       | 16 ++++++++++--
 7 files changed, 79 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +11 -11
index c604c7ca6432..3080aef9ad67 100644
@@ -434,20 +434,20 @@ Description:
 		interleave_granularity).
 
 
-What:		/sys/bus/cxl/devices/decoderX.Y/create_{pmem,ram}_region
-Date:		May, 2022, January, 2023
-KernelVersion:	v6.0 (pmem), v6.3 (ram)
+What:		/sys/bus/cxl/devices/decoderX.Y/create_{pmem,ram,dynamic_ram_a}_region
+Date:		May, 2022, January, 2023, May 2025
+KernelVersion:	v6.0 (pmem), v6.3 (ram), v6.16 (dynamic_ram_a)
 Contact:	[email protected]
 Description:
 		(RW) Write a string in the form 'regionZ' to start the process
-		of defining a new persistent, or volatile memory region
-		(interleave-set) within the decode range bounded by root decoder
-		'decoderX.Y'. The value written must match the current value
-		returned from reading this attribute. An atomic compare exchange
-		operation is done on write to assign the requested id to a
-		region and allocate the region-id for the next creation attempt.
-		EBUSY is returned if the region name written does not match the
-		current cached value.
+		of defining a new persistent, volatile, or dynamic RAM memory
+		region (interleave-set) within the decode range bounded by root
+		decoder 'decoderX.Y'. The value written must match the current
+		value returned from reading this attribute.  An atomic compare
+		exchange operation is done on write to assign the requested id
+		to a region and allocate the region-id for the next creation
+		attempt.  EBUSY is returned if the region name written does not
+		match the current cached value.
 
 
 What:		/sys/bus/cxl/devices/decoderX.Y/delete_region
drivers/cxl/core/core.h +11 -0
index 82ca3a476708..8881cc9323e0 100644
@@ -6,6 +6,7 @@
 
 #include <cxl/mailbox.h>
 #include <linux/rwsem.h>
+#include <cxlmem.h>
 
 extern const struct device_type cxl_nvdimm_bridge_type;
 extern const struct device_type cxl_nvdimm_type;
@@ -18,6 +19,15 @@ enum cxl_detach_mode {
 	DETACH_INVALIDATE,
 };
 
+static inline struct cxl_memdev_state *
+cxled_to_mds(struct cxl_endpoint_decoder *cxled)
+{
+	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+
+	return container_of(cxlds, struct cxl_memdev_state, cxlds);
+}
+
 #ifdef CONFIG_CXL_REGION
 
 struct cxl_region_context {
@@ -29,6 +39,7 @@ struct cxl_region_context {
 
 extern struct device_attribute dev_attr_create_pmem_region;
 extern struct device_attribute dev_attr_create_ram_region;
+extern struct device_attribute dev_attr_create_dynamic_ram_a_region;
 extern struct device_attribute dev_attr_delete_region;
 extern struct device_attribute dev_attr_region;
 extern const struct device_type cxl_pmem_region_type;
drivers/cxl/core/port.c +1 -0
index a7f71f36531f..2d33001dac26 100644
@@ -337,6 +337,7 @@ static struct attribute *cxl_decoder_root_attrs[] = {
 	&dev_attr_qos_class.attr,
 	SET_CXL_REGION_ATTR(create_pmem_region)
 	SET_CXL_REGION_ATTR(create_ram_region)
+	SET_CXL_REGION_ATTR(create_dynamic_ram_a_region)
 	SET_CXL_REGION_ATTR(delete_region)
 	NULL,
 };
drivers/cxl/core/region.c +31 -2
index edc267c6cf77..d2ce844a142f 100644
@@ -533,6 +533,11 @@ static ssize_t interleave_ways_store(struct device *dev,
 	if (rc)
 		return rc;
 
+	if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A && val != 1) {
+		dev_err(dev, "Interleaving and DCD not supported\n");
+		return -EINVAL;
+	}
+
 	ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
 	if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
 		return rc;
@@ -2389,6 +2394,7 @@ static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos,
 	if (sysfs_streq(buf, "\n"))
 		rc = detach_target(cxlr, pos);
 	else {
+		struct cxl_endpoint_decoder *cxled;
 		struct device *dev;
 
 		dev = bus_find_device_by_name(&cxl_bus_type, NULL, buf);
@@ -2400,8 +2406,14 @@ static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos,
 			goto out;
 		}
 
-		rc = attach_target(cxlr, to_cxl_endpoint_decoder(dev), pos,
-				   TASK_INTERRUPTIBLE);
+		cxled = to_cxl_endpoint_decoder(dev);
+		if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A &&
+		    !cxl_dcd_supported(cxled_to_mds(cxled))) {
+			dev_dbg(dev, "DCD unsupported\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		rc = attach_target(cxlr, cxled, pos, TASK_INTERRUPTIBLE);
 out:
 		put_device(dev);
 	}
@@ -2750,6 +2762,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
 	switch (mode) {
 	case CXL_PARTMODE_RAM:
 	case CXL_PARTMODE_PMEM:
+	case CXL_PARTMODE_DYNAMIC_RAM_A:
 		break;
 	default:
 		dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %d\n", mode);
@@ -2802,6 +2815,21 @@ static ssize_t create_ram_region_store(struct device *dev,
 }
 DEVICE_ATTR_RW(create_ram_region);
 
+static ssize_t create_dynamic_ram_a_region_show(struct device *dev,
+						struct device_attribute *attr,
+						char *buf)
+{
+	return __create_region_show(to_cxl_root_decoder(dev), buf);
+}
+
+static ssize_t create_dynamic_ram_a_region_store(struct device *dev,
+						 struct device_attribute *attr,
+						 const char *buf, size_t len)
+{
+	return create_region_store(dev, buf, len, CXL_PARTMODE_DYNAMIC_RAM_A);
+}
+DEVICE_ATTR_RW(create_dynamic_ram_a_region);
+
 static ssize_t region_show(struct device *dev, struct device_attribute *attr,
 			   char *buf)
 {
@@ -4081,6 +4109,7 @@ static int cxl_region_probe(struct device *dev)
 
 		return devm_cxl_add_pmem_region(cxlr);
 	case CXL_PARTMODE_RAM:
+	case CXL_PARTMODE_DYNAMIC_RAM_A:
 		rc = devm_cxl_region_edac_register(cxlr);
 		if (rc)
 			dev_dbg(&cxlr->dev, "CXL EDAC registration for region_id=%d failed\n",
drivers/dax/bus.c +10 -0
index 68437c05e21d..e41e36747111 100644
@@ -179,6 +179,11 @@ static bool is_static(struct dax_region *dax_region)
 	return (dax_region->res.flags & IORESOURCE_DAX_STATIC) != 0;
 }
 
+static bool is_sparse(struct dax_region *dax_region)
+{
+	return (dax_region->res.flags & IORESOURCE_DAX_SPARSE_CAP) != 0;
+}
+
 bool static_dev_dax(struct dev_dax *dev_dax)
 {
 	return is_static(dev_dax->region);
@@ -302,6 +307,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)
 
 	lockdep_assert_held(&dax_region_rwsem);
 
+	if (is_sparse(dax_region))
+		return 0;
+
 	for_each_dax_region_resource(dax_region, res)
 		size -= resource_size(res);
 	return size;
@@ -1387,6 +1395,8 @@ static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n)
 		return 0;
 	if (a == &dev_attr_mapping.attr && is_static(dax_region))
 		return 0;
+	if (a == &dev_attr_mapping.attr && is_sparse(dax_region))
+		return 0;
 	if ((a == &dev_attr_align.attr ||
 	     a == &dev_attr_size.attr) && is_static(dax_region))
 		return 0444;
drivers/dax/bus.h +1 -0
index 7b1a83f1ce1f..7abdd5a403dc 100644
@@ -15,6 +15,7 @@ struct dax_region;
 /* dax bus specific ioresource flags */
 #define IORESOURCE_DAX_STATIC BIT(0)
 #define IORESOURCE_DAX_KMEM BIT(1)
+#define IORESOURCE_DAX_SPARSE_CAP BIT(2)
 
 struct dax_region *alloc_dax_region(struct device *parent, int region_id,
 		struct range *range, int target_node, unsigned int align,
drivers/dax/cxl.c +14 -2
index 3ab39b77843d..9ebe974d25c3 100644
@@ -13,19 +13,31 @@ static int cxl_dax_region_probe(struct device *dev)
 	struct cxl_region *cxlr = cxlr_dax->cxlr;
 	struct dax_region *dax_region;
 	struct dev_dax_data data;
+	resource_size_t dev_size;
+	unsigned long flags;
 
 	if (nid == NUMA_NO_NODE)
 		nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
 
+	flags = IORESOURCE_DAX_KMEM;
+	if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A)
+		flags |= IORESOURCE_DAX_SPARSE_CAP;
+
 	dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid,
-				      PMD_SIZE, IORESOURCE_DAX_KMEM);
+				      PMD_SIZE, flags);
 	if (!dax_region)
 		return -ENOMEM;
 
+	if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A)
+		/* Add empty seed dax device */
+		dev_size = 0;
+	else
+		dev_size = range_len(&cxlr_dax->hpa_range);
+
 	data = (struct dev_dax_data) {
 		.dax_region = dax_region,
 		.id = -1,
-		.size = range_len(&cxlr_dax->hpa_range),
+		.size = dev_size,
 		.memmap_on_memory = true,
 	};
 
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH 8/20 cxl/events: Split event msgnum configuration from irq setup

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic Capacity Devices (DCD) require event interrupts to process memory addition or removal. BIOS may have control over non-DCD event processing. DCD interrupt configuration needs to be separate from memory event interrupt configuration.

Split cxl_event_config_msgnums() from irq setup in preparation for separate DCD interrupts configuration.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/pci.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/cxl/pci.c +11 -11
index 60f9fa05d9ef..35942b2ace53 100644
@@ -599,35 +599,31 @@ static int cxl_event_config_msgnums(struct cxl_memdev_state *mds,
 	return cxl_event_get_int_policy(mds, policy);
 }
 
-static int cxl_event_irqsetup(struct cxl_memdev_state *mds)
+static int cxl_event_irqsetup(struct cxl_memdev_state *mds,
+			      struct cxl_event_interrupt_policy *policy)
 {
 	struct cxl_dev_state *cxlds = &mds->cxlds;
-	struct cxl_event_interrupt_policy policy;
 	int rc;
 
-	rc = cxl_event_config_msgnums(mds, &policy);
-	if (rc)
-		return rc;
-
-	rc = cxl_event_req_irq(cxlds, policy.info_settings);
+	rc = cxl_event_req_irq(cxlds, policy->info_settings);
 	if (rc) {
 		dev_err(cxlds->dev, "Failed to get interrupt for event Info log\n");
 		return rc;
 	}
 
-	rc = cxl_event_req_irq(cxlds, policy.warn_settings);
+	rc = cxl_event_req_irq(cxlds, policy->warn_settings);
 	if (rc) {
 		dev_err(cxlds->dev, "Failed to get interrupt for event Warn log\n");
 		return rc;
 	}
 
-	rc = cxl_event_req_irq(cxlds, policy.failure_settings);
+	rc = cxl_event_req_irq(cxlds, policy->failure_settings);
 	if (rc) {
 		dev_err(cxlds->dev, "Failed to get interrupt for event Failure log\n");
 		return rc;
 	}
 
-	rc = cxl_event_req_irq(cxlds, policy.fatal_settings);
+	rc = cxl_event_req_irq(cxlds, policy->fatal_settings);
 	if (rc) {
 		dev_err(cxlds->dev, "Failed to get interrupt for event Fatal log\n");
 		return rc;
@@ -674,11 +670,15 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,
 		return -EBUSY;
 	}
 
+	rc = cxl_event_config_msgnums(mds, &policy);
+	if (rc)
+		return rc;
+
 	rc = cxl_mem_alloc_event_buf(mds);
 	if (rc)
 		return rc;
 
-	rc = cxl_event_irqsetup(mds);
+	rc = cxl_event_irqsetup(mds, &policy);
 	if (rc)
 		return rc;
 
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH 9/20 cxl/pci: Factor out interrupt policy check

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic Capacity Devices (DCD) require event interrupts to process memory addition or removal. BIOS may have control over non-DCD event processing. DCD interrupt configuration needs to be separate from memory event interrupt configuration.

Factor out event interrupt setting validation.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/pci.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/cxl/pci.c +16 -7
index 35942b2ace53..8d12c684d670 100644
@@ -639,6 +639,21 @@ static bool cxl_event_int_is_fw(u8 setting)
 	return mode == CXL_INT_FW;
 }
 
+static bool cxl_event_validate_mem_policy(struct cxl_memdev_state *mds,
+					  struct cxl_event_interrupt_policy *policy)
+{
+	if (cxl_event_int_is_fw(policy->info_settings) ||
+	    cxl_event_int_is_fw(policy->warn_settings) ||
+	    cxl_event_int_is_fw(policy->failure_settings) ||
+	    cxl_event_int_is_fw(policy->fatal_settings)) {
+		dev_err(mds->cxlds.dev,
+			"FW still in control of Event Logs despite _OSC settings\n");
+		return false;
+	}
+
+	return true;
+}
+
 static int cxl_event_config(struct pci_host_bridge *host_bridge,
 			    struct cxl_memdev_state *mds, bool irq_avail)
 {
@@ -661,14 +676,8 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,
 	if (rc)
 		return rc;
 
-	if (cxl_event_int_is_fw(policy.info_settings) ||
-	    cxl_event_int_is_fw(policy.warn_settings) ||
-	    cxl_event_int_is_fw(policy.failure_settings) ||
-	    cxl_event_int_is_fw(policy.fatal_settings)) {
-		dev_err(mds->cxlds.dev,
-			"FW still in control of Event Logs despite _OSC settings\n");
+	if (!cxl_event_validate_mem_policy(mds, &policy))
 		return -EBUSY;
-	}
 
 	rc = cxl_event_config_msgnums(mds, &policy);
 	if (rc)
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH 10/20 cxl/mem: Configure dynamic capacity interrupts

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic Capacity Devices (DCD) support extent change notifications through the event log mechanism. The interrupt mailbox commands were extended in CXL 3.1 to support these notifications. Firmware can't configure DCD events to be FW controlled but can retain control of memory events.

Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.

Care is taken to preserve the interrupt policy set by the FW if FW first has been selected by the BIOS.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/cxlmem.h |  2 ++
 drivers/cxl/pci.c    | 73 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 62 insertions(+), 13 deletions(-)
drivers/cxl/cxlmem.h +2 -0
index a933b6f5454f..88bcc69f22c2 100644
@@ -218,7 +218,9 @@ struct cxl_event_interrupt_policy {
 	u8 warn_settings;
 	u8 failure_settings;
 	u8 fatal_settings;
+	u8 dcd_settings;
 } __packed;
+#define CXL_EVENT_INT_POLICY_BASE_SIZE 4 /* info, warn, failure, fatal */
 
 /**
  * struct cxl_event_state - Event log driver state
drivers/cxl/pci.c +60 -13

129 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#11 lore raw

PATCH 11/20 cxl/core: Return endpoint decoder information from region search

In reply to Anisa Su

From: Ira Weiny <[email protected]>

cxl_dpa_to_region() finds the region from a <DPA, device> tuple. The search involves finding the device endpoint decoder as well.

Dynamic capacity extent processing uses the endpoint decoder HPA information to calculate the HPA offset. In addition, well behaved extents should be contained within an endpoint decoder.

Return the endpoint decoder found to be used in subsequent DCD code.

---
Changes:
[anisa: rebase]

---
 drivers/cxl/core/core.h   | 6 ++++--
 drivers/cxl/core/mbox.c   | 2 +-
 drivers/cxl/core/memdev.c | 4 ++--
 drivers/cxl/core/region.c | 8 +++++++-
 4 files changed, 14 insertions(+), 6 deletions(-)
drivers/cxl/core/core.h +4 -2
index 8881cc9323e0..14723cfd05f0 100644
@@ -58,7 +58,8 @@ int cxl_decoder_detach(struct cxl_region *cxlr,
 int cxl_region_init(void);
 void cxl_region_exit(void);
 int cxl_get_poison_by_endpoint(struct cxl_port *port);
-struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa);
+struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,
+				     struct cxl_endpoint_decoder **cxled);
 u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
 		   u64 dpa);
 int devm_cxl_add_dax_region(struct cxl_region *cxlr);
@@ -71,7 +72,8 @@ static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,
 	return ULLONG_MAX;
 }
 static inline
-struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
+struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,
+				     struct cxl_endpoint_decoder **cxled)
 {
 	return NULL;
 }
drivers/cxl/core/mbox.c +1 -1
index f9a5e21f5d09..01b1a318f34f 100644
@@ -968,7 +968,7 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd,
 		guard(rwsem_read)(&cxl_rwsem.dpa);
 
 		dpa = le64_to_cpu(evt->media_hdr.phys_addr) & CXL_DPA_MASK;
-		cxlr = cxl_dpa_to_region(cxlmd, dpa);
+		cxlr = cxl_dpa_to_region(cxlmd, dpa, NULL);
 		if (cxlr) {
 			u64 cache_size = cxlr->params.cache_size;
 
drivers/cxl/core/memdev.c +2 -2
index 064cfd628577..b8b3489f69e5 100644
@@ -320,7 +320,7 @@ int cxl_inject_poison_locked(struct cxl_memdev *cxlmd, u64 dpa)
 	if (rc)
 		return rc;
 
-	cxlr = cxl_dpa_to_region(cxlmd, dpa);
+	cxlr = cxl_dpa_to_region(cxlmd, dpa, NULL);
 	if (cxlr)
 		dev_warn_once(cxl_mbox->host,
 			      "poison inject dpa:%#llx region: %s\n", dpa,
@@ -389,7 +389,7 @@ int cxl_clear_poison_locked(struct cxl_memdev *cxlmd, u64 dpa)
 	if (rc)
 		return rc;
 
-	cxlr = cxl_dpa_to_region(cxlmd, dpa);
+	cxlr = cxl_dpa_to_region(cxlmd, dpa, NULL);
 	if (cxlr)
 		dev_warn_once(cxl_mbox->host,
 			      "poison clear dpa:%#llx region: %s\n", dpa,
drivers/cxl/core/region.c +7 -1
index d2ce844a142f..e00fdb74589c 100644
@@ -2991,6 +2991,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port)
 struct cxl_dpa_to_region_context {
 	struct cxl_region *cxlr;
 	u64 dpa;
+	struct cxl_endpoint_decoder *cxled;
 };
 
 static int __cxl_dpa_to_region(struct device *dev, void *arg)
@@ -3024,11 +3025,13 @@ static int __cxl_dpa_to_region(struct device *dev, void *arg)
 			dev_name(dev));
 
 	ctx->cxlr = cxlr;
+	ctx->cxled = cxled;
 
 	return 1;
 }
 
-struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
+struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,
+				     struct cxl_endpoint_decoder **cxled)
 {
 	struct cxl_dpa_to_region_context ctx;
 	struct cxl_port *port = cxlmd->endpoint;
@@ -3042,6 +3045,9 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
 	if (cxl_num_decoders_committed(port))
 		device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
 
+	if (cxled)
+		*cxled = ctx.cxled;
+
 	return ctx.cxlr;
 }
 
Signature · 1 line
2.43.0
author
#12 lore raw

PATCH 12/20 cxl/extent: Process dynamic partition events and realize region extents

In reply to Anisa Su

From: Ira Weiny <[email protected]>

A dynamic capacity device (DCD) sends events to signal the host for changes in the availability of Dynamic Capacity (DC) memory. These events contain extents describing a DPA range and meta data for memory to be added or removed. Events may be sent from the device at any time.

Three types of events can be signaled, Add, Release, and Force Release.

On add, the host may accept or reject the memory being offered. If no region exists or the extent DPA range is invalid, the extent is rejected. Additionally, the implementation choice to reject extents without a tag or form a non-contiguous range has been made (not stated in the spec).

Add extent events may be grouped by a 'more' bit which indicates those extents should be processed as a group. Use the first extent with a valid DPA range, region, and non-null tag to check subsequent extents against for contiguity and that it has the same tag.

On remove, the host can delay the response until the host is safely not using the memory. If no region exists the release can be sent immediately. The host may also release extents at any time. Thus the 'more' bit grouping of release events is of less value and can be ignored in favor of sending multiple release capacity responses for groups of release events. Upon receiving a release event containing any extent falling under a region with a tag matching the region's tag, release all extents under the region.

Force removal is intended as a mechanism between the FM and the device and intended only when the host is unresponsive, out of sync, or otherwise broken. Purposely ignore force removal events.

Regions are made up of one or more devices which may be surfacing memory to the host. Once all devices in a region have surfaced an extent the region can expose a corresponding extent for the user to consume. A region extent is comprised of 1 or more contiguous device extents with the same tag. It is surfaced after all extents from the DC event ar
processed (events grouped together with the "More" flag).
Interleaving is unsupported.

Per the specification the device is allowed to offer or remove extents at any time. However, anticipated use cases can expect extents to be offered, accepted, and removed in well defined chunks.

Simplify extent tracking with the following restrictions.

1) Flag for removal any extent which overlaps a requested release range.
2) Refuse the offer of extents which overlap already accepted memory ranges.
3) Accept again a range which has already been accepted by the host. Eating duplicates serves three purposes. 3a) This simplifies the code if the device should get out of sync with the host. And it should be safe to acknowledge the extent again.
3b) This simplifies the code to process existing extents if
the extent list should change while the extent list is being read.
3c) Duplicates for a given partition which are seen during a
race between the hardware surfacing an extent and the cxl dax driver scanning for existing extents will be ignored.

NOTE: Processing existing extents is done in a later patch.

Management of the region extent devices must be synchronized with potential uses of the memory within the DAX layer. Create region extent devices as children of the cxl_dax_region device such that the DAX region driver can co-drive them and synchronize with the DAX layer. Synchronization and management is handled in a subsequent patch.

Process DCD events and create region devices.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa] replace mds->pending_extents xarray with list

Spec requires the DC add response to send extents back in the same order they were received in DC add event record. Extents are sorted by dpa order to check for contiguity, then re-sorted by original index to send DC rsp.

[anisa] replace cxl_dax_region->extent_ida with pointer to single region_extent

Each region is now associated with 1 tagged capacity. Make cxl_dax_region:region_extent 1:1 instead of 1:many.

[anisa] enforce contiguous tagged add
Collect extents in pending_list and sort by dpa to enforce they are contiguous. Drop non-contiguous extents.

Build 1 region_extent incrementally while iterating over pending_extents. Uses the first valid extent (valid DPA, non-null tag, etc.) to check all other extents against. Then all following extents must have the same tag in order to be added to the region_extent.

"Commit" the region by onlining the region extent (sets cxlr_dax->region_extent = region_ext). Once set, we disallow adding additional extents to the region. It can only be added to after being cleared with a release event, when we remove the entire tagged capacity and set cxlr_dax->region_extent back to NULL.

[anisa] enforce tagged release

Upon receiving any DC release event, check that the extent is within the bounds of a cxl_dax_region and its tag matches the region's tag.

Then release the entire capacity of the region by removing the cxlr_dax->region_extent.

Deletes the functions allowing us to delete individual decoder_extents and recalc the region_extent hpa range, as partial release is no longer supported

---
 drivers/cxl/core/Makefile     |   2 +-
 drivers/cxl/core/core.h       |  18 +-
 drivers/cxl/core/extent.c     | 368 +++++++++++++++++++++++++++++++
 drivers/cxl/core/mbox.c       | 401 +++++++++++++++++++++++++++++++++-
 drivers/cxl/core/region_dax.c |   6 +
 drivers/cxl/cxl.h             |  55 ++++-
 drivers/cxl/cxlmem.h          |  30 +++
 include/cxl/event.h           |  39 ++++
 tools/testing/cxl/Kbuild      |   5 +-
 9 files changed, 919 insertions(+), 5 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
drivers/cxl/core/Makefile +1 -1
index ce7213818d3c..208917ad8aac 100644
@@ -15,7 +15,7 @@ cxl_core-y += hdm.o
 cxl_core-y += pmu.o
 cxl_core-y += cdat.o
 cxl_core-$(CONFIG_TRACING) += trace.o
-cxl_core-$(CONFIG_CXL_REGION) += region.o region_pmem.o region_dax.o
+cxl_core-$(CONFIG_CXL_REGION) += region.o region_pmem.o region_dax.o extent.o
 cxl_core-$(CONFIG_CXL_MCE) += mce.o
 cxl_core-$(CONFIG_CXL_FEATURES) += features.o
 cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o
drivers/cxl/core/core.h +17 -1
index 14723cfd05f0..14d91dd52b02 100644
@@ -64,13 +64,28 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
 		   u64 dpa);
 int devm_cxl_add_dax_region(struct cxl_region *cxlr);
 int devm_cxl_add_pmem_region(struct cxl_region *cxlr);
-
+int cxl_add_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent);
+int cxl_rm_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent);
+int online_region_extent(struct region_extent *region_extent);
 #else
 static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,
 				 const struct cxl_memdev *cxlmd, u64 dpa)
 {
 	return ULLONG_MAX;
 }
+static inline int cxl_add_extent(struct cxl_memdev_state *mds,
+				   struct cxl_extent *extent) {
+	return 0;
+}
+static inline int cxl_rm_extent(struct cxl_memdev_state *mds,
+				struct cxl_extent *extent)
+{
+	return 0;
+}
+static inline int online_region_extent(struct region_extent *region_extent)
+{
+	return 0;
+}
 static inline
 struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,
 				     struct cxl_endpoint_decoder **cxled)
@@ -166,6 +181,7 @@ long cxl_pci_get_latency(struct pci_dev *pdev);
 int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c);
 int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
 					struct access_coordinate *c);
+void memdev_release_extent(struct cxl_memdev_state *mds, struct range *range);
 
 static inline struct device *port_to_host(struct cxl_port *port)
 {
drivers/cxl/core/extent.c new file +368 -0

368 lines not on this page · raw message

drivers/cxl/core/mbox.c +400 -1

439 lines not on this page · raw message

drivers/cxl/core/region_dax.c +6 -0
index 068690d02c8c..b2853494aee2 100644
@@ -90,6 +90,12 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr)
 	if (IS_ERR(cxlr_dax))
 		return PTR_ERR(cxlr_dax);
 
+	if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A &&
+	    cxlr->params.interleave_ways != 1) {
+		dev_err(&cxlr->dev, "Interleaving DC not supported\n");
+		return -EINVAL;
+	}
+
 	dev = &cxlr_dax->dev;
 	rc = dev_set_name(dev, "dax_region%d", cxlr->id);
 	if (rc)
drivers/cxl/cxl.h +54 -1

101 lines not on this page · raw message

drivers/cxl/cxlmem.h +30 -0
index 88bcc69f22c2..6da958352afd 100644
@@ -7,6 +7,7 @@
 #include <linux/cdev.h>
 #include <linux/uuid.h>
 #include <linux/node.h>
+#include <linux/list.h>
 #include <cxl/event.h>
 #include <cxl/mailbox.h>
 #include "cxl.h"
@@ -415,6 +416,7 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)
  * @active_volatile_bytes: sum of hard + soft volatile
  * @active_persistent_bytes: sum of hard + soft persistent
  * @dcd_supported: all DCD commands are supported
+ * @pending_ctx: pending_add ctx
  * @event: event log driver state
  * @poison: poison driver state info
  * @security: security driver state info
@@ -435,6 +437,10 @@ struct cxl_memdev_state {
 	u64 active_volatile_bytes;
 	u64 active_persistent_bytes;
 	bool dcd_supported;
+	struct pending_add_ctx {
+		struct list_head pending_extents;
+		struct region_extent *region_extent;
+	} add_ctx;
 
 	struct cxl_event_state event;
 	struct cxl_poison_state poison;
@@ -511,6 +517,21 @@ enum cxl_opcode {
 	UUID_INIT(0x5e1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19,     \
 		  0x40, 0x3d, 0x86)
 
+/*
+ * Add Dynamic Capacity Response
+ * CXL rev 3.1 section 8.2.9.9.9.3; Table 8-168 & Table 8-169
+ */
+struct cxl_mbox_dc_response {
+	__le32 extent_list_size;
+	u8 flags;
+	u8 reserved[3];
+	struct updated_extent_list {
+		__le64 dpa_start;
+		__le64 length;
+		u8 reserved[8];
+	} __packed extent_list[] __counted_by(extent_list_size);
+} __packed;
+
 struct cxl_mbox_get_supported_logs {
 	__le16 entries;
 	u8 rsvd[6];
@@ -581,6 +602,14 @@ struct cxl_mbox_identify {
 	UUID_INIT(0xe71f3a40, 0x2d29, 0x4092, 0x8a, 0x39, 0x4d, 0x1c, 0x96, \
 		  0x6c, 0x7c, 0x65)
 
+/*
+ * Dynamic Capacity Event Record
+ * CXL rev 3.1 section 8.2.9.2.1; Table 8-43
+ */
+#define CXL_EVENT_DC_EVENT_UUID                                             \
+	UUID_INIT(0xca95afa7, 0xf183, 0x4018, 0x8c, 0x2f, 0x95, 0x26, 0x8e, \
+		  0x10, 0x1a, 0x2a)
+
 /*
  * Get Event Records output payload
  * CXL rev 3.0 section 8.2.9.2.2; Table 8-50
@@ -606,6 +635,7 @@ enum cxl_event_log_type {
 	CXL_EVENT_TYPE_WARN,
 	CXL_EVENT_TYPE_FAIL,
 	CXL_EVENT_TYPE_FATAL,
+	CXL_EVENT_TYPE_DCD,
 	CXL_EVENT_TYPE_MAX
 };
 
include/cxl/event.h +39 -0
index ff97fea718d2..fbd95e381e41 100644
@@ -6,6 +6,7 @@
 #include <linux/types.h>
 #include <linux/uuid.h>
 #include <linux/workqueue_types.h>
+#include <linux/list.h>
 
 /*
  * Common Event Record Format
@@ -141,12 +142,50 @@ struct cxl_event_mem_sparing {
 	u8 reserved2[0x25];
 } __packed;
 
+/*
+ * CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51
+ */
+struct cxl_extent {
+	__le64 start_dpa;
+	__le64 length;
+	u8 uuid[UUID_SIZE];
+	__le16 shared_extn_seq;
+	u8 reserved[0x6];
+} __packed;
+
+struct cxl_extent_list_node {
+	struct cxl_extent *extent;
+	struct list_head list;
+	int idx;
+	int rid;
+};
+
+/*
+ * Dynamic Capacity Event Record
+ * CXL rev 3.1 section 8.2.9.2.1.6; Table 8-50
+ */
+#define CXL_DCD_EVENT_MORE			BIT(0)
+struct cxl_event_dcd {
+	struct cxl_event_record_hdr hdr;
+	u8 event_type;
+	u8 validity_flags;
+	__le16 host_id;
+	u8 partition_index;
+	u8 flags;
+	u8 reserved1[0x2];
+	struct cxl_extent extent;
+	u8 reserved2[0x18];
+	__le32 num_avail_extents;
+	__le32 num_avail_tags;
+} __packed;
+
 union cxl_event {
 	struct cxl_event_generic generic;
 	struct cxl_event_gen_media gen_media;
 	struct cxl_event_dram dram;
 	struct cxl_event_mem_module mem_module;
 	struct cxl_event_mem_sparing mem_sparing;
+	struct cxl_event_dcd dcd;
 	/* dram & gen_media event header */
 	struct cxl_event_media_hdr media_hdr;
 } __packed;
tools/testing/cxl/Kbuild +4 -1
index 2be1df80fcc9..8941cf187462 100644
@@ -63,7 +63,10 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o
 cxl_core-y += $(CXL_CORE_SRC)/pmu.o
 cxl_core-y += $(CXL_CORE_SRC)/cdat.o
 cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
-cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o $(CXL_CORE_SRC)/region_pmem.o $(CXL_CORE_SRC)/region_dax.o
+cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o \
+				 $(CXL_CORE_SRC)/region_pmem.o \
+				 $(CXL_CORE_SRC)/region_dax.o \
+				 $(CXL_CORE_SRC)/extent.o
 cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o
 cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o
 cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o
Signature · 1 line
2.43.0
author
#13 lore raw

PATCH 13/20 cxl/region/extent: Expose region extent information in sysfs

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Extent information can be helpful to the user to coordinate memory usage with the external orchestrator and FM.

Expose the details of region extents by creating the following sysfs entries.

/sys/bus/cxl/devices/dax_regionX/extentX.Y /sys/bus/cxl/devices/dax_regionX/extentX.Y/offset /sys/bus/cxl/devices/dax_regionX/extentX.Y/length /sys/bus/cxl/devices/dax_regionX/extentX.Y/tag

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: rebase]

---
 Documentation/ABI/testing/sysfs-bus-cxl | 36 +++++++++++++++
 drivers/cxl/core/extent.c               | 58 +++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +36 -0
index 3080aef9ad67..38cf0a2894b9 100644
@@ -661,3 +661,39 @@ Description:
 		The count is persistent across power loss and wraps back to 0
 		upon overflow. If this file is not present, the device does not
 		have the necessary support for dirty tracking.
+
+
+What:		/sys/bus/cxl/devices/dax_regionX/extentX.Y/offset
+Date:		May, 2025
+KernelVersion:	v6.16
+Contact:	[email protected]
+Description:
+		(RO) [For Dynamic Capacity regions only] Users can use the
+		extent information to create DAX devices on specific extents.
+		This is done by creating and destroying DAX devices in specific
+		sequences and looking at the mappings created.  Extent offset
+		within the region.
+
+
+What:		/sys/bus/cxl/devices/dax_regionX/extentX.Y/length
+Date:		May, 2025
+KernelVersion:	v6.16
+Contact:	[email protected]
+Description:
+		(RO) [For Dynamic Capacity regions only] Users can use the
+		extent information to create DAX devices on specific extents.
+		This is done by creating and destroying DAX devices in specific
+		sequences and looking at the mappings created.  Extent length
+		within the region.
+
+
+What:		/sys/bus/cxl/devices/dax_regionX/extentX.Y/uuid
+Date:		May, 2025
+KernelVersion:	v6.16
+Contact:	[email protected]
+Description:
+		(RO) [For Dynamic Capacity regions only] Users can use the
+		extent information to create DAX devices on specific extents.
+		This is done by creating and destroying DAX devices in specific
+		sequences and looking at the mappings created.  UUID of this
+		extent.
drivers/cxl/core/extent.c +58 -0

70 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#14 lore raw

PATCH 14/20 dax/bus: Factor out dev dax resize logic

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic Capacity regions must limit dev dax resources to those areas which have extents backing real memory. Such DAX regions are dubbed 'sparse' regions. In order to manage where memory is available four alternatives were considered:

1) Create a single region resource child on region creation which reserves the entire region. Then as extents are added punch holes in this reservation. This requires new resource manipulation to punch the holes and still requires an additional iteration over the extent areas which may already have existing dev dax resources used.

2) Maintain an ordered xarray of extents which can be queried while processing the resize logic. The issue is that existing region->res children may artificially limit the allocation size sent to alloc_dev_dax_range(). IE the resource children can't be directly used in the resize logic to find where space in the region is. This also poses a problem of managing the available size in 2 places.

3) Maintain a separate resource tree with extents. This option is the same as 2) but with the different data structure. Most ideally there should be a unified representation of the resource tree not two places to look for space.

4) Create region resource children for each extent. Manage the dax dev resize logic in the same way as before but use a region child (extent) resource as the parents to find space within each extent.

Option 4 can leverage the existing resize algorithm to find space within the extents. It manages the available space in a singular resource tree which is less complicated for finding space.

In preparation for this change, factor out the dev_dax_resize logic. For static regions use dax_region->res as the parent to find space for the dax ranges. Future patches will use the same algorithm with individual extent resources as the parent.

---
Changes:
[anisa: rebase]

---
 drivers/dax/bus.c | 130 ++++++++++++++++++++++++++++------------------
 1 file changed, 80 insertions(+), 50 deletions(-)
drivers/dax/bus.c +80 -50
index e41e36747111..40f11fda66b5 100644
@@ -858,11 +858,9 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id)
 	return 0;
 }
 
-static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start,
-		resource_size_t size)
+static int alloc_dev_dax_range(struct resource *parent, struct dev_dax *dev_dax,
+			       u64 start, resource_size_t size)
 {
-	struct dax_region *dax_region = dev_dax->region;
-	struct resource *res = &dax_region->res;
 	struct device *dev = &dev_dax->dev;
 	struct dev_dax_range *ranges;
 	unsigned long pgoff = 0;
@@ -880,14 +878,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start,
 		return 0;
 	}
 
-	alloc = __request_region(res, start, size, dev_name(dev), 0);
+	alloc = __request_region(parent, start, size, dev_name(dev), 0);
 	if (!alloc)
 		return -ENOMEM;
 
 	ranges = krealloc(dev_dax->ranges, sizeof(*ranges)
 			* (dev_dax->nr_range + 1), GFP_KERNEL);
 	if (!ranges) {
-		__release_region(res, alloc->start, resource_size(alloc));
+		__release_region(parent, alloc->start, resource_size(alloc));
 		return -ENOMEM;
 	}
 
@@ -1040,50 +1038,45 @@ static bool adjust_ok(struct dev_dax *dev_dax, struct resource *res)
 	return true;
 }
 
-static ssize_t dev_dax_resize(struct dax_region *dax_region,
-		struct dev_dax *dev_dax, resource_size_t size)
+/**
+ * dev_dax_resize_static - Expand the device into the unused portion of the
+ * region. This may involve adjusting the end of an existing resource, or
+ * allocating a new resource.
+ *
+ * @parent: parent resource to allocate this range in
+ * @dev_dax: DAX device to be expanded
+ * @to_alloc: amount of space to alloc; must be <= space available in @parent
+ *
+ * Return the amount of space allocated or -ERRNO on failure
+ */
+static ssize_t dev_dax_resize_static(struct resource *parent,
+				     struct dev_dax *dev_dax,
+				     resource_size_t to_alloc)
 {
-	resource_size_t avail = dax_region_avail_size(dax_region), to_alloc;
-	resource_size_t dev_size = dev_dax_size(dev_dax);
-	struct resource *region_res = &dax_region->res;
-	struct device *dev = &dev_dax->dev;
 	struct resource *res, *first;
-	resource_size_t alloc = 0;
 	int rc;
 
-	if (dev->driver)
-		return -EBUSY;
-	if (size == dev_size)
-		return 0;
-	if (size > dev_size && size - dev_size > avail)
-		return -ENOSPC;
-	if (size < dev_size)
-		return dev_dax_shrink(dev_dax, size);
-
-	to_alloc = size - dev_size;
-	if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc),
-			"resize of %pa misaligned\n", &to_alloc))
-		return -ENXIO;
-
-	/*
-	 * Expand the device into the unused portion of the region. This
-	 * may involve adjusting the end of an existing resource, or
-	 * allocating a new resource.
-	 */
-retry:
-	first = region_res->child;
-	if (!first)
-		return alloc_dev_dax_range(dev_dax, dax_region->res.start, to_alloc);
+	first = parent->child;
+	if (!first) {
+		rc = alloc_dev_dax_range(parent, dev_dax,
+					   parent->start, to_alloc);
+		if (rc)
+			return rc;
+		return to_alloc;
+	}
 
-	rc = -ENOSPC;
 	for (res = first; res; res = res->sibling) {
 		struct resource *next = res->sibling;
+		resource_size_t alloc;
 
 		/* space at the beginning of the region */
-		if (res == first && res->start > dax_region->res.start) {
-			alloc = min(res->start - dax_region->res.start, to_alloc);
-			rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, alloc);
-			break;
+		if (res == first && res->start > parent->start) {
+			alloc = min(res->start - parent->start, to_alloc);
+			rc = alloc_dev_dax_range(parent, dev_dax,
+						 parent->start, alloc);
+			if (rc)
+				return rc;
+			return alloc;
 		}
 
 		alloc = 0;
@@ -1092,21 +1085,56 @@ static ssize_t dev_dax_resize(struct dax_region *dax_region,
 			alloc = min(next->start - (res->end + 1), to_alloc);
 
 		/* space at the end of the region */
-		if (!alloc && !next && res->end < region_res->end)
-			alloc = min(region_res->end - res->end, to_alloc);
+		if (!alloc && !next && res->end < parent->end)
+			alloc = min(parent->end - res->end, to_alloc);
 
 		if (!alloc)
 			continue;
 
 		if (adjust_ok(dev_dax, res)) {
 			rc = adjust_dev_dax_range(dev_dax, res, resource_size(res) + alloc);
-			break;
+			if (rc)
+				return rc;
+			return alloc;
 		}
-		rc = alloc_dev_dax_range(dev_dax, res->end + 1, alloc);
-		break;
+		rc = alloc_dev_dax_range(parent, dev_dax, res->end + 1, alloc);
+		if (rc)
+			return rc;
+		return alloc;
 	}
-	if (rc)
-		return rc;
+
+	/* available was already calculated and should never be an issue */
+	dev_WARN_ONCE(&dev_dax->dev, 1, "space not found?");
+	return 0;
+}
+
+static ssize_t dev_dax_resize(struct dax_region *dax_region,
+		struct dev_dax *dev_dax, resource_size_t size)
+{
+	resource_size_t avail = dax_region_avail_size(dax_region);
+	resource_size_t dev_size = dev_dax_size(dev_dax);
+	struct device *dev = &dev_dax->dev;
+	resource_size_t to_alloc;
+	resource_size_t alloc;
+
+	if (dev->driver)
+		return -EBUSY;
+	if (size == dev_size)
+		return 0;
+	if (size > dev_size && size - dev_size > avail)
+		return -ENOSPC;
+	if (size < dev_size)
+		return dev_dax_shrink(dev_dax, size);
+
+	to_alloc = size - dev_size;
+	if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc),
+			"resize of %pa misaligned\n", &to_alloc))
+		return -ENXIO;
+
+retry:
+	alloc = dev_dax_resize_static(&dax_region->res, dev_dax, to_alloc);
+	if (alloc <= 0)
+		return alloc;
 	to_alloc -= alloc;
 	if (to_alloc)
 		goto retry;
@@ -1212,7 +1240,8 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr,
 
 	to_alloc = range_len(&r);
 	if (alloc_is_aligned(dev_dax, to_alloc))
-		rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc);
+		rc = alloc_dev_dax_range(&dax_region->res, dev_dax, r.start,
+					 to_alloc);
 	up_write(&dax_dev_rwsem);
 	up_write(&dax_region_rwsem);
 
@@ -1480,7 +1509,8 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data)
 	device_initialize(dev);
 	dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id);
 
-	rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, data->size);
+	rc = alloc_dev_dax_range(&dax_region->res, dev_dax, dax_region->res.start,
+				 data->size);
 	if (rc)
 		goto err_range;
 
Signature · 1 line
2.43.0
author
#15 lore raw

PATCH 15/20 dax/region: Create resources on DAX regions

In reply to Anisa Su

From: Ira Weiny <[email protected]>

DAX regions which map dynamic capacity partitions require that memory be allowed to come and go. Recall struct dax_resource was created for this purpose. Now that extents can be realized within DAX regions the DAX region driver can start tracking sub-resource information.

The tight relationship between DAX region operations and extent operations require memory changes to be controlled synchronously with the user of the region. Synchronize through the dax_region_rwsem and by having the region driver drive both the region device as well as the extent sub-devices.

Recall requests to remove extents can happen at any time and that a host is not obligated to release the memory until it is not being used. If an extent is not used allow a release response.

When extents are eligible for release. No mappings exist but data may reside in caches not yet written to the device. Call cxl_region_invalidate_memregion() to write back data to the device prior to signaling the release complete.

Speculative writes after a release may dirty the cache such that a read from a newly surfaced extent may not come from the device. Call cxl_region_invalidate_memregion() prior to bringing a new extent online to ensure the cache is marked invalid.

While these invalidate calls are inefficient they are the best we can do to ensure cache consistency without back invalidate. Furthermore this should occur infrequently with sufficiently large extents that real work loads should not be impacted much.

The DAX layer has no need for the details of the CXL memory extent devices. Expose extents to the DAX layer as device children of the DAX region device. A single callback from the driver aids the DAX layer to determine if the child device is an extent. The DAX layer also registers a devres function to automatically clean up when the device is removed from the region.

There is a race between extents being surfaced and the dax_cxl driver being loaded. Synchronizes the driver during probe by scanning for existing extents while under the device lock.

Respond to extent notifications. Manage the DAX region resource tree based on the extents lifetime. Return the status of remove notifications to lower layers such that it can manage the hardware appropriately.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa: notify once for region_extent_online and region_rm_extent]

Instead of notifying the DAX layer for each device extent, notify only once after processing the entire pending list. This ensures the tagged capacity is added/removed all at once.

---
 drivers/cxl/core/core.h   |  11 ++
 drivers/cxl/core/extent.c |  47 +++++++-
 drivers/cxl/core/mbox.c   |  16 ++-
 drivers/cxl/core/region.c |   2 +-
 drivers/cxl/cxl.h         |   5 +
 drivers/dax/bus.c         | 247 ++++++++++++++++++++++++++++++++++----
 drivers/dax/bus.h         |   3 +-
 drivers/dax/cxl.c         |  61 +++++++++-
 drivers/dax/dax-private.h |  40 ++++++
 drivers/dax/hmem/hmem.c   |   2 +-
 drivers/dax/pmem.c        |   2 +-
 include/linux/ioport.h    |   3 +
 12 files changed, 404 insertions(+), 35 deletions(-)
drivers/cxl/core/core.h +11 -0
index 14d91dd52b02..cb3f46a1152a 100644
@@ -28,6 +28,8 @@ cxled_to_mds(struct cxl_endpoint_decoder *cxled)
 	return container_of(cxlds, struct cxl_memdev_state, cxlds);
 }
 
+int cxl_region_invalidate_memregion(struct cxl_region *cxlr);
+
 #ifdef CONFIG_CXL_REGION
 
 struct cxl_region_context {
@@ -67,6 +69,9 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);
 int cxl_add_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent);
 int cxl_rm_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent);
 int online_region_extent(struct region_extent *region_extent);
+void region_rm_extent(struct region_extent *region_extent);
+int cxlr_notify_extent(struct cxl_region *cxlr, enum dc_event event,
+		       struct region_extent *region_extent);
 #else
 static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,
 				 const struct cxl_memdev *cxlmd, u64 dpa)
@@ -86,6 +91,12 @@ static inline int online_region_extent(struct region_extent *region_extent)
 {
 	return 0;
 }
+static inline void region_rm_extent(struct region_extent *region_extent) { }
+static int cxlr_notify_extent(struct cxl_region *cxlr, enum dc_event event,
+			      struct region_extent *region_extent)
+{
+	return 0;
+}
 static inline
 struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,
 				     struct cxl_endpoint_decoder **cxled)
drivers/cxl/core/extent.c +46 -1

74 lines not on this page · raw message

drivers/cxl/core/mbox.c +15 -1
index 56d8b2a9974c..c256081d2c65 100644
@@ -1375,12 +1375,26 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)
 	}
 
 	pending_reg_ext = mds->add_ctx.region_extent;
+	/* Ensure caches are clean prior onlining */
+	rc = cxl_region_invalidate_memregion(pending_reg_ext->cxlr_dax->cxlr);
+	if (rc)
+		return rc;
 
 	/* device model handles freeing region_extent */
-	rc = online_region_extent(mds->add_ctx.region_extent);
+	rc = online_region_extent(pending_reg_ext);
 	if (rc)
 		return rc;
 
+	rc = cxlr_notify_extent(pending_reg_ext->cxlr_dax->cxlr,
+				DCD_ADD_CAPACITY,
+				pending_reg_ext);
+	/*
+	 * The region device was briefly live but DAX layer ensures it was not
+	 * used
+	 */
+	if (rc)
+		region_rm_extent(pending_reg_ext);
+
 	/* Restore remaining extents to original order and send rsp */
 	list_sort(NULL, &mds->add_ctx.pending_extents, idx_compare);
 	return cxl_send_dc_response(mds, CXL_MBOX_OP_ADD_DC_RESPONSE,
drivers/cxl/core/region.c +1 -1
index e00fdb74589c..7b869c8ada22 100644
@@ -222,7 +222,7 @@ static struct cxl_region_ref *cxl_rr_load(struct cxl_port *port,
 	return xa_load(&port->regions, (unsigned long)cxlr);
 }
 
-static int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
+int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
 {
 	if (!cpu_cache_has_invalidate_memregion()) {
 		if (IS_ENABLED(CONFIG_CXL_REGION_INVALIDATION_TEST)) {
drivers/cxl/cxl.h +5 -0
index 477e91bc2ab7..6fda10e25043 100644
@@ -858,12 +858,17 @@ extern const struct bus_type cxl_bus_type;
  * by @id and the add_dport() op only defined for the CXL_DEVICE_PORT driver
  * template.
  */
+struct cxl_notify_data {
+	enum dc_event event;
+	struct region_extent *region_extent;
+};
 struct cxl_driver {
 	const char *name;
 	int (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct cxl_dport *(*add_dport)(struct cxl_port *port,
 				       struct device *dport_dev);
+	int (*notify)(struct device *dev, struct cxl_notify_data *notify_data);
 	struct device_driver drv;
 	int id;
 };
drivers/dax/bus.c +221 -26

385 lines not on this page · raw message

drivers/dax/bus.h +2 -1
index 7abdd5a403dc..d41cb36e8868 100644
@@ -11,6 +11,7 @@ struct dev_dax;
 struct resource;
 struct dax_device;
 struct dax_region;
+struct dax_sparse_ops;
 
 /* dax bus specific ioresource flags */
 #define IORESOURCE_DAX_STATIC BIT(0)
@@ -19,7 +20,7 @@ struct dax_region;
 
 struct dax_region *alloc_dax_region(struct device *parent, int region_id,
 		struct range *range, int target_node, unsigned int align,
-		unsigned long flags);
+		unsigned long flags, struct dax_sparse_ops *sparse_ops);
 
 struct dev_dax_data {
 	struct dax_region *dax_region;
drivers/dax/cxl.c +58 -3

85 lines not on this page · raw message

drivers/dax/dax-private.h +40 -0
index c6ae27c982f4..83b198068597 100644
@@ -16,6 +16,14 @@ struct inode *dax_inode(struct dax_device *dax_dev);
 int dax_bus_init(void);
 void dax_bus_exit(void);
 
+/**
+ * struct dax_sparse_ops - Operations for sparse regions
+ * @is_extent: return if the device is an extent
+ */
+struct dax_sparse_ops {
+	bool (*is_extent)(struct device *dev);
+};
+
 /**
  * struct dax_region - mapping infrastructure for dax devices
  * @id: kernel-wide unique region for a memory range
@@ -27,6 +35,7 @@ void dax_bus_exit(void);
  * @res: resource tree to track instance allocations
  * @seed: allow userspace to find the first unbound seed device
  * @youngest: allow userspace to find the most recently created device
+ * @sparse_ops: operations required for sparse regions
  */
 struct dax_region {
 	int id;
@@ -38,6 +47,7 @@ struct dax_region {
 	struct resource res;
 	struct device *seed;
 	struct device *youngest;
+	struct dax_sparse_ops *sparse_ops;
 };
 
 /**
@@ -57,11 +67,13 @@ struct dax_mapping {
  * @pgoff: page offset
  * @range: resource-span
  * @mapping: reference to the dax_mapping for this range
+ * @dax_resource: if not NULL; dax sparse resource containing this range
  */
 struct dev_dax_range {
 	unsigned long pgoff;
 	struct range range;
 	struct dax_mapping *mapping;
+	struct dax_resource *dax_resource;
 };
 
 /**
@@ -102,6 +114,34 @@ struct dev_dax {
  */
 void run_dax(struct dax_device *dax_dev);
 
+/**
+ * struct dax_resource - For sparse regions; an active resource
+ * @region: dax_region this resources is in
+ * @res: resource
+ * @use_cnt: count the number of uses of this resource
+ *
+ * Changes to the dax_region and the dax_resources within it are protected by
+ * dax_region_rwsem
+ *
+ * dax_resource's are not intended to be used outside the dax layer.
+ */
+struct dax_resource {
+	struct dax_region *region;
+	struct resource *res;
+	unsigned int use_cnt;
+};
+
+/*
+ * Similar to run_dax() dax_region_{add,rm}_resource() and dax_avail_size() are
+ * exported but are not intended to be generic operations outside the dax
+ * subsystem.  They are only generic between the dax layer and the dax drivers.
+ */
+int dax_region_add_resource(struct dax_region *dax_region, struct device *dev,
+			    resource_size_t start, resource_size_t length);
+int dax_region_rm_resource(struct dax_region *dax_region,
+			   struct device *dev);
+resource_size_t dax_avail_size(struct resource *dax_resource);
+
 static inline struct dev_dax *to_dev_dax(struct device *dev)
 {
 	return container_of(dev, struct dev_dax, dev);
drivers/dax/hmem/hmem.c +1 -1
index af21f66bf872..be938c2a73f8 100644
@@ -28,7 +28,7 @@ static int dax_hmem_probe(struct platform_device *pdev)
 
 	mri = dev->platform_data;
 	dax_region = alloc_dax_region(dev, pdev->id, &mri->range,
-				      mri->target_node, PMD_SIZE, flags);
+				      mri->target_node, PMD_SIZE, flags, NULL);
 	if (!dax_region)
 		return -ENOMEM;
 
drivers/dax/pmem.c +1 -1
index bee93066a849..5b5be86768f3 100644
@@ -53,7 +53,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
 	range.start += offset;
 	dax_region = alloc_dax_region(dev, region_id, &range,
 			nd_region->target_node, le32_to_cpu(pfn_sb->align),
-			IORESOURCE_DAX_STATIC);
+			IORESOURCE_DAX_STATIC, NULL);
 	if (!dax_region)
 		return ERR_PTR(-ENOMEM);
 
include/linux/ioport.h +3 -0
index 5533a5debf3f..ab364e25f479 100644
@@ -28,6 +28,9 @@ struct resource {
 	struct resource *parent, *sibling, *child;
 };
 
+#define for_each_child_resource(parent, res) \
+	for (res = (parent)->child; res; res = res->sibling)
+
 /*
  * IO resources have these defined flags.
  *
Signature · 1 line
2.43.0
author
#16 lore raw

PATCH 16/20 cxl/region: Read existing extents on region creation

In reply to Anisa Su

From: Ira Weiny <[email protected]>

Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case it is expected that the creation of a new region on top of a DC partition can read those extents and surface them for continued use.

Once all endpoint decoders are part of a region and the region is being realized, a read of the 'devices extent list' can reveal these previously accepted extents.

CXL r3.1 specifies the mailbox call Get Dynamic Capacity Extent List for this purpose. The call returns all the extents for all dynamic capacity partitions. If the fabric manager is adding extents to any DCD partition, the extent list for the recovered region may change. In this case the query must retry. Upon retry the query could encounter extents which were accepted on a previous list query. Adding such extents is ignored without error because they are entirely within a previous accepted extent. Instead warn on this case to allow for differentiating bad devices from this normal condition.

Latch any errors to be bubbled up to ensure notification to the user even if individual errors are rate limited or otherwise ignored.

The scan for existing extents races with the dax_cxl driver. This is synchronized through the region device lock. Extents which are found after the driver has loaded will surface through the normal notification path while extents seen prior to the driver are read during driver load.

Based on an original patch by Navneet Singh.

---
Changes:
[anisa]: enforce same tagged add rules for processing existing extents

Instead of onlining and notifying the dax layer as we go, process the entire list, creating a single region extent from it, then online/notify.

---
 drivers/cxl/core/core.h |   1 +
 drivers/cxl/core/mbox.c | 116 ++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    |  21 ++++++++
 3 files changed, 138 insertions(+)
drivers/cxl/core/core.h +1 -0
index cb3f46a1152a..24121734b2d5 100644
@@ -28,6 +28,7 @@ cxled_to_mds(struct cxl_endpoint_decoder *cxled)
 	return container_of(cxlds, struct cxl_memdev_state, cxlds);
 }
 
+int cxl_process_extent_list(struct cxl_endpoint_decoder *cxled);
 int cxl_region_invalidate_memregion(struct cxl_region *cxlr);
 
 #ifdef CONFIG_CXL_REGION
drivers/cxl/core/mbox.c +116 -0

122 lines not on this page · raw message

drivers/cxl/cxlmem.h +21 -0
index 6da958352afd..3346da309be3 100644
@@ -532,6 +532,27 @@ struct cxl_mbox_dc_response {
 	} __packed extent_list[] __counted_by(extent_list_size);
 } __packed;
 
+/*
+ * Get Dynamic Capacity Extent List; Input Payload
+ * CXL rev 3.1 section 8.2.9.9.9.2; Table 8-166
+ */
+struct cxl_mbox_get_extent_in {
+	__le32 extent_cnt;
+	__le32 start_extent_index;
+} __packed;
+
+/*
+ * Get Dynamic Capacity Extent List; Output Payload
+ * CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167
+ */
+struct cxl_mbox_get_extent_out {
+	__le32 returned_extent_count;
+	__le32 total_extent_count;
+	__le32 generation_num;
+	u8 rsvd[4];
+	struct cxl_extent extent[];
+} __packed;
+
 struct cxl_mbox_get_supported_logs {
 	__le16 entries;
 	u8 rsvd[6];
Signature · 1 line
2.43.0
author
#17 lore raw

PATCH 17/20 cxl/mem: Trace Dynamic capacity Event Record

In reply to Anisa Su

From: Ira Weiny <[email protected]>

CXL rev 3.1 section 8.2.9.2.1 adds the Dynamic Capacity Event Records. User space can use trace events for debugging of DC capacity changes.

Add DC trace points to the trace log.

Based on an original patch by Navneet Singh.

---
Changes:
[djbw: s/region/partition/]
[iweiny: s/tag/uuid/]

---
 drivers/cxl/core/mbox.c  |  5 ++++
 drivers/cxl/core/trace.h | 65 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
drivers/cxl/core/mbox.c +5 -0
index 9ef38a81933d..81a1d7afced9 100644
@@ -1097,6 +1097,11 @@ static void __cxl_event_trace_record(struct cxl_memdev *cxlmd,
 		ev_type = CXL_CPER_EVENT_MEM_MODULE;
 	else if (uuid_equal(uuid, &CXL_EVENT_MEM_SPARING_UUID))
 		ev_type = CXL_CPER_EVENT_MEM_SPARING;
+	else if (uuid_equal(uuid, &CXL_EVENT_DC_EVENT_UUID)) {
+/* FIXME still valid? */
+		trace_cxl_dynamic_capacity(cxlmd, type, &record->event.dcd);
+		return;
+	}
 
 	cxl_event_trace_record(cxlmd, type, ev_type, uuid, &record->event);
 }
drivers/cxl/core/trace.h +65 -0

71 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#18 lore raw

PATCH 18/20 tools/testing/cxl: Make event logs dynamic

In reply to Anisa Su

From: Ira Weiny <[email protected]>

The event logs test was created as static arrays as an easy way to mock events. Dynamic Capacity Device (DCD) test support requires events be generated dynamically when extents are created or destroyed.

The current event log test has specific checks for the number of events seen including log overflow.

Modify mock event logs to be dynamically allocated. Adjust array size and mock event entry data to match the output expected by the existing event test.

Use the static event data to create the dynamic events in the new logs without inventing complex event injection for the previous tests.

Simplify log processing by using the event log array index as the handle. Add a lock to manage concurrency required when user space is allowed to control DCD extents

---
Changes:
[iweiny: rebase to 6.15-rc1]

---
 tools/testing/cxl/test/mem.c | 265 +++++++++++++++++++++--------------
 1 file changed, 161 insertions(+), 104 deletions(-)
tools/testing/cxl/test/mem.c +161 -104
index 271c7ad8cc32..fe1dadddd18e 100644
@@ -142,18 +142,26 @@ static struct {
 
 #define PASS_TRY_LIMIT 3
 
-#define CXL_TEST_EVENT_CNT_MAX 15
+#define CXL_TEST_EVENT_CNT_MAX 16
+/* 1 extra slot to accommodate that handles can't be 0 */
+#define CXL_TEST_EVENT_ARRAY_SIZE (CXL_TEST_EVENT_CNT_MAX + 1)
 
 /* Set a number of events to return at a time for simulation.  */
 #define CXL_TEST_EVENT_RET_MAX 4
 
+/*
+ * @last_handle: last handle (index) to have an entry stored
+ * @current_handle: current handle (index) to be returned to the user on get_event
+ * @nr_overflow: number of events added past the log size
+ * @lock: protect these state variables
+ * @events: array of pending events to be returned.
+ */
 struct mock_event_log {
-	u16 clear_idx;
-	u16 cur_idx;
-	u16 nr_events;
+	u16 last_handle;
+	u16 current_handle;
 	u16 nr_overflow;
-	u16 overflow_reset;
-	struct cxl_event_record_raw *events[CXL_TEST_EVENT_CNT_MAX];
+	rwlock_t lock;
+	struct cxl_event_record_raw *events[CXL_TEST_EVENT_ARRAY_SIZE];
 };
 
 struct mock_event_store {
@@ -194,56 +202,65 @@ static struct mock_event_log *event_find_log(struct device *dev, int log_type)
 	return &mdata->mes.mock_logs[log_type];
 }
 
-static struct cxl_event_record_raw *event_get_current(struct mock_event_log *log)
-{
-	return log->events[log->cur_idx];
-}
-
-static void event_reset_log(struct mock_event_log *log)
-{
-	log->cur_idx = 0;
-	log->clear_idx = 0;
-	log->nr_overflow = log->overflow_reset;
-}
-
 /* Handle can never be 0 use 1 based indexing for handle */
-static u16 event_get_clear_handle(struct mock_event_log *log)
+static u16 event_inc_handle(u16 handle)
 {
-	return log->clear_idx + 1;
+	handle = (handle + 1) % CXL_TEST_EVENT_ARRAY_SIZE;
+	if (handle == 0)
+		handle = 1;
+	return handle;
 }
 
-/* Handle can never be 0 use 1 based indexing for handle */
-static __le16 event_get_cur_event_handle(struct mock_event_log *log)
-{
-	u16 cur_handle = log->cur_idx + 1;
-
-	return cpu_to_le16(cur_handle);
-}
-
-static bool event_log_empty(struct mock_event_log *log)
-{
-	return log->cur_idx == log->nr_events;
-}
-
-static void mes_add_event(struct mock_event_store *mes,
+/* Add the event or free it on overflow */
+static void mes_add_event(struct cxl_mockmem_data *mdata,
 			  enum cxl_event_log_type log_type,
 			  struct cxl_event_record_raw *event)
 {
+	struct device *dev = mdata->mds->cxlds.dev;
 	struct mock_event_log *log;
 
 	if (WARN_ON(log_type >= CXL_EVENT_TYPE_MAX))
 		return;
 
-	log = &mes->mock_logs[log_type];
+	log = &mdata->mes.mock_logs[log_type];
+
+	guard(write_lock)(&log->lock);
 
-	if ((log->nr_events + 1) > CXL_TEST_EVENT_CNT_MAX) {
+	dev_dbg(dev, "Add log %d cur %d last %d\n",
+		log_type, log->current_handle, log->last_handle);
+
+	/* Check next buffer */
+	if (event_inc_handle(log->last_handle) == log->current_handle) {
 		log->nr_overflow++;
-		log->overflow_reset = log->nr_overflow;
+		dev_dbg(dev, "Overflowing log %d nr %d\n",
+			log_type, log->nr_overflow);
+		devm_kfree(dev, event);
 		return;
 	}
 
-	log->events[log->nr_events] = event;
-	log->nr_events++;
+	dev_dbg(dev, "Log %d; handle %u\n", log_type, log->last_handle);
+	event->event.generic.hdr.handle = cpu_to_le16(log->last_handle);
+	log->events[log->last_handle] = event;
+	log->last_handle = event_inc_handle(log->last_handle);
+}
+
+static void mes_del_event(struct device *dev,
+			  struct mock_event_log *log,
+			  u16 handle)
+{
+	struct cxl_event_record_raw *record;
+
+	lockdep_assert(lockdep_is_held(&log->lock));
+
+	dev_dbg(dev, "Clearing event %u; record %u\n",
+		handle, log->current_handle);
+	record = log->events[handle];
+	if (!record)
+		dev_err(dev, "Mock event index %u empty?\n", handle);
+
+	log->events[handle] = NULL;
+	log->current_handle = event_inc_handle(log->current_handle);
+	devm_kfree(dev, record);
 }
 
 /*
@@ -257,6 +274,7 @@ static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 	struct cxl_get_event_payload *pl;
 	struct mock_event_log *log;
 	int ret_limit;
+	u16 handle;
 	u8 log_type;
 	int i;
 
@@ -276,22 +294,31 @@ static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 	memset(cmd->payload_out, 0, struct_size(pl, records, 0));
 
 	log = event_find_log(dev, log_type);
-	if (!log || event_log_empty(log))
+	if (!log)
 		return 0;
 
 	pl = cmd->payload_out;
 
-	for (i = 0; i < ret_limit && !event_log_empty(log); i++) {
-		memcpy(&pl->records[i], event_get_current(log),
-		       sizeof(pl->records[i]));
-		pl->records[i].event.generic.hdr.handle =
-				event_get_cur_event_handle(log);
-		log->cur_idx++;
+	guard(read_lock)(&log->lock);
+
+	handle = log->current_handle;
+	dev_dbg(dev, "Get log %d handle %u last %u\n",
+		log_type, handle, log->last_handle);
+	for (i = 0; i < ret_limit && handle != log->last_handle;
+	     i++, handle = event_inc_handle(handle)) {
+		struct cxl_event_record_raw *cur;
+
+		cur = log->events[handle];
+		dev_dbg(dev, "Sending event log %d handle %d idx %u\n",
+			log_type, le16_to_cpu(cur->event.generic.hdr.handle),
+			handle);
+		memcpy(&pl->records[i], cur, sizeof(pl->records[i]));
+		pl->records[i].event.generic.hdr.handle = cpu_to_le16(handle);
 	}
 
 	cmd->size_out = struct_size(pl, records, i);
 	pl->record_count = cpu_to_le16(i);
-	if (!event_log_empty(log))
+	if (handle != log->last_handle)
 		pl->flags |= CXL_GET_EVENT_FLAG_MORE_RECORDS;
 
 	if (log->nr_overflow) {
@@ -313,8 +340,8 @@ static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 static int mock_clear_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 {
 	struct cxl_mbox_clear_event_payload *pl = cmd->payload_in;
-	struct mock_event_log *log;
 	u8 log_type = pl->event_log;
+	struct mock_event_log *log;
 	u16 handle;
 	int nr;
 
@@ -325,23 +352,20 @@ static int mock_clear_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 	if (!log)
 		return 0; /* No mock data in this log */
 
-	/*
-	 * This check is technically not invalid per the specification AFAICS.
-	 * (The host could 'guess' handles and clear them in order).
-	 * However, this is not good behavior for the host so test it.
-	 */
-	if (log->clear_idx + pl->nr_recs > log->cur_idx) {
-		dev_err(dev,
-			"Attempting to clear more events than returned!\n");
-		return -EINVAL;
-	}
+	guard(write_lock)(&log->lock);
 
 	/* Check handle order prior to clearing events */
-	for (nr = 0, handle = event_get_clear_handle(log);
-	     nr < pl->nr_recs;
-	     nr++, handle++) {
+	handle = log->current_handle;
+	for (nr = 0; nr < pl->nr_recs && handle != log->last_handle;
+	     nr++, handle = event_inc_handle(handle)) {
+
+		dev_dbg(dev, "Checking clear of %d handle %u plhandle %u\n",
+			log_type, handle,
+			le16_to_cpu(pl->handles[nr]));
+
 		if (handle != le16_to_cpu(pl->handles[nr])) {
-			dev_err(dev, "Clearing events out of order\n");
+			dev_err(dev, "Clearing events out of order %u %u\n",
+				handle, le16_to_cpu(pl->handles[nr]));
 			return -EINVAL;
 		}
 	}
@@ -350,25 +374,12 @@ static int mock_clear_event(struct device *dev, struct cxl_mbox_cmd *cmd)
 		log->nr_overflow = 0;
 
 	/* Clear events */
-	log->clear_idx += pl->nr_recs;
-	return 0;
-}
-
-static void cxl_mock_event_trigger(struct device *dev)
-{
-	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
-	struct mock_event_store *mes = &mdata->mes;
-	int i;
-
-	for (i = CXL_EVENT_TYPE_INFO; i < CXL_EVENT_TYPE_MAX; i++) {
-		struct mock_event_log *log;
+	for (nr = 0; nr < pl->nr_recs; nr++)
+		mes_del_event(dev, log, le16_to_cpu(pl->handles[nr]));
+	dev_dbg(dev, "Delete log %d cur %d last %d\n",
+		log_type, log->current_handle, log->last_handle);
 
-		log = event_find_log(dev, i);
-		if (log)
-			event_reset_log(log);
-	}
-
-	cxl_mem_get_event_records(mdata->mds, mes->ev_status);
+	return 0;
 }
 
 struct cxl_event_record_raw maint_needed = {
@@ -509,8 +520,27 @@ static int mock_set_timestamp(struct cxl_dev_state *cxlds,
 	return 0;
 }
 
-static void cxl_mock_add_event_logs(struct mock_event_store *mes)
+/* Create a dynamically allocated event out of a statically defined event. */
+static void add_event_from_static(struct cxl_mockmem_data *mdata,
+				  enum cxl_event_log_type log_type,
+				  struct cxl_event_record_raw *raw)
 {
+	struct device *dev = mdata->mds->cxlds.dev;
+	struct cxl_event_record_raw *rec;
+
+	rec = devm_kmemdup(dev, raw, sizeof(*rec), GFP_KERNEL);
+	if (!rec) {
+		dev_err(dev, "Failed to alloc event for log\n");
+		return;
+	}
+	mes_add_event(mdata, log_type, rec);
+}
+
+static void cxl_mock_add_event_logs(struct cxl_mockmem_data *mdata)
+{
+	struct mock_event_store *mes = &mdata->mes;
+	struct device *dev = mdata->mds->cxlds.dev;
+
 	put_unaligned_le16(CXL_GMER_VALID_CHANNEL | CXL_GMER_VALID_RANK |
 			   CXL_GMER_VALID_COMPONENT | CXL_GMER_VALID_COMPONENT_ID_FORMAT,
 			   &gen_media.rec.media_hdr.validity_flags);
@@ -523,43 +553,60 @@ static void cxl_mock_add_event_logs(struct mock_event_store *mes)
 	put_unaligned_le16(CXL_MMER_VALID_COMPONENT | CXL_MMER_VALID_COMPONENT_ID_FORMAT,
 			   &mem_module.rec.validity_flags);
 
-	mes_add_event(mes, CXL_EVENT_TYPE_INFO, &maint_needed);
-	mes_add_event(mes, CXL_EVENT_TYPE_INFO,
+	dev_dbg(dev, "Generating fake event logs %d\n",
+		CXL_EVENT_TYPE_INFO);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_INFO, &maint_needed);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_INFO,
 		      (struct cxl_event_record_raw *)&gen_media);
-	mes_add_event(mes, CXL_EVENT_TYPE_INFO,
+	add_event_from_static(mdata, CXL_EVENT_TYPE_INFO,
 		      (struct cxl_event_record_raw *)&mem_module);
 	mes->ev_status |= CXLDEV_EVENT_STATUS_INFO;
 
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &maint_needed);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL,
+	dev_dbg(dev, "Generating fake event logs %d\n",
+		CXL_EVENT_TYPE_FAIL);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &maint_needed);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL,
+		      (struct cxl_event_record_raw *)&mem_module);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL,
 		      (struct cxl_event_record_raw *)&dram);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL,
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL,
 		      (struct cxl_event_record_raw *)&gen_media);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL,
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL,
 		      (struct cxl_event_record_raw *)&mem_module);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL,
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL,
 		      (struct cxl_event_record_raw *)&dram);
 	/* Overflow this log */
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FAIL, &hardware_replace);
 	mes->ev_status |= CXLDEV_EVENT_STATUS_FAIL;
 
-	mes_add_event(mes, CXL_EVENT_TYPE_FATAL, &hardware_replace);
-	mes_add_event(mes, CXL_EVENT_TYPE_FATAL,
+	dev_dbg(dev, "Generating fake event logs %d\n",
+		CXL_EVENT_TYPE_FATAL);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FATAL, &hardware_replace);
+	add_event_from_static(mdata, CXL_EVENT_TYPE_FATAL,
 		      (struct cxl_event_record_raw *)&dram);
 	mes->ev_status |= CXLDEV_EVENT_STATUS_FATAL;
 }
 
+static void cxl_mock_event_trigger(struct device *dev)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct mock_event_store *mes = &mdata->mes;
+
+	cxl_mock_add_event_logs(mdata);
+	cxl_mem_get_event_records(mdata->mds, mes->ev_status);
+}
+
 static int mock_gsl(struct cxl_mbox_cmd *cmd)
 {
 	if (cmd->size_out < sizeof(mock_gsl_payload))
@@ -1684,6 +1731,14 @@ static void cxl_mock_test_feat_init(struct cxl_mockmem_data *mdata)
 	mdata->test_feat.data = cpu_to_le32(0xdeadbeef);
 }
 
+static void init_event_log(struct mock_event_log *log)
+{
+	rwlock_init(&log->lock);
+	/* Handle can never be 0 use 1 based indexing for handle */
+	log->current_handle = 1;
+	log->last_handle = 1;
+}
+
 static int cxl_mock_mem_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -1767,7 +1822,9 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
 	if (rc)
 		dev_dbg(dev, "No CXL Features discovered\n");
 
-	cxl_mock_add_event_logs(&mdata->mes);
+	for (int i = 0; i < CXL_EVENT_TYPE_MAX; i++)
+		init_event_log(&mdata->mes.mock_logs[i]);
+	cxl_mock_add_event_logs(mdata);
 
 	cxlmd = devm_cxl_add_memdev(cxlds, NULL);
 	if (IS_ERR(cxlmd))
Signature · 1 line
2.43.0
author
#19 lore raw

PATCH 19/20 tools/testing/cxl: Add DC Regions to mock mem data

In reply to Anisa Su

From: Ira Weiny <[email protected]>

cxl_test provides a good way to ensure quick smoke and regression testing. The complexity of Dynamic Capacity (DC) extent processing as well as the complexity of the new sparse DAX regions can mostly be tested through cxl_test. This includes management of sparse regions and DAX devices on those regions; the management of extent device lifetimes; and the processing of DCD events.

The only missing functionality from this test is actual interrupt processing.

Mock memory devices can easily mock DC information and manage fake extent data.

Define mock_dc_partition information within the mock memory data. Add sysfs entries on the mock device to inject and delete extents.

The inject format is <start>:<length>:<tag>:<more_flag> The delete format is <start>:<length>

Directly call the event irq callback to simulate irqs to process the test extents.

Add DC mailbox commands to the CEL and implement those commands.

---
Changes:
[iweiny: rebase]
[djbw: s/region/partition/]
[iweiny: s/tag/uuid/]

---
 tools/testing/cxl/test/mem.c | 753 +++++++++++++++++++++++++++++++++++
 1 file changed, 753 insertions(+)
tools/testing/cxl/test/mem.c +753 -0
index fe1dadddd18e..6e3d97dce09e 100644
@@ -20,6 +20,7 @@
 #define FW_SLOTS 3
 #define DEV_SIZE SZ_2G
 #define EFFECT(x) (1U << x)
+#define BASE_DYNAMIC_CAP_DPA DEV_SIZE
 
 #define MOCK_INJECT_DEV_MAX 8
 #define MOCK_INJECT_TEST_MAX 128
@@ -113,6 +114,22 @@ static struct cxl_cel_entry mock_cel[] = {
 				      EFFECT(SECURITY_CHANGE_IMMEDIATE) |
 				      EFFECT(BACKGROUND_OP)),
 	},
+	{
+		.opcode = cpu_to_le16(CXL_MBOX_OP_GET_DC_CONFIG),
+		.effect = CXL_CMD_EFFECT_NONE,
+	},
+	{
+		.opcode = cpu_to_le16(CXL_MBOX_OP_GET_DC_EXTENT_LIST),
+		.effect = CXL_CMD_EFFECT_NONE,
+	},
+	{
+		.opcode = cpu_to_le16(CXL_MBOX_OP_ADD_DC_RESPONSE),
+		.effect = cpu_to_le16(EFFECT(CONF_CHANGE_IMMEDIATE)),
+	},
+	{
+		.opcode = cpu_to_le16(CXL_MBOX_OP_RELEASE_DC),
+		.effect = cpu_to_le16(EFFECT(CONF_CHANGE_IMMEDIATE)),
+	},
 };
 
 /* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -173,6 +190,8 @@ struct vendor_test_feat {
 	__le32 data;
 } __packed;
 
+#define NUM_MOCK_DC_REGIONS 2
+
 struct cxl_mockmem_data {
 	void *lsa;
 	void *fw;
@@ -191,6 +210,20 @@ struct cxl_mockmem_data {
 	unsigned long sanitize_timeout;
 	struct vendor_test_feat test_feat;
 	u8 shutdown_state;
+
+	struct cxl_dc_partition dc_partitions[NUM_MOCK_DC_REGIONS];
+	u32 dc_ext_generation;
+	struct mutex ext_lock;
+
+	/*
+	 * Extents are in 1 of 3 states
+	 * FM (sysfs added but not sent to the host yet)
+	 * sent (sent to the host but not accepted)
+	 * accepted (by the host)
+	 */
+	struct xarray dc_fm_extents;
+	struct xarray dc_sent_extents;
+	struct xarray dc_accepted_exts;
 };
 
 static struct mock_event_log *event_find_log(struct device *dev, int log_type)
@@ -607,6 +640,251 @@ static void cxl_mock_event_trigger(struct device *dev)
 	cxl_mem_get_event_records(mdata->mds, mes->ev_status);
 }
 
+struct cxl_extent_data {
+	u64 dpa_start;
+	u64 length;
+	u8 uuid[UUID_SIZE];
+	bool shared;
+};
+
+static int __devm_add_extent(struct device *dev, struct xarray *array,
+			     u64 start, u64 length, const char *uuid,
+			     bool shared)
+{
+	struct cxl_extent_data *extent;
+
+	extent = devm_kzalloc(dev, sizeof(*extent), GFP_KERNEL);
+	if (!extent)
+		return -ENOMEM;
+
+	extent->dpa_start = start;
+	extent->length = length;
+	memcpy(extent->uuid, uuid, min(sizeof(extent->uuid), strlen(uuid)));
+	extent->shared = shared;
+
+	if (xa_insert(array, start, extent, GFP_KERNEL)) {
+		devm_kfree(dev, extent);
+		dev_err(dev, "Failed xarry insert %#llx\n", start);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int devm_add_fm_extent(struct device *dev, u64 start, u64 length,
+			      const char *uuid, bool shared)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+
+	guard(mutex)(&mdata->ext_lock);
+	return __devm_add_extent(dev, &mdata->dc_fm_extents, start, length,
+				 uuid, shared);
+}
+
+/* It is known that ext and the new range are not equal */
+static struct cxl_extent_data *
+split_ext(struct device *dev, struct xarray *array,
+	  struct cxl_extent_data *ext, u64 start, u64 length)
+{
+	u64 new_start, new_length;
+
+	if (ext->dpa_start == start) {
+		new_start = start + length;
+		new_length = (ext->dpa_start + ext->length) - new_start;
+
+		if (__devm_add_extent(dev, array, new_start, new_length,
+				      ext->uuid, false))
+			return NULL;
+
+		ext = xa_erase(array, ext->dpa_start);
+		if (__devm_add_extent(dev, array, start, length, ext->uuid,
+				      false))
+			return NULL;
+
+		return xa_load(array, start);
+	}
+
+	/* ext->dpa_start != start */
+
+	if (__devm_add_extent(dev, array, start, length, ext->uuid, false))
+		return NULL;
+
+	new_start = ext->dpa_start;
+	new_length = start - ext->dpa_start;
+
+	ext = xa_erase(array, ext->dpa_start);
+	if (__devm_add_extent(dev, array, new_start, new_length, ext->uuid,
+			      false))
+		return NULL;
+
+	return xa_load(array, start);
+}
+
+/*
+ * Do not handle extents which are not inside a single extent sent to
+ * the host.
+ */
+static struct cxl_extent_data *
+find_create_ext(struct device *dev, struct xarray *array, u64 start, u64 length)
+{
+	struct cxl_extent_data *ext;
+	unsigned long index;
+
+	xa_for_each(array, index, ext) {
+		u64 end = start + length;
+
+		/* start < [ext) <= start */
+		if (start < ext->dpa_start ||
+		    (ext->dpa_start + ext->length) <= start)
+			continue;
+
+		if (end <= ext->dpa_start ||
+		    (ext->dpa_start + ext->length) < end) {
+			dev_err(dev, "Invalid range %#llx-%#llx\n", start,
+				end);
+			return NULL;
+		}
+
+		break;
+	}
+
+	if (!ext)
+		return NULL;
+
+	if (start == ext->dpa_start && length == ext->length)
+		return ext;
+
+	return split_ext(dev, array, ext, start, length);
+}
+
+static int dc_accept_extent(struct device *dev, u64 start, u64 length)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_extent_data *ext;
+
+	dev_dbg(dev, "Host accepting extent %#llx\n", start);
+	mdata->dc_ext_generation++;
+
+	lockdep_assert_held(&mdata->ext_lock);
+	ext = find_create_ext(dev, &mdata->dc_sent_extents, start, length);
+	if (!ext) {
+		dev_err(dev, "Extent %#llx-%#llx not found\n",
+			start, start + length);
+		return -ENOMEM;
+	}
+	ext = xa_erase(&mdata->dc_sent_extents, ext->dpa_start);
+	return xa_insert(&mdata->dc_accepted_exts, start, ext, GFP_KERNEL);
+}
+
+static void release_dc_ext(void *md)
+{
+	struct cxl_mockmem_data *mdata = md;
+
+	xa_destroy(&mdata->dc_fm_extents);
+	xa_destroy(&mdata->dc_sent_extents);
+	xa_destroy(&mdata->dc_accepted_exts);
+}
+
+/* Pretend to have some previous accepted extents */
+struct pre_ext_info {
+	u64 offset;
+	u64 length;
+} pre_ext_info[] = {
+	{
+		.offset = SZ_128M,
+		.length = SZ_64M,
+	},
+	{
+		.offset = SZ_256M,
+		.length = SZ_64M,
+	},
+};
+
+static int devm_add_sent_extent(struct device *dev, u64 start, u64 length,
+				const char *tag, bool shared)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+
+	lockdep_assert_held(&mdata->ext_lock);
+	return __devm_add_extent(dev, &mdata->dc_sent_extents, start, length,
+				 tag, shared);
+}
+
+static int inject_prev_extents(struct device *dev, u64 base_dpa)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	int rc;
+
+	dev_dbg(dev, "Adding %ld pre-extents for testing\n",
+		ARRAY_SIZE(pre_ext_info));
+
+	guard(mutex)(&mdata->ext_lock);
+	for (int i = 0; i < ARRAY_SIZE(pre_ext_info); i++) {
+		u64 ext_dpa = base_dpa + pre_ext_info[i].offset;
+		u64 ext_len = pre_ext_info[i].length;
+
+		dev_dbg(dev, "Adding pre-extent DPA:%#llx LEN:%#llx\n",
+			ext_dpa, ext_len);
+
+		rc = devm_add_sent_extent(dev, ext_dpa, ext_len, "", false);
+		if (rc) {
+			dev_err(dev, "Failed to add pre-extent DPA:%#llx LEN:%#llx; %d\n",
+				ext_dpa, ext_len, rc);
+			return rc;
+		}
+
+		rc = dc_accept_extent(dev, ext_dpa, ext_len);
+		if (rc)
+			return rc;
+	}
+	return 0;
+}
+
+static int cxl_mock_dc_partition_setup(struct device *dev)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	u64 base_dpa = BASE_DYNAMIC_CAP_DPA;
+	u32 dsmad_handle = 0xFADE;
+	u64 decode_length = SZ_512M;
+	u64 block_size = SZ_512;
+	u64 length = SZ_512M;
+	int rc;
+
+	mutex_init(&mdata->ext_lock);
+	xa_init(&mdata->dc_fm_extents);
+	xa_init(&mdata->dc_sent_extents);
+	xa_init(&mdata->dc_accepted_exts);
+
+	rc = devm_add_action_or_reset(dev, release_dc_ext, mdata);
+	if (rc)
+		return rc;
+
+	for (int i = 0; i < NUM_MOCK_DC_REGIONS; i++) {
+		struct cxl_dc_partition *part = &mdata->dc_partitions[i];
+
+		dev_dbg(dev, "Creating DC partition DC%d DPA:%#llx LEN:%#llx\n",
+			i, base_dpa, length);
+
+		part->base = cpu_to_le64(base_dpa);
+		part->decode_length = cpu_to_le64(decode_length /
+						  CXL_CAPACITY_MULTIPLIER);
+		part->length = cpu_to_le64(length);
+		part->block_size = cpu_to_le64(block_size);
+		part->dsmad_handle = cpu_to_le32(dsmad_handle);
+		dsmad_handle++;
+
+		rc = inject_prev_extents(dev, base_dpa);
+		if (rc) {
+			dev_err(dev, "Failed to add pre-extents for DC%d\n", i);
+			return rc;
+		}
+
+		base_dpa += decode_length;
+	}
+
+	return 0;
+}
+
 static int mock_gsl(struct cxl_mbox_cmd *cmd)
 {
 	if (cmd->size_out < sizeof(mock_gsl_payload))
@@ -1582,6 +1860,192 @@ static int mock_get_supported_features(struct cxl_mockmem_data *mdata,
 	return 0;
 }
 
+static int mock_get_dc_config(struct device *dev,
+			      struct cxl_mbox_cmd *cmd)
+{
+	struct cxl_mbox_get_dc_config_in *dc_config = cmd->payload_in;
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	u8 partition_requested, partition_start_idx, partition_ret_cnt;
+	struct cxl_mbox_get_dc_config_out *resp;
+	int i;
+
+	partition_requested = min(dc_config->partition_count, NUM_MOCK_DC_REGIONS);
+
+	if (cmd->size_out < struct_size(resp, partition, partition_requested))
+		return -EINVAL;
+
+	memset(cmd->payload_out, 0, cmd->size_out);
+	resp = cmd->payload_out;
+
+	partition_start_idx = dc_config->start_partition_index;
+	partition_ret_cnt = 0;
+	for (i = 0; i < NUM_MOCK_DC_REGIONS; i++) {
+		if (i >= partition_start_idx) {
+			memcpy(&resp->partition[partition_ret_cnt],
+				&mdata->dc_partitions[i],
+				sizeof(resp->partition[partition_ret_cnt]));
+			partition_ret_cnt++;
+		}
+	}
+	resp->avail_partition_count = NUM_MOCK_DC_REGIONS;
+	resp->partitions_returned = i;
+
+	dev_dbg(dev, "Returning %d dc partitions\n", partition_ret_cnt);
+	return 0;
+}
+
+static int mock_get_dc_extent_list(struct device *dev,
+				   struct cxl_mbox_cmd *cmd)
+{
+	struct cxl_mbox_get_extent_out *resp = cmd->payload_out;
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_mbox_get_extent_in *get = cmd->payload_in;
+	u32 total_avail = 0, total_ret = 0;
+	struct cxl_extent_data *ext;
+	u32 ext_count, start_idx;
+	unsigned long i;
+
+	ext_count = le32_to_cpu(get->extent_cnt);
+	start_idx = le32_to_cpu(get->start_extent_index);
+
+	memset(resp, 0, sizeof(*resp));
+
+	guard(mutex)(&mdata->ext_lock);
+	/*
+	 * Total available needs to be calculated and returned regardless of
+	 * how many can actually be returned.
+	 */
+	xa_for_each(&mdata->dc_accepted_exts, i, ext)
+		total_avail++;
+
+	if (start_idx > total_avail)
+		return -EINVAL;
+
+	xa_for_each(&mdata->dc_accepted_exts, i, ext) {
+		if (total_ret >= ext_count)
+			break;
+
+		if (total_ret >= start_idx) {
+			resp->extent[total_ret].start_dpa =
+						cpu_to_le64(ext->dpa_start);
+			resp->extent[total_ret].length =
+						cpu_to_le64(ext->length);
+			memcpy(&resp->extent[total_ret].uuid, ext->uuid,
+					sizeof(resp->extent[total_ret]));
+			total_ret++;
+		}
+	}
+
+	resp->returned_extent_count = cpu_to_le32(total_ret);
+	resp->total_extent_count = cpu_to_le32(total_avail);
+	resp->generation_num = cpu_to_le32(mdata->dc_ext_generation);
+
+	dev_dbg(dev, "Returning %d extents of %d total\n",
+		total_ret, total_avail);
+
+	return 0;
+}
+
+static void dc_clear_sent(struct device *dev)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_extent_data *ext;
+	unsigned long index;
+
+	lockdep_assert_held(&mdata->ext_lock);
+
+	/* Any extents not accepted must be cleared */
+	xa_for_each(&mdata->dc_sent_extents, index, ext) {
+		dev_dbg(dev, "Host rejected extent %#llx\n", ext->dpa_start);
+		xa_erase(&mdata->dc_sent_extents, ext->dpa_start);
+	}
+}
+
+static int mock_add_dc_response(struct device *dev,
+				struct cxl_mbox_cmd *cmd)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_mbox_dc_response *req = cmd->payload_in;
+	u32 list_size = le32_to_cpu(req->extent_list_size);
+
+	guard(mutex)(&mdata->ext_lock);
+	for (int i = 0; i < list_size; i++) {
+		u64 start = le64_to_cpu(req->extent_list[i].dpa_start);
+		u64 length = le64_to_cpu(req->extent_list[i].length);
+		int rc;
+
+		rc = dc_accept_extent(dev, start, length);
+		if (rc)
+			return rc;
+	}
+
+	dc_clear_sent(dev);
+	return 0;
+}
+
+static void dc_delete_extent(struct device *dev, unsigned long long start,
+			     unsigned long long length)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	unsigned long long end = start + length;
+	struct cxl_extent_data *ext;
+	unsigned long index;
+
+	dev_dbg(dev, "Deleting extent at %#llx len:%#llx\n", start, length);
+
+	guard(mutex)(&mdata->ext_lock);
+	xa_for_each(&mdata->dc_fm_extents, index, ext) {
+		u64 extent_end = ext->dpa_start + ext->length;
+
+		/*
+		 * Any extent which 'touches' the released delete range will be
+		 * removed.
+		 */
+		if ((start <= ext->dpa_start && ext->dpa_start < end) ||
+		    (start <= extent_end && extent_end < end))
+			xa_erase(&mdata->dc_fm_extents, ext->dpa_start);
+	}
+
+	/*
+	 * If the extent was accepted let it be for the host to drop
+	 * later.
+	 */
+}
+
+static int release_accepted_extent(struct device *dev, u64 start, u64 length)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_extent_data *ext;
+
+	guard(mutex)(&mdata->ext_lock);
+	ext = find_create_ext(dev, &mdata->dc_accepted_exts, start, length);
+	if (!ext) {
+		dev_err(dev, "Extent %#llx not in accepted state\n", start);
+		return -EINVAL;
+	}
+	xa_erase(&mdata->dc_accepted_exts, ext->dpa_start);
+	mdata->dc_ext_generation++;
+
+	return 0;
+}
+
+static int mock_dc_release(struct device *dev,
+			   struct cxl_mbox_cmd *cmd)
+{
+	struct cxl_mbox_dc_response *req = cmd->payload_in;
+	u32 list_size = le32_to_cpu(req->extent_list_size);
+
+	for (int i = 0; i < list_size; i++) {
+		u64 start = le64_to_cpu(req->extent_list[i].dpa_start);
+		u64 length = le64_to_cpu(req->extent_list[i].length);
+
+		dev_dbg(dev, "Extent %#llx released by host\n", start);
+		release_accepted_extent(dev, start, length);
+	}
+
+	return 0;
+}
+
 static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,
 			      struct cxl_mbox_cmd *cmd)
 {
@@ -1673,6 +2137,18 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,
 	case CXL_MBOX_OP_GET_SUPPORTED_FEATURES:
 		rc = mock_get_supported_features(mdata, cmd);
 		break;
+	case CXL_MBOX_OP_GET_DC_CONFIG:
+		rc = mock_get_dc_config(dev, cmd);
+		break;
+	case CXL_MBOX_OP_GET_DC_EXTENT_LIST:
+		rc = mock_get_dc_extent_list(dev, cmd);
+		break;
+	case CXL_MBOX_OP_ADD_DC_RESPONSE:
+		rc = mock_add_dc_response(dev, cmd);
+		break;
+	case CXL_MBOX_OP_RELEASE_DC:
+		rc = mock_dc_release(dev, cmd);
+		break;
 	case CXL_MBOX_OP_GET_FEATURE:
 		rc = mock_get_feature(mdata, cmd);
 		break;
@@ -1758,6 +2234,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	dev_set_drvdata(dev, mdata);
 
+	rc = cxl_mock_dc_partition_setup(dev);
+	if (rc)
+		return rc;
+
 	mdata->lsa = vmalloc(LSA_SIZE);
 	if (!mdata->lsa)
 		return -ENOMEM;
@@ -1814,6 +2294,9 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
 	if (rc)
 		return rc;
 
+	if (cxl_dcd_supported(mds))
+		cxl_configure_dcd(mds, &range_info);
+
 	rc = cxl_dpa_setup(cxlds, &range_info);
 	if (rc)
 		return rc;
@@ -1921,11 +2404,281 @@ static ssize_t sanitize_timeout_store(struct device *dev,
 
 static DEVICE_ATTR_RW(sanitize_timeout);
 
+/* Return if the proposed extent would break the test code */
+static bool new_extent_valid(struct device *dev, size_t new_start,
+			     size_t new_len)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_extent_data *extent;
+	size_t new_end, i;
+
+	if (!new_len)
+		return false;
+
+	new_end = new_start + new_len;
+
+	dev_dbg(dev, "New extent %zx-%zx\n", new_start, new_end);
+
+	guard(mutex)(&mdata->ext_lock);
+	dev_dbg(dev, "Checking extents starts...\n");
+	xa_for_each(&mdata->dc_fm_extents, i, extent) {
+		if (extent->dpa_start == new_start)
+			return false;
+	}
+
+	dev_dbg(dev, "Checking sent extents starts...\n");
+	xa_for_each(&mdata->dc_sent_extents, i, extent) {
+		if (extent->dpa_start == new_start)
+			return false;
+	}
+
+	dev_dbg(dev, "Checking accepted extents starts...\n");
+	xa_for_each(&mdata->dc_accepted_exts, i, extent) {
+		if (extent->dpa_start == new_start)
+			return false;
+	}
+
+	return true;
+}
+
+struct cxl_test_dcd {
+	uuid_t id;
+	struct cxl_event_dcd rec;
+} __packed;
+
+struct cxl_test_dcd dcd_event_rec_template = {
+	.id = CXL_EVENT_DC_EVENT_UUID,
+	.rec = {
+		.hdr = {
+			.length = sizeof(struct cxl_test_dcd),
+		},
+	},
+};
+
+static int log_dc_event(struct cxl_mockmem_data *mdata, enum dc_event type,
+			u64 start, u64 length, const char *tag_str, bool more)
+{
+	struct device *dev = mdata->mds->cxlds.dev;
+	struct cxl_test_dcd *dcd_event;
+
+	dev_dbg(dev, "mock device log event %d\n", type);
+
+	dcd_event = devm_kmemdup(dev, &dcd_event_rec_template,
+				     sizeof(*dcd_event), GFP_KERNEL);
+	if (!dcd_event)
+		return -ENOMEM;
+
+	dcd_event->rec.flags = 0;
+	if (more)
+		dcd_event->rec.flags |= CXL_DCD_EVENT_MORE;
+	dcd_event->rec.event_type = type;
+	dcd_event->rec.extent.start_dpa = cpu_to_le64(start);
+	dcd_event->rec.extent.length = cpu_to_le64(length);
+	memcpy(dcd_event->rec.extent.uuid, tag_str,
+	       min(sizeof(dcd_event->rec.extent.uuid),
+		   strlen(tag_str)));
+
+	mes_add_event(mdata, CXL_EVENT_TYPE_DCD,
+		      (struct cxl_event_record_raw *)dcd_event);
+
+	/* Fake the irq */
+	cxl_mem_get_event_records(mdata->mds, CXLDEV_EVENT_STATUS_DCD);
+
+	return 0;
+}
+
+static void mark_extent_sent(struct device *dev, unsigned long long start)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	struct cxl_extent_data *ext;
+
+	guard(mutex)(&mdata->ext_lock);
+	ext = xa_erase(&mdata->dc_fm_extents, start);
+	if (xa_insert(&mdata->dc_sent_extents, ext->dpa_start, ext, GFP_KERNEL))
+		dev_err(dev, "Failed to mark extent %#llx sent\n", ext->dpa_start);
+}
+
+/*
+ * Format <start>:<length>:<tag>:<more_flag>
+ *
+ * start and length must be a multiple of the configured partition block size.
+ * Tag can be any string up to 16 bytes.
+ *
+ * Extents must be exclusive of other extents
+ *
+ * If the more flag is specified it is expected that an additional extent will
+ * be specified without the more flag to complete the test transaction with the
+ * host.
+ */
+static ssize_t __dc_inject_extent_store(struct device *dev,
+					struct device_attribute *attr,
+					const char *buf, size_t count,
+					bool shared)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	unsigned long long start, length, more;
+	char *len_str, *uuid_str, *more_str;
+	size_t buf_len = count;
+	int rc;
+
+	char *start_str __free(kfree) = kstrdup(buf, GFP_KERNEL);
+	if (!start_str)
+		return -ENOMEM;
+
+	len_str = strnchr(start_str, buf_len, ':');
+	if (!len_str) {
+		dev_err(dev, "Extent failed to find len_str: %s\n", start_str);
+		return -EINVAL;
+	}
+
+	*len_str = '\0';
+	len_str += 1;
+	buf_len -= strlen(start_str);
+
+	uuid_str = strnchr(len_str, buf_len, ':');
+	if (!uuid_str) {
+		dev_err(dev, "Extent failed to find uuid_str: %s\n", len_str);
+		return -EINVAL;
+	}
+	*uuid_str = '\0';
+	uuid_str += 1;
+
+	more_str = strnchr(uuid_str, buf_len, ':');
+	if (!more_str) {
+		dev_err(dev, "Extent failed to find more_str: %s\n", uuid_str);
+		return -EINVAL;
+	}
+	*more_str = '\0';
+	more_str += 1;
+
+	if (kstrtoull(start_str, 0, &start)) {
+		dev_err(dev, "Extent failed to parse start: %s\n", start_str);
+		return -EINVAL;
+	}
+
+	if (kstrtoull(len_str, 0, &length)) {
+		dev_err(dev, "Extent failed to parse length: %s\n", len_str);
+		return -EINVAL;
+	}
+
+	if (kstrtoull(more_str, 0, &more)) {
+		dev_err(dev, "Extent failed to parse more: %s\n", more_str);
+		return -EINVAL;
+	}
+
+	if (!new_extent_valid(dev, start, length))
+		return -EINVAL;
+
+	rc = devm_add_fm_extent(dev, start, length, uuid_str, shared);
+	if (rc) {
+		dev_err(dev, "Failed to add extent DPA:%#llx LEN:%#llx; %d\n",
+			start, length, rc);
+		return rc;
+	}
+
+	mark_extent_sent(dev, start);
+	rc = log_dc_event(mdata, DCD_ADD_CAPACITY, start, length, uuid_str, more);
+	if (rc) {
+		dev_err(dev, "Failed to add event %d\n", rc);
+		return rc;
+	}
+
+	return count;
+}
+
+static ssize_t dc_inject_extent_store(struct device *dev,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	return __dc_inject_extent_store(dev, attr, buf, count, false);
+}
+static DEVICE_ATTR_WO(dc_inject_extent);
+
+static ssize_t dc_inject_shared_extent_store(struct device *dev,
+					     struct device_attribute *attr,
+					     const char *buf, size_t count)
+{
+	return __dc_inject_extent_store(dev, attr, buf, count, true);
+}
+static DEVICE_ATTR_WO(dc_inject_shared_extent);
+
+static ssize_t __dc_del_extent_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count,
+				     enum dc_event type)
+{
+	struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
+	unsigned long long start, length;
+	char *len_str;
+	int rc;
+
+	char *start_str __free(kfree) = kstrdup(buf, GFP_KERNEL);
+	if (!start_str)
+		return -ENOMEM;
+
+	len_str = strnchr(start_str, count, ':');
+	if (!len_str) {
+		dev_err(dev, "Failed to find len_str: %s\n", start_str);
+		return -EINVAL;
+	}
+	*len_str = '\0';
+	len_str += 1;
+
+	if (kstrtoull(start_str, 0, &start)) {
+		dev_err(dev, "Failed to parse start: %s\n", start_str);
+		return -EINVAL;
+	}
+
+	if (kstrtoull(len_str, 0, &length)) {
+		dev_err(dev, "Failed to parse length: %s\n", len_str);
+		return -EINVAL;
+	}
+
+	dc_delete_extent(dev, start, length);
+
+	if (type == DCD_FORCED_CAPACITY_RELEASE)
+		dev_dbg(dev, "Forcing delete of extent %#llx len:%#llx\n",
+			start, length);
+
+	rc = log_dc_event(mdata, type, start, length, "", false);
+	if (rc) {
+		dev_err(dev, "Failed to add event %d\n", rc);
+		return rc;
+	}
+
+	return count;
+}
+
+/*
+ * Format <start>:<length>
+ */
+static ssize_t dc_del_extent_store(struct device *dev,
+				   struct device_attribute *attr,
+				   const char *buf, size_t count)
+{
+	return __dc_del_extent_store(dev, attr, buf, count,
+				     DCD_RELEASE_CAPACITY);
+}
+static DEVICE_ATTR_WO(dc_del_extent);
+
+static ssize_t dc_force_del_extent_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t count)
+{
+	return __dc_del_extent_store(dev, attr, buf, count,
+				     DCD_FORCED_CAPACITY_RELEASE);
+}
+static DEVICE_ATTR_WO(dc_force_del_extent);
+
 static struct attribute *cxl_mock_mem_attrs[] = {
 	&dev_attr_security_lock.attr,
 	&dev_attr_event_trigger.attr,
 	&dev_attr_fw_buf_checksum.attr,
 	&dev_attr_sanitize_timeout.attr,
+	&dev_attr_dc_inject_extent.attr,
+	&dev_attr_dc_inject_shared_extent.attr,
+	&dev_attr_dc_del_extent.attr,
+	&dev_attr_dc_force_del_extent.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(cxl_mock_mem);
Signature · 1 line
2.43.0
author
#20 lore raw

PATCH 20/20 dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

In reply to Anisa Su

Change DC region driver type from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to fsdev driver

---
 drivers/dax/bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dax/bus.c +2 -1
index 2ada38fa7dca..a9b25046d845 100644
@@ -71,7 +71,8 @@ static int dax_match_type(const struct dax_device_driver *dax_drv, struct device
 	enum dax_driver_type type = DAXDRV_DEVICE_TYPE;
 	struct dev_dax *dev_dax = to_dev_dax(dev);
 
-	if (dev_dax->region->res.flags & IORESOURCE_DAX_KMEM)
+	if (dev_dax->region->res.flags & IORESOURCE_DAX_KMEM &&
+	    !(dev_dax->region->res.flags & IORESOURCE_DAX_SPARSE_CAP))
 		type = DAXDRV_KMEM_TYPE;
 
 	if (dax_drv->type == type)
Signature · 1 line
2.43.0
#21 lore raw
In reply to Anisa Su
Quoted 11 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

Quoted 4 lines

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order.

Are you saying they need to be contiguous in DPA? I don't think that's what we want - in fact that's actually somewhat defeats the entire point of DCD being allocator-like.

We don't much care what DPA space the extents take up so long as the total size of the set of extents matches the size of the HPA region.

Sorting by DPA at least gets you extent-ordering for free as a pre-agreed upon mechanism, so that's fine.

Basically: we don't want sparse regions where the HPA space has holes (i.e. an extent hasn't been sent by the device to back the hole yet), but we don't really care what DPA actually backs those HPA regions.

Unless my take on how DCD "should" work is wildly different from the general understand.

~Gregory

author
#22 lore raw
Quoted 27 lines · Gregory Price
Quoted 11 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

Quoted 4 lines

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order.

Are you saying they need to be contiguous in DPA? I don't think that's what we want - in fact that's actually somewhat defeats the entire point of DCD being allocator-like.

We don't much care what DPA space the extents take up so long as the total size of the set of extents matches the size of the HPA region.

Sorting by DPA at least gets you extent-ordering for free as a pre-agreed upon mechanism, so that's fine.

Quoted 8 lines

Basically: we don't want sparse regions where the HPA space has holes (i.e. an extent hasn't been sent by the device to back the hole yet), but we don't really care what DPA actually backs those HPA regions.

Unless my take on how DCD "should" work is wildly different from the general understand.

~Gregory

Super belated follow up to document some discussion from last Monday's DAX call:

Instead of enforcing contiguous DPA, what we mean by not supporting sparse regions means that each DAX *device* needs to be fully backed by extents?

- The CXL region/DAX region itself can be made of multiple DAX devices, and there can be HPA gaps between the devices, so the CXL region can be "sparse"
- But each DAX device must be fully backed (non-sparse)

We potentially want to do something like "daxctl prepare-device daxX.Y" to set up an "empty" DAX device? Then as extents come in, make sure they cover the full range of the device?
- Add some kind of timeout to receive extents that back the device
- If not fully backed within timeout, release all and destroy device

That's kind of my understanding after letting it marinate in my brain... pls correct if that's wrong

One quick question I currently have is: in this scenario, we expect the orchestrator to coordinate the "daxctl prepare-device daxX.Y"? Is that correct?

Thanks,
Anisa

#23 lore raw
Quoted 46 lines · Anisa Su
Quoted 27 lines · Gregory Price
Quoted 11 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

Quoted 4 lines

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order.

Are you saying they need to be contiguous in DPA? I don't think that's what we want - in fact that's actually somewhat defeats the entire point of DCD being allocator-like.

We don't much care what DPA space the extents take up so long as the total size of the set of extents matches the size of the HPA region.

Sorting by DPA at least gets you extent-ordering for free as a pre-agreed upon mechanism, so that's fine.

Quoted 8 lines

Basically: we don't want sparse regions where the HPA space has holes (i.e. an extent hasn't been sent by the device to back the hole yet), but we don't really care what DPA actually backs those HPA regions.

Unless my take on how DCD "should" work is wildly different from the general understand.

~Gregory

Super belated follow up to document some discussion from last Monday's DAX call:

Instead of enforcing contiguous DPA, what we mean by not supporting sparse regions means that each DAX *device* needs to be fully backed by extents?

- The CXL region/DAX region itself can be made of multiple DAX devices, and there can be HPA gaps between the devices, so the CXL region can be "sparse"
- But each DAX device must be fully backed (non-sparse)

Quoted 5 lines

We potentially want to do something like "daxctl prepare-device daxX.Y" to set up an "empty" DAX device? Then as extents come in, make sure they cover the full range of the device?
- Add some kind of timeout to receive extents that back the device
- If not fully backed within timeout, release all and destroy device

I don't think a strict timeout is needed here. If prepare-device does not actually surface a dax device until all extents are there a subsequent destroy-device (prior to all the extents being there) could release all the extents which were there. Basically allow user space to handle any 'timeout'. It could even decide to ask the orchestrator what to do at that point and either wait or unwind.

Quoted 6 lines

That's kind of my understanding after letting it marinate in my brain... pls correct if that's wrong

One quick question I currently have is: in this scenario, we expect the orchestrator to coordinate the "daxctl prepare-device daxX.Y"? Is that correct?

I would think so yes.

Ira

Quoted 3 lines

Thanks,
Anisa

#24 lore raw
In reply to Anisa Su
Quoted 238 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

This patchset was tested with Ali's QEMU patchset adding tag support:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Details:

Topology: '-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=12G \
     -object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1G \
     -device usb-ehci,id=ehci \
     -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
     -device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
     -device cxl-type3,bus=cxl_rp_port0,id=cxl-dcd0,dc-regions-total-size=12G,num-dc-regions=1,sn=99 \
     -device usb-cxl-mctp,bus=ehci.0,id=usb1,target=cxl-dcd0\
     -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=12G,cxl-fmw.0.interleave-granularity=1k'

1. Start VM (12GB)
2. Issue QMP to add tagged backend (8GB):
{ "execute": "qmp_capabilities" }

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 8589934592,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
3. Create region on the VM: cxl create-region -m -d decoder0.0 -w 1 -s 8G mem0 -t dynamic_ram_a
4. Issue QMP to add an 8GB extent:
{ "execute": "qmp_capabilities" }
{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-dcd0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 8589934592
            }
        ]
    }
}
5. Verify with sysfs:
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/offset
0x0
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/length
0x200000000
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/uuid
5be13bce-ae34-4a77-b6c3-16df975fcf1a

6. daxctl create-device -r region0
[

  {
    "chardev":"dax0.1",
    "size":8589934592,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"

}
]
created 1 device

Currently, QEMU only supports sending 1 extent in an add/release request, which limits what I can test. However, I was able to verify that once extent(s) have been added to a region, it can't be added to again (size cannot be increased).

Up to this point is what I test with this patchset. Then below is the additional famfs tests for the version applied on famfs.
================================================================================
7. Install famfs userspace tool:
https://github.com/cxl-micron-reskit/famfs

8.mkfs.famfs --v /dev/dax0.1 output:
devsize: 8589934592
Famfs Superblock:

  Filesystem UUID:   c33b4525-a2c7-4d64-9204-e8ed273b4ffb
  Device UUID:       ae887e6b-f886-45f9-bc55-f0696f3cd91d
  System UUID:       da314140-12e7-45c2-98b2-753d3bfe4f46

role of this node: Owner
alloc_unit: 0x200000
OMF major version: 2
OMF minor version: 1
sizeof superblock: 200
log size (bytes): 8388608
primary: /dev/dax0.1 8589934592

Log stats:

  # of log entries in use: 0 of 15420
  Log size in use:          48
  Log size (total bytes)    8388608
  No allocation errors found

Capacity:

  Device capacity:        8.00G
  Bitmap capacity:        8.00G
  Sum of file sizes:      0.00G
  Allocated space:        0.01G
  Free space:             7.99G

Space amplification: inf
Percent used: 0.1%

Famfs log:
0 of 15420 entries used
0 bad log entries detected
0 files
0 directories

9. famfs smoke tests also succeed. The smoke tests include some fio tests, which run some simulated workloads

:== Test Timing Summary :==-------------------------------------------------------------------

:==  prepare              0:10
:==  test0                0:07
:==  test_shadow_yaml     0:04
:==  test1                0:22
:==  test2                0:12
:==  test3                0:03
:==  test4                0:10
:==  test_errors          0:01
:==  stripe_test          0:58
:==  test_pcq             1:26
:==  test_fio             0:34

:==-------------------------------------------------------------------
:== TOTAL 4:27
:==------------------------------------------------------------------- :==run_smoke completed successfully (Thu Apr 9 10:33:28 PM UTC 2026)

Anisa Su (1):
dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

Ira Weiny (19):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/cdat: Gather DSMAS data for DCD partitions cxl/core: Enforce partition order/simplify partition calls cxl/mem: Expose dynamic ram A partition in sysfs cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode cxl/region: Add sparse DAX region support
cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/mem: Configure dynamic capacity interrupts cxl/core: Return endpoint decoder information from region search cxl/extent: Process dynamic partition events and realize region
extents
cxl/region/extent: Expose region extent information in sysfs dax/bus: Factor out dev dax resize logic
dax/region: Create resources on DAX regions cxl/region: Read existing extents on region creation cxl/mem: Trace Dynamic capacity Event Record tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

 Documentation/ABI/testing/sysfs-bus-cxl |  100 ++-
 drivers/cxl/core/Makefile               |    2 +-
 drivers/cxl/core/cdat.c                 |   11 +
 drivers/cxl/core/core.h                 |   47 +-
 drivers/cxl/core/extent.c               |  471 +++++++++++
 drivers/cxl/core/hdm.c                  |   13 +-
 drivers/cxl/core/mbox.c                 |  770 ++++++++++++++++-
 drivers/cxl/core/memdev.c               |   87 +-
 drivers/cxl/core/port.c                 |    5 +
 drivers/cxl/core/region.c               |   43 +-
 drivers/cxl/core/region_dax.c           |    6 +
 drivers/cxl/core/trace.h                |   65 ++
 drivers/cxl/cxl.h                       |   60 +-
 drivers/cxl/cxlmem.h                    |  124 ++-
 drivers/cxl/mem.c                       |    2 +-
 drivers/cxl/pci.c                       |  115 ++-
 drivers/dax/bus.c                       |  360 ++++++--
 drivers/dax/bus.h                       |    4 +-
 drivers/dax/cxl.c                       |   71 +-
 drivers/dax/dax-private.h               |   40 +
 drivers/dax/hmem/hmem.c                 |    2 +-
Quoted 12 lines
 drivers/dax/pmem.c                      |    2 +-
 include/cxl/cxl.h                       |    6 +
 include/cxl/event.h                     |   39 +
 include/linux/ioport.h                  |    3 +
 tools/testing/cxl/Kbuild                |    5 +-
 tools/testing/cxl/test/mem.c            | 1018 ++++++++++++++++++++---
 27 files changed, 3210 insertions(+), 261 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
Signature · 1 line
2.43.0

what commit or branch does this apply on top of? Not v7.0...

Thanks!
John

author
#25 lore raw
Quoted 248 lines · John Groves
Quoted 247 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

i've tacked on 1 commit at the end to change the driver type of dc regions from daxdrv_kmem_type to daxdrv_device_type so it can be bound to the new fsdev driver.

also, i've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so i hope that's clear.

================================================================================
git history

this series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

This patchset was tested with Ali's QEMU patchset adding tag support:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Details:

Topology: '-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=12G \
     -object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1G \
     -device usb-ehci,id=ehci \
     -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
     -device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
     -device cxl-type3,bus=cxl_rp_port0,id=cxl-dcd0,dc-regions-total-size=12G,num-dc-regions=1,sn=99 \
     -device usb-cxl-mctp,bus=ehci.0,id=usb1,target=cxl-dcd0\
     -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=12G,cxl-fmw.0.interleave-granularity=1k'

1. Start VM (12GB)
2. Issue QMP to add tagged backend (8GB):
{ "execute": "qmp_capabilities" }

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 8589934592,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
3. Create region on the VM: cxl create-region -m -d decoder0.0 -w 1 -s 8G mem0 -t dynamic_ram_a
4. Issue QMP to add an 8GB extent:
{ "execute": "qmp_capabilities" }
{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-dcd0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 8589934592
            }
        ]
    }
}
5. Verify with sysfs:
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/offset
0x0
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/length
0x200000000
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/uuid
5be13bce-ae34-4a77-b6c3-16df975fcf1a

6. daxctl create-device -r region0
[

  {
    "chardev":"dax0.1",
    "size":8589934592,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"

}
]
created 1 device

Currently, QEMU only supports sending 1 extent in an add/release request, which limits what I can test. However, I was able to verify that once extent(s) have been added to a region, it can't be added to again (size cannot be increased).

Up to this point is what I test with this patchset. Then below is the additional famfs tests for the version applied on famfs.
================================================================================
7. Install famfs userspace tool:
https://github.com/cxl-micron-reskit/famfs

8.mkfs.famfs --v /dev/dax0.1 output:
devsize: 8589934592
Famfs Superblock:

  Filesystem UUID:   c33b4525-a2c7-4d64-9204-e8ed273b4ffb
  Device UUID:       ae887e6b-f886-45f9-bc55-f0696f3cd91d
  System UUID:       da314140-12e7-45c2-98b2-753d3bfe4f46

role of this node: Owner
alloc_unit: 0x200000
OMF major version: 2
OMF minor version: 1
sizeof superblock: 200
log size (bytes): 8388608
primary: /dev/dax0.1 8589934592

Log stats:

  # of log entries in use: 0 of 15420
  Log size in use:          48
  Log size (total bytes)    8388608
  No allocation errors found

Capacity:

  Device capacity:        8.00G
  Bitmap capacity:        8.00G
  Sum of file sizes:      0.00G
  Allocated space:        0.01G
  Free space:             7.99G

Space amplification: inf
Percent used: 0.1%

Famfs log:
0 of 15420 entries used
0 bad log entries detected
0 files
0 directories

9. famfs smoke tests also succeed. The smoke tests include some fio tests, which run some simulated workloads

:== Test Timing Summary :==-------------------------------------------------------------------

:==  prepare              0:10
:==  test0                0:07
:==  test_shadow_yaml     0:04
:==  test1                0:22
:==  test2                0:12
:==  test3                0:03
:==  test4                0:10
:==  test_errors          0:01
:==  stripe_test          0:58
:==  test_pcq             1:26
:==  test_fio             0:34

:==-------------------------------------------------------------------
:== TOTAL 4:27
:==------------------------------------------------------------------- :==run_smoke completed successfully (Thu Apr 9 10:33:28 PM UTC 2026)

Anisa Su (1):
dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

Ira Weiny (19):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/cdat: Gather DSMAS data for DCD partitions cxl/core: Enforce partition order/simplify partition calls cxl/mem: Expose dynamic ram A partition in sysfs cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode cxl/region: Add sparse DAX region support
cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/mem: Configure dynamic capacity interrupts cxl/core: Return endpoint decoder information from region search cxl/extent: Process dynamic partition events and realize region
extents
cxl/region/extent: Expose region extent information in sysfs dax/bus: Factor out dev dax resize logic
dax/region: Create resources on DAX regions cxl/region: Read existing extents on region creation cxl/mem: Trace Dynamic capacity Event Record tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

 Documentation/ABI/testing/sysfs-bus-cxl |  100 ++-
 drivers/cxl/core/Makefile               |    2 +-
 drivers/cxl/core/cdat.c                 |   11 +
 drivers/cxl/core/core.h                 |   47 +-
 drivers/cxl/core/extent.c               |  471 +++++++++++
 drivers/cxl/core/hdm.c                  |   13 +-
 drivers/cxl/core/mbox.c                 |  770 ++++++++++++++++-
 drivers/cxl/core/memdev.c               |   87 +-
 drivers/cxl/core/port.c                 |    5 +
 drivers/cxl/core/region.c               |   43 +-
 drivers/cxl/core/region_dax.c           |    6 +
 drivers/cxl/core/trace.h                |   65 ++
 drivers/cxl/cxl.h                       |   60 +-
 drivers/cxl/cxlmem.h                    |  124 ++-
 drivers/cxl/mem.c                       |    2 +-
 drivers/cxl/pci.c                       |  115 ++-
 drivers/dax/bus.c                       |  360 ++++++--
 drivers/dax/bus.h                       |    4 +-
 drivers/dax/cxl.c                       |   71 +-
 drivers/dax/dax-private.h               |   40 +
 drivers/dax/hmem/hmem.c                 |    2 +-
 drivers/dax/pmem.c                      |    2 +-
 include/cxl/cxl.h                       |    6 +
 include/cxl/event.h                     |   39 +
 include/linux/ioport.h                  |    3 +
 tools/testing/cxl/Kbuild                |    5 +-
 tools/testing/cxl/test/mem.c            | 1018 ++++++++++++++++++++---
 27 files changed, 3210 insertions(+), 261 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
Quoted 6 lines
Quoted 3 lines
Signature · 1 line
2.43.0

what commit or branch does this apply on top of? Not v7.0...

This series was based on cxl-for-next: 3939dba00f98 Merge branch 'for-7.1/cxl-misc' But I was dumb while resolving the merge conflicts when I rebased and dropped 1 loc which I need to add back in :( sorry...

But I also have a version of this that's based on famfs-v9, which I used to run the famfs smoke tests. It's on github:
https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd

or I can send you the patches separately?

- Anisa

Quoted 2 lines

Thanks!
John

#26 lore raw
In reply to John Groves
Quoted 248 lines · John Groves
Quoted 247 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

This patchset was tested with Ali's QEMU patchset adding tag support:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Details:

Topology: '-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=12G \
     -object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1G \
     -device usb-ehci,id=ehci \
     -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
     -device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
     -device cxl-type3,bus=cxl_rp_port0,id=cxl-dcd0,dc-regions-total-size=12G,num-dc-regions=1,sn=99 \
     -device usb-cxl-mctp,bus=ehci.0,id=usb1,target=cxl-dcd0\
     -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=12G,cxl-fmw.0.interleave-granularity=1k'

1. Start VM (12GB)
2. Issue QMP to add tagged backend (8GB):
{ "execute": "qmp_capabilities" }

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 8589934592,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
3. Create region on the VM: cxl create-region -m -d decoder0.0 -w 1 -s 8G mem0 -t dynamic_ram_a
4. Issue QMP to add an 8GB extent:
{ "execute": "qmp_capabilities" }
{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-dcd0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 8589934592
            }
        ]
    }
}
5. Verify with sysfs:
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/offset
0x0
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/length
0x200000000
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/uuid
5be13bce-ae34-4a77-b6c3-16df975fcf1a

6. daxctl create-device -r region0
[

  {
    "chardev":"dax0.1",
    "size":8589934592,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"

}
]
created 1 device

Currently, QEMU only supports sending 1 extent in an add/release request, which limits what I can test. However, I was able to verify that once extent(s) have been added to a region, it can't be added to again (size cannot be increased).

Up to this point is what I test with this patchset. Then below is the additional famfs tests for the version applied on famfs.
================================================================================
7. Install famfs userspace tool:
https://github.com/cxl-micron-reskit/famfs

8.mkfs.famfs --v /dev/dax0.1 output:
devsize: 8589934592
Famfs Superblock:

  Filesystem UUID:   c33b4525-a2c7-4d64-9204-e8ed273b4ffb
  Device UUID:       ae887e6b-f886-45f9-bc55-f0696f3cd91d
  System UUID:       da314140-12e7-45c2-98b2-753d3bfe4f46

role of this node: Owner
alloc_unit: 0x200000
OMF major version: 2
OMF minor version: 1
sizeof superblock: 200
log size (bytes): 8388608
primary: /dev/dax0.1 8589934592

Log stats:

  # of log entries in use: 0 of 15420
  Log size in use:          48
  Log size (total bytes)    8388608
  No allocation errors found

Capacity:

  Device capacity:        8.00G
  Bitmap capacity:        8.00G
  Sum of file sizes:      0.00G
  Allocated space:        0.01G
  Free space:             7.99G

Space amplification: inf
Percent used: 0.1%

Famfs log:
0 of 15420 entries used
0 bad log entries detected
0 files
0 directories

9. famfs smoke tests also succeed. The smoke tests include some fio tests, which run some simulated workloads

:== Test Timing Summary :==-------------------------------------------------------------------

:==  prepare              0:10
:==  test0                0:07
:==  test_shadow_yaml     0:04
:==  test1                0:22
:==  test2                0:12
:==  test3                0:03
:==  test4                0:10
:==  test_errors          0:01
:==  stripe_test          0:58
:==  test_pcq             1:26
:==  test_fio             0:34

:==-------------------------------------------------------------------
:== TOTAL 4:27
:==------------------------------------------------------------------- :==run_smoke completed successfully (Thu Apr 9 10:33:28 PM UTC 2026)

Anisa Su (1):
dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

Ira Weiny (19):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/cdat: Gather DSMAS data for DCD partitions cxl/core: Enforce partition order/simplify partition calls cxl/mem: Expose dynamic ram A partition in sysfs cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode cxl/region: Add sparse DAX region support
cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/mem: Configure dynamic capacity interrupts cxl/core: Return endpoint decoder information from region search cxl/extent: Process dynamic partition events and realize region
extents
cxl/region/extent: Expose region extent information in sysfs dax/bus: Factor out dev dax resize logic
dax/region: Create resources on DAX regions cxl/region: Read existing extents on region creation cxl/mem: Trace Dynamic capacity Event Record tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

 Documentation/ABI/testing/sysfs-bus-cxl |  100 ++-
 drivers/cxl/core/Makefile               |    2 +-
 drivers/cxl/core/cdat.c                 |   11 +
 drivers/cxl/core/core.h                 |   47 +-
 drivers/cxl/core/extent.c               |  471 +++++++++++
 drivers/cxl/core/hdm.c                  |   13 +-
 drivers/cxl/core/mbox.c                 |  770 ++++++++++++++++-
 drivers/cxl/core/memdev.c               |   87 +-
 drivers/cxl/core/port.c                 |    5 +
 drivers/cxl/core/region.c               |   43 +-
 drivers/cxl/core/region_dax.c           |    6 +
 drivers/cxl/core/trace.h                |   65 ++
 drivers/cxl/cxl.h                       |   60 +-
 drivers/cxl/cxlmem.h                    |  124 ++-
 drivers/cxl/mem.c                       |    2 +-
 drivers/cxl/pci.c                       |  115 ++-
 drivers/dax/bus.c                       |  360 ++++++--
 drivers/dax/bus.h                       |    4 +-
 drivers/dax/cxl.c                       |   71 +-
 drivers/dax/dax-private.h               |   40 +
 drivers/dax/hmem/hmem.c                 |    2 +-
 drivers/dax/pmem.c                      |    2 +-
 include/cxl/cxl.h                       |    6 +
 include/cxl/event.h                     |   39 +
 include/linux/ioport.h                  |    3 +
 tools/testing/cxl/Kbuild                |    5 +-
 tools/testing/cxl/test/mem.c            | 1018 ++++++++++++++++++++---
 27 files changed, 3210 insertions(+), 261 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
Quoted 8 lines
Quoted 3 lines
Signature · 1 line
2.43.0

what commit or branch does this apply on top of? Not v7.0...

Thanks!
John

I've bounced around about the best way to do this, but I'm working on one patch at the end of this series that fixes up the tagged extent handling to concatenate together all extents that share the same tag into one daxdev, in sequence number order (and fail if any of the extent boundaries are misaligned). The DPA ranges of the extents don't matter, provided the boundary alignment is good. And the extents get assembled in sequence number order, not DPA order.

Once we've agreed it's right, I'll help with squashing it sensibly if you like.

I'm close, but it's not quite ready. I should be able to send it Wednesday.

Then I'll try to channel Jonathan and to a general review pass on the series. Actually, maybe I'll try to program AI Jonathan :D

Thanks for what you do Anisa,
John

author
#27 lore raw
Quoted 268 lines · John Groves
Quoted 248 lines · John Groves
Quoted 247 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

This patchset was tested with Ali's QEMU patchset adding tag support:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Details:

Topology: '-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=12G \
     -object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1G \
     -device usb-ehci,id=ehci \
     -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
     -device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
     -device cxl-type3,bus=cxl_rp_port0,id=cxl-dcd0,dc-regions-total-size=12G,num-dc-regions=1,sn=99 \
     -device usb-cxl-mctp,bus=ehci.0,id=usb1,target=cxl-dcd0\
     -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=12G,cxl-fmw.0.interleave-granularity=1k'

1. Start VM (12GB)
2. Issue QMP to add tagged backend (8GB):
{ "execute": "qmp_capabilities" }

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 8589934592,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
3. Create region on the VM: cxl create-region -m -d decoder0.0 -w 1 -s 8G mem0 -t dynamic_ram_a
4. Issue QMP to add an 8GB extent:
{ "execute": "qmp_capabilities" }
{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-dcd0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 8589934592
            }
        ]
    }
}
5. Verify with sysfs:
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/offset
0x0
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/length
0x200000000
root@bgt-140510-bm03:~# cat /sys/bus/cxl/devices/dax_region0/extent0.0/uuid
5be13bce-ae34-4a77-b6c3-16df975fcf1a

6. daxctl create-device -r region0
[

  {
    "chardev":"dax0.1",
    "size":8589934592,
    "target_node":1,
    "align":2097152,
    "mode":"devdax"

}
]
created 1 device

Currently, QEMU only supports sending 1 extent in an add/release request, which limits what I can test. However, I was able to verify that once extent(s) have been added to a region, it can't be added to again (size cannot be increased).

Up to this point is what I test with this patchset. Then below is the additional famfs tests for the version applied on famfs.
================================================================================
7. Install famfs userspace tool:
https://github.com/cxl-micron-reskit/famfs

8.mkfs.famfs --v /dev/dax0.1 output:
devsize: 8589934592
Famfs Superblock:

  Filesystem UUID:   c33b4525-a2c7-4d64-9204-e8ed273b4ffb
  Device UUID:       ae887e6b-f886-45f9-bc55-f0696f3cd91d
  System UUID:       da314140-12e7-45c2-98b2-753d3bfe4f46

role of this node: Owner
alloc_unit: 0x200000
OMF major version: 2
OMF minor version: 1
sizeof superblock: 200
log size (bytes): 8388608
primary: /dev/dax0.1 8589934592

Log stats:

  # of log entries in use: 0 of 15420
  Log size in use:          48
  Log size (total bytes)    8388608
  No allocation errors found

Capacity:

  Device capacity:        8.00G
  Bitmap capacity:        8.00G
  Sum of file sizes:      0.00G
  Allocated space:        0.01G
  Free space:             7.99G

Space amplification: inf
Percent used: 0.1%

Famfs log:
0 of 15420 entries used
0 bad log entries detected
0 files
0 directories

9. famfs smoke tests also succeed. The smoke tests include some fio tests, which run some simulated workloads

:== Test Timing Summary :==-------------------------------------------------------------------

:==  prepare              0:10
:==  test0                0:07
:==  test_shadow_yaml     0:04
:==  test1                0:22
:==  test2                0:12
:==  test3                0:03
:==  test4                0:10
:==  test_errors          0:01
:==  stripe_test          0:58
:==  test_pcq             1:26
:==  test_fio             0:34

:==-------------------------------------------------------------------
:== TOTAL 4:27
:==------------------------------------------------------------------- :==run_smoke completed successfully (Thu Apr 9 10:33:28 PM UTC 2026)

Anisa Su (1):
dax/bus.c: make DC regions driver type DAXDRV_DEVICE_TYPE

Ira Weiny (19):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/cdat: Gather DSMAS data for DCD partitions cxl/core: Enforce partition order/simplify partition calls cxl/mem: Expose dynamic ram A partition in sysfs cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode cxl/region: Add sparse DAX region support
cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/mem: Configure dynamic capacity interrupts cxl/core: Return endpoint decoder information from region search cxl/extent: Process dynamic partition events and realize region
extents
cxl/region/extent: Expose region extent information in sysfs dax/bus: Factor out dev dax resize logic
dax/region: Create resources on DAX regions cxl/region: Read existing extents on region creation cxl/mem: Trace Dynamic capacity Event Record tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

 Documentation/ABI/testing/sysfs-bus-cxl |  100 ++-
 drivers/cxl/core/Makefile               |    2 +-
 drivers/cxl/core/cdat.c                 |   11 +
 drivers/cxl/core/core.h                 |   47 +-
 drivers/cxl/core/extent.c               |  471 +++++++++++
 drivers/cxl/core/hdm.c                  |   13 +-
 drivers/cxl/core/mbox.c                 |  770 ++++++++++++++++-
 drivers/cxl/core/memdev.c               |   87 +-
 drivers/cxl/core/port.c                 |    5 +
 drivers/cxl/core/region.c               |   43 +-
 drivers/cxl/core/region_dax.c           |    6 +
 drivers/cxl/core/trace.h                |   65 ++
 drivers/cxl/cxl.h                       |   60 +-
 drivers/cxl/cxlmem.h                    |  124 ++-
 drivers/cxl/mem.c                       |    2 +-
 drivers/cxl/pci.c                       |  115 ++-
 drivers/dax/bus.c                       |  360 ++++++--
 drivers/dax/bus.h                       |    4 +-
 drivers/dax/cxl.c                       |   71 +-
 drivers/dax/dax-private.h               |   40 +
 drivers/dax/hmem/hmem.c                 |    2 +-
 drivers/dax/pmem.c                      |    2 +-
 include/cxl/cxl.h                       |    6 +
 include/cxl/event.h                     |   39 +
 include/linux/ioport.h                  |    3 +
 tools/testing/cxl/Kbuild                |    5 +-
 tools/testing/cxl/test/mem.c            | 1018 ++++++++++++++++++++---
 27 files changed, 3210 insertions(+), 261 deletions(-)
 create mode 100644 drivers/cxl/core/extent.c
Quoted 8 lines
Quoted 3 lines
Signature · 1 line
2.43.0

what commit or branch does this apply on top of? Not v7.0...

Thanks!
John

I've bounced around about the best way to do this, but I'm working on one patch at the end of this series that fixes up the tagged extent handling to concatenate together all extents that share the same tag into one daxdev, in sequence number order (and fail if any of the extent boundaries are misaligned). The DPA ranges of the extents don't matter, provided the boundary alignment is good. And the extents get assembled in sequence number order, not DPA order.

Quoted 4 lines

Once we've agreed it's right, I'll help with squashing it sensibly if you like.

I'm close, but it's not quite ready. I should be able to send it Wednesday.

Ok sounds good!

Thanks,
Anisa

Quoted 5 lines

Then I'll try to channel Jonathan and to a general review pass on the series. Actually, maybe I'll try to program AI Jonathan :D

Thanks for what you do Anisa,
John

maintainer
#28 lore raw
In reply to Anisa Su
Quoted 52 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

Quoted 8 lines

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

Where's the CXl unit testing...

big skip

Quoted 2 lines

tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

Hi Anisa,

I'm inserting here and referencing the last 2 patches above that add cxl/test support for DCD testing.

Let's use it! We'd really like to see the ndctl patches sync'd up with this kernel set. That would give us a CXL Unit test 'cxl-dcd.sh' to run on each revision.

This is one link, perhaps the last to the ndctl set, but I think you may have posted something long ago too:
https://lore.kernel.org/nvdimm/[email protected]/

-- Alison

author
#29 lore raw
Quoted 70 lines · Alison Schofield
Quoted 52 lines · Anisa Su

This RFC modifies Ira's DCD patchset to enforce tags and remove sparse DAX region support, which are the requirements that I've understood from the community meetings, with the end goal of FAMFS as the end user for DCD. Feedback would be greatly appreciated to let me know if this is on the right track? Or totally off the mark...

Everything is the same as before except:
- extents must have tags (uuids)
- 1 tag per region
- regions must be contiguous (no more sparse regions)

To achieve this, the main thing is to change the relationship between cxl_dax_region : region_extent from 1 : many to 1 : 1. Each region_extent is comprised of 1+ contiguous device extents with the same tag. Contiguity is enforced by sorting device extents by DPA order. They're re-sorted by the original order in which they were sent for the response, which is required by the spec.

Once valid extents have been collected, it's passed as 1 contiguous capacity to the DAX layer via cxl_dax_region notify(). Once notified, the same region cannot be added to again, unless all extents are released.

For release: upon receiving a release event record, if the extent is within the bounds of any cxl_region, and it has the correct tag, then all extents in the region are released, so the "More" flag is still ignored. Not sure if this is the right way to do it but it was the simplest.

The changes to the DAX layer remain untouched, as all of this extra validation is done in the CXL layer. And since FAMFS already takes care of the devdax -> fsdev conversion, there was no need to add anything there.

Most of the series remains unchanged as I've tried not to make too many big changes right off the bat. Only the following commits were modified:
- cxl/extent: Process dynamic partition events and realize region extents
- dax/region: Create resources on DAX regions
- cxl/region: Read existing extents on region creation

I've tacked on 1 commit at the end to change the driver type of DC regions from DAXDRV_KMEM_TYPE to DAXDRV_DEVICE_TYPE so it can be bound to the new fsdev driver.

Also, I've documented with more detail in the commit messages of the commits that were modified on what exactly was changed, so I hope that's clear.

================================================================================
Git History

This series is based on cxl-next, with base commit:
3939dba00f98 Merge branch 'for-7.1/cxl-misc' into cxl-for-next
+ bug fix: https://lore.kernel.org/linux-cxl/[email protected]/T/#u

GH Branch: https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-rfc-04-10-26

Quoted 8 lines

It doesn't apply cleanly onto famfs-v9, although I have the version that's applied onto famfs-v9 here: https://github.com/anisa-su993/anisa-linux-kernel/tree/famfs-v9-dcd
- famfs-v9 for reference: https://github.com/jagalactic/linux/tree/famfs-v9

I've tested the current series without famfs as well as the series applied on famfs-v9 with famfs.
================================================================================
Testing:

Where's the CXl unit testing...

big skip

Quoted 2 lines

tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data

Quoted 9 lines

Hi Anisa,

I'm inserting here and referencing the last 2 patches above that add cxl/test support for DCD testing.

Let's use it! We'd really like to see the ndctl patches sync'd up with this kernel set. That would give us a CXL Unit test 'cxl-dcd.sh' to run on each revision.

Will do for the next version! I wasn't sure if the behavior in this RFC was what famfs wanted, so I left the tests alone. But anyway, once cleared up with John, those will be updated :3

Thanks,
Anisa

Quoted 6 lines

This is one link, perhaps the last to the ndctl set, but I think you may have posted something long ago too:
https://lore.kernel.org/nvdimm/[email protected]/

-- Alison