]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sed-opal: add IOC_OPAL_LR_SET_START_LEN ioctl.
authorOndrej Kozina <okozina@redhat.com>
Fri, 6 Feb 2026 14:18:00 +0000 (15:18 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 Mar 2026 20:29:59 +0000 (14:29 -0600)
This ioctl is used to set up locking range start (offset)
and locking range length attributes only.

In Single User Mode (SUM), if the RangeStartRangeLengthPolicy parameter
is set in the 'Reactivate' method, only Admin authority maintains the
locking range length and start (offset) attributes of Locking objects
set up for SUM. All other attributes from struct opal_user_lr_setup
(RLE - read locking enabled, WLE - write locking enabled) shall
remain in possession of the User authority associated with the Locking
object set for SUM.

Therefore, we need a separate function for setting up locking range
start and locking range length because it may require two different
authorities (and sessions) if the RangeStartRangeLengthPolicy attribute
is set.

With the IOC_OPAL_LR_SET_START_LEN ioctl, the opal_user_lr_setup
members 'RLE' and 'WLE' of the ioctl argument are ignored.

Signed-off-by: Ondrej Kozina <okozina@redhat.com>
Reviewed-and-tested-by: Milan Broz <gmazyland@gmail.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 7be72f621952c4c80e55e52cbff56232130e9a76..55c8a0953d78fa36967114794bfe4999ffd93648 100644 (file)
@@ -3091,6 +3091,31 @@ static int opal_setup_locking_range(struct opal_dev *dev,
        return ret;
 }
 
+static int opal_setup_locking_range_start_length(struct opal_dev *dev,
+                                   struct opal_user_lr_setup *opal_lrs)
+{
+       const struct opal_step lr_steps[] = {
+               { start_auth_opal_session, &opal_lrs->session },
+               { setup_locking_range_start_length, opal_lrs },
+               { end_opal_session, }
+       };
+       int ret;
+
+       /* we can not set global locking range offset or length */
+       if (opal_lrs->session.opal_key.lr == 0)
+               return -EINVAL;
+
+       ret = opal_get_key(dev, &opal_lrs->session.opal_key);
+       if (ret)
+               return ret;
+       mutex_lock(&dev->dev_lock);
+       setup_opal_dev(dev);
+       ret = execute_steps(dev, lr_steps, ARRAY_SIZE(lr_steps));
+       mutex_unlock(&dev->dev_lock);
+
+       return ret;
+}
+
 static int opal_locking_range_status(struct opal_dev *dev,
                          struct opal_lr_status *opal_lrst,
                          void __user *data)
@@ -3431,6 +3456,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
        case IOC_OPAL_REACTIVATE_LSP:
                ret = opal_reactivate_lsp(dev, p);
                break;
+       case IOC_OPAL_LR_SET_START_LEN:
+               ret = opal_setup_locking_range_start_length(dev, p);
+               break;
 
        default:
                break;
index 2ae5e6b0ac2139a77363486e80f80ba0917824a7..a0df6819b0a93c40ee51d80517c90955daedf928 100644 (file)
@@ -54,6 +54,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
        case IOC_OPAL_REVERT_LSP:
        case IOC_OPAL_SET_SID_PW:
        case IOC_OPAL_REACTIVATE_LSP:
+       case IOC_OPAL_LR_SET_START_LEN:
                return true;
        }
        return false;
index d03e590b6501281e9449798ebacb6b264da763e7..82de38f3fbeb8e216e9a4258badeff2054f0ba88 100644 (file)
@@ -230,5 +230,6 @@ struct opal_revert_lsp {
 #define IOC_OPAL_REVERT_LSP         _IOW('p', 240, struct opal_revert_lsp)
 #define IOC_OPAL_SET_SID_PW         _IOW('p', 241, struct opal_new_pw)
 #define IOC_OPAL_REACTIVATE_LSP     _IOW('p', 242, struct opal_lr_react)
+#define IOC_OPAL_LR_SET_START_LEN   _IOW('p', 243, struct opal_user_lr_setup)
 
 #endif /* _UAPI_SED_OPAL_H */