Skip to content

Commit 814a15f

Browse files
weiny2djbw
authored andcommitted
cxl/uapi: Tag commands from cxl_query_cmd()
It was pointed out that commands not supported by the device or excluded by the kernel were being returned in cxl_query_cmd().[1] While libcxl correctly handles failing commands, it is more efficient to not issue an invalid command in the first place. This can't be done without additional information being returned from cxl_query_cmd(). In addition, information about the availability of commands can be useful for debugging. Add flags to struct cxl_command_info which reflect if a command is enabled and/or exclusive to the kernel. [1] https://lore.kernel.org/all/[email protected]/ Suggested-by: Dan Williams <[email protected]> Signed-off-by: Ira Weiny <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 11ef026 commit 814a15f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

drivers/cxl/core/mbox.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,14 @@ int cxl_query_cmd(struct cxl_memdev *cxlmd,
451451
* structures.
452452
*/
453453
cxl_for_each_cmd(cmd) {
454-
const struct cxl_command_info *info = &cmd->info;
454+
struct cxl_command_info info = cmd->info;
455455

456-
if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
456+
if (test_bit(info.id, cxlmd->cxlds->enabled_cmds))
457+
info.flags |= CXL_MEM_COMMAND_FLAG_ENABLED;
458+
if (test_bit(info.id, cxlmd->cxlds->exclusive_cmds))
459+
info.flags |= CXL_MEM_COMMAND_FLAG_EXCLUSIVE;
460+
461+
if (copy_to_user(&q->commands[j++], &info, sizeof(info)))
457462
return -EFAULT;
458463

459464
if (j == n_commands)

include/uapi/linux/cxl_mem.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ static const struct {
7272
* struct cxl_command_info - Command information returned from a query.
7373
* @id: ID number for the command.
7474
* @flags: Flags that specify command behavior.
75+
*
76+
* CXL_MEM_COMMAND_FLAG_USER_ENABLED
77+
*
78+
* The given command id is supported by the driver and is supported by
79+
* a related opcode on the device.
80+
*
81+
* CXL_MEM_COMMAND_FLAG_EXCLUSIVE
82+
*
83+
* Requests with the given command id will terminate with EBUSY as the
84+
* kernel actively owns management of the given resource. For example,
85+
* the label-storage-area can not be written while the kernel is
86+
* actively managing that space.
87+
*
7588
* @size_in: Expected input size, or ~0 if variable length.
7689
* @size_out: Expected output size, or ~0 if variable length.
7790
*
@@ -81,7 +94,7 @@ static const struct {
8194
* bytes of output.
8295
*
8396
* - @id = 10
84-
* - @flags = 0
97+
* - @flags = CXL_MEM_COMMAND_FLAG_ENABLED
8598
* - @size_in = ~0
8699
* - @size_out = 0
87100
*
@@ -91,7 +104,9 @@ struct cxl_command_info {
91104
__u32 id;
92105

93106
__u32 flags;
94-
#define CXL_MEM_COMMAND_FLAG_MASK GENMASK(0, 0)
107+
#define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0)
108+
#define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0)
109+
#define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1)
95110

96111
__u32 size_in;
97112
__u32 size_out;

0 commit comments

Comments
 (0)