Skip to content

Commit 4ce6081

Browse files
author
Miklos Szeredi
committed
fuse: iqueue locking
Use fiq->waitq.lock for protecting members of struct fuse_iqueue and FR_PENDING request flag, previously protected by fc->lock. Following patches will remove fc->lock protection from these members. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Reviewed-by: Ashish Samant <ashish.samant@oracle.com>
1 parent ef75925 commit 4ce6081

1 file changed

Lines changed: 45 additions & 6 deletions

File tree

‎fs/fuse/dev.c‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void queue_request(struct fuse_iqueue *fiq, struct fuse_req *req)
328328
req->in.h.len = sizeof(struct fuse_in_header) +
329329
len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
330330
list_add_tail(&req->list, &fiq->pending);
331-
wake_up(&fiq->waitq);
331+
wake_up_locked(&fiq->waitq);
332332
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
333333
}
334334

@@ -341,14 +341,16 @@ void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
341341
forget->forget_one.nlookup = nlookup;
342342

343343
spin_lock(&fc->lock);
344+
spin_lock(&fiq->waitq.lock);
344345
if (fiq->connected) {
345346
fiq->forget_list_tail->next = forget;
346347
fiq->forget_list_tail = forget;
347-
wake_up(&fiq->waitq);
348+
wake_up_locked(&fiq->waitq);
348349
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
349350
} else {
350351
kfree(forget);
351352
}
353+
spin_unlock(&fiq->waitq.lock);
352354
spin_unlock(&fc->lock);
353355
}
354356

@@ -362,8 +364,10 @@ static void flush_bg_queue(struct fuse_conn *fc)
362364
req = list_entry(fc->bg_queue.next, struct fuse_req, list);
363365
list_del(&req->list);
364366
fc->active_background++;
367+
spin_lock(&fiq->waitq.lock);
365368
req->in.h.unique = fuse_get_unique(fiq);
366369
queue_request(fiq, req);
370+
spin_unlock(&fiq->waitq.lock);
367371
}
368372
}
369373

