ublk: Allow more than 64 ublk devices
Subsystems (2)
v2 cover ublk: Allow more than 64 ublk devices
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.
PATCH v2 1/2 ublk: Limit dev_id/ub_number values
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.
--- drivers/block/ublk_drv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +9 -1
@@ -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_MINORSstatic 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);
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] ublk: Limit dev_id/ub_number values
Quoted 7 lines · 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_idrfor the case where userspace has the kernel allocate the dev_id/ub_number.Signed-off-by Mike Christie <[email protected]>
Thanks,
Ming
PATCH v2 2/2 ublk: Make ublks_max configurable
In reply to Mike ChristieWe 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.
--- drivers/block/ublk_drv.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +16 -1
@@ -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 <[email protected]>" );
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] ublk: Make ublks_max configurable
Quoted 5 lines · 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_maxfrom userspace with theublks_maxmodparam.Signed-off-by Mike Christie <[email protected]>
Thanks,
Ming
Quoted 11 lines · Mike Christie
The following patches were made over Linus's tree and also apply over Jens's for-6.7/block and
io_uringbranches. 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:
- SetUBLK_MAX_UBLKStoUBLK_MINORS.
- Useparam_set_uint_minmax.[...]
Applied, thanks!
[1/2] ublk: Limit dev_id/ub_number values
commit: 8378a3e3718eb47f0ff404f4830fc07ea5c51f40
[2/2] ublk: Make ublks_max configurable
commit: aff3a66230e078e35cbaa7c68537e87dc78dd887Best regards,
Signature · 1 line
Jens Axboe