From: Havard Skinnemoen <hskinnemoen@google.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
qemu-arm <qemu-arm@nongnu.org>,
"IS20 Avi Fishman" <Avi.Fishman@nuvoton.com>,
"CS20 KFTing" <kfting@nuvoton.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [PATCH 4/6] hw/misc: Add npcm7xx random number generator
Date: Tue, 20 Oct 2020 16:40:09 -0700 [thread overview]
Message-ID: <CAFQmdRbTxH_NPnnekFC_6uw1KLkf5uNvwL32hezTTo129Xs=RA@mail.gmail.com> (raw)
In-Reply-To: <CAFEAcA_-sWHjQ4ct66h=9ZMRqwnuFT+LWPFYLHGuuur2-+C9yg@mail.gmail.com>
On Tue, Oct 20, 2020 at 6:02 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Fri, 9 Oct 2020 at 00:22, Havard Skinnemoen <hskinnemoen@google.com> wrote:
> >
> > The RNG module returns a byte of randomness when the Data Valid bit is
> > set.
> >
> > This implementation ignores the prescaler setting, and loads a new value
> > into RNGD every time RNGCS is read while the RNG is enabled and random
> > data is available.
> >
> > A qtest featuring some simple randomness tests is included.
> >
> > Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
> > Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
>
>
> > +static const VMStateDescription vmstate_npcm7xx_rng = {
> > + .name = "npcm7xx-rng",
> > + .version_id = 0,
> > + .minimum_version_id = 0,
> > + .fields = (VMStateField[]) {
> > + VMSTATE_UINT8(rngcs, NPCM7xxRNGState),
> > + VMSTATE_UINT8(rngd, NPCM7xxRNGState),
> > + VMSTATE_UINT8(rngmode, NPCM7xxRNGState),
> > + },
>
> This is missing the VMSTATE_END_OF_LIST() terminator.
>
> > +};
> > +
>
> > --- /dev/null
> > +++ b/tests/qtest/npcm7xx_rng-test.c
> > @@ -0,0 +1,278 @@
> > +/*
> > + * QTest testcase for the Nuvoton NPCM7xx Random Number Generator
> > + *
> > + * Copyright 2020 Google LLC
> > + *
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms of the GNU General Public License as published by the
> > + * Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
> > + * for more details.
> > + */
> > +
> > +#include <math.h>
> > +
> > +#include "qemu/osdep.h"
>
> osdep.h must always be the first #include line, before anything
> else, including system includes.
>
> > + * Verifies that the first data byte collected after enabling the RNG satisfies
> > + * a monobit test.
>
> Some of this "is this really a random number" testing seems a bit
> overkill given that the RNG device is just plumbing through the
> qemu_guest_getrandom() result, but since you've written the code
> we may as well keep it :-)
You may be right, though there were a couple of reasons why I added it.
One is that rngd was complaining about /dev/hwrng failing randomness
tests, so I wanted to make sure my device wasn't doing anything to
ruin the randomness. In the end, it turned out to be a kernel bug:
https://lkml.org/lkml/2020/9/23/1021
Another reason is that the value from qemu_guest_getrandom() isn't
consumed directly when reading the data register; it's latched when
reading the status register and returned on the next read from the
data register. So it's possible to imagine a bug causing the same
value to be returned over and over, which should cause the randomness
test to fail.
> If you fix the #include order and the missing terminator then
Will do, thanks!
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>
> thanks
> -- PMM
next prev parent reply other threads:[~2020-10-20 23:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-08 23:21 [PATCH 0/6] Additional NPCM7xx features, devices and tests Havard Skinnemoen via
2020-10-08 23:21 ` [PATCH 1/6] tests/qtest: Add npcm7xx timer test Havard Skinnemoen via
2020-10-08 23:21 ` [PATCH 2/6] Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause Havard Skinnemoen via
2020-10-19 16:00 ` Philippe Mathieu-Daudé
2020-10-08 23:21 ` [PATCH 3/6] hw/timer: Adding watchdog for NPCM7XX Timer Havard Skinnemoen via
2020-10-20 12:55 ` Peter Maydell
2020-10-08 23:21 ` [PATCH 4/6] hw/misc: Add npcm7xx random number generator Havard Skinnemoen via
2020-10-20 13:02 ` Peter Maydell
2020-10-20 23:40 ` Havard Skinnemoen [this message]
2020-10-08 23:21 ` [PATCH 5/6] hw/arm/npcm7xx: Add EHCI and OHCI controllers Havard Skinnemoen via
2020-10-13 7:05 ` Gerd Hoffmann
2020-10-08 23:21 ` [PATCH 6/6] hw/gpio: Add GPIO model for Nuvoton NPCM7xx Havard Skinnemoen via
2020-10-20 13:07 ` Peter Maydell
2020-10-20 13:12 ` [PATCH 0/6] Additional NPCM7xx features, devices and tests Peter Maydell
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='CAFQmdRbTxH_NPnnekFC_6uw1KLkf5uNvwL32hezTTo129Xs=RA@mail.gmail.com' \
--to=hskinnemoen@google.com \
--cc=Avi.Fishman@nuvoton.com \
--cc=clg@kaod.org \
--cc=f4bug@amsat.org \
--cc=kfting@nuvoton.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).