From patchwork Mon Jan 9 03:44:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 40619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1960765wrt; Sun, 8 Jan 2023 19:47:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXuVRmogJsD2np3EfGJPuO2IO339R0xTPI2UkPO6Yw5Di7KlP+Z/JXdfwjCkb3eqm9Yywe9C X-Received: by 2002:a05:6402:1245:b0:498:3bb9:941 with SMTP id l5-20020a056402124500b004983bb90941mr4756039edw.19.1673236053514; Sun, 08 Jan 2023 19:47:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673236053; cv=none; d=google.com; s=arc-20160816; b=zqVNbFEo5Sh13Kjm+zcrcE3V5q9e4rLVRT57Cyh+fu9WejV2su8Pb+oODp+yUP2Kfo XFHFn+7+aNGJzLGoIlOtAeulQbr/7c+ESWCJNOx5F1zIqjRWZr5QfG2jpA86mvFxQjel 7tFtu+JhSswiySJ64AzqQFJao2cTCAV0HIBxaqp5pcuELXzBIL2XrqdFw9Yg8WekbsqW A0ejQjXQOH2Q2dt8M6eCTSj0o+ecqckoiK1suOkO2S6ZxHY4QAP+oQkNqbWkEESX3Oye Yy8MP2JS7A5aF4PJLwwB2bREn8QESH7gf+eyyDxG3hPzUA5saGYr5cv9DGiofOE+ZF4B Kl9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pYIsgz6M0IEbdXuv1QgRwh57qWZajCSyHE1sCPMFfs8=; b=E6sEqDSf2ypmSQe1P0b3vEmMD8OEFRMrH/tTGyTwlu2Oet6WVcChzHP7b43Oku8Xqs r76ak5Sp7GicNTdUKDMym1VtFlZ+tnjP/dUPpsRZGKvqQRot3jiAwM0+PVn/lBq2/SYO LDEcDsL84S0Fyau2d6IjeCr7e18vT9TOob/HpyTJ1xdq/5DUkcWvtRgpmkJJraDPWZkj 447oqZTBqsThEy1Fq3+lRST2/rQtBUgpDIa3zUfrCCNRKpO5zY0tFlwyakn/9zqk1LiI ARXNoGVZ0lIE6qjjEfO0V4bmC036Q/mu+hV2mX503jIGyaEZkyV3sO4UAEmmEVhEF/AC NXNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dy6vAaYU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a05640242c900b00485fa68b06csi10384376edc.354.2023.01.08.19.47.10; Sun, 08 Jan 2023 19:47:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dy6vAaYU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234355AbjAIDpU (ORCPT + 99 others); Sun, 8 Jan 2023 22:45:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbjAIDpQ (ORCPT ); Sun, 8 Jan 2023 22:45:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9CF495A0 for ; Sun, 8 Jan 2023 19:45:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1C94960EE3 for ; Mon, 9 Jan 2023 03:45:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60CC0C433EF; Mon, 9 Jan 2023 03:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673235912; bh=o0QGez8JNtfwfRegKYb2IXEmNk+VVLuwDSFz2DvJBSY=; h=From:To:Cc:Subject:Date:From; b=Dy6vAaYUAxbL0xhJdA/zEa4jCKnVodSGMc2y9Q4A0ow9KBjQxCrDnqHLIbsIXZa2f TywH6ZfEZpyz2yPG5trS6msnAOgiPWvdRGF689/7tOTnVZXt+c73hS2ZSJj40cON5b 1DB/RBLilUSOMCk0SYq0HJOc45t9r67XXCiwulrNyVs9gY399xQy2a3Nge7XowtrWL I0KOZxviWblfWtzlRft6Zq4ovvUOxvHeIzgJNnw/xj7DXwTuPrF63qVZoUSU5kXlng viw1wNIdvG/P2pRZZ8AYfVRjnb3iad7ZJoK333Ln8ZzSQn+PauwxNNeaiohdMwcIn4 OLozjyTItmxKw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/5] f2fs: introduce trace_f2fs_replace_atomic_write_block Date: Mon, 9 Jan 2023 11:44:49 +0800 Message-Id: <20230109034453.490176-1-chao@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754515167851502158?= X-GMAIL-MSGID: =?utf-8?q?1754515167851502158?= Commit 3db1de0e582c ("f2fs: change the current atomic write way") removed old tracepoints, but it missed to add new one, this patch fixes to introduce trace_f2fs_replace_atomic_write_block to trace atomic_write commit flow. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 3 +++ include/trace/events/f2fs.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8b773f3eef3b..c6f6d0618164 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -255,6 +255,9 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, } f2fs_put_dnode(&dn); + + trace_f2fs_replace_atomic_write_block(inode, F2FS_I(inode)->cow_inode, + index, *old_addr, new_addr, recover); return 0; } diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index 3852085198fb..fe6bcf5f917d 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -1290,6 +1290,43 @@ DEFINE_EVENT(f2fs__page, f2fs_vm_page_mkwrite, TP_ARGS(page, type) ); +TRACE_EVENT(f2fs_replace_atomic_write_block, + + TP_PROTO(struct inode *inode, struct inode *cow_inode, pgoff_t index, + block_t old_addr, block_t new_addr, bool recovery), + + TP_ARGS(inode, cow_inode, index, old_addr, new_addr, recovery), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(ino_t, cow_ino) + __field(pgoff_t, index) + __field(block_t, old_addr) + __field(block_t, new_addr) + __field(bool, recovery) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->cow_ino = cow_inode->i_ino; + __entry->index = index; + __entry->old_addr = old_addr; + __entry->new_addr = new_addr; + __entry->recovery = recovery; + ), + + TP_printk("dev = (%d,%d), ino = %lu, cow_ino = %lu, index = %lu, " + "old_addr = 0x%llx, new_addr = 0x%llx, recovery = %d", + show_dev_ino(__entry), + __entry->cow_ino, + (unsigned long)__entry->index, + (unsigned long long)__entry->old_addr, + (unsigned long long)__entry->new_addr, + __entry->recovery) +); + TRACE_EVENT(f2fs_filemap_fault, TP_PROTO(struct inode *inode, pgoff_t index, unsigned long ret), From patchwork Mon Jan 9 03:44:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 40620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1960797wrt; Sun, 8 Jan 2023 19:47:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKRlfMzLpitSG0qT51bCo3xSParLabOVdcULdD3zQ2tvBB6UNDPuF5OreQ9EGq8oS6D7X+ X-Received: by 2002:a17:907:8e93:b0:7ae:bfec:74c7 with SMTP id tx19-20020a1709078e9300b007aebfec74c7mr57913561ejc.72.1673236064426; Sun, 08 Jan 2023 19:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673236064; cv=none; d=google.com; s=arc-20160816; b=yBmGqRD251KQhpB4gc/8v92ABA+/SWaWrq9wz7aIRjYgk28ul8NZNvC37hDEWL1tHq oTJ7lUNXR3jXeaAmbVpZ6unePYR03cNr52QpEoFyMFGP2489XtpnT3GE+0KVw5QFhBuR sN/jbNdFP93CftofDexPNWizzIgzjsYGJaqtDpweGHM1zaM8LuidhTuFTN1ZJ+abDO2O Nw8JIKUXmKqDW4udflNSKkhqzUWGpw5dBKdEGzFzuEsQInQB9C/tXciiepJTJeVedm73 6Eo61BCOCvEjPhjIzIdosMAhthsQjRmaNN4280/CKTqq7Tvou5lFeR0xTaN8i0/XkjF+ UDlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=euvkepgFT3TX951BGNdItfqdJ54GGwjTkv52+qkVxEQ=; b=z6Ghc7IYaeJLbsh/jGJrhIphHy8Sdqdr6efBzGbDhawq35XPawz/XXK/afIFxmnmGt ++nAKxGfdt3aGGL4/hi+bPIhMqK3DKPMYk5G6q4YuLSTRiGebHvS1ETVxKIbPM1/Cd/H blU2yrPf0uCVEpg+6OeX9YYaYMMIET08m3iif1lrh/g0zCtd1xxO4XK1L0sYP240Rh+W iZFtWNE2avWMkNpV2nLBAB4UOR8b20vhogsDgeOe0hOrWqLPIINM6KW1b2Jh1aScrZ8o IWXeiijJGgrxE3hiYIbex53FORYajoZGFGprVtP+qLYUPuBoVYkfNgQXK2sjKpHLtXsp 9GCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HtGz6EvX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ww2-20020a170907084200b0084cb7291b36si7375546ejb.991.2023.01.08.19.47.21; Sun, 08 Jan 2023 19:47:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HtGz6EvX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234261AbjAIDpW (ORCPT + 99 others); Sun, 8 Jan 2023 22:45:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233682AbjAIDpR (ORCPT ); Sun, 8 Jan 2023 22:45:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A82F020 for ; Sun, 8 Jan 2023 19:45:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A165060EAD for ; Mon, 9 Jan 2023 03:45:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEBC1C433F2; Mon, 9 Jan 2023 03:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673235914; bh=z+rEkFMv+wRfNSPG7VtFK07vpI0/Mb7wF/w9G4C5Uac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HtGz6EvXa+PBbLwGnayMZXLkItsmkkRMAzq4RG4PAi2baRQI+1yaWsh/aM3xDxP2v 3Vjdh6bHI6i/e4n+cSTmMDxh1IPlD7HACU6HAUuQgLw6uXVeZk1UTEHfGHCg4xyF+V suZvvZrCquqM7Fe88ORTzPJQEgckViUKuctoe0+hrsgRFsS1ME4falCNouyTrbyXvj kXliOVbAeEV9pt7voeRaoA4ACYnq8fpfm05Ao6f/Vc9vmBTJlZI6AczeccBXXOIjrz H6bFMyumDZIkYiUL5B9lQFVw7LjzK2c+syKYUp8wN5e2CnZn8nnQFRR95pU2mWGLdc uPACqtsXlbEnA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 2/5] f2fs: clear atomic_write_task in f2fs_abort_atomic_write() Date: Mon, 9 Jan 2023 11:44:50 +0800 Message-Id: <20230109034453.490176-2-chao@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109034453.490176-1-chao@kernel.org> References: <20230109034453.490176-1-chao@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754515179721060008?= X-GMAIL-MSGID: =?utf-8?q?1754515179721060008?= Otherwise, last .atomic_write_task will be remained in structure f2fs_inode_info, resulting in aborting atomic_write accidentally in race case. Meanwhile, clear original_i_size as well. Fixes: 7a10f0177e11 ("f2fs: don't give partially written atomic data from process crash") Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c6f6d0618164..5f7e42b355eb 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -201,9 +201,12 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean) clear_inode_flag(inode, FI_ATOMIC_FILE); stat_dec_atomic_inode(inode); + F2FS_I(inode)->atomic_write_task = NULL; + if (clean) { truncate_inode_pages_final(inode->i_mapping); f2fs_i_size_write(inode, fi->original_i_size); + fi->original_i_size = 0; } } From patchwork Mon Jan 9 03:44:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 40624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1961447wrt; Sun, 8 Jan 2023 19:50:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXszDOEo3UTmK4WcOsMuy47XDA0SqxoiODgPbd1vcieEnb/SDaX0yzaelE6SeSOoOZNK9he7 X-Received: by 2002:a17:906:c192:b0:7c1:6fe:f4a2 with SMTP id g18-20020a170906c19200b007c106fef4a2mr55092226ejz.45.1673236221151; Sun, 08 Jan 2023 19:50:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673236221; cv=none; d=google.com; s=arc-20160816; b=wDOlXOUip8yaJVsL/zWocQzJ0KbrH9MISLmybi/ciD7Bo+/lDxuOQrPxhczU3HYDrX yRyoWWWrsQ/zpJQlijJymbH+a19zH/a505/hARWo5lvM3OtHizI83W2spVK1MO2TjCJK hZRfTXqqxuAxM/m9cvCzcWJgwcULjkla7pXbmHaPKxkBfYu4jAmYK/5XEJvqobRRIgYr IH9n00TL3dtLNDKJV6uBooO575XkmteXD/NGFvJqHuKtWJrTtKNef7lU/n4E4GaLIfVM gChLfUZciKJmjh+7d1fCFna1IRkGll26FGeYNiiKbnVqPiMZwF3e2WXgvNQEZI6x8ic4 swJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rHRshsuBf+8lCGtLmK89FWYAz7KW/e2jrXHpUqGarjU=; b=CERE9HP2Pk+1UPtUJEQB4PF6/ZLBjihojDhIYtMNnQ1/2JueIAPeyAXmlvD0+jZe0J sdNaOqQ2Ns3x9lBg1Qh+ogyF4xCbw1oixFlshPx0y4mBq+qlTY3hA8+xCaVYQu/UkjA6 EyjiY5PB/PFmqzAJufN7a2sVlV4Z01TW/juiiNSQqO8IMawUn5ObvtGSmcq8UdSzOBP/ W0pnRxkCaBERfuqSDE1S3SPrq/6kFHQxGvNwx8/1VuGx5DtD4f4CWkUkLYwfMhFyHD30 r+HVqayf2gPA4PIusBHkr3HhEZ2kQ39WfCiyDy5aaDfyHaDylogy7qP39riapV0evP1u i98A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tjJos42k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xc13-20020a170907074d00b0084d7c8a4be0si6000ejb.447.2023.01.08.19.49.58; Sun, 08 Jan 2023 19:50:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tjJos42k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236008AbjAIDpk (ORCPT + 99 others); Sun, 8 Jan 2023 22:45:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234319AbjAIDpT (ORCPT ); Sun, 8 Jan 2023 22:45:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D611593 for ; Sun, 8 Jan 2023 19:45:18 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EEEE8B8085B for ; Mon, 9 Jan 2023 03:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8769EC433F0; Mon, 9 Jan 2023 03:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673235915; bh=hVQIDpSVJOnPY2pK3qWpbcFhTb9CAdeMNX3yCL8XtEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tjJos42kd7YwDy512Qj+aLjV4Lf4PU/FjJhfrLf/9lBdLNo8IV4QeYNs4yxC6TXdn LCk6WkCi4srQ/ohEXXB8RUPAPD0oDBPiVtQ3hYVh2j/BBoJKKfDi21Oj+gXI6tucyN azQGIomcooCa+UMy1wTUrISbPzyjY0/Gzd9by6iz/3VuArvhLCEPhcWo42enhqRVgn PzMSaOd0YiKYCJZcjlPDvLNP1CXttCtFTqpJ2HAuenfd/0op4YNFEwfJ1bNqShu9bK XeqL4Sg0O3/3/bRFqJxuO4HDsFrBxKiZJnxOCpQg9MDiKYP1c0KYGQ4Tk4QmLyJOME SbusW1M3r6woQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 3/5] f2fs: fix to abort atomic write only during do_exist() Date: Mon, 9 Jan 2023 11:44:51 +0800 Message-Id: <20230109034453.490176-3-chao@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109034453.490176-1-chao@kernel.org> References: <20230109034453.490176-1-chao@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754515343904810831?= X-GMAIL-MSGID: =?utf-8?q?1754515343904810831?= Commit 7a10f0177e11 ("f2fs: don't give partially written atomic data from process crash") attempted to drop atomic write data after process crash, however, f2fs_abort_atomic_write() may be called from noncrash case, fix it by adding missed PF_EXITING check condition f2fs_file_flush(). - application crashs - do_exit - exit_signals -- sets PF_EXITING - exit_files - put_files_struct - close_files - filp_close - flush (f2fs_file_flush) - check atomic_write_task && PF_EXITING - f2fs_abort_atomic_write Fixes: 7a10f0177e11 ("f2fs: don't give partially written atomic data from process crash") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 434c0d89c145..7b62c533f6d3 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1876,7 +1876,8 @@ static int f2fs_file_flush(struct file *file, fl_owner_t id) * until all the writers close its file. Since this should be done * before dropping file lock, it needs to do in ->flush. */ - if (F2FS_I(inode)->atomic_write_task == current) + if (F2FS_I(inode)->atomic_write_task == current && + (current->flags & PF_EXITING)) f2fs_abort_atomic_write(inode, true); return 0; } From patchwork Mon Jan 9 03:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 40621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1960942wrt; Sun, 8 Jan 2023 19:48:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXvRX+br1UV/J0Ewep8kzjbKm4soZjHF+O9NWxc4IRsc5c/R/PJp7GBny8Z5qBv38H1IehSj X-Received: by 2002:a17:906:3544:b0:84d:3fa7:12e5 with SMTP id s4-20020a170906354400b0084d3fa712e5mr3168119eja.32.1673236099906; Sun, 08 Jan 2023 19:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673236099; cv=none; d=google.com; s=arc-20160816; b=sZ1y9wmSUBjeDpFxCxO359/CZTthPRJRLZIXl0K8PyGDH/FTVdRFyxIeGm/iuiZS6S 2RIkjt74pt9okQkwdY1ztVJ+IezPd5kFZer4QQYSbismy/y0w2RPHpjriEkCXg33aRjI UAd9AH10nInFJVtUWC6NORmF39R3dxflUjhvd1OGkVEgxIWmZSePkjxGLs5klPBDtraw kPxWhfsex2sfFcm17w8YD/CjRa3Os2LHbaMfaoqRP7nRLAgIzEHsCYC2HGEw423FUWap woF53MUNvBs1o1mO+/Z5ke2YCZRcBFXHezEAKkmQu80UPqp/gafH8B7pqOLc6Ie8VrjH hqCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BdLqJeLtzpNkFpkUgEU+4QDrBz/bontDoMJt5v1nsWQ=; b=QlggCOBv3vdjVcJ/wn3o4l5eLB3Y8TK9/GIjmtG4GhxIKQ4VRCaCGYma9ALZu6zMPw GaETAmAxyWwYfqgs7wfC33YPJHhLmGrIfWY2g8snZ9bfPtAmkkviEwf5G5wen+5pRViJ soYRqv2RhdnaS2Bn0ozNVU84BMJUAEbMowPGp3/MzEnADMnjdKimYk9lwxP2vVN1Cb8z YRA7YExYWw4aYyEHLm4mBwgNwaOBL0dPvPHEag94l+fkIqA0vG2FuJoXVBCRAZusOshb U7tf0jX4W3F8FqlxiUTtDA6mcGxK13R21kJgf7JgFvyRsQsZPh77rVUlkVUvh3F+1bDf v4/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=usr0EL8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn4-20020a17090794c400b0084c7b099652si9325771ejc.567.2023.01.08.19.47.57; Sun, 08 Jan 2023 19:48:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=usr0EL8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234285AbjAIDp3 (ORCPT + 99 others); Sun, 8 Jan 2023 22:45:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234384AbjAIDpV (ORCPT ); Sun, 8 Jan 2023 22:45:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7194DA45B for ; Sun, 8 Jan 2023 19:45:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B1E34B80CA3 for ; Mon, 9 Jan 2023 03:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F702C433F2; Mon, 9 Jan 2023 03:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673235917; bh=p3rbTOR1QFjXLaPSnR9uaBLuFIGzPk439CwPaP0U//8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usr0EL8S2TWfVQj+6ygM2g8ntOS+6+nOYBoOMFpmSClbP1nd1kNQp7S0NZOFyUCNs k2HR7uMtEeEmp/KhHGsdYqzmficO41WyG+xvUemkT6xd84HnuKBzV/4Xfi2dJT0z4i dMa7uGrneuB8tYADOtTa07DJDdXbNYBoDFtdTdL0CBA2yvp5YnleqCg3GSwv2DmxyQ QkkSp9uRuKu7VHPhSnMJtuQx5DD8x37MVu9xe2Hndbhn6e+gIVTpFzufWGr3LOuvGC Qr1b7CW/u8GPRXJRMSIgx2+ptZfrdPBBj4WN0rLjQuXO3O1tdu/ZqfSJVkY7yVvQnS e1Av9wykN6wnw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , syzbot+9b7be0f1263ed2dbfbba@syzkaller.appspotmail.com Subject: [PATCH 4/5] f2fs: fix to avoid race condition of f2fs_abort_atomic_write() Date: Mon, 9 Jan 2023 11:44:52 +0800 Message-Id: <20230109034453.490176-4-chao@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109034453.490176-1-chao@kernel.org> References: <20230109034453.490176-1-chao@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754515216541759065?= X-GMAIL-MSGID: =?utf-8?q?1754515216541759065?= Syzbot reports a kernel panic as below: kernel BUG at fs/inode.c:1763! RIP: 0010:iput+0x68/0x80 fs/inode.c:1763 Call Trace: f2fs_abort_atomic_write+0xea/0x4f0 fs/f2fs/segment.c:196 f2fs_ioc_commit_atomic_write+0x19f/0x260 fs/f2fs/file.c:2157 __f2fs_ioctl+0x26f0/0xaaf0 fs/f2fs/file.c:4154 f2fs_ioctl+0x18e/0x220 fs/f2fs/file.c:4242 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl fs/ioctl.c:856 [inline] __x64_sys_ioctl+0x197/0x210 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd The root cause is there may be race case in between f2fs_abort_atomic_write() called from f2fs_file_flush() and f2fs_ioc_commit_atomic_write(). Thread A Thread B - close - close_fd - filp_close - f2fs_file_flush - f2fs_ioctl - f2fs_ioc_commit_atomic_write - f2fs_abort_atomic_write - iput(cow_inode) - f2fs_evict_inode - clear_inode - inode->i_state = I_FREEING | I_CLEAR; - f2fs_abort_atomic_write - iput(cow_inode) - BUG_ON(inode->i_state & I_CLEAR) - cow_inode = NULL - cow_inode = NULL So let's cover f2fs_abort_atomic_write() with f2fs_inode_info.i_atomic_sem lock to avoid this race condition. Reported-by: syzbot+9b7be0f1263ed2dbfbba@syzkaller.appspotmail.com Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 6 +++++- fs/f2fs/super.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 70ed01aca6f6..fa41c0dad308 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -854,6 +854,7 @@ struct f2fs_inode_info { struct extent_tree *extent_tree[NR_EXTENT_CACHES]; /* cached extent_tree entry */ struct inode *cow_inode; /* copy-on-write inode for atomic write */ + struct f2fs_rwsem i_atomic_sem; /* protect atomic write context */ /* avoid racing between foreground op and gc */ struct f2fs_rwsem i_gc_rwsem[2]; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 5f7e42b355eb..245d7adef6c6 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -189,8 +189,10 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean) { struct f2fs_inode_info *fi = F2FS_I(inode); + f2fs_down_write(&fi->i_atomic_sem); + if (!f2fs_is_atomic_file(inode)) - return; + goto out_unlock; clear_inode_flag(fi->cow_inode, FI_COW_FILE); iput(fi->cow_inode); @@ -208,6 +210,8 @@ void f2fs_abort_atomic_write(struct inode *inode, bool clean) f2fs_i_size_write(inode, fi->original_i_size); fi->original_i_size = 0; } +out_unlock: + f2fs_up_write(&fi->i_atomic_sem); } static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 0e8b3e27fa14..3edc8630eb4b 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1411,6 +1411,7 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) init_f2fs_rwsem(&fi->i_gc_rwsem[READ]); init_f2fs_rwsem(&fi->i_gc_rwsem[WRITE]); init_f2fs_rwsem(&fi->i_xattr_sem); + init_f2fs_rwsem(&fi->i_atomic_sem); /* Will be used by directory only */ fi->i_dir_level = F2FS_SB(sb)->dir_level; From patchwork Mon Jan 9 03:44:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 40622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1961010wrt; Sun, 8 Jan 2023 19:48:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXtIpvaZJ3gfj5ojxhnljWEf9fT9Yjl4wNxH2IbY421wJ03y4C+zKXj4xAG+NCyl8R2a/qE2 X-Received: by 2002:a17:907:c242:b0:7c1:9e6:d38e with SMTP id tj2-20020a170907c24200b007c109e6d38emr64755242ejc.67.1673236113112; Sun, 08 Jan 2023 19:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673236113; cv=none; d=google.com; s=arc-20160816; b=W4CyVggXBbA/uctekzZQ7MqpkBuCsUyDk6XnRtcL/mO7k6yyD/wZluAmODpEbHTrmo e+RVl6HNzk0Is83k/2dfXLZDO7tfKI2RAhTxrqzOlZ39Z56jQgsTIwa5BdoroucJO9vS VtTA1GMKJN458HUBeb1WheYXhJ1affBWLx4I6y0KKDTebkqSPiGUsLqUhRLcmAgcWl/Q DIsqzY7m9TGZ4+WhHfQe+27iKvpOjU1hdmjHqrXjMvuGpc/GLGJiLoTXHLl0/rwIke77 NtxmWxw0tUf9cZ10AaNFTDvJWBfJpknQ6v3XUcC3eKS8djoGdc57bQcmGp+iRZCELmW0 03gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ddB79ksns4t2a1Y6SpOqk674sSKsAYNx9zfbCxBSxo4=; b=MxVcOcp80SorknUBg0lv1mvtbC+EkmRRGAAVHsQWZC71OpAIZ2II84yKfLB58fl7KA hCEZZRiycAQN5WTsHIi8Bo3MDGmB4qjzBHMqLf2Cc6IFlLCHxnmR2o/2e53zOeIes2rM nFJyv9YYQIABZBbOBhP9KQ63EO4EOlrNvbqaO5mTCbYQSY0zCaHraXyOGkTBWW77wdrE FAHDQ+UdgMsrrsVbXxdNeUCYbFtLx3frEV4l4neproJiTnV3cBTYFv2R1vZC/vG8CjwQ VSt6Jj9TotTyGx9JjtwuRbGLF+PiUXFCFz6ecdZ5AQUIStlgtoylmviLSr+uy9A5QwIS aQ6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fnz5Izj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he17-20020a1709073d9100b0078def5c29e3si8970056ejc.596.2023.01.08.19.48.10; Sun, 08 Jan 2023 19:48:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fnz5Izj6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234219AbjAIDpe (ORCPT + 99 others); Sun, 8 Jan 2023 22:45:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234343AbjAIDpU (ORCPT ); Sun, 8 Jan 2023 22:45:20 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D1DD2DC for ; Sun, 8 Jan 2023 19:45:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8993A60EAD for ; Mon, 9 Jan 2023 03:45:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7FC3C433D2; Mon, 9 Jan 2023 03:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673235919; bh=hKDOr8JIcD75xkm83bOzZlDNnSHJYgKqfFQhYck7fao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fnz5Izj6HLtcxq0IIK6AI95gkyGbaKgKRuG+asb279Pl0s1mm1k0R+E41pV8g8Zew 4jNTdjkDcybVvv8+/nEOzETVYM7RTOFSYd65UoKD8a7On4TvdZSP2JVXI6TviD4OrE U7iySzqLi/1nzSJkYhKTYg80ZDPvm7Z42YvVBWht0Wg+lheknO4vMaCbuf91Y5FlX3 qwp10urnh9YwPbTsLjAYdLObjGSlGqOEl7aNM+4Cx7q3ZIlzMArRNsG6k0DOvAoW1V vwN0Q6yXUSW4drJRhnKnkcWpVaVajeZg82U0UAGynd+/QVfuz8PlL0eCX5d4wxyU3M /KHS/LAe3//cA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 5/5] f2fs: fix to avoid race condition of atomic write Date: Mon, 9 Jan 2023 11:44:53 +0800 Message-Id: <20230109034453.490176-5-chao@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109034453.490176-1-chao@kernel.org> References: <20230109034453.490176-1-chao@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754515230399947850?= X-GMAIL-MSGID: =?utf-8?q?1754515230399947850?= Thread A Kworker - application crashs - do_exit - close_files - filp_close - flush (f2fs_file_flush) - writepages - f2fs_write_cache_pages - f2fs_write_single_data_page - f2fs_do_write_data_page - check f2fs_is_atomic_file - f2fs_abort_atomic_write - check f2fs_is_atomic_file - iput(cow_inode) - cow_inode = NULL - set_new_dnode(cow_inode) Fix this issue by covering f2fs_do_write_data_page() with i_atomic_sem. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu --- fs/f2fs/data.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c940da1c540f..1645b8a1b904 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2637,13 +2637,24 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) struct dnode_of_data dn; struct node_info ni; bool ipu_force = false; + bool atomic_locked = false; int err = 0; /* Use COW inode to make dnode_of_data for atomic write */ - if (f2fs_is_atomic_file(inode)) + if (f2fs_is_atomic_file(inode)) { + f2fs_down_write(&F2FS_I(inode)->i_atomic_sem); + atomic_locked = true; + + if (!f2fs_is_atomic_file(inode)) { + /* atomic write is aborted */ + err = -ENOENT; + goto out_err; + } + set_new_dnode(&dn, F2FS_I(inode)->cow_inode, NULL, NULL, 0); - else + } else { set_new_dnode(&dn, inode, NULL, NULL, 0); + } if (need_inplace_update(fio) && f2fs_lookup_read_extent_cache_block(inode, page->index, @@ -2652,7 +2663,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) DATA_GENERIC_ENHANCE)) { f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR); - return -EFSCORRUPTED; + err = -EFSCORRUPTED; + goto out_err; } ipu_force = true; @@ -2661,8 +2673,10 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) } /* Deadlock due to between page->lock and f2fs_lock_op */ - if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi)) - return -EAGAIN; + if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi)) { + err = -EAGAIN; + goto out_err; + } err = f2fs_get_dnode_of_data(&dn, page->index, LOOKUP_NODE); if (err) @@ -2710,6 +2724,9 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) set_inode_flag(inode, FI_UPDATE_WRITE); } trace_f2fs_do_write_data_page(fio->page, IPU); + + if (atomic_locked) + f2fs_up_write(&F2FS_I(inode)->i_atomic_sem); return err; } @@ -2747,6 +2764,9 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) out: if (fio->need_lock == LOCK_REQ) f2fs_unlock_op(fio->sbi); +out_err: + if (atomic_locked) + f2fs_up_write(&F2FS_I(inode)->i_atomic_sem); return err; }