linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/16] sed-opal: fix shadow MBR enable/disable and clean up code
@ 2019-02-14  0:15 David Kozub
  2019-02-14  0:15 ` [PATCH 01/16] block: sed-opal: fix IOC_OPAL_ENABLE_DISABLE_MBR David Kozub
                   ` (16 more replies)
  0 siblings, 17 replies; 39+ messages in thread
From: David Kozub @ 2019-02-14  0:15 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Derrick, Scott Bauer, linux-block, linux-kernel
  Cc: Jonas Rabenstein, David Kozub

This patch series contains various code cleanup and fixes for Opal SED support.
It's been created by taking a part of the original patch series by Jonas and me
(PATCHv4 block: sed-opal: support shadow MBR done flag and write) [1], as
suggested by Christoph in [2].

The most important patch is the first one where I tried to fix the shadow MBR
enable/disable issue we discussed in [3]. This change goes against Christoph's
original propsal in [4] but I think - in light of the issue and keeping in mind
the planned addition of an IOCTL specifically for toggling the done flag - that
passing just OPAL_TRUE or OPAL_FALSE to set_mbr_done and set_mbr_enable_disable
is more useful and also more understandable. Maybe this change is superfluous if
Scott found the time to submit his take on the fix. (?)

I tried to include all the feedback from the v4 review[1]. I also added some
more trivial changes (11/16 as suggested in [4]) and also 13/16 motivated by the
same idea - that's why I again reached the magical number of 16 patches.

I kept the reviewed-by/acked-by tags where the changes were trivial but I
removed them where I thought a re-review would be useful.

I plan to submit the remaining patches from the original series (these that add
new Opal IOCTLs) after this fix and cleanup is accepted.

I did a brief test toggling shadow MBR and unlocking a locking range. I will try
to do more thorough tests - but I will not get to it before the beginning of the
next week. It would be great if this could get some more testing. Especially the
unlock from suspend part - that's something I don't have set up and I have not
tested.

The series applies on v5.0-rc6.

[1] https://lore.kernel.org/lkml/1549054223-12220-1-git-send-email-zub@linux.fjfi.cvut.cz/
[2] https://lore.kernel.org/lkml/20190204150415.GO31132@infradead.org/
[3] https://lore.kernel.org/lkml/alpine.LRH.2.21.1902072247060.29258@linux.fjfi.cvut.cz/
[4] https://lore.kernel.org/lkml/20190204145244.GJ31132@infradead.org/

David Kozub (12):
  block: sed-opal: fix IOC_OPAL_ENABLE_DISABLE_MBR
  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: add token for OPAL_LIFECYCLE
  block: sed-opal: unify retrieval of table columns
  block: sed-opal: use named Opal tokens instead of integer literals
  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 (4):
  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/opal_proto.h            |   2 +
 block/sed-opal.c              | 716 ++++++++++++++--------------------
 include/uapi/linux/sed-opal.h |   2 +-
 3 files changed, 287 insertions(+), 433 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 39+ messages in thread
* [PATCH 12/16] block: sed-opal: unify retrieval of table columns
@ 2018-03-19 18:36 Jonas Rabenstein
  0 siblings, 0 replies; 39+ messages in thread
From: Jonas Rabenstein @ 2018-03-19 18:36 UTC (permalink / raw)
  To: Jens Axboe, Scott Bauer, Jonathan Derrick, linux-block, linux-kernel
  Cc: Jonas Rabenstein

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>
---
 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 ee24e4e7ad6e..034cb940b34a 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,
@@ -1819,17 +1838,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");
@@ -1839,49 +1860,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;
 	}
 
@@ -1894,33 +1885,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 related	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2019-04-06 17:09 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14  0:15 [PATCH 00/16] sed-opal: fix shadow MBR enable/disable and clean up code David Kozub
2019-02-14  0:15 ` [PATCH 01/16] block: sed-opal: fix IOC_OPAL_ENABLE_DISABLE_MBR David Kozub
2019-03-28 17:04   ` Christoph Hellwig
2019-04-06 15:15   ` Scott Bauer
2019-02-14  0:15 ` [PATCH 02/16] block: sed-opal: fix typos and formatting David Kozub
2019-03-28 17:05   ` Christoph Hellwig
2019-02-14  0:15 ` [PATCH 03/16] block: sed-opal: use correct macro for method length David Kozub
2019-02-14  0:15 ` [PATCH 04/16] block: sed-opal: unify space check in add_token_* David Kozub
2019-03-28 15:43   ` Derrick, Jonathan
2019-03-28 17:05   ` Christoph Hellwig
2019-04-06 15:18   ` Scott Bauer
2019-04-06 15:19   ` Scott Bauer
2019-02-14  0:15 ` [PATCH 05/16] block: sed-opal: close parameter list in cmd_finalize David Kozub
2019-02-14  0:15 ` [PATCH 06/16] block: sed-opal: unify cmd start David Kozub
2019-02-14  0:15 ` [PATCH 07/16] block: sed-opal: unify error handling of responses David Kozub
2019-02-14  0:16 ` [PATCH 08/16] block: sed-opal: reuse response_get_token to decrease code duplication David Kozub
2019-02-14  0:16 ` [PATCH 09/16] block: sed-opal: print failed function address David Kozub
2019-02-14  0:16 ` [PATCH 10/16] block: sed-opal: split generation of bytestring header and content David Kozub
2019-02-14  0:16 ` [PATCH 11/16] block: sed-opal: add token for OPAL_LIFECYCLE David Kozub
2019-03-28 15:43   ` Derrick, Jonathan
2019-03-28 17:06   ` Christoph Hellwig
2019-04-06 15:19   ` Scott Bauer
2019-02-14  0:16 ` [PATCH 12/16] block: sed-opal: unify retrieval of table columns David Kozub
2019-02-14  0:16 ` [PATCH 13/16] block: sed-opal: use named Opal tokens instead of integer literals David Kozub
2019-03-28 15:44   ` Derrick, Jonathan
2019-03-28 17:06   ` Christoph Hellwig
2019-04-06 15:20   ` Scott Bauer
2019-02-14  0:16 ` [PATCH 14/16] block: sed-opal: pass steps via argument rather than via opal_dev David Kozub
2019-03-28 15:44   ` Derrick, Jonathan
2019-03-28 17:07   ` Christoph Hellwig
2019-04-06 15:20   ` Scott Bauer
2019-02-14  0:16 ` [PATCH 15/16] block: sed-opal: don't repeat opal_discovery0 in each steps array David Kozub
2019-03-28 15:44   ` Derrick, Jonathan
2019-03-28 17:09   ` Christoph Hellwig
2019-04-06 15:22   ` Scott Bauer
2019-02-14  0:16 ` [PATCH 16/16] block: sed-opal: rename next to execute_steps David Kozub
2019-04-06 15:26 ` [PATCH 00/16] sed-opal: fix shadow MBR enable/disable and clean up code Scott Bauer
2019-04-06 17:09   ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2018-03-19 18:36 [PATCH 12/16] block: sed-opal: unify retrieval of table columns Jonas Rabenstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).