Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3078277imm; Sun, 1 Jul 2018 11:45:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeDbLZ8ollQnQJFKgfYUohMYYK6ll0o/aU6KHe9/x4khI71Z3D85m0qMGYE4rT8ynJ2kZpe X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr10367867pla.52.1530470740390; Sun, 01 Jul 2018 11:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530470740; cv=none; d=google.com; s=arc-20160816; b=i4PqlwgsWigqiuWHre52qIr+O/GyLCqx3U7liQjnpHFYLwRATWtR3EiVg/dUTR4qME E0/lSwHa32R5BewXJzG1KN/MDu4eVHmK9vLbDNDrRMt8NjiiQMdn+zMM1fHt96eULdoX Rk6yaNsQyLmvNnywNF3UasJ7Pkd0cvRZxWXKFZC9PKeeUrfuPMatRet31hZQYtkqBT+4 XvQP8InZ7wfr3thvgptQGRlTl2+O5zvyrsRlVBWicocv1mEP7cHZTGnBQbJzQ8FBDx9y BPniJZ3le0Lf2IDJGOmMF3rL6o81Wq8C2to+9cdY1QecSLKeROkGfxCsp+VIvotDo7Ly 4jNA== 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=HvNJS/vF3SjNgIOPX6+g9C8SYrt81Ixnke5377myne8=; b=qgTzjg76uvwPBMewhdiqbV4wEF12K2yyj+7OfAZnZYOkQKe9lpkTXj4o3uIhy4wm/7 MvaEXT6hgEvCTYiWSDbALfjOfm+J86610fxZy1yogMLXJjcyTCnUBVfNPgcunVMu/NaB rN+gSjhEUjbjza9Z3rV9b+4YM+mmI0bEHYWAU9ZtwMR7w9mw1YgjITdqf9LzBjpyZ/fB sk1Mt2Eq6hU5a+OcztZh6KLNxWVuRwU8c+8ssHxozzDEQ7B+ZyzF2unij7+em1tQhDa5 G9UG9j1+bZkzfPd12H/eGLvPcQcve7BbjBB/Rgww3GRIFu5eFFo8o2GWzeiV1FC03sXX dfWA== 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 u2-v6si12369913pgv.335.2018.07.01.11.45.26; Sun, 01 Jul 2018 11:45:40 -0700 (PDT) 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 S932219AbeGAQMx (ORCPT + 99 others); Sun, 1 Jul 2018 12:12:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59972 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932092AbeGAQMh (ORCPT ); Sun, 1 Jul 2018 12:12:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8CE42ACD; Sun, 1 Jul 2018 16:12:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Harvey , Qu Wenruo , David Sterba Subject: [PATCH 3.18 40/85] btrfs: scrub: Dont use inode pages for device replace Date: Sun, 1 Jul 2018 18:01:58 +0200 Message-Id: <20180701153123.955693585@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153122.365061142@linuxfoundation.org> References: <20180701153122.365061142@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo commit ac0b4145d662a3b9e34085dea460fb06ede9b69b upstream. [BUG] Btrfs can create compressed extent without checksum (even though it shouldn't), and if we then try to replace device containing such extent, the result device will contain all the uncompressed data instead of the compressed one. Test case already submitted to fstests: https://patchwork.kernel.org/patch/10442353/ [CAUSE] When handling compressed extent without checksum, device replace will goe into copy_nocow_pages() function. In that function, btrfs will get all inodes referring to this data extents and then use find_or_create_page() to get pages direct from that inode. The problem here is, pages directly from inode are always uncompressed. And for compressed data extent, they mismatch with on-disk data. Thus this leads to corrupted compressed data extent written to replace device. [FIX] In this attempt, we could just remove the "optimization" branch, and let unified scrub_pages() to handle it. Although scrub_pages() won't bother reusing page cache, it will be a little slower, but it does the correct csum checking and won't cause such data corruption caused by "optimization". Note about the fix: this is the minimal fix that can be backported to older stable trees without conflicts. The whole callchain from copy_nocow_pages() can be deleted, and will be in followup patches. Fixes: ff023aac3119 ("Btrfs: add code to scrub to copy read data to another disk") CC: stable@vger.kernel.org # 4.4+ Reported-by: James Harvey Reviewed-by: James Harvey Signed-off-by: Qu Wenruo [ remove code removal, add note why ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/scrub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2207,7 +2207,7 @@ static int scrub_extent(struct scrub_ctx have_csum = scrub_find_csum(sctx, logical, l, csum); if (have_csum == 0) ++sctx->stat.no_csum; - if (sctx->is_dev_replace && !have_csum) { + if (0 && sctx->is_dev_replace && !have_csum) { ret = copy_nocow_pages(sctx, logical, l, mirror_num, physical_for_dev_replace);