Skip to contentSkip to conversation

block: sed-opal: Add ioctl to return device status

PATCH Applied [email protected] 3 participants 5 messages Aug 16, 2022 – Aug 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 block: sed-opal: Add ioctl to return device status

From: "[email protected]" <[email protected]>

Provide a mechanism to retrieve basic status information about the device, including the "supported" flag indicating whether SED-OPAL is supported. The information returned is from the various feature descriptors received during the discovery0 step, and so this ioctl does nothing more than perform the discovery0 step and then save the information received. See "struct opal_status" and OPAL_FL_* bits for the status information currently returned.

This is necessary to be able to check whether a device is OPAL enabled, set up, locked or unlocked from userspace programs like systemd-cryptsetup and libcryptsetup. Right now we just have to assume the user 'knows' or blindly attempt setup/lock/unlock operations.

---
v2: https://patchwork.kernel.org/project/linux-block/patch/612795b5.tj7FMS9wzchsMzrK%[email protected]/
v3: resend on request, after rebasing and testing on my machine

    https://patchwork.kernel.org/project/linux-block/patch/[email protected]/

v4: it's been more than 7 months and no alternative approach has appeared.
we really need to be able to identify and query the status of a sed-opal device, so rebased and resending.
v5: as requested by reviewer, add __32 reserved to the UAPI ioctl struct to align to 64
bits and to reserve space for future expansion
v6: as requested by reviewer, update commit message with use case
v7: as requested by reviewer, remove braces around single-line 'if'
added received acked-by/reviewed-by tags

 block/opal_proto.h            |  5 ++
 block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++-----
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h | 13 +++++
 4 files changed, 96 insertions(+), 12 deletions(-)
block/opal_proto.h +5 -0
index b486b3ec7dc4..7152aa1f1a49 100644
@@ -39,7 +39,12 @@ enum opal_response_token {
 #define FIRST_TPER_SESSION_NUM	4096
 
 #define TPER_SYNC_SUPPORTED 0x01
+/* FC_LOCKING features */
+#define LOCKING_SUPPORTED_MASK 0x01
+#define LOCKING_ENABLED_MASK 0x02
+#define LOCKED_MASK 0x04
 #define MBR_ENABLED_MASK 0x10
+#define MBR_DONE_MASK 0x20
 
 #define TINY_ATOM_DATA_MASK 0x3F
 #define TINY_ATOM_SIGNED 0x40
block/sed-opal.c +77 -12

167 lines not on this page · raw message

include/linux/sed-opal.h +1 -0
index 1ac0d712a9c3..6f837bb6c715 100644
@@ -43,6 +43,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
 	case IOC_OPAL_MBR_DONE:
 	case IOC_OPAL_WRITE_SHADOW_MBR:
 	case IOC_OPAL_GENERIC_TABLE_RW:
+	case IOC_OPAL_GET_STATUS:
 		return true;
 	}
 	return false;
include/uapi/linux/sed-opal.h +13 -0
index 6f5af1a84213..2573772e2fb3 100644
@@ -132,6 +132,18 @@ struct opal_read_write_table {
 	__u64 priv;
 };
 
+#define OPAL_FL_SUPPORTED		0x00000001
+#define OPAL_FL_LOCKING_SUPPORTED	0x00000002
+#define OPAL_FL_LOCKING_ENABLED		0x00000004
+#define OPAL_FL_LOCKED			0x00000008
+#define OPAL_FL_MBR_ENABLED		0x00000010
+#define OPAL_FL_MBR_DONE		0x00000020
+
+struct opal_status {
+	__u32 flags;
+	__u32 reserved;
+};
+
 #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)
