Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5765594imm; Mon, 23 Jul 2018 05:49:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdeaTRsksTFwoaAJ9XzEDfeivSjJPMWm0UqrgukIgDUQOOp1fdhGvIyVvac14CUDrPyM8ov X-Received: by 2002:a63:f18:: with SMTP id e24-v6mr12262162pgl.320.1532350173120; Mon, 23 Jul 2018 05:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350173; cv=none; d=google.com; s=arc-20160816; b=fgPN6LvrZaaIa95uZnBpZQUuiIpQGFRHg4jpScrGXoetvNKIF/CjUnS5jpuAMWhHOv 3q0I4LJiAnQrn+L3PO0x3lFs7XVYPSxu+v1D+/EWfRTKM+ue+QqYILPT+rRNXtr/8fcb 7KE7/uD1S5PovCEXhedb5s2H6IDWcfwZUP3nsMwxq9BisHojg6/8in0Q/nsdXxT+YINb Nd9uUV663jCvX7TUlhRn5nE00qgCshetV/BmXk2U2Du2q7k0wbpR0+uzv+tc9OhvPI8I 8+8sNhSp3osPczysYNmHq9H1Lv4/iy6iIli6V5civ//JnKRRviVQdX2GPvmMl3WBgYqy xWeA== 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=RIs/969LFbgaTkvMVdrftlWbDK6n/mdtmeAqG7QojI8=; b=rfXYF1EEdOQHbtAb6YKMbGzRd696tpAcLzFOR4UvEGWUC9XwoQykCHeeFPiXJmnzLT hynYYUgqsZ73cXFZFYzZbQh0gClX3Bf9WOcFNt0sKlTs6dowxsE97S1/I0hNJ34ALL9j /ieiK5LKk4aXxxJxVE7tCet5rzwhcfKHtW5uL8DsMKiBMSSM/72rPvX4gbbE2WQGVZvR dAyQwCvs1J+rOm5/pDSYltVuR0FZlqnzwoufpJY9Sy2ejVE38grPiRLZKZFc1yZS+zME 7hqaevPHKYUHBDJ+K/FkYiJmkzbUgf5uV+lURrrnk53ZtumYitYN3BUdClyBrt6gHdUS ibvw== 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 z63-v6si8734415pfi.214.2018.07.23.05.49.18; Mon, 23 Jul 2018 05:49:33 -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 S2389907AbeGWNs4 (ORCPT + 99 others); Mon, 23 Jul 2018 09:48:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52062 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389885AbeGWNsz (ORCPT ); Mon, 23 Jul 2018 09:48:55 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0F0FCBDB; Mon, 23 Jul 2018 12:47:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger Subject: [PATCH 4.4 104/107] ubi: Be more paranoid while seaching for the most recent Fastmap Date: Mon, 23 Jul 2018 14:42:38 +0200 Message-Id: <20180723122418.722288656@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@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: Richard Weinberger commit 74f2c6e9a47cf4e508198c8594626cc82906a13d upstream. Since PEB erasure is asynchornous it can happen that there is more than one Fastmap on the MTD. This is fine because the attach logic will pick the Fastmap data structure with the highest sequence number. On a not so well configured MTD stack spurious ECC errors are common. Causes can be different, bad hardware, wrong operating modes, etc... If the most current Fastmap renders bad due to ECC errors UBI might pick an older Fastmap to attach from. While this can only happen on an anyway broken setup it will show completely different sympthoms and makes finding the root cause much more difficult. So, be debug friendly and fall back to scanning mode of we're facing an ECC error while scanning for Fastmap. Cc: Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/ubi/attach.c | 28 ++++++++++++++++++++++++---- drivers/mtd/ubi/ubi.h | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-) --- a/drivers/mtd/ubi/attach.c +++ b/drivers/mtd/ubi/attach.c @@ -856,13 +856,15 @@ static bool vol_ignored(int vol_id) * @ubi: UBI device description object * @ai: attaching information * @pnum: the physical eraseblock number + * @fast: true if we're scanning for a Fastmap * * This function reads UBI headers of PEB @pnum, checks them, and adds * information about this PEB to the corresponding list or RB-tree in the * "attaching info" structure. Returns zero if the physical eraseblock was * successfully handled and a negative error code in case of failure. */ -static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum) +static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, + int pnum, bool fast) { long long ec; int err, bitflips = 0, vol_id = -1, ec_err = 0; @@ -980,6 +982,20 @@ static int scan_peb(struct ubi_device *u */ ai->maybe_bad_peb_count += 1; case UBI_IO_BAD_HDR: + /* + * If we're facing a bad VID header we have to drop *all* + * Fastmap data structures we find. The most recent Fastmap + * could be bad and therefore there is a chance that we attach + * from an old one. On a fine MTD stack a PEB must not render + * bad all of a sudden, but the reality is different. + * So, let's be paranoid and help finding the root cause by + * falling back to scanning mode instead of attaching with a + * bad EBA table and cause data corruption which is hard to + * analyze. + */ + if (fast) + ai->force_full_scan = 1; + if (ec_err) /* * Both headers are corrupted. There is a possibility @@ -1293,7 +1309,7 @@ static int scan_all(struct ubi_device *u cond_resched(); dbg_gen("process PEB %d", pnum); - err = scan_peb(ubi, ai, pnum); + err = scan_peb(ubi, ai, pnum, false); if (err < 0) goto out_vidh; } @@ -1407,7 +1423,7 @@ static int scan_fast(struct ubi_device * cond_resched(); dbg_gen("process PEB %d", pnum); - err = scan_peb(ubi, scan_ai, pnum); + err = scan_peb(ubi, scan_ai, pnum, true); if (err < 0) goto out_vidh; } @@ -1415,7 +1431,11 @@ static int scan_fast(struct ubi_device * ubi_free_vid_hdr(ubi, vidh); kfree(ech); - err = ubi_scan_fastmap(ubi, *ai, scan_ai); + if (scan_ai->force_full_scan) + err = UBI_NO_FASTMAP; + else + err = ubi_scan_fastmap(ubi, *ai, scan_ai); + if (err) { /* * Didn't attach via fastmap, do a full scan but reuse what --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -711,6 +711,8 @@ struct ubi_ainf_volume { * @vols_found: number of volumes found * @highest_vol_id: highest volume ID * @is_empty: flag indicating whether the MTD device is empty or not + * @force_full_scan: flag indicating whether we need to do a full scan and drop + all existing Fastmap data structures * @min_ec: lowest erase counter value * @max_ec: highest erase counter value * @max_sqnum: highest sequence number value @@ -738,6 +740,7 @@ struct ubi_attach_info { int vols_found; int highest_vol_id; int is_empty; + int force_full_scan; int min_ec; int max_ec; unsigned long long max_sqnum;