Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/nvme/api-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct nvme_identify_args {
* @ot: Offset Type; if set @lpo specifies the index into the list
* of data structures, otherwise @lpo specifies the byte offset
* into the log page.
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_get_log_args {
__u64 lpo;
Expand All @@ -91,6 +92,7 @@ struct nvme_get_log_args {
__u8 uuidx;
bool rae;
bool ot;
bool ish;
};

/**
Expand Down Expand Up @@ -171,6 +173,7 @@ struct nvme_get_features_args {
* @lbaf: Logical block address format least significant 4 bits
* @rsvd1: Reserved
* @lbafu: Logical block address format most significant 2 bits
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_format_nvm_args {
__u32 *result;
Expand All @@ -185,6 +188,7 @@ struct nvme_format_nvm_args {
__u8 lbaf;
__u8 rsvd1[7];
__u8 lbafu;
bool ish;
};

/**
Expand All @@ -200,6 +204,7 @@ struct nvme_format_nvm_args {
* @rsvd1: Reserved
* @rsvd2: Reserved
* @data: Host Software Specified Fields
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_ns_mgmt_args {
__u32 *result;
Expand All @@ -213,6 +218,7 @@ struct nvme_ns_mgmt_args {
__u8 rsvd1[3];
void *rsvd2;
struct nvme_ns_mgmt_host_sw_specified *data;
bool ish;
};

/**
Expand All @@ -224,6 +230,7 @@ struct nvme_ns_mgmt_args {
* @timeout: Timeout in ms
* @nsid: Namespace ID to execute attach selection
* @sel: Attachment selection, see &enum nvme_ns_attach_sel
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_ns_attach_args {
__u32 *result;
Expand All @@ -233,6 +240,7 @@ struct nvme_ns_attach_args {
__u32 timeout;
__u32 nsid;
enum nvme_ns_attach_sel sel;
bool ish;
};

/**
Expand All @@ -244,6 +252,7 @@ struct nvme_ns_attach_args {
* @offset: Offset in the firmware data
* @data: Userspace address of the firmware data
* @data_len: Length of data in this command in bytes
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_fw_download_args {
__u32 *result;
Expand All @@ -253,6 +262,7 @@ struct nvme_fw_download_args {
__u32 timeout;
__u32 offset;
__u32 data_len;
bool ish;
};

/**
Expand All @@ -264,6 +274,7 @@ struct nvme_fw_download_args {
* @result: The command completion result from CQE dword0
* @slot: Firmware slot to commit the downloaded image
* @bpid: Set to true to select the boot partition id
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_fw_commit_args {
__u32 *result;
Expand All @@ -273,6 +284,7 @@ struct nvme_fw_commit_args {
enum nvme_fw_commit_ca action;
__u8 slot;
bool bpid;
bool ish;
};

/**
Expand All @@ -289,6 +301,7 @@ struct nvme_fw_commit_args {
* @spsp0: Security Protocol Specific field
* @spsp1: Security Protocol Specific field
* @secp: Security Protocol
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_security_send_args {
__u32 *result;
Expand All @@ -303,6 +316,7 @@ struct nvme_security_send_args {
__u8 spsp0;
__u8 spsp1;
__u8 secp;
bool ish;
};

/**
Expand All @@ -319,6 +333,7 @@ struct nvme_security_send_args {
* @spsp0: Security Protocol Specific field
* @spsp1: Security Protocol Specific field
* @secp: Security Protocol
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_security_receive_args {
__u32 *result;
Expand All @@ -333,6 +348,7 @@ struct nvme_security_receive_args {
__u8 spsp0;
__u8 spsp1;
__u8 secp;
bool ish;
};

/**
Expand Down Expand Up @@ -513,6 +529,7 @@ struct nvme_get_property_args {
* @oipbp: Set to overwrite invert pattern between passes
* @nodas: Set to not deallocate blocks after sanitizing
* @emvs: Set to enter media verification state
* @ish: Ignore Shutdown (for NVMe-MI command)
*/
struct nvme_sanitize_nvm_args {
__u32 *result;
Expand All @@ -526,6 +543,7 @@ struct nvme_sanitize_nvm_args {
bool oipbp;
bool nodas;
bool emvs;
bool ish;
};

/**
Expand Down
37 changes: 27 additions & 10 deletions src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ int nvme_identify(struct nvme_identify_args *args)

int nvme_get_log(struct nvme_get_log_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_get_log_args, ot, __u64);
const size_t size_v2 = sizeof_args(struct nvme_get_log_args, ish, __u64);
__u32 numd = (args->len >> 2) - 1;
__u16 numdu = numd >> 16, numdl = numd & 0xffff;

Expand Down Expand Up @@ -313,7 +315,7 @@ int nvme_get_log(struct nvme_get_log_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(struct nvme_get_log_args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -373,6 +375,8 @@ static void nvme_uring_cmd_exit(struct io_uring *ring)

static int nvme_uring_cmd_admin_passthru_async(struct io_uring *ring, struct nvme_get_log_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_get_log_args, ot, __u64);
const size_t size_v2 = sizeof_args(struct nvme_get_log_args, ish, __u64);
struct io_uring_sqe *sqe;
struct nvme_uring_cmd *cmd;
int ret;
Expand All @@ -392,7 +396,7 @@ static int nvme_uring_cmd_admin_passthru_async(struct io_uring *ring, struct nvm
NVME_SET(!!args->ot, LOG_CDW14_OT) |
NVME_SET(args->csi, LOG_CDW14_CSI);

if (args->args_size < sizeof(struct nvme_get_log_args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1501,9 +1505,10 @@ int nvme_format_nvm(struct nvme_format_nvm_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_format_nvm_args, lbaf, __u64);
const size_t size_v2 = sizeof_args(struct nvme_format_nvm_args, lbafu, __u64);
const size_t size_v3 = sizeof_args(struct nvme_format_nvm_args, ish, __u64);
__u32 cdw10;

if (args->args_size < size_v1 || args->args_size > size_v2) {
if (args->args_size < size_v1 || args->args_size > size_v3) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1533,10 +1538,11 @@ int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_ns_mgmt_args, csi, __u64);
const size_t size_v2 = sizeof_args(struct nvme_ns_mgmt_args, data, __u64);
const size_t size_v3 = sizeof_args(struct nvme_ns_mgmt_args, ish, __u64);
__u32 cdw10 = NVME_SET(args->sel, NAMESPACE_MGMT_CDW10_SEL);
__u32 cdw11 = NVME_SET(args->csi, NAMESPACE_MGMT_CDW11_CSI);

if (args->args_size < size_v1 || args->args_size > size_v2) {
if (args->args_size < size_v1 || args->args_size > size_v3) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1566,6 +1572,8 @@ int nvme_ns_mgmt(struct nvme_ns_mgmt_args *args)

int nvme_ns_attach(struct nvme_ns_attach_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_ns_attach_args, sel, __u64);
const size_t size_v2 = sizeof_args(struct nvme_ns_attach_args, ish, __u64);
__u32 cdw10 = NVME_SET(args->sel, NAMESPACE_ATTACH_CDW10_SEL);

struct nvme_passthru_cmd cmd = {
Expand All @@ -1577,7 +1585,7 @@ int nvme_ns_attach(struct nvme_ns_attach_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand All @@ -1586,6 +1594,8 @@ int nvme_ns_attach(struct nvme_ns_attach_args *args)

int nvme_fw_download(struct nvme_fw_download_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_fw_download_args, data_len, __u64);
const size_t size_v2 = sizeof_args(struct nvme_fw_download_args, ish, __u64);
__u32 cdw10 = (args->data_len >> 2) - 1;
__u32 cdw11 = args->offset >> 2;

Expand All @@ -1598,7 +1608,7 @@ int nvme_fw_download(struct nvme_fw_download_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand All @@ -1607,6 +1617,8 @@ int nvme_fw_download(struct nvme_fw_download_args *args)

int nvme_fw_commit(struct nvme_fw_commit_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_fw_commit_args, bpid, __u64);
const size_t size_v2 = sizeof_args(struct nvme_fw_commit_args, ish, __u64);
__u32 cdw10 = NVME_SET(args->slot, FW_COMMIT_CDW10_FS) |
NVME_SET(args->action, FW_COMMIT_CDW10_CA) |
NVME_SET(args->bpid, FW_COMMIT_CDW10_BPID);
Expand All @@ -1617,7 +1629,7 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand All @@ -1626,6 +1638,8 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args)

int nvme_security_send(struct nvme_security_send_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_security_send_args, secp, __u64);
const size_t size_v2 = sizeof_args(struct nvme_security_send_args, ish, __u64);
__u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) |
NVME_SET(args->spsp0, SECURITY_SPSP0) |
NVME_SET(args->spsp1, SECURITY_SPSP1) |
Expand All @@ -1642,7 +1656,7 @@ int nvme_security_send(struct nvme_security_send_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand All @@ -1651,6 +1665,8 @@ int nvme_security_send(struct nvme_security_send_args *args)

int nvme_security_receive(struct nvme_security_receive_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_security_receive_args, secp, __u64);
const size_t size_v2 = sizeof_args(struct nvme_security_receive_args, ish, __u64);
__u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) |
NVME_SET(args->spsp0, SECURITY_SPSP0) |
NVME_SET(args->spsp1, SECURITY_SPSP1) |
Expand All @@ -1667,7 +1683,7 @@ int nvme_security_receive(struct nvme_security_receive_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1858,9 +1874,10 @@ int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args)
{
const size_t size_v1 = sizeof_args(struct nvme_sanitize_nvm_args, nodas, __u64);
const size_t size_v2 = sizeof_args(struct nvme_sanitize_nvm_args, emvs, __u64);
const size_t size_v3 = sizeof_args(struct nvme_sanitize_nvm_args, ish, __u64);
__u32 cdw10, cdw11;

if (args->args_size < size_v1 || args->args_size > size_v2) {
if (args->args_size < size_v1 || args->args_size > size_v3) {
errno = EINVAL;
return -1;
}
Expand Down
Loading
Loading