Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3072877imm; Sun, 1 Jul 2018 11:36:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL2QI5D35CrtOJCHClrEnlQWyUaK3FmDLCsJPqqzIGU484Y8gbWvkjjCMTFY7PLMGQGYdrj X-Received: by 2002:a63:89c7:: with SMTP id v190-v6mr18822839pgd.194.1530470211852; Sun, 01 Jul 2018 11:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530470211; cv=none; d=google.com; s=arc-20160816; b=LafSfywWvUVA9KgfYVMjQVAolIOpM2CocOogymXUVHpnqY4sVyJSH3WpCMdC5FwiFw lr0iP6UiOA6W0zGLuhY4shIvCq0qPGhS6qBhIGv1GJUdeX+SnZP6ciO8QGCWvSzZsYEI 3cNSli28RL2usZpS66zCnLt8+7nnHvg4bKscPJ0OG8JxfkcqEQgrR26i8/Oke6w/U3BO J7u4ruXfVKDUnq+h1NcngH3/RGC4DpeOcZMkXLhpspytmahbHldRgOv25iu1T2Mv788V cqKXjF5uImIba4zsYGTS7EH14oodHCxjL5zKuSE5y4gpwY6OzWFjOQ0dYUKaa5Q24A6Z tjDA== 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=W2VD1pTgx1Ibtz6uJcOmgecrr6COc5WmBdaDUU6CVvA=; b=LFJmtXNojyibJZGC1rdiDTo/UgL7jglz3uAK4h6ZhLP71qvdxNZjwmtp5Xkduymx/K ygb0k0GARPeUMXo0TlX4oV6aAWO+WWjmqK+guGldfGA11XEvJ7scaG8+dvt3Zbr4V/Iy h1zLI9oax3NJpBsDSCAuYm9KODfMut+mTLHIRdf6pPr1VWZyCCCRp2YD4IzllZNCzli3 wZ9iyc8ZRZwNlhOs9hgGKme0nBJpg93jDdfd0lQHBimhzRTpXf0b2L+Rk09ueSMJjql5 Z+jEsK9E6SUlZ/majEk3yAz6iAVIkbq6CoTW4Ikqwilg7NtNpsZsDesT5Jb6ZWldSpWV rOCw== 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 a20-v6si393051pgb.600.2018.07.01.11.36.37; Sun, 01 Jul 2018 11:36:51 -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 S933065AbeGAQPh (ORCPT + 99 others); Sun, 1 Jul 2018 12:15:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60584 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932440AbeGAQPa (ORCPT ); Sun, 1 Jul 2018 12:15:30 -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 269B086D; Sun, 1 Jul 2018 16:15:30 +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 4.4 016/105] btrfs: scrub: Dont use inode pages for device replace Date: Sun, 1 Jul 2018 18:01:26 +0200 Message-Id: <20180701153150.595826825@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@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 4.4-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 @@ -2513,7 +2513,7 @@ static int scrub_extent(struct scrub_ctx have_csum = scrub_find_csum(sctx, logical, 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);