aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/drivers
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-06-16 16:48:52 -0400
committerRusty Russell <rusty@rustcorp.com.au>2015-06-23 01:57:38 -0400
commitb51d23e4e9fea6f264d39535c2a62d1f51e7ccc3 (patch)
tree032ebaa1088f1c20985b0872ab31a9d403a35884 /arch/um/drivers
parent5104b7d7678b0029417f6ac08243773a77259ac6 (diff)
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use the correct built-in or module mutex while locking kernel params. Remove the kparam_block_sysfs_r/w() macros, replace them with direct calls to kernel_param_[un]lock(module). The kernel param code currently uses a single mutex to protect modification of any and all kernel params. While this generally works, there is one specific problem with it; a module callback function cannot safely load another module, i.e. with request_module() or even with indirect calls such as crypto_has_alg(). If the module to be loaded has any of its params configured (e.g. with a /etc/modprobe.d/* config file), then the attempt will result in a deadlock between the first module param callback waiting for modprobe, and modprobe trying to lock the single kernel param mutex to set the new module's param. This fixes that by using per-module mutexes, so that each individual module is protected against concurrent changes in its own kernel params, but is not blocked by changes to other module params. All built-in modules continue to use the built-in mutex, since they will always be loaded at runtime and references (e.g. request_module(), crypto_has_alg()) to them will never cause load-time param changing. This also simplifies the interface used by modules to block sysfs access to their params; while there are currently functions to block and unblock sysfs param access which are split up by read and write and expect a single kernel param to be passed, their actual operation is identical and applies to all params, not just the one passed to them; they simply lock and unlock the global param mutex. They are replaced with direct calls to kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or if the module is built-in, it locks the built-in mutex. Suggested-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'arch/um/drivers')
-rw-r--r--arch/um/drivers/hostaudio_kern.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/arch/um/drivers/hostaudio_kern.c b/arch/um/drivers/hostaudio_kern.c
index 9b90fdc4b151..f6b911cc3923 100644
--- a/arch/um/drivers/hostaudio_kern.c
+++ b/arch/um/drivers/hostaudio_kern.c
@@ -185,9 +185,9 @@ static int hostaudio_open(struct inode *inode, struct file *file)
185 int ret; 185 int ret;
186 186
187#ifdef DEBUG 187#ifdef DEBUG
188 kparam_block_sysfs_write(dsp); 188 kernel_param_lock(THIS_MODULE);
189 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); 189 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
190 kparam_unblock_sysfs_write(dsp); 190 kernel_param_unlock(THIS_MODULE);
191#endif 191#endif
192 192
193 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); 193 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
@@ -199,11 +199,11 @@ static int hostaudio_open(struct inode *inode, struct file *file)
199 if (file->f_mode & FMODE_WRITE) 199 if (file->f_mode & FMODE_WRITE)
200 w = 1; 200 w = 1;
201 201
202 kparam_block_sysfs_write(dsp); 202 kernel_param_lock(THIS_MODULE);
203 mutex_lock(&hostaudio_mutex); 203 mutex_lock(&hostaudio_mutex);
204 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); 204 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
205 mutex_unlock(&hostaudio_mutex); 205 mutex_unlock(&hostaudio_mutex);
206 kparam_unblock_sysfs_write(dsp); 206 kernel_param_unlock(THIS_MODULE);
207 207
208 if (ret < 0) { 208 if (ret < 0) {
209 kfree(state); 209 kfree(state);
@@ -260,17 +260,17 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
260 if (file->f_mode & FMODE_WRITE) 260 if (file->f_mode & FMODE_WRITE)
261 w = 1; 261 w = 1;
262 262
263 kparam_block_sysfs_write(mixer); 263 kernel_param_lock(THIS_MODULE);
264 mutex_lock(&hostaudio_mutex); 264 mutex_lock(&hostaudio_mutex);
265 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); 265 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
266 mutex_unlock(&hostaudio_mutex); 266 mutex_unlock(&hostaudio_mutex);
267 kparam_unblock_sysfs_write(mixer); 267 kernel_param_unlock(THIS_MODULE);
268 268
269 if (ret < 0) { 269 if (ret < 0) {
270 kparam_block_sysfs_write(dsp); 270 kernel_param_lock(THIS_MODULE);
271 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " 271 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
272 "err = %d\n", dsp, -ret); 272 "err = %d\n", dsp, -ret);
273 kparam_unblock_sysfs_write(dsp); 273 kernel_param_unlock(THIS_MODULE);
274 kfree(state); 274 kfree(state);
275 return ret; 275 return ret;
276 } 276 }
@@ -326,10 +326,10 @@ MODULE_LICENSE("GPL");
326 326
327static int __init hostaudio_init_module(void) 327static int __init hostaudio_init_module(void)
328{ 328{
329 __kernel_param_lock(); 329 kernel_param_lock(THIS_MODULE);
330 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n", 330 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
331 dsp, mixer); 331 dsp, mixer);
332 __kernel_param_unlock(); 332 kernel_param_unlock(THIS_MODULE);
333 333
334 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); 334 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
335 if (module_data.dev_audio < 0) { 335 if (module_data.dev_audio < 0) {