From patchwork Tue Jan 31 06:15:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 1734559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=qszb=54=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mit.edu header.i=@mit.edu header.a=rsa-sha256 header.s=outgoing header.b=C4xVlxHs; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P5ZYq312xz23j9 for ; Tue, 31 Jan 2023 17:16:15 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P5ZYp4LK1z4wgv for ; Tue, 31 Jan 2023 17:16:14 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4P5ZYp4HpTz4xwy; Tue, 31 Jan 2023 17:16:14 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=none dis=none) header.from=mit.edu Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mit.edu header.i=@mit.edu header.a=rsa-sha256 header.s=outgoing header.b=C4xVlxHs; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4P5ZYp4CLwz4wgv for ; Tue, 31 Jan 2023 17:16:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229963AbjAaGQN (ORCPT ); Tue, 31 Jan 2023 01:16:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbjAaGQJ (ORCPT ); Tue, 31 Jan 2023 01:16:09 -0500 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 979123B652 for ; Mon, 30 Jan 2023 22:16:04 -0800 (PST) Received: from cwcc.thunk.org (pool-173-48-120-46.bstnma.fios.verizon.net [173.48.120.46]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 30V6Fllp024372 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 01:15:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1675145749; bh=hLou58FOHENe/dNZmvXpv2PAJVqLzUyie6xQoHGmIf4=; h=From:To:Cc:Subject:Date; b=C4xVlxHsNEwjoJfi3bkvQiGToHVHMYgYY3iie3N2HlZ+merJYesJUuwzZsD4dKedy LSLD281kSUvLzbtKHhLrQ511eYFSinCbn7SiI9z0RwPyvNsVJOoNxW195TcO5zkzER V0x3YAsP2HhwzG9tVKKNv+TL9gvABZetnLcY07CVpbd0RincKBEu71Wq0aL5+NdbOd DQednXGm1QwaCvsUD3a4JJYm0k28Qcld+yBQtGI6Cbo2MHF7KCQ4y+9DmGgcIXz+AX JbZ7b0hJxsEHm8QLGVBfklyfBHtRmm2DxtQmSEV6axfnqXV1uzuw8a820EzT2k77Cd Sngohm/UgFk/w== Received: by cwcc.thunk.org (Postfix, from userid 15806) id BC80915C359D; Tue, 31 Jan 2023 01:15:47 -0500 (EST) From: "Theodore Ts'o" To: Ext4 Developers List Cc: zhanchengbin1@huawei.com, linfeilong@huawei.com, "Theodore Ts'o" Subject: [PATCH 0/3] e2fsprogs: fix deadlock issus in unix_io on write errors Date: Tue, 31 Jan 2023 01:15:39 -0500 Message-Id: <20230131061542.324172-1-tytso@mit.edu> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This problem was reported by [1] but the fix was incorrect. The issue is that when unix_io was made thread-safe, it was necessary that to add a CACHE_MUTEX to protect multiple threads from potentially colliding with the very simple writeback cache used by the unix_io I/O manager. The original I/O manager was purposefully kept simple, used a fixed-size cache; accordingly, the locking used also kept simple, and used a single global mutex. [1] https://lore.kernel.org/r/310fb77f-dfed-1196-c4ee-30d5138ee5a2@huawei.com The problem was that if an application (such as e2fsck) registers a write error handler, that handler would be called with the CACHE_MUTEX still held, and if that application tried to do any I/O --- for example, closing the file system using ext2fs_close() and then exiting --- the application would deadlock. The fixes here are good enough for the use case found in e2fsprogs, and in practice there are very few other users of the error handler feature in libext2fs. *** BLURB HERE *** Theodore Ts'o (3): libext2fs: unix_io: add flag which suppresses calling the write error handler libext2fs: unix_io: fix potential error path deadlock in reuse_cache() libext2fs: unix_io: fix_potential error path deadlock in flush_cached_blocks() lib/ext2fs/unix_io.c | 151 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 126 insertions(+), 25 deletions(-)