Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5068840ybl; Wed, 22 Jan 2020 09:42:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwCaUX1EpxqvgFGyXPAgNbgw8EA6sHtm1ogAdi2u28WAmK0V3cO287wBDBwg9IV341Btm7w X-Received: by 2002:a9d:760e:: with SMTP id k14mr4726321otl.344.1579714960569; Wed, 22 Jan 2020 09:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579714960; cv=none; d=google.com; s=arc-20160816; b=Hi9LBWADG7i0+vOONVbnFhEPPPgVn5GUiNluC64gZjZH+0oiykFPE6l8Gc59oCyIGC EYUyTbybU0pxo6BHc9A4I4qzvV/lAsC0o4jkLxAXvjNFp5Sx6DSkDpX9fmfKLmvpRzPx MDp4pR3a9KNqyjCVQG8vvQHQrSIF1vMZhP1gYSj7AiP+IZlDxAzGAnYM5DJIYwOv1xZu 3wHmEQ93Rt1poXpCwYb3w8ZL43qS0IFscHQiVEwrpCVZTZAldXzh9T2W/T6bg1eRj54u NZwVTBAClU8l3Tct42j411ZSR//0QfOgoF9b2bBuJEShqd8YXf0WlFCn0Pn70WDsmVFY fCGg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JoP4L186ufdbUKO4jMB8QJ7IqyTuSyzPoH3/22yKzT4=; b=p2+mUJF5gXFYBdXoJFA+y2u7rFYkO5yQcWtTSq4NKY38CruER8ydEkZkB886Oe5IyS yIWZVRKL6GaB9ctXsiSnyomxNFvQTrrrZlQstZ03AOR88/fvmQVWexYH3irVgzRKSGpo L2UlsuRQ8bN3V0GJ8GnaPus6Cr/ApMZCLDmQR6jUVRPre1H5PP/cc604+LfYSJQdhtUo cfcTcwGzwcpVTpcXLiGtLfceUumhPxpIT0FEYWBV81tGnpDv9Qw1KAlDljwU3ruysxSb 9W7AxoEw7KLmPEPEI6vvFIGzv+YT+jcT1VlBzZxvO5KZf8TeZZHHODqHUIC9coBXusGl baOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V8Ya36BD; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si24659900otn.281.2020.01.22.09.42.28; Wed, 22 Jan 2020 09:42:40 -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=@kernel.org header.s=default header.b=V8Ya36BD; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728799AbgAVRl2 (ORCPT + 99 others); Wed, 22 Jan 2020 12:41:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:41948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgAVRl2 (ORCPT ); Wed, 22 Jan 2020 12:41:28 -0500 Received: from xps13 (98.197.23.93.rev.sfr.net [93.23.197.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7289F24125; Wed, 22 Jan 2020 17:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579714887; bh=YGZ2cRqG5u4bxPklZHpHWDQi8QEwqwd/Zc28kRnomzE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=V8Ya36BDaBIBQBr6PhRda8ehKTO24jQw4a2r6ushXaJ8q2k3IY2Ebytd6NzFYjUTQ 0zLl/q7dHK1rIepkQM2BYPSSmvKSiQXevCDQmKnsyYsJmF26mtKwIA21USoS+pDf6T +1Rs5gVzvPKqm+G2MG6hUO5lqY4UtMFX3HWoUekI= Date: Wed, 22 Jan 2020 18:41:14 +0100 From: Miquel Raynal To: liaoweixiong Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Richard Weinberger , Vignesh Raghavendra , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Greg Kroah-Hartman , Jonathan Cameron , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: Re: [PATCH v1 11/11] mtd: new support oops logger based on pstore/blk Message-ID: <20200122184114.125b42c8@xps13> In-Reply-To: <2c6000b1-ae25-564b-911a-2879e9c244b2@allwinnertech.com> References: <1579482233-2672-1-git-send-email-liaoweixiong@allwinnertech.com> <1579482233-2672-12-git-send-email-liaoweixiong@allwinnertech.com> <20200120110306.32e53fd8@xps13> <27226590-379c-8784-f461-f5d701015611@allwinnertech.com> <20200121094802.61f8cb4d@xps13> <2c6000b1-ae25-564b-911a-2879e9c244b2@allwinnertech.com> 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=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, > >>>> +/* > >>>> + * All zones will be read as pstore/blk will read zone one by one w= hen do > >>>> + * recover. > >>>> + */ > >>>> +static ssize_t mtdpstore_read(char *buf, size_t size, loff_t off) > >>>> +{ > >>>> + struct mtdpstore_context *cxt =3D &oops_cxt; > >>>> + size_t retlen; > >>>> + int ret; > >>>> + > >>>> + if (mtdpstore_block_isbad(cxt, off)) > >>>> + return -ENEXT; > >>>> + > >>>> + pr_debug("try to read off 0x%llx size %zu\n", off, size); > >>>> + ret =3D mtd_read(cxt->mtd, off, size, &retlen, (u_char *)buf); > >>>> + if ((ret < 0 && !mtd_is_bitflip(ret)) || size !=3D retlen) { =20 > >>> > >>> IIRC size !=3D retlen does not mean it failed, but that you should > >>> continue reading after retlen bytes, no? =20 > >>> >> =20 > >> Yes, you are right. I will fix it. Thanks. > >> =20 > >>> Also, mtd_is_bitflip() does not mean that you are reading a false > >>> buffer, but that the data has been corrected as it contained bitflips. > >>> mtd_is_eccerr() however, would be meaningful. =20 > >>> >> =20 > >> Sure I know mtd_is_bitflip() does not mean failure, but I do not think > >> mtd_is_eccerr() should be here since the codes are ret < 0 and NOT > >> mtd_is_bitflip(). =20 > >=20 > > Yes, just drop this check, only keep ret < 0. > > =20 >=20 > If I don't get it wrong, it should not be dropped here. Like your words, > "mtd_is_bitflip() does not mean that you are reading a false buffer, > but that the data has been corrected as it contained bitflips.", the > data I get are valid even if mtd_is_bitflip() return true. It's correct > data and it's no need to go to handle error. To me, the codes > should be: > if (ret < 0 && !mit_is_bitflip()) > [error handling] Please check the implementation of mtd_is_bitflip(). You'll probably figure out what I am saying. https://elixir.bootlin.com/linux/latest/source/include/linux/mtd/mtd.h#L585 |...] > >>>> + return; > >>>> + } > >>>> + if (unlikely(info->dmesg_size % mtd->writesize)) { > >>>> + pr_err("record size %lu KB must align to write size %d KB\n", > >>>> + info->dmesg_size / 1024, > >>>> + mtd->writesize / 1024); =20 > >>> > >>> This condition is weird, why would you check this? =20 > >>> >> =20 > >> pstore/blk will write 'record_size' dmesg log at one time. > >> Since each write data must be aligned to 'writesize' for flash, I am n= ot > >> sure > >> all flash drivers are compatible with misaligned data, that's why i > >> check this. =20 > >=20 > > I think you should enforce this alignment instead of checking it. > > =20 >=20 > Do you mean that mtdpstore should enforce this alignment while running? > The way I can think of is to handle a buffer aligned to writesize and > write to flash with this aligned buffer. >=20 > That causes some error. The MTD device will be divided into mutil > chunks accroding to dmesg_size. Each chunk stores a individual > OOPS/Panic log. If dmesg_size is misaligned to writesize, the last > write results in next write failure because the page of flash can only > be programed once before next erase and the page shared by two chunks > has been used by the last write. Besides, we can not read to buffer, > ersae and write back as there is no read/erase for panic case. I mean: what is the usual size of dmesg? I don't get why you need it to be ie. a multiple of 2k. It probably is actually, I don't know if there is a standard. But if dmesg_size is eg 3k, just skip the end of the partially written page and start writing at the next page? >=20 > >> =20 > >>>> + return; > >>>> + } > >>>> + if (unlikely(mtd->size > MTDPSTORE_MAX_MTD_SIZE)) { > >>>> + pr_err("mtd%d is too large (limit is %d MiB)\n", > >>>> + mtd->index, > >>>> + MTDPSTORE_MAX_MTD_SIZE / 1024 / 1024); =20 > >>> > >>> Same question? I could understand that it is easier to manage blocks > >>> knowing their maximum number though. =20 > >>> >> =20 > >> It refers to mtdoops. =20 > >=20 > > What do you mean? > > =20 >=20 > To me, it's unnecessary to check at all, however it is really there > on codes of mtdoops. I refer to module mtdoops when I design mtdpstore. > It may be helpfull for some cases out of my think, that's why I keep it. Why not. [...] > >> > >> In case of repeated erase when users remove several log files, mtdpsto= re > >> do remove jobs when exit. > >> > >> Besides, mtdpstore do not check the return code to ensure write back v= alid > >> log as much as possible. =20 > >=20 > > You are not in a critical path, I don't understand why you don't check > > it? If it returns an error, it means the data is not written. IMHO it > > is best to alert the user than to silently fail. > > =20 >=20 > This function will be called only when mtd device is removing. It's > useless to alert the user but try to flush the other valid data to It is useful to alert the user! It means something went wrong while everything seems fine. > flash as mush as possible by which reduce losses. If it's just > because of busy, what happens next time? Just because of busy? I don't get it. I'm okay with the idea of trying to write the other chunks though: while (remaining_chunk) { ret =3D mtd_write() if (ret) { alert-user; continue; } } >=20 > >> =20 > >>>> +. >>>> + off +=3D zonesize; > >>>> + size -=3D min_t(unsigned int, zonesize, size); > >>>> + } > >>>> + > >>>> +free: > >>>> + kfree(buf); > >>>> + return ret; > >>>> +} > >>>> + =20 > >=20 > >=20 > > [...] > > =20 > >>> > >>> Thanks, > >>> Miqu=C3=A8l =20 > >>> >> =20 > >> I will collect more suggestions and submit the new version at one time. > >> =20 > >=20 > > Sure, no hurry. > > =20 >=20 > I am on holiday, please forgive me for my slow response. Take your time, as I said, no hurry. >=20 > >=20 > > Thanks, > > Miqu=C3=A8l > > =20 Thanks, Miqu=C3=A8l