Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2473616ybb; Mon, 30 Mar 2020 06:54:31 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtxIA+1qs9pnhmBONKgSONPnW20v7isIWO2RF8rSxjQnYNrguzXdf1DzhaIyeWCnQ2aRDK4 X-Received: by 2002:a4a:370f:: with SMTP id r15mr9693852oor.100.1585576471674; Mon, 30 Mar 2020 06:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585576471; cv=none; d=google.com; s=arc-20160816; b=j77KemkSuNWrCKsRPVzpxnaDpiWCTKF24yoA+soiJ6pwkbDm4SqkjHywegm8tInMwh zaMEaSQ44M3yS1HAfeETLUPtGckQxwhiozVKJV37x8txSt1e1njg5oaC2lsi6Y/JsykC ssxu0sA8Uf/PTUJCEpu5sncQsZi+9BEd5GFThFgDRqmFE6wFrhYhr1g1LV6VUp8x72UH omBI19BQZXm6nFOwAUfwuCZvraBt/oME87j0vWz4eY0kpxfYeK3ultk4sbXnhtgLf0JP ltiyHetbJSpjsoJIbVYEUWkO1FugeHXJWSGiMcRDvb7UV3SMA7K8Y5jJaCtiiP8XtZH1 Wi0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=GYj1OyWGsS/xQzwCPtFYDPawrO0M9XlCjaL+GytpMGQ=; b=Qf6LYTuBRaiFgjw4dK5waVHHAh2IORIfPPcVRAdOI9IIvR89HMMzwVX8svXsLOcuib 0vxDvNC7RdL5dW7u77S/is8uN8xAMKiqjQHzSZjn67dHEtiwnpQf7ENPbafuEVId/4i8 11q8Pf/Qzznk9YD4dqObYfIUiCCixvlg6KiqyNi13KKEErpsj0wXPCawm9PfPEEomtnd OG6CzzOf/X0Yn3MC4of7oD1qh3hVXF3hnH9R0lZ966culTC9lW0Gr4wlWXrgp9gXDzL9 WD9EmDzAGyU905Si0RAN0fovcTQYd41LF3+fAL3ChiDlisNUaQ3HES1SgXic78m/sS51 J/JA== 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 d21si6260895oof.2.2020.03.30.06.54.18; Mon, 30 Mar 2020 06:54:31 -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 S1728345AbgC3Nw2 (ORCPT + 99 others); Mon, 30 Mar 2020 09:52:28 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:32973 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgC3Nw2 (ORCPT ); Mon, 30 Mar 2020 09:52:28 -0400 X-Originating-IP: 91.224.148.103 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id C14F520009; Mon, 30 Mar 2020 13:52:24 +0000 (UTC) Date: Mon, 30 Mar 2020 15:52:22 +0200 From: Miquel Raynal To: Xiaoming Ni Cc: , , , , , , , , , Subject: Re: [PATCH v3] mtd:fix cache_state to avoid writing to bad blocks repeatedly Message-ID: <20200330155222.20359293@xps13> In-Reply-To: <1585575925-84017-1-git-send-email-nixiaoming@huawei.com> References: <1585575925-84017-1-git-send-email-nixiaoming@huawei.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xiaoming, Xiaoming Ni wrote on Mon, 30 Mar 2020 21:45:25 +0800: > The function call process is as follows: > mtd_blktrans_work() > while (1) > do_blktrans_request() > mtdblock_writesect() > do_cached_write() > write_cached_data() /*if cache_state is STATE_DIRTY*/ > erase_write() > > write_cached_data() returns failure without modifying cache_state > and cache_offset. So when do_cached_write() is called again, > write_cached_data() will be called again to perform erase_write() > on the same cache_offset. > > But if this cache_offset points to a bad block, erase_write() will > always return -EIO. Writing to this mtdblk is equivalent to losing > the current data, and repeatedly writing to the bad block. > > Repeatedly writing a bad block has no real benefits, > but brings some negative effects: > 1 Lost subsequent data > 2 Loss of flash device life > 3 erase_write() bad blocks are very time-consuming. For example: > the function do_erase_oneblock() in chips/cfi_cmdset_0020.c or > chips/cfi_cmdset_0002.c may take more than 20 seconds to return > > Therefore, when erase_write() returns -EIO in write_cached_data(), > clear cache_state to avoid writing to bad blocks repeatedly. > > Signed-off-by: Xiaoming Ni > Reviewed-by: Miquel Raynal > Cc: stable@vger.kernel.org Still missing: * Fixes: tag * Wrong title prefix