Final opal patches for rc1
Subsystems (3)
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.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 1/3 block/sed-opal: Introduce free_opal_dev to free the structure and clean up state
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.
--- block/sed-opal.c | 30 ++++++++++++++++++++++++++++++ include/linux/sed-opal.h | 5 +++++ 2 files changed, 35 insertions(+)
block/sed-opal.c +30 -0
@@ -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; }
include/linux/sed-opal.h +5 -0
@@ -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;
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 2/3 nvme/pci: re-check security protocol support after reset
In reply to Scott BauerA 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.
--- drivers/nvme/host/pci.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/nvme/host/pci.c +10 -7
@@ -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;
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 3/3 block/sed-opal: Propagate original error message to userland.
In reply to Scott BauerDuring 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.
--- block/sed-opal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
block/sed-opal.c +5 -2
@@ -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);
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Jens Axboe
AppliedQuoted 11 lines · Scott Bauer
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.
Signature · 1 line
Jens Axboe