Skip to content

Conversation

@blktests-ci
Copy link

@blktests-ci blktests-ci bot commented Dec 8, 2025

Pull request for series with
subject: block: add IOC_PR_READ_KEYS and IOC_PR_READ_RESERVATION ioctls
version: 3
url: https://patchwork.kernel.org/project/linux-block/list/?series=1029438

kawasaki and others added 5 commits December 8, 2025 14:14
The pr_read_keys() interface has a u32 num_keys parameter. The SCSI
PERSISTENT RESERVE IN command has a maximum READ KEYS service action
size of 65536 bytes. Reject num_keys values that are too large to fit
into the SCSI command.

This will become important when pr_read_keys() is exposed to untrusted
userspace via an <linux/pr.h> ioctl.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
The pr_read_keys() interface has a u32 num_keys parameter. The NVMe
Reservation Report command has a u32 maximum length. Reject num_keys
values that are too large to fit.

This will become important when pr_read_keys() is exposed to untrusted
userspace via an <linux/pr.h> ioctl.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Add a Persistent Reservations ioctl to read the list of currently
registered reservation keys. This calls the pr_ops->read_keys() function
that was previously added in commit c787f1b ("block: Add PR
callouts for read keys and reservation") but was only used by the
in-kernel SCSI target so far.

The IOC_PR_READ_KEYS ioctl is necessary so that userspace applications
that rely on Persistent Reservations ioctls have a way of inspecting the
current state. Cluster managers and validation tests need this
functionality.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Add a Persistent Reservations ioctl to read the current reservation.
This calls the pr_ops->read_reservation() function that was previously
added in commit c787f1b ("block: Add PR callouts for read keys and
reservation") but was only used by the in-kernel SCSI target so far.

The IOC_PR_READ_RESERVATION ioctl is necessary so that userspace
applications that rely on Persistent Reservations ioctls have a way of
inspecting the current state. Cluster managers and validation tests need
this functionality.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
@blktests-ci
Copy link
Author

blktests-ci bot commented Dec 8, 2025

Upstream branch: c2f2b01
series: https://patchwork.kernel.org/project/linux-block/list/?series=1029438
version: 3

@blktests-ci
Copy link
Author

blktests-ci bot commented Dec 28, 2025

Upstream branch: d26143b
series: https://patchwork.kernel.org/project/linux-block/list/?series=1029438
version: 3

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-block/list/?series=1029438
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: scsi: sd: reject invalid pr_read_keys() num_keys values
Using index info to reconstruct a base tree...
M	drivers/scsi/sd.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/scsi/sd.c
No changes -- Patch already applied.
Applying: nvme: reject invalid pr_read_keys() num_keys values
Using index info to reconstruct a base tree...
M	drivers/nvme/host/pr.c
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: block: add IOC_PR_READ_KEYS ioctl
Using index info to reconstruct a base tree...
M	block/ioctl.c
M	include/uapi/linux/pr.h
Falling back to patching base and 3-way merge...
Auto-merging include/uapi/linux/pr.h
CONFLICT (content): Merge conflict in include/uapi/linux/pr.h
Auto-merging block/ioctl.c
CONFLICT (content): Merge conflict in block/ioctl.c
Patch failed at 0003 block: add IOC_PR_READ_KEYS ioctl'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"'

conflict:

diff --cc block/ioctl.c
index 344478348a54,95ce9aa90bba..000000000000
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@@ -442,12 -442,11 +442,20 @@@ static int blkdev_pr_read_keys(struct b
  	if (copy_from_user(&read_keys, arg, sizeof(read_keys)))
  		return -EFAULT;
  
++<<<<<<< HEAD
 +	if (read_keys.num_keys > PR_KEYS_MAX)
 +		return -EINVAL;
 +
 +	keys_info_len = struct_size(keys_info, keys, read_keys.num_keys);
 +
 +	keys_info = kvzalloc(keys_info_len, GFP_KERNEL);
++=======
+ 	keys_info_len = struct_size(keys_info, keys, read_keys.num_keys);
+ 	if (keys_info_len == SIZE_MAX)
+ 		return -EINVAL;
+ 
+ 	keys_info = kzalloc(keys_info_len, GFP_KERNEL);
++>>>>>>> block: add IOC_PR_READ_KEYS ioctl
  	if (!keys_info)
  		return -ENOMEM;
  
@@@ -474,36 -473,10 +482,43 @@@
  	if (copy_to_user(arg, &read_keys, sizeof(read_keys)))
  		ret = -EFAULT;
  out:
++<<<<<<< HEAD
 +	kvfree(keys_info);
 +	return ret;
 +}
 +
 +static int blkdev_pr_read_reservation(struct block_device *bdev,
 +		blk_mode_t mode, struct pr_read_reservation __user *arg)
 +{
 +	const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
 +	struct pr_held_reservation rsv = {};
 +	struct pr_read_reservation out = {};
 +	int ret;
 +
 +	if (!blkdev_pr_allowed(bdev, mode))
 +		return -EPERM;
 +	if (!ops || !ops->pr_read_reservation)
 +		return -EOPNOTSUPP;
 +
 +	ret = ops->pr_read_reservation(bdev, &rsv);
 +	if (ret)
 +		return ret;
 +
 +	out.key = rsv.key;
 +	out.generation = rsv.generation;
 +	out.type = rsv.type;
 +
 +	if (copy_to_user(arg, &out, sizeof(out)))
 +		return -EFAULT;
 +	return 0;
 +}
 +
++=======
+ 	kfree(keys_info);
+ 	return ret;
+ }
+ 
++>>>>>>> block: add IOC_PR_READ_KEYS ioctl
  static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
  		unsigned long arg)
  {
@@@ -728,8 -700,6 +743,11 @@@ static int blkdev_common_ioctl(struct b
  		return blkdev_pr_clear(bdev, mode, argp);
  	case IOC_PR_READ_KEYS:
  		return blkdev_pr_read_keys(bdev, mode, argp);
++<<<<<<< HEAD
 +	case IOC_PR_READ_RESERVATION:
 +		return blkdev_pr_read_reservation(bdev, mode, argp);
++=======
++>>>>>>> block: add IOC_PR_READ_KEYS ioctl
  	default:
  		return blk_get_meta_cap(bdev, cmd, argp);
  	}
diff --cc include/uapi/linux/pr.h
index f0ecb1677317,fcb74eab92c8..000000000000
--- a/include/uapi/linux/pr.h
+++ b/include/uapi/linux/pr.h
@@@ -62,12 -62,6 +62,15 @@@ struct pr_read_keys 
  	__u64	keys_ptr;
  };
  
++<<<<<<< HEAD
 +struct pr_read_reservation {
 +	__u64	key;
 +	__u32	generation;
 +	__u32	type;
 +};
 +
++=======
++>>>>>>> block: add IOC_PR_READ_KEYS ioctl
  #define PR_FL_IGNORE_KEY	(1 << 0)	/* ignore existing key */
  
  #define IOC_PR_REGISTER		_IOW('p', 200, struct pr_registration)
@@@ -77,8 -71,5 +80,11 @@@
  #define IOC_PR_PREEMPT_ABORT	_IOW('p', 204, struct pr_preempt)
  #define IOC_PR_CLEAR		_IOW('p', 205, struct pr_clear)
  #define IOC_PR_READ_KEYS	_IOWR('p', 206, struct pr_read_keys)
++<<<<<<< HEAD
 +#define IOC_PR_READ_RESERVATION	_IOR('p', 207, struct pr_read_reservation)
 +
 +#define PR_KEYS_MAX		(1u << 16)
++=======
++>>>>>>> block: add IOC_PR_READ_KEYS ioctl
  
  #endif /* _UAPI_PR_H */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants