Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netdevsim: disable devlink reload when resources are being used
devlink reload destroys resources and allocates resources again. So, when devices and ports resources are being used, devlink reload function should not be executed. In order to avoid this race, a new lock is added and new_port() and del_port() call devlink_reload_disable() and devlink_reload_enable(). Thread0 Thread1 {new/del}_port() {new/del}_port() devlink_reload_disable() devlink_reload_disable() devlink_reload_enable() //here devlink_reload_enable() Before Thread1's devlink_reload_enable(), the devlink is already allowed to execute reload because Thread0 allows it. devlink reload disable/enable variable type is bool. So the above case would exist. So, disable/enable should be executed atomically. In order to do that, a new lock is used. Test commands: modprobe netdevsim echo 1 > /sys/bus/netdevsim/new_device while : do echo 1 > /sys/devices/netdevsim1/new_port & echo 1 > /sys/devices/netdevsim1/del_port & devlink dev reload netdevsim/netdevsim1 & done Splat looks like: [ 1067.313531][ T1480] kernel BUG at lib/list_debug.c:53! [ 1067.314519][ T1480] invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN PTI [ 1067.315948][ T1480] CPU: 3 PID: 1480 Comm: bash Tainted: G W 5.5.0-rc6+ torvalds#318 [ 1067.326082][ T1480] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 1067.356308][ T1480] RIP: 0010:__list_del_entry_valid+0xe6/0x150 [ 1067.357006][ T1480] Code: 89 ea 48 c7 c7 a0 64 1e 9f e8 7f 5b 4d ff 0f 0b 48 c7 c7 00 65 1e 9f e8 71 5b 4d ff 4 [ 1067.395359][ T1480] RSP: 0018:ffff8880a316fb58 EFLAGS: 00010282 [ 1067.396016][ T1480] RAX: 0000000000000054 RBX: ffff8880c0e76718 RCX: 0000000000000000 [ 1067.402370][ T1480] RDX: 0000000000000054 RSI: 0000000000000008 RDI: ffffed101462df61 [ 1067.430844][ T1480] RBP: ffff8880a31bfca0 R08: ffffed101b5404f9 R09: ffffed101b5404f9 [ 1067.432165][ T1480] R10: 0000000000000001 R11: ffffed101b5404f8 R12: ffff8880a316fcb0 [ 1067.433526][ T1480] R13: ffff8880a310d440 R14: ffffffffa117a7c0 R15: ffff8880c0e766c0 [ 1067.435818][ T1480] FS: 00007f001c026740(0000) GS:ffff8880da800000(0000) knlGS:0000000000000000 [ 1067.441677][ T1480] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1067.451305][ T1480] CR2: 00007f001afb7180 CR3: 00000000a3170003 CR4: 00000000000606e0 [ 1067.453416][ T1480] Call Trace: [ 1067.453832][ T1480] mutex_remove_waiter+0x101/0x520 [ 1067.455949][ T1480] __mutex_lock+0xac7/0x14b0 [ 1067.456880][ T1480] ? nsim_dev_port_add+0x50/0x150 [netdevsim] [ 1067.458946][ T1480] ? mutex_lock_io_nested+0x1380/0x1380 [ 1067.460614][ T1480] ? _parse_integer+0xf0/0xf0 [ 1067.472498][ T1480] ? kstrtouint+0x86/0x110 [ 1067.473327][ T1480] ? nsim_dev_port_add+0x50/0x150 [netdevsim] [ 1067.474187][ T1480] nsim_dev_port_add+0x50/0x150 [netdevsim] [ 1067.474980][ T1480] new_port_store+0xc4/0xf0 [netdevsim] [ 1067.475717][ T1480] ? del_port_store+0xf0/0xf0 [netdevsim] [ 1067.476478][ T1480] ? sysfs_kf_write+0x3b/0x180 [ 1067.477106][ T1480] ? sysfs_file_ops+0x160/0x160 [ 1067.477744][ T1480] kernfs_fop_write+0x276/0x410 [ ... ] Fixes: 4418f86 ("netdevsim: implement support for devlink region and snapshots") Fixes: 75ba029 ("netdevsim: implement proper devlink reload") Signed-off-by: Taehee Yoo <[email protected]>
- Loading branch information