* [PATCH 1/3] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state
2017-02-22 17:15 Final opal patches for rc1 Scott Bauer
@ 2017-02-22 17:15 ` Scott Bauer
2017-02-22 17:15 ` [PATCH 2/3] nvme/pci: re-check security protocol support after reset Scott Bauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Scott Bauer @ 2017-02-22 17:15 UTC (permalink / raw)
To: linux-block
Cc: keith.busch, linux-nvme, axboe, jonathan.derrick, hch,
Scott Bauer
Before we free the opal structure we need to clean up any saved
locking ranges that the user had told us to unlock from a suspend.
Signed-off-by: Scott Bauer <scott.bauer@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
block/sed-opal.c | 30 ++++++++++++++++++++++++++++++
include/linux/sed-opal.h | 5 +++++
2 files changed, 35 insertions(+)
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 8935575..020bf3e 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -1987,6 +1987,28 @@ static int check_opal_support(struct opal_dev *dev)
return ret;
}
+static void clean_opal_dev(struct opal_dev *dev)
+{
+
+ struct opal_suspend_data *suspend, *next;
+
+ mutex_lock(&dev->dev_lock);
+ list_for_each_entry_safe(suspend, next, &dev->unlk_lst, node) {
+ list_del(&suspend->node);
+ kfree(suspend);
+ }
+ mutex_unlock(&dev->dev_lock);
+}
+
+void free_opal_dev(struct opal_dev *dev)
+{
+ if (!dev)
+ return;
+ clean_opal_dev(dev);
+ kfree(dev);
+}
+EXPORT_SYMBOL(free_opal_dev);
+
struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv)
{
struct opal_dev *dev;
@@ -2141,6 +2163,14 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
setup_opal_dev(dev, revert_steps);
ret = next(dev);
mutex_unlock(&dev->dev_lock);
+
+ /*
+ * If we successfully reverted lets clean
+ * any saved locking ranges.
+ */
+ if (!ret)
+ clean_opal_dev(dev);
+
return ret;
}
diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
index deee23d..04b124f 100644
--- a/include/linux/sed-opal.h
+++ b/include/linux/sed-opal.h
@@ -27,6 +27,7 @@ typedef int (sec_send_recv)(void *data, u16 spsp, u8 secp, void *buffer,
size_t len, bool send);
#ifdef CONFIG_BLK_SED_OPAL
+void free_opal_dev(struct opal_dev *dev);
bool opal_unlock_from_suspend(struct opal_dev *dev);
struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv);
int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *ioctl_ptr);
@@ -51,6 +52,10 @@ static inline bool is_sed_ioctl(unsigned int cmd)
return false;
}
#else
+static inline void free_opal_dev(struct opal_dev *dev)
+{
+}
+
static inline bool is_sed_ioctl(unsigned int cmd)
{
return false;
--
2.7.4
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] nvme/pci: re-check security protocol support after reset
2017-02-22 17:15 Final opal patches for rc1 Scott Bauer
2017-02-22 17:15 ` [PATCH 1/3] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state Scott Bauer
@ 2017-02-22 17:15 ` Scott Bauer
2017-02-22 17:15 ` [PATCH 3/3] block/sed-opal: Propagate original error message to userland Scott Bauer
2017-02-23 18:57 ` Final opal patches for rc1 Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Scott Bauer @ 2017-02-22 17:15 UTC (permalink / raw)
To: linux-block
Cc: keith.busch, linux-nvme, axboe, jonathan.derrick, hch,
Scott Bauer
A device may change capabilities after each reset, e.g. due to a firmware
upgrade. We should thus check for Security Send/Receive and OPAL support
after each reset.
Based on patches from Christoph and Keith.
Signed-off-by: Scott Bauer <scott.bauer@intel.com>
---
drivers/nvme/host/pci.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index ddc51ad..f660fc2 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1739,7 +1739,7 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
if (dev->ctrl.admin_q)
blk_put_queue(dev->ctrl.admin_q);
kfree(dev->queues);
- kfree(dev->ctrl.opal_dev);
+ free_opal_dev(dev->ctrl.opal_dev);
kfree(dev);
}
@@ -1789,14 +1789,17 @@ static void nvme_reset_work(struct work_struct *work)
if (result)
goto out;
- if ((dev->ctrl.oacs & NVME_CTRL_OACS_SEC_SUPP) && !dev->ctrl.opal_dev) {
- dev->ctrl.opal_dev =
- init_opal_dev(&dev->ctrl, &nvme_sec_submit);
+ if (dev->ctrl.oacs & NVME_CTRL_OACS_SEC_SUPP) {
+ if (!dev->ctrl.opal_dev)
+ dev->ctrl.opal_dev =
+ init_opal_dev(&dev->ctrl, &nvme_sec_submit);
+ else if (was_suspend)
+ opal_unlock_from_suspend(dev->ctrl.opal_dev);
+ } else {
+ free_opal_dev(dev->ctrl.opal_dev);
+ dev->ctrl.opal_dev = NULL;
}
- if (was_suspend)
- opal_unlock_from_suspend(dev->ctrl.opal_dev);
-
result = nvme_setup_io_queues(dev);
if (result)
goto out;
--
2.7.4
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] block/sed-opal: Propagate original error message to userland.
2017-02-22 17:15 Final opal patches for rc1 Scott Bauer
2017-02-22 17:15 ` [PATCH 1/3] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state Scott Bauer
2017-02-22 17:15 ` [PATCH 2/3] nvme/pci: re-check security protocol support after reset Scott Bauer
@ 2017-02-22 17:15 ` Scott Bauer
2017-02-23 18:57 ` Final opal patches for rc1 Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Scott Bauer @ 2017-02-22 17:15 UTC (permalink / raw)
To: linux-block
Cc: keith.busch, linux-nvme, axboe, jonathan.derrick, hch,
Scott Bauer
During an error on a comannd, ex: user provides wrong pw to unlock
range, we will gracefully terminate the opal session. We want to
propagate the original error to userland instead of the result of
the session termination, which is almost always a success.
Signed-off-by: Scott Bauer <scott.bauer@intel.com>
---
block/sed-opal.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 020bf3e..1e18dca 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -396,8 +396,11 @@ static int next(struct opal_dev *dev)
* session. Therefore we shouldn't attempt to terminate
* a session, as one has not yet been created.
*/
- if (state > 1)
- return end_opal_session_error(dev);
+ if (state > 1) {
+ end_opal_session_error(dev);
+ return error;
+ }
+
}
state++;
} while (!error);
--
2.7.4
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Final opal patches for rc1
2017-02-22 17:15 Final opal patches for rc1 Scott Bauer
` (2 preceding siblings ...)
2017-02-22 17:15 ` [PATCH 3/3] block/sed-opal: Propagate original error message to userland Scott Bauer
@ 2017-02-23 18:57 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2017-02-23 18:57 UTC (permalink / raw)
To: Scott Bauer, linux-block; +Cc: keith.busch, linux-nvme, hch, jonathan.derrick
On 02/22/2017 10:15 AM, Scott Bauer wrote:
> These are the final changes for rc1.
>
> Patch 1 contains some code to clean up an opal structure if something changes
> at runtime. (already reviewed by Christoph)
>
> Patch 2 contains changes to the nvme driver to use the above patch. If a new
> FW is loaded and we no longer support opal we clean up. This patch is based off
> code from Keith and Christoph.
>
> Patch 3 is a one line change to propagate an original error messaage to user
> land instead of the return status of the session termination code.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread