linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: liaoweixiong <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 01/11] pstore/blk: new support logger for block devices
Date: Wed, 18 Mar 2020 10:23:55 -0700	[thread overview]
Message-ID: <202003180944.3B36871@keescook> (raw)
In-Reply-To: <5fd540be-6ed9-a1c7-4932-e67194dddca8@allwinnertech.com>

On Thu, Feb 27, 2020 at 04:21:51PM +0800, liaoweixiong wrote:
> On 2020/2/26 AM 8:52, Kees Cook wrote:
> > On Fri, Feb 07, 2020 at 08:25:45PM +0800, WeiXiong Liao wrote:
> >> +obj-$(CONFIG_PSTORE_BLK) += pstore_blk.o
> >> +pstore_blk-y += blkzone.o
> > 
> > Why this dance with files? I would just expect:
> > 
> > obj-$(CONFIG_PSTORE_BLK)     += blkzone.o
> > 
> 
> This makes the built module named blkzone.ko rather than
> pstore_blk.ko.

You can just do a regular build rule:

obj-$(CONFIG_PSTORE_BLK) += blkzone.o

> >> +#define BLK_SIG (0x43474244) /* DBGC */
> > 
> > I was going to suggest extracting PERSISTENT_RAM_SIG, renaming it and
> > using it in here and in ram_core.c, but then I realize they're not
> > marking the same structure. How about choosing a new magic sig for the
> > blkzone data header?
> > 
> 
> That's OK to me. I don't know if there is a rule to get a new magic?
> In addition, all members of this structure are the same as
> struct persistent_ram_buffer after patch 2. Maybe it's a good idea to
> extract it
> if you want to merge ramoops and pstore/blk.

Okay, let's leave it as-is for now.

> >> +	uint32_t sig;
> >> +	atomic_t datalen;
> >> +	uint8_t data[];
> >> +};
> >> +
> >> +/**
> >> + * struct blkz_dmesg_header: dmesg information
> > 
> > This is the on-disk structure also?
> > 
> Yes. The structure blkz_buffer is a generic header for all recorder
> zone, and the
> structure blkz_dmesg_header is a header for dmesg, saved in
> blkz_buffer->data.
> The dmesg recorder use it to save it's specific attributes.

Okay, can you add comments to distinguish the on-disk structures from
the in-memory, etc?

> >> +#define DMESG_HEADER_MAGIC 0x4dfc3ae5
> > 
> > How was this magic chosen?
> 
> It's a random number. Maybe should I chose a meaningful magic?

That's fine; just add a comment to say so.

> >> + * @dirty:
> >> + *	mark whether the data in @buffer are dirty (not flush to storage yet)
> >> + */
> > 
> > Thank you for the kerndoc! :) Is it linked to from any .rst files?
> > 
> 
> I don't get your words. There is a document on the 6th patch. I don't know
> whether it is what you want?

Patch 6 is excellent; I think you might want to add references back to
these kern-doc structures using the ".. kernel-doc::
fs/pstore/blkzone.c" syntax:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#including-kernel-doc-comments

> >> +static int blkz_zone_write(struct blkz_zone *zone,
> >> +		enum blkz_flush_mode flush_mode, const char *buf,
> >> +		size_t len, unsigned long off)
> >> +{
> >> +	struct blkz_info *info = blkz_cxt.bzinfo;
> >> +	ssize_t wcnt = 0;
> >> +	ssize_t (*writeop)(const char *buf, size_t bytes, loff_t pos);
> >> +	size_t wlen;
> >> +
> >> +	if (off > zone->buffer_size)
> >> +		return -EINVAL;
> >> +	wlen = min_t(size_t, len, zone->buffer_size - off);
> >> +	if (buf && wlen) {
> >> +		memcpy(zone->buffer->data + off, buf, wlen);
> >> +		atomic_set(&zone->buffer->datalen, wlen + off);
> >> +	}
> > 
> > If you're expecting concurrent writers (use of atomic_set(), I would
> > expect the whole write to be locked instead. (i.e. what happens if
> > multiple callers call blkz_zone_write()?)
> > 
> 
> I don't agree with it. The datalen will be updated everywhere. It's useless
> to lock here.

But there could be multiple writers; locking should be needed.

> One more things. During the analysis, I found another problem.
> Removing old files will cause new logs to be lost. Take console recorder as
> am example. After new rebooting, new logs are saved to buf while old
> logs are
> saved to old_buf. If we remove old file at that time, not only old_buf
> is freed, but
> also length of buf for new data is reset to zero. The ramoops may also
> has this
> problem.

Hmm. I'll need to double-check this. It's possible the call to
persistent_ram_zap() in ramoops_pstore_erase() is not needed.

> >> +static int blkz_recover_dmesg_data(struct blkz_context *cxt)
> > 
> > What does "recover" mean in this context? Is this "read from storage"?
> 
> Yes. "recover" means reading data back from storage.

Okay. Please add some comments here. I would think of it more as "read"
or "load". When I think of "recover" I think of "finding something that
was lost". But the name isn't important as long as there is a comment
somewhere about what it's doing.

-Kees

-- 
Kees Cook

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

  reply	other threads:[~2020-03-18 17:24 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 [this message]
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
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=202003180944.3B36871@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).