* [PATCH] misc: Increase available dyanmic minors
@ 2014-12-08 23:01 Keith Busch
2014-12-09 8:46 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Keith Busch @ 2014-12-08 23:01 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arnd Bergmann, linux-kernel; +Cc: linux-nvme, Keith Busch
This increases the number of available miscellaneous character device
dynamic minors from 63 to the max minor, 1M.
Dynamic minor previously started at 63 and went down to zero. That's not
enough in some situations, and also eventually creates a collision with
'psaux' misc device. This patch starts minors at the last defined misc
minor (255) and works up to the max possible.
Signed-off-by: Keith Busch <keith.busch@intel.com>
---
drivers/char/misc.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index ffa97d2..229dba5 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -59,8 +59,7 @@ static DEFINE_MUTEX(misc_mtx);
/*
* Assigned numbers, used for dynamic minors
*/
-#define DYNAMIC_MINORS 64 /* like dynamic majors */
-static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS);
+static DEFINE_IDA(misc_minors_ida);
#ifdef CONFIG_PROC_FS
static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
@@ -183,15 +182,14 @@ int misc_register(struct miscdevice * misc)
INIT_LIST_HEAD(&misc->list);
mutex_lock(&misc_mtx);
-
if (misc->minor == MISC_DYNAMIC_MINOR) {
- int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
- if (i >= DYNAMIC_MINORS) {
+ int i = ida_simple_get(&misc_minors_ida, MISC_DYNAMIC_MINOR,
+ MINORMASK, GFP_KERNEL);
+ if (i < 0) {
err = -EBUSY;
goto out;
}
- misc->minor = DYNAMIC_MINORS - i - 1;
- set_bit(i, misc_minors);
+ misc->minor = i;
} else {
struct miscdevice *c;
@@ -208,9 +206,8 @@ int misc_register(struct miscdevice * misc)
misc->this_device = device_create(misc_class, misc->parent, dev,
misc, "%s", misc->name);
if (IS_ERR(misc->this_device)) {
- int i = DYNAMIC_MINORS - misc->minor - 1;
- if (i < DYNAMIC_MINORS && i >= 0)
- clear_bit(i, misc_minors);
+ if (misc->minor >= MISC_DYNAMIC_MINOR)
+ ida_simple_remove(&misc_minors_ida, misc->minor);
err = PTR_ERR(misc->this_device);
goto out;
}
@@ -237,16 +234,14 @@ int misc_register(struct miscdevice * misc)
int misc_deregister(struct miscdevice *misc)
{
- int i = DYNAMIC_MINORS - misc->minor - 1;
-
if (WARN_ON(list_empty(&misc->list)))
return -EINVAL;
mutex_lock(&misc_mtx);
list_del(&misc->list);
device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
- if (i < DYNAMIC_MINORS && i >= 0)
- clear_bit(i, misc_minors);
+ if (misc->minor >= MISC_DYNAMIC_MINOR)
+ ida_simple_remove(&misc_minors_ida, misc->minor);
mutex_unlock(&misc_mtx);
return 0;
}
--
1.7.10.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: Increase available dyanmic minors
2014-12-08 23:01 [PATCH] misc: Increase available dyanmic minors Keith Busch
@ 2014-12-09 8:46 ` Arnd Bergmann
2014-12-09 16:15 ` Keith Busch
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2014-12-09 8:46 UTC (permalink / raw)
To: Keith Busch; +Cc: Greg Kroah-Hartman, linux-kernel, linux-nvme
On Monday 08 December 2014 16:01:50 Keith Busch wrote:
> This increases the number of available miscellaneous character device
> dynamic minors from 63 to the max minor, 1M.
>
> Dynamic minor previously started at 63 and went down to zero. That's not
> enough in some situations, and also eventually creates a collision with
> 'psaux' misc device. This patch starts minors at the last defined misc
> minor (255) and works up to the max possible.
>
> Signed-off-by: Keith Busch <keith.busch@intel.com>
I guess this will break support for ancient user space tools, and
possibly also old file systems that do not support more than 8-bit
minor numbers. I would assume that it's ok, but you definitely have
to mention in the changelog that things might break and how you
have concluded that this is safe enough.
If you cannot come up with a good reasoning, it might be better
to combine both and use up the traditional dynamic minor numbers
before using the >255 range.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: Increase available dyanmic minors
2014-12-09 8:46 ` Arnd Bergmann
@ 2014-12-09 16:15 ` Keith Busch
0 siblings, 0 replies; 3+ messages in thread
From: Keith Busch @ 2014-12-09 16:15 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Keith Busch, Greg Kroah-Hartman, linux-kernel, linux-nvme
On Tue, 9 Dec 2014, Arnd Bergmann wrote:
> On Monday 08 December 2014 16:01:50 Keith Busch wrote:
>> This increases the number of available miscellaneous character device
>> dynamic minors from 63 to the max minor, 1M.
>>
>> Dynamic minor previously started at 63 and went down to zero. That's not
>> enough in some situations, and also eventually creates a collision with
>> 'psaux' misc device. This patch starts minors at the last defined misc
>> minor (255) and works up to the max possible.
>>
>> Signed-off-by: Keith Busch <keith.busch@intel.com>
>
> I guess this will break support for ancient user space tools, and
> possibly also old file systems that do not support more than 8-bit
> minor numbers. I would assume that it's ok, but you definitely have
> to mention in the changelog that things might break and how you
> have concluded that this is safe enough.
Sure, I can call this out in the change log. I hadn't considered file
systems on a character device. Tooling as well.
If a character device is so tightly coupled to such legacy tools, maybe
they should register a static minor, and this patch makes 63 additional
ones available. Does that sound reasonable?
> If you cannot come up with a good reasoning, it might be better
> to combine both and use up the traditional dynamic minor numbers
> before using the >255 range.
A problem with the existing method is that anyone can use a number in the
range it's dynamically allocating from. Once you encounter a collision,
all following dynamic misc_device registration will fail. Most of the
defined minors in that range are marked unused, but PSMOUSE_MINOR is
still used.
If we continue using the traditional dynamic allocator, the component
registering as dynamic races against the one registering with its static,
so that doesn't sound right.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-12-09 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-08 23:01 [PATCH] misc: Increase available dyanmic minors Keith Busch
2014-12-09 8:46 ` Arnd Bergmann
2014-12-09 16:15 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®