Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1833491imm; Mon, 3 Sep 2018 10:36:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYYcLmnLLoOUMBY41CO25mKQindzl2KQGjb8ZeTohcP+R2ZDO/48+Vmn1k/p240YV43kk/5 X-Received: by 2002:a63:2906:: with SMTP id p6-v6mr27332572pgp.204.1535996205752; Mon, 03 Sep 2018 10:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996205; cv=none; d=google.com; s=arc-20160816; b=XfKlvsjt3yIVjaQyy4RyjWWnCA25qrUCt4gWlV+9FKGguphnMv6riKDP96DDtmdfMP egDFodinrb1P0/QHDlOKccayTGjAV7hVTGjwViTtE6/7jsnG9gGWWSrR/MdLyDU/EYq7 9qMA+WjPui+Ks7VZ7Inj9hd6PQBJuuUp2ZPNX+tib/mrzEnNhGlISugswCfs5M2Zs9DH SH+Xxv6DDr7YAxxZ8FESMCkW/uAI9fXwqgmyMWSBmc+Sh/QEbwxfh0hDWmfIuczkce7v 7RaF8a9FnzhugZ+uXoKezxlvjvppOY61EBWj6VGRjV79/+nnOq0QTiHcUExA04qNSJ9P p9Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=pLsva/7EfU4A3wEO8MkcO0P1w2aHxDN3mlY7eM4EF9M=; b=ggrw0QqekgO2/2f3E6oqFMDdHv2MP8Jv9Ny1iwiPV3o84/89a5+JR9B6li1puFEmx2 qWHAHMZwNf5AxBEh+6ptC9UAhjUJes1rnIqLsoJ7/TQyDThWuJmExRCDj43H4VgwCKEV 3d/GX37ePh+G0N4BBMuIzH4K0a59a3dSLzJE4ReC9SJQg6uiAdmAIG0OV1o0TfZpYOwc gV7NF5sk4N+m1F2T6v36Qy7v1JrhPS4bgcAczsgIYMERN3i90b48zvO9mB0wGU7gw37k suLIuPwzYBzU1amR6y6L+S0HOwTXJfl6fjSjI17eqRMdtU44WMHu7bns0Wzw0DFbvbDY HpzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5-v6si21105219pfb.104.2018.09.03.10.36.30; Mon, 03 Sep 2018 10:36:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731375AbeICV4j (ORCPT + 99 others); Mon, 3 Sep 2018 17:56:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48006 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbeICV4i (ORCPT ); Mon, 3 Sep 2018 17:56:38 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7706CD1B; Mon, 3 Sep 2018 17:35:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miklos Szeredi Subject: [PATCH 4.18 062/123] fuse: umount should wait for all requests Date: Mon, 3 Sep 2018 18:56:46 +0200 Message-Id: <20180903165722.059920912@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miklos Szeredi commit b8f95e5d13f5f0191dcb4b9113113d241636e7cb upstream. fuse_abort_conn() does not guarantee that all async requests have actually finished aborting (i.e. their ->end() function is called). This could actually result in still used inodes after umount. Add a helper to wait until all requests are fully done. This is done by looking at the "num_waiting" counter. When this counter drops to zero, we can be sure that no more requests are outstanding. Fixes: 0d8e84b0432b ("fuse: simplify request abort") Cc: # v4.2 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev.c | 23 +++++++++++++++++++---- fs/fuse/fuse_i.h | 1 + fs/fuse/inode.c | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -127,6 +127,16 @@ static bool fuse_block_alloc(struct fuse return !fc->initialized || (for_background && fc->blocked); } +static void fuse_drop_waiting(struct fuse_conn *fc) +{ + if (fc->connected) { + atomic_dec(&fc->num_waiting); + } else if (atomic_dec_and_test(&fc->num_waiting)) { + /* wake up aborters */ + wake_up_all(&fc->blocked_waitq); + } +} + static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, bool for_background) { @@ -175,7 +185,7 @@ static struct fuse_req *__fuse_get_req(s return req; out: - atomic_dec(&fc->num_waiting); + fuse_drop_waiting(fc); return ERR_PTR(err); } @@ -285,7 +295,7 @@ void fuse_put_request(struct fuse_conn * if (test_bit(FR_WAITING, &req->flags)) { __clear_bit(FR_WAITING, &req->flags); - atomic_dec(&fc->num_waiting); + fuse_drop_waiting(fc); } if (req->stolen_file) @@ -371,7 +381,7 @@ static void request_end(struct fuse_conn struct fuse_iqueue *fiq = &fc->iq; if (test_and_set_bit(FR_FINISHED, &req->flags)) - goto out_put_req; + goto put_request; spin_lock(&fiq->waitq.lock); list_del_init(&req->intr_entry); @@ -400,7 +410,7 @@ static void request_end(struct fuse_conn wake_up(&req->waitq); if (req->end) req->end(fc, req); -out_put_req: +put_request: fuse_put_request(fc, req); } @@ -2146,6 +2156,11 @@ void fuse_abort_conn(struct fuse_conn *f } EXPORT_SYMBOL_GPL(fuse_abort_conn); +void fuse_wait_aborted(struct fuse_conn *fc) +{ + wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); +} + int fuse_dev_release(struct inode *inode, struct file *file) { struct fuse_dev *fud = fuse_get_dev(file); --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -862,6 +862,7 @@ void fuse_request_send_background_locked /* Abort all requests */ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); +void fuse_wait_aborted(struct fuse_conn *fc); /** * Invalidate inode attributes --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -400,6 +400,8 @@ static void fuse_put_super(struct super_ fuse_send_destroy(fc); fuse_abort_conn(fc, false); + fuse_wait_aborted(fc); + mutex_lock(&fuse_mutex); list_del(&fc->entry); fuse_ctl_remove_conn(fc);