aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Brauner <christian@brauner.io>2019-01-11 05:19:40 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-01-11 07:42:15 -0500
commit36bdf3cae09df891b191f3955c8e54a2e05d67d0 (patch)
tree0bbdd8f9aad41f102f8a1d6941c97c2bbe2215d4
parentc13295ad219d8bb0e47942d4cfc8251de449a67e (diff)
binderfs: reserve devices for initial mount
The binderfs instance in the initial ipc namespace will always have a reserve of 4 binder devices unless explicitly capped by specifying a lower value via the "max" mount option. This ensures when binder devices are removed (on accident or on purpose) they can always be recreated without risking that all minor numbers have already been used up. Cc: Todd Kjos <tkjos@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/android/binderfs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
index f6341893b5ba..ad3ad2f7f9f4 100644
--- a/drivers/android/binderfs.c
+++ b/drivers/android/binderfs.c
@@ -40,6 +40,8 @@
40#define INODE_OFFSET 3 40#define INODE_OFFSET 3
41#define INTSTRLEN 21 41#define INTSTRLEN 21
42#define BINDERFS_MAX_MINOR (1U << MINORBITS) 42#define BINDERFS_MAX_MINOR (1U << MINORBITS)
43/* Ensure that the initial ipc namespace always has devices available. */
44#define BINDERFS_MAX_MINOR_CAPPED (BINDERFS_MAX_MINOR - 4)
43 45
44static dev_t binderfs_dev; 46static dev_t binderfs_dev;
45static DEFINE_MUTEX(binderfs_minors_mutex); 47static DEFINE_MUTEX(binderfs_minors_mutex);
@@ -127,11 +129,14 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
127 struct inode *inode = NULL; 129 struct inode *inode = NULL;
128 struct super_block *sb = ref_inode->i_sb; 130 struct super_block *sb = ref_inode->i_sb;
129 struct binderfs_info *info = sb->s_fs_info; 131 struct binderfs_info *info = sb->s_fs_info;
132 bool use_reserve = (info->ipc_ns == &init_ipc_ns);
130 133
131 /* Reserve new minor number for the new device. */ 134 /* Reserve new minor number for the new device. */
132 mutex_lock(&binderfs_minors_mutex); 135 mutex_lock(&binderfs_minors_mutex);
133 if (++info->device_count <= info->mount_opts.max) 136 if (++info->device_count <= info->mount_opts.max)
134 minor = ida_alloc_max(&binderfs_minors, BINDERFS_MAX_MINOR, 137 minor = ida_alloc_max(&binderfs_minors,
138 use_reserve ? BINDERFS_MAX_MINOR :
139 BINDERFS_MAX_MINOR_CAPPED,
135 GFP_KERNEL); 140 GFP_KERNEL);
136 else 141 else
137 minor = -ENOSPC; 142 minor = -ENOSPC;