All of lore.kernel.org
 help / color / mirror / Atom feed
* virtio-rng only returns zeros with CONFIG_HW_RANDOM=m
@ 2013-02-24 23:11 Aurelien Jarno
  2013-02-27  0:13 ` Rusty Russell
  2013-02-27  1:26 ` Rusty Russell
  0 siblings, 2 replies; 12+ messages in thread
From: Aurelien Jarno @ 2013-02-24 23:11 UTC (permalink / raw)
  To: kvm; +Cc: Ian Molton, Matt Mackall, Rusty Russell, Herbert Xu

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-05-30  7:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-24 23:11 virtio-rng only returns zeros with CONFIG_HW_RANDOM=m Aurelien Jarno
2013-02-27  0:13 ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.