* [PATCH v2 0/2] ublk: Allow more than 64 ublk devices
@ 2023-10-12 15:05 Mike Christie
2023-10-12 15:05 ` [PATCH v2 1/2] ublk: Limit dev_id/ub_number values Mike Christie
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Mike Christie @ 2023-10-12 15:05 UTC (permalink / raw)
To: linux-block, ming.lei, axboe
The following patches were made over Linus's tree and also apply over
Jens's for-6.7/block and io_uring branches. They allow users to
configure the max number of ublk devices. We are currently converting
users from tcmu to ublk so the 64 device limit is too small, because we
have setups that have 512-1k devices.
V2:
- Set UBLK_MAX_UBLKS to UBLK_MINORS.
- Use param_set_uint_minmax.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] ublk: Limit dev_id/ub_number values
2023-10-12 15:05 [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Mike Christie
@ 2023-10-12 15:05 ` Mike Christie
2023-10-13 0:18 ` Ming Lei
2023-10-12 15:06 ` [PATCH v2 2/2] ublk: Make ublks_max configurable Mike Christie
2023-10-13 1:05 ` [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Jens Axboe
2 siblings, 1 reply; 6+ messages in thread
From: Mike Christie @ 2023-10-12 15:05 UTC (permalink / raw)
To: linux-block, ming.lei, axboe; +Cc: Mike Christie
The dev_id/ub_number is used for the ublk dev's char device's minor
number so it has to fit into MINORMASK. This patch adds checks to prevent
userspace from passing a number that's too large and limits what can be
allocated by the ublk_index_idr for the case where userspace has the
kernel allocate the dev_id/ub_number.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/block/ublk_drv.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 630ddfe6657b..ba7c6f9ee136 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -470,6 +470,7 @@ static DEFINE_MUTEX(ublk_ctl_mutex);
* It can be extended to one per-user limit in future or even controlled
* by cgroup.
*/
+#define UBLK_MAX_UBLKS UBLK_MINORS
static unsigned int ublks_max = 64;
static unsigned int ublks_added; /* protected by ublk_ctl_mutex */
@@ -2026,7 +2027,8 @@ static int ublk_alloc_dev_number(struct ublk_device *ub, int idx)
if (err == -ENOSPC)
err = -EEXIST;
} else {
- err = idr_alloc(&ublk_index_idr, ub, 0, 0, GFP_NOWAIT);
+ err = idr_alloc(&ublk_index_idr, ub, 0, UBLK_MAX_UBLKS,
+ GFP_NOWAIT);
}
spin_unlock(&ublk_idr_lock);
@@ -2305,6 +2307,12 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
return -EINVAL;
}
+ if (header->dev_id != U32_MAX && header->dev_id >= UBLK_MAX_UBLKS) {
+ pr_warn("%s: dev id is too large. Max supported is %d\n",
+ __func__, UBLK_MAX_UBLKS - 1);
+ return -EINVAL;
+ }
+
ublk_dump_dev_info(&info);
ret = mutex_lock_killable(&ublk_ctl_mutex);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] ublk: Make ublks_max configurable
2023-10-12 15:05 [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Mike Christie
2023-10-12 15:05 ` [PATCH v2 1/2] ublk: Limit dev_id/ub_number values Mike Christie
@ 2023-10-12 15:06 ` Mike Christie
2023-10-13 0:40 ` Ming Lei
2023-10-13 1:05 ` [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Jens Axboe
2 siblings, 1 reply; 6+ messages in thread
From: Mike Christie @ 2023-10-12 15:06 UTC (permalink / raw)
To: linux-block, ming.lei, axboe; +Cc: Mike Christie
We are converting tcmu applications to ublk, but have systems with up
to 1k devices. This patch allows us to configure the ublks_max from
userspace with the ublks_max modparam.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/block/ublk_drv.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index ba7c6f9ee136..b0bbda08ad45 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2940,7 +2940,22 @@ static void __exit ublk_exit(void)
module_init(ublk_init);
module_exit(ublk_exit);
-module_param(ublks_max, int, 0444);
+static int ublk_set_max_ublks(const char *buf, const struct kernel_param *kp)
+{
+ return param_set_uint_minmax(buf, kp, 0, UBLK_MAX_UBLKS);
+}
+
+static int ublk_get_max_ublks(char *buf, const struct kernel_param *kp)
+{
+ return sysfs_emit(buf, "%u\n", ublks_max);
+}
+
+static const struct kernel_param_ops ublk_max_ublks_ops = {
+ .set = ublk_set_max_ublks,
+ .get = ublk_get_max_ublks,
+};
+
+module_param_cb(ublks_max, &ublk_max_ublks_ops, &ublks_max, 0644);
MODULE_PARM_DESC(ublks_max, "max number of ublk devices allowed to add(default: 64)");
MODULE_AUTHOR("Ming Lei <ming.lei@redhat.com>");
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] ublk: Limit dev_id/ub_number values
2023-10-12 15:05 ` [PATCH v2 1/2] ublk: Limit dev_id/ub_number values Mike Christie
@ 2023-10-13 0:18 ` Ming Lei
0 siblings, 0 replies; 6+ messages in thread
From: Ming Lei @ 2023-10-13 0:18 UTC (permalink / raw)
To: Mike Christie; +Cc: linux-block, axboe
On Thu, Oct 12, 2023 at 10:05:59AM -0500, Mike Christie wrote:
> The dev_id/ub_number is used for the ublk dev's char device's minor
> number so it has to fit into MINORMASK. This patch adds checks to prevent
> userspace from passing a number that's too large and limits what can be
> allocated by the ublk_index_idr for the case where userspace has the
> kernel allocate the dev_id/ub_number.
>
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] ublk: Make ublks_max configurable
2023-10-12 15:06 ` [PATCH v2 2/2] ublk: Make ublks_max configurable Mike Christie
@ 2023-10-13 0:40 ` Ming Lei
0 siblings, 0 replies; 6+ messages in thread
From: Ming Lei @ 2023-10-13 0:40 UTC (permalink / raw)
To: Mike Christie; +Cc: linux-block, axboe
On Thu, Oct 12, 2023 at 10:06:00AM -0500, Mike Christie wrote:
> We are converting tcmu applications to ublk, but have systems with up
> to 1k devices. This patch allows us to configure the ublks_max from
> userspace with the ublks_max modparam.
>
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] ublk: Allow more than 64 ublk devices
2023-10-12 15:05 [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Mike Christie
2023-10-12 15:05 ` [PATCH v2 1/2] ublk: Limit dev_id/ub_number values Mike Christie
2023-10-12 15:06 ` [PATCH v2 2/2] ublk: Make ublks_max configurable Mike Christie
@ 2023-10-13 1:05 ` Jens Axboe
2 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2023-10-13 1:05 UTC (permalink / raw)
To: linux-block, ming.lei, Mike Christie
On Thu, 12 Oct 2023 10:05:58 -0500, Mike Christie wrote:
> The following patches were made over Linus's tree and also apply over
> Jens's for-6.7/block and io_uring branches. They allow users to
> configure the max number of ublk devices. We are currently converting
> users from tcmu to ublk so the 64 device limit is too small, because we
> have setups that have 512-1k devices.
>
> V2:
> - Set UBLK_MAX_UBLKS to UBLK_MINORS.
> - Use param_set_uint_minmax.
>
> [...]
Applied, thanks!
[1/2] ublk: Limit dev_id/ub_number values
commit: 8378a3e3718eb47f0ff404f4830fc07ea5c51f40
[2/2] ublk: Make ublks_max configurable
commit: aff3a66230e078e35cbaa7c68537e87dc78dd887
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-13 1:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-12 15:05 [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Mike Christie
2023-10-12 15:05 ` [PATCH v2 1/2] ublk: Limit dev_id/ub_number values Mike Christie
2023-10-13 0:18 ` Ming Lei
2023-10-12 15:06 ` [PATCH v2 2/2] ublk: Make ublks_max configurable Mike Christie
2023-10-13 0:40 ` Ming Lei
2023-10-13 1:05 ` [PATCH v2 0/2] ublk: Allow more than 64 ublk devices Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox