Received: by 10.223.176.46 with SMTP id f43csp280763wra; Tue, 23 Jan 2018 20:58:42 -0800 (PST) X-Google-Smtp-Source: AH8x227eU62hewZMoSiMGrqOUr5oCNhRNplW/zVyEujQ7qnM0hKVX33BccPgQhjSpChe/VB9Q9oU X-Received: by 2002:a17:902:481:: with SMTP id e1-v6mr5069091ple.228.1516769922100; Tue, 23 Jan 2018 20:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769922; cv=none; d=google.com; s=arc-20160816; b=tyELhdnGpVL/baIUc7nl2qxho1elrYSsUp/wu6VxmnGkA59/bOenvGR6Ruusa6esB+ SNCzTfFVJmKpVVIEjMYKiFd6U198zT25PFonQWGRk28ru5aqS57ZIUaeLXtjB0a+0Cw+ AA/aRa56x6evvTsG9VZCKnRRAKXjRU7gaDJxLTt0AxDbJ4U9UfoPB8MSWyKrGjuGMxNH U3pjjblMEzIuID1Fdw0Ma2hjICj3y04gLQsQAG8/vi3bv56WYuCUEDDEXuGvsDX7mu2D Gm89CGGlQlX3si88jZvD+EHNwIOOUsNo7vIEuqiEMeM7rhFoTKlk/YOQiUsswsSNYmld /VeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=CAfQrmXUp3ZUTTvtJdCXwpisrLAks25b1Suez4N+6AQ=; b=dBNJJMXEgkCD8RQVBI8jjm5pJUW7aXdFwZA/pnUYUQhZ4JBpiTNvErSG50+/XkvbEH HMx1CWCx3s0d2Gof4RgC0za1QwKwh8du7/nIDdDjrvQz46R5ugcSGaAZrf+JwhLv5fs+ dJIu+4ksELSbkfnwg5wdd+QLy7pg0CuoQxybCxpdeleJoY7e6kV3k7gSfLgU9fidaBtI P45m8vhWAklwIEVl9xlTy+RELbpgzxS+Eota4714YfVcseMB3tARGC0G+pcsC0+VFxDj rlNOCeTSD98u8EYKMZU0bE+HdO6QKsJxwkOcBl0ppa/NfJ4jBdLcEIOYh3/d06lgFYkn Pnjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=APCmWNVj; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q127si8376254pga.660.2018.01.23.20.58.28; Tue, 23 Jan 2018 20:58:42 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=APCmWNVj; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932613AbeAXE4p (ORCPT + 99 others); Tue, 23 Jan 2018 23:56:45 -0500 Received: from mail-dm3nam03on0107.outbound.protection.outlook.com ([104.47.41.107]:39081 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932158AbeAXEPT (ORCPT ); Tue, 23 Jan 2018 23:15:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CAfQrmXUp3ZUTTvtJdCXwpisrLAks25b1Suez4N+6AQ=; b=APCmWNVjsTTj4y4iG+NaE52tobp1J5XDnAXuu8bf3NF8W3Vfc2aZisGiO0iM+2sRTCyphcQBl46ZCRXedRVbZFtCLecXYkLDDeyn8Z9EgbdEcyZHIk8sx+kOwRgPE3XSXcAuALcUe4C3e9mRe3U/0fdnV5xMOWyWEqgE3G6dKOc= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.0; Wed, 24 Jan 2018 04:15:17 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:17 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Liu Bo , David Sterba , "Sasha Levin" Subject: [PATCH AUTOSEL for 4.14 049/100] Btrfs: fix list_add corruption and soft lockups in fsync Thread-Topic: [PATCH AUTOSEL for 4.14 049/100] Btrfs: fix list_add corruption and soft lockups in fsync Thread-Index: AQHTlMnfYcHhYNGFrEqrSNgMeJhSOA== Date: Wed, 24 Jan 2018 04:14:49 +0000 Message-ID: <20180124041414.32065-49-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:EwDPNemFrqE0t2m0UwzjHQ8abPwUBNNcoD8U51W2LRzqcOLEETvBIcMSVmolTiOmbNPSHbO+8V1ZegFL605u6hdUENsegBov8elslGJu9hlm+Bzwq5TjC1N23oyk9JzxQEGLPCGnG/ZSjl44De9L9Ujp2zK0KGK5zQiutI6b+vttNHkWmvPQ0qT9JF7h+teXH53OoDNonhOmmK5NKQWx+mWNf9HfaLoJEQmhPssoPr7+gaPDo/cQfhFI0vNXSsti x-ms-office365-filtering-correlation-id: 083d9f0a-949e-4cb3-9b02-08d562e11341 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(376002)(366004)(39860400002)(346002)(199004)(189003)(478600001)(6666003)(106356001)(6512007)(53936002)(2900100001)(36756003)(102836004)(2950100002)(6306002)(2501003)(10290500003)(97736004)(14454004)(81166006)(72206003)(8936002)(6486002)(1076002)(551934003)(10090500001)(6346003)(26005)(54906003)(4326008)(76176011)(99286004)(86362001)(3660700001)(105586002)(6116002)(8676002)(68736007)(22452003)(966005)(66066001)(25786009)(6506007)(5660300001)(305945005)(59450400001)(7736002)(3280700002)(5250100002)(2906002)(107886003)(86612001)(6436002)(316002)(81156014)(3846002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: ZucynMLDmgZkPeggk08RWZXhtqPBlDkbHiT69/Ttg/KgjN3wrN4jXgSQGXnBxksQMkqOCDnAtF8s5X5V4jFwow== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 083d9f0a-949e-4cb3-9b02-08d562e11341 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:49.0653 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 p= age 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 (ffff88005e67= 75d8), but was ffffc9000189be88. (prev=3Dffffc9000189be88). [ 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 handl= ing" Fixes: 8407f553268a4611f254 ("Btrfs: fix data corruption after fast fsync a= nd writeback error") Signed-off-by: Liu Bo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file.c | 5 +++-- fs/btrfs/tree-log.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index aafcc785f840..d564a7049d7f 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2056,6 +2056,8 @@ int btrfs_sync_file(struct file *file, loff_t start, = loff_t end, int datasync) len =3D (u64)end - (u64)start + 1; trace_btrfs_sync_file(file, datasync); =20 + 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, loff_t start, = loff_t end, int datasync) } trans->sync =3D true; =20 - btrfs_init_log_ctx(&ctx, inode); - ret =3D 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, loff_t start, = loff_t end, int datasync) ret =3D btrfs_end_transaction(trans); } out: + ASSERT(list_empty(&ctx.list)); err =3D file_check_and_advance_wb_err(file); if (!ret) ret =3D err; diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index c800d067fcbf..d3002842d7f6 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4100,7 +4100,7 @@ static int log_one_extent(struct btrfs_trans_handle *= trans, =20 if (ordered_io_err) { ctx->io_err =3D -EIO; - return 0; + return ctx->io_err; } =20 btrfs_init_map_token(&token); --=20 2.11.0