summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>2019-05-21 16:46:44 -0400
committerJens Axboe <axboe@kernel.dk>2019-06-29 12:31:33 -0400
commitc9888443413e4e06013e482fc484dbb9c559c145 (patch)
tree80a5698e6cf15049f1464ad6b305da731a7aed70
parentb620743077e291ae7d0debd21f50413a8c266229 (diff)
block: sed-opal: add ioctl for done-mark of shadow mbr
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>
-rw-r--r--block/sed-opal.c27
-rw-r--r--include/linux/sed-opal.h1
-rw-r--r--include/uapi/linux/sed-opal.h12
3 files changed, 40 insertions, 0 deletions
diff --git a/block/sed-opal.c b/block/sed-opal.c
index c54019c11e91..f94f359dd688 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -1989,6 +1989,30 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
1989 return ret; 1989 return ret;
1990} 1990}
1991 1991
1992static int opal_set_mbr_done(struct opal_dev *dev,
1993 struct opal_mbr_done *mbr_done)
1994{
1995 u8 mbr_done_tf = mbr_done->done_flag == OPAL_MBR_DONE ?
1996 OPAL_TRUE : OPAL_FALSE;
1997
1998 const struct opal_step mbr_steps[] = {
1999 { start_admin1LSP_opal_session, &mbr_done->key },
2000 { set_mbr_done, &mbr_done_tf },
2001 { end_opal_session, }
2002 };
2003 int ret;
2004
2005 if (mbr_done->done_flag != OPAL_MBR_DONE &&
2006 mbr_done->done_flag != OPAL_MBR_NOT_DONE)
2007 return -EINVAL;
2008
2009 mutex_lock(&dev->dev_lock);
2010 setup_opal_dev(dev);
2011 ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
2012 mutex_unlock(&dev->dev_lock);
2013 return ret;
2014}
2015
1992static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk) 2016static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
1993{ 2017{
1994 struct opal_suspend_data *suspend; 2018 struct opal_suspend_data *suspend;
@@ -2310,6 +2334,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
2310 case IOC_OPAL_ENABLE_DISABLE_MBR: 2334 case IOC_OPAL_ENABLE_DISABLE_MBR:
2311 ret = opal_enable_disable_shadow_mbr(dev, p); 2335 ret = opal_enable_disable_shadow_mbr(dev, p);
2312 break; 2336 break;
2337 case IOC_OPAL_MBR_DONE:
2338 ret = opal_set_mbr_done(dev, p);
2339 break;
2313 case IOC_OPAL_ERASE_LR: 2340 case IOC_OPAL_ERASE_LR:
2314 ret = opal_erase_locking_range(dev, p); 2341 ret = opal_erase_locking_range(dev, p);
2315 break; 2342 break;
diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
index f03bbffd3281..f834e8a1495f 100644
--- a/include/linux/sed-opal.h
+++ b/include/linux/sed-opal.h
@@ -40,6 +40,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
40 case IOC_OPAL_ERASE_LR: 40 case IOC_OPAL_ERASE_LR:
41 case IOC_OPAL_SECURE_ERASE_LR: 41 case IOC_OPAL_SECURE_ERASE_LR:
42 case IOC_OPAL_PSID_REVERT_TPR: 42 case IOC_OPAL_PSID_REVERT_TPR:
43 case IOC_OPAL_MBR_DONE:
43 return true; 44 return true;
44 } 45 }
45 return false; 46 return false;
diff --git a/include/uapi/linux/sed-opal.h b/include/uapi/linux/sed-opal.h
index 7a03e5b4df6e..5681f55d334b 100644
--- a/include/uapi/linux/sed-opal.h
+++ b/include/uapi/linux/sed-opal.h
@@ -20,6 +20,11 @@ enum opal_mbr {
20 OPAL_MBR_DISABLE = 0x01, 20 OPAL_MBR_DISABLE = 0x01,
21}; 21};
22 22
23enum opal_mbr_done_flag {
24 OPAL_MBR_NOT_DONE = 0x0,
25 OPAL_MBR_DONE = 0x01
26};
27
23enum opal_user { 28enum opal_user {
24 OPAL_ADMIN1 = 0x0, 29 OPAL_ADMIN1 = 0x0,
25 OPAL_USER1 = 0x01, 30 OPAL_USER1 = 0x01,
@@ -95,6 +100,12 @@ struct opal_mbr_data {
95 __u8 __align[7]; 100 __u8 __align[7];
96}; 101};
97 102
103struct opal_mbr_done {
104 struct opal_key key;
105 __u8 done_flag;
106 __u8 __align[7];
107};
108
98#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock) 109#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock)
99#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock) 110#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock)
100#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key) 111#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key)
@@ -108,5 +119,6 @@ struct opal_mbr_data {
108#define IOC_OPAL_ERASE_LR _IOW('p', 230, struct opal_session_info) 119#define IOC_OPAL_ERASE_LR _IOW('p', 230, struct opal_session_info)
109#define IOC_OPAL_SECURE_ERASE_LR _IOW('p', 231, struct opal_session_info) 120#define IOC_OPAL_SECURE_ERASE_LR _IOW('p', 231, struct opal_session_info)
110#define IOC_OPAL_PSID_REVERT_TPR _IOW('p', 232, struct opal_key) 121#define IOC_OPAL_PSID_REVERT_TPR _IOW('p', 232, struct opal_key)
122#define IOC_OPAL_MBR_DONE _IOW('p', 233, struct opal_mbr_done)
111 123
112#endif /* _UAPI_SED_OPAL_H */ 124#endif /* _UAPI_SED_OPAL_H */