@@ -148,5 +160,6 @@ struct opal_read_write_table {
 #define IOC_OPAL_MBR_DONE           _IOW('p', 233, struct opal_mbr_done)
 #define IOC_OPAL_WRITE_SHADOW_MBR   _IOW('p', 234, struct opal_shadow_mbr)
 #define IOC_OPAL_GENERIC_TABLE_RW   _IOW('p', 235, struct opal_read_write_table)
+#define IOC_OPAL_GET_STATUS         _IOR('p', 236, struct opal_status)
 
 #endif /* _UAPI_SED_OPAL_H */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 34 lines · On Tue, 16 Aug 2022 at 15:07, <[email protected]> wrote:

From: "[email protected]" <[email protected]>

Provide a mechanism to retrieve basic status information about the device, including the "supported" flag indicating whether SED-OPAL is supported. The information returned is from the various feature descriptors received during the discovery0 step, and so this ioctl does nothing more than perform the discovery0 step and then save the information received. See "struct opal_status" and OPAL_FL_* bits for the status information currently returned.

This is necessary to be able to check whether a device is OPAL enabled, set up, locked or unlocked from userspace programs like systemd-cryptsetup and libcryptsetup. Right now we just have to assume the user 'knows' or blindly attempt setup/lock/unlock operations.

---
v2: https://patchwork.kernel.org/project/linux-block/patch/612795b5.tj7FMS9wzchsMzrK%[email protected]/
v3: resend on request, after rebasing and testing on my machine

    https://patchwork.kernel.org/project/linux-block/patch/[email protected]/

v4: it's been more than 7 months and no alternative approach has appeared.
we really need to be able to identify and query the status of a sed-opal device, so rebased and resending.
v5: as requested by reviewer, add __32 reserved to the UAPI ioctl struct to align to 64
bits and to reserve space for future expansion
v6: as requested by reviewer, update commit message with use case
v7: as requested by reviewer, remove braces around single-line 'if'
added received acked-by/reviewed-by tags

Quoted 5 lines
 block/opal_proto.h            |  5 ++
 block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++-----
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h | 13 +++++
 4 files changed, 96 insertions(+), 12 deletions(-)

Hello Jens,

Is there anything else I can do for this patch? I've got two acks. We really need this interface in place to start working on supporting sed/opal in cryptsetup.

Thanks!

Kind regards,
Luca Boccassi

maintainer
#2 lore raw
Quoted 41 lines · Luca Boccassi
Quoted 34 lines · On Tue, 16 Aug 2022 at 15:07, <[email protected]> wrote:

From: "[email protected]" <[email protected]>

Provide a mechanism to retrieve basic status information about the device, including the "supported" flag indicating whether SED-OPAL is supported. The information returned is from the various feature descriptors received during the discovery0 step, and so this ioctl does nothing more than perform the discovery0 step and then save the information received. See "struct opal_status" and OPAL_FL_* bits for the status information currently returned.

This is necessary to be able to check whether a device is OPAL enabled, set up, locked or unlocked from userspace programs like systemd-cryptsetup and libcryptsetup. Right now we just have to assume the user 'knows' or blindly attempt setup/lock/unlock operations.

---
v2: https://patchwork.kernel.org/project/linux-block/patch/612795b5.tj7FMS9wzchsMzrK%[email protected]/
v3: resend on request, after rebasing and testing on my machine

    https://patchwork.kernel.org/project/linux-block/patch/[email protected]/

v4: it's been more than 7 months and no alternative approach has appeared.
we really need to be able to identify and query the status of a sed-opal device, so rebased and resending.
v5: as requested by reviewer, add __32 reserved to the UAPI ioctl struct to align to 64
bits and to reserve space for future expansion
v6: as requested by reviewer, update commit message with use case
v7: as requested by reviewer, remove braces around single-line 'if'
added received acked-by/reviewed-by tags

Quoted 5 lines
 block/opal_proto.h            |  5 ++
 block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++-----
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h | 13 +++++
 4 files changed, 96 insertions(+), 12 deletions(-)
Quoted 5 lines

Hello Jens,

Is there anything else I can do for this patch? I've got two acks. We really need this interface in place to start working on supporting sed/opal in cryptsetup.

It's just bad timing, since we just left the merge window. I'll queue it up when I open up the block bits for 6.1.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 49 lines · Jens Axboe
Quoted 41 lines · Luca Boccassi
Quoted 34 lines · On Tue, 16 Aug 2022 at 15:07, <[email protected]> wrote:

From: "[email protected]" <[email protected]>

Provide a mechanism to retrieve basic status information about the device, including the "supported" flag indicating whether SED-OPAL is supported. The information returned is from the various feature descriptors received during the discovery0 step, and so this ioctl does nothing more than perform the discovery0 step and then save the information received. See "struct opal_status" and OPAL_FL_* bits for the status information currently returned.

This is necessary to be able to check whether a device is OPAL enabled, set up, locked or unlocked from userspace programs like systemd-cryptsetup and libcryptsetup. Right now we just have to assume the user 'knows' or blindly attempt setup/lock/unlock operations.

---
v2: https://patchwork.kernel.org/project/linux-block/patch/612795b5.tj7FMS9wzchsMzrK%[email protected]/
v3: resend on request, after rebasing and testing on my machine

    https://patchwork.kernel.org/project/linux-block/patch/[email protected]/

v4: it's been more than 7 months and no alternative approach has appeared.
we really need to be able to identify and query the status of a sed-opal device, so rebased and resending.
v5: as requested by reviewer, add __32 reserved to the UAPI ioctl struct to align to 64
bits and to reserve space for future expansion
v6: as requested by reviewer, update commit message with use case
v7: as requested by reviewer, remove braces around single-line 'if'
added received acked-by/reviewed-by tags

Quoted 5 lines
 block/opal_proto.h            |  5 ++
 block/sed-opal.c              | 89 ++++++++++++++++++++++++++++++-----
 include/linux/sed-opal.h      |  1 +
 include/uapi/linux/sed-opal.h | 13 +++++
 4 files changed, 96 insertions(+), 12 deletions(-)
Quoted 5 lines

Hello Jens,

Is there anything else I can do for this patch? I've got two acks. We really need this interface in place to start working on supporting sed/opal in cryptsetup.

Quoted 5 lines

It's just bad timing, since we just left the merge window. I'll queue it up when I open up the block bits for 6.1.

--
Jens Axboe

Thanks!

Kind regards,
Luca Boccassi

maintainer Applied
#4 lore raw
In reply to [email protected]
Quoted 11 lines · On Tue, 16 Aug 2022 15:07:13 +0100, [email protected] wrote:

From: "[email protected]" <[email protected]>

Provide a mechanism to retrieve basic status information about the device, including the "supported" flag indicating whether SED-OPAL is supported. The information returned is from the various feature descriptors received during the discovery0 step, and so this ioctl does nothing more than perform the discovery0 step and then save the information received. See "struct opal_status" and OPAL_FL_* bits for the status information currently returned.

[...]

Applied, thanks!

[1/1] block: sed-opal: Add ioctl to return device status

      commit: 5ba3cd2f94a4fbc952f7a343a267e5c570412dd8

Best regards,

Signature · 1 line
Jens Axboe