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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 B8058C433DB for ; Fri, 25 Dec 2020 08:53:35 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62B55230FF for ; Fri, 25 Dec 2020 08:53:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62B55230FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1ksiqs-0003lY-TZ; Fri, 25 Dec 2020 08:53:34 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksiqr-0003lQ-LZ for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Dec 2020 08:53:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=z1wfGqZN4/m99P16jjXHJ9H8Kr2y5CXSGn89lR43sPU=; b=Jf1ykU5C7G1M3OhepWdrLp2iLB OJJptpcFiBO/mUdWEM/+gwrH6BLwKryAmg4pCVBpmnebc+2YNmnNTW1uUdEEBX63l9U/Gc4X+n69x pl9RCbr3wI/siGqy+cMoDT99E3EnCAVb65GxjvbvBz9eQOKLnoGKiFON0scHeRbLID/Q=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:CC:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=z1wfGqZN4/m99P16jjXHJ9H8Kr2y5CXSGn89lR43sPU=; b=Q 6Cky7/FBBt3LjKgM9wDPVxkgRXoz3RcrpEz2KsC9A93BLj2kGF2I8RZUYWz69yY7RdknpJVk6KU9Z zVPzgoY4rTQqZOFMFduqBPno7flRTXHwVCMtg03aXfKOjIjs3iWEBRKpucLKKptS5EgXaPV5X9nOZ jWlfZTCyVY/uRguc=; Received: from szxga05-in.huawei.com ([45.249.212.191]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1ksiqn-00Dzwe-3E for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Dec 2020 08:53:33 +0000 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D2LLC2slSzhxJW; Fri, 25 Dec 2020 16:52:35 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Fri, 25 Dec 2020 16:53:12 +0800 From: Chao Yu To: Date: Fri, 25 Dec 2020 16:53:04 +0800 Message-ID: <20201225085304.114448-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected X-Headers-End: 1ksiqn-00Dzwe-3E Subject: [f2fs-dev] [PATCH] f2fs: fix to keep isolation of atomic write X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net ThreadA ThreadB - f2fs_ioc_start_atomic_write - write - f2fs_ioc_commit_atomic_write - f2fs_commit_inmem_pages - f2fs_drop_inmem_pages - f2fs_drop_inmem_pages - __revoke_inmem_pages - f2fs_vm_page_mkwrite - set_page_dirty - tag ATOMIC_WRITTEN_PAGE and add page to inmem_pages list - clear_inode_flag(FI_ATOMIC_FILE) - f2fs_vm_page_mkwrite - set_page_dirty - f2fs_update_dirty_page - f2fs_trace_pid - tag inmem page private to pid - truncate - f2fs_invalidate_page - set page->mapping to NULL then it will cause panic once we access page->mapping The root cause is we missed to keep isolation of atomic write in the case of commit_atomic_write vs mkwrite, let commit_atomic_write helds i_mmap_sem lock to avoid this issue. Signed-off-by: Chao Yu --- fs/f2fs/file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 22a0101538c0..1ff5fc10e1fa 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2094,10 +2094,12 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) goto err_out; } + down_write(&F2FS_I(inode)->i_mmap_sem); + if (f2fs_is_atomic_file(inode)) { ret = f2fs_commit_inmem_pages(inode); if (ret) - goto err_out; + goto up_write; ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); if (!ret) @@ -2105,6 +2107,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) } else { ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); } +up_write: + up_write(&F2FS_I(inode)->i_mmap_sem); err_out: if (is_inode_flag_set(inode, FI_ATOMIC_REVOKE_REQUEST)) { clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); -- 2.29.2 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel