Received: by 10.223.176.5 with SMTP id f5csp1030457wra; Fri, 2 Feb 2018 10:00:34 -0800 (PST) X-Google-Smtp-Source: AH8x22753A+It9f2//RyVaJnea3E8LIb4598E8Dnhi+/RL2F6ax3F1NWs7wwp28wSeP5p5XA1Crv X-Received: by 10.99.120.134 with SMTP id t128mr16573388pgc.313.1517594434430; Fri, 02 Feb 2018 10:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517594434; cv=none; d=google.com; s=arc-20160816; b=Taxjajia1+KvWMnjHIVkN13k9remqrDx++cxdZuBAE05G3zNGBfbM+rJoYzf6G0Ps6 hmXNrLsd+T1V/XARC07aunBb2Z1VdzNJ+Kwjdphlrj5BKRAZYS8j9FkONeZvMJF3xF8q Skz2RWmAUYmBygQ8nC87E2x6tGr9Kg2bjMCd1az6SaDvS6V6GXR3lUySaEARqA5lggVV vNLlaWw+RepJZJkxVVcAwOH9tfV2vvKhEqeSTx5YZD5BDL2MIz0M6cnxNOgWtC9TkBdg p3811aFYsI7bkEJxKFBNHQuXk5BgBgDJhXJ5594Es5nB44IdQ63V+p7uLyC/axOfW0Rk WqGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kt5p7F6XjwxenMB2sGuif7BSQScpS0vAtVbBtlSXkeA=; b=HE/htFGYcadt4N766VVmjz8LJXMtFGC4mCWq0beHei0UOr9fyLraWmeZHgfu+0bDDb EMfSgEKl1aMseY8s2YP5SNL/n+tmpOLWetvZiyHSkLMeXgJQ87UxuHZyYISUDM2Oy1xT Xk4NO4flljZBCxEoy5FBG0jDGJWlv4efqVuPS5xOFJ4GlRbvf5PRBpNMFVapI42Sxkgc VEK8Nc9BcTHKKHdew67XlqnlgDqwv6vKQUvilrhPwLgCQisGymtKNm/rP04FVViJYMF4 4U5KGO6IFLkFAoLLADqG9LmB6uVP8sjTyZBbLDvJP1CJApF8cj+Sls2431gMpxjansTu 1O4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si2179157pfl.198.2018.02.02.10.00.19; Fri, 02 Feb 2018 10:00:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753351AbeBBR7V (ORCPT + 99 others); Fri, 2 Feb 2018 12:59:21 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38328 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbeBBRKa (ORCPT ); Fri, 2 Feb 2018 12:10:30 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A1BDAEFA; Fri, 2 Feb 2018 17:10:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , David Sterba , Sasha Levin Subject: [PATCH 4.14 078/156] Btrfs: fix list_add corruption and soft lockups in fsync Date: Fri, 2 Feb 2018 17:57:39 +0100 Message-Id: <20180202140843.808678497@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo [ Upstream commit ebb70442cdd4872260c2415929c456be3562da82 ] Xfstests btrfs/146 revealed this corruption, [ 58.138831] Buffer I/O error on dev dm-0, logical block 2621424, async page read [ 58.151233] BTRFS error (device sdf): bdev /dev/mapper/error-test errs: wr 1, rd 0, flush 0, corrupt 0, gen 0 [ 58.152403] list_add corruption. prev->next should be next (ffff88005e6775d8), but was ffffc9000189be88. (prev=ffffc9000189be88). [ 58.153518] ------------[ cut here ]------------ [ 58.153892] WARNING: CPU: 1 PID: 1287 at lib/list_debug.c:31 __list_add_valid+0x169/0x1f0 ... [ 58.157379] RIP: 0010:__list_add_valid+0x169/0x1f0 ... [ 58.161956] Call Trace: [ 58.162264] btrfs_log_inode_parent+0x5bd/0xfb0 [btrfs] [ 58.163583] btrfs_log_dentry_safe+0x60/0x80 [btrfs] [ 58.164003] btrfs_sync_file+0x4c2/0x6f0 [btrfs] [ 58.164393] vfs_fsync_range+0x5f/0xd0 [ 58.164898] do_fsync+0x5a/0x90 [ 58.165170] SyS_fsync+0x10/0x20 [ 58.165395] entry_SYSCALL_64_fastpath+0x1f/0xbe ... It turns out that we could record btrfs_log_ctx:io_err in log_one_extents when IO fails, but make log_one_extents() return '0' instead of -EIO, so the IO error is not acknowledged by the callers, i.e. btrfs_log_inode_parent(), which would remove btrfs_log_ctx:list from list head 'root->log_ctxs'. Since btrfs_log_ctx is allocated from stack memory, it'd get freed with a object alive on the list. then a future list_add will throw the above warning. This returns the correct error in the above case. Jeff also reported this while testing against his fsync error patch set[1]. [1]: https://www.spinics.net/lists/linux-btrfs/msg65308.html "btrfs list corruption and soft lockups while testing writeback error handling" Fixes: 8407f553268a4611f254 ("Btrfs: fix data corruption after fast fsync and writeback error") Signed-off-by: Liu Bo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/file.c | 5 +++-- fs/btrfs/tree-log.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2056,6 +2056,8 @@ int btrfs_sync_file(struct file *file, l len = (u64)end - (u64)start + 1; trace_btrfs_sync_file(file, datasync); + btrfs_init_log_ctx(&ctx, inode); + /* * We write the dirty pages in the range and wait until they complete * out of the ->i_mutex. If so, we can flush the dirty pages by @@ -2202,8 +2204,6 @@ int btrfs_sync_file(struct file *file, l } trans->sync = true; - btrfs_init_log_ctx(&ctx, inode); - ret = btrfs_log_dentry_safe(trans, root, dentry, start, end, &ctx); if (ret < 0) { /* Fallthrough and commit/free transaction. */ @@ -2261,6 +2261,7 @@ int btrfs_sync_file(struct file *file, l ret = btrfs_end_transaction(trans); } out: + ASSERT(list_empty(&ctx.list)); err = file_check_and_advance_wb_err(file); if (!ret) ret = err; --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4100,7 +4100,7 @@ static int log_one_extent(struct btrfs_t if (ordered_io_err) { ctx->io_err = -EIO; - return 0; + return ctx->io_err; } btrfs_init_map_token(&token);