Skip to content

Commit 6958c1c

Browse files
Mikulas Patockasnitm
authored andcommitted
dm: use noio when sending kobject event
kobject_uevent may allocate memory and it may be called while there are dm devices suspended. The allocation may recurse into a suspended device, causing a deadlock. We must set the noio flag when sending a uevent. The observed deadlock was reported here: https://www.redhat.com/archives/dm-devel/2020-March/msg00025.html Reported-by: Khazhismel Kumykov <[email protected]> Reported-by: Tahsin Erdogan <[email protected]> Reported-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]> Cc: [email protected] Signed-off-by: Mike Snitzer <[email protected]>
1 parent 174364f commit 6958c1c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/md/dm.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/module.h>
1414
#include <linux/mutex.h>
15+
#include <linux/sched/mm.h>
1516
#include <linux/sched/signal.h>
1617
#include <linux/blkpg.h>
1718
#include <linux/bio.h>
@@ -2939,17 +2940,25 @@ EXPORT_SYMBOL_GPL(dm_internal_resume_fast);
29392940
int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
29402941
unsigned cookie)
29412942
{
2943+
int r;
2944+
unsigned noio_flag;
29422945
char udev_cookie[DM_COOKIE_LENGTH];
29432946
char *envp[] = { udev_cookie, NULL };
29442947

2948+
noio_flag = memalloc_noio_save();
2949+
29452950
if (!cookie)
2946-
return kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
2951+
r = kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
29472952
else {
29482953
snprintf(udev_cookie, DM_COOKIE_LENGTH, "%s=%u",
29492954
DM_COOKIE_ENV_VAR_NAME, cookie);
2950-
return kobject_uevent_env(&disk_to_dev(md->disk)->kobj,
2951-
action, envp);
2955+
r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj,
2956+
action, envp);
29522957
}
2958+
2959+
memalloc_noio_restore(noio_flag);
2960+
2961+
return r;
29532962
}
29542963

29552964
uint32_t dm_next_uevent_seq(struct mapped_device *md)

0 commit comments

Comments
 (0)