public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: kvm@vger.kernel.org
Cc: Ian Molton <ian.molton@collabora.co.uk>,
	Matt Mackall <mpm@selenic.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
Date: Mon, 25 Feb 2013 00:11:54 +0100	[thread overview]
Message-ID: <20130224231154.GA30477@hall.aurel32.net> (raw)

Hi,

I have noticed that virtio-rng only returns zero for kernels >= 2.6.33
built with CONFIG_HW_RANDOM=m. This is a bit much too predictable for a
random generator ;-).

The reason for that is virtio expects guest real addresses, while
rng_core.ko (ie when built as a module) is passing a vmalloced buffer 
to the virtio-rng read function, declared as such:

  static u8 rng_buffer[SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES]
          __cacheline_aligned;

This is basically the same issue than the following one:

  https://lists.linux-foundation.org/pipermail/virtualization/2008-May/010946.html

but introduced in a more subtle way in this commit:

  commit bb347d98079a547e80bd4722dee1de61e4dca0e8
  Author: Ian Molton <ian.molton@collabora.co.uk>
  Date:   Tue Dec 1 15:26:33 2009 +0800

      hwrng: virtio-rng - Convert to new API
    
      This patch converts virtio-rng to the new hw_rng API.
    
      In the process it fixes a previously untriggered buffering bug where the
      buffer is not drained correctly if it has a non-multiple-of-4 length.
    
      Performance has improved under qemu-kvm testing also.
    
      Signed-off-by: Ian Molton <ian.molton@collabora.co.uk>
      Acked-by: Matt Mackall <mpm@selenic.com>
      Acked-by: Rusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>


I basically see three possible way of fixing that:
- prevent rng_core to be built as a module;
- use an intermediary kmalloced buffer in virtio-rng passed to virtio
  functions, followed by a memcpy to get the data in the rng core
  buffer;
- use a kmalloc buffer in rng_core instead of vmalloc one.

What would be best way to fix that? Did I miss another way?

Thanks,
Aurelien

-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

             reply	other threads:[~2013-02-24 23:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-24 23:11 Aurelien Jarno [this message]
2013-02-27  0:13 ` virtio-rng only returns zeros with CONFIG_HW_RANDOM=m Rusty Russell
2013-02-27  3:40   ` Ben Hutchings
2013-02-27 10:33   ` Aurelien Jarno
2013-02-27 13:22   ` Jens Axboe
2013-02-28  3:00     ` Rusty Russell
2013-05-30  1:07     ` Rusty Russell
2013-05-30  7:18       ` Jens Axboe
2013-02-27  1:26 ` Rusty Russell
2013-02-27 16:36   ` Aurelien Jarno
2013-02-28  3:04     ` Rusty Russell
2013-03-10  8:26   ` 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=20130224231154.GA30477@hall.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=ian.molton@collabora.co.uk \
    --cc=kvm@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=rusty@rustcorp.com.au \
    /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