linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: WeiXiong Liao <liaoweixiong@allwinnertech.com>
Cc: Rob Herring <robh@kernel.org>, Tony Luck <tony.luck@intel.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Richard Weinberger <richard@nod.at>,
	Anton Vorontsov <anton@enomsg.org>,
	linux-doc@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, Colin Cross <ccross@android.com>,
	linux-mtd@lists.infradead.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v2 09/11] pstore/blk: blkoops: support special removing jobs for dmesg.
Date: Wed, 18 Mar 2020 11:47:20 -0700	[thread overview]
Message-ID: <202003181144.BD1DE93@keescook> (raw)
In-Reply-To: <1581078355-19647-10-git-send-email-liaoweixiong@allwinnertech.com>

On Fri, Feb 07, 2020 at 08:25:53PM +0800, WeiXiong Liao wrote:
> It's one of a series of patches for adaptive to MTD device.
> 
> MTD device is not block device. To write to flash device on MTD, erase
> must to be done before. However, pstore/blk just set datalen as 0 when
> remove, which is not enough for mtd device. That's why this patch here,
> to support special jobs when removing pstore/blk record.
> 
> Signed-off-by: WeiXiong Liao <liaoweixiong@allwinnertech.com>
> ---
>  Documentation/admin-guide/pstore-block.rst |  9 +++++++++
>  fs/pstore/blkoops.c                        |  4 +++-
>  fs/pstore/blkzone.c                        |  9 ++++++++-
>  include/linux/blkoops.h                    | 10 ++++++++++
>  include/linux/pstore_blk.h                 | 11 +++++++++++
>  5 files changed, 41 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/pstore-block.rst b/Documentation/admin-guide/pstore-block.rst
> index 299142b3d8e6..1735476621df 100644
> --- a/Documentation/admin-guide/pstore-block.rst
> +++ b/Documentation/admin-guide/pstore-block.rst
> @@ -200,6 +200,15 @@ negative number will be returned. The following return numbers mean more:
>  1. -EBUSY: pstore/blk should try again later.
>  #. -ENEXT: this zone is used or broken, pstore/blk should try next one.
>  
> +erase
> +~~~~~
> +
> +It's generic erase API for pstore/blk, which is requested by non-block device.
> +It will be called while pstore record is removing. It's required only when the
> +device has special removing jobs. For example, MTD device tries to erase block.
> +
> +Normally zero should be returned, otherwise it indicates an error.
> +
>  panic_write (for non-block device)
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  
> diff --git a/fs/pstore/blkoops.c b/fs/pstore/blkoops.c
> index 01170b344f00..7cf4731e52f7 100644
> --- a/fs/pstore/blkoops.c
> +++ b/fs/pstore/blkoops.c
> @@ -164,6 +164,7 @@ int blkoops_register_device(struct blkoops_device *bo_dev)
>  	bzinfo->dump_oops = dump_oops;
>  	bzinfo->read = bo_dev->read;
>  	bzinfo->write = bo_dev->write;
> +	bzinfo->erase = bo_dev->erase;
>  	bzinfo->panic_write = bo_dev->panic_write;
>  	bzinfo->name = "blkoops";
>  	bzinfo->owner = THIS_MODULE;
> @@ -383,10 +384,11 @@ int blkoops_register_blkdev(unsigned int major, unsigned int flags,
>  	bo_dev.total_size = blkoops_bdev_size(bdev);
>  	if (bo_dev.total_size == 0)
>  		goto err_put_bdev;
> -	bo_dev.panic_write = panic_write ? blkoops_blk_panic_write : NULL;
>  	bo_dev.flags = flags;
>  	bo_dev.read = blkoops_generic_blk_read;
>  	bo_dev.write = blkoops_generic_blk_write;
> +	bo_dev.erase = NULL;
> +	bo_dev.panic_write = panic_write ? blkoops_blk_panic_write : NULL;
>  
>  	ret = blkoops_register_device(&bo_dev);
>  	if (ret)

I think this patch, like the prior, needs to be reordered in the series.
How about adding

blkoops_register_device()

as a single patch, which is what provides support for the "non-block"
block devices? Then the blkoops_register_blkdev() can stand alone in the
first patch?

It just might be easier to review, since nothing uses
blkoops_register_device() until the mtd driver is added. So that
function and this patch would go together as a single "support non-block
devices" change.

> diff --git a/fs/pstore/blkzone.c b/fs/pstore/blkzone.c
> index 205aeff28992..a17fff77b875 100644
> --- a/fs/pstore/blkzone.c
> +++ b/fs/pstore/blkzone.c
> @@ -593,11 +593,18 @@ static inline bool blkz_ok(struct blkz_zone *zone)
>  static inline int blkz_dmesg_erase(struct blkz_context *cxt,
>  		struct blkz_zone *zone)
>  {
> +	size_t size;
> +
>  	if (unlikely(!blkz_ok(zone)))
>  		return 0;
>  
>  	atomic_set(&zone->buffer->datalen, 0);
> -	return blkz_zone_write(zone, FLUSH_META, NULL, 0, 0);
> +
> +	size = buffer_datalen(zone) + sizeof(*zone->buffer);
> +	if (cxt->bzinfo->erase)
> +		return cxt->bzinfo->erase(size, zone->off);
> +	else
> +		return blkz_zone_write(zone, FLUSH_META, NULL, 0, 0);
>  }
>  
>  static inline int blkz_record_erase(struct blkz_context *cxt,
> diff --git a/include/linux/blkoops.h b/include/linux/blkoops.h
> index bc7665d14a98..11cb3036ad5f 100644
> --- a/include/linux/blkoops.h
> +++ b/include/linux/blkoops.h
> @@ -33,6 +33,15 @@
>   *	number means more:
>   *	  -EBUSY: pstore/blk should try again later.
>   *	  -ENEXT: this zone is used or broken, pstore/blk should try next one.
> + * @erase:
> + *	The general (not panic) erase operation. It will be call while pstore
> + *	record is removing. It's required only when device have special
> + *	removing jobs, for example, MTD device try to erase block.
> + *
> + *	Both of the @size and @offset parameters on this interface are
> + *	the relative size of the space provided, not the whole disk/flash.
> + *
> + *	On success, 0 should be returned. Others mean error.
>   * @panic_write:
>   *	The write operation only used for panic.
>   *
> @@ -53,6 +62,7 @@ struct blkoops_device {
>  	unsigned long total_size;
>  	blkz_read_op read;
>  	blkz_write_op write;
> +	blkz_erase_op erase;
>  	blkz_write_op panic_write;
>  };
>  
> diff --git a/include/linux/pstore_blk.h b/include/linux/pstore_blk.h
> index bbbe4fe37f7c..9641969f888f 100644
> --- a/include/linux/pstore_blk.h
> +++ b/include/linux/pstore_blk.h
> @@ -46,6 +46,15 @@
>   *	number means more:
>   *	  -EBUSY: pstore/blk should try again later.
>   *	  -ENEXT: this zone is used or broken, pstore/blk should try next one.
> + * @erase:
> + *	The general (not panic) erase operation. It will be call while pstore
> + *	record is removing. It's required only when device have special
> + *	removing jobs, for example, MTD device try to erase block.
> + *
> + *	Both of the @size and @offset parameters on this interface are
> + *	the relative size of the space provided, not the whole disk/flash.
> + *
> + *	On success, 0 should be returned. Others mean error.
>   * @panic_write:
>   *	The write operation only used for panic. It's optional if you do not
>   *	care panic record. If panic occur but blkzone do not recover yet, the
> @@ -59,6 +68,7 @@
>   */
>  typedef ssize_t (*blkz_read_op)(char *, size_t, loff_t);
>  typedef ssize_t (*blkz_write_op)(const char *, size_t, loff_t);
> +typedef ssize_t (*blkz_erase_op)(size_t, loff_t);
>  struct blkz_info {
>  	struct module *owner;
>  	const char *name;
> @@ -71,6 +81,7 @@ struct blkz_info {
>  	int dump_oops;
>  	blkz_read_op read;
>  	blkz_write_op write;
> +	blkz_erase_op erase;
>  	blkz_write_op panic_write;
>  };
>  
> -- 
> 1.9.1
> 

-- 
Kees Cook

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2020-03-18 18:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07 12:25 [PATCH v2 00/11] pstore: mtd: support crash log to block and mtd device WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 01/11] pstore/blk: new support logger for block devices WeiXiong Liao
2020-02-26  0:52   ` Kees Cook
2020-02-27  8:21     ` liaoweixiong
2020-03-18 17:23       ` Kees Cook
2020-03-20  1:50         ` WeiXiong Liao
2020-03-20 18:20           ` Kees Cook
2020-03-22 10:28             ` WeiXiong Liao
2020-03-09  0:52     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 02/11] blkoops: add blkoops, a warpper for pstore/blk WeiXiong Liao
2020-03-18 18:06   ` Kees Cook
2020-03-22 10:00     ` WeiXiong Liao
2020-03-22 15:44       ` Kees Cook
2020-02-07 12:25 ` [PATCH v2 03/11] pstore/blk: blkoops: support pmsg recorder WeiXiong Liao
2020-03-18 18:13   ` Kees Cook
2020-03-22 11:14     ` WeiXiong Liao
2020-03-22 15:59       ` Kees Cook
2020-02-07 12:25 ` [PATCH v2 04/11] pstore/blk: blkoops: support console recorder WeiXiong Liao
2020-03-18 18:16   ` Kees Cook
2020-03-22 11:35     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 05/11] pstore/blk: blkoops: support ftrace recorder WeiXiong Liao
2020-03-18 18:19   ` Kees Cook
2020-03-22 11:42     ` WeiXiong Liao
2020-03-22 15:16       ` Kees Cook
2020-02-07 12:25 ` [PATCH v2 06/11] Documentation: pstore/blk: blkoops: create document for pstore_blk WeiXiong Liao
2020-03-18 18:31   ` Kees Cook
2020-03-22 12:20     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 07/11] pstore/blk: skip broken zone for mtd device WeiXiong Liao
2020-03-18 18:35   ` Kees Cook
2020-03-22 12:27     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 08/11] blkoops: respect for device to pick recorders WeiXiong Liao
2020-03-18 18:42   ` Kees Cook
2020-03-22 13:06     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 09/11] pstore/blk: blkoops: support special removing jobs for dmesg WeiXiong Liao
2020-03-18 18:47   ` Kees Cook [this message]
2020-03-22 13:03     ` WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 10/11] blkoops: add interface for dirver to get information of blkoops WeiXiong Liao
2020-02-07 12:25 ` [PATCH v2 11/11] mtd: new support oops logger based on pstore/blk WeiXiong Liao
2020-02-18 10:34   ` Miquel Raynal
2020-02-19  1:13     ` liaoweixiong
2020-03-18 18:57   ` Kees Cook
2020-03-22 13:51     ` WeiXiong Liao
2020-03-22 15:13       ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202003181144.BD1DE93@keescook \
    --to=keescook@chromium.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=liaoweixiong@allwinnertech.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mchehab+samsung@kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=robh@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).