Add partitioning support for CXL memdevs
[email protected]
maintainerv3 cover Add partitioning support for CXL memdevs
From: Alison Schofield <[email protected]>
Users may want to view and change partition layouts of CXL memory devices that support partitioning. Provide userspace access to the device partitioning capabilities as defined in the CXL 2.0 specification.
The first 4 patches add accessors for all the information needed to formulate a new partition layout. This info is accessible via the libcxl API and a new option in the cxl list command:
"partition_info":{
"active_volatile_bytes":273535729664,
"active_persistent_bytes":0,
"next_volatile_bytes":268435456,
"next_persistent_bytes":273267294208,
"total_bytes":273535729664,
"volatile_only_bytes":0,
"persistent_only_bytes":0,
"partition_alignment_bytes":268435456
}Patch 5 introduces the libcxl interfaces for the SET_PARTITION_INFO mailbox command and Patch 6 adds the new CXL command:
# cxl set-partition-info usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]
-v, --verbose turn on debug
-s, --volatile_size <n>
next volatile partition size in bytesThe CXL command does not offer the IMMEDIATE mode option defined in the CXL 2.0 spec because the CXL kernel driver does not support immediate mode yet. Since userspace could use the libcxl API to send a SET_PARTITION_INFO mailbox command with immediate mode selected, a kernel patch that rejects such requests is in review for the CXL driver.
Tested in QEMU and Simics environment. No cxl_test yet.
Repo: https://github.com/AlisonSchofield/ndctl/tree/as/partitions
Changes in v3:
- Back out the API name change to the partition align accessor. The API was already released in v72.
- Man page: collapse into one .txt file.
- Man page: add to Documentation/meson.build
Changes in v2:
- Rebase onto https://github.com/pmem/ndctl.git djbw/meson.
- Clarify that capacities are reported in bytes. (Ira) This led to renaming accessors like *_capacity to *_bytes and a spattering of changes in the man pages and commit messages.
- Add missing cxl_cmd_unref() when creating json objects. (Ira)
- Change the cxl list option to: -I --partition (Dan)
- Use OPT_STRING for the --volatile_size parameter (Dan, Vishal)
- Drop extra _get_ in accessor names. (Vishal)
- Add an accessor for the SET_PARTITION_INFO mbox cmd flag.
- Display usage_with_options if size parameter is missing.
- Drop the OPT64 define patch. Use OPT_STRING instead.
Alison Schofield (6):
libcxl: add GET_PARTITION_INFO mailbox command and accessors
libcxl: add accessors for capacity fields of the IDENTIFY command
libcxl: return the partition alignment field in bytes
cxl: add memdev partition information to cxl-list
libcxl: add interfaces for SET_PARTITION_INFO mailbox command
cxl: add command set-partition-info
Documentation/cxl/cxl-list.txt | 23 ++++ Documentation/cxl/cxl-set-partition-info.txt | 53 ++++++++ Documentation/cxl/meson.build | 1 + cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/json.c | 114 +++++++++++++++++ cxl/lib/libcxl.c | 122 ++++++++++++++++++- cxl/lib/libcxl.sym | 13 ++ cxl/lib/private.h | 18 +++ cxl/libcxl.h | 13 ++ cxl/list.c | 5 + cxl/memdev.c | 101 +++++++++++++++ util/json.h | 1 + util/size.h | 1 + 14 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 Documentation/cxl/cxl-set-partition-info.txt
base-commit: 25062cf34c70012f5d42ce1fef7e2dc129807c10
prerequisite-patch-id: d34c91059d77651eaf1e71adb6135b397f64c056
prerequisite-patch-id: 72a64823dc720b5c7b65fe949d75e9f6fbf79035
prerequisite-patch-id: f9fd1d50d96896f27ce1d6df59d1aa8ea06795ab
prerequisite-patch-id: 0e904349e14e74754a22bd72ce97add030d80e90
prerequisite-patch-id: 331899e7b565c625ef0647f71057850a919535d8
prerequisite-patch-id: 0ddeb2219011fe7b272cbbf59bc046bf26ee1bc7
prerequisite-patch-id: fe1023948a0202cca8d641e694de425512512f92
prerequisite-patch-id: 48b0b8feddcc98201f3c75b15bb1ed13d30e1269
prerequisite-patch-id: 5a9be92f860c0bf9144772b550d62e0c0a463e7c
prerequisite-patch-id: 113e1fa147e96ba5d4127246cc3dcae895d33e7c
prerequisite-patch-id: 03ad3eb99d14b51a0d0a48dfb3f6f3b2f84bac24
prerequisite-patch-id: 6c9b29768efc178c37d62c53501a98bc7baa9934
prerequisite-patch-id: d4086981a857f5f2d3720f33e1c823f906b3211f
prerequisite-patch-id: 3ad6ea54cc6430977c8ae4a0833e22499f1ccd96
prerequisite-patch-id: d4ff0ee2dc988440e0cad26d43e1a740fb89fbfd
prerequisite-patch-id: e33606c2a4ab9ac74034cb3bde8947317274d8b3
prerequisite-patch-id: e7b57274d44fd9cdf1b64ca802b33afe255cef44
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 1/6 libcxl: add GET_PARTITION_INFO mailbox command and accessors
From: Alison Schofield <[email protected]>
Users need access to the CXL GET_PARTITION_INFO mailbox command to inspect and confirm changes to the partition layout of a memory device.
Add libcxl APIs to create a new GET_PARTITION_INFO mailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the partition info output.
Per the CXL 2.0 specification, devices report partition capacities as multiples of 256MB. Define and use a capacity multiplier to convert the raw data into bytes for user consumption. Use byte format as the norm for all capacity values produced or consumed using CXL Mailbox commands.
--- cxl/lib/libcxl.c | 41 +++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 10 ++++++++++ cxl/libcxl.h | 5 +++++ util/size.h | 1 + 5 files changed, 62 insertions(+)
cxl/lib/libcxl.c +41 -0
@@ -1160,6 +1160,47 @@ CXL_EXPORT ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd,return length; } +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_get_partition_info(struct cxl_memdev *memdev) +{ +return cxl_cmd_new_generic (memdev, +CXL_MEM_COMMAND_ID_GET_PARTITION_INFO ); +} + +#define cmd_partition_get_capacity_field (cmd, field) \ +do { \ + struct cxl_cmd_get_partition_info *c = \ + (struct cxl_cmd_get_partition_info *)cmd->send_cmd->out.payload;\ + int rc = cxl_cmd_validate_status(cmd, \ + CXL_MEM_COMMAND_ID_GET_PARTITION_INFO); \ + if (rc) \ + return ULLONG_MAX; \ + return le64_to_cpu(c->field) * CXL_CAPACITY_MULTIPLIER; \ +} while (0) + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_active_volatile_bytes (struct cxl_cmd *cmd) +{ +cmd_partition_get_capacity_field (cmd, active_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_active_persistent_bytes (struct cxl_cmd *cmd) +{ +cmd_partition_get_capacity_field (cmd, active_persistent_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_next_volatile_bytes (struct cxl_cmd *cmd) +{ +cmd_partition_get_capacity_field (cmd, next_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_next_persistent_bytes (struct cxl_cmd *cmd) +{ +cmd_partition_get_capacity_field (cmd, next_persistent_cap); +} + CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd) {struct cxl_memdev *memdev = cmd->memdev;
cxl/lib/libcxl.sym +5 -0
@@ -70,6 +70,11 @@ global: cxl_memdev_zero_label; cxl_memdev_write_label; cxl_memdev_read_label; + cxl_cmd_new_get_partition_info; + cxl_cmd_partition_info_get_active_volatile_bytes; + cxl_cmd_partition_info_get_active_persistent_bytes; + cxl_cmd_partition_info_get_next_volatile_bytes; + cxl_cmd_partition_info_get_next_persistent_bytes; local: *; };
cxl/lib/private.h +10 -0
@@ -7,6 +7,7 @@#include <cxl/cxl_mem.h> #include <ccan/endian/endian.h> #include <ccan/short_types/short_types.h> +#include <util/size.h> #define CXL_EXPORT __attribute__ ((visibility("default")))
@@ -104,6 +105,15 @@ struct cxl_cmd_get_health_info {le32 pmem_errors; } __attribute__((packed)); +struct cxl_cmd_get_partition_info { +le64 active_volatile_cap; +le64 active_persistent_cap; +le64 next_volatile_cap; +le64 next_persistent_cap; +} __attribute__((packed)); + +#define CXL_CAPACITY_MULTIPLIER SZ_256M +/* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */ #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK BIT(0)#define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK BIT(1)
cxl/libcxl.h +5 -0
@@ -109,6 +109,11 @@ ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf, unsigned int length);struct cxl_cmd *cxl_cmd_new_write_label (struct cxl_memdev *memdev,void *buf,unsigned int offset,unsigned int length); +struct cxl_cmd *cxl_cmd_new_get_partition_info (struct cxl_memdev *memdev); +unsigned long long cxl_cmd_partition_info_get_active_volatile_bytes (struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_active_persistent_bytes (struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_next_volatile_bytes (struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_next_persistent_bytes (struct cxl_cmd *cmd); #ifdef __cplusplus }/* extern "C" */
util/size.h +1 -0
@@ -15,6 +15,7 @@#define SZ_4M 0x00400000#define SZ_16M 0x01000000#define SZ_64M 0x04000000 +#define SZ_256M 0x10000000#define SZ_1G 0x40000000#define SZ_1T 0x10000000000ULL
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 2/6 libcxl: add accessors for capacity fields of the IDENTIFY command
In reply to [email protected]From: Alison Schofield <[email protected]>
Users need access to a few additional fields reported by the IDENTIFY mailbox command: total, volatile_only, and persistent_only capacities. These values are useful when defining partition layouts.
Add accessors to the libcxl API to retrieve these values from the IDENTIFY command.
The fields are specified in multiples of 256MB per the CXL 2.0 spec. Use the capacity multiplier to convert the raw data into bytes for user consumption.
--- cxl/lib/libcxl.c | 29 +++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 3 +++ cxl/libcxl.h | 3 +++ 3 files changed, 35 insertions(+)
cxl/lib/libcxl.c +29 -0
@@ -1105,6 +1105,35 @@ CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd)return le32_to_cpu (id->lsa_size); } +#define cmd_identify_get_capacity_field (cmd, field) \ +do { \ + struct cxl_cmd_identify *c = \ + (struct cxl_cmd_identify *)cmd->send_cmd->out.payload;\ + int rc = cxl_cmd_validate_status(cmd, \ + CXL_MEM_COMMAND_ID_IDENTIFY); \ + if (rc) \ + return ULLONG_MAX; \ + return le64_to_cpu(c->field) * CXL_CAPACITY_MULTIPLIER; \ +} while (0) + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_total_bytes (struct cxl_cmd *cmd) +{ +cmd_identify_get_capacity_field (cmd, total_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_volatile_only_bytes (struct cxl_cmd *cmd) +{ +cmd_identify_get_capacity_field (cmd, volatile_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_persistent_only_bytes (struct cxl_cmd *cmd) +{ +cmd_identify_get_capacity_field (cmd, persistent_capacity); +} + CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev,int opcode) {
cxl/lib/libcxl.sym +3 -0
@@ -31,6 +31,9 @@ global: cxl_cmd_get_out_size; cxl_cmd_new_identify; cxl_cmd_identify_get_fw_rev; + cxl_cmd_identify_get_total_bytes; + cxl_cmd_identify_get_volatile_only_bytes; + cxl_cmd_identify_get_persistent_only_bytes; cxl_cmd_identify_get_partition_align; cxl_cmd_identify_get_label_size; cxl_cmd_new_get_health_info;
cxl/libcxl.h +3 -0
@@ -68,6 +68,9 @@ int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd);int cxl_cmd_get_out_size (struct cxl_cmd *cmd);struct cxl_cmd *cxl_cmd_new_identify (struct cxl_memdev *memdev);int cxl_cmd_identify_get_fw_rev (struct cxl_cmd *cmd,char *fw_rev,int fw_len); +unsigned long long cxl_cmd_identify_get_total_bytes (struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_volatile_only_bytes (struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_persistent_only_bytes (struct cxl_cmd *cmd);unsigned long long cxl_cmd_identify_get_partition_align (struct cxl_cmd *cmd);unsigned int cxl_cmd_identify_get_label_size (struct cxl_cmd *cmd);struct cxl_cmd *cxl_cmd_new_get_health_info (struct cxl_memdev *memdev);
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 3/6 libcxl: return the partition alignment field in bytes
In reply to [email protected]From: Alison Schofield <[email protected]>
Per the CXL specification, the partition alignment field reports the alignment value in multiples of 256MB. In the libcxl API, values for all capacity fields are defined to return bytes.
Update the partition alignment accessor to return bytes so that it is in sync with other capacity related fields.
--- cxl/lib/libcxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cxl/lib/libcxl.c +1 -1
@@ -1089,7 +1089,7 @@ CXL_EXPORT unsigned long long cxl_cmd_identify_get_partition_align(if (cmd->status <0 )return cmd->status; -return le64_to_cpu (id->partition_align); +return le64_to_cpu (id->partition_align) *CXL_CAPACITY_MULTIPLIER ; } CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd)
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 4/6 cxl: add memdev partition information to cxl-list
In reply to [email protected]From: Alison Schofield <[email protected]>
Users may want to check the partition information of a memory device using the CXL command line tool. This is useful for understanding the active, as well as creating the next, partition layout.
Add an option the 'cxl list' command to display partition information. Include all of the fields from GET_PARTITION_INFO and the partitioning related fields from the IDENTIFY mailbox command.
Example:
"partition_info":{
"active_volatile_bytes":273535729664,
"active_persistent_bytes":0,
"next_volatile_bytes":0,
"next_persistent_bytes":0,
"total_bytes":273535729664,
"volatile_only_bytes":0,
"persistent_only_bytes":0,
"partition_alignment_bytes":268435456
}--- Documentation/cxl/cxl-list.txt | 23 +++++++ cxl/json.c | 114 +++++++++++++++++++++++++++++++++ cxl/list.c | 5 ++ util/json.h | 1 + 4 files changed, 143 insertions(+)
Documentation/cxl/cxl-list.txt +23 -0
@@ -85,6 +85,29 @@ OPTIONS } ] ---- +-I:: +--partition:: + Include partition information in the memdev listing. Example listing: +---- +# cxl list -m mem0 -I +[ + { + "memdev":"mem0", + "pmem_size":0, + "ram_size":273535729664, + "partition_info":{ + "active_volatile_bytes":273535729664, + "active_persistent_bytes":0, + "next_volatile_bytes":0, + "next_persistent_bytes":0, + "total_bytes":273535729664, + "volatile_only_bytes":0, + "persistent_only_bytes":0, + "partition_alignment_bytes":268435456 + } + } +] +---- include::human-option.txt[]
cxl/json.c +114 -0
130 lines not on this page · raw message
cxl/list.c +5 -0
@@ -19,6 +19,7 @@ static struct {bool idle;bool human;bool health; +bool partition; } list;static unsigned long listopts_to_flags (void )
@@ -31,6 +32,8 @@ static unsigned long listopts_to_flags(void) flags |=UTIL_JSON_HUMAN ;if (list.health) flags |=UTIL_JSON_HEALTH ; +if (list.partition) + flags |=UTIL_JSON_PARTITION ;return flags; }
@@ -64,6 +67,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) "use human friendly number formats "),OPT_BOOLEAN ('H' ,"health" , &list.health,"include memory device health information " ), +OPT_BOOLEAN ('I' ,"partition" , &list.partition, +"include memory device partition information " ), OPT_END(), }; const char * const u[] = {
util/json.h +1 -0
@@ -17,6 +17,7 @@ enum util_json_flags {UTIL_JSON_FIRMWARE = (1 <<8 ),UTIL_JSON_DAX_MAPPINGS = (1 <<9 ),UTIL_JSON_HEALTH = (1 <<10 ), + UTIL_JSON_PARTITION = (1 << 11), };struct json_object ;
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 5/6 libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to [email protected]From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a SET_PARTITION_INFO mailbox as defined in the CXL 2.0 specification.
--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)
cxl/lib/libcxl.c +50 -0
@@ -1230,6 +1230,21 @@ cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd)cmd_partition_get_capacity_field (cmd, next_persistent_cap); } +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags) +{ +struct cxl_cmd_set_partition_info *set_partition; +struct cxl_cmd *cmd; + + cmd =cxl_cmd_new_generic (memdev, +CXL_MEM_COMMAND_ID_SET_PARTITION_INFO ); + + set_partition = (struct cxl_cmd_set_partition_info *)cmd->send_cmd->in.payload; + set_partition->volatile_capacity =cpu_to_le64 (volatile_capacity); + set_partition->flags = flags; +return cmd; +} + CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd) {struct cxl_memdev *memdev = cmd->memdev;
@@ -1428,3 +1443,38 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, {return lsa_op (memdev,LSA_OP_GET , buf, length, offset); } + +CXL_EXPORT int cxl_memdev_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags) +{ +struct cxl_ctx *ctx =cxl_memdev_get_ctx (memdev); +struct cxl_cmd *cmd; +int rc; + +dbg (ctx,"%s: enter cap: %llx, flags %d\n" , __func__, + volatile_capacity, flags); + + cmd =cxl_cmd_new_set_partition_info (memdev, + volatile_capacity /CXL_CAPACITY_MULTIPLIER , flags); +if (!cmd) +return -ENXIO ; + + rc =cxl_cmd_submit (cmd); +if (rc <0 ) { +err (ctx,"cmd submission failed: %s\n" ,strerror (-rc)); + goto err; + } + rc =cxl_cmd_get_mbox_status (cmd); +if (rc !=0 ) { +err (ctx,"%s: mbox status: %d\n" , __func__, rc); + rc = -ENXIO ; + } +err: +cxl_cmd_unref (cmd); +return rc; +} + +CXL_EXPORT int cxl_cmd_partition_info_flag_immediate(void) +{ +return CXL_CMD_SET_PARTITION_INFO_FLAG_IMMEDIATE ; +}
cxl/lib/libcxl.sym +5 -0
@@ -78,6 +78,11 @@ global: cxl_cmd_partition_info_get_active_persistent_bytes; cxl_cmd_partition_info_get_next_volatile_bytes; cxl_cmd_partition_info_get_next_persistent_bytes; + cxl_cmd_new_set_partition_info; + cxl_memdev_set_partition_info; + cxl_cmd_partition_info_flag_none; + cxl_cmd_partition_info_flag_immediate; + local: *; };
cxl/lib/private.h +8 -0
@@ -114,6 +114,14 @@ struct cxl_cmd_get_partition_info {#define CXL_CAPACITY_MULTIPLIER SZ_256M +struct cxl_cmd_set_partition_info { +le64 volatile_capacity; +u8 flags; +} __attribute__((packed)); + +/* CXL 2.0 8.2.9.5.2 Set Partition Info */ +#define CXL_CMD_SET_PARTITION_INFO_FLAG_IMMEDIATE BIT(0) +/* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */ #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK BIT(0)#define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK BIT(1)
cxl/libcxl.h +5 -0
@@ -50,6 +50,8 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset);int cxl_memdev_write_label (struct cxl_memdev *memdev,void *buf,size_t length,size_t offset); +int cxl_memdev_set_partition_info (struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags);#define cxl_memdev_foreach (ctx, memdev) \ for (memdev = cxl_memdev_get_first(ctx); \
@@ -117,6 +119,9 @@ unsigned long long cxl_cmd_partition_info_get_active_volatile_bytes(struct cxl_cunsigned long long cxl_cmd_partition_info_get_active_persistent_bytes (struct cxl_cmd *cmd);unsigned long long cxl_cmd_partition_info_get_next_volatile_bytes (struct cxl_cmd *cmd);unsigned long long cxl_cmd_partition_info_get_next_persistent_bytes (struct cxl_cmd *cmd); +struct cxl_cmd *cxl_cmd_new_set_partition_info (struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags); +int cxl_cmd_partition_info_flag_immediate (void ); #ifdef __cplusplus }/* extern "C" */
Signature · 1 line
2.31.1
[email protected]
maintainerPATCH v3 6/6 cxl: add command set-partition-info
In reply to [email protected]From: Alison Schofield <[email protected]>
Users may want to change the partition layout of a memory device using the CXL command line tool. Add a new CXL command, 'cxl set-partition-info', that operates on a CXL memdev, or a set of memdevs, and allows the user to change the partition layout of the device(s).
Synopsis:
Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]
-v, --verbose turn on debug -s, --volatile_size <n> next volatile partition size in bytes
The included MAN page explains how to find the partitioning capabilities and restrictions of a CXL memory device.
--- Documentation/cxl/cxl-set-partition-info.txt | 53 ++++++++++ Documentation/cxl/meson.build | 1 + cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/memdev.c | 101 +++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 Documentation/cxl/cxl-set-partition-info.txt
Documentation/cxl/cxl-set-partition-info.txt new file +53 -0
@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-set-partition-info(1) +========================= + +NAME +---- +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev + +SYNOPSIS +-------- +[verse] +'cxl set-partition-info <mem> [ [<mem1>..<memN>] [<options>]' + +DESCRIPTION +----------- +Partition the device into volatile and persistent capacity. The change +in partitioning will become the “next” configuration, to become active +on the next device reset. + +Use "cxl list -m <memdev> -I" to examine the partitioning capabilities +of a device. A partition_alignment_bytes value of zero means there are +no partitionable bytes available and therefore the partitions cannot be +changed. + +Using this command to change the size of the persistent capacity shall +result in the loss of data stored. + +OPTIONS +------- +<memory device(s)>:: +include::memdev-option.txt[] + +-s:: +--size=:: + Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment_bytes. + Use 'cxl list -m <memdev> -I' to find partition_alignment_bytes. + + Size must be less than or equal to the device's partitionable bytes. + Calculate partitionable bytes by subracting the volatile_only_bytes, + and the persistent_only_bytes, from the total_bytes. + Use 'cxl list -m <memdev> -I' to find the above mentioned_byte values. + +-v:: + Turn on verbose debug messages in the library (if libcxl was built with + logging and debug enabled). + +SEE ALSO +-------- +linkcxl:cxl-list[1], +CXL-2.0 8.2.9.5.2
Documentation/cxl/meson.build +1 -0
@@ -28,6 +28,7 @@ cxl_manpages = [ 'cxl-read-labels.txt', 'cxl-write-labels.txt', 'cxl-zero-labels.txt', + 'cxl-set-partition-info.txt', ] foreach man : cxl_manpages
cxl/builtin.h +1 -0
@@ -10,4 +10,5 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx);int cmd_zero_labels (int argc,const char **argv,struct cxl_ctx *ctx);int cmd_init_labels (int argc,const char **argv,struct cxl_ctx *ctx);int cmd_check_labels (int argc,const char **argv,struct cxl_ctx *ctx); +int cmd_set_partition_info (int argc,const char **argv,struct cxl_ctx *ctx);#endif /* _CXL_BUILTIN_H_ */
cxl/cxl.c +1 -0
@@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { { "zero-labels", .c_fn = cmd_zero_labels }, { "read-labels", .c_fn = cmd_read_labels }, { "write-labels", .c_fn = cmd_write_labels }, + { "set-partition-info", .c_fn = cmd_set_partition_info }, };int main (int argc,const char **argv)
cxl/memdev.c +101 -0
140 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [ndctl PATCH v3 1/6] libcxl: add GET_PARTITION_INFO mailbox command and accessors
In reply to [email protected]Quoted 11 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users need access to the CXL
GET_PARTITION_INFOmailbox command to inspect and confirm changes to the partition layout of a memory device.Add libcxl APIs to create a new
GET_PARTITION_INFOmailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the partition info output.
Quoted 7 lines
Per the CXL 2.0 specification, devices report partition capacities as multiples of 256MB. Define and use a capacity multiplier to convert the raw data into bytes for user consumption. Use byte format as the norm for all capacity values produced or consumed using CXL Mailbox commands.
Signed-off-by Alison Schofield <[email protected]>
Looks good to me, you might want to also add a short note about the "cxl_cmd_new_get_partition_info()" API in the "=== MEMDEV: Commands" section of Documentation/cxl/lib/libcxl.txt that I started here:
Note that I'm not adding every single API there, but I think each cxl_cmd_new_<command_type>() API could use a short note.
That can be a follow on depending on whether Vishal merges this first or the topology enumeration series.
Re: [ndctl PATCH v3 2/6] libcxl: add accessors for capacity fields of the IDENTIFY command
In reply to [email protected]Quoted 29 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users need access to a few additional fields reported by the IDENTIFY mailbox command: total,
volatile_only, andpersistent_onlycapacities. These values are useful when defining partition layouts.Add accessors to the libcxl API to retrieve these values from the IDENTIFY command.
The fields are specified in multiples of 256MB per the CXL 2.0 spec. Use the capacity multiplier to convert the raw data into bytes for user consumption.
Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 29 +++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 3 +++ cxl/libcxl.h | 3 +++ 3 files changed, 35 insertions(+)cxl/lib/libcxl.c +0
-0@@ -1105,6 +1105,35 @@ CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd)return le32_to_cpu (id->lsa_size); }
cxl/lib/libcxl.c CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd) · line 1117
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+#define cmd_identify_get_capacity_field (cmd, field) \ +do { \ + struct cxl_cmd_identify *c = \ + (struct cxl_cmd_identify *)cmd->send_cmd->out.payload;\ + int rc = cxl_cmd_validate_status(cmd, \ + CXL_MEM_COMMAND_ID_IDENTIFY); \ + if (rc) \ + return ULLONG_MAX; \ + return le64_to_cpu(c->field) * CXL_CAPACITY_MULTIPLIER; \ +} while (0)
This could probably just be 2 functions
cmd_to_identify()capacity_to_bytes()
...and then the caller does:
return capactity_to_bytes(cmd_to_identify()->field);
...and skip the macro. Otherwise, a macro with a "return" statement can be unwieldy unless that macro is defining an entire function.
Alison Schofield
maintainerRe: [ndctl PATCH v3 1/6] libcxl: add GET_PARTITION_INFO mailbox command and accessors
In reply to Dan WilliamsQuoted 18 lines · Dan Williams
Quoted 17 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users need access to the CXL
GET_PARTITION_INFOmailbox command to inspect and confirm changes to the partition layout of a memory device.Add libcxl APIs to create a new
GET_PARTITION_INFOmailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the partition info output.Per the CXL 2.0 specification, devices report partition capacities as multiples of 256MB. Define and use a capacity multiplier to convert the raw data into bytes for user consumption. Use byte format as the norm for all capacity values produced or consumed using CXL Mailbox commands.
Quoted 7 lines
Quoted 1 line
Signed-off-by Alison Schofield <[email protected]>Looks good to me, you might want to also add a short note about the "
cxl_cmd_new_get_partition_info()" API in the "=== MEMDEV: Commands" section ofDocumentation/cxl/lib/libcxl.txtthat I started here:
Will do.
Quoted 6 lines
Note that I'm not adding every single API there, but I think each cxl_cmd_new_<command_type>() API could use a short note.
That can be a follow on depending on whether Vishal merges this first or the topology enumeration series.
Vishal - I think this should follow the topology enumeration series because it wants to use the cxl_filter_walk() that the topo series introduces. (to spit out the updated partition info upon completion of the set-partition-info cmd.)
So, a v4 posting will apply after topo series.
Quoted 2 lines
Reviewed-by Dan Williams <[email protected]>
Re: [ndctl PATCH v3 3/6] libcxl: return the partition alignment field in bytes
In reply to [email protected]Quoted 20 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Per the CXL specification, the partition alignment field reports the alignment value in multiples of 256MB. In the libcxl API, values for all capacity fields are defined to return bytes.
Update the partition alignment accessor to return bytes so that it is in sync with other capacity related fields.
Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)cxl/lib/libcxl.c +0
-0
cxl/lib/libcxl.c CXL_EXPORT unsigned long long cxl_cmd_identify_get_partition_align( · line 1094
Quoted 7 lines
cxl/lib/libcxl.c +1
-1@@ -1089,7 +1089,7 @@ CXL_EXPORT unsigned long long cxl_cmd_identify_get_partition_align(if (cmd->status <0 )return cmd->status; -return le64_to_cpu (id->partition_align); +return le64_to_cpu (id->partition_align) *CXL_CAPACITY_MULTIPLIER ; }
Looks ok, and likely no one has noticed the old behavior. If someone does notice though we'll likely need to introduce a new cxl_cmd_identify_get_partition_align_bytes() and support both styles forever.
Re: [ndctl PATCH v3 4/6] cxl: add memdev partition information to cxl-list
In reply to [email protected]Quoted 48 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want to check the partition information of a memory device using the CXL command line tool. This is useful for understanding the active, as well as creating the next, partition layout.
Add an option the 'cxl list' command to display partition information. Include all of the fields from
GET_PARTITION_INFOand the partitioning related fields from the IDENTIFY mailbox command.Example:
"partition_info":{ "active_volatile_bytes":273535729664, "active_persistent_bytes":0, "next_volatile_bytes":0, "next_persistent_bytes":0, "total_bytes":273535729664, "volatile_only_bytes":0, "persistent_only_bytes":0, "partition_alignment_bytes":268435456 }Signed-off-by Alison Schofield <[email protected]>--- Documentation/cxl/cxl-list.txt | 23 +++++++ cxl/json.c | 114 +++++++++++++++++++++++++++++++++ cxl/list.c | 5 ++ util/json.h | 1 + 4 files changed, 143 insertions(+)Documentation/cxl/cxl-list.txt +9
-0@@ -85,6 +85,29 @@ OPTIONS } ] ---- +-I:: +--partition:: + Include partition information in the memdev listing. Example listing: +---- +# cxl list -m mem0 -I +[ + { + "memdev":"mem0", + "pmem_size":0,
Documentation/cxl/cxl-list.txt OPTIONS · line 106
Quoted 10 lines
Documentation/cxl/cxl-list.txt +10
-0+ "ram_size":273535729664, + "partition_info":{ + "active_volatile_bytes":273535729664, + "active_persistent_bytes":0, + "next_volatile_bytes":0, + "next_persistent_bytes":0, + "total_bytes":273535729664, + "volatile_only_bytes":0, + "persistent_only_bytes":0, + "partition_alignment_bytes":268435456
I think it's confusing to include "_bytes" in the json listing as it's not used in any of the other byte oriented output fields across 'cxl list' and 'ndctl list'. "_size" would match similar fields in other json objects.
Other than that,
Verma, Vishal L
maintainerRe: [ndctl PATCH v3 1/6] libcxl: add GET_PARTITION_INFO mailbox command and accessors
In reply to Alison SchofieldQuoted 36 lines · Alison Schofield
Quoted 18 lines · Dan Williams
Quoted 17 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users need access to the CXL
GET_PARTITION_INFOmailbox command to inspect and confirm changes to the partition layout of a memory device.Add libcxl APIs to create a new
GET_PARTITION_INFOmailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the partition info output.Per the CXL 2.0 specification, devices report partition capacities as multiples of 256MB. Define and use a capacity multiplier to convert the raw data into bytes for user consumption. Use byte format as the norm for all capacity values produced or consumed using CXL Mailbox commands.
Quoted 7 lines
Quoted 1 line
Signed-off-by Alison Schofield <[email protected]>Looks good to me, you might want to also add a short note about the "
cxl_cmd_new_get_partition_info()" API in the "=== MEMDEV: Commands" section ofDocumentation/cxl/lib/libcxl.txtthat I started here:Will do.
Quoted 6 lines
Note that I'm not adding every single API there, but I think each cxl_cmd_new_<command_type>() API could use a short note.
That can be a follow on depending on whether Vishal merges this first or the topology enumeration series.
Quoted 6 lines
Vishal - I think this should follow the topology enumeration series because it wants to use the
cxl_filter_walk()that the topo series introduces. (to spit out the updated partition info upon completion of the set-partition-info cmd.)So, a v4 posting will apply after topo series.
Yep that sounds good to me.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Dan Williams <[email protected]>
Alison Schofield
maintainerRe: [ndctl PATCH v3 4/6] cxl: add memdev partition information to cxl-list
In reply to Dan WilliamsQuoted 2 lines · Dan Williams
Quoted 1 line · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
snip
Quoted 16 lines
Quoted 5 lines
Documentation/cxl/cxl-list.txt +5
-0+# cxl list -m mem0 -I +[ + { + "memdev":"mem0", + "pmem_size":0,Documentation/cxl/cxl-list.txt OPTIONS · line 106
Quoted 10 lines
Documentation/cxl/cxl-list.txt +10
-0+ "ram_size":273535729664, + "partition_info":{ + "active_volatile_bytes":273535729664, + "active_persistent_bytes":0, + "next_volatile_bytes":0, + "next_persistent_bytes":0, + "total_bytes":273535729664, + "volatile_only_bytes":0, + "persistent_only_bytes":0, + "partition_alignment_bytes":268435456
Quoted 4 lines
I think it's confusing to include "
_bytes" in the json listing as it's not used in any of the other byte oriented output fields across 'cxl list' and 'ndctl list'. "_size" would match similar fields in other json objects.
Got it. Will drop the _bytes in v4. Thanks!
Quoted 4 lines
Other than that,
Reviewed-by Dan Williams <[email protected]>
Re: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to [email protected]Quoted 25 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a
SET_PARTITION_INFOmailbox as defined in the CXL 2.0 specification.Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)cxl/lib/libcxl.c +0
-0@@ -1230,6 +1230,21 @@ cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd)cmd_partition_get_capacity_field (cmd, next_persistent_cap); }
cxl/lib/libcxl.c cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) · line 1242
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags) +{ +struct cxl_cmd_set_partition_info *set_partition; +struct cxl_cmd *cmd; + + cmd =cxl_cmd_new_generic (memdev, +CXL_MEM_COMMAND_ID_SET_PARTITION_INFO ); + + set_partition = (struct cxl_cmd_set_partition_info *)cmd->send_cmd->in.payload;
->in.payload is a 'void *', no casting required.
cxl/lib/libcxl.c cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) · line 1244
Quoted 2 lines
cxl/lib/libcxl.c +2
-0+ set_partition->volatile_capacity =cpu_to_le64 (volatile_capacity); + set_partition->flags = flags;
This has the potential to bite if users get accustomed passing in raw values directly... more below.
Quoted 13 lines
cxl/lib/libcxl.c +6
-0+return cmd; +} + CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd) {struct cxl_memdev *memdev = cmd->memdev;@@ -1428,3 +1443,38 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, {return lsa_op (memdev,LSA_OP_GET , buf, length, offset); } + +CXL_EXPORT int cxl_memdev_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags)
cxl/lib/libcxl.c CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, · line 1458
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+{ +struct cxl_ctx *ctx =cxl_memdev_get_ctx (memdev); +struct cxl_cmd *cmd; +int rc; + +dbg (ctx,"%s: enter cap: %llx, flags %d\n" , __func__, + volatile_capacity, flags); + + cmd =cxl_cmd_new_set_partition_info (memdev, + volatile_capacity /CXL_CAPACITY_MULTIPLIER , flags);
Given that the get-partition-info helpers emit 'bytes' I think it would make sense for the set-partition-info to take bytes, i.e. move the conversion to the 256MB shifted value internal to xl_cmd_new_set_partition_info().
Quoted 12 lines
cxl/lib/libcxl.c +12
-0+if (!cmd) +return -ENXIO ; + + rc =cxl_cmd_submit (cmd); +if (rc <0 ) { +err (ctx,"cmd submission failed: %s\n" ,strerror (-rc)); + goto err; + } + rc =cxl_cmd_get_mbox_status (cmd); +if (rc !=0 ) { +err (ctx,"%s: mbox status: %d\n" , __func__, rc); + rc = -ENXIO ;
cxl/lib/libcxl.c CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, · line 1480
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+ } +err: +cxl_cmd_unref (cmd); +return rc; +} + +CXL_EXPORT int cxl_cmd_partition_info_flag_immediate(void) +{ +return CXL_CMD_SET_PARTITION_INFO_FLAG_IMMEDIATE ; +}
I don't understand what this is for?
Let's back up. In order to future proof against spec changes, and endianness, struct packing and all other weird things that make struct ABIs hard to maintain compatibility the ndctl project adopts the libabc template of just not letting library consumers see any raw data structures or bit fields by default [1]. For a situation like this since the command only has one flag that affects the mode of operation I would just go ahead and define an enum for that explicitly.
enum cxl_setpartition_mode {
CXL_SETPART_NONE,
CXL_SETPART_NEXTBOOT,
CXL_SETPART_IMMEDIATE,
};
Then the main function prototype becomes:
int cxl_cmd_new_setpartition(struct cxl_memdev *memdev, unsigned long long volatile_capacity);
...with a new:
int cxl_cmd_setpartition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode);
...and it becomes impossible for users to pass unsupported flag values. If the specification later on adds more flags then we can add more:
int cxl_cmd_setpartition_set_<X>(struct cxl_cmd *cmd, enum cxl_setpartition_X x);
...style helpers.
Note, I was thinking CXL_SETPART_NONE is there to catch API users that forget to set a mode, but I also don't mind skipping that and just defaulting cxl_cmd_new_setpartition() to CXL_SETPART_NEXTBOOT, up to you.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/kay/libabc.git/tree/README#n99
Re: [ndctl PATCH v3 6/6] cxl: add command set-partition-info
In reply to [email protected]Quoted 5 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want to change the partition layout of a memory device using the CXL command line tool.
How about:
CXL devices may support both volatile and persistent memory capacity. The amount of device capacity set aside for each type is typically established at the factory, but some devices also allow for dynamic re-partitioning, add a command for this purpose.
Quoted 7 lines
Add a new CXL command,
'cxl set-partition-info', that operates on a CXL memdev, or a set of memdevs, and allows the user to change the partition layout of the device(s).Synopsis:
Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]
It's unfortunate that the specification kept the word "info" in the set-partition command name, let's leave it out of this name and just call this 'cxl set-partition'.
Quoted 4 lines
-v, --verbose turn on debug
-s, --volatile_size <n>
next volatile partition size in bytesSome users will come to this tool with the thought, "I want volatile capacity X", others "I want pmem capacity Y". All but the most advanced users will not understand how the volatile setting affects the pmem and vice versa, nor will they understand that capacity might be fixed and other capacity is dynamic. So how about a set of options like:
-t, --type=<volatile,pmem>
-s,--size=<size>
...where by default -t is 'pmem' and -s is '0' for 100% of the dynamic capacity set to PMEM.
The tool can then help the user get what they want relative to whatever frame of reference led them to read the set-partition man page. The tool can figure out the details behind the scenes, or warn them if they want something impossible like setting PMEM capacity to 1GB on a device where 2GB of PMEM is statically allocated.
This also helps with future proofing in case there are other types that come along.
Quoted 45 lines
The included MAN page explains how to find the partitioning capabilities and restrictions of a CXL memory device.
Signed-off-by Alison Schofield <[email protected]>--- Documentation/cxl/cxl-set-partition-info.txt | 53 ++++++++++ Documentation/cxl/meson.build | 1 + cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/memdev.c | 101 +++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 Documentation/cxl/cxl-set-partition-info.txtDocumentation/cxl/cxl-set-partition-info.txt new file +25
-0@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-set-partition-info(1) +========================= + +NAME +---- +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev + +SYNOPSIS +-------- +[verse] +'cxl set-partition-info <mem> [ [<mem1>..<memN>] [<options>]' + +DESCRIPTION +----------- +Partition the device into volatile and persistent capacity. The change +in partitioning will become the “next” configuration, to become active +on the next device reset. + +Use "cxl list -m <memdev> -I" to examine the partitioning capabilities +of a device. A partition_alignment_bytes value of zero means there are +no partitionable bytes available and therefore the partitions cannot be +changed. +
Documentation/cxl/cxl-set-partition-info.txt line 35
Quoted 10 lines
Documentation/cxl/cxl-set-partition-info.txt new file +10
-0+Using this command to change the size of the persistent capacity shall +result in the loss of data stored. + +OPTIONS +------- +<memory device(s)>:: +include::memdev-option.txt[] + +-s:: +--size=::
This is "--volatile_size" in the current patch, but that's moot with feedback to move to a --type + --size scheme.
Documentation/cxl/cxl-set-partition-info.txt line 39
Quoted 4 lines
Documentation/cxl/cxl-set-partition-info.txt new file +4
-0+ Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment_bytes. + Use 'cxl list -m <memdev> -I' to find partition_alignment_bytes.
This a static 256M, that can just be documented here.
Documentation/cxl/cxl-set-partition-info.txt line 42
Quoted 3 lines
Documentation/cxl/cxl-set-partition-info.txt new file +3
-0+ + Size must be less than or equal to the device's partitionable bytes. + Calculate partitionable bytes by subracting the volatile_only_bytes,
s/subracting/subtracting/
...but rather than teaching the user to input valid values, tell them the validation and translation the tool will do on their behalf with the input based on type and the details they don't need to worry about.
Alison Schofield
maintainerRe: [ndctl PATCH v3 6/6] cxl: add command set-partition-info
Quoted 7 lines · Dan Williams
Quoted 5 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want to change the partition layout of a memory device using the CXL command line tool.
Quoted 6 lines
How about:
CXL devices may support both volatile and persistent memory capacity. The amount of device capacity set aside for each type is typically established at the factory, but some devices also allow for dynamic re-partitioning, add a command for this purpose.
Thanks!
Quoted 6 lines
Quoted 6 lines
Add a new CXL command,
'cxl set-partition-info', that operates on a CXL memdev, or a set of memdevs, and allows the user to change the partition layout of the device(s).
Quoted 7 lines
Quoted 2 lines
Synopsis:
Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]It's unfortunate that the specification kept the word "info" in the set-partition command name, let's leave it out of this name and just call this 'cxl set-partition'.
Will do.
Quoted 10 lines
Quoted 4 lines
-v, --verbose turn on debug -s, --volatile_size <n> next volatile partition size in bytesSome users will come to this tool with the thought, "I want volatile capacity X", others "I want pmem capacity Y". All but the most advanced users will not understand how the volatile setting affects the pmem and vice versa, nor will they understand that capacity might be fixed and other capacity is dynamic.
I went very by the spec here, with those advance users in mind. I do think the user with limited knowledge may get frustrated by the rules. ie. like finding that their total capacity is not all partitionable capacity. I looked at ipmctl goal setting, where they do percentages, and didn't pursue - stuck with the spec.
I like this below. If user wants 100% of any type, no math needed. But, anything else the user will have to specify a byte value.
Quoted 8 lines
So how about a set of options like:
(quoted diff) +0
-2-t, --type=<volatile,pmem> -s,--size=<size>...where by default -t is 'pmem' and -s is '0' for 100% of the dynamic capacity set to PMEM.
I don't get the language "and -s is '0' for 100%", specifically, the "-s is 0".
If -s is ommitted the default behavior will be to set 100% of the partitionable capacity to type.
If both type and size are ommitted, 100% of partitionable capacity is set to PMEM.
Humor me...are these right?
set-partition mem0
100% to pmem
set-partition mem0 -tpmem
100% to pmem
set-partition mem0 -tvolatile -s0
100% to pmem ^^ That's what I think a -s0 does?!?
set-partition mem0 -tvolatile
100% to volatile
set-partition mem0 -tvolatile -s256MB
256MB to volatile
Remainder to pmem
set-partition mem0 -s256MB
256MB to pmem
Remainder to volatile
Thanks!
Quoted 9 lines
The tool can then help the user get what they want relative to whatever frame of reference led them to read the set-partition man page. The tool can figure out the details behind the scenes, or warn them if they want something impossible like setting PMEM capacity to 1GB on a device where 2GB of PMEM is statically allocated.
This also helps with future proofing in case there are other types that come along.
Got it.
Quoted 4 lines
Quoted 4 lines
The included MAN page explains how to find the partitioning capabilities and restrictions of a CXL memory device.
snip
Quoted 9 lines
Documentation/cxl/cxl-set-partition-info.txt line 35
Quoted 6 lines
+-------
+<memory device(s)>::Documentation/cxl/cxl-set-partition-info.txt new file +4
-0+include::memdev-option.txt[] + +-s:: +--size=::This is "--volatile_size" in the current patch, but that's moot with feedback to move to a --type + --size scheme.
Got it.
Quoted 8 lines
Documentation/cxl/cxl-set-partition-info.txt line 39
Quoted 5 lines
Documentation/cxl/cxl-set-partition-info.txt new file +4
-0+ Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment_bytes. + Use 'cxl list -m <memdev> -I' to find partition_alignment_bytes.This a static 256M, that can just be documented here.
My read of the spec says partition alignment is "Expressed in multiples of 256MB", not static. Where is it defined as static?
Quoted 10 lines
Documentation/cxl/cxl-set-partition-info.txt line 42
Quoted 3 lines
Documentation/cxl/cxl-set-partition-info.txt new file +3
-0+ + Size must be less than or equal to the device's partitionable bytes. + Calculate partitionable bytes by subracting the volatile_only_bytes,s/subracting/subtracting/
...but rather than teaching the user to input valid values, tell them the validation and translation the tool will do on their behalf with the input based on type and the details they don't need to worry about.
Got it.
Thanks Dan.
Re: [ndctl PATCH v3 6/6] cxl: add command set-partition-info
Quoted 57 lines · Alison Schofield
Quoted 7 lines · Dan Williams
Quoted 5 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want to change the partition layout of a memory device using the CXL command line tool.
Quoted 6 lines
How about:
CXL devices may support both volatile and persistent memory capacity. The amount of device capacity set aside for each type is typically established at the factory, but some devices also allow for dynamic re-partitioning, add a command for this purpose.
Thanks!
Quoted 6 lines
Quoted 6 lines
Add a new CXL command,
'cxl set-partition-info', that operates on a CXL memdev, or a set of memdevs, and allows the user to change the partition layout of the device(s).Quoted 7 lines
Quoted 2 lines
Synopsis:
Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]It's unfortunate that the specification kept the word "info" in the set-partition command name, let's leave it out of this name and just call this 'cxl set-partition'.
Will do.
Quoted 10 lines
Quoted 4 lines
-v, --verbose turn on debug -s, --volatile_size <n> next volatile partition size in bytesSome users will come to this tool with the thought, "I want volatile capacity X", others "I want pmem capacity Y". All but the most advanced users will not understand how the volatile setting affects the pmem and vice versa, nor will they understand that capacity might be fixed and other capacity is dynamic.
I went very by the spec here, with those advance users in mind. I do think the user with limited knowledge may get frustrated by the rules. ie. like finding that their total capacity is not all partitionable capacity. I looked at ipmctl goal setting, where they do percentages, and didn't pursue - stuck with the spec.
I like this below. If user wants 100% of any type, no math needed. But, anything else the user will have to specify a byte value.
Quoted 5 lines
So how about a set of options like:
(quoted diff) +0
-2-t, --type=<volatile,pmem> -s,--size=<size>
Quoted 8 lines
Quoted 3 lines
...where by default -t is 'pmem' and -s is '0' for 100% of the dynamic capacity set to PMEM.
I don't get the language "and -s is '0' for 100%", specifically, the "-s is 0".
If -s is ommitted the default behavior will be to set 100% of the partitionable capacity to type.
Right, sorry, yes I should have been clear that "-s 0" on the command line means zero-out that capacity, but no "-s" is a default value that means 100% of the given type.
I forgot that NULL can be used to detect string options not specified.
Quoted 8 lines
If both type and size are ommitted, 100% of partitionable capacity is set to PMEM.
Humor me...are these right?
set-partition mem0
100% to pmem
yup.
Quoted 3 lines
set-partition mem0 -tpmem
100% to pmem
I thought you need a space after short options, but apparently not.
Quoted 4 lines
set-partition mem0 -tvolatile -s0
100% to pmem ^^ That's what I think a -s0 does?!?
Agree, looks good.
Quoted 2 lines
set-partition mem0 -tvolatile
100% to volatile
yup.
Quoted 8 lines
set-partition mem0 -tvolatile -s256MB
256MB to volatile
Remainder to pmemset-partition mem0 -s256MB
256MB to pmem
Remainder to volatile
Yup, thanks for going through the examples to clarify.
Alison Schofield
maintainerRe: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to Dan WilliamsHi Dan,
Thanks for the review. I'm still working thru this, but a clarifying question below...
Quoted 18 lines · Dan Williams
Quoted 17 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a
SET_PARTITION_INFOmailbox as defined in the CXL 2.0 specification.Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)
snip
Quoted 20 lines
I don't understand what this is for?
Let's back up. In order to future proof against spec changes, and endianness, struct packing and all other weird things that make struct ABIs hard to maintain compatibility the ndctl project adopts the libabc template of just not letting library consumers see any raw data structures or bit fields by default [1]. For a situation like this since the command only has one flag that affects the mode of operation I would just go ahead and define an enum for that explicitly.
enum
cxl_setpartition_mode{
CXL_SETPART_NONE,
CXL_SETPART_NEXTBOOT,
CXL_SETPART_IMMEDIATE,
};Then the main function prototype becomes:
Quoted 8 lines
int
cxl_cmd_new_setpartition(struct cxl_memdev *memdev, unsigned long long volatile_capacity);...with a new:
int
cxl_cmd_setpartition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode);
I don't understand setting of the mode separately. Can it be:
int cxl_cmd_new_setpartition(struct cxl_memdev *memdev,
unsigned long long volatile_capacity, enum cxl_setpartition_mode mode);
Quoted 15 lines
...and it becomes impossible for users to pass unsupported flag values. If the specification later on adds more flags then we can add more:
int cxl_cmd_setpartition_set_<X>(struct
cxl_cmd*cmd, enumcxl_setpartition_Xx);...style helpers.
Note, I was thinking
CXL_SETPART_NONEis there to catch API users that forget to set a mode, but I also don't mind skipping that and just defaultingcxl_cmd_new_setpartition()toCXL_SETPART_NEXTBOOT, up to you.[1]: https://git.kernel.org/pub/scm/linux/kernel/git/kay/libabc.git/tree/README#n99
Alison Schofield
maintainerRe: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to Dan WilliamsDan, One follow up below...
Quoted 26 lines · Dan Williams
Quoted 25 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a
SET_PARTITION_INFOmailbox as defined in the CXL 2.0 specification.Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)cxl/lib/libcxl.c +0
-0@@ -1230,6 +1230,21 @@ cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd)cmd_partition_get_capacity_field (cmd, next_persistent_cap); }
Quoted 13 lines
cxl/lib/libcxl.c cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) · line 1242
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags) +{ +struct cxl_cmd_set_partition_info *set_partition; +struct cxl_cmd *cmd; + + cmd =cxl_cmd_new_generic (memdev, +CXL_MEM_COMMAND_ID_SET_PARTITION_INFO ); + + set_partition = (struct cxl_cmd_set_partition_info *)cmd->send_cmd->in.payload;->in.payload is a 'void *', no casting required.
send_cmd->in.payload is a __u64 so this cast is needed.
Of course, I wondered what Dan was thinking ;) and I see that struct cxl_cmd's input_payload is indeed a 'void *'.
I believe this is the correct payload here, umm.. because it works ;)
But - let me know if you suspect something is off here.
Thanks!
snip
Quoted 1 line
Re: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to Alison SchofieldQuoted 54 lines · Alison Schofield
Hi Dan,
Thanks for the review. I'm still working thru this, but a clarifying question below...Quoted 18 lines · Dan Williams
Quoted 17 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a
SET_PARTITION_INFOmailbox as defined in the CXL 2.0 specification.Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)snip
Quoted 20 lines
I don't understand what this is for?
Let's back up. In order to future proof against spec changes, and endianness, struct packing and all other weird things that make struct ABIs hard to maintain compatibility the ndctl project adopts the libabc template of just not letting library consumers see any raw data structures or bit fields by default [1]. For a situation like this since the command only has one flag that affects the mode of operation I would just go ahead and define an enum for that explicitly.
enum
cxl_setpartition_mode{
CXL_SETPART_NONE,
CXL_SETPART_NEXTBOOT,
CXL_SETPART_IMMEDIATE,
};Then the main function prototype becomes:
Quoted 8 lines
int
cxl_cmd_new_setpartition(struct cxl_memdev *memdev, unsigned long long volatile_capacity);...with a new:
int
cxl_cmd_setpartition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode);
Quoted 5 lines
I don't understand setting of the mode separately. Can it be:
int cxl_cmd_new_setpartition(struct
cxl_memdev*memdev,
unsigned long longvolatile_capacity, enumcxl_setpartition_modemode);
It could be, but what happens when the specification defines a new flag for this command? Then we would have cxl_cmd_new_setpartition() and cxl_cmd_new_setpartition2() to add the new parameters. A helper function after establishing the cxl_cmd context lets you have flexibility to extend the base command by as many new flags and modes that come along... hopefully none, but you never know.
Alison Schofield
maintainerRe: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
Quoted 36 lines
Quoted 30 lines
snip
Quoted 20 lines
I don't understand what this is for?
Let's back up. In order to future proof against spec changes, and endianness, struct packing and all other weird things that make struct ABIs hard to maintain compatibility the ndctl project adopts the libabc template of just not letting library consumers see any raw data structures or bit fields by default [1]. For a situation like this since the command only has one flag that affects the mode of operation I would just go ahead and define an enum for that explicitly.
enum
cxl_setpartition_mode{
CXL_SETPART_NONE,
CXL_SETPART_NEXTBOOT,
CXL_SETPART_IMMEDIATE,
};Then the main function prototype becomes:
Quoted 8 lines
int
cxl_cmd_new_setpartition(struct cxl_memdev *memdev, unsigned long long volatile_capacity);...with a new:
int
cxl_cmd_setpartition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode);Quoted 5 lines
I don't understand setting of the mode separately. Can it be:
int cxl_cmd_new_setpartition(struct
cxl_memdev*memdev,
unsigned long longvolatile_capacity, enumcxl_setpartition_modemode);
Quoted 6 lines
It could be, but what happens when the specification defines a new flag for this command? Then we would have
cxl_cmd_new_setpartition()andcxl_cmd_new_setpartition2()to add the new parameters. A helper function after establishing thecxl_cmdcontext lets you have flexibility to extend the base command by as many new flags and modes that come along... hopefully none, but you never know.
Got it. Doing the 'new' followed by 'mode' set up you suggested. (Sorry, I didn't update this thread after our offline chat.)
Re: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command
In reply to Alison SchofieldQuoted 44 lines · Alison Schofield
Dan, One follow up below...
Quoted 26 lines · Dan Williams
Quoted 25 lines · On Tue, Jan 18, 2022 at 12:20 PM <[email protected]> wrote:
From: Alison Schofield <[email protected]>
Users may want the ability to change the partition layout of a CXL memory device.
Add interfaces to libcxl to allocate and send a
SET_PARTITION_INFOmailbox as defined in the CXL 2.0 specification.Signed-off-by Alison Schofield <[email protected]>--- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+)cxl/lib/libcxl.c +0
-0@@ -1230,6 +1230,21 @@ cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd)cmd_partition_get_capacity_field (cmd, next_persistent_cap); }Quoted 13 lines
cxl/lib/libcxl.c cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) · line 1242
Quoted 10 lines
cxl/lib/libcxl.c +10
-0+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, +unsigned long long volatile_capacity,int flags) +{ +struct cxl_cmd_set_partition_info *set_partition; +struct cxl_cmd *cmd; + + cmd =cxl_cmd_new_generic (memdev, +CXL_MEM_COMMAND_ID_SET_PARTITION_INFO ); + + set_partition = (struct cxl_cmd_set_partition_info *)cmd->send_cmd->in.payload;->in.payload is a 'void *', no casting required.
Quoted 8 lines
send_cmd->in.payloadis a__u64so this cast is needed.Of course, I wondered what Dan was thinking ;) and I see that struct cxl_cmd's
input_payloadis indeed a 'void *'.I believe this is the correct payload here, umm.. because it works ;)
But - let me know if you suspect something is off here.
You're right...
...however :), I think this casting is what the core cxl_cmd_alloc_send() helper is doing for everyone when it does:
cmd->send_cmd->in.payload = (u64)cmd->input_payload;
...so cxl_cmd_new_set_partition_info() can safely switch to the shorter cmd->input_payload and drop its own redundant local casting.