Skip to contentSkip to conversation

libndctl, nfit: Fix in/out sizes for error injection commands

PATCH Superseded Vishal Verma 2 participants 4 messages Nov 7, 2017 – Nov 8, 2017 libnvdimm: non-volatile memory device

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/1 libndctl, nfit: Fix in/out sizes for error injection commands

The input/output size bounds being set in the various nd_bus_cmd_new_* helpers for error injection commands were larger than they needed to be, and platforms could reject these. Fix the bounds to be exactly as the spec describes.

---
 ndctl/lib/nfit.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
ndctl/lib/nfit.c +8 -8
index fb6af32..6346fd9 100644
@@ -164,9 +164,9 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus)
 	cmd->status = 1;
 	pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
 	pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-	pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u32);
-	pkg->nd_size_out = cmd_length;
-	pkg->nd_fw_size = cmd_length;
+	pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);
+	pkg->nd_size_out = sizeof(u32);
+	pkg->nd_fw_size = sizeof(u32);
 	err_inj = (struct nd_cmd_ars_err_inj *)&pkg->nd_payload[0];
 	cmd->firmware_status = &err_inj->status;
 
@@ -194,8 +194,8 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj_clr(struct ndctl_bus *bus)
 	pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
 	pkg->nd_command = NFIT_CMD_ARS_INJECT_CLEAR;
 	pkg->nd_size_in = 2 * sizeof(u64);
-	pkg->nd_size_out = cmd_length;
-	pkg->nd_fw_size = cmd_length;
+	pkg->nd_size_out = sizeof(u32);
+	pkg->nd_fw_size = sizeof(u32);
 	err_inj_clr = (struct nd_cmd_ars_err_inj_clr *)&pkg->nd_payload[0];
 	cmd->firmware_status = &err_inj_clr->status;
 
@@ -224,9 +224,9 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj_stat(struct ndctl_bus *bus,
 	cmd->status = 1;
 	pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
 	pkg->nd_command = NFIT_CMD_ARS_INJECT_GET;
-	pkg->nd_size_in = cmd_length;
-	pkg->nd_size_out = cmd_length + buf_size;
-	pkg->nd_fw_size = cmd_length + buf_size;
+	pkg->nd_size_in = 0;
+	pkg->nd_size_out = (2 * sizeof(u32)) + buf_size;
+	pkg->nd_fw_size = (2 * sizeof(u32)) + buf_size;
 	err_inj_stat = (struct nd_cmd_ars_err_inj_stat *)&pkg->nd_payload[0];
 	cmd->firmware_status = &err_inj_stat->status;
 
Signature · 6 lines
2.9.5

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 17 lines · Vishal Verma

The input/output size bounds being set in the various nd_bus_cmd_new_* helpers for error injection commands were larger than they needed to be, and platforms could reject these. Fix the bounds to be exactly as the spec describes.

---
 ndctl/lib/nfit.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
ndctl/lib/nfit.c +0 -0
index fb6af32..6346fd9 100644

ndctl/lib/nfit.c struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus) · line 167

Quoted 7 lines
ndctl/lib/nfit.c +1 -3
@@ -164,9 +164,9 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus)
        cmd->status = 1;
        pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
        pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u32);
-       pkg->nd_size_out = cmd_length;
-       pkg->nd_fw_size = cmd_length;
+       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);

How about:

    pkg->nd_size_in = offset_of(struct nd_cmd_ars_err_inj, status);

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 28 lines · Dan Williams
Quoted 17 lines · Vishal Verma

The input/output size bounds being set in the various nd_bus_cmd_new_* helpers for error injection commands were larger than they needed to be, and platforms could reject these. Fix the bounds to be exactly as the spec describes.

---
 ndctl/lib/nfit.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
ndctl/lib/nfit.c +0 -0
index fb6af32..6346fd9 100644

ndctl/lib/nfit.c struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus) · line 167

Quoted 7 lines
ndctl/lib/nfit.c +1 -3
@@ -164,9 +164,9 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus)
        cmd->status = 1;
        pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
        pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u32);
-       pkg->nd_size_out = cmd_length;
-       pkg->nd_fw_size = cmd_length;
+       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);

How about:

Quoted 1 line
    pkg->nd_size_in = offset_of(struct nd_cmd_ars_err_inj, status);

Actually, something like this to make the pkg-> settings and inter-relations clearer:

ndctl/lib/nfit.c +0 -0
index 6346fd90f0e2..21c567ad5d4a 100644
@@ -164,9 +164,9 @@ struct ndctl_cmd *ndctl_bus_cmd_new_err_inj(struct

ndctl_bus *bus)

        cmd->status = 1;
        pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
        pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);
-       pkg->nd_size_out = sizeof(u32);
-       pkg->nd_fw_size = sizeof(u32);
+       pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj, status);
+       pkg->nd_size_out = sizeof(struct nd_cmd_ars_err_inj) - pkg->nd_size_in;
+       pkg->nd_fw_size = pkg->nd_size_out;
        err_inj = (struct nd_cmd_ars_err_inj *)&pkg->nd_payload[0];
        cmd->firmware_status = &err_inj->status;

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#3 lore raw
Quoted 57 lines · Dan Williams
Quoted 33 lines · Dan Williams
Quoted 20 lines · Vishal Verma

The input/output size bounds being set in the various nd_bus_cmd_new_*
helpers for error injection commands were larger than they needed to be,
and platforms could reject these. Fix the bounds to be exactly as the
spec describes.

---
 ndctl/lib/nfit.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
ndctl/lib/nfit.c +0 -0
index fb6af32..6346fd9 100644

ndctl/lib/nfit.c struct ndctl_cmd · line 168

Quoted 8 lines
ndctl/lib/nfit.c +1 -3
@@ -164,9 +164,9 @@ struct ndctl_cmd
 *ndctl_bus_cmd_new_err_inj(struct ndctl_bus *bus)
        cmd->status = 1;
        pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
        pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u32);
-       pkg->nd_size_out = cmd_length;
-       pkg->nd_fw_size = cmd_length;
+       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);

How about:

Quoted 1 line
    pkg->nd_size_in = offset_of(struct nd_cmd_ars_err_inj, status);

Actually, something like this to make the pkg-> settings and inter-relations clearer:

ndctl/lib/nfit.c +2 -3
index 6346fd90f0e2..21c567ad5d4a 100644
@@ -164,9 +164,9 @@ struct ndctl_cmd
 *ndctl_bus_cmd_new_err_inj(struct
 ndctl_bus *bus)
        cmd->status = 1;
        pkg = (struct nd_cmd_pkg *)&cmd->cmd_buf[0];
        pkg->nd_command = NFIT_CMD_ARS_INJECT_SET;
-       pkg->nd_size_in = (2 * sizeof(u64)) + sizeof(u8);
-       pkg->nd_size_out = sizeof(u32);
-       pkg->nd_fw_size = sizeof(u32);
+       pkg->nd_size_in = offsetof(struct nd_cmd_ars_err_inj,
 status);
+       pkg->nd_size_out = sizeof(struct nd_cmd_ars_err_inj) - pkg-
Quoted 1 line

nd_size_in;

Quoted 3 lines
+       pkg->nd_fw_size = pkg->nd_size_out;
        err_inj = (struct nd_cmd_ars_err_inj *)&pkg->nd_payload[0];
        cmd->firmware_status = &err_inj->status;

Yep, I like that. I will resend.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm