Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp7078534pxu; Fri, 25 Dec 2020 00:55:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+1zable8YIqE24QrjaEjrlIMBkX2A1DOARcPW6RyXiGXsvgCDvsMm1oWDIJhYnQ1+7qGL X-Received: by 2002:a17:906:5f97:: with SMTP id a23mr31877228eju.128.1608886538734; Fri, 25 Dec 2020 00:55:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608886538; cv=none; d=google.com; s=arc-20160816; b=z5HbURYauCJODgxT7J87ya0jille/J6XyJ6e3WNcJhc07RkQRGNdayQMnzWJ7/2Ws4 JSwMDp90R83vL8V8YtSRl+p9YUbcX1N1RwR2d+1OWKzIDBRMxs4O5ex1d/5XQHpKbdbx 0I9FoK556E8ODLiTJbGUqv6/h48COvzZWqWtXRrNiY9GoopcSkOZDn75JTmP425nowEj JrCYZcbKYAhTvstJbBD5k4QBMD/qPwyVrt3Rd8jBm/NzL//8dBebFGp6HV2VYkOedOEF UXT9HiqVIAA1NtcrahtZgk0RtLOTi/TS43ViAgptdcjwRh5oZ4LGisTjstz3gVKJeU+2 +hbw== 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; bh=z1wfGqZN4/m99P16jjXHJ9H8Kr2y5CXSGn89lR43sPU=; b=0V53FnOSJZ2ThaBsupWqUhd6emy2SZI1S/iDJedsWNBZmO0GkOOLLsGyEGFpbemEPM nFjD6yvOW/PiED4gHKEWayY00AQz9PLj2wfE77r4AjVh3uZA4V4w853UiI99pI9vlzBA aH+4QsgybrWacGFzIgG+ryHYfCbeFnKtceDpiI4yvL2E54W2fL7iUak6Jjx5AU1Fgcsk 1+lK1ihKCSg/g4+j63frp4Ekf+tZ+U2qb4T96KpHGf9hrz1WziCNDW95OgUKCfUdqM0+ yqP8y24HqdHzUXqiNMA3ClHAykAQda5cStAt2Sl9VYqRKDG5KdROEGf8n7r+wHsNArQY 4PHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gw23si14981968ejb.235.2020.12.25.00.55.16; Fri, 25 Dec 2020 00:55:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729025AbgLYIyC (ORCPT + 99 others); Fri, 25 Dec 2020 03:54:02 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9993 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725863AbgLYIyB (ORCPT ); Fri, 25 Dec 2020 03:54:01 -0500 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: CC: , , , Chao Yu Subject: [PATCH] f2fs: fix to keep isolation of atomic write 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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