From: Pankaj Gupta <pagupta@redhat.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Amos Kong <akong@redhat.com>,
linux-crypto@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Herbert Xu <herbert@gondor.apana.org.au>,
Rusty Russell <rusty@rustcorp.com.au>,
kvm@vger.kernel.org, Michael Buesch <m@bues.ch>,
Matt Mackall <mpm@selenic.com>, amit shah <amit.shah@redhat.com>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 REPOST 1/6] hw_random: place mutex around read functions and buffers.
Date: Tue, 26 Sep 2017 02:36:57 -0400 (EDT) [thread overview]
Message-ID: <369186187.14365871.1506407817157.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <CAKdAkRSF1qJv_03PJh44gkQ7NOJ3ccW2EwPckGvch=iUYY1-Qw@mail.gmail.com>
>
> A bit late to a party, but:
>
> On Mon, Dec 8, 2014 at 12:50 AM, Amos Kong <akong@redhat.com> wrote:
> > From: Rusty Russell <rusty@rustcorp.com.au>
> >
> > There's currently a big lock around everything, and it means that we
> > can't query sysfs (eg /sys/devices/virtual/misc/hw_random/rng_current)
> > while the rng is reading. This is a real problem when the rng is slow,
> > or blocked (eg. virtio_rng with qemu's default /dev/random backend)
> >
> > This doesn't help (it leaves the current lock untouched), just adds a
> > lock to protect the read function and the static buffers, in preparation
> > for transition.
> >
> > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> > ---
> ...
> >
> > @@ -160,13 +166,14 @@ static ssize_t rng_dev_read(struct file *filp, char
> > __user *buf,
> > goto out_unlock;
> > }
> >
> > + mutex_lock(&reading_mutex);
>
> I think this breaks O_NONBLOCK: we have hwrng core thread that is
> constantly pumps underlying rng for data; the thread takes the mutex
> and calls rng_get_data() that blocks until RNG responds. This means
> that even user specified O_NONBLOCK here we'll be waiting until
> [hwrng] thread releases reading_mutex before we can continue.
I think for 'virtio_rng' for 'O_NON_BLOCK' 'rng_get_data' returns
without waiting for data which can let mutex to be used by other
threads waiting if any?
rng_dev_read
rng_get_data
virtio_read
static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait)
{
int ret;
struct virtrng_info *vi = (struct virtrng_info *)rng->priv;
if (vi->hwrng_removed)
return -ENODEV;
if (!vi->busy) {
vi->busy = true;
init_completion(&vi->have_data);
register_buffer(vi, buf, size);
}
if (!wait)
return 0;
ret = wait_for_completion_killable(&vi->have_data);
if (ret < 0)
return ret;
vi->busy = false;
return vi->data_avail;
}
>
> > if (!data_avail) {
> > bytes_read = rng_get_data(current_rng, rng_buffer,
> > rng_buffer_size(),
> > !(filp->f_flags & O_NONBLOCK));
> > if (bytes_read < 0) {
> > err = bytes_read;
> > - goto out_unlock;
> > + goto out_unlock_reading;
> > }
> > data_avail = bytes_read;
> > }
>
> Thanks.
>
> --
> Dmitry
>
next prev parent reply other threads:[~2017-09-26 6:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-08 8:50 [PATCH v5 REPOST 0/6] fix hw_random stuck Amos Kong
2014-12-08 8:50 ` [PATCH v5 REPOST 1/6] hw_random: place mutex around read functions and buffers Amos Kong
2017-09-25 22:00 ` Dmitry Torokhov
2017-09-26 6:36 ` Pankaj Gupta [this message]
2017-09-26 16:52 ` Dmitry Torokhov
2017-09-27 6:35 ` Pankaj Gupta
2014-12-08 8:50 ` [PATCH v5 REPOST 2/6] hw_random: move some code out mutex_lock for avoiding underlying deadlock Amos Kong
2014-12-08 8:50 ` [PATCH v5 REPOST 3/6] hw_random: use reference counts on each struct hwrng Amos Kong
2014-12-08 8:50 ` [PATCH v5 REPOST 4/6] hw_random: fix unregister race Amos Kong
2014-12-08 8:50 ` [PATCH v5 REPOST 5/6] hw_random: don't double-check old_rng Amos Kong
2014-12-08 8:50 ` [PATCH v5 REPOST 6/6] hw_random: don't init list element we're about to add to list Amos Kong
2014-12-22 12:05 ` [PATCH v5 REPOST 0/6] fix hw_random stuck Herbert Xu
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=369186187.14365871.1506407817157.JavaMail.zimbra@redhat.com \
--to=pagupta@redhat.com \
--cc=akong@redhat.com \
--cc=amit.shah@redhat.com \
--cc=dmitry.torokhov@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=kvm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m@bues.ch \
--cc=mpm@selenic.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.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