linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "岩松信洋 / IWAMATSU,NOBUHIRO" <nobuhiro.iwamatsu.kw@hitachi.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Anton Vorontsov" <anton@enomsg.org>,
	"Colin Cross" <ccross@android.com>,
	"Tony Luck" <tony.luck@intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"Mark Salyzyn" <salyzyn@android.com>,
	"阿口誠司 / AGUCHI,SEIJI" <seiji.aguchi.tr@hitachi.com>
Subject: RE: [PATCH v2 3/5] pstore: support multiple pmsg instances
Date: Wed, 5 Oct 2016 04:09:44 +0000	[thread overview]
Message-ID: <F89ECF87BC754A49BB74E794F6A0EC2FF6825B@GSjpTKYDCembx31.service.hitachi.net> (raw)
In-Reply-To: <CAGXu5jL-_Oxp8Q4GfJszpt8hBOUANYVa9f4S-nhjVTzcOhVHQw@mail.gmail.com>

Hi,

> -----Original Message-----
> From: keescook@google.com [mailto:keescook@google.com] On Behalf Of Kees
> Cook
> Sent: Friday, September 09, 2016 6:34 AM
> To: 岩松信洋 / IWAMATSU,NOBUHIRO
> Cc: Anton Vorontsov; Colin Cross; Tony Luck; LKML; Hiraku Toyooka; Mark
> Salyzyn; 阿口誠司 / AGUCHI,SEIJI
> Subject: Re: [PATCH v2 3/5] pstore: support multiple pmsg instances
> 
> On Sun, Jul 24, 2016 at 8:56 PM, Nobuhiro Iwamatsu
> <nobuhiro.iwamatsu.kw@hitachi.com> wrote:
> > From: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
> >
> > This enables pmsg to deal with multiple instances. One possible use is
> > content priority control on limited persistent store space. By using
> > different buffers, we can prevent important messages from being
> > overwritten by less important messages.
> >
> > When pstore backend module specifies the number of instances
> > (num_pmsg) in pstore_info, multiple /dev/pmsg[ID] appear. (ID is an
> > integer starting at 0. It corresponds to minor number of the each char
> > device.) Writes to each /dev/pmsg[ID] are isolated each other. After
> > reboot, the contents are available in
> /sys/fs/pstore/pmsg-[backend]-[ID].
> >
> > Signed-off-by: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
> > Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
> > Cc: Mark Salyzyn <salyzyn@android.com>
> > Cc: Seiji Aguchi <seiji.aguchi.tr@hitachi.com>
> > ---
> >  fs/pstore/pmsg.c       | 20 ++++++++++++++++++--
> >  include/linux/pstore.h |  1 +
> >  2 files changed, 19 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c index
> > 7de20cd..2e281ed 100644
> > --- a/fs/pstore/pmsg.c
> > +++ b/fs/pstore/pmsg.c
> > @@ -52,8 +52,8 @@ static ssize_t write_pmsg(struct file *file, const char
> __user *buf,
> >                         vfree(buffer);
> >                         return -EFAULT;
> >                 }
> > -               psinfo->write_buf(PSTORE_TYPE_PMSG, 0, &id, 0, buffer,
> 0, c,
> > -                                 psinfo);
> > +               psinfo->write_buf(PSTORE_TYPE_PMSG, 0, &id,
> > +                                 iminor(file->f_inode), buffer, 0, c,
> > + psinfo);
> >
> >                 i += c;
> >         }
> > @@ -85,6 +85,7 @@ static char *pmsg_devnode(struct device *dev,
> > umode_t *mode)  void pstore_register_pmsg(void)  {
> >         struct device *pmsg_device;
> > +       int i = 0;
> >
> >         pmsg_major = register_chrdev(0, PMSG_NAME, &pmsg_fops);
> >         if (pmsg_major < 0) {
> > @@ -105,9 +106,24 @@ void pstore_register_pmsg(void)
> >                 pr_err("failed to create device\n");
> >                 goto err_device;
> >         }
> > +
> > +       /* allocate additional /dev/pmsg[ID] */
> > +       for (i = 1; i < psinfo->num_pmsg; i++) {
> > +               struct device *pmsg_device;
> > +
> > +               pmsg_device = device_create(pmsg_class, NULL,
> > +                                           MKDEV(pmsg_major, i), NULL,
> "%s%d",
> > +                                           PMSG_NAME, i);
> > +               if (IS_ERR(pmsg_device)) {
> > +                       pr_err("failed to create device\n");
> > +                       goto err_device;
> > +               }
> > +       }
> 
> This should just be merged into the first device_create call (i.e.
> drop the first one, keep your loop, but have "i" start at 0). There's no
> reason that I can see to do it separately.

Indeed, I will fix.
> 
> >         return;
> >
> >  err_device:
> > +       for (i--; i >= 0; i--)
> > +               device_destroy(pmsg_class, MKDEV(pmsg_major, i));
> 
> Was the device_destroy() for /dev/pmsg0 missing before? (i.e. does
> class_destroy() or unregister_chrdev() already clean up the devices?)

Your are right.
I will fix as /dev/pmsg0 also treated with device_destroy().

> 
> >         class_destroy(pmsg_class);
> >  err_class:
> >         unregister_chrdev(pmsg_major, PMSG_NAME); diff --git
> > a/include/linux/pstore.h b/include/linux/pstore.h index
> > 831479f..b0c24cc 100644
> > --- a/include/linux/pstore.h
> > +++ b/include/linux/pstore.h
> > @@ -54,6 +54,7 @@ struct pstore_info {
> >         size_t          bufsize;
> >         struct mutex    read_mutex;     /* serialize open/read/close
> */
> >         int             flags;
> > +       unsigned int    num_pmsg;
> >         int             (*open)(struct pstore_info *psi);
> >         int             (*close)(struct pstore_info *psi);
> >         ssize_t         (*read)(u64 *id, enum pstore_type_id *type,
> > --
> > 2.8.1
> >
> >
> 
> -Kees
> 
> 
> --
> Kees Cook
> Nexus Security

Best regards,
  Nobuhiro

  reply	other threads:[~2016-10-05  4:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25  3:56 [PATCH v2 0/5] pstore: ramoops: support multiple pmsg instances Nobuhiro Iwamatsu
2016-07-25  3:56 ` [PATCH v2 1/5] ramoops: use persistent_ram_free() instead of kfree() for freeing prz Nobuhiro Iwamatsu
2016-07-28 19:35   ` Kees Cook
2016-07-29  5:58     ` 岩松信洋 / IWAMATSU,NOBUHIRO
2016-08-03 19:04       ` Kees Cook
2016-07-25  3:56 ` [PATCH v2 2/5] ramoops: introduce generic init/free functions for prz Nobuhiro Iwamatsu
2016-09-08 21:22   ` Kees Cook
2016-10-05  4:06     ` 岩松信洋 / IWAMATSU,NOBUHIRO
2016-07-25  3:56 ` [PATCH v2 3/5] pstore: support multiple pmsg instances Nobuhiro Iwamatsu
2016-09-08 21:33   ` Kees Cook
2016-10-05  4:09     ` 岩松信洋 / IWAMATSU,NOBUHIRO [this message]
2016-07-25  3:56 ` [PATCH v2 4/5] ramoops: " Nobuhiro Iwamatsu
2016-09-08 21:53   ` Kees Cook
2016-10-05  4:13     ` 岩松信洋 / IWAMATSU,NOBUHIRO
2016-07-25  3:56 ` [PATCH v2 5/5] selftests/pstore: add testcases for " Nobuhiro Iwamatsu
2016-09-08 21:55   ` Kees Cook
2016-10-05  4:14     ` 岩松信洋 / IWAMATSU,NOBUHIRO

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=F89ECF87BC754A49BB74E794F6A0EC2FF6825B@GSjpTKYDCembx31.service.hitachi.net \
    --to=nobuhiro.iwamatsu.kw@hitachi.com \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=salyzyn@android.com \
    --cc=seiji.aguchi.tr@hitachi.com \
    --cc=tony.luck@intel.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).