@@ -380,10 +384,13 @@ static void flush_bg_queue(struct fuse_conn *fc)
380384
static void request_end(struct fuse_conn *fc, struct fuse_req *req)
381385
__releases(fc->lock)
382386
{
387+
struct fuse_iqueue *fiq = &fc->iq;
383388
void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
384389
req->end = NULL;
385390
list_del_init(&req->list);
391+
spin_lock(&fiq->waitq.lock);
386392
list_del_init(&req->intr_entry);
393+
spin_unlock(&fiq->waitq.lock);
387394
WARN_ON(test_bit(FR_PENDING, &req->flags));
388395
WARN_ON(test_bit(FR_SENT, &req->flags));
389396
smp_wmb();
@@ -415,13 +422,16 @@ __releases(fc->lock)
415422

416423
static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
417424
{
425+
spin_lock(&fiq->waitq.lock);
418426
list_add_tail(&req->intr_entry, &fiq->interrupts);
419-
wake_up(&fiq->waitq);
427+
wake_up_locked(&fiq->waitq);
428+
spin_unlock(&fiq->waitq.lock);
420429
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
421430
}
422431

423432
static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
424433
{
434+
struct fuse_iqueue *fiq = &fc->iq;
425435
int err;
426436

427437
if (!fc->no_interrupt) {
@@ -434,7 +444,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
434444
spin_lock(&fc->lock);
435445
set_bit(FR_INTERRUPTED, &req->flags);
436446
if (test_bit(FR_SENT, &req->flags))
437-
queue_interrupt(&fc->iq, req);
447+
queue_interrupt(fiq, req);
438448
spin_unlock(&fc->lock);
439449
}
440450

@@ -451,14 +461,17 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
451461
return;
452462

453463
spin_lock(&fc->lock);
464+
spin_lock(&fiq->waitq.lock);
454465
/* Request is not yet in userspace, bail out */
455466
if (test_bit(FR_PENDING, &req->flags)) {
456467
list_del(&req->list);
468+
spin_unlock(&fiq->waitq.lock);
457469
spin_unlock(&fc->lock);
458470
__fuse_put_request(req);
459471
req->out.h.error = -EINTR;
460472
return;
461473
}
474+
spin_unlock(&fiq->waitq.lock);
462475
spin_unlock(&fc->lock);
463476
}
464477

@@ -475,15 +488,18 @@ static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
475488

476489
BUG_ON(test_bit(FR_BACKGROUND, &req->flags));
477490
spin_lock(&fc->lock);
491+
spin_lock(&fiq->waitq.lock);
478492
if (!fiq->connected) {
479493
spin_unlock(&fc->lock);
494+
spin_unlock(&fiq->waitq.lock);
480495
req->out.h.error = -ENOTCONN;
481496
} else {
482497
req->in.h.unique = fuse_get_unique(fiq);
483498
queue_request(fiq, req);
484499
/* acquire extra reference, since request is still needed
485500
after request_end() */
486501
__fuse_get_request(req);
502+
spin_unlock(&fiq->waitq.lock);
487503
spin_unlock(&fc->lock);
488504

489505
request_wait_answer(fc, req);
@@ -619,10 +635,12 @@ static int fuse_request_send_notify_reply(struct fuse_conn *fc,
619635
__clear_bit(FR_ISREPLY, &req->flags);
620636
req->in.h.unique = unique;
621637
spin_lock(&fc->lock);
638+
spin_lock(&fiq->waitq.lock);
622639
if (fiq->connected) {
623640
queue_request(fiq, req);
624641
err = 0;
625642
}
643+
spin_unlock(&fiq->waitq.lock);
626644
spin_unlock(&fc->lock);
627645

628646
return err;
@@ -1064,8 +1082,10 @@ static int request_pending(struct fuse_iqueue *fiq)
10641082

10651083
/* Wait until a request is available on the pending list */
10661084
static void request_wait(struct fuse_conn *fc)
1085+
__releases(fc->iq.waitq.lock)
10671086
__releases(fc->lock)
10681087
__acquires(fc->lock)
1088+
__acquires(fc->iq.waitq.lock)
10691089
{
10701090
struct fuse_iqueue *fiq = &fc->iq;
10711091
DECLARE_WAITQUEUE(wait, current);
@@ -1076,9 +1096,11 @@ __acquires(fc->lock)
10761096
if (signal_pending(current))
10771097
break;
10781098

1099+
spin_unlock(&fiq->waitq.lock);
10791100
spin_unlock(&fc->lock);
10801101
schedule();
10811102
spin_lock(&fc->lock);
1103+
spin_lock(&fiq->waitq.lock);
10821104
}
10831105
set_current_state(TASK_RUNNING);
10841106
remove_wait_queue(&fiq->waitq, &wait);
@@ -1094,22 +1116,25 @@ __acquires(fc->lock)
10941116
*/
10951117
static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_copy_state *cs,
10961118
size_t nbytes, struct fuse_req *req)
1119+
__releases(fc->iq.waitq.lock)
10971120
__releases(fc->lock)
10981121
{
1122+
struct fuse_iqueue *fiq = &fc->iq;
10991123
struct fuse_in_header ih;
11001124
struct fuse_interrupt_in arg;
11011125
unsigned reqsize = sizeof(ih) + sizeof(arg);
11021126
int err;
11031127

11041128
list_del_init(&req->intr_entry);
1105-
req->intr_unique = fuse_get_unique(&fc->iq);
1129+
req->intr_unique = fuse_get_unique(fiq);
11061130
memset(&ih, 0, sizeof(ih));
11071131
memset(&arg, 0, sizeof(arg));
11081132
ih.len = reqsize;
11091133
ih.opcode = FUSE_INTERRUPT;
11101134
ih.unique = req->intr_unique;
11111135
arg.unique = req->in.h.unique;
11121136

1137+
spin_unlock(&fiq->waitq.lock);
11131138
spin_unlock(&fc->lock);
11141139
if (nbytes < reqsize)
11151140
return -EINVAL;
@@ -1147,6 +1172,7 @@ static struct fuse_forget_link *dequeue_forget(struct fuse_iqueue *fiq,
11471172
static int fuse_read_single_forget(struct fuse_conn *fc,
11481173
struct fuse_copy_state *cs,
11491174
size_t nbytes)
1175+
__releases(fc->iq.waitq.lock)
11501176
__releases(fc->lock)
11511177
{
11521178
int err;
@@ -1162,6 +1188,7 @@ __releases(fc->lock)
11621188
.len = sizeof(ih) + sizeof(arg),
11631189
};
11641190

1191+
spin_unlock(&fiq->waitq.lock);
11651192
spin_unlock(&fc->lock);
11661193
kfree(forget);
11671194
if (nbytes < ih.len)
@@ -1180,6 +1207,7 @@ __releases(fc->lock)
11801207

11811208
static int fuse_read_batch_forget(struct fuse_conn *fc,
11821209
struct fuse_copy_state *cs, size_t nbytes)
1210+
__releases(fc->iq.waitq.lock)
11831211
__releases(fc->lock)
11841212
{
11851213
int err;
@@ -1195,12 +1223,14 @@ __releases(fc->lock)
11951223
};
11961224

11971225
if (nbytes < ih.len) {
1226+
spin_unlock(&fiq->waitq.lock);
11981227
spin_unlock(&fc->lock);
11991228
return -EINVAL;
12001229
}
12011230

12021231
max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one);
12031232
head = dequeue_forget(fiq, max_forgets, &count);
1233+
spin_unlock(&fiq->waitq.lock);
12041234
spin_unlock(&fc->lock);
12051235

12061236
arg.count = count;
@@ -1230,6 +1260,7 @@ __releases(fc->lock)
12301260

12311261
static int fuse_read_forget(struct fuse_conn *fc, struct fuse_copy_state *cs,
12321262
size_t nbytes)
1263+
__releases(fc->iq.waitq.lock)
12331264
__releases(fc->lock)
12341265
{
12351266
struct fuse_iqueue *fiq = &fc->iq;
@@ -1260,6 +1291,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
12601291

12611292
restart:
12621293
spin_lock(&fc->lock);
1294+
spin_lock(&fiq->waitq.lock);
12631295
err = -EAGAIN;
12641296
if ((file->f_flags & O_NONBLOCK) && fiq->connected &&
12651297
!request_pending(fiq))
@@ -1290,6 +1322,8 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
12901322
req = list_entry(fiq->pending.next, struct fuse_req, list);
12911323
clear_bit(FR_PENDING, &req->flags);
12921324
list_del_init(&req->list);
1325+
spin_unlock(&fiq->waitq.lock);
1326+
12931327
list_add(&req->list, &fc->io);
12941328

12951329
in = &req->in;
@@ -1333,6 +1367,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
13331367
return reqsize;
13341368

13351369
err_unlock:
1370+
spin_unlock(&fiq->waitq.lock);
13361371
spin_unlock(&fc->lock);
13371372
return err;
13381373
}
@@ -2055,10 +2090,12 @@ static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
20552090
poll_wait(file, &fiq->waitq, wait);
20562091

20572092
spin_lock(&fc->lock);
2093+
spin_lock(&fiq->waitq.lock);
20582094
if (!fiq->connected)
20592095
mask = POLLERR;
20602096
else if (request_pending(fiq))
20612097
mask |= POLLIN | POLLRDNORM;
2098+
spin_unlock(&fiq->waitq.lock);
20622099
spin_unlock(&fc->lock);
20632100

20642101
return mask;
@@ -2141,11 +2178,13 @@ void fuse_abort_conn(struct fuse_conn *fc)
21412178
fc->max_background = UINT_MAX;
21422179
flush_bg_queue(fc);
21432180

2181+
spin_lock(&fiq->waitq.lock);
21442182
fiq->connected = 0;
21452183
list_splice_init(&fiq->pending, &to_end2);
21462184
while (forget_pending(fiq))
21472185
kfree(dequeue_forget(fiq, 1, NULL));
2148-
wake_up_all(&fiq->waitq);
2186+
wake_up_all_locked(&fiq->waitq);
2187+
spin_unlock(&fiq->waitq.lock);
21492188
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
21502189

21512190
list_splice_init(&fc->processing, &to_end2);

0 commit comments

Comments
 (0)