DCD: Add support for Dynamic Capacity Devices (DCD)
Subsystems (3)
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-2024-03-24
Pre-requisite:
==============
The locking introduced by Vishal for DAX regions: https://lore.kernel.org/all/[email protected]/T/#u
Background
==========
A Dynamic Capacity Device (DCD) (CXL 3.1 sec 9.13.3) is a CXL memory device that allows the memory capacity 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 Device the host sees, 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 RFCs of this series[0] resulted in significant architectural comments. Previous versions allowed memory capacity to be accepted by the host regardless of the existence of a software region being mapped.
With this new patch set the order of the create region and DAX device creation must be synchronized with the Orchestrator adding/removing capacity. 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.
Neither of these synchronizations are 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 greatly simplify extent tracking. Specifically, in comparison to previous versions of the patch set, all extent tracking xarrays have been eliminated from the code. In addition, most of the extra software objects and associated referenced counts have been eliminated.
In this version, extents are tracked purely as sub-devices of the region. This ensures that the region destruction cleans up all extent allocations properly. Device managed callbacks are wired to ensure any additional data required for DAX device references are handled correctly.
Due to these major changes I'm setting this new series to V1.
In summary the major functionality of this series includes:
- Getting the dynamic capacity (DC) configuration information from cxl devices
- Configuring the DC regions 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)
- Host response for remove capacity
a. If no DAX devices reference 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 latest v5 of Qemu DCD was used for testing.[2]
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)
[0] RFC v2: https://lore.kernel.org/r/[email protected]
[1] https://github.com/weiny2/ndctl/tree/dcd-region2-2024-03-22
[2] https://lore.kernel.org/all/[email protected]/
---
Changes for v1:
- iweiny: Largely new series
- iweiny: Remove review tags due to the series being a major rework
- iweiny: Fix authorship for Navneet patches
- iweiny: Remove extent xarrays
- iweiny: Remove kreferences, replace with 1 use count protected under dax_rwsem
- iweiny: Mark all sysfs entries for the 6.10 June 2024 kernel
- iweiny: Remove gotos
- iweiny: Fix 0day issues
- Jonathan Cameron: address comments
- Navneet Singh: address comments
- Dan Williams: address comments
- Dave Jiang: address comments
- Fan Ni: address comments
- Jørgen Hansen: address comments
- Link to RFC v2: https://lore.kernel.org/r/[email protected]
---
Ira Weiny (12):
cxl/core: Simplify cxl_dpa_set_mode()
cxl/events: Factor out event msgnum configuration cxl/pci: Delay event buffer allocation
cxl/pci: Factor out interrupt policy check
range: Add range_overlaps()
dax/bus: Factor out dev dax resize logic
dax: Document dax dev range tuple
dax/region: Prevent range mapping allocation on sparse regions dax/region: Support DAX device creation on sparse DAX regions tools/testing/cxl: Make event logs dynamic tools/testing/cxl: Add DC Regions to mock mem data tools/testing/cxl: Add Dynamic Capacity events
Navneet Singh (14):
cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) cxl/core: Separate region mode from decoder mode cxl/mem: Read dynamic capacity configuration from the device cxl/region: Add dynamic capacity decoder and region modes cxl/port: Add Dynamic Capacity mode support to endpoint decoders cxl/port: Add dynamic capacity size support to endpoint decoders cxl/mem: Expose device dynamic capacity capabilities cxl/region: Add Dynamic Capacity CXL region support cxl/mem: Configure dynamic capacity interrupts cxl/region: Read existing extents on region creation cxl/extent: Realize extent devices
dax/region: Create extent resources on DAX region driver load cxl/mem: Handle DCD add & release capacity events. cxl/mem: Trace Dynamic capacity Event Record
Documentation/ABI/testing/sysfs-bus-cxl | 60 ++- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 10 + drivers/cxl/core/extent.c | 145 +++++ drivers/cxl/core/hdm.c | 254 +++++++-- drivers/cxl/core/mbox.c | 591 ++++++++++++++++++++- drivers/cxl/core/memdev.c | 76 +++ drivers/cxl/core/port.c | 19 + drivers/cxl/core/region.c | 334 +++++++++++- drivers/cxl/core/trace.h | 65 +++ drivers/cxl/cxl.h | 127 ++++- drivers/cxl/cxlmem.h | 114 ++++ drivers/cxl/mem.c | 45 ++ drivers/cxl/pci.c | 122 +++-- drivers/dax/bus.c | 353 +++++++++--- drivers/dax/bus.h | 4 +- drivers/dax/cxl.c | 127 ++++- drivers/dax/dax-private.h | 40 +- drivers/dax/hmem/hmem.c | 2 +- drivers/dax/pmem.c | 2 +- fs/btrfs/ordered-data.c | 10 +- include/linux/cxl-event.h | 31 ++ include/linux/range.h | 7 + tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/test/mem.c | 914 ++++++++++++++++++++++++++++---- 25 files changed, 3152 insertions(+), 302 deletions(-)
---
base-commit: dff54316795991e88a453a095a9322718a34034a
change-id: 20230604-dcd-type2-upstream-0cd15f6216fd
Best regards,
Signature · 1 line
Ira Weiny <[email protected]>
PATCH 1/26 cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:
https://lore.kernel.org/all/[email protected]/ [jonathan: remove unneeded format change] [jonathan: don't split security code in mbox.c] --- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)
drivers/cxl/core/mbox.c +33 -0
@@ -161,6 +161,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
@@ -733,6 +761,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
@@ -481,6 +491,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;
@@ -551,6 +562,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.44.0
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
Quoted 7 lines · On Sun, 24 Mar 2024 16:18:04 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Quoted 6 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
This aligns with similar existing code etc and the opcodes are right so There is a vague argument that maybe we shouldn't claim to support the command in the debug message at that point in the patch set, but I don't think we really care either way as expectation is this set should go in all together.
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
In reply to [email protected]Quoted 7 lines · On Sun, Mar 24, 2024 at 04:18:04PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Quoted 7 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Quoted 114 lines
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/ [jonathan: remove unneeded format change] [jonathan: don't split security code in mbox.c] --- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)drivers/cxl/core/mbox.c +33
-0@@ -161,6 +161,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@@ -733,6 +761,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 @@ -481,6 +491,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;@@ -551,6 +562,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 · 2 lines
-- 2.44.0
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
In reply to [email protected]Quoted 6 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
I vote to fold this into patch 3, favoring reduced patch count in the series to trvially enlarging that particular patch.
Quoted 2 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
It would be good to mention these here explicitly (if this patch will live on). For example, that config will be the driver's way of telling if dcd is enabled or disabled - we could have cases of that zeroed bit but the rest enabled.
lgtm otherwise.
Quoted 118 lines
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/[jonathan: remove unneeded format change]
[jonathan: don't split security code inmbox.c]
---drivers/cxl/core/mbox.c| 33 +++++++++++++++++++++++++++++++++drivers/cxl/cxlmem.h| 15 +++++++++++++++2 files changed, 48 insertions(+)drivers/cxl/core/mbox.c +33
-0@@ -161,6 +161,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@@ -733,6 +761,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
-1@@ -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 @@ -481,6 +491,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;@@ -551,6 +562,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 }; --2.44.0
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
Quoted 11 lines · Davidlohr Bueso
Quoted 6 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
I vote to fold this into patch 3, favoring reduced patch count in the series to trvially enlarging that particular patch.
I'll consider it. I've tried hard to split the original series up into very easily reviewable chunks. So I'm inclined to leave this separate for now.
Quoted 8 lines
Quoted 3 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
It would be good to mention these here explicitly (if this patch will live on). For example, that config will be the driver's way of telling if dcd is enabled or disabled - we could have cases of that zeroed bit but the rest enabled.
It took me a bit to parse this but I see what you mean. Yes the GET_CONFIG command is the one used specifically to determine if DCD is supported.
I'll clean up the commit message. In retrospect it was wrong for me to mention subsequent patches here. I'm going to move this final detail to patch 3.
Quoted 4 lines
lgtm otherwise.
Reviewed-by Davidlohr Bueso <[email protected]>
Thanks! :-D
Ira
Quoted 119 lines
Quoted 119 lines
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/[jonathan: remove unneeded format change]
[jonathan: don't split security code inmbox.c]
---drivers/cxl/core/mbox.c| 33 +++++++++++++++++++++++++++++++++drivers/cxl/cxlmem.h| 15 +++++++++++++++2 files changed, 48 insertions(+)drivers/cxl/core/mbox.c +33
-0@@ -161,6 +161,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@@ -733,6 +761,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
-1@@ -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 @@ -481,6 +491,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;@@ -551,6 +562,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 }; --2.44.0
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
In reply to [email protected]Quoted 7 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Quoted 6 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
small formatting nit below
Quoted 20 lines
---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/ [jonathan: remove unneeded format change] [jonathan: don't split security code in mbox.c] --- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)drivers/cxl/core/mbox.c +0
-0@@ -161,6 +161,34 @@ static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, } }
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 172
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+static bool cxl_is_dcd_command (u16 opcode) +{ +#define CXL_MBOX_OP_DCD_CMDS 0x48 + +return (opcode >>8 ) ==CXL_MBOX_OP_DCD_CMDS ; +} + +static void cxl_set_dcd_cmd_enabled (struct cxl_memdev_state *mds, +u16 opcode)
This seems misaligned.
DJ
Quoted 82 lines
drivers/cxl/core/mbox.c +24
-0+{ +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@@ -733,6 +761,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 @@ -481,6 +491,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;@@ -551,6 +562,10 @@ enum cxl_opcode {CXL_MBOX_OP_UNLOCK =0x4503 ,CXL_MBOX_OP_FREEZE_SECURITY =0x4504 ,CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE =0x4505 , +CXL_MBOX_OP_GET_DC_CONFIG =0x4800 , +CXL_MBOX_OP_GET_DC_EXTENT_LIST =0x4801 , +CXL_MBOX_OP_ADD_DC_RESPONSE =0x4802 , +CXL_MBOX_OP_RELEASE_DC =0x4803 , CXL_MBOX_OP_MAX = 0x10000 };
Re: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
Quoted 42 lines · Dave Jiang
Quoted 7 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Quoted 6 lines
Flag DC Device (DCD) commands in a device if they are supported. Subsequent patches will key off these bits to configure DCD.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>Reviewed-by Dave Jiang <[email protected]>small formatting nit below
Quoted 21 lines
---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/ [jonathan: remove unneeded format change] [jonathan: don't split security code in mbox.c] --- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)drivers/cxl/core/mbox.c +0
-0@@ -161,6 +161,34 @@ static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, } }
Quoted 11 lines
drivers/cxl/core/mbox.c static void cxl_set_security_cmd_enabled(struct cxl_security_state *security, · line 172
Quoted 9 lines
drivers/cxl/core/mbox.c +9
-0+static bool cxl_is_dcd_command (u16 opcode) +{ +#define CXL_MBOX_OP_DCD_CMDS 0x48 + +return (opcode >>8 ) ==CXL_MBOX_OP_DCD_CMDS ; +} + +static void cxl_set_dcd_cmd_enabled (struct cxl_memdev_state *mds, +u16 opcode)This seems misaligned.
Fixed,
Ira
Alison Schofield
maintainerRe: [PATCH 01/26] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD)
In reply to [email protected]Quoted 6 lines · Ira Weiny
From: Navneet Singh <[email protected]>
Per the CXL 3.1 specification software must check the Command Effects Log (CEL) to know if a device supports dynamic capacity (DC). If the device does support DC the specifics of the DC Regions (0-7) are read through the mailbox.
Do I need to know this 'If the device...' piece to understand this patch? I like that below you say 'Subsequent patches will...' That seems enough to set the scene.
Quoted 2 lines
Flag DC Device (DCD) commands in a device if they are supported.
Why be vague w 'Flag'. How about 'Add a bitmap of DCD enabled commands to the driver device state structure.'
Quoted 18 lines
Subsequent patches will key off these bits to configure DCD.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: update to latest master]
[iweiny: update commit message]
[iweiny: Based on the fix:https://lore.kernel.org/all/[email protected]/ [jonathan: remove unneeded format change] [jonathan: don't split security code in mbox.c] --- drivers/cxl/core/mbox.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+)
snip
drivers/cxl/cxlmem.h struct cxl_dev_state { · line 468
Quoted 10 lines
/* Device enabled poison commands */
enumpoison_cmd_enabled_bits{drivers/cxl/cxlmem.h +1
-0CXL_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
It's not a 'List' it's a bitmap. How about mimicing 'enabled_cmds' description:
* @dcd_cmds: DCD commands found enabled in CEL
Quoted 24 lines
drivers/cxl/cxlmem.h +5
-0* @total_bytes: sum of all possible capacities @@ -481,6 +491,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;@@ -551,6 +562,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 · 2 lines
-- 2.44.0
PATCH 2/26 cxl/core: Separate region mode from decoder mode
In reply to [email protected]From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Define a new region mode enumeration and adjust the code for it.
---
Changes for v1
<none>
--- drivers/cxl/core/region.c | 77 +++++++++++++++++++++++++++++++++++------------ drivers/cxl/cxl.h | 26 ++++++++++++++-- 2 files changed, 81 insertions(+), 22 deletions(-)
drivers/cxl/core/region.c +57 -20
@@ -40,7 +40,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);
@@ -353,7 +353,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; }
@@ -516,7 +516,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);
@@ -542,7 +542,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);
@@ -1683,6 +1683,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) {
@@ -1693,9 +1704,11 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ; -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 ; }
@@ -2168,7 +2181,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i* 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
@@ -2179,7 +2192,7 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i*/ 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);
@@ -2188,11 +2201,12 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,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 ); }
@@ -2242,7 +2256,7 @@ 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;
@@ -2270,7 +2284,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);
@@ -2290,7 +2304,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);
@@ -2800,6 +2814,24 @@ 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 ; + } + +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)
@@ -2808,12 +2840,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 );
@@ -2996,9 +3033,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'
@@ -3010,8 +3047,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
@@ -383,6 +383,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.
@@ -511,7 +532,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 mode 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
@@ -521,7 +543,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.44.0
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
Quoted 9 lines · On Sun, 24 Mar 2024 16:18:05 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Quoted 6 lines
Define a new region mode enumeration and adjust the code for it.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
I can't really remember the reasoning behind this split, but from a fresh read it seems reasonable. Some trivial comments inline.
Jonathan
Quoted 24 lines
---
Changes for v1
<none>--- drivers/cxl/core/region.c | 77 +++++++++++++++++++++++++++++++++++------------ drivers/cxl/cxl.h | 26 ++++++++++++++-- 2 files changed, 81 insertions(+), 22 deletions(-)drivers/cxl/core/region.c +5
-0@@ -2800,6 +2814,24 @@ 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 :
drivers/cxl/core/region.c static int match_region_by_range(struct device *dev, void *data) · line 2831
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+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 ; + } +
Dead code.
Quoted 7 lines
drivers/cxl/core/region.c +3
-0+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)
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 2849
Quoted 10 lines
drivers/cxl/core/region.c +3
-0@@ -2808,12 +2840,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 );
Not a bad thing necessarily, but why do we now need this and didn't before?
Quoted 19 lines
drivers/cxl/core/region.c +3
-1+ + 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 );drivers/cxl/cxl.h +0
-0/* * Track whether this decoder is reserved for region autodiscovery, or * free for userspace provisioning.
drivers/cxl/cxl.h struct cxl_region_params { · line 535
Quoted 5 lines
drivers/cxl/cxl.h +1
-1@@ -511,7 +532,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 mode the region is
mode or potentially modes?
If region is mixed, I guess that means endpoint could be pmem or ram in theory? Don't think anyone has implemented anything yet, but is the potential there?
Quoted 1 line
drivers/cxl/cxl.h +1
-0+* compatible with
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
Quoted 2 lines · Jonathan Cameron
On Sun, 24 Mar 2024 16:18:05 -0700
[email protected] wrote:
[snip]
Quoted 28 lines
Quoted 28 lines
---
Changes for v1
<none>--- drivers/cxl/core/region.c | 77 +++++++++++++++++++++++++++++++++++------------ drivers/cxl/cxl.h | 26 ++++++++++++++-- 2 files changed, 81 insertions(+), 22 deletions(-)drivers/cxl/core/region.c +9
-0@@ -2800,6 +2814,24 @@ 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 :
Quoted 8 lines
drivers/cxl/core/region.c static int match_region_by_range(struct device *dev, void *data) · line 2831
Quoted 6 lines
drivers/cxl/core/region.c +6
-0+return CXL_REGION_PMEM ; +case CXL_DECODER_MIXED : +default : +return CXL_REGION_MIXED ; + } +Dead code.
Fixed thanks.
Quoted 16 lines
Quoted 16 lines
drivers/cxl/core/region.c +4
-0+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)@@ -2808,12 +2840,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;
Quoted 4 lines
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 2849
Quoted 2 lines
drivers/cxl/core/region.c +2
-0+if (cxled->mode ==CXL_DECODER_DEAD ) +return ERR_PTR (-EINVAL );Not a bad thing necessarily, but why do we now need this and didn't before?
Ah. Because in devm_cxl_add_region() the mode of CXL_DECODER_DEAD used to return -EINVAL.
There is no logical equivalent to decoder dead in the region mode (regions don't need it). So this correctly flags the error based on the decoder mode rather than introduce a mode for regions which does not make sense.
I'll update the commit message because that is hard to see.
Quoted 27 lines
Quoted 20 lines
drivers/cxl/core/region.c +3
-1+ + 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 );drivers/cxl/cxl.h +0
-0/* * Track whether this decoder is reserved for region autodiscovery, or * free for userspace provisioning. drivers/cxl/cxl.h struct cxl_region_params { · line 535
Quoted 5 lines
drivers/cxl/cxl.h +1
-1@@ -511,7 +532,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 mode the region is mode or potentially modes?
Quoted 2 lines
If region is mixed, I guess that means endpoint could be pmem or ram in theory? Don't think anyone has implemented anything yet, but is the potential there?
Yes the potential is there. The endpoint decoder is set to CXL_DECODER_MIXED in __cxl_dpa_reserve(). But I am unclear how that will ever be executed except if the BIOS sets up a decoder to span ram/pmem. In this case the rest of the stack is not going to work and will complain about mixed mode.
Ok Dan clued me in. Check out cxl_dpa_alloc(). Spanning partitions is not allowed.
So the comment is targeted toward the 'normal' case even though the region could be created incorrectly via BIOS.
Ira
Davidlohr Bueso
maintainerRe: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
In reply to [email protected]Quoted 10 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Define a new region mode enumeration and adjust the code for it.
Could this could also be picked up regardless of dcd?
Thanks,
Davidlohr
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
Quoted 11 lines · Davidlohr Bueso
Quoted 9 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Quoted 3 lines
Quoted 1 line
Define a new region mode enumeration and adjust the code for it.
Could this could also be picked up regardless of dcd?
It could but there is no need for it without DCD.
I will work on re-ordering the cleanups if Dave will agree to take them early.
Ira
Dave Jiang
maintainerRe: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
Quoted 12 lines · Ira Weiny
Quoted 11 lines · Davidlohr Bueso
Quoted 9 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Define a new region mode enumeration and adjust the code for it.
Could this could also be picked up regardless of dcd?
It could but there is no need for it without DCD.
I will work on re-ordering the cleanups if Dave will agree to take them early.
There's no reason for the change unless it comes with DCD right? And probably no urgent need to taking it ahead then?
Quoted 2 lines
Ira
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
Quoted 17 lines · Dave Jiang
Quoted 14 lines · Ira Weiny
Quoted 13 lines · Davidlohr Bueso
Quoted 10 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Define a new region mode enumeration and adjust the code for it.
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Could this could also be picked up regardless of dcd?
It could but there is no need for it without DCD.
I will work on re-ordering the cleanups if Dave will agree to take them early.
There's no reason for the change unless it comes with DCD right? And probably no urgent need to taking it ahead then?
Quoted 1 line
I think I just replied for a 2nd time to this... yea.
LOL I have to do better...
Ira
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
In reply to Dave JiangQuoted 17 lines · Dave Jiang
Quoted 14 lines · Ira Weiny
Quoted 13 lines · Davidlohr Bueso
Quoted 10 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Define a new region mode enumeration and adjust the code for it.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Could this could also be picked up regardless of dcd?
It could but there is no need for it without DCD.
I will work on re-ordering the cleanups if Dave will agree to take them early.
There's no reason for the change unless it comes with DCD right? And probably no urgent need to taking it ahead then?
No I don't think so.
Ira
Quoted 2 lines
Quoted 2 lines
Ira
Re: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
In reply to Davidlohr BuesoQuoted 11 lines · Davidlohr Bueso
Quoted 9 lines · On Sun, 24 Mar 2024, [email protected] wrote:
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Quoted 3 lines
Quoted 1 line
Define a new region mode enumeration and adjust the code for it.
Could this could also be picked up regardless of dcd?
It could be. But there is no practical need for it without the addition of DCD. So I don't think it should be.
Ira
Alison Schofield
maintainerRe: [PATCH 02/26] cxl/core: Separate region mode from decoder mode
In reply to [email protected]Quoted 65 lines · Ira Weiny
From: Navneet Singh <[email protected]>
Until now region modes and decoder modes were equivalent in that they were either PMEM or RAM. With the upcoming addition of Dynamic Capacity regions (which will represent an array of device regions [better named partitions] the index of which could be different on different interleaved devices), the mode of an endpoint decoder and a region will no longer be equivalent.
Define a new region mode enumeration and adjust the code for it.
Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
<none>--- drivers/cxl/core/region.c | 77 +++++++++++++++++++++++++++++++++++------------ drivers/cxl/cxl.h | 26 ++++++++++++++-- 2 files changed, 81 insertions(+), 22 deletions(-)drivers/cxl/core/region.c +4
-4@@ -40,7 +40,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);@@ -353,7 +353,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; }@@ -516,7 +516,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);@@ -542,7 +542,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);
drivers/cxl/core/region.c static int cxl_region_sort_targets(struct cxl_region *cxlr) · line 1688
Quoted 6 lines
drivers/cxl/core/region.c +3
-0@@ -1683,6 +1683,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) +{
Perhaps is_region_mode_compatible() ?
Seems we have precedence for asking these questions that have boolean responses. I picked 'region' because it is the region we are trying to construct.
Quoted 15 lines
drivers/cxl/core/region.c +8
-0+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) {@@ -1693,9 +1704,11 @@ static int cxl_region_attach(struct cxl_region *cxlr,struct cxl_dport *dport;int rc = -ENXIO ;
drivers/cxl/core/region.c static int cxl_region_attach(struct cxl_region *cxlr, · line 1713
Quoted 10 lines
drivers/cxl/core/region.c +5
-3-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 ; }
Does the above return bypass this next code segment (not in your diff):
if (cxled->mode == CXL_DECODER_DEAD) {
dev_dbg(&cxlr->dev, "%s dead\n", dev_name(&cxled->cxld.dev));
return -ENODEV;
}It seems we are changing the return value on DEAD.
More below where a new check for DEAD is added ...
snip
Quoted 4 lines
drivers/cxl/core/region.c +0
-0/* Establish an empty region covering the given HPA range */ static struct
cxl_region*construct_region(structcxl_root_decoder*cxlrd,drivers/cxl/core/region.c +0
-0struct cxl_endpoint_decoder *cxled)
drivers/cxl/core/region.c static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, · line 2849
Quoted 10 lines
drivers/cxl/core/region.c +3
-0@@ -2808,12 +2840,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 );
I see this addition, but it is in a different place and with a different return value. Help me understand that this is no change in behavior.
Quoted 8 lines
drivers/cxl/core/region.c +3
-1+ + 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 );
snip
drivers/cxl/core/region.c struct cxl_region_params { · line 536
Quoted 10 lines
/*
* Track whether this decoder is reserved for region autodiscovery, or
* free for userspace provisioning.drivers/cxl/core/region.c +2
-1@@ -511,7 +532,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 mode the region is +* compatible with
Maybe...
@mode: Region mode used for decoder compatibility check
snip to end
--Alison
Quoted 1 line
PATCH 3/26 cxl/mem: Read dynamic capacity configuration from the device
In reply to [email protected]From: Navneet Singh <[email protected]>
Devices can optionally support Dynamic Capacity (DC). These devices are known as Dynamic Capacity Devices (DCD).
Implement the DC mailbox commands as specified in CXL 3.1 section 8.2.9.9.9 (opcodes 48XXh). Read the DC configuration and store the DC region information in the device state.
---
Changes for v1
[Jørgen: ensure CXL 2.0 device support by removing dc_event_log_size] [iweiny/Jørgen: use get DC config command to signal DCD support] [djiang: fix subject]
[Fan: add additional region configuration checks] [Jonathan/djiang: split out region mode changes] [Jonathan: fix up comments/kdoc]
[Jonathan: s/cxl_get_dc_id/cxl_get_dc_config/]
[Jonathan: use __free() in identify call]
[Jonathan: remove unneeded formatting changes]
[Jonathan: s/cxl_mbox_dynamic_capacity/cxl_mbox_get_dc_config_out/] [Jonathan: s/cxl_mbox_get_dc_config/cxl_mbox_get_dc_config_in/] [iweiny: remove type2 work dependancy/rebase on master] [iweiny: fix 0day build issues]
--- drivers/cxl/core/mbox.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 49 +++++++++++++ drivers/cxl/pci.c | 4 ++ 3 files changed, 236 insertions(+), 1 deletion(-)
drivers/cxl/core/mbox.c +183 -1
@@ -1123,7 +1123,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_cap =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;
@@ -1230,6 +1230,175 @@ 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 %0x40 || + !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 DPA: %#llx LEN: %#llx BLKSZ: %#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; + + rc = dc_resp->avail_region_count - start_region; + +/* +* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out); + +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} + +static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} + +/** +* 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; +int rc =0 ; + +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */ +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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +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)
@@ -1260,8 +1429,12 @@ 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; + untenanted_mem = mds->dc_region[0 ].base - mds->static_cap; + mds->total_bytes = mds->static_cap + untenanted_mem + mds->dynamic_cap; +if (!cxlds->media_ready) { cxlds->dpa_res =DEFINE_RES_MEM (0 ,0 ); cxlds->ram_res =DEFINE_RES_MEM (0 ,0 );
@@ -1271,6 +1444,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 +49 -0
108 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) +return rc; + rc =cxl_mem_create_range_info (mds);if (rc)return rc;
Signature · 1 line
2.44.0
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
Quoted 5 lines · On Sun, 24 Mar 2024 16:18:06 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Devices can optionally support Dynamic Capacity (DC). These devices are known as Dynamic Capacity Devices (DCD).
Quoted 7 lines
Implement the DC mailbox commands as specified in CXL 3.1 section 8.2.9.9.9 (opcodes 48XXh). Read the DC configuration and store the DC region information in the device state.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
A few minor things inline,
Jonathan
Quoted 59 lines
---
Changes for v1
[Jørgen: ensure CXL 2.0 device support by removingdc_event_log_size] [iweiny/Jørgen: use get DC config command to signal DCD support] [djiang: fix subject]
[Fan: add additional region configuration checks] [Jonathan/djiang: split out region mode changes] [Jonathan: fix up comments/kdoc]
[Jonathan: s/cxl_get_dc_id/cxl_get_dc_config/]
[Jonathan: use__free()in identify call]
[Jonathan: remove unneeded formatting changes]
[Jonathan: s/cxl_mbox_dynamic_capacity/cxl_mbox_get_dc_config_out/] [Jonathan: s/cxl_mbox_get_dc_config/cxl_mbox_get_dc_config_in/] [iweiny: remove type2 work dependancy/rebase on master] [iweiny: fix 0day build issues]--- drivers/cxl/core/mbox.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 49 +++++++++++++ drivers/cxl/pci.c | 4 ++ 3 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/mbox.c +21
-1@@ -1123,7 +1123,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_cap =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;@@ -1230,6 +1230,175 @@ 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) {
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1262
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+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,
Odd choice of line wrap. I'd drag index onto the line below.
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1274
Quoted 12 lines
drivers/cxl/core/mbox.c +12
-0+ 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 % 0x40 ||
Hmm. I thought we had a define for CXL 'cacheline' size, but can't find it now. If not we should add one (and find a better name than that).
Quoted 35 lines
drivers/cxl/core/mbox.c +35
-0+ !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 DPA: %#llx LEN: %#llx BLKSZ: %#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 )
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1319
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+return rc; + + rc = dc_resp->avail_region_count - start_region; + +/* +* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out);
Why not always return this? If there was space, doesn't it equal the value set above anyway?
Quoted 12 lines
drivers/cxl/core/mbox.c +11
-0+ +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} +/** +* 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
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1346
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+* 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; +int rc =0 ;
Is this used before being set?
Quoted 75 lines
drivers/cxl/core/mbox.c +54
-0+ +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */ +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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL );drivers/cxl/cxlmem.h +2
-0/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities +* @static_cap: Sum of static RAM and PMEM capacities +* @dynamic_cap: Complete DPA range occupied by DC regions * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity
drivers/cxl/cxlmem.h struct cxl_dev_state { · line 493
Quoted 3 lines
drivers/cxl/cxlmem.h +0
-0@@ -474,6 +491,8 @@ struct cxl_dev_state {* @active_persistent_bytes: sum of hard + soft persistent * @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset
Looks like we have some ordering issues ram_perf and pmem_perf (at least) that we should fix up as a precursor. I sent a reply to the QoS patch that added these.
drivers/cxl/cxlmem.h struct cxl_memdev_state { · line 516
Quoted 10 lines
drivers/cxl/cxlmem.h +3
-0+* @nr_dc_region: number of DC regions implemented in the memory device +* @dc_region: array containing info about the DC regions * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -494,7 +513,10 @@ struct cxl_memdev_state {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 ); +
Trivial but this is an unrelated change and shouldn't be in this patch.
Quoted 25 lines
drivers/cxl/cxlmem.h +13
-0u64 total_bytes; +u64 static_cap; +u64 dynamic_cap;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;@@ -506,6 +528,9 @@ struct cxl_memdev_state {struct cxl_dpa_perf ram_perf;struct cxl_dpa_perf pmem_perf; +u8 nr_dc_region; +struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct cxl_event_state event;struct cxl_poison_state poison;struct cxl_security_state security; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length;
drivers/cxl/cxlmem.h struct cxl_memdev_state {
Quoted 10 lines
drivers/cxl/cxlmem.h +10
-0+__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + }__packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config))
Can we make that 8 self documenting? offsetof(struct cxl_dc_region_config, region) perhaps?
Quoted 1 line
+
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
Quoted 3 lines · Jonathan Cameron
On Sun, 24 Mar 2024 16:18:06 -0700
[email protected] wrote:
[snip]
Quoted 10 lines
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ +/* 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 ;
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1262
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+ } + } + +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,Odd choice of line wrap. I'd drag index onto the line below.
fixed.
Quoted 16 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1274
Quoted 13 lines
drivers/cxl/core/mbox.c +12
-0+ 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 % 0x40 ||Hmm. I thought we had a define for CXL 'cacheline' size, but can't find it now. If not we should add one (and find a better name than that).
Asking me to add a define is fine... Asking me to name said define is... The issue... I am absolute rubbish at picking names... :-/ ;-) :-D
Quoted 41 lines
Quoted 41 lines
drivers/cxl/core/mbox.c +40
-0+ !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 DPA: %#llx LEN: %#llx BLKSZ: %#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; + + rc = dc_resp->avail_region_count - start_region; + +/*
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1319
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out);Why not always return this? If there was space, doesn't it equal the value set above anyway?
I've been looking at this more carefully and there is a bigger issue with this. I need to update this code to handle the regions_returned which was added in the errata and get rid of this macro.
Quoted 17 lines
Quoted 17 lines
drivers/cxl/core/mbox.c +15
-0+ +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} +/** +* 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. +*/
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1346
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+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; +int rc =0 ;Is this used before being set?
nope...
Quoted 75 lines
Quoted 75 lines
drivers/cxl/core/mbox.c +54
-0+ +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */ +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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL );drivers/cxl/cxlmem.h +2
-0/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities +* @static_cap: Sum of static RAM and PMEM capacities +* @dynamic_cap: Complete DPA range occupied by DC regions * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity
Quoted 8 lines
drivers/cxl/cxlmem.h struct cxl_dev_state { · line 493
Quoted 4 lines
drivers/cxl/cxlmem.h +0
-0@@ -474,6 +491,8 @@ struct cxl_dev_state {* @active_persistent_bytes: sum of hard + soft persistent * @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset Looks like we have some ordering issues
ram_perfandpmem_perf(at least) that we should fix up as a precursor. I sent a reply to the QoS patch that added these.
I see. That will likely resolve out when I rebase. But seems nothing to be done for this patch and best left as a separate patch from this series.
Quoted 43 lines
drivers/cxl/cxlmem.h struct cxl_memdev_state { · line 516
Quoted 11 lines
drivers/cxl/cxlmem.h +3
-0+* @nr_dc_region: number of DC regions implemented in the memory device +* @dc_region: array containing info about the DC regions * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -494,7 +513,10 @@ struct cxl_memdev_state {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 ); +Trivial but this is an unrelated change and shouldn't be in this patch.
Quoted 30 lines
drivers/cxl/cxlmem.h +18
-0u64 total_bytes; +u64 static_cap; +u64 dynamic_cap;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;@@ -506,6 +528,9 @@ struct cxl_memdev_state {struct cxl_dpa_perf ram_perf;struct cxl_dpa_perf pmem_perf; +u8 nr_dc_region; +struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct cxl_event_state event;struct cxl_poison_state poison;struct cxl_security_state security; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length; +__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ];
Quoted 8 lines
drivers/cxl/cxlmem.h struct cxl_mbox_set_partition_info { · line 754
Quoted 5 lines
drivers/cxl/cxlmem.h +5
-0+ }__packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config))Can we make that 8 self documenting?
offsetof(struct cxl_dc_region_config, region)perhaps?
As I said above I think this macro is wrong I'm adjusting to remove it.
Thanks,
Ira
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
In reply to [email protected]Quoted 351 lines · On Sun, Mar 24, 2024 at 04:18:06PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Devices can optionally support Dynamic Capacity (DC). These devices are known as Dynamic Capacity Devices (DCD).
Implement the DC mailbox commands as specified in CXL 3.1 section 8.2.9.9.9 (opcodes 48XXh). Read the DC configuration and store the DC region information in the device state.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[Jørgen: ensure CXL 2.0 device support by removingdc_event_log_size] [iweiny/Jørgen: use get DC config command to signal DCD support] [djiang: fix subject]
[Fan: add additional region configuration checks] [Jonathan/djiang: split out region mode changes] [Jonathan: fix up comments/kdoc]
[Jonathan: s/cxl_get_dc_id/cxl_get_dc_config/]
[Jonathan: use__free()in identify call]
[Jonathan: remove unneeded formatting changes]
[Jonathan: s/cxl_mbox_dynamic_capacity/cxl_mbox_get_dc_config_out/] [Jonathan: s/cxl_mbox_get_dc_config/cxl_mbox_get_dc_config_in/] [iweiny: remove type2 work dependancy/rebase on master] [iweiny: fix 0day build issues]--- drivers/cxl/core/mbox.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 49 +++++++++++++ drivers/cxl/pci.c | 4 ++ 3 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/mbox.c +183
-1@@ -1123,7 +1123,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_cap =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;@@ -1230,6 +1230,175 @@ 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 %0x40 || + !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 DPA: %#llx LEN: %#llx BLKSZ: %#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; + + rc = dc_resp->avail_region_count - start_region; + +/* +* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out); + +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} + +static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} + +/** +* 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; +int rc =0 ; + +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */ +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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +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)@@ -1260,8 +1429,12 @@ 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; + untenanted_mem = mds->dc_region[0 ].base - mds->static_cap; + mds->total_bytes = mds->static_cap + untenanted_mem + mds->dynamic_cap; +if (!cxlds->media_ready) { cxlds->dpa_res =DEFINE_RES_MEM (0 ,0 ); cxlds->ram_res =DEFINE_RES_MEM (0 ,0 );@@ -1271,6 +1444,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 +37
-0@@ -402,6 +402,7 @@ enum cxl_devtype { CXL_DEVTYPE_CLASSMEM, }; +#define CXL_MAX_DC_REGION 8/** * struct cxl_dpa_perf - DPA performance property entry * @dpa_range - range for DPA address @@ -431,6 +432,8 @@ struct cxl_dpa_perf {* @dpa_res: Overall DPA resource tree for the device * @pmem_res: Active Persistent memory capacity configuration * @ram_res: Active Volatile memory capacity configuration +* @dc_res: Active Dynamic Capacity memory configuration for each possible +* region * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device */ @@ -445,10 +448,22 @@ struct cxl_dev_state {struct resource dpa_res;struct resource pmem_res;struct resource ram_res; +struct resource dc_res[CXL_MAX_DC_REGION ];u64 serial;enum cxl_devtype type; }; +#define CXL_DC_REGION_STRLEN 8 +struct cxl_dc_region_info { +u64 base; +u64 decode_len; +u64 len; +u64 blk_size; +u32 dsmad_handle; +u8 flags; +u8 name[CXL_DC_REGION_STRLEN ]; +}; +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities +* @static_cap: Sum of static RAM and PMEM capacities +* @dynamic_cap: Complete DPA range occupied by DC regions * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity @@ -474,6 +491,8 @@ struct cxl_dev_state {* @active_persistent_bytes: sum of hard + soft persistent * @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset +* @nr_dc_region: number of DC regions implemented in the memory device +* @dc_region: array containing info about the DC regions * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -494,7 +513,10 @@ struct cxl_memdev_state {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; +u64 static_cap; +u64 dynamic_cap;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;@@ -506,6 +528,9 @@ struct cxl_memdev_state {struct cxl_dpa_perf ram_perf;struct cxl_dpa_perf pmem_perf; +u8 nr_dc_region; +struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct cxl_event_state event;struct cxl_poison_state poison;struct cxl_security_state security;@@ -705,6 +730,29 @@ struct cxl_mbox_set_partition_info {#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) +struct cxl_mbox_get_dc_config_in { +u8 region_count; +u8 start_region_index; +} __packed; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length;
drivers/cxl/cxlmem.h struct cxl_mbox_set_partition_info { · line 754
Quoted 10 lines
drivers/cxl/cxlmem.h +10
-0+__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + }__packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config))
Although the result may be unchanged, but in cxl spec r3.1, there are four fields after the region configuration structure.
Fan
Quoted 31 lines
drivers/cxl/cxlmem.h +2
-0+/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -828,6 +876,7 @@ enum {int cxl_internal_send_cmd (struct cxl_memdev_state *mds,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); +int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);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) +return rc; + rc =cxl_mem_create_range_info (mds);if (rc)return rc;Signature · 2 lines
-- 2.44.0
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
Quoted 3 lines · fan
Quoted 2 lines · On Sun, Mar 24, 2024 at 04:18:06PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 18 lines
Quoted 18 lines
drivers/cxl/cxlmem.h +17
-0+struct cxl_mbox_get_dc_config_in { +u8 region_count; +u8 start_region_index; +} __packed; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length; +__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ];
Quoted 8 lines
drivers/cxl/cxlmem.h struct cxl_mbox_set_partition_info { · line 754
Quoted 5 lines
drivers/cxl/cxlmem.h +5
-0+ }__packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config))Although the result may be unchanged, but in cxl spec r3.1, there are four fields after the region configuration structure.
Yes. This macro is not needed.
The fields after the structure are of little use to the host at this time. So I'm going to leave them out until a use can be found for them.
Ira
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
In reply to [email protected]Quoted 297 lines · On 3/25/24 00:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
Devices can optionally support Dynamic Capacity (DC). These devices are known as Dynamic Capacity Devices (DCD).
Implement the DC mailbox commands as specified in CXL 3.1 section 8.2.9.9.9 (opcodes 48XXh). Read the DC configuration and store the DC region information in the device state.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[Jørgen: ensure CXL 2.0 device support by removingdc_event_log_size] [iweiny/Jørgen: use get DC config command to signal DCD support] [djiang: fix subject]
[Fan: add additional region configuration checks] [Jonathan/djiang: split out region mode changes] [Jonathan: fix up comments/kdoc]
[Jonathan: s/cxl_get_dc_id/cxl_get_dc_config/]
[Jonathan: use__free()in identify call]
[Jonathan: remove unneeded formatting changes]
[Jonathan: s/cxl_mbox_dynamic_capacity/cxl_mbox_get_dc_config_out/] [Jonathan: s/cxl_mbox_get_dc_config/cxl_mbox_get_dc_config_in/] [iweiny: remove type2 work dependancy/rebase on master] [iweiny: fix 0day build issues]--- drivers/cxl/core/mbox.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 49 +++++++++++++ drivers/cxl/pci.c | 4 ++ 3 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/mbox.c +183
-1@@ -1123,7 +1123,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_cap =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;@@ -1230,6 +1230,175 @@ 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 %0x40 || + !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 DPA: %#llx LEN: %#llx BLKSZ: %#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; + + rc = dc_resp->avail_region_count - start_region; + +/* +* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out); + +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} + +static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} + +/** +* 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; +int rc =0 ; + +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */ +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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +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)@@ -1260,8 +1429,12 @@ 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; + untenanted_mem = mds->dc_region[0 ].base - mds->static_cap; + mds->total_bytes = mds->static_cap + untenanted_mem + mds->dynamic_cap; +if (!cxlds->media_ready) { cxlds->dpa_res =DEFINE_RES_MEM (0 ,0 ); cxlds->ram_res =DEFINE_RES_MEM (0 ,0 );@@ -1271,6 +1444,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 +15
-0@@ -402,6 +402,7 @@ enum cxl_devtype { CXL_DEVTYPE_CLASSMEM, }; +#define CXL_MAX_DC_REGION 8/** * struct cxl_dpa_perf - DPA performance property entry * @dpa_range - range for DPA address @@ -431,6 +432,8 @@ struct cxl_dpa_perf {* @dpa_res: Overall DPA resource tree for the device * @pmem_res: Active Persistent memory capacity configuration * @ram_res: Active Volatile memory capacity configuration +* @dc_res: Active Dynamic Capacity memory configuration for each possible +* region * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device */ @@ -445,10 +448,22 @@ struct cxl_dev_state {struct resource dpa_res;struct resource pmem_res;struct resource ram_res; +struct resource dc_res[CXL_MAX_DC_REGION ];u64 serial;enum cxl_devtype type; }; +#define CXL_DC_REGION_STRLEN 8 +struct cxl_dc_region_info { +u64 base; +u64 decode_len; +u64 len; +u64 blk_size; +u32 dsmad_handle; +u8 flags; +u8 name[CXL_DC_REGION_STRLEN ]; +}; +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data *
drivers/cxl/cxlmem.h struct cxl_dev_state { · line 486
Quoted 5 lines
drivers/cxl/cxlmem.h +2
-0@@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities +* @static_cap: Sum of static RAM and PMEM capacities +* @dynamic_cap: Complete DPA range occupied by DC regions
How about naming these total_range, static_cap and dynamic_range to make it clear that the DPA range occupied by DC regions isn't necessarily usable capacity (as opposed to the static_cap where the spec defines it as usable capacity).
Thanks,
Jørgen
Quoted 91 lines
drivers/cxl/cxlmem.h +32
-0* @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity @@ -474,6 +491,8 @@ struct cxl_dev_state {* @active_persistent_bytes: sum of hard + soft persistent * @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset +* @nr_dc_region: number of DC regions implemented in the memory device +* @dc_region: array containing info about the DC regions * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -494,7 +513,10 @@ struct cxl_memdev_state {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; +u64 static_cap; +u64 dynamic_cap;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;@@ -506,6 +528,9 @@ struct cxl_memdev_state {struct cxl_dpa_perf ram_perf;struct cxl_dpa_perf pmem_perf; +u8 nr_dc_region; +struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct cxl_event_state event;struct cxl_poison_state poison;struct cxl_security_state security;@@ -705,6 +730,29 @@ struct cxl_mbox_set_partition_info {#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) +struct cxl_mbox_get_dc_config_in { +u8 region_count; +u8 start_region_index; +} __packed; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length; +__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + } __packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config)) +/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -828,6 +876,7 @@ enum {int cxl_internal_send_cmd (struct cxl_memdev_state *mds,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); +int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);drivers/cxl/pci.c +4
-1@@ -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) +return rc; + rc =cxl_mem_create_range_info (mds);if (rc)return rc; --2.44.0
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
Quoted 4 lines · Jørgen Hansen
Quoted 2 lines · On 3/25/24 00:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 6 lines
Quoted 6 lines
/**
* structcxl_memdev_state- Generic Type-3 Memory Device Class driver data *(quoted diff) +0
-0@@ -467,6 +482,8 @@ struct cxl_dev_state { * @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only
Quoted 8 lines
Review struct cxl_dev_state { · line 486
Quoted 3 lines
(quoted diff) +2
-0* @total_bytes: sum of all possible capacities + * @static_cap: Sum of static RAM and PMEM capacities + * @dynamic_cap: Complete DPA range occupied by DC regionsHow about naming these
total_range,static_capanddynamic_rangeto make it clear that the DPA range occupied by DC regions isn't necessarily usable capacity (as opposed to thestatic_capwhere the spec defines it as usable capacity).
I thought this was a good idea but on second thought these are not range variables at all. They really represent the various lengths of the resources.
For total_bytes the documentation already says 'sum of all __possible__ capacities'.
I think you have a point for the new fields though. They should all be named in some consistent manner and documented as such.
So I propose:
drivers/cxl/cxlmem.h +5 -5
@@ -481,9 +481,9 @@ struct cxl_dc_region_info {* @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 -* @static_cap: Sum of static RAM and PMEM capacities -* @dynamic_cap: Complete DPA range occupied by DC regions +* @total_bytes: length of all possible capacities +* @static_bytes: length of possible static RAM and PMEM partitions +* @dynamic_bytes: length of possible DC partitions (DC Regions) * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity
@@ -515,8 +515,8 @@ struct cxl_memdev_state {DECLARE_BITMAP (exclusive_cmds,CXL_MEM_COMMAND_ID_MAX );u64 total_bytes; -u64 static_cap; -u64 dynamic_cap; +u64 static_bytes; +u64 dynamic_bytes;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;
Re: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
Quoted 52 lines · Ira Weiny
Quoted 4 lines · Jørgen Hansen
Quoted 2 lines · On 3/25/24 00:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 6 lines
Quoted 6 lines
/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data *drivers/cxl/cxlmem.h +0
-0@@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only Quoted 8 lines
Review struct cxl_dev_state { · line 486
Quoted 3 lines
(quoted diff) +2
-0* @total_bytes: sum of all possible capacities + * @static_cap: Sum of static RAM and PMEM capacities + * @dynamic_cap: Complete DPA range occupied by DC regionsHow about naming these
total_range,static_capanddynamic_rangeto make it clear that the DPA range occupied by DC regions isn't necessarily usable capacity (as opposed to thestatic_capwhere the spec defines it as usable capacity).I thought this was a good idea but on second thought these are not range variables at all. They really represent the various lengths of the resources.
For
total_bytesthe documentation already says 'sum of all__possible__capacities >
I think you have a point for the new fields though. They should all be named in some consistent manner and documented as such.So I propose:
drivers/cxl/cxlmem.h +3
-3@@ -481,9 +481,9 @@ struct cxl_dc_region_info {* @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 -* @static_cap: Sum of static RAM and PMEM capacities -* @dynamic_cap: Complete DPA range occupied by DC regions +* @total_bytes: length of all possible capacities +* @static_bytes: length of possible static RAM and PMEM partitions +* @dynamic_bytes: length of possible DC partitions (DC Regions) * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity
drivers/cxl/cxlmem.h struct cxl_memdev_state { · line 522
Quoted 10 lines
drivers/cxl/cxlmem.h +2
-2@@ -515,8 +515,8 @@ struct cxl_memdev_state {DECLARE_BITMAP (exclusive_cmds,CXL_MEM_COMMAND_ID_MAX );u64 total_bytes; -u64 static_cap; -u64 dynamic_cap; +u64 static_bytes; +u64 dynamic_bytes;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;
That looks good. My main concern was that the DC regions may be separated by gaps that take up part of the DPA range but isn't part of the usable capacity. Pre-DCD, total_bytes was in fact all the usable capacity of the device as reported by the device itself, but now it includes the potential gaps between DC regions as well as the potential gap between static and dynamic regions.
Thanks,
Jørgen
Alison Schofield
maintainerRe: [PATCH 03/26] cxl/mem: Read dynamic capacity configuration from the device
In reply to [email protected]Quoted 8 lines · Ira Weiny
From: Navneet Singh <[email protected]>
Devices can optionally support Dynamic Capacity (DC). These devices are known as Dynamic Capacity Devices (DCD).
Implement the DC mailbox commands as specified in CXL 3.1 section 8.2.9.9.9 (opcodes 48XXh). Read the DC configuration and store the DC region information in the device state.
It seems worth mentioning that it validates against a bunch of alignment rules. Speaking of which...
Quoted 48 lines
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[Jørgen: ensure CXL 2.0 device support by removingdc_event_log_size] [iweiny/Jørgen: use get DC config command to signal DCD support] [djiang: fix subject]
[Fan: add additional region configuration checks] [Jonathan/djiang: split out region mode changes] [Jonathan: fix up comments/kdoc]
[Jonathan: s/cxl_get_dc_id/cxl_get_dc_config/]
[Jonathan: use__free()in identify call]
[Jonathan: remove unneeded formatting changes]
[Jonathan: s/cxl_mbox_dynamic_capacity/cxl_mbox_get_dc_config_out/] [Jonathan: s/cxl_mbox_get_dc_config/cxl_mbox_get_dc_config_in/] [iweiny: remove type2 work dependancy/rebase on master] [iweiny: fix 0day build issues]--- drivers/cxl/core/mbox.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 49 +++++++++++++ drivers/cxl/pci.c | 4 ++ 3 files changed, 236 insertions(+), 1 deletion(-)drivers/cxl/core/mbox.c +6
-1@@ -1123,7 +1123,7 @@ int cxl_dev_state_identify(struct cxl_memdev_state *mds)if (rc <0 )return rc; - mds->total_bytes = + mds->static_cap =le64_to_cpu (id.total_capacity) *CXL_CAPACITY_MULTIPLIER ; mds->volatile_only_bytes =le64_to_cpu (id.volatile_capacity) *CXL_CAPACITY_MULTIPLIER ;@@ -1230,6 +1230,175 @@ 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;
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1247
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ + 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); +
Below - where are these rules defined in CXL spec?
Maybe one general comment referring to a CXL spec section if available?
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1248
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+/* Check regions are in increasing DPA order */
Better to state the rule and who's rule it is:
/* CXL spec mandates increasing DPA order */
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+/* 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)
Is that allowing overlap at dcr->base?
Quoted 12 lines
drivers/cxl/core/mbox.c +12
-0+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 ;
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1274
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ } + +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 % 0x40 ||
OK - I know 0x40 must be cache align, but only because I saw Jonathans comment. Please comment or macro.
Quoted 67 lines
drivers/cxl/core/mbox.c +67
-0+ !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 DPA: %#llx LEN: %#llx BLKSZ: %#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; + + rc = dc_resp->avail_region_count - start_region; + +/* +* The number of regions in the payload may have been truncated due to +* payload_size limits; if so adjust the returned count to match. +*/ +if (mbox_cmd.size_out <sizeof (*dc_resp)) + rc =CXL_REGIONS_RETURNED (mbox_cmd.size_out); + +dev_dbg (dev,"Read %d/%d DC regions\n" , rc, dc_resp->avail_region_count); + +return rc; +} + +static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +{ +return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} + +/** +* 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)
drivers/cxl/core/mbox.c int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) · line 1351
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+{ +size_t dc_resp_size = mds->payload_size; +struct device *dev = mds->cxlds.dev; +u8 start_region, i; +int rc =0 ; + +for (i =0 ; i <CXL_MAX_DC_REGION ; i++) +snprintf (mds->dc_region[i].name,CXL_DC_REGION_STRLEN ,"<nil>" ); + +/* Check GET_DC_CONFIG is supported by device */
Needless comment above due to nicely named cxl_dcd_supported() below
Quoted 222 lines
drivers/cxl/core/mbox.c +63
-0+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 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_cap = + 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 capacity: %#llx\n" , mds->dynamic_cap); + +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)@@ -1260,8 +1429,12 @@ 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; + untenanted_mem = mds->dc_region[0 ].base - mds->static_cap; + mds->total_bytes = mds->static_cap + untenanted_mem + mds->dynamic_cap; +if (!cxlds->media_ready) { cxlds->dpa_res =DEFINE_RES_MEM (0 ,0 ); cxlds->ram_res =DEFINE_RES_MEM (0 ,0 );@@ -1271,6 +1444,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 +49
-0@@ -402,6 +402,7 @@ enum cxl_devtype { CXL_DEVTYPE_CLASSMEM, }; +#define CXL_MAX_DC_REGION 8/** * struct cxl_dpa_perf - DPA performance property entry * @dpa_range - range for DPA address @@ -431,6 +432,8 @@ struct cxl_dpa_perf {* @dpa_res: Overall DPA resource tree for the device * @pmem_res: Active Persistent memory capacity configuration * @ram_res: Active Volatile memory capacity configuration +* @dc_res: Active Dynamic Capacity memory configuration for each possible +* region * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device */ @@ -445,10 +448,22 @@ struct cxl_dev_state {struct resource dpa_res;struct resource pmem_res;struct resource ram_res; +struct resource dc_res[CXL_MAX_DC_REGION ];u64 serial;enum cxl_devtype type; }; +#define CXL_DC_REGION_STRLEN 8 +struct cxl_dc_region_info { +u64 base; +u64 decode_len; +u64 len; +u64 blk_size; +u32 dsmad_handle; +u8 flags; +u8 name[CXL_DC_REGION_STRLEN ]; +}; +/** * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data * @@ -467,6 +482,8 @@ struct cxl_dev_state {* @enabled_cmds: Hardware commands found enabled in CEL. * @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities +* @static_cap: Sum of static RAM and PMEM capacities +* @dynamic_cap: Complete DPA range occupied by DC regions * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity * @partition_align_bytes: alignment size for partition-able capacity @@ -474,6 +491,8 @@ struct cxl_dev_state {* @active_persistent_bytes: sum of hard + soft persistent * @next_volatile_bytes: volatile capacity change pending device reset * @next_persistent_bytes: persistent capacity change pending device reset +* @nr_dc_region: number of DC regions implemented in the memory device +* @dc_region: array containing info about the DC regions * @event: event log driver state * @poison: poison driver state info * @security: security driver state info @@ -494,7 +513,10 @@ struct cxl_memdev_state {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; +u64 static_cap; +u64 dynamic_cap;u64 volatile_only_bytes;u64 persistent_only_bytes;u64 partition_align_bytes;@@ -506,6 +528,9 @@ struct cxl_memdev_state {struct cxl_dpa_perf ram_perf;struct cxl_dpa_perf pmem_perf; +u8 nr_dc_region; +struct cxl_dc_region_info dc_region[CXL_MAX_DC_REGION ]; +struct cxl_event_state event;struct cxl_poison_state poison;struct cxl_security_state security;@@ -705,6 +730,29 @@ struct cxl_mbox_set_partition_info {#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) +struct cxl_mbox_get_dc_config_in { +u8 region_count; +u8 start_region_index; +} __packed; + +/* See CXL 3.0 Table 125 get dynamic capacity config Output Payload */ +struct cxl_mbox_get_dc_config_out { +u8 avail_region_count; +u8 rsvd[7 ]; +struct cxl_dc_region_config { +__le64 region_base; +__le64 region_decode_length; +__le64 region_length; +__le64 region_block_size; +__le32 region_dsmad_handle; +u8 flags; +u8 rsvd[3 ]; + } __packed region[]; +} __packed; +#define CXL_DYNAMIC_CAPACITY_SANITIZE_ON_RELEASE_FLAG BIT(0) +#define CXL_REGIONS_RETURNED (size_out) \ + ((size_out - 8) / sizeof(struct cxl_dc_region_config)) +/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ struct cxl_mbox_set_timestamp_in {__le64 timestamp;@@ -828,6 +876,7 @@ enum {int cxl_internal_send_cmd (struct cxl_memdev_state *mds,struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds); +int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);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) +return rc; + rc =cxl_mem_create_range_info (mds);if (rc)return rc;Signature · 2 lines
-- 2.44.0
PATCH 4/26 cxl/region: Add dynamic capacity decoder and region modes
In reply to [email protected]From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Decoder mode reflects a specific DC partition.
Define the new modes to use in subsequent patches and the helper functions required to make the association between these new modes.
---
Changes for v1
[iweiny: split out from: Add dynamic capacity cxl region support.]
--- drivers/cxl/core/region.c | 4 ++++ drivers/cxl/cxl.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)
drivers/cxl/core/region.c +4 -0
@@ -1690,6 +1690,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; }
@@ -2824,6 +2826,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
@@ -365,6 +365,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, };
@@ -375,6 +383,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", };
@@ -383,10 +399,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 , };
@@ -396,6 +418,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.44.0
Re: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
Quoted 7 lines · On Sun, 24 Mar 2024 16:18:07 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Quoted 8 lines
Decoder mode reflects a specific DC partition.
Define the new modes to use in subsequent patches and the helper functions required to make the association between these new modes.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Re: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
In reply to [email protected]Quoted 4 lines · On Sun, Mar 24, 2024 at 04:18:07PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each
s/partitions/partition/
Otherwise,
Quoted 104 lines
device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Decoder mode reflects a specific DC partition.
Define the new modes to use in subsequent patches and the helper functions required to make the association between these new modes.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: split out from: Add dynamic capacity cxl region support.]--- drivers/cxl/core/region.c | 4 ++++ drivers/cxl/cxl.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +4
-0@@ -1690,6 +1690,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; }@@ -2824,6 +2826,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@@ -365,6 +365,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, };@@ -375,6 +383,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", };@@ -383,10 +399,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 , };@@ -396,6 +418,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 · 2 lines
-- 2.44.0
Dave Jiang
maintainerRe: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
In reply to [email protected]Quoted 6 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
This section reads somewhat awkward to me. Does this read any better?
One or more Dynamic Capacity (DC) partitions (and decoders) 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 but is not the same entity as CXL software regions.
DJ
Quoted 99 lines
Decoder mode reflects a specific DC partition.
Define the new modes to use in subsequent patches and the helper functions required to make the association between these new modes.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: split out from: Add dynamic capacity cxl region support.]--- drivers/cxl/core/region.c | 4 ++++ drivers/cxl/cxl.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +4
-0@@ -1690,6 +1690,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; }@@ -2824,6 +2826,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@@ -365,6 +365,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, };@@ -375,6 +383,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", };@@ -383,10 +399,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 , };@@ -396,6 +418,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", };
Re: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
Quoted 10 lines · Dave Jiang
Quoted 6 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Quoted 7 lines
This section reads somewhat awkward to me. Does this read any better?
One or more Dynamic Capacity (DC) partitions (and decoders) 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 but is not the same entity as CXL software regions.
Yea that does sound better but I think this builds on your text and is even more clear.
<commit>
cxl/region: Add dynamic capacity decoder and region modes
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 but they are not the same entity as CXL software regions.
Define the new modes and helper functions required to make the association between these new modes.
</commit>
Ira
Dave Jiang
maintainerRe: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
Quoted 31 lines · Ira Weiny
Quoted 10 lines · Dave Jiang
Quoted 6 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Quoted 7 lines
This section reads somewhat awkward to me. Does this read any better?
One or more Dynamic Capacity (DC) partitions (and decoders) 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 but is not the same entity as CXL software regions.
Yea that does sound better but I think this builds on your text and is even more clear.
<commit>
cxl/region: Add dynamic capacity decoder and region modesOne 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 but they are not the same entity as CXL software regions.
Quoted 5 lines
Define the new modes and helper functions required to make the association between these new modes.
</commit>
LGTM
Quoted 2 lines
Ira
Re: [PATCH 04/26] cxl/region: Add dynamic capacity decoder and region modes
In reply to [email protected]The following change is preferred to show the correct mode name.
drivers/cxl/core/hdm.c +1 -1
@@ -684,7 +684,7 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)if (size > avail) {dev_dbg (dev,"%pa exceeds available %s capacity: %pa\n" , &size, - cxled->mode ==CXL_DECODER_RAM ?"ram" :"pmem" , +cxl_decoder_mode_name (cxled->mode), &avail); rc = -ENOSPC ; goto out;
Quoted 105 lines · On 25/03/2024 07:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
Region mode must reflect a general dynamic capacity type which is associated with a specific Dynamic Capacity (DC) partitions in each device decoder within the region. DC partitions are also know as DC regions per CXL 3.1.
Decoder mode reflects a specific DC partition.
Define the new modes to use in subsequent patches and the helper functions required to make the association between these new modes.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: split out from: Add dynamic capacity cxl region support.]--- drivers/cxl/core/region.c | 4 ++++ drivers/cxl/cxl.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)drivers/cxl/core/region.c +4
-0@@ -1690,6 +1690,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; }@@ -2824,6 +2826,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@@ -365,6 +365,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, };@@ -375,6 +383,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", };@@ -383,10 +399,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 , };@@ -396,6 +418,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", };
PATCH 5/26 cxl/core: Simplify cxl_dpa_set_mode()
In reply to [email protected]cxl_dpa_set_mode() checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Simplify the mode check before adding the more complex DC modes.
---
Changes for v1:
[iweiny: new patch]
[Jonathan: based on getting rid of the loop in cxl_dpa_set_mode] [Jonathan: standardize on resource_size() == 0]
--- drivers/cxl/core/hdm.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-)
drivers/cxl/core/hdm.c +18 -27
@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; } -down_write (&cxl_dpa_rwsem); -if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) { - rc = -EBUSY ; - goto out; - } - -/* -* Only allow modes that are supported by the current partition -* configuration -*/ -if (mode ==CXL_DECODER_PMEM && !resource_size (&cxlds->pmem_res)) { -dev_dbg (dev,"no available pmem capacity\n" ); - rc = -ENXIO ; - goto out; - } -if (mode ==CXL_DECODER_RAM && !resource_size (&cxlds->ram_res)) { -dev_dbg (dev,"no available ram capacity\n" ); - rc = -ENXIO ; - goto out; - } - cxled->mode = mode; - rc =0 ; -out: -up_write (&cxl_dpa_rwsem); - -return rc; +return 0 ; }int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size)
Signature · 1 line
2.44.0
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 9 lines · On Sun, 24 Mar 2024 16:18:08 -0700 Ira Weiny <[email protected]> wrote:
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.Simplify the mode check before adding the more complex DC modes.
Signed-off-by Ira Weiny <[email protected]>
Nice. Maybe drag this earlier in series so it could potentially be picked up as a cleanup? Same with patch 2 potentially. If Dave is fine with doing that sort of precursor patches going earlier, it will save carrying quite so many in this series for future versions (and make it look less terrifying :)
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 5 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
I agree (also to pick this up regardless of dcd work).
Quoted 2 lines
Simplify the mode check before adding the more complex DC modes.
Quoted 82 lines
Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: new patch]
[Jonathan: based on getting rid of the loop incxl_dpa_set_mode] [Jonathan: standardize onresource_size()== 0]
---drivers/cxl/core/hdm.c| 45 ++++++++++++++++++---------------------------1 file changed, 18 insertions(+), 27 deletions(-)drivers/cxl/core/hdm.c +18
-28@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; } -down_write (&cxl_dpa_rwsem); -if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) { - rc = -EBUSY ; - goto out; - } - -/* -* Only allow modes that are supported by the current partition -* configuration -*/ -if (mode ==CXL_DECODER_PMEM && !resource_size (&cxlds->pmem_res)) { -dev_dbg (dev,"no available pmem capacity\n" ); - rc = -ENXIO ; - goto out; - } -if (mode ==CXL_DECODER_RAM && !resource_size (&cxlds->ram_res)) { -dev_dbg (dev,"no available ram capacity\n" ); - rc = -ENXIO ; - goto out; - } - cxled->mode = mode; - rc =0 ; -out: -up_write (&cxl_dpa_rwsem); - -return rc; +return 0 ; }int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size) --2.44.0
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 10 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.Simplify the mode check before adding the more complex DC modes.
Signed-off-by Ira Weiny <[email protected]>
Quoted 80 lines
---
Changes for v1:
[iweiny: new patch]
[Jonathan: based on getting rid of the loop incxl_dpa_set_mode] [Jonathan: standardize onresource_size()== 0]--- drivers/cxl/core/hdm.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-)drivers/cxl/core/hdm.c +18
-27@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; } -down_write (&cxl_dpa_rwsem); -if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) { - rc = -EBUSY ; - goto out; - } - -/* -* Only allow modes that are supported by the current partition -* configuration -*/ -if (mode ==CXL_DECODER_PMEM && !resource_size (&cxlds->pmem_res)) { -dev_dbg (dev,"no available pmem capacity\n" ); - rc = -ENXIO ; - goto out; - } -if (mode ==CXL_DECODER_RAM && !resource_size (&cxlds->ram_res)) { -dev_dbg (dev,"no available ram capacity\n" ); - rc = -ENXIO ; - goto out; - } - cxled->mode = mode; - rc =0 ; -out: -up_write (&cxl_dpa_rwsem); - -return rc; +return 0 ; }int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size)Signature · 2 lines
-- 2.44.0
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 7 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.Simplify the mode check before adding the more complex DC modes.
I would augment this by saying simplify "by using scope-based resource menagement".
Quoted 2 lines
Signed-off-by Ira Weiny <[email protected]>
Quoted 78 lines
---
Changes for v1:
[iweiny: new patch]
[Jonathan: based on getting rid of the loop incxl_dpa_set_mode] [Jonathan: standardize onresource_size()== 0]--- drivers/cxl/core/hdm.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-)drivers/cxl/core/hdm.c +18
-27@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; } -down_write (&cxl_dpa_rwsem); -if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) { - rc = -EBUSY ; - goto out; - } - -/* -* Only allow modes that are supported by the current partition -* configuration -*/ -if (mode ==CXL_DECODER_PMEM && !resource_size (&cxlds->pmem_res)) { -dev_dbg (dev,"no available pmem capacity\n" ); - rc = -ENXIO ; - goto out; - } -if (mode ==CXL_DECODER_RAM && !resource_size (&cxlds->ram_res)) { -dev_dbg (dev,"no available ram capacity\n" ); - rc = -ENXIO ; - goto out; - } - cxled->mode = mode; - rc =0 ; -out: -up_write (&cxl_dpa_rwsem); - -return rc; +return 0 ; }int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size)
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 9 lines · Dave Jiang
Quoted 6 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Quoted 3 lines
Quoted 1 line
Simplify the mode check before adding the more complex DC modes.
I would augment this by saying simplify "by using scope-based resource menagement".
However, using the guard cleanup is not really the simplification here. It is more about checking the mode a single time.
That said I will change this to:
Simplify the mode check and convert to use of a cleanup guard.
Ira
Dave Jiang
maintainerRe: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 12 lines · Ira Weiny
Quoted 11 lines · Dave Jiang
Quoted 7 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within. The function is not in a critical path. Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.Simplify the mode check before adding the more complex DC modes.
Quoted 8 lines
Quoted 1 line
I would augment this by saying simplify "by using scope-based resource menagement".
However, using the guard cleanup is not really the simplification here. It is more about checking the mode a single time.
That said I will change this to:
Simplify the mode check and convert to use of a cleanup guard.
Ok
Quoted 2 lines
Ira
Alison Schofield
maintainerRe: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.
Not true. It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
Quoted 1 line
The function is not in a critical path.
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Quoted 6 lines
Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Simplify the mode check before adding the more complex DC modes.
The addition of the DC mode check doesn't seem complex.
Pardon my picking at the words, but if you'd like to refactor the function, just say so. The final result is a bit more readable, but also adding the DC mode checks without refactoring would read fine also.
and...a bit spacing nit below -
Quoted 37 lines
Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: new patch]
[Jonathan: based on getting rid of the loop incxl_dpa_set_mode] [Jonathan: standardize onresource_size()== 0]--- drivers/cxl/core/hdm.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-)drivers/cxl/core/hdm.c +13
-1@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM :
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 440
Quoted 10 lines
drivers/cxl/core/hdm.c +4
-0+if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; }
delete extra line
Quoted 17 lines
drivers/cxl/core/hdm.c +0
-17-down_write (&cxl_dpa_rwsem); -if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) { - rc = -EBUSY ; - goto out; - } - -/* -* Only allow modes that are supported by the current partition -* configuration -*/ -if (mode ==CXL_DECODER_PMEM && !resource_size (&cxlds->pmem_res)) { -dev_dbg (dev,"no available pmem capacity\n" ); - rc = -ENXIO ; - goto out; - } -if (mode ==CXL_DECODER_RAM && !resource_size (&cxlds->ram_res)) { -dev_dbg (dev,"no available ram capacity\n" );
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 451
Quoted 10 lines
drivers/cxl/core/hdm.c +0
-9- rc = -ENXIO ; - goto out; - } - cxled->mode = mode; - rc =0 ; -out: -up_write (&cxl_dpa_rwsem); - -return rc;
insert blank line
Quoted 8 lines
drivers/cxl/core/hdm.c +1
-0+return 0 ; }int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size)Signature · 2 lines
-- 2.44.0
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 5 lines · Alison Schofield
Quoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.Not true.
Sorry for not being clear. It does check the mode 2x but not for validity. I'll clarify.
Quoted 3 lines
It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
But we can check the mode 1 time and either check the size or fail.
Quoted 5 lines
Quoted 2 lines
The function is not in a critical path.
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Implying that checking the mode outside the lock is not required.
Quoted 9 lines
Quoted 7 lines
Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Simplify the mode check before adding the more complex DC modes.
The addition of the DC mode check doesn't seem complex.
It is if you have to check it 2 times.
Quoted 5 lines
Pardon my picking at the words, but if you'd like to refactor the function, just say so. The final result is a bit more readable, but also adding the DC mode checks without refactoring would read fine also.
When I added the DC mode to this function without this refactoring it was quite a bit more code and ugly IMO. So this cleanup helped. If I were not adding the DC code there would be much less reason to change this function.
[snip]
Quoted 30 lines
Quoted 30 lines
drivers/cxl/core/hdm.c +17
-1@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }
Quoted 8 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 440
Quoted 6 lines
drivers/cxl/core/hdm.c +0
-0break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; }delete extra line
You don't like the space following the switch?
Ira
Alison Schofield
maintainerRe: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
On Fri, May 03, 2024 at 12:09:27PM -0700, Ira Weiny wrote:
snip
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
drivers/cxl/core/hdm.c +17
-1@@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +guard (rwsem_write)(&cxl_dpa_rwsem); +if (cxled->cxld.flags &CXL_DECODER_F_ENABLE ) +return -EBUSY ; + +/* +* Check that the mode is supported by the current partition +* configuration +*/ switch (mode) {case CXL_DECODER_RAM : +if (!resource_size (&cxlds->ram_res)) { +dev_dbg (dev,"no available ram capacity\n" ); +return -ENXIO ; + } +break ;case CXL_DECODER_PMEM : +if (!resource_size (&cxlds->pmem_res)) { +dev_dbg (dev,"no available pmem capacity\n" ); +return -ENXIO ; + }Quoted 8 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 440
Quoted 6 lines
drivers/cxl/core/hdm.c +0
-0break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ; }delete extra line
Quoted 3 lines
You don't like the space following the switch?
Ira
Sorry - looks fine. Ignore my comment.
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 17 lines · Ira Weiny
Quoted 5 lines · Alison Schofield
Quoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.Not true.
Sorry for not being clear. It does check the mode 2x but not for validity. I'll clarify.
Quoted 3 lines
It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
But we can check the mode 1 time and either check the size or fail.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
The function is not in a critical path.
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Implying that checking the mode outside the lock is not required.
The @mode check outside the lock is there to taking the lock when not necessary because the passed in mode is already bogus.
The lock is about making sure the write of cxled->mode relative to the state of the dpa partitions is an atomic check-and-set.
So this makes the function unconditionally take the lock when it might be bogus to do so. The value of reorganizing this is questionable.
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 20 lines · Dan Williams
Quoted 19 lines · Ira Weiny
Quoted 5 lines · Alison Schofield
Quoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.Not true.
Sorry for not being clear. It does check the mode 2x but not for validity. I'll clarify.
Quoted 3 lines
It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
But we can check the mode 1 time and either check the size or fail.
Quoted 3 lines
Quoted 2 lines
The function is not in a critical path.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Implying that checking the mode outside the lock is not required.
The @mode check outside the lock is there to taking the lock when not necessary because the passed in mode is already bogus.
Sorry I meant to say 'is required'.
Quoted 6 lines
The lock is about making sure the write of
cxled->moderelative to the state of the dpa partitions is an atomic check-and-set.So this makes the function unconditionally take the lock when it might be bogus to do so. The value of reorganizing this is questionable.
Why would it be bogus? I don't see that. Regardless I dropped the patch as it is not worth spending more time on. There are bigger issues to resolve with this series.
Ira
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
In reply to Ira WeinyQuoted 42 lines · Ira Weiny
Quoted 5 lines · Alison Schofield
Quoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.Not true.
Sorry for not being clear. It does check the mode 2x but not for validity. I'll clarify.
Quoted 3 lines
It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
But we can check the mode 1 time and either check the size or fail.
Quoted 5 lines
Quoted 2 lines
The function is not in a critical path.
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Implying that checking the mode outside the lock is not required.
Quoted 9 lines
Quoted 7 lines
Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Simplify the mode check before adding the more complex DC modes.
The addition of the DC mode check doesn't seem complex.
It is if you have to check it 2 times.
Quoted 5 lines
Pardon my picking at the words, but if you'd like to refactor the function, just say so. The final result is a bit more readable, but also adding the DC mode checks without refactoring would read fine also.
Quoted 4 lines
When I added the DC mode to this function without this refactoring it was quite a bit more code and ugly IMO. So this cleanup helped. If I were not adding the DC code there would be much less reason to change this function.
Where did the "quite a bit more code" come from? A change that moves unnecessary code under a lock and is larger than just incrementally extending the status quo does not feel like a cleanup.
drivers/cxl/core/hdm.c +7 -1
@@ -411,11 +411,12 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +int rc, dcd;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);
@@ -442,6 +443,11 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, rc = -ENXIO ; goto out; } + dcd =dc_mode_to_region_index (mode); +if (resource_size (&cxlds->dc_res[dcd]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); + goto out; + } cxled->mode = mode; rc =0 ;
Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode()
Quoted 43 lines · Dan Williams
Quoted 42 lines · Ira Weiny
Quoted 5 lines · Alison Schofield
Quoted 2 lines · Ira Weiny
cxl_dpa_set_mode()checks the mode for validity two times, once outside of the DPA RW semaphore and again within.Not true.
Sorry for not being clear. It does check the mode 2x but not for validity. I'll clarify.
Quoted 3 lines
It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through.
But we can check the mode 1 time and either check the size or fail.
Quoted 5 lines
Quoted 2 lines
The function is not in a critical path.
Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking.
Implying that checking the mode outside the lock is not required.
Quoted 9 lines
Quoted 7 lines
Prior to Dynamic Capacity the extra check was not much of an issue. The addition of DC modes increases the complexity of the check.
Simplify the mode check before adding the more complex DC modes.
The addition of the DC mode check doesn't seem complex.
It is if you have to check it 2 times.
Quoted 5 lines
Pardon my picking at the words, but if you'd like to refactor the function, just say so. The final result is a bit more readable, but also adding the DC mode checks without refactoring would read fine also.
Quoted 8 lines
Quoted 4 lines
When I added the DC mode to this function without this refactoring it was quite a bit more code and ugly IMO. So this cleanup helped. If I were not adding the DC code there would be much less reason to change this function.
Where did the "quite a bit more code" come from? A change that moves unnecessary code under a lock and is larger than just incrementally extending the status quo does not feel like a cleanup.
I'll drop the patch.
Ira
Quoted 31 lines
drivers/cxl/core/hdm.c +7
-1@@ -411,11 +411,12 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; -int rc; +int rc, dcd;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);@@ -442,6 +443,11 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, rc = -ENXIO ; goto out; } + dcd =dc_mode_to_region_index (mode); +if (resource_size (&cxlds->dc_res[dcd]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); + goto out; + } cxled->mode = mode; rc =0 ;
PATCH 6/26 cxl/port: Add Dynamic Capacity mode support to endpoint decoders
In reply to [email protected]From: Navneet Singh <[email protected]>
Endpoint decoders which are used to map Dynamic Capacity must be configured to point to the correct Dynamic Capacity (DC) Region. The decoder mode currently represents the partition the decoder points to such as ram or pmem.
Expand the mode to include DC regions [partitions].
---
Changes for v1:
[iweiny: eliminate added gotos]
[iweiny: Mark DC support for 6.10 kernel]
--- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++++++---------- drivers/cxl/core/hdm.c | 19 +++++++++++++++++++ drivers/cxl/core/port.c | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 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, June 2024 +KernelVersion: v6.0, v6.10 (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 the volatile/persistent partition boundary, + 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 +19 -0
@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode) +return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)
@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )
@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc; + +if (resource_size (&cxlds->dc_res[rc]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + } +break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;
drivers/cxl/core/port.c +16 -0
@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ; + else if (sysfs_streq(buf, "dc3")) + mode =CXL_DECODER_DC3 ; + else if (sysfs_streq(buf, "dc4")) + mode =CXL_DECODER_DC4 ; + else if (sysfs_streq(buf, "dc5")) + mode =CXL_DECODER_DC5 ; + else if (sysfs_streq(buf, "dc6")) + mode =CXL_DECODER_DC6 ; + else if (sysfs_streq(buf, "dc7")) + mode =CXL_DECODER_DC7 ; else return -EINVAL;
Signature · 1 line
2.44.0
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Quoted 7 lines · On Sun, Mar 24, 2024 at 04:18:09PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Endpoint decoders which are used to map Dynamic Capacity must be configured to point to the correct Dynamic Capacity (DC) Region. The decoder mode currently represents the partition the decoder points to such as ram or pmem.
Quoted 5 lines
Expand the mode to include DC regions [partitions].
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Minor comments below.
Quoted 55 lines
---
Changes for v1:
[iweiny: eliminate added gotos]
[iweiny: Mark DC support for 6.10 kernel]--- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++++++---------- drivers/cxl/core/hdm.c | 19 +++++++++++++++++++ drivers/cxl/core/port.c | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 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, June 2024 +KernelVersion: v6.0, v6.10 (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 the volatile/persistent partition boundary, + 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_resourcedrivers/cxl/core/hdm.c +0
-0
drivers/cxl/core/hdm.c static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled) · line 260
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode)
To me, it is more natural to have something like x<a || x>b other than x<a || b < x for out of range check.
Quoted 17 lines
drivers/cxl/core/hdm.c +6
-0+return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 450
Quoted 9 lines
drivers/cxl/core/hdm.c +6
-0@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc; + +if (resource_size (&cxlds->dc_res[rc]) ==0 ) {
The other similar checks above use "!resource_size(...)".
Fan
Quoted 38 lines
drivers/cxl/core/hdm.c +4
-0+dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + } +break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;drivers/cxl/core/port.c +16
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ; + else if (sysfs_streq(buf, "dc3")) + mode =CXL_DECODER_DC3 ; + else if (sysfs_streq(buf, "dc4")) + mode =CXL_DECODER_DC4 ; + else if (sysfs_streq(buf, "dc5")) + mode =CXL_DECODER_DC5 ; + else if (sysfs_streq(buf, "dc6")) + mode =CXL_DECODER_DC6 ; + else if (sysfs_streq(buf, "dc7")) + mode =CXL_DECODER_DC7 ; else return -EINVAL;Signature · 2 lines
-- 2.44.0
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Quoted 3 lines · fan
Quoted 2 lines · On Sun, Mar 24, 2024 at 04:18:09PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 8 lines
Quoted 8 lines
drivers/cxl/core/hdm.c +0
-0@@ -255,6 +255,14 @@ static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled)__cxl_dpa_release (cxled); }
Quoted 6 lines
drivers/cxl/core/hdm.c static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled) · line 260
Quoted 3 lines
drivers/cxl/core/hdm.c +3
-0+static int dc_mode_to_region_index (enum cxl_decoder_mode mode) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode)To me, it is more natural to have something like x<a || x>b other than x<a || b < x for out of range check.
Ok.
[snip]
Quoted 16 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 450
Quoted 13 lines
drivers/cxl/core/hdm.c +6
-0guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc; + +if (resource_size (&cxlds->dc_res[rc]) ==0 ) {The other similar checks above use "!resource_size(...)".
Yea good catch.
Ira
Dave Jiang
maintainerRe: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
In reply to [email protected]Quoted 67 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Endpoint decoders which are used to map Dynamic Capacity must be configured to point to the correct Dynamic Capacity (DC) Region. The decoder mode currently represents the partition the decoder points to such as ram or pmem.
Expand the mode to include DC regions [partitions].
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: eliminate added gotos]
[iweiny: Mark DC support for 6.10 kernel]--- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++++++---------- drivers/cxl/core/hdm.c | 19 +++++++++++++++++++ drivers/cxl/core/port.c | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 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, June 2024 +KernelVersion: v6.0, v6.10 (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 the volatile/persistent partition boundary, + 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_resourcedrivers/cxl/core/hdm.c +0
-0
drivers/cxl/core/hdm.c static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled) · line 260
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode)
I second what Fan said about readability here if you do (mode > CXL_DECODER_DC7) for upper bound check instead.
Quoted 47 lines
drivers/cxl/core/hdm.c +16
-0+return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc; + +if (resource_size (&cxlds->dc_res[rc]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + } +break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;drivers/cxl/core/port.c +6
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ;
drivers/cxl/core/port.c static ssize_t mode_store(struct device *dev, struct device_attribute *attr, · line 226
Quoted 10 lines
drivers/cxl/core/port.c +10
-0+else if (sysfs_streq (buf,"dc3" )) + mode =CXL_DECODER_DC3 ; +else if (sysfs_streq (buf,"dc4" )) + mode =CXL_DECODER_DC4 ; +else if (sysfs_streq (buf,"dc5" )) + mode =CXL_DECODER_DC5 ; +else if (sysfs_streq (buf,"dc6" )) + mode =CXL_DECODER_DC6 ; +else if (sysfs_streq (buf,"dc7" )) + mode =CXL_DECODER_DC7 ;
I think maybe create a static string table that correlates cxl_decoder_mode to string. Then you can simplify cxl_decoder_mode_name() and as well as here. And here I think you can just do a for loop and go through the entire static table.
Quoted 4 lines
drivers/cxl/core/port.c +0
-0else return -EINVAL ;
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Quoted 5 lines · Dave Jiang
Quoted 2 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 8 lines
Quoted 8 lines
drivers/cxl/core/hdm.c +0
-0@@ -255,6 +255,14 @@ static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled)__cxl_dpa_release (cxled); }
Quoted 6 lines
drivers/cxl/core/hdm.c static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled) · line 260
Quoted 3 lines
drivers/cxl/core/hdm.c +3
-0+static int dc_mode_to_region_index (enum cxl_decoder_mode mode) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode)I second what Fan said about readability here if you do (mode >
CXL_DECODER_DC7) for upper bound check instead.
Sure...
[snip]
Quoted 21 lines
Quoted 21 lines
drivers/cxl/core/port.c +13
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ; + else if (sysfs_streq(buf, "dc3")) + mode =CXL_DECODER_DC3 ; + else if (sysfs_streq(buf, "dc4")) + mode =CXL_DECODER_DC4 ; + else if (sysfs_streq(buf, "dc5")) + mode =CXL_DECODER_DC5 ; + else if (sysfs_streq(buf, "dc6"))
Quoted 8 lines
drivers/cxl/core/port.c static ssize_t mode_store(struct device *dev, struct device_attribute *attr, · line 226
Quoted 3 lines
drivers/cxl/core/port.c +3
-0+ mode =CXL_DECODER_DC6 ; + else if (sysfs_streq(buf, "dc7")) + mode =CXL_DECODER_DC7 ;I think maybe create a static string table that correlates
cxl_decoder_modeto string. Then you can simplifycxl_decoder_mode_name()and as well as here. And here I think you can just do a for loop and go through the entire static table.
Ok... Sure.
Ira
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
In reply to [email protected]Quoted 41 lines · On Sun, 24 Mar 2024 16:18:09 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Endpoint decoders which are used to map Dynamic Capacity must be configured to point to the correct Dynamic Capacity (DC) Region. The decoder mode currently represents the partition the decoder points to such as ram or pmem.
Expand the mode to include DC regions [partitions].
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: eliminate added gotos]
[iweiny: Mark DC support for 6.10 kernel]--- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++++++---------- drivers/cxl/core/hdm.c | 19 +++++++++++++++++++ drivers/cxl/core/port.c | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +2
-3@@ -316,23 +316,24 @@ Description: What: /sys/bus/cxl/devices/decoderX.Y/mode -Date: May, 2022 -KernelVersion: v6.0 +Date: May, 2022, June 2024 +KernelVersion: v6.0, v6.10 (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
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 330
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +5
-5- 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 the volatile/persistent partition boundary,
I love corners. What happen if no persistent and decoder straddles volatile / dc0? Would only happen if the bios was having fun I think...
Quoted 39 lines
Documentation/ABI/testing/sysfs-bus-cxl +4
-2+ 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_resourcedrivers/cxl/core/hdm.c +9
-0@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode) +return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 448
Quoted 7 lines
drivers/cxl/core/hdm.c +4
-0@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc;
Can't fail, so you could not bother checking.. Seems very unlikely that function will gain other error cases in the future.
Quoted 23 lines
drivers/cxl/core/hdm.c +6
-0+ +if (resource_size (&cxlds->dc_res[rc]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + } +break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;drivers/cxl/core/port.c +6
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ;
drivers/cxl/core/port.c static ssize_t mode_store(struct device *dev, struct device_attribute *attr, · line 226
Quoted 10 lines
drivers/cxl/core/port.c +10
-0+else if (sysfs_streq (buf,"dc3" )) + mode =CXL_DECODER_DC3 ; +else if (sysfs_streq (buf,"dc4" )) + mode =CXL_DECODER_DC4 ; +else if (sysfs_streq (buf,"dc5" )) + mode =CXL_DECODER_DC5 ; +else if (sysfs_streq (buf,"dc6" )) + mode =CXL_DECODER_DC6 ; +else if (sysfs_streq (buf,"dc7" )) + mode =CXL_DECODER_DC7 ;
Fully agree with the comment that a string + enum table and search is probably appropriate here.
Quoted 4 lines
drivers/cxl/core/port.c +0
-0else return -EINVAL ;
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 24 Mar 2024 16:18:09 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 23 lines
Quoted 23 lines
Documentation/ABI/testing/sysfs-bus-cxl +2
-8@@ -316,23 +316,24 @@ Description: What: /sys/bus/cxl/devices/decoderX.Y/mode -Date: May, 2022 -KernelVersion: v6.0 +Date: May, 2022, June 2024 +KernelVersion: v6.0, v6.10 (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.
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 330
Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-cxl +5
-0+ 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 the volatile/persistent partition boundary,I love corners. What happen if no persistent and decoder straddles volatile / dc0? Would only happen if the bios was having fun I think..
Yep same issue with a wonky bios... I did not change this text. Only got reformatted. But it is worth changing to:
... The 'mixed' indication is for error cases when a decoder
straddles partition boundaries, ...
Quoted 37 lines
Quoted 37 lines
Documentation/ABI/testing/sysfs-bus-cxl +4
-2+ 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_resourcedrivers/cxl/core/hdm.c +9
-0@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode) +return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +} +static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;
Quoted 13 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 448
Quoted 10 lines
drivers/cxl/core/hdm.c +4
-0guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc;Can't fail, so you could not bother checking.. Seems very unlikely that function will gain other error cases in the future.
Sure, done.
Quoted 29 lines
Quoted 29 lines
drivers/cxl/core/hdm.c +6
-0+ +if (resource_size (&cxlds->dc_res[rc]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + } +break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;drivers/cxl/core/port.c +11
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ; + else if (sysfs_streq(buf, "dc3")) + mode =CXL_DECODER_DC3 ; + else if (sysfs_streq(buf, "dc4")) + mode =CXL_DECODER_DC4 ; + else if (sysfs_streq(buf, "dc5"))
Quoted 9 lines
drivers/cxl/core/port.c static ssize_t mode_store(struct device *dev, struct device_attribute *attr, · line 226
Quoted 5 lines
drivers/cxl/core/port.c +5
-0+ mode =CXL_DECODER_DC5 ; + else if (sysfs_streq(buf, "dc6")) + mode =CXL_DECODER_DC6 ; + else if (sysfs_streq(buf, "dc7")) + mode =CXL_DECODER_DC7 ;Fully agree with the comment that a string + enum table and search is probably appropriate here.
Ok, done.
Ira
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Ira Weiny wrote:
[..]
Quoted 9 lines
Quoted 7 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 448
Quoted 4 lines
drivers/cxl/core/hdm.c +4
-0+ case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc;Can't fail, so you could not bother checking.. Seems very unlikely that function will gain other error cases in the future.
Sure, done.
Can dc_mode_to_region_index() be dropped altogether? Is there any scenario where dc_mode_to_region_index() is really handling an anonymous @mode argument? I.e. just replace all dc_mode_to_region_index() with "mode - CXL_DECODER_DC0"?
Re: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
Quoted 10 lines · Dan Williams
Ira Weiny wrote:
[..]Quoted 8 lines
Quoted 7 lines
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 448
Quoted 4 lines
drivers/cxl/core/hdm.c +4
-0+ case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc;Can't fail, so you could not bother checking.. Seems very unlikely that function will gain other error cases in the future.
Quoted 6 lines
Quoted 1 line
Sure, done.
Can
dc_mode_to_region_index()be dropped altogether? Is there any scenario wheredc_mode_to_region_index()is really handling an anonymous @mode argument? I.e. just replace alldc_mode_to_region_index()with "mode -CXL_DECODER_DC0"?
Once we open up DC partitions to support multiple regions, no.
How about we remove the check in dc_mode_to_region_index() but keep the function? That makes it clear that we are converting from an enum to int index?
Ira
Alison Schofield
maintainerRe: [PATCH 06/26] cxl/port: Add Dynamic Capacity mode support to endpoint decoders
In reply to [email protected]Quoted 67 lines · Ira Weiny
From: Navneet Singh <[email protected]>
Endpoint decoders which are used to map Dynamic Capacity must be configured to point to the correct Dynamic Capacity (DC) Region. The decoder mode currently represents the partition the decoder points to such as ram or pmem.
Expand the mode to include DC regions [partitions].
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: eliminate added gotos]
[iweiny: Mark DC support for 6.10 kernel]--- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++++++++++---------- drivers/cxl/core/hdm.c | 19 +++++++++++++++++++ drivers/cxl/core/port.c | 16 ++++++++++++++++ 3 files changed, 46 insertions(+), 10 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, June 2024 +KernelVersion: v6.0, v6.10 (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 the volatile/persistent partition boundary, + 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_resourcedrivers/cxl/core/hdm.c +0
-0
drivers/cxl/core/hdm.c static void devm_cxl_dpa_release(struct cxl_endpoint_decoder *cxled) · line 264
Quoted 10 lines
drivers/cxl/core/hdm.c +7
-0@@ -255,6 +255,14 @@ 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) +{ +if (mode <CXL_DECODER_DC0 ||CXL_DECODER_DC7 < mode) +return -EINVAL ; + +return mode -CXL_DECODER_DC0 ; +}
Curious why this works?
Quoted 15 lines
drivers/cxl/core/hdm.c +2
-0+static int __cxl_dpa_reserve (struct cxl_endpoint_decoder *cxled,resource_size_t base,resource_size_t len,resource_size_t skipped)@@ -411,6 +419,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev; +int rc;guard (rwsem_write)(&cxl_dpa_rwsem);if (cxled->cxld.flags &CXL_DECODER_F_ENABLE )@@ -433,6 +442,16 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,return -ENXIO ; }
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 453
Quoted 10 lines
drivers/cxl/core/hdm.c +9
-0break ; + case CXL_DECODER_DC0 ... CXL_DECODER_DC7: + rc =dc_mode_to_region_index (mode); +if (rc <0 ) +return rc; + +if (resource_size (&cxlds->dc_res[rc]) ==0 ) { +dev_dbg (dev,"no available dynamic capacity\n" ); +return -ENXIO ; + }
return rc breaks the pattern in this function.
Feels like 'rc' can be named 'index' since we index into dc_res[]. Explicitly show the return -EINVAL here as other cases do.
like:
index = dc_mode_to_region_index(mode); if (index < 0) return -EINVAL;
and then:
dc_mode_to_region_index() can just return -1 or still return -EINVAL.
Quoted 35 lines
drivers/cxl/core/hdm.c +1
-0+break ;default :dev_dbg (dev,"unsupported mode: %d\n" , mode);return -EINVAL ;drivers/cxl/core/port.c +16
-0@@ -208,6 +208,22 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr, mode =CXL_DECODER_PMEM ; else if (sysfs_streq(buf, "ram")) mode =CXL_DECODER_RAM ; + else if (sysfs_streq(buf, "dc0")) + mode =CXL_DECODER_DC0 ; + else if (sysfs_streq(buf, "dc1")) + mode =CXL_DECODER_DC1 ; + else if (sysfs_streq(buf, "dc2")) + mode =CXL_DECODER_DC2 ; + else if (sysfs_streq(buf, "dc3")) + mode =CXL_DECODER_DC3 ; + else if (sysfs_streq(buf, "dc4")) + mode =CXL_DECODER_DC4 ; + else if (sysfs_streq(buf, "dc5")) + mode =CXL_DECODER_DC5 ; + else if (sysfs_streq(buf, "dc6")) + mode =CXL_DECODER_DC6 ; + else if (sysfs_streq(buf, "dc7")) + mode =CXL_DECODER_DC7 ; else return -EINVAL;Signature · 2 lines
-- 2.44.0
PATCH 7/26 cxl/port: Add dynamic capacity size support to endpoint decoders
In reply to [email protected]From: 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 Regions. 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 Regions. The desired CXL mapping is 5GB of RAM, 5GB of PMEM, and all 10GB 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|----|----------|----------|----------|XXXXXXXXXX| 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|----|----------|----------|----------|XXXXXXXXXX|
skip skip skip skip skipExpand the calculation of DPA freespace and enhance the logic to support mapping/unmapping DC DPA space. 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 for v1:
[iweiny: Update cover letter]
--- drivers/cxl/core/hdm.c | 192 +++++++++++++++++++++++++++++++++++++++++++----- drivers/cxl/core/port.c | 2 + drivers/cxl/cxl.h | 2 + 3 files changed, 179 insertions(+), 17 deletions(-)
drivers/cxl/core/hdm.c +175 -17
@@ -210,6 +210,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)
@@ -220,15 +239,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);
@@ -263,6 +278,100 @@ 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)
@@ -300,13 +409,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,
@@ -314,14 +422,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))
@@ -332,6 +446,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 ;
@@ -463,14 +580,14 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size) { +resource_size_t free_ram_start, free_pmem_start, free_dc_start;struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -resource_size_t free_ram_start, free_pmem_start;struct cxl_port *port =cxled_to_port (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev;resource_size_t start, avail, skip;struct resource *p, *last; -int rc; +int rc, dc_index;down_write (&cxl_dpa_rwsem);if (cxled->cxld.region) {
@@ -500,6 +617,21 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry. +*/ + dc_index =dc_mode_to_region_index (cxled->mode); +if (dc_index >=0 ) { +if (cxlds->dc_res[dc_index].child) { +dev_err (dev,"Cannot allocate DPA from DC Region: %d\n" , + dc_index); + rc = -EINVAL ; + goto out; + } + free_dc_start = cxlds->dc_res[dc_index].start; + } +if (cxled->mode ==CXL_DECODER_RAM ) { start = free_ram_start; avail = cxlds->ram_res.end - start +1 ;
@@ -521,12 +653,38 @@ 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)) { +resource_size_t skip_start, skip_end; + + start = free_dc_start; + avail = cxlds->dc_res[dc_index].end - start +1 ; +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 ; }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, cxled->mode == CXL_DECODER_RAM ? "ram" : "pmem",
drivers/cxl/core/port.c +2 -0
@@ -434,6 +434,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); }
@@ -1896,6 +1897,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
@@ -441,6 +441,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
@@ -449,6 +450,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.44.0
Re: [PATCH 07/26] cxl/port: Add dynamic capacity size support to endpoint decoders
Quoted 22 lines · On Sun, 24 Mar 2024 16:18:10 -0700 [email protected] wrote:
From: 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 Regions. 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 Regions. The desired CXL mapping is 5GB of RAM, 5GB of PMEM, and all 10GB of DC1.
DPA RANGE (dpa_res) 0GB 10GB 20GB 30GB 40GB 50GB 60GB |----------|----------|----------|----------|----------|----------|
Quoted 7 lines
RAM PMEM DC0 DC1 (ram_res) (pmem_res) (dc_res[0]) (dc_res[1])|----------|----------| <gap> |----------| <gap> |----------|
RAM PMEM DC1
|XXXXX|----|XXXXX|----|----------|----------|----------|XXXXXXXXXX| 0GB 5GB 10GB 15GB 20GB 30GB 40GB 50GB 60GB
To add another corner to the example, maybe map only part of DC1?
Quoted 249 lines
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|----|----------|----------|----------|XXXXXXXXXX| skip skip skip skip skipExpand the calculation of DPA freespace and enhance the logic to support mapping/unmapping DC DPA space. 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.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: Update cover letter]--- drivers/cxl/core/hdm.c | 192 +++++++++++++++++++++++++++++++++++++++++++----- drivers/cxl/core/port.c | 2 + drivers/cxl/cxl.h | 2 + 3 files changed, 179 insertions(+), 17 deletions(-)drivers/cxl/core/hdm.c +133
-15@@ -210,6 +210,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) @@ -220,15 +239,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);@@ -263,6 +278,100 @@ 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)@@ -300,13 +409,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,@@ -314,14 +422,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))@@ -332,6 +446,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 ;@@ -463,14 +580,14 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size) { +resource_size_t free_ram_start, free_pmem_start, free_dc_start;struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);
drivers/cxl/core/hdm.c int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, · line 592
Quoted 10 lines
drivers/cxl/core/hdm.c +1
-2-resource_size_t free_ram_start, free_pmem_start;struct cxl_port *port =cxled_to_port (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev;resource_size_t start, avail, skip;struct resource *p, *last; -int rc; +int rc, dc_index;down_write (&cxl_dpa_rwsem);
Obviously not related to this patch as such, but maybe a good place for scoped_guard() to avoid the dance around unlocking the rwsem and allow some early returns on the error paths.
Quoted 40 lines
drivers/cxl/core/hdm.c +28
-0if (cxled->cxld.region) {@@ -500,6 +617,21 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry. +*/ + dc_index =dc_mode_to_region_index (cxled->mode); +if (dc_index >=0 ) { +if (cxlds->dc_res[dc_index].child) { +dev_err (dev,"Cannot allocate DPA from DC Region: %d\n" , + dc_index); + rc = -EINVAL ; + goto out; + } + free_dc_start = cxlds->dc_res[dc_index].start; + } +if (cxled->mode ==CXL_DECODER_RAM ) { start = free_ram_start; avail = cxlds->ram_res.end - start +1 ;@@ -521,12 +653,38 @@ 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)) { +resource_size_t skip_start, skip_end; + + start = free_dc_start; + avail = cxlds->dc_res[dc_index].end - start +1 ; +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.
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 678
Quoted 10 lines
drivers/cxl/core/hdm.c +10
-0+*/ +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 ;
I notice in the pmem equivalent there is a case for part of the region already mapped. Can that not happen for a DC region as well?
Quoted 12 lines
drivers/cxl/core/hdm.c +3
-0}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, cxled->mode == CXL_DECODER_RAM ? "ram" : "pmem",
Re: [PATCH 07/26] cxl/port: Add dynamic capacity size support to endpoint decoders
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Sun, 24 Mar 2024 16:18:10 -0700 [email protected] wrote:
From: 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 Regions. 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 Regions. The desired CXL mapping is 5GB of RAM, 5GB of PMEM, and all 10GB 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> |----------|
Quoted 6 lines
Quoted 3 lines
RAM PMEM DC1
|XXXXX|----|XXXXX|----|----------|----------|----------|XXXXXXXXXX| 0GB 5GB 10GB 15GB 20GB 30GB 40GB 50GB 60GBTo add another corner to the example, maybe map only part of DC1?
Maybe. See below.
[snip]
Quoted 7 lines
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 622
Quoted 7 lines
drivers/cxl/core/hdm.c +3
-0@@ -500,6 +617,21 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry.
This prevents more than 1 region per DC partition (region).
Quoted 37 lines
Quoted 37 lines
drivers/cxl/core/hdm.c +30
-0+*/ + dc_index =dc_mode_to_region_index (cxled->mode); +if (dc_index >=0 ) { +if (cxlds->dc_res[dc_index].child) { +dev_err (dev,"Cannot allocate DPA from DC Region: %d\n" , + dc_index); + rc = -EINVAL ; + goto out; + } + free_dc_start = cxlds->dc_res[dc_index].start; + } +if (cxled->mode ==CXL_DECODER_RAM ) { start = free_ram_start; avail = cxlds->ram_res.end - start +1 ;@@ -521,12 +653,38 @@ 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)) { +resource_size_t skip_start, skip_end; + + start = free_dc_start; + avail = cxlds->dc_res[dc_index].end - start +1 ; +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 ;
Quoted 8 lines
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 678
Quoted 5 lines
drivers/cxl/core/hdm.c +5
-0+ } + } + + skip_end = start -1 ; + skip = skip_end - skip_start +1 ;I notice in the pmem equivalent there is a case for part of the region already mapped. Can that not happen for a DC region as well?
See above check. Each DC region (partition) was to be associated with a single DSMAS entry. I'm unclear now why that decision was made.
It does not seem hard to add this though. Do we really need that ability considering dax devices are likely going to be the main boundry for users of a DC region?
Ira
Re: [PATCH 07/26] cxl/port: Add dynamic capacity size support to endpoint decoders
Quoted 8 lines · Ira Weiny
Quoted 6 lines
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 622
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry. This prevents more than 1 region per DC partition (region).
Why? Multiple regions per partition is the current status quo for other partition types.
Quoted 5 lines
Quoted 2 lines
I notice in the pmem equivalent there is a case for part of the region already mapped. Can that not happen for a DC region as well?
See above check. Each DC region (partition) was to be associated with a single DSMAS entry. I'm unclear now why that decision was made.
The limitation of one DSMAS per partition makes sense otherwise that would indicate performance across different spans of the partition.
Quoted 3 lines
It does not seem hard to add this though. Do we really need that ability considering dax devices are likely going to be the main boundry for users of a DC region?
It seems like extra work to make DCD a special case compared to the other partition types, so the burden of proof is the other way. Why tolerate DCD divergence from the status quo?
Re: [PATCH 07/26] cxl/port: Add dynamic capacity size support to endpoint decoders
Quoted 22 lines · Dan Williams
Quoted 8 lines · Ira Weiny
Quoted 6 lines
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 622
Quoted 6 lines
drivers/cxl/core/hdm.c +3
-0else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry. This prevents more than 1 region per DC partition (region).
Why? Multiple regions per partition is the current status quo for other partition types.
Quoted 5 lines
Quoted 2 lines
I notice in the pmem equivalent there is a case for part of the region already mapped. Can that not happen for a DC region as well?
See above check. Each DC region (partition) was to be associated with a single DSMAS entry. I'm unclear now why that decision was made.
The limitation of one DSMAS per partition makes sense otherwise that would indicate performance across different spans of the partition.
Quoted 7 lines
Quoted 3 lines
It does not seem hard to add this though. Do we really need that ability considering dax devices are likely going to be the main boundry for users of a DC region?
It seems like extra work to make DCD a special case compared to the other partition types, so the burden of proof is the other way. Why tolerate DCD divergence from the status quo?
I don't remember the details. But this was discussed before in a call. I'm ok adding this support. I have a test for it now. Just need to tweek a couple of things.
Ira
Alison Schofield
maintainerRe: [PATCH 07/26] cxl/port: Add dynamic capacity size support to endpoint decoders
In reply to [email protected]Quoted 9 lines · Ira Weiny
From: 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
RAM
Quoted 31 lines
exist between and around the DC Regions. 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 Regions. The desired CXL mapping is 5GB of RAM, 5GB of PMEM, and all 10GB 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|----|----------|----------|----------|XXXXXXXXXX| 0GB 5GB 10GB 15GB 20GB 30GB 40GB 50GB 60GBThe 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).
Quoted 10 lines
0GB 10GB 20GB 30GB 40GB 50GB 60GB
|----------|----------|----------|----------|----------|----------|
| |
|----------|----------| | |----------| | |----------|
| | | | |
(S) (A) (B) (C) (D)
v v v v v
|XXXXX|----|XXXXX|----|----------|----------|----------|XXXXXXXXXX|
skip skip skip skip skipNice art!
Quoted 6 lines
Expand the calculation of DPA freespace and enhance the logic to support mapping/unmapping DC DPA space. 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.
This passed the unit test cxl-poison.sh that relies on you not totally breaking the cxled->skip here. Not exactly a tested by, but something!
Quoted 19 lines
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: Update cover letter]--- drivers/cxl/core/hdm.c | 192 +++++++++++++++++++++++++++++++++++++++++++----- drivers/cxl/core/port.c | 2 + drivers/cxl/cxl.h | 2 + 3 files changed, 179 insertions(+), 17 deletions(-)drivers/cxl/core/hdm.c +0
-0
drivers/cxl/core/hdm.c void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds) · line 217
Quoted 8 lines
drivers/cxl/core/hdm.c +5
-0@@ -210,6 +210,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;
Here and below it's probably needless to define dev. Just &port->dev in your single dev_dbg() This is something to check for across the patchset.
Quoted 36 lines
drivers/cxl/core/hdm.c +15
-5+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) @@ -220,15 +239,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);@@ -263,6 +278,100 @@ static int dc_mode_to_region_index(enum cxl_decoder_mode mode)return mode -CXL_DECODER_DC0 ;
drivers/cxl/core/hdm.c static int dc_mode_to_region_index(enum cxl_decoder_mode mode) · line 288
Quoted 10 lines
drivers/cxl/core/hdm.c +8
-0} +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;
again
Quoted 168 lines
drivers/cxl/core/hdm.c +110
-12+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)@@ -300,13 +409,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,@@ -314,14 +422,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))@@ -332,6 +446,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 ;@@ -463,14 +580,14 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,int cxl_dpa_alloc (struct cxl_endpoint_decoder *cxled,unsigned long long size) { +resource_size_t free_ram_start, free_pmem_start, free_dc_start;struct cxl_memdev *cxlmd =cxled_to_memdev (cxled); -resource_size_t free_ram_start, free_pmem_start;struct cxl_port *port =cxled_to_port (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct device *dev = &cxled->cxld.dev;resource_size_t start, avail, skip;struct resource *p, *last; -int rc; +int rc, dc_index;down_write (&cxl_dpa_rwsem);if (cxled->cxld.region) {@@ -500,6 +617,21 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)else free_pmem_start = cxlds->pmem_res.start; +/* +* Limit each decoder to a single DC region to map memory with +* different DSMAS entry. +*/
drivers/cxl/core/hdm.c int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) · line 633
Quoted 10 lines
drivers/cxl/core/hdm.c +10
-0+ dc_index =dc_mode_to_region_index (cxled->mode); +if (dc_index >=0 ) { +if (cxlds->dc_res[dc_index].child) { +dev_err (dev,"Cannot allocate DPA from DC Region: %d\n" , + dc_index); + rc = -EINVAL ; + goto out; + } + free_dc_start = cxlds->dc_res[dc_index].start; + }
From the "Limit each decoder" comment to here please explain. I'm reading we cannot alloc dpa from this DC region because is has a child? And a child is a region? Maybe I got it ;)
snip to end
--Alison
PATCH 8/26 cxl/mem: Expose device dynamic capacity capabilities
In reply to [email protected]From: 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 Regions available on a device.
Expose driver dynamic capacity capabilities through sysfs attributes.
---
Changes for v1:
[iweiny: remove review tags]
[iweiny: mark sysfs for 6.10 kernel]
--- Documentation/ABI/testing/sysfs-bus-cxl | 17 ++++++++ drivers/cxl/core/memdev.c | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +17 -0
@@ -54,6 +54,23 @@ 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 +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Number of Dynamic Capacity (DC) regions supported on the + device. May be 0 if the device does not support Dynamic + Capacity. + +What: /sys/bus/cxl/devices/memX/dc/regionY_size +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Size of the Dynamic Capacity (DC) region Y. Only + available on devices which support DC and only for those + region indexes supported by the device. What: /sys/bus/cxl/devices/memX/pmem/qos_class Date: May, 2023
drivers/cxl/core/memdev.c +76 -0
99 lines not on this page · raw message
Signature · 1 line
2.44.0
Davidlohr Bueso
maintainerRe: [PATCH 08/26] cxl/mem: Expose device dynamic capacity capabilities
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 64
Quoted 8 lines · On Sun, 24 Mar 2024, [email protected] wrote:
Documentation/ABI/testing/sysfs-bus-cxl +8
-0+What: /sys/bus/cxl/devices/memX/dc/region_count +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Number of Dynamic Capacity (DC) regions supported on the + device. May be 0 if the device does not support Dynamic + Capacity.
If dcd is not supported then we should not have the dc/ directory altogether.
Thanks,
Davidlohr
Re: [PATCH 08/26] cxl/mem: Expose device dynamic capacity capabilities
Quoted 14 lines · Davidlohr Bueso
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 64
Quoted 8 lines · On Sun, 24 Mar 2024, [email protected] wrote:
Documentation/ABI/testing/sysfs-bus-cxl +8
-0+What: /sys/bus/cxl/devices/memX/dc/region_count +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Number of Dynamic Capacity (DC) regions supported on the + device. May be 0 if the device does not support Dynamic + Capacity.If dcd is not supported then we should not have the dc/ directory altogether.
Quoted 2 lines
Thanks,
Davidlohr
I also think so. However, I also noticed one thing (not DCD related). Even for a PMEM device, for example, we have a ram directory under the device directory.
===================
root@DT:~# cxl list
[
{
"memdev":"mem0",
"pmem_size":536870912,
"serial":0,
"host":"0000:0d:00.0"
}
]
root@DT:~# ls /sys/bus/cxl/devices/mem0/
dc dev driver firmware firmware_version label_storage_size numa_node payload_max pmem pmem0 ram security serial subsystem trigger_poison_list uevent
root@DT:~#
===================Fan
Re: [PATCH 08/26] cxl/mem: Expose device dynamic capacity capabilities
Quoted 15 lines · On Tue, 26 Mar 2024 11:30:38 -0700 fan <[email protected]> wrote:
Quoted 14 lines · Davidlohr Bueso
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 64
Quoted 8 lines · On Sun, 24 Mar 2024, [email protected] wrote:
Documentation/ABI/testing/sysfs-bus-cxl +8
-0+What: /sys/bus/cxl/devices/memX/dc/region_count +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Number of Dynamic Capacity (DC) regions supported on the + device. May be 0 if the device does not support Dynamic + Capacity.If dcd is not supported then we should not have the dc/ directory altogether.
Quoted 6 lines
Quoted 2 lines
Thanks,
DavidlohrI also think so. However, I also noticed one thing (not DCD related). Even for a PMEM device, for example, we have a ram directory under the device directory.
True, but it's new ABI so we don't have to copy and Dan's patch to allow for hiding static attribute directories has landed in the meantime. So I vote for hiding it.
Quoted 18 lines
===================
root@DT:~# cxl list [ { "memdev":"mem0", "pmem_size":536870912, "serial":0, "host":"0000:0d:00.0" } ] root@DT:~# ls /sys/bus/cxl/devices/mem0/ dc dev driver firmware firmware_version label_storage_size numa_node payload_max pmem pmem0 ram security serial subsystem trigger_poison_list uevent root@DT:~# ===================Fan
Re: [PATCH 08/26] cxl/mem: Expose device dynamic capacity capabilities
In reply to [email protected]Quoted 6 lines · On Sun, 24 Mar 2024 16:18:11 -0700 [email protected] wrote:
From: 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 Regions available on a device.
Quoted 6 lines
Expose driver dynamic capacity capabilities through sysfs attributes.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Trivial comments inline.
Whilst I'd like the directory hidden as per the other suggestions, I don't mind that much.
Quoted 16 lines
---
Changes for v1:
[iweiny: remove review tags]
[iweiny: mark sysfs for 6.10 kernel]--- Documentation/ABI/testing/sysfs-bus-cxl | 17 ++++++++ drivers/cxl/core/memdev.c | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)Documentation/ABI/testing/sysfs-bus-cxl +0
-0@@ -54,6 +54,23 @@ Description: identically named field in the Identify Memory Device Output
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 64
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +8
-0Payload in the CXL-2.0 specification. +What: /sys/bus/cxl/devices/memX/dc/region_count +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Number of Dynamic Capacity (DC) regions supported on the + device. May be 0 if the device does not support Dynamic + Capacity.
That will change if you go ahead and hide the directory as per suggestions.
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 71
Quoted 7 lines
Documentation/ABI/testing/sysfs-bus-cxl +7
-0+ +What: /sys/bus/cxl/devices/memX/dc/regionY_size +Date: June, 2024 +KernelVersion: v6.10 +Contact: [email protected] +Description: + (RO) Size of the Dynamic Capacity (DC) region Y. Only
Units always good to have in docs even if somewhat obvious.
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +2
-0+ available on devices which support DC and only for those + region indexes supported by the device. What: /sys/bus/cxl/devices/memX/pmem/qos_class Date: May, 2023drivers/cxl/core/memdev.c +0
-0@@ -101,6 +101,18 @@ static ssize_t pmem_size_show(struct device *dev, struct device_attribute *attr,
...
Quoted 19 lines
drivers/cxl/core/memdev.c +19
-0+static struct attribute *cxl_memdev_dc_attributes[] = { + &dev_attr_region0_size.attr, + &dev_attr_region1_size.attr, + &dev_attr_region2_size.attr, + &dev_attr_region3_size.attr, + &dev_attr_region4_size.attr, + &dev_attr_region5_size.attr, + &dev_attr_region6_size.attr, + &dev_attr_region7_size.attr, + &dev_attr_region_count.attr, +NULL , +}; + +static umode_t cxl_dc_visible (struct kobject *kobj,struct attribute *a,int n) +{ +struct device *dev =kobj_to_dev (kobj); +struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +
drivers/cxl/core/memdev.c static struct attribute *cxl_memdev_security_attributes[] = { · line 559
Quoted 10 lines
drivers/cxl/core/memdev.c +10
-0+/* Not a memory device */ +if (!mds) +return 0 ; + +if (a == &dev_attr_region_count.attr) +return a->mode; + +/* Show only the regions supported */ +if (n < mds->nr_dc_region) +return a->mode;
This feels a bit fragile if anyone adds new attrs in future and for whatever reason does it before these.
Maybe add a comment at top of cxl_memdev_dc_attributes()? Say they must be first.
Quoted 6 lines
drivers/cxl/core/memdev.c +4
-0+ +return 0 ; +} +
PATCH 9/26 cxl/region: Add Dynamic Capacity CXL region support
In reply to [email protected]From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the create_dc_region sysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backwards compatibility with older software which needs a default DAX device to hold the region reference.
Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Interleaving is deferred in this series. Add an early check.
---
Changes for v1:
[djiang: mark sysfs entries to be in 6.10 kernel including date] [djbw: change dax region typing to be 'sparse' rather than 'dynamic'] [iweiny: rebase changes to master instead of type2 patches]
--- Documentation/ABI/testing/sysfs-bus-cxl | 22 +++++++++++----------- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 1 + drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++++ drivers/dax/bus.c | 8 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 15 +++++++++++++-- 7 files changed, 68 insertions(+), 13 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +11 -11
@@ -411,20 +411,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, June 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.10 (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 +1 -0
@@ -13,6 +13,7 @@ extern struct attribute_group cxl_base_attribute_group;#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
@@ -335,6 +335,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 +33 -0
@@ -2205,6 +2205,7 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,switch (mode) {case CXL_REGION_RAM :case CXL_REGION_PMEM : +case CXL_REGION_DC :break ;default : dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %s\n",
@@ -2314,6 +2315,32 @@ static ssize_t create_ram_region_store(struct device *dev, }DEVICE_ATTR_RW (create_ram_region); +static ssize_t create_dc_region_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return __create_region_show (to_cxl_root_decoder (dev), buf); +} + +static ssize_t create_dc_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_DC , id); +if (IS_ERR (cxlr)) +return PTR_ERR (cxlr); + +return len; +} +DEVICE_ATTR_RW (create_dc_region); +static ssize_t region_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -2759,6 +2786,11 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_REGION_DC && cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + cxlr_dax =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))return PTR_ERR (cxlr_dax);
@@ -3040,6 +3072,7 @@ static int cxl_region_probe(struct device *dev)case CXL_REGION_PMEM :return devm_cxl_add_pmem_region (cxlr);case CXL_REGION_RAM : +case CXL_REGION_DC :/* * The region can not be manged by CXL if any portion of * it is already online as 'System RAM'
drivers/dax/bus.c +8 -0
@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_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);
@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)WARN_ON_ONCE (!rwsem_is_locked (&dax_region_rwsem)); +if (is_sparse (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;
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 +13 -2
@@ -13,19 +13,30 @@ 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 ; + dev_size =range_len (&cxlr_dax->hpa_range); +/* Add empty seed dax device */ +if (cxlr->mode ==CXL_REGION_DC ) + dev_size =0 ; + 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.44.0
Re: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
Quoted 128 lines · On Sun, Mar 24, 2024 at 04:18:12PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the
create_dc_regionsysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backwards compatibility with older software which needs a default DAX device to hold the region reference.Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Interleaving is deferred in this series. Add an early check.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[djiang: mark sysfs entries to be in 6.10 kernel including date] [djbw: change dax region typing to be 'sparse' rather than 'dynamic'] [iweiny: rebase changes to master instead of type2 patches]--- Documentation/ABI/testing/sysfs-bus-cxl | 22 +++++++++++----------- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 1 + drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++++ drivers/dax/bus.c | 8 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 15 +++++++++++++-- 7 files changed, 68 insertions(+), 13 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +11
-11@@ -411,20 +411,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, June 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.10 (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_regiondrivers/cxl/core/core.h +1
-0@@ -13,6 +13,7 @@ extern struct attribute_group cxl_base_attribute_group;#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@@ -335,6 +335,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 +16
-0@@ -2205,6 +2205,7 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,switch (mode) {case CXL_REGION_RAM :case CXL_REGION_PMEM : +case CXL_REGION_DC :break ;default : dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %s\n",@@ -2314,6 +2315,32 @@ static ssize_t create_ram_region_store(struct device *dev, }DEVICE_ATTR_RW (create_ram_region); +static ssize_t create_dc_region_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return __create_region_show (to_cxl_root_decoder (dev), buf); +} + +static ssize_t create_dc_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);
drivers/cxl/core/region.c static ssize_t create_ram_region_store(struct device *dev, · line 2342
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+if (rc !=1 ) +return -EINVAL ; + + cxlr =__create_region (cxlrd,CXL_REGION_DC , id); +if (IS_ERR (cxlr)) +return PTR_ERR (cxlr); + +return len; +} +DEVICE_ATTR_RW (create_dc_region);
create_ram_region_store, create_pmem_region_store and create_dc_region_store have mostly duplicate code, should we consider extracting out as a helper function and pass region type for ram/pmem/dc region store?
Fan
Quoted 103 lines
drivers/cxl/core/region.c +7
-0+static ssize_t region_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -2759,6 +2786,11 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_REGION_DC && cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + cxlr_dax =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))return PTR_ERR (cxlr_dax);@@ -3040,6 +3072,7 @@ static int cxl_region_probe(struct device *dev)case CXL_REGION_PMEM :return devm_cxl_add_pmem_region (cxlr);case CXL_REGION_RAM : +case CXL_REGION_DC :/* * The region can not be manged by CXL if any portion of * it is already online as 'System RAM' drivers/dax/bus.c +8
-0@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_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);@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)WARN_ON_ONCE (!rwsem_is_locked (&dax_region_rwsem)); +if (is_sparse (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;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 +13
-2@@ -13,19 +13,30 @@ 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 ; + dev_size =range_len (&cxlr_dax->hpa_range); +/* Add empty seed dax device */ +if (cxlr->mode ==CXL_REGION_DC ) + dev_size =0 ; + 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 · 2 lines
-- 2.44.0
Re: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
Quoted 136 lines · fan
Quoted 135 lines · On Sun, Mar 24, 2024 at 04:18:12PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the
create_dc_regionsysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backwards compatibility with older software which needs a default DAX device to hold the region reference.Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Interleaving is deferred in this series. Add an early check.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[djiang: mark sysfs entries to be in 6.10 kernel including date] [djbw: change dax region typing to be 'sparse' rather than 'dynamic'] [iweiny: rebase changes to master instead of type2 patches]--- Documentation/ABI/testing/sysfs-bus-cxl | 22 +++++++++++----------- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 1 + drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++++ drivers/dax/bus.c | 8 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 15 +++++++++++++-- 7 files changed, 68 insertions(+), 13 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +11
-11@@ -411,20 +411,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, June 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.10 (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_regiondrivers/cxl/core/core.h +1
-0@@ -13,6 +13,7 @@ extern struct attribute_group cxl_base_attribute_group;#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@@ -335,6 +335,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 +23
-0@@ -2205,6 +2205,7 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,switch (mode) {case CXL_REGION_RAM :case CXL_REGION_PMEM : +case CXL_REGION_DC :break ;default : dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %s\n",@@ -2314,6 +2315,32 @@ static ssize_t create_ram_region_store(struct device *dev, }DEVICE_ATTR_RW (create_ram_region); +static ssize_t create_dc_region_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return __create_region_show (to_cxl_root_decoder (dev), buf); +} + +static ssize_t create_dc_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_DC , id); +if (IS_ERR (cxlr)) +return PTR_ERR (cxlr); +
Quoted 8 lines
drivers/cxl/core/region.c static ssize_t create_ram_region_store(struct device *dev, · line 2342
Quoted 3 lines
drivers/cxl/core/region.c +3
-0+return len; +} +DEVICE_ATTR_RW (create_dc_region);
create_ram_region_store,create_pmem_region_storeandcreate_dc_region_storehave mostly duplicate code, should we consider extracting out as a helper function and pass region type for ram/pmem/dc region store?
That is mostly done with __create_region(). But the following is a nice cleanup.
I'll test it.
Ira
21:24:37 > git di
drivers/cxl/core/region.c +12 -30
@@ -2638,9 +2638,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;
@@ -2650,31 +2649,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);
@@ -2688,19 +2682,7 @@ static ssize_t create_dc_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_DC , id); -if (IS_ERR (cxlr)) -return PTR_ERR (cxlr); - -return len; + return create_region_store(dev, buf, len, CXL_REGION_DC); }DEVICE_ATTR_RW (create_dc_region);
Dave Jiang
maintainerRe: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
In reply to [email protected]Quoted 59 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the
create_dc_regionsysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backwards compatibility with older software which needs a default DAX device to hold the region reference.Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Interleaving is deferred in this series. Add an early check.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[djiang: mark sysfs entries to be in 6.10 kernel including date] [djbw: change dax region typing to be 'sparse' rather than 'dynamic'] [iweiny: rebase changes to master instead of type2 patches]--- Documentation/ABI/testing/sysfs-bus-cxl | 22 +++++++++++----------- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 1 + drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++++ drivers/dax/bus.c | 8 ++++++++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 15 +++++++++++++-- 7 files changed, 68 insertions(+), 13 deletions(-)Documentation/ABI/testing/sysfs-bus-cxl +3
-8@@ -411,20 +411,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, June 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.10 (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
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 426
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +7
-3- 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
-EBUSY?
Quoted 149 lines
Documentation/ABI/testing/sysfs-bus-cxl +1
-0+ written does not match the current cached value. What: /sys/bus/cxl/devices/decoderX.Y/delete_regiondrivers/cxl/core/core.h +1
-0@@ -13,6 +13,7 @@ extern struct attribute_group cxl_base_attribute_group;#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@@ -335,6 +335,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 +33
-0@@ -2205,6 +2205,7 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,switch (mode) {case CXL_REGION_RAM :case CXL_REGION_PMEM : +case CXL_REGION_DC :break ;default : dev_err(&cxlrd->cxlsd.cxld.dev, "unsupported mode %s\n",@@ -2314,6 +2315,32 @@ static ssize_t create_ram_region_store(struct device *dev, }DEVICE_ATTR_RW (create_ram_region); +static ssize_t create_dc_region_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return __create_region_show (to_cxl_root_decoder (dev), buf); +} + +static ssize_t create_dc_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_DC , id); +if (IS_ERR (cxlr)) +return PTR_ERR (cxlr); + +return len; +} +DEVICE_ATTR_RW (create_dc_region); +static ssize_t region_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -2759,6 +2786,11 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)struct device *dev;int rc; +if (cxlr->mode ==CXL_REGION_DC && cxlr->params.interleave_ways !=1 ) { +dev_err (&cxlr->dev,"Interleaving DC not supported\n" ); +return -EINVAL ; + } + cxlr_dax =cxl_dax_region_alloc (cxlr);if (IS_ERR (cxlr_dax))return PTR_ERR (cxlr_dax);@@ -3040,6 +3072,7 @@ static int cxl_region_probe(struct device *dev)case CXL_REGION_PMEM :return devm_cxl_add_pmem_region (cxlr);case CXL_REGION_RAM : +case CXL_REGION_DC :/* * The region can not be manged by CXL if any portion of * it is already online as 'System RAM' drivers/dax/bus.c +8
-0@@ -181,6 +181,11 @@ static bool is_static(struct dax_region *dax_region)return (dax_region->res.flags &IORESOURCE_DAX_STATIC ) !=0 ; } +static bool is_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);@@ -304,6 +309,9 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region)WARN_ON_ONCE (!rwsem_is_locked (&dax_region_rwsem)); +if (is_sparse (dax_region)) +return 0 ; +for_each_dax_region_resource (dax_region, res) size -=resource_size (res);return size;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 +6
-0@@ -13,19 +13,30 @@ 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 ; +
drivers/dax/cxl.c static int cxl_dax_region_probe(struct device *dev) · line 34
Quoted 10 lines
drivers/dax/cxl.c +5
-1dax_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 ; + dev_size =range_len (&cxlr_dax->hpa_range); +/* Add empty seed dax device */ +if (cxlr->mode ==CXL_REGION_DC ) + dev_size =0 ;
Nit. Just do if/else so dev_size isn't set twice if mode is DC.
Quoted 10 lines
drivers/dax/cxl.c +2
-1+ data = (struct dev_dax_data ) { .dax_region = dax_region, .id =-1 , - .size =range_len (&cxlr_dax->hpa_range), + .size = dev_size, .memmap_on_memory = true, };
Re: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
Quoted 5 lines · Dave Jiang
Quoted 2 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 19 lines
Quoted 19 lines
Documentation/ABI/testing/sysfs-bus-cxl +4
-11-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, June 2024 +KernelVersion: v6.0 (pmem), v6.3 (ram), v6.10 (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
Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-cxl Description: · line 426
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +6
-0+ (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
-EBUSY?
To match the other documentation I would say no. The other docs show ENXIO/EBUSY/EINVAL without the negative indicator.
[snip]
Quoted 24 lines
Quoted 24 lines
drivers/dax/cxl.c +7
-1@@ -13,19 +13,30 @@ 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 ;
Quoted 6 lines
drivers/dax/cxl.c static int cxl_dax_region_probe(struct device *dev) · line 34
Quoted 4 lines
drivers/dax/cxl.c +4
-0+ dev_size =range_len (&cxlr_dax->hpa_range); +/* Add empty seed dax device */ +if (cxlr->mode ==CXL_REGION_DC ) + dev_size =0 ;Nit. Just do if/else so
dev_sizeisn't set twice if mode is DC.
Ok yea.
Ira
Re: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
In reply to [email protected]Quoted 13 lines · On Sun, 24 Mar 2024 16:18:12 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the
create_dc_regionsysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backwards compatibility with older software which needs a default DAX device to hold the region reference.
Quoted 8 lines
Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Interleaving is deferred in this series. Add an early check.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
With the -EBUSY others addressed LGTM. Fan's duplication comment might be something to tidy up later.
Re: [PATCH 09/26] cxl/region: Add Dynamic Capacity CXL region support
Quoted 19 lines · Jonathan Cameron
Quoted 16 lines · On Sun, 24 Mar 2024 16:18:12 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
CXL devices optionally support dynamic capacity. CXL Regions must be configured correctly to access this capacity. Similar to ram and pmem partitions, DC Regions, as they are called in CXL 3.1, represent different partitions of the DPA space.
Introduce the concept of a sparse DAX region. Add the
create_dc_regionsysfs entry to create sparse DC DAX regions. Special case DC capable regions to create a 0 sized seed DAX device to maintain backards compatibility with older software which needs a default DAX device to hold the region reference.Flag sparse DAX regions to indicate 0 capacity available until such time as DC capacity is added.
Quoted 6 lines
Quoted 5 lines
Interleaving is deferred in this series. Add an early check.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>With the
-EBUSYothers addressed LGTM.
But the other docs do not have that notation. Also the EBUSY was not changed from the previous documentation. Only the text for DC was added.
I'm inclined to leave this.
Quoted 4 lines
Fan's duplication comment
might be something to tidy up later.Reviewed-by Jonathan Cameron <[email protected]>
Thanks,
Ira
PATCH 10/26 cxl/events: Factor out event msgnum configuration
In reply to [email protected]Dynamic Capacity Devices (DCD) require events to process extent addition or removal. BIOS may have control over memory event processing.
Factor out cxl_event_config_msgnums() in preparation for setting up DCD event interrupts separate from memory events.
--- 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;/*
@@ -777,7 +773,11 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,return -EBUSY ; } - rc =cxl_event_irqsetup (mds); + rc =cxl_event_config_msgnums (mds, &policy); +if (rc) +return rc; + + rc =cxl_event_irqsetup (mds, &policy);if (rc)return rc;
Signature · 1 line
2.44.0
Re: [PATCH 10/26] cxl/events: Factor out event msgnum configuration
Quoted 7 lines · Ira Weiny
Dynamic Capacity Devices (DCD) require events to process extent addition or removal. BIOS may have control over memory event processing.
Factor out
cxl_event_config_msgnums()in preparation for setting up DCD event interrupts separate from memory events.Signed-off-by Ira Weiny <[email protected]>
Quoted 73 lines
--- 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;/* @@ -777,7 +773,11 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,return -EBUSY ; } - rc =cxl_event_irqsetup (mds); + rc =cxl_event_config_msgnums (mds, &policy); +if (rc) +return rc; + + rc =cxl_event_irqsetup (mds, &policy);if (rc)return rc;
Re: [PATCH 10/26] cxl/events: Factor out event msgnum configuration
In reply to Ira WeinyQuoted 8 lines · On Sun, 24 Mar 2024 16:18:13 -0700 Ira Weiny <[email protected]> wrote:
Dynamic Capacity Devices (DCD) require events to process extent addition or removal. BIOS may have control over memory event processing.
Factor out
cxl_event_config_msgnums()in preparation for setting up DCD event interrupts separate from memory events.Signed-off-by Ira Weiny <[email protected]>
PATCH 11/26 cxl/pci: Delay event buffer allocation
In reply to [email protected]The 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.
--- drivers/cxl/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/pci.c +4 -4
@@ -756,10 +756,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,if (rc)return rc; + rc =cxl_mem_alloc_event_buf (mds); +if (rc) +return rc; + rc =cxl_event_irqsetup (mds, &policy);if (rc)return rc;
Signature · 1 line
2.44.0
Re: [PATCH 11/26] cxl/pci: Delay event buffer allocation
Quoted 5 lines · Ira Weiny
The 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.
The above could be removed and just picked up independet of dcd.
Quoted 36 lines
Signed-off-by Ira Weiny <[email protected]>---
drivers/cxl/pci.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/cxl/pci.c +4
-5@@ -756,10 +756,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,if (rc)return rc; + rc =cxl_mem_alloc_event_buf (mds); +if (rc) +return rc; + rc =cxl_event_irqsetup (mds, &policy);if (rc)return rc; --2.44.0
Re: [PATCH 11/26] cxl/pci: Delay event buffer allocation
In reply to Ira WeinyQuoted 7 lines · Ira Weiny
The 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.
Signed-off-by Ira Weiny <[email protected]>
Quoted 31 lines
--- drivers/cxl/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/cxl/pci.c +4
-4@@ -756,10 +756,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,if (rc)return rc; + rc =cxl_mem_alloc_event_buf (mds); +if (rc) +return rc; + rc =cxl_event_irqsetup (mds, &policy);if (rc)return rc;
Re: [PATCH 11/26] cxl/pci: Delay event buffer allocation
In reply to Ira WeinyQuoted 7 lines · On Sun, 24 Mar 2024 16:18:14 -0700 Ira Weiny <[email protected]> wrote:
The 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.
Signed-off-by Ira Weiny <[email protected]>
PATCH 12/26 cxl/pci: Factor out interrupt policy check
In reply to [email protected]Dynamic capacity devices (DCD) require interrupts to notify the host of events in the DCD log. The interrupts for DCD may be supported despite FW control of memory event logs.
Prepare to support DCD event interrupts separate from other event interrupts by factoring out the check for event interrupt settings.
---
Changes for V3:
[iweiny: new 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.44.0
Re: [PATCH 12/26] cxl/pci: Factor out interrupt policy check
Quoted 8 lines · Ira Weiny
Dynamic capacity devices (DCD) require interrupts to notify the host of events in the DCD log. The interrupts for DCD may be supported despite FW control of memory event logs.
Prepare to support DCD event interrupts separate from other event interrupts by factoring out the check for event interrupt settings.
Signed-off-by Ira Weiny <[email protected]>
Quoted 51 lines
---
Changes for V3:
[iweiny: new 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)
Re: [PATCH 12/26] cxl/pci: Factor out interrupt policy check
In reply to Ira WeinyQuoted 8 lines · On Sun, 24 Mar 2024 16:18:15 -0700 Ira Weiny <[email protected]> wrote:
Dynamic capacity devices (DCD) require interrupts to notify the host of events in the DCD log. The interrupts for DCD may be supported despite FW control of memory event logs.
Prepare to support DCD event interrupts separate from other event interrupts by factoring out the check for event interrupt settings.
Signed-off-by Ira Weiny <[email protected]>
PATCH 13/26 cxl/mem: Configure dynamic capacity interrupts
In reply to [email protected]From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
---
Changes for v1
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]
--- drivers/cxl/core/mbox.c | 9 ++++++- drivers/cxl/cxl.h | 4 ++- drivers/cxl/cxlmem.h | 4 +++ drivers/cxl/pci.c | 71 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 14 deletions(-)
drivers/cxl/core/mbox.c +8 -1
@@ -1323,10 +1323,17 @@ static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region,return rc; } -static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +bool cxl_dcd_supported (struct cxl_memdev_state *mds) {return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); } +EXPORT_SYMBOL_NS_GPL (cxl_dcd_supported,CXL ); + +void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ +clear_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} +EXPORT_SYMBOL_NS_GPL (cxl_disable_dcd,CXL );/** * cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity
drivers/cxl/cxl.h +3 -1
@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL| \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)
drivers/cxl/cxlmem.h +4 -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
@@ -890,6 +892,8 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,enum cxl_event_log_type type, enum cxl_event_type event_type, const uuid_t *uuid, union cxl_event *evt); +bool cxl_dcd_supported (struct cxl_memdev_state *mds); +void cxl_disable_dcd (struct cxl_memdev_state *mds);int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
drivers/cxl/pci.c +59 -12
126 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
Quoted 215 lines · On Sun, Mar 24, 2024 at 04:18:16PM -0700, [email protected] wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]--- drivers/cxl/core/mbox.c | 9 ++++++- drivers/cxl/cxl.h | 4 ++- drivers/cxl/cxlmem.h | 4 +++ drivers/cxl/pci.c | 71 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 14 deletions(-)drivers/cxl/core/mbox.c +8
-1@@ -1323,10 +1323,17 @@ static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region,return rc; } -static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +bool cxl_dcd_supported (struct cxl_memdev_state *mds) {return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); } +EXPORT_SYMBOL_NS_GPL (cxl_dcd_supported,CXL ); + +void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ +clear_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} +EXPORT_SYMBOL_NS_GPL (cxl_disable_dcd,CXL );/** * cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity drivers/cxl/cxl.h +3
-1@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL| \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)drivers/cxl/cxlmem.h +4
-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 @@ -890,6 +892,8 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,enum cxl_event_log_type type, enum cxl_event_type event_type, const uuid_t *uuid, union cxl_event *evt); +bool cxl_dcd_supported (struct cxl_memdev_state *mds); +void cxl_disable_dcd (struct cxl_memdev_state *mds);int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +55
-11@@ -669,22 +669,33 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mbox_cmd mbox_cmd; +size_t size_in;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX , - .failure_settings =CXL_INT_MSI_MSIX , - .fatal_settings =CXL_INT_MSI_MSIX , - }; +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 , + }; + } + size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ; + +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings); + } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (mds, &mbox_cmd);@@ -731,6 +742,31 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); +return rc; + } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -757,17 +793,25 @@ 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 = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -775,10 +819,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;@@ -786,12 +830,15 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc;
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 840
Quoted 10 lines
drivers/cxl/pci.c +3
-1- rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL ); +dev_dbg (mds->cxlds.dev,"Event config : %d %d\n" , + native_cxl,cxl_dcd_supported (mds));
The message will print out two numbers, seems not very clear. Should we translate to more straightforward message, likenative_cxl? "OS...":""cxl_dcd_supported(msd)? "DCD supported": "DCD not supported"?
Fan
Quoted 8 lines
drivers/cxl/pci.c +1
-0+return 0 ; }Signature · 2 lines
-- 2.44.0
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
Quoted 2 lines · fan
Quoted 1 line · On Sun, Mar 24, 2024 at 04:18:16PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 11 lines
Quoted 11 lines
drivers/cxl/pci.c +1
-1@@ -786,12 +830,15 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL );
Quoted 7 lines
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 840
Quoted 2 lines
drivers/cxl/pci.c +2
-0+dev_dbg (mds->cxlds.dev,"Event config : %d %d\n" , + native_cxl,cxl_dcd_supported (mds));The message will print out two numbers, seems not very clear. Should we translate to more straightforward message, like
native_cxl? "OS...":""cxl_dcd_supported(msd)? "DCD supported": "DCD not supported"?
Perhaps but it is just a debug message to know if something is wonky with a BIOS configuration.
So I'm inclined to leave it alone.
Ira
Dave Jiang
maintainerRe: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
In reply to [email protected]Quoted 11 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Quoted 6 lines
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
A few minor comments. The rest LGTM.
Quoted 22 lines
---
Changes for v1
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]--- drivers/cxl/core/mbox.c | 9 ++++++- drivers/cxl/cxl.h | 4 ++- drivers/cxl/cxlmem.h | 4 +++ drivers/cxl/pci.c | 71 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 14 deletions(-)drivers/cxl/core/mbox.c +1
-1@@ -1323,10 +1323,17 @@ static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region,return rc; } -static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +bool cxl_dcd_supported (struct cxl_memdev_state *mds)
drivers/cxl/core/mbox.c static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region, · line 1336
Quoted 10 lines
drivers/cxl/core/mbox.c +7
-0{return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); } +EXPORT_SYMBOL_NS_GPL (cxl_dcd_supported,CXL ); + +void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ +clear_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} +EXPORT_SYMBOL_NS_GPL (cxl_disable_dcd,CXL );
Should these one-liners just go into a header file?
drivers/cxl/cxl.h static inline int ways_to_eiw(unsigned int ways, u8 *eiw) · line 167
Quoted 12 lines
drivers/cxl/core/mbox.c +0
-0/** * cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity drivers/cxl/cxl.h +1
-0@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)
extra tab?
DJ
Quoted 169 lines
drivers/cxl/cxl.h +2
-1#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL| \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)drivers/cxl/cxlmem.h +4
-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 @@ -890,6 +892,8 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,enum cxl_event_log_type type, enum cxl_event_type event_type, const uuid_t *uuid, union cxl_event *evt); +bool cxl_dcd_supported (struct cxl_memdev_state *mds); +void cxl_disable_dcd (struct cxl_memdev_state *mds);int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +59
-12@@ -669,22 +669,33 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mbox_cmd mbox_cmd; +size_t size_in;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX , - .failure_settings =CXL_INT_MSI_MSIX , - .fatal_settings =CXL_INT_MSI_MSIX , - }; +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 , + }; + } + size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ; + +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings); + } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (mds, &mbox_cmd);@@ -731,6 +742,31 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); +return rc; + } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -757,17 +793,25 @@ 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 = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event +* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" ); +cxl_disable_dcd (mds); + }return 0 ; }@@ -775,10 +819,10 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; -if (!cxl_event_validate_mem_policy (mds, &policy)) +if (native_cxl && !cxl_event_validate_mem_policy (mds, &policy))return -EBUSY ; - rc =cxl_event_config_msgnums (mds, &policy); + rc =cxl_event_config_msgnums (mds, &policy, native_cxl);if (rc)return rc;@@ -786,12 +830,15 @@ static int cxl_event_config(struct pci_host_bridge *host_bridge,if (rc)return rc; - rc =cxl_event_irqsetup (mds, &policy); + rc =cxl_irqsetup (mds, &policy, native_cxl);if (rc)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL ); +dev_dbg (mds->cxlds.dev,"Event config : %d %d\n" , + native_cxl,cxl_dcd_supported (mds)); +return 0 ; }
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
Quoted 42 lines · Dave Jiang
Quoted 11 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Quoted 6 lines
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>A few minor comments. The rest LGTM.
Quoted 20 lines
---
Changes for v1
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]--- drivers/cxl/core/mbox.c | 9 ++++++- drivers/cxl/cxl.h | 4 ++- drivers/cxl/cxlmem.h | 4 +++ drivers/cxl/pci.c | 71 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 14 deletions(-)drivers/cxl/core/mbox.c +0
-0@@ -1323,10 +1323,17 @@ static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region,return rc; }
Quoted 14 lines
drivers/cxl/core/mbox.c static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region, · line 1336
Quoted 12 lines
drivers/cxl/core/mbox.c +8
-1-static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +bool cxl_dcd_supported (struct cxl_memdev_state *mds) {return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); } +EXPORT_SYMBOL_NS_GPL (cxl_dcd_supported,CXL ); + +void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ +clear_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} +EXPORT_SYMBOL_NS_GPL (cxl_disable_dcd,CXL );Should these one-liners just go into a header file?
Yea they could.
Quoted 15 lines
drivers/cxl/cxl.h static inline int ways_to_eiw(unsigned int ways, u8 *eiw) · line 167
Quoted 13 lines
drivers/cxl/core/mbox.c +0
-0/** * cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity drivers/cxl/cxl.h +1
-0@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)extra tab?
It does not look like it on my end... :-/
#define CXLDEV_DEV_EVENT_STATUS_OFFSET>->-------0x00$ #define CXLDEV_EVENT_STATUS_INFO>------->-------BIT(0)$ #define CXLDEV_EVENT_STATUS_WARN>------->-------BIT(1)$ #define CXLDEV_EVENT_STATUS_FAIL>------->-------BIT(2)$ #define CXLDEV_EVENT_STATUS_FATAL>------>-------BIT(3)$ #define CXLDEV_EVENT_STATUS_DCD>>------->-------BIT(4)$
Ira
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
In reply to [email protected]Quoted 11 lines · On Sun, 24 Mar 2024 16:18:16 -0700 [email protected] wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Quoted 6 lines
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Trivial comment inline and Fan's suggestion on the debug print seems sensible to me. Either way
Quoted 7 lines
/**
*cxl_dev_dynamic_capacity_identify()- Reads the dynamic capacitydrivers/cxl/cxl.h +0
-0
drivers/cxl/cxl.h static inline int ways_to_eiw(unsigned int ways, u8 *eiw) · line 172
Quoted 10 lines
drivers/cxl/cxl.h +2
-1@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL| \
Space after L
You could realign the others but I wouldn't bother.
Quoted 1 line
drivers/cxl/cxl.h +1
-0+ CXLDEV_EVENT_STATUS_DCD)
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
Quoted 17 lines · Jonathan Cameron
Quoted 14 lines · On Sun, 24 Mar 2024 16:18:16 -0700 [email protected] wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>Trivial comment inline and Fan's suggestion on the debug print seems sensible to me.
Ok I went ahead and added it.
Quoted 3 lines
Either way
Reviewed-by Jonathan Cameron <[email protected]>
Thanks,
Ira
Alison Schofield
maintainerRe: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
In reply to [email protected]Quoted 19 lines · Ira Weiny
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
snip
Quoted 4 lines
drivers/cxl/pci.c +0
-0
snip
Quoted 8 lines
drivers/cxl/pci.c +7
-0+static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; +
drivers/cxl/pci.c static int cxl_event_irqsetup(struct cxl_memdev_state *mds, · line 761
Quoted 10 lines
drivers/cxl/pci.c +10
-0+if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc; + } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" );
move this..
drivers/cxl/pci.c
Quoted 1 line
drivers/cxl/pci.c +1
-0+cxl_disable_dcd (mds);
to after you've done the disabling...
dev_err(cxlds->dev, "DCD disabled: failed to get interrupt for event log\n");
drivers/cxl/pci.c
Quoted 1 line
drivers/cxl/pci.c +1
-0+return rc;
not sure I got the words right.
Quoted 21 lines
drivers/cxl/pci.c +9
-0+ } + } + +return 0 ; +} +static bool cxl_event_int_is_fw (u8 setting) {u8 mode =FIELD_GET (CXLDEV_EVENT_INT_MODE_MASK , setting);@@ -757,17 +793,25 @@ 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 = {0 }; +bool native_cxl = host_bridge->native_cxl_error;int rc;/* * When BIOS maintains CXL error reporting control, it will process * event records. Only one agent can do so. +* +* If BIOS has control of events and DCD is not supported skip event
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 812
Quoted 10 lines
drivers/cxl/pci.c +4
-1+* configuration. */ -if (!host_bridge->native_cxl_error) +if (!native_cxl && !cxl_dcd_supported (mds))return 0 ;if (!irq_avail) {dev_info (mds->cxlds.dev,"No interrupt support, disable event processing.\n" ); +if (cxl_dcd_supported (mds)) { +dev_info (mds->cxlds.dev,"DCD requires interrupts, disable DCD\n" );
Similar here -
Maybe better to disable, and just say it's done because this sounds a bit like a request to the user.
drivers/cxl/pci.c static int cxl_event_config(struct pci_host_bridge *host_bridge, · line 813
Quoted 1 line
drivers/cxl/pci.c +1
-0+cxl_disable_dcd (mds);
dev_info(mds->cxlds.dev, "DCD disabled: no interrupt support\n");
How come this one is dev_info() and prior case of disabling was a dev_err()/
snip to end
-- Alison
Re: [PATCH 13/26] cxl/mem: Configure dynamic capacity interrupts
In reply to [email protected]Quoted 39 lines · ira.weiny@ wrote:
From: 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. Split irq configuration of memory events and DCD events to allow for FW control of memory events while DCD is host controlled.
Configure DCD event log interrupts on devices supporting dynamic capacity. Disable DCD if interrupts are not supported.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1
[iweiny: rebase to upstream irq code]
[iweiny: disable DCD if irqs not supported]--- drivers/cxl/core/mbox.c | 9 ++++++- drivers/cxl/cxl.h | 4 ++- drivers/cxl/cxlmem.h | 4 +++ drivers/cxl/pci.c | 71 ++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 14 deletions(-)drivers/cxl/core/mbox.c +1
-1@@ -1323,10 +1323,17 @@ static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region,return rc; } -static bool cxl_dcd_supported (struct cxl_memdev_state *mds) +bool cxl_dcd_supported (struct cxl_memdev_state *mds)
drivers/cxl/core/mbox.c static int cxl_get_dc_config(struct cxl_memdev_state *mds, u8 start_region, · line 1336
Quoted 10 lines
drivers/cxl/core/mbox.c +7
-0{return test_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); } +EXPORT_SYMBOL_NS_GPL (cxl_dcd_supported,CXL ); + +void cxl_disable_dcd (struct cxl_memdev_state *mds) +{ +clear_bit (CXL_DCD_ENABLED_GET_CONFIG , mds->dcd_cmds); +} +EXPORT_SYMBOL_NS_GPL (cxl_disable_dcd,CXL );
Just use the open-coded bit ops, or local / static helpers because these helpers do not consume any other infra from core/mbox.c.
Quoted 63 lines
drivers/cxl/core/mbox.c +0
-0/** * cxl_dev_dynamic_capacity_identify() - Reads the dynamic capacity drivers/cxl/cxl.h +3
-1@@ -164,11 +164,13 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXLDEV_EVENT_STATUS_WARN BIT(1)#define CXLDEV_EVENT_STATUS_FAIL BIT(2)#define CXLDEV_EVENT_STATUS_FATAL BIT(3) +#define CXLDEV_EVENT_STATUS_DCD BIT(4)#define CXLDEV_EVENT_STATUS_ALL (CXLDEV_EVENT_STATUS_INFO | \ CXLDEV_EVENT_STATUS_WARN | \ CXLDEV_EVENT_STATUS_FAIL | \ - CXLDEV_EVENT_STATUS_FATAL) + CXLDEV_EVENT_STATUS_FATAL| \ + CXLDEV_EVENT_STATUS_DCD)/* CXL rev 3.0 section 8.2.9.2.4; Table 8-52 */ #define CXLDEV_EVENT_INT_MODE_MASK GENMASK(1, 0)drivers/cxl/cxlmem.h +4
-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 @@ -890,6 +892,8 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,enum cxl_event_log_type type, enum cxl_event_type event_type, const uuid_t *uuid, union cxl_event *evt); +bool cxl_dcd_supported (struct cxl_memdev_state *mds); +void cxl_disable_dcd (struct cxl_memdev_state *mds);int cxl_set_timestamp (struct cxl_memdev_state *mds);int cxl_poison_state_init (struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,drivers/cxl/pci.c +3
-4@@ -669,22 +669,33 @@ static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, }static int cxl_event_config_msgnums (struct cxl_memdev_state *mds, -struct cxl_event_interrupt_policy *policy) +struct cxl_event_interrupt_policy *policy, +bool native_cxl) {struct cxl_mbox_cmd mbox_cmd; +size_t size_in;int rc; - *policy = (struct cxl_event_interrupt_policy ) { - .info_settings =CXL_INT_MSI_MSIX , - .warn_settings =CXL_INT_MSI_MSIX ,
drivers/cxl/pci.c static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, · line 685
Quoted 10 lines
drivers/cxl/pci.c +7
-3- .failure_settings = CXL_INT_MSI_MSIX, - .fatal_settings = CXL_INT_MSI_MSIX, - }; +if (native_cxl) { + *policy = (struct cxl_event_interrupt_policy ) { + .info_settings =CXL_INT_MSI_MSIX , + .warn_settings =CXL_INT_MSI_MSIX , + .failure_settings =CXL_INT_MSI_MSIX , + .fatal_settings =CXL_INT_MSI_MSIX , + .dcd_settings =0 ,
No need to initialize dcd_settings.
drivers/cxl/pci.c static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, · line 688
Quoted 3 lines
drivers/cxl/pci.c +3
-0+ }; + } + size_in =CXL_EVENT_INT_POLICY_BASE_SIZE ;
Let's skip adding this new #define and make it explicit, i.e. wihtout needing to crack open the spec, that the dcd settings are incremental to the original payload size:
size_in = offsetof(typeof(*policy), dcd_settings);
drivers/cxl/pci.c static int cxl_event_get_int_policy(struct cxl_memdev_state *mds, · line 692
Quoted 4 lines
drivers/cxl/pci.c +4
-0+ +if (cxl_dcd_supported (mds)) { + policy->dcd_settings =CXL_INT_MSI_MSIX ; + size_in +=sizeof (policy->dcd_settings);
...and then this can just be:
size_in = sizeof(*policy);
Quoted 25 lines
drivers/cxl/pci.c +13
-1+ } mbox_cmd = (struct cxl_mbox_cmd ) { .opcode =CXL_MBOX_OP_SET_EVT_INT_POLICY , .payload_in = policy, - .size_in =sizeof (*policy), + .size_in = size_in, }; rc =cxl_internal_send_cmd (mds, &mbox_cmd);@@ -731,6 +742,31 @@ static int cxl_event_irqsetup(struct cxl_memdev_state *mds,return 0 ; } +static int cxl_irqsetup (struct cxl_memdev_state *mds, +struct cxl_event_interrupt_policy *policy, +bool native_cxl) +{ +struct cxl_dev_state *cxlds = &mds->cxlds; +int rc; + +if (native_cxl) { + rc =cxl_event_irqsetup (mds, policy); +if (rc) +return rc;
drivers/cxl/pci.c static int cxl_event_irqsetup(struct cxl_memdev_state *mds, · line 765
Quoted 10 lines
drivers/cxl/pci.c +10
-0+ } + +if (cxl_dcd_supported (mds)) { + rc =cxl_event_req_irq (cxlds, policy->dcd_settings); +if (rc) { +dev_err (cxlds->dev,"Failed to get interrupt for DCD event log\n" ); +cxl_disable_dcd (mds); +return rc; + } + }
I think this could be simplified if cxl_event_req_irq() simply skipped the non CXL_INT_MSI_MSIX modes. I.e. cxl_event_req_irq() is being too strict after the policy settings have already run the gauntlet.
PATCH 14/26 cxl/region: Read existing extents on region creation
In reply to [email protected]From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]
--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)
drivers/cxl/core/core.h +9 -0
@@ -4,6 +4,8 @@#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;
@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {
@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)
drivers/cxl/core/mbox.c +192 -0
210 lines not on this page · raw message
drivers/cxl/core/region.c +29 -0
@@ -1450,6 +1450,13 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,return 0 ; } +/* Callers are expected to ensure cxled has been attached to a region */ +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +} + static int cxl_region_attach_position(struct cxl_region *cxlr, struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled,
@@ -2773,6 +2780,22 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)return rc; } +static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax;
@@ -2807,6 +2830,12 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)dev_dbg (&cxlr->dev,"%s: register %s\n" ,dev_name (dev->parent),dev_name (dev)); +if (cxlr->mode ==CXL_REGION_DC ) { + rc =cxl_region_read_extents (cxlr); +if (rc) + goto err; + } +return devm_add_action_or_reset (&cxlr->dev, cxlr_dax_unregister, cxlr_dax); err:
drivers/cxl/cxlmem.h +49 -0
61 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
Quoted 78 lines · On Sun, Mar 24, 2024 at 04:18:17PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)drivers/cxl/core/core.h +9
-0@@ -4,6 +4,8 @@#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;@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)drivers/cxl/core/mbox.c +5
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len;
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 887
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) {
Why not use range_contains here as below?
Fan
Quoted 319 lines
drivers/cxl/core/mbox.c +177
-0+dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length); +struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt (struct cxl_memdev_state *mds, +unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ), + .start_extent_index =cpu_to_le32 (0 ), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents (struct cxl_endpoint_decoder *cxled, +unsigned int start_gen_num, +unsigned int exp_cnt) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +unsigned int start_index, total_read; +struct device *dev = mds->cxlds.dev; +struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = +kvmalloc (mds->payload_size,GFP_KERNEL ); +if (!dc_extents) +return -ENOMEM ; + + total_read =0 ; + start_index =0 ; +do { +unsigned int nr_ext, total_extent_cnt, gen_num; +struct cxl_mbox_get_dc_extent_in get_dc_extent; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (exp_cnt - start_index), + .start_extent_index =cpu_to_le32 (start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { +dev_err (dev,"Possible incomplete extent list; gen %u != %u : cnt %u != %u\n" , + gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ; +if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ; + rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +} + +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" ); +return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); +dev_dbg (mds->cxlds.dev,"Extent count: %d Generation Num: %d\n" , + rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc); +} +EXPORT_SYMBOL_NS_GPL (cxl_read_dc_extents,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)drivers/cxl/core/region.c +29
-0@@ -1450,6 +1450,13 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,return 0 ; } +/* Callers are expected to ensure cxled has been attached to a region */ +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +} + static int cxl_region_attach_position(struct cxl_region *cxlr, struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled,@@ -2773,6 +2780,22 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)return rc; } +static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax;@@ -2807,6 +2830,12 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)dev_dbg (&cxlr->dev,"%s: register %s\n" ,dev_name (dev->parent),dev_name (dev)); +if (cxlr->mode ==CXL_REGION_DC ) { + rc =cxl_region_read_extents (cxlr); +if (rc) + goto err; + } +return devm_add_action_or_reset (&cxlr->dev, cxlr_dax_unregister, cxlr_dax); err:drivers/cxl/cxlmem.h +49
-0@@ -604,6 +604,54 @@ enum cxl_opcode {UUID_INIT (0xe1819d9 ,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; + +/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51 +*/ +#define CXL_DC_EXTENT_TAG_LEN 0x10 +struct cxl_dc_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_DC_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[6 ]; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Input Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-166 +*/ +struct cxl_mbox_get_dc_extent_in { +__le32 extent_cnt; +__le32 start_extent_index; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Output Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167 +*/ +struct cxl_mbox_get_dc_extent_out { +__le32 ret_extent_cnt; +__le32 total_extent_cnt; +__le32 extent_list_num; +u8 rsvd[4 ]; +struct cxl_dc_extent extent[]; +} __packed; +struct cxl_mbox_get_supported_logs {__le16 entries;u8 rsvd[6 ];@@ -879,6 +927,7 @@ int cxl_internal_send_cmd(struct cxl_memdev_state *mds, struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds); +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);Signature · 2 lines
-- 2.44.0
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
Quoted 3 lines · fan
Quoted 2 lines · On Sun, Mar 24, 2024 at 04:18:17PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 17 lines
Quoted 17 lines
drivers/cxl/core/mbox.c +9
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len; + + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); +
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 887
Quoted 6 lines
drivers/cxl/core/mbox.c +6
-0+/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) {Why not use
range_containshere as below?
Because when I initially wrote this I (or perhaps Navneet, I can't remember) we were not using ranges. This version I tried to convert to ranges and I missed this one.
Good catch!
Ira
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]Quoted 266 lines · On Sun, Mar 24, 2024 at 04:18:17PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)drivers/cxl/core/core.h +9
-0@@ -4,6 +4,8 @@#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;@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)drivers/cxl/core/mbox.c +179
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len; + + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) { +dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length); +struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt (struct cxl_memdev_state *mds, +unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ), + .start_extent_index =cpu_to_le32 (0 ), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents (struct cxl_endpoint_decoder *cxled, +unsigned int start_gen_num, +unsigned int exp_cnt) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +unsigned int start_index, total_read; +struct device *dev = mds->cxlds.dev; +struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = +kvmalloc (mds->payload_size,GFP_KERNEL ); +if (!dc_extents) +return -ENOMEM ; + + total_read =0 ; + start_index =0 ; +do { +unsigned int nr_ext, total_extent_cnt, gen_num; +struct cxl_mbox_get_dc_extent_in get_dc_extent; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (exp_cnt - start_index), + .start_extent_index =cpu_to_le32 (start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { +dev_err (dev,"Possible incomplete extent list; gen %u != %u : cnt %u != %u\n" , + gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ; +if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ; + rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +} + +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" );
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1597
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); +dev_dbg (mds->cxlds.dev,"Extent count: %d Generation Num: %d\n" , + rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc);
Not sure about the behaviour here. From the cxl_dev_get_dc_extents implementation below, if gen_num changed or the expected extent count changed, it will return error.
If I understand it correctly, if the above two values change, it means the extent list has been updated due to extent add/release since last time we read the extent list info (cxl_dev_get_dc_extent_cnt), do we need to fail the operation or try again?
Fan
Quoted 131 lines
drivers/cxl/core/mbox.c +3
-0+} +EXPORT_SYMBOL_NS_GPL (cxl_read_dc_extents,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)drivers/cxl/core/region.c +29
-0@@ -1450,6 +1450,13 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,return 0 ; } +/* Callers are expected to ensure cxled has been attached to a region */ +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +} + static int cxl_region_attach_position(struct cxl_region *cxlr, struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled,@@ -2773,6 +2780,22 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)return rc; } +static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax;@@ -2807,6 +2830,12 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)dev_dbg (&cxlr->dev,"%s: register %s\n" ,dev_name (dev->parent),dev_name (dev)); +if (cxlr->mode ==CXL_REGION_DC ) { + rc =cxl_region_read_extents (cxlr); +if (rc) + goto err; + } +return devm_add_action_or_reset (&cxlr->dev, cxlr_dax_unregister, cxlr_dax); err:drivers/cxl/cxlmem.h +49
-0@@ -604,6 +604,54 @@ enum cxl_opcode {UUID_INIT (0xe1819d9 ,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; + +/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51 +*/ +#define CXL_DC_EXTENT_TAG_LEN 0x10 +struct cxl_dc_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_DC_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[6 ]; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Input Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-166 +*/ +struct cxl_mbox_get_dc_extent_in { +__le32 extent_cnt; +__le32 start_extent_index; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Output Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167 +*/ +struct cxl_mbox_get_dc_extent_out { +__le32 ret_extent_cnt; +__le32 total_extent_cnt; +__le32 extent_list_num; +u8 rsvd[4 ]; +struct cxl_dc_extent extent[]; +} __packed; +struct cxl_mbox_get_supported_logs {__le16 entries;u8 rsvd[6 ];@@ -879,6 +927,7 @@ int cxl_internal_send_cmd(struct cxl_memdev_state *mds, struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds); +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);Signature · 2 lines
-- 2.44.0
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
Quoted 3 lines · fan
Quoted 2 lines · On Sun, Mar 24, 2024 at 04:18:17PM -0700, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 25 lines
Quoted 25 lines
drivers/cxl/core/mbox.c +25
-0+ +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" ); +return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); +dev_dbg (mds->cxlds.dev,"Extent count: %d Generation Num: %d\n" , + rc, extent_gen_num);
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1597
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc);Not sure about the behaviour here. From the
cxl_dev_get_dc_extentsimplementation below, ifgen_numchanged or the expected extent count changed, it will return error.
yep.
Quoted 4 lines
If I understand it correctly, if the above two values change, it means the extent list has been updated due to extent add/release since last time we read the extent list info (
cxl_dev_get_dc_extent_cnt), do we need to fail the operation or try again?
The original series was safe to fail the operation because the list was read on memory device driver load and not when the regions were created. This is an oversight with the new architecture. Now that regions query for the list independent of other regions being active the list could indeed change during this operation. :-/ So a retry is necessary.
Let me work on the retry because some of the extents may have been surfaced during the list processing which means a re-read of the list will need to properly ignore those already found. Or some other tracking needs to be put in place.
Ira
Dave Jiang
maintainerRe: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]Quoted 70 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)drivers/cxl/core/core.h +9
-0@@ -4,6 +4,8 @@#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;@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)drivers/cxl/core/mbox.c +0
-0
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 877
Quoted 8 lines
drivers/cxl/core/mbox.c +5
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len;
u64
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 887
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) {
Can range_contains() be used here as well?
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 900
Quoted 13 lines
drivers/cxl/core/mbox.c +13
-0+dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed(struct cxl_endpoint_decoder *cxled,
cxl_dc_extent_in_endpoint_decoder() is more readable
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 904
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+ struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length);
u64
Quoted 35 lines
drivers/cxl/core/mbox.c +24
-0+struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1465
Quoted 4 lines
drivers/cxl/core/mbox.c +1
-0@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt(struct cxl_memdev_state *mds,
cxl_dev_get_dc_extent_generation()? or spell out count
DJ
Quoted 260 lines
drivers/cxl/core/mbox.c +135
-0+ unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ), + .start_extent_index =cpu_to_le32 (0 ), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents (struct cxl_endpoint_decoder *cxled, +unsigned int start_gen_num, +unsigned int exp_cnt) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +unsigned int start_index, total_read; +struct device *dev = mds->cxlds.dev; +struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = +kvmalloc (mds->payload_size,GFP_KERNEL ); +if (!dc_extents) +return -ENOMEM ; + + total_read =0 ; + start_index =0 ; +do { +unsigned int nr_ext, total_extent_cnt, gen_num; +struct cxl_mbox_get_dc_extent_in get_dc_extent; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (exp_cnt - start_index), + .start_extent_index =cpu_to_le32 (start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { +dev_err (dev,"Possible incomplete extent list; gen %u != %u : cnt %u != %u\n" , + gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ; +if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ; + rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +} + +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" ); +return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); +dev_dbg (mds->cxlds.dev,"Extent count: %d Generation Num: %d\n" , + rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc); +} +EXPORT_SYMBOL_NS_GPL (cxl_read_dc_extents,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)drivers/cxl/core/region.c +29
-0@@ -1450,6 +1450,13 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,return 0 ; } +/* Callers are expected to ensure cxled has been attached to a region */ +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +} + static int cxl_region_attach_position(struct cxl_region *cxlr, struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled,@@ -2773,6 +2780,22 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)return rc; } +static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax;@@ -2807,6 +2830,12 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)dev_dbg (&cxlr->dev,"%s: register %s\n" ,dev_name (dev->parent),dev_name (dev)); +if (cxlr->mode ==CXL_REGION_DC ) { + rc =cxl_region_read_extents (cxlr); +if (rc) + goto err; + } +return devm_add_action_or_reset (&cxlr->dev, cxlr_dax_unregister, cxlr_dax); err:drivers/cxl/cxlmem.h +49
-0@@ -604,6 +604,54 @@ enum cxl_opcode {UUID_INIT (0xe1819d9 ,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; + +/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51 +*/ +#define CXL_DC_EXTENT_TAG_LEN 0x10 +struct cxl_dc_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_DC_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[6 ]; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Input Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-166 +*/ +struct cxl_mbox_get_dc_extent_in { +__le32 extent_cnt; +__le32 start_extent_index; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Output Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167 +*/ +struct cxl_mbox_get_dc_extent_out { +__le32 ret_extent_cnt; +__le32 total_extent_cnt; +__le32 extent_list_num; +u8 rsvd[4 ]; +struct cxl_dc_extent extent[]; +} __packed; +struct cxl_mbox_get_supported_logs {__le16 entries;u8 rsvd[6 ];@@ -879,6 +927,7 @@ int cxl_internal_send_cmd(struct cxl_memdev_state *mds, struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds); +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds);
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
Quoted 5 lines · Dave Jiang
Quoted 2 lines · On 3/24/24 4:18 PM, [email protected] wrote:
From: Navneet Singh <[email protected]>
[snip]
Quoted 8 lines
Quoted 8 lines
drivers/cxl/core/mbox.c +0
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL );
Quoted 7 lines
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 877
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len;u64
Yep
Quoted 13 lines
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 887
Quoted 11 lines
drivers/cxl/core/mbox.c +10
-0+ + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) {Can
range_contains()be used here as well?
Yep and done.
Quoted 16 lines
Quoted 4 lines
drivers/cxl/core/mbox.c +3
-0+dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ;drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 900
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed(struct cxl_endpoint_decoder *cxled,
cxl_dc_extent_in_endpoint_decoder()is more readable
Sure but we are getting awful close to Java naming there... j/k ;-) Changed.
Quoted 7 lines
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 904
Quoted 5 lines
drivers/cxl/core/mbox.c +4
-0+ struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length);u64
Yep
[snip]
Quoted 17 lines
Quoted 17 lines
drivers/cxl/core/mbox.c +9
-0+static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL );
Quoted 3 lines
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1465
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+static int cxl_dev_get_dc_extent_cnt(struct cxl_memdev_state *mds,
cxl_dev_get_dc_extent_generation()? or spell out count
I'll spell out count because that is the primary goal. The generation number is just to be able to check each query to ensure the list does not change whilst reading.
Ira
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]Quoted 266 lines · On 3/25/24 00:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)drivers/cxl/core/core.h +9
-0@@ -4,6 +4,8 @@#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;@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)drivers/cxl/core/mbox.c +179
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len; + + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) { +dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length); +struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt (struct cxl_memdev_state *mds, +unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ), + .start_extent_index =cpu_to_le32 (0 ), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents (struct cxl_endpoint_decoder *cxled, +unsigned int start_gen_num, +unsigned int exp_cnt) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +unsigned int start_index, total_read; +struct device *dev = mds->cxlds.dev; +struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = +kvmalloc (mds->payload_size,GFP_KERNEL ); +if (!dc_extents) +return -ENOMEM ; + + total_read =0 ; + start_index =0 ; +do { +unsigned int nr_ext, total_extent_cnt, gen_num; +struct cxl_mbox_get_dc_extent_in get_dc_extent; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (exp_cnt - start_index), + .start_extent_index =cpu_to_le32 (start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { +dev_err (dev,"Possible incomplete extent list; gen %u != %u : cnt %u != %u\n" , + gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ; +if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ; + rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +} + +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" );
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1597
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); +dev_dbg (mds->cxlds.dev,"Extent count: %d Generation Num: %d\n" , + rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc);
Is it necessary to spend a device interaction to get the generation number? Couldn't cxl_dev_get_dc_extents obtain that as part of the first call to the device, and then use it to ensure the consistency of any remaining calls, if any are necessary?
Thanks,
Jørgen
Quoted 132 lines
drivers/cxl/core/mbox.c +3
-0+} +EXPORT_SYMBOL_NS_GPL (cxl_read_dc_extents,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)drivers/cxl/core/region.c +29
-0@@ -1450,6 +1450,13 @@ static int cxl_region_validate_position(struct cxl_region *cxlr,return 0 ; } +/* Callers are expected to ensure cxled has been attached to a region */ +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +} + static int cxl_region_attach_position(struct cxl_region *cxlr, struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled,@@ -2773,6 +2780,22 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)return rc; } +static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +static void cxlr_dax_unregister (void *_cxlr_dax) {struct cxl_dax_region *cxlr_dax = _cxlr_dax;@@ -2807,6 +2830,12 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)dev_dbg (&cxlr->dev,"%s: register %s\n" ,dev_name (dev->parent),dev_name (dev)); +if (cxlr->mode ==CXL_REGION_DC ) { + rc =cxl_region_read_extents (cxlr); +if (rc) + goto err; + } +return devm_add_action_or_reset (&cxlr->dev, cxlr_dax_unregister, cxlr_dax); err:drivers/cxl/cxlmem.h +49
-1@@ -604,6 +604,54 @@ enum cxl_opcode {UUID_INIT (0xe1819d9 ,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; + +/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51 +*/ +#define CXL_DC_EXTENT_TAG_LEN 0x10 +struct cxl_dc_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_DC_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[6 ]; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Input Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-166 +*/ +struct cxl_mbox_get_dc_extent_in { +__le32 extent_cnt; +__le32 start_extent_index; +} __packed; + +/* +* Get Dynamic Capacity Extent List; Output Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167 +*/ +struct cxl_mbox_get_dc_extent_out { +__le32 ret_extent_cnt; +__le32 total_extent_cnt; +__le32 extent_list_num; +u8 rsvd[4 ]; +struct cxl_dc_extent extent[]; +} __packed; +struct cxl_mbox_get_supported_logs {__le16 entries;u8 rsvd[6 ];@@ -879,6 +927,7 @@ int cxl_internal_send_cmd(struct cxl_memdev_state *mds, struct cxl_mbox_cmd *cmd);int cxl_dev_state_identify (struct cxl_memdev_state *mds);int cxl_dev_dynamic_capacity_identify (struct cxl_memdev_state *mds); +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled);int cxl_await_media_ready (struct cxl_dev_state *cxlds);int cxl_enumerate_cmds (struct cxl_memdev_state *mds);int cxl_mem_create_range_info (struct cxl_memdev_state *mds); --2.44.0
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
Quoted 272 lines · Jørgen Hansen
Quoted 271 lines · On 3/25/24 00:18, [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)drivers/cxl/core/core.h +9
-0@@ -4,6 +4,8 @@#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;@@ -28,6 +30,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); +int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent);#else static inline int cxl_get_poison_by_endpoint (struct cxl_port *port) {@@ -43,6 +47,11 @@ static inline int cxl_region_init(void)static inline void cxl_region_exit (void ) { } +static inline int cxl_ed_add_one_extent (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *dc_extent) +{ +return 0 ; +}#define CXL_REGION_ATTR (x) NULL#define CXL_REGION_TYPE (x) NULL#define SET_CXL_REGION_ATTR (x)drivers/cxl/core/mbox.c +184
-0@@ -870,6 +870,53 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_enumerate_cmds,CXL ); +static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{ +struct device *dev = mds->cxlds.dev; +uint64_t start, len; + + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; + +if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) { +dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 ); +return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length); +struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; } +static 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); +} +static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt (struct cxl_memdev_state *mds, +unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ), + .start_extent_index =cpu_to_le32 (0 ), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents (struct cxl_endpoint_decoder *cxled, +unsigned int start_gen_num, +unsigned int exp_cnt) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +unsigned int start_index, total_read; +struct device *dev = mds->cxlds.dev; +struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = +kvmalloc (mds->payload_size,GFP_KERNEL ); +if (!dc_extents) +return -ENOMEM ; + + total_read =0 ; + start_index =0 ; +do { +unsigned int nr_ext, total_extent_cnt, gen_num; +struct cxl_mbox_get_dc_extent_in get_dc_extent; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (exp_cnt - start_index), + .start_extent_index =cpu_to_le32 (start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 , + }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { +dev_err (dev,"Possible incomplete extent list; gen %u != %u : cnt %u != %u\n" , + gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ; +if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ; + rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +} + +/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev; +unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" ); +return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); + dev_dbg(mds->cxlds.dev, "Extent count: %d Generation Num: %d\n",
Quoted 8 lines
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1597
Quoted 5 lines
drivers/cxl/core/mbox.c +5
-0+ rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc);Is it necessary to spend a device interaction to get the generation number?
Not completely necessary no.
Quoted 3 lines
Couldn't
cxl_dev_get_dc_extentsobtain that as part of the first call to the device, and then use it to ensure the consistency of any remaining calls, if any are necessary?
... However, this is not a critical path and the extra query to hardware makes the code a bit easier to follow IMO. There are 2 distinct steps.
1) get expected number of extents and the current generation number
2) query for that number whilst checking that the gen number is stable
Doing what you suggest results in special casing the first query within the loop which is kind of ugly IMO.
That said, with the new retry requirement Fan pointed out I'll consider this in that new algorithm context.
Ira
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]Quoted 7 lines · On Sun, 24 Mar 2024 16:18:17 -0700 [email protected] wrote:
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Quoted 8 lines
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>
A few things inline.
J
Quoted 18 lines
static void cxl_mem_get_records_log(struct
cxl_memdev_state*mds,drivers/cxl/core/mbox.c +11
-0enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt (struct cxl_memdev_state *mds, +unsigned int *extent_gen_num) +{ +struct cxl_mbox_get_dc_extent_in get_dc_extent; +struct cxl_mbox_get_dc_extent_out dc_extents; +struct cxl_mbox_cmd mbox_cmd; +unsigned int count; +int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in ) { + .extent_cnt =cpu_to_le32 (0 ),
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1485
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ .start_extent_index = cpu_to_le32(0), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out =sizeof (dc_extents), + .payload_out = &dc_extents, + .min_out =1 ,
Why 1?
Quoted 35 lines
drivers/cxl/core/mbox.c +35
-0+ }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + count =le32_to_cpu (dc_extents.total_extent_cnt); + *extent_gen_num =le32_to_cpu (dc_extents.extent_list_num); + +return count; +} + +static int cxl_dev_get_dc_extents(struct cxl_endpoint_decoder *cxled, + unsigned int start_gen_num, + unsigned int exp_cnt) +{ + struct cxl_memdev_state *mds = cxled_to_mds(cxled); + unsigned int start_index, total_read; + struct device *dev = mds->cxlds.dev; + struct cxl_mbox_cmd mbox_cmd; + + struct cxl_mbox_get_dc_extent_out *dc_extents __free(kfree) = + kvmalloc(mds->payload_size, GFP_KERNEL); + if (!dc_extents) + return -ENOMEM; + + total_read = 0; + start_index = 0; + do { + unsigned int nr_ext, total_extent_cnt, gen_num; + struct cxl_mbox_get_dc_extent_in get_dc_extent; + int rc; + + get_dc_extent = (struct cxl_mbox_get_dc_extent_in) { + .extent_cnt = cpu_to_le32(exp_cnt - start_index),
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1530
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ .start_extent_index = cpu_to_le32(start_index), + }; + + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_DC_EXTENT_LIST , + .payload_in = &get_dc_extent, + .size_in =sizeof (get_dc_extent), + .size_out = mds->payload_size, + .payload_out = dc_extents, + .min_out =1 ,
Why 1?
Quoted 16 lines
drivers/cxl/core/mbox.c +16
-0+ }; + + rc =cxl_internal_send_cmd (mds, &mbox_cmd); +if (rc <0 ) +return rc; + + nr_ext =le32_to_cpu (dc_extents->ret_extent_cnt); + total_read += nr_ext; + total_extent_cnt =le32_to_cpu (dc_extents->total_extent_cnt); + gen_num =le32_to_cpu (dc_extents->extent_list_num); + +dev_dbg (dev,"Get extent list count:%d generation Num:%d\n" , + total_extent_cnt, gen_num); + +if (gen_num != start_gen_num || exp_cnt != total_extent_cnt) { + dev_err(dev, "Possible incomplete extent list; gen %u != %u : cnt %u != %u\n",
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1556
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+ gen_num, start_gen_num, exp_cnt, total_extent_cnt); +return -EIO ; + } + +for (int i =0 ; i < nr_ext ; i++) { +dev_dbg (dev,"Processing extent %d/%d\n" , + start_index + i, exp_cnt); + rc =cxl_validate_extent (mds, &dc_extents->extent[i]); +if (rc) +continue ;
A blank line here
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1558
Quoted 2 lines
drivers/cxl/core/mbox.c +2
-0+if (!cxl_dc_extent_in_ed (cxled, &dc_extents->extent[i])) +continue ;
and here would make this more readable I think.
Quoted 15 lines
drivers/cxl/core/mbox.c +10
-0+ rc =cxl_ed_add_one_extent (cxled, &dc_extents->extent[i]); +if (rc) +return rc; + } + + start_index += nr_ext; + }while (exp_cnt > total_read); + +return 0 ; +}drivers/cxl/core/region.c +0
-0
drivers/cxl/core/region.c static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) · line 2789
Quoted 9 lines
drivers/cxl/core/region.c +7
-0+static int cxl_region_read_extents (struct cxl_region *cxlr) +{ +struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc;
Maybe worth giving up early if we see nr_targets > 1?
If nothing else it saves people trying to figure out what happens if we reboot into an older kernel that doesn't support interleave (from one that does)
Quoted 14 lines
drivers/cxl/core/region.c +9
-0+ + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +} +drivers/cxl/cxlmem.h +0
-0
drivers/cxl/cxlmem.h enum cxl_opcode { · line 623
Quoted 3 lines
drivers/cxl/cxlmem.h +2
-0+/* +* CXL rev 3.1 section 8.2.9.2.1.6; Table 8-51
Throw a table name or section name into the reference so people can find it in CXL rNext.
Quoted 9 lines
+ */
drivers/cxl/cxlmem.h +8
-0+#define CXL_DC_EXTENT_TAG_LEN 0x10 +struct cxl_dc_extent { +__le64 start_dpa; +__le64 length; +u8 tag[CXL_DC_EXTENT_TAG_LEN ]; +__le16 shared_extn_seq; +u8 reserved[6 ]; +} __packed;
drivers/cxl/cxlmem.h enum cxl_opcode { · line 650
Quoted 10 lines
drivers/cxl/cxlmem.h +9
-0+ +/* +* Get Dynamic Capacity Extent List; Output Payload +* CXL rev 3.1 section 8.2.9.9.9.2; Table 8-167 +*/ +struct cxl_mbox_get_dc_extent_out { +__le32 ret_extent_cnt; +__le32 total_extent_cnt; +__le32 extent_list_num;
Naming isn't that clear given generation bit missing.
Quoted 4 lines
drivers/cxl/cxlmem.h +4
-0+u8 rsvd[4 ]; +struct cxl_dc_extent extent[]; +} __packed; +
Re: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 905
Quoted 7 lines
drivers/cxl/core/mbox.c +6
-0+static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length); +struct range ext_range = (struct range ){
space ) {
Quoted 7 lines
drivers/cxl/core/mbox.c +7
-0+ .start = start, + .end = start + length - 1, + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + };
Alison Schofield
maintainerRe: [PATCH 14/26] cxl/region: Read existing extents on region creation
In reply to [email protected]Quoted 30 lines · Ira Weiny
From: Navneet Singh <[email protected]>
Dynamic capacity device extents may be left in an accepted state on a device due to an unexpected host crash. In this case creation of a new region on top of the DC partition (region) is expected to expose those extents for continued use.
Once all endpoint decoders are part of a region and the region is being realized read the device extent list. For ease of review, this patch stops after reading the extent list and leaves realization of the region extents to a future patch.
Signed-off-by Navneet Singh <[email protected]>Co-developed-by Ira Weiny <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Changes for v1:
[iweiny: remove extent list xarray]
[iweiny: Update spec references to 3.1]
[iweiny: use struct range in extents]
[iweiny: remove all reference tracking and let regions track extents
through the extent devices.]
[djbw/Jonathan/Fan: move extent tracking to endpoint decoders]--- drivers/cxl/core/core.h | 9 +++ drivers/cxl/core/mbox.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 29 +++++++ drivers/cxl/cxlmem.h | 49 ++++++++++++ 4 files changed, 279 insertions(+)
snip
Quoted 4 lines
drivers/cxl/core/mbox.c +3
-0+static int cxl_validate_extent (struct cxl_memdev_state *mds, +struct cxl_dc_extent *dc_extent) +{
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 885
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+struct device *dev = mds->cxlds.dev; +uint64_t start, len; + + start =le64_to_cpu (dc_extent->start_dpa); + len =le64_to_cpu (dc_extent->length); + +/* Extents must not cross region boundary's */ +for (int i =0 ; i < mds->nr_dc_region; i++) { +struct cxl_dc_region_info *dcr = &mds->dc_region[i]; +
I think you already got range_contains suggestion
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 896
Quoted 11 lines
drivers/cxl/core/mbox.c +11
-0+if (dcr->base <= start && + (start + len) <= (dcr->base + dcr->decode_len)) { +dev_dbg (dev,"DC extent DPA %#llx - %#llx (DCR:%d:%#llx)\n" , + start, start + len -1 , i, start - dcr->base); +return 0 ; + } + } + +dev_err_ratelimited (dev, +"DC extent DPA %#llx - %#llx is not in any DC region\n" , + start, start + len -1 );
Need some clarification.
Isn't this checking that the extent is fully contained within a region? And then, it dev_err's if not fully contained. There is not actually a check and an error message about crossing region boundary's as the comment suggests. Maybe update the comment to reflect the work.. like:
/* Extent must be fully contained in a region */
drivers/cxl/core/mbox.c int cxl_enumerate_cmds(struct cxl_memdev_state *mds) · line 904
Quoted 8 lines
drivers/cxl/core/mbox.c +8
-0+return -EINVAL ; +} + +static bool cxl_dc_extent_in_ed (struct cxl_endpoint_decoder *cxled, +struct cxl_dc_extent *extent) +{ +uint64_t start =le64_to_cpu (extent->start_dpa); +uint64_t length =le64_to_cpu (extent->length);
u64 here (and in other places too)
Quoted 21 lines
drivers/cxl/core/mbox.c +15
-0+struct range ext_range = (struct range ){ + .start = start, + .end = start + length -1 , + }; +struct range ed_range = (struct range ) { + .start = cxled->dpa_res->start, + .end = cxled->dpa_res->end, + }; + +dev_dbg (&cxled->cxld.dev,"Checking ED (%pr) for extent DPA:%#llx LEN:%#llx\n" , + cxled->dpa_res, start, length); + +return range_contains (&ed_range, &ext_range); +} + void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_log_type type, enum cxl_event_type event_type,@@ -973,6 +1020,15 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,return rc; }
drivers/cxl/core/mbox.c static int cxl_clear_event_record(struct cxl_memdev_state *mds, · line 1031
Quoted 10 lines
drivers/cxl/core/mbox.c +9
-0+static 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); +} +
That's nice!
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1465
Quoted 8 lines
drivers/cxl/core/mbox.c +1
-0static void cxl_mem_get_records_log (struct cxl_memdev_state *mds,enum cxl_event_log_type type) {@@ -1406,6 +1462,142 @@ int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) }EXPORT_SYMBOL_NS_GPL (cxl_dev_dynamic_capacity_identify,CXL ); +static int cxl_dev_get_dc_extent_cnt(struct cxl_memdev_state *mds,
Perhaps drop the _dev_ from this (and other, like below) function names.
Quoted 1 line
drivers/cxl/core/mbox.c +1
-0+static int cxl_dev_get_dc_extents(struct cxl_endpoint_decoder *cxled,
snip
Quoted 13 lines
drivers/cxl/core/mbox.c +13
-0+/** +* cxl_read_dc_extents() - Read any existing extents +* @cxled: Endpoint decoder which is part of a region +* +* Issue the Get Dynamic Capacity Extent List command to the device +* and add any existing extents found which belong to this decoder. +* +* Return: 0 if command was executed successfully, -ERRNO on error. +*/ +int cxl_read_dc_extents (struct cxl_endpoint_decoder *cxled) +{ +struct cxl_memdev_state *mds =cxled_to_mds (cxled); +struct device *dev = mds->cxlds.dev;
drivers/cxl/core/mbox.c int cxl_dev_dynamic_capacity_identify(struct cxl_memdev_state *mds) · line 1592
Quoted 10 lines
drivers/cxl/core/mbox.c +10
-0+unsigned int extent_gen_num; +int rc; + +if (!cxl_dcd_supported (mds)) { +dev_dbg (dev,"DCD unsupported\n" ); +return 0 ; + } + + rc =cxl_dev_get_dc_extent_cnt (mds, &extent_gen_num); + dev_dbg(mds->cxlds.dev, "Extent count: %d Generation Num: %d\n",
Either use the *dev defined in both dev_dbg()'s or get rid of it use mds->cxlds.dev.
Quoted 8 lines
drivers/cxl/core/mbox.c +8
-0+ rc, extent_gen_num); +if (rc <=0 )/* 0 == no records found */ +return rc; + +return cxl_dev_get_dc_extents (cxled, extent_gen_num, rc); +} +EXPORT_SYMBOL_NS_GPL (cxl_read_dc_extents,CXL ); +
snip
drivers/cxl/core/region.c static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) · line 2784
Quoted 3 lines
drivers/cxl/core/region.c +2
-0+static int cxl_region_read_extents (struct cxl_region *cxlr) +{
How about:
static int cxl_region_read_extents(struct cxl_region_params *p)
drivers/cxl/core/region.c static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) · line 2797
Quoted 13 lines
drivers/cxl/core/region.c +13
-0+struct cxl_region_params *p = &cxlr->params; +int i; + +for (i =0 ; i < p->nr_targets; i++) { +int rc; + + rc =cxl_read_dc_extents (p->targets[i]); +if (rc) +return rc; + } + +return 0 ; +}
snip to end