From patchwork Tue Jan 15 10:19:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41B0013B5 for ; Tue, 15 Jan 2019 10:19:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 302602B2ED for ; Tue, 15 Jan 2019 10:19:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 243A22B2FF; Tue, 15 Jan 2019 10:19:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3FA12B2ED for ; Tue, 15 Jan 2019 10:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbfAOKTW (ORCPT ); Tue, 15 Jan 2019 05:19:22 -0500 Received: from relay.sw.ru ([185.231.240.75]:36284 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfAOKTW (ORCPT ); Tue, 15 Jan 2019 05:19:22 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLoW-00012W-2Z; Tue, 15 Jan 2019 13:19:20 +0300 Subject: [PATCH 1/7] fuse: Check for fc->connected in fuse_dev_alloc() From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:19 +0300 Message-ID: <154754755979.4244.14965151684224631403.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP fuse_dev_alloc() may be called after fc->connected is dropped (from ioctl), so here we add sanity check for that case. Signed-off-by: Kirill Tkhai --- fs/fuse/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 336844d0eb3a..0361a3d62356 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -1054,10 +1054,19 @@ struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc) fuse_pqueue_init(&fud->pq); spin_lock(&fc->lock); + if (!fc->connected) { + spin_unlock(&fc->lock); + goto out_put; + } list_add_tail(&fud->entry, &fc->devices); spin_unlock(&fc->lock); return fud; +out_put: + fuse_conn_put(fc); + kfree(pq); + kfree(fud); + return NULL; } EXPORT_SYMBOL_GPL(fuse_dev_alloc); From patchwork Tue Jan 15 10:19:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C70D1390 for ; Tue, 15 Jan 2019 10:19:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19AE82B2EF for ; Tue, 15 Jan 2019 10:19:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C7102B2ED; Tue, 15 Jan 2019 10:19:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ED8C2B2ED for ; Tue, 15 Jan 2019 10:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727703AbfAOKT2 (ORCPT ); Tue, 15 Jan 2019 05:19:28 -0500 Received: from relay.sw.ru ([185.231.240.75]:36290 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfAOKT1 (ORCPT ); Tue, 15 Jan 2019 05:19:27 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLob-00012c-My; Tue, 15 Jan 2019 13:19:25 +0300 Subject: [PATCH 2/7] fuse: Move flush_bg_queue() up in fuse_abort_conn() From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:25 +0300 Message-ID: <154754756520.4244.2632848231069869374.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Preparation for next patches. Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 8a63e52785e9..dd8f019447a9 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2191,6 +2191,9 @@ void fuse_abort_conn(struct fuse_conn *fc) /* Background queuing checks fc->connected under bg_lock */ spin_lock(&fc->bg_lock); fc->connected = 0; + fc->blocked = 0; + fc->max_background = UINT_MAX; + flush_bg_queue(fc); spin_unlock(&fc->bg_lock); fuse_set_initialized(fc); @@ -2215,11 +2218,6 @@ void fuse_abort_conn(struct fuse_conn *fc) &to_end); spin_unlock(&fpq->lock); } - spin_lock(&fc->bg_lock); - fc->blocked = 0; - fc->max_background = UINT_MAX; - flush_bg_queue(fc); - spin_unlock(&fc->bg_lock); spin_lock(&fiq->waitq.lock); fiq->connected = 0; From patchwork Tue Jan 15 10:19:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2DF513B5 for ; Tue, 15 Jan 2019 10:19:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1D4F2B2ED for ; Tue, 15 Jan 2019 10:19:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D57532B2FF; Tue, 15 Jan 2019 10:19:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A3EF2B2ED for ; Tue, 15 Jan 2019 10:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbfAOKTg (ORCPT ); Tue, 15 Jan 2019 05:19:36 -0500 Received: from relay.sw.ru ([185.231.240.75]:36298 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfAOKTg (ORCPT ); Tue, 15 Jan 2019 05:19:36 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLoh-00012i-23; Tue, 15 Jan 2019 13:19:31 +0300 Subject: [PATCH 3/7] fuse: Drop and reacquire fc->lock in middle of fuse_abort_conn() From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:30 +0300 Message-ID: <154754757079.4244.14375895153780525981.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Preparation for next patches. Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 7 +++++++ fs/fuse/fuse_i.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index dd8f019447a9..b393fbedcc1f 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2231,11 +2231,18 @@ void fuse_abort_conn(struct fuse_conn *fc) kill_fasync(&fiq->fasync, SIGIO, POLL_IN); end_polls(fc); wake_up_all(&fc->blocked_waitq); + fc->aborting = true; spin_unlock(&fc->lock); end_requests(fc, &to_end); + + spin_lock(&fc->lock); + fc->aborting = false; + spin_unlock(&fc->lock); + wake_up_all(&fc->blocked_waitq); } else { spin_unlock(&fc->lock); + wait_event(fc->blocked_waitq, !fc->aborting); } } EXPORT_SYMBOL_GPL(fuse_abort_conn); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 033e30af519f..b5f2265c437c 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -587,6 +587,9 @@ struct fuse_conn { abort and device release */ unsigned connected; + /** Connection abort is in process */ + bool aborting; + /** Connection aborted via sysfs */ bool aborted; From patchwork Tue Jan 15 10:19:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 728BC13B5 for ; Tue, 15 Jan 2019 10:19:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 610EA2B2ED for ; Tue, 15 Jan 2019 10:19:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5572F2B2FF; Tue, 15 Jan 2019 10:19:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E43A22B2ED for ; Tue, 15 Jan 2019 10:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728404AbfAOKTj (ORCPT ); Tue, 15 Jan 2019 05:19:39 -0500 Received: from relay.sw.ru ([185.231.240.75]:36304 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfAOKTj (ORCPT ); Tue, 15 Jan 2019 05:19:39 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLom-00012o-OA; Tue, 15 Jan 2019 13:19:36 +0300 Subject: [PATCH 4/7] fuse: Add fud pointer to struct fuse_copy_state From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:36 +0300 Message-ID: <154754757625.4244.1439886690789751308.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ... and propagate fud into fuse_copy_init(). This is preparation for next patches. Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index b393fbedcc1f..afadf462ec18 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -769,6 +769,7 @@ static int unlock_request(struct fuse_req *req) } struct fuse_copy_state { + struct fuse_dev *fud; int write; struct fuse_req *req; struct iov_iter *iter; @@ -782,10 +783,12 @@ struct fuse_copy_state { unsigned move_pages:1; }; -static void fuse_copy_init(struct fuse_copy_state *cs, int write, +static void fuse_copy_init(struct fuse_copy_state *cs, + struct fuse_dev *fud, int write, struct iov_iter *iter) { memset(cs, 0, sizeof(*cs)); + cs->fud = fud; cs->write = write; cs->iter = iter; } @@ -1436,7 +1439,7 @@ static ssize_t fuse_dev_read(struct kiocb *iocb, struct iov_iter *to) if (!iter_is_iovec(to)) return -EINVAL; - fuse_copy_init(&cs, 1, to); + fuse_copy_init(&cs, fud, 1, to); return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); } @@ -1459,7 +1462,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, if (!bufs) return -ENOMEM; - fuse_copy_init(&cs, 1, NULL); + fuse_copy_init(&cs, fud, 1, NULL); cs.pipebufs = bufs; cs.pipe = pipe; ret = fuse_dev_do_read(fud, in, &cs, len); @@ -2020,7 +2023,7 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from) if (!iter_is_iovec(from)) return -EINVAL; - fuse_copy_init(&cs, 0, from); + fuse_copy_init(&cs, fud, 0, from); return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); } @@ -2089,7 +2092,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, } pipe_unlock(pipe); - fuse_copy_init(&cs, 0, NULL); + fuse_copy_init(&cs, fud, 0, NULL); cs.pipebufs = bufs; cs.nr_segs = nbuf; cs.pipe = pipe; From patchwork Tue Jan 15 10:19:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40EA613B5 for ; Tue, 15 Jan 2019 10:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DEDE2B2ED for ; Tue, 15 Jan 2019 10:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 223F62B2FF; Tue, 15 Jan 2019 10:19:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 964842B2ED for ; Tue, 15 Jan 2019 10:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728421AbfAOKTo (ORCPT ); Tue, 15 Jan 2019 05:19:44 -0500 Received: from relay.sw.ru ([185.231.240.75]:36308 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728202AbfAOKTn (ORCPT ); Tue, 15 Jan 2019 05:19:43 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLos-00012u-6J; Tue, 15 Jan 2019 13:19:42 +0300 Subject: [PATCH 5/7] fuse: Introduce generic fuse_copy_aborted() From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:41 +0300 Message-ID: <154754758189.4244.13193829723902632197.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no a reason to set individual FR_ABORTED state for every request, since fuse_abort_conn() aborts all unlocked requests at once. FR_ABORTED bit just makes fuse_copy_aborted() to end some of requests, which are in the middle of fuse_dev_do_read() and fuse_dev_do_write(), but this is not a big deal. These functions may abort the requests themselves. The patch kills lock_request and unlock_request(), and introduces generic fuse_copy_aborted() to use instead of them. This allows next patches to kill FR_ABORTED, FR_LOCKED and FR_PRIVATE, and simplify fuse dev read/write function. Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 82 +++++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 64 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index afadf462ec18..4905abfb279e 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -731,43 +731,6 @@ void fuse_force_forget(struct file *file, u64 nodeid) fuse_put_request(fc, req); } -/* - * Lock the request. Up to the next unlock_request() there mustn't be - * anything that could cause a page-fault. If the request was already - * aborted bail out. - */ -static int lock_request(struct fuse_req *req) -{ - int err = 0; - if (req) { - spin_lock(&req->waitq.lock); - if (test_bit(FR_ABORTED, &req->flags)) - err = -ENOENT; - else - set_bit(FR_LOCKED, &req->flags); - spin_unlock(&req->waitq.lock); - } - return err; -} - -/* - * Unlock request. If it was aborted while locked, caller is responsible - * for unlocking and ending the request. - */ -static int unlock_request(struct fuse_req *req) -{ - int err = 0; - if (req) { - spin_lock(&req->waitq.lock); - if (test_bit(FR_ABORTED, &req->flags)) - err = -ENOENT; - else - clear_bit(FR_LOCKED, &req->flags); - spin_unlock(&req->waitq.lock); - } - return err; -} - struct fuse_copy_state { struct fuse_dev *fud; int write; @@ -812,6 +775,16 @@ static void fuse_copy_finish(struct fuse_copy_state *cs) cs->pg = NULL; } +static int fuse_copy_aborted(struct fuse_copy_state *cs) +{ + struct fuse_pqueue *pq = &cs->fud->pq; + + if (READ_ONCE(pq->connected)) + return 0; + else + return -ENOENT; +} + /* * Get another pagefull of userspace buffer, and map it to kernel * address space, and lock request @@ -821,7 +794,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) struct page *page; int err; - err = unlock_request(cs->req); + err = fuse_copy_aborted(cs); if (err) return err; @@ -872,7 +845,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) iov_iter_advance(cs->iter, err); } - return lock_request(cs->req); + return fuse_copy_aborted(cs); } /* Do as much copy to/from userspace buffer as we can */ @@ -923,7 +896,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) struct page *newpage; struct pipe_buffer *buf = cs->pipebufs; - err = unlock_request(cs->req); + err = fuse_copy_aborted(cs); if (err) return err; @@ -980,12 +953,10 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) lru_cache_add_file(newpage); err = 0; - spin_lock(&cs->req->waitq.lock); - if (test_bit(FR_ABORTED, &cs->req->flags)) + if (fuse_copy_aborted(cs)) err = -ENOENT; else *pagep = newpage; - spin_unlock(&cs->req->waitq.lock); if (err) { unlock_page(newpage); @@ -1005,7 +976,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) cs->pg = buf->page; cs->offset = buf->offset; - err = lock_request(cs->req); + err = fuse_copy_aborted(cs); if (err) return err; @@ -1021,7 +992,7 @@ static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, if (cs->nr_segs == cs->pipe->buffers) return -EIO; - err = unlock_request(cs->req); + err = fuse_copy_aborted(cs); if (err) return err; @@ -2172,13 +2143,6 @@ static void end_polls(struct fuse_conn *fc) * and all users of the filesystem. The exception is the combination of an * asynchronous request and the tricky deadlock (see * Documentation/filesystems/fuse.txt). - * - * Aborting requests under I/O goes as follows: 1: Separate out unlocked - * requests, they should be finished off immediately. Locked requests will be - * finished after unlock; see unlock_request(). 2: Finish off the unlocked - * requests. It is possible that some request will finish before we can. This - * is OK, the request will in that case be removed from the list before we touch - * it. */ void fuse_abort_conn(struct fuse_conn *fc) { @@ -2187,7 +2151,7 @@ void fuse_abort_conn(struct fuse_conn *fc) spin_lock(&fc->lock); if (fc->connected) { struct fuse_dev *fud; - struct fuse_req *req, *next; + struct fuse_req *req; LIST_HEAD(to_end); unsigned int i; @@ -2205,17 +2169,6 @@ void fuse_abort_conn(struct fuse_conn *fc) spin_lock(&fpq->lock); fpq->connected = 0; - list_for_each_entry_safe(req, next, &fpq->io, list) { - req->out.h.error = -ECONNABORTED; - spin_lock(&req->waitq.lock); - set_bit(FR_ABORTED, &req->flags); - if (!test_bit(FR_LOCKED, &req->flags)) { - set_bit(FR_PRIVATE, &req->flags); - __fuse_get_request(req); - list_move(&req->list, &to_end); - } - spin_unlock(&req->waitq.lock); - } for (i = 0; i < FUSE_PQ_HASH_SIZE; i++) list_splice_tail_init(&fpq->processing[i], &to_end); @@ -2238,6 +2191,7 @@ void fuse_abort_conn(struct fuse_conn *fc) spin_unlock(&fc->lock); end_requests(fc, &to_end); + fuse_wait_aborted(fc); spin_lock(&fc->lock); fc->aborting = false; From patchwork Tue Jan 15 10:19:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F9A3186E for ; Tue, 15 Jan 2019 10:19:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D95B2B2ED for ; Tue, 15 Jan 2019 10:19:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 121692B2FF; Tue, 15 Jan 2019 10:19:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8A252B2ED for ; Tue, 15 Jan 2019 10:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728439AbfAOKTv (ORCPT ); Tue, 15 Jan 2019 05:19:51 -0500 Received: from relay.sw.ru ([185.231.240.75]:36314 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728202AbfAOKTu (ORCPT ); Tue, 15 Jan 2019 05:19:50 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLoy-000130-9F; Tue, 15 Jan 2019 13:19:48 +0300 Subject: [PATCH 6/7] fuse: Kill unused FR_ABORTED, FR_LOCKED and FR_PRIVATE flags From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:47 +0300 Message-ID: <154754758730.4244.17451195008535612523.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 9 ++------- fs/fuse/fuse_i.h | 14 +------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 4905abfb279e..c3bacf9191a6 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1349,7 +1349,6 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, (struct fuse_arg *) in->args, 0); fuse_copy_finish(cs); spin_lock(&fpq->lock); - clear_bit(FR_LOCKED, &req->flags); if (!fpq->connected) { err = fc->aborted ? -ECONNABORTED : -ENODEV; goto out_end; @@ -1376,8 +1375,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, return reqsize; out_end: - if (!test_bit(FR_PRIVATE, &req->flags)) - list_del_init(&req->list); + list_del_init(&req->list); spin_unlock(&fpq->lock); request_end(fc, req); return err; @@ -1955,7 +1953,6 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, clear_bit(FR_SENT, &req->flags); list_move(&req->list, &fpq->io); req->out.h = oh; - set_bit(FR_LOCKED, &req->flags); spin_unlock(&fpq->lock); cs->req = req; if (!req->out.page_replace) @@ -1965,13 +1962,11 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, fuse_copy_finish(cs); spin_lock(&fpq->lock); - clear_bit(FR_LOCKED, &req->flags); if (!fpq->connected) err = -ENOENT; else if (err) req->out.h.error = -EIO; - if (!test_bit(FR_PRIVATE, &req->flags)) - list_del_init(&req->list); + list_del_init(&req->list); spin_unlock(&fpq->lock); request_end(fc, req); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index b5f2265c437c..09ea5773ad81 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -332,35 +332,23 @@ struct fuse_io_priv { * FR_FORCE: force sending of the request even if interrupted * FR_BACKGROUND: request is sent in the background * FR_WAITING: request is counted as "waiting" - * FR_ABORTED: the request was aborted * FR_INTERRUPTED: the request has been interrupted - * FR_LOCKED: data is being copied to/from the request * FR_PENDING: request is not yet in userspace * FR_SENT: request is in userspace, waiting for an answer * FR_FINISHED: request is finished - * FR_PRIVATE: request is on private list */ enum fuse_req_flag { FR_ISREPLY, FR_FORCE, FR_BACKGROUND, FR_WAITING, - FR_ABORTED, FR_INTERRUPTED, - FR_LOCKED, FR_PENDING, FR_SENT, FR_FINISHED, - FR_PRIVATE, }; -/** - * A request to the client - * - * .waitq.lock protects the following fields: - * - FR_ABORTED - * - FR_LOCKED (may also be modified under fc->lock, tested under both) - */ +/* A request to the client */ struct fuse_req { /** This can be on either pending processing or io lists in fuse_conn */ From patchwork Tue Jan 15 10:19:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10764251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F1B513B5 for ; Tue, 15 Jan 2019 10:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D1A72B2ED for ; Tue, 15 Jan 2019 10:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 419C32B2FF; Tue, 15 Jan 2019 10:19:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5A332B2ED for ; Tue, 15 Jan 2019 10:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbfAOKTz (ORCPT ); Tue, 15 Jan 2019 05:19:55 -0500 Received: from relay.sw.ru ([185.231.240.75]:36324 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728202AbfAOKTz (ORCPT ); Tue, 15 Jan 2019 05:19:55 -0500 Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gjLp3-000136-Q7; Tue, 15 Jan 2019 13:19:53 +0300 Subject: [PATCH 7/7] fuse: Kill fuse_pqueue::io list and avoid taking fpq->lock on hot paths From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Tue, 15 Jan 2019 13:19:53 +0300 Message-ID: <154754759346.4244.16770136881400272907.stgit@localhost.localdomain> In-Reply-To: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> References: <154754701031.4244.8089449938935364463.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This list was used to make fuse_abort_conn() end some of requests under io. But it is not used anymore. This allows to avoid taking unneeded fpq->lock in two hot paths: fuse_dev_do_write() and fuse_dev_do_read(). Signed-off-by: Kirill Tkhai --- fs/fuse/dev.c | 16 +++------------- fs/fuse/fuse_i.h | 3 --- fs/fuse/inode.c | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index c3bacf9191a6..b4ce37dda353 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1339,9 +1339,6 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, request_end(fc, req); goto restart; } - spin_lock(&fpq->lock); - list_add(&req->list, &fpq->io); - spin_unlock(&fpq->lock); cs->req = req; err = fuse_copy_one(cs, &in->h, sizeof(in->h)); if (!err) @@ -1362,7 +1359,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, goto out_end; } hash = fuse_req_hash(req->in.h.unique); - list_move_tail(&req->list, &fpq->processing[hash]); + list_add_tail(&req->list, &fpq->processing[hash]); __fuse_get_request(req); set_bit(FR_SENT, &req->flags); spin_unlock(&fpq->lock); @@ -1375,7 +1372,6 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, return reqsize; out_end: - list_del_init(&req->list); spin_unlock(&fpq->lock); request_end(fc, req); return err; @@ -1951,7 +1947,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, } clear_bit(FR_SENT, &req->flags); - list_move(&req->list, &fpq->io); + list_del_init(&req->list); req->out.h = oh; spin_unlock(&fpq->lock); cs->req = req; @@ -1961,13 +1957,8 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, err = copy_out_args(cs, &req->out, nbytes); fuse_copy_finish(cs); - spin_lock(&fpq->lock); - if (!fpq->connected) - err = -ENOENT; - else if (err) + if (err) req->out.h.error = -EIO; - list_del_init(&req->list); - spin_unlock(&fpq->lock); request_end(fc, req); out: @@ -2217,7 +2208,6 @@ int fuse_dev_release(struct inode *inode, struct file *file) unsigned int i; spin_lock(&fpq->lock); - WARN_ON(!list_empty(&fpq->io)); for (i = 0; i < FUSE_PQ_HASH_SIZE; i++) list_splice_init(&fpq->processing[i], &to_end); spin_unlock(&fpq->lock); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 09ea5773ad81..e6b7087fd6b1 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -469,9 +469,6 @@ struct fuse_pqueue { /** Hash table of requests being processed */ struct list_head *processing; - - /** The list of requests under I/O */ - struct list_head io; }; /** diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 0361a3d62356..a36d2675471f 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -601,7 +601,6 @@ static void fuse_pqueue_init(struct fuse_pqueue *fpq) spin_lock_init(&fpq->lock); for (i = 0; i < FUSE_PQ_HASH_SIZE; i++) INIT_LIST_HEAD(&fpq->processing[i]); - INIT_LIST_HEAD(&fpq->io); fpq->connected = 1; }