block: sed-opal: add ioctl for done-mark of shadow mbr
authorJonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
Tue, 21 May 2019 20:46:44 +0000 (22:46 +0200)
committerJens Axboe <axboe@kernel.dk>
Sat, 29 Jun 2019 16:31:33 +0000 (10:31 -0600)
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.

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: Christoph Hellwig <hch@lst.de>
Reviewed by: Scott Bauer <sbauer@plzdonthack.me>
Reviewed-by: Jon Derrick <jonathan.derrick@intel.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/sed-opal.c
include/linux/sed-opal.h
include/uapi/linux/sed-opal.h

index c54019c11e916d0ca66ec43b781dd5c269b6d280..f94f359dd68807753ee4d44fe401b40cb4eb0c7e 100644 (file)
@@ -1989,6 +1989,30 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
        return ret;
 }
 
+static int opal_set_mbr_done(struct opal_dev *dev,
+                            struct opal_mbr_done *mbr_done)
+{
+       u8 mbr_done_tf = mbr_done->done_flag == OPAL_MBR_DONE ?
+               OPAL_TRUE : OPAL_FALSE;
+
+       const struct opal_step mbr_steps[] = {
+               { start_admin1LSP_opal_session, &mbr_done->key },
+               { set_mbr_done, &mbr_done_tf },
+               { end_opal_session, }
+       };
+       int ret;
+
+       if (mbr_done->done_flag != OPAL_MBR_DONE &&
+           mbr_done->done_flag != OPAL_MBR_NOT_DONE)
+               return -EINVAL;
+
+       mutex_lock(&dev->dev_lock);
+       setup_opal_dev(dev);
+       ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
+       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;
@@ -2310,6 +2334,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_DONE:
+               ret = opal_set_mbr_done(dev, p);
+               break;
        case IOC_OPAL_ERASE_LR:
                ret = opal_erase_locking_range(dev, p);
                break;
index f03bbffd328174872a184d63114521e47846ef13..f834e8a1495f11cc36c0191a340affc7abe17963 100644 (file)
@@ -40,6 +40,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
        case IOC_OPAL_ERASE_LR:
        case IOC_OPAL_SECURE_ERASE_LR:
        case IOC_OPAL_PSID_REVERT_TPR:
+       case IOC_OPAL_MBR_DONE:
                return true;
        }
        return false;
index 7a03e5b4df6e06d4881830f1ab74893f7891d1df..5681f55d334be320dbc1d2f26728c5cd62ff4b9d 100644 (file)
@@ -20,6 +20,11 @@ enum opal_mbr {
        OPAL_MBR_DISABLE = 0x01,
 };
 
+enum opal_mbr_done_flag {
+       OPAL_MBR_NOT_DONE = 0x0,
+       OPAL_MBR_DONE = 0x01
+};
+
 enum opal_user {
        OPAL_ADMIN1 = 0x0,
        OPAL_USER1 = 0x01,
@@ -95,6 +100,12 @@ struct opal_mbr_data {
        __u8 __align[7];
 };
 
+struct opal_mbr_done {
+       struct opal_key key;
+       __u8 done_flag;
+       __u8 __align[7];
+};
+
 #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)
@@ -108,5 +119,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_PSID_REVERT_TPR    _IOW('p', 232, struct opal_key)
+#define IOC_OPAL_MBR_DONE           _IOW('p', 233, struct opal_mbr_done)
 
 #endif /* _UAPI_SED_OPAL_H */