From patchwork Fri May 1 13:21:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 226490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FCEBC47254 for ; Fri, 1 May 2020 13:58:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEED1206D6 for ; Fri, 1 May 2020 13:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588341535; bh=O3QIexIeqU5P2QEyxwjjbx+5fccgxwre6dJpMsJdDm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jCu5mDz2nN05lqitJGACUA5mwPQWD8KPcUQUg6JI1J3SJ+h0wag/i6xz6vNEYGl8d ckkc9Ik68amDK5sk0DunMiFW3e2gnCqnGRydg+LzCfeDJeLKByAVpg7RP2fmsxFMqZ lxBui0OIAIJC5xVbRMrlA49UMpE1ncRhmdVQ3OKQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729835AbgEAN3t (ORCPT ); Fri, 1 May 2020 09:29:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:53538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbgEAN3s (ORCPT ); Fri, 1 May 2020 09:29:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A3B53208C3; Fri, 1 May 2020 13:29:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339788; bh=O3QIexIeqU5P2QEyxwjjbx+5fccgxwre6dJpMsJdDm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kK/2zhQiJnVb7CAZRWDUYETnOMT69imq8AhjVBgRvY/3fBkm+Gs3SAnqKb7xLlUhS A2LLlhzx+66ndq7YAPYKqcrpSMHIq5W2L8VXorJKeMCArYnRGt2ReW/luRg6ac6eDf AoEr8S8/eoP5iWL1zOUP8fKbVIeVQbDKg7eUs0s4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miklos Szeredi , Guenter Roeck Subject: [PATCH 4.9 60/80] fuse: fix possibly missed wake-up after abort Date: Fri, 1 May 2020 15:21:54 +0200 Message-Id: <20200501131531.407149934@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.810761598@linuxfoundation.org> References: <20200501131513.810761598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Miklos Szeredi commit 2d84a2d19b6150c6dbac1e6ebad9c82e4c123772 upstream. In current fuse_drop_waiting() implementation it's possible that fuse_wait_aborted() will not be woken up in the unlikely case that fuse_abort_conn() + fuse_wait_aborted() runs in between checking fc->connected and calling atomic_dec(&fc->num_waiting). Do the atomic_dec_and_test() unconditionally, which also provides the necessary barrier against reordering with the fc->connected check. The explicit smp_mb() in fuse_wait_aborted() is not actually needed, since the spin_unlock() in fuse_abort_conn() provides the necessary RELEASE barrier after resetting fc->connected. However, this is not a performance sensitive path, and adding the explicit barrier makes it easier to document. Signed-off-by: Miklos Szeredi Fixes: b8f95e5d13f5 ("fuse: umount should wait for all requests") Cc: #v4.19 Cc: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -132,9 +132,13 @@ static bool fuse_block_alloc(struct fuse 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)) { + /* + * lockess check of fc->connected is okay, because atomic_dec_and_test() + * provides a memory barrier mached with the one in fuse_wait_aborted() + * to ensure no wake-up is missed. + */ + if (atomic_dec_and_test(&fc->num_waiting) && + !READ_ONCE(fc->connected)) { /* wake up aborters */ wake_up_all(&fc->blocked_waitq); } @@ -2164,6 +2168,8 @@ EXPORT_SYMBOL_GPL(fuse_abort_conn); void fuse_wait_aborted(struct fuse_conn *fc) { + /* matches implicit memory barrier in fuse_drop_waiting() */ + smp_mb(); wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); }