Skip to content

Commit 573c24c

Browse files
committed
dlm: always use GFP_NOFS
Replace all GFP_KERNEL and ls_allocation with GFP_NOFS. ls_allocation would be GFP_KERNEL for userland lockspaces and GFP_NOFS for file system lockspaces. It was discovered that any lockspaces on the system can affect all others by triggering memory reclaim in the file system which could in turn call back into the dlm to acquire locks, deadlocking dlm threads that were shared by all lockspaces, like dlm_recv. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent a8a8a66 commit 573c24c

14 files changed

Lines changed: 46 additions & 53 deletions

File tree

‎fs/dlm/config.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ static struct config_group *make_cluster(struct config_group *g,
410410
struct dlm_comms *cms = NULL;
411411
void *gps = NULL;
412412

413-
cl = kzalloc(sizeof(struct dlm_cluster), GFP_KERNEL);
414-
gps = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
415-
sps = kzalloc(sizeof(struct dlm_spaces), GFP_KERNEL);
416-
cms = kzalloc(sizeof(struct dlm_comms), GFP_KERNEL);
413+
cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS);
414+
gps = kcalloc(3, sizeof(struct config_group *), GFP_NOFS);
415+
sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS);
416+
cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS);
417417

418418
if (!cl || !gps || !sps || !cms)
419419
goto fail;
@@ -482,9 +482,9 @@ static struct config_group *make_space(struct config_group *g, const char *name)
482482
struct dlm_nodes *nds = NULL;
483483
void *gps = NULL;
484484

485-
sp = kzalloc(sizeof(struct dlm_space), GFP_KERNEL);
486-
gps = kcalloc(2, sizeof(struct config_group *), GFP_KERNEL);
487-
nds = kzalloc(sizeof(struct dlm_nodes), GFP_KERNEL);
485+
sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS);
486+
gps = kcalloc(2, sizeof(struct config_group *), GFP_NOFS);
487+
nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS);
488488

489489
if (!sp || !gps || !nds)
490490
goto fail;
@@ -536,7 +536,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)
536536
{
537537
struct dlm_comm *cm;
538538

539-
cm = kzalloc(sizeof(struct dlm_comm), GFP_KERNEL);
539+
cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS);
540540
if (!cm)
541541
return ERR_PTR(-ENOMEM);
542542

@@ -569,7 +569,7 @@ static struct config_item *make_node(struct config_group *g, const char *name)
569569
struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
570570
struct dlm_node *nd;
571571

572-
nd = kzalloc(sizeof(struct dlm_node), GFP_KERNEL);
572+
nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS);
573573
if (!nd)
574574
return ERR_PTR(-ENOMEM);
575575

@@ -705,7 +705,7 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
705705
if (cm->addr_count >= DLM_MAX_ADDR_COUNT)
706706
return -ENOSPC;
707707

708-
addr = kzalloc(sizeof(*addr), GFP_KERNEL);
708+
addr = kzalloc(sizeof(*addr), GFP_NOFS);
709709
if (!addr)
710710
return -ENOMEM;
711711

@@ -868,7 +868,7 @@ int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
868868

869869
ids_count = sp->members_count;
870870

871-
ids = kcalloc(ids_count, sizeof(int), GFP_KERNEL);
871+
ids = kcalloc(ids_count, sizeof(int), GFP_NOFS);
872872
if (!ids) {
873873
rv = -ENOMEM;
874874
goto out;
@@ -886,7 +886,7 @@ int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
886886
if (!new_count)
887887
goto out_ids;
888888

889-
new = kcalloc(new_count, sizeof(int), GFP_KERNEL);
889+
new = kcalloc(new_count, sizeof(int), GFP_NOFS);
890890
if (!new) {
891891
kfree(ids);
892892
rv = -ENOMEM;

‎fs/dlm/debug_fs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos)
404404
if (bucket >= ls->ls_rsbtbl_size)
405405
return NULL;
406406

407-
ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_KERNEL);
407+
ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS);
408408
if (!ri)
409409
return NULL;
410410
if (n == 0)

‎fs/dlm/dir.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ static struct dlm_direntry *get_free_de(struct dlm_ls *ls, int len)
4949
spin_unlock(&ls->ls_recover_list_lock);
5050

5151
if (!found)
52-
de = kzalloc(sizeof(struct dlm_direntry) + len,
53-
ls->ls_allocation);
52+
de = kzalloc(sizeof(struct dlm_direntry) + len, GFP_NOFS);
5453
return de;
5554
}
5655

@@ -212,7 +211,7 @@ int dlm_recover_directory(struct dlm_ls *ls)
212211

213212
dlm_dir_clear(ls);
214213

