DCD: Add support for Dynamic Capacity Devices (DCD)
v10 cover DCD: Add support for Dynamic Capacity Devices (DCD)
Table of Contents
==================
- Use Case
- LSFMM`26 Discussion
- Updated Design Overview
- DC Add
- DC Release
- Series Info
- Changes from v9
- CXL Layer Changes
- DAX Layer Changes
- Testing
- References
Since this is v10, this cover letter is aimed at folks who are familiar with the patchset history and concept of DCD. Background section now lives at the bottom.
This series:
https://github.com/anisa-su993/anisa-linux-kernel/tree/dcd-v10-23-05-2026
The corresponding NDCTL branch:
https://github.com/anisa-su993/anisa-ndctl/tree/dcd-2026-05-21
Use Case:
=========
The use case for DCD has been a long-time blocker for this series. In the previous months, we discussed moving forward with FAMFS as the first end-user for DCD.
In the CXL call from this week (19-05-2026), I mentioned another potential use case: LM Cache (an open-source KV Cache layer for LLM inference servers) supports using DAX-devices as a backend for L2 tier.
In the meeting, it was noted that "we don't actually need an in-kernel user for DCD DAX devices because there's user space users of DCD DAX devices and a DCD DAX device is just a DAX device."[meeting transcript] To paraphrase, any consumer of DAX devices can use DCD, so I hope the use case is not a blocker moving forward for the series, but if there are outstanding concerns, let's discuss them now.
LSFMM`26 Discussion:
====================
To briefly recap, we discussed the following requirements:
1) tags must be unique
2) each tagged allocation (1+ extents with the same tag) forms one DAX device. a. if shared, the extents gets pieced together by the
shared extent sequence number
b. if not shared, extents get pieced together by the order
they arrive in the event log
c. extents are only surfaced to the DAX layer when the 'More' chain
closes. The 'More' chain refers to DC event records grouped together with the 'More' bit. The end of the chain ('More'=0) means all extents for each tagged allocation have been sent.
d. timeout if 'More' chain is not closed within 20s as a defensive
measure against lost event records or crashed FM. Clears all extents that were pending add
3) untagged extents form their own DAX device -- 1 untagged extent : 1 DAX device
4) a DCD extent backed DAX device must present a contiguous range to the user irrespective of whether the extents are physically contiguous
5) interleaving between extents remains unsupported for now
Originally, tags were unsupported (all extents w/non-null tag was not accepted). Shareable extents - a subset of tagged extents which have a shared_extn_seq number - were also unsupported. We now support both.
For more details on the semantics of tagged allocations, shareability, and the 'More' chain, see John Groves' RFC, which was refactored into this tree[1].
The section below describes the current design to satisfy these requirements.
Updated Design Overview:
========================
This section describes the end-to-end flow for how extents from the event log are accepted to how it surfaces as a DAX device.
DC Add:
========
The 2 main "phases" (illustrated in an example below) are:
1) CXL layer validates and accepts device extents; notifies DAX layer
- extents hang out under the DAX region as a sub-resource until claimed by a DAX device. The resource tree will sort by HPA range, but the step below will assemble them by tag and sequence order.
2) "DC" DAX-devices must be created with a uuid specified:
- similar to before, DC DAX devices must be created at size 0
- in order to actually claim resources from the region, you must store tag_a to /sys/.../daxX.Y/uuid
- this claims all sub-resources under DAX region with tag_a
- each extent becomes the backing for dev_dax->ranges[i]
- the index (i) depends on shared_ext_seq_num or arrival order for non-shared extents
The diagram below illustrates an example and describes the key structures and which layer they live in.
* To keep this diagram simple, DPA/HPA is left out. But to avoid confusion:
e1, e2, and e3 are not necessarily contiguous, nor ordered by DPA/HPA. The sequence number is the sole determinant of how to piece them together for form the VA view.
device extents dc_extent dax_resource DAX device
(CXL core) (CXL DAX) (DAX bus) (/dev/daxN.Y)
------------- ------------- ------------- ------------
shared extents
e1 ─┐ ┌─► dc_e1 ─► res_1 (seq=1) ──┐
e2 ─┼── tag A ─► ┼─► dc_e2 ─► res_2 (seq=2) ──┼─► daxN.0
e3 ─┘ └─► dc_e3 ─► res_3 (seq=3) ──┘ (size = Σ |e_i|)
tagged - unshared
e4 ─┐ ┌─► dc_e4 ─► res_4 (seq=1) ──┐
├── tag B ─► ┤ ├─► daxN.1
e5 ─┘ └─► dc_e5 ─► res_5 (seq=2) ──┘ (size = Σ |e_i|)
untagged
e6 ─ null tag ─► dc_e6 ─► res_6 (seq=0) ────► daxN.2
e7 ─ null tag ─► dc_e7 ─► res_7 (seq=0) ────► daxN.3
- device extent:
This is the exact payload structure of extents in a DC Add/Release event record.
They get validated and processed in the CXL driver
- dc_extent
One per surviving device extent. Registered under the CXL DAX driver (parent = cxlr_dax->dev)
/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/uuid
- dax_resource
DAX bus's per-extent view, one-to-one with dc_extent. Carries the tag uuid and a 1..n seq_num to the DAX layer so DAX devices can find the matched set and put into dev_dax->ranges[] in order.
- DAX device (/dev/daxN.Y)
Built when userspace writes the tag UUID to the seed device's 'uuid' attribute.
uuid_claim_tagged() collects every matching dax_resource and assembles in seq_num order by appending each dax_resource to dev_dax->ranges[i] where i = seq_num. uuid_claim_untagged() grabs a single unused untagged dax_resource in its entirety.
Resize (shrink and grow) is disallowed, since the size is pre-determined by sum of sizes of matching extents. Only resizing to 0 is allowed for destroying the device.
DC Release:
============
Now that the coordination between CXL/CXL-DAX/DAX layers is understood, DC Release can be understood quickly with some pseudo-code.
To summarize: release is done 'loosely', in the sense that we release the entire tag group upon receiving a release event containing any extent in the tag group rather than checking that every single extent in the tag group is in the release event. This only applies if the extent is not in use (corresponding dax_resource->use_count == 0).
If the extent is in use, release can be delayed until it's not in use, since Force Release is unsupported.
device cxl driver cxl_dax driver
----- -------------- --------------
release(dpa, tag) ──► look up (dpa, tag) in
cxlr_dax->dc_extents
found → notify dax
(DCD_RELEASE_CAPACITY) ─► backing in use?
EBUSY → defer
ok → dax_region_rm_resources()
rm_tag_group():
- invalidate memregion (once for group)
- unregister every dc_extent device
- cascades into dax_region_rm_resources() (refuse-all-or-none under dax_region_rwsem)
The release path is always whole-tag-group; the kernel never splits a group in response to a sub-range release request.
Series Info
=============
The series builds on top of cxl-next with the famfs-v9 patchset applied.
Specifically, famfs-v9 was applied on
3939dba00f98 "Merge branch 'for-7.1/cxl-misc' into cxl-for-next", which then became the base for this series, so the history looks like this:
|--branch tip - e3343e260ce4 Documentation/cxl: Document DCD... |... [DCD patches] |-- last famfs patch 878df599bd1f (famfs-v9) famfs_fuse: Add documentation |... [famfs patches] |-- base commit - 3939dba00f98 (origin/next)
Since this series has gotten so long, I've broken the commits down into logical sections. Most of the original scaffolding commits are untouched (Sections 1-3).
1. Device discovery and partition layout (4 commits)
- 4700826deb08 cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
- 692890d6934d cxl/mem: Read dynamic capacity configuration from the device
- f7800561164a cxl/cdat: Gather DSMAS data for DCD partitions
- 22ae445b8a99 cxl/core: Enforce partition order/simplify partition calls
Identify a DCD, read its partition layout via the GET_DYNAMIC_CAPACITY_CONFIG mailbox, and pair each DC partition with its CDAT DSMAS entry (sharable / writable / coherency).
2. Region and endpoint-decoder wiring (3 commits)
- 45bc277b11c1 cxl/mem: Expose dynamic ram A partition in sysfs
- 58e5e5007cd1 cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode
- 9f0e0b3deeb1 cxl/region: Add DC DAX region support
Make DC partitions reachable through the existing region/decoder machinery so a DC region can be created with an HPA window that's empty until extents arrive.
3. Event/interrupt plumbing (5 commits)
- 2906584012fc cxl/events: Split event msgnum configuration from irq setup
- a211cbf4417c cxl/pci: Factor out interrupt policy check
- 7f2e4fe38541 cxl/mem: Configure dynamic capacity interrupts
- aca91b273921 cxl/core: Return endpoint decoder information from region search
- e11ff26899d6 cxl/mem: Set up framework for handling DC Events
Configure the DCD interrupt class, refactor the irq policy plumbing, and add the event-loop framework that the ADD/RELEASE paths hang off of.
4. DC Add Implementation (5 commits)
- 68caa60e758c cxl/mem: Add 20 second timeout for stalled DC_ADD_CAPACITY chains
- 22f480966589 cxl/extent: Handle DC Add Capacity events
- 60e23199f7ef cxl/mem: Drop misaligned DCD extent groups
- def526ee51b6 cxl/extent: Validate DC extent partition
- 9e1f5b0b36fd cxl/mem: Enforce tag-group semantics
Process device-offered extents after the "More"-chain closes, applying the per-extent checks (region resolution, endpoint decoder containment, no-overlap, duplicate tolerance) and per-tag-group checks (alignment, partition equality, seq-num integrity, all-or-nothing acceptance). A defensive watchdog refuses an unterminated ADD chain after 20s so a lost closing record can't strand the staged list.
5. DC Release Implementation path (1 commit)
- b6069cc18b77 cxl/extent: Handle DC Release Capacity events
Handle device-initiated release: locate the owning tag group by (DPA, UUID) and release all extents in the group atomically.
6. Cross-region uniqueness + sysfs surface (2 commits)
- 8f4aa2f5da26 cxl/extent: Enforce cross-region tag uniqueness
- 52f5a9ba1754 cxl/region/extent: Expose dc_extent information in sysfs
Add the host-wide tag registry (cxl_tag_register) so an orchestrator UUID collision across regions is caught, and expose extent info as extentX.Y under its region device.
7. CXL<->DAX bridge (2 commits)
- 9195bbfbed68 cxl + dax: Surface dax_resources on DCD Add Capacity events
- e6cea279dcb2 cxl + dax: Release dax_resources on DCD Release Capacity events
Add the .notify callback on the cxl_dax region driver.
On ADD: register one dax_resource per dc_extent.
On RELEASE: atomically remove the whole tag set, with deferred release on -EBUSY.
8. DAX bus DC support (4 commits)
- 29393afa419c dax/bus: Factor out dev dax resize logic
- 00e5da991afc dax/bus: Add uuid sysfs attribute to dax devices
- 9c73377182f1 dax/bus: Reject resize on DC dax devices and enforce 0-size creation
- 89784b600e42 dax/bus: Tag-aware uuid claim and show on DC dax devices
Generalize the resize allocator to operate on any parent resource, add the new uuid attribute, gate DC sizing rules (reject any non-zero resize; size=0 is the destroy path), and implement the tagged/untagged claim flow.
9. Boot-time scan (1 commit)
- ec8d257b5305 cxl/region: Read existing extents on region creation
Replay the device's already-accepted list at region probe so reboots and host crashes recover without losing tagged allocations.
10. Tracing, mock, docs (4 commits)
- 54f9e863fac7 cxl/mem: Trace Dynamic capacity Event Record
- 41c47ec44202 tools/testing/cxl: Make event logs dynamic
- b8aa5ccbb327 tools/testing/cxl: Add DC Regions to mock mem data
- e3343e260ce4 Documentation/cxl: Document DCD extent handling and DC-backed DAX regions
Add a tracepoint for DC event records, extend the cxl_test mocks to model dynamic event logs and DC partitions, and document the accept/release conditions plus how CXL and DAX coordinate add/release transactions
Changes from v9:
=================
I am comparing this patchset against the last "official" version of this patchset by Ira [2]
This section describes the structural changes made to add support for tags/sharing and uuid-based DAX device creation.
========= CXL Layer Changes ==============
1) The original patchset was designed with interleaving in mind and
without support for tags. As such, it was set up with
struct region_extent forming the HPA range for 1+ interleaved
cxled_extents.
/**
* struct cxled_extent - Extent within an endpoint decoder
* @cxled: Reference to the endpoint decoder
* @dpa_range: DPA range this extent covers within the decoder
* @uuid: uuid from device for this extent
*/
struct cxled_extent {
struct cxl_endpoint_decoder *cxled;
struct range dpa_range;
uuid_t uuid;
};
struct region_extent {
struct device dev;
struct range hpa_range;
uuid_t uuid;
struct xarray decoder_extents;
};
> Without interleaving a device extent forms a 1:1 relationship with the
> region extent [3]
cxled_extent and region_extent are replaced by struct dc_extent and
struct cxl_dc_tag_group to match the new requirement for tags and defers
interleave support.
struct dc_extent {
struct device dev;
struct cxl_dc_tag_group *group;
struct cxl_endpoint_decoder *cxled;
struct range dpa_range;
struct range hpa_range;
uuid_t uuid;
u16 seq_num;
};
struct cxl_dc_tag_group {
struct cxl_dax_region *cxlr_dax;
uuid_t uuid;
struct xarray dc_extents;
unsigned int nr_extents;
struct list_head registry_node;
};
2) More validation is done in mbox.c as well to support the
tag-uniqueness, shared_extn_seq num integrity, etc. Most
of this work is from John Groves[1].
========= DAX Layer Changes ==============
As described above, struct dax_resource is a sub-resource
of the dc dax region that represents a usable resource
(physically backed).
1)
Original | Now
----------------------------------|----------------------------------
struct dax_resource { | struct dax_resource {
struct dax_region *region; | struct dax_region *region;
struct resource *res; | struct resource *res;
| uuid_t uuid;
| u16 seq_num;
unsigned int use_cnt; | unsigned int use_cnt;
}; | };
The uuid and seq_num must be propagated to the DAX layer in
order for DAX devices to be able to assemble them
by tag and sequence number in dev_dax->ranges[].
2) The model for claiming dax_resources has changed.
| Original | Now
------------|----------------------------------------|----------------------------------------
semantics | Tags were unsupported, so | dax_resources (which correspond to
| dax_resources were claimed through | 1 extent) cannot be split up. Not
| the resize operation. Individual | only can extents not be partially
| extents could be partially claimed | claimed, but the entire tag group
| and unclaimed by DAX devices. | must be atomically claimed.
------------|----------------------------------------|----------------------------------------
resize | Introduced the | Removed dev_dax_resize_sparse().
| dev_dax_resize_sparse() function | Grow and shrink is disallowed
| to enable splitting extents. | because the size is predetermined
| | by the tag group's size. Only
| | resizing to size 0 for destroy
| | is allowed.
------------|----------------------------------------|----------------------------------------
uuid | — unsupported | New dev_dax uuid sysfs attribute:
| | /sys/bus/dax/devices/daxX.Y/+{uuid}+
| | Enables uuid_store, which enables
| | tag-aware resource claiming.
3) Renamed 'sparse' DAX regions to 'DC' or 'DC-backed' DAX regions. Unsure if
this is better?Testing:
================
Unit testing:
- The NDCTL branch posted at the top adds test/cxl-dcd.sh, which leverages the mock device and extent-injection helpers added in sec 10 (41c47ec44202, b8aa5ccbb327). Coverage:
DC Add — validation
- Misaligned (non-2M) extent drops the whole group
- Overlapping extent injection rejected; original extent remains
- "More"-chain: extents stay staged until More=0 closes the chain
- Cross-More tag uniqueness: second event re-using a committed tag dropped
- Sharable partition: shared extents arrive with device-stamped seq 1..n
- Sharable group with a seq-integrity gap (1, 3) refused on claim
DC Add — uuid claim
- Pre-existing untagged + tagged extents (mock-injected at module load) claimed via --uuid "0" / tag uuid
- Newly injected untagged + tagged extents claimed via --uuid "0" / tag uuid
- Multiple extents under one tagged More-chain aggregate into a single DAX device of summed size
- --uuid <unknown> fails with -ENOENT and does not consume region space
- dev_dax uuid sysfs attribute reads back the claim source ("0" for untagged, the tag string for tagged)
DC Release
- Release event under an in-use DAX device is deferred (-EBUSY); the extent stays under the region until the DAX device is destroyed, then a re-issued release completes
- Tag-group release: a release event addressed at any DPA in the group releases the whole group atomically
- Partial-range release event targets the whole containing region_extent rather than carving it
DAX device sizing policy
- Plain create-device (no --uuid) on a sparse region fails
- --uuid "0" with no remaining untagged dax_resource returns -ENOENT
- Any non-zero resize on a sparse DAX device returns -EOPNOTSUPP
- Resize on a tagged multi-extent DAX device also rejected
- size=0 / destroy releases the dax_resource so it can be re-claimed
Region / driver lifecycle
- Destroy region with extents (no DAX devices) succeeds
- Destroy region with extents + active DAX devices succeeds
- Two DC regions hosted on the same DC partition
- modprobe -r dax_cxl releases all extents; modprobe-in afterwards preserves region state and accepts new injections
QEMU testing:
Tested with Ali's QEMU patchset adding support for tags[4]
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-16df975fcf1a6. daxctl create-device -r region0 --uuid 5be13bce-ae34-4a77-b6c3-16df975fcf1a [
{
"chardev":"dax0.1",
"size":8589934592,
"target_node":1,
"align":2097152,
"mode":"devdax" }
]
created 1 device
7. Test compatibility with famfs[5]
DEV=/dev/dax0.1 ./run_smoke.sh
... lots of other output ...
:== Test Timing Summary :==-------------------------------------------------------------------
:== prepare 0:13 :== test_daxmode 0:06 :== test_load_module 0:00 :== test0 0:06 :== test_shadow_yaml 0:05 :== test1 0:17 :== test2 0:11 :== test3 0:03 :== test4 0:16 :== test_errors 0:01 :== stripe_test 0:53 :== test_pcq 1:31 :== test_fio 0:34
:==-------------------------------------------------------------------
:== TOTAL 4:40
:==------------------------------------------------------------------- :==run_smoke completed successfully (Mon May 18 23:24:44 UTC 2026)
8. Test release
daxctl disable-device /dev/dax0.1
daxctl destroy-device /dev/dax0.1
Send release QMP
{ "execute": "qmp_capabilities" }
{
"execute": "cxl-release-dynamic-capacity",
"arguments": {
"path": "/machine/peripheral/cxl-dcd0",
"host-id": 0,
"removal-policy": "prescriptive",
"region": 0,
"tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
"extents": [
{
"offset": 0,
"len": 8589934592
}
]
}
}Extent sysfs entries disappear and dmesg shows:
[ 55.816172] cxl_core:cxl_handle_dcd_event_records:1655: cxl_pci 0000:0d:00.0: DCD event release : DPA:0x0 LEN:0x200000000 [ 55.819311] cxl_core:__cxl_dpa_to_region:3021: cxl decoder2.0: dpa:0x0 mapped in region:region0 [ 55.821966] cxl_core:cxlr_notify_extent:368: cxl_dax_region dax_region0: Trying notify: type 1 tag 5be13bce-ae34-4a77-b6c3-16df975fcf1a [ 55.825736] cxl_core:cxlr_notify_extent:387: cxl_dax_region dax_region0: Notify: type 1 tag 5be13bce-ae34-4a77-b6c3-16df975fcf1a [ 55.829374] dax:__dax_release_resource:195: cxl_dax_region dax_region0: Extent release resource [mem 0x1290000000-0x148fffffff flags 0x80000200] [ 55.832745] cxl_core:dc_extent_unregister:489: extent0.0: DAX region rm extent HPA [range 0x0000000000000000-0x00000001ffffffff] [ 55.836048] dax:__dax_release_resource:195: cxl_dax_region dax_region0: Extent release resource (null) [ 55.838850] cxl_core:cxled_release_extent:72: cxl decoder2.0: Remove extent [range 0x0000000000000000-0x00000001ffffffff] (5be13bce-ae34-4a77-b6c3-16df975fcf1a) [ 55.843347] cxl_core:memdev_release_extent:1197: cxl_pci 0000:0d:00.0: Release response dpa [range 0x0000000000000000-0x00000001ffffffff] [ 55.846887] cxl_pci:__cxl_pci_mbox_send_cmd:263: cxl_pci 0000:0d:00.0: Sending command: 0x4803
Background
=============
A Dynamic Capacity Device (DCD) (CXL 3.1 sec 9.13.3) is a CXL memory device that allows memory capacity within a region to change dynamically without the need for resetting the device, reconfiguring HDM decoders, or reconfiguring software DAX regions.
One of the biggest anticipated use cases for Dynamic Capacity is to allow hosts to dynamically add or remove memory from a host within a data center without physically changing the per-host attached memory nor rebooting the host.
The general flow for the addition or removal of memory is to have an orchestrator coordinate the use of the memory. Generally there are 5 actors in such a system, the Orchestrator, Fabric Manager, the Logical device, the Host Kernel, and a Host User.
An example work flow is shown below.
Orchestrator FM Device Host Kernel Host User
| | | | |
|-------------- Create region ------------------------>|
| | | | |
| | | |<-- Create ----|
| | | | Region |
| | | |(dynamic_ram_a)|
|<------------- Signal done ---------------------------|
| | | | |
|-- Add ----->|-- Add --->|--- Add --->| |
| Capacity | Extent | Extent | |
| | | | |
| |<- Accept -|<- Accept -| |
| | Extent | Extent | |
| | | |<- Create -----|
| | | | DAX dev |-- Use memory
| | | | | |
| | | | | |
| | | |<- Release ----| <-+
| | | | DAX dev |
| | | | |
|<------------- Signal done ---------------------------|
| | | | |
|-- Remove -->|- Release->|- Release ->| |
| Capacity | Extent | Extent | |
| | | | |
| |<- Release-|<- Release -| |
| | Extent | Extent | |
| | | | |
|-- Add ----->|-- Add --->|--- Add --->| |
| Capacity | Extent | Extent | |
| | | | |
| |<- Accept -|<- Accept -| |
| | Extent | Extent | |
| | | |<- Create -----|
| | | | DAX dev |-- Use memory
| | | | | |
| | | |<- Release ----| <-+
| | | | DAX dev |
|<------------- Signal done ---------------------------|
| | | | |
|-- Remove -->|- Release->|- Release ->| |
| Capacity | Extent | Extent | |
| | | | |
| |<- Release-|<- Release -| |
| | Extent | Extent | |
| | | | |
|-- Add ----->|-- Add --->|--- Add --->| |
| Capacity | Extent | Extent | |
| | | |<- Create -----|
| | | | DAX dev |-- Use memory
| | | | | |
|-- Remove -->|- Release->|- Release ->| | |
| Capacity | Extent | Extent | | |
| | | | | |
| | | (Release Ignored) | |
| | | | | |
| | | |<- Release ----| <-+
| | | | DAX dev |
|<------------- Signal done ---------------------------|
| | | | |
| |- Release->|- Release ->| |
| | Extent | Extent | |
| | | | |
| |<- Release-|<- Release -| |
| | Extent | Extent | |
| | | |<- Destroy ----|
| | | | Region |
| | | | |References:
================
[1]: https://lore.kernel.org/linux-cxl/[email protected]/T/#m2a079aa47d5ec8cb1e6625d9b91c6aca09afbbd0
[2]: https://lore.kernel.org/linux-cxl/[email protected]/
[3]: https://lore.kernel.org/linux-cxl/[email protected]/T/#m97bb501f8cee434956f5cfbde3a65e9d7c0cd9be
[4]: https://lore.kernel.org/linux-cxl/[email protected]/T/#t
[5]: https://github.com/cxl-micron-reskit/famfs
Signature · 1 line
2.43.0
PATCH v10 1/31 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
@@ -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
@@ -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
Dave Jiang
maintainerRe: [PATCH v10 01/31] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
Quoted 3 lines · Anisa Su
From: Ira Weiny <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects
May as well update to CXL r4.0
Quoted 4 lines
Log (CEL) for dynamic capacity command support.
Detect support for the DCD commands while reading the CEL, including:
Quoted 8 lines
Get DC Config
Get DC Extent List
Add DC Response
Release DCBased on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>
missing Anisa sign off
Quoted 16 lines
---
Changes:
[anisa: rebase]--- drivers/cxl/core/mbox.c | 43 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 ++++++++++++++ 2 files changed, 58 insertions(+)drivers/cxl/core/mbox.c +0
-0@@ -165,6 +165,42 @@ static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, } }
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 176
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+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)
mds not used, consider drop
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+{ +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);
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 196
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+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)
mds not used. consider drop
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 201
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+{ +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 );
Above lines can be replaced with:
return bitmap_full(cmds_seen, CXL_DCD_ENABLED_MAX);
drivers/cxl/core/mbox.c static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · line 796
Quoted 10 lines
drivers/cxl/core/mbox.c +3
-0+} +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 );
Need to zero out the declared bitmap 'dcd_cmds' on stack before using.
DECLARE_BITMAP(dcd_cmds, CXL_DCD_ENABLED_MAX) = {};Quoted 28 lines
drivers/cxl/core/mbox.c +6
-0struct 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 +0
-0@@ -230,6 +230,15 @@ struct cxl_event_state {struct mutex log_lock; };
drivers/cxl/cxlmem.h struct cxl_event_state { · line 241
Quoted 10 lines
drivers/cxl/cxlmem.h +9
-0+/* 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 +}; +
would be nice to have comment point to where in the spec this is
DJ
Quoted 30 lines
drivers/cxl/cxlmem.h +6
-0/* 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 };
Re: [PATCH v10 01/31] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
Quoted 9 lines · Dave Jiang
Quoted 3 lines · Anisa Su
From: Ira Weiny <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects
May as well update to CXL r4.0
Updated!
Quoted 9 lines
Quoted 9 lines
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
Quoted 6 lines
Quoted 3 lines
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>missing Anisa sign off
Added!
Quoted 17 lines
Quoted 17 lines
---
Changes:
[anisa: rebase]--- drivers/cxl/core/mbox.c | 43 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 ++++++++++++++ 2 files changed, 58 insertions(+)drivers/cxl/core/mbox.c +0
-0@@ -165,6 +165,42 @@ static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, } }
Quoted 12 lines
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 176
Quoted 9 lines
drivers/cxl/core/mbox.c +9
-0+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)mds not used, consider drop
dropped
Quoted 14 lines
Quoted 14 lines
drivers/cxl/core/mbox.c +14
-0+{ +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 ;
Quoted 9 lines
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 196
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+default : +break ; + } +} + +static bool cxl_verify_dcd_cmds (struct cxl_memdev_state *mds,unsigned long *cmds_seen)mds not used. consider drop
also dropped
Quoted 9 lines
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 201
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+{ +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 );Above lines can be replaced with:
returnbitmap_full(cmds_seen, CXL_DCD_ENABLED_MAX);
replaced
Quoted 13 lines
drivers/cxl/core/mbox.c static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) · line 796
Quoted 10 lines
drivers/cxl/core/mbox.c +3
-0+} +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 );Need to zero out the declared bitmap '
dcd_cmds' on stack before using.
Quoted 2 lines
DECLARE_BITMAP(dcd_cmds, CXL_DCD_ENABLED_MAX) = {};done :)
Quoted 29 lines
Quoted 29 lines
drivers/cxl/core/mbox.c +6
-0struct 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 +0
-0@@ -230,6 +230,15 @@ struct cxl_event_state {struct mutex log_lock; };
Quoted 12 lines
drivers/cxl/cxlmem.h struct cxl_event_state { · line 241
Quoted 9 lines
drivers/cxl/cxlmem.h +9
-0+/* 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 +}; +would be nice to have comment point to where in the spec this is
Added
Quoted 2 lines
DJ
Thanks!
Anisa
Quoted 31 lines
Quoted 30 lines
drivers/cxl/cxlmem.h +6
-0/* 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 };
PATCH v10 2/31 cxl/mem: Read dynamic capacity configuration from the device
In reply to Anisa SuFrom: 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]
[jonathan: mbox.c: use max possible size for get_dc_config command to avoid vmalloc]
[jonathan & fan: cxlmem.h: remove unused struct cxl_mem_dev_info]
--- drivers/cxl/core/hdm.c | 2 + drivers/cxl/core/mbox.c | 182 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 47 +++++++++++ drivers/cxl/pci.c | 3 + include/cxl/cxl.h | 3 +- 5 files changed, 236 insertions(+), 1 deletion(-)
drivers/cxl/core/hdm.c +2 -0
@@ -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 +47 -0
74 lines not on this page · raw message
drivers/cxl/pci.c +3 -0
@@ -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 -1
@@ -133,6 +133,7 @@ struct cxl_dpa_perf {enum cxl_partition_mode {CXL_PARTMODE_RAM ,CXL_PARTMODE_PMEM , +CXL_PARTMODE_DYNAMIC_RAM_A , };/**
@@ -147,7 +148,7 @@ struct cxl_dpa_partition {enum cxl_partition_mode mode; }; -#define CXL_NR_PARTITIONS_MAX 2 +#define CXL_NR_PARTITIONS_MAX 3/** * struct cxl_dev_state - The driver device state
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 02/31] cxl/mem: Read dynamic capacity configuration from the device
Quoted 4 lines · 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
4.0
Quoted 4 lines
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
4.0
Quoted 16 lines
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.
Quoted 3 lines
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>
Missing Anisa sign off
Quoted 66 lines
---
Changes:
[anisa: rebase]
[jonathan:mbox.c: use max possible size forget_dc_configcommand to avoid vmalloc]
[jonathan & fan:cxlmem.h: remove unused structcxl_mem_dev_info]--- drivers/cxl/core/hdm.c | 2 + drivers/cxl/core/mbox.c | 182 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 47 +++++++++++ drivers/cxl/pci.c | 3 + include/cxl/cxl.h | 3 +- 5 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/hdm.c +2
-0@@ -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 +30
-0@@ -1351,6 +1351,156 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)return -EBUSY ; } +static int cxl_dc_check (struct device *dev,struct cxl_dc_partition_info *part_array, +u8 index,struct cxl_dc_partition *dev_part) +{ +size_t blk_size =le64_to_cpu (dev_part->block_size); +size_t len =le64_to_cpu (dev_part->length); + + 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 ; + +/* Check partitions are in increasing DPA order */ +if (index >0 ) { +struct cxl_dc_partition_info *prev_part = &part_array[index -1 ]; + +if ((prev_part->start + prev_part->size) > + part_array[index].start) { +dev_err (dev, +"DPA ordering violation for DC partition %d and %d\n" , + index -1 , index); +return -EINVAL ; + } + } + +if (!IS_ALIGNED (part_array[index].start,SZ_256M ) || + !IS_ALIGNED (part_array[index].start, blk_size)) { +dev_err (dev,"DC partition %d invalid start %zu blk size %zu\n" , + index, part_array[index].start, blk_size); +return -EINVAL ; + } +
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1393
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+if (part_array[index].size ==0 || len ==0 || + part_array[index].size < len || !IS_ALIGNED (len, blk_size)) { +dev_err (dev,"DC partition %d invalid length; size %zu len %zu blk size %zu\n" , + index, part_array[index].size, len, blk_size); +return -EINVAL ; + } + +if (blk_size ==0 || blk_size %CXL_DCD_BLOCK_LINE_SIZE || + !is_power_of_2 (blk_size)) { + dev_err(dev, "DC partition %d invalid block size; %zu\n",
size: instead of size;
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1398
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+ index, blk_size); +return -EINVAL ; + } + + dev_dbg(dev, "DC partition %d start %zu start %zu size %zu\n",
should it be "DC partition %d start %zu size %zu blk_size: %zu\n"?
Quoted 43 lines
drivers/cxl/core/mbox.c +43
-0+ index, part_array[index].start, part_array[index].size, + blk_size); + +return 0 ; +} + +/* Returns the number of partitions in dc_resp or -ERRNO */ +static int cxl_get_dc_config (struct cxl_mailbox *mbox,u8 start_partition, +struct cxl_mbox_get_dc_config_out *dc_resp, +size_t dc_resp_size) +{ +struct cxl_mbox_get_dc_config_in get_dc = (struct cxl_mbox_get_dc_config_in ) { + .partition_count =CXL_MAX_DC_PARTITIONS , + .start_partition_index = start_partition, + }; +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_CONFIG , + .payload_in = &get_dc, + .size_in =sizeof (get_dc), + .size_out = dc_resp_size, + .payload_out = dc_resp, + .min_out =8 , + }; +int rc; + + rc =cxl_internal_send_cmd (mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +dev_dbg (mbox->host,"Read %d/%d DC partitions\n" , + dc_resp->partitions_returned, dc_resp->avail_partition_count); +return dc_resp->partitions_returned; +} + +/** +* cxl_dev_dc_identify() - Reads the dynamic capacity information from the +* device. +* @mbox: Mailbox to query +* @dc_info: The dynamic partition information to return +* +* Read Dynamic Capacity information from the device and return the partition +* information. +*
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1451
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+* Return: 0 if identify was executed successfully, -ERRNO on error. +* on error only dynamic_bytes is left unchanged. +*/ +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info) +{ +struct cxl_dc_partition_info partitions[CXL_MAX_DC_PARTITIONS ]; +struct device *dev = mbox->host; +size_t dc_resp_size = +sizeof (struct cxl_mbox_get_dc_config_out ) +sizeof (partitions);
I think it needs to be something like below because of the 'partition' flex array:size_t dc_resp_size = struct_size(dc_resp, partition, CXL_MAX_DC_PARTITIONS);
partitions is type 'struct cxl_dc_partition_info'. and dc_resp->partition is type 'struct cxl_dc_partition'. So the size calucation is wrong. It should at least be:size_t dc_resp_size = sizeof(struct cxl_mbox_get_dc_config_out) + sizeof(struct cxl_dc_partition) * CXL_MAX_DC_PARTITIONS;
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1460
Quoted 9 lines
drivers/cxl/core/mbox.c +9
-0+u8 start_partition; +u8 num_partitions; + + struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) = +kmalloc (dc_resp_size,GFP_KERNEL ); +if (!dc_resp) +return -ENOMEM ; + +/**
/*
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+* Read and check all partition information for validity and potential +* debugging; see debug output in cxl_dc_check() +*/ + start_partition =0 ; + num_partitions =0 ;
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1475
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ do { + int rc, i, j; + + rc = cxl_get_dc_config(mbox, start_partition, dc_resp, dc_resp_size); + if (rc < 0) { + dev_err(dev, "Failed to get DC config: %d\n", rc); + return rc; + } + + num_partitions += rc;
Would cxl_get_dc_config() keep returning 0 be a problem? Not likely to happen unless device is malicious.
Quoted 43 lines
drivers/cxl/core/mbox.c +36
-0+ +if (num_partitions <1 || num_partitions >CXL_MAX_DC_PARTITIONS ) { +dev_err (dev,"Invalid num of dynamic capacity partitions %d\n" , + num_partitions); +return -EINVAL ; + } + +for (i = start_partition, j =0 ; i < num_partitions; i++, j++) { + rc =cxl_dc_check (dev, partitions, i, + &dc_resp->partition[j]); +if (rc) +return rc; + } + + start_partition = num_partitions; + + }while (num_partitions < dc_resp->avail_partition_count); + +/* Return 1st partition */ + dc_info->start = partitions[0 ].start; + dc_info->size = partitions[0 ].size; +dev_dbg (dev,"Returning partition 0 %zu size %zu\n" , + dc_info->start, dc_info->size); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dc_identify,"CXL" ); +static void add_part (struct cxl_dpa_info *info,u64 start,u64 size,enum cxl_partition_mode mode) {int i = info->nr_partitions;@@ -1421,6 +1571,38 @@ int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) }EXPORT_SYMBOL_NS_GPL (cxl_get_dirty_count,"CXL" ); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info) +{ +struct cxl_dc_partition_info dc_info = {0 }; +struct device *dev = mds->cxlds.dev; +size_t skip; +int rc; + + rc =cxl_dev_dc_identify (&mds->cxlds.cxl_mbox, &dc_info);
drivers/cxl/core/mbox.c int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) · line 1591
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+if (rc) { +dev_warn (dev, +"Failed to read Dynamic Capacity config: %d\n" , rc); +cxl_disable_dcd (mds); +return ; + } + +/* Skips between pmem and the dynamic partition are not supported */ + skip = dc_info.start - info->size; +if (skip) {
Would this be sufficient?
if (dc_info.start != info->size)
DJ
Quoted 134 lines
drivers/cxl/core/mbox.c +14
-0+dev_warn (dev, +"Dynamic Capacity skip from pmem not supported: %zu\n" , + skip); +cxl_disable_dcd (mds); +return ; + } + + info->size += dc_info.size; +dev_dbg (dev,"Adding dynamic ram partition A; %zu size %zu\n" , + dc_info.start, dc_info.size); +add_part (info, dc_info.start, dc_info.size,CXL_PARTMODE_DYNAMIC_RAM_A ); +} +EXPORT_SYMBOL_NS_GPL (cxl_configure_dcd,"CXL" ); +int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;drivers/cxl/cxlmem.h +47
-0@@ -380,6 +380,8 @@ struct cxl_security_state {struct kernfs_node *sanitize_node; }; +#define CXL_MAX_DC_PARTITIONS 8 +static inline resource_size_t cxl_pmem_size (struct cxl_dev_state *cxlds) {/* @@ -664,6 +666,31 @@ struct cxl_mbox_set_shutdown_state_in {u8 state; } __packed; +/* See CXL 3.2 Table 8-178 get dynamic capacity config Input Payload */ +struct cxl_mbox_get_dc_config_in { +u8 partition_count; +u8 start_partition_index; +} __packed; + +/* See CXL 3.2 Table 8-179 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_partition_count; +u8 partitions_returned; +u8 rsvd[6 ]; +/* See CXL 3.2 Table 8-180 */ +struct cxl_dc_partition { +__le64 base; +__le64 decode_length; +__le64 length; +__le64 block_size; +__le32 dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + } __packed partition[] __counted_by(partitions_returned); +/* Trailing fields unused */ +} __packed; +#define CXL_DCD_BLOCK_LINE_SIZE 0x40 +/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -787,9 +814,18 @@ enum {int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); + +struct cxl_dc_partition_info { +size_t start; +size_t size; +}; + +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_dpa_fetch (struct cxl_memdev_state *mds,struct cxl_dpa_info *info); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info);struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev,u64 serial,u16 dvsec); void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,@@ -803,6 +839,17 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd, const uuid_t *uuid, union cxl_event *evt);int cxl_get_dirty_count (struct cxl_memdev_state *mds,u32 *count);int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds); + +static inline bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return mds->dcd_supported; +} + +static inline void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ + mds->dcd_supported = false; +} +int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +3
-0@@ -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
-1@@ -133,6 +133,7 @@ struct cxl_dpa_perf {enum cxl_partition_mode {CXL_PARTMODE_RAM ,CXL_PARTMODE_PMEM , +CXL_PARTMODE_DYNAMIC_RAM_A , };/** @@ -147,7 +148,7 @@ struct cxl_dpa_partition {enum cxl_partition_mode mode; }; -#define CXL_NR_PARTITIONS_MAX 2 +#define CXL_NR_PARTITIONS_MAX 3/** * struct cxl_dev_state - The driver device state
Re: [PATCH v10 02/31] cxl/mem: Read dynamic capacity configuration from the device
Quoted 10 lines · Dave Jiang
Quoted 4 lines · 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
4.0
done
Quoted 7 lines
Quoted 4 lines
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
4.0
done :)
Quoted 16 lines
Quoted 16 lines
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.
Quoted 6 lines
Quoted 3 lines
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Missing Anisa sign off
Added
Quoted 70 lines
Quoted 70 lines
---
Changes:
[anisa: rebase]
[jonathan:mbox.c: use max possible size forget_dc_configcommand to avoid vmalloc]
[jonathan & fan:cxlmem.h: remove unused structcxl_mem_dev_info]--- drivers/cxl/core/hdm.c | 2 + drivers/cxl/core/mbox.c | 182 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 47 +++++++++++ drivers/cxl/pci.c | 3 + include/cxl/cxl.h | 3 +- 5 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/hdm.c +2
-0@@ -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 +34
-0@@ -1351,6 +1351,156 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)return -EBUSY ; } +static int cxl_dc_check (struct device *dev,struct cxl_dc_partition_info *part_array, +u8 index,struct cxl_dc_partition *dev_part) +{ +size_t blk_size =le64_to_cpu (dev_part->block_size); +size_t len =le64_to_cpu (dev_part->length); + + 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 ; + +/* Check partitions are in increasing DPA order */ +if (index >0 ) { +struct cxl_dc_partition_info *prev_part = &part_array[index -1 ]; + +if ((prev_part->start + prev_part->size) > + part_array[index].start) { +dev_err (dev, +"DPA ordering violation for DC partition %d and %d\n" , + index -1 , index); +return -EINVAL ; + } + } + +if (!IS_ALIGNED (part_array[index].start,SZ_256M ) || + !IS_ALIGNED (part_array[index].start, blk_size)) { +dev_err (dev,"DC partition %d invalid start %zu blk size %zu\n" , + index, part_array[index].start, blk_size); +return -EINVAL ; + } + +if (part_array[index].size ==0 || len ==0 || + part_array[index].size < len || !IS_ALIGNED (len, blk_size)) { +dev_err (dev,"DC partition %d invalid length; size %zu len %zu blk size %zu\n" , + index, part_array[index].size, len, blk_size);
Quoted 9 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1393
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+return -EINVAL ; + } + +if (blk_size ==0 || blk_size %CXL_DCD_BLOCK_LINE_SIZE || + !is_power_of_2 (blk_size)) { + dev_err(dev, "DC partition %d invalid block size; %zu\n",size: instead of size;
fixed!
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1398
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+ index, blk_size); +return -EINVAL ; + } + + dev_dbg(dev, "DC partition %d start %zu start %zu size %zu\n",should it be "DC partition %d start %zu size %zu
blk_size: %zu\n"?
yep, fixed! Also I changed the type of
struct cxl_dc_partition_info->start/size from size_t to u64 so the print specifier uses %llu now. Unless it's better to stick with size_t?
Quoted 57 lines
Quoted 43 lines
drivers/cxl/core/mbox.c +43
-0+ index, part_array[index].start, part_array[index].size, + blk_size); + +return 0 ; +} + +/* Returns the number of partitions in dc_resp or -ERRNO */ +static int cxl_get_dc_config (struct cxl_mailbox *mbox,u8 start_partition, +struct cxl_mbox_get_dc_config_out *dc_resp, +size_t dc_resp_size) +{ +struct cxl_mbox_get_dc_config_in get_dc = (struct cxl_mbox_get_dc_config_in ) { + .partition_count =CXL_MAX_DC_PARTITIONS , + .start_partition_index = start_partition, + }; +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_CONFIG , + .payload_in = &get_dc, + .size_in =sizeof (get_dc), + .size_out = dc_resp_size, + .payload_out = dc_resp, + .min_out =8 , + }; +int rc; + + rc =cxl_internal_send_cmd (mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +dev_dbg (mbox->host,"Read %d/%d DC partitions\n" , + dc_resp->partitions_returned, dc_resp->avail_partition_count); +return dc_resp->partitions_returned; +} + +/** +* cxl_dev_dc_identify() - Reads the dynamic capacity information from the +* device. +* @mbox: Mailbox to query +* @dc_info: The dynamic partition information to return +* +* Read Dynamic Capacity information from the device and return the partition +* information. +* drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1451
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+* Return: 0 if identify was executed successfully, -ERRNO on error. +* on error only dynamic_bytes is left unchanged. +*/ +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info) +{ +struct cxl_dc_partition_info partitions[CXL_MAX_DC_PARTITIONS ]; +struct device *dev = mbox->host; +size_t dc_resp_size = +sizeof (struct cxl_mbox_get_dc_config_out ) +sizeof (partitions);I think it needs to be something like below because of the 'partition' flex array:
size_tdc_resp_size=struct_size(dc_resp, partition, CXL_MAX_DC_PARTITIONS);
Quoted 3 lines
partitions is type 'struct
cxl_dc_partition_info'. anddc_resp->partitionis type 'structcxl_dc_partition'. So the size calucation is wrong. It should at least be:size_tdc_resp_size=sizeof(struct cxl_mbox_get_dc_config_out)+sizeof(struct cxl_dc_partition)*CXL_MAX_DC_PARTITIONS;
Fixed!
Quoted 13 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1460
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+u8 start_partition; +u8 num_partitions; + + struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) = +kmalloc (dc_resp_size,GFP_KERNEL ); +if (!dc_resp) +return -ENOMEM ; + +/** /*
Quoted 14 lines
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+* Read and check all partition information for validity and potential +* debugging; see debug output in cxl_dc_check() +*/ + start_partition =0 ;drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1474
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ num_partitions =0 ; + do { + int rc, i, j; + + rc = cxl_get_dc_config(mbox, start_partition, dc_resp, dc_resp_size); + if (rc < 0) { + dev_err(dev, "Failed to get DC config: %d\n", rc); + return rc; + } +
if (rc == 0) {
dev_err(dev,
"Device reported %u partitions available but returned none at index %u\n",
dc_resp->avail_partition_count, start_partition);
return -EIO;
}Quoted 4 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1475
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+ num_partitions += rc;Would
cxl_get_dc_config()keep returning 0 be a problem? Not likely to happen unless device is malicious.
Not sure but I added a check anyway. ^ See above. It prohibits cxl_get_dc_config() returning 0 at all though. But could be changed to err only if 0 partitions are returned X amount of times...?
Quoted 56 lines
Quoted 43 lines
drivers/cxl/core/mbox.c +36
-0+ +if (num_partitions <1 || num_partitions >CXL_MAX_DC_PARTITIONS ) { +dev_err (dev,"Invalid num of dynamic capacity partitions %d\n" , + num_partitions); +return -EINVAL ; + } + +for (i = start_partition, j =0 ; i < num_partitions; i++, j++) { + rc =cxl_dc_check (dev, partitions, i, + &dc_resp->partition[j]); +if (rc) +return rc; + } + + start_partition = num_partitions; + + }while (num_partitions < dc_resp->avail_partition_count); + +/* Return 1st partition */ + dc_info->start = partitions[0 ].start; + dc_info->size = partitions[0 ].size; +dev_dbg (dev,"Returning partition 0 %zu size %zu\n" , + dc_info->start, dc_info->size); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dc_identify,"CXL" ); +static void add_part (struct cxl_dpa_info *info,u64 start,u64 size,enum cxl_partition_mode mode) {int i = info->nr_partitions;@@ -1421,6 +1571,38 @@ int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) }EXPORT_SYMBOL_NS_GPL (cxl_get_dirty_count,"CXL" ); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info) +{ +struct cxl_dc_partition_info dc_info = {0 }; +struct device *dev = mds->cxlds.dev; +size_t skip; +int rc; + + rc =cxl_dev_dc_identify (&mds->cxlds.cxl_mbox, &dc_info);drivers/cxl/core/mbox.c int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) · line 1591
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+if (rc) { +dev_warn (dev, +"Failed to read Dynamic Capacity config: %d\n" , rc); +cxl_disable_dcd (mds); +return ; + } + +/* Skips between pmem and the dynamic partition are not supported */ + skip = dc_info.start - info->size; +if (skip) {Would this be sufficient?
Quoted 2 lines
if (dc_info.start !=
info->size)
Fixed!
Quoted 1 line
DJ
Thanks,
Anisa
Quoted 135 lines
Quoted 134 lines
drivers/cxl/core/mbox.c +14
-0+dev_warn (dev, +"Dynamic Capacity skip from pmem not supported: %zu\n" , + skip); +cxl_disable_dcd (mds); +return ; + } + + info->size += dc_info.size; +dev_dbg (dev,"Adding dynamic ram partition A; %zu size %zu\n" , + dc_info.start, dc_info.size); +add_part (info, dc_info.start, dc_info.size,CXL_PARTMODE_DYNAMIC_RAM_A ); +} +EXPORT_SYMBOL_NS_GPL (cxl_configure_dcd,"CXL" ); +int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;drivers/cxl/cxlmem.h +47
-0@@ -380,6 +380,8 @@ struct cxl_security_state {struct kernfs_node *sanitize_node; }; +#define CXL_MAX_DC_PARTITIONS 8 +static inline resource_size_t cxl_pmem_size (struct cxl_dev_state *cxlds) {/* @@ -664,6 +666,31 @@ struct cxl_mbox_set_shutdown_state_in {u8 state; } __packed; +/* See CXL 3.2 Table 8-178 get dynamic capacity config Input Payload */ +struct cxl_mbox_get_dc_config_in { +u8 partition_count; +u8 start_partition_index; +} __packed; + +/* See CXL 3.2 Table 8-179 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_partition_count; +u8 partitions_returned; +u8 rsvd[6 ]; +/* See CXL 3.2 Table 8-180 */ +struct cxl_dc_partition { +__le64 base; +__le64 decode_length; +__le64 length; +__le64 block_size; +__le32 dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + } __packed partition[] __counted_by(partitions_returned); +/* Trailing fields unused */ +} __packed; +#define CXL_DCD_BLOCK_LINE_SIZE 0x40 +/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -787,9 +814,18 @@ enum {int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); + +struct cxl_dc_partition_info { +size_t start; +size_t size; +}; + +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_dpa_fetch (struct cxl_memdev_state *mds,struct cxl_dpa_info *info); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info);struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev,u64 serial,u16 dvsec); void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,@@ -803,6 +839,17 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd, const uuid_t *uuid, union cxl_event *evt);int cxl_get_dirty_count (struct cxl_memdev_state *mds,u32 *count);int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds); + +static inline bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return mds->dcd_supported; +} + +static inline void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ + mds->dcd_supported = false; +} +int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +3
-0@@ -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
-1@@ -133,6 +133,7 @@ struct cxl_dpa_perf {enum cxl_partition_mode {CXL_PARTMODE_RAM ,CXL_PARTMODE_PMEM , +CXL_PARTMODE_DYNAMIC_RAM_A , };/** @@ -147,7 +148,7 @@ struct cxl_dpa_partition {enum cxl_partition_mode mode; }; -#define CXL_NR_PARTITIONS_MAX 2 +#define CXL_NR_PARTITIONS_MAX 3/** * struct cxl_dev_state - The driver device state
Dave Jiang
maintainerRe: [PATCH v10 02/31] cxl/mem: Read dynamic capacity configuration from the device
Quoted 131 lines · Anisa Su
Quoted 10 lines · Dave Jiang
Quoted 4 lines · 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
4.0
done
Quoted 7 lines
Quoted 4 lines
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
4.0
done :)
Quoted 16 lines
Quoted 16 lines
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.
Quoted 6 lines
Quoted 3 lines
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Missing Anisa sign off
Added
Quoted 70 lines
Quoted 70 lines
---
Changes:
[anisa: rebase]
[jonathan:mbox.c: use max possible size forget_dc_configcommand to avoid vmalloc]
[jonathan & fan:cxlmem.h: remove unused structcxl_mem_dev_info]--- drivers/cxl/core/hdm.c | 2 + drivers/cxl/core/mbox.c | 182 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 47 +++++++++++ drivers/cxl/pci.c | 3 + include/cxl/cxl.h | 3 +- 5 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/hdm.c +2
-0@@ -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 +34
-0@@ -1351,6 +1351,156 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)return -EBUSY ; } +static int cxl_dc_check (struct device *dev,struct cxl_dc_partition_info *part_array, +u8 index,struct cxl_dc_partition *dev_part) +{ +size_t blk_size =le64_to_cpu (dev_part->block_size); +size_t len =le64_to_cpu (dev_part->length); + + 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 ; + +/* Check partitions are in increasing DPA order */ +if (index >0 ) { +struct cxl_dc_partition_info *prev_part = &part_array[index -1 ]; + +if ((prev_part->start + prev_part->size) > + part_array[index].start) { +dev_err (dev, +"DPA ordering violation for DC partition %d and %d\n" , + index -1 , index); +return -EINVAL ; + } + } + +if (!IS_ALIGNED (part_array[index].start,SZ_256M ) || + !IS_ALIGNED (part_array[index].start, blk_size)) { +dev_err (dev,"DC partition %d invalid start %zu blk size %zu\n" , + index, part_array[index].start, blk_size); +return -EINVAL ; + } + +if (part_array[index].size ==0 || len ==0 || + part_array[index].size < len || !IS_ALIGNED (len, blk_size)) { +dev_err (dev,"DC partition %d invalid length; size %zu len %zu blk size %zu\n" , + index, part_array[index].size, len, blk_size);Quoted 9 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1393
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+return -EINVAL ; + } + +if (blk_size ==0 || blk_size %CXL_DCD_BLOCK_LINE_SIZE || + !is_power_of_2 (blk_size)) { + dev_err(dev, "DC partition %d invalid block size; %zu\n",size: instead of size;
fixed!
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1398
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+ index, blk_size); +return -EINVAL ; + } + + dev_dbg(dev, "DC partition %d start %zu start %zu size %zu\n",should it be "DC partition %d start %zu size %zu
blk_size: %zu\n"?
Quoted 4 lines
yep, fixed! Also I changed the type of
struct cxl_dc_partition_info->start/size fromsize_tto u64 so the print specifier uses %llu now. Unless it's better to stick withsize_t?
I think u64 would be explicit and better. I can just see the kbot complaining about 32bit systems and size_t....
Quoted 95 lines
Quoted 58 lines
Quoted 44 lines
drivers/cxl/core/mbox.c +43
-0+ index, part_array[index].start, part_array[index].size, + blk_size); + +return 0 ; +} + +/* Returns the number of partitions in dc_resp or -ERRNO */ +static int cxl_get_dc_config (struct cxl_mailbox *mbox,u8 start_partition, +struct cxl_mbox_get_dc_config_out *dc_resp, +size_t dc_resp_size) +{ +struct cxl_mbox_get_dc_config_in get_dc = (struct cxl_mbox_get_dc_config_in ) { + .partition_count =CXL_MAX_DC_PARTITIONS , + .start_partition_index = start_partition, + }; +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_CONFIG , + .payload_in = &get_dc, + .size_in =sizeof (get_dc), + .size_out = dc_resp_size, + .payload_out = dc_resp, + .min_out =8 , + }; +int rc; + + rc =cxl_internal_send_cmd (mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +dev_dbg (mbox->host,"Read %d/%d DC partitions\n" , + dc_resp->partitions_returned, dc_resp->avail_partition_count); +return dc_resp->partitions_returned; +} + +/** +* cxl_dev_dc_identify() - Reads the dynamic capacity information from the +* device. +* @mbox: Mailbox to query +* @dc_info: The dynamic partition information to return +* +* Read Dynamic Capacity information from the device and return the partition +* information. +* drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1451
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+* Return: 0 if identify was executed successfully, -ERRNO on error. +* on error only dynamic_bytes is left unchanged. +*/ +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info) +{ +struct cxl_dc_partition_info partitions[CXL_MAX_DC_PARTITIONS ]; +struct device *dev = mbox->host; +size_t dc_resp_size = +sizeof (struct cxl_mbox_get_dc_config_out ) +sizeof (partitions);I think it needs to be something like below because of the 'partition' flex array:
size_tdc_resp_size=struct_size(dc_resp, partition, CXL_MAX_DC_PARTITIONS);Quoted 3 lines
partitions is type 'struct
cxl_dc_partition_info'. anddc_resp->partitionis type 'structcxl_dc_partition'. So the size calucation is wrong. It should at least be:size_tdc_resp_size=sizeof(struct cxl_mbox_get_dc_config_out)+sizeof(struct cxl_dc_partition)*CXL_MAX_DC_PARTITIONS;Fixed!
Quoted 13 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1460
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+u8 start_partition; +u8 num_partitions; + + struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) = +kmalloc (dc_resp_size,GFP_KERNEL ); +if (!dc_resp) +return -ENOMEM ; + +/** /*
Quoted 14 lines
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+* Read and check all partition information for validity and potential +* debugging; see debug output in cxl_dc_check() +*/ + start_partition =0 ;drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1474
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ num_partitions =0 ; + do { + int rc, i, j; + + rc = cxl_get_dc_config(mbox, start_partition, dc_resp, dc_resp_size); + if (rc < 0) { + dev_err(dev, "Failed to get DC config: %d\n", rc); + return rc; + } +if (rc == 0) { dev_err(dev, "Device reported %u partitions available but returned none at index %u\n", dc_resp->avail_partition_count, start_partition); return -EIO; }
Quoted 7 lines
Quoted 4 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1475
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+ num_partitions += rc;Would
cxl_get_dc_config()keep returning 0 be a problem? Not likely to happen unless device is malicious.Not sure but I added a check anyway. ^ See above. It prohibits
cxl_get_dc_config()returning 0 at all though. But could be changed to err only if 0 partitions are returned X amount of times...?
I think as long as we have a way to detect that we aren't moving forward in this loop and need to get out at some point.
DJ
Quoted 197 lines
Quoted 56 lines
Quoted 43 lines
drivers/cxl/core/mbox.c +36
-0+ +if (num_partitions <1 || num_partitions >CXL_MAX_DC_PARTITIONS ) { +dev_err (dev,"Invalid num of dynamic capacity partitions %d\n" , + num_partitions); +return -EINVAL ; + } + +for (i = start_partition, j =0 ; i < num_partitions; i++, j++) { + rc =cxl_dc_check (dev, partitions, i, + &dc_resp->partition[j]); +if (rc) +return rc; + } + + start_partition = num_partitions; + + }while (num_partitions < dc_resp->avail_partition_count); + +/* Return 1st partition */ + dc_info->start = partitions[0 ].start; + dc_info->size = partitions[0 ].size; +dev_dbg (dev,"Returning partition 0 %zu size %zu\n" , + dc_info->start, dc_info->size); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dc_identify,"CXL" ); +static void add_part (struct cxl_dpa_info *info,u64 start,u64 size,enum cxl_partition_mode mode) {int i = info->nr_partitions;@@ -1421,6 +1571,38 @@ int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) }EXPORT_SYMBOL_NS_GPL (cxl_get_dirty_count,"CXL" ); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info) +{ +struct cxl_dc_partition_info dc_info = {0 }; +struct device *dev = mds->cxlds.dev; +size_t skip; +int rc; + + rc =cxl_dev_dc_identify (&mds->cxlds.cxl_mbox, &dc_info);drivers/cxl/core/mbox.c int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count) · line 1591
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+if (rc) { +dev_warn (dev, +"Failed to read Dynamic Capacity config: %d\n" , rc); +cxl_disable_dcd (mds); +return ; + } + +/* Skips between pmem and the dynamic partition are not supported */ + skip = dc_info.start - info->size; +if (skip) {Would this be sufficient?
Quoted 2 lines
if (dc_info.start !=
info->size)Fixed!
Quoted 1 line
DJ
Thanks,
AnisaQuoted 135 lines
Quoted 134 lines
drivers/cxl/core/mbox.c +14
-0+dev_warn (dev, +"Dynamic Capacity skip from pmem not supported: %zu\n" , + skip); +cxl_disable_dcd (mds); +return ; + } + + info->size += dc_info.size; +dev_dbg (dev,"Adding dynamic ram partition A; %zu size %zu\n" , + dc_info.start, dc_info.size); +add_part (info, dc_info.start, dc_info.size,CXL_PARTMODE_DYNAMIC_RAM_A ); +} +EXPORT_SYMBOL_NS_GPL (cxl_configure_dcd,"CXL" ); +int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;drivers/cxl/cxlmem.h +47
-0@@ -380,6 +380,8 @@ struct cxl_security_state {struct kernfs_node *sanitize_node; }; +#define CXL_MAX_DC_PARTITIONS 8 +static inline resource_size_t cxl_pmem_size (struct cxl_dev_state *cxlds) {/* @@ -664,6 +666,31 @@ struct cxl_mbox_set_shutdown_state_in {u8 state; } __packed; +/* See CXL 3.2 Table 8-178 get dynamic capacity config Input Payload */ +struct cxl_mbox_get_dc_config_in { +u8 partition_count; +u8 start_partition_index; +} __packed; + +/* See CXL 3.2 Table 8-179 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_partition_count; +u8 partitions_returned; +u8 rsvd[6 ]; +/* See CXL 3.2 Table 8-180 */ +struct cxl_dc_partition { +__le64 base; +__le64 decode_length; +__le64 length; +__le64 block_size; +__le32 dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + } __packed partition[] __counted_by(partitions_returned); +/* Trailing fields unused */ +} __packed; +#define CXL_DCD_BLOCK_LINE_SIZE 0x40 +/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -787,9 +814,18 @@ enum {int cxl_internal_send_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); + +struct cxl_dc_partition_info { +size_t start; +size_t size; +}; + +int cxl_dev_dc_identify (struct cxl_mailbox *mbox, +struct cxl_dc_partition_info *dc_info);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_dpa_fetch (struct cxl_memdev_state *mds,struct cxl_dpa_info *info); +void cxl_configure_dcd (struct cxl_memdev_state *mds,struct cxl_dpa_info *info);struct cxl_memdev_state *cxl_memdev_state_create (struct device *dev,u64 serial,u16 dvsec); void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,@@ -803,6 +839,17 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd, const uuid_t *uuid, union cxl_event *evt);int cxl_get_dirty_count (struct cxl_memdev_state *mds,u32 *count);int cxl_arm_dirty_shutdown (struct cxl_memdev_state *mds); + +static inline bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return mds->dcd_supported; +} + +static inline void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ + mds->dcd_supported = false; +} +int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +3
-0@@ -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
-1@@ -133,6 +133,7 @@ struct cxl_dpa_perf {enum cxl_partition_mode {CXL_PARTMODE_RAM ,CXL_PARTMODE_PMEM , +CXL_PARTMODE_DYNAMIC_RAM_A , };/** @@ -147,7 +148,7 @@ struct cxl_dpa_partition {enum cxl_partition_mode mode; }; -#define CXL_NR_PARTITIONS_MAX 2 +#define CXL_NR_PARTITIONS_MAX 3/** * struct cxl_dev_state - The driver device state
Re: [PATCH v10 02/31] cxl/mem: Read dynamic capacity configuration from the device
Quoted 7 lines · Dave Jiang
Quoted 4 lines · Anisa Su
Quoted 3 lines · Dave Jiang
On 5/23/26 2:42 AM, Anisa Su wrote:
[snip]
Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1460
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+ struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) = +kmalloc (dc_resp_size,GFP_KERNEL ); +if (!dc_resp) +return -ENOMEM ; + +/** /*
Quoted 14 lines
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+* Read and check all partition information for validity and potential +* debugging; see debug output in cxl_dc_check() +*/ + start_partition =0 ;drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1474
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ num_partitions =0 ; + do { + int rc, i, j; + + rc = cxl_get_dc_config(mbox, start_partition, dc_resp, dc_resp_size); + if (rc < 0) { + dev_err(dev, "Failed to get DC config: %d\n", rc); + return rc; + } +if (rc == 0) { dev_err(dev, "Device reported %u partitions available but returned none at index %u\n", dc_resp->avail_partition_count, start_partition); return -EIO; }Quoted 4 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1475
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+ num_partitions += rc;Would
cxl_get_dc_config()keep returning 0 be a problem? Not likely to happen unless device is malicious.
Quoted 8 lines
Quoted 3 lines
Not sure but I added a check anyway. ^ See above. It prohibits
cxl_get_dc_config()returning 0 at all though. But could be changed to err only if 0 partitions are returned X amount of times...?I think as long as we have a way to detect that we aren't moving forward in this loop and need to get out at some point.
DJ
I'll keep the check above then, and just prohibit returning 0 partitions when the device reports that it has more partitions available, since I don't think it makes sense for the device to transiently return 0 and for some reason make progress on retry anyway...
But need to move it below this check
if (num_partitions < 1 || num_partitions > CXL_MAX_DC_PARTITIONS) {
so the no forward progress check is differentiated from returning 0 partitions.
Thanks,
Anisa
Quoted 29 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
drivers/cxl/core/mbox.c +28
-0+ +if (num_partitions <1 || num_partitions >CXL_MAX_DC_PARTITIONS ) { +dev_err (dev,"Invalid num of dynamic capacity partitions %d\n" , + num_partitions); +return -EINVAL ; + } + +for (i = start_partition, j =0 ; i < num_partitions; i++, j++) { + rc =cxl_dc_check (dev, partitions, i, + &dc_resp->partition[j]); +if (rc) +return rc; + } + + start_partition = num_partitions; + + }while (num_partitions < dc_resp->avail_partition_count); + +/* Return 1st partition */ + dc_info->start = partitions[0 ].start; + dc_info->size = partitions[0 ].size; +dev_dbg (dev,"Returning partition 0 %zu size %zu\n" , + dc_info->start, dc_info->size); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dc_identify,"CXL" ); +
[snip]
PATCH v10 3/31 cxl/cdat: Gather DSMAS data for DCD partitions
In reply to Anisa SuFrom: 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]
[jonathan: core/mbox.c: error if there are non-zero reserved bits in DSMAD handle in cxl_dc_check]
--- 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
@@ -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
@@ -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
@@ -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; };
@@ -818,6 +819,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
@@ -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 3
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 03/31] cxl/cdat: Gather DSMAS data for DCD partitions
Quoted 7 lines · 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.
DCD handle needs to be propogated.
add_part() needs to copy over the handlecxl_dpa_setup() also needs to copy the handle
Would be good to get this checked against actual hardware.
Quoted 51 lines
Signed-off-by Ira Weiny <[email protected]>---
Changes:
[anisa: rebase]
[jonathan:core/mbox.c: error if there are non-zero reserved bits in DSMAD handle incxl_dc_check]--- 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 +5
-0@@ -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 = {
drivers/cxl/core/cdat.c static void cxl_memdev_set_qos_class(struct cxl_dev_state *cxlds, · line 285
Quoted 10 lines
drivers/cxl/core/cdat.c +5
-0.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);
Should it 'continue' here since it mismatches?
DJ
Quoted 86 lines
drivers/cxl/core/cdat.c +1
-0+update_perf_entry (dev, dent, &cxlds->part[i].perf); found = true;drivers/cxl/core/mbox.c +7
-0@@ -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@@ -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; };@@ -818,6 +819,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@@ -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 3
Re: [PATCH v10 03/31] cxl/cdat: Gather DSMAS data for DCD partitions
Quoted 9 lines · Dave Jiang
Quoted 6 lines · 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.
Quoted 5 lines
Quoted 1 line
Match DCD partitions with DSMAS tables and store the meta data.
DCD handle needs to be propogated.
add_part()needs to copy over the handle
Fixed: add_part() function signature gains u8 handle parameter.
Call site from cxl_mem_dpa_fetch() for RAM and PMEM partitions passes in 0 for handle.
Call site from cxl_configure_dcd() passes in dc_info->handle.
Quoted 1 line
cxl_dpa_setup()also needs to copy the handle
Fixed
Quoted 4 lines
Would be good to get this checked against actual hardware.
Yes, we are coordinating with another team within Samsung to validate.
Quoted 56 lines
Quoted 56 lines
Signed-off-by Ira Weiny <[email protected]>---
Changes:
[anisa: rebase]
[jonathan:core/mbox.c: error if there are non-zero reserved bits in DSMAD handle incxl_dc_check]--- 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 +5
-0@@ -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, };
Quoted 9 lines
drivers/cxl/core/cdat.c static void cxl_memdev_set_qos_class(struct cxl_dev_state *cxlds, · line 285
Quoted 6 lines
drivers/cxl/core/cdat.c +5
-0if (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);Should it 'continue' here since it mismatches?
Fixed!
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 87 lines
Quoted 86 lines
drivers/cxl/core/cdat.c +1
-0+update_perf_entry (dev, dent, &cxlds->part[i].perf); found = true;drivers/cxl/core/mbox.c +7
-0@@ -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@@ -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; };@@ -818,6 +819,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@@ -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 3
PATCH v10 4/31 cxl/core: Enforce partition order/simplify partition calls
In reply to Anisa SuFrom: 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]
[davidlohr: core/hdm.c: return -EINVAL instead of 0 in cxl_dpa_setup if partitions are out of order]
--- 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
@@ -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
@@ -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
@@ -383,14 +383,11 @@ struct cxl_security_state {#define CXL_MAX_DC_PARTITIONS 8 -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
@@ -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
Dave Jiang
maintainerRe: [PATCH v10 04/31] cxl/core: Enforce partition order/simplify partition calls
Quoted 36 lines · 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.
Signed-off-by Ira Weiny <[email protected]>---
Changes::
[anisa: rebase]
[davidlohr:core/hdm.c: return-EINVALinstead of 0 incxl_dpa_setupif partitions are out of order]--- 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 +1
-0@@ -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);
drivers/cxl/core/hdm.c int cxl_dpa_setup(struct cxl_dev_state *cxlds, const struct cxl_dpa_info *info) · line 482
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0@@ -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) {
I think we need to check info->part[i].mode and not cxlds here. cxlds mode is assigned later in this function.
DJ
Quoted 145 lines
drivers/cxl/core/hdm.c +6
-1+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@@ -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@@ -383,14 +383,11 @@ struct cxl_security_state {#define CXL_MAX_DC_PARTITIONS 8 -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@@ -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 )
Re: [PATCH v10 04/31] cxl/core: Enforce partition order/simplify partition calls
Quoted 42 lines · Dave Jiang
Quoted 39 lines · 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.
Signed-off-by Ira Weiny <[email protected]>---
Changes::
[anisa: rebase]
[davidlohr:core/hdm.c: return-EINVALinstead of 0 incxl_dpa_setupif partitions are out of order]--- 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 +1
-0@@ -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 ; }
Quoted 6 lines
drivers/cxl/core/hdm.c int cxl_dpa_setup(struct cxl_dev_state *cxlds, const struct cxl_dpa_info *info) · line 482
Quoted 3 lines
drivers/cxl/core/hdm.c +3
-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) {I think we need to check info->part[i].mode and not cxlds here. cxlds mode is assigned later in this function.
fixed!
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 147 lines
Quoted 146 lines
drivers/cxl/core/hdm.c +6
-1+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@@ -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@@ -383,14 +383,11 @@ struct cxl_security_state {#define CXL_MAX_DC_PARTITIONS 8 -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@@ -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 )
PATCH v10 5/31 cxl/mem: Expose dynamic ram A partition in sysfs
In reply to Anisa SuFrom: 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
@@ -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
Re: [PATCH v10 05/31] cxl/mem: Expose dynamic ram A partition in sysfs
Quoted 8 lines · 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.
Signed-off-by Ira Weiny <[email protected]>
Missing Anisa sign off
Quoted 142 lines
---
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@@ -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, 2022drivers/cxl/core/memdev.c +57
-0@@ -101,6 +101,19 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,static struct device_attribute dev_attr_pmem_size =__ATTR (size,0444 , pmem_size_show,NULL ); +static ssize_t dynamic_ram_a_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_part_size (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +return sysfs_emit (buf,"%#llx\n" , len); +} + +static struct device_attribute dev_attr_dynamic_ram_a_size = +__ATTR (size,0444 , dynamic_ram_a_size_show,NULL ); +static ssize_t serial_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -443,6 +456,25 @@ static struct attribute *cxl_memdev_pmem_attributes[] = { NULL, }; +static ssize_t dynamic_ram_a_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" , +part_perf (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A )->qos_class); +} + +static struct device_attribute dev_attr_dynamic_ram_a_qos_class = +__ATTR (qos_class,0444 , dynamic_ram_a_qos_class_show,NULL ); + +static struct attribute *cxl_memdev_dynamic_ram_a_attributes[] = { + &dev_attr_dynamic_ram_a_size.attr, + &dev_attr_dynamic_ram_a_qos_class.attr, +NULL , +}; +static ssize_t ram_qos_class_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -519,6 +551,29 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = { .is_visible = cxl_pmem_visible, }; +static umode_t cxl_dynamic_ram_a_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 =part_perf (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +if (a == &dev_attr_dynamic_ram_a_qos_class.attr && + (!perf || perf->qos_class ==CXL_QOS_CLASS_INVALID )) +return 0 ; + +if (a == &dev_attr_dynamic_ram_a_size.attr && + (!cxl_part_size (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ))) +return 0 ; + +return a->mode; +} + +static struct attribute_group cxl_memdev_dynamic_ram_a_attribute_group = { + .name ="dynamic_ram_a" , + .attrs = cxl_memdev_dynamic_ram_a_attributes, + .is_visible = cxl_dynamic_ram_a_visible, +}; +static umode_t cxl_memdev_security_visible (struct kobject *kobj,struct attribute *a,int n) {@@ -547,6 +602,7 @@ static const struct attribute_group *cxl_memdev_attribute_groups[] = { &cxl_memdev_attribute_group, &cxl_memdev_ram_attribute_group, &cxl_memdev_pmem_attribute_group, + &cxl_memdev_dynamic_ram_a_attribute_group, &cxl_memdev_security_attribute_group, NULL, };@@ -555,6 +611,7 @@ void cxl_memdev_update_perf(struct cxl_memdev *cxlmd) {sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_ram_attribute_group);sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_pmem_attribute_group); +sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_dynamic_ram_a_attribute_group); }EXPORT_SYMBOL_NS_GPL (cxl_memdev_update_perf,"CXL" );
Dave Jiang
maintainerRe: [PATCH v10 05/31] cxl/mem: Expose dynamic ram A partition in sysfs
In reply to Anisa SuQuoted 24 lines · 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.
Signed-off-by Ira Weiny <[email protected]>---
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 +0
-0
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 94
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +3
-0@@ -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
Probably should update this to 7.3 maybe?
DJ
Quoted 120 lines
Documentation/ABI/testing/sysfs-bus-cxl +21
-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, 2022drivers/cxl/core/memdev.c +57
-0@@ -101,6 +101,19 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,static struct device_attribute dev_attr_pmem_size =__ATTR (size,0444 , pmem_size_show,NULL ); +static ssize_t dynamic_ram_a_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_part_size (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +return sysfs_emit (buf,"%#llx\n" , len); +} + +static struct device_attribute dev_attr_dynamic_ram_a_size = +__ATTR (size,0444 , dynamic_ram_a_size_show,NULL ); +static ssize_t serial_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -443,6 +456,25 @@ static struct attribute *cxl_memdev_pmem_attributes[] = { NULL, }; +static ssize_t dynamic_ram_a_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" , +part_perf (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A )->qos_class); +} + +static struct device_attribute dev_attr_dynamic_ram_a_qos_class = +__ATTR (qos_class,0444 , dynamic_ram_a_qos_class_show,NULL ); + +static struct attribute *cxl_memdev_dynamic_ram_a_attributes[] = { + &dev_attr_dynamic_ram_a_size.attr, + &dev_attr_dynamic_ram_a_qos_class.attr, +NULL , +}; +static ssize_t ram_qos_class_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -519,6 +551,29 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = { .is_visible = cxl_pmem_visible, }; +static umode_t cxl_dynamic_ram_a_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 =part_perf (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +if (a == &dev_attr_dynamic_ram_a_qos_class.attr && + (!perf || perf->qos_class ==CXL_QOS_CLASS_INVALID )) +return 0 ; + +if (a == &dev_attr_dynamic_ram_a_size.attr && + (!cxl_part_size (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ))) +return 0 ; + +return a->mode; +} + +static struct attribute_group cxl_memdev_dynamic_ram_a_attribute_group = { + .name ="dynamic_ram_a" , + .attrs = cxl_memdev_dynamic_ram_a_attributes, + .is_visible = cxl_dynamic_ram_a_visible, +}; +static umode_t cxl_memdev_security_visible (struct kobject *kobj,struct attribute *a,int n) {@@ -547,6 +602,7 @@ static const struct attribute_group *cxl_memdev_attribute_groups[] = { &cxl_memdev_attribute_group, &cxl_memdev_ram_attribute_group, &cxl_memdev_pmem_attribute_group, + &cxl_memdev_dynamic_ram_a_attribute_group, &cxl_memdev_security_attribute_group, NULL, };@@ -555,6 +611,7 @@ void cxl_memdev_update_perf(struct cxl_memdev *cxlmd) {sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_ram_attribute_group);sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_pmem_attribute_group); +sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_dynamic_ram_a_attribute_group); }EXPORT_SYMBOL_NS_GPL (cxl_memdev_update_perf,"CXL" );
Re: [PATCH v10 05/31] cxl/mem: Expose dynamic ram A partition in sysfs
Quoted 30 lines · Dave Jiang
Quoted 27 lines · 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.
Signed-off-by Ira Weiny <[email protected]>---
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 +0
-0@@ -89,6 +89,30 @@ Description: and there are platform specific performance related side-effects that may result. First class-id is displayed.
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 94
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-cxl +3
-0+What: /sys/bus/cxl/devices/memX/dynamic_ram_a/size +Date: May, 2025 +KernelVersion: v7.0Probably should update this to 7.3 maybe?
Updated
Quoted 10 lines
DJ
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 102
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-cxl +8
-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
Also updated
Thanks,
Anisa
Quoted 113 lines
Quoted 112 lines
Documentation/ABI/testing/sysfs-bus-cxl +13
-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, 2022drivers/cxl/core/memdev.c +57
-0@@ -101,6 +101,19 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,static struct device_attribute dev_attr_pmem_size =__ATTR (size,0444 , pmem_size_show,NULL ); +static ssize_t dynamic_ram_a_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_part_size (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +return sysfs_emit (buf,"%#llx\n" , len); +} + +static struct device_attribute dev_attr_dynamic_ram_a_size = +__ATTR (size,0444 , dynamic_ram_a_size_show,NULL ); +static ssize_t serial_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -443,6 +456,25 @@ static struct attribute *cxl_memdev_pmem_attributes[] = { NULL, }; +static ssize_t dynamic_ram_a_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" , +part_perf (cxlds,CXL_PARTMODE_DYNAMIC_RAM_A )->qos_class); +} + +static struct device_attribute dev_attr_dynamic_ram_a_qos_class = +__ATTR (qos_class,0444 , dynamic_ram_a_qos_class_show,NULL ); + +static struct attribute *cxl_memdev_dynamic_ram_a_attributes[] = { + &dev_attr_dynamic_ram_a_size.attr, + &dev_attr_dynamic_ram_a_qos_class.attr, +NULL , +}; +static ssize_t ram_qos_class_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -519,6 +551,29 @@ static struct attribute_group cxl_memdev_pmem_attribute_group = { .is_visible = cxl_pmem_visible, }; +static umode_t cxl_dynamic_ram_a_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 =part_perf (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ); + +if (a == &dev_attr_dynamic_ram_a_qos_class.attr && + (!perf || perf->qos_class ==CXL_QOS_CLASS_INVALID )) +return 0 ; + +if (a == &dev_attr_dynamic_ram_a_size.attr && + (!cxl_part_size (cxlmd->cxlds,CXL_PARTMODE_DYNAMIC_RAM_A ))) +return 0 ; + +return a->mode; +} + +static struct attribute_group cxl_memdev_dynamic_ram_a_attribute_group = { + .name ="dynamic_ram_a" , + .attrs = cxl_memdev_dynamic_ram_a_attributes, + .is_visible = cxl_dynamic_ram_a_visible, +}; +static umode_t cxl_memdev_security_visible (struct kobject *kobj,struct attribute *a,int n) {@@ -547,6 +602,7 @@ static const struct attribute_group *cxl_memdev_attribute_groups[] = { &cxl_memdev_attribute_group, &cxl_memdev_ram_attribute_group, &cxl_memdev_pmem_attribute_group, + &cxl_memdev_dynamic_ram_a_attribute_group, &cxl_memdev_security_attribute_group, NULL, };@@ -555,6 +611,7 @@ void cxl_memdev_update_perf(struct cxl_memdev *cxlmd) {sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_ram_attribute_group);sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_pmem_attribute_group); +sysfs_update_group (&cxlmd->dev.kobj, &cxl_memdev_dynamic_ram_a_attribute_group); }EXPORT_SYMBOL_NS_GPL (cxl_memdev_update_perf,"CXL" );
PATCH v10 6/31 cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode
In reply to Anisa SuFrom: 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
@@ -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
@@ -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
Re: [PATCH v10 06/31] cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode
Quoted 9 lines · 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.
Signed-off-by Ira Weiny <[email protected]>
Need Anisa sign off
Just update kver and dates below.
Quoted 14 lines
---
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 +0
-0
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 361
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +1
-2@@ -358,22 +358,22 @@ Description: What: /sys/bus/cxl/devices/decoderX.Y/mode -Date: May, 2022 -KernelVersion: v6.0 +Date: May, 2022, May 2025
A later date
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 362
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-cxl +1
-0+KernelVersion: v6.0, v6.16 (dynamic_ram_a)
7.3 maybe?
DJ
Quoted 53 lines
Documentation/ABI/testing/sysfs-bus-cxl +7
-7Contact: [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_resourcedrivers/cxl/core/port.c +4
-0@@ -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,
Re: [PATCH v10 06/31] cxl/port: Add 'dynamic_ram_a' to endpoint decoder mode
Quoted 11 lines · Dave Jiang
Quoted 8 lines · 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.
Quoted 8 lines
Quoted 1 line
Signed-off-by Ira Weiny <[email protected]>Need Anisa sign off
Reviewed-by Dave Jiang <[email protected]>Just update kver and dates below.
Updated!
Thanks,
Anisa
Quoted 83 lines
Quoted 14 lines
---
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 +0
-0Documentation/ABI/testing/sysfs-bus-cxl Description: · line 361
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +1
-2@@ -358,22 +358,22 @@ Description: What: /sys/bus/cxl/devices/decoderX.Y/mode -Date: May, 2022 -KernelVersion: v6.0 +Date: May, 2022, May 2025A later date
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 362
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-cxl +1
-0+KernelVersion: v6.0, v6.16 (dynamic_ram_a)7.3 maybe?
DJ
Quoted 53 lines
Documentation/ABI/testing/sysfs-bus-cxl +7
-7Contact: [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_resourcedrivers/cxl/core/port.c +4
-0@@ -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,
PATCH v10 7/31 cxl/region: Add DC DAX region support
In reply to Anisa SuFrom: Ira Weiny <[email protected]>
DC DAX 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 dynamic movement of this memory in the management of DAX regions and devices.
Introduce the concept of a dynamic DAX region. Introduce create_dynamic_ram_a_region() sysfs entry to create such regions. Special case DC-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.
Dynamic regions complicate the range mapping of dax devices. There is no known use case for range mapping on dynamic regions. Avoid the complication by preventing range mapping of dax devices on dynamic regions.
Interleaving is deferred for now. Add checks.
Based on an original patch by Navneet Singh.
---
Changes:
[anisa: rebase]
[anisa: change "sparse" naming conventions and to "dynamic"]
--- 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/cxl/core/region_dax.c | 6 +++++ drivers/dax/bus.c | 10 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 17 +++++++++++-- 8 files changed, 86 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +11 -11
@@ -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
@@ -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
@@ -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
@@ -493,6 +493,11 @@ static int set_interleave_ways(struct cxl_region *cxlr, int val)int save, rc;u8 iw; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && val !=1 ) { +dev_err (&cxlr->dev,"Interleaving and DCD not supported\n" ); +return -EINVAL ; + } + rc =ways_to_eiw (val, &iw);if (rc)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/cxl/core/region_dax.c +6 -0
@@ -84,6 +84,12 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && + cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))
drivers/dax/bus.c +10 -0
@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_dynamic (struct dax_region *dax_region) +{ +return (dax_region->res.flags &IORESOURCE_DAX_DCD ) !=0 ; +} +bool static_dev_dax (struct dev_dax *dev_dax) {return is_static (dev_dax->region);
@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)lockdep_assert_held (&dax_region_rwsem); +if (is_dynamic (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;
@@ -1389,6 +1397,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_dynamic (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
@@ -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_DCD 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 +15 -2
@@ -13,19 +13,32 @@ 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); +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A ) + flags =IORESOURCE_DAX_DCD ; +else + flags =IORESOURCE_DAX_KMEM ; + 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
Dave Jiang
maintainerRe: [PATCH v10 07/31] cxl/region: Add DC DAX region support
Quoted 22 lines · Anisa Su
From: Ira Weiny <[email protected]>
DC DAX 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 dynamic movement of this memory in the management of DAX regions and devices.Introduce the concept of a dynamic DAX region. Introduce
create_dynamic_ram_a_region()sysfs entry to create such regions. Special case DC-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.
Dynamic regions complicate the range mapping of dax devices. There is no known use case for range mapping on dynamic regions. Avoid the complication by preventing range mapping of dax devices on dynamic regions.
Quoted 5 lines
Interleaving is deferred for now. Add checks.
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>
Missing Anisa sign off
Quoted 21 lines
---
Changes:
[anisa: rebase]
[anisa: change "sparse" naming conventions and to "dynamic"]--- 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/cxl/core/region_dax.c | 6 +++++ drivers/dax/bus.c | 10 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 17 +++++++++++-- 8 files changed, 86 insertions(+), 15 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +0
-0
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 439
Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-cxl +3
-3@@ -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)
update
Quoted 35 lines
Documentation/ABI/testing/sysfs-bus-cxl +8
-8Contact: [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_regiondrivers/cxl/core/core.h +1
-0@@ -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;
drivers/cxl/core/core.h enum cxl_detach_mode { · line 28
Quoted 10 lines
drivers/cxl/core/core.h +7
-0@@ -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);
return to_cxl_memdev_state(cxlmd->cxlds);
Quoted 18 lines
drivers/cxl/core/core.h +3
-0+} +#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 +0
-0
drivers/cxl/core/port.c static struct attribute *cxl_decoder_root_attrs[] = { · line 340
Quoted 4 lines
drivers/cxl/core/port.c +1
-0@@ -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)
With this add, may need to add checks in cxl_root_decoder_visible() for dynamic_ram for create and also delete.
Quoted 28 lines
drivers/cxl/core/port.c +0
-0SET_CXL_REGION_ATTR(delete_region) NULL, };drivers/cxl/core/region.c +6
-0@@ -493,6 +493,11 @@ static int set_interleave_ways(struct cxl_region *cxlr, int val)int save, rc;u8 iw; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && val !=1 ) { +dev_err (&cxlr->dev,"Interleaving and DCD not supported\n" ); +return -EINVAL ; + } + rc =ways_to_eiw (val, &iw);if (rc)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);
drivers/cxl/core/region.c static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos, · line 2411
Quoted 8 lines
drivers/cxl/core/region.c +3
-2@@ -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))) {
cxled_to_mds() can return NULL with the earlier change suggested. Need to handle that
DJ
Quoted 149 lines
drivers/cxl/core/region.c +22
-0+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/cxl/core/region_dax.c +6
-0@@ -84,6 +84,12 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && + cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))drivers/dax/bus.c +10
-0@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_dynamic (struct dax_region *dax_region) +{ +return (dax_region->res.flags &IORESOURCE_DAX_DCD ) !=0 ; +} +bool static_dev_dax (struct dev_dax *dev_dax) {return is_static (dev_dax->region);@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)lockdep_assert_held (&dax_region_rwsem); +if (is_dynamic (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;@@ -1389,6 +1397,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_dynamic (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@@ -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_DCD 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 +15
-2@@ -13,19 +13,32 @@ 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); +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A ) + flags =IORESOURCE_DAX_DCD ; +else + flags =IORESOURCE_DAX_KMEM ; + 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, };
Re: [PATCH v10 07/31] cxl/region: Add DC DAX region support
Quoted 25 lines · Dave Jiang
Quoted 22 lines · Anisa Su
From: Ira Weiny <[email protected]>
DC DAX 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 dynamic movement of this memory in the management of DAX regions and devices.Introduce the concept of a dynamic DAX region. Introduce
create_dynamic_ram_a_region()sysfs entry to create such regions. Special case DC-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.
Dynamic regions complicate the range mapping of dax devices. There is no known use case for range mapping on dynamic regions. Avoid the complication by preventing range mapping of dax devices on dynamic regions.
Quoted 8 lines
Quoted 5 lines
Interleaving is deferred for now. Add checks.
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Missing Anisa sign off
Added!
Quoted 25 lines
Quoted 25 lines
---
Changes:
[anisa: rebase]
[anisa: change "sparse" naming conventions and to "dynamic"]--- 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/cxl/core/region_dax.c | 6 +++++ drivers/dax/bus.c | 10 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 17 +++++++++++-- 8 files changed, 86 insertions(+), 15 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +0
-0@@ -434,20 +434,20 @@ Description: interleave_granularity).
Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 439
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +3
-3-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)update
updated
Quoted 38 lines
Quoted 38 lines
Documentation/ABI/testing/sysfs-bus-cxl +8
-8Contact: [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_regiondrivers/cxl/core/core.h +1
-0@@ -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, };
Quoted 10 lines
drivers/cxl/core/core.h enum cxl_detach_mode { · line 28
Quoted 7 lines
drivers/cxl/core/core.h +7
-0+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);return
to_cxl_memdev_state(cxlmd->cxlds);
done
Quoted 16 lines
Quoted 16 lines
drivers/cxl/core/core.h +3
-0+} +#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 +0
-1--- a/drivers/cxl/core/port.c
Quoted 9 lines
drivers/cxl/core/port.c static struct attribute *cxl_decoder_root_attrs[] = { · line 340
Quoted 6 lines
+++
b/drivers/cxl/core/port.cdrivers/cxl/core/port.c +1
-0@@ -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)With this add, may need to add checks in
cxl_root_decoder_visible()fordynamic_ramfor create and also delete.
So for this check, since there's no CXL_DECODER_F_ bit defined for DCD, I considered traversing through all endpoints and seeing if they have a DYNAMIC_RAM_A partition, but that traversal already happens in the store_targetN() path, which also includes the mode mismatch check.
Specifically, in cxl_region_attach:
if (cxlds->part[cxled->part].mode != cxlr->mode) {
dev_dbg(&cxlr->dev, "%s region mode: %d mismatch\n",
dev_name(&cxled->cxld.dev), cxlr->mode);
return -EINVAL;
}Is it sufficient here to prohibit creating a dynamic ram region if the root decoder does not support ram?
if (a == CXL_REGION_ATTR(create_dynamic_ram_a_region) && !can_create_ram(cxlrd))
return 0;
Quoted 31 lines
Quoted 31 lines
drivers/cxl/core/port.c +0
-0SET_CXL_REGION_ATTR(delete_region) NULL, };drivers/cxl/core/region.c +6
-0@@ -493,6 +493,11 @@ static int set_interleave_ways(struct cxl_region *cxlr, int val)int save, rc;u8 iw; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && val !=1 ) { +dev_err (&cxlr->dev,"Interleaving and DCD not supported\n" ); +return -EINVAL ; + } + rc =ways_to_eiw (val, &iw);if (rc)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; }
Quoted 8 lines
drivers/cxl/core/region.c static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos, · line 2411
Quoted 5 lines
drivers/cxl/core/region.c +3
-2- 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))) {
cxled_to_mds()can return NULL with the earlier change suggested. Need to handle that
Fixed
Quoted 2 lines
DJ
Thanks,
Anisa
Also, for potential future support for multiple DC partitions not to be awkward, I think it would make sense to rename dynamic_ram_a to dynamic_ram_1. Any objections?
Quoted 151 lines
Quoted 150 lines
drivers/cxl/core/region.c +22
-0+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/cxl/core/region_dax.c +6
-0@@ -84,6 +84,12 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && + cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + struct cxl_dax_region *cxlr_dax __free(put_cxl_dax_region) =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))drivers/dax/bus.c +10
-0@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_dynamic (struct dax_region *dax_region) +{ +return (dax_region->res.flags &IORESOURCE_DAX_DCD ) !=0 ; +} +bool static_dev_dax (struct dev_dax *dev_dax) {return is_static (dev_dax->region);@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)lockdep_assert_held (&dax_region_rwsem); +if (is_dynamic (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;@@ -1389,6 +1397,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_dynamic (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@@ -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_DCD 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 +15
-2@@ -13,19 +13,32 @@ 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); +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A ) + flags =IORESOURCE_DAX_DCD ; +else + flags =IORESOURCE_DAX_KMEM ; + 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, };
Dave Jiang
maintainerRe: [PATCH v10 07/31] cxl/region: Add DC DAX region support
Quoted 5 lines · Anisa Su
Quoted 4 lines · Dave Jiang
Quoted 1 line · Anisa Su
From: Ira Weiny <[email protected]>
< --snip -->
Quoted 25 lines
Quoted 12 lines
drivers/cxl/core/port.c static struct attribute *cxl_decoder_root_attrs[] = { · line 340
Quoted 9 lines
drivers/cxl/core/port.c +1
-0@@ -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)With this add, may need to add checks in
cxl_root_decoder_visible()fordynamic_ramfor create and also delete.So for this check, since there's no
CXL_DECODER_F_bit defined for DCD, I considered traversing through all endpoints and seeing if they have aDYNAMIC_RAM_Apartition, but that traversal already happens in thestore_targetN()path, which also includes the mode mismatch check.Specifically, in
cxl_region_attach:if (cxlds->part[cxled->part].mode != cxlr->mode) { dev_dbg(&cxlr->dev, "%s region mode: %d mismatch\n", dev_name(&cxled->cxld.dev), cxlr->mode); return -EINVAL; }
Quoted 6 lines
Is it sufficient here to prohibit creating a dynamic ram region if the root decoder does not support ram?
if (a ==
CXL_REGION_ATTR(create_dynamic_ram_a_region)&& !can_create_ram(cxlrd))return 0;
I think so.
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
drivers/cxl/core/port.c +0
-0SET_CXL_REGION_ATTR(delete_region) NULL, };drivers/cxl/core/region.c +6
-0@@ -493,6 +493,11 @@ static int set_interleave_ways(struct cxl_region *cxlr, int val)int save, rc;u8 iw; +if (cxlr->mode ==CXL_PARTMODE_DYNAMIC_RAM_A && val !=1 ) { +dev_err (&cxlr->dev,"Interleaving and DCD not supported\n" ); +return -EINVAL ; + } + rc =ways_to_eiw (val, &iw);if (rc)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; }Quoted 8 lines
drivers/cxl/core/region.c static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos, · line 2411
Quoted 5 lines
drivers/cxl/core/region.c +3
-2- 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))) {
cxled_to_mds()can return NULL with the earlier change suggested. Need to handle thatFixed
Quoted 8 lines
Quoted 2 lines
DJ
Thanks,
AnisaAlso, for potential future support for multiple DC partitions not to be awkward, I think it would make sense to rename
dynamic_ram_atodynamic_ram_1. Any objections?
No objections from me. Seems reasonable.
Alison Schofield
maintainerRe: [PATCH v10 07/31] cxl/region: Add DC DAX region support
In reply to Anisa SuQuoted 22 lines · Anisa Su
From: Ira Weiny <[email protected]>
DC DAX 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 dynamic movement of this memory in the management of DAX regions and devices.Introduce the concept of a dynamic DAX region. Introduce
create_dynamic_ram_a_region()sysfs entry to create such regions. Special case DC-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.
Dynamic regions complicate the range mapping of dax devices. There is no known use case for range mapping on dynamic regions. Avoid the complication by preventing range mapping of dax devices on dynamic regions.
Quoted 6 lines
Interleaving is deferred for now. Add checks.
Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>
Hi Anisa,
This change is needed and I think it belongs in this patch:
drivers/cxl/core/region.c +2 -0
@@ -647,6 +647,8 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, desc ="ram" ; else if (cxlr->mode == CXL_PARTMODE_PMEM) desc ="pmem" ; + else if (cxlr->mode == CXL_PARTMODE_DYNAMIC_RAM_A) + desc ="dynamic_ram_a" ; else desc ="" ;
IIUC That empty string default should be for an unset mode only. And, this makes the new type appear in cxl list -R
-- Alison
PATCH v10 8/31 cxl/events: Split event msgnum configuration from irq setup
In reply to Anisa SuFrom: 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
@@ -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
PATCH v10 9/31 cxl/pci: Factor out interrupt policy check
In reply to Anisa SuFrom: 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
@@ -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
PATCH v10 10/31 cxl/mem: Configure dynamic capacity interrupts
In reply to Anisa SuFrom: 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.
Accept the 4-byte CXL 2.0 reply on GET Event Interrupt Policy by setting min_out to CXL_EVENT_INT_POLICY_BASE_SIZE; pre-CXL 3.1 firmware omits dcd_settings and would otherwise fail the size check.
Based on an original patch by Navneet Singh.
---
Changes:
[anisa: rebase]
[anisa: accept 4-byte CXL 2.0 GET reply via min_out] [anisa: drop Reviewed-by tags now that the patch carries new changes]
--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 75 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-)
drivers/cxl/cxlmem.h +2 -0
@@ -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 +62 -13
137 lines not on this page · raw message
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 10/31] cxl/mem: Configure dynamic capacity interrupts
Quoted 177 lines · 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.
Accept the 4-byte CXL 2.0 reply on GET Event Interrupt Policy by setting
min_outtoCXL_EVENT_INT_POLICY_BASE_SIZE; pre-CXL 3.1 firmware omitsdcd_settingsand would otherwise fail the size check.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: rebase]
[anisa: accept 4-byte CXL 2.0 GET reply viamin_out] [anisa: drop Reviewed-by tags now that the patch carries new changes]--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 75 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-)drivers/cxl/cxlmem.h +2
-0@@ -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 +57
-12@@ -557,6 +557,8 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, .opcode = CXL_MBOX_OP_GET_EVT_INT_POLICY, .payload_out = policy, .size_out = sizeof(*policy), + /* CXL 2.0 firmware omits dcd_settings; accept the shorter reply */ + .min_out = CXL_EVENT_INT_POLICY_BASE_SIZE, };int rc;@@ -569,23 +571,34 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +size_t size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ;struct cxl_mbox_cmd mbox_cmd;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX , - .failure_settings =CXL_INT_MSI_MSIX , - .fatal_settings =CXL_INT_MSI_MSIX , - }; +/* memory event policy is left if FW has control */ +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 , + }; + } + +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings); + } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);@@ -632,6 +645,30 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); + } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -657,18 +694,26 @@ static bool cxl_event_validate_mem_policy(struct cxl_memdev_state *mds,static int cxl_event_config (struct pci_host_bridge *host_bridge,struct cxl_memdev_state *mds,bool irq_avail) { -struct cxl_event_interrupt_policy policy; +struct cxl_event_interrupt_policy policy = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -676,10 +721,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 739
Quoted 9 lines
drivers/cxl/pci.c +1
-1@@ -687,12 +732,16 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL );
Issue that was always there probably, should this check native_cxl so the BIOS owned events are not retrieved?
if (native_cxl) cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
Also, CXLDEV_EVENT_STATUS_ALL is missing bit 4 (Dynamic Capcity Event Log). CXL r4.0 8.2.9.3.1 Table 8-203.
DJ
Quoted 8 lines
drivers/cxl/pci.c +4
-0+dev_dbg (mds->cxlds.dev,"Event config : %s DCD %s\n" , + native_cxl ?"OS" :"BIOS" , +cxl_dcd_supported (mds) ?"supported" :"not supported" ); +return 0 ; }
Re: [PATCH v10 10/31] cxl/mem: Configure dynamic capacity interrupts
Quoted 188 lines · Dave Jiang
Quoted 185 lines · 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.
Accept the 4-byte CXL 2.0 reply on GET Event Interrupt Policy by setting
min_outtoCXL_EVENT_INT_POLICY_BASE_SIZE; pre-CXL 3.1 firmware omitsdcd_settingsand would otherwise fail the size check.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: rebase]
[anisa: accept 4-byte CXL 2.0 GET reply viamin_out] [anisa: drop Reviewed-by tags now that the patch carries new changes]--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 75 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-)drivers/cxl/cxlmem.h +2
-0@@ -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 +58
-13@@ -557,6 +557,8 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, .opcode = CXL_MBOX_OP_GET_EVT_INT_POLICY, .payload_out = policy, .size_out = sizeof(*policy), + /* CXL 2.0 firmware omits dcd_settings; accept the shorter reply */ + .min_out = CXL_EVENT_INT_POLICY_BASE_SIZE, };int rc;@@ -569,23 +571,34 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +size_t size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ;struct cxl_mbox_cmd mbox_cmd;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX , - .failure_settings =CXL_INT_MSI_MSIX , - .fatal_settings =CXL_INT_MSI_MSIX , - }; +/* memory event policy is left if FW has control */ +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 , + }; + } + +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings); + } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);@@ -632,6 +645,30 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); + } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -657,18 +694,26 @@ static bool cxl_event_validate_mem_policy(struct cxl_memdev_state *mds,static int cxl_event_config (struct pci_host_bridge *host_bridge,struct cxl_memdev_state *mds,bool irq_avail) { -struct cxl_event_interrupt_policy policy; +struct cxl_event_interrupt_policy policy = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -676,10 +721,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;@@ -687,12 +732,16 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;
Quoted 8 lines
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 739
Quoted 1 line
drivers/cxl/pci.c +0
-0cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL );Issue that was always there probably, should this check
native_cxlso the BIOS owned events are not retrieved?if (native_cxl) cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
That makes sense. Would you prefer the fix as a separate patch?
Quoted 2 lines
Also,
CXLDEV_EVENT_STATUS_ALLis missing bit 4 (Dynamic Capcity Event Log). CXL r4.0 8.2.9.3.1 Table 8-203.
It was added in a later commit, but yeah it makes more sense to have it in this one. Moved to this commit.
Quoted 3 lines
DJ
Thanks,
Anisa
Quoted 10 lines
Quoted 9 lines
drivers/cxl/pci.c +4
-0+dev_dbg (mds->cxlds.dev,"Event config : %s DCD %s\n" , + native_cxl ?"OS" :"BIOS" , +cxl_dcd_supported (mds) ?"supported" :"not supported" ); +return 0 ; }
Dave Jiang
maintainerRe: [PATCH v10 10/31] cxl/mem: Configure dynamic capacity interrupts
Quoted 193 lines · Anisa Su
Quoted 192 lines · Dave Jiang
Quoted 177 lines · 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.
Accept the 4-byte CXL 2.0 reply on GET Event Interrupt Policy by setting
min_outtoCXL_EVENT_INT_POLICY_BASE_SIZE; pre-CXL 3.1 firmware omitsdcd_settingsand would otherwise fail the size check.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: rebase]
[anisa: accept 4-byte CXL 2.0 GET reply viamin_out] [anisa: drop Reviewed-by tags now that the patch carries new changes]--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 75 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-)drivers/cxl/cxlmem.h +2
-0@@ -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 +57
-12@@ -557,6 +557,8 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, .opcode = CXL_MBOX_OP_GET_EVT_INT_POLICY, .payload_out = policy, .size_out = sizeof(*policy), + /* CXL 2.0 firmware omits dcd_settings; accept the shorter reply */ + .min_out = CXL_EVENT_INT_POLICY_BASE_SIZE, };int rc;@@ -569,23 +571,34 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +size_t size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ;struct cxl_mbox_cmd mbox_cmd;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX , - .failure_settings =CXL_INT_MSI_MSIX , - .fatal_settings =CXL_INT_MSI_MSIX , - }; +/* memory event policy is left if FW has control */ +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 , + }; + } + +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings); + } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd);@@ -632,6 +645,30 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); + } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -657,18 +694,26 @@ static bool cxl_event_validate_mem_policy(struct cxl_memdev_state *mds,static int cxl_event_config (struct pci_host_bridge *host_bridge,struct cxl_memdev_state *mds,bool irq_avail) { -struct cxl_event_interrupt_policy policy; +struct cxl_event_interrupt_policy policy = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -676,10 +721,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 739
Quoted 9 lines
drivers/cxl/pci.c +1
-1@@ -687,12 +732,16 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL );Issue that was always there probably, should this check
native_cxlso the BIOS owned events are not retrieved?
Quoted 5 lines
Quoted 4 lines
if (native_cxl) cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);That makes sense. Would you prefer the fix as a separate patch?
Yes please.
DJ
Re: [PATCH v10 10/31] cxl/mem: Configure dynamic capacity interrupts
Quoted 36 lines · Dave Jiang
Quoted 33 lines · Anisa Su
Quoted 32 lines · Dave Jiang
Quoted 29 lines · 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.
Accept the 4-byte CXL 2.0 reply on GET Event Interrupt Policy by setting
min_outtoCXL_EVENT_INT_POLICY_BASE_SIZE; pre-CXL 3.1 firmware omitsdcd_settingsand would otherwise fail the size check.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: rebase]
[anisa: accept 4-byte CXL 2.0 GET reply viamin_out] [anisa: drop Reviewed-by tags now that the patch carries new changes]
---
[snip]
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines
Quoted 42 lines
static int cxl_event_config(struct
pci_host_bridge*host_bridge,drivers/cxl/pci.c +12
-4struct cxl_memdev_state *mds, bool irq_avail) { -struct cxl_event_interrupt_policy policy; +struct cxl_event_interrupt_policy policy = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -676,10 +721,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 739
Quoted 9 lines
drivers/cxl/pci.c +1
-1@@ -687,12 +732,16 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL );Issue that was always there probably, should this check
native_cxlso the BIOS owned events are not retrieved?if (native_cxl) cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
Quoted 6 lines
Quoted 1 line
That makes sense. Would you prefer the fix as a separate patch?
Yes please.
DJ
Oops I was wrong; the issue wasn't there before. This function used to return 0 if !native_cxl at the top of the function but this patchset added && !cxl_dcd_supported() to the condition.
Added the fix to this commit.
Thanks,
Anisa
PATCH v10 11/31 cxl/core: Return endpoint decoder information from region search
In reply to Anisa SuFrom: 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v10 12/31 cxl/mem: Set up framework for handling DC Events
In reply to Anisa SuAdds the support for receiving DC event records but defers the real add/release logic to subsequent commits. Simply refuse all extents for DC_ADD and ack all DC_RELEASE events for now. Forced release is currently unsupported.
In order, this commit adds the following:
1. Learn about DC Event Records and how to respond to them
* cxl_mem_get_event_records() learns about the DC Event record. Records of that type are routed to cxl_handle_dcd_event_records().
* cxl_handle_dcd_event_records() switches on event_type:
- DCD_ADD_CAPACITY -> handle_add_event()
- DCD_RELEASE_CAPACITY -> cxl_rm_extent()
- DCD_FORCED_CAPACITY_RELEASE is logged and ignored (FM/device-only).
* cxl_send_dc_response() sends the reply mailbox commands ADD_DC_RESPONSE / RELEASE_DC
2. Add stubs for DC_ADD and DC_RELEASE logic
* handle_add_event() stages incoming extents onto mds->add_ctx.pending_extents and, when More=0 closes the chain, replies with an empty ADD_DC_RESPONSE — refusing all extents for now
* cxl_rm_extent() acks the release via memdev_release_extent() so the device's view stays consistent; we can ack all releases because we currently don't accept/use any extents offered.
3. Structural setup for later commits:
* struct dc_extent, struct cxl_dc_tag_group, and pending_add_ctx set up the stage for the real DC_ADD path, which will enforce tag/grouping semantics
Based on an original patch by Navneet Singh.
---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit lands only the wire-level intake and dispatches the add/release logic to stubbed handlers. The handlers are fleshed out in subsequent commits.]
--- drivers/cxl/core/mbox.c | 246 +++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxl.h | 73 +++++++++++- drivers/cxl/cxlmem.h | 45 ++++++++ include/cxl/event.h | 38 +++++++ 4 files changed, 400 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +245 -1
@@ -5,6 +5,7 @@#include <linux/ktime.h> #include <linux/mutex.h> #include <linux/unaligned.h> +#include <linux/list.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h>
@@ -1102,6 +1103,238 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static int send_one_response (struct cxl_mailbox *cxl_mbox, +struct cxl_mbox_dc_response *response, +int opcode,u32 extent_list_size,u8 flags) +{ +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode = opcode, + .size_in =struct_size (response, extent_list, extent_list_size), + .payload_in = response, + }; + + response->extent_list_size =cpu_to_le32 (extent_list_size); + response->flags = flags; +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +} + +static int cxl_send_dc_response (struct cxl_memdev_state *mds,int opcode, +struct list_head *extent_list,int cnt) +{ +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +struct cxl_mbox_dc_response *p; +struct cxl_extent_list_node *pos, *tmp; +struct cxl_extent *extent; +u32 pl_index; + +size_t pl_size =struct_size (p, extent_list, cnt); +u32 max_extents = cnt; + +/* May have to use more bit on response. */ +if (pl_size > cxl_mbox->payload_size) { + max_extents = (cxl_mbox->payload_size -sizeof (*p)) / +sizeof (struct updated_extent_list ); + pl_size =struct_size (p, extent_list, max_extents); + } + + struct cxl_mbox_dc_response *response __free(kfree) = +kzalloc (pl_size,GFP_KERNEL ); +if (!response) +return -ENOMEM ; + +if (cnt ==0 ) +return send_one_response (cxl_mbox, response, opcode,0 ,0 ); + + pl_index =0 ; +list_for_each_entry_safe (pos, tmp, extent_list, list) { + extent = pos->extent; + response->extent_list[pl_index].dpa_start = extent->start_dpa; + response->extent_list[pl_index].length = extent->length; + pl_index++; + +if (pl_index == max_extents) { +u8 flags =0 ; +int rc; + +if (pl_index < cnt) + flags |=CXL_DCD_EVENT_MORE ; + rc =send_one_response (cxl_mbox, response, opcode, + pl_index, flags); +if (rc) +return rc; + cnt -= pl_index; +if (cnt < max_extents) + max_extents = cnt; + pl_index =0 ; + } + } + +if (!pl_index)/* nothing more to do */ +return 0 ; +return send_one_response (cxl_mbox, response, opcode, pl_index,0 ); +} + +static void delete_extent_node (struct cxl_extent_list_node *node) +{ +list_del (&node->list); +kfree (node->extent); +kfree (node); +} + +static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +{ +struct device *dev = mds->cxlds.dev; +struct cxl_extent_list_node *node; +LIST_HEAD (extent_list); + +dev_dbg (dev,"Release response dpa %pra\n" , range); + + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return ; + + node->extent =kzalloc (sizeof (*node->extent),GFP_KERNEL ); +if (!node->extent) { +kfree (node); +return ; + } + + node->extent->start_dpa =cpu_to_le64 (range->start); + node->extent->length =cpu_to_le64 (range_len (range)); +list_add_tail (&node->list, &extent_list); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_RELEASE_DC , &extent_list,1 )) +dev_dbg (dev,"Failed to release %pra\n" , range); + +delete_extent_node (node); +} + +static void clear_pending_extents (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, &mds->add_ctx.pending_extents, list) +delete_extent_node (pos); + mds->add_ctx.group =NULL ; +} + +static int add_to_pending_list (struct list_head *pending_list, +struct cxl_extent *to_add) +{ +struct cxl_extent_list_node *node; +struct cxl_extent *extent; + + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return -ENOMEM ; + extent =kmemdup (to_add,sizeof (*extent),GFP_KERNEL ); +if (!extent) +return -ENOMEM ; + + node->extent = extent; +list_add_tail (&node->list, pending_list); +return 0 ; +} + +/* +* Stub: stage extents on the pending list and reply with an empty +* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces +* the no-op tail with the real Add pipeline that surfaces a dax +* device per accepted extent. +*/ +static int handle_add_event (struct cxl_memdev_state *mds, +struct cxl_event_dcd *event) +{ +struct device *dev = mds->cxlds.dev; +int rc; + + rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +if (rc) +return rc; + +if (event->flags &CXL_DCD_EVENT_MORE ) { +dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +return 0 ; + } + + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &mds->add_ctx.pending_extents,0 ); +clear_pending_extents (mds); +return rc; +} + +/* +* Stub: ack the release back to the device so it knows we are not +* using the range. A later commit replaces this with the real +* teardown that walks the region's tag group and tears down the +* member dc_extent devices. +*/ +static int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct range dpa_range = { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; + +memdev_release_extent (mds, &dpa_range); +return 0 ; +} + +static char *cxl_dcd_evt_type_str (u8 type) +{ +switch (type) { +case DCD_ADD_CAPACITY : +return "add" ; +case DCD_RELEASE_CAPACITY : +return "release" ; +case DCD_FORCED_CAPACITY_RELEASE : +return "force release" ; +default : +break ; + } + +return "<unknown>" ; +} + +static void cxl_handle_dcd_event_records (struct cxl_memdev_state *mds, +struct cxl_event_record_raw *raw_rec) +{ +struct cxl_event_dcd *event = &raw_rec->event.dcd; +struct cxl_extent *extent = &event->extent; +struct device *dev = mds->cxlds.dev; +uuid_t *id = &raw_rec->id; +int rc; + +if (!uuid_equal (id, &CXL_EVENT_DC_EVENT_UUID )) +return ; + +dev_dbg (dev,"DCD event %s : DPA:%#llx LEN:%#llx\n" , +cxl_dcd_evt_type_str (event->event_type), +le64_to_cpu (extent->start_dpa),le64_to_cpu (extent->length)); + +switch (event->event_type) { +case DCD_ADD_CAPACITY : + rc =handle_add_event (mds, event); +break ; +case DCD_RELEASE_CAPACITY : + rc =cxl_rm_extent (mds, &event->extent); +break ; +case DCD_FORCED_CAPACITY_RELEASE : +dev_err_ratelimited (dev,"Forced release event ignored.\n" ); + rc =0 ; +break ; +default : + rc = -EINVAL ; +break ; + } + +if (rc) +dev_err_ratelimited (dev,"dcd event failed: %d\n" , rc); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {
@@ -1138,9 +1371,13 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds,if (!nr_rec)break ; -for (i =0 ; i < nr_rec; i++) +for (i =0 ; i < nr_rec; i++) {__cxl_event_trace_record (cxlmd, type, &payload->records[i]); +if (type ==CXL_EVENT_TYPE_DCD ) +cxl_handle_dcd_event_records (mds, + &payload->records[i]); + }if (payload->flags &CXL_GET_EVENT_FLAG_OVERFLOW )trace_cxl_overflow (cxlmd, type, payload);
@@ -1172,6 +1409,8 @@ void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status) {dev_dbg (mds->cxlds.dev,"Reading event logs: %x\n" , status); +if (cxl_dcd_supported (mds) && (status &CXLDEV_EVENT_STATUS_DCD )) +cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_DCD );if (status &CXLDEV_EVENT_STATUS_FATAL )cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_FATAL );if (status &CXLDEV_EVENT_STATUS_FAIL )
@@ -1769,6 +2008,11 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, }mutex_init (&mds->event.log_lock); +INIT_LIST_HEAD (&mds->add_ctx.pending_extents); + + rc =devm_add_action_or_reset (dev, clear_pending_extents, mds); +if (rc) +return ERR_PTR (rc); rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )
drivers/cxl/cxl.h +72 -1
107 lines not on this page · raw message
drivers/cxl/cxlmem.h +45 -0
87 lines not on this page · raw message
include/cxl/event.h +38 -0
@@ -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,49 @@ 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 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;
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 12/31] cxl/mem: Set up framework for handling DC Events
Quoted 188 lines · Anisa Su
Adds the support for receiving DC event records but defers the real add/release logic to subsequent commits. Simply refuse all extents for
DC_ADDand ack allDC_RELEASEevents for now. Forced release is currently unsupported.In order, this commit adds the following:
1. Learn about DC Event Records and how to respond to them
*
cxl_mem_get_event_records()learns about the DC Event record. Records of that type are routed tocxl_handle_dcd_event_records().*
cxl_handle_dcd_event_records()switches onevent_type:
-DCD_ADD_CAPACITY->handle_add_event()
-DCD_RELEASE_CAPACITY->cxl_rm_extent()
-DCD_FORCED_CAPACITY_RELEASEis logged and ignored (FM/device-only).*
cxl_send_dc_response()sends the reply mailbox commandsADD_DC_RESPONSE/RELEASE_DC2. Add stubs for
DC_ADDandDC_RELEASElogic*
handle_add_event()stages incoming extents ontomds->add_ctx.pending_extentsand, when More=0 closes the chain, replies with an emptyADD_DC_RESPONSE— refusing all extents for now*
cxl_rm_extent()acks the release viamemdev_release_extent()so the device's view stays consistent; we can ack all releases because we currently don't accept/use any extents offered.3. Structural setup for later commits:
* struct
dc_extent, structcxl_dc_tag_group, andpending_add_ctxset up the stage for the realDC_ADDpath, which will enforce tag/grouping semanticsBased on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit lands only the wire-level intake and dispatches the add/release logic to stubbed handlers. The handlers are fleshed out in subsequent commits.]--- drivers/cxl/core/mbox.c | 246 +++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxl.h | 73 +++++++++++- drivers/cxl/cxlmem.h | 45 ++++++++ include/cxl/event.h | 38 +++++++ 4 files changed, 400 insertions(+), 2 deletions(-)drivers/cxl/core/mbox.c +119
-0@@ -5,6 +5,7 @@#include <linux/ktime.h> #include <linux/mutex.h> #include <linux/unaligned.h> +#include <linux/list.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1102,6 +1103,238 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static int send_one_response (struct cxl_mailbox *cxl_mbox, +struct cxl_mbox_dc_response *response, +int opcode,u32 extent_list_size,u8 flags) +{ +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode = opcode, + .size_in =struct_size (response, extent_list, extent_list_size), + .payload_in = response, + }; + + response->extent_list_size =cpu_to_le32 (extent_list_size); + response->flags = flags; +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +} + +static int cxl_send_dc_response (struct cxl_memdev_state *mds,int opcode, +struct list_head *extent_list,int cnt) +{ +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +struct cxl_mbox_dc_response *p; +struct cxl_extent_list_node *pos, *tmp; +struct cxl_extent *extent; +u32 pl_index; + +size_t pl_size =struct_size (p, extent_list, cnt); +u32 max_extents = cnt; + +/* May have to use more bit on response. */ +if (pl_size > cxl_mbox->payload_size) { + max_extents = (cxl_mbox->payload_size -sizeof (*p)) / +sizeof (struct updated_extent_list ); + pl_size =struct_size (p, extent_list, max_extents); + } + + struct cxl_mbox_dc_response *response __free(kfree) = +kzalloc (pl_size,GFP_KERNEL ); +if (!response) +return -ENOMEM ; + +if (cnt ==0 ) +return send_one_response (cxl_mbox, response, opcode,0 ,0 ); + + pl_index =0 ; +list_for_each_entry_safe (pos, tmp, extent_list, list) { + extent = pos->extent; + response->extent_list[pl_index].dpa_start = extent->start_dpa; + response->extent_list[pl_index].length = extent->length; + pl_index++; + +if (pl_index == max_extents) { +u8 flags =0 ; +int rc; + +if (pl_index < cnt) + flags |=CXL_DCD_EVENT_MORE ; + rc =send_one_response (cxl_mbox, response, opcode, + pl_index, flags); +if (rc) +return rc; + cnt -= pl_index; +if (cnt < max_extents) + max_extents = cnt; + pl_index =0 ; + } + } + +if (!pl_index)/* nothing more to do */ +return 0 ; +return send_one_response (cxl_mbox, response, opcode, pl_index,0 ); +} + +static void delete_extent_node (struct cxl_extent_list_node *node) +{ +list_del (&node->list); +kfree (node->extent); +kfree (node); +} + +static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +{ +struct device *dev = mds->cxlds.dev; +struct cxl_extent_list_node *node; +LIST_HEAD (extent_list); + +dev_dbg (dev,"Release response dpa %pra\n" , range); + + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return ; + + node->extent =kzalloc (sizeof (*node->extent),GFP_KERNEL ); +if (!node->extent) { +kfree (node); +return ; + } + + node->extent->start_dpa =cpu_to_le64 (range->start); + node->extent->length =cpu_to_le64 (range_len (range)); +list_add_tail (&node->list, &extent_list); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_RELEASE_DC , &extent_list,1 )) +dev_dbg (dev,"Failed to release %pra\n" , range); + +delete_extent_node (node); +} + +static void clear_pending_extents (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, &mds->add_ctx.pending_extents, list) +delete_extent_node (pos); + mds->add_ctx.group =NULL ; +} + +static int add_to_pending_list (struct list_head *pending_list, +struct cxl_extent *to_add)
drivers/cxl/core/mbox.c static int cxl_clear_event_record(struct cxl_memdev_state *mds, · line 1233
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+{ +struct cxl_extent_list_node *node; +struct cxl_extent *extent; + + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return -ENOMEM ; + extent =kmemdup (to_add,sizeof (*extent),GFP_KERNEL ); +if (!extent) +return -ENOMEM ;
Leaking node here. Maybe convert to using __free()?
Quoted 11 lines
drivers/cxl/core/mbox.c +11
-0+ + node->extent = extent; +list_add_tail (&node->list, pending_list); +return 0 ; +} + +/* +* Stub: stage extents on the pending list and reply with an empty +* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces +* the no-op tail with the real Add pipeline that surfaces a dax +* device per accepted extent.
drivers/cxl/core/mbox.c static int cxl_clear_event_record(struct cxl_memdev_state *mds, · line 1254
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+*/ +static int handle_add_event (struct cxl_memdev_state *mds, +struct cxl_event_dcd *event) +{ +struct device *dev = mds->cxlds.dev; +int rc; + + rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +if (rc) +return rc;
Should clear_pending_extents() be called before return to clean up previously staged extents?
DJ
Quoted 397 lines
drivers/cxl/core/mbox.c +95
-1+ +if (event->flags &CXL_DCD_EVENT_MORE ) { +dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +return 0 ; + } + + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &mds->add_ctx.pending_extents,0 ); +clear_pending_extents (mds); +return rc; +} + +/* +* Stub: ack the release back to the device so it knows we are not +* using the range. A later commit replaces this with the real +* teardown that walks the region's tag group and tears down the +* member dc_extent devices. +*/ +static int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct range dpa_range = { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; + +memdev_release_extent (mds, &dpa_range); +return 0 ; +} + +static char *cxl_dcd_evt_type_str (u8 type) +{ +switch (type) { +case DCD_ADD_CAPACITY : +return "add" ; +case DCD_RELEASE_CAPACITY : +return "release" ; +case DCD_FORCED_CAPACITY_RELEASE : +return "force release" ; +default : +break ; + } + +return "<unknown>" ; +} + +static void cxl_handle_dcd_event_records (struct cxl_memdev_state *mds, +struct cxl_event_record_raw *raw_rec) +{ +struct cxl_event_dcd *event = &raw_rec->event.dcd; +struct cxl_extent *extent = &event->extent; +struct device *dev = mds->cxlds.dev; +uuid_t *id = &raw_rec->id; +int rc; + +if (!uuid_equal (id, &CXL_EVENT_DC_EVENT_UUID )) +return ; + +dev_dbg (dev,"DCD event %s : DPA:%#llx LEN:%#llx\n" , +cxl_dcd_evt_type_str (event->event_type), +le64_to_cpu (extent->start_dpa),le64_to_cpu (extent->length)); + +switch (event->event_type) { +case DCD_ADD_CAPACITY : + rc =handle_add_event (mds, event); +break ; +case DCD_RELEASE_CAPACITY : + rc =cxl_rm_extent (mds, &event->extent); +break ; +case DCD_FORCED_CAPACITY_RELEASE : +dev_err_ratelimited (dev,"Forced release event ignored.\n" ); + rc =0 ; +break ; +default : + rc = -EINVAL ; +break ; + } + +if (rc) +dev_err_ratelimited (dev,"dcd event failed: %d\n" , rc); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1138,9 +1371,13 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds,if (!nr_rec)break ; -for (i =0 ; i < nr_rec; i++) +for (i =0 ; i < nr_rec; i++) {__cxl_event_trace_record (cxlmd, type, &payload->records[i]); +if (type ==CXL_EVENT_TYPE_DCD ) +cxl_handle_dcd_event_records (mds, + &payload->records[i]); + }if (payload->flags &CXL_GET_EVENT_FLAG_OVERFLOW )trace_cxl_overflow (cxlmd, type, payload);@@ -1172,6 +1409,8 @@ void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status) {dev_dbg (mds->cxlds.dev,"Reading event logs: %x\n" , status); +if (cxl_dcd_supported (mds) && (status &CXLDEV_EVENT_STATUS_DCD )) +cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_DCD );if (status &CXLDEV_EVENT_STATUS_FATAL )cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_FATAL );if (status &CXLDEV_EVENT_STATUS_FAIL )@@ -1769,6 +2008,11 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, }mutex_init (&mds->event.log_lock); +INIT_LIST_HEAD (&mds->add_ctx.pending_extents); + + rc =devm_add_action_or_reset (dev, clear_pending_extents, mds); +if (rc) +return ERR_PTR (rc); rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )drivers/cxl/cxl.h +72
-1@@ -12,6 +12,7 @@#include <linux/node.h> #include <linux/io.h> #include <linux/range.h> +#include <linux/xarray.h> #include <cxl/cxl.h> extern const struct nvdimm_security_ops *cxl_security_ops;@@ -180,11 +181,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL | \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)@@ -306,6 +309,41 @@ enum cxl_decoder_state { CXL_DECODER_STATE_AUTO_STAGED, }; +struct cxl_dc_tag_group ; + +/** +* struct dc_extent - A single dynamic-capacity extent surfaced to the host. +* +* One per device-stamped extent. Multiple dc_extents that share a tag +* (see &struct cxl_dc_tag_group) form a single logical allocation, but +* each dc_extent has its own HPA range and is the unit that the DAX +* layer sees as a backing dax_resource. +* +* @dev: device representing this extent; child of cxlr_dax->dev. +* @group: containing tag group (allocation); shared across siblings. +* @cxled: endpoint decoder backing the DPA range. +* @dpa_range: DPA range this extent covers within @cxled. +* @hpa_range: HPA range that @dpa_range decodes to, relative to +* cxlr_dax->hpa_range.start. +* @uuid: tag uuid (matches @group->uuid; kept for the release-path log). +* @seq_num: 1..n assembly-order index within the tag group. For extents +* from a sharable partition this equals the device-stamped +* shared_extn_seq (CXL 3.1 Table 8-51). For extents from a +* non-sharable partition the device leaves shared_extn_seq == 0 +* and the host assigns @seq_num in event arrival order at +* cxl_add_pending() time. Used by the dax layer to assemble +* ranges in the right order regardless of source. +*/ +struct dc_extent { +struct device dev; +struct cxl_dc_tag_group *group; +struct cxl_endpoint_decoder *cxled; +struct range dpa_range; +struct range hpa_range; +uuid_t uuid; +u16 seq_num; +}; +/** * struct cxl_endpoint_decoder - Endpoint / SPA to DPA decoder * @cxld: base cxl_decoder_object @@ -518,12 +556,45 @@ struct cxl_pmem_region {struct cxl_pmem_region_mapping mapping[]; }; +/* See CXL 3.1 8.2.9.2.1.6 */ +enum dc_event { +DCD_ADD_CAPACITY , +DCD_RELEASE_CAPACITY , +DCD_FORCED_CAPACITY_RELEASE , +DCD_REGION_CONFIGURATION_UPDATED , +}; +struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; }; +/** +* struct cxl_dc_tag_group - A tagged dynamic-capacity allocation. +* +* Container for the &struct dc_extent siblings that share a tag. The +* group has no sysfs identity; userspace sees the individual dc_extents +* directly under the parent dax_region device. The group exists to +* keep tag-scoped invariants (atomic add, atomic release, ordered carve +* by seq_num) in one place. +* +* @cxlr_dax: back reference to parent region device. +* @uuid: tag identifying this allocation; same across all member dc_extents. +* @dc_extents: xarray of &struct dc_extent in this group, indexed by the +* dc_extent's @seq_num (1..n, dense). See &struct dc_extent +* for how seq_num is sourced for sharable vs non-sharable +* allocations. +* @nr_extents: live count of dc_extents in the group; the group is freed +* when the last dc_extent device is released. +*/ +struct cxl_dc_tag_group { +struct cxl_dax_region *cxlr_dax; +uuid_t uuid; +struct xarray dc_extents; +unsigned int nr_extents; +}; +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory drivers/cxl/cxlmem.h +45
-0@@ -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" @@ -399,6 +400,23 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)return dev_get_drvdata (cxl_mbox->host); } +/** +* struct pending_add_ctx - Staging state for an in-progress +* DCD_ADD_CAPACITY event chain +* @pending_extents: extents received so far in the chain; flushed when +* the chain closes (More=0) +* @group: tag group being assembled from the chain +* +* A DCD_ADD_CAPACITY notification can span multiple event records +* stitched together by the CXL_DCD_EVENT_MORE flag. Records are staged +* here until the device clears More, at which point the staged batch is +* processed and responded to as a single Add_DC_Response. +*/ +struct pending_add_ctx { +struct list_head pending_extents; +struct cxl_dc_tag_group *group; +}; +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -417,6 +435,8 @@ 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 +* @add_ctx: state for an in-progress DCD_ADD_CAPACITY chain +* (see &struct pending_add_ctx) * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -437,6 +457,7 @@ struct cxl_memdev_state {u64 active_volatile_bytes;u64 active_persistent_bytes;bool dcd_supported; +struct pending_add_ctx add_ctx;struct cxl_event_state event;struct cxl_poison_state poison;@@ -513,6 +534,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 ];@@ -583,6 +619,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 @@ -608,6 +652,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 +38
-0@@ -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,49 @@ 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 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;
Re: [PATCH v10 12/31] cxl/mem: Set up framework for handling DC Events
Quoted 195 lines · Dave Jiang
Quoted 192 lines · Anisa Su
Adds the support for receiving DC event records but defers the real add/release logic to subsequent commits. Simply refuse all extents for
DC_ADDand ack allDC_RELEASEevents for now. Forced release is currently unsupported.In order, this commit adds the following:
1. Learn about DC Event Records and how to respond to them
*
cxl_mem_get_event_records()learns about the DC Event record. Records of that type are routed tocxl_handle_dcd_event_records().*
cxl_handle_dcd_event_records()switches onevent_type:
-DCD_ADD_CAPACITY->handle_add_event()
-DCD_RELEASE_CAPACITY->cxl_rm_extent()
-DCD_FORCED_CAPACITY_RELEASEis logged and ignored (FM/device-only).*
cxl_send_dc_response()sends the reply mailbox commandsADD_DC_RESPONSE/RELEASE_DC2. Add stubs for
DC_ADDandDC_RELEASElogic*
handle_add_event()stages incoming extents ontomds->add_ctx.pending_extentsand, when More=0 closes the chain, replies with an emptyADD_DC_RESPONSE— refusing all extents for now*
cxl_rm_extent()acks the release viamemdev_release_extent()so the device's view stays consistent; we can ack all releases because we currently don't accept/use any extents offered.3. Structural setup for later commits:
* struct
dc_extent, structcxl_dc_tag_group, andpending_add_ctxset up the stage for the realDC_ADDpath, which will enforce tag/grouping semanticsBased on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit lands only the wire-level intake and dispatches the add/release logic to stubbed handlers. The handlers are fleshed out in subsequent commits.]--- drivers/cxl/core/mbox.c | 246 +++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxl.h | 73 +++++++++++- drivers/cxl/cxlmem.h | 45 ++++++++ include/cxl/event.h | 38 +++++++ 4 files changed, 400 insertions(+), 2 deletions(-)drivers/cxl/core/mbox.c +123
-0@@ -5,6 +5,7 @@#include <linux/ktime.h> #include <linux/mutex.h> #include <linux/unaligned.h> +#include <linux/list.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1102,6 +1103,238 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static int send_one_response (struct cxl_mailbox *cxl_mbox, +struct cxl_mbox_dc_response *response, +int opcode,u32 extent_list_size,u8 flags) +{ +struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode = opcode, + .size_in =struct_size (response, extent_list, extent_list_size), + .payload_in = response, + }; + + response->extent_list_size =cpu_to_le32 (extent_list_size); + response->flags = flags; +return cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +} + +static int cxl_send_dc_response (struct cxl_memdev_state *mds,int opcode, +struct list_head *extent_list,int cnt) +{ +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +struct cxl_mbox_dc_response *p; +struct cxl_extent_list_node *pos, *tmp; +struct cxl_extent *extent; +u32 pl_index; + +size_t pl_size =struct_size (p, extent_list, cnt); +u32 max_extents = cnt; + +/* May have to use more bit on response. */ +if (pl_size > cxl_mbox->payload_size) { + max_extents = (cxl_mbox->payload_size -sizeof (*p)) / +sizeof (struct updated_extent_list ); + pl_size =struct_size (p, extent_list, max_extents); + } + + struct cxl_mbox_dc_response *response __free(kfree) = +kzalloc (pl_size,GFP_KERNEL ); +if (!response) +return -ENOMEM ; + +if (cnt ==0 ) +return send_one_response (cxl_mbox, response, opcode,0 ,0 ); + + pl_index =0 ; +list_for_each_entry_safe (pos, tmp, extent_list, list) { + extent = pos->extent; + response->extent_list[pl_index].dpa_start = extent->start_dpa; + response->extent_list[pl_index].length = extent->length; + pl_index++; + +if (pl_index == max_extents) { +u8 flags =0 ; +int rc; + +if (pl_index < cnt) + flags |=CXL_DCD_EVENT_MORE ; + rc =send_one_response (cxl_mbox, response, opcode, + pl_index, flags); +if (rc) +return rc; + cnt -= pl_index; +if (cnt < max_extents) + max_extents = cnt; + pl_index =0 ; + } + } + +if (!pl_index)/* nothing more to do */ +return 0 ; +return send_one_response (cxl_mbox, response, opcode, pl_index,0 ); +} + +static void delete_extent_node (struct cxl_extent_list_node *node) +{ +list_del (&node->list); +kfree (node->extent); +kfree (node); +} + +static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +{ +struct device *dev = mds->cxlds.dev; +struct cxl_extent_list_node *node; +LIST_HEAD (extent_list); + +dev_dbg (dev,"Release response dpa %pra\n" , range); + + node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return ; + + node->extent =kzalloc (sizeof (*node->extent),GFP_KERNEL ); +if (!node->extent) { +kfree (node); +return ; + } + + node->extent->start_dpa =cpu_to_le64 (range->start); + node->extent->length =cpu_to_le64 (range_len (range)); +list_add_tail (&node->list, &extent_list); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_RELEASE_DC , &extent_list,1 )) +dev_dbg (dev,"Failed to release %pra\n" , range); + +delete_extent_node (node); +} + +static void clear_pending_extents (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, &mds->add_ctx.pending_extents, list) +delete_extent_node (pos); + mds->add_ctx.group =NULL ; +} + +static int add_to_pending_list (struct list_head *pending_list, +struct cxl_extent *to_add) +{ +struct cxl_extent_list_node *node; +struct cxl_extent *extent; +
Quoted 8 lines
drivers/cxl/core/mbox.c static int cxl_clear_event_record(struct cxl_memdev_state *mds, · line 1233
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+ node =kzalloc (sizeof (*node),GFP_KERNEL ); +if (!node) +return -ENOMEM ; + extent =kmemdup (to_add,sizeof (*extent),GFP_KERNEL ); +if (!extent) +return -ENOMEM ;Leaking node here. Maybe convert to using
__free()?
Yep, done!
Quoted 15 lines
Quoted 15 lines
drivers/cxl/core/mbox.c +15
-0+ + node->extent = extent; +list_add_tail (&node->list, pending_list); +return 0 ; +} + +/* +* Stub: stage extents on the pending list and reply with an empty +* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces +* the no-op tail with the real Add pipeline that surfaces a dax +* device per accepted extent. +*/ +static int handle_add_event (struct cxl_memdev_state *mds, +struct cxl_event_dcd *event) +{
Quoted 9 lines
drivers/cxl/core/mbox.c static int cxl_clear_event_record(struct cxl_memdev_state *mds, · line 1254
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+struct device *dev = mds->cxlds.dev; +int rc; + + rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +if (rc) +return rc;Should
clear_pending_extents()be called before return to clean up previously staged extents?
Yes I think so. Done!
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 398 lines
Quoted 397 lines
drivers/cxl/core/mbox.c +95
-1+ +if (event->flags &CXL_DCD_EVENT_MORE ) { +dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +return 0 ; + } + + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &mds->add_ctx.pending_extents,0 ); +clear_pending_extents (mds); +return rc; +} + +/* +* Stub: ack the release back to the device so it knows we are not +* using the range. A later commit replaces this with the real +* teardown that walks the region's tag group and tears down the +* member dc_extent devices. +*/ +static int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct range dpa_range = { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; + +memdev_release_extent (mds, &dpa_range); +return 0 ; +} + +static char *cxl_dcd_evt_type_str (u8 type) +{ +switch (type) { +case DCD_ADD_CAPACITY : +return "add" ; +case DCD_RELEASE_CAPACITY : +return "release" ; +case DCD_FORCED_CAPACITY_RELEASE : +return "force release" ; +default : +break ; + } + +return "<unknown>" ; +} + +static void cxl_handle_dcd_event_records (struct cxl_memdev_state *mds, +struct cxl_event_record_raw *raw_rec) +{ +struct cxl_event_dcd *event = &raw_rec->event.dcd; +struct cxl_extent *extent = &event->extent; +struct device *dev = mds->cxlds.dev; +uuid_t *id = &raw_rec->id; +int rc; + +if (!uuid_equal (id, &CXL_EVENT_DC_EVENT_UUID )) +return ; + +dev_dbg (dev,"DCD event %s : DPA:%#llx LEN:%#llx\n" , +cxl_dcd_evt_type_str (event->event_type), +le64_to_cpu (extent->start_dpa),le64_to_cpu (extent->length)); + +switch (event->event_type) { +case DCD_ADD_CAPACITY : + rc =handle_add_event (mds, event); +break ; +case DCD_RELEASE_CAPACITY : + rc =cxl_rm_extent (mds, &event->extent); +break ; +case DCD_FORCED_CAPACITY_RELEASE : +dev_err_ratelimited (dev,"Forced release event ignored.\n" ); + rc =0 ; +break ; +default : + rc = -EINVAL ; +break ; + } + +if (rc) +dev_err_ratelimited (dev,"dcd event failed: %d\n" , rc); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1138,9 +1371,13 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds,if (!nr_rec)break ; -for (i =0 ; i < nr_rec; i++) +for (i =0 ; i < nr_rec; i++) {__cxl_event_trace_record (cxlmd, type, &payload->records[i]); +if (type ==CXL_EVENT_TYPE_DCD ) +cxl_handle_dcd_event_records (mds, + &payload->records[i]); + }if (payload->flags &CXL_GET_EVENT_FLAG_OVERFLOW )trace_cxl_overflow (cxlmd, type, payload);@@ -1172,6 +1409,8 @@ void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status) {dev_dbg (mds->cxlds.dev,"Reading event logs: %x\n" , status); +if (cxl_dcd_supported (mds) && (status &CXLDEV_EVENT_STATUS_DCD )) +cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_DCD );if (status &CXLDEV_EVENT_STATUS_FATAL )cxl_mem_get_records_log (mds,CXL_EVENT_TYPE_FATAL );if (status &CXLDEV_EVENT_STATUS_FAIL )@@ -1769,6 +2008,11 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, }mutex_init (&mds->event.log_lock); +INIT_LIST_HEAD (&mds->add_ctx.pending_extents); + + rc =devm_add_action_or_reset (dev, clear_pending_extents, mds); +if (rc) +return ERR_PTR (rc); rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )drivers/cxl/cxl.h +72
-1@@ -12,6 +12,7 @@#include <linux/node.h> #include <linux/io.h> #include <linux/range.h> +#include <linux/xarray.h> #include <cxl/cxl.h> extern const struct nvdimm_security_ops *cxl_security_ops;@@ -180,11 +181,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL | \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)@@ -306,6 +309,41 @@ enum cxl_decoder_state { CXL_DECODER_STATE_AUTO_STAGED, }; +struct cxl_dc_tag_group ; + +/** +* struct dc_extent - A single dynamic-capacity extent surfaced to the host. +* +* One per device-stamped extent. Multiple dc_extents that share a tag +* (see &struct cxl_dc_tag_group) form a single logical allocation, but +* each dc_extent has its own HPA range and is the unit that the DAX +* layer sees as a backing dax_resource. +* +* @dev: device representing this extent; child of cxlr_dax->dev. +* @group: containing tag group (allocation); shared across siblings. +* @cxled: endpoint decoder backing the DPA range. +* @dpa_range: DPA range this extent covers within @cxled. +* @hpa_range: HPA range that @dpa_range decodes to, relative to +* cxlr_dax->hpa_range.start. +* @uuid: tag uuid (matches @group->uuid; kept for the release-path log). +* @seq_num: 1..n assembly-order index within the tag group. For extents +* from a sharable partition this equals the device-stamped +* shared_extn_seq (CXL 3.1 Table 8-51). For extents from a +* non-sharable partition the device leaves shared_extn_seq == 0 +* and the host assigns @seq_num in event arrival order at +* cxl_add_pending() time. Used by the dax layer to assemble +* ranges in the right order regardless of source. +*/ +struct dc_extent { +struct device dev; +struct cxl_dc_tag_group *group; +struct cxl_endpoint_decoder *cxled; +struct range dpa_range; +struct range hpa_range; +uuid_t uuid; +u16 seq_num; +}; +/** * struct cxl_endpoint_decoder - Endpoint / SPA to DPA decoder * @cxld: base cxl_decoder_object @@ -518,12 +556,45 @@ struct cxl_pmem_region {struct cxl_pmem_region_mapping mapping[]; }; +/* See CXL 3.1 8.2.9.2.1.6 */ +enum dc_event { +DCD_ADD_CAPACITY , +DCD_RELEASE_CAPACITY , +DCD_FORCED_CAPACITY_RELEASE , +DCD_REGION_CONFIGURATION_UPDATED , +}; +struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; }; +/** +* struct cxl_dc_tag_group - A tagged dynamic-capacity allocation. +* +* Container for the &struct dc_extent siblings that share a tag. The +* group has no sysfs identity; userspace sees the individual dc_extents +* directly under the parent dax_region device. The group exists to +* keep tag-scoped invariants (atomic add, atomic release, ordered carve +* by seq_num) in one place. +* +* @cxlr_dax: back reference to parent region device. +* @uuid: tag identifying this allocation; same across all member dc_extents. +* @dc_extents: xarray of &struct dc_extent in this group, indexed by the +* dc_extent's @seq_num (1..n, dense). See &struct dc_extent +* for how seq_num is sourced for sharable vs non-sharable +* allocations. +* @nr_extents: live count of dc_extents in the group; the group is freed +* when the last dc_extent device is released. +*/ +struct cxl_dc_tag_group { +struct cxl_dax_region *cxlr_dax; +uuid_t uuid; +struct xarray dc_extents; +unsigned int nr_extents; +}; +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory drivers/cxl/cxlmem.h +45
-0@@ -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" @@ -399,6 +400,23 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)return dev_get_drvdata (cxl_mbox->host); } +/** +* struct pending_add_ctx - Staging state for an in-progress +* DCD_ADD_CAPACITY event chain +* @pending_extents: extents received so far in the chain; flushed when +* the chain closes (More=0) +* @group: tag group being assembled from the chain +* +* A DCD_ADD_CAPACITY notification can span multiple event records +* stitched together by the CXL_DCD_EVENT_MORE flag. Records are staged +* here until the device clears More, at which point the staged batch is +* processed and responded to as a single Add_DC_Response. +*/ +struct pending_add_ctx { +struct list_head pending_extents; +struct cxl_dc_tag_group *group; +}; +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -417,6 +435,8 @@ 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 +* @add_ctx: state for an in-progress DCD_ADD_CAPACITY chain +* (see &struct pending_add_ctx) * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -437,6 +457,7 @@ struct cxl_memdev_state {u64 active_volatile_bytes;u64 active_persistent_bytes;bool dcd_supported; +struct pending_add_ctx add_ctx;struct cxl_event_state event;struct cxl_poison_state poison;@@ -513,6 +534,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 ];@@ -583,6 +619,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 @@ -608,6 +652,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 +38
-0@@ -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,49 @@ 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 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;
PATCH v10 13/31 cxl/mem: Add 20 second timeout for stalled DC_ADD_CAPACITY chains
In reply to Anisa SuA DC_ADD_CAPACITY event can span multiple event records grouped together by the CXL_DCD_EVENT_MORE flag. Extents are staged in the pending list until the last event record ('More'=0) is received, at which point the pending list is processed. If the device opens such a chain (More=1) but never sends the closing record, the staged list sits indefinitely.
Add a delayed-work watchdog that, on expiry, refuses the chain with an empty ADD_DC_RESPONSE and drops the staged list.
The 20s timeout is a conservative upper bound and may be tightened later. The timeout is purely defensive — the spec does not require it, but prevents issues from a lost mailbox response or a crashed fabric manager.
--- drivers/cxl/core/mbox.c | 73 ++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 23 ++++++++++--- 2 files changed, 91 insertions(+), 5 deletions(-)
drivers/cxl/core/mbox.c +72 -1
@@ -1219,6 +1219,48 @@ static void clear_pending_extents(void *_mds) mds->add_ctx.group =NULL ; } +/* +* Bound on how long the host will wait for a device to finish a +* multi-record DC_ADD_CAPACITY chain (More=1 ... More=0) before +* refusing the chain. +* The timeout is not defined in the spec, but added for defensive purposes. +* Since there is no spec-defined timeout, 20s is chosen as a generous +* upper bound and matches the GPF timeout. +*/ +#define CXL_DC_ADD_TIMEOUT (20 * HZ) + +static void cxl_dc_add_timeout (struct work_struct *work) +{ +struct pending_add_ctx *ctx =container_of (to_delayed_work (work), + struct pending_add_ctx, + timeout_work); +struct cxl_memdev_state *mds =container_of (ctx, + struct cxl_memdev_state, + add_ctx); +struct device *dev = mds->cxlds.dev; + +guard (mutex)(&ctx->lock); + +if (!ctx->armed) +return ; + +dev_warn (dev,"DC add chain timed out; refusing staged extents\n" ); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &ctx->pending_extents,0 )) +dev_dbg (dev,"Failed to send empty ADD_DC_RESPONSE on timeout\n" ); + +clear_pending_extents (mds); + ctx->armed = false; +} + +static void cxl_cancel_dcd_add_chain_work (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; + +cancel_delayed_work_sync (&mds->add_ctx.timeout_work); +} +static int add_to_pending_list (struct list_head *pending_list,struct cxl_extent *to_add) {
@@ -1246,18 +1288,34 @@ static int add_to_pending_list(struct list_head *pending_list,static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) { +struct pending_add_ctx *ctx = &mds->add_ctx;struct device *dev = mds->cxlds.dev;int rc; - rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +guard (mutex)(&ctx->lock); + + rc =add_to_pending_list (&ctx->pending_extents, &event->extent);if (rc)return rc;if (event->flags &CXL_DCD_EVENT_MORE ) {dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +mod_delayed_work (system_wq, &ctx->timeout_work, +CXL_DC_ADD_TIMEOUT ); + ctx->armed = true;return 0 ; } +/* +* Chain is closing. Disarm before flushing so a pending watchdog +* (queued but blocked on @ctx->lock) sees !armed and bails out. +* cancel_delayed_work() — not _sync — because handle_add_event() +* itself runs on system_wq and a sync cancel of same-wq work can +* deadlock. +*/ + ctx->armed = false; +cancel_delayed_work (&ctx->timeout_work); + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , &mds->add_ctx.pending_extents,0 );clear_pending_extents (mds);
@@ -2009,11 +2067,24 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,mutex_init (&mds->event.log_lock);INIT_LIST_HEAD (&mds->add_ctx.pending_extents); +mutex_init (&mds->add_ctx.lock); +INIT_DELAYED_WORK (&mds->add_ctx.timeout_work, + cxl_dc_add_timeout); + mds->add_ctx.armed = false; rc =devm_add_action_or_reset (dev, clear_pending_extents, mds);if (rc)return ERR_PTR (rc); +/* +* Registered after clear_pending_extents so devm's reverse-order +* unwind cancels (and waits for) the watchdog first, then the list +* cleanup runs with the watchdog guaranteed not to refire. +*/ + rc =devm_add_action_or_reset (dev, cxl_cancel_dcd_add_chain_work, mds); +if (rc) +return ERR_PTR (rc); + rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )dev_warn (dev,"CXL MCE unsupported\n" );
drivers/cxl/cxlmem.h +19 -4
@@ -8,6 +8,8 @@#include <linux/uuid.h> #include <linux/node.h> #include <linux/list.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> #include <cxl/event.h> #include <cxl/mailbox.h> #include "cxl.h"
@@ -402,19 +404,32 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)/** * struct pending_add_ctx - Staging state for an in-progress -* DCD_ADD_CAPACITY event chain +* DCD_ADD_CAPACITY event chain * @pending_extents: extents received so far in the chain; flushed when -* the chain closes (More=0) +* the chain closes (More=0) * @group: tag group being assembled from the chain +* @timeout_work: watchdog that fires if a chain is opened with +* CXL_DCD_EVENT_MORE but the closing record never arrives +* @lock: serialises updates to the chain state against the watchdog +* @armed: set when a More=1 chain opens; cleared when the chain closes, +* either by a More=0 event record or by the watchdog firing. * * A DCD_ADD_CAPACITY notification can span multiple event records * stitched together by the CXL_DCD_EVENT_MORE flag. Records are staged -* here until the device clears More, at which point the staged batch is -* processed and responded to as a single Add_DC_Response. +* here until an event record with 'More'=0 is received, at which point the +* staged batch is processed and responded to as a single Add_DC_Response. +* +* If a chain is opened (More=1) but the device never sends the closing +* record, the staged list would otherwise sit indefinitely. @timeout_work +* is a defensive watchdog that refuses such a chain with an empty response +* and drops the staged list. */ struct pending_add_ctx {struct list_head pending_extents;struct cxl_dc_tag_group *group; +struct delayed_work timeout_work; +struct mutex lock; +bool armed; };/**
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 13/31] cxl/mem: Add 20 second timeout for stalled DC_ADD_CAPACITY chains
Quoted 92 lines · Anisa Su
A
DC_ADD_CAPACITYevent can span multiple event records grouped together by theCXL_DCD_EVENT_MOREflag. Extents are staged in the pending list until the last event record ('More'=0) is received, at which point the pending list is processed. If the device opens such a chain (More=1) but never sends the closing record, the staged list sits indefinitely.Add a delayed-work watchdog that, on expiry, refuses the chain with an empty
ADD_DC_RESPONSEand drops the staged list.The 20s timeout is a conservative upper bound and may be tightened later. The timeout is purely defensive — the spec does not require it, but prevents issues from a lost mailbox response or a crashed fabric manager.
Signed-off-by Anisa Su <[email protected]>--- drivers/cxl/core/mbox.c | 73 ++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 23 ++++++++++--- 2 files changed, 91 insertions(+), 5 deletions(-)drivers/cxl/core/mbox.c +49
-1@@ -1219,6 +1219,48 @@ static void clear_pending_extents(void *_mds) mds->add_ctx.group =NULL ; } +/* +* Bound on how long the host will wait for a device to finish a +* multi-record DC_ADD_CAPACITY chain (More=1 ... More=0) before +* refusing the chain. +* The timeout is not defined in the spec, but added for defensive purposes. +* Since there is no spec-defined timeout, 20s is chosen as a generous +* upper bound and matches the GPF timeout. +*/ +#define CXL_DC_ADD_TIMEOUT (20 * HZ) + +static void cxl_dc_add_timeout (struct work_struct *work) +{ +struct pending_add_ctx *ctx =container_of (to_delayed_work (work), + struct pending_add_ctx, + timeout_work); +struct cxl_memdev_state *mds =container_of (ctx, + struct cxl_memdev_state, + add_ctx); +struct device *dev = mds->cxlds.dev; + +guard (mutex)(&ctx->lock); + +if (!ctx->armed) +return ; + +dev_warn (dev,"DC add chain timed out; refusing staged extents\n" ); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &ctx->pending_extents,0 )) +dev_dbg (dev,"Failed to send empty ADD_DC_RESPONSE on timeout\n" ); + +clear_pending_extents (mds); + ctx->armed = false; +} + +static void cxl_cancel_dcd_add_chain_work (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; + +cancel_delayed_work_sync (&mds->add_ctx.timeout_work); +} +static int add_to_pending_list (struct list_head *pending_list,struct cxl_extent *to_add) {@@ -1246,18 +1288,34 @@ static int add_to_pending_list(struct list_head *pending_list,static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) { +struct pending_add_ctx *ctx = &mds->add_ctx;struct device *dev = mds->cxlds.dev;int rc; - rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +guard (mutex)(&ctx->lock); + + rc =add_to_pending_list (&ctx->pending_extents, &event->extent);if (rc)return rc;if (event->flags &CXL_DCD_EVENT_MORE ) {dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +mod_delayed_work (system_wq, &ctx->timeout_work, +CXL_DC_ADD_TIMEOUT ); + ctx->armed = true;
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1315
Quoted 10 lines
drivers/cxl/core/mbox.c +7
-0return 0 ; } +/* +* Chain is closing. Disarm before flushing so a pending watchdog +* (queued but blocked on @ctx->lock) sees !armed and bails out. +* cancel_delayed_work() — not _sync — because handle_add_event() +* itself runs on system_wq and a sync cancel of same-wq work can +* deadlock. +*/
Don't think this comment is correct. handle_add_event() is launched from threaded irq and does not run in system_wq. Just drop that second part of the comments.
Quoted 7 lines
drivers/cxl/core/mbox.c +3
-0+ ctx->armed = false; +cancel_delayed_work (&ctx->timeout_work); + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , &mds->add_ctx.pending_extents,0 );clear_pending_extents (mds);
drivers/cxl/core/mbox.c struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, · line 2073
Quoted 7 lines
drivers/cxl/core/mbox.c +4
-0@@ -2009,11 +2067,24 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,mutex_init (&mds->event.log_lock);INIT_LIST_HEAD (&mds->add_ctx.pending_extents); +mutex_init (&mds->add_ctx.lock); +INIT_DELAYED_WORK (&mds->add_ctx.timeout_work, + cxl_dc_add_timeout); + mds->add_ctx.armed = false;
Not needed. Allocated memory zeroed.
DJ
Quoted 67 lines
drivers/cxl/core/mbox.c +9
-0rc =devm_add_action_or_reset (dev, clear_pending_extents, mds);if (rc)return ERR_PTR (rc); +/* +* Registered after clear_pending_extents so devm's reverse-order +* unwind cancels (and waits for) the watchdog first, then the list +* cleanup runs with the watchdog guaranteed not to refire. +*/ + rc =devm_add_action_or_reset (dev, cxl_cancel_dcd_add_chain_work, mds); +if (rc) +return ERR_PTR (rc); + rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )dev_warn (dev,"CXL MCE unsupported\n" );drivers/cxl/cxlmem.h +19
-4@@ -8,6 +8,8 @@#include <linux/uuid.h> #include <linux/node.h> #include <linux/list.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> #include <cxl/event.h> #include <cxl/mailbox.h> #include "cxl.h" @@ -402,19 +404,32 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)/** * struct pending_add_ctx - Staging state for an in-progress -* DCD_ADD_CAPACITY event chain +* DCD_ADD_CAPACITY event chain * @pending_extents: extents received so far in the chain; flushed when -* the chain closes (More=0) +* the chain closes (More=0) * @group: tag group being assembled from the chain +* @timeout_work: watchdog that fires if a chain is opened with +* CXL_DCD_EVENT_MORE but the closing record never arrives +* @lock: serialises updates to the chain state against the watchdog +* @armed: set when a More=1 chain opens; cleared when the chain closes, +* either by a More=0 event record or by the watchdog firing. * * A DCD_ADD_CAPACITY notification can span multiple event records * stitched together by the CXL_DCD_EVENT_MORE flag. Records are staged -* here until the device clears More, at which point the staged batch is -* processed and responded to as a single Add_DC_Response. +* here until an event record with 'More'=0 is received, at which point the +* staged batch is processed and responded to as a single Add_DC_Response. +* +* If a chain is opened (More=1) but the device never sends the closing +* record, the staged list would otherwise sit indefinitely. @timeout_work +* is a defensive watchdog that refuses such a chain with an empty response +* and drops the staged list. */ struct pending_add_ctx {struct list_head pending_extents;struct cxl_dc_tag_group *group; +struct delayed_work timeout_work; +struct mutex lock; +bool armed; };/**
Re: [PATCH v10 13/31] cxl/mem: Add 20 second timeout for stalled DC_ADD_CAPACITY chains
Quoted 98 lines · Dave Jiang
Quoted 95 lines · Anisa Su
A
DC_ADD_CAPACITYevent can span multiple event records grouped together by theCXL_DCD_EVENT_MOREflag. Extents are staged in the pending list until the last event record ('More'=0) is received, at which point the pending list is processed. If the device opens such a chain (More=1) but never sends the closing record, the staged list sits indefinitely.Add a delayed-work watchdog that, on expiry, refuses the chain with an empty
ADD_DC_RESPONSEand drops the staged list.The 20s timeout is a conservative upper bound and may be tightened later. The timeout is purely defensive — the spec does not require it, but prevents issues from a lost mailbox response or a crashed fabric manager.
Signed-off-by Anisa Su <[email protected]>--- drivers/cxl/core/mbox.c | 73 ++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 23 ++++++++++--- 2 files changed, 91 insertions(+), 5 deletions(-)drivers/cxl/core/mbox.c +49
-1@@ -1219,6 +1219,48 @@ static void clear_pending_extents(void *_mds) mds->add_ctx.group =NULL ; } +/* +* Bound on how long the host will wait for a device to finish a +* multi-record DC_ADD_CAPACITY chain (More=1 ... More=0) before +* refusing the chain. +* The timeout is not defined in the spec, but added for defensive purposes. +* Since there is no spec-defined timeout, 20s is chosen as a generous +* upper bound and matches the GPF timeout. +*/ +#define CXL_DC_ADD_TIMEOUT (20 * HZ) + +static void cxl_dc_add_timeout (struct work_struct *work) +{ +struct pending_add_ctx *ctx =container_of (to_delayed_work (work), + struct pending_add_ctx, + timeout_work); +struct cxl_memdev_state *mds =container_of (ctx, + struct cxl_memdev_state, + add_ctx); +struct device *dev = mds->cxlds.dev; + +guard (mutex)(&ctx->lock); + +if (!ctx->armed) +return ; + +dev_warn (dev,"DC add chain timed out; refusing staged extents\n" ); + +if (cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + &ctx->pending_extents,0 )) +dev_dbg (dev,"Failed to send empty ADD_DC_RESPONSE on timeout\n" ); + +clear_pending_extents (mds); + ctx->armed = false; +} + +static void cxl_cancel_dcd_add_chain_work (void *_mds) +{ +struct cxl_memdev_state *mds = _mds; + +cancel_delayed_work_sync (&mds->add_ctx.timeout_work); +} +static int add_to_pending_list (struct list_head *pending_list,struct cxl_extent *to_add) {@@ -1246,18 +1288,34 @@ static int add_to_pending_list(struct list_head *pending_list,static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) { +struct pending_add_ctx *ctx = &mds->add_ctx;struct device *dev = mds->cxlds.dev;int rc; - rc =add_to_pending_list (&mds->add_ctx.pending_extents, &event->extent); +guard (mutex)(&ctx->lock); + + rc =add_to_pending_list (&ctx->pending_extents, &event->extent);if (rc)return rc;if (event->flags &CXL_DCD_EVENT_MORE ) {dev_dbg (dev,"more bit set; delay the surfacing of extent\n" ); +mod_delayed_work (system_wq, &ctx->timeout_work, +CXL_DC_ADD_TIMEOUT ); + ctx->armed = true;return 0 ; }
Quoted 10 lines
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1315
Quoted 7 lines
drivers/cxl/core/mbox.c +7
-0+/* +* Chain is closing. Disarm before flushing so a pending watchdog +* (queued but blocked on @ctx->lock) sees !armed and bails out. +* cancel_delayed_work() — not _sync — because handle_add_event() +* itself runs on system_wq and a sync cancel of same-wq work can +* deadlock. +*/ Don't think this comment is correct.
handle_add_event()is launched from threaded irq and does not run insystem_wq. Just drop that second part of the comments.
Oh I see. Done!
Quoted 8 lines
Quoted 8 lines
drivers/cxl/core/mbox.c +3
-0+ ctx->armed = false; +cancel_delayed_work (&ctx->timeout_work); + rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , &mds->add_ctx.pending_extents,0 );clear_pending_extents (mds);@@ -2009,11 +2067,24 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,
Quoted 9 lines
drivers/cxl/core/mbox.c struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial, · line 2073
Quoted 6 lines
drivers/cxl/core/mbox.c +4
-0mutex_init (&mds->event.log_lock);INIT_LIST_HEAD (&mds->add_ctx.pending_extents); +mutex_init (&mds->add_ctx.lock); +INIT_DELAYED_WORK (&mds->add_ctx.timeout_work, + cxl_dc_add_timeout); + mds->add_ctx.armed = false;Not needed. Allocated memory zeroed.
Dropped
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 68 lines
Quoted 67 lines
drivers/cxl/core/mbox.c +9
-0rc =devm_add_action_or_reset (dev, clear_pending_extents, mds);if (rc)return ERR_PTR (rc); +/* +* Registered after clear_pending_extents so devm's reverse-order +* unwind cancels (and waits for) the watchdog first, then the list +* cleanup runs with the watchdog guaranteed not to refire. +*/ + rc =devm_add_action_or_reset (dev, cxl_cancel_dcd_add_chain_work, mds); +if (rc) +return ERR_PTR (rc); + rc =devm_cxl_register_mce_notifier (dev, &mds->mce_notifier);if (rc == -EOPNOTSUPP )dev_warn (dev,"CXL MCE unsupported\n" );drivers/cxl/cxlmem.h +19
-4@@ -8,6 +8,8 @@#include <linux/uuid.h> #include <linux/node.h> #include <linux/list.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> #include <cxl/event.h> #include <cxl/mailbox.h> #include "cxl.h" @@ -402,19 +404,32 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)/** * struct pending_add_ctx - Staging state for an in-progress -* DCD_ADD_CAPACITY event chain +* DCD_ADD_CAPACITY event chain * @pending_extents: extents received so far in the chain; flushed when -* the chain closes (More=0) +* the chain closes (More=0) * @group: tag group being assembled from the chain +* @timeout_work: watchdog that fires if a chain is opened with +* CXL_DCD_EVENT_MORE but the closing record never arrives +* @lock: serialises updates to the chain state against the watchdog +* @armed: set when a More=1 chain opens; cleared when the chain closes, +* either by a More=0 event record or by the watchdog firing. * * A DCD_ADD_CAPACITY notification can span multiple event records * stitched together by the CXL_DCD_EVENT_MORE flag. Records are staged -* here until the device clears More, at which point the staged batch is -* processed and responded to as a single Add_DC_Response. +* here until an event record with 'More'=0 is received, at which point the +* staged batch is processed and responded to as a single Add_DC_Response. +* +* If a chain is opened (More=1) but the device never sends the closing +* record, the staged list would otherwise sit indefinitely. @timeout_work +* is a defensive watchdog that refuses such a chain with an empty response +* and drops the staged list. */ struct pending_add_ctx {struct list_head pending_extents;struct cxl_dc_tag_group *group; +struct delayed_work timeout_work; +struct mutex lock; +bool armed; };/**
PATCH v10 14/31 cxl/extent: Handle DC Add Capacity events
In reply to Anisa SuReplace the empty-response stub in handle_add_event() with the real add pipeline.
DC Event Records can be grouped together with the 'More' flag. The previous commit completed the set up for holding onto extents in the pending list until receiving the last event record of the group, marked by 'More'=0.
This commit fills in the logic for processing the pending list and adds basic validation for extents before they are added to the device model as a child of the cxlr_dax region. More complete checks for tags/sequence numbers/alignment is added in subsequent commits.
For each tag that appears in the pending list:
1. Extract all extents in the pending list with that tag to a local list.
2. The spec requires that shareable extents are ordered by shared extent sequence number, which "instructs each host on the relative order these extents must be placed in adjacent virtual address space" (r4.0 Section 9.13.3 Figure 9-23 Shared Extent List Example). Otherwise, retain arrival order.
Thus the tag group is stable-sorted by shared_extn_seq; for non-sharable extents every key is 0 and the stable sort preserves arrival order.
Individual extents are checked for the following:
1. The extent's DPA range fully resolves to an endpoint decoder.
2. Doesn't overlap with a previously accepted extent.
3. Sequence number doesn't collide with others in the same tag group
Upon passing these checks, extents are "onlined" together as a tag group:online_tag_group() registers a struct device per dc_extent under cxlr_dax->dev so the dax layer can discover them via device_for_each_child().
Once the pending list has been fully processed, send the DC_ADD_RESPONSE.
Based on an original patch by Navneet Singh.
---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit fills in the Add path on top of the previous commit's stubs. Further validation lands in subsequent commits.]
--- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 13 ++ drivers/cxl/core/extent.c | 372 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 123 ++++++++++- drivers/cxl/core/region_dax.c | 3 + drivers/cxl/cxl.h | 19 ++ tools/testing/cxl/Kbuild | 5 +- 7 files changed, 528 insertions(+), 9 deletions(-) create mode 100644 drivers/cxl/core/extent.c
drivers/cxl/core/Makefile +1 -1
@@ -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 +13 -0
@@ -65,12 +65,24 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,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, +u16 seq_num); +int online_tag_group (struct cxl_dc_tag_group *group);#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,u16 seq_num) +{ +return 0 ; +} +static inline int online_tag_group (struct cxl_dc_tag_group *group) +{ +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 +178,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 +372 -0
372 lines not on this page · raw message
drivers/cxl/core/mbox.c +116 -7
148 lines not on this page · raw message
drivers/cxl/core/region_dax.c +3 -0
@@ -13,6 +13,7 @@ static void cxl_dax_region_release(struct device *dev) {struct cxl_dax_region *cxlr_dax =to_cxl_dax_region (dev); +xa_destroy (&cxlr_dax->dc_extents);kfree (cxlr_dax); }
@@ -57,11 +58,13 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr)if (!cxlr_dax)return ERR_PTR (-ENOMEM ); +xa_init_flags (&cxlr_dax->dc_extents,XA_FLAGS_ALLOC ); cxlr_dax->hpa_range.start = p->res->start; cxlr_dax->hpa_range.end = p->res->end; dev = &cxlr_dax->dev; cxlr_dax->cxlr = cxlr; + cxlr->cxlr_dax = cxlr_dax;device_initialize (dev);lockdep_set_class (&dev->mutex, &cxl_dax_region_key);device_set_pm_not_required (dev);
drivers/cxl/cxl.h +19 -0
@@ -495,6 +495,7 @@ struct cxl_region_params {* @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown * @cxlr_pmem: (for pmem regions) cached copy of the nvdimm bridge +* @cxlr_dax: (for DC regions) cached copy of CXL DAX bridge * @flags: Region state flags * @params: active + config params for the region * @coord: QoS access coordinates for the region
@@ -510,6 +511,7 @@ struct cxl_region {enum cxl_decoder_type type;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_pmem_region *cxlr_pmem; +struct cxl_dax_region *cxlr_dax;unsigned long flags;struct cxl_region_params params;struct access_coordinate coord[ACCESS_COORDINATE_MAX ];
@@ -568,6 +570,15 @@ struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; +/* +* dc_extents is keyed by an allocator-assigned u32 (see +* online_tag_group()). Tag groups have no first-class identity in +* this xarray; siblings within a tag find each other via +* dc_extent->group. Tag-uniqueness lookup is a linear xa_for_each +* walk, adequate at the bounded per-region extent counts the +* driver handles. +*/ +struct xarray dc_extents; };/**
@@ -595,6 +606,14 @@ struct cxl_dc_tag_group {unsigned int nr_extents; }; +bool is_dc_extent (struct device *dev); +static inline struct dc_extent *to_dc_extent (struct device *dev) +{ +if (!is_dc_extent (dev)) +return NULL ; + return container_of(dev, struct dc_extent, dev); +} +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory
tools/testing/cxl/Kbuild +4 -1
@@ -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
Dave Jiang
maintainerRe: [PATCH v10 14/31] cxl/extent: Handle DC Add Capacity events
Quoted 141 lines · Anisa Su
Replace the empty-response stub in
handle_add_event()with the real add pipeline.DC Event Records can be grouped together with the 'More' flag. The previous commit completed the set up for holding onto extents in the pending list until receiving the last event record of the group, marked by 'More'=0.
This commit fills in the logic for processing the pending list and adds basic validation for extents before they are added to the device model as a child of the
cxlr_daxregion. More complete checks for tags/sequence numbers/alignment is added in subsequent commits.For each tag that appears in the pending list:
1. Extract all extents in the pending list with that tag to a local list.2. The spec requires that shareable extents are ordered by shared extent sequence number, which "instructs each host on the relative order these extents must be placed in adjacent virtual address space" (r4.0 Section 9.13.3 Figure 9-23 Shared Extent List Example). Otherwise, retain arrival order.
Thus the tag group is stable-sorted by
shared_extn_seq; for non-sharable extents every key is 0 and the stable sort preserves arrival order.Individual extents are checked for the following:
1. The extent's DPA range fully resolves to an endpoint decoder.2. Doesn't overlap with a previously accepted extent.
3. Sequence number doesn't collide with others in the same tag group
Upon passing these checks, extents are "onlined" together as a tag group:
online_tag_group()registers a struct device perdc_extentundercxlr_dax->devso the dax layer can discover them viadevice_for_each_child().Once the pending list has been fully processed, send the
DC_ADD_RESPONSE.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit fills in the Add path on top of the previous commit's stubs. Further validation lands in subsequent commits.]--- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 13 ++ drivers/cxl/core/extent.c | 372 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 123 ++++++++++- drivers/cxl/core/region_dax.c | 3 + drivers/cxl/cxl.h | 19 ++ tools/testing/cxl/Kbuild | 5 +- 7 files changed, 528 insertions(+), 9 deletions(-) create mode 100644 drivers/cxl/core/extent.cdrivers/cxl/core/Makefile +1
-1@@ -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.odrivers/cxl/core/core.h +13
-0@@ -65,12 +65,24 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,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, +u16 seq_num); +int online_tag_group (struct cxl_dc_tag_group *group);#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,u16 seq_num) +{ +return 0 ; +} +static inline int online_tag_group (struct cxl_dc_tag_group *group) +{ +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 +178,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 +19
-0@@ -0,0 +1,372 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ + +#include <linux/device.h> +#include <cxl.h> + +#include "core.h" + + +static void cxled_release_extent (struct cxl_endpoint_decoder *cxled, +struct dc_extent *dc_extent) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = &cxled->cxld.dev; + +dev_dbg (dev,"Remove extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); +memdev_release_extent (mds, &dc_extent->dpa_range); +}
drivers/cxl/core/extent.c line 29
Quoted 10 lines
drivers/cxl/core/extent.c new file +10
-0+ +static void free_tag_group (struct cxl_dc_tag_group *group) +{ +xa_destroy (&group->dc_extents); +kfree (group); +} + +static void dc_extent_release (struct device *dev) +{ +struct dc_extent *dc_extent =to_dc_extent (dev);
to_dc_extent() can return NULL. Need to check dc_extent before use.
drivers/cxl/core/extent.c line 33
Quoted 4 lines
drivers/cxl/core/extent.c new file +4
-0+struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->cxlr_dax->dc_extents, dc_extent->dev.id);
This could potentially be a problem. See comments later with online_tag_group()
Quoted 65 lines
drivers/cxl/core/extent.c new file +65
-0+xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +static const struct device_type dc_extent_type = { + .name ="extent" , + .release = dc_extent_release, +}; + +bool is_dc_extent (struct device *dev) +{ +return dev->type == &dc_extent_type; +} +EXPORT_SYMBOL_NS_GPL (is_dc_extent,"CXL" ); + +static struct cxl_dc_tag_group * +alloc_tag_group (struct cxl_dax_region *cxlr_dax,uuid_t *uuid) +{ + struct cxl_dc_tag_group *group __free(kfree) = +kzalloc (sizeof (*group),GFP_KERNEL ); +if (!group) +return ERR_PTR (-ENOMEM ); + + group->cxlr_dax = cxlr_dax; +uuid_copy (&group->uuid, uuid); +xa_init (&group->dc_extents); +return no_free_ptr (group); +} + +/* +* Stage 1 of the add pipeline: pure, no allocation. Resolve the extent +* to its region/endpoint decoder and ext_range, and verify the range +* fits in the resolved endpoint decoder's DPA resource. Further +* per-extent invariants layer into this function in subsequent commits. +* +* Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). +* On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the +* resolved handles consumed by the rest of the pipeline. +*/ +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct cxl_endpoint_decoder **out_cxled, +struct cxl_dax_region **out_cxlr_dax, +struct range *out_ext_range) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct cxl_endpoint_decoder *cxled; +struct cxl_region *cxlr; +struct range ext_range = (struct range ) { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; +struct range ed_range; + + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled); +if (!cxlr) +return -ENXIO ; + + ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end,
drivers/cxl/core/extent.c line 108
Quoted 10 lines
drivers/cxl/core/extent.c new file +10
-0+ }; +if (!range_contains (&ed_range, &ext_range)) { +dev_err_ratelimited (&cxled->cxld.dev, +"DC extent DPA %pra (%pU) is not fully in ED %pra\n" , + &ext_range, extent->uuid, &ed_range); +return -ENXIO ; + } + + *out_cxled = cxled; + *out_cxlr_dax = cxlr->cxlr_dax;
Should there be check for cxled and cxlr->cxlr_dax to make sure they aren't NULL?
Quoted 130 lines
drivers/cxl/core/extent.c new file +130
-0+ *out_ext_range = ext_range; +return 0 ; +} + +enum cxl_extent_class { +CXL_EXT_NEW , +CXL_EXT_DUPLICATE , +CXL_EXT_OVERLAP , +}; + +/* +* Stage 2: classify @ext_range against extents already accepted on this +* cxlr_dax+cxled. Walks cxlr_dax->dc_extents once: a stored extent that +* fully contains @ext_range means a duplicate accept (idempotent, fine); +* a stored extent that only overlaps means an inconsistent offer. +*/ +static enum cxl_extent_class +cxlr_dax_classify_extent (struct cxl_dax_region *cxlr_dax, +struct cxl_endpoint_decoder *cxled, +const struct range *ext_range) +{ +struct dc_extent *entry; +unsigned long i; + +xa_for_each (&cxlr_dax->dc_extents, i, entry) { +if (entry->cxled != cxled) +continue ; +if (range_contains (&entry->dpa_range, ext_range)) +return CXL_EXT_DUPLICATE ; +if (range_overlaps (&entry->dpa_range, ext_range)) +return CXL_EXT_OVERLAP ; + } +return CXL_EXT_NEW ; +} + +/* +* Stage 3: allocate and populate a dc_extent for an already-validated, +* already-classified-as-new @ext_range. Only -ENOMEM can fail here. +*/ +static struct dc_extent * +dc_extent_build (struct cxl_endpoint_decoder *cxled, +struct cxl_dax_region *cxlr_dax, +struct cxl_extent *extent, +const struct range *ext_range,u16 seq_num) +{ +resource_size_t dpa_offset = ext_range->start - cxled->dpa_res->start; +resource_size_t hpa = cxled->cxld.hpa_range.start + dpa_offset; +struct dc_extent *dc_extent; + + dc_extent =kzalloc (sizeof (*dc_extent),GFP_KERNEL ); +if (!dc_extent) +return ERR_PTR (-ENOMEM ); + + dc_extent->cxled = cxled; + dc_extent->dpa_range = *ext_range; + dc_extent->hpa_range.start = hpa - cxlr_dax->hpa_range.start; + dc_extent->hpa_range.end = dc_extent->hpa_range.start + +range_len (ext_range) -1 ; + dc_extent->seq_num = seq_num; +import_uuid (&dc_extent->uuid, extent->uuid); +return dc_extent; +} + +/* +* Stage 4: insert @dc_extent into the pending tag group. All extents in +* one More-chain group share a UUID — enforced here as the group is +* either being created (first extent) or appended to. On any failure +* the dc_extent is freed. +*/ +static int cxlr_add_extent (struct cxl_memdev_state *mds, +struct cxl_dax_region *cxlr_dax, +struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group **group = &mds->add_ctx.group; +int rc; + +if (*group && !uuid_equal (&(*group)->uuid, &dc_extent->uuid)) { +kfree (dc_extent); +return -EINVAL ; + } + +if (!*group) { +dev_dbg (&cxlr_dax->dev,"Alloc new tag group\n" ); + *group =alloc_tag_group (cxlr_dax, &dc_extent->uuid); +if (IS_ERR (*group)) { + rc =PTR_ERR (*group); + *group =NULL ; +kfree (dc_extent); +return rc; + } + }else { +dev_dbg (&cxlr_dax->dev,"Append dc_extent to tag group\n" ); + } + + dc_extent->group = *group; + +/* +* Key by @seq_num so iteration order equals assembly order, in both +* the sharable case (device-stamped 1..n) and the non-sharable case +* (host-assigned arrival-order 1..n). A collision here signals a +* cxl-side validation gap. +*/ + rc =xa_insert (&(*group)->dc_extents, dc_extent->seq_num, + dc_extent,GFP_KERNEL ); +if (rc) { +dev_WARN_ONCE (&cxlr_dax->dev, rc == -EBUSY , +"duplicate seq_num %u in tag %pUb\n" , + dc_extent->seq_num, &dc_extent->uuid); +kfree (dc_extent); +return rc; + } + +return 0 ; +} + +int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent, +u16 seq_num) +{ +struct cxl_endpoint_decoder *cxled; +struct cxl_dax_region *cxlr_dax; +struct dc_extent *dc_extent; +struct range ext_range; +int rc; + +guard (rwsem_read)(&cxl_rwsem.region); + + rc =cxl_validate_extent (mds, extent, &cxled, &cxlr_dax, &ext_range); +if (rc) +return rc; +
drivers/cxl/core/extent.c line 248
Quoted 10 lines
drivers/cxl/core/extent.c new file +10
-0+switch (cxlr_dax_classify_extent (cxlr_dax, cxled, &ext_range)) { +case CXL_EXT_DUPLICATE : +/* +* Idempotent accept simplifies the dax-side scan for existing +* extents on region creation; reply success without duplicating. +*/ +dev_warn_ratelimited (&cxled->cxld.dev, +"Extent %pra exists; accept again\n" , + &ext_range); +return 0 ;
Does this cause issues with the accounting in cxl_add_pending()? At the end the total_accepted would include duplicates as well. I wonder if modify cxlr_add_extent() to return 1 if an extent is added and handle the returns approriately would make the accounting more accurate.
Quoted 60 lines
drivers/cxl/core/extent.c new file +60
-0+case CXL_EXT_OVERLAP : +return -ENXIO ; +case CXL_EXT_NEW : +break ; + } + + dc_extent =dc_extent_build (cxled, cxlr_dax, extent, &ext_range, + seq_num); +if (IS_ERR (dc_extent)) +return PTR_ERR (dc_extent); + +dev_dbg (&cxled->cxld.dev,"Add extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); + +return cxlr_add_extent (mds, cxlr_dax, dc_extent); +} + +static void dc_extent_unregister (void *ext) +{ +struct dc_extent *dc_extent = ext; + +dev_dbg (&dc_extent->dev,"DAX region rm extent HPA %pra\n" , + &dc_extent->hpa_range); +device_unregister (&dc_extent->dev); +} + +static void cleanup_pending_dc_extent (struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +int online_tag_group (struct cxl_dc_tag_group *group) +{ +struct cxl_dax_region *cxlr_dax = group->cxlr_dax; +struct dc_extent *dc_extent; +unsigned long index; +int rc =0 ; + +/* +* Seed nr_extents with the full group size plus a +1 pin held by +* this function. The size counts every dc_extent that might +* decrement nr_extents on cleanup; the pin keeps @group alive +* across the body even if every dc_extent release fires inside +* the loop (e.g. devm_add_action_or_reset failure on the only +* pending extent). The pin is dropped at the end of the function. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) + group->nr_extents++; + group->nr_extents++; + +xa_for_each (&group->dc_extents, index, dc_extent) { +struct device *dev = &dc_extent->dev; +u32 id;
drivers/cxl/core/extent.c line 318
Quoted 10 lines
drivers/cxl/core/extent.c new file +10
-0+ +device_initialize (dev); +device_set_pm_not_required (dev); + dev->parent = &cxlr_dax->dev; + dev->type = &dc_extent_type; + + rc =xa_alloc (&cxlr_dax->dc_extents, &id, dc_extent, + xa_limit_32b,GFP_KERNEL ); +if (rc <0 ) { +put_device (dev);
Here xa_alloc() fails, so there no valid id. But the put_device() will trigger dc_extent_release(). And therefore dev->id of 0 is passed in and potentially erase the id 0 slot even if that's not the intended id. Can always define xarray with XA_FLAGS_ALLOC1 to start it at 1 and therefore slot 0 is not used.
Quoted 145 lines
drivers/cxl/core/extent.c new file +54
-0+break ; + } + dev->id = id; + + rc =dev_set_name (dev,"extent%d.%d" , cxlr_dax->cxlr->id, + dev->id); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + + rc =device_add (dev); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + +dev_dbg (dev,"dc_extent HPA %pra (%pU)\n" , + &dc_extent->hpa_range, &group->uuid); + + rc =devm_add_action_or_reset (&cxlr_dax->dev, + dc_extent_unregister, dc_extent); +if (rc) +break ; + } + +if (rc) { +/* +* Unwind every remaining dc_extent in the group. The pin +* above keeps @group alive across this walk. Distinguish +* onlined dc_extents (have a devm action) from pending ones +* via devm_remove_action_nowarn(): a 0 return means the +* action was installed and is now consumed, so we run the +* unregister ourselves; -ENOENT means pending. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) { +int r =devm_remove_action_nowarn (&cxlr_dax->dev, + dc_extent_unregister, + dc_extent); +if (r ==0 ) +dc_extent_unregister (dc_extent); +else +cleanup_pending_dc_extent (dc_extent); + } + } + +/* Drop the pin; if nothing else still references @group, free it. */ + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +return rc; +}drivers/cxl/core/mbox.c +63
-5@@ -6,6 +6,7 @@#include <linux/mutex.h> #include <linux/unaligned.h> #include <linux/list.h> +#include <linux/list_sort.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1181,7 +1182,7 @@ static void delete_extent_node(struct cxl_extent_list_node *node)kfree (node); } -static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) {struct device *dev = mds->cxlds.dev;struct cxl_extent_list_node *node;@@ -1280,11 +1281,120 @@ static int add_to_pending_list(struct list_head *pending_list, }/* -* Stub: stage extents on the pending list and reply with an empty -* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces -* the no-op tail with the real Add pipeline that surfaces a dax -* device per accepted extent. +* Compare two extents by shared_extn_seq (ascending). list_sort is +* stable so when shared_extn_seq is 0 for every entry (non-sharable +* partition) ties fall back to arrival order via list_add_tail() in +* add_to_pending_list(). */ +static int extent_seq_compare (void *priv, +const struct list_head *a, +const struct list_head *b) +{ +const struct cxl_extent_list_node *ea = + list_entry(a, struct cxl_extent_list_node, list); +const struct cxl_extent_list_node *eb = + list_entry(b, struct cxl_extent_list_node, list); +u16 sa =le16_to_cpu (ea->extent->shared_extn_seq); +u16 sb =le16_to_cpu (eb->extent->shared_extn_seq); + +if (sa < sb) +return -1 ; +if (sa > sb) +return 1 ; +return 0 ; +} + +/* +* Move every pending extent whose tag matches @tag onto @group, preserving +* the order they appear in @pending. +*/ +static void extract_tag_group (struct list_head *pending, +const uuid_t *tag, +struct list_head *group) +{ +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, pending, list) { +uuid_t t; + +import_uuid (&t, pos->extent->uuid); +if (uuid_equal (&t, tag)) +list_move_tail (&pos->list, group); + } +} + +/* +* Drive the pending Add-Capacity records through cxl_add_extent(), +* grouped by tag. Per group: extract from pending, stable-sort by +* shared_extn_seq, then attempt to add each extent. Online the tag +* group via online_tag_group() once all of its extents have been +* realized. Validation gates layer onto this loop in later commits. +*/ +static int cxl_add_pending (struct cxl_memdev_state *mds) +{ +struct device *dev = mds->cxlds.dev; +struct list_head *pending = &mds->add_ctx.pending_extents; +struct cxl_extent_list_node *pos, *tmp; +LIST_HEAD (accepted); +int total_accepted =0 ; + +while (!list_empty (pending)) { +LIST_HEAD (group); +struct cxl_dc_tag_group *tag_group; +int group_cnt =0 ; +uuid_t tag;
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1355
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+int rc; + +import_uuid (&tag, +list_first_entry (pending, + struct cxl_extent_list_node, + list)->extent->uuid); +extract_tag_group (pending, &tag, &group); +list_sort (NULL , &group, extent_seq_compare); + +u16 logical_seq =1 ;
declaring var in middle of code
Quoted 11 lines
drivers/cxl/core/mbox.c +11
-0+list_for_each_entry_safe (pos, tmp, &group, list) { +u16 raw =le16_to_cpu (pos->extent->shared_extn_seq); +u16 seq = raw ? raw : logical_seq; + + logical_seq++; + +if (cxl_add_extent (mds, pos->extent, seq)) { + dev_dbg(dev, + "Tag %pUb: failed to add extent DPA:%#llx LEN:%#llx\n", + &tag, + le64_to_cpu(pos->extent->start_dpa),
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1376
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ le64_to_cpu(pos->extent->length)); +delete_extent_node (pos); +continue ; + } + group_cnt++; + } + + tag_group = mds->add_ctx.group; +if (!tag_group) +continue ;
Does it need to add delete_extent_node() for the group before continue?
DJ
Quoted 127 lines
drivers/cxl/core/mbox.c +22
-2+ + rc =online_tag_group (tag_group); +if (rc) { +dev_warn (dev, +"Tag %pUb: failed to online tag group (%d)\n" , + &tag, rc); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); + }else { +list_splice_tail_init (&group, &accepted); + total_accepted += group_cnt; + } + + mds->add_ctx.group =NULL ; + } + +list_splice (&accepted, pending); +return cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + pending, total_accepted); +} +static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) {@@ -1316,8 +1426,7 @@ static int handle_add_event(struct cxl_memdev_state *mds, ctx->armed = false;cancel_delayed_work (&ctx->timeout_work); - rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , - &mds->add_ctx.pending_extents,0 ); + rc =cxl_add_pending (mds);clear_pending_extents (mds);return rc; }drivers/cxl/core/region_dax.c +3
-0@@ -13,6 +13,7 @@ static void cxl_dax_region_release(struct device *dev) {struct cxl_dax_region *cxlr_dax =to_cxl_dax_region (dev); +xa_destroy (&cxlr_dax->dc_extents);kfree (cxlr_dax); }@@ -57,11 +58,13 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr)if (!cxlr_dax)return ERR_PTR (-ENOMEM ); +xa_init_flags (&cxlr_dax->dc_extents,XA_FLAGS_ALLOC ); cxlr_dax->hpa_range.start = p->res->start; cxlr_dax->hpa_range.end = p->res->end; dev = &cxlr_dax->dev; cxlr_dax->cxlr = cxlr; + cxlr->cxlr_dax = cxlr_dax;device_initialize (dev);lockdep_set_class (&dev->mutex, &cxl_dax_region_key);device_set_pm_not_required (dev);drivers/cxl/cxl.h +19
-0@@ -495,6 +495,7 @@ struct cxl_region_params {* @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown * @cxlr_pmem: (for pmem regions) cached copy of the nvdimm bridge +* @cxlr_dax: (for DC regions) cached copy of CXL DAX bridge * @flags: Region state flags * @params: active + config params for the region * @coord: QoS access coordinates for the region @@ -510,6 +511,7 @@ struct cxl_region {enum cxl_decoder_type type;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_pmem_region *cxlr_pmem; +struct cxl_dax_region *cxlr_dax;unsigned long flags;struct cxl_region_params params;struct access_coordinate coord[ACCESS_COORDINATE_MAX ];@@ -568,6 +570,15 @@ struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; +/* +* dc_extents is keyed by an allocator-assigned u32 (see +* online_tag_group()). Tag groups have no first-class identity in +* this xarray; siblings within a tag find each other via +* dc_extent->group. Tag-uniqueness lookup is a linear xa_for_each +* walk, adequate at the bounded per-region extent counts the +* driver handles. +*/ +struct xarray dc_extents; };/** @@ -595,6 +606,14 @@ struct cxl_dc_tag_group {unsigned int nr_extents; }; +bool is_dc_extent (struct device *dev); +static inline struct dc_extent *to_dc_extent (struct device *dev) +{ +if (!is_dc_extent (dev)) +return NULL ; + return container_of(dev, struct dc_extent, dev); +} +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory tools/testing/cxl/Kbuild +4
-1@@ -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
Re: [PATCH v10 14/31] cxl/extent: Handle DC Add Capacity events
Quoted 148 lines · Dave Jiang
Quoted 145 lines · Anisa Su
Replace the empty-response stub in
handle_add_event()with the real add pipeline.DC Event Records can be grouped together with the 'More' flag. The previous commit completed the set up for holding onto extents in the pending list until receiving the last event record of the group, marked by 'More'=0.
This commit fills in the logic for processing the pending list and adds basic validation for extents before they are added to the device model as a child of the
cxlr_daxregion. More complete checks for tags/sequence numbers/alignment is added in subsequent commits.For each tag that appears in the pending list:
1. Extract all extents in the pending list with that tag to a local list.2. The spec requires that shareable extents are ordered by shared extent sequence number, which "instructs each host on the relative order these extents must be placed in adjacent virtual address space" (r4.0 Section 9.13.3 Figure 9-23 Shared Extent List Example). Otherwise, retain arrival order.
Thus the tag group is stable-sorted by
shared_extn_seq; for non-sharable extents every key is 0 and the stable sort preserves arrival order.Individual extents are checked for the following:
1. The extent's DPA range fully resolves to an endpoint decoder.2. Doesn't overlap with a previously accepted extent.
3. Sequence number doesn't collide with others in the same tag group
Upon passing these checks, extents are "onlined" together as a tag group:
online_tag_group()registers a struct device perdc_extentundercxlr_dax->devso the dax layer can discover them viadevice_for_each_child().Once the pending list has been fully processed, send the
DC_ADD_RESPONSE.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit fills in the Add path on top of the previous commit's stubs. Further validation lands in subsequent commits.]--- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 13 ++ drivers/cxl/core/extent.c | 372 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 123 ++++++++++- drivers/cxl/core/region_dax.c | 3 + drivers/cxl/cxl.h | 19 ++ tools/testing/cxl/Kbuild | 5 +- 7 files changed, 528 insertions(+), 9 deletions(-) create mode 100644 drivers/cxl/core/extent.cdrivers/cxl/core/Makefile +1
-1@@ -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.odrivers/cxl/core/core.h +13
-0@@ -65,12 +65,24 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,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, +u16 seq_num); +int online_tag_group (struct cxl_dc_tag_group *group);#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,u16 seq_num) +{ +return 0 ; +} +static inline int online_tag_group (struct cxl_dc_tag_group *group) +{ +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 +178,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 +23
-0@@ -0,0 +1,372 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ + +#include <linux/device.h> +#include <cxl.h> + +#include "core.h" + + +static void cxled_release_extent (struct cxl_endpoint_decoder *cxled, +struct dc_extent *dc_extent) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = &cxled->cxld.dev; + +dev_dbg (dev,"Remove extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); +memdev_release_extent (mds, &dc_extent->dpa_range); +} + +static void free_tag_group (struct cxl_dc_tag_group *group) +{ +xa_destroy (&group->dc_extents);
Quoted 9 lines
drivers/cxl/core/extent.c line 29
Quoted 6 lines
drivers/cxl/core/extent.c new file +6
-0+kfree (group); +} + +static void dc_extent_release (struct device *dev) +{ +struct dc_extent *dc_extent =to_dc_extent (dev);
to_dc_extent()can return NULL. Need to checkdc_extentbefore use.
done :)
Quoted 76 lines
drivers/cxl/core/extent.c line 33
Quoted 4 lines
drivers/cxl/core/extent.c new file +4
-0+struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->cxlr_dax->dc_extents, dc_extent->dev.id);This could potentially be a problem. See comments later with
online_tag_group()Quoted 69 lines
drivers/cxl/core/extent.c new file +69
-0+xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +static const struct device_type dc_extent_type = { + .name ="extent" , + .release = dc_extent_release, +}; + +bool is_dc_extent (struct device *dev) +{ +return dev->type == &dc_extent_type; +} +EXPORT_SYMBOL_NS_GPL (is_dc_extent,"CXL" ); + +static struct cxl_dc_tag_group * +alloc_tag_group (struct cxl_dax_region *cxlr_dax,uuid_t *uuid) +{ + struct cxl_dc_tag_group *group __free(kfree) = +kzalloc (sizeof (*group),GFP_KERNEL ); +if (!group) +return ERR_PTR (-ENOMEM ); + + group->cxlr_dax = cxlr_dax; +uuid_copy (&group->uuid, uuid); +xa_init (&group->dc_extents); +return no_free_ptr (group); +} + +/* +* Stage 1 of the add pipeline: pure, no allocation. Resolve the extent +* to its region/endpoint decoder and ext_range, and verify the range +* fits in the resolved endpoint decoder's DPA resource. Further +* per-extent invariants layer into this function in subsequent commits. +* +* Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). +* On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the +* resolved handles consumed by the rest of the pipeline. +*/ +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct cxl_endpoint_decoder **out_cxled, +struct cxl_dax_region **out_cxlr_dax, +struct range *out_ext_range) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct cxl_endpoint_decoder *cxled; +struct cxl_region *cxlr; +struct range ext_range = (struct range ) { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; +struct range ed_range; + + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled); +if (!cxlr) +return -ENXIO ; + + ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; +if (!range_contains (&ed_range, &ext_range)) { + dev_err_ratelimited(&cxled->cxld.dev, + "DC extent DPA %pra (%pU) is not fully in ED %pra\n",
Quoted 9 lines
drivers/cxl/core/extent.c line 108
Quoted 6 lines
drivers/cxl/core/extent.c new file +6
-0+ &ext_range, extent->uuid, &ed_range); +return -ENXIO ; + } + + *out_cxled = cxled; + *out_cxlr_dax = cxlr->cxlr_dax;Should there be check for cxled and
cxlr->cxlr_daxto make sure they aren't NULL?
yes for cxlr->cxlr_dax. cxled should be fine because cxl_dpa_to_region returns a non-null cxled when a non-null cxlr is returned. So null check for cxled is encapsulated with null check for cxlr
Quoted 134 lines
Quoted 134 lines
drivers/cxl/core/extent.c new file +134
-0+ *out_ext_range = ext_range; +return 0 ; +} + +enum cxl_extent_class { +CXL_EXT_NEW , +CXL_EXT_DUPLICATE , +CXL_EXT_OVERLAP , +}; + +/* +* Stage 2: classify @ext_range against extents already accepted on this +* cxlr_dax+cxled. Walks cxlr_dax->dc_extents once: a stored extent that +* fully contains @ext_range means a duplicate accept (idempotent, fine); +* a stored extent that only overlaps means an inconsistent offer. +*/ +static enum cxl_extent_class +cxlr_dax_classify_extent (struct cxl_dax_region *cxlr_dax, +struct cxl_endpoint_decoder *cxled, +const struct range *ext_range) +{ +struct dc_extent *entry; +unsigned long i; + +xa_for_each (&cxlr_dax->dc_extents, i, entry) { +if (entry->cxled != cxled) +continue ; +if (range_contains (&entry->dpa_range, ext_range)) +return CXL_EXT_DUPLICATE ; +if (range_overlaps (&entry->dpa_range, ext_range)) +return CXL_EXT_OVERLAP ; + } +return CXL_EXT_NEW ; +} + +/* +* Stage 3: allocate and populate a dc_extent for an already-validated, +* already-classified-as-new @ext_range. Only -ENOMEM can fail here. +*/ +static struct dc_extent * +dc_extent_build (struct cxl_endpoint_decoder *cxled, +struct cxl_dax_region *cxlr_dax, +struct cxl_extent *extent, +const struct range *ext_range,u16 seq_num) +{ +resource_size_t dpa_offset = ext_range->start - cxled->dpa_res->start; +resource_size_t hpa = cxled->cxld.hpa_range.start + dpa_offset; +struct dc_extent *dc_extent; + + dc_extent =kzalloc (sizeof (*dc_extent),GFP_KERNEL ); +if (!dc_extent) +return ERR_PTR (-ENOMEM ); + + dc_extent->cxled = cxled; + dc_extent->dpa_range = *ext_range; + dc_extent->hpa_range.start = hpa - cxlr_dax->hpa_range.start; + dc_extent->hpa_range.end = dc_extent->hpa_range.start + +range_len (ext_range) -1 ; + dc_extent->seq_num = seq_num; +import_uuid (&dc_extent->uuid, extent->uuid); +return dc_extent; +} + +/* +* Stage 4: insert @dc_extent into the pending tag group. All extents in +* one More-chain group share a UUID — enforced here as the group is +* either being created (first extent) or appended to. On any failure +* the dc_extent is freed. +*/ +static int cxlr_add_extent (struct cxl_memdev_state *mds, +struct cxl_dax_region *cxlr_dax, +struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group **group = &mds->add_ctx.group; +int rc; + +if (*group && !uuid_equal (&(*group)->uuid, &dc_extent->uuid)) { +kfree (dc_extent); +return -EINVAL ; + } + +if (!*group) { +dev_dbg (&cxlr_dax->dev,"Alloc new tag group\n" ); + *group =alloc_tag_group (cxlr_dax, &dc_extent->uuid); +if (IS_ERR (*group)) { + rc =PTR_ERR (*group); + *group =NULL ; +kfree (dc_extent); +return rc; + } + }else { +dev_dbg (&cxlr_dax->dev,"Append dc_extent to tag group\n" ); + } + + dc_extent->group = *group; + +/* +* Key by @seq_num so iteration order equals assembly order, in both +* the sharable case (device-stamped 1..n) and the non-sharable case +* (host-assigned arrival-order 1..n). A collision here signals a +* cxl-side validation gap. +*/ + rc =xa_insert (&(*group)->dc_extents, dc_extent->seq_num, + dc_extent,GFP_KERNEL ); +if (rc) { +dev_WARN_ONCE (&cxlr_dax->dev, rc == -EBUSY , +"duplicate seq_num %u in tag %pUb\n" , + dc_extent->seq_num, &dc_extent->uuid); +kfree (dc_extent); +return rc; + } + +return 0 ; +} + +int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent, +u16 seq_num) +{ +struct cxl_endpoint_decoder *cxled; +struct cxl_dax_region *cxlr_dax; +struct dc_extent *dc_extent; +struct range ext_range; +int rc; + +guard (rwsem_read)(&cxl_rwsem.region); + + rc =cxl_validate_extent (mds, extent, &cxled, &cxlr_dax, &ext_range); +if (rc) +return rc; + +switch (cxlr_dax_classify_extent (cxlr_dax, cxled, &ext_range)) { +case CXL_EXT_DUPLICATE : +/* +* Idempotent accept simplifies the dax-side scan for existing
Quoted 9 lines
drivers/cxl/core/extent.c line 248
Quoted 6 lines
drivers/cxl/core/extent.c new file +6
-0+* extents on region creation; reply success without duplicating. +*/ +dev_warn_ratelimited (&cxled->cxld.dev, +"Extent %pra exists; accept again\n" , + &ext_range); +return 0 ;Does this cause issues with the accounting in
cxl_add_pending()? At the end thetotal_acceptedwould include duplicates as well. I wonder if modifycxlr_add_extent()to return 1 if an extent is added and handle the returns approriately would make the accounting more accurate.
ur right. Modified cxlr_add_extent to return 1 on success
Quoted 64 lines
Quoted 64 lines
drivers/cxl/core/extent.c new file +64
-0+case CXL_EXT_OVERLAP : +return -ENXIO ; +case CXL_EXT_NEW : +break ; + } + + dc_extent =dc_extent_build (cxled, cxlr_dax, extent, &ext_range, + seq_num); +if (IS_ERR (dc_extent)) +return PTR_ERR (dc_extent); + +dev_dbg (&cxled->cxld.dev,"Add extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); + +return cxlr_add_extent (mds, cxlr_dax, dc_extent); +} + +static void dc_extent_unregister (void *ext) +{ +struct dc_extent *dc_extent = ext; + +dev_dbg (&dc_extent->dev,"DAX region rm extent HPA %pra\n" , + &dc_extent->hpa_range); +device_unregister (&dc_extent->dev); +} + +static void cleanup_pending_dc_extent (struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +int online_tag_group (struct cxl_dc_tag_group *group) +{ +struct cxl_dax_region *cxlr_dax = group->cxlr_dax; +struct dc_extent *dc_extent; +unsigned long index; +int rc =0 ; + +/* +* Seed nr_extents with the full group size plus a +1 pin held by +* this function. The size counts every dc_extent that might +* decrement nr_extents on cleanup; the pin keeps @group alive +* across the body even if every dc_extent release fires inside +* the loop (e.g. devm_add_action_or_reset failure on the only +* pending extent). The pin is dropped at the end of the function. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) + group->nr_extents++; + group->nr_extents++; + +xa_for_each (&group->dc_extents, index, dc_extent) { +struct device *dev = &dc_extent->dev; +u32 id; + +device_initialize (dev); +device_set_pm_not_required (dev); + dev->parent = &cxlr_dax->dev;
Quoted 9 lines
drivers/cxl/core/extent.c line 318
Quoted 6 lines
drivers/cxl/core/extent.c new file +6
-0+ dev->type = &dc_extent_type; + + rc =xa_alloc (&cxlr_dax->dc_extents, &id, dc_extent, + xa_limit_32b,GFP_KERNEL ); +if (rc <0 ) { +put_device (dev);Here
xa_alloc()fails, so there no valid id. But theput_device()will triggerdc_extent_release(). And thereforedev->idof 0 is passed in and potentially erase the id 0 slot even if that's not the intended id. Can always define xarray withXA_FLAGS_ALLOC1to start it at 1 and therefore slot 0 is not used.
good catch, thanks! Used the XA_FLAGS_ALLOC1 flag during xa_init_flags
Quoted 150 lines
Quoted 150 lines
drivers/cxl/core/extent.c new file +54
-0+break ; + } + dev->id = id; + + rc =dev_set_name (dev,"extent%d.%d" , cxlr_dax->cxlr->id, + dev->id); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + + rc =device_add (dev); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + +dev_dbg (dev,"dc_extent HPA %pra (%pU)\n" , + &dc_extent->hpa_range, &group->uuid); + + rc =devm_add_action_or_reset (&cxlr_dax->dev, + dc_extent_unregister, dc_extent); +if (rc) +break ; + } + +if (rc) { +/* +* Unwind every remaining dc_extent in the group. The pin +* above keeps @group alive across this walk. Distinguish +* onlined dc_extents (have a devm action) from pending ones +* via devm_remove_action_nowarn(): a 0 return means the +* action was installed and is now consumed, so we run the +* unregister ourselves; -ENOENT means pending. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) { +int r =devm_remove_action_nowarn (&cxlr_dax->dev, + dc_extent_unregister, + dc_extent); +if (r ==0 ) +dc_extent_unregister (dc_extent); +else +cleanup_pending_dc_extent (dc_extent); + } + } + +/* Drop the pin; if nothing else still references @group, free it. */ + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +return rc; +}drivers/cxl/core/mbox.c +67
-5@@ -6,6 +6,7 @@#include <linux/mutex.h> #include <linux/unaligned.h> #include <linux/list.h> +#include <linux/list_sort.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1181,7 +1182,7 @@ static void delete_extent_node(struct cxl_extent_list_node *node)kfree (node); } -static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) {struct device *dev = mds->cxlds.dev;struct cxl_extent_list_node *node;@@ -1280,11 +1281,120 @@ static int add_to_pending_list(struct list_head *pending_list, }/* -* Stub: stage extents on the pending list and reply with an empty -* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces -* the no-op tail with the real Add pipeline that surfaces a dax -* device per accepted extent. +* Compare two extents by shared_extn_seq (ascending). list_sort is +* stable so when shared_extn_seq is 0 for every entry (non-sharable +* partition) ties fall back to arrival order via list_add_tail() in +* add_to_pending_list(). */ +static int extent_seq_compare (void *priv, +const struct list_head *a, +const struct list_head *b) +{ +const struct cxl_extent_list_node *ea = + list_entry(a, struct cxl_extent_list_node, list); +const struct cxl_extent_list_node *eb = + list_entry(b, struct cxl_extent_list_node, list); +u16 sa =le16_to_cpu (ea->extent->shared_extn_seq); +u16 sb =le16_to_cpu (eb->extent->shared_extn_seq); + +if (sa < sb) +return -1 ; +if (sa > sb) +return 1 ; +return 0 ; +} + +/* +* Move every pending extent whose tag matches @tag onto @group, preserving +* the order they appear in @pending. +*/ +static void extract_tag_group (struct list_head *pending, +const uuid_t *tag, +struct list_head *group) +{ +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, pending, list) { +uuid_t t; + +import_uuid (&t, pos->extent->uuid); +if (uuid_equal (&t, tag)) +list_move_tail (&pos->list, group); + } +} + +/* +* Drive the pending Add-Capacity records through cxl_add_extent(), +* grouped by tag. Per group: extract from pending, stable-sort by +* shared_extn_seq, then attempt to add each extent. Online the tag +* group via online_tag_group() once all of its extents have been +* realized. Validation gates layer onto this loop in later commits. +*/ +static int cxl_add_pending (struct cxl_memdev_state *mds) +{ +struct device *dev = mds->cxlds.dev; +struct list_head *pending = &mds->add_ctx.pending_extents; +struct cxl_extent_list_node *pos, *tmp; +LIST_HEAD (accepted); +int total_accepted =0 ; + +while (!list_empty (pending)) { +LIST_HEAD (group); +struct cxl_dc_tag_group *tag_group; +int group_cnt =0 ; +uuid_t tag; +int rc; + + import_uuid(&tag, + list_first_entry(pending,
Quoted 9 lines
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1355
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+ struct cxl_extent_list_node, + list)->extent->uuid); +extract_tag_group (pending, &tag, &group); +list_sort (NULL , &group, extent_seq_compare); + +u16 logical_seq =1 ;declaring var in middle of code
Moved up to top of function
Quoted 15 lines
Quoted 15 lines
drivers/cxl/core/mbox.c +15
-0+list_for_each_entry_safe (pos, tmp, &group, list) { +u16 raw =le16_to_cpu (pos->extent->shared_extn_seq); +u16 seq = raw ? raw : logical_seq; + + logical_seq++; + +if (cxl_add_extent (mds, pos->extent, seq)) { +dev_dbg (dev, +"Tag %pUb: failed to add extent DPA:%#llx LEN:%#llx\n" , + &tag, +le64_to_cpu (pos->extent->start_dpa), +le64_to_cpu (pos->extent->length)); +delete_extent_node (pos); +continue ; + }
Quoted 9 lines
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1376
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+ group_cnt++; + } + + tag_group = mds->add_ctx.group; +if (!tag_group) +continue ;Does it need to add
delete_extent_node()for the group before continue?
Yes, fixed!
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 128 lines
Quoted 127 lines
drivers/cxl/core/mbox.c +22
-2+ + rc =online_tag_group (tag_group); +if (rc) { +dev_warn (dev, +"Tag %pUb: failed to online tag group (%d)\n" , + &tag, rc); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); + }else { +list_splice_tail_init (&group, &accepted); + total_accepted += group_cnt; + } + + mds->add_ctx.group =NULL ; + } + +list_splice (&accepted, pending); +return cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + pending, total_accepted); +} +static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) {@@ -1316,8 +1426,7 @@ static int handle_add_event(struct cxl_memdev_state *mds, ctx->armed = false;cancel_delayed_work (&ctx->timeout_work); - rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , - &mds->add_ctx.pending_extents,0 ); + rc =cxl_add_pending (mds);clear_pending_extents (mds);return rc; }drivers/cxl/core/region_dax.c +3
-0@@ -13,6 +13,7 @@ static void cxl_dax_region_release(struct device *dev) {struct cxl_dax_region *cxlr_dax =to_cxl_dax_region (dev); +xa_destroy (&cxlr_dax->dc_extents);kfree (cxlr_dax); }@@ -57,11 +58,13 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr)if (!cxlr_dax)return ERR_PTR (-ENOMEM ); +xa_init_flags (&cxlr_dax->dc_extents,XA_FLAGS_ALLOC ); cxlr_dax->hpa_range.start = p->res->start; cxlr_dax->hpa_range.end = p->res->end; dev = &cxlr_dax->dev; cxlr_dax->cxlr = cxlr; + cxlr->cxlr_dax = cxlr_dax;device_initialize (dev);lockdep_set_class (&dev->mutex, &cxl_dax_region_key);device_set_pm_not_required (dev);drivers/cxl/cxl.h +19
-0@@ -495,6 +495,7 @@ struct cxl_region_params {* @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown * @cxlr_pmem: (for pmem regions) cached copy of the nvdimm bridge +* @cxlr_dax: (for DC regions) cached copy of CXL DAX bridge * @flags: Region state flags * @params: active + config params for the region * @coord: QoS access coordinates for the region @@ -510,6 +511,7 @@ struct cxl_region {enum cxl_decoder_type type;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_pmem_region *cxlr_pmem; +struct cxl_dax_region *cxlr_dax;unsigned long flags;struct cxl_region_params params;struct access_coordinate coord[ACCESS_COORDINATE_MAX ];@@ -568,6 +570,15 @@ struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; +/* +* dc_extents is keyed by an allocator-assigned u32 (see +* online_tag_group()). Tag groups have no first-class identity in +* this xarray; siblings within a tag find each other via +* dc_extent->group. Tag-uniqueness lookup is a linear xa_for_each +* walk, adequate at the bounded per-region extent counts the +* driver handles. +*/ +struct xarray dc_extents; };/** @@ -595,6 +606,14 @@ struct cxl_dc_tag_group {unsigned int nr_extents; }; +bool is_dc_extent (struct device *dev); +static inline struct dc_extent *to_dc_extent (struct device *dev) +{ +if (!is_dc_extent (dev)) +return NULL ; + return container_of(dev, struct dc_extent, dev); +} +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory tools/testing/cxl/Kbuild +4
-1@@ -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
Re: [PATCH v10 14/31] cxl/extent: Handle DC Add Capacity events
In reply to Anisa SuQuoted 346 lines · Anisa Su
Replace the empty-response stub in
handle_add_event()with the real add pipeline.DC Event Records can be grouped together with the 'More' flag. The previous commit completed the set up for holding onto extents in the pending list until receiving the last event record of the group, marked by 'More'=0.
This commit fills in the logic for processing the pending list and adds basic validation for extents before they are added to the device model as a child of the
cxlr_daxregion. More complete checks for tags/sequence numbers/alignment is added in subsequent commits.For each tag that appears in the pending list:
1. Extract all extents in the pending list with that tag to a local list.2. The spec requires that shareable extents are ordered by shared extent sequence number, which "instructs each host on the relative order these extents must be placed in adjacent virtual address space" (r4.0 Section 9.13.3 Figure 9-23 Shared Extent List Example). Otherwise, retain arrival order.
Thus the tag group is stable-sorted by
shared_extn_seq; for non-sharable extents every key is 0 and the stable sort preserves arrival order.Individual extents are checked for the following:
1. The extent's DPA range fully resolves to an endpoint decoder.2. Doesn't overlap with a previously accepted extent.
3. Sequence number doesn't collide with others in the same tag group
Upon passing these checks, extents are "onlined" together as a tag group:
online_tag_group()registers a struct device perdc_extentundercxlr_dax->devso the dax layer can discover them viadevice_for_each_child().Once the pending list has been fully processed, send the
DC_ADD_RESPONSE.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit fills in the Add path on top of the previous commit's stubs. Further validation lands in subsequent commits.]--- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 13 ++ drivers/cxl/core/extent.c | 372 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 123 ++++++++++- drivers/cxl/core/region_dax.c | 3 + drivers/cxl/cxl.h | 19 ++ tools/testing/cxl/Kbuild | 5 +- 7 files changed, 528 insertions(+), 9 deletions(-) create mode 100644 drivers/cxl/core/extent.cdrivers/cxl/core/Makefile +1
-1@@ -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.odrivers/cxl/core/core.h +13
-0@@ -65,12 +65,24 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,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, +u16 seq_num); +int online_tag_group (struct cxl_dc_tag_group *group);#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,u16 seq_num) +{ +return 0 ; +} +static inline int online_tag_group (struct cxl_dc_tag_group *group) +{ +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 +178,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 +224
-0@@ -0,0 +1,372 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2024 Intel Corporation. All rights reserved. */ + +#include <linux/device.h> +#include <cxl.h> + +#include "core.h" + + +static void cxled_release_extent (struct cxl_endpoint_decoder *cxled, +struct dc_extent *dc_extent) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = &cxled->cxld.dev; + +dev_dbg (dev,"Remove extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); +memdev_release_extent (mds, &dc_extent->dpa_range); +} + +static void free_tag_group (struct cxl_dc_tag_group *group) +{ +xa_destroy (&group->dc_extents); +kfree (group); +} + +static void dc_extent_release (struct device *dev) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); +struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->cxlr_dax->dc_extents, dc_extent->dev.id); +xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +static const struct device_type dc_extent_type = { + .name ="extent" , + .release = dc_extent_release, +}; + +bool is_dc_extent (struct device *dev) +{ +return dev->type == &dc_extent_type; +} +EXPORT_SYMBOL_NS_GPL (is_dc_extent,"CXL" ); + +static struct cxl_dc_tag_group * +alloc_tag_group (struct cxl_dax_region *cxlr_dax,uuid_t *uuid) +{ + struct cxl_dc_tag_group *group __free(kfree) = +kzalloc (sizeof (*group),GFP_KERNEL ); +if (!group) +return ERR_PTR (-ENOMEM ); + + group->cxlr_dax = cxlr_dax; +uuid_copy (&group->uuid, uuid); +xa_init (&group->dc_extents); +return no_free_ptr (group); +} + +/* +* Stage 1 of the add pipeline: pure, no allocation. Resolve the extent +* to its region/endpoint decoder and ext_range, and verify the range +* fits in the resolved endpoint decoder's DPA resource. Further +* per-extent invariants layer into this function in subsequent commits. +* +* Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). +* On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the +* resolved handles consumed by the rest of the pipeline. +*/ +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct cxl_endpoint_decoder **out_cxled, +struct cxl_dax_region **out_cxlr_dax, +struct range *out_ext_range) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct cxl_endpoint_decoder *cxled; +struct cxl_region *cxlr; +struct range ext_range = (struct range ) { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; +struct range ed_range; + + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled); +if (!cxlr) +return -ENXIO ; + + ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; +if (!range_contains (&ed_range, &ext_range)) { +dev_err_ratelimited (&cxled->cxld.dev, +"DC extent DPA %pra (%pU) is not fully in ED %pra\n" , + &ext_range, extent->uuid, &ed_range); +return -ENXIO ; + } + + *out_cxled = cxled; + *out_cxlr_dax = cxlr->cxlr_dax; + *out_ext_range = ext_range; +return 0 ; +} + +enum cxl_extent_class { +CXL_EXT_NEW , +CXL_EXT_DUPLICATE , +CXL_EXT_OVERLAP , +}; + +/* +* Stage 2: classify @ext_range against extents already accepted on this +* cxlr_dax+cxled. Walks cxlr_dax->dc_extents once: a stored extent that +* fully contains @ext_range means a duplicate accept (idempotent, fine); +* a stored extent that only overlaps means an inconsistent offer. +*/ +static enum cxl_extent_class +cxlr_dax_classify_extent (struct cxl_dax_region *cxlr_dax, +struct cxl_endpoint_decoder *cxled, +const struct range *ext_range) +{ +struct dc_extent *entry; +unsigned long i; + +xa_for_each (&cxlr_dax->dc_extents, i, entry) { +if (entry->cxled != cxled) +continue ; +if (range_contains (&entry->dpa_range, ext_range)) +return CXL_EXT_DUPLICATE ; +if (range_overlaps (&entry->dpa_range, ext_range)) +return CXL_EXT_OVERLAP ; + } +return CXL_EXT_NEW ; +} + +/* +* Stage 3: allocate and populate a dc_extent for an already-validated, +* already-classified-as-new @ext_range. Only -ENOMEM can fail here. +*/ +static struct dc_extent * +dc_extent_build (struct cxl_endpoint_decoder *cxled, +struct cxl_dax_region *cxlr_dax, +struct cxl_extent *extent, +const struct range *ext_range,u16 seq_num) +{ +resource_size_t dpa_offset = ext_range->start - cxled->dpa_res->start; +resource_size_t hpa = cxled->cxld.hpa_range.start + dpa_offset; +struct dc_extent *dc_extent; + + dc_extent =kzalloc (sizeof (*dc_extent),GFP_KERNEL ); +if (!dc_extent) +return ERR_PTR (-ENOMEM ); + + dc_extent->cxled = cxled; + dc_extent->dpa_range = *ext_range; + dc_extent->hpa_range.start = hpa - cxlr_dax->hpa_range.start; + dc_extent->hpa_range.end = dc_extent->hpa_range.start + +range_len (ext_range) -1 ; + dc_extent->seq_num = seq_num; +import_uuid (&dc_extent->uuid, extent->uuid); +return dc_extent; +} + +/* +* Stage 4: insert @dc_extent into the pending tag group. All extents in +* one More-chain group share a UUID — enforced here as the group is +* either being created (first extent) or appended to. On any failure +* the dc_extent is freed. +*/ +static int cxlr_add_extent (struct cxl_memdev_state *mds, +struct cxl_dax_region *cxlr_dax, +struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group **group = &mds->add_ctx.group; +int rc; + +if (*group && !uuid_equal (&(*group)->uuid, &dc_extent->uuid)) { +kfree (dc_extent); +return -EINVAL ; + } + +if (!*group) { +dev_dbg (&cxlr_dax->dev,"Alloc new tag group\n" ); + *group =alloc_tag_group (cxlr_dax, &dc_extent->uuid); +if (IS_ERR (*group)) { + rc =PTR_ERR (*group); + *group =NULL ; +kfree (dc_extent); +return rc; + } + }else { +dev_dbg (&cxlr_dax->dev,"Append dc_extent to tag group\n" ); + } + + dc_extent->group = *group; + +/* +* Key by @seq_num so iteration order equals assembly order, in both +* the sharable case (device-stamped 1..n) and the non-sharable case +* (host-assigned arrival-order 1..n). A collision here signals a +* cxl-side validation gap. +*/ + rc =xa_insert (&(*group)->dc_extents, dc_extent->seq_num, + dc_extent,GFP_KERNEL ); +if (rc) { +dev_WARN_ONCE (&cxlr_dax->dev, rc == -EBUSY , +"duplicate seq_num %u in tag %pUb\n" , + dc_extent->seq_num, &dc_extent->uuid); +kfree (dc_extent); +return rc; + } + +return 0 ; +} + +int cxl_add_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent,
drivers/cxl/core/extent.c line 234
Quoted 10 lines
drivers/cxl/core/extent.c new file +10
-0+ u16 seq_num) +{ +struct cxl_endpoint_decoder *cxled; +struct cxl_dax_region *cxlr_dax; +struct dc_extent *dc_extent; +struct range ext_range; +int rc; + +guard (rwsem_read)(&cxl_rwsem.region); +
From Sashiko: https://sashiko.dev/#/patchset/cover.1779528761.git.anisa.su%40samsung.com?part=14
read lock is released when this function returns. cxl_validate_extent() returns pointer to cxlr_dax through the return param. Other functions dereference the pointer later, which could result in use-after-free if cxlr_dax is concurrently unbound and destroyed.
Fix: Pin cxlr_dax by refcount. On success in alloc_tag_group():get_device(&cxlr_dax->dev);
Then in free_tag_group():put_device(&group->cxlr_dax->dev);
- Anisa
Quoted 390 lines
drivers/cxl/core/extent.c new file +138
-0+ rc =cxl_validate_extent (mds, extent, &cxled, &cxlr_dax, &ext_range); +if (rc) +return rc; + +switch (cxlr_dax_classify_extent (cxlr_dax, cxled, &ext_range)) { +case CXL_EXT_DUPLICATE : +/* +* Idempotent accept simplifies the dax-side scan for existing +* extents on region creation; reply success without duplicating. +*/ +dev_warn_ratelimited (&cxled->cxld.dev, +"Extent %pra exists; accept again\n" , + &ext_range); +return 0 ; +case CXL_EXT_OVERLAP : +return -ENXIO ; +case CXL_EXT_NEW : +break ; + } + + dc_extent =dc_extent_build (cxled, cxlr_dax, extent, &ext_range, + seq_num); +if (IS_ERR (dc_extent)) +return PTR_ERR (dc_extent); + +dev_dbg (&cxled->cxld.dev,"Add extent %pra (%pU)\n" , + &dc_extent->dpa_range, &dc_extent->uuid); + +return cxlr_add_extent (mds, cxlr_dax, dc_extent); +} + +static void dc_extent_unregister (void *ext) +{ +struct dc_extent *dc_extent = ext; + +dev_dbg (&dc_extent->dev,"DAX region rm extent HPA %pra\n" , + &dc_extent->hpa_range); +device_unregister (&dc_extent->dev); +} + +static void cleanup_pending_dc_extent (struct dc_extent *dc_extent) +{ +struct cxl_dc_tag_group *group = dc_extent->group; + +cxled_release_extent (dc_extent->cxled, dc_extent); +xa_erase (&group->dc_extents, dc_extent->seq_num); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +kfree (dc_extent); +} + +int online_tag_group (struct cxl_dc_tag_group *group) +{ +struct cxl_dax_region *cxlr_dax = group->cxlr_dax; +struct dc_extent *dc_extent; +unsigned long index; +int rc =0 ; + +/* +* Seed nr_extents with the full group size plus a +1 pin held by +* this function. The size counts every dc_extent that might +* decrement nr_extents on cleanup; the pin keeps @group alive +* across the body even if every dc_extent release fires inside +* the loop (e.g. devm_add_action_or_reset failure on the only +* pending extent). The pin is dropped at the end of the function. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) + group->nr_extents++; + group->nr_extents++; + +xa_for_each (&group->dc_extents, index, dc_extent) { +struct device *dev = &dc_extent->dev; +u32 id; + +device_initialize (dev); +device_set_pm_not_required (dev); + dev->parent = &cxlr_dax->dev; + dev->type = &dc_extent_type; + + rc =xa_alloc (&cxlr_dax->dc_extents, &id, dc_extent, + xa_limit_32b,GFP_KERNEL ); +if (rc <0 ) { +put_device (dev); +break ; + } + dev->id = id; + + rc =dev_set_name (dev,"extent%d.%d" , cxlr_dax->cxlr->id, + dev->id); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + + rc =device_add (dev); +if (rc) { +xa_erase (&cxlr_dax->dc_extents, dev->id); +put_device (dev); +break ; + } + +dev_dbg (dev,"dc_extent HPA %pra (%pU)\n" , + &dc_extent->hpa_range, &group->uuid); + + rc =devm_add_action_or_reset (&cxlr_dax->dev, + dc_extent_unregister, dc_extent); +if (rc) +break ; + } + +if (rc) { +/* +* Unwind every remaining dc_extent in the group. The pin +* above keeps @group alive across this walk. Distinguish +* onlined dc_extents (have a devm action) from pending ones +* via devm_remove_action_nowarn(): a 0 return means the +* action was installed and is now consumed, so we run the +* unregister ourselves; -ENOENT means pending. +*/ +xa_for_each (&group->dc_extents, index, dc_extent) { +int r =devm_remove_action_nowarn (&cxlr_dax->dev, + dc_extent_unregister, + dc_extent); +if (r ==0 ) +dc_extent_unregister (dc_extent); +else +cleanup_pending_dc_extent (dc_extent); + } + } + +/* Drop the pin; if nothing else still references @group, free it. */ + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +return rc; +}drivers/cxl/core/mbox.c +116
-7@@ -6,6 +6,7 @@#include <linux/mutex.h> #include <linux/unaligned.h> #include <linux/list.h> +#include <linux/list_sort.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1181,7 +1182,7 @@ static void delete_extent_node(struct cxl_extent_list_node *node)kfree (node); } -static void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) +void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range) {struct device *dev = mds->cxlds.dev;struct cxl_extent_list_node *node;@@ -1280,11 +1281,120 @@ static int add_to_pending_list(struct list_head *pending_list, }/* -* Stub: stage extents on the pending list and reply with an empty -* ADD_DC_RESPONSE on More=0 (refuse all). A later commit replaces -* the no-op tail with the real Add pipeline that surfaces a dax -* device per accepted extent. +* Compare two extents by shared_extn_seq (ascending). list_sort is +* stable so when shared_extn_seq is 0 for every entry (non-sharable +* partition) ties fall back to arrival order via list_add_tail() in +* add_to_pending_list(). */ +static int extent_seq_compare (void *priv, +const struct list_head *a, +const struct list_head *b) +{ +const struct cxl_extent_list_node *ea = + list_entry(a, struct cxl_extent_list_node, list); +const struct cxl_extent_list_node *eb = + list_entry(b, struct cxl_extent_list_node, list); +u16 sa =le16_to_cpu (ea->extent->shared_extn_seq); +u16 sb =le16_to_cpu (eb->extent->shared_extn_seq); + +if (sa < sb) +return -1 ; +if (sa > sb) +return 1 ; +return 0 ; +} + +/* +* Move every pending extent whose tag matches @tag onto @group, preserving +* the order they appear in @pending. +*/ +static void extract_tag_group (struct list_head *pending, +const uuid_t *tag, +struct list_head *group) +{ +struct cxl_extent_list_node *pos, *tmp; + +list_for_each_entry_safe (pos, tmp, pending, list) { +uuid_t t; + +import_uuid (&t, pos->extent->uuid); +if (uuid_equal (&t, tag)) +list_move_tail (&pos->list, group); + } +} + +/* +* Drive the pending Add-Capacity records through cxl_add_extent(), +* grouped by tag. Per group: extract from pending, stable-sort by +* shared_extn_seq, then attempt to add each extent. Online the tag +* group via online_tag_group() once all of its extents have been +* realized. Validation gates layer onto this loop in later commits. +*/ +static int cxl_add_pending (struct cxl_memdev_state *mds) +{ +struct device *dev = mds->cxlds.dev; +struct list_head *pending = &mds->add_ctx.pending_extents; +struct cxl_extent_list_node *pos, *tmp; +LIST_HEAD (accepted); +int total_accepted =0 ; + +while (!list_empty (pending)) { +LIST_HEAD (group); +struct cxl_dc_tag_group *tag_group; +int group_cnt =0 ; +uuid_t tag; +int rc; + +import_uuid (&tag, +list_first_entry (pending, + struct cxl_extent_list_node, + list)->extent->uuid); +extract_tag_group (pending, &tag, &group); +list_sort (NULL , &group, extent_seq_compare); + +u16 logical_seq =1 ; +list_for_each_entry_safe (pos, tmp, &group, list) { +u16 raw =le16_to_cpu (pos->extent->shared_extn_seq); +u16 seq = raw ? raw : logical_seq; + + logical_seq++; + +if (cxl_add_extent (mds, pos->extent, seq)) { +dev_dbg (dev, +"Tag %pUb: failed to add extent DPA:%#llx LEN:%#llx\n" , + &tag, +le64_to_cpu (pos->extent->start_dpa), +le64_to_cpu (pos->extent->length)); +delete_extent_node (pos); +continue ; + } + group_cnt++; + } + + tag_group = mds->add_ctx.group; +if (!tag_group) +continue ; + + rc =online_tag_group (tag_group); +if (rc) { +dev_warn (dev, +"Tag %pUb: failed to online tag group (%d)\n" , + &tag, rc); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); + }else { +list_splice_tail_init (&group, &accepted); + total_accepted += group_cnt; + } + + mds->add_ctx.group =NULL ; + } + +list_splice (&accepted, pending); +return cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , + pending, total_accepted); +} +static int handle_add_event (struct cxl_memdev_state *mds,struct cxl_event_dcd *event) {@@ -1316,8 +1426,7 @@ static int handle_add_event(struct cxl_memdev_state *mds, ctx->armed = false;cancel_delayed_work (&ctx->timeout_work); - rc =cxl_send_dc_response (mds,CXL_MBOX_OP_ADD_DC_RESPONSE , - &mds->add_ctx.pending_extents,0 ); + rc =cxl_add_pending (mds);clear_pending_extents (mds);return rc; }drivers/cxl/core/region_dax.c +3
-0@@ -13,6 +13,7 @@ static void cxl_dax_region_release(struct device *dev) {struct cxl_dax_region *cxlr_dax =to_cxl_dax_region (dev); +xa_destroy (&cxlr_dax->dc_extents);kfree (cxlr_dax); }@@ -57,11 +58,13 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr)if (!cxlr_dax)return ERR_PTR (-ENOMEM ); +xa_init_flags (&cxlr_dax->dc_extents,XA_FLAGS_ALLOC ); cxlr_dax->hpa_range.start = p->res->start; cxlr_dax->hpa_range.end = p->res->end; dev = &cxlr_dax->dev; cxlr_dax->cxlr = cxlr; + cxlr->cxlr_dax = cxlr_dax;device_initialize (dev);lockdep_set_class (&dev->mutex, &cxl_dax_region_key);device_set_pm_not_required (dev);drivers/cxl/cxl.h +19
-0@@ -495,6 +495,7 @@ struct cxl_region_params {* @type: Endpoint decoder target type * @cxl_nvb: nvdimm bridge for coordinating @cxlr_pmem setup / shutdown * @cxlr_pmem: (for pmem regions) cached copy of the nvdimm bridge +* @cxlr_dax: (for DC regions) cached copy of CXL DAX bridge * @flags: Region state flags * @params: active + config params for the region * @coord: QoS access coordinates for the region @@ -510,6 +511,7 @@ struct cxl_region {enum cxl_decoder_type type;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_pmem_region *cxlr_pmem; +struct cxl_dax_region *cxlr_dax;unsigned long flags;struct cxl_region_params params;struct access_coordinate coord[ACCESS_COORDINATE_MAX ];@@ -568,6 +570,15 @@ struct cxl_dax_region {struct device dev;struct cxl_region *cxlr;struct range hpa_range; +/* +* dc_extents is keyed by an allocator-assigned u32 (see +* online_tag_group()). Tag groups have no first-class identity in +* this xarray; siblings within a tag find each other via +* dc_extent->group. Tag-uniqueness lookup is a linear xa_for_each +* walk, adequate at the bounded per-region extent counts the +* driver handles. +*/ +struct xarray dc_extents; };/** @@ -595,6 +606,14 @@ struct cxl_dc_tag_group {unsigned int nr_extents; }; +bool is_dc_extent (struct device *dev); +static inline struct dc_extent *to_dc_extent (struct device *dev) +{ +if (!is_dc_extent (dev)) +return NULL ; + return container_of(dev, struct dc_extent, dev); +} +/** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory tools/testing/cxl/Kbuild +4
-1@@ -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.oSignature · 1 line
2.43.0
PATCH v10 15/31 cxl/mem: Drop misaligned DCD extent groups
In reply to Anisa SuAdd an alignment gate to cxl_add_pending(): every extent in a tag group must have its start_dpa and length aligned to CXL_DCD_EXTENT_ALIGN (SZ_2M, the minimum device-dax mapping granularity on every architecture that enables CXL DCD). A misaligned extent makes the resulting dax device unusable, so drop the whole group rather than accept a partial allocation that would surface a broken dax_resource.
Based on patches by John Groves.
---
Changes:
[anisa: split out as a separate validation step]
--- drivers/cxl/core/mbox.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/cxl/core/mbox.c +39 -0
@@ -7,6 +7,7 @@#include <linux/unaligned.h> #include <linux/list.h> #include <linux/list_sort.h> +#include <linux/sizes.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h>
@@ -1280,6 +1281,24 @@ static int add_to_pending_list(struct list_head *pending_list,return 0 ; } +/* +* Device-dax requires extent boundaries aligned to its mapping granularity. +* Use SZ_2M as a conservative default; a tighter check that queries the +* cxl_dax_region / cxl_endpoint_decoder for its actual alignment would be +* strictly more correct, but SZ_2M is the minimum device-dax supports on +* every architecture that enables CXL DCD today. +*/ +#define CXL_DCD_EXTENT_ALIGN SZ_2M + +static bool cxl_extent_dcd_aligned (const struct cxl_extent *extent) +{ +u64 start =le64_to_cpu (extent->start_dpa); +u64 len =le64_to_cpu (extent->length); + +return IS_ALIGNED (start,CXL_DCD_EXTENT_ALIGN ) && +IS_ALIGNED (len,CXL_DCD_EXTENT_ALIGN ); +} +/* * Compare two extents by shared_extn_seq (ascending). list_sort is * stable so when shared_extn_seq is 0 for every entry (non-sharable
@@ -1352,6 +1371,26 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare); +/* Alignment gate — abort the group if any member fails */ +bool aligned = true; +list_for_each_entry (pos, &group, list) { +if (!cxl_extent_dcd_aligned (pos->extent)) { +dev_warn (dev, +"Tag %pUb: dropping group, extent DPA:%#llx LEN:%#llx not %u-aligned\n" , + &tag, +le64_to_cpu (pos->extent->start_dpa), +le64_to_cpu (pos->extent->length), +CXL_DCD_EXTENT_ALIGN ); + aligned = false; +break ; + } + } +if (!aligned) { +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +u16 logical_seq =1 ;list_for_each_entry_safe (pos, tmp, &group, list) {u16 raw =le16_to_cpu (pos->extent->shared_extn_seq);
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 15/31] cxl/mem: Drop misaligned DCD extent groups
Quoted 34 lines · Anisa Su
Add an alignment gate to
cxl_add_pending(): every extent in a tag group must have itsstart_dpaand length aligned toCXL_DCD_EXTENT_ALIGN(SZ_2M, the minimum device-dax mapping granularity on every architecture that enables CXL DCD). A misaligned extent makes the resulting dax device unusable, so drop the whole group rather than accept a partial allocation that would surface a brokendax_resource.Based on patches by John Groves.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by John Groves <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: split out as a separate validation step]--- drivers/cxl/core/mbox.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)drivers/cxl/core/mbox.c +1
-0@@ -7,6 +7,7 @@#include <linux/unaligned.h> #include <linux/list.h> #include <linux/list_sort.h> +#include <linux/sizes.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1280,6 +1281,24 @@ static int add_to_pending_list(struct list_head *pending_list,return 0 ;
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1291
Quoted 10 lines
drivers/cxl/core/mbox.c +8
-0} +/* +* Device-dax requires extent boundaries aligned to its mapping granularity. +* Use SZ_2M as a conservative default; a tighter check that queries the +* cxl_dax_region / cxl_endpoint_decoder for its actual alignment would be +* strictly more correct, but SZ_2M is the minimum device-dax supports on +* every architecture that enables CXL DCD today. +*/ +#define CXL_DCD_EXTENT_ALIGN SZ_2M
Wonder if this would cause issues in DAX on ARM64 with 64k page size since its PMD size is 512M.
DJ
Quoted 14 lines
drivers/cxl/core/mbox.c +10
-0+ +static bool cxl_extent_dcd_aligned (const struct cxl_extent *extent) +{ +u64 start =le64_to_cpu (extent->start_dpa); +u64 len =le64_to_cpu (extent->length); + +return IS_ALIGNED (start,CXL_DCD_EXTENT_ALIGN ) && +IS_ALIGNED (len,CXL_DCD_EXTENT_ALIGN ); +} +/* * Compare two extents by shared_extn_seq (ascending). list_sort is * stable so when shared_extn_seq is 0 for every entry (non-sharable
drivers/cxl/core/mbox.c static int cxl_add_pending(struct cxl_memdev_state *mds) · line 1375
Quoted 5 lines
drivers/cxl/core/mbox.c +2
-0@@ -1352,6 +1371,26 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare); +/* Alignment gate — abort the group if any member fails */ +bool aligned = true;
declaring var in middle of code
Quoted 9 lines
drivers/cxl/core/mbox.c +9
-0+list_for_each_entry (pos, &group, list) { +if (!cxl_extent_dcd_aligned (pos->extent)) { +dev_warn (dev, +"Tag %pUb: dropping group, extent DPA:%#llx LEN:%#llx not %u-aligned\n" , + &tag, +le64_to_cpu (pos->extent->start_dpa), +le64_to_cpu (pos->extent->length), +CXL_DCD_EXTENT_ALIGN ); + aligned = false;
drivers/cxl/core/mbox.c static int cxl_add_pending(struct cxl_memdev_state *mds) · line 1394
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+break ; + } + } +if (!aligned) { +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +u16 logical_seq =1 ;
Looks like this one came from a previous patch.
Quoted 2 lines
drivers/cxl/core/mbox.c +0
-0list_for_each_entry_safe (pos, tmp, &group, list) {u16 raw =le16_to_cpu (pos->extent->shared_extn_seq);
Re: [PATCH v10 15/31] cxl/mem: Drop misaligned DCD extent groups
Quoted 39 lines · Dave Jiang
Quoted 36 lines · Anisa Su
Add an alignment gate to
cxl_add_pending(): every extent in a tag group must have itsstart_dpaand length aligned toCXL_DCD_EXTENT_ALIGN(SZ_2M, the minimum device-dax mapping granularity on every architecture that enables CXL DCD). A misaligned extent makes the resulting dax device unusable, so drop the whole group rather than accept a partial allocation that would surface a brokendax_resource.Based on patches by John Groves.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by John Groves <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: split out as a separate validation step]--- drivers/cxl/core/mbox.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)drivers/cxl/core/mbox.c +1
-0@@ -7,6 +7,7 @@#include <linux/unaligned.h> #include <linux/list.h> #include <linux/list_sort.h> +#include <linux/sizes.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h> @@ -1280,6 +1281,24 @@ static int add_to_pending_list(struct list_head *pending_list,return 0 ; }
Quoted 11 lines
drivers/cxl/core/mbox.c static int add_to_pending_list(struct list_head *pending_list, · line 1291
Quoted 8 lines
drivers/cxl/core/mbox.c +8
-0+/* +* Device-dax requires extent boundaries aligned to its mapping granularity. +* Use SZ_2M as a conservative default; a tighter check that queries the +* cxl_dax_region / cxl_endpoint_decoder for its actual alignment would be +* strictly more correct, but SZ_2M is the minimum device-dax supports on +* every architecture that enables CXL DCD today. +*/ +#define CXL_DCD_EXTENT_ALIGN SZ_2MWonder if this would cause issues in DAX on ARM64 with 64k page size since its PMD size is 512M.
Changed to use PMD_SIZE
Quoted 18 lines
DJ
Quoted 17 lines
drivers/cxl/core/mbox.c +10
-0+ +static bool cxl_extent_dcd_aligned (const struct cxl_extent *extent) +{ +u64 start =le64_to_cpu (extent->start_dpa); +u64 len =le64_to_cpu (extent->length); + +return IS_ALIGNED (start,CXL_DCD_EXTENT_ALIGN ) && +IS_ALIGNED (len,CXL_DCD_EXTENT_ALIGN ); +} +/* * Compare two extents by shared_extn_seq (ascending). list_sort is * stable so when shared_extn_seq is 0 for every entry (non-sharable @@ -1352,6 +1371,26 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare);
Quoted 5 lines
drivers/cxl/core/mbox.c static int cxl_add_pending(struct cxl_memdev_state *mds) · line 1375
Quoted 2 lines
drivers/cxl/core/mbox.c +2
-0+/* Alignment gate — abort the group if any member fails */ +bool aligned = true;declaring var in middle of code
Moved up
Quoted 13 lines
Quoted 13 lines
drivers/cxl/core/mbox.c +13
-0+list_for_each_entry (pos, &group, list) { +if (!cxl_extent_dcd_aligned (pos->extent)) { +dev_warn (dev, +"Tag %pUb: dropping group, extent DPA:%#llx LEN:%#llx not %u-aligned\n" , + &tag, +le64_to_cpu (pos->extent->start_dpa), +le64_to_cpu (pos->extent->length), +CXL_DCD_EXTENT_ALIGN ); + aligned = false; +break ; + } + } +if (!aligned) {
Quoted 9 lines
drivers/cxl/core/mbox.c static int cxl_add_pending(struct cxl_memdev_state *mds) · line 1394
Quoted 6 lines
drivers/cxl/core/mbox.c +5
-0+list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +u16 logical_seq =1 ;Looks like this one came from a previous patch.
Moved up in prev patch
Thanks,
Anisa
Quoted 4 lines
Quoted 3 lines
drivers/cxl/core/mbox.c +0
-0list_for_each_entry_safe (pos, tmp, &group, list) {u16 raw =le16_to_cpu (pos->extent->shared_extn_seq);
PATCH v10 16/31 cxl/extent: Validate DC extent partition
In reply to Anisa SuExtend cxl_validate_extent() — the per-extent check of the add pipeline to check partition membership.
Resolves an extent's DPA to its containing DC partition. Then based on if the partition is shareable:
- Shareable: tag must be non-null and shared_extn_seq must be non-zero — multiple hosts reading the same allocation rely on the device- stamped 1..n sequence to assemble extents in agreed order.
- Non-sharable: shared_extn_seq must be zero — sequencing is meaningless when only one host consumes the allocation; tag is optional (null UUID permitted).
Any cross-mix is a device firmware bug; reject the extent.
Based on patches by John Groves.
---
Changes:
[anisa: split out as a separate validation step]
--- drivers/cxl/core/core.h | 4 ++ drivers/cxl/core/extent.c | 78 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-)
drivers/cxl/core/core.h +4 -0
@@ -179,6 +179,10 @@ 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); +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range);static inline struct device *port_to_host (struct cxl_port *port) {
drivers/cxl/core/extent.c +75 -3
98 lines not on this page · raw message
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 16/31] cxl/extent: Validate DC extent partition
Quoted 52 lines · Anisa Su
Extend
cxl_validate_extent()— the per-extent check of the add pipeline to check partition membership.Resolves an extent's DPA to its containing DC partition. Then based on if the partition is shareable:
- Shareable: tag must be non-null and
shared_extn_seqmust be non-zero — multiple hosts reading the same allocation rely on the device- stamped 1..n sequence to assemble extents in agreed order.
- Non-sharable:shared_extn_seqmust be zero — sequencing is meaningless when only one host consumes the allocation; tag is optional (null UUID permitted).Any cross-mix is a device firmware bug; reject the extent.
Based on patches by John Groves.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by John Groves <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: split out as a separate validation step]--- drivers/cxl/core/core.h | 4 ++ drivers/cxl/core/extent.c | 78 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-)drivers/cxl/core/core.h +4
-0@@ -179,6 +179,10 @@ 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); +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range);static inline struct device *port_to_host (struct cxl_port *port) {drivers/cxl/core/extent.c +0
-0@@ -63,11 +63,55 @@ alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid)return no_free_ptr (group); }
drivers/cxl/core/extent.c alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid) · line 75
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+/* +* Find the DC (Dynamic Capacity) partition that fully contains @ext_range, +* or NULL if the extent falls outside every DC partition on this memdev. +* The returned pointer is owned by mds->cxlds.part[] and lives for the +* lifetime of the memdev. +*/ +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range)
This can be static, given it's only called in extent.c
Quoted 46 lines
drivers/cxl/core/extent.c +37
-3+{ +struct cxl_dev_state *cxlds = &mds->cxlds; +struct device *dev = mds->cxlds.dev; + +for (int i =0 ; i < cxlds->nr_partitions; i++) { +struct cxl_dpa_partition *part = &cxlds->part[i]; +struct range partition_range = { + .start = part->res.start, + .end = part->res.end, + }; + +if (part->mode !=CXL_PARTMODE_DYNAMIC_RAM_A ) +continue ; + +if (range_contains (&partition_range, ext_range)) { +dev_dbg (dev,"DC extent DPA %pra (DCR:%pra)(%pU)\n" , + ext_range, &partition_range, extent->uuid); +return part; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU) is not in a valid DC partition\n" , + ext_range, extent->uuid); +return NULL ; +} +/* * Stage 1 of the add pipeline: pure, no allocation. Resolve the extent -* to its region/endpoint decoder and ext_range, and verify the range -* fits in the resolved endpoint decoder's DPA resource. Further -* per-extent invariants layer into this function in subsequent commits. +* to its region/endpoint decoder and ext_range, and enforce every +* per-extent invariant the device must satisfy: +* +* - DPA falls inside a Dynamic Capacity partition (cxl_extent_dc_partition). +* - CDAT-sharability rules: +* sharable: tag must be non-null AND shared_extn_seq != 0 +* non-sharable: shared_extn_seq must be 0 (tag is optional) +* Any cross-mixing is a device firmware bug. +* - DPA resolves to an endpoint decoder attached to a region. +* - The extent's range is fully contained in that ED's DPA resource. * * Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). * On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the
drivers/cxl/core/extent.c static int cxl_validate_extent(struct cxl_memdev_state *mds, · line 129
Quoted 5 lines
drivers/cxl/core/extent.c +2
-0@@ -81,6 +125,10 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, {u64 start_dpa =le64_to_cpu (extent->start_dpa);struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct device *dev = mds->cxlds.dev; +uuid_t *uuid = (uuid_t *)extent->uuid;
Consider using import_uuid() instead of direct cast.
Quoted 11 lines
drivers/cxl/core/extent.c +4
-0+u16 seq =le16_to_cpu (extent->shared_extn_seq); +const struct cxl_dpa_partition *part;struct cxl_endpoint_decoder *cxled;struct cxl_region *cxlr;struct range ext_range = (struct range ) {@@ -89,6 +137,30 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, };struct range ed_range; + part =cxl_extent_dc_partition (mds, extent, &ext_range); +if (!part)
drivers/cxl/core/extent.c static int cxl_validate_extent(struct cxl_memdev_state *mds, · line 151
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+return -ENXIO ; + +if (part->perf.shareable) { +if (uuid_is_null (uuid)) { +dev_err_ratelimited (dev, +"DC extent DPA %pra: sharable-partition extent has null tag (firmware bug)\n" , + &ext_range); +return -ENXIO ; + } +if (seq ==0 ) {
I don't think this complies with the spec language. In r4.0 Table 8-230: "For extents describing shareable regions this field shall be within the range of 0 to n-1 where n is the number of extents, with each value appearing only once." So seq == 0 is an acceptable value.
Also, looking at cxl_add_pending() @ line ~1396, does shared seq number '0' holds special meanings? Maybe that needs to change? Also suggest adding comments to point out what's happening there if '0' is special.
DJ
Quoted 15 lines
drivers/cxl/core/extent.c +12
-0+dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): sharable-partition extent missing shared_extn_seq (firmware bug)\n" , + &ext_range, uuid); +return -ENXIO ; + } + }else if (seq !=0 ) { +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): non-sharable partition but shared_extn_seq=%u (firmware bug)\n" , + &ext_range, uuid, seq); +return -ENXIO ; + } + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled);if (!cxlr)return -ENXIO ;
Re: [PATCH v10 16/31] cxl/extent: Validate DC extent partition
Quoted 55 lines · Dave Jiang
Quoted 52 lines · Anisa Su
Extend
cxl_validate_extent()— the per-extent check of the add pipeline to check partition membership.Resolves an extent's DPA to its containing DC partition. Then based on if the partition is shareable:
- Shareable: tag must be non-null and
shared_extn_seqmust be non-zero — multiple hosts reading the same allocation rely on the device- stamped 1..n sequence to assemble extents in agreed order.
- Non-sharable:shared_extn_seqmust be zero — sequencing is meaningless when only one host consumes the allocation; tag is optional (null UUID permitted).Any cross-mix is a device firmware bug; reject the extent.
Based on patches by John Groves.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by John Groves <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: split out as a separate validation step]--- drivers/cxl/core/core.h | 4 ++ drivers/cxl/core/extent.c | 78 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-)drivers/cxl/core/core.h +4
-0@@ -179,6 +179,10 @@ 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); +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range);static inline struct device *port_to_host (struct cxl_port *port) {drivers/cxl/core/extent.c +0
-0@@ -63,11 +63,55 @@ alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid)return no_free_ptr (group); }
Quoted 13 lines
drivers/cxl/core/extent.c alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid) · line 75
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+/* +* Find the DC (Dynamic Capacity) partition that fully contains @ext_range, +* or NULL if the extent falls outside every DC partition on this memdev. +* The returned pointer is owned by mds->cxlds.part[] and lives for the +* lifetime of the memdev. +*/ +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range)This can be static, given it's only called in
extent.c
Fixed. Later called in mbox.c so declared non-static in that commit.
Quoted 45 lines
Quoted 45 lines
drivers/cxl/core/extent.c +37
-3+{ +struct cxl_dev_state *cxlds = &mds->cxlds; +struct device *dev = mds->cxlds.dev; + +for (int i =0 ; i < cxlds->nr_partitions; i++) { +struct cxl_dpa_partition *part = &cxlds->part[i]; +struct range partition_range = { + .start = part->res.start, + .end = part->res.end, + }; + +if (part->mode !=CXL_PARTMODE_DYNAMIC_RAM_A ) +continue ; + +if (range_contains (&partition_range, ext_range)) { +dev_dbg (dev,"DC extent DPA %pra (DCR:%pra)(%pU)\n" , + ext_range, &partition_range, extent->uuid); +return part; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU) is not in a valid DC partition\n" , + ext_range, extent->uuid); +return NULL ; +} +/* * Stage 1 of the add pipeline: pure, no allocation. Resolve the extent -* to its region/endpoint decoder and ext_range, and verify the range -* fits in the resolved endpoint decoder's DPA resource. Further -* per-extent invariants layer into this function in subsequent commits. +* to its region/endpoint decoder and ext_range, and enforce every +* per-extent invariant the device must satisfy: +* +* - DPA falls inside a Dynamic Capacity partition (cxl_extent_dc_partition). +* - CDAT-sharability rules: +* sharable: tag must be non-null AND shared_extn_seq != 0 +* non-sharable: shared_extn_seq must be 0 (tag is optional) +* Any cross-mixing is a device firmware bug. +* - DPA resolves to an endpoint decoder attached to a region. +* - The extent's range is fully contained in that ED's DPA resource. * * Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). * On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the
Quoted 9 lines
drivers/cxl/core/extent.c static int cxl_validate_extent(struct cxl_memdev_state *mds, · line 129
Quoted 6 lines
drivers/cxl/core/extent.c +2
-0@@ -81,6 +125,10 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, {u64 start_dpa =le64_to_cpu (extent->start_dpa);struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct device *dev = mds->cxlds.dev; +uuid_t *uuid = (uuid_t *)extent->uuid;Consider using
import_uuid()instead of direct cast.
Fixed
Quoted 24 lines
Quoted 11 lines
drivers/cxl/core/extent.c +4
-0+u16 seq =le16_to_cpu (extent->shared_extn_seq); +const struct cxl_dpa_partition *part;struct cxl_endpoint_decoder *cxled;struct cxl_region *cxlr;struct range ext_range = (struct range ) {@@ -89,6 +137,30 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, };struct range ed_range; + part =cxl_extent_dc_partition (mds, extent, &ext_range); +if (!part)drivers/cxl/core/extent.c static int cxl_validate_extent(struct cxl_memdev_state *mds, · line 151
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+return -ENXIO ; + +if (part->perf.shareable) { +if (uuid_is_null (uuid)) { +dev_err_ratelimited (dev, +"DC extent DPA %pra: sharable-partition extent has null tag (firmware bug)\n" , + &ext_range); +return -ENXIO ; + } +if (seq ==0 ) {I don't think this complies with the spec language. In r4.0 Table 8-230: "For extents describing shareable regions this field shall be within the range of 0 to n-1 where n is the number of extents, with each value appearing only once." So seq == 0 is an acceptable value.
Quoted 2 lines
Also, looking at
cxl_add_pending()@ line ~1396, does shared seq number '0' holds special meanings? Maybe that needs to change? Also suggest adding comments to point out what's happening there if '0' is special.
Fixed to enforce 0...n-1 for shared seq num instead of 1...n. 0 no longer used as sentinel val for unshared extents.
'Enforce tag-group semantics', which checks seq num have no duplicates/gaps, is also fixed
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 17 lines
Quoted 16 lines
drivers/cxl/core/extent.c +12
-0+dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): sharable-partition extent missing shared_extn_seq (firmware bug)\n" , + &ext_range, uuid); +return -ENXIO ; + } + }else if (seq !=0 ) { +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): non-sharable partition but shared_extn_seq=%u (firmware bug)\n" , + &ext_range, uuid, seq); +return -ENXIO ; + } + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled);if (!cxlr)return -ENXIO ;
Re: [PATCH v10 16/31] cxl/extent: Validate DC extent partition
In reply to Anisa SuQuoted 56 lines · Anisa Su
Extend
cxl_validate_extent()— the per-extent check of the add pipeline to check partition membership.Resolves an extent's DPA to its containing DC partition. Then based on if the partition is shareable:
- Shareable: tag must be non-null and
shared_extn_seqmust be non-zero — multiple hosts reading the same allocation rely on the device- stamped 1..n sequence to assemble extents in agreed order.
- Non-sharable:shared_extn_seqmust be zero — sequencing is meaningless when only one host consumes the allocation; tag is optional (null UUID permitted).Any cross-mix is a device firmware bug; reject the extent.
Based on patches by John Groves.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by John Groves <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: split out as a separate validation step]--- drivers/cxl/core/core.h | 4 ++ drivers/cxl/core/extent.c | 78 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-)drivers/cxl/core/core.h +4
-0@@ -179,6 +179,10 @@ 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); +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range);static inline struct device *port_to_host (struct cxl_port *port) {drivers/cxl/core/extent.c +4
-0@@ -63,11 +63,55 @@ alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid)return no_free_ptr (group); } +/* +* Find the DC (Dynamic Capacity) partition that fully contains @ext_range, +* or NULL if the extent falls outside every DC partition on this memdev. +* The returned pointer is owned by mds->cxlds.part[] and lives for the
drivers/cxl/core/extent.c alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid) · line 79
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+* lifetime of the memdev. +*/ +const struct cxl_dpa_partition * +cxl_extent_dc_partition (struct cxl_memdev_state *mds, +struct cxl_extent *extent, +struct range *ext_range) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +struct device *dev = mds->cxlds.dev; +
From Sashiko: https://sashiko.dev/#/patchset/cover.1779528761.git.anisa.su%40samsung.com?part=16
Sashiko complains about the possibility of end < start in multiple places. Add a check here for that. Should be sufficient to add the check here, since every add-able extent passes through here.
if (ext_range->end < ext_range->start) {
dev_err_ratelimited(dev,
"DC extent DPA %pra (%pU) has invalid length (firmware bug)\n",
ext_range, extent->uuid);
return NULL;
}- Anisa
Quoted 86 lines
drivers/cxl/core/extent.c +61
-3+for (int i =0 ; i < cxlds->nr_partitions; i++) { +struct cxl_dpa_partition *part = &cxlds->part[i]; +struct range partition_range = { + .start = part->res.start, + .end = part->res.end, + }; + +if (part->mode !=CXL_PARTMODE_DYNAMIC_RAM_A ) +continue ; + +if (range_contains (&partition_range, ext_range)) { +dev_dbg (dev,"DC extent DPA %pra (DCR:%pra)(%pU)\n" , + ext_range, &partition_range, extent->uuid); +return part; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU) is not in a valid DC partition\n" , + ext_range, extent->uuid); +return NULL ; +} +/* * Stage 1 of the add pipeline: pure, no allocation. Resolve the extent -* to its region/endpoint decoder and ext_range, and verify the range -* fits in the resolved endpoint decoder's DPA resource. Further -* per-extent invariants layer into this function in subsequent commits. +* to its region/endpoint decoder and ext_range, and enforce every +* per-extent invariant the device must satisfy: +* +* - DPA falls inside a Dynamic Capacity partition (cxl_extent_dc_partition). +* - CDAT-sharability rules: +* sharable: tag must be non-null AND shared_extn_seq != 0 +* non-sharable: shared_extn_seq must be 0 (tag is optional) +* Any cross-mixing is a device firmware bug. +* - DPA resolves to an endpoint decoder attached to a region. +* - The extent's range is fully contained in that ED's DPA resource. * * Caller must hold cxl_rwsem.region for read (cxl_dpa_to_region()). * On success, @out_cxled / @out_cxlr_dax / @out_ext_range carry the @@ -81,6 +125,10 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, {u64 start_dpa =le64_to_cpu (extent->start_dpa);struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct device *dev = mds->cxlds.dev; +uuid_t *uuid = (uuid_t *)extent->uuid; +u16 seq =le16_to_cpu (extent->shared_extn_seq); +const struct cxl_dpa_partition *part;struct cxl_endpoint_decoder *cxled;struct cxl_region *cxlr;struct range ext_range = (struct range ) {@@ -89,6 +137,30 @@ static int cxl_validate_extent(struct cxl_memdev_state *mds, };struct range ed_range; + part =cxl_extent_dc_partition (mds, extent, &ext_range); +if (!part) +return -ENXIO ; + +if (part->perf.shareable) { +if (uuid_is_null (uuid)) { +dev_err_ratelimited (dev, +"DC extent DPA %pra: sharable-partition extent has null tag (firmware bug)\n" , + &ext_range); +return -ENXIO ; + } +if (seq ==0 ) { +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): sharable-partition extent missing shared_extn_seq (firmware bug)\n" , + &ext_range, uuid); +return -ENXIO ; + } + }else if (seq !=0 ) { +dev_err_ratelimited (dev, +"DC extent DPA %pra (%pU): non-sharable partition but shared_extn_seq=%u (firmware bug)\n" , + &ext_range, uuid, seq); +return -ENXIO ; + } + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled);if (!cxlr)return -ENXIO ;Signature · 1 line
2.43.0
PATCH v10 17/31 cxl/mem: Enforce tag-group semantics
In reply to Anisa SuThe previous commit fully-fleshed out validation for individual extents. This commit completes tag-group validation.
Add two group-level gates to cxl_add_pending() that cxl_validate_extent()'s per-extent view can't see:
- Sequence integrity (cxl_check_group_seq): well-formed iff. every member is shared_extn_seq == 0 (non-shareable) or the sorted group is exactly 1..n contiguous (shareable).
- Partition equality (cxl_check_group_partition): tagged allocations cannot span DC partitions; a partition's CDAT DSMAS entry is the unit at which shareable / writable / coherency attributes are described. Skipped for the null UUID.
Each check drops the whole group on violation. Cross-chain uniqueness of a tag lands in a subsequent commit alongside the host-wide tag registry.
Based on patches by John Groves.
---
Changes:
[anisa: split out as a separate validation step. Cross-chain
uniqueness moved to the dedicated "Enforce cross-region tag uniqueness" commit so this one only adds — no add-then-replace.]
--- drivers/cxl/core/mbox.c | 117 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+)
drivers/cxl/core/mbox.c +117 -0
@@ -1342,6 +1342,109 @@ static void extract_tag_group(struct list_head *pending, } } +/* +* Validate shared_extn_seq across a tag group already sorted ascending. +* +* A tag group is well-formed iff either every member has +* shared_extn_seq == 0 (non-sharable allocation) or the sorted group is +* exactly 1, 2, ..., n (sharable). Anything else — mix, gap, duplicate, +* non-zero starting other than 1 — is a device firmware bug. +*/ +static int cxl_check_group_seq (struct device *dev, +const uuid_t *tag, +const struct list_head *group) +{ +struct cxl_extent_list_node *pos; +u16 first, expected; + +if (list_empty (group)) +return 0 ; + + pos = list_first_entry(group, struct cxl_extent_list_node, list); + first =le16_to_cpu (pos->extent->shared_extn_seq); + +if (first ==0 ) { +list_for_each_entry (pos, group, list) { +if (le16_to_cpu (pos->extent->shared_extn_seq) !=0 ) { +dev_warn (dev, +"Tag %pUb: shared_extn_seq mixed 0/non-zero in one allocation (firmware bug)\n" , + tag); +return -EINVAL ; + } + } +return 0 ; + } + +if (first !=1 ) { +dev_warn (dev, +"Tag %pUb: shared_extn_seq starts at %u, expected 1 (firmware bug)\n" , + tag, first); +return -EINVAL ; + } + + expected =1 ; +list_for_each_entry (pos, group, list) { +u16 s =le16_to_cpu (pos->extent->shared_extn_seq); + +if (s != expected) { +dev_warn (dev, +"Tag %pUb: shared_extn_seq gap/dup: expected %u got %u (firmware bug)\n" , + tag, expected, s); +return -EINVAL ; + } + expected++; + } +return 0 ; +} + +/* +* For tagged groups, reject allocations that span DC partitions. A tag +* is an allocation identity; the partition's CDAT DSMAS entry is what +* tells the host which attributes (sharable, writable, coherency) +* apply. Untagged groups are skipped — the spec does not define a +* cross-chain identity for them. +*/ +static int cxl_check_group_partition (struct cxl_memdev_state *mds, +const uuid_t *tag, +const struct list_head *group) +{ +struct device *dev = mds->cxlds.dev; +const struct cxl_dpa_partition *first_part =NULL ; +u64 first_dpa =0 ; +struct cxl_extent_list_node *pos; + +if (uuid_is_null (tag) ||list_empty (group)) +return 0 ; + +list_for_each_entry (pos, group, list) { +struct cxl_extent *extent = pos->extent; +struct range ext_range = (struct range ) { + .start =le64_to_cpu (extent->start_dpa), + .end =le64_to_cpu (extent->start_dpa) + +le64_to_cpu (extent->length) -1 , + }; +const struct cxl_dpa_partition *part; + + part =cxl_extent_dc_partition (mds, extent, &ext_range); +if (!part) +return -ENXIO ; + +if (!first_part) { + first_part = part; + first_dpa = ext_range.start; +continue ; + } + +if (part != first_part) { +dev_warn (dev, +"Tag %pUb: extents span DC partitions (DPA:%#llx and DPA:%#llx), firmware bug\n" , + tag, first_dpa, ext_range.start); +return -EINVAL ; + } + } +return 0 ; +} +/* * Drive the pending Add-Capacity records through cxl_add_extent(), * grouped by tag. Per group: extract from pending, stable-sort by
@@ -1371,6 +1474,20 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare); +/* Sequence-number integrity */ +if (cxl_check_group_seq (dev, &tag, &group)) { +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } + +/* Partition equality (skipped for null UUID) */ +if (cxl_check_group_partition (mds, &tag, &group)) { +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +/* Alignment gate — abort the group if any member fails */ bool aligned = true;list_for_each_entry (pos, &group, list) {
Signature · 1 line
2.43.0
PATCH v10 18/31 cxl/extent: Handle DC Release Capacity events
In reply to Anisa SuReplace the no-op ack stub for cxl_rm_extent() with the real teardown:
resolve the released DPA range to its region and endpoint decoder, locate the matching dc_extent in cxlr_dax->dc_extents (filtering by cxled, range containment, and tag), and tear down the entire containing tag group atomically through rm_tag_group(). Partial release is not supported.
rm_tag_group() invalidates caches once for the whole group (no mappings exist at this point — partial release is not supported, so all members are leaving together), then walks the group's dc_extents and releases each via its devm action installed at online_tag_group() time.
cxl_region_invalidate_memregion() becomes non-static and is declared in core.h so rm_tag_group() can flush caches before tearing the group down.
When the released range maps to no region (host crashed before persisting acceptance, region destruction raced device release, or the device is confused) the host has nothing to drop, so reply via memdev_release_extent() to keep the device's view consistent.
Based on an original patch by Navneet Singh.
---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit replaces the stubbed release with the real walk-and-tear-down of the matching tag group.]
--- drivers/cxl/core/core.h | 8 +++ drivers/cxl/core/extent.c | 101 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 19 ------- drivers/cxl/core/region.c | 2 +- 4 files changed, 110 insertions(+), 20 deletions(-)
drivers/cxl/core/core.h +8 -0
@@ -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,7 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent,u16 seq_num); +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group);#else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,
@@ -79,6 +82,11 @@ static inline int cxl_add_extent(struct cxl_memdev_state *mds, {return 0 ; } +static inline int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +return 0 ; +}static inline int online_tag_group (struct cxl_dc_tag_group *group) {return 0 ;
drivers/cxl/core/extent.c +101 -0
107 lines not on this page · raw message
drivers/cxl/core/mbox.c +0 -19
@@ -1587,25 +1587,6 @@ static int handle_add_event(struct cxl_memdev_state *mds,return rc; } -/* -* Stub: ack the release back to the device so it knows we are not -* using the range. A later commit replaces this with the real -* teardown that walks the region's tag group and tears down the -* member dc_extent devices. -*/ -static int cxl_rm_extent (struct cxl_memdev_state *mds, -struct cxl_extent *extent) -{ -u64 start_dpa =le64_to_cpu (extent->start_dpa); -struct range dpa_range = { - .start = start_dpa, - .end = start_dpa +le64_to_cpu (extent->length) -1 , - }; - -memdev_release_extent (mds, &dpa_range); -return 0 ; -} -static char *cxl_dcd_evt_type_str (u8 type) {switch (type) {
drivers/cxl/core/region.c +1 -1
@@ -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 )) {
Signature · 1 line
2.43.0
Dave Jiang
maintainerRe: [PATCH v10 18/31] cxl/extent: Handle DC Release Capacity events
Quoted 42 lines · Anisa Su
Replace the no-op ack stub for
cxl_rm_extent()with the real teardown:
resolve the released DPA range to its region and endpoint decoder, locate the matchingdc_extentincxlr_dax->dc_extents(filtering by cxled, range containment, and tag), and tear down the entire containing tag group atomically throughrm_tag_group(). Partial release is not supported.
rm_tag_group()invalidates caches once for the whole group (no mappings exist at this point — partial release is not supported, so all members are leaving together), then walks the group'sdc_extentsand releases each via its devm action installed atonline_tag_group()time.
cxl_region_invalidate_memregion()becomes non-static and is declared incore.hsorm_tag_group()can flush caches before tearing the group down.When the released range maps to no region (host crashed before persisting acceptance, region destruction raced device release, or the device is confused) the host has nothing to drop, so reply via
memdev_release_extent()to keep the device's view consistent.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit replaces the stubbed release with the real walk-and-tear-down of the matching tag group.]--- drivers/cxl/core/core.h | 8 +++ drivers/cxl/core/extent.c | 101 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 19 ------- drivers/cxl/core/region.c | 2 +- 4 files changed, 110 insertions(+), 20 deletions(-)drivers/cxl/core/core.h +0
-0
drivers/cxl/core/core.h cxled_to_mds(struct cxl_endpoint_decoder *cxled) · line 31
Quoted 4 lines
drivers/cxl/core/core.h +1
-0@@ -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);
Doesn't this need to go within CONFIG_CXL_REGION?
Quoted 42 lines
drivers/cxl/core/core.h +7
-0+#ifdef CONFIG_CXL_REGION struct cxl_region_context {@@ -67,6 +69,7 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent,u16 seq_num); +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group);#else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,@@ -79,6 +82,11 @@ static inline int cxl_add_extent(struct cxl_memdev_state *mds, {return 0 ; } +static inline int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +return 0 ; +}static inline int online_tag_group (struct cxl_dc_tag_group *group) {return 0 ;drivers/cxl/core/extent.c +10
-0@@ -344,6 +344,107 @@ static void dc_extent_unregister(void *ext)device_unregister (&dc_extent->dev); } +static void rm_tag_group (struct cxl_dc_tag_group *group) +{ +struct device *region_dev = &group->cxlr_dax->dev; +struct dc_extent *dc_extent; +unsigned long index; + +/* +* Tagged allocations release atomically. Invalidate caches once +* for the whole group (no mappings exist at this point — partial +* release is not supported, so all members are leaving use
drivers/cxl/core/extent.c static void dc_extent_unregister(void *ext) · line 366
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+* together) before tearing down each dc_extent device. +* +* Pin @group across the walk: each devm_release_action runs the +* dc_extent_unregister action synchronously, which drops the last +* reference on the dc_extent device and fires dc_extent_release. +* The release decrements group->nr_extents and, on the final +* decrement, frees @group. Without the pin the next iteration's +* xa_find_after() dereferences a freed xarray. +*/ +cxl_region_invalidate_memregion (group->cxlr_dax->cxlr);
check return value?
Quoted 42 lines
drivers/cxl/core/extent.c +42
-0+ + group->nr_extents++; +xa_for_each (&group->dc_extents, index, dc_extent) +devm_release_action (region_dev, dc_extent_unregister, dc_extent); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +} + +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct cxl_endpoint_decoder *cxled; +struct cxl_dax_region *cxlr_dax; +struct cxl_dc_tag_group *group; +struct dc_extent *dc_extent; +struct cxl_region *cxlr; +struct range dpa_range; +unsigned long idx; +uuid_t tag; + + dpa_range = (struct range ) { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; + +guard (rwsem_read)(&cxl_rwsem.region); + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled); +if (!cxlr) { +/* +* No region can happen here for a few reasons: +* +* 1) Extents were accepted and the host crashed/rebooted +* leaving them in an accepted state. On reboot the host +* has not yet created a region to own them. +* +* 2) Region destruction won the race with the device releasing +* all the extents. Here the release will be a duplicate of +* the one sent via region destruction. +* +* 3) The device is confused and releasing extents for which no
drivers/cxl/core/extent.c static void dc_extent_unregister(void *ext) · line 418
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+* region ever existed. +* +* In all these cases make sure the device knows we are not +* using this extent. +*/ +memdev_release_extent (mds, &dpa_range); +return -ENXIO ; + } + + cxlr_dax = cxlr->cxlr_dax;
Does it need to check if cxlr_dax is NULL?
DJ
Quoted 75 lines
drivers/cxl/core/extent.c +29
-0+import_uuid (&tag, extent->uuid); + +/* +* Find the dc_extent whose DPA range covers the released range and +* whose tag matches. The release targets the entire containing +* tag group atomically; partial release is not supported. +*/ + group =NULL ; +xa_for_each (&cxlr_dax->dc_extents, idx, dc_extent) { +if (dc_extent->cxled != cxled) +continue ; +if (!range_contains (&dc_extent->dpa_range, &dpa_range)) +continue ; +if (!uuid_equal (&dc_extent->group->uuid, &tag)) +continue ; + group = dc_extent->group; +break ; + } +if (!group) { +dev_err (&cxlr_dax->dev, +"release DPA %pra (%pU) matches no dc_extent\n" , + &dpa_range, &tag); +return -EINVAL ; + } + +rm_tag_group (group); +return 0 ; +} +static void cleanup_pending_dc_extent (struct dc_extent *dc_extent) {struct cxl_dc_tag_group *group = dc_extent->group;drivers/cxl/core/mbox.c +0
-19@@ -1587,25 +1587,6 @@ static int handle_add_event(struct cxl_memdev_state *mds,return rc; } -/* -* Stub: ack the release back to the device so it knows we are not -* using the range. A later commit replaces this with the real -* teardown that walks the region's tag group and tears down the -* member dc_extent devices. -*/ -static int cxl_rm_extent (struct cxl_memdev_state *mds, -struct cxl_extent *extent) -{ -u64 start_dpa =le64_to_cpu (extent->start_dpa); -struct range dpa_range = { - .start = start_dpa, - .end = start_dpa +le64_to_cpu (extent->length) -1 , - }; - -memdev_release_extent (mds, &dpa_range); -return 0 ; -} -static char *cxl_dcd_evt_type_str (u8 type) {switch (type) {drivers/cxl/core/region.c +1
-1@@ -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 )) {
Re: [PATCH v10 18/31] cxl/extent: Handle DC Release Capacity events
Quoted 48 lines · Dave Jiang
Quoted 45 lines · Anisa Su
Replace the no-op ack stub for
cxl_rm_extent()with the real teardown:
resolve the released DPA range to its region and endpoint decoder, locate the matchingdc_extentincxlr_dax->dc_extents(filtering by cxled, range containment, and tag), and tear down the entire containing tag group atomically throughrm_tag_group(). Partial release is not supported.
rm_tag_group()invalidates caches once for the whole group (no mappings exist at this point — partial release is not supported, so all members are leaving together), then walks the group'sdc_extentsand releases each via its devm action installed atonline_tag_group()time.
cxl_region_invalidate_memregion()becomes non-static and is declared incore.hsorm_tag_group()can flush caches before tearing the group down.When the released range maps to no region (host crashed before persisting acceptance, region destruction raced device release, or the device is confused) the host has nothing to drop, so reply via
memdev_release_extent()to keep the device's view consistent.Based on an original patch by Navneet Singh.
Signed-off-by Ira Weiny <[email protected]>Signed-off-by Anisa Su <[email protected]>---
Changes:
[anisa: restructured from the original "Process dynamic partition
events" monolith; this commit replaces the stubbed release with the real walk-and-tear-down of the matching tag group.]--- drivers/cxl/core/core.h | 8 +++ drivers/cxl/core/extent.c | 101 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 19 ------- drivers/cxl/core/region.c | 2 +- 4 files changed, 110 insertions(+), 20 deletions(-)drivers/cxl/core/core.h +0
-0@@ -28,6 +28,8 @@ cxled_to_mds(struct cxl_endpoint_decoder *cxled) return container_of(cxlds, struct cxl_memdev_state, cxlds); }
Quoted 4 lines
drivers/cxl/core/core.h cxled_to_mds(struct cxl_endpoint_decoder *cxled) · line 31
Quoted 1 line
drivers/cxl/core/core.h +1
-0+int cxl_region_invalidate_memregion (struct cxl_region *cxlr);Doesn't this need to go within
CONFIG_CXL_REGION?
oopsie yes
Quoted 46 lines
Quoted 46 lines
drivers/cxl/core/core.h +7
-0+#ifdef CONFIG_CXL_REGION struct cxl_region_context {@@ -67,6 +69,7 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent,u16 seq_num); +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group);#else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,@@ -79,6 +82,11 @@ static inline int cxl_add_extent(struct cxl_memdev_state *mds, {return 0 ; } +static inline int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +return 0 ; +}static inline int online_tag_group (struct cxl_dc_tag_group *group) {return 0 ;drivers/cxl/core/extent.c +14
-0@@ -344,6 +344,107 @@ static void dc_extent_unregister(void *ext)device_unregister (&dc_extent->dev); } +static void rm_tag_group (struct cxl_dc_tag_group *group) +{ +struct device *region_dev = &group->cxlr_dax->dev; +struct dc_extent *dc_extent; +unsigned long index; + +/* +* Tagged allocations release atomically. Invalidate caches once +* for the whole group (no mappings exist at this point — partial +* release is not supported, so all members are leaving use +* together) before tearing down each dc_extent device. +* +* Pin @group across the walk: each devm_release_action runs the +* dc_extent_unregister action synchronously, which drops the last
Quoted 9 lines
drivers/cxl/core/extent.c static void dc_extent_unregister(void *ext) · line 366
Quoted 6 lines
drivers/cxl/core/extent.c +6
-0+* reference on the dc_extent device and fires dc_extent_release. +* The release decrements group->nr_extents and, on the final +* decrement, frees @group. Without the pin the next iteration's +* xa_find_after() dereferences a freed xarray. +*/ +cxl_region_invalidate_memregion (group->cxlr_dax->cxlr);check return value?
done. if invalidate_memregion fails, doesn't release and device needs to retry
Quoted 46 lines
Quoted 46 lines
drivers/cxl/core/extent.c +46
-0+ + group->nr_extents++; +xa_for_each (&group->dc_extents, index, dc_extent) +devm_release_action (region_dev, dc_extent_unregister, dc_extent); + group->nr_extents--; +if (!group->nr_extents) +free_tag_group (group); +} + +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent) +{ +u64 start_dpa =le64_to_cpu (extent->start_dpa); +struct cxl_memdev *cxlmd = mds->cxlds.cxlmd; +struct cxl_endpoint_decoder *cxled; +struct cxl_dax_region *cxlr_dax; +struct cxl_dc_tag_group *group; +struct dc_extent *dc_extent; +struct cxl_region *cxlr; +struct range dpa_range; +unsigned long idx; +uuid_t tag; + + dpa_range = (struct range ) { + .start = start_dpa, + .end = start_dpa +le64_to_cpu (extent->length) -1 , + }; + +guard (rwsem_read)(&cxl_rwsem.region); + cxlr =cxl_dpa_to_region (cxlmd, start_dpa, &cxled); +if (!cxlr) { +/* +* No region can happen here for a few reasons: +* +* 1) Extents were accepted and the host crashed/rebooted +* leaving them in an accepted state. On reboot the host +* has not yet created a region to own them. +* +* 2) Region destruction won the race with the device releasing +* all the extents. Here the release will be a duplicate of +* the one sent via region destruction. +* +* 3) The device is confused and releasing extents for which no +* region ever existed. +* +* In all these cases make sure the device knows we are not +* using this extent.
Quoted 9 lines
drivers/cxl/core/extent.c static void dc_extent_unregister(void *ext) · line 418
Quoted 6 lines
drivers/cxl/core/extent.c +6
-0+*/ +memdev_release_extent (mds, &dpa_range); +return -ENXIO ; + } + + cxlr_dax = cxlr->cxlr_dax;Does it need to check if
cxlr_daxis NULL?
added check. same behavior as if !cxlr, bc if !cxlr_dax, we're not tracking or using any extents, so safe to reply to device with release
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 76 lines
Quoted 75 lines
drivers/cxl/core/extent.c +29
-0+import_uuid (&tag, extent->uuid); + +/* +* Find the dc_extent whose DPA range covers the released range and +* whose tag matches. The release targets the entire containing +* tag group atomically; partial release is not supported. +*/ + group =NULL ; +xa_for_each (&cxlr_dax->dc_extents, idx, dc_extent) { +if (dc_extent->cxled != cxled) +continue ; +if (!range_contains (&dc_extent->dpa_range, &dpa_range)) +continue ; +if (!uuid_equal (&dc_extent->group->uuid, &tag)) +continue ; + group = dc_extent->group; +break ; + } +if (!group) { +dev_err (&cxlr_dax->dev, +"release DPA %pra (%pU) matches no dc_extent\n" , + &dpa_range, &tag); +return -EINVAL ; + } + +rm_tag_group (group); +return 0 ; +} +static void cleanup_pending_dc_extent (struct dc_extent *dc_extent) {struct cxl_dc_tag_group *group = dc_extent->group;drivers/cxl/core/mbox.c +0
-19@@ -1587,25 +1587,6 @@ static int handle_add_event(struct cxl_memdev_state *mds,return rc; } -/* -* Stub: ack the release back to the device so it knows we are not -* using the range. A later commit replaces this with the real -* teardown that walks the region's tag group and tears down the -* member dc_extent devices. -*/ -static int cxl_rm_extent (struct cxl_memdev_state *mds, -struct cxl_extent *extent) -{ -u64 start_dpa =le64_to_cpu (extent->start_dpa); -struct range dpa_range = { - .start = start_dpa, - .end = start_dpa +le64_to_cpu (extent->length) -1 , - }; - -memdev_release_extent (mds, &dpa_range); -return 0 ; -} -static char *cxl_dcd_evt_type_str (u8 type) {switch (type) {drivers/cxl/core/region.c +1
-1@@ -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 )) {
PATCH v10 19/31 cxl/extent: Enforce cross-region tag uniqueness
In reply to Anisa SuThe per-region scan in cxl_tag_already_committed() only catches a tag re-appearing on the same cxlr_dax. The orchestrator owns tag allocation and is responsible for global uniqueness, but a buggy FM (or firmware redelivering a tag for a previously-closed allocation) can still hand the same uuid to extents on two different regions or memdevs, and the per-region check accepts the second one — leaving two independent cxl_dc_tag_group objects with the same uuid.
Add a host-wide registry of live tag groups with non-null uuids. alloc_tag_group() inserts on success, free_tag_group() removes; both skip the null-uuid case since the spec defines no cross-chain identity for untagged allocations.
An attempt to add a second group with the same uuid fails with -EBUSY.
No exit hook is needed: cxl_core only unloads after every dependent module has, by which point every live tag group has been freed and the registry is empty.
--- drivers/cxl/core/core.h | 5 ++++ drivers/cxl/core/extent.c | 60 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 19 +++++++++++++ drivers/cxl/cxl.h | 3 ++ 4 files changed, 87 insertions(+)
drivers/cxl/core/core.h +5 -0
@@ -69,6 +69,7 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent,u16 seq_num); +bool cxl_tag_already_committed (const uuid_t *tag);int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group);#else
@@ -91,6 +92,10 @@ static inline int online_tag_group(struct cxl_dc_tag_group *group) {return 0 ; } +static inline bool cxl_tag_already_committed (const uuid_t *tag) +{ +return false; +}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 +60 -0
80 lines not on this page · raw message
drivers/cxl/core/mbox.c +19 -0
@@ -1474,6 +1474,25 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare); +/* +* Cross-More-chain uniqueness. A non-null tag seen in this +* group must not already correspond to a committed tag group +* anywhere on this host. More=0 was supposed to close that +* allocation, and tag uuids must be unique across all regions +* and memdevs (the orchestrator owns assignment per spec). +* Either constraint failing — same chain redelivered, or two +* distinct allocations colliding on the same uuid — is a +* firmware/orchestrator bug; reject the whole group. +*/ +if (cxl_tag_already_committed (&tag)) { +dev_warn (dev, +"Tag %pUb: dropping group, tag already committed (firmware/orchestrator bug)\n" , + &tag); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +/* Sequence-number integrity */ if (cxl_check_group_seq (dev, &tag, &group)) {list_for_each_entry_safe (pos, tmp, &group, list)
drivers/cxl/cxl.h +3 -0
@@ -598,12 +598,15 @@ struct cxl_dax_region {* allocations. * @nr_extents: live count of dc_extents in the group; the group is freed * when the last dc_extent device is released. +* @registry_node: anchor in the host-wide non-null-tag registry that +* enforces tag uuid uniqueness across all regions and memdevs. */ struct cxl_dc_tag_group {struct cxl_dax_region *cxlr_dax;uuid_t uuid;struct xarray dc_extents;unsigned int nr_extents; +struct list_head registry_node; };bool is_dc_extent (struct device *dev);
Signature · 1 line
2.43.0
Re: [PATCH v10 19/31] cxl/extent: Enforce cross-region tag uniqueness
Quoted 13 lines · Anisa Su
The per-region scan in
cxl_tag_already_committed()only catches a tag re-appearing on the samecxlr_dax. The orchestrator owns tag allocation and is responsible for global uniqueness, but a buggy FM (or firmware redelivering a tag for a previously-closed allocation) can still hand the same uuid to extents on two different regions or memdevs, and the per-region check accepts the second one — leaving two independentcxl_dc_tag_groupobjects with the same uuid.Add a host-wide registry of live tag groups with non-null uuids.
alloc_tag_group()inserts on success,free_tag_group()removes; both skip the null-uuid case since the spec defines no cross-chain identity for untagged allocations.
Quoted 8 lines
An attempt to add a second group with the same uuid fails with
-EBUSY.No exit hook is needed:
cxl_coreonly unloads after every dependent module has, by which point every live tag group has been freed and the registry is empty.Signed-off-by Anisa Su <[email protected]>
Quoted 166 lines
--- drivers/cxl/core/core.h | 5 ++++ drivers/cxl/core/extent.c | 60 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 19 +++++++++++++ drivers/cxl/cxl.h | 3 ++ 4 files changed, 87 insertions(+)drivers/cxl/core/core.h +5
-0@@ -69,6 +69,7 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr);int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent,u16 seq_num); +bool cxl_tag_already_committed (const uuid_t *tag);int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group);#else @@ -91,6 +92,10 @@ static inline int online_tag_group(struct cxl_dc_tag_group *group) {return 0 ; } +static inline bool cxl_tag_already_committed (const uuid_t *tag) +{ +return false; +}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 +60
-0@@ -18,8 +18,60 @@ static void cxled_release_extent(struct cxl_endpoint_decoder *cxled,memdev_release_extent (mds, &dc_extent->dpa_range); } +/* +* Host-wide registry of live tag groups with non-null uuids. Enforces +* that within this host, a tag uuid identifies exactly one allocation +* across all regions and memdevs — closing the gap left by the +* per-region scans in cxlr_add_extent() and uuid_claim_tagged(). The +* orchestrator (FM) owns tag-uuid allocation per spec; this is a +* defense against firmware bugs and orchestrator misbehavior. Untagged +* (null uuid) allocations are not tracked: the spec defines no +* cross-chain identity for them. +*/ +static DEFINE_MUTEX (cxl_tag_lock); +static LIST_HEAD (cxl_tag_groups); + +static int cxl_tag_register (struct cxl_dc_tag_group *grp) +{ +struct cxl_dc_tag_group *g; + +if (uuid_is_null (&grp->uuid)) +return 0 ; + +guard (mutex)(&cxl_tag_lock); +list_for_each_entry (g, &cxl_tag_groups, registry_node) +if (uuid_equal (&g->uuid, &grp->uuid)) +return -EBUSY ; +list_add_tail (&grp->registry_node, &cxl_tag_groups); +return 0 ; +} + +static void cxl_tag_unregister (struct cxl_dc_tag_group *grp) +{ +if (uuid_is_null (&grp->uuid)) +return ; + +guard (mutex)(&cxl_tag_lock); +list_del (&grp->registry_node); +} + +bool cxl_tag_already_committed (const uuid_t *tag) +{ +struct cxl_dc_tag_group *g; + +if (uuid_is_null (tag)) +return false; + +guard (mutex)(&cxl_tag_lock); +list_for_each_entry (g, &cxl_tag_groups, registry_node) +if (uuid_equal (&g->uuid, tag)) +return true; +return false; +} +static void free_tag_group (struct cxl_dc_tag_group *group) { +cxl_tag_unregister (group);xa_destroy (&group->dc_extents);kfree (group); }@@ -54,12 +106,20 @@ alloc_tag_group(struct cxl_dax_region *cxlr_dax, uuid_t *uuid) { struct cxl_dc_tag_group *group __free(kfree) =kzalloc (sizeof (*group),GFP_KERNEL ); +int rc; +if (!group)return ERR_PTR (-ENOMEM ); group->cxlr_dax = cxlr_dax;uuid_copy (&group->uuid, uuid);xa_init (&group->dc_extents); +INIT_LIST_HEAD (&group->registry_node); + + rc =cxl_tag_register (group); +if (rc) +return ERR_PTR (rc); +return no_free_ptr (group); }drivers/cxl/core/mbox.c +19
-0@@ -1474,6 +1474,25 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)extract_tag_group (pending, &tag, &group);list_sort (NULL , &group, extent_seq_compare); +/* +* Cross-More-chain uniqueness. A non-null tag seen in this +* group must not already correspond to a committed tag group +* anywhere on this host. More=0 was supposed to close that +* allocation, and tag uuids must be unique across all regions +* and memdevs (the orchestrator owns assignment per spec). +* Either constraint failing — same chain redelivered, or two +* distinct allocations colliding on the same uuid — is a +* firmware/orchestrator bug; reject the whole group. +*/ +if (cxl_tag_already_committed (&tag)) { +dev_warn (dev, +"Tag %pUb: dropping group, tag already committed (firmware/orchestrator bug)\n" , + &tag); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); +continue ; + } +/* Sequence-number integrity */ if (cxl_check_group_seq (dev, &tag, &group)) {list_for_each_entry_safe (pos, tmp, &group, list)drivers/cxl/cxl.h +3
-0@@ -598,12 +598,15 @@ struct cxl_dax_region {* allocations. * @nr_extents: live count of dc_extents in the group; the group is freed * when the last dc_extent device is released. +* @registry_node: anchor in the host-wide non-null-tag registry that +* enforces tag uuid uniqueness across all regions and memdevs. */ struct cxl_dc_tag_group {struct cxl_dax_region *cxlr_dax;uuid_t uuid;struct xarray dc_extents;unsigned int nr_extents; +struct list_head registry_node; };bool is_dc_extent (struct device *dev);
PATCH v10 20/31 cxl/region/extent: Expose dc_extent information in sysfs
In reply to Anisa SuFrom: 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 each dc_extent 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/uuid
Each dc_extent surfaces as its own extentX.Y device under the parent dax_region. offset and length describe that dc_extent's HPA range, not an aggregate bounding box across the containing tagged allocation — so when a tagged allocation has multiple DPA-discontiguous extents, each is reported with its own offset and length. uuid is the tag identifying the containing allocation; it is shared across dc_extents that belong to the same tagged allocation and is hidden for untagged extents.
Based on an original patch by Navneet Singh.
--- 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
@@ -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
Dave Jiang
maintainerRe: [PATCH v10 20/31] cxl/region/extent: Expose dc_extent information in sysfs
Quoted 22 lines · 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 each
dc_extentby 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/uuidEach
dc_extentsurfaces as its own extentX.Y device under the parentdax_region. offset and length describe that dc_extent's HPA range, not an aggregate bounding box across the containing tagged allocation — so when a tagged allocation has multiple DPA-discontiguous extents, each is reported with its own offset and length. uuid is the tag identifying the containing allocation; it is shared acrossdc_extentsthat belong to the same tagged allocation and is hidden for untagged extents.
Quoted 6 lines
Based on an original patch by Navneet Singh.
Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Fan Ni <[email protected]>Tested-by Fan Ni <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Missing Anisa sign off
Quoted 10 lines
--- Documentation/ABI/testing/sysfs-bus-cxl | 36 +++++++++++++++ drivers/cxl/core/extent.c | 58 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+)Documentation/ABI/testing/sysfs-bus-cxl +0
-0
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 668
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-cxl +5
-0@@ -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
Update date and kernel version for all
Quoted 74 lines
Documentation/ABI/testing/sysfs-bus-cxl +31
-0+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 +35
-0@@ -6,6 +6,63 @@#include "core.h" +static ssize_t offset_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); + +return sysfs_emit (buf,"%#llx\n" , dc_extent->hpa_range.start); +} +static DEVICE_ATTR_RO (offset); + +static ssize_t length_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); +u64 length =range_len (&dc_extent->hpa_range); + +return sysfs_emit (buf,"%#llx\n" , length); +} +static DEVICE_ATTR_RO (length); + +static ssize_t uuid_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); + +return sysfs_emit (buf,"%pUb\n" , &dc_extent->group->uuid); +} +static DEVICE_ATTR_RO (uuid); + +static struct attribute *dc_extent_attrs[] = { + &dev_attr_offset.attr, + &dev_attr_length.attr, + &dev_attr_uuid.attr, +NULL +}; +
drivers/cxl/core/extent.c line 53
Quoted 10 lines
drivers/cxl/core/extent.c +10
-0+static uuid_t empty_uuid = {0 }; + +static umode_t dc_extent_visible (struct kobject *kobj, +struct attribute *a,int n) +{ +struct device *dev =kobj_to_dev (kobj); +struct dc_extent *dc_extent =to_dc_extent (dev); + +if (a == &dev_attr_uuid.attr && + uuid_equal(&dc_extent->group->uuid, &empty_uuid))'
uuid_is_null() can be used?
DJ
Quoted 23 lines
drivers/cxl/core/extent.c +13
-0+return 0 ; + +return a->mode; +} + +static const struct attribute_group dc_extent_attribute_group = { + .attrs = dc_extent_attrs, + .is_visible = dc_extent_visible, +}; + +__ATTRIBUTE_GROUPS (dc_extent_attribute); +static void cxled_release_extent (struct cxl_endpoint_decoder *cxled,struct dc_extent *dc_extent)@@ -93,6 +150,7 @@ static void dc_extent_release(struct device *dev)static const struct device_type dc_extent_type = { .name ="extent" , .release = dc_extent_release, + .groups = dc_extent_attribute_groups, };bool is_dc_extent (struct device *dev)
Re: [PATCH v10 20/31] cxl/region/extent: Expose dc_extent information in sysfs
Quoted 25 lines · Dave Jiang
Quoted 22 lines · 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 each
dc_extentby 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/uuidEach
dc_extentsurfaces as its own extentX.Y device under the parentdax_region. offset and length describe that dc_extent's HPA range, not an aggregate bounding box across the containing tagged allocation — so when a tagged allocation has multiple DPA-discontiguous extents, each is reported with its own offset and length. uuid is the tag identifying the containing allocation; it is shared acrossdc_extentsthat belong to the same tagged allocation and is hidden for untagged extents.
Quoted 9 lines
Quoted 6 lines
Based on an original patch by Navneet Singh.
Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Fan Ni <[email protected]>Tested-by Fan Ni <[email protected]>Signed-off-by Ira Weiny <[email protected]>Missing Anisa sign off
added
Quoted 5 lines
Quoted 5 lines
--- Documentation/ABI/testing/sysfs-bus-cxl | 36 +++++++++++++++ drivers/cxl/core/extent.c | 58 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
Quoted 16 lines
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 668
Quoted 13 lines
Documentation/ABI/testing/sysfs-bus-cxl +5
-0@@ -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.16Update date and kernel version for all
updated
Quoted 78 lines
Quoted 78 lines
Documentation/ABI/testing/sysfs-bus-cxl +31
-0+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 +39
-0@@ -6,6 +6,63 @@#include "core.h" +static ssize_t offset_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); + +return sysfs_emit (buf,"%#llx\n" , dc_extent->hpa_range.start); +} +static DEVICE_ATTR_RO (offset); + +static ssize_t length_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); +u64 length =range_len (&dc_extent->hpa_range); + +return sysfs_emit (buf,"%#llx\n" , length); +} +static DEVICE_ATTR_RO (length); + +static ssize_t uuid_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct dc_extent *dc_extent =to_dc_extent (dev); + +return sysfs_emit (buf,"%pUb\n" , &dc_extent->group->uuid); +} +static DEVICE_ATTR_RO (uuid); + +static struct attribute *dc_extent_attrs[] = { + &dev_attr_offset.attr, + &dev_attr_length.attr, + &dev_attr_uuid.attr, +NULL +}; + +static uuid_t empty_uuid = {0 }; + +static umode_t dc_extent_visible (struct kobject *kobj, +struct attribute *a,int n)
Quoted 9 lines
drivers/cxl/core/extent.c
Quoted 6 lines
drivers/cxl/core/extent.c +6
-0+{ +struct device *dev =kobj_to_dev (kobj); +struct dc_extent *dc_extent =to_dc_extent (dev); + +if (a == &dev_attr_uuid.attr && + uuid_equal(&dc_extent->group->uuid, &empty_uuid))'
uuid_is_null()can be used?
oh yeah oops... replaced w/uuid_is_null()
Quoted 2 lines
DJ
Thanks,
Anisa
Quoted 24 lines
Quoted 23 lines
drivers/cxl/core/extent.c +13
-0+return 0 ; + +return a->mode; +} + +static const struct attribute_group dc_extent_attribute_group = { + .attrs = dc_extent_attrs, + .is_visible = dc_extent_visible, +}; + +__ATTRIBUTE_GROUPS (dc_extent_attribute); +static void cxled_release_extent (struct cxl_endpoint_decoder *cxled,struct dc_extent *dc_extent)@@ -93,6 +150,7 @@ static void dc_extent_release(struct device *dev)static const struct device_type dc_extent_type = { .name ="extent" , .release = dc_extent_release, + .groups = dc_extent_attribute_groups, };bool is_dc_extent (struct device *dev)
PATCH v10 21/31 cxl + dax: Surface dax_resources on DCD Add Capacity events
In reply to Anisa SuWhen an extent is accepted/released, the CXL driver must notify the DAX driver to coordinate the management of resources. Define the .notify callback to the cxl_dax region driver to enable the coordination.
Define struct dax_resource, a sub-resource of a DC dax_region representing the capacity of one dc_extent.
When the cxl side onlines a tag group during a DC Add event, notify the DAX region to register a struct dax_resource for each extent under the dax_region's resource tree.
The dax_resource model:
* struct dax_resource (dax-private.h) — per-extent sub-resource of a DC dax_region: pointer back to its region, the kernel struct resource, the tag uuid, the per-allocation seq_num, and a use_cnt that lets a later commit refuse release of an in-use extent.
* struct dev_dax_range gains a dax_resource back-pointer so a carved range remembers which extent it lives in.
For now, dax_resources live under the dax_region and remain inaccessible to DAX devices. A later commit adds the support to specify a tag when creating a DAX device, which then allows dax_resources to be claimed by tag.
Release is handled in the following commit.
Based on an original patch by Navneet Singh.
---
Changes:
[anisa:restructured from the original "Create resources on sparse DAX
regions" commit】
--- drivers/cxl/core/core.h | 10 ++++ drivers/cxl/core/extent.c | 33 ++++++++++- drivers/cxl/core/mbox.c | 17 +++++- drivers/cxl/cxl.h | 6 ++ drivers/dax/bus.c | 118 ++++++++++++++++++++++++++++++++++---- drivers/dax/bus.h | 3 +- drivers/dax/cxl.c | 88 +++++++++++++++++++++++++++- drivers/dax/dax-private.h | 49 ++++++++++++++++ drivers/dax/hmem/hmem.c | 2 +- drivers/dax/pmem.c | 2 +- 10 files changed, 306 insertions(+), 22 deletions(-)
drivers/cxl/core/core.h +10 -0
@@ -72,6 +72,9 @@ int cxl_add_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent,bool cxl_tag_already_committed (const uuid_t *tag);int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);int online_tag_group (struct cxl_dc_tag_group *group); +void rm_tag_group (struct cxl_dc_tag_group *group); +int cxlr_notify_extent (struct cxl_region *cxlr,enum dc_event event, +struct cxl_dc_tag_group *group);#else static inline u64 cxl_dpa_to_hpa (struct cxl_region *cxlr,const struct cxl_memdev *cxlmd,u64 dpa)
@@ -96,6 +99,13 @@ static inline bool cxl_tag_already_committed(const uuid_t *tag) {return false; } +static inline void rm_tag_group (struct cxl_dc_tag_group *group) { } +static inline int cxlr_notify_extent (struct cxl_region *cxlr, +enum dc_event event, +struct cxl_dc_tag_group *group) +{ +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 +31 -2
@@ -63,7 +63,6 @@ static const struct attribute_group dc_extent_attribute_group = {__ATTRIBUTE_GROUPS (dc_extent_attribute); -static void cxled_release_extent (struct cxl_endpoint_decoder *cxled,struct dc_extent *dc_extent) {
@@ -359,6 +358,36 @@ dc_extent_build(struct cxl_endpoint_decoder *cxled,return dc_extent; } +int cxlr_notify_extent (struct cxl_region *cxlr,enum dc_event event, +struct cxl_dc_tag_group *group) +{ +struct device *dev = &cxlr->cxlr_dax->dev; +struct cxl_notify_data notify_data; +struct cxl_driver *driver; + +dev_dbg (dev,"Trying notify: type %d tag %pUb\n" , event, &group->uuid); + +guard (device)(dev); + +/* +* The lack of a driver indicates a notification has failed. No user +* space coordination was possible. +*/ +if (!dev->driver) +return 0 ; + driver =to_cxl_drv (dev->driver); +if (!driver->notify) +return 0 ; + + notify_data = (struct cxl_notify_data ) { + .event = event, + .group = group, + }; + +dev_dbg (dev,"Notify: type %d tag %pUb\n" , event, &group->uuid); +return driver->notify (dev, ¬ify_data); +} +/* * Stage 4: insert @dc_extent into the pending tag group. All extents in * one More-chain group share a UUID — enforced here as the group is
@@ -462,7 +491,7 @@ static void dc_extent_unregister(void *ext)device_unregister (&dc_extent->dev); } -static void rm_tag_group (struct cxl_dc_tag_group *group) +void rm_tag_group (struct cxl_dc_tag_group *group) {struct device *region_dev = &group->cxlr_dax->dev;struct dc_extent *dc_extent;
drivers/cxl/core/mbox.c +15 -2
@@ -1558,8 +1558,21 @@ static int cxl_add_pending(struct cxl_memdev_state *mds)list_for_each_entry_safe (pos, tmp, &group, list)delete_extent_node (pos); }else { -list_splice_tail_init (&group, &accepted); - total_accepted += group_cnt; + rc =cxlr_notify_extent (tag_group->cxlr_dax->cxlr, +DCD_ADD_CAPACITY , tag_group); +if (rc) { +/* +* The dax-side notification failed; tear down the +* tag group and drop the extents so we do not +* mis-report acceptance to the device. +*/ +rm_tag_group (tag_group); +list_for_each_entry_safe (pos, tmp, &group, list) +delete_extent_node (pos); + }else { +list_splice_tail_init (&group, &accepted); + total_accepted += group_cnt; + } } mds->add_ctx.group =NULL ;
drivers/cxl/cxl.h +6 -0
@@ -892,6 +892,11 @@ bool is_cxl_region(struct device *dev);extern const struct bus_type cxl_bus_type; +struct cxl_notify_data { +enum dc_event event; +struct cxl_dc_tag_group *group; +}; +/* * Note, add_dport() is expressly for the cxl_port driver. TODO: investigate a * type-safe driver model where probe()/remove() take the type of object implied
@@ -904,6 +909,7 @@ struct cxl_driver {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 +106 -12
206 lines not on this page · raw message
drivers/dax/bus.h +2 -1
@@ -11,6 +11,7 @@ struct dev_dax;struct resource ;struct dax_device ;struct dax_region ; +struct dax_dc_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_dc_ops *dc_ops);struct dev_dax_data {struct dax_region *dax_region;
drivers/dax/cxl.c +85 -3
112 lines not on this page · raw message
drivers/dax/dax-private.h +49 -0
90 lines not on this page · raw message
drivers/dax/hmem/hmem.c +1 -1
@@ -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
@@ -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 );
Signature · 1 line
2.43.0