Skip to content

Commit 8f7bb36

Browse files
author
Miklos Szeredi
committed
fuse: allow interrupt queuing without fc->lock
Interrupt is only queued after the request has been sent to userspace. This is either done in request_wait_answer() or fuse_dev_do_read() depending on which state the request is in at the time of the interrupt. If it's not yet sent, then queuing the interrupt is postponed until the request is read. Otherwise (the request has already been read and is waiting for an answer) the interrupt is queued immedidately. We want to call queue_interrupt() without fc->lock protection, in which case there can be a race between the two functions: - neither of them queue the interrupt (thinking the other one has already done it). - both of them queue the interrupt The first one is prevented by adding memory barriers, the second is prevented by checking (under fiq->waitq.lock) if the interrupt has already been queued. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
1 parent 4ce6081 commit 8f7bb36

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎fs/fuse/dev.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ __releases(fc->lock)
423423
static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
424424
{
425425
spin_lock(&fiq->waitq.lock);
426-
list_add_tail(&req->intr_entry, &fiq->interrupts);
427-
wake_up_locked(&fiq->waitq);
426+
if (list_empty(&req->intr_entry)) {
427+
list_add_tail(&req->intr_entry, &fiq->interrupts);
428+
wake_up_locked(&fiq->waitq);
429+
}
428430
spin_unlock(&fiq->waitq.lock);
429431
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
430432
}
@@ -443,6 +445,8 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
443445

444446
spin_lock(&fc->lock);
445447
set_bit(FR_INTERRUPTED, &req->flags);
448+
/* matches barrier in fuse_dev_do_read() */
449+
smp_mb__after_atomic();
446450
if (test_bit(FR_SENT, &req->flags))
447451
queue_interrupt(fiq, req);
448452
spin_unlock(&fc->lock);
@@ -1358,8 +1362,10 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
13581362
if (!test_bit(FR_ISREPLY, &req->flags)) {
13591363
request_end(fc, req);
13601364
} else {
1361-
set_bit(FR_SENT, &req->flags);
13621365
list_move_tail(&req->list, &fc->processing);
1366+
set_bit(FR_SENT, &req->flags);
1367+
/* matches barrier in request_wait_answer() */
1368+
smp_mb__after_atomic();
13631369
if (test_bit(FR_INTERRUPTED, &req->flags))
13641370
queue_interrupt(fiq, req);
13651371
spin_unlock(&fc->lock);

0 commit comments

Comments
 (0)