215-
last_name = kmalloc(DLM_RESNAME_MAXLEN, ls->ls_allocation);
214+
last_name = kmalloc(DLM_RESNAME_MAXLEN, GFP_NOFS);
216215
if (!last_name)
217216
goto out;
218217

@@ -323,7 +322,7 @@ static int get_entry(struct dlm_ls *ls, int nodeid, char *name,
323322
if (namelen > DLM_RESNAME_MAXLEN)
324323
return -EINVAL;
325324

326-
de = kzalloc(sizeof(struct dlm_direntry) + namelen, ls->ls_allocation);
325+
de = kzalloc(sizeof(struct dlm_direntry) + namelen, GFP_NOFS);
327326
if (!de)
328327
return -ENOMEM;
329328

‎fs/dlm/dlm_internal.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ struct dlm_ls {
473473
int ls_low_nodeid;
474474
int ls_total_weight;
475475
int *ls_node_array;
476-
gfp_t ls_allocation;
477476

478477
struct dlm_rsb ls_stub_rsb; /* for returning errors */
479478
struct dlm_lkb ls_stub_lkb; /* for returning errors */

‎fs/dlm/lock.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ static int _create_message(struct dlm_ls *ls, int mb_len,
26892689
pass into lowcomms_commit and a message buffer (mb) that we
26902690
write our data into */
26912691

2692-
mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, ls->ls_allocation, &mb);
2692+
mh = dlm_lowcomms_get_buffer(to_nodeid, mb_len, GFP_NOFS, &mb);
26932693
if (!mh)
26942694
return -ENOBUFS;
26952695

@@ -4512,7 +4512,7 @@ int dlm_user_request(struct dlm_ls *ls, struct dlm_user_args *ua,
45124512
}
45134513

45144514
if (flags & DLM_LKF_VALBLK) {
4515-
ua->lksb.sb_lvbptr = kzalloc(DLM_USER_LVB_LEN, GFP_KERNEL);
4515+
ua->lksb.sb_lvbptr = kzalloc(DLM_USER_LVB_LEN, GFP_NOFS);
45164516
if (!ua->lksb.sb_lvbptr) {
45174517
kfree(ua);
45184518
__put_lkb(ls, lkb);
@@ -4582,7 +4582,7 @@ int dlm_user_convert(struct dlm_ls *ls, struct dlm_user_args *ua_tmp,
45824582
ua = lkb->lkb_ua;
45834583

45844584
if (flags & DLM_LKF_VALBLK && !ua->lksb.sb_lvbptr) {
4585-
ua->lksb.sb_lvbptr = kzalloc(DLM_USER_LVB_LEN, GFP_KERNEL);
4585+
ua->lksb.sb_lvbptr = kzalloc(DLM_USER_LVB_LEN, GFP_NOFS);
45864586
if (!ua->lksb.sb_lvbptr) {
45874587
error = -ENOMEM;
45884588
goto out_put;

‎fs/dlm/lockspace.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
430430

431431
error = -ENOMEM;
432432

433-
ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_KERNEL);
433+
ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_NOFS);
434434
if (!ls)
435435
goto out;
436436
memcpy(ls->ls_name, name, namelen);
@@ -443,11 +443,6 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
443443
if (flags & DLM_LSFL_TIMEWARN)
444444
set_bit(LSFL_TIMEWARN, &ls->ls_flags);
445445

446-
if (flags & DLM_LSFL_FS)
447-
ls->ls_allocation = GFP_NOFS;
448-
else
449-
ls->ls_allocation = GFP_KERNEL;
450-
451446
/* ls_exflags are forced to match among nodes, and we don't
452447
need to require all nodes to have some flags set */
453448
ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS |
@@ -456,7 +451,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
456451
size = dlm_config.ci_rsbtbl_size;
457452
ls->ls_rsbtbl_size = size;
458453

459-
ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_KERNEL);
454+
ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_NOFS);
460455
if (!ls->ls_rsbtbl)
461456
goto out_lsfree;
462457
for (i = 0; i < size; i++) {
@@ -468,7 +463,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
468463
size = dlm_config.ci_lkbtbl_size;
469464
ls->ls_lkbtbl_size = size;
470465

471-
ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_KERNEL);
466+
ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_NOFS);
472467
if (!ls->ls_lkbtbl)
473468
goto out_rsbfree;
474469
for (i = 0; i < size; i++) {
@@ -480,7 +475,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
480475
size = dlm_config.ci_dirtbl_size;
481476
ls->ls_dirtbl_size = size;
482477

483-
ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_KERNEL);
478+
ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_NOFS);
484479
if (!ls->ls_dirtbl)
485480
goto out_lkbfree;
486481
for (i = 0; i < size; i++) {
@@ -527,7 +522,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
527522
mutex_init(&ls->ls_requestqueue_mutex);
528523
mutex_init(&ls->ls_clear_proc_locks);
529524

530-
ls->ls_recover_buf = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
525+
ls->ls_recover_buf = kmalloc(dlm_config.ci_buffer_size, GFP_NOFS);
531526
if (!ls->ls_recover_buf)
532527
goto out_dirfree;
533528

‎fs/dlm/lowcomms.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ static void init_local(void)
10601060
if (dlm_our_addr(&sas, i))
10611061
break;
10621062

1063-
addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1063+
addr = kmalloc(sizeof(*addr), GFP_NOFS);
10641064
if (!addr)
10651065
break;
10661066
memcpy(addr, &sas, sizeof(*addr));
@@ -1099,7 +1099,7 @@ static int sctp_listen_for_all(void)
10991099
struct sockaddr_storage localaddr;
11001100
struct sctp_event_subscribe subscribe;
11011101
int result = -EINVAL, num = 1, i, addr_len;
1102-
struct connection *con = nodeid2con(0, GFP_KERNEL);
1102+
struct connection *con = nodeid2con(0, GFP_NOFS);
11031103
int bufsize = NEEDED_RMEM;
11041104

11051105
if (!con)
@@ -1171,7 +1171,7 @@ static int sctp_listen_for_all(void)
11711171
static int tcp_listen_for_all(void)
11721172
{
11731173
struct socket *sock = NULL;
1174-
struct connection *con = nodeid2con(0, GFP_KERNEL);
1174+
struct connection *con = nodeid2con(0, GFP_NOFS);
11751175
int result = -EINVAL;
11761176

11771177
if (!con)

‎fs/dlm/member.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int dlm_add_member(struct dlm_ls *ls, int nodeid)
4848
struct dlm_member *memb;
4949
int w, error;
5050

51-
memb = kzalloc(sizeof(struct dlm_member), ls->ls_allocation);
51+
memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS);
5252
if (!memb)
5353
return -ENOMEM;
5454

@@ -143,7 +143,7 @@ static void make_member_array(struct dlm_ls *ls)
143143

144144
ls->ls_total_weight = total;
145145

146-
array = kmalloc(sizeof(int) * total, ls->ls_allocation);
146+
array = kmalloc(sizeof(int) * total, GFP_NOFS);
147147
if (!array)
148148
return;
149149

@@ -226,7 +226,7 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
226226
continue;
227227
log_debug(ls, "new nodeid %d is a re-added member", rv->new[i]);
228228

229-
memb = kzalloc(sizeof(struct dlm_member), ls->ls_allocation);
229+
memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS);
230230
if (!memb)
231231
return -ENOMEM;
232232
memb->nodeid = rv->new[i];
@@ -341,7 +341,7 @@ int dlm_ls_start(struct dlm_ls *ls)
341341
int *ids = NULL, *new = NULL;
342342
int error, ids_count = 0, new_count = 0;
343343

344-
rv = kzalloc(sizeof(struct dlm_recover), ls->ls_allocation);
344+
rv = kzalloc(sizeof(struct dlm_recover), GFP_NOFS);
345345
if (!rv)
346346
return -ENOMEM;
347347

‎fs/dlm/memory.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ char *dlm_allocate_lvb(struct dlm_ls *ls)
3939
{
4040
char *p;
4141

42-
p = kzalloc(ls->ls_lvblen, ls->ls_allocation);
42+
p = kzalloc(ls->ls_lvblen, GFP_NOFS);
4343
return p;
4444
}
4545

@@ -57,7 +57,7 @@ struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls, int namelen)
5757

5858
DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,);
5959

60-
r = kzalloc(sizeof(*r) + namelen, ls->ls_allocation);
60+
r = kzalloc(sizeof(*r) + namelen, GFP_NOFS);
6161
return r;
6262
}
6363

@@ -72,7 +72,7 @@ struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
7272
{
7373
struct dlm_lkb *lkb;
7474

75-
lkb = kmem_cache_zalloc(lkb_cache, ls->ls_allocation);
75+
lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
7676
return lkb;
7777
}
7878

‎fs/dlm/netlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static int prepare_data(u8 cmd, struct sk_buff **skbp, size_t size)
2626
struct sk_buff *skb;
2727
void *data;
2828

29-
skb = genlmsg_new(size, GFP_KERNEL);
29+
skb = genlmsg_new(size, GFP_NOFS);
3030
if (!skb)
3131
return -ENOMEM;
3232

0 commit comments

Comments
 (0)