DCD: Add support for Dynamic Capacity Devices (DCD)
Subsystems (6)
v2 cover DCD: Add support for Dynamic Capacity Devices (DCD)
A git tree of this series can be found here:
https://github.com/weiny2/linux-kernel/tree/dcd-v4-2024-08-15
This series requires the CXL memory notifier lock change:
https://lore.kernel.org/all/[email protected]/
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 use cases for Dynamic Capacity is to allow hosts to share memory dynamically within a data center without increasing the per-host attached memory.
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.
Typical work flows are shown below.
Orchestrator FM Device Host Kernel Host User
| | | | |
|-------------- Create region ----------------------->|
| | | | |
| | | |<-- Create ---|
| | | | Region |
|<------------- 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 |
| | | | |Previous versions of this series[0] resulted in architectural comments as well as confusion on the architecture based on the organization of patch series itself.
This version has reordered the patches to clarify the architecture. It also streamlines extent handling more.
The series still requires the creation of regions and DAX devices to be synchronized with the Orchestrator and Fabric Manager. The host kernel will reject an add extent event if the region is not created yet. It will also ignore a release if the DAX device is created and referencing an extent.
These synchronizations are not anticipated to be an issue with real applications.
In order to allow for capacity to be added and removed a new concept of a sparse DAX region is introduced. A sparse DAX region may have 0 or more bytes of available space. The total space depends on the number and size of the extents which have been added.
Initially it is anticipated that users of the memory will carefully coordinate the surfacing of additional capacity with the creation of DAX devices which use that capacity. Therefore, the allocation of the memory to DAX devices does not allow for specific associations between DAX device and extent. This keeps allocations very similar to existing DAX region behavior.
Great care was taken to keep the extent tracking simple. Some xarray's needed to be added but extra software objects were kept to a minimum.
Region extents continue to be tracked as sub-devices of the DAX region. This ensures that region destruction cleans up all extent allocations properly.
Due to these major changes all reviews were removed from the larger patches. A few of the straight forward patches have kept the tags.
In summary the major functionality of this series includes:
- Getting the dynamic capacity (DC) configuration information from cxl devices
- Configuring the DC partitions reported by hardware
- Enhancing the CXL and DAX regions for dynamic capacity support a. Maintain a logical separation between hardware extents and software managed region extents. This provides an abstraction between the layers and should allow for interleaving in the future
- Get hardware extent lists for endpoint decoders upon region creation.
- Adjust extent/region memory available on the following events. a. Add capacity Events
b. Release capacity events
- Host response for add capacity
a. do not accept the extent if:
If the region does not exist
or an error occurs realizing the extent
b. If the region does exist
realize a DAX region extent with 1:1 mapping (no interleave yet)
c. Support the more bit by processing a list of extents marked
with the more bit together before setting up a response.
- Host response for remove capacity
a. If no DAX device references the extent; release the extent b. If a reference does exist, ignore the request.
(Require FM to issue release again.)
- Modify DAX device creation/resize to account for extents within a sparse DAX region
- Trace Dynamic Capacity events for debugging
- Add cxl-test infrastructure to allow for faster unit testing (See new ndctl branch for cxl-dcd.sh test[1])
Fan Ni's upstream of Qemu DCD was used for testing.
Remaining work:
1) Integrate the QoS work from Dave Jiang
2) Interleave support
Possible additional work depending on requirements:
1) Allow mapping to specific extents (perhaps based on label/tag)
2) Release extents when DAX devices are released if a release was previously seen from the device
3) Accept a new extent which extends (but overlaps) an existing extent(s)
4) Rework DAX device interfaces, memfd has been explored a bit
[0] v1: https://lore.kernel.org/all/[email protected]/
[1] https://github.com/weiny2/ndctl/tree/dcd-region2-2024-08-15
---
Major changes:
- Jonathan: support the more bit
- djbw: Allow more than 1 region per DC partition
- All: Address the many comments on the series.
- iweiny: rebase
- iweiny: Rework the series to make it easier to review and understand
the flow
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ira Weiny (13):
range: Add range_overlaps()
printk: Add print format (%par) for struct range
dax: Document dax dev range tuple
cxl/pci: Delay event buffer allocation
cxl/region: Refactor common create region code cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/core: Return endpoint decoder information from region search dax/bus: Factor out dev dax resize logic
dax/region: Create resources on sparse DAX regions cxl/region: Read existing extents on region creation tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data
Navneet Singh (12):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/core: Separate region mode from decoder mode cxl/region: Add dynamic capacity decoder and region modes cxl/hdm: Add dynamic capacity size support to endpoint decoders cxl/port: Add endpoint decoder DC mode support to sysfs cxl/mem: Expose DCD partition capabilities in sysfs cxl/region: Add sparse DAX region support
cxl/mem: Configure dynamic capacity interrupts cxl/extent: Process DCD events and realize region extents cxl/region/extent: Expose region extent information in sysfs cxl/mem: Trace Dynamic capacity Event Record
Documentation/ABI/testing/sysfs-bus-cxl | 68 ++- Documentation/core-api/printk-formats.rst | 14 + drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 33 +- drivers/cxl/core/extent.c | 467 ++++++++++++++ drivers/cxl/core/hdm.c | 206 ++++++- drivers/cxl/core/mbox.c | 578 +++++++++++++++++- drivers/cxl/core/memdev.c | 101 ++- drivers/cxl/core/port.c | 13 +- drivers/cxl/core/region.c | 173 ++++-- drivers/cxl/core/trace.h | 65 ++ drivers/cxl/cxl.h | 122 +++- drivers/cxl/cxlmem.h | 128 +++- drivers/cxl/pci.c | 123 +++- drivers/dax/bus.c | 352 +++++++++-- drivers/dax/bus.h | 4 +- drivers/dax/cxl.c | 73 ++- drivers/dax/dax-private.h | 39 +- drivers/dax/hmem/hmem.c | 2 +- drivers/dax/pmem.c | 2 +- fs/btrfs/ordered-data.c | 10 +- include/linux/cxl-event.h | 32 + include/linux/range.h | 7 + lib/vsprintf.c | 37 ++ tools/testing/cxl/Kbuild | 3 +- tools/testing/cxl/test/mem.c | 981 ++++++++++++++++++++++++++---- 26 files changed, 3327 insertions(+), 308 deletions(-)
---
base-commit: 3cef9316df4cda21b5bf25e4230221b02050dfa1
change-id: 20230604-dcd-type2-upstream-0cd15f6216fd
Best regards,
Signature · 1 line
Ira Weiny <[email protected]>
PATCH v2 1/25 range: Add range_overlaps()
Code to support CXL Dynamic Capacity devices will have extent ranges which need to be compared for intersection not a subset as is being checked in range_contains().
range_overlaps() is defined in btrfs with a different meaning from what is required in the standard range code. Dan Williams pointed this out in [1]. Adjust the btrfs call according to his suggestion there.
Then add a generic range_overlaps().
[1] https://lore.kernel.org/all/[email protected]/
--- fs/btrfs/ordered-data.c | 10 +++++----- include/linux/range.h | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
fs/btrfs/ordered-data.c +5 -5
@@ -111,8 +111,8 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 file_offset,return NULL ; } -static int range_overlaps (struct btrfs_ordered_extent *entry,u64 file_offset, -u64 len) +static int btrfs_range_overlaps (struct btrfs_ordered_extent *entry,u64 file_offset, +u64 len) {if (file_offset + len <= entry->file_offset || entry->file_offset + entry->num_bytes <= file_offset)
@@ -985,7 +985,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(while (1 ) { entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); -if (range_overlaps (entry, file_offset, len)) +if (btrfs_range_overlaps (entry, file_offset, len))break ;if (entry->file_offset >= file_offset + len) {
@@ -1114,12 +1114,12 @@ struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range( }if (prev) { entry = rb_entry(prev, struct btrfs_ordered_extent, rb_node); -if (range_overlaps (entry, file_offset, len)) +if (btrfs_range_overlaps (entry, file_offset, len)) goto out; }if (next) { entry = rb_entry(next, struct btrfs_ordered_extent, rb_node); -if (range_overlaps (entry, file_offset, len)) +if (btrfs_range_overlaps (entry, file_offset, len)) goto out; }/* No ordered extent in the range */
include/linux/range.h +7 -0
@@ -13,11 +13,18 @@ static inline u64 range_len(const struct range *range)return range->end - range->start +1 ; } +/* True if r1 completely contains r2 */ static inline bool range_contains (struct range *r1,struct range *r2) {return r1->start <= r2->start && r1->end >= r2->end; } +/* True if any part of r1 overlaps r2 */ +static inline bool range_overlaps (struct range *r1,struct range *r2) +{ +return r1->start <= r2->end && r1->end >= r2->start; +} +int add_range (struct range *range,int az,int nr_range,u64 start,u64 end);
Signature · 1 line
2.45.2
PATCH v2 2/25 printk: Add print format (%par) for struct range
In reply to Ira WeinyThe use of struct range in the CXL subsystem is growing. In particular, the addition of Dynamic Capacity devices uses struct range in a number of places which are reported in debug and error messages.
To wit requiring the printing of the start/end fields in each print became cumbersome. Dan Williams mentions in [1] that it might be time to have a print specifier for struct range similar to struct resource
A few alternatives were considered including '%pn' for 'print raNge' but %par follows that struct range is most often used to store a range of physical addresses. So use '%par' for 'print address range'.
To: Petr Mladek <[email protected]> (maintainer:VSPRINTF)
To: Steven Rostedt <[email protected]> (maintainer:VSPRINTF)
To: Jonathan Corbet <[email protected]> (maintainer:DOCUMENTATION)
--- Documentation/core-api/printk-formats.rst | 14 ++++++++++++ lib/vsprintf.c | 37 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
Documentation/core-api/printk-formats.rst +14 -0
@@ -231,6 +231,20 @@ width of the CPU data path. Passed by reference. +Struct Range +------------ + +:: + + %par [range 0x60000000-0x6fffffff] or + [range 0x0000000060000000-0x000000006fffffff] + +For printing struct range. A variation of printing a physical address is to +print the value of struct range which are often used to hold a physical address +range. + +Passed by reference. + DMA address types dma_addr_t ----------------------------
lib/vsprintf.c +37 -0
@@ -1140,6 +1140,39 @@ char *resource_string(char *buf, char *end, struct resource *res,return string_nocheck (buf, end, sym, spec); } +static noinline_for_stack +char *range_string(char *buf, char *end, const struct range *range, +struct printf_spec spec,const char *fmt) +{ +#define RANGE_PRINTK_SIZE 16 +#define RANGE_DECODED_BUF_SIZE ((2 * sizeof(struct range)) + 4) +#define RANGE_PRINT_BUF_SIZE sizeof("[range - ]") +char sym[RANGE_DECODED_BUF_SIZE +RANGE_PRINT_BUF_SIZE ]; +char *p = sym, *pend = sym +sizeof (sym); + +static const struct printf_spec str_spec = { + .field_width =-1 , + .precision =10 , + .flags =LEFT , + }; +static const struct printf_spec range_spec = { + .base =16 , + .field_width =RANGE_PRINTK_SIZE , + .precision =-1 , + .flags =SPECIAL |SMALL |ZEROPAD , + }; + + *p++ ='[' ; + p =string_nocheck (p, pend,"range " , str_spec); + p =number (p, pend, range->start, range_spec); + *p++ ='-' ; + p =number (p, pend, range->end, range_spec); + *p++ =']' ; + *p ='\0' ; + +return string_nocheck (buf, end, sym, spec); +} +static noinline_for_stack char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,const char *fmt)
@@ -1802,6 +1835,8 @@ char *address_val(char *buf, char *end, const void *addr,return buf;switch (fmt[1 ]) { +case 'r' : +return range_string (buf, end, addr, spec, fmt);case 'd' : num = *(const dma_addr_t *)addr; size =sizeof (dma_addr_t);
@@ -2364,6 +2399,8 @@ char *rust_fmt_argument(char *buf, char *end, void *ptr);* to use print_hex_dump() for the larger input. * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives * (default assumed to be phys_addr_t, passed by reference) +* - 'ar' For decoded struct ranges (a variation of physical address which are +* most often stored in struct ranges. * - 'd[234]' For a dentry name (optionally 2-4 last components) * - 'D[234]' Same as 'd' but for a struct file * - 'g' For block_device name (gendisk + partition number)
Signature · 1 line
2.45.2
PATCH v2 3/25 dax: Document dax dev range tuple
In reply to Ira WeinyThe device DAX structure is being enhanced to track additional DCD information.
The current range tuple was not fully documented. Document it prior to adding information for DC.
---
Changes:
[iweiny: move to start of series]
--- drivers/dax/dax-private.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dax/dax-private.h +4 -1
@@ -58,7 +58,10 @@ struct dax_mapping {* @dev - device core * @pgmap - pgmap for memmap setup / lifetime (driver owned) * @nr_range: size of @ranges -* @ranges: resource-span + pgoff tuples for the instance +* @ranges: range tuples of memory used +* @pgoff: page offset +* @range: resource-span +* @mapping: device to assist in interrogating the range layout */ struct dev_dax {struct dax_region *region;
Signature · 1 line
2.45.2
PATCH v2 4/25 cxl/pci: Delay event buffer allocation
In reply to Ira WeinyThe event buffer does not need to be allocated if something has failed in setting up event irq's.
In prep for adjusting event configuration for DCD events move the buffer allocation to the end of the event configuration.
---
Changes:
[iweiny: keep tags for early simple patch] [Davidlohr, Jonathan, djiang: move to beginning of series]
[Dave feel free to pick this up if you like]
--- drivers/cxl/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/pci.c +4 -4
@@ -760,10 +760,6 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,return 0 ; } - rc =cxl_mem_alloc_event_buf (mds); -if (rc) -return rc; - rc =cxl_event_get_int_policy (mds, &policy);if (rc)return rc;
@@ -777,6 +773,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,return -EBUSY ; } + rc =cxl_mem_alloc_event_buf (mds); +if (rc) +return rc; + rc =cxl_event_irqsetup (mds);if (rc)return rc;
Signature · 1 line
2.45.2
PATCH v2 5/25 cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
In reply to Ira WeinyFrom: Navneet Singh <[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
---
Changes:
[iweiny: Keep tags for this early simple patch]
[Davidlohr: update commit message]
[djiang: Fix misalignment]
--- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)
drivers/cxl/core/mbox.c +33 -0
@@ -164,6 +164,34 @@ 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) +{ +switch (opcode) { +case CXL_MBOX_OP_GET_DC_CONFIG : +set_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +break ; +case CXL_MBOX_OP_GET_DC_EXTENT_LIST : +set_bit (CXL_DCD_ENABLED_GET_EXTENT_LIST , mds->dcd_cmds); +break ; +case CXL_MBOX_OP_ADD_DC_RESPONSE : +set_bit (CXL_DCD_ENABLED_ADD_RESPONSE , mds->dcd_cmds); +break ; +case CXL_MBOX_OP_RELEASE_DC : +set_bit (CXL_DCD_ENABLED_RELEASE , mds->dcd_cmds); +break ; +default : +break ; + } +} +static bool cxl_is_poison_command (u16 opcode) {#define CXL_MBOX_OP_POISON_CMDS 0x43
@@ -745,6 +773,11 @@ 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); + enabled++; + } +dev_dbg (dev,"Opcode 0x%04x %s\n" , opcode, enabled ?"enabled" :"unsupported by driver" ); }
drivers/cxl/cxlmem.h +15 -0
@@ -238,6 +238,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 ,
@@ -454,6 +463,7 @@ struct cxl_dev_state {* (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) * @mbox_mutex: Mutex to synchronize mailbox access. * @firmware_version: Firmware version for the memory device. +* @dcd_cmds: List of DCD commands implemented by memory device * @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities
@@ -482,6 +492,7 @@ struct cxl_memdev_state {size_t lsa_size;struct mutex mbox_mutex;/* Protects device mailbox and firmware */ char firmware_version[0x10 ]; +DECLARE_BITMAP (dcd_cmds,CXL_DCD_ENABLED_MAX );DECLARE_BITMAP (enabled_cmds,CXL_MEM_COMMAND_ID_MAX );DECLARE_BITMAP (exclusive_cmds,CXL_MEM_COMMAND_ID_MAX );u64 total_bytes;
@@ -555,6 +566,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.45.2
PATCH v2 6/25 cxl/mem: Read dynamic capacity configuration from the device
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
Devices which optionally support Dynamic Capacity (DC) are configured via mailbox commands. CXL 3.1 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.1 section 8.2.9.9.9 (opcodes 48XXh) to read and store the DCD configuration information. Disable DCD if DCD is not supported. Leverage the Get DC Configuration command supported bit to indicate if DCD support.
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.
---
Changes:
[Li, Ming: Fix bug in total_bytes calculation]
[iweiny: update commit message]
[Jonathan: fix formatting]
[Jonathan: Define block line size]
[Jonathan/Fan: use regions returned field instead of macro in get config] [Jørgen: Rename memdev state range variables]
[Jonathan: adjust use of rc in cxl_dev_dynamic_capacity_identify()] [Jonathan: white space cleanup]
[fan: make a comment about the trailing configuration output fields]
--- drivers/cxl/core/mbox.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 64 +++++++++++++++++- drivers/cxl/pci.c | 4 ++ 3 files changed, 237 insertions(+), 2 deletions(-)
drivers/cxl/core/mbox.c +170 -1
@@ -1157,7 +1157,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_bytes =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;
@@ -1264,6 +1264,159 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)return rc; } +static int cxl_dc_save_region_info (struct cxl_memdev_state *mds,u8 index, +struct cxl_dc_region_config *region_config) +{ +struct cxl_dc_region_info *dcr = &mds->dc_region[index]; +struct device *dev = mds->cxlds.dev; + + dcr->base =le64_to_cpu (region_config->region_base); + dcr->decode_len =le64_to_cpu (region_config->region_decode_length); + dcr->decode_len *=CXL_CAPACITY_MULTIPLIER ; + dcr->len =le64_to_cpu (region_config->region_length); + dcr->blk_size =le64_to_cpu (region_config->region_block_size); + dcr->dsmad_handle =le32_to_cpu (region_config->region_dsmad_handle); + dcr->flags = region_config->flags; +snprintf (dcr->name,CXL_DC_REGION_STRLEN ,"dc%d" , index); + +/* Check regions are in increasing DPA order */ +if (index >0 ) { +struct cxl_dc_region_info *prev_dcr = &mds->dc_region[index -1 ]; + +if ((prev_dcr->base + prev_dcr->decode_len) > dcr->base) { +dev_err (dev, +"DPA ordering violation for DC region %d and %d\n" , + index -1 , index); +return -EINVAL ; + } + } + +if (!IS_ALIGNED (dcr->base,SZ_256M ) || + !IS_ALIGNED (dcr->base, dcr->blk_size)) { +dev_err (dev,"DC region %d invalid base %#llx blk size %#llx\n" , + index, dcr->base, dcr->blk_size); +return -EINVAL ; + } + +if (dcr->decode_len ==0 || dcr->len ==0 || dcr->decode_len < dcr->len || + !IS_ALIGNED (dcr->len, dcr->blk_size)) { +dev_err (dev,"DC region %d invalid length; decode %#llx len %#llx blk size %#llx\n" , + index, dcr->decode_len, dcr->len, dcr->blk_size); +return -EINVAL ; + } + +if (dcr->blk_size ==0 || dcr->blk_size %CXL_DCD_BLOCK_LINE_SIZE || + !is_power_of_2 (dcr->blk_size)) { +dev_err (dev,"DC region %d invalid block size; %#llx\n" , + index, dcr->blk_size); +return -EINVAL ; + } + +dev_dbg (dev, +"DC region %s base %#llx length %#llx block size %#llx\n" , + dcr->name, dcr->base, dcr->decode_len, dcr->blk_size); + +return 0 ; +} + +/* Returns the number of regions in dc_resp or -ERRNO */ +static int cxl_get_dc_config (struct cxl_memdev_state *mds,u8 start_region, +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 ) { + .region_count =CXL_MAX_DC_REGION , + .start_region_index = start_region, + }; +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 =1 , + }; +struct device *dev = mds->cxlds.dev; +int rc; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + +dev_dbg (dev,"Read %d/%d DC regions\n" , + dc_resp->regions_returned, dc_resp->avail_region_count); +return dc_resp->regions_returned; +} + +/** +* cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity +* information from the device. +* @mds: The memory device state +* +* Read Dynamic Capacity information from the device and populate the state +* structures for later use. +* +* Return: 0 if identify was executed successfully, -ERRNO on error. +*/ +int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds) +{ +size_t dc_resp_size = mds->payload_size; +struct device *dev = mds->cxlds.dev; +u8 start_region, i; + +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD not supported\n" ); +return 0 ; + } + + struct cxl_mbox_get_dc_config_out *dc_resp __free(kfree) = +kvmalloc (dc_resp_size,GFP_KERNEL ); +if (!dc_resp) +return -ENOMEM ; + + start_region =0 ; +do { +int rc, j; + + rc =cxl_get_dc_config (mds, start_region, dc_resp, dc_resp_size); +if (rc <0 ) { +dev_dbg (dev,"Failed to get DC config: %d\n" , rc); +return rc; + } + + mds->nr_dc_region += rc; + +if (mds->nr_dc_region <1 || mds->nr_dc_region >CXL_MAX_DC_REGION ) { +dev_err (dev,"Invalid num of dynamic capacity regions %d\n" , + mds->nr_dc_region); +return -EINVAL ; + } + +for (i = start_region, j =0 ; i < mds->nr_dc_region; i++, j++) { + rc =cxl_dc_save_region_info (mds, i, &dc_resp->region[j]); +if (rc) { +dev_dbg (dev,"Failed to save region info: %d\n" , rc); +return rc; + } + } + + start_region = mds->nr_dc_region; + + }while (mds->nr_dc_region < dc_resp->avail_region_count); + + mds->dynamic_bytes = + mds->dc_region[mds->nr_dc_region -1 ].base + + mds->dc_region[mds->nr_dc_region -1 ].decode_len - + mds->dc_region[0 ].base; +dev_dbg (dev,"Total dynamic range: %#llx\n" , mds->dynamic_bytes); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int add_dpa_res (struct device *dev,struct resource *parent,struct resource *res,resource_size_t start,resource_size_t size,const char *type)
@@ -1294,8 +1447,15 @@ int cxl_mem_create_range_info(struct cxl_memdev_state *mds) {struct cxl_dev_state *cxlds = &mds->cxlds;struct device *dev = cxlds->dev; +size_t untenanted_mem;int rc; + mds->total_bytes = mds->static_bytes; +if (mds->nr_dc_region) { + untenanted_mem = mds->dc_region[0 ].base - mds->static_bytes; + mds->total_bytes += untenanted_mem + mds->dynamic_bytes; + } +if (!cxlds->media_ready) { cxlds->dpa_res =DEFINE_RES_MEM (0 ,0 ); cxlds->ram_res =DEFINE_RES_MEM (0 ,0 );
@@ -1305,6 +1465,15 @@ int cxl_mem_create_range_info(struct cxl_memdev_state *mds) cxlds->dpa_res =DEFINE_RES_MEM (0 , mds->total_bytes); +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + + rc =add_dpa_res (dev, &cxlds->dpa_res, &cxlds->dc_res[i], + dcr->base, dcr->decode_len, dcr->name); +if (rc) +return rc; + } +if (mds->partition_align_bytes ==0 ) { rc =add_dpa_res (dev, &cxlds->dpa_res, &cxlds->ram_res,0 , mds->volatile_only_bytes,"ram" );
drivers/cxl/cxlmem.h +63 -1
128 lines not on this page · raw message
drivers/cxl/pci.c +4 -0
@@ -874,6 +874,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; + rc =cxl_dev_dynamic_capacity_identify (mds); +if (rc) +cxl_disable_dcd (mds); + rc =cxl_mem_create_range_info (mds);if (rc)return rc;
Signature · 1 line
2.45.2
PATCH v2 7/25 cxl/core: Separate region mode from decoder mode
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that both modes were either PMEM or RAM. The addition of Dynamic Capacity partitions defines up to 8 DC partitions per device.
The region mode is thus no longer equivalent to the endpoint decoder mode. IOW the endpoint decoders may have modes of DC0-DC7 while the region mode is simply DC.
Define a new region mode enumeration which applies to regions separate from the decoder mode. Adjust the code to process these modes independently.
There is no equal to decoder mode dead in region modes. Avoid constructing regions with decoders which have been flagged as dead.
---
Changes:
[iweiny: rebase]
[Jonathan: remove dead code]
[Jonathan: clarify commit message]
--- drivers/cxl/core/region.c | 75 ++++++++++++++++++++++++++++++++++------------- drivers/cxl/cxl.h | 26 ++++++++++++++-- 2 files changed, 79 insertions(+), 22 deletions(-)
drivers/cxl/core/region.c +55 -20
@@ -144,7 +144,7 @@ static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, rc =down_read_interruptible (&cxl_region_rwsem);if (rc)return rc; -if (cxlr->mode !=CXL_DECODER_PMEM ) +if (cxlr->mode !=CXL_REGION_PMEM ) rc =sysfs_emit (buf,"\n" );else rc =sysfs_emit (buf,"%pUb\n" , &p->uuid);
@@ -457,7 +457,7 @@ static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,* Support tooling that expects to find a 'uuid' attribute for all * regions regardless of mode. */ -if (a == &dev_attr_uuid.attr && cxlr->mode !=CXL_DECODER_PMEM ) +if (a == &dev_attr_uuid.attr && cxlr->mode !=CXL_REGION_PMEM )return 0444 ;return a->mode; }
@@ -620,7 +620,7 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, {struct cxl_region *cxlr =to_cxl_region (dev); -return sysfs_emit (buf,"%s\n" ,cxl_decoder_mode_name (cxlr->mode)); +return sysfs_emit (buf,"%s\n" ,cxl_region_mode_name (cxlr->mode)); }static DEVICE_ATTR_RO (mode);
@@ -646,7 +646,7 @@ static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)/* ways, granularity and uuid (if PMEM) need to be set before HPA */ if (!p->interleave_ways || !p->interleave_granularity || - (cxlr->mode ==CXL_DECODER_PMEM &&uuid_is_null (&p->uuid))) + (cxlr->mode ==CXL_REGION_PMEM &&uuid_is_null (&p->uuid)))return -ENXIO ;div64_u64_rem (size, (u64 )SZ_256M * p->interleave_ways, &remainder);
@@ -1863,6 +1863,17 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)return rc; } +static bool cxl_modes_compatible (enum cxl_region_mode rmode, +enum cxl_decoder_mode dmode) +{ +if (rmode ==CXL_REGION_RAM && dmode ==CXL_DECODER_RAM ) +return true; +if (rmode ==CXL_REGION_PMEM && dmode ==CXL_DECODER_PMEM ) +return true; + +return false; +} +static int cxl_region_attach (struct cxl_region *cxlr,struct cxl_endpoint_decoder *cxled,int pos) {
@@ -1882,9 +1893,11 @@ static int cxl_region_attach(struct cxl_region *cxlr,return rc; } -if (cxled->mode != cxlr->mode) { -dev_dbg (&cxlr->dev,"%s region mode: %d mismatch: %d\n" , -dev_name (&cxled->cxld.dev), cxlr->mode, cxled->mode); +if (!cxl_modes_compatible (cxlr->mode, cxled->mode)) { +dev_dbg (&cxlr->dev,"%s region mode: %s mismatch decoder: %s\n" , +dev_name (&cxled->cxld.dev), +cxl_region_mode_name (cxlr->mode), +cxl_decoder_mode_name (cxled->mode));return -EINVAL ; }
@@ -2447,7 +2460,7 @@ static int cxl_region_calculate_adistance(struct notifier_block *nb,* devm_cxl_add_region - Adds a region to a decoder * @cxlrd: root decoder * @id: memregion id to create, or memregion_free() on failure -* @mode: mode for the endpoint decoders of this region +* @mode: mode of this region * @type: select whether this is an expander or accelerator (type-2 or type-3) * * This is the second step of region initialization. Regions exist within an
@@ -2458,7 +2471,7 @@ static int cxl_region_calculate_adistance(struct notifier_block *nb,*/ static struct cxl_region *devm_cxl_add_region (struct cxl_root_decoder *cxlrd,int id, -enum cxl_decoder_mode mode, +enum cxl_region_mode mode,enum cxl_decoder_type type) {struct cxl_port *port =to_cxl_port (cxlrd->cxlsd.cxld.dev.parent);
@@ -2512,16 +2525,17 @@ static ssize_t create_ram_region_show(struct device *dev, }static struct cxl_region *__create_region (struct cxl_root_decoder *cxlrd, -enum cxl_decoder_mode mode,int id) +enum cxl_region_mode mode,int id) {int rc;switch (mode) { -case CXL_DECODER_RAM : -case CXL_DECODER_PMEM : +case CXL_REGION_RAM : +case CXL_REGION_PMEM :break ;default : -dev_err (&cxlrd->cxlsd.cxld.dev,"unsupported mode %d\n" , mode); +dev_err (&cxlrd->cxlsd.cxld.dev,"unsupported mode %s\n" , +cxl_region_mode_name (mode));return ERR_PTR (-EINVAL ); }
@@ -2549,7 +2563,7 @@ static ssize_t create_pmem_region_store(struct device *dev,if (rc !=1 )return -EINVAL ; - cxlr =__create_region (cxlrd,CXL_DECODER_PMEM , id); + cxlr =__create_region (cxlrd,CXL_REGION_PMEM , id);if (IS_ERR (cxlr))return PTR_ERR (cxlr);
@@ -2569,7 +2583,7 @@ static ssize_t create_ram_region_store(struct device *dev,if (rc !=1 )return -EINVAL ; - cxlr =__create_region (cxlrd,CXL_DECODER_RAM , id); + cxlr =__create_region (cxlrd,CXL_REGION_RAM , id);if (IS_ERR (cxlr))return PTR_ERR (cxlr);
@@ -3215,6 +3229,22 @@ static int match_region_by_range(struct device *dev, void *data)return rc; } +static enum cxl_region_mode +cxl_decoder_to_region_mode (enum cxl_decoder_mode mode) +{ +switch (mode) { +case CXL_DECODER_NONE : +return CXL_REGION_NONE ; +case CXL_DECODER_RAM : +return CXL_REGION_RAM ; +case CXL_DECODER_PMEM : +return CXL_REGION_PMEM ; +case CXL_DECODER_MIXED : +default : +return CXL_REGION_MIXED ; + } +} +/* Establish an empty region covering the given HPA range */ static struct cxl_region *construct_region (struct cxl_root_decoder *cxlrd,struct cxl_endpoint_decoder *cxled)
@@ -3223,12 +3253,17 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,struct cxl_port *port =cxlrd_to_port (cxlrd);struct range *hpa = &cxled->cxld.hpa_range;struct cxl_region_params *p; +enum cxl_region_mode mode;struct cxl_region *cxlr;struct resource *res;int rc; +if (cxled->mode ==CXL_DECODER_DEAD ) +return ERR_PTR (-EINVAL ); + + mode =cxl_decoder_to_region_mode (cxled->mode);do { - cxlr =__create_region (cxlrd, cxled->mode, + cxlr =__create_region (cxlrd, mode,atomic_read (&cxlrd->region_id)); }while (IS_ERR (cxlr) &&PTR_ERR (cxlr) == -EBUSY );
@@ -3431,9 +3466,9 @@ static int cxl_region_probe(struct device *dev)return rc;switch (cxlr->mode) { -case CXL_DECODER_PMEM : +case CXL_REGION_PMEM :return devm_cxl_add_pmem_region (cxlr); -case CXL_DECODER_RAM : +case CXL_REGION_RAM :/* * The region can not be manged by CXL if any portion of * it is already online as 'System RAM'
@@ -3445,8 +3480,8 @@ static int cxl_region_probe(struct device *dev)return 0 ;return devm_cxl_add_dax_region (cxlr);default : -dev_dbg (&cxlr->dev,"unsupported region mode: %d\n" , - cxlr->mode); +dev_dbg (&cxlr->dev,"unsupported region mode: %s\n" , +cxl_region_mode_name (cxlr->mode));return -ENXIO ; } }
drivers/cxl/cxl.h +24 -2
@@ -388,6 +388,27 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)return "mixed" ; } +enum cxl_region_mode { +CXL_REGION_NONE , +CXL_REGION_RAM , +CXL_REGION_PMEM , +CXL_REGION_MIXED , +}; + +static inline const char *cxl_region_mode_name (enum cxl_region_mode mode) +{ +static const char *const names[] = { + [CXL_REGION_NONE ] ="none" , + [CXL_REGION_RAM ] ="ram" , + [CXL_REGION_PMEM ] ="pmem" , + [CXL_REGION_MIXED ] ="mixed" , + }; + +if (mode >=CXL_REGION_NONE && mode <=CXL_REGION_MIXED ) +return names[mode]; +return "mixed" ; +} +/* * Track whether this decoder is reserved for region autodiscovery, or * free for userspace provisioning.
@@ -515,7 +536,8 @@ struct cxl_region_params {* struct cxl_region - CXL region * @dev: This region's device * @id: This region's id. Id is globally unique across all regions -* @mode: Endpoint decoder allocation / access mode +* @mode: Region mode which defines which endpoint decoder modes the region is +* compatible with * @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
@@ -528,7 +550,7 @@ struct cxl_region_params {struct cxl_region {struct device dev;int id; -enum cxl_decoder_mode mode; +enum cxl_region_mode mode;enum cxl_decoder_type type;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_pmem_region *cxlr_pmem;
Signature · 1 line
2.45.2
PATCH v2 8/25 cxl/region: Add dynamic capacity decoder and region modes
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
One or more decoders each pointing to a Dynamic Capacity (DC) partition form a CXL software region. The region mode reflects composition of that entire software region. Decoder mode reflects a specific DC partition. DC partitions are also known as DC regions per CXL specification r3.1.
Define the new modes and helper functions required to make the association between these new modes.
---
Changes:
[iweiny: keep tags on simple patch]
[Fan: s/partitions/partition/]
[djiang: New wording for the commit message]
[iweiny: reword commit message more]
--- drivers/cxl/core/region.c | 4 ++++ drivers/cxl/cxl.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)
drivers/cxl/core/region.c +4 -0
@@ -1870,6 +1870,8 @@ static bool cxl_modes_compatible(enum cxl_region_mode rmode,return true;if (rmode ==CXL_REGION_PMEM && dmode ==CXL_DECODER_PMEM )return true; +if (rmode ==CXL_REGION_DC &&cxl_decoder_mode_is_dc (dmode)) +return true;return false; }
@@ -3239,6 +3241,8 @@ cxl_decoder_to_region_mode(enum cxl_decoder_mode mode)return CXL_REGION_RAM ;case CXL_DECODER_PMEM :return CXL_REGION_PMEM ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: +return CXL_REGION_DC ;case CXL_DECODER_MIXED :default :return CXL_REGION_MIXED ;
drivers/cxl/cxl.h +23 -0
@@ -370,6 +370,14 @@ enum cxl_decoder_mode {CXL_DECODER_NONE ,CXL_DECODER_RAM ,CXL_DECODER_PMEM , +CXL_DECODER_DC0 , +CXL_DECODER_DC1 , +CXL_DECODER_DC2 , +CXL_DECODER_DC3 , +CXL_DECODER_DC4 , +CXL_DECODER_DC5 , +CXL_DECODER_DC6 , +CXL_DECODER_DC7 ,CXL_DECODER_MIXED , CXL_DECODER_DEAD, };
@@ -380,6 +388,14 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode) [CXL_DECODER_NONE] = "none", [CXL_DECODER_RAM] = "ram", [CXL_DECODER_PMEM] = "pmem", + [CXL_DECODER_DC0] = "dc0", + [CXL_DECODER_DC1] = "dc1", + [CXL_DECODER_DC2] = "dc2", + [CXL_DECODER_DC3] = "dc3", + [CXL_DECODER_DC4] = "dc4", + [CXL_DECODER_DC5] = "dc5", + [CXL_DECODER_DC6] = "dc6", + [CXL_DECODER_DC7] = "dc7", [CXL_DECODER_MIXED] = "mixed", };
@@ -388,10 +404,16 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)return "mixed" ; } +static inline bool cxl_decoder_mode_is_dc (enum cxl_decoder_mode mode) +{ +return (mode >=CXL_DECODER_DC0 && mode <=CXL_DECODER_DC7 ); +} +enum cxl_region_mode {CXL_REGION_NONE ,CXL_REGION_RAM ,CXL_REGION_PMEM , +CXL_REGION_DC ,CXL_REGION_MIXED , };
@@ -401,6 +423,7 @@ static inline const char *cxl_region_mode_name(enum cxl_region_mode mode) [CXL_REGION_NONE] = "none", [CXL_REGION_RAM] = "ram", [CXL_REGION_PMEM] = "pmem", + [CXL_REGION_DC] = "dc", [CXL_REGION_MIXED] = "mixed", };
Signature · 1 line
2.45.2
PATCH v2 9/25 cxl/hdm: Add dynamic capacity size support to endpoint decoders
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
To support Dynamic Capacity Devices (DCD) endpoint decoders will need to map DC partitions (regions). In addition to assigning the size of the DC partition, the decoder must assign any skip value from the previous decoder. This must be done within a contiguous DPA space.
Two complications arise with Dynamic Capacity regions which did not exist with Ram and PMEM partitions. First, gaps in the DPA space can exist between and around the DC partitions. Second, the Linux resource tree does not allow a resource to be marked across existing nodes within a tree.
For clarity, below is an example of an 60GB device with 10GB of RAM, 10GB of PMEM and 10GB for each of 2 DC partitions. The desired CXL mapping is 5GB of RAM, 5GB of PMEM, and 5GB of DC1.
DPA RANGE
(dpa_res)
0GB 10GB 20GB 30GB 40GB 50GB 60GB
|----------|----------|----------|----------|----------|----------|RAM PMEM DC0 DC1 (ram_res) (pmem_res) (dc_res[0]) (dc_res[1])
|----------|----------| <gap> |----------| <gap> |----------|
RAM PMEM DC1
|XXXXX|----|XXXXX|----|----------|----------|----------|XXXXX-----| 0GB 5GB 10GB 15GB 20GB 30GB 40GB 50GB 60GB
The previous skip resource between RAM and PMEM was always a child of the RAM resource and fit nicely [see (S) below]. Because of this simplicity this skip resource reference was not stored in any CXL state. On release the skip range could be calculated based on the endpoint decoders stored values.
Now when DC1 is being mapped 4 skip resources must be created as children. One for the PMEM resource (A), two of the parent DPA resource (B,D), and one more child of the DC0 resource (C).
0GB 10GB 20GB 30GB 40GB 50GB 60GB
|----------|----------|----------|----------|----------|----------|
| |
|----------|----------| | |----------| | |----------|
| | | | |
(S) (A) (B) (C) (D)
v v v v v
|XXXXX|----|XXXXX|----|----------|----------|----------|XXXXX-----|
skip skip skip skip skipExpand the calculation of DPA free space and enhance the logic to support this more complex skipping. To track the potential of multiple skip resources an xarray is attached to the endpoint decoder. The existing algorithm between RAM and PMEM is consolidated within the new one to streamline the code even though the result is the storage of a single skip resource in the xarray.
---
Changes:
[Jonathan: Use an example only mapping 1/2 of DC1] [iweiny: Update cover letter]
[iweiny: Fix 0day bugs
https://lore.kernel.org/all/[email protected]/ [djbw/Jonathan: allow more than 1 region per DC partition] --- drivers/cxl/core/hdm.c | 196 ++++++++++++++++++++++++++++++++++++++++++++---- drivers/cxl/core/port.c | 2 + drivers/cxl/cxl.h | 2 + 3 files changed, 184 insertions(+), 16 deletions(-)
drivers/cxl/core/hdm.c +180 -16
@@ -223,6 +223,25 @@ void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds) }EXPORT_SYMBOL_NS_GPL (cxl_dpa_debug,CXL ); +static void cxl_skip_release (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds; +struct cxl_port *port =cxled_to_port (cxled); +struct device *dev = &port->dev; +unsigned long index; +void *entry; + +xa_for_each (&cxled->skip_res, index, entry) { +struct resource *res = entry; + +dev_dbg (dev,"decoder%d.%d: releasing skipped space; %pr\n" , + port->id, cxled->cxld.id, res); +__release_region (&cxlds->dpa_res, res->start, +resource_size (res)); +xa_erase (&cxled->skip_res, index); + } +} +/* * Must be called in a context that synchronizes against this decoder's * port ->remove() callback (like an endpoint decoder sysfs attribute)
@@ -233,15 +252,11 @@ static void __cxl_dpa_release(struct cxl_endpoint_decoder *cxled)struct cxl_port *port =cxled_to_port (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct resource *res = cxled->dpa_res; -resource_size_t skip_start;lockdep_assert_held_write (&cxl_dpa_rwsem); -/* save @skip_start, before @res is released */ - skip_start = res->start - cxled->skip;__release_region (&cxlds->dpa_res, res->start,resource_size (res)); -if (cxled->skip) -__release_region (&cxlds->dpa_res, skip_start, cxled->skip); +cxl_skip_release (cxled); cxled->skip =0 ; cxled->dpa_res =NULL ;put_device (&cxled->cxld.dev);
@@ -268,6 +283,105 @@ static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled)__cxl_dpa_release (cxled); } +static int dc_mode_to_region_index (enum cxl_decoder_mode mode) +{ +return mode -CXL_DECODER_DC0 ; +} + +static int cxl_request_skip (struct cxl_endpoint_decoder *cxled, +resource_size_t skip_base,resource_size_t skip_len) +{ +struct cxl_dev_state *cxlds =cxled_to_memdev (cxled)->cxlds; +const char *name =dev_name (&cxled->cxld.dev); +struct cxl_port *port =cxled_to_port (cxled); +struct resource *dpa_res = &cxlds->dpa_res; +struct device *dev = &port->dev; +struct resource *res; +int rc; + + res =__request_region (dpa_res, skip_base, skip_len, name,0 ); +if (!res) +return -EBUSY ; + + rc =xa_insert (&cxled->skip_res, skip_base, res,GFP_KERNEL ); +if (rc) { +__release_region (dpa_res, skip_base, skip_len); +return rc; + } + +dev_dbg (dev,"decoder%d.%d: skipped space; %pr\n" , + port->id, cxled->cxld.id, res); +return 0 ; +} + +static int cxl_reserve_dpa_skip (struct cxl_endpoint_decoder *cxled, +resource_size_t base,resource_size_t skipped) +{ +struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); +struct cxl_port *port =cxled_to_port (cxled); +struct cxl_dev_state *cxlds = cxlmd->cxlds; +resource_size_t skip_base = base - skipped; +struct device *dev = &port->dev; +resource_size_t skip_len =0 ; +int rc, index; + +if (resource_size (&cxlds->ram_res) && skip_base <= cxlds->ram_res.end) { + skip_len = cxlds->ram_res.end - skip_base +1 ; + rc =cxl_request_skip (cxled, skip_base, skip_len); +if (rc) +return rc; + skip_base += skip_len; + } + +if (skip_base == base) { +dev_dbg (dev,"skip done ram!\n" ); +return 0 ; + } + +if (resource_size (&cxlds->pmem_res) && + skip_base <= cxlds->pmem_res.end) { + skip_len = cxlds->pmem_res.end - skip_base +1 ; + rc =cxl_request_skip (cxled, skip_base, skip_len); +if (rc) +return rc; + skip_base += skip_len; + } + + index =dc_mode_to_region_index (cxled->mode); +for (int i =0 ; i <= index; i++) { +struct resource *dcr = &cxlds->dc_res[i]; + +if (skip_base < dcr->start) { + skip_len = dcr->start - skip_base; + rc =cxl_request_skip (cxled, skip_base, skip_len); +if (rc) +return rc; + skip_base += skip_len; + } + +if (skip_base == base) { +dev_dbg (dev,"skip done DC region %d!\n" , i); +break ; + } + +if (resource_size (dcr) && skip_base <= dcr->end) { +if (skip_base > base) { +dev_err (dev,"Skip error DC region %d; skip_base %pa; base %pa\n" , + i, &skip_base, &base); +return -ENXIO ; + } + + skip_len = dcr->end - skip_base +1 ; + rc =cxl_request_skip (cxled, skip_base, skip_len); +if (rc) +return rc; + skip_base += skip_len; + } + } + +return 0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)
@@ -305,13 +419,12 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, }if (skipped) { - res =__request_region (&cxlds->dpa_res, base - skipped, skipped, -dev_name (&cxled->cxld.dev),0 ); -if (!res) { -dev_dbg (dev, -"decoder%d.%d: failed to reserve skipped space\n" , - port->id, cxled->cxld.id); -return -EBUSY ; +int rc =cxl_reserve_dpa_skip (cxled, base, skipped); + +if (rc) { +dev_dbg (dev,"decoder%d.%d: failed to reserve skipped space; %pa - %pa\n" , + port->id, cxled->cxld.id, &base, &skipped); +return rc; } } res = __request_region(&cxlds->dpa_res, base, len,
@@ -319,14 +432,20 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,if (!res) {dev_dbg (dev,"decoder%d.%d: failed to reserve allocation\n" , port->id, cxled->cxld.id); -if (skipped) -__release_region (&cxlds->dpa_res, base - skipped, - skipped); +cxl_skip_release (cxled);return -EBUSY ; } cxled->dpa_res = res; cxled->skip = skipped; +for (int mode =CXL_DECODER_DC0 ; mode <=CXL_DECODER_DC7 ; mode++) { +int index =dc_mode_to_region_index (mode); + +if (resource_contains (&cxlds->dc_res[index], res)) { + cxled->mode = mode; + goto success; + } + }if (resource_contains (&cxlds->pmem_res, res)) cxled->mode =CXL_DECODER_PMEM ;else if (resource_contains (&cxlds->ram_res, res))
@@ -337,6 +456,9 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, cxled->mode =CXL_DECODER_MIXED ; } +success: +dev_dbg (dev,"decoder%d.%d: %pr mode: %d\n" , port->id, cxled->cxld.id, + cxled->dpa_res, cxled->mode); port->hdm_end++;get_device (&cxled->cxld.dev);return 0 ;
@@ -466,8 +588,8 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size) { -struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);resource_size_t free_ram_start, free_pmem_start; +struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_port *port =cxled_to_port (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev;
@@ -524,12 +646,54 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)else skip_end = start -1 ; skip = skip_end - skip_start +1 ; + }else if (cxl_decoder_mode_is_dc (cxled->mode)) { +int dc_index =dc_mode_to_region_index (cxled->mode); + +for (p = cxlds->dc_res[dc_index].child, last =NULL ; p; p = p->sibling) + last = p; + +if (last) { +/* +* Some capacity in this DC partition is already allocated, +* that allocation already handled the skip. +*/ + start = last->end +1 ; + skip =0 ; + }else { +/* Calculate skip */ +resource_size_t skip_start, skip_end; + + start = cxlds->dc_res[dc_index].start; + +if ((resource_size (&cxlds->pmem_res) ==0 ) || !cxlds->pmem_res.child) + skip_start = free_ram_start; +else + skip_start = free_pmem_start; +/* +* If any dc region is already mapped, then that allocation +* already handled the RAM and PMEM skip. Check for DC region +* skip. +*/ +for (int i = dc_index -1 ; i >=0 ; i--) { +if (cxlds->dc_res[i].child) { + skip_start = cxlds->dc_res[i].child->end +1 ; +break ; + } + } + + skip_end = start -1 ; + skip = skip_end - skip_start +1 ; + } + avail = cxlds->dc_res[dc_index].end - start +1 ; }else {dev_dbg (dev,"mode not set\n" ); rc = -EINVAL ; goto out; } +dev_dbg (dev,"DPA Allocation start: %pa len: %#llx Skip: %pa\n" , + &start, size, &skip); +if (size > avail) {dev_dbg (dev,"%pa exceeds available %s capacity: %pa\n" , &size,cxl_decoder_mode_name (cxled->mode), &avail);
drivers/cxl/core/port.c +2 -0
@@ -419,6 +419,7 @@ static void cxl_endpoint_decoder_release(struct device *dev)struct cxl_endpoint_decoder *cxled =to_cxl_endpoint_decoder (dev);__cxl_decoder_release (&cxled->cxld); +xa_destroy (&cxled->skip_res);kfree (cxled); }
@@ -1899,6 +1900,7 @@ struct cxl_endpoint_decoder *cxl_endpoint_decoder_alloc(struct cxl_port *port)return ERR_PTR (-ENOMEM ); cxled->pos =-1 ; +xa_init (&cxled->skip_res); cxld = &cxled->cxld; rc =cxl_decoder_init (port, cxld);if (rc) {
drivers/cxl/cxl.h +2 -0
@@ -446,6 +446,7 @@ enum cxl_decoder_state {* @cxld: base cxl_decoder_object * @dpa_res: actively claimed DPA span of this decoder * @skip: offset into @dpa_res where @cxld.hpa_range maps +* @skip_res: array of skipped resources from the previous decoder end * @mode: which memory type / access-mode-partition this decoder targets * @state: autodiscovery state * @pos: interleave position in @cxld.region
@@ -454,6 +455,7 @@ struct cxl_endpoint_decoder {struct cxl_decoder cxld;struct resource *dpa_res;resource_size_t skip; +struct xarray skip_res;enum cxl_decoder_mode mode;enum cxl_decoder_state state;int pos;
Signature · 1 line
2.45.2
PATCH v2 10/25 cxl/port: Add endpoint decoder DC mode support to sysfs
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
Endpoint decoder mode is used to represent the partition the decoder points to such as ram or pmem.
Expand the mode to allow a decoder to point to a specific DC partition (Region).
---
Changes:
[Fan: change mode range logic]
[Fan: use !resource_size()]
[djiang: use the static mode name string array in mode_store()] [Jonathan: remove rc check from mode to region index]
[Jonathan: clarify decoder mode 'mixed']
[djbw: drop cleanup patch and just follow the convention in cxl_dpa_set_mode()] [fan: make dcd resource size check similar to other partitions] [djbw, jonathan, fan: remove mode range check from dc_mode_to_region_index] [iweiny: push sysfs versions to 6.12]
--- Documentation/ABI/testing/sysfs-bus-cxl | 21 ++++++++++---------- drivers/cxl/core/hdm.c | 10 ++++++++++ drivers/cxl/core/port.c | 10 +++++----- drivers/cxl/cxl.h | 35 ++++++++++++++++++--------------- 4 files changed, 45 insertions(+), 31 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +11 -10
@@ -316,23 +316,24 @@ Description: What: /sys/bus/cxl/devices/decoderX.Y/mode -Date: May, 2022 -KernelVersion: v6.0 +Date: May, 2022, October 2024 +KernelVersion: v6.0, v6.12 (dcY) 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', - 'mixed', or 'none'. The 'mixed' indication is for error cases - when a decoder straddles the volatile/persistent partition - boundary, and 'none' indicates the decoder is not actively - decoding, or no DPA allocation policy has been set. + into a 'ram' (volatile memory) range, 'pmem' (persistent + memory) range, or Dynamic Capacity (DC) range. The 'mode' + attribute emits one of 'ram', 'pmem', 'dcY', 'mixed', or + 'none'. The 'mixed' indication is for error cases when a + decoder straddles partition boundaries, and '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 'ram', 'pmem', or 'dcY' to set the boundaries for + the next allocation. What: /sys/bus/cxl/devices/decoderX.Y/dpa_resource
drivers/cxl/core/hdm.c +10 -0
@@ -551,6 +551,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,switch (mode) {case CXL_DECODER_RAM :case CXL_DECODER_PMEM : + case CXL_DECODER_DC0 ... CXL_DECODER_DC7:break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);
@@ -578,6 +579,15 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, goto out; } +if (mode >=CXL_DECODER_DC0 && mode <=CXL_DECODER_DC7 ) { + rc =dc_mode_to_region_index (mode); +if (!resource_size (&cxlds->dc_res[rc])) { +dev_dbg (dev,"no available dynamic capacity\n" ); + rc = -ENXIO ; + goto out; + } + } + cxled->mode = mode; rc =0 ; out:
drivers/cxl/core/port.c +5 -5
@@ -205,11 +205,11 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr,enum cxl_decoder_mode mode;ssize_t rc; -if (sysfs_streq (buf,"pmem" )) - mode =CXL_DECODER_PMEM ; -else if (sysfs_streq (buf,"ram" )) - mode =CXL_DECODER_RAM ; -else +for (mode =CXL_DECODER_RAM ; mode <CXL_DECODER_MIXED ; mode++) +if (sysfs_streq (buf, cxl_decoder_mode_names[mode])) +break ; + +if (mode >=CXL_DECODER_MIXED )return -EINVAL ; rc =cxl_dpa_set_mode (cxled, mode);
drivers/cxl/cxl.h +19 -16
@@ -365,6 +365,9 @@ struct cxl_decoder {/* * CXL_DECODER_DEAD prevents endpoints from being reattached to regions * while cxld_unregister() is running +* +* NOTE: CXL_DECODER_RAM must be second and CXL_DECODER_MIXED must be last. +* See mode_store() */ enum cxl_decoder_mode {CXL_DECODER_NONE ,
@@ -382,25 +385,25 @@ enum cxl_decoder_mode { CXL_DECODER_DEAD, }; +static const char *const cxl_decoder_mode_names[] = { + [CXL_DECODER_NONE ] ="none" , + [CXL_DECODER_RAM ] ="ram" , + [CXL_DECODER_PMEM ] ="pmem" , + [CXL_DECODER_DC0 ] ="dc0" , + [CXL_DECODER_DC1 ] ="dc1" , + [CXL_DECODER_DC2 ] ="dc2" , + [CXL_DECODER_DC3 ] ="dc3" , + [CXL_DECODER_DC4 ] ="dc4" , + [CXL_DECODER_DC5 ] ="dc5" , + [CXL_DECODER_DC6 ] ="dc6" , + [CXL_DECODER_DC7 ] ="dc7" , + [CXL_DECODER_MIXED ] ="mixed" , +}; +static inline const char *cxl_decoder_mode_name (enum cxl_decoder_mode mode) { -static const char *const names[] = { - [CXL_DECODER_NONE ] ="none" , - [CXL_DECODER_RAM ] ="ram" , - [CXL_DECODER_PMEM ] ="pmem" , - [CXL_DECODER_DC0 ] ="dc0" , - [CXL_DECODER_DC1 ] ="dc1" , - [CXL_DECODER_DC2 ] ="dc2" , - [CXL_DECODER_DC3 ] ="dc3" , - [CXL_DECODER_DC4 ] ="dc4" , - [CXL_DECODER_DC5 ] ="dc5" , - [CXL_DECODER_DC6 ] ="dc6" , - [CXL_DECODER_DC7 ] ="dc7" , - [CXL_DECODER_MIXED ] ="mixed" , - }; -if (mode >=CXL_DECODER_NONE && mode <=CXL_DECODER_MIXED ) -return names[mode]; +return cxl_decoder_mode_names[mode];return "mixed" ; }
Signature · 1 line
2.45.2
PATCH v2 11/25 cxl/mem: Expose DCD partition capabilities in sysfs
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
To properly configure CXL regions on Dynamic Capacity Devices (DCD), user space will need to know the details of the DC partitions available.
Expose dynamic capacity capabilities through sysfs.
---
Changes:
[iweiny: remove review tags]
[Davidlohr/Fan/Jonathan: omit 'dc' attribute directory if device is not DC] [Jonathan: update documentation for dc visibility]
[Jonathan: Add a comment to DC region X attributes to ensure visibility checks work] [iweiny: push sysfs version to 6.12]
--- Documentation/ABI/testing/sysfs-bus-cxl | 12 ++++ drivers/cxl/core/memdev.c | 97 +++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +12 -0
@@ -54,6 +54,18 @@ Description: identically named field in the Identify Memory Device Output Payload in the CXL-2.0 specification. +What: /sys/bus/cxl/devices/memX/dc/region_count + /sys/bus/cxl/devices/memX/dc/regionY_size +Date: August, 2024 +KernelVersion: v6.12 +Contact: [email protected] +Description: + (RO) Dynamic Capacity (DC) region information. The dc + directory is only visible on devices which support Dynamic + Capacity. + The region_count is the number of Dynamic Capacity (DC) + partitions (regions) supported on the device. + regionY_size is the size of each of those partitions. What: /sys/bus/cxl/devices/memX/pmem/qos_class Date: May, 2023
drivers/cxl/core/memdev.c +97 -0
115 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v2 12/25 cxl/region: Refactor common create region code
In reply to Ira Weinycreate_pmem_region_store() and create_ram_region_store() are identical with the exception of the region mode. With the addition of DC region mode this would end up being 3 copies of the same code.
Refactor create_pmem_region_store() and create_ram_region_store() to use a single common function to be used in subsequent DC code.
--- drivers/cxl/core/region.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/cxl/core/region.c +11 -17
@@ -2553,9 +2553,8 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,return devm_cxl_add_region (cxlrd, id, mode,CXL_DECODER_HOSTONLYMEM ); } -static ssize_t create_pmem_region_store (struct device *dev, -struct device_attribute *attr, -const char *buf,size_t len) +static ssize_t create_region_store (struct device *dev,const char *buf, +size_t len,enum cxl_region_mode mode) {struct cxl_root_decoder *cxlrd =to_cxl_root_decoder (dev);struct cxl_region *cxlr;
@@ -2565,31 +2564,26 @@ static ssize_t create_pmem_region_store(struct device *dev,if (rc !=1 )return -EINVAL ; - cxlr =__create_region (cxlrd,CXL_REGION_PMEM , id); + cxlr =__create_region (cxlrd, mode, id);if (IS_ERR (cxlr))return PTR_ERR (cxlr);return len; } + +static ssize_t create_pmem_region_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +return create_region_store (dev, buf, len,CXL_REGION_PMEM ); +}DEVICE_ATTR_RW (create_pmem_region);static ssize_t create_ram_region_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t len) { -struct cxl_root_decoder *cxlrd =to_cxl_root_decoder (dev); -struct cxl_region *cxlr; -int rc, id; - - rc =sscanf (buf,"region%d\n" , &id); -if (rc !=1 ) -return -EINVAL ; - - cxlr =__create_region (cxlrd,CXL_REGION_RAM , id); -if (IS_ERR (cxlr)) -return PTR_ERR (cxlr); - -return len; +return create_region_store (dev, buf, len,CXL_REGION_RAM ); }DEVICE_ATTR_RW (create_ram_region);
Signature · 1 line
2.45.2
PATCH v2 13/25 cxl/region: Add sparse DAX region support
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
Dynamic Capacity CXL regions must allow memory to be added or removed dynamically. In addition to the quantity of memory available the location of the memory within a DC partition is dynamic based on the extents offered by a device. CXL DAX regions must accommodate the sparseness of this memory in the management of DAX regions and devices.
Introduce the concept of a sparse DAX region. Add a create_dc_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.
Sparse regions complicate the range mapping of dax devices. There is no known use case for range mapping on sparse regions. Avoid the complication by preventing range mapping of dax devices on sparse regions.
Interleaving is deferred for now. Add checks.
---
Changes:
[Fan: use single function for dc region store]
[djiang: avoid setting dev_size twice]
[djbw: Check DCD support and interleave restriction on region creation] [iweiny: squash patch : dax/region: Prevent range mapping allocation on sparse regions] [iwieny: remove reviews]
[iweiny: rebase to master]
[iweiny: push sysfs version to 6.12]
[iweiny: make cxled_to_mds inline]
--- Documentation/ABI/testing/sysfs-bus-cxl | 22 ++++++++-------- drivers/cxl/core/core.h | 12 +++++++++ drivers/cxl/core/port.c | 1 + drivers/cxl/core/region.c | 46 +++++++++++++++++++++++++++++++-- drivers/dax/bus.c | 10 +++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 16 ++++++++++-- 7 files changed, 93 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +11 -11
@@ -406,20 +406,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,dc}_region +Date: May, 2022, January, 2023, August 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.12 (dc) 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 Capacity + (DC) 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 +12 -0
@@ -4,15 +4,27 @@#ifndef __CXL_CORE_H__#define __CXL_CORE_H__ +#include <cxlmem.h> +extern const struct device_type cxl_nvdimm_bridge_type;extern const struct device_type cxl_nvdimm_type;extern const struct device_type cxl_pmu_type;extern struct attribute_group cxl_base_attribute_group; +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 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_dc_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
@@ -320,6 +320,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_dc_region) SET_CXL_REGION_ATTR(delete_region) NULL, };
drivers/cxl/core/region.c +44 -2
94 lines not on this page · raw message
drivers/dax/bus.c +10 -0
@@ -178,6 +178,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_sparse (struct dax_region *dax_region) +{ +return (dax_region->res.flags &IORESOURCE_DAX_SPARSE_CAP ) !=0 ; +} +bool static_dev_dax (struct dev_dax *dev_dax) {return is_static (dev_dax->region);
@@ -301,6 +306,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)lockdep_assert_held (&dax_region_rwsem); +if (is_sparse (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;
@@ -1373,6 +1381,8 @@ static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n)return 0 ;if (a == &dev_attr_mapping.attr &&is_static (dax_region))return 0 ; +if (a == &dev_attr_mapping.attr &&is_sparse (dax_region)) +return 0 ;if ((a == &dev_attr_align.attr || a == &dev_attr_size.attr) &&is_static (dax_region))return 0444 ;
drivers/dax/bus.h +1 -0
@@ -13,6 +13,7 @@ struct dax_region;/* dax bus specific ioresource flags */ #define IORESOURCE_DAX_STATIC BIT(0)#define IORESOURCE_DAX_KMEM BIT(1) +#define IORESOURCE_DAX_SPARSE_CAP BIT(2) struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct range *range, int target_node, unsigned int align,
drivers/dax/cxl.c +14 -2
@@ -13,19 +13,31 @@ static int cxl_dax_region_probe(struct device *dev)struct cxl_region *cxlr = cxlr_dax->cxlr;struct dax_region *dax_region;struct dev_dax_data data; +resource_size_t dev_size; +unsigned long flags;if (nid ==NUMA_NO_NODE ) nid =memory_add_physaddr_to_nid (cxlr_dax->hpa_range.start); + flags =IORESOURCE_DAX_KMEM ; +if (cxlr->mode ==CXL_REGION_DC ) + flags |=IORESOURCE_DAX_SPARSE_CAP ; + dax_region =alloc_dax_region (dev, cxlr->id, &cxlr_dax->hpa_range, nid, -PMD_SIZE ,IORESOURCE_DAX_KMEM ); +PMD_SIZE , flags);if (!dax_region)return -ENOMEM ; +if (cxlr->mode ==CXL_REGION_DC ) +/* 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.45.2
PATCH v2 14/25 cxl/events: Split event msgnum configuration from irq setup
In reply to Ira WeinyDynamic 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.
--- drivers/cxl/pci.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/cxl/pci.c +12 -12
@@ -698,35 +698,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;
@@ -745,7 +741,7 @@ static bool cxl_event_int_is_fw(u8 setting)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 };int rc;/*
@@ -773,11 +769,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.45.2
PATCH v2 15/25 cxl/pci: Factor out interrupt policy check
In reply to Ira WeinyDynamic 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:
[iweiny: reword commit message]
[iweiny: keep review tags on simple patch]
--- drivers/cxl/pci.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/cxl/pci.c +16 -7
@@ -738,6 +738,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) {
@@ -760,14 +775,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.45.2
PATCH v2 16/25 cxl/mem: Configure dynamic capacity interrupts
In reply to Ira WeinyFrom: Navneet Singh <[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.
---
Changes:
[iweiny: update commit message]
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]
[Jonathan: formatting fix]
[Fan: add text to debug print]
[djiang: make dcd helpers inline]
--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 12 deletions(-)
drivers/cxl/cxlmem.h +2 -0
@@ -225,7 +225,9 @@ struct cxl_event_interrupt_policy {u8 warn_settings;u8 failure_settings;u8 fatal_settings; +u8 dcd_settings; } __packed; +#define CXL_EVENT_INT_POLICY_BASE_SIZE 4/* info, warn, failure, fatal */ /** * struct cxl_event_state - Event log driver state
drivers/cxl/pci.c +60 -12
127 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v2 17/25 cxl/core: Return endpoint decoder information from region search
In reply to Ira Weinycxl_dpa_to_region() finds the region from a <DPA, device> tuple. The search involves finding the device endpoint decoder as well.
Dyanmic 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.
--- 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
@@ -39,7 +39,8 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);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);
@@ -50,7 +51,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
@@ -909,7 +909,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,guard (rwsem_read)(&cxl_dpa_rwsem); 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) hpa =cxl_dpa_to_hpa (cxlr, cxlmd, dpa);
drivers/cxl/core/memdev.c +2 -2
@@ -323,7 +323,7 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa)if (rc) goto out; - cxlr =cxl_dpa_to_region (cxlmd, dpa); + cxlr =cxl_dpa_to_region (cxlmd, dpa,NULL );if (cxlr) dev_warn_once(mds->cxlds.dev, "poison inject dpa:%#llx region: %s\n", dpa,
@@ -387,7 +387,7 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa)if (rc) goto out; - cxlr =cxl_dpa_to_region (cxlmd, dpa); + cxlr =cxl_dpa_to_region (cxlmd, dpa,NULL );if (cxlr) dev_warn_once(mds->cxlds.dev, "poison clear dpa:%#llx region: %s\n", dpa,
drivers/cxl/core/region.c +7 -1
@@ -2828,6 +2828,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)
@@ -2861,11 +2862,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;
@@ -2877,6 +2880,9 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)if (port &&is_cxl_endpoint (port) &&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.45.2
PATCH v2 18/25 cxl/extent: Process DCD events and realize region extents
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
A dynamic capacity device (DCD) sends events to signal the host for changes in the availability of Dynamic Capacity (DC) memory. These events contain extents describing a DPA range and meta data for memory to be added or removed. Events may be sent from the device at any time.
Three types of events can be signaled, Add, Release, and Force Release.
On add, the host may accept or reject the memory being offered. If no region exists, or the extent is invalid, the extent should be rejected. Add extent events may be grouped by a 'more' bit which indicates those extents should be processed as a group.
On remove, the host can delay the response until the host is safely not using the memory. If no region exists the release can be sent immediately. The host may also release extents (or partial extents) at any time. Thus the 'more' bit grouping of release events is of less value and can be ignored in favor of sending multiple release capacity responses for groups of release events.
Force removal is intended as a mechanism between the FM and the device and intended only when the host is unresponsive, out of sync, or otherwise broken. Purposely ignore force removal events.
Regions are made up of one or more devices which may be surfacing memory to the host. Once all devices in a region have surfaced an extent the region can expose a corresponding extent for the user to consume. Without interleaving a device extent forms a 1:1 relationship with the region extent. Immediately surface a region extent upon getting a device extent.
Per the specification the device is allowed to offer or remove extents at any time. However, anticipated use cases can expect extents to be offered, accepted, and removed in well defined chunks.
Simplify extent tracking with the following restrictions.
1) Flag for removal any extent which overlaps a requested release range.
2) Refuse the offer of extents which overlap already accepted memory ranges.
3) Accept again a range which has already been accepted by the host. (It is likely the device has an error because it should already know that this range was accepted. But from the host point of view it is safe to acknowledge that acceptance again.)
Management of the region extent devices must be synchronized with potential uses of the memory within the DAX layer. Create region extent devices as children of the cxl_dax_region device such that the DAX region driver can co-drive them and synchronize with the DAX layer. Synchronization and management is handled in a subsequent patch.
Process DCD events and create region devices.
---
Changes:
[iweiny: combine this with the extent surface patches to better show the
lifetime extent objects in review]
[iweiny: clean up commit message.]
[iweiny: move extent verification of the 'read extents on region
creation' to this patch]
[iweiny: Provide for a common path for extent realization between an add
event and adding existing extents.]
[iweiny: Persist a check that an extent is within an endpoint decoder] [iweiny: reduce exported and non-static calls]
[iweiny: use %par]
<Combined comments from the old patches which were addressed>
[Jonathan: implement the more bit with a simple algorithm which accepts
all extents it can.
Also include the response more bit to prevent payload overflow]
[Fan: Do not error if a contained extent is added.] [Jonathan: allocate ida after kzalloc]
[iweiny: fix ida resource leak]
[fan/djiang: remove unneeded memset]
[djiang: fix indentation]
[Jonathan: Fix indentation]
[Jonathan/djbw: make tag a uuid]
[djbw: create helper calc_hpa_range() straight away]
[djbw: Allow for multiple cxled_extents per region_extent] [djbw: s/cxl_ed/cxled]
[djbw: s/cxl_release_ed_extent/cxled_release_extent/]
[djbw: s/reg_ext/region_extent/]
[djbw: s/dc_extent/extent/]
[Gregory/djbw: reject shared extents]
[iweiny: predicate extent.c compile on CONFIG_CXL_REGION]
--- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 13 ++ drivers/cxl/core/extent.c | 345 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/mbox.c | 268 ++++++++++++++++++++++++++++++++++- drivers/cxl/core/region.c | 6 + drivers/cxl/cxl.h | 52 ++++++- drivers/cxl/cxlmem.h | 26 ++++ include/linux/cxl-event.h | 32 +++++ tools/testing/cxl/Kbuild | 3 +- 9 files changed, 743 insertions(+), 4 deletions(-)
drivers/cxl/core/Makefile +1 -1
@@ -15,4 +15,4 @@ 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 +cxl_core-$(CONFIG_CXL_REGION) += region.o extent.o
drivers/cxl/core/core.h +13 -0
@@ -44,12 +44,24 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa,u64 cxl_dpa_to_hpa (struct cxl_region *cxlr,const struct cxl_memdev *cxlmd,u64 dpa); +int cxl_add_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent); +int cxl_rm_extent (struct cxl_memdev_state *mds,struct cxl_extent *extent);#else static inline u64 cxl_dpa_to_hpa (struct cxl_region *cxlr,const struct cxl_memdev *cxlmd,u64 dpa) {return ULLONG_MAX ; } +static inline int cxl_add_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +return 0 ; +} +static inline int cxl_rm_extent (struct cxl_memdev_state *mds, +struct cxl_extent *extent) +{ +return 0 ; +}static inline struct cxl_region *cxl_dpa_to_region (const struct cxl_memdev *cxlmd,u64 dpa,struct cxl_endpoint_decoder **cxled)
@@ -121,5 +133,6 @@ long cxl_pci_get_latency(struct pci_dev *pdev);int cxl_update_hmat_access_coordinates (int nid,struct cxl_region *cxlr,enum access_coordinate_class access);bool cxl_need_node_perf_attrs_update (int nid); +void memdev_release_extent (struct cxl_memdev_state *mds,struct range *range);#endif /* __CXL_CORE_H__ */
drivers/cxl/core/extent.c new file +345 -0
345 lines not on this page · raw message
drivers/cxl/core/mbox.c +267 -1
306 lines not on this page · raw message
drivers/cxl/core/region.c +6 -0
@@ -3037,6 +3037,7 @@ static void cxl_dax_region_release(struct device *dev) {struct cxl_dax_region *cxlr_dax =to_cxl_dax_region (dev); +ida_destroy (&cxlr_dax->extent_ida);kfree (cxlr_dax); }
@@ -3090,6 +3091,8 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) dev = &cxlr_dax->dev; cxlr_dax->cxlr = cxlr; + cxlr->cxlr_dax = cxlr_dax; +ida_init (&cxlr_dax->extent_ida);device_initialize (dev);lockdep_set_class (&dev->mutex, &cxl_dax_region_key);device_set_pm_not_required (dev);
@@ -3190,7 +3193,10 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax; +struct cxl_region *cxlr = cxlr_dax->cxlr; + cxlr->cxlr_dax =NULL ; + cxlr_dax->cxlr =NULL ;device_unregister (&cxlr_dax->dev); }
drivers/cxl/cxl.h +51 -1
98 lines not on this page · raw message
drivers/cxl/cxlmem.h +26 -0
@@ -497,6 +497,7 @@ struct cxl_dc_region_info {* @pmem_perf: performance data entry matched to PMEM partition * @nr_dc_region: number of DC regions implemented in the memory device * @dc_region: array containing info about the DC regions +* @pending_extents: array of extents pending during more bit processing * @event: event log driver state * @poison: poison driver state info * @security: security driver state info
@@ -532,6 +533,7 @@ struct cxl_memdev_state {u8 nr_dc_region;struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct xarray pending_extents;struct cxl_event_state event;struct cxl_poison_state poison;
@@ -607,6 +609,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[]; +} __packed; +struct cxl_mbox_get_supported_logs {__le16 entries;u8 rsvd[6 ];
@@ -669,6 +686,14 @@ struct cxl_mbox_identify {UUID_INIT (0xfe927475 ,0xdd59 ,0x4339 ,0xa5 ,0x86 ,0x79 ,0xba ,0xb1 , \0x13 ,0xb7 ,0x74 ) +/* +* 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
@@ -694,6 +719,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/linux/cxl-event.h +32 -0
@@ -96,11 +96,43 @@ struct cxl_event_mem_module {u8 reserved[0x3d ]; } __packed; +/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51 +*/ +#define CXL_EXTENT_TAG_LEN 0x10 +struct cxl_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[0x6 ]; +} __packed; + +/* +* 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 region_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_dcd dcd;/* dram & gen_media event header */ struct cxl_event_media_hdr media_hdr; } __packed;
tools/testing/cxl/Kbuild +2 -1
@@ -61,7 +61,8 @@ 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-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o \ + $(CXL_CORE_SRC)/extent.o cxl_core-y += config_check.o cxl_core-y += cxl_core_test.o cxl_core-y += cxl_core_exports.o
Signature · 1 line
2.45.2
PATCH v2 19/25 cxl/region/extent: Expose region extent information in sysfs
In reply to Ira WeinyFrom: Navneet Singh <[email protected]>
Extent information can be helpful to the user to coordinate memory usage with the external orchestrator and FM.
Expose the details of region extents by creating the following sysfs entries.
/sys/bus/cxl/devices/dax_regionX/extentX.Y /sys/bus/cxl/devices/dax_regionX/extentX.Y/offset /sys/bus/cxl/devices/dax_regionX/extentX.Y/length /sys/bus/cxl/devices/dax_regionX/extentX.Y/tag
---
Changes:
[iweiny: split this out]
[Jonathan: add documentation for extent sysfs] [Jonathan/djbw: s/label/tag]
[Jonathan/djbw: treat tag as uuid]
[djbw: use __ATTRIBUTE_GROUPS]
[djbw: make tag invisible if it is empty] [djbw/iweiny: use conventional id names for extents; extentX.Y]
--- Documentation/ABI/testing/sysfs-bus-cxl | 13 ++++++++ drivers/cxl/core/extent.c | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +13 -0
@@ -599,3 +599,16 @@ Description: See Documentation/ABI/stable/sysfs-devices-node. access0 provides the number to the closest initiator and access1 provides the number to the closest CPU. + +What: /sys/bus/cxl/devices/dax_regionX/extentX.Y/offset + /sys/bus/cxl/devices/dax_regionX/extentX.Y/length + /sys/bus/cxl/devices/dax_regionX/extentX.Y/tag +Date: October, 2024 +KernelVersion: v6.12 +Contact: [email protected] +Description: + (RO) [For Dynamic Capacity regions only] Extent offset and + length within the region. 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.
drivers/cxl/core/extent.c +58 -0
70 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v2 20/25 dax/bus: Factor out dev dax resize logic
In reply to Ira WeinyDynamic Capacity regions must limit dev dax resources to those areas which have extents backing real memory. Such DAX regions are dubbed 'sparse' regions. In order to manage where memory is available four alternatives were considered:
1) Create a single region resource child on region creation which reserves the entire region. Then as extents are added punch holes in this reservation. This requires new resource manipulation to punch the holes and still requires an additional iteration over the extent areas which may already have existing dev dax resources used.
2) Maintain an ordered xarray of extents which can be queried while processing the resize logic. The issue is that existing region->res children may artificially limit the allocation size sent to alloc_dev_dax_range(). IE the resource children can't be directly used in the resize logic to find where space in the region is. This also poses a problem of managing the available size in 2 places.
3) Maintain a separate resource tree with extents. This option is the same as 2) but with the different data structure. Most ideally there should be a unified representation of the resource tree not two places to look for space.
4) Create region resource children for each extent. Manage the dax dev resize logic in the same way as before but use a region child (extent) resource as the parents to find space within each extent.
Option 4 can leverage the existing resize algorithm to find space within the extents. It manages the available space in a singular resource tree which is less complicated for finding space.
In preparation for this change, factor out the dev_dax_resize logic. For static regions use dax_region->res as the parent to find space for the dax ranges. Future patches will use the same algorithm with individual extent resources as the parent.
---
Changes:
[iweiny: Rebase on new DAX region locking]
[iweiny: Reword commit message]
[iweiny: Drop reviews]
--- drivers/dax/bus.c | 129 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 50 deletions(-)
drivers/dax/bus.c +79 -50
@@ -844,11 +844,9 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id)return 0 ; } -static int alloc_dev_dax_range (struct dev_dax *dev_dax,u64 start, -resource_size_t size) +static int alloc_dev_dax_range (struct resource *parent,struct dev_dax *dev_dax, +u64 start,resource_size_t size) { -struct dax_region *dax_region = dev_dax->region; -struct resource *res = &dax_region->res;struct device *dev = &dev_dax->dev;struct dev_dax_range *ranges;unsigned long pgoff =0 ;
@@ -866,14 +864,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start,return 0 ; } - alloc =__request_region (res, start, size,dev_name (dev),0 ); + alloc =__request_region (parent, start, size,dev_name (dev),0 );if (!alloc)return -ENOMEM ; ranges =krealloc (dev_dax->ranges,sizeof (*ranges) * (dev_dax->nr_range +1 ),GFP_KERNEL );if (!ranges) { -__release_region (res, alloc->start,resource_size (alloc)); +__release_region (parent, alloc->start,resource_size (alloc));return -ENOMEM ; }
@@ -1026,50 +1024,45 @@ static bool adjust_ok(struct dev_dax *dev_dax, struct resource *res)return true; } -static ssize_t dev_dax_resize (struct dax_region *dax_region, -struct dev_dax *dev_dax,resource_size_t size) +/** +* dev_dax_resize_static - Expand the device into the unused portion of the +* region. This may involve adjusting the end of an existing resource, or +* allocating a new resource. +* +* @parent: parent resource to allocate this range in +* @dev_dax: DAX device to be expanded +* @to_alloc: amount of space to alloc; must be <= space available in @parent +* +* Return the amount of space allocated or -ERRNO on failure +*/ +static ssize_t dev_dax_resize_static (struct resource *parent, +struct dev_dax *dev_dax, +resource_size_t to_alloc) { -resource_size_t avail =dax_region_avail_size (dax_region), to_alloc; -resource_size_t dev_size =dev_dax_size (dev_dax); -struct resource *region_res = &dax_region->res; -struct device *dev = &dev_dax->dev;struct resource *res, *first; -resource_size_t alloc =0 ;int rc; -if (dev->driver) -return -EBUSY ; -if (size == dev_size) -return 0 ; -if (size > dev_size && size - dev_size > avail) -return -ENOSPC ; -if (size < dev_size) -return dev_dax_shrink (dev_dax, size); - - to_alloc = size - dev_size; -if (dev_WARN_ONCE (dev, !alloc_is_aligned (dev_dax, to_alloc), -"resize of %pa misaligned\n" , &to_alloc)) -return -ENXIO ; - -/* -* Expand the device into the unused portion of the region. This -* may involve adjusting the end of an existing resource, or -* allocating a new resource. -*/ -retry: - first = region_res->child; -if (!first) -return alloc_dev_dax_range (dev_dax, dax_region->res.start, to_alloc); + first = parent->child; +if (!first) { + rc =alloc_dev_dax_range (parent, dev_dax, + parent->start, to_alloc); +if (rc) +return rc; +return to_alloc; + } - rc = -ENOSPC ;for (res = first; res; res = res->sibling) {struct resource *next = res->sibling; +resource_size_t alloc;/* space at the beginning of the region */ -if (res == first && res->start > dax_region->res.start) { - alloc =min (res->start - dax_region->res.start, to_alloc); - rc =alloc_dev_dax_range (dev_dax, dax_region->res.start, alloc); -break ; +if (res == first && res->start > parent->start) { + alloc =min (res->start - parent->start, to_alloc); + rc =alloc_dev_dax_range (parent, dev_dax, + parent->start, alloc); +if (rc) +return rc; +return alloc; } alloc =0 ;
@@ -1078,21 +1071,55 @@ static ssize_t dev_dax_resize(struct dax_region *dax_region, alloc =min (next->start - (res->end +1 ), to_alloc);/* space at the end of the region */ -if (!alloc && !next && res->end < region_res->end) - alloc =min (region_res->end - res->end, to_alloc); +if (!alloc && !next && res->end < parent->end) + alloc =min (parent->end - res->end, to_alloc);if (!alloc)continue ;if (adjust_ok (dev_dax, res)) { rc =adjust_dev_dax_range (dev_dax, res,resource_size (res) + alloc); -break ; +if (rc) +return rc; +return alloc; } - rc =alloc_dev_dax_range (dev_dax, res->end +1 , alloc); -break ; + rc =alloc_dev_dax_range (parent, dev_dax, res->end +1 , alloc); +if (rc) +return rc; +return alloc; } -if (rc) -return rc; + +/* available was already calculated and should never be an issue */ +dev_WARN_ONCE (&dev_dax->dev,1 ,"space not found?" ); +return 0 ; +} + +static ssize_t dev_dax_resize (struct dax_region *dax_region, +struct dev_dax *dev_dax,resource_size_t size) +{ +resource_size_t avail =dax_region_avail_size (dax_region), to_alloc; +resource_size_t dev_size =dev_dax_size (dev_dax); +struct device *dev = &dev_dax->dev; +resource_size_t alloc =0 ; + +if (dev->driver) +return -EBUSY ; +if (size == dev_size) +return 0 ; +if (size > dev_size && size - dev_size > avail) +return -ENOSPC ; +if (size < dev_size) +return dev_dax_shrink (dev_dax, size); + + to_alloc = size - dev_size; +if (dev_WARN_ONCE (dev, !alloc_is_aligned (dev_dax, to_alloc), +"resize of %pa misaligned\n" , &to_alloc)) +return -ENXIO ; + +retry: + alloc =dev_dax_resize_static (&dax_region->res, dev_dax, to_alloc); +if (alloc <=0 ) +return alloc; to_alloc -= alloc;if (to_alloc) goto retry;
@@ -1198,7 +1225,8 @@ static ssize_t mapping_store(struct device *dev, struct device_attribute *attr, to_alloc =range_len (&r);if (alloc_is_aligned (dev_dax, to_alloc)) - rc =alloc_dev_dax_range (dev_dax, r.start, to_alloc); + rc =alloc_dev_dax_range (&dax_region->res, dev_dax, r.start, + to_alloc);up_write (&dax_dev_rwsem);up_write (&dax_region_rwsem);
@@ -1466,7 +1494,8 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data)device_initialize (dev);dev_set_name (dev,"dax%d.%d" , dax_region->id, dev_dax->id); - rc =alloc_dev_dax_range (dev_dax, dax_region->res.start, data->size); + rc =alloc_dev_dax_range (&dax_region->res, dev_dax, dax_region->res.start, + data->size);if (rc) goto err_range;
Signature · 1 line
2.45.2
PATCH v2 21/25 dax/region: Create resources on sparse DAX regions
In reply to Ira WeinyDAX regions which map dynamic capacity partitions require that memory be allowed to come and go. Recall sparse regions were created for this purpose. Now that extents can be realized within DAX regions the DAX region driver can start tracking sub-resource information.
The tight relationship between DAX region operations and extent operations require memory changes to be controlled synchronously with the user of the region. Synchronize through the dax_region_rwsem and by having the region driver drive both the region device as well as the extent sub-devices.
Recall requests to remove extents can happen at any time and that a host is not obligated to release the memory until it is not being used. If an extent is not used allow a release response.
The DAX layer has no need for the details of the CXL memory extent devices. Expose extents to the DAX layer as device children of the DAX region device. A single callback from the driver aids the DAX layer to determine if the child device is an extent. The DAX layer also registers a devres function to automatically clean up when the device is removed from the region.
There is a race between extents being surfaced and the dax_cxl driver being loaded. The driver must therefore scan for any existing extents while still under the device lock.
Respond to extent notifications. Manage the DAX region resource tree based on the extents lifetime. Return the status of remove notifications to lower layers such that it can manage the hardware appropriately.
---
Changes:
[iweiny: patch reorder]
[iweiny: move hunks from other patches to clarify code changes and
add/release flows WRT dax regions]
[iweiny: use %par]
[iweiny: clean up variable names]
[iweiny: Simplify sparse_ops]
[Fan: avoid open coding range_len()]
[djbw: s/reg_ext/region_extent]
--- drivers/cxl/core/extent.c | 76 +++++++++++++-- drivers/cxl/cxl.h | 6 ++ drivers/dax/bus.c | 243 +++++++++++++++++++++++++++++++++++++++++----- drivers/dax/bus.h | 3 +- drivers/dax/cxl.c | 63 +++++++++++- drivers/dax/dax-private.h | 34 +++++++ drivers/dax/hmem/hmem.c | 2 +- drivers/dax/pmem.c | 2 +- 8 files changed, 391 insertions(+), 38 deletions(-)
drivers/cxl/core/extent.c +70 -6
@@ -271,20 +271,67 @@ static void calc_hpa_range(struct cxl_endpoint_decoder *cxled, hpa_range->end = hpa_range->start +range_len (dpa_range) -1 ; } +static int cxlr_notify_extent (struct cxl_region *cxlr,enum dc_event event, +struct region_extent *region_extent) +{ +struct cxl_dax_region *cxlr_dax; +struct device *dev; +int rc =0 ; + + cxlr_dax = cxlr->cxlr_dax; + dev = &cxlr_dax->dev; +dev_dbg (dev,"Trying notify: type %d HPA %par\n" , + event, ®ion_extent->hpa_range); + +/* +* NOTE the lack of a driver indicates a notification has failed. No +* user space coordiantion was possible. +*/ +device_lock (dev); +if (dev->driver) { +struct cxl_driver *driver =to_cxl_drv (dev->driver); +struct cxl_notify_data notify_data = (struct cxl_notify_data ) { + .event = event, + .region_extent = region_extent, + }; + +if (driver->notify) { +dev_dbg (dev,"Notify: type %d HPA %par\n" , + event, ®ion_extent->hpa_range); + rc = driver->notify (dev, ¬ify_data); + } + } +device_unlock (dev); +return rc; +} + +struct rm_data { +struct cxl_region *cxlr; +struct range *range; +}; +static int cxlr_rm_extent (struct device *dev,void *data) {struct region_extent *region_extent =to_region_extent (dev); -struct range *region_hpa_range = data; +struct rm_data *rm_data = data; +int rc;if (!region_extent)return 0 ;/* -* Any extent which 'touches' the released range is removed. +* Any extent which 'touches' the released range is attempted to be +* removed. */ -if (range_overlaps (region_hpa_range, ®ion_extent->hpa_range)) { +if (range_overlaps (rm_data->range, ®ion_extent->hpa_range)) { +struct cxl_region *cxlr = rm_data->cxlr; +dev_dbg (dev,"Remove region extent HPA %par\n" , ®ion_extent->hpa_range); + rc =cxlr_notify_extent (cxlr,DCD_RELEASE_CAPACITY , region_extent); +if (rc == -EBUSY ) +return 0 ; +/* Extent not in use or error, remove it */ region_rm_extent (region_extent); }return 0 ;
@@ -312,8 +359,13 @@ int cxl_rm_extent(struct cxl_memdev_state *mds, struct cxl_extent *extent)calc_hpa_range (cxled, cxlr->cxlr_dax, &dpa_range, &hpa_range); +struct rm_data rm_data = { + .cxlr = cxlr, + .range = &hpa_range, + }; +/* Remove region extents which overlap */ -return device_for_each_child (&cxlr->cxlr_dax->dev, &hpa_range, +return device_for_each_child (&cxlr->cxlr_dax->dev, &rm_data, cxlr_rm_extent); }
@@ -338,8 +390,20 @@ static int cxlr_add_extent(struct cxl_dax_region *cxlr_dax,return rc; } -/* device model handles freeing region_extent */ -return online_region_extent (region_extent); + rc =online_region_extent (region_extent); +/* device model handled freeing region_extent */ +if (rc) +return rc; + + rc =cxlr_notify_extent (cxlr_dax->cxlr,DCD_ADD_CAPACITY , region_extent); +/* +* The region device was breifly live but DAX layer ensures it was not +* used +*/ +if (rc) +region_rm_extent (region_extent); + +return rc; }/* Callers are expected to ensure cxled has been attached to a region */
drivers/cxl/cxl.h +6 -0
@@ -916,10 +916,16 @@ bool is_cxl_region(struct device *dev);extern struct bus_type cxl_bus_type; +struct cxl_notify_data { +enum dc_event event; +struct region_extent *region_extent; +}; +struct cxl_driver {const char *name;int (*probe)(struct device *dev);void (*remove)(struct device *dev); +int (*notify)(struct device *dev,struct cxl_notify_data *notify_data);struct device_driver drv;int id; };
drivers/dax/bus.c +217 -26
376 lines not on this page · raw message
drivers/dax/bus.h +2 -1
@@ -9,6 +9,7 @@ struct dev_dax;struct resource ;struct dax_device ;struct dax_region ; +struct dax_sparse_ops ;/* dax bus specific ioresource flags */ #define IORESOURCE_DAX_STATIC BIT(0)
@@ -17,7 +18,7 @@ struct dax_region;struct dax_region *alloc_dax_region (struct device *parent,int region_id,struct range *range,int target_node,unsigned int align, -unsigned long flags); +unsigned long flags,struct dax_sparse_ops *sparse_ops);struct dev_dax_data {struct dax_region *dax_region;
drivers/dax/cxl.c +60 -3
86 lines not on this page · raw message
drivers/dax/dax-private.h +34 -0
@@ -16,6 +16,36 @@ struct inode *dax_inode(struct dax_device *dax_dev);int dax_bus_init (void );void dax_bus_exit (void ); +/** +* struct dax_resource - For sparse regions; an active resource +* @region: dax_region this resources is in +* @res: resource +* @use_cnt: count the number of uses of this resource +* +* Changes to the dax_reigon and the dax_resources within it are protected by +* dax_region_rwsem +*/ +struct dax_resource { +struct dax_region *region; +struct resource *res; +unsigned int use_cnt; +}; +int dax_region_add_resource (struct dax_region *dax_region,struct device *dev, +resource_size_t start,resource_size_t length); +int dax_region_rm_resource (struct dax_region *dax_region, +struct device *dev); +resource_size_t dax_avail_size (struct resource *dax_resource); + +typedef int (*match_cb )(struct device *dev,resource_size_t *size_avail); + +/** +* struct dax_sparse_ops - Operations for sparse regions +* @is_extent: return if the device is an extent +*/ +struct dax_sparse_ops { +bool (*is_extent)(struct device *dev); +}; +/** * struct dax_region - mapping infrastructure for dax devices * @id: kernel-wide unique region for a memory range
@@ -27,6 +57,7 @@ void dax_bus_exit(void);* @res: resource tree to track instance allocations * @seed: allow userspace to find the first unbound seed device * @youngest: allow userspace to find the most recently created device +* @sparse_ops: operations required for sparse regions */ struct dax_region {int id;
@@ -38,6 +69,7 @@ struct dax_region {struct resource res;struct device *seed;struct device *youngest; +struct dax_sparse_ops *sparse_ops; };struct dax_mapping {
@@ -62,6 +94,7 @@ struct dax_mapping {* @pgoff: page offset * @range: resource-span * @mapping: device to assist in interrogating the range layout +* @dax_resource: if not NULL; dax sparse resource containing this range */ struct dev_dax {struct dax_region *region;
@@ -79,6 +112,7 @@ struct dev_dax {unsigned long pgoff;struct range range;struct dax_mapping *mapping; +struct dax_resource *dax_resource; } *ranges; };
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
@@ -54,7 +54,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.45.2
Please ignore this series __and__ the RESEND.
The series did not get sent properly. Something went wrong with my smtp server in the middle.
[PATCH v2 22/25] cxl/region: Read existing extents on region creation
CRITICAL: Error running /usr/bin/msmtp -i: msmtp: cannot locate host smtpauth.intel.com: No address associated with hostname
msmtp: could not send mail (account default from /home/iweiny/.msmtprc)
Then I used b4 --resend v2. But glossed over the fact that it was going to do something very bad and send a very old version.
https://lore.kernel.org/all/[email protected]/
So please ignore that too. :-(
At this point I'm going to send v3.
<fingers crossed>
Ira
Quoted 273 lines · Ira Weiny
A git tree of this series can be found here:
https://github.com/weiny2/linux-kernel/tree/dcd-v4-2024-08-15This series requires the CXL memory notifier lock change:
https://lore.kernel.org/all/[email protected]/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 use cases for Dynamic Capacity is to allow hosts to share memory dynamically within a data center without increasing the per-host attached memory.
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.
Typical work flows are shown below.
Orchestrator FM Device Host Kernel Host User
| | | | | |-------------- Create region ----------------------->| | | | | | | | | |<-- Create ---| | | | | Region | |<------------- 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 | | | | | |Previous versions of this series[0] resulted in architectural comments as well as confusion on the architecture based on the organization of patch series itself.
This version has reordered the patches to clarify the architecture. It also streamlines extent handling more.
The series still requires the creation of regions and DAX devices to be synchronized with the Orchestrator and Fabric Manager. The host kernel will reject an add extent event if the region is not created yet. It will also ignore a release if the DAX device is created and referencing an extent.
These synchronizations are not anticipated to be an issue with real applications.
In order to allow for capacity to be added and removed a new concept of a sparse DAX region is introduced. A sparse DAX region may have 0 or more bytes of available space. The total space depends on the number and size of the extents which have been added.
Initially it is anticipated that users of the memory will carefully coordinate the surfacing of additional capacity with the creation of DAX devices which use that capacity. Therefore, the allocation of the memory to DAX devices does not allow for specific associations between DAX device and extent. This keeps allocations very similar to existing DAX region behavior.
Great care was taken to keep the extent tracking simple. Some xarray's needed to be added but extra software objects were kept to a minimum.
Region extents continue to be tracked as sub-devices of the DAX region. This ensures that region destruction cleans up all extent allocations properly.
Due to these major changes all reviews were removed from the larger patches. A few of the straight forward patches have kept the tags.
In summary the major functionality of this series includes:
- Getting the dynamic capacity (DC) configuration information from cxl devices
- Configuring the DC partitions reported by hardware
- Enhancing the CXL and DAX regions for dynamic capacity support a. Maintain a logical separation between hardware extents and software managed region extents. This provides an abstraction between the layers and should allow for interleaving in the future
- Get hardware extent lists for endpoint decoders upon region creation.
- Adjust extent/region memory available on the following events. a. Add capacity Events
b. Release capacity events- Host response for add capacity
a. do not accept the extent if:
If the region does not exist
or an error occurs realizing the extent
b. If the region does exist
realize a DAX region extent with 1:1 mapping (no interleave yet)
c. Support the more bit by processing a list of extents marked
with the more bit together before setting up a response.- Host response for remove capacity
a. If no DAX device references the extent; release the extent b. If a reference does exist, ignore the request.
(Require FM to issue release again.)- Modify DAX device creation/resize to account for extents within a sparse DAX region
- Trace Dynamic Capacity events for debugging
- Add cxl-test infrastructure to allow for faster unit testing (See new ndctl branch for
cxl-dcd.shtest[1])Fan Ni's upstream of Qemu DCD was used for testing.
Remaining work:
1) Integrate the QoS work from Dave Jiang
2) Interleave supportPossible additional work depending on requirements:
1) Allow mapping to specific extents (perhaps based on label/tag)
2) Release extents when DAX devices are released if a release was previously seen from the device
3) Accept a new extent which extends (but overlaps) an existing extent(s)
4) Rework DAX device interfaces, memfd has been explored a bit[0] v1: https://lore.kernel.org/all/[email protected]/
[1] https://github.com/weiny2/ndctl/tree/dcd-region2-2024-08-15---
Major changes:
- Jonathan: support the more bit
- djbw: Allow more than 1 region per DC partition
- All: Address the many comments on the series.
- iweiny: rebase
- iweiny: Rework the series to make it easier to review and understand
the flow
- Link to v1: https://lore.kernel.org/r/[email protected]---
Ira Weiny (13):
range: Addrange_overlaps()
printk: Add print format (%par) for struct range
dax: Document dax dev range tuple
cxl/pci: Delay event buffer allocation
cxl/region: Refactor common create region code cxl/events: Split event msgnum configuration from irq setup cxl/pci: Factor out interrupt policy check
cxl/core: Return endpoint decoder information from region search dax/bus: Factor out dev dax resize logic
dax/region: Create resources on sparse DAX regions cxl/region: Read existing extents on region creationtools/testing/cxl: Make event logs dynamictools/testing/cxl: Add DC Regions to mock mem dataNavneet Singh (12):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/mem: Read dynamic capacity configuration from the device cxl/core: Separate region mode from decoder mode cxl/region: Add dynamic capacity decoder and region modes cxl/hdm: Add dynamic capacity size support to endpoint decoders cxl/port: Add endpoint decoder DC mode support to sysfs cxl/mem: Expose DCD partition capabilities in sysfs cxl/region: Add sparse DAX region support
cxl/mem: Configure dynamic capacity interrupts cxl/extent: Process DCD events and realize region extents cxl/region/extent: Expose region extent information in sysfs cxl/mem: Trace Dynamic capacity Event RecordDocumentation/ABI/testing/sysfs-bus-cxl | 68 ++- Documentation/core-api/printk-formats.rst | 14 + drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 33 +- drivers/cxl/core/extent.c | 467 ++++++++++++++ drivers/cxl/core/hdm.c | 206 ++++++- drivers/cxl/core/mbox.c | 578 +++++++++++++++++- drivers/cxl/core/memdev.c | 101 ++- drivers/cxl/core/port.c | 13 +- drivers/cxl/core/region.c | 173 ++++-- drivers/cxl/core/trace.h | 65 ++ drivers/cxl/cxl.h | 122 +++- drivers/cxl/cxlmem.h | 128 +++- drivers/cxl/pci.c | 123 +++- drivers/dax/bus.c | 352 +++++++++-- drivers/dax/bus.h | 4 +- drivers/dax/cxl.c | 73 ++- drivers/dax/dax-private.h | 39 +- drivers/dax/hmem/hmem.c | 2 +- drivers/dax/pmem.c | 2 +- fs/btrfs/ordered-data.c | 10 +- include/linux/cxl-event.h | 32 + include/linux/range.h | 7 + lib/vsprintf.c | 37 ++ tools/testing/cxl/Kbuild | 3 +- tools/testing/cxl/test/mem.c | 981 ++++++++++++++++++++++++++---- 26 files changed, 3327 insertions(+), 308 deletions(-)---
base-commit:3cef9316df4cda21b5bf25e4230221b02050dfa1
change-id: 20230604-dcd-type2-upstream-0cd15f6216fdBest regards,
Signature · 1 line
Ira Weiny <[email protected]>