LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
@ 2019-02-01 20:50 David Kozub
  2019-02-01 20:50 ` [PATCH v4 01/16] block: sed-opal: fix typos and formatting David Kozub
                   ` (18 more replies)
  0 siblings, 19 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

This patch series extends SED OPAL support: it adds IOCTL for setting the shadow
MBR done flag which can be useful for unlocking an OPAL disk on boot and it adds
IOCTL for writing to the shadow MBR. Also included are some minor fixes and
improvements.

This series is based on the original work done by Jonas Rabenstein which was
submitted in March 2018.[1]

There is a fork of sed-opal-temp that can use these new IOCTLs.[2] I tested
these on Samsung 840 EVO and 850 EVO drives, on x86-64 and arm64 systems.

The series applies on v5.0-rc4.

I'm resending as v4 as suggested by Scott Bauer.[3]

Changes from v3 to v4:
* added Reviewed-by from Scott, including for the patch 16/16 (details in
[3])

[1] https://lore.kernel.org/lkml/cover.1521482295.git.jonas.rabenstein@studium.uni-erlangen.de/
[2] https://github.com/ghostav/sed-opal-temp
[3] https://lore.kernel.org/lkml/20190127211449.GP21149@hacktheplanet/

David Kozub (8):
  block: sed-opal: fix typos and formatting
  block: sed-opal: close parameter list in cmd_finalize
  block: sed-opal: unify cmd start
  block: sed-opal: unify error handling of responses
  block: sed-opal: reuse response_get_token to decrease code duplication
  block: sed-opal: pass steps via argument rather than via opal_dev
  block: sed-opal: don't repeat opal_discovery0 in each steps array
  block: sed-opal: rename next to execute_steps

Jonas Rabenstein (8):
  block: sed-opal: use correct macro for method length
  block: sed-opal: unify space check in add_token_*
  block: sed-opal: print failed function address
  block: sed-opal: split generation of bytestring header and content
  block: sed-opal: add ioctl for done-mark of shadow mbr
  block: sed-opal: ioctl for writing to shadow mbr
  block: sed-opal: unify retrieval of table columns
  block: sed-opal: check size of shadow mbr

 block/opal_proto.h            |  18 +
 block/sed-opal.c              | 845 +++++++++++++++++-----------------
 include/linux/sed-opal.h      |   2 +
 include/uapi/linux/sed-opal.h |   9 +
 4 files changed, 451 insertions(+), 423 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 01/16] block: sed-opal: fix typos and formatting
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:42   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 02/16] block: sed-opal: use correct macro for method length David Kozub
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

This should make no change in functionality.
The formatting changes were triggered by checkpatch.pl.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index e0de4dd448b3..c882a193e162 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -11,8 +11,8 @@
  *
  * This program is distributed in the hope it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ":OPAL: " fmt
@@ -157,7 +157,7 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
 
 	/* C_PIN_TABLE object ID's */
 
-        [OPAL_C_PIN_MSID] =
+	[OPAL_C_PIN_MSID] =
 		{ 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x84, 0x02},
 	[OPAL_C_PIN_SID] =
 		{ 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x01},
@@ -623,7 +623,7 @@ static int build_locking_range(u8 *buffer, size_t length, u8 lr)
 static int build_locking_user(u8 *buffer, size_t length, u8 lr)
 {
 	if (length > OPAL_UID_LENGTH) {
-		pr_debug("Can't build locking range user, Length OOB\n");
+		pr_debug("Can't build locking range user. Length OOB\n");
 		return -ERANGE;
 	}
 
@@ -1324,6 +1324,7 @@ static int start_SIDASP_opal_session(struct opal_dev *dev, void *data)
 
 	if (!key) {
 		const struct opal_key *okey = data;
+
 		ret = start_generic_opal_session(dev, OPAL_SID_UID,
 						 OPAL_ADMINSP_UID,
 						 okey->key,
@@ -1341,6 +1342,7 @@ static int start_SIDASP_opal_session(struct opal_dev *dev, void *data)
 static int start_admin1LSP_opal_session(struct opal_dev *dev, void *data)
 {
 	struct opal_key *key = data;
+
 	return start_generic_opal_session(dev, OPAL_ADMIN1_UID,
 					  OPAL_LOCKINGSP_UID,
 					  key->key, key->key_len);
@@ -1714,7 +1716,7 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
 		write_locked = 0;
 		break;
 	case OPAL_LK:
-		/* vars are initalized to locked */
+		/* vars are initialized to locked */
 		break;
 	default:
 		pr_debug("Tried to set an invalid locking state... returning to uland\n");
@@ -1775,7 +1777,7 @@ static int lock_unlock_locking_range_sum(struct opal_dev *dev, void *data)
 		write_locked = 0;
 		break;
 	case OPAL_LK:
-		/* vars are initalized to locked */
+		/* vars are initialized to locked */
 		break;
 	default:
 		pr_debug("Tried to set an invalid locking state.\n");
@@ -2222,7 +2224,7 @@ static int __opal_lock_unlock(struct opal_dev *dev,
 static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 {
 	u8 mbr_done_tf = 1;
-	const struct opal_step mbrdone_step [] = {
+	const struct opal_step mbrdone_step[] = {
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, key },
 		{ set_mbr_done, &mbr_done_tf },
@@ -2273,7 +2275,8 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 	return ret;
 }
 
-static int opal_activate_lsp(struct opal_dev *dev, struct opal_lr_act *opal_lr_act)
+static int opal_activate_lsp(struct opal_dev *dev,
+			     struct opal_lr_act *opal_lr_act)
 {
 	const struct opal_step active_steps[] = {
 		{ opal_discovery0, },
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 02/16] block: sed-opal: use correct macro for method length
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
  2019-02-01 20:50 ` [PATCH v4 01/16] block: sed-opal: fix typos and formatting David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:43   ` Christoph Hellwig
  2019-02-08 22:56   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 03/16] block: sed-opal: unify space check in add_token_* David Kozub
                   ` (16 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Also the values of OPAL_UID_LENGTH and OPAL_METHOD_LENGTH are the same,
it is weird to use OPAL_UID_LENGTH for the definition of the methods.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index c882a193e162..5c123a5b4ab1 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -181,7 +181,7 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
  * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
  * Section: 6.3 Assigned UIDs
  */
-static const u8 opalmethod[][OPAL_UID_LENGTH] = {
+static const u8 opalmethod[][OPAL_METHOD_LENGTH] = {
 	[OPAL_PROPERTIES] =
 		{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01 },
 	[OPAL_STARTSESSION] =
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 03/16] block: sed-opal: unify space check in add_token_*
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
  2019-02-01 20:50 ` [PATCH v4 01/16] block: sed-opal: fix typos and formatting David Kozub
  2019-02-01 20:50 ` [PATCH v4 02/16] block: sed-opal: use correct macro for method length David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:44   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

All add_token_* functions have a common set of conditions that have to
be checked. Use a common function for those checks in order to avoid
different behaviour as well as code duplication.

Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 5c123a5b4ab1..980705681806 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -510,15 +510,29 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
 	return opal_discovery0_end(dev);
 }
 
-static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
+static size_t remaining_size(struct opal_dev *cmd)
+{
+	return IO_BUFFER_LENGTH - cmd->pos;
+}
+
+static bool can_add(int *err, struct opal_dev *cmd, size_t len)
 {
 	if (*err)
-		return;
-	if (cmd->pos >= IO_BUFFER_LENGTH - 1) {
-		pr_debug("Error adding u8: end of buffer.\n");
+		return false;
+
+	if (remaining_size(cmd) < len) {
+		pr_debug("Error adding %zu bytes: end of buffer.\n", len);
 		*err = -ERANGE;
-		return;
+		return false;
 	}
+
+	return true;
+}
+
+static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
+{
+	if (!can_add(err, cmd, 1))
+		return;
 	cmd->cmd[cmd->pos++] = tok;
 }
 
@@ -563,9 +577,8 @@ static void add_token_u64(int *err, struct opal_dev *cmd, u64 number)
 	msb = fls64(number);
 	len = DIV_ROUND_UP(msb, 8);
 
-	if (cmd->pos >= IO_BUFFER_LENGTH - len - 1) {
+	if (!can_add(err, cmd, len + 1)) {
 		pr_debug("Error adding u64: end of buffer.\n");
-		*err = -ERANGE;
 		return;
 	}
 	add_short_atom_header(cmd, false, false, len);
@@ -587,9 +600,8 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd,
 		is_short_atom = false;
 	}
 
-	if (len >= IO_BUFFER_LENGTH - cmd->pos - header_len) {
+	if (!can_add(err, cmd, header_len + len)) {
 		pr_debug("Error adding bytestring: end of buffer.\n");
-		*err = -ERANGE;
 		return;
 	}
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (2 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 03/16] block: sed-opal: unify space check in add_token_* David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:44   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 05/16] block: sed-opal: unify cmd start David Kozub
                   ` (14 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

Every step ends by calling cmd_finalize (via finalize_and_send)
yet every step adds the token OPAL_ENDLIST on its own. Moving
this into cmd_finalize decreases code duplication.

Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 980705681806..35b1747b650f 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -661,6 +661,9 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
 	struct opal_header *hdr;
 	int err = 0;
 
+	/* close parameter list */
+	add_token_u8(&err, cmd, OPAL_ENDLIST);
+
 	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
 	add_token_u8(&err, cmd, OPAL_STARTLIST);
 	add_token_u8(&err, cmd, 0);
@@ -1079,7 +1082,6 @@ static int gen_key(struct opal_dev *dev, void *data)
 	add_token_bytestring(&err, dev, opalmethod[OPAL_GENKEY],
 			     OPAL_UID_LENGTH);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building gen key command\n");
@@ -1142,7 +1144,6 @@ static int get_active_key(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, 10); /* ActiveKey */
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 	if (err) {
 		pr_debug("Error building get active key command\n");
 		return err;
@@ -1188,7 +1189,6 @@ static int generic_lr_enable_disable(struct opal_dev *dev,
 
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 	return err;
 }
 
@@ -1254,8 +1254,6 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
 
 		add_token_u8(&err, dev, OPAL_ENDLIST);
 		add_token_u8(&err, dev, OPAL_ENDNAME);
-		add_token_u8(&err, dev, OPAL_ENDLIST);
-
 	}
 	if (err) {
 		pr_debug("Error building Setup Locking range command.\n");
@@ -1295,7 +1293,6 @@ static int start_generic_opal_session(struct opal_dev *dev,
 
 	switch (auth) {
 	case OPAL_ANYBODY_UID:
-		add_token_u8(&err, dev, OPAL_ENDLIST);
 		break;
 	case OPAL_ADMIN1_UID:
 	case OPAL_SID_UID:
@@ -1308,7 +1305,6 @@ static int start_generic_opal_session(struct opal_dev *dev,
 		add_token_bytestring(&err, dev, opaluid[auth],
 				     OPAL_UID_LENGTH);
 		add_token_u8(&err, dev, OPAL_ENDNAME);
-		add_token_u8(&err, dev, OPAL_ENDLIST);
 		break;
 	default:
 		pr_debug("Cannot start Admin SP session with auth %d\n", auth);
@@ -1406,7 +1402,6 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, 3);
 	add_token_bytestring(&err, dev, lk_ul_user, OPAL_UID_LENGTH);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building STARTSESSION command.\n");
@@ -1429,7 +1424,6 @@ static int revert_tper(struct opal_dev *dev, void *data)
 	add_token_bytestring(&err, dev, opalmethod[OPAL_REVERT],
 			     OPAL_UID_LENGTH);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 	if (err) {
 		pr_debug("Error building REVERT TPER command.\n");
 		return err;
@@ -1463,7 +1457,6 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building Activate UserN command.\n");
@@ -1490,7 +1483,6 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
 	add_token_bytestring(&err, dev, opalmethod[OPAL_ERASE],
 			     OPAL_UID_LENGTH);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building Erase Locking Range Command.\n");
@@ -1521,7 +1513,6 @@ static int set_mbr_done(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error Building set MBR Done command\n");
@@ -1553,7 +1544,6 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error Building set MBR done command\n");
@@ -1585,7 +1575,6 @@ static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	return err;
 }
@@ -1694,7 +1683,6 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building add user to locking range command.\n");
@@ -1755,7 +1743,6 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
 
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
 		pr_debug("Error building SET command.\n");
@@ -1843,11 +1830,8 @@ static int activate_lsp(struct opal_dev *dev, void *data)
 		}
 		add_token_u8(&err, dev, OPAL_ENDLIST);
 		add_token_u8(&err, dev, OPAL_ENDNAME);
-		add_token_u8(&err, dev, OPAL_ENDLIST);
-
 	} else {
 		add_token_u8(&err, dev, OPAL_STARTLIST);
-		add_token_u8(&err, dev, OPAL_ENDLIST);
 	}
 
 	if (err) {
@@ -1904,7 +1888,6 @@ static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, 6); /* Lifecycle Column */
 	add_token_u8(&err, dev, OPAL_ENDNAME);
 
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
@@ -1964,8 +1947,6 @@ static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
 	add_token_u8(&err, dev, 4); /* End Column */
 	add_token_u8(&err, dev, 3); /* Lifecycle Column */
 	add_token_u8(&err, dev, OPAL_ENDNAME);
-
-	add_token_u8(&err, dev, OPAL_ENDLIST);
 	add_token_u8(&err, dev, OPAL_ENDLIST);
 
 	if (err) {
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 05/16] block: sed-opal: unify cmd start
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (3 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:45   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 06/16] block: sed-opal: unify error handling of responses David Kozub
                   ` (13 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

Every step starts with resetting the cmd buffer as well as the comid and
constructs the appropriate OPAL_CALL command. Consequently, those
actions may be combined into one generic function. On should take care
that the opening and closing tokens for the argument list are already
emitted by cmd_start and cmd_finalize respectively and thus must not be
additionally added.

Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 228 ++++++++++++++---------------------------------
 1 file changed, 69 insertions(+), 159 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 35b1747b650f..e29cb2f445ff 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -661,7 +661,7 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
 	struct opal_header *hdr;
 	int err = 0;
 
-	/* close parameter list */
+	/* close the parameter list opened from cmd_start */
 	add_token_u8(&err, cmd, OPAL_ENDLIST);
 
 	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
@@ -1006,6 +1006,27 @@ static void clear_opal_cmd(struct opal_dev *dev)
 	memset(dev->cmd, 0, IO_BUFFER_LENGTH);
 }
 
+static int cmd_start(struct opal_dev *dev, const u8 *uid, const u8 *method)
+{
+	int err = 0;
+
+	clear_opal_cmd(dev);
+	set_comid(dev, dev->comid);
+
+	add_token_u8(&err, dev, OPAL_CALL);
+	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
+	add_token_bytestring(&err, dev, method, OPAL_METHOD_LENGTH);
+
+	/*
+	 * Every method call is followed by its parameters enclosed within
+	 * OPAL_STARTLIST and OPAL_ENDLIST tokens. We automatically open the
+	 * parameter list here and close it later in cmd_finalize.
+	 */
+	add_token_u8(&err, dev, OPAL_STARTLIST);
+
+	return err;
+}
+
 static int start_opal_session_cont(struct opal_dev *dev)
 {
 	u32 hsn, tsn;
@@ -1068,20 +1089,13 @@ static int finalize_and_send(struct opal_dev *dev, cont_fn cont)
 static int gen_key(struct opal_dev *dev, void *data)
 {
 	u8 uid[OPAL_UID_LENGTH];
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
 	memcpy(uid, dev->prev_data, min(sizeof(uid), dev->prev_d_len));
 	kfree(dev->prev_data);
 	dev->prev_data = NULL;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_GENKEY],
-			     OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, uid, opalmethod[OPAL_GENKEY]);
 
 	if (err) {
 		pr_debug("Error building gen key command\n");
@@ -1119,21 +1133,14 @@ static int get_active_key_cont(struct opal_dev *dev)
 static int get_active_key(struct opal_dev *dev, void *data)
 {
 	u8 uid[OPAL_UID_LENGTH];
-	int err = 0;
+	int err;
 	u8 *lr = data;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
-
 	err = build_locking_range(uid, sizeof(uid), *lr);
 	if (err)
 		return err;
 
-	err = 0;
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, uid, opalmethod[OPAL_GET]);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, 3); /* startCloumn */
@@ -1156,13 +1163,10 @@ static int generic_lr_enable_disable(struct opal_dev *dev,
 				     u8 *uid, bool rle, bool wle,
 				     bool rl, bool wl)
 {
-	int err = 0;
+	int err;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
+	err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
 
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1209,10 +1213,7 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
 	u8 uid[OPAL_UID_LENGTH];
 	struct opal_user_lr_setup *setup = data;
 	u8 lr;
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
 	lr = setup->session.opal_key.lr;
 	err = build_locking_range(uid, sizeof(uid), lr);
@@ -1222,12 +1223,8 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
 	if (lr == 0)
 		err = enable_global_lr(dev, uid, setup);
 	else {
-		add_token_u8(&err, dev, OPAL_CALL);
-		add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-		add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
-				     OPAL_UID_LENGTH);
+		err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
 
-		add_token_u8(&err, dev, OPAL_STARTLIST);
 		add_token_u8(&err, dev, OPAL_STARTNAME);
 		add_token_u8(&err, dev, OPAL_VALUES);
 		add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1271,22 +1268,15 @@ static int start_generic_opal_session(struct opal_dev *dev,
 				      u8 key_len)
 {
 	u32 hsn;
-	int err = 0;
+	int err;
 
 	if (key == NULL && auth != OPAL_ANYBODY_UID)
 		return OPAL_INVAL_PARAM;
 
-	clear_opal_cmd(dev);
-
-	set_comid(dev, dev->comid);
 	hsn = GENERIC_HOST_SESSION_NUM;
+	err = cmd_start(dev, opaluid[OPAL_SMUID_UID],
+			opalmethod[OPAL_STARTSESSION]);
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_SMUID_UID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_STARTSESSION],
-			     OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u64(&err, dev, hsn);
 	add_token_bytestring(&err, dev, opaluid[sp_type], OPAL_UID_LENGTH);
 	add_token_u8(&err, dev, 1);
@@ -1366,30 +1356,21 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
 	u8 *key = session->opal_key.key;
 	u32 hsn = GENERIC_HOST_SESSION_NUM;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
-
-	if (session->sum) {
+	if (session->sum)
 		err = build_locking_user(lk_ul_user, sizeof(lk_ul_user),
 					 session->opal_key.lr);
-		if (err)
-			return err;
-
-	} else if (session->who != OPAL_ADMIN1 && !session->sum) {
+	else if (session->who != OPAL_ADMIN1 && !session->sum)
 		err = build_locking_user(lk_ul_user, sizeof(lk_ul_user),
 					 session->who - 1);
-		if (err)
-			return err;
-	} else
+	else
 		memcpy(lk_ul_user, opaluid[OPAL_ADMIN1_UID], OPAL_UID_LENGTH);
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_SMUID_UID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_STARTSESSION],
-			     OPAL_UID_LENGTH);
+	if (err)
+		return err;
+
+	err = cmd_start(dev, opaluid[OPAL_SMUID_UID],
+			opalmethod[OPAL_STARTSESSION]);
 
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u64(&err, dev, hsn);
 	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
 			     OPAL_UID_LENGTH);
@@ -1413,17 +1394,10 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
 
 static int revert_tper(struct opal_dev *dev, void *data)
 {
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_ADMINSP_UID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_REVERT],
-			     OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, opaluid[OPAL_ADMINSP_UID],
+			opalmethod[OPAL_REVERT]);
 	if (err) {
 		pr_debug("Error building REVERT TPER command.\n");
 		return err;
@@ -1436,18 +1410,12 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
 {
 	struct opal_session_info *session = data;
 	u8 uid[OPAL_UID_LENGTH];
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
 	memcpy(uid, opaluid[OPAL_USER1_UID], OPAL_UID_LENGTH);
 	uid[7] = session->who;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1470,19 +1438,12 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
 {
 	struct opal_session_info *session = data;
 	u8 uid[OPAL_UID_LENGTH];
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
 	if (build_locking_range(uid, sizeof(uid), session->opal_key.lr) < 0)
 		return -ERANGE;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_ERASE],
-			     OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, uid, opalmethod[OPAL_ERASE]);
 
 	if (err) {
 		pr_debug("Error building Erase Locking Range Command.\n");
@@ -1494,16 +1455,11 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
 static int set_mbr_done(struct opal_dev *dev, void *data)
 {
 	u8 *mbr_done_tf = data;
-	int err = 0;
+	int err;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	err = cmd_start(dev, opaluid[OPAL_MBRCONTROL],
+			opalmethod[OPAL_SET]);
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_MBRCONTROL],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1525,16 +1481,11 @@ static int set_mbr_done(struct opal_dev *dev, void *data)
 static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
 {
 	u8 *mbr_en_dis = data;
-	int err = 0;
+	int err;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	err = cmd_start(dev, opaluid[OPAL_MBRCONTROL],
+			opalmethod[OPAL_SET]);
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_MBRCONTROL],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1556,16 +1507,10 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
 static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
 			  struct opal_dev *dev)
 {
-	int err = 0;
+	int err;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	err = cmd_start(dev, cpin_uid, opalmethod[OPAL_SET]);
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, cpin_uid, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
-			     OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1622,10 +1567,7 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
 	u8 lr_buffer[OPAL_UID_LENGTH];
 	u8 user_uid[OPAL_UID_LENGTH];
 	struct opal_lock_unlock *lkul = data;
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
 	memcpy(lr_buffer, opaluid[OPAL_LOCKINGRANGE_ACE_RDLOCKED],
 	       OPAL_UID_LENGTH);
@@ -1640,12 +1582,8 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
 
 	user_uid[7] = lkul->session.who;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, lr_buffer, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
-			     OPAL_UID_LENGTH);
+	err = cmd_start(dev, lr_buffer, opalmethod[OPAL_SET]);
 
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 
@@ -1699,9 +1637,6 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
 	u8 read_locked = 1, write_locked = 1;
 	int err = 0;
 
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
-
 	if (build_locking_range(lr_buffer, sizeof(lr_buffer),
 				lkul->session.opal_key.lr) < 0)
 		return -ERANGE;
@@ -1723,10 +1658,8 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
 		return OPAL_INVAL_PARAM;
 	}
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, lr_buffer, OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
+	err = cmd_start(dev, lr_buffer, opalmethod[OPAL_SET]);
+
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, OPAL_VALUES);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
@@ -1797,17 +1730,10 @@ static int activate_lsp(struct opal_dev *dev, void *data)
 	struct opal_lr_act *opal_act = data;
 	u8 user_lr[OPAL_UID_LENGTH];
 	u8 uint_3 = 0x83;
-	int err = 0, i;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
-
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_ACTIVATE],
-			     OPAL_UID_LENGTH);
+	int err, i;
 
+	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
+			opalmethod[OPAL_ACTIVATE]);
 
 	if (opal_act->sum) {
 		err = build_locking_range(user_lr, sizeof(user_lr),
@@ -1815,7 +1741,6 @@ static int activate_lsp(struct opal_dev *dev, void *data)
 		if (err)
 			return err;
 
-		add_token_u8(&err, dev, OPAL_STARTLIST);
 		add_token_u8(&err, dev, OPAL_STARTNAME);
 		add_token_u8(&err, dev, uint_3);
 		add_token_u8(&err, dev, 6);
@@ -1830,8 +1755,6 @@ static int activate_lsp(struct opal_dev *dev, void *data)
 		}
 		add_token_u8(&err, dev, OPAL_ENDLIST);
 		add_token_u8(&err, dev, OPAL_ENDNAME);
-	} else {
-		add_token_u8(&err, dev, OPAL_STARTLIST);
 	}
 
 	if (err) {
@@ -1865,17 +1788,11 @@ static int get_lsp_lifecycle_cont(struct opal_dev *dev)
 /* Determine if we're in the Manufactured Inactive or Active state */
 static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
 {
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
+	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
+			opalmethod[OPAL_GET]);
 
-	add_token_u8(&err, dev, OPAL_STARTLIST);
 	add_token_u8(&err, dev, OPAL_STARTLIST);
 
 	add_token_u8(&err, dev, OPAL_STARTNAME);
@@ -1925,19 +1842,12 @@ static int get_msid_cpin_pin_cont(struct opal_dev *dev)
 
 static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
 {
-	int err = 0;
-
-	clear_opal_cmd(dev);
-	set_comid(dev, dev->comid);
+	int err;
 
-	add_token_u8(&err, dev, OPAL_CALL);
-	add_token_bytestring(&err, dev, opaluid[OPAL_C_PIN_MSID],
-			     OPAL_UID_LENGTH);
-	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
+	err = cmd_start(dev, opaluid[OPAL_C_PIN_MSID],
+			opalmethod[OPAL_GET]);
 
 	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
-
 	add_token_u8(&err, dev, OPAL_STARTNAME);
 	add_token_u8(&err, dev, 3); /* Start Column */
 	add_token_u8(&err, dev, 3); /* PIN */
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 06/16] block: sed-opal: unify error handling of responses
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (4 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 05/16] block: sed-opal: unify cmd start David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:45   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

response_get_{string,u64} include error handling for argument resp being
NULL but response_get_token does not handle this.

Make all three of response_get_{string,u64,token} handle NULL resp in
the same way.

Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index e29cb2f445ff..537cd73ea88a 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -702,6 +702,11 @@ static const struct opal_resp_tok *response_get_token(
 {
 	const struct opal_resp_tok *tok;
 
+	if (!resp) {
+		pr_debug("Response is NULL\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	if (n >= resp->num) {
 		pr_debug("Token number doesn't exist: %d, resp: %d\n",
 			 n, resp->num);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (5 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 06/16] block: sed-opal: unify error handling of responses David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:46   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 08/16] block: sed-opal: print failed function address David Kozub
                   ` (11 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

response_get_token had already been in place, its functionality had
been duplicated within response_get_{u64,bytestring} with the same error
handling. Unify the handling by reusing response_get_token within the
other functions.

Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 46 +++++++++++++++-------------------------------
 1 file changed, 15 insertions(+), 31 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 537cd73ea88a..1332547e5a99 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -889,27 +889,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
 				  const char **store)
 {
 	u8 skip;
-	const struct opal_resp_tok *token;
+	const struct opal_resp_tok *tok;
 
 	*store = NULL;
-	if (!resp) {
-		pr_debug("Response is NULL\n");
-		return 0;
-	}
-
-	if (n >= resp->num) {
-		pr_debug("Response has %d tokens. Can't access %d\n",
-			 resp->num, n);
+	tok = response_get_token(resp, n);
+	if (IS_ERR(tok))
 		return 0;
-	}
 
-	token = &resp->toks[n];
-	if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
+	if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) {
 		pr_debug("Token is not a byte string!\n");
 		return 0;
 	}
 
-	switch (token->width) {
+	switch (tok->width) {
 	case OPAL_WIDTH_TINY:
 	case OPAL_WIDTH_SHORT:
 		skip = 1;
@@ -925,37 +917,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
 		return 0;
 	}
 
-	*store = token->pos + skip;
-	return token->len - skip;
+	*store = tok->pos + skip;
+	return tok->len - skip;
 }
 
 static u64 response_get_u64(const struct parsed_resp *resp, int n)
 {
-	if (!resp) {
-		pr_debug("Response is NULL\n");
-		return 0;
-	}
+	const struct opal_resp_tok *tok;
 
-	if (n >= resp->num) {
-		pr_debug("Response has %d tokens. Can't access %d\n",
-			 resp->num, n);
+	tok = response_get_token(resp, n);
+	if (IS_ERR(tok))
 		return 0;
-	}
 
-	if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) {
-		pr_debug("Token is not unsigned it: %d\n",
-			 resp->toks[n].type);
+	if (tok->type != OPAL_DTA_TOKENID_UINT) {
+		pr_debug("Token is not unsigned int: %d\n", tok->type);
 		return 0;
 	}
 
-	if (!(resp->toks[n].width == OPAL_WIDTH_TINY ||
-	      resp->toks[n].width == OPAL_WIDTH_SHORT)) {
-		pr_debug("Atom is not short or tiny: %d\n",
-			 resp->toks[n].width);
+	if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) {
+		pr_debug("Atom is not short or tiny: %d\n", tok->width);
 		return 0;
 	}
 
-	return resp->toks[n].stored.u;
+	return tok->stored.u;
 }
 
 static bool response_token_matches(const struct opal_resp_tok *token, u8 match)
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 08/16] block: sed-opal: print failed function address
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (6 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:46   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content David Kozub
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Add function address (and if available its symbol) to the message if a
step function fails.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 1332547e5a99..4225f23b2165 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -394,8 +394,8 @@ static int next(struct opal_dev *dev)
 
 		error = step->fn(dev, step->data);
 		if (error) {
-			pr_debug("Error on step function: %d with error %d: %s\n",
-				 state, error,
+			pr_debug("Step %d (%pS) failed wit error %d: %s\n",
+				 state, step->fn, error,
 				 opal_error_to_human(error));
 
 			/* For each OPAL command we do a discovery0 then we
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (7 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 08/16] block: sed-opal: print failed function address David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:48   ` Christoph Hellwig
  2019-02-08 22:58   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr David Kozub
                   ` (9 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Split the header generation from the (normal) memcpy part if a
bytestring is copied into the command buffer. This allows in-place
generation of the bytestring content. For example, copy_from_user may be
used without an intermediate buffer.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 4225f23b2165..4b0a63b9d7c9 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -586,14 +586,11 @@ static void add_token_u64(int *err, struct opal_dev *cmd, u64 number)
 		add_token_u8(err, cmd, number >> (len * 8));
 }
 
-static void add_token_bytestring(int *err, struct opal_dev *cmd,
-				 const u8 *bytestring, size_t len)
+static u8 *add_bytestring_header(int *err, struct opal_dev *cmd, size_t len)
 {
 	size_t header_len = 1;
 	bool is_short_atom = true;
-
-	if (*err)
-		return;
+	char *start;
 
 	if (len & ~SHORT_ATOM_LEN_MASK) {
 		header_len = 2;
@@ -602,17 +599,27 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd,
 
 	if (!can_add(err, cmd, header_len + len)) {
 		pr_debug("Error adding bytestring: end of buffer.\n");
-		return;
+		return NULL;
 	}
 
 	if (is_short_atom)
 		add_short_atom_header(cmd, true, false, len);
 	else
 		add_medium_atom_header(cmd, true, false, len);
+	start = &cmd->cmd[cmd->pos];
+	return start;
+}
 
-	memcpy(&cmd->cmd[cmd->pos], bytestring, len);
-	cmd->pos += len;
+static void add_token_bytestring(int *err, struct opal_dev *cmd,
+				 const u8 *bytestring, size_t len)
+{
+	u8 *start;
 
+	start = add_bytestring_header(err, cmd, len);
+	if (!start)
+		return;
+	memcpy(start, bytestring, len);
+	cmd->pos += len;
 }
 
 static int build_locking_range(u8 *buffer, size_t length, u8 lr)
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (8 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:52   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 11/16] block: sed-opal: ioctl for writing to " David Kozub
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Enable users to mark the shadow mbr as done without completely
deactivating the shadow mbr feature. This may be useful on reboots,
when the power to the disk is not disconnected in between and the shadow
mbr stores the required boot files. Of course, this saves also the
(few) commands required to enable the feature if it is already enabled
and one only wants to mark the shadow mbr as done.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c              | 33 +++++++++++++++++++++++++++++++--
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h |  1 +
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 4b0a63b9d7c9..e03838cfd31b 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -1996,13 +1996,39 @@ static int opal_erase_locking_range(struct opal_dev *dev,
 static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 					  struct opal_mbr_data *opal_mbr)
 {
+	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
+		? OPAL_TRUE : OPAL_FALSE;
 	const struct opal_step mbr_steps[] = {
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
-		{ set_mbr_done, &opal_mbr->enable_disable },
+		{ set_mbr_done, &token },
 		{ end_opal_session, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
-		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
+		{ set_mbr_enable_disable, &token },
+		{ end_opal_session, },
+		{ NULL, }
+	};
+	int ret;
+
+	if (opal_mbr->enable_disable != OPAL_MBR_ENABLE &&
+	    opal_mbr->enable_disable != OPAL_MBR_DISABLE)
+		return -EINVAL;
+
+	mutex_lock(&dev->dev_lock);
+	setup_opal_dev(dev, mbr_steps);
+	ret = next(dev);
+	mutex_unlock(&dev->dev_lock);
+	return ret;
+}
+
+static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
+{
+	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
+		? OPAL_TRUE : OPAL_FALSE;
+	const struct opal_step mbr_steps[] = {
+		{ opal_discovery0, },
+		{ start_admin1LSP_opal_session, &opal_mbr->key },
+		{ set_mbr_done, &token },
 		{ end_opal_session, },
 		{ NULL, }
 	};
@@ -2349,6 +2375,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
 	case IOC_OPAL_ENABLE_DISABLE_MBR:
 		ret = opal_enable_disable_shadow_mbr(dev, p);
 		break;
+	case IOC_OPAL_MBR_STATUS:
+		ret = opal_mbr_status(dev, p);
+		break;
 	case IOC_OPAL_ERASE_LR:
 		ret = opal_erase_locking_range(dev, p);
 		break;
diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
index 04b124fca51e..b38dc602cae3 100644
--- a/include/linux/sed-opal.h
+++ b/include/linux/sed-opal.h
@@ -47,6 +47,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
 	case IOC_OPAL_ENABLE_DISABLE_MBR:
 	case IOC_OPAL_ERASE_LR:
 	case IOC_OPAL_SECURE_ERASE_LR:
+	case IOC_OPAL_MBR_STATUS:
 		return true;
 	}
 	return false;
diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
index 627624d35030..0cb9890cdc04 100644
--- a/include/uapi/linux/sed-opal.h
+++ b/include/uapi/linux/sed-opal.h
@@ -116,5 +116,6 @@ struct opal_mbr_data {
 #define IOC_OPAL_ENABLE_DISABLE_MBR _IOW('p', 229, struct opal_mbr_data)
 #define IOC_OPAL_ERASE_LR           _IOW('p', 230, struct opal_session_info)
 #define IOC_OPAL_SECURE_ERASE_LR    _IOW('p', 231, struct opal_session_info)
+#define IOC_OPAL_MBR_STATUS         _IOW('p', 232, struct opal_mbr_data)
 
 #endif /* _UAPI_SED_OPAL_H */
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 11/16] block: sed-opal: ioctl for writing to shadow mbr
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (9 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr David Kozub
@ 2019-02-01 20:50 ` " David Kozub
  2019-02-04 17:58   ` kbuild test robot
  2019-02-08 22:58   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns David Kozub
                   ` (7 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Allow modification of the shadow mbr. If the shadow mbr is not marked as
done, this data will be presented read only as the device content. Only
after marking the shadow mbr as done and unlocking a locking range the
actual content is accessible.

Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++++++-
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h |  8 ++++
 3 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index e03838cfd31b..88c84906ce98 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -34,6 +34,9 @@
 #define IO_BUFFER_LENGTH 2048
 #define MAX_TOKS 64
 
+/* Number of bytes needed by cmd_finalize. */
+#define CMD_FINALIZE_BYTES_NEEDED 7
+
 struct opal_step {
 	int (*fn)(struct opal_dev *dev, void *data);
 	void *data;
@@ -668,7 +671,11 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
 	struct opal_header *hdr;
 	int err = 0;
 
-	/* close the parameter list opened from cmd_start */
+	/*
+	 * Close the parameter list opened from cmd_start.
+	 * The number of bytes added must be equal to
+	 * CMD_FINALIZE_BYTES_NEEDED.
+	 */
 	add_token_u8(&err, cmd, OPAL_ENDLIST);
 
 	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
@@ -1500,6 +1507,58 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
 	return finalize_and_send(dev, parse_and_check_status);
 }
 
+static int write_shadow_mbr(struct opal_dev *dev, void *data)
+{
+	struct opal_shadow_mbr *shadow = data;
+	const u8 __user *src;
+	u8 *dst;
+	size_t off = 0;
+	u64 len;
+	int err = 0;
+
+	/* do the actual transmission(s) */
+	src = (u8 *) shadow->data;
+	while (off < shadow->size) {
+		err = cmd_start(dev, opaluid[OPAL_MBR], opalmethod[OPAL_SET]);
+		add_token_u8(&err, dev, OPAL_STARTNAME);
+		add_token_u8(&err, dev, OPAL_WHERE);
+		add_token_u64(&err, dev, shadow->offset + off);
+		add_token_u8(&err, dev, OPAL_ENDNAME);
+
+		add_token_u8(&err, dev, OPAL_STARTNAME);
+		add_token_u8(&err, dev, OPAL_VALUES);
+
+		/*
+		 * The bytestring header is either 1 or 2 bytes, so assume 2.
+		 * There also needs to be enough space to accommodate the
+		 * trailing OPAL_ENDNAME (1 byte) and tokens added by
+		 * cmd_finalize.
+		 */
+		len = min(remaining_size(dev) - (2+1+CMD_FINALIZE_BYTES_NEEDED),
+			  (size_t)(shadow->size - off));
+		pr_debug("MBR: write bytes %zu+%llu/%llu\n",
+			 off, len, shadow->size);
+
+		dst = add_bytestring_header(&err, dev, len);
+		if (!dst)
+			break;
+		if (copy_from_user(dst, src + off, len))
+			err = -EFAULT;
+		dev->pos += len;
+
+		add_token_u8(&err, dev, OPAL_ENDNAME);
+		if (err)
+			break;
+
+		err = finalize_and_send(dev, parse_and_check_status);
+		if (err)
+			break;
+
+		off += len;
+	}
+	return err;
+}
+
 static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
 			  struct opal_dev *dev)
 {
@@ -2045,6 +2104,31 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 	return ret;
 }
 
+static int opal_write_shadow_mbr(struct opal_dev *dev,
+				 struct opal_shadow_mbr *info)
+{
+	const struct opal_step mbr_steps[] = {
+		{ opal_discovery0, },
+		{ start_admin1LSP_opal_session, &info->key },
+		{ write_shadow_mbr, info },
+		{ end_opal_session, },
+		{ NULL, }
+	};
+	int ret;
+
+	if (info->size == 0)
+		return 0;
+
+	if (!access_ok(info->data, info->size))
+		return -EINVAL;
+
+	mutex_lock(&dev->dev_lock);
+	setup_opal_dev(dev, mbr_steps);
+	ret = next(dev);
+	mutex_unlock(&dev->dev_lock);
+	return ret;
+}
+
 static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
 {
 	struct opal_suspend_data *suspend;
@@ -2378,6 +2462,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
 	case IOC_OPAL_MBR_STATUS:
 		ret = opal_mbr_status(dev, p);
 		break;
+	case IOC_OPAL_WRITE_SHADOW_MBR:
+		ret = opal_write_shadow_mbr(dev, p);
+		break;
 	case IOC_OPAL_ERASE_LR:
 		ret = opal_erase_locking_range(dev, p);
 		break;
diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
index b38dc602cae3..cf08cdc13cbd 100644
--- a/include/linux/sed-opal.h
+++ b/include/linux/sed-opal.h
@@ -47,6 +47,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
 	case IOC_OPAL_ENABLE_DISABLE_MBR:
 	case IOC_OPAL_ERASE_LR:
 	case IOC_OPAL_SECURE_ERASE_LR:
+	case IOC_OPAL_WRITE_SHADOW_MBR:
 	case IOC_OPAL_MBR_STATUS:
 		return true;
 	}
diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
index 0cb9890cdc04..8e84307f66d4 100644
--- a/include/uapi/linux/sed-opal.h
+++ b/include/uapi/linux/sed-opal.h
@@ -104,6 +104,13 @@ struct opal_mbr_data {
 	__u8 __align[7];
 };
 
+struct opal_shadow_mbr {
+	struct opal_key key;
+	const __u64 data;
+	__u64 offset;
+	__u64 size;
+};
+
 #define IOC_OPAL_SAVE		    _IOW('p', 220, struct opal_lock_unlock)
 #define IOC_OPAL_LOCK_UNLOCK	    _IOW('p', 221, struct opal_lock_unlock)
 #define IOC_OPAL_TAKE_OWNERSHIP	    _IOW('p', 222, struct opal_key)
@@ -117,5 +124,6 @@ struct opal_mbr_data {
 #define IOC_OPAL_ERASE_LR           _IOW('p', 230, struct opal_session_info)
 #define IOC_OPAL_SECURE_ERASE_LR    _IOW('p', 231, struct opal_session_info)
 #define IOC_OPAL_MBR_STATUS         _IOW('p', 232, struct opal_mbr_data)
+#define IOC_OPAL_WRITE_SHADOW_MBR   _IOW('p', 233, struct opal_shadow_mbr)
 
 #endif /* _UAPI_SED_OPAL_H */
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (10 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 11/16] block: sed-opal: ioctl for writing to " David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:56   ` Christoph Hellwig
  2019-02-08 22:58   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 13/16] block: sed-opal: check size of shadow mbr David Kozub
                   ` (6 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Instead of having multiple places defining the same argument list to get
a specific column of a sed-opal table, provide a generic version and
call it from those functions.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/opal_proto.h |   2 +
 block/sed-opal.c   | 132 +++++++++++++++++----------------------------
 2 files changed, 50 insertions(+), 84 deletions(-)

diff --git a/block/opal_proto.h b/block/opal_proto.h
index e20be8258854..b6e352cfe982 100644
--- a/block/opal_proto.h
+++ b/block/opal_proto.h
@@ -170,6 +170,8 @@ enum opal_token {
 	OPAL_READLOCKED = 0x07,
 	OPAL_WRITELOCKED = 0x08,
 	OPAL_ACTIVEKEY = 0x0A,
+	/* lockingsp table */
+	OPAL_LIFECYCLE = 0x06,
 	/* locking info table */
 	OPAL_MAXRANGES = 0x04,
 	 /* mbr control */
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 88c84906ce98..2459ac4d523b 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -1089,6 +1089,37 @@ static int finalize_and_send(struct opal_dev *dev, cont_fn cont)
 	return opal_send_recv(dev, cont);
 }
 
+/*
+ * request @column from table @table on device @dev. On success, the column
+ * data will be available in dev->resp->tok[4]
+ */
+static int generic_get_column(struct opal_dev *dev, const u8 *table,
+			      u64 column)
+{
+	int err;
+
+	err = cmd_start(dev, table, opalmethod[OPAL_GET]);
+
+	add_token_u8(&err, dev, OPAL_STARTLIST);
+
+	add_token_u8(&err, dev, OPAL_STARTNAME);
+	add_token_u8(&err, dev, OPAL_STARTCOLUMN);
+	add_token_u64(&err, dev, column);
+	add_token_u8(&err, dev, OPAL_ENDNAME);
+
+	add_token_u8(&err, dev, OPAL_STARTNAME);
+	add_token_u8(&err, dev, OPAL_ENDCOLUMN);
+	add_token_u64(&err, dev, column);
+	add_token_u8(&err, dev, OPAL_ENDNAME);
+
+	add_token_u8(&err, dev, OPAL_ENDLIST);
+
+	if (err)
+		return err;
+
+	return finalize_and_send(dev, parse_and_check_status);
+}
+
 static int gen_key(struct opal_dev *dev, void *data)
 {
 	u8 uid[OPAL_UID_LENGTH];
@@ -1143,23 +1174,11 @@ static int get_active_key(struct opal_dev *dev, void *data)
 	if (err)
 		return err;
 
-	err = cmd_start(dev, uid, opalmethod[OPAL_GET]);
-	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 3); /* startCloumn */
-	add_token_u8(&err, dev, 10); /* ActiveKey */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 4); /* endColumn */
-	add_token_u8(&err, dev, 10); /* ActiveKey */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
-	if (err) {
-		pr_debug("Error building get active key command\n");
+	err = generic_get_column(dev, uid, OPAL_ACTIVEKEY);
+	if (err)
 		return err;
-	}
 
-	return finalize_and_send(dev, get_active_key_cont);
+	return get_active_key_cont(dev);
 }
 
 static int generic_lr_enable_disable(struct opal_dev *dev,
@@ -1820,17 +1839,19 @@ static int activate_lsp(struct opal_dev *dev, void *data)
 	return finalize_and_send(dev, parse_and_check_status);
 }
 
-static int get_lsp_lifecycle_cont(struct opal_dev *dev)
+/* Determine if we're in the Manufactured Inactive or Active state */
+static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
 {
 	u8 lc_status;
-	int error = 0;
+	int err;
 
-	error = parse_and_check_status(dev);
-	if (error)
-		return error;
+	err = generic_get_column(dev, opaluid[OPAL_LOCKINGSP_UID],
+				 OPAL_LIFECYCLE);
+	if (err)
+		return err;
 
 	lc_status = response_get_u64(&dev->parsed, 4);
-	/* 0x08 is Manufacured Inactive */
+	/* 0x08 is Manufactured Inactive */
 	/* 0x09 is Manufactured */
 	if (lc_status != OPAL_MANUFACTURED_INACTIVE) {
 		pr_debug("Couldn't determine the status of the Lifecycle state\n");
@@ -1840,49 +1861,19 @@ static int get_lsp_lifecycle_cont(struct opal_dev *dev)
 	return 0;
 }
 
-/* Determine if we're in the Manufactured Inactive or Active state */
-static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
-{
-	int err;
-
-	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
-			opalmethod[OPAL_GET]);
-
-	add_token_u8(&err, dev, OPAL_STARTLIST);
-
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 3); /* Start Column */
-	add_token_u8(&err, dev, 6); /* Lifecycle Column */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 4); /* End Column */
-	add_token_u8(&err, dev, 6); /* Lifecycle Column */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-
-	add_token_u8(&err, dev, OPAL_ENDLIST);
-
-	if (err) {
-		pr_debug("Error Building GET Lifecycle Status command\n");
-		return err;
-	}
-
-	return finalize_and_send(dev, get_lsp_lifecycle_cont);
-}
-
-static int get_msid_cpin_pin_cont(struct opal_dev *dev)
+static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
 {
 	const char *msid_pin;
 	size_t strlen;
-	int error = 0;
+	int err;
 
-	error = parse_and_check_status(dev);
-	if (error)
-		return error;
+	err = generic_get_column(dev, opaluid[OPAL_C_PIN_MSID], OPAL_PIN);
+	if (err)
+		return err;
 
 	strlen = response_get_string(&dev->parsed, 4, &msid_pin);
 	if (!msid_pin) {
-		pr_debug("%s: Couldn't extract PIN from response\n", __func__);
+		pr_debug("Couldn't extract MSID_CPIN from response\n");
 		return OPAL_INVAL_PARAM;
 	}
 
@@ -1895,33 +1886,6 @@ static int get_msid_cpin_pin_cont(struct opal_dev *dev)
 	return 0;
 }
 
-static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
-{
-	int err;
-
-	err = cmd_start(dev, opaluid[OPAL_C_PIN_MSID],
-			opalmethod[OPAL_GET]);
-
-	add_token_u8(&err, dev, OPAL_STARTLIST);
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 3); /* Start Column */
-	add_token_u8(&err, dev, 3); /* PIN */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-
-	add_token_u8(&err, dev, OPAL_STARTNAME);
-	add_token_u8(&err, dev, 4); /* End Column */
-	add_token_u8(&err, dev, 3); /* Lifecycle Column */
-	add_token_u8(&err, dev, OPAL_ENDNAME);
-	add_token_u8(&err, dev, OPAL_ENDLIST);
-
-	if (err) {
-		pr_debug("Error building Get MSID CPIN PIN command.\n");
-		return err;
-	}
-
-	return finalize_and_send(dev, get_msid_cpin_pin_cont);
-}
-
 static int end_opal_session(struct opal_dev *dev, void *data)
 {
 	int err = 0;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 13/16] block: sed-opal: check size of shadow mbr
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (11 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-08 22:58   ` Derrick, Jonathan
  2019-02-01 20:50 ` [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
                   ` (5 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>

Check whether the shadow mbr does fit in the provided space on the
target. Also a proper firmware should handle this case and return an
error we may prevent problems or even damage with crappy firmwares.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/opal_proto.h | 16 ++++++++++++++++
 block/sed-opal.c   | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/block/opal_proto.h b/block/opal_proto.h
index b6e352cfe982..5e8df3245eb0 100644
--- a/block/opal_proto.h
+++ b/block/opal_proto.h
@@ -106,6 +106,7 @@ enum opal_uid {
 	OPAL_ENTERPRISE_BANDMASTER0_UID,
 	OPAL_ENTERPRISE_ERASEMASTER_UID,
 	/* tables */
+	OPAL_TABLE_TABLE,
 	OPAL_LOCKINGRANGE_GLOBAL,
 	OPAL_LOCKINGRANGE_ACE_RDLOCKED,
 	OPAL_LOCKINGRANGE_ACE_WRLOCKED,
@@ -160,6 +161,21 @@ enum opal_token {
 	OPAL_STARTCOLUMN = 0x03,
 	OPAL_ENDCOLUMN = 0x04,
 	OPAL_VALUES = 0x01,
+	/* table table */
+	OPAL_TABLE_UID = 0x00,
+	OPAL_TABLE_NAME = 0x01,
+	OPAL_TABLE_COMMON = 0x02,
+	OPAL_TABLE_TEMPLATE = 0x03,
+	OPAL_TABLE_KIND = 0x04,
+	OPAL_TABLE_COLUMN = 0x05,
+	OPAL_TABLE_COLUMNS = 0x06,
+	OPAL_TABLE_ROWS = 0x07,
+	OPAL_TABLE_ROWS_FREE = 0x08,
+	OPAL_TABLE_ROW_BYTES = 0x09,
+	OPAL_TABLE_LASTID = 0x0A,
+	OPAL_TABLE_MIN = 0x0B,
+	OPAL_TABLE_MAX = 0x0C,
+
 	/* authority table */
 	OPAL_PIN = 0x03,
 	/* locking tokens */
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 2459ac4d523b..3493bb979978 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -139,6 +139,8 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
 
 	/* tables */
 
+	[OPAL_TABLE_TABLE]
+		{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 },
 	[OPAL_LOCKINGRANGE_GLOBAL] =
 		{ 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 },
 	[OPAL_LOCKINGRANGE_ACE_RDLOCKED] =
@@ -1120,6 +1122,29 @@ static int generic_get_column(struct opal_dev *dev, const u8 *table,
 	return finalize_and_send(dev, parse_and_check_status);
 }
 
+/*
+ * see TCG SAS 5.3.2.3 for a description of the available columns
+ *
+ * the result is provided in dev->resp->tok[4]
+ */
+static int generic_get_table_info(struct opal_dev *dev, enum opal_uid table,
+				  u64 column)
+{
+	u8 uid[OPAL_UID_LENGTH];
+	const unsigned int half = OPAL_UID_LENGTH/2;
+
+	/* sed-opal UIDs can be split in two halves:
+	 *  first:  actual table index
+	 *  second: relative index in the table
+	 * so we have to get the first half of the OPAL_TABLE_TABLE and use the
+	 * first part of the target table as relative index into that table
+	 */
+	memcpy(uid, opaluid[OPAL_TABLE_TABLE], half);
+	memcpy(uid+half, opaluid[table], half);
+
+	return generic_get_column(dev, uid, column);
+}
+
 static int gen_key(struct opal_dev *dev, void *data)
 {
 	u8 uid[OPAL_UID_LENGTH];
@@ -1535,6 +1560,20 @@ static int write_shadow_mbr(struct opal_dev *dev, void *data)
 	u64 len;
 	int err = 0;
 
+	/* do we fit in the available shadow mbr space? */
+	err = generic_get_table_info(dev, OPAL_MBR, OPAL_TABLE_ROWS);
+	if (err) {
+		pr_debug("MBR: could not get shadow size\n");
+		return err;
+	}
+
+	len = response_get_u64(&dev->parsed, 4);
+	if (shadow->size > len || shadow->offset > len - shadow->size) {
+		pr_debug("MBR: does not fit in shadow (%llu vs. %llu)\n",
+			 shadow->offset + shadow->size, len);
+		return -ENOSPC;
+	}
+
 	/* do the actual transmission(s) */
 	src = (u8 *) shadow->data;
 	while (off < shadow->size) {
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (12 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 13/16] block: sed-opal: check size of shadow mbr David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 14:57   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

The steps argument is only read by the next function, so it can
be passed directly as an argument rather than via opal_dev.

Normally, the steps is an array on the stack, so the pointer stops
being valid then the function that set opal_dev.steps returns.
If opal_dev.steps was not set to NULL before return it would become
a dangling pointer. When the steps are passed as argument this
becomes easier to see and more difficult to misuse.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 142 ++++++++++++++++++++---------------------------
 1 file changed, 61 insertions(+), 81 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 3493bb979978..21f2789a20cb 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -88,7 +88,6 @@ struct opal_dev {
 	void *data;
 	sec_send_recv *send_recv;
 
-	const struct opal_step *steps;
 	struct mutex dev_lock;
 	u16 comid;
 	u32 hsn;
@@ -387,19 +386,19 @@ static void check_geometry(struct opal_dev *dev, const void *data)
 	dev->lowest_lba = geo->lowest_aligned_lba;
 }
 
-static int next(struct opal_dev *dev)
+static int next(struct opal_dev *dev, const struct opal_step *steps,
+		size_t n_steps)
 {
 	const struct opal_step *step;
-	int state = 0, error = 0;
+	size_t state;
+	int error = 0;
 
-	do {
-		step = &dev->steps[state];
-		if (!step->fn)
-			break;
+	for (state = 0; !error && state < n_steps; state++) {
+		step = &steps[state];
 
 		error = step->fn(dev, step->data);
 		if (error) {
-			pr_debug("Step %d (%pS) failed wit error %d: %s\n",
+			pr_debug("Step %zu (%pS) failed with error %d: %s\n",
 				 state, step->fn, error,
 				 opal_error_to_human(error));
 
@@ -416,8 +415,7 @@ static int next(struct opal_dev *dev)
 			}
 
 		}
-		state++;
-	} while (!error);
+	}
 
 	return error;
 }
@@ -1941,17 +1939,13 @@ static int end_opal_session(struct opal_dev *dev, void *data)
 static int end_opal_session_error(struct opal_dev *dev)
 {
 	const struct opal_step error_end_session[] = {
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
-	dev->steps = error_end_session;
-	return next(dev);
+	return next(dev, error_end_session, ARRAY_SIZE(error_end_session));
 }
 
-static inline void setup_opal_dev(struct opal_dev *dev,
-				  const struct opal_step *steps)
+static inline void setup_opal_dev(struct opal_dev *dev)
 {
-	dev->steps = steps;
 	dev->tsn = 0;
 	dev->hsn = 0;
 	dev->prev_data = NULL;
@@ -1960,14 +1954,13 @@ static inline void setup_opal_dev(struct opal_dev *dev,
 static int check_opal_support(struct opal_dev *dev)
 {
 	const struct opal_step steps[] = {
-		{ opal_discovery0, },
-		{ NULL, }
+		{ opal_discovery0, }
 	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, steps, ARRAY_SIZE(steps));
 	dev->supported = !ret;
 	mutex_unlock(&dev->dev_lock);
 	return ret;
@@ -2024,14 +2017,13 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
 		{ start_auth_opal_session, opal_session },
 		{ get_active_key, &opal_session->opal_key.lr },
 		{ gen_key, },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, erase_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2043,14 +2035,13 @@ static int opal_erase_locking_range(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_auth_opal_session, opal_session },
 		{ erase_locking_range, opal_session },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, erase_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2067,8 +2058,7 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 		{ end_opal_session, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
 		{ set_mbr_enable_disable, &token },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2077,8 +2067,8 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, mbr_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2091,8 +2081,7 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
 		{ set_mbr_done, &token },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2101,8 +2090,8 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, mbr_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2114,8 +2103,7 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &info->key },
 		{ write_shadow_mbr, info },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2126,8 +2114,8 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, mbr_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2144,7 +2132,7 @@ static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
 	suspend->lr = lk_unlk->session.opal_key.lr;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, NULL);
+	setup_opal_dev(dev);
 	add_suspend_info(dev, suspend);
 	mutex_unlock(&dev->dev_lock);
 	return 0;
@@ -2157,8 +2145,7 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &lk_unlk->session.opal_key },
 		{ add_user_to_lr, lk_unlk },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2180,8 +2167,8 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 	}
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, steps, ARRAY_SIZE(steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2191,14 +2178,13 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
 	const struct opal_step revert_steps[] = {
 		{ opal_discovery0, },
 		{ start_SIDASP_opal_session, opal },
-		{ revert_tper, }, /* controller will terminate session */
-		{ NULL, }
+		{ revert_tper, } /* controller will terminate session */
 	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, revert_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, revert_steps, ARRAY_SIZE(revert_steps));
 	mutex_unlock(&dev->dev_lock);
 
 	/*
@@ -2218,19 +2204,20 @@ static int __opal_lock_unlock(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_auth_opal_session, &lk_unlk->session },
 		{ lock_unlock_locking_range, lk_unlk },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	const struct opal_step unlock_sum_steps[] = {
 		{ opal_discovery0, },
 		{ start_auth_opal_session, &lk_unlk->session },
 		{ lock_unlock_locking_range_sum, lk_unlk },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 
-	dev->steps = lk_unlk->session.sum ? unlock_sum_steps : unlock_steps;
-	return next(dev);
+	if (lk_unlk->session.sum)
+		return next(dev, unlock_sum_steps,
+			    ARRAY_SIZE(unlock_sum_steps));
+	else
+		return next(dev, unlock_steps, ARRAY_SIZE(unlock_steps));
 }
 
 static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
@@ -2240,12 +2227,10 @@ static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, key },
 		{ set_mbr_done, &mbr_done_tf },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 
-	dev->steps = mbrdone_step;
-	return next(dev);
+	return next(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
 }
 
 static int opal_lock_unlock(struct opal_dev *dev,
@@ -2272,8 +2257,7 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 		{ end_opal_session, },
 		{ start_SIDASP_opal_session, opal },
 		{ set_sid_cpin_pin, opal },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2281,8 +2265,8 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 		return -ENODEV;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, owner_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, owner_steps, ARRAY_SIZE(owner_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2295,8 +2279,7 @@ static int opal_activate_lsp(struct opal_dev *dev,
 		{ start_SIDASP_opal_session, &opal_lr_act->key },
 		{ get_lsp_lifecycle, },
 		{ activate_lsp, opal_lr_act },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2304,8 +2287,8 @@ static int opal_activate_lsp(struct opal_dev *dev,
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, active_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, active_steps, ARRAY_SIZE(active_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2317,14 +2300,13 @@ static int opal_setup_locking_range(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_auth_opal_session, &opal_lrs->session },
 		{ setup_locking_range, opal_lrs },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, lr_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, lr_steps, ARRAY_SIZE(lr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2335,8 +2317,7 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
 		{ opal_discovery0, },
 		{ start_auth_opal_session, &opal_pw->session },
 		{ set_new_pw, &opal_pw->new_user_pw },
-		{ end_opal_session, },
-		{ NULL }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2347,8 +2328,8 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
 		return -EINVAL;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, pw_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, pw_steps, ARRAY_SIZE(pw_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2360,8 +2341,7 @@ static int opal_activate_user(struct opal_dev *dev,
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_session->opal_key },
 		{ internal_activate_user, opal_session },
-		{ end_opal_session, },
-		{ NULL, }
+		{ end_opal_session, }
 	};
 	int ret;
 
@@ -2373,8 +2353,8 @@ static int opal_activate_user(struct opal_dev *dev,
 	}
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, act_steps);
-	ret = next(dev);
+	setup_opal_dev(dev);
+	ret = next(dev, act_steps, ARRAY_SIZE(act_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2391,7 +2371,7 @@ bool opal_unlock_from_suspend(struct opal_dev *dev)
 		return false;
 
 	mutex_lock(&dev->dev_lock);
-	setup_opal_dev(dev, NULL);
+	setup_opal_dev(dev);
 
 	list_for_each_entry(suspend, &dev->unlk_lst, node) {
 		dev->tsn = 0;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (13 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 15:01   ` Christoph Hellwig
  2019-02-01 20:50 ` [PATCH v4 16/16] block: sed-opal: rename next to execute_steps David Kozub
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

Originally each of the opal functions that call next include
opal_discovery0 in the array of steps. This is superfluous and
can be done always inside next.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 89 +++++++++++++++++++++++-------------------------
 1 file changed, 43 insertions(+), 46 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 21f2789a20cb..3362741dd198 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -221,6 +221,7 @@ static const u8 opalmethod[][OPAL_METHOD_LENGTH] = {
 };
 
 static int end_opal_session_error(struct opal_dev *dev);
+static int opal_discovery0_step(struct opal_dev *dev);
 
 struct opal_suspend_data {
 	struct opal_lock_unlock unlk;
@@ -386,36 +387,42 @@ static void check_geometry(struct opal_dev *dev, const void *data)
 	dev->lowest_lba = geo->lowest_aligned_lba;
 }
 
+static int execute_step(struct opal_dev *dev,
+			const struct opal_step *step, size_t stepIndex)
+{
+	int error = step->fn(dev, step->data);
+
+	if (error) {
+		pr_debug("Step %zu (%pS) failed with error %d: %s\n",
+			 stepIndex, step->fn, error,
+			 opal_error_to_human(error));
+	}
+
+	return error;
+}
+
 static int next(struct opal_dev *dev, const struct opal_step *steps,
 		size_t n_steps)
 {
-	const struct opal_step *step;
 	size_t state;
-	int error = 0;
+	int error;
 
-	for (state = 0; !error && state < n_steps; state++) {
-		step = &steps[state];
-
-		error = step->fn(dev, step->data);
-		if (error) {
-			pr_debug("Step %zu (%pS) failed with error %d: %s\n",
-				 state, step->fn, error,
-				 opal_error_to_human(error));
-
-			/* For each OPAL command we do a discovery0 then we
-			 * start some sort of session.
-			 * If we haven't passed state 1 then there was an error
-			 * on discovery0 or during the attempt to start a
-			 * session. Therefore we shouldn't attempt to terminate
-			 * a session, as one has not yet been created.
-			 */
-			if (state > 1) {
-				end_opal_session_error(dev);
-				return error;
-			}
+	/* first do a discovery0 */
+	error = opal_discovery0_step(dev);
 
-		}
-	}
+	for (state = 0; !error && state < n_steps; state++)
+		error = execute_step(dev, &steps[state], state);
+
+	/*
+	 * For each OPAL command the first step in steps starts some sort of
+	 * session. If an error occurred in the initial discovery0 or if an
+	 * error occurred in the first step (and thus stopping the loop with
+	 * state == 1) then there was an error before or during the attempt to
+	 * start a session. Therefore we shouldn't attempt to terminate a
+	 * session, as one has not yet been created.
+	 */
+	if (error && state > 1)
+		end_opal_session_error(dev);
 
 	return error;
 }
@@ -513,6 +520,14 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
 	return opal_discovery0_end(dev);
 }
 
+static int opal_discovery0_step(struct opal_dev *dev)
+{
+	const struct opal_step discovery0_step = {
+		opal_discovery0,
+	};
+	return execute_step(dev, &discovery0_step, 0);
+}
+
 static size_t remaining_size(struct opal_dev *cmd)
 {
 	return IO_BUFFER_LENGTH - cmd->pos;
@@ -1938,10 +1953,10 @@ static int end_opal_session(struct opal_dev *dev, void *data)
 
 static int end_opal_session_error(struct opal_dev *dev)
 {
-	const struct opal_step error_end_session[] = {
-		{ end_opal_session, }
+	const struct opal_step error_end_session = {
+		end_opal_session,
 	};
-	return next(dev, error_end_session, ARRAY_SIZE(error_end_session));
+	return execute_step(dev, &error_end_session, 0);
 }
 
 static inline void setup_opal_dev(struct opal_dev *dev)
@@ -1953,14 +1968,11 @@ static inline void setup_opal_dev(struct opal_dev *dev)
 
 static int check_opal_support(struct opal_dev *dev)
 {
-	const struct opal_step steps[] = {
-		{ opal_discovery0, }
-	};
 	int ret;
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, steps, ARRAY_SIZE(steps));
+	ret = opal_discovery0_step(dev);
 	dev->supported = !ret;
 	mutex_unlock(&dev->dev_lock);
 	return ret;
@@ -2013,7 +2025,6 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
 					   struct opal_session_info *opal_session)
 {
 	const struct opal_step erase_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, opal_session },
 		{ get_active_key, &opal_session->opal_key.lr },
 		{ gen_key, },
@@ -2032,7 +2043,6 @@ static int opal_erase_locking_range(struct opal_dev *dev,
 				    struct opal_session_info *opal_session)
 {
 	const struct opal_step erase_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, opal_session },
 		{ erase_locking_range, opal_session },
 		{ end_opal_session, }
@@ -2052,7 +2062,6 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
 		? OPAL_TRUE : OPAL_FALSE;
 	const struct opal_step mbr_steps[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
 		{ set_mbr_done, &token },
 		{ end_opal_session, },
@@ -2078,7 +2087,6 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
 		? OPAL_TRUE : OPAL_FALSE;
 	const struct opal_step mbr_steps[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
 		{ set_mbr_done, &token },
 		{ end_opal_session, }
@@ -2100,7 +2108,6 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
 				 struct opal_shadow_mbr *info)
 {
 	const struct opal_step mbr_steps[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &info->key },
 		{ write_shadow_mbr, info },
 		{ end_opal_session, }
@@ -2142,7 +2149,6 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 			       struct opal_lock_unlock *lk_unlk)
 {
 	const struct opal_step steps[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &lk_unlk->session.opal_key },
 		{ add_user_to_lr, lk_unlk },
 		{ end_opal_session, }
@@ -2176,7 +2182,6 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
 {
 	const struct opal_step revert_steps[] = {
-		{ opal_discovery0, },
 		{ start_SIDASP_opal_session, opal },
 		{ revert_tper, } /* controller will terminate session */
 	};
@@ -2201,13 +2206,11 @@ static int __opal_lock_unlock(struct opal_dev *dev,
 			      struct opal_lock_unlock *lk_unlk)
 {
 	const struct opal_step unlock_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, &lk_unlk->session },
 		{ lock_unlock_locking_range, lk_unlk },
 		{ end_opal_session, }
 	};
 	const struct opal_step unlock_sum_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, &lk_unlk->session },
 		{ lock_unlock_locking_range_sum, lk_unlk },
 		{ end_opal_session, }
@@ -2224,7 +2227,6 @@ static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 {
 	u8 mbr_done_tf = 1;
 	const struct opal_step mbrdone_step[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, key },
 		{ set_mbr_done, &mbr_done_tf },
 		{ end_opal_session, }
@@ -2251,7 +2253,6 @@ static int opal_lock_unlock(struct opal_dev *dev,
 static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 {
 	const struct opal_step owner_steps[] = {
-		{ opal_discovery0, },
 		{ start_anybodyASP_opal_session, },
 		{ get_msid_cpin_pin, },
 		{ end_opal_session, },
@@ -2275,7 +2276,6 @@ static int opal_activate_lsp(struct opal_dev *dev,
 			     struct opal_lr_act *opal_lr_act)
 {
 	const struct opal_step active_steps[] = {
-		{ opal_discovery0, },
 		{ start_SIDASP_opal_session, &opal_lr_act->key },
 		{ get_lsp_lifecycle, },
 		{ activate_lsp, opal_lr_act },
@@ -2297,7 +2297,6 @@ static int opal_setup_locking_range(struct opal_dev *dev,
 				    struct opal_user_lr_setup *opal_lrs)
 {
 	const struct opal_step lr_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, &opal_lrs->session },
 		{ setup_locking_range, opal_lrs },
 		{ end_opal_session, }
@@ -2314,7 +2313,6 @@ static int opal_setup_locking_range(struct opal_dev *dev,
 static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
 {
 	const struct opal_step pw_steps[] = {
-		{ opal_discovery0, },
 		{ start_auth_opal_session, &opal_pw->session },
 		{ set_new_pw, &opal_pw->new_user_pw },
 		{ end_opal_session, }
@@ -2338,7 +2336,6 @@ static int opal_activate_user(struct opal_dev *dev,
 			      struct opal_session_info *opal_session)
 {
 	const struct opal_step act_steps[] = {
-		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_session->opal_key },
 		{ internal_activate_user, opal_session },
 		{ end_opal_session, }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 16/16] block: sed-opal: rename next to execute_steps
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (14 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
@ 2019-02-01 20:50 ` David Kozub
  2019-02-04 15:01   ` Christoph Hellwig
  2019-02-08 22:59   ` Derrick, Jonathan
  2019-02-04  8:55 ` David Kozub
                   ` (2 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-01 20:50 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

As the function is responsible for executing the individual steps supplied
in the steps argument, execute_steps is a more descriptive name than the
rather generic next.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 3362741dd198..c09149dd5e0a 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -401,8 +401,8 @@ static int execute_step(struct opal_dev *dev,
 	return error;
 }
 
-static int next(struct opal_dev *dev, const struct opal_step *steps,
-		size_t n_steps)
+static int execute_steps(struct opal_dev *dev,
+			 const struct opal_step *steps, size_t n_steps)
 {
 	size_t state;
 	int error;
@@ -2034,7 +2034,7 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
+	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2051,7 +2051,7 @@ static int opal_erase_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
+	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2077,7 +2077,7 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2099,7 +2099,7 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2122,7 +2122,7 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2174,7 +2174,7 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, steps, ARRAY_SIZE(steps));
+	ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2189,7 +2189,7 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, revert_steps, ARRAY_SIZE(revert_steps));
+	ret = execute_steps(dev, revert_steps, ARRAY_SIZE(revert_steps));
 	mutex_unlock(&dev->dev_lock);
 
 	/*
@@ -2217,10 +2217,11 @@ static int __opal_lock_unlock(struct opal_dev *dev,
 	};
 
 	if (lk_unlk->session.sum)
-		return next(dev, unlock_sum_steps,
-			    ARRAY_SIZE(unlock_sum_steps));
+		return execute_steps(dev, unlock_sum_steps,
+				     ARRAY_SIZE(unlock_sum_steps));
 	else
-		return next(dev, unlock_steps, ARRAY_SIZE(unlock_steps));
+		return execute_steps(dev, unlock_steps,
+				     ARRAY_SIZE(unlock_steps));
 }
 
 static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
@@ -2232,7 +2233,7 @@ static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 		{ end_opal_session, }
 	};
 
-	return next(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
+	return execute_steps(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
 }
 
 static int opal_lock_unlock(struct opal_dev *dev,
@@ -2267,7 +2268,7 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, owner_steps, ARRAY_SIZE(owner_steps));
+	ret = execute_steps(dev, owner_steps, ARRAY_SIZE(owner_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2288,7 +2289,7 @@ static int opal_activate_lsp(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, active_steps, ARRAY_SIZE(active_steps));
+	ret = execute_steps(dev, active_steps, ARRAY_SIZE(active_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2305,7 +2306,7 @@ static int opal_setup_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, lr_steps, ARRAY_SIZE(lr_steps));
+	ret = execute_steps(dev, lr_steps, ARRAY_SIZE(lr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2327,7 +2328,7 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, pw_steps, ARRAY_SIZE(pw_steps));
+	ret = execute_steps(dev, pw_steps, ARRAY_SIZE(pw_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2351,7 +2352,7 @@ static int opal_activate_user(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, act_steps, ARRAY_SIZE(act_steps));
+	ret = execute_steps(dev, act_steps, ARRAY_SIZE(act_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v4 16/16] block: sed-opal: rename next to execute_steps
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (15 preceding siblings ...)
  2019-02-01 20:50 ` [PATCH v4 16/16] block: sed-opal: rename next to execute_steps David Kozub
@ 2019-02-04  8:55 ` David Kozub
  2019-02-04  9:44 ` [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
  2019-02-04 15:04 ` Christoph Hellwig
  18 siblings, 0 replies; 64+ messages in thread
From: David Kozub @ 2019-02-04  8:55 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

As the function is responsible for executing the individual steps supplied
in the steps argument, execute_steps is a more descriptive name than the
rather generic next.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
---
 block/sed-opal.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 3362741dd198..c09149dd5e0a 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -401,8 +401,8 @@ static int execute_step(struct opal_dev *dev,
 	return error;
 }
 
-static int next(struct opal_dev *dev, const struct opal_step *steps,
-		size_t n_steps)
+static int execute_steps(struct opal_dev *dev,
+			 const struct opal_step *steps, size_t n_steps)
 {
 	size_t state;
 	int error;
@@ -2034,7 +2034,7 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
+	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2051,7 +2051,7 @@ static int opal_erase_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
+	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2077,7 +2077,7 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2099,7 +2099,7 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2122,7 +2122,7 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2174,7 +2174,7 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, steps, ARRAY_SIZE(steps));
+	ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2189,7 +2189,7 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, revert_steps, ARRAY_SIZE(revert_steps));
+	ret = execute_steps(dev, revert_steps, ARRAY_SIZE(revert_steps));
 	mutex_unlock(&dev->dev_lock);
 
 	/*
@@ -2217,10 +2217,11 @@ static int __opal_lock_unlock(struct opal_dev *dev,
 	};
 
 	if (lk_unlk->session.sum)
-		return next(dev, unlock_sum_steps,
-			    ARRAY_SIZE(unlock_sum_steps));
+		return execute_steps(dev, unlock_sum_steps,
+				     ARRAY_SIZE(unlock_sum_steps));
 	else
-		return next(dev, unlock_steps, ARRAY_SIZE(unlock_steps));
+		return execute_steps(dev, unlock_steps,
+				     ARRAY_SIZE(unlock_steps));
 }
 
 static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
@@ -2232,7 +2233,7 @@ static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 		{ end_opal_session, }
 	};
 
-	return next(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
+	return execute_steps(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
 }
 
 static int opal_lock_unlock(struct opal_dev *dev,
@@ -2267,7 +2268,7 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, owner_steps, ARRAY_SIZE(owner_steps));
+	ret = execute_steps(dev, owner_steps, ARRAY_SIZE(owner_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2288,7 +2289,7 @@ static int opal_activate_lsp(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, active_steps, ARRAY_SIZE(active_steps));
+	ret = execute_steps(dev, active_steps, ARRAY_SIZE(active_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2305,7 +2306,7 @@ static int opal_setup_locking_range(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, lr_steps, ARRAY_SIZE(lr_steps));
+	ret = execute_steps(dev, lr_steps, ARRAY_SIZE(lr_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2327,7 +2328,7 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, pw_steps, ARRAY_SIZE(pw_steps));
+	ret = execute_steps(dev, pw_steps, ARRAY_SIZE(pw_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
@@ -2351,7 +2352,7 @@ static int opal_activate_user(struct opal_dev *dev,
 
 	mutex_lock(&dev->dev_lock);
 	setup_opal_dev(dev);
-	ret = next(dev, act_steps, ARRAY_SIZE(act_steps));
+	ret = execute_steps(dev, act_steps, ARRAY_SIZE(act_steps));
 	mutex_unlock(&dev->dev_lock);
 	return ret;
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (16 preceding siblings ...)
  2019-02-04  8:55 ` David Kozub
@ 2019-02-04  9:44 ` David Kozub
  2019-02-04 15:04 ` Christoph Hellwig
  18 siblings, 0 replies; 64+ messages in thread
From: David Kozub @ 2019-02-04  9:44 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein

On Fri, 1 Feb 2019, David Kozub wrote:

> This patch series extends SED OPAL support: it adds IOCTL for setting the shadow
> MBR done flag which can be useful for unlocking an OPAL disk on boot and it adds
> IOCTL for writing to the shadow MBR. Also included are some minor fixes and
> improvements.
>
> This series is based on the original work done by Jonas Rabenstein which was
> submitted in March 2018.[1]
>
> There is a fork of sed-opal-temp that can use these new IOCTLs.[2] I tested
> these on Samsung 840 EVO and 850 EVO drives, on x86-64 and arm64 systems.
>
> The series applies on v5.0-rc4.
>
> I'm resending as v4 as suggested by Scott Bauer.[3]
>
> Changes from v3 to v4:
> * added Reviewed-by from Scott, including for the patch 16/16 (details in
> [3])

So this time really the 16th patch got lost somewhere - while I have 
received it, I could not see it in https://lore.kernel.org/lkml/. So I 
re-sent it now.

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 01/16] block: sed-opal: fix typos and formatting
  2019-02-01 20:50 ` [PATCH v4 01/16] block: sed-opal: fix typos and formatting David Kozub
@ 2019-02-04 14:42   ` Christoph Hellwig
  2019-02-04 20:28     ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:42 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:08PM +0100, David Kozub wrote:
> This should make no change in functionality.
> The formatting changes were triggered by checkpatch.pl.
> 
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index e0de4dd448b3..c882a193e162 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -11,8 +11,8 @@
>   *
>   * This program is distributed in the hope it will be useful, but WITHOUT
>   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> - * more details.
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> + * for more details.

What exactly is the fix here?

If we want to fix the licence boilerplate we should switch it to an
SPDX tag instead.

Otherwise this looks fine to me.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 02/16] block: sed-opal: use correct macro for method length
  2019-02-01 20:50 ` [PATCH v4 02/16] block: sed-opal: use correct macro for method length David Kozub
@ 2019-02-04 14:43   ` Christoph Hellwig
  2019-02-08 22:56   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:43 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:09PM +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Also the values of OPAL_UID_LENGTH and OPAL_METHOD_LENGTH are the same,
> it is weird to use OPAL_UID_LENGTH for the definition of the methods.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

Dave, when you resubmit other peoples patches you should also add
your Signed-off-by: line to the end of the signoff chain.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 03/16] block: sed-opal: unify space check in add_token_*
  2019-02-01 20:50 ` [PATCH v4 03/16] block: sed-opal: unify space check in add_token_* David Kozub
@ 2019-02-04 14:44   ` Christoph Hellwig
  2019-02-04 21:07     ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:44 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:10PM +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> All add_token_* functions have a common set of conditions that have to
> be checked. Use a common function for those checks in order to avoid
> different behaviour as well as code duplication.
> 
> Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 30 +++++++++++++++++++++---------
>  1 file changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 5c123a5b4ab1..980705681806 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -510,15 +510,29 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
>  	return opal_discovery0_end(dev);
>  }
>  
> -static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
> +static size_t remaining_size(struct opal_dev *cmd)
> +{
> +	return IO_BUFFER_LENGTH - cmd->pos;
> +}

This function seem a little pointless to me, at least as of this patch
where it only has a single user just below.

Otherwise this looks good to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize
  2019-02-01 20:50 ` [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
@ 2019-02-04 14:44   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:44 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:11PM +0100, David Kozub wrote:
> Every step ends by calling cmd_finalize (via finalize_and_send)
> yet every step adds the token OPAL_ENDLIST on its own. Moving
> this into cmd_finalize decreases code duplication.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 05/16] block: sed-opal: unify cmd start
  2019-02-01 20:50 ` [PATCH v4 05/16] block: sed-opal: unify cmd start David Kozub
@ 2019-02-04 14:45   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:45 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 06/16] block: sed-opal: unify error handling of responses
  2019-02-01 20:50 ` [PATCH v4 06/16] block: sed-opal: unify error handling of responses David Kozub
@ 2019-02-04 14:45   ` Christoph Hellwig
  0 siblings, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:45 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:13PM +0100, David Kozub wrote:
> response_get_{string,u64} include error handling for argument resp being
> NULL but response_get_token does not handle this.
> 
> Make all three of response_get_{string,u64,token} handle NULL resp in
> the same way.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication
  2019-02-01 20:50 ` [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
@ 2019-02-04 14:46   ` Christoph Hellwig
  2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:46 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:14PM +0100, David Kozub wrote:
> response_get_token had already been in place, its functionality had
> been duplicated within response_get_{u64,bytestring} with the same error
> handling. Unify the handling by reusing response_get_token within the
> other functions.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 08/16] block: sed-opal: print failed function address
  2019-02-01 20:50 ` [PATCH v4 08/16] block: sed-opal: print failed function address David Kozub
@ 2019-02-04 14:46   ` Christoph Hellwig
  0 siblings, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:46 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:15PM +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Add function address (and if available its symbol) to the message if a
> step function fails.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content
  2019-02-01 20:50 ` [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content David Kozub
@ 2019-02-04 14:48   ` Christoph Hellwig
  2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:48 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

> +	start = &cmd->cmd[cmd->pos];
> +	return start;

No need for the local start variable here, just return the computed
address directly.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-01 20:50 ` [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr David Kozub
@ 2019-02-04 14:52   ` Christoph Hellwig
  2019-02-07 22:56     ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:52 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:17PM +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Enable users to mark the shadow mbr as done without completely
> deactivating the shadow mbr feature. This may be useful on reboots,
> when the power to the disk is not disconnected in between and the shadow
> mbr stores the required boot files. Of course, this saves also the
> (few) commands required to enable the feature if it is already enabled
> and one only wants to mark the shadow mbr as done.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c              | 33 +++++++++++++++++++++++++++++++--
>  include/linux/sed-opal.h      |  1 +
>  include/uapi/linux/sed-opal.h |  1 +
>  3 files changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 4b0a63b9d7c9..e03838cfd31b 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -1996,13 +1996,39 @@ static int opal_erase_locking_range(struct opal_dev *dev,
>  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
>  					  struct opal_mbr_data *opal_mbr)
>  {
> +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> +		? OPAL_TRUE : OPAL_FALSE;
>  	const struct opal_step mbr_steps[] = {
>  		{ opal_discovery0, },
>  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> -		{ set_mbr_done, &opal_mbr->enable_disable },
> +		{ set_mbr_done, &token },
>  		{ end_opal_session, },
>  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> -		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
> +		{ set_mbr_enable_disable, &token },
> +		{ end_opal_session, },
> +		{ NULL, }

This seems to be a change of what we pass to set_mbr_done /
set_mbr_enable_disable and not really related to the new functionality
here, so it should be split into a separate patch.

That being said if we really care about this translation between
the two sets of constants, why not do it inside
set_mbr_done and set_mbr_enable_disable?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns
  2019-02-01 20:50 ` [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns David Kozub
@ 2019-02-04 14:56   ` Christoph Hellwig
  2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:56 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

> +++ b/block/opal_proto.h
> @@ -170,6 +170,8 @@ enum opal_token {
>  	OPAL_READLOCKED = 0x07,
>  	OPAL_WRITELOCKED = 0x08,
>  	OPAL_ACTIVEKEY = 0x0A,
> +	/* lockingsp table */
> +	OPAL_LIFECYCLE = 0x06,

Adding a name for the colum seems independent of the refactoring,
and probably should be a patch of its own.

> -	/* 0x08 is Manufacured Inactive */
> +	/* 0x08 is Manufactured Inactive */

Shouldn't this go into the typo fixes patch at the beginning of
the series?

Otherwise looks fine:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev
  2019-02-01 20:50 ` [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
@ 2019-02-04 14:57   ` Christoph Hellwig
  0 siblings, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 14:57 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:21PM +0100, David Kozub wrote:
> The steps argument is only read by the next function, so it can
> be passed directly as an argument rather than via opal_dev.
> 
> Normally, the steps is an array on the stack, so the pointer stops
> being valid then the function that set opal_dev.steps returns.
> If opal_dev.steps was not set to NULL before return it would become
> a dangling pointer. When the steps are passed as argument this
> becomes easier to see and more difficult to misuse.
> 
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-01 20:50 ` [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
@ 2019-02-04 15:01   ` Christoph Hellwig
  2019-02-04 22:44     ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 15:01 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

> +	/* first do a discovery0 */
> +	error = opal_discovery0_step(dev);
>  
> +	for (state = 0; !error && state < n_steps; state++)
> +		error = execute_step(dev, &steps[state], state);
> +
> +	/*
> +	 * For each OPAL command the first step in steps starts some sort of
> +	 * session. If an error occurred in the initial discovery0 or if an
> +	 * error occurred in the first step (and thus stopping the loop with
> +	 * state == 1) then there was an error before or during the attempt to
> +	 * start a session. Therefore we shouldn't attempt to terminate a
> +	 * session, as one has not yet been created.
> +	 */
> +	if (error && state > 1)
> +		end_opal_session_error(dev);
>  
>  	return error;

The flow here is a little too condensed for my taste.  Why not the
plain obvoious, if a little longer:

	error = error = opal_discovery0_step(dev);
	if (error)
		return error;

	for (state = 0; state < n_steps; state++) {
		error = execute_step(dev, &steps[state], state);
		if (error)
			goto out_error;
	}

	return 0;

out_error:
	if (state > 1)
		end_opal_session_error(dev);
 	return error;

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 16/16] block: sed-opal: rename next to execute_steps
  2019-02-01 20:50 ` [PATCH v4 16/16] block: sed-opal: rename next to execute_steps David Kozub
@ 2019-02-04 15:01   ` Christoph Hellwig
  2019-02-08 22:59   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 15:01 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:23PM +0100, David Kozub wrote:
> As the function is responsible for executing the individual steps supplied
> in the steps argument, execute_steps is a more descriptive name than the
> rather generic next.
> 
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
                   ` (17 preceding siblings ...)
  2019-02-04  9:44 ` [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
@ 2019-02-04 15:04 ` Christoph Hellwig
  2019-02-04 15:36   ` Scott Bauer
  2019-02-04 23:06   ` David Kozub
  18 siblings, 2 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 15:04 UTC (permalink / raw)
  To: David Kozub
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Fri, Feb 01, 2019 at 09:50:07PM +0100, David Kozub wrote:
> This patch series extends SED OPAL support: it adds IOCTL for setting the shadow
> MBR done flag which can be useful for unlocking an OPAL disk on boot and it adds
> IOCTL for writing to the shadow MBR. Also included are some minor fixes and
> improvements.

Actually most of it is really useful cleanups and small fixes for the
existing OPAL code.  Any chance you could resend just those bits as
a first series ASAP?  I'll try to spend some time to to review the
actual feature additions in the meantime.

> There is a fork of sed-opal-temp that can use these new IOCTLs.[2] I tested
> these on Samsung 840 EVO and 850 EVO drives, on x86-64 and arm64 systems.

Which brings up another question:  how do we get a properly maintained
version of the sed-opal tool up ASAP?  It's been a bit bitrotting
unfortunately, and the documentation and error handling hasn't been all
that great to start with.  Are we going to find a good home for it?
Util-linux for example?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-04 15:04 ` Christoph Hellwig
@ 2019-02-04 15:36   ` Scott Bauer
  2019-02-04 15:44     ` Christoph Hellwig
  2019-02-04 23:06   ` David Kozub
  1 sibling, 1 reply; 64+ messages in thread
From: Scott Bauer @ 2019-02-04 15:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: David Kozub, Jens Axboe, Jonathan Derrick, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, Feb 04, 2019 at 07:04:15AM -0800, Christoph Hellwig wrote:
> On Fri, Feb 01, 2019 at 09:50:07PM +0100, David Kozub wrote:
> > This patch series extends SED OPAL support: it adds IOCTL for setting the shadow
> > MBR done flag which can be useful for unlocking an OPAL disk on boot and it adds
> > IOCTL for writing to the shadow MBR. Also included are some minor fixes and
> > improvements.
> 
> Actually most of it is really useful cleanups and small fixes for the
> existing OPAL code.  Any chance you could resend just those bits as
> a first series ASAP?  I'll try to spend some time to to review the
> actual feature additions in the meantime.
> 
> > There is a fork of sed-opal-temp that can use these new IOCTLs.[2] I tested
> > these on Samsung 840 EVO and 850 EVO drives, on x86-64 and arm64 systems.
> 
> Which brings up another question:  how do we get a properly maintained
> version of the sed-opal tool up ASAP?  It's been a bit bitrotting
> unfortunately, and the documentation and error handling hasn't been all
> that great to start with.  Are we going to find a good home for it?
> Util-linux for example?

I would also like to get it off my github and into a proper location as well.

Christoph, do you know off hand how we would get it in util-linux?


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-04 15:36   ` Scott Bauer
@ 2019-02-04 15:44     ` Christoph Hellwig
  0 siblings, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 15:44 UTC (permalink / raw)
  To: Scott Bauer
  Cc: Christoph Hellwig, David Kozub, Jens Axboe, Jonathan Derrick,
	linux-block, linux-kernel, Jonas Rabenstein

On Mon, Feb 04, 2019 at 10:36:10AM -0500, Scott Bauer wrote:
> > Which brings up another question:  how do we get a properly maintained
> > version of the sed-opal tool up ASAP?  It's been a bit bitrotting
> > unfortunately, and the documentation and error handling hasn't been all
> > that great to start with.  Are we going to find a good home for it?
> > Util-linux for example?
> 
> I would also like to get it off my github and into a proper location as well.
> 
> Christoph, do you know off hand how we would get it in util-linux?

Maybe just ask util-linux@vger.kernel.org if they are interested?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 11/16] block: sed-opal: ioctl for writing to shadow mbr
  2019-02-01 20:50 ` [PATCH v4 11/16] block: sed-opal: ioctl for writing to " David Kozub
@ 2019-02-04 17:58   ` kbuild test robot
  2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: kbuild test robot @ 2019-02-04 17:58 UTC (permalink / raw)
  To: David Kozub
  Cc: kbuild-all, Jens Axboe, Jonathan Derrick, Scott Bauer,
	linux-block, linux-kernel, Jonas Rabenstein, David Kozub

[-- Attachment #1: Type: text/plain, Size: 2791 bytes --]

Hi Jonas,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on block/for-next]
[also build test WARNING on v5.0-rc4 next-20190204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/David-Kozub/block-sed-opal-support-shadow-MBR-done-flag-and-write/20190205-005425
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: i386-randconfig-x002-201905 (attached as .config)
compiler: gcc-8 (Debian 8.2.0-14) 8.2.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   block/sed-opal.c: In function 'write_shadow_mbr':
>> block/sed-opal.c:1520:8: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     src = (u8 *) shadow->data;
           ^

vim +1520 block/sed-opal.c

  1509	
  1510	static int write_shadow_mbr(struct opal_dev *dev, void *data)
  1511	{
  1512		struct opal_shadow_mbr *shadow = data;
  1513		const u8 __user *src;
  1514		u8 *dst;
  1515		size_t off = 0;
  1516		u64 len;
  1517		int err = 0;
  1518	
  1519		/* do the actual transmission(s) */
> 1520		src = (u8 *) shadow->data;
  1521		while (off < shadow->size) {
  1522			err = cmd_start(dev, opaluid[OPAL_MBR], opalmethod[OPAL_SET]);
  1523			add_token_u8(&err, dev, OPAL_STARTNAME);
  1524			add_token_u8(&err, dev, OPAL_WHERE);
  1525			add_token_u64(&err, dev, shadow->offset + off);
  1526			add_token_u8(&err, dev, OPAL_ENDNAME);
  1527	
  1528			add_token_u8(&err, dev, OPAL_STARTNAME);
  1529			add_token_u8(&err, dev, OPAL_VALUES);
  1530	
  1531			/*
  1532			 * The bytestring header is either 1 or 2 bytes, so assume 2.
  1533			 * There also needs to be enough space to accommodate the
  1534			 * trailing OPAL_ENDNAME (1 byte) and tokens added by
  1535			 * cmd_finalize.
  1536			 */
  1537			len = min(remaining_size(dev) - (2+1+CMD_FINALIZE_BYTES_NEEDED),
  1538				  (size_t)(shadow->size - off));
  1539			pr_debug("MBR: write bytes %zu+%llu/%llu\n",
  1540				 off, len, shadow->size);
  1541	
  1542			dst = add_bytestring_header(&err, dev, len);
  1543			if (!dst)
  1544				break;
  1545			if (copy_from_user(dst, src + off, len))
  1546				err = -EFAULT;
  1547			dev->pos += len;
  1548	
  1549			add_token_u8(&err, dev, OPAL_ENDNAME);
  1550			if (err)
  1551				break;
  1552	
  1553			err = finalize_and_send(dev, parse_and_check_status);
  1554			if (err)
  1555				break;
  1556	
  1557			off += len;
  1558		}
  1559		return err;
  1560	}
  1561	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32290 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 01/16] block: sed-opal: fix typos and formatting
  2019-02-04 14:42   ` Christoph Hellwig
@ 2019-02-04 20:28     ` David Kozub
  2019-02-08 22:56       ` Derrick, Jonathan
  0 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-04 20:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, 4 Feb 2019, Christoph Hellwig wrote:

> On Fri, Feb 01, 2019 at 09:50:08PM +0100, David Kozub wrote:
>> This should make no change in functionality.
>> The formatting changes were triggered by checkpatch.pl.
>>
>> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
>> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
>> ---
>>  block/sed-opal.c | 19 +++++++++++--------
>>  1 file changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/block/sed-opal.c b/block/sed-opal.c
>> index e0de4dd448b3..c882a193e162 100644
>> --- a/block/sed-opal.c
>> +++ b/block/sed-opal.c
>> @@ -11,8 +11,8 @@
>>   *
>>   * This program is distributed in the hope it will be useful, but WITHOUT
>>   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>> - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>> - * more details.
>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>> + * for more details.
>
> What exactly is the fix here?
>
> If we want to fix the licence boilerplate we should switch it to an
> SPDX tag instead.
>
> Otherwise this looks fine to me.

I thought checkpatch.pl -f block/sed-opal.c complained about the line 
being too long. But when I try that again now (with the original version), 
it does not complain. So I probably saw a ghost.

I'll undo this change.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 03/16] block: sed-opal: unify space check in add_token_*
  2019-02-04 14:44   ` Christoph Hellwig
@ 2019-02-04 21:07     ` David Kozub
  2019-02-04 21:09       ` Christoph Hellwig
  2019-02-08 22:57       ` Derrick, Jonathan
  0 siblings, 2 replies; 64+ messages in thread
From: David Kozub @ 2019-02-04 21:07 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, 4 Feb 2019, Christoph Hellwig wrote:

> On Fri, Feb 01, 2019 at 09:50:10PM +0100, David Kozub wrote:
>> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>>
>> All add_token_* functions have a common set of conditions that have to
>> be checked. Use a common function for those checks in order to avoid
>> different behaviour as well as code duplication.
>>
>> Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
>> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
>> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
>> ---
>>  block/sed-opal.c | 30 +++++++++++++++++++++---------
>>  1 file changed, 21 insertions(+), 9 deletions(-)
>>
>> diff --git a/block/sed-opal.c b/block/sed-opal.c
>> index 5c123a5b4ab1..980705681806 100644
>> --- a/block/sed-opal.c
>> +++ b/block/sed-opal.c
>> @@ -510,15 +510,29 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
>>  	return opal_discovery0_end(dev);
>>  }
>>
>> -static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
>> +static size_t remaining_size(struct opal_dev *cmd)
>> +{
>> +	return IO_BUFFER_LENGTH - cmd->pos;
>> +}
>
> This function seem a little pointless to me, at least as of this patch
> where it only has a single user just below.

It is eventually used for the second time in 11/16 block: sed-opal: ioctl 
for writing to shadow mbr.

If you feel strongly about this I can exclude it from this commit and 
introduce it in 11/16 (where it then will called from here and from 
write_shadow_mbr).

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 03/16] block: sed-opal: unify space check in add_token_*
  2019-02-04 21:07     ` David Kozub
@ 2019-02-04 21:09       ` Christoph Hellwig
  2019-02-08 22:57       ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-04 21:09 UTC (permalink / raw)
  To: David Kozub
  Cc: Christoph Hellwig, Jens Axboe, Jonathan Derrick, Scott Bauer,
	linux-block, linux-kernel, Jonas Rabenstein

On Mon, Feb 04, 2019 at 10:07:09PM +0100, David Kozub wrote:
> It is eventually used for the second time in 11/16 block: sed-opal: ioctl
> for writing to shadow mbr.
> 
> If you feel strongly about this I can exclude it from this commit and
> introduce it in 11/16 (where it then will called from here and from
> write_shadow_mbr).

No problem, just keep it.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-04 15:01   ` Christoph Hellwig
@ 2019-02-04 22:44     ` David Kozub
  2019-02-08 22:59       ` Derrick, Jonathan
  0 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-04 22:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, 4 Feb 2019, Christoph Hellwig wrote:

>> +	/* first do a discovery0 */
>> +	error = opal_discovery0_step(dev);
>>
>> +	for (state = 0; !error && state < n_steps; state++)
>> +		error = execute_step(dev, &steps[state], state);
>> +
>> +	/*
>> +	 * For each OPAL command the first step in steps starts some sort of
>> +	 * session. If an error occurred in the initial discovery0 or if an
>> +	 * error occurred in the first step (and thus stopping the loop with
>> +	 * state == 1) then there was an error before or during the attempt to
>> +	 * start a session. Therefore we shouldn't attempt to terminate a
>> +	 * session, as one has not yet been created.
>> +	 */
>> +	if (error && state > 1)
>> +		end_opal_session_error(dev);
>>
>>  	return error;
>
> The flow here is a little too condensed for my taste.  Why not the
> plain obvoious, if a little longer:
>
> 	error = error = opal_discovery0_step(dev);
> 	if (error)
> 		return error;
>
> 	for (state = 0; state < n_steps; state++) {
> 		error = execute_step(dev, &steps[state], state);
> 		if (error)
> 			goto out_error;
> 	}
>
> 	return 0;
>
> out_error:
> 	if (state > 1)
> 		end_opal_session_error(dev);
> 	return error;

No problem, I can use this version. But I think there is a minor issue - 
the same one I hit in my original change, just from the other direction:

If the loop succeds for the 0-th element of steps, and then fails for the 
1st element, then state equals 1 yet the session has been started, so we 
should close it.

I think the condition in out_error should be if (state > 0).

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-04 15:04 ` Christoph Hellwig
  2019-02-04 15:36   ` Scott Bauer
@ 2019-02-04 23:06   ` David Kozub
  2019-02-05  6:57     ` Christoph Hellwig
  1 sibling, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-04 23:06 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, 4 Feb 2019, Christoph Hellwig wrote:

> On Fri, Feb 01, 2019 at 09:50:07PM +0100, David Kozub wrote:
>> This patch series extends SED OPAL support: it adds IOCTL for setting the shadow
>> MBR done flag which can be useful for unlocking an OPAL disk on boot and it adds
>> IOCTL for writing to the shadow MBR. Also included are some minor fixes and
>> improvements.
>
> Actually most of it is really useful cleanups and small fixes for the
> existing OPAL code.  Any chance you could resend just those bits as
> a first series ASAP?  I'll try to spend some time to to review the
> actual feature additions in the meantime.

OK, I'll try to separate these into two sets.

This will unfortunately trigger some changes (conflict resolving - e.g. if 
I move the last two patches in the current series forward, in front of the 
patches with new functionality). What is the proper procedure w.r.t. 
Reviewed-by tags which were already given? Common sense would make me keep 
them for trivial changes and remove them if the patch should be 
re-reviewed. Is that correct?

>> There is a fork of sed-opal-temp that can use these new IOCTLs.[2] I tested
>> these on Samsung 840 EVO and 850 EVO drives, on x86-64 and arm64 systems.
>
> Which brings up another question:  how do we get a properly maintained
> version of the sed-opal tool up ASAP?  It's been a bit bitrotting
> unfortunately, and the documentation and error handling hasn't been all
> that great to start with.  Are we going to find a good home for it?
> Util-linux for example?

FWIW I also hacked together a tool to cover my usecase: 
https://gitlab.com/zub2/opalctl

The selling point is that it can handle passwords the same way that 
sedutil (https://github.com/Drive-Trust-Alliance/sedutil) does.

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write
  2019-02-04 23:06   ` David Kozub
@ 2019-02-05  6:57     ` Christoph Hellwig
  0 siblings, 0 replies; 64+ messages in thread
From: Christoph Hellwig @ 2019-02-05  6:57 UTC (permalink / raw)
  To: David Kozub
  Cc: Christoph Hellwig, Jens Axboe, Jonathan Derrick, Scott Bauer,
	linux-block, linux-kernel, Jonas Rabenstein

On Tue, Feb 05, 2019 at 12:06:54AM +0100, David Kozub wrote:
> This will unfortunately trigger some changes (conflict resolving - e.g. if I
> move the last two patches in the current series forward, in front of the
> patches with new functionality). What is the proper procedure w.r.t.
> Reviewed-by tags which were already given? Common sense would make me keep
> them for trivial changes and remove them if the patch should be re-reviewed.
> Is that correct?

I don't think there is a general rule.  As long as the change is trivial
I keep them personally, otherwise I drop them.

E.g. if you just remove a few hunk because of new code that isn't
present now I'd keep them, if there are more complex changes to the code
flow I would consider dropping them.

> FWIW I also hacked together a tool to cover my usecase:
> https://gitlab.com/zub2/opalctl
> 
> The selling point is that it can handle passwords the same way that sedutil
> (https://github.com/Drive-Trust-Alliance/sedutil) does.

That actually is pretty nice, as it allows people to migrate over
(not that I've heard of a whole lot of usage of sedutil, but being
compatible to some extent is always nice)

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-04 14:52   ` Christoph Hellwig
@ 2019-02-07 22:56     ` David Kozub
  2019-02-08  0:44       ` Derrick, Jonathan
  0 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-07 22:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block,
	linux-kernel, Jonas Rabenstein

On Mon, 4 Feb 2019, Christoph Hellwig wrote:

> On Fri, Feb 01, 2019 at 09:50:17PM +0100, David Kozub wrote:
>> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>>
>> Enable users to mark the shadow mbr as done without completely
>> deactivating the shadow mbr feature. This may be useful on reboots,
>> when the power to the disk is not disconnected in between and the shadow
>> mbr stores the required boot files. Of course, this saves also the
>> (few) commands required to enable the feature if it is already enabled
>> and one only wants to mark the shadow mbr as done.
>>
>> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
>> ---
>>  block/sed-opal.c              | 33 +++++++++++++++++++++++++++++++--
>>  include/linux/sed-opal.h      |  1 +
>>  include/uapi/linux/sed-opal.h |  1 +
>>  3 files changed, 33 insertions(+), 2 deletions(-)
>>
>> diff --git a/block/sed-opal.c b/block/sed-opal.c
>> index 4b0a63b9d7c9..e03838cfd31b 100644
>> --- a/block/sed-opal.c
>> +++ b/block/sed-opal.c
>> @@ -1996,13 +1996,39 @@ static int opal_erase_locking_range(struct opal_dev *dev,
>>  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
>>  					  struct opal_mbr_data *opal_mbr)
>>  {
>> +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
>> +		? OPAL_TRUE : OPAL_FALSE;
>>  	const struct opal_step mbr_steps[] = {
>>  		{ opal_discovery0, },
>>  		{ start_admin1LSP_opal_session, &opal_mbr->key },
>> -		{ set_mbr_done, &opal_mbr->enable_disable },
>> +		{ set_mbr_done, &token },
>>  		{ end_opal_session, },
>>  		{ start_admin1LSP_opal_session, &opal_mbr->key },
>> -		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
>> +		{ set_mbr_enable_disable, &token },
>> +		{ end_opal_session, },
>> +		{ NULL, }
>
> This seems to be a change of what we pass to set_mbr_done /
> set_mbr_enable_disable and not really related to the new functionality
> here, so it should be split into a separate patch.
>
> That being said if we really care about this translation between
> the two sets of constants, why not do it inside
> set_mbr_done and set_mbr_enable_disable?

Hi Christoph,

I agree, this should be split. Furthermore I think I found an issue here: 
OPAL_MBR_ENABLE and OPAL_MBR_DISABLE are defined as follows:

enum opal_mbr {
 	OPAL_MBR_ENABLE = 0x0,
 	OPAL_MBR_DISABLE = 0x01,
};

... while OPAL_TRUE and OPAL_FALSE tokens are:

 	OPAL_TRUE = 0x01,
 	OPAL_FALSE = 0x00,

so in the current code in kernel, when the IOCTL input is directly passed 
in place of the TRUE/FALSE tokens (in opal_enable_disable_shadow_mbr), 
passing OPAL_MBR_ENABLE (0) to IOC_OPAL_ENABLE_DISABLE_MBR ends up being 
interpreted as OPAL_FALSE (0) and passing OPAL_MBR_DISABLE (1) ended up 
being interpreted as OPAL_TRUE (1). So the behavior is:

OPAL_MBR_ENABLE: set MBR enable to OPAL_FALSE and done to OPAL_FALSE
OPAL_MBR_DISABLE: set MBR enable to OPAL_TRUE and done to OPAL_TRUE

Am I missing something here? This seems wrong to me. And I think this 
patch actually changes it by introducing:

+    u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
+            ? OPAL_TRUE : OPAL_FALSE;

which is essentially a negation (map 0 to 1 and 1 to 0).

I had a strange feeling of IOC_OPAL_ENABLE_DISABLE_MBR behaving 
incorrectly when I first tried it. But when I checked later I was not able 
to reproduce it - probably originally I tested without this patch.

With regard to the new IOC_OPAL_MBR_STATUS: I find the usage of 
OPAL_MBR_ENABLE/DISABLE for this confusing: what should passing 
OPAL_MBR_ENABLE do? Should it enable the shadow MBR? Or should it 
enable the MBR-done flag? I think the implementation in this patch 
interprets OPAL_MBR_ENABLE as 'set the "done" flag to true', thus hiding 
the shadow MBR. But this is not obvious looking at the IOCTL name.

What if I introduced two new constants for this? OPAL_MBR_DONE and 
OPAL_MBR_NOT_DONE? Maybe the IOCTL could be renamed too - 
IOC_OPAL_MBR_DONE? Or is it only me who finds this confusing?

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-07 22:56     ` David Kozub
@ 2019-02-08  0:44       ` Derrick, Jonathan
  2019-02-08  1:37         ` Scott Bauer
  2019-02-10 18:26         ` Scott Bauer
  0 siblings, 2 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08  0:44 UTC (permalink / raw)
  To: hch, zub; +Cc: linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 5965 bytes --]

On Thu, 2019-02-07 at 23:56 +0100, David Kozub wrote:
> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> 
> > On Fri, Feb 01, 2019 at 09:50:17PM +0100, David Kozub wrote:
> > > From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > 
> > > Enable users to mark the shadow mbr as done without completely
> > > deactivating the shadow mbr feature. This may be useful on reboots,
> > > when the power to the disk is not disconnected in between and the shadow
> > > mbr stores the required boot files. Of course, this saves also the
> > > (few) commands required to enable the feature if it is already enabled
> > > and one only wants to mark the shadow mbr as done.
> > > 
> > > Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> > > ---
> > >  block/sed-opal.c              | 33 +++++++++++++++++++++++++++++++--
> > >  include/linux/sed-opal.h      |  1 +
> > >  include/uapi/linux/sed-opal.h |  1 +
> > >  3 files changed, 33 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/block/sed-opal.c b/block/sed-opal.c
> > > index 4b0a63b9d7c9..e03838cfd31b 100644
> > > --- a/block/sed-opal.c
> > > +++ b/block/sed-opal.c
> > > @@ -1996,13 +1996,39 @@ static int opal_erase_locking_range(struct opal_dev *dev,
> > >  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
> > >  					  struct opal_mbr_data *opal_mbr)
> > >  {
> > > +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > > +		? OPAL_TRUE : OPAL_FALSE;
> > >  	const struct opal_step mbr_steps[] = {
> > >  		{ opal_discovery0, },
> > >  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> > > -		{ set_mbr_done, &opal_mbr->enable_disable },
> > > +		{ set_mbr_done, &token },
> > >  		{ end_opal_session, },
> > >  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> > > -		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
> > > +		{ set_mbr_enable_disable, &token },
> > > +		{ end_opal_session, },
> > > +		{ NULL, }
> > 
> > This seems to be a change of what we pass to set_mbr_done /
> > set_mbr_enable_disable and not really related to the new functionality
> > here, so it should be split into a separate patch.
> > 
> > That being said if we really care about this translation between
> > the two sets of constants, why not do it inside
> > set_mbr_done and set_mbr_enable_disable?
> 
> Hi Christoph,
> 
> I agree, this should be split. Furthermore I think I found an issue here: 
> OPAL_MBR_ENABLE and OPAL_MBR_DISABLE are defined as follows:
> 
> enum opal_mbr {
>  	OPAL_MBR_ENABLE = 0x0,
>  	OPAL_MBR_DISABLE = 0x01,
> };
> 
> ... while OPAL_TRUE and OPAL_FALSE tokens are:
> 
>  	OPAL_TRUE = 0x01,
>  	OPAL_FALSE = 0x00,
> 
> so in the current code in kernel, when the IOCTL input is directly passed 
> in place of the TRUE/FALSE tokens (in opal_enable_disable_shadow_mbr), 
> passing OPAL_MBR_ENABLE (0) to IOC_OPAL_ENABLE_DISABLE_MBR ends up being 
> interpreted as OPAL_FALSE (0) and passing OPAL_MBR_DISABLE (1) ended up 
> being interpreted as OPAL_TRUE (1). So the behavior is:
> 
> OPAL_MBR_ENABLE: set MBR enable to OPAL_FALSE and done to OPAL_FALSE
> OPAL_MBR_DISABLE: set MBR enable to OPAL_TRUE and done to OPAL_TRUE
> 
> Am I missing something here? This seems wrong to me. And I think this 
> patch actually changes it by introducing:
> 
> +    u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> +            ? OPAL_TRUE : OPAL_FALSE;
> 
> which is essentially a negation (map 0 to 1 and 1 to 0).
> 
> I had a strange feeling of IOC_OPAL_ENABLE_DISABLE_MBR behaving 
> incorrectly when I first tried it. But when I checked later I was not able 
> to reproduce it - probably originally I tested without this patch.
> 
> With regard to the new IOC_OPAL_MBR_STATUS: I find the usage of 
> OPAL_MBR_ENABLE/DISABLE for this confusing: what should passing 
> OPAL_MBR_ENABLE do? Should it enable the shadow MBR? Or should it 
> enable the MBR-done flag? I think the implementation in this patch 
> interprets OPAL_MBR_ENABLE as 'set the "done" flag to true', thus hiding 
> the shadow MBR. But this is not obvious looking at the IOCTL name.
> 
> What if I introduced two new constants for this? OPAL_MBR_DONE and 
> OPAL_MBR_NOT_DONE? Maybe the IOCTL could be renamed too - 
> IOC_OPAL_MBR_DONE? Or is it only me who finds this confusing?
> 
> Best regards,
> David

Hi David,

Based on the spec and appnote [1], it does look like sed-opal-temp is
providing the inverted value for shadow mbr enable:

        if (cfg.enable_mbr)
                mbr.enable_disable = OPAL_MBR_ENABLE;
        else    
                mbr.enable_disable = OPAL_MBR_DISABLE;

where
enum opal_mbr {
        OPAL_MBR_ENABLE = 0x0,
        OPAL_MBR_DISABLE = 0x01,
};

The appnote says as much:
3.2.9.4
Enable the MBR Shadowing feature
session[TSN:HSN] -> MBRControl_UID.Set[Values = [Enable = TRUE]]
0000 00000000 07FE0000 00000000 00000000
0010 00000048 00001001 00000001 00000000
0020 00000000 00000000 00000030 00000000
0030 00000000 00000024 F8A80000 08030000
0040 0001A800 00000600 000017F0 F201F0F2
0050 0101F3F1 F3F1F9F0 000000F1 00000000
      ^ ^
01: Tiny Atom Token: Name: “Enable”
01: Tiny Atom Token: Value: <1> (True)

In order to keep the userspace interface consistent, I'll ACK your
change in this patch, unless Scott can fill me in on why this looks
wrong but is actually right.

We have 7 bytes in the opal_mbr_data struct we could use for DONE/NOT
DONE. I'm not sure how to go about keeping it consistent with old uapi,
although arguably opal_enable_disable_shadow_mbr is already doing the
wrong thing with DONE and ENABLE so it's low impact.

Acked-by: Jon Derrick <jonathan.derrick@intel.com>

[1] https://trustedcomputinggroup.org/wp-content/uploads/TCG_Storage_Opal_SSC_Application_Note_1-00_1-00-Final.pdf

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-08  0:44       ` Derrick, Jonathan
@ 2019-02-08  1:37         ` Scott Bauer
  2019-02-10 18:26         ` Scott Bauer
  1 sibling, 0 replies; 64+ messages in thread
From: Scott Bauer @ 2019-02-08  1:37 UTC (permalink / raw)
  To: Derrick, Jonathan
  Cc: hch, zub, linux-kernel, linux-block, jonas.rabenstein, axboe

On Fri, Feb 08, 2019 at 12:44:14AM +0000, Derrick, Jonathan wrote:
> On Thu, 2019-02-07 at 23:56 +0100, David Kozub wrote:
> > On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> > 
> > > On Fri, Feb 01, 2019 at 09:50:17PM +0100, David Kozub wrote:
> > > > From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > > 
> > > > Enable users to mark the shadow mbr as done without completely
> > > > deactivating the shadow mbr feature. This may be useful on reboots,
> > > > when the power to the disk is not disconnected in between and the shadow
> > > > mbr stores the required boot files. Of course, this saves also the
> > > > (few) commands required to enable the feature if it is already enabled
> > > > and one only wants to mark the shadow mbr as done.
> > > > 
> > > > Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > > Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> > > > ---
> > > >  block/sed-opal.c              | 33 +++++++++++++++++++++++++++++++--
> > > >  include/linux/sed-opal.h      |  1 +
> > > >  include/uapi/linux/sed-opal.h |  1 +
> > > >  3 files changed, 33 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/block/sed-opal.c b/block/sed-opal.c
> > > > index 4b0a63b9d7c9..e03838cfd31b 100644
> > > > --- a/block/sed-opal.c
> > > > +++ b/block/sed-opal.c
> > > > @@ -1996,13 +1996,39 @@ static int opal_erase_locking_range(struct opal_dev *dev,
> > > >  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
> > > >  					  struct opal_mbr_data *opal_mbr)
> > > >  {
> > > > +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > > > +		? OPAL_TRUE : OPAL_FALSE;
> > > >  	const struct opal_step mbr_steps[] = {
> > > >  		{ opal_discovery0, },
> > > >  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> > > > -		{ set_mbr_done, &opal_mbr->enable_disable },
> > > > +		{ set_mbr_done, &token },
> > > >  		{ end_opal_session, },
> > > >  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> > > > -		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
> > > > +		{ set_mbr_enable_disable, &token },
> > > > +		{ end_opal_session, },
> > > > +		{ NULL, }
> > > 
> > > This seems to be a change of what we pass to set_mbr_done /
> > > set_mbr_enable_disable and not really related to the new functionality
> > > here, so it should be split into a separate patch.
> > > 
> > > That being said if we really care about this translation between
> > > the two sets of constants, why not do it inside
> > > set_mbr_done and set_mbr_enable_disable?
> > 
> > Hi Christoph,
> > 
> > I agree, this should be split. Furthermore I think I found an issue here: 
> > OPAL_MBR_ENABLE and OPAL_MBR_DISABLE are defined as follows:
> > 
> > enum opal_mbr {
> >  	OPAL_MBR_ENABLE = 0x0,
> >  	OPAL_MBR_DISABLE = 0x01,
> > };
> > 
> > ... while OPAL_TRUE and OPAL_FALSE tokens are:
> > 
> >  	OPAL_TRUE = 0x01,
> >  	OPAL_FALSE = 0x00,
> > 
> > so in the current code in kernel, when the IOCTL input is directly passed 
> > in place of the TRUE/FALSE tokens (in opal_enable_disable_shadow_mbr), 
> > passing OPAL_MBR_ENABLE (0) to IOC_OPAL_ENABLE_DISABLE_MBR ends up being 
> > interpreted as OPAL_FALSE (0) and passing OPAL_MBR_DISABLE (1) ended up 
> > being interpreted as OPAL_TRUE (1). So the behavior is:
> > 
> > OPAL_MBR_ENABLE: set MBR enable to OPAL_FALSE and done to OPAL_FALSE
> > OPAL_MBR_DISABLE: set MBR enable to OPAL_TRUE and done to OPAL_TRUE
> > 
> > Am I missing something here? This seems wrong to me. And I think this 
> > patch actually changes it by introducing:
> > 
> > +    u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > +            ? OPAL_TRUE : OPAL_FALSE;
> > 
> > which is essentially a negation (map 0 to 1 and 1 to 0).
> > 
> > I had a strange feeling of IOC_OPAL_ENABLE_DISABLE_MBR behaving 
> > incorrectly when I first tried it. But when I checked later I was not able 
> > to reproduce it - probably originally I tested without this patch.
> > 
> > With regard to the new IOC_OPAL_MBR_STATUS: I find the usage of 
> > OPAL_MBR_ENABLE/DISABLE for this confusing: what should passing 
> > OPAL_MBR_ENABLE do? Should it enable the shadow MBR? Or should it 
> > enable the MBR-done flag? I think the implementation in this patch 
> > interprets OPAL_MBR_ENABLE as 'set the "done" flag to true', thus hiding 
> > the shadow MBR. But this is not obvious looking at the IOCTL name.
> > 
> > What if I introduced two new constants for this? OPAL_MBR_DONE and 
> > OPAL_MBR_NOT_DONE? Maybe the IOCTL could be renamed too - 
> > IOC_OPAL_MBR_DONE? Or is it only me who finds this confusing?
> > 
> > Best regards,
> > David
> 
> Hi David,
> 
> Based on the spec and appnote [1], it does look like sed-opal-temp is
> providing the inverted value for shadow mbr enable:
> 
>         if (cfg.enable_mbr)
>                 mbr.enable_disable = OPAL_MBR_ENABLE;
>         else    
>                 mbr.enable_disable = OPAL_MBR_DISABLE;
> 
> where
> enum opal_mbr {
>         OPAL_MBR_ENABLE = 0x0,
>         OPAL_MBR_DISABLE = 0x01,
> };
> 
> The appnote says as much:
> 3.2.9.4
> Enable the MBR Shadowing feature
> session[TSN:HSN] -> MBRControl_UID.Set[Values = [Enable = TRUE]]
> 0000 00000000 07FE0000 00000000 00000000
> 0010 00000048 00001001 00000001 00000000
> 0020 00000000 00000000 00000030 00000000
> 0030 00000000 00000024 F8A80000 08030000
> 0040 0001A800 00000600 000017F0 F201F0F2
> 0050 0101F3F1 F3F1F9F0 000000F1 00000000
>       ^ ^
> 01: Tiny Atom Token: Name: “Enable”
> 01: Tiny Atom Token: Value: <1> (True)
> 
> In order to keep the userspace interface consistent, I'll ACK your
> change in this patch, unless Scott can fill me in on why this looks
> wrong but is actually right.
> 
> We have 7 bytes in the opal_mbr_data struct we could use for DONE/NOT
> DONE. I'm not sure how to go about keeping it consistent with old uapi,
> although arguably opal_enable_disable_shadow_mbr is already doing the
> wrong thing with DONE and ENABLE so it's low impact.
> 
> Acked-by: Jon Derrick <jonathan.derrick@intel.com>

I don't have a good answer to this right now. I'm going to have to review
this portion of the spec, as well as the implementation to understand what
went wrong.

As for changing UAPI, I know that's usually a no-go, but no one actually
uses this portion of the opal driver as far as I can tell. No distro ships
sed-util, and enabling/disabling the mbr is a one shot deal during initial
bring up. If I had messed up the resume from suspsend portion we wouldn't
be able to change that, as I know people use that. But for this part I think
we'd be okay to do this small modification.

If util-linux, will take a patch for the opal driver, then
we'd be locked in for 5.1 or when ever this lands (as distros would now be
shipping).

Anyway, let me review again whats happened here over the weekend when I have
some free time and mental cycles left to spare.









^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 01/16] block: sed-opal: fix typos and formatting
  2019-02-04 20:28     ` David Kozub
@ 2019-02-08 22:56       ` Derrick, Jonathan
  0 siblings, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:56 UTC (permalink / raw)
  To: hch, zub; +Cc: linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 1624 bytes --]

Looks good otherwise

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Mon, 2019-02-04 at 21:28 +0100, David Kozub wrote:
> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> 
> > On Fri, Feb 01, 2019 at 09:50:08PM +0100, David Kozub wrote:
> > > This should make no change in functionality.
> > > The formatting changes were triggered by checkpatch.pl.
> > > 
> > > Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> > > Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> > > ---
> > >  block/sed-opal.c | 19 +++++++++++--------
> > >  1 file changed, 11 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/block/sed-opal.c b/block/sed-opal.c
> > > index e0de4dd448b3..c882a193e162 100644
> > > --- a/block/sed-opal.c
> > > +++ b/block/sed-opal.c
> > > @@ -11,8 +11,8 @@
> > >   *
> > >   * This program is distributed in the hope it will be useful, but WITHOUT
> > >   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > > - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > > - * more details.
> > > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> > > + * for more details.
> > 
> > What exactly is the fix here?
> > 
> > If we want to fix the licence boilerplate we should switch it to an
> > SPDX tag instead.
> > 
> > Otherwise this looks fine to me.
> 
> I thought checkpatch.pl -f block/sed-opal.c complained about the line 
> being too long. But when I try that again now (with the original version), 
> it does not complain. So I probably saw a ghost.
> 
> I'll undo this change.

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 02/16] block: sed-opal: use correct macro for method length
  2019-02-01 20:50 ` [PATCH v4 02/16] block: sed-opal: use correct macro for method length David Kozub
  2019-02-04 14:43   ` Christoph Hellwig
@ 2019-02-08 22:56   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:56 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 1116 bytes --]

Looks good

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Also the values of OPAL_UID_LENGTH and OPAL_METHOD_LENGTH are the same,
> it is weird to use OPAL_UID_LENGTH for the definition of the methods.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index c882a193e162..5c123a5b4ab1 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -181,7 +181,7 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
>   * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
>   * Section: 6.3 Assigned UIDs
>   */
> -static const u8 opalmethod[][OPAL_UID_LENGTH] = {
> +static const u8 opalmethod[][OPAL_METHOD_LENGTH] = {
>  	[OPAL_PROPERTIES] =
>  		{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01 },
>  	[OPAL_STARTSESSION] =

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 03/16] block: sed-opal: unify space check in add_token_*
  2019-02-04 21:07     ` David Kozub
  2019-02-04 21:09       ` Christoph Hellwig
@ 2019-02-08 22:57       ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:57 UTC (permalink / raw)
  To: hch, zub; +Cc: linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 1945 bytes --]

On Mon, 2019-02-04 at 22:07 +0100, David Kozub wrote:
> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> 
> > On Fri, Feb 01, 2019 at 09:50:10PM +0100, David Kozub wrote:
> > > From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > 
> > > All add_token_* functions have a common set of conditions that have to
> > > be checked. Use a common function for those checks in order to avoid
> > > different behaviour as well as code duplication.
> > > 
> > > Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
> > > Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> > > Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> > > ---
> > >  block/sed-opal.c | 30 +++++++++++++++++++++---------
> > >  1 file changed, 21 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/block/sed-opal.c b/block/sed-opal.c
> > > index 5c123a5b4ab1..980705681806 100644
> > > --- a/block/sed-opal.c
> > > +++ b/block/sed-opal.c
> > > @@ -510,15 +510,29 @@ static int opal_discovery0(struct opal_dev *dev, void *data)
> > >  	return opal_discovery0_end(dev);
> > >  }
> > > 
> > > -static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
> > > +static size_t remaining_size(struct opal_dev *cmd)
> > > +{
> > > +	return IO_BUFFER_LENGTH - cmd->pos;
> > > +}
> > 
> > This function seem a little pointless to me, at least as of this patch
> > where it only has a single user just below.
> 
> It is eventually used for the second time in 11/16 block: sed-opal: ioctl 
> for writing to shadow mbr.
> 
> If you feel strongly about this I can exclude it from this commit and 
> introduce it in 11/16 (where it then will called from here and from 
> write_shadow_mbr).
> 
> Best regards,
> David
I'd prefer this option where we refactor later

Otherwise looks good
Reviewed-by Jon Derrick <jonathan.derrick@intel.com>

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize
  2019-02-01 20:50 ` [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
  2019-02-04 14:44   ` Christoph Hellwig
@ 2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:57 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 7275 bytes --]

Normally I wouldn't like decreasing the readability (having a STARTLIST
without an ENDLIST in the same function), but this makes a lot of sense
with 5/16

Acked-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> Every step ends by calling cmd_finalize (via finalize_and_send)
> yet every step adds the token OPAL_ENDLIST on its own. Moving
> this into cmd_finalize decreases code duplication.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 25 +++----------------------
>  1 file changed, 3 insertions(+), 22 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 980705681806..35b1747b650f 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -661,6 +661,9 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
>  	struct opal_header *hdr;
>  	int err = 0;
>  
> +	/* close parameter list */
> +	add_token_u8(&err, cmd, OPAL_ENDLIST);
> +
>  	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
>  	add_token_u8(&err, cmd, OPAL_STARTLIST);
>  	add_token_u8(&err, cmd, 0);
> @@ -1079,7 +1082,6 @@ static int gen_key(struct opal_dev *dev, void *data)
>  	add_token_bytestring(&err, dev, opalmethod[OPAL_GENKEY],
>  			     OPAL_UID_LENGTH);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building gen key command\n");
> @@ -1142,7 +1144,6 @@ static int get_active_key(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, 10); /* ActiveKey */
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	if (err) {
>  		pr_debug("Error building get active key command\n");
>  		return err;
> @@ -1188,7 +1189,6 @@ static int generic_lr_enable_disable(struct opal_dev *dev,
>  
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	return err;
>  }
>  
> @@ -1254,8 +1254,6 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
>  
>  		add_token_u8(&err, dev, OPAL_ENDLIST);
>  		add_token_u8(&err, dev, OPAL_ENDNAME);
> -		add_token_u8(&err, dev, OPAL_ENDLIST);
> -
>  	}
>  	if (err) {
>  		pr_debug("Error building Setup Locking range command.\n");
> @@ -1295,7 +1293,6 @@ static int start_generic_opal_session(struct opal_dev *dev,
>  
>  	switch (auth) {
>  	case OPAL_ANYBODY_UID:
> -		add_token_u8(&err, dev, OPAL_ENDLIST);
>  		break;
>  	case OPAL_ADMIN1_UID:
>  	case OPAL_SID_UID:
> @@ -1308,7 +1305,6 @@ static int start_generic_opal_session(struct opal_dev *dev,
>  		add_token_bytestring(&err, dev, opaluid[auth],
>  				     OPAL_UID_LENGTH);
>  		add_token_u8(&err, dev, OPAL_ENDNAME);
> -		add_token_u8(&err, dev, OPAL_ENDLIST);
>  		break;
>  	default:
>  		pr_debug("Cannot start Admin SP session with auth %d\n", auth);
> @@ -1406,7 +1402,6 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, 3);
>  	add_token_bytestring(&err, dev, lk_ul_user, OPAL_UID_LENGTH);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building STARTSESSION command.\n");
> @@ -1429,7 +1424,6 @@ static int revert_tper(struct opal_dev *dev, void *data)
>  	add_token_bytestring(&err, dev, opalmethod[OPAL_REVERT],
>  			     OPAL_UID_LENGTH);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	if (err) {
>  		pr_debug("Error building REVERT TPER command.\n");
>  		return err;
> @@ -1463,7 +1457,6 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building Activate UserN command.\n");
> @@ -1490,7 +1483,6 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
>  	add_token_bytestring(&err, dev, opalmethod[OPAL_ERASE],
>  			     OPAL_UID_LENGTH);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building Erase Locking Range Command.\n");
> @@ -1521,7 +1513,6 @@ static int set_mbr_done(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error Building set MBR Done command\n");
> @@ -1553,7 +1544,6 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error Building set MBR done command\n");
> @@ -1585,7 +1575,6 @@ static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	return err;
>  }
> @@ -1694,7 +1683,6 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building add user to locking range command.\n");
> @@ -1755,7 +1743,6 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
>  
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
>  		pr_debug("Error building SET command.\n");
> @@ -1843,11 +1830,8 @@ static int activate_lsp(struct opal_dev *dev, void *data)
>  		}
>  		add_token_u8(&err, dev, OPAL_ENDLIST);
>  		add_token_u8(&err, dev, OPAL_ENDNAME);
> -		add_token_u8(&err, dev, OPAL_ENDLIST);
> -
>  	} else {
>  		add_token_u8(&err, dev, OPAL_STARTLIST);
> -		add_token_u8(&err, dev, OPAL_ENDLIST);
>  	}
>  
>  	if (err) {
> @@ -1904,7 +1888,6 @@ static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, 6); /* Lifecycle Column */
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
>  
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {
> @@ -1964,8 +1947,6 @@ static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
>  	add_token_u8(&err, dev, 4); /* End Column */
>  	add_token_u8(&err, dev, 3); /* Lifecycle Column */
>  	add_token_u8(&err, dev, OPAL_ENDNAME);
> -
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
>  	add_token_u8(&err, dev, OPAL_ENDLIST);
>  
>  	if (err) {

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 05/16] block: sed-opal: unify cmd start
  2019-02-01 20:50 ` [PATCH v4 05/16] block: sed-opal: unify cmd start David Kozub
  2019-02-04 14:45   ` Christoph Hellwig
@ 2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:57 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 16882 bytes --]

Looks fine with 4/16

Acked-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> Every step starts with resetting the cmd buffer as well as the comid and
> constructs the appropriate OPAL_CALL command. Consequently, those
> actions may be combined into one generic function. On should take care
> that the opening and closing tokens for the argument list are already
> emitted by cmd_start and cmd_finalize respectively and thus must not be
> additionally added.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 228 ++++++++++++++---------------------------------
>  1 file changed, 69 insertions(+), 159 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 35b1747b650f..e29cb2f445ff 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -661,7 +661,7 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
>  	struct opal_header *hdr;
>  	int err = 0;
>  
> -	/* close parameter list */
> +	/* close the parameter list opened from cmd_start */
>  	add_token_u8(&err, cmd, OPAL_ENDLIST);
>  
>  	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
> @@ -1006,6 +1006,27 @@ static void clear_opal_cmd(struct opal_dev *dev)
>  	memset(dev->cmd, 0, IO_BUFFER_LENGTH);
>  }
>  
> +static int cmd_start(struct opal_dev *dev, const u8 *uid, const u8 *method)
> +{
> +	int err = 0;
> +
> +	clear_opal_cmd(dev);
> +	set_comid(dev, dev->comid);
> +
> +	add_token_u8(&err, dev, OPAL_CALL);
> +	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> +	add_token_bytestring(&err, dev, method, OPAL_METHOD_LENGTH);
> +
> +	/*
> +	 * Every method call is followed by its parameters enclosed within
> +	 * OPAL_STARTLIST and OPAL_ENDLIST tokens. We automatically open the
> +	 * parameter list here and close it later in cmd_finalize.
> +	 */
> +	add_token_u8(&err, dev, OPAL_STARTLIST);
> +
> +	return err;
> +}
> +
>  static int start_opal_session_cont(struct opal_dev *dev)
>  {
>  	u32 hsn, tsn;
> @@ -1068,20 +1089,13 @@ static int finalize_and_send(struct opal_dev *dev, cont_fn cont)
>  static int gen_key(struct opal_dev *dev, void *data)
>  {
>  	u8 uid[OPAL_UID_LENGTH];
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
>  	memcpy(uid, dev->prev_data, min(sizeof(uid), dev->prev_d_len));
>  	kfree(dev->prev_data);
>  	dev->prev_data = NULL;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_GENKEY],
> -			     OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, uid, opalmethod[OPAL_GENKEY]);
>  
>  	if (err) {
>  		pr_debug("Error building gen key command\n");
> @@ -1119,21 +1133,14 @@ static int get_active_key_cont(struct opal_dev *dev)
>  static int get_active_key(struct opal_dev *dev, void *data)
>  {
>  	u8 uid[OPAL_UID_LENGTH];
> -	int err = 0;
> +	int err;
>  	u8 *lr = data;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> -
>  	err = build_locking_range(uid, sizeof(uid), *lr);
>  	if (err)
>  		return err;
>  
> -	err = 0;
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, uid, opalmethod[OPAL_GET]);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, 3); /* startCloumn */
> @@ -1156,13 +1163,10 @@ static int generic_lr_enable_disable(struct opal_dev *dev,
>  				     u8 *uid, bool rle, bool wle,
>  				     bool rl, bool wl)
>  {
> -	int err = 0;
> +	int err;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
> +	err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
>  
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1209,10 +1213,7 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
>  	u8 uid[OPAL_UID_LENGTH];
>  	struct opal_user_lr_setup *setup = data;
>  	u8 lr;
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
>  	lr = setup->session.opal_key.lr;
>  	err = build_locking_range(uid, sizeof(uid), lr);
> @@ -1222,12 +1223,8 @@ static int setup_locking_range(struct opal_dev *dev, void *data)
>  	if (lr == 0)
>  		err = enable_global_lr(dev, uid, setup);
>  	else {
> -		add_token_u8(&err, dev, OPAL_CALL);
> -		add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -		add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
> -				     OPAL_UID_LENGTH);
> +		err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
>  
> -		add_token_u8(&err, dev, OPAL_STARTLIST);
>  		add_token_u8(&err, dev, OPAL_STARTNAME);
>  		add_token_u8(&err, dev, OPAL_VALUES);
>  		add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1271,22 +1268,15 @@ static int start_generic_opal_session(struct opal_dev *dev,
>  				      u8 key_len)
>  {
>  	u32 hsn;
> -	int err = 0;
> +	int err;
>  
>  	if (key == NULL && auth != OPAL_ANYBODY_UID)
>  		return OPAL_INVAL_PARAM;
>  
> -	clear_opal_cmd(dev);
> -
> -	set_comid(dev, dev->comid);
>  	hsn = GENERIC_HOST_SESSION_NUM;
> +	err = cmd_start(dev, opaluid[OPAL_SMUID_UID],
> +			opalmethod[OPAL_STARTSESSION]);
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_SMUID_UID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_STARTSESSION],
> -			     OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u64(&err, dev, hsn);
>  	add_token_bytestring(&err, dev, opaluid[sp_type], OPAL_UID_LENGTH);
>  	add_token_u8(&err, dev, 1);
> @@ -1366,30 +1356,21 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
>  	u8 *key = session->opal_key.key;
>  	u32 hsn = GENERIC_HOST_SESSION_NUM;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> -
> -	if (session->sum) {
> +	if (session->sum)
>  		err = build_locking_user(lk_ul_user, sizeof(lk_ul_user),
>  					 session->opal_key.lr);
> -		if (err)
> -			return err;
> -
> -	} else if (session->who != OPAL_ADMIN1 && !session->sum) {
> +	else if (session->who != OPAL_ADMIN1 && !session->sum)
>  		err = build_locking_user(lk_ul_user, sizeof(lk_ul_user),
>  					 session->who - 1);
> -		if (err)
> -			return err;
> -	} else
> +	else
>  		memcpy(lk_ul_user, opaluid[OPAL_ADMIN1_UID], OPAL_UID_LENGTH);
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_SMUID_UID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_STARTSESSION],
> -			     OPAL_UID_LENGTH);
> +	if (err)
> +		return err;
> +
> +	err = cmd_start(dev, opaluid[OPAL_SMUID_UID],
> +			opalmethod[OPAL_STARTSESSION]);
>  
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u64(&err, dev, hsn);
>  	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
>  			     OPAL_UID_LENGTH);
> @@ -1413,17 +1394,10 @@ static int start_auth_opal_session(struct opal_dev *dev, void *data)
>  
>  static int revert_tper(struct opal_dev *dev, void *data)
>  {
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_ADMINSP_UID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_REVERT],
> -			     OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, opaluid[OPAL_ADMINSP_UID],
> +			opalmethod[OPAL_REVERT]);
>  	if (err) {
>  		pr_debug("Error building REVERT TPER command.\n");
>  		return err;
> @@ -1436,18 +1410,12 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
>  {
>  	struct opal_session_info *session = data;
>  	u8 uid[OPAL_UID_LENGTH];
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
>  	memcpy(uid, opaluid[OPAL_USER1_UID], OPAL_UID_LENGTH);
>  	uid[7] = session->who;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, uid, opalmethod[OPAL_SET]);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1470,19 +1438,12 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
>  {
>  	struct opal_session_info *session = data;
>  	u8 uid[OPAL_UID_LENGTH];
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
>  	if (build_locking_range(uid, sizeof(uid), session->opal_key.lr) < 0)
>  		return -ERANGE;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_ERASE],
> -			     OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, uid, opalmethod[OPAL_ERASE]);
>  
>  	if (err) {
>  		pr_debug("Error building Erase Locking Range Command.\n");
> @@ -1494,16 +1455,11 @@ static int erase_locking_range(struct opal_dev *dev, void *data)
>  static int set_mbr_done(struct opal_dev *dev, void *data)
>  {
>  	u8 *mbr_done_tf = data;
> -	int err = 0;
> +	int err;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	err = cmd_start(dev, opaluid[OPAL_MBRCONTROL],
> +			opalmethod[OPAL_SET]);
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_MBRCONTROL],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1525,16 +1481,11 @@ static int set_mbr_done(struct opal_dev *dev, void *data)
>  static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
>  {
>  	u8 *mbr_en_dis = data;
> -	int err = 0;
> +	int err;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	err = cmd_start(dev, opaluid[OPAL_MBRCONTROL],
> +			opalmethod[OPAL_SET]);
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_MBRCONTROL],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1556,16 +1507,10 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
>  static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
>  			  struct opal_dev *dev)
>  {
> -	int err = 0;
> +	int err;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	err = cmd_start(dev, cpin_uid, opalmethod[OPAL_SET]);
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, cpin_uid, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
> -			     OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1622,10 +1567,7 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
>  	u8 lr_buffer[OPAL_UID_LENGTH];
>  	u8 user_uid[OPAL_UID_LENGTH];
>  	struct opal_lock_unlock *lkul = data;
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
>  	memcpy(lr_buffer, opaluid[OPAL_LOCKINGRANGE_ACE_RDLOCKED],
>  	       OPAL_UID_LENGTH);
> @@ -1640,12 +1582,8 @@ static int add_user_to_lr(struct opal_dev *dev, void *data)
>  
>  	user_uid[7] = lkul->session.who;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, lr_buffer, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET],
> -			     OPAL_UID_LENGTH);
> +	err = cmd_start(dev, lr_buffer, opalmethod[OPAL_SET]);
>  
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  
> @@ -1699,9 +1637,6 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
>  	u8 read_locked = 1, write_locked = 1;
>  	int err = 0;
>  
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> -
>  	if (build_locking_range(lr_buffer, sizeof(lr_buffer),
>  				lkul->session.opal_key.lr) < 0)
>  		return -ERANGE;
> @@ -1723,10 +1658,8 @@ static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
>  		return OPAL_INVAL_PARAM;
>  	}
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, lr_buffer, OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_SET], OPAL_UID_LENGTH);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> +	err = cmd_start(dev, lr_buffer, opalmethod[OPAL_SET]);
> +
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, OPAL_VALUES);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> @@ -1797,17 +1730,10 @@ static int activate_lsp(struct opal_dev *dev, void *data)
>  	struct opal_lr_act *opal_act = data;
>  	u8 user_lr[OPAL_UID_LENGTH];
>  	u8 uint_3 = 0x83;
> -	int err = 0, i;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> -
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_ACTIVATE],
> -			     OPAL_UID_LENGTH);
> +	int err, i;
>  
> +	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
> +			opalmethod[OPAL_ACTIVATE]);
>  
>  	if (opal_act->sum) {
>  		err = build_locking_range(user_lr, sizeof(user_lr),
> @@ -1815,7 +1741,6 @@ static int activate_lsp(struct opal_dev *dev, void *data)
>  		if (err)
>  			return err;
>  
> -		add_token_u8(&err, dev, OPAL_STARTLIST);
>  		add_token_u8(&err, dev, OPAL_STARTNAME);
>  		add_token_u8(&err, dev, uint_3);
>  		add_token_u8(&err, dev, 6);
> @@ -1830,8 +1755,6 @@ static int activate_lsp(struct opal_dev *dev, void *data)
>  		}
>  		add_token_u8(&err, dev, OPAL_ENDLIST);
>  		add_token_u8(&err, dev, OPAL_ENDNAME);
> -	} else {
> -		add_token_u8(&err, dev, OPAL_STARTLIST);
>  	}
>  
>  	if (err) {
> @@ -1865,17 +1788,11 @@ static int get_lsp_lifecycle_cont(struct opal_dev *dev)
>  /* Determine if we're in the Manufactured Inactive or Active state */
>  static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
>  {
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_LOCKINGSP_UID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
> +	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
> +			opalmethod[OPAL_GET]);
>  
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
>  
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
> @@ -1925,19 +1842,12 @@ static int get_msid_cpin_pin_cont(struct opal_dev *dev)
>  
>  static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
>  {
> -	int err = 0;
> -
> -	clear_opal_cmd(dev);
> -	set_comid(dev, dev->comid);
> +	int err;
>  
> -	add_token_u8(&err, dev, OPAL_CALL);
> -	add_token_bytestring(&err, dev, opaluid[OPAL_C_PIN_MSID],
> -			     OPAL_UID_LENGTH);
> -	add_token_bytestring(&err, dev, opalmethod[OPAL_GET], OPAL_UID_LENGTH);
> +	err = cmd_start(dev, opaluid[OPAL_C_PIN_MSID],
> +			opalmethod[OPAL_GET]);
>  
>  	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> -
>  	add_token_u8(&err, dev, OPAL_STARTNAME);
>  	add_token_u8(&err, dev, 3); /* Start Column */
>  	add_token_u8(&err, dev, 3); /* PIN */

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication
  2019-02-01 20:50 ` [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
  2019-02-04 14:46   ` Christoph Hellwig
@ 2019-02-08 22:57   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:57 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 3237 bytes --]

Looks good

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> response_get_token had already been in place, its functionality had
> been duplicated within response_get_{u64,bytestring} with the same error
> handling. Unify the handling by reusing response_get_token within the
> other functions.
> 
> Co-authored-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 46 +++++++++++++++-------------------------------
>  1 file changed, 15 insertions(+), 31 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 537cd73ea88a..1332547e5a99 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -889,27 +889,19 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
>  				  const char **store)
>  {
>  	u8 skip;
> -	const struct opal_resp_tok *token;
> +	const struct opal_resp_tok *tok;
>  
>  	*store = NULL;
> -	if (!resp) {
> -		pr_debug("Response is NULL\n");
> -		return 0;
> -	}
> -
> -	if (n >= resp->num) {
> -		pr_debug("Response has %d tokens. Can't access %d\n",
> -			 resp->num, n);
> +	tok = response_get_token(resp, n);
> +	if (IS_ERR(tok))
>  		return 0;
> -	}
>  
> -	token = &resp->toks[n];
> -	if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
> +	if (tok->type != OPAL_DTA_TOKENID_BYTESTRING) {
>  		pr_debug("Token is not a byte string!\n");
>  		return 0;
>  	}
>  
> -	switch (token->width) {
> +	switch (tok->width) {
>  	case OPAL_WIDTH_TINY:
>  	case OPAL_WIDTH_SHORT:
>  		skip = 1;
> @@ -925,37 +917,29 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
>  		return 0;
>  	}
>  
> -	*store = token->pos + skip;
> -	return token->len - skip;
> +	*store = tok->pos + skip;
> +	return tok->len - skip;
>  }
>  
>  static u64 response_get_u64(const struct parsed_resp *resp, int n)
>  {
> -	if (!resp) {
> -		pr_debug("Response is NULL\n");
> -		return 0;
> -	}
> +	const struct opal_resp_tok *tok;
>  
> -	if (n >= resp->num) {
> -		pr_debug("Response has %d tokens. Can't access %d\n",
> -			 resp->num, n);
> +	tok = response_get_token(resp, n);
> +	if (IS_ERR(tok))
>  		return 0;
> -	}
>  
> -	if (resp->toks[n].type != OPAL_DTA_TOKENID_UINT) {
> -		pr_debug("Token is not unsigned it: %d\n",
> -			 resp->toks[n].type);
> +	if (tok->type != OPAL_DTA_TOKENID_UINT) {
> +		pr_debug("Token is not unsigned int: %d\n", tok->type);
>  		return 0;
>  	}
>  
> -	if (!(resp->toks[n].width == OPAL_WIDTH_TINY ||
> -	      resp->toks[n].width == OPAL_WIDTH_SHORT)) {
> -		pr_debug("Atom is not short or tiny: %d\n",
> -			 resp->toks[n].width);
> +	if (tok->width != OPAL_WIDTH_TINY && tok->width != OPAL_WIDTH_SHORT) {
> +		pr_debug("Atom is not short or tiny: %d\n", tok->width);
>  		return 0;
>  	}
>  
> -	return resp->toks[n].stored.u;
> +	return tok->stored.u;
>  }
>  
>  static bool response_token_matches(const struct opal_resp_tok *token, u8 match)

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content
  2019-02-01 20:50 ` [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content David Kozub
  2019-02-04 14:48   ` Christoph Hellwig
@ 2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:58 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 2263 bytes --]

Looks good

Reviewed-by Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Split the header generation from the (normal) memcpy part if a
> bytestring is copied into the command buffer. This allows in-place
> generation of the bytestring content. For example, copy_from_user may be
> used without an intermediate buffer.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 4225f23b2165..4b0a63b9d7c9 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -586,14 +586,11 @@ static void add_token_u64(int *err, struct opal_dev *cmd, u64 number)
>  		add_token_u8(err, cmd, number >> (len * 8));
>  }
>  
> -static void add_token_bytestring(int *err, struct opal_dev *cmd,
> -				 const u8 *bytestring, size_t len)
> +static u8 *add_bytestring_header(int *err, struct opal_dev *cmd, size_t len)
>  {
>  	size_t header_len = 1;
>  	bool is_short_atom = true;
> -
> -	if (*err)
> -		return;
> +	char *start;
>  
>  	if (len & ~SHORT_ATOM_LEN_MASK) {
>  		header_len = 2;
> @@ -602,17 +599,27 @@ static void add_token_bytestring(int *err, struct opal_dev *cmd,
>  
>  	if (!can_add(err, cmd, header_len + len)) {
>  		pr_debug("Error adding bytestring: end of buffer.\n");
> -		return;
> +		return NULL;
>  	}
>  
>  	if (is_short_atom)
>  		add_short_atom_header(cmd, true, false, len);
>  	else
>  		add_medium_atom_header(cmd, true, false, len);
> +	start = &cmd->cmd[cmd->pos];
> +	return start;
> +}
>  
> -	memcpy(&cmd->cmd[cmd->pos], bytestring, len);
> -	cmd->pos += len;
> +static void add_token_bytestring(int *err, struct opal_dev *cmd,
> +				 const u8 *bytestring, size_t len)
> +{
> +	u8 *start;
>  
> +	start = add_bytestring_header(err, cmd, len);
> +	if (!start)
> +		return;
> +	memcpy(start, bytestring, len);
> +	cmd->pos += len;
>  }
>  
>  static int build_locking_range(u8 *buffer, size_t length, u8 lr)

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 11/16] block: sed-opal: ioctl for writing to shadow mbr
  2019-02-01 20:50 ` [PATCH v4 11/16] block: sed-opal: ioctl for writing to " David Kozub
  2019-02-04 17:58   ` kbuild test robot
@ 2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:58 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 6313 bytes --]

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Allow modification of the shadow mbr. If the shadow mbr is not marked as
> done, this data will be presented read only as the device content. Only
> after marking the shadow mbr as done and unlocking a locking range the
> actual content is accessible.
> 
> Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++++++-
>  include/linux/sed-opal.h      |  1 +
>  include/uapi/linux/sed-opal.h |  8 ++++
>  3 files changed, 97 insertions(+), 1 deletion(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index e03838cfd31b..88c84906ce98 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -34,6 +34,9 @@
>  #define IO_BUFFER_LENGTH 2048
>  #define MAX_TOKS 64
>  
> +/* Number of bytes needed by cmd_finalize. */
> +#define CMD_FINALIZE_BYTES_NEEDED 7
> +
>  struct opal_step {
>  	int (*fn)(struct opal_dev *dev, void *data);
>  	void *data;
> @@ -668,7 +671,11 @@ static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
>  	struct opal_header *hdr;
>  	int err = 0;
>  
> -	/* close the parameter list opened from cmd_start */
> +	/*
> +	 * Close the parameter list opened from cmd_start.
> +	 * The number of bytes added must be equal to
> +	 * CMD_FINALIZE_BYTES_NEEDED.
> +	 */
>  	add_token_u8(&err, cmd, OPAL_ENDLIST);
>  
>  	add_token_u8(&err, cmd, OPAL_ENDOFDATA);
> @@ -1500,6 +1507,58 @@ static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
>  	return finalize_and_send(dev, parse_and_check_status);
>  }
>  
> +static int write_shadow_mbr(struct opal_dev *dev, void *data)
> +{
> +	struct opal_shadow_mbr *shadow = data;
> +	const u8 __user *src;
> +	u8 *dst;
> +	size_t off = 0;
> +	u64 len;
> +	int err = 0;
> +
> +	/* do the actual transmission(s) */
> +	src = (u8 *) shadow->data;
> +	while (off < shadow->size) {
> +		err = cmd_start(dev, opaluid[OPAL_MBR], opalmethod[OPAL_SET]);
> +		add_token_u8(&err, dev, OPAL_STARTNAME);
> +		add_token_u8(&err, dev, OPAL_WHERE);
> +		add_token_u64(&err, dev, shadow->offset + off);
> +		add_token_u8(&err, dev, OPAL_ENDNAME);
> +
> +		add_token_u8(&err, dev, OPAL_STARTNAME);
> +		add_token_u8(&err, dev, OPAL_VALUES);
> +
> +		/*
> +		 * The bytestring header is either 1 or 2 bytes, so assume 2.
> +		 * There also needs to be enough space to accommodate the
> +		 * trailing OPAL_ENDNAME (1 byte) and tokens added by
> +		 * cmd_finalize.
> +		 */
> +		len = min(remaining_size(dev) - (2+1+CMD_FINALIZE_BYTES_NEEDED),
> +			  (size_t)(shadow->size - off));
> +		pr_debug("MBR: write bytes %zu+%llu/%llu\n",
> +			 off, len, shadow->size);
> +
> +		dst = add_bytestring_header(&err, dev, len);
> +		if (!dst)
> +			break;
> +		if (copy_from_user(dst, src + off, len))
> +			err = -EFAULT;
> +		dev->pos += len;
> +
> +		add_token_u8(&err, dev, OPAL_ENDNAME);
> +		if (err)
> +			break;
> +
> +		err = finalize_and_send(dev, parse_and_check_status);
> +		if (err)
> +			break;
> +
> +		off += len;
> +	}
> +	return err;
> +}
> +
>  static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
>  			  struct opal_dev *dev)
>  {
> @@ -2045,6 +2104,31 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
>  	return ret;
>  }
>  
> +static int opal_write_shadow_mbr(struct opal_dev *dev,
> +				 struct opal_shadow_mbr *info)
> +{
> +	const struct opal_step mbr_steps[] = {
> +		{ opal_discovery0, },
> +		{ start_admin1LSP_opal_session, &info->key },
> +		{ write_shadow_mbr, info },
> +		{ end_opal_session, },
> +		{ NULL, }
> +	};
> +	int ret;
> +
> +	if (info->size == 0)
> +		return 0;
> +
> +	if (!access_ok(info->data, info->size))
> +		return -EINVAL;
-EFAULT?

> +
> +	mutex_lock(&dev->dev_lock);
> +	setup_opal_dev(dev, mbr_steps);
> +	ret = next(dev);
> +	mutex_unlock(&dev->dev_lock);
> +	return ret;
> +}
> +
>  static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
>  {
>  	struct opal_suspend_data *suspend;
> @@ -2378,6 +2462,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
>  	case IOC_OPAL_MBR_STATUS:
>  		ret = opal_mbr_status(dev, p);
>  		break;
> +	case IOC_OPAL_WRITE_SHADOW_MBR:
> +		ret = opal_write_shadow_mbr(dev, p);
> +		break;
>  	case IOC_OPAL_ERASE_LR:
>  		ret = opal_erase_locking_range(dev, p);
>  		break;
> diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
> index b38dc602cae3..cf08cdc13cbd 100644
> --- a/include/linux/sed-opal.h
> +++ b/include/linux/sed-opal.h
> @@ -47,6 +47,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
>  	case IOC_OPAL_ENABLE_DISABLE_MBR:
>  	case IOC_OPAL_ERASE_LR:
>  	case IOC_OPAL_SECURE_ERASE_LR:
> +	case IOC_OPAL_WRITE_SHADOW_MBR:
>  	case IOC_OPAL_MBR_STATUS:
>  		return true;
>  	}
> diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
> index 0cb9890cdc04..8e84307f66d4 100644
> --- a/include/uapi/linux/sed-opal.h
> +++ b/include/uapi/linux/sed-opal.h
> @@ -104,6 +104,13 @@ struct opal_mbr_data {
>  	__u8 __align[7];
>  };
>  
> +struct opal_shadow_mbr {
> +	struct opal_key key;
> +	const __u64 data;
> +	__u64 offset;
> +	__u64 size;
> +};
> +
>  #define IOC_OPAL_SAVE		    _IOW('p', 220, struct opal_lock_unlock)
>  #define IOC_OPAL_LOCK_UNLOCK	    _IOW('p', 221, struct opal_lock_unlock)
>  #define IOC_OPAL_TAKE_OWNERSHIP	    _IOW('p', 222, struct opal_key)
> @@ -117,5 +124,6 @@ struct opal_mbr_data {
>  #define IOC_OPAL_ERASE_LR           _IOW('p', 230, struct opal_session_info)
>  #define IOC_OPAL_SECURE_ERASE_LR    _IOW('p', 231, struct opal_session_info)
>  #define IOC_OPAL_MBR_STATUS         _IOW('p', 232, struct opal_mbr_data)
> +#define IOC_OPAL_WRITE_SHADOW_MBR   _IOW('p', 233, struct opal_shadow_mbr)
>  
>  #endif /* _UAPI_SED_OPAL_H */
Otherwise looks good

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>


[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns
  2019-02-01 20:50 ` [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns David Kozub
  2019-02-04 14:56   ` Christoph Hellwig
@ 2019-02-08 22:58   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:58 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 7050 bytes --]

Looks good

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Instead of having multiple places defining the same argument list to get
> a specific column of a sed-opal table, provide a generic version and
> call it from those functions.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/opal_proto.h |   2 +
>  block/sed-opal.c   | 132 +++++++++++++++++----------------------------
>  2 files changed, 50 insertions(+), 84 deletions(-)
> 
> diff --git a/block/opal_proto.h b/block/opal_proto.h
> index e20be8258854..b6e352cfe982 100644
> --- a/block/opal_proto.h
> +++ b/block/opal_proto.h
> @@ -170,6 +170,8 @@ enum opal_token {
>  	OPAL_READLOCKED = 0x07,
>  	OPAL_WRITELOCKED = 0x08,
>  	OPAL_ACTIVEKEY = 0x0A,
> +	/* lockingsp table */
> +	OPAL_LIFECYCLE = 0x06,
>  	/* locking info table */
>  	OPAL_MAXRANGES = 0x04,
>  	 /* mbr control */
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 88c84906ce98..2459ac4d523b 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -1089,6 +1089,37 @@ static int finalize_and_send(struct opal_dev *dev, cont_fn cont)
>  	return opal_send_recv(dev, cont);
>  }
>  
> +/*
> + * request @column from table @table on device @dev. On success, the column
> + * data will be available in dev->resp->tok[4]
> + */
> +static int generic_get_column(struct opal_dev *dev, const u8 *table,
> +			      u64 column)
> +{
> +	int err;
> +
> +	err = cmd_start(dev, table, opalmethod[OPAL_GET]);
> +
> +	add_token_u8(&err, dev, OPAL_STARTLIST);
> +
> +	add_token_u8(&err, dev, OPAL_STARTNAME);
> +	add_token_u8(&err, dev, OPAL_STARTCOLUMN);
> +	add_token_u64(&err, dev, column);
> +	add_token_u8(&err, dev, OPAL_ENDNAME);
> +
> +	add_token_u8(&err, dev, OPAL_STARTNAME);
> +	add_token_u8(&err, dev, OPAL_ENDCOLUMN);
> +	add_token_u64(&err, dev, column);
> +	add_token_u8(&err, dev, OPAL_ENDNAME);
> +
> +	add_token_u8(&err, dev, OPAL_ENDLIST);
> +
> +	if (err)
> +		return err;
> +
> +	return finalize_and_send(dev, parse_and_check_status);
> +}
> +
>  static int gen_key(struct opal_dev *dev, void *data)
>  {
>  	u8 uid[OPAL_UID_LENGTH];
> @@ -1143,23 +1174,11 @@ static int get_active_key(struct opal_dev *dev, void *data)
>  	if (err)
>  		return err;
>  
> -	err = cmd_start(dev, uid, opalmethod[OPAL_GET]);
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 3); /* startCloumn */
> -	add_token_u8(&err, dev, 10); /* ActiveKey */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 4); /* endColumn */
> -	add_token_u8(&err, dev, 10); /* ActiveKey */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
> -	if (err) {
> -		pr_debug("Error building get active key command\n");
> +	err = generic_get_column(dev, uid, OPAL_ACTIVEKEY);
> +	if (err)
>  		return err;
> -	}
>  
> -	return finalize_and_send(dev, get_active_key_cont);
> +	return get_active_key_cont(dev);
>  }
>  
>  static int generic_lr_enable_disable(struct opal_dev *dev,
> @@ -1820,17 +1839,19 @@ static int activate_lsp(struct opal_dev *dev, void *data)
>  	return finalize_and_send(dev, parse_and_check_status);
>  }
>  
> -static int get_lsp_lifecycle_cont(struct opal_dev *dev)
> +/* Determine if we're in the Manufactured Inactive or Active state */
> +static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
>  {
>  	u8 lc_status;
> -	int error = 0;
> +	int err;
>  
> -	error = parse_and_check_status(dev);
> -	if (error)
> -		return error;
> +	err = generic_get_column(dev, opaluid[OPAL_LOCKINGSP_UID],
> +				 OPAL_LIFECYCLE);
> +	if (err)
> +		return err;
>  
>  	lc_status = response_get_u64(&dev->parsed, 4);
> -	/* 0x08 is Manufacured Inactive */
> +	/* 0x08 is Manufactured Inactive */
>  	/* 0x09 is Manufactured */
>  	if (lc_status != OPAL_MANUFACTURED_INACTIVE) {
>  		pr_debug("Couldn't determine the status of the Lifecycle state\n");
> @@ -1840,49 +1861,19 @@ static int get_lsp_lifecycle_cont(struct opal_dev *dev)
>  	return 0;
>  }
>  
> -/* Determine if we're in the Manufactured Inactive or Active state */
> -static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
> -{
> -	int err;
> -
> -	err = cmd_start(dev, opaluid[OPAL_LOCKINGSP_UID],
> -			opalmethod[OPAL_GET]);
> -
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> -
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 3); /* Start Column */
> -	add_token_u8(&err, dev, 6); /* Lifecycle Column */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 4); /* End Column */
> -	add_token_u8(&err, dev, 6); /* Lifecycle Column */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
> -
> -	if (err) {
> -		pr_debug("Error Building GET Lifecycle Status command\n");
> -		return err;
> -	}
> -
> -	return finalize_and_send(dev, get_lsp_lifecycle_cont);
> -}
> -
> -static int get_msid_cpin_pin_cont(struct opal_dev *dev)
> +static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
>  {
>  	const char *msid_pin;
>  	size_t strlen;
> -	int error = 0;
> +	int err;
>  
> -	error = parse_and_check_status(dev);
> -	if (error)
> -		return error;
> +	err = generic_get_column(dev, opaluid[OPAL_C_PIN_MSID], OPAL_PIN);
> +	if (err)
> +		return err;
>  
>  	strlen = response_get_string(&dev->parsed, 4, &msid_pin);
>  	if (!msid_pin) {
> -		pr_debug("%s: Couldn't extract PIN from response\n", __func__);
> +		pr_debug("Couldn't extract MSID_CPIN from response\n");
>  		return OPAL_INVAL_PARAM;
>  	}
>  
> @@ -1895,33 +1886,6 @@ static int get_msid_cpin_pin_cont(struct opal_dev *dev)
>  	return 0;
>  }
>  
> -static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
> -{
> -	int err;
> -
> -	err = cmd_start(dev, opaluid[OPAL_C_PIN_MSID],
> -			opalmethod[OPAL_GET]);
> -
> -	add_token_u8(&err, dev, OPAL_STARTLIST);
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 3); /* Start Column */
> -	add_token_u8(&err, dev, 3); /* PIN */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -
> -	add_token_u8(&err, dev, OPAL_STARTNAME);
> -	add_token_u8(&err, dev, 4); /* End Column */
> -	add_token_u8(&err, dev, 3); /* Lifecycle Column */
> -	add_token_u8(&err, dev, OPAL_ENDNAME);
> -	add_token_u8(&err, dev, OPAL_ENDLIST);
> -
> -	if (err) {
> -		pr_debug("Error building Get MSID CPIN PIN command.\n");
> -		return err;
> -	}
> -
> -	return finalize_and_send(dev, get_msid_cpin_pin_cont);
> -}
> -
>  static int end_opal_session(struct opal_dev *dev, void *data)
>  {
>  	int err = 0;

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 13/16] block: sed-opal: check size of shadow mbr
  2019-02-01 20:50 ` [PATCH v4 13/16] block: sed-opal: check size of shadow mbr David Kozub
@ 2019-02-08 22:58   ` Derrick, Jonathan
  2019-02-10 20:05     ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:58 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 3551 bytes --]

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> 
> Check whether the shadow mbr does fit in the provided space on the
> target. Also a proper firmware should handle this case and return an
> error we may prevent problems or even damage with crappy firmwares.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/opal_proto.h | 16 ++++++++++++++++
>  block/sed-opal.c   | 39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 55 insertions(+)
> 
> diff --git a/block/opal_proto.h b/block/opal_proto.h
> index b6e352cfe982..5e8df3245eb0 100644
> --- a/block/opal_proto.h
> +++ b/block/opal_proto.h
> @@ -106,6 +106,7 @@ enum opal_uid {
>  	OPAL_ENTERPRISE_BANDMASTER0_UID,
>  	OPAL_ENTERPRISE_ERASEMASTER_UID,
>  	/* tables */
> +	OPAL_TABLE_TABLE,
>  	OPAL_LOCKINGRANGE_GLOBAL,
>  	OPAL_LOCKINGRANGE_ACE_RDLOCKED,
>  	OPAL_LOCKINGRANGE_ACE_WRLOCKED,
> @@ -160,6 +161,21 @@ enum opal_token {
>  	OPAL_STARTCOLUMN = 0x03,
>  	OPAL_ENDCOLUMN = 0x04,
>  	OPAL_VALUES = 0x01,
> +	/* table table */
> +	OPAL_TABLE_UID = 0x00,
> +	OPAL_TABLE_NAME = 0x01,
> +	OPAL_TABLE_COMMON = 0x02,
> +	OPAL_TABLE_TEMPLATE = 0x03,
> +	OPAL_TABLE_KIND = 0x04,
> +	OPAL_TABLE_COLUMN = 0x05,
> +	OPAL_TABLE_COLUMNS = 0x06,
> +	OPAL_TABLE_ROWS = 0x07,
> +	OPAL_TABLE_ROWS_FREE = 0x08,
> +	OPAL_TABLE_ROW_BYTES = 0x09,
> +	OPAL_TABLE_LASTID = 0x0A,
> +	OPAL_TABLE_MIN = 0x0B,
> +	OPAL_TABLE_MAX = 0x0C,
> +
>  	/* authority table */
>  	OPAL_PIN = 0x03,
>  	/* locking tokens */
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 2459ac4d523b..3493bb979978 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -139,6 +139,8 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
>  
>  	/* tables */
>  
> +	[OPAL_TABLE_TABLE]
> +		{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 },
>  	[OPAL_LOCKINGRANGE_GLOBAL] =
>  		{ 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 },
>  	[OPAL_LOCKINGRANGE_ACE_RDLOCKED] =
> @@ -1120,6 +1122,29 @@ static int generic_get_column(struct opal_dev *dev, const u8 *table,
>  	return finalize_and_send(dev, parse_and_check_status);
>  }
>  
> +/*
> + * see TCG SAS 5.3.2.3 for a description of the available columns
> + *
> + * the result is provided in dev->resp->tok[4]
> + */
> +static int generic_get_table_info(struct opal_dev *dev, enum opal_uid table,
> +				  u64 column)
> +{
> +	u8 uid[OPAL_UID_LENGTH];
> +	const unsigned int half = OPAL_UID_LENGTH/2;
> +
> +	/* sed-opal UIDs can be split in two halves:
> +	 *  first:  actual table index
> +	 *  second: relative index in the table
> +	 * so we have to get the first half of the OPAL_TABLE_TABLE and use the
> +	 * first part of the target table as relative index into that table
> +	 */
> +	memcpy(uid, opaluid[OPAL_TABLE_TABLE], half);
> +	memcpy(uid+half, opaluid[table], half);
> +
> +	return generic_get_column(dev, uid, column);
> +}
> +
>  static int gen_key(struct opal_dev *dev, void *data)
>  {
>  	u8 uid[OPAL_UID_LENGTH];
> @@ -1535,6 +1560,20 @@ static int write_shadow_mbr(struct opal_dev *dev, void *data)
>  	u64 len;
>  	int err = 0;
>  
> +	/* do we fit in the available shadow mbr space? */
> +	err = generic_get_table_info(dev, OPAL_MBR, OPAL_TABLE_ROWS);
Wouldn't you need to multiply this by result from OPAL_TABLE_ROWBYTES?
What does ROWBYTES return for you?

[snip]

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-04 22:44     ` David Kozub
@ 2019-02-08 22:59       ` Derrick, Jonathan
  2019-02-10 17:46         ` David Kozub
  0 siblings, 1 reply; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:59 UTC (permalink / raw)
  To: hch, zub; +Cc: linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 1958 bytes --]

On Mon, 2019-02-04 at 23:44 +0100, David Kozub wrote:
> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> 
> > > +	/* first do a discovery0 */
> > > +	error = opal_discovery0_step(dev);
> > > 
> > > +	for (state = 0; !error && state < n_steps; state++)
> > > +		error = execute_step(dev, &steps[state], state);
> > > +
> > > +	/*
> > > +	 * For each OPAL command the first step in steps starts some sort of
> > > +	 * session. If an error occurred in the initial discovery0 or if an
> > > +	 * error occurred in the first step (and thus stopping the loop with
> > > +	 * state == 1) then there was an error before or during the attempt to
> > > +	 * start a session. Therefore we shouldn't attempt to terminate a
> > > +	 * session, as one has not yet been created.
> > > +	 */
> > > +	if (error && state > 1)
> > > +		end_opal_session_error(dev);
> > > 
> > >  	return error;
> > 
> > The flow here is a little too condensed for my taste.  Why not the
> > plain obvoious, if a little longer:
> > 
> > 	error = error = opal_discovery0_step(dev);
> > 	if (error)
> > 		return error;
> > 
> > 	for (state = 0; state < n_steps; state++) {
> > 		error = execute_step(dev, &steps[state], state);
> > 		if (error)
> > 			goto out_error;
> > 	}
> > 
> > 	return 0;
> > 
> > out_error:
> > 	if (state > 1)
> > 		end_opal_session_error(dev);
> > 	return error;
> 
> No problem, I can use this version. But I think there is a minor issue - 
> the same one I hit in my original change, just from the other direction:
> 
> If the loop succeds for the 0-th element of steps, and then fails for the 
> 1st element, then state equals 1 yet the session has been started, so we 
> should close it.
> 
> I think the condition in out_error should be if (state > 0).
> 
> Best regards,
> David
Looks good with Christoph's suggestion (for 14/16) and your state check fix


Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 16/16] block: sed-opal: rename next to execute_steps
  2019-02-01 20:50 ` [PATCH v4 16/16] block: sed-opal: rename next to execute_steps David Kozub
  2019-02-04 15:01   ` Christoph Hellwig
@ 2019-02-08 22:59   ` Derrick, Jonathan
  1 sibling, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-08 22:59 UTC (permalink / raw)
  To: linux-kernel, zub, linux-block, sbauer, axboe; +Cc: jonas.rabenstein

[-- Attachment #1: Type: text/plain, Size: 5914 bytes --]

Looks good

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> As the function is responsible for executing the individual steps supplied
> in the steps argument, execute_steps is a more descriptive name than the
> rather generic next.
> 
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> ---
>  block/sed-opal.c | 37 +++++++++++++++++++------------------
>  1 file changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 3362741dd198..c09149dd5e0a 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -401,8 +401,8 @@ static int execute_step(struct opal_dev *dev,
>  	return error;
>  }
>  
> -static int next(struct opal_dev *dev, const struct opal_step *steps,
> -		size_t n_steps)
> +static int execute_steps(struct opal_dev *dev,
> +			 const struct opal_step *steps, size_t n_steps)
>  {
>  	size_t state;
>  	int error;
> @@ -2034,7 +2034,7 @@ static int opal_secure_erase_locking_range(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
> +	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2051,7 +2051,7 @@ static int opal_erase_locking_range(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, erase_steps, ARRAY_SIZE(erase_steps));
> +	ret = execute_steps(dev, erase_steps, ARRAY_SIZE(erase_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2077,7 +2077,7 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
> +	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2099,7 +2099,7 @@ static int opal_mbr_status(struct opal_dev *dev, struct opal_mbr_data *opal_mbr)
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
> +	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2122,7 +2122,7 @@ static int opal_write_shadow_mbr(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
> +	ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2174,7 +2174,7 @@ static int opal_add_user_to_lr(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, steps, ARRAY_SIZE(steps));
> +	ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2189,7 +2189,7 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, revert_steps, ARRAY_SIZE(revert_steps));
> +	ret = execute_steps(dev, revert_steps, ARRAY_SIZE(revert_steps));
>  	mutex_unlock(&dev->dev_lock);
>  
>  	/*
> @@ -2217,10 +2217,11 @@ static int __opal_lock_unlock(struct opal_dev *dev,
>  	};
>  
>  	if (lk_unlk->session.sum)
> -		return next(dev, unlock_sum_steps,
> -			    ARRAY_SIZE(unlock_sum_steps));
> +		return execute_steps(dev, unlock_sum_steps,
> +				     ARRAY_SIZE(unlock_sum_steps));
>  	else
> -		return next(dev, unlock_steps, ARRAY_SIZE(unlock_steps));
> +		return execute_steps(dev, unlock_steps,
> +				     ARRAY_SIZE(unlock_steps));
>  }
>  
>  static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
> @@ -2232,7 +2233,7 @@ static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
>  		{ end_opal_session, }
>  	};
>  
> -	return next(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
> +	return execute_steps(dev, mbrdone_step, ARRAY_SIZE(mbrdone_step));
>  }
>  
>  static int opal_lock_unlock(struct opal_dev *dev,
> @@ -2267,7 +2268,7 @@ static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, owner_steps, ARRAY_SIZE(owner_steps));
> +	ret = execute_steps(dev, owner_steps, ARRAY_SIZE(owner_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2288,7 +2289,7 @@ static int opal_activate_lsp(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, active_steps, ARRAY_SIZE(active_steps));
> +	ret = execute_steps(dev, active_steps, ARRAY_SIZE(active_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2305,7 +2306,7 @@ static int opal_setup_locking_range(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, lr_steps, ARRAY_SIZE(lr_steps));
> +	ret = execute_steps(dev, lr_steps, ARRAY_SIZE(lr_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2327,7 +2328,7 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, pw_steps, ARRAY_SIZE(pw_steps));
> +	ret = execute_steps(dev, pw_steps, ARRAY_SIZE(pw_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }
> @@ -2351,7 +2352,7 @@ static int opal_activate_user(struct opal_dev *dev,
>  
>  	mutex_lock(&dev->dev_lock);
>  	setup_opal_dev(dev);
> -	ret = next(dev, act_steps, ARRAY_SIZE(act_steps));
> +	ret = execute_steps(dev, act_steps, ARRAY_SIZE(act_steps));
>  	mutex_unlock(&dev->dev_lock);
>  	return ret;
>  }

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-08 22:59       ` Derrick, Jonathan
@ 2019-02-10 17:46         ` David Kozub
  2019-02-11 17:22           ` Derrick, Jonathan
  0 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-10 17:46 UTC (permalink / raw)
  To: Derrick, Jonathan
  Cc: hch, linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

On Fri, 8 Feb 2019, Derrick, Jonathan wrote:

> On Mon, 2019-02-04 at 23:44 +0100, David Kozub wrote:
>> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
>>
>>>> +	/* first do a discovery0 */
>>>> +	error = opal_discovery0_step(dev);
>>>>
>>>> +	for (state = 0; !error && state < n_steps; state++)
>>>> +		error = execute_step(dev, &steps[state], state);
>>>> +
>>>> +	/*
>>>> +	 * For each OPAL command the first step in steps starts some sort of
>>>> +	 * session. If an error occurred in the initial discovery0 or if an
>>>> +	 * error occurred in the first step (and thus stopping the loop with
>>>> +	 * state == 1) then there was an error before or during the attempt to
>>>> +	 * start a session. Therefore we shouldn't attempt to terminate a
>>>> +	 * session, as one has not yet been created.
>>>> +	 */
>>>> +	if (error && state > 1)
>>>> +		end_opal_session_error(dev);
>>>>
>>>>  	return error;
>>>
>>> The flow here is a little too condensed for my taste.  Why not the
>>> plain obvoious, if a little longer:
>>>
>>> 	error = error = opal_discovery0_step(dev);
>>> 	if (error)
>>> 		return error;
>>>
>>> 	for (state = 0; state < n_steps; state++) {
>>> 		error = execute_step(dev, &steps[state], state);
>>> 		if (error)
>>> 			goto out_error;
>>> 	}
>>>
>>> 	return 0;
>>>
>>> out_error:
>>> 	if (state > 1)
>>> 		end_opal_session_error(dev);
>>> 	return error;
>>
>> No problem, I can use this version. But I think there is a minor issue -
>> the same one I hit in my original change, just from the other direction:
>>
>> If the loop succeds for the 0-th element of steps, and then fails for the
>> 1st element, then state equals 1 yet the session has been started, so we
>> should close it.
>>
>> I think the condition in out_error should be if (state > 0).
>>
>> Best regards,
>> David
> Looks good with Christoph's suggestion (for 14/16) and your state check fix
>
>
> Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

Hi Jon,

What suggestion by Christoph you have in mind? I don't see any for 14/16. 
Currently, in my git repo, for this patch, I applied Christoph suggestion 
for this (15/16) patch + the "state > 0" fix. Is this what you mean?

Best regards,
David

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-08  0:44       ` Derrick, Jonathan
  2019-02-08  1:37         ` Scott Bauer
@ 2019-02-10 18:26         ` Scott Bauer
  2019-02-10 20:25           ` David Kozub
  1 sibling, 1 reply; 64+ messages in thread
From: Scott Bauer @ 2019-02-10 18:26 UTC (permalink / raw)
  To: Derrick, Jonathan
  Cc: hch, zub, linux-kernel, linux-block, jonas.rabenstein, axboe

On Fri, Feb 08, 2019 at 12:44:14AM +0000, Derrick, Jonathan wrote:
> On Thu, 2019-02-07 at 23:56 +0100, David Kozub wrote:
> > On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> > > >  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
> > > >  					  struct opal_mbr_data *opal_mbr)
> > > >  {
> > > > +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > > > +		? OPAL_TRUE : OPAL_FALSE;
> > > >  	const struct opal_step mbr_steps[] = {
> > > >  		{ opal_discovery0, },
> > > >  		{ start_admin1LSP_opal_session, &opal_mbr->key },
> > > > -		{ set_mbr_done, &opal_mbr->enable_disable },
> > > > +		{ set_mbr_done, &token },

> > Am I missing something here? This seems wrong to me. And I think this 
> > patch actually changes it by introducing:
> > 
> > +    u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > +            ? OPAL_TRUE : OPAL_FALSE;
> > 
> > which is essentially a negation (map 0 to 1 and 1 to 0).

Agreed the original code did the opposite of what the user wanted, looks like
when I authored it I messed up that enum which set everything off.



> > With regard to the new IOC_OPAL_MBR_STATUS: I find the usage of 
> > OPAL_MBR_ENABLE/DISABLE for this confusing: what should passing 
> > OPAL_MBR_ENABLE do? Should it enable the shadow MBR? Or should it 
> > enable the MBR-done flag? I think the implementation in this patch 
> > interprets OPAL_MBR_ENABLE as 'set the "done" flag to true', thus hiding 
> > the shadow MBR. But this is not obvious looking at the IOCTL name.

For the new ioctl I think we should just add a new enum with the correct
nomenclature.  So OPAL_MBR_DONE, OPAL_MBR_NOT_DONE.


> In order to keep the userspace interface consistent, I'll ACK your
> change in this patch, unless Scott can fill me in on why this looks
> wrong but is actually right.

I think it is just wrong. 


> 
> We have 7 bytes in the opal_mbr_data struct we could use for DONE/NOT
> DONE. I'm not sure how to go about keeping it consistent with old uapi,
> although arguably opal_enable_disable_shadow_mbr is already doing the
> wrong thing with DONE and ENABLE so it's low impact.

Can we keep the old mbr struct the same and just add a new struct with new enums
for the new done ioctl? I think this will keep the new ioctl cleaner instead
of trying to apply older, some what incorrectly named, enums.

Lastly someone will need to backport his

> > > > +       u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
> > > > +               ? OPAL_TRUE : OPAL_FALSE;

to stable so we can fix up my broken coding in older kernels.


I can do that or, if David wants to do that that's fine... just want to coordinate.








^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 13/16] block: sed-opal: check size of shadow mbr
  2019-02-08 22:58   ` Derrick, Jonathan
@ 2019-02-10 20:05     ` David Kozub
  2019-02-11 21:27       ` Derrick, Jonathan
  0 siblings, 1 reply; 64+ messages in thread
From: David Kozub @ 2019-02-10 20:05 UTC (permalink / raw)
  To: Derrick, Jonathan
  Cc: linux-kernel, linux-block, sbauer, axboe, jonas.rabenstein

On Fri, 8 Feb 2019, Derrick, Jonathan wrote:

> On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
>> From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>>
>> Check whether the shadow mbr does fit in the provided space on the
>> target. Also a proper firmware should handle this case and return an
>> error we may prevent problems or even damage with crappy firmwares.
>>
>> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
>> Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
>> ---
>>  block/opal_proto.h | 16 ++++++++++++++++
>>  block/sed-opal.c   | 39 +++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 55 insertions(+)
>>
>> diff --git a/block/opal_proto.h b/block/opal_proto.h
>> index b6e352cfe982..5e8df3245eb0 100644
>> --- a/block/opal_proto.h
>> +++ b/block/opal_proto.h
>> @@ -106,6 +106,7 @@ enum opal_uid {
>>  	OPAL_ENTERPRISE_BANDMASTER0_UID,
>>  	OPAL_ENTERPRISE_ERASEMASTER_UID,
>>  	/* tables */
>> +	OPAL_TABLE_TABLE,
>>  	OPAL_LOCKINGRANGE_GLOBAL,
>>  	OPAL_LOCKINGRANGE_ACE_RDLOCKED,
>>  	OPAL_LOCKINGRANGE_ACE_WRLOCKED,
>> @@ -160,6 +161,21 @@ enum opal_token {
>>  	OPAL_STARTCOLUMN = 0x03,
>>  	OPAL_ENDCOLUMN = 0x04,
>>  	OPAL_VALUES = 0x01,
>> +	/* table table */
>> +	OPAL_TABLE_UID = 0x00,
>> +	OPAL_TABLE_NAME = 0x01,
>> +	OPAL_TABLE_COMMON = 0x02,
>> +	OPAL_TABLE_TEMPLATE = 0x03,
>> +	OPAL_TABLE_KIND = 0x04,
>> +	OPAL_TABLE_COLUMN = 0x05,
>> +	OPAL_TABLE_COLUMNS = 0x06,
>> +	OPAL_TABLE_ROWS = 0x07,
>> +	OPAL_TABLE_ROWS_FREE = 0x08,
>> +	OPAL_TABLE_ROW_BYTES = 0x09,
>> +	OPAL_TABLE_LASTID = 0x0A,
>> +	OPAL_TABLE_MIN = 0x0B,
>> +	OPAL_TABLE_MAX = 0x0C,
>> +
>>  	/* authority table */
>>  	OPAL_PIN = 0x03,
>>  	/* locking tokens */
>> diff --git a/block/sed-opal.c b/block/sed-opal.c
>> index 2459ac4d523b..3493bb979978 100644
>> --- a/block/sed-opal.c
>> +++ b/block/sed-opal.c
>> @@ -139,6 +139,8 @@ static const u8 opaluid[][OPAL_UID_LENGTH] = {
>>
>>  	/* tables */
>>
>> +	[OPAL_TABLE_TABLE]
>> +		{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 },
>>  	[OPAL_LOCKINGRANGE_GLOBAL] =
>>  		{ 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 },
>>  	[OPAL_LOCKINGRANGE_ACE_RDLOCKED] =
>> @@ -1120,6 +1122,29 @@ static int generic_get_column(struct opal_dev *dev, const u8 *table,
>>  	return finalize_and_send(dev, parse_and_check_status);
>>  }
>>
>> +/*
>> + * see TCG SAS 5.3.2.3 for a description of the available columns
>> + *
>> + * the result is provided in dev->resp->tok[4]
>> + */
>> +static int generic_get_table_info(struct opal_dev *dev, enum opal_uid table,
>> +				  u64 column)
>> +{
>> +	u8 uid[OPAL_UID_LENGTH];
>> +	const unsigned int half = OPAL_UID_LENGTH/2;
>> +
>> +	/* sed-opal UIDs can be split in two halves:
>> +	 *  first:  actual table index
>> +	 *  second: relative index in the table
>> +	 * so we have to get the first half of the OPAL_TABLE_TABLE and use the
>> +	 * first part of the target table as relative index into that table
>> +	 */
>> +	memcpy(uid, opaluid[OPAL_TABLE_TABLE], half);
>> +	memcpy(uid+half, opaluid[table], half);
>> +
>> +	return generic_get_column(dev, uid, column);
>> +}
>> +
>>  static int gen_key(struct opal_dev *dev, void *data)
>>  {
>>  	u8 uid[OPAL_UID_LENGTH];
>> @@ -1535,6 +1560,20 @@ static int write_shadow_mbr(struct opal_dev *dev, void *data)
>>  	u64 len;
>>  	int err = 0;
>>
>> +	/* do we fit in the available shadow mbr space? */
>> +	err = generic_get_table_info(dev, OPAL_MBR, OPAL_TABLE_ROWS);
> Wouldn't you need to multiply this by result from OPAL_TABLE_ROWBYTES?
> What does ROWBYTES return for you?

Hi Jon,

reading the spec[1], I think it defines the MBR table to be a "byte table" 
(see 5.7.2.6 MBR (Byte Table)). For byte tables, it says (see 3.2.5.1 
Kinds of Tables) "A byte table has one unnamed column of type bytes_1." I 
think this implies that each row is 1 byte and so number of rows = size of 
table in rows.

When I actually try to get OPAL_TABLE_ROWS abd OPAL_TABLE_ROWBYTES of the 
MBR table from a Samsung 840 EVO, I get:
* OPAL_TABLE_ROWS 134217728 which is 128 MiB
* OPAL_TABLE_ROWBYTES 0

I'm not sure if I'm doing something wrong here. I just added:

 	err = generic_get_table_info(dev, OPAL_MBR, OPAL_TABLE_ROW_BYTES);
 	if (err) {
 		pr_debug("MBR: could not get shadow row bytes size\n");
 		return err;
 	}

 	row_bytes = response_get_u64(&dev->parsed, 4);

Best regards,
David

[1] https://trustedcomputinggroup.org/wp-content/uploads/TCG_Storage_Architecture_Core_Spec_v2.01_r1.00.pdf

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr
  2019-02-10 18:26         ` Scott Bauer
@ 2019-02-10 20:25           ` David Kozub
  0 siblings, 0 replies; 64+ messages in thread
From: David Kozub @ 2019-02-10 20:25 UTC (permalink / raw)
  To: Scott Bauer
  Cc: Derrick, Jonathan, hch, linux-kernel, linux-block,
	jonas.rabenstein, axboe

On Sun, 10 Feb 2019, Scott Bauer wrote:

> On Fri, Feb 08, 2019 at 12:44:14AM +0000, Derrick, Jonathan wrote:
>> On Thu, 2019-02-07 at 23:56 +0100, David Kozub wrote:
>>> On Mon, 4 Feb 2019, Christoph Hellwig wrote:
>>>>>  static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
>>>>>  					  struct opal_mbr_data *opal_mbr)
>>>>>  {
>>>>> +	u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
>>>>> +		? OPAL_TRUE : OPAL_FALSE;
>>>>>  	const struct opal_step mbr_steps[] = {
>>>>>  		{ opal_discovery0, },
>>>>>  		{ start_admin1LSP_opal_session, &opal_mbr->key },
>>>>> -		{ set_mbr_done, &opal_mbr->enable_disable },
>>>>> +		{ set_mbr_done, &token },
>
>>> Am I missing something here? This seems wrong to me. And I think this
>>> patch actually changes it by introducing:
>>>
>>> +    u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
>>> +            ? OPAL_TRUE : OPAL_FALSE;
>>>
>>> which is essentially a negation (map 0 to 1 and 1 to 0).
>
> Agreed the original code did the opposite of what the user wanted, looks like
> when I authored it I messed up that enum which set everything off.
>
>
>
>>> With regard to the new IOC_OPAL_MBR_STATUS: I find the usage of
>>> OPAL_MBR_ENABLE/DISABLE for this confusing: what should passing
>>> OPAL_MBR_ENABLE do? Should it enable the shadow MBR? Or should it
>>> enable the MBR-done flag? I think the implementation in this patch
>>> interprets OPAL_MBR_ENABLE as 'set the "done" flag to true', thus hiding
>>> the shadow MBR. But this is not obvious looking at the IOCTL name.
>
> For the new ioctl I think we should just add a new enum with the correct
> nomenclature.  So OPAL_MBR_DONE, OPAL_MBR_NOT_DONE.
>
>
>> In order to keep the userspace interface consistent, I'll ACK your
>> change in this patch, unless Scott can fill me in on why this looks
>> wrong but is actually right.
>
> I think it is just wrong.
>
>
>>
>> We have 7 bytes in the opal_mbr_data struct we could use for DONE/NOT
>> DONE. I'm not sure how to go about keeping it consistent with old uapi,
>> although arguably opal_enable_disable_shadow_mbr is already doing the
>> wrong thing with DONE and ENABLE so it's low impact.
>
> Can we keep the old mbr struct the same and just add a new struct with new enums
> for the new done ioctl? I think this will keep the new ioctl cleaner instead
> of trying to apply older, some what incorrectly named, enums.

I like this proposal, I'll try to implement it. Although currently I plan 
to first re-submit the cleanup parts, as suggested by Christoph[1]. So 
this will happen after that.

> Lastly someone will need to backport his
>
>>>>> +       u8 token = opal_mbr->enable_disable == OPAL_MBR_ENABLE
>>>>> +               ? OPAL_TRUE : OPAL_FALSE;
>
> to stable so we can fix up my broken coding in older kernels.
>
>
> I can do that or, if David wants to do that that's fine... just want to coordinate.

I'm quite busy juggling patches in this series. If you can find the time, 
please do it.

Best regards,
David

[1] https://lore.kernel.org/lkml/20190204150415.GO31132@infradead.org/


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array
  2019-02-10 17:46         ` David Kozub
@ 2019-02-11 17:22           ` Derrick, Jonathan
  0 siblings, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-11 17:22 UTC (permalink / raw)
  To: zub; +Cc: hch, linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]

Hi David,

On Sun, 2019-02-10 at 18:46 +0100, David Kozub wrote:
> On Fri, 8 Feb 2019, Derrick, Jonathan wrote:
> 
> > On Mon, 2019-02-04 at 23:44 +0100, David Kozub wrote:
> > > On Mon, 4 Feb 2019, Christoph Hellwig wrote:
> > > 
> > > > > +	/* first do a discovery0 */
> > > > > +	error = opal_discovery0_step(dev);
> > > > > 
> > > > > +	for (state = 0; !error && state < n_steps; state++)
> > > > > +		error = execute_step(dev, &steps[state], state);
This was implemented in v4's 14/16, rather than this patch (15/16)

> > > > > +
> > > > > +	/*
> > > > > +	 * For each OPAL command the first step in steps starts some sort of
> > > > > +	 * session. If an error occurred in the initial discovery0 or if an
> > > > > +	 * error occurred in the first step (and thus stopping the loop with
> > > > > +	 * state == 1) then there was an error before or during the attempt to
> > > > > +	 * start a session. Therefore we shouldn't attempt to terminate a
> > > > > +	 * session, as one has not yet been created.
> > > > > +	 */
> > > > > +	if (error && state > 1)
> > > > > +		end_opal_session_error(dev);
> > > > > 
> > > > >  	return error;
> > > > 
> > > > The flow here is a little too condensed for my taste.  Why not the
> > > > plain obvoious, if a little longer:
> > > > 
> > > > 	error = error = opal_discovery0_step(dev);
> > > > 	if (error)
> > > > 		return error;
> > > > 
> > > > 	for (state = 0; state < n_steps; state++) {
> > > > 		error = execute_step(dev, &steps[state], state);
> > > > 		if (error)
> > > > 			goto out_error;
> > > > 	}
> > > > 
> > > > 	return 0;
> > > > 
> > > > out_error:
> > > > 	if (state > 1)
> > > > 		end_opal_session_error(dev);
> > > > 	return error;
> > > 
> > > No problem, I can use this version. But I think there is a minor issue -
> > > the same one I hit in my original change, just from the other direction:
> > > 
> > > If the loop succeds for the 0-th element of steps, and then fails for the
> > > 1st element, then state equals 1 yet the session has been started, so we
> > > should close it.
> > > 
> > > I think the condition in out_error should be if (state > 0).
> > > 
> > > Best regards,
> > > David
> > 
> > Looks good with Christoph's suggestion (for 14/16) and your state check fix
> > 
> > 
> > Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>
> 
> Hi Jon,
> 
> What suggestion by Christoph you have in mind? I don't see any for 14/16. 
> Currently, in my git repo, for this patch, I applied Christoph suggestion 
> for this (15/16) patch + the "state > 0" fix. Is this what you mean?
> 
> Best regards,
> David

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v4 13/16] block: sed-opal: check size of shadow mbr
  2019-02-10 20:05     ` David Kozub
@ 2019-02-11 21:27       ` Derrick, Jonathan
  0 siblings, 0 replies; 64+ messages in thread
From: Derrick, Jonathan @ 2019-02-11 21:27 UTC (permalink / raw)
  To: zub; +Cc: linux-kernel, linux-block, sbauer, jonas.rabenstein, axboe

[-- Attachment #1: Type: text/plain, Size: 5348 bytes --]

On Sun, 2019-02-10 at 21:05 +0100, David Kozub wrote:
> On Fri, 8 Feb 2019, Derrick, Jonathan wrote:
> 
> > On Fri, 2019-02-01 at 21:50 +0100, David Kozub wrote:
> > > From: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
> > > 
> > > Check whether the shadow mbr does fit in the provided space on
> > > the
> > > target. Also a proper firmware should handle this case and return
> > > an
> > > error we may prevent problems or even damage with crappy
> > > firmwares.
> > > 
> > > Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erl
> > > angen.de>
> > > Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
> > > ---
> > >  block/opal_proto.h | 16 ++++++++++++++++
> > >  block/sed-opal.c   | 39 +++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 55 insertions(+)
> > > 
> > > diff --git a/block/opal_proto.h b/block/opal_proto.h
> > > index b6e352cfe982..5e8df3245eb0 100644
> > > --- a/block/opal_proto.h
> > > +++ b/block/opal_proto.h
> > > @@ -106,6 +106,7 @@ enum opal_uid {
> > >  	OPAL_ENTERPRISE_BANDMASTER0_UID,
> > >  	OPAL_ENTERPRISE_ERASEMASTER_UID,
> > >  	/* tables */
> > > +	OPAL_TABLE_TABLE,
> > >  	OPAL_LOCKINGRANGE_GLOBAL,
> > >  	OPAL_LOCKINGRANGE_ACE_RDLOCKED,
> > >  	OPAL_LOCKINGRANGE_ACE_WRLOCKED,
> > > @@ -160,6 +161,21 @@ enum opal_token {
> > >  	OPAL_STARTCOLUMN = 0x03,
> > >  	OPAL_ENDCOLUMN = 0x04,
> > >  	OPAL_VALUES = 0x01,
> > > +	/* table table */
> > > +	OPAL_TABLE_UID = 0x00,
> > > +	OPAL_TABLE_NAME = 0x01,
> > > +	OPAL_TABLE_COMMON = 0x02,
> > > +	OPAL_TABLE_TEMPLATE = 0x03,
> > > +	OPAL_TABLE_KIND = 0x04,
> > > +	OPAL_TABLE_COLUMN = 0x05,
> > > +	OPAL_TABLE_COLUMNS = 0x06,
> > > +	OPAL_TABLE_ROWS = 0x07,
> > > +	OPAL_TABLE_ROWS_FREE = 0x08,
> > > +	OPAL_TABLE_ROW_BYTES = 0x09,
> > > +	OPAL_TABLE_LASTID = 0x0A,
> > > +	OPAL_TABLE_MIN = 0x0B,
> > > +	OPAL_TABLE_MAX = 0x0C,
> > > +
> > >  	/* authority table */
> > >  	OPAL_PIN = 0x03,
> > >  	/* locking tokens */
> > > diff --git a/block/sed-opal.c b/block/sed-opal.c
> > > index 2459ac4d523b..3493bb979978 100644
> > > --- a/block/sed-opal.c
> > > +++ b/block/sed-opal.c
> > > @@ -139,6 +139,8 @@ static const u8 opaluid[][OPAL_UID_LENGTH] =
> > > {
> > > 
> > >  	/* tables */
> > > 
> > > +	[OPAL_TABLE_TABLE]
> > > +		{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01
> > > },
> > >  	[OPAL_LOCKINGRANGE_GLOBAL] =
> > >  		{ 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01
> > > },
> > >  	[OPAL_LOCKINGRANGE_ACE_RDLOCKED] =
> > > @@ -1120,6 +1122,29 @@ static int generic_get_column(struct
> > > opal_dev *dev, const u8 *table,
> > >  	return finalize_and_send(dev, parse_and_check_status);
> > >  }
> > > 
> > > +/*
> > > + * see TCG SAS 5.3.2.3 for a description of the available
> > > columns
> > > + *
> > > + * the result is provided in dev->resp->tok[4]
> > > + */
> > > +static int generic_get_table_info(struct opal_dev *dev, enum
> > > opal_uid table,
> > > +				  u64 column)
> > > +{
> > > +	u8 uid[OPAL_UID_LENGTH];
> > > +	const unsigned int half = OPAL_UID_LENGTH/2;
> > > +
> > > +	/* sed-opal UIDs can be split in two halves:
> > > +	 *  first:  actual table index
> > > +	 *  second: relative index in the table
> > > +	 * so we have to get the first half of the
> > > OPAL_TABLE_TABLE and use the
> > > +	 * first part of the target table as relative index into
> > > that table
> > > +	 */
> > > +	memcpy(uid, opaluid[OPAL_TABLE_TABLE], half);
> > > +	memcpy(uid+half, opaluid[table], half);
> > > +
> > > +	return generic_get_column(dev, uid, column);
> > > +}
> > > +
> > >  static int gen_key(struct opal_dev *dev, void *data)
> > >  {
> > >  	u8 uid[OPAL_UID_LENGTH];
> > > @@ -1535,6 +1560,20 @@ static int write_shadow_mbr(struct
> > > opal_dev *dev, void *data)
> > >  	u64 len;
> > >  	int err = 0;
> > > 
> > > +	/* do we fit in the available shadow mbr space? */
> > > +	err = generic_get_table_info(dev, OPAL_MBR,
> > > OPAL_TABLE_ROWS);
> > 
> > Wouldn't you need to multiply this by result from
> > OPAL_TABLE_ROWBYTES?
> > What does ROWBYTES return for you?
> 
> Hi Jon,
> 
> reading the spec[1], I think it defines the MBR table to be a "byte
> table" 
> (see 5.7.2.6 MBR (Byte Table)). For byte tables, it says (see
> 3.2.5.1 
> Kinds of Tables) "A byte table has one unnamed column of type
> bytes_1." I 
> think this implies that each row is 1 byte and so number of rows =
> size of 
> table in rows.
> 
> When I actually try to get OPAL_TABLE_ROWS abd OPAL_TABLE_ROWBYTES of
> the 
> MBR table from a Samsung 840 EVO, I get:
> * OPAL_TABLE_ROWS 134217728 which is 128 MiB
> * OPAL_TABLE_ROWBYTES 0
> 
> I'm not sure if I'm doing something wrong here. I just added:
> 
>  	err = generic_get_table_info(dev, OPAL_MBR,
> OPAL_TABLE_ROW_BYTES);
>  	if (err) {
>  		pr_debug("MBR: could not get shadow row bytes
> size\n");
>  		return err;
>  	}
> 
>  	row_bytes = response_get_u64(&dev->parsed, 4);
> 
> Best regards,
> David
> 
> [1] https://trustedcomputinggroup.org/wp-content/uploads/TCG_Storage_
> Architecture_Core_Spec_v2.01_r1.00.pdf

I also see ROWS=0x8000000 and ROWBYTES=0 on an Intel drive, so my
interpretation of rowbytes was probably incorrect.

Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, back to index

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-01 20:50 [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
2019-02-01 20:50 ` [PATCH v4 01/16] block: sed-opal: fix typos and formatting David Kozub
2019-02-04 14:42   ` Christoph Hellwig
2019-02-04 20:28     ` David Kozub
2019-02-08 22:56       ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 02/16] block: sed-opal: use correct macro for method length David Kozub
2019-02-04 14:43   ` Christoph Hellwig
2019-02-08 22:56   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 03/16] block: sed-opal: unify space check in add_token_* David Kozub
2019-02-04 14:44   ` Christoph Hellwig
2019-02-04 21:07     ` David Kozub
2019-02-04 21:09       ` Christoph Hellwig
2019-02-08 22:57       ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 04/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
2019-02-04 14:44   ` Christoph Hellwig
2019-02-08 22:57   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 05/16] block: sed-opal: unify cmd start David Kozub
2019-02-04 14:45   ` Christoph Hellwig
2019-02-08 22:57   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 06/16] block: sed-opal: unify error handling of responses David Kozub
2019-02-04 14:45   ` Christoph Hellwig
2019-02-01 20:50 ` [PATCH v4 07/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
2019-02-04 14:46   ` Christoph Hellwig
2019-02-08 22:57   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 08/16] block: sed-opal: print failed function address David Kozub
2019-02-04 14:46   ` Christoph Hellwig
2019-02-01 20:50 ` [PATCH v4 09/16] block: sed-opal: split generation of bytestring header and content David Kozub
2019-02-04 14:48   ` Christoph Hellwig
2019-02-08 22:58   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 10/16] block: sed-opal: add ioctl for done-mark of shadow mbr David Kozub
2019-02-04 14:52   ` Christoph Hellwig
2019-02-07 22:56     ` David Kozub
2019-02-08  0:44       ` Derrick, Jonathan
2019-02-08  1:37         ` Scott Bauer
2019-02-10 18:26         ` Scott Bauer
2019-02-10 20:25           ` David Kozub
2019-02-01 20:50 ` [PATCH v4 11/16] block: sed-opal: ioctl for writing to " David Kozub
2019-02-04 17:58   ` kbuild test robot
2019-02-08 22:58   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 12/16] block: sed-opal: unify retrieval of table columns David Kozub
2019-02-04 14:56   ` Christoph Hellwig
2019-02-08 22:58   ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 13/16] block: sed-opal: check size of shadow mbr David Kozub
2019-02-08 22:58   ` Derrick, Jonathan
2019-02-10 20:05     ` David Kozub
2019-02-11 21:27       ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
2019-02-04 14:57   ` Christoph Hellwig
2019-02-01 20:50 ` [PATCH v4 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
2019-02-04 15:01   ` Christoph Hellwig
2019-02-04 22:44     ` David Kozub
2019-02-08 22:59       ` Derrick, Jonathan
2019-02-10 17:46         ` David Kozub
2019-02-11 17:22           ` Derrick, Jonathan
2019-02-01 20:50 ` [PATCH v4 16/16] block: sed-opal: rename next to execute_steps David Kozub
2019-02-04 15:01   ` Christoph Hellwig
2019-02-08 22:59   ` Derrick, Jonathan
2019-02-04  8:55 ` David Kozub
2019-02-04  9:44 ` [PATCH v4 00/16] block: sed-opal: support shadow MBR done flag and write David Kozub
2019-02-04 15:04 ` Christoph Hellwig
2019-02-04 15:36   ` Scott Bauer
2019-02-04 15:44     ` Christoph Hellwig
2019-02-04 23:06   ` David Kozub
2019-02-05  6:57     ` Christoph Hellwig

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox