All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly
@ 2018-10-26 13:59 Hongxu Jia
  2018-10-29 15:07 ` richard.purdie
  2018-10-30  2:00 ` [PATCH] " Hongxu Jia
  0 siblings, 2 replies; 7+ messages in thread
From: Hongxu Jia @ 2018-10-26 13:59 UTC (permalink / raw)
  To: openembedded-core, richard.purdie

Just adding `-device virtio-rng-pci' to the QEMU invocation will
add the device with a default host backend. As of QEMU 1.3+,
the default backend is to use the host's /dev/random as a
source of entropy. [1]

When the entropy pool is empty, reads from /dev/random will
block until additional environmental noise is gathered. [2]

For Yocto, if call runqemu frequently, it will consume lots
of host's /dev/random, and kernel finish crng init in guest get
more and more slowly.

Here are 4 times runqemu boot test:

[    3.464432] random: crng init done
[   20.874030] random: crng init done
[   23.583589] random: crng init done
[   23.858945] random: crng init done

Modify entropy source to /dev/urandom device on the host which
returns random bytes using a pseudorandom number generator seeded
from the entropy pool. Reads from this device do not block and
kernel finish crng init in guest will not delay.

Of course, the side effect is obviously, we lost the quality of
randomness, but the modification is only on runqemu script
rather than real embedded device, and it benefits oeqa efficiency
in which many cases call runqemu especially multiple oeqa builds
on one host.

After apply the fix:

[    3.364670] random: crng init done
[    4.619061] random: crng init done
[    3.403897] random: crng init done
[    3.450717] random: crng init done

[1] https://wiki.qemu.org/Features/VirtIORNG
[2] http://man7.org/linux/man-pages/man4/random.4.html

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
 meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
 meta/conf/machine/qemuarm.conf              | 3 ++-
 meta/conf/machine/qemuarm64.conf            | 4 +++-
 meta/conf/machine/qemuppc.conf              | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/meta/conf/machine/include/qemuboot-mips.inc b/meta/conf/machine/include/qemuboot-mips.inc
index 7d9fa52..75bb988 100644
--- a/meta/conf/machine/include/qemuboot-mips.inc
+++ b/meta/conf/machine/include/qemuboot-mips.inc
@@ -3,6 +3,7 @@ IMAGE_CLASSES += "qemuboot"
 QB_MEM = "-m 256"
 QB_MACHINE = "-machine malta"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
+QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
diff --git a/meta/conf/machine/include/qemuboot-x86.inc b/meta/conf/machine/include/qemuboot-x86.inc
index 1456bf7..ae6c2de 100644
--- a/meta/conf/machine/include/qemuboot-x86.inc
+++ b/meta/conf/machine/include/qemuboot-x86.inc
@@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
 QB_AUDIO_DRV = "alsa"
 QB_AUDIO_OPT = "-soundhw ac97,es1370"
 QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
+QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 
 UVESA_MODE ?= "640x480-32"
diff --git a/meta/conf/machine/qemuarm.conf b/meta/conf/machine/qemuarm.conf
index d2f2c85..a544312 100644
--- a/meta/conf/machine/qemuarm.conf
+++ b/meta/conf/machine/qemuarm.conf
@@ -14,7 +14,8 @@ SERIAL_CONSOLES ?= "115200;ttyAMA0 115200;ttyAMA1"
 QB_SYSTEM_NAME = "qemu-system-arm"
 QB_MACHINE = "-machine versatilepb"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,115200 console=tty"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 PREFERRED_VERSION_linux-yocto ??= "4.18%"
 QB_DTB = "${@oe.utils.version_less_or_equal('PREFERRED_VERSION_linux-yocto', '4.7', '', 'zImage-versatile-pb.dtb', d)}"
diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
index 242889a..34fcd2a 100644
--- a/meta/conf/machine/qemuarm64.conf
+++ b/meta/conf/machine/qemuarm64.conf
@@ -16,7 +16,9 @@ QB_MACHINE = "-machine virt"
 QB_CPU = "-cpu cortex-a57"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,38400"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -device virtio-rng-pci -monitor null"
+QB_OPT_APPEND = "-show-cursor -monitor null"
+# Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
 QB_NETWORK_DEVICE = "-device virtio-net-device,netdev=net0,mac=@MAC@"
 QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
diff --git a/meta/conf/machine/qemuppc.conf b/meta/conf/machine/qemuppc.conf
index 537b2f6..743d261 100644
--- a/meta/conf/machine/qemuppc.conf
+++ b/meta/conf/machine/qemuppc.conf
@@ -16,6 +16,7 @@ QB_SYSTEM_NAME = "qemu-system-ppc"
 QB_MACHINE = "-machine mac99"
 QB_CPU = "-cpu G4"
 QB_KERNEL_CMDLINE_APPEND = "console=tty console=ttyS0"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
-- 
2.8.1



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

* Re: [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-10-26 13:59 [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly Hongxu Jia
@ 2018-10-29 15:07 ` richard.purdie
  2018-10-30  2:22   ` [PATCH V2] " Hongxu Jia
  2018-10-30  2:00 ` [PATCH] " Hongxu Jia
  1 sibling, 1 reply; 7+ messages in thread
From: richard.purdie @ 2018-10-29 15:07 UTC (permalink / raw)
  To: Hongxu Jia, openembedded-core

On Fri, 2018-10-26 at 09:59 -0400, Hongxu Jia wrote:
> Just adding `-device virtio-rng-pci' to the QEMU invocation will
> add the device with a default host backend. As of QEMU 1.3+,
> the default backend is to use the host's /dev/random as a
> source of entropy. [1]
> 
> When the entropy pool is empty, reads from /dev/random will
> block until additional environmental noise is gathered. [2]
> 
> For Yocto, if call runqemu frequently, it will consume lots
> of host's /dev/random, and kernel finish crng init in guest get
> more and more slowly.
> 
> Here are 4 times runqemu boot test:
> 
> [    3.464432] random: crng init done
> [   20.874030] random: crng init done
> [   23.583589] random: crng init done
> [   23.858945] random: crng init done
> 
> Modify entropy source to /dev/urandom device on the host which
> returns random bytes using a pseudorandom number generator seeded
> from the entropy pool. Reads from this device do not block and
> kernel finish crng init in guest will not delay.
> 
> Of course, the side effect is obviously, we lost the quality of
> randomness, but the modification is only on runqemu script
> rather than real embedded device, and it benefits oeqa efficiency
> in which many cases call runqemu especially multiple oeqa builds
> on one host.
> 
> After apply the fix:
> 
> [    3.364670] random: crng init done
> [    4.619061] random: crng init done
> [    3.403897] random: crng init done
> [    3.450717] random: crng init done
> 
> [1] https://wiki.qemu.org/Features/VirtIORNG
> [2] http://man7.org/linux/man-pages/man4/random.4.html
> 
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
>  meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
>  meta/conf/machine/qemuarm.conf              | 3 ++-
>  meta/conf/machine/qemuarm64.conf            | 4 +++-
>  meta/conf/machine/qemuppc.conf              | 3 ++-
>  5 files changed, 11 insertions(+), 5 deletions(-)

Doesn't work unfortunately, e.g.:

https://autobuilder.yoctoproject.org/typhoon/#/builders/21/builds/155/steps/7/logs/step1c


Cheers,

Richard





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

* Re: [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-10-26 13:59 [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly Hongxu Jia
  2018-10-29 15:07 ` richard.purdie
@ 2018-10-30  2:00 ` Hongxu Jia
  1 sibling, 0 replies; 7+ messages in thread
From: Hongxu Jia @ 2018-10-30  2:00 UTC (permalink / raw)
  To: openembedded-core, richard.purdie

On 2018/10/26 下午9:59, Hongxu Jia wrote:
> --- a/meta/conf/machine/include/qemuboot-x86.inc
> +++ b/meta/conf/machine/include/qemuboot-x86.inc
> @@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
>   QB_AUDIO_DRV = "alsa"
>   QB_AUDIO_OPT = "-soundhw ac97,es1370"
>   QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
> +QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device"

Hi RP,

Sorry there is an extra `-device' should be remove which caused the 
issue you mentioned.

[snip]

runqemu - INFO - Running 
/home/pokybuild/yocto-worker/nightly-deb-non-deb/build/build/tmp/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/qemu-system-i386 
-device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:04 -netdev 
tap,id=net0,ifname=tap1,script=no,downscript=no -drive 
file=/home/pokybuild/yocto-worker/nightly-deb-non-deb/build/build/tmp/deploy/images/qemux86/core-image-sato-qemux86.ext4,if=virtio,format=raw 
-vga vmware -show-cursor -usb -device usb-tablet -device -object 
rng-random,filename=/dev/urandom,id=rng0 -device 
virtio-rng-pci,rng=rng0  -serial tcp:127.0.0.1:56531 -pidfile 
pidfile_43632  -cpu pentium2 -enable-kvm -m 256 -serial 
tcp:127.0.0.1:46573 -snapshot -kernel 
/home/pokybuild/yocto-worker/nightly-deb-non-deb/build/build/tmp/deploy/images/qemux86/bzImage--4.18.14+git0+bf98e195a4_33859b3077-r0.2-qemux86-20181019214032.bin 
-append 'root=/dev/vda rw highres=off  clocksource=kvm-clock 
hpet=disable noapic nolapic mem=256M 
ip=192.168.7.4::192.168.7.3:255.255.255.0 vga=0 
uvesafb.mode_option=640x480-32 oprofile.timer=1 uvesafb.task_timeout=-1 
console=tty1 console=ttyS0,115200n8 printk.time=1'

runqemu - ERROR - Failed to run qemu: qemu-system-i386: -device -object: 
Could not open 'rng-random,filename=/dev/urandom,id=rng0': No such file 
or directory

[snip]

After I do a runqemu build on qemux86/qemux86-64, then V2 incoming

//Hongxu

>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   




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

* [PATCH V2] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-10-29 15:07 ` richard.purdie
@ 2018-10-30  2:22   ` Hongxu Jia
  2018-10-30  6:59     ` Hongxu Jia
  2018-11-07  1:45     ` Hongxu Jia
  0 siblings, 2 replies; 7+ messages in thread
From: Hongxu Jia @ 2018-10-30  2:22 UTC (permalink / raw)
  To: openembedded-core, richard.purdie

Just adding `-device virtio-rng-pci' to the QEMU invocation will
add the device with a default host backend. As of QEMU 1.3+,
the default backend is to use the host's /dev/random as a
source of entropy. [1]

When the entropy pool is empty, reads from /dev/random will
block until additional environmental noise is gathered. [2]

For Yocto, if call runqemu frequently, it will consume lots
of host's /dev/random, and kernel finish crng init in guest get
more and more slowly.

Here are 4 times runqemu boot test:

[    3.464432] random: crng init done
[   20.874030] random: crng init done
[   23.583589] random: crng init done
[   23.858945] random: crng init done

Modify entropy source to /dev/urandom device on the host which
returns random bytes using a pseudorandom number generator seeded
from the entropy pool. Reads from this device do not block and
kernel finish crng init in guest will not delay.

Of course, the side effect is obviously, we lost the quality of
randomness, but the modification is only on runqemu script
rather than real embedded device, and it benefits oeqa efficiency
in which many cases call runqemu especially multiple oeqa builds
on one host.

After apply the fix:

[    3.364670] random: crng init done
[    4.619061] random: crng init done
[    3.403897] random: crng init done
[    3.450717] random: crng init done

[1] https://wiki.qemu.org/Features/VirtIORNG
[2] http://man7.org/linux/man-pages/man4/random.4.html

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
 meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
 meta/conf/machine/qemuarm.conf              | 3 ++-
 meta/conf/machine/qemuarm64.conf            | 4 +++-
 meta/conf/machine/qemuppc.conf              | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/meta/conf/machine/include/qemuboot-mips.inc b/meta/conf/machine/include/qemuboot-mips.inc
index 7d9fa52..75bb988 100644
--- a/meta/conf/machine/include/qemuboot-mips.inc
+++ b/meta/conf/machine/include/qemuboot-mips.inc
@@ -3,6 +3,7 @@ IMAGE_CLASSES += "qemuboot"
 QB_MEM = "-m 256"
 QB_MACHINE = "-machine malta"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
+QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
diff --git a/meta/conf/machine/include/qemuboot-x86.inc b/meta/conf/machine/include/qemuboot-x86.inc
index 1456bf7..5fdbe4d 100644
--- a/meta/conf/machine/include/qemuboot-x86.inc
+++ b/meta/conf/machine/include/qemuboot-x86.inc
@@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
 QB_AUDIO_DRV = "alsa"
 QB_AUDIO_OPT = "-soundhw ac97,es1370"
 QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
+QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 
 UVESA_MODE ?= "640x480-32"
diff --git a/meta/conf/machine/qemuarm.conf b/meta/conf/machine/qemuarm.conf
index d2f2c85..a544312 100644
--- a/meta/conf/machine/qemuarm.conf
+++ b/meta/conf/machine/qemuarm.conf
@@ -14,7 +14,8 @@ SERIAL_CONSOLES ?= "115200;ttyAMA0 115200;ttyAMA1"
 QB_SYSTEM_NAME = "qemu-system-arm"
 QB_MACHINE = "-machine versatilepb"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,115200 console=tty"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 PREFERRED_VERSION_linux-yocto ??= "4.18%"
 QB_DTB = "${@oe.utils.version_less_or_equal('PREFERRED_VERSION_linux-yocto', '4.7', '', 'zImage-versatile-pb.dtb', d)}"
diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
index 242889a..34fcd2a 100644
--- a/meta/conf/machine/qemuarm64.conf
+++ b/meta/conf/machine/qemuarm64.conf
@@ -16,7 +16,9 @@ QB_MACHINE = "-machine virt"
 QB_CPU = "-cpu cortex-a57"
 QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,38400"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -device virtio-rng-pci -monitor null"
+QB_OPT_APPEND = "-show-cursor -monitor null"
+# Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
 QB_NETWORK_DEVICE = "-device virtio-net-device,netdev=net0,mac=@MAC@"
 QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
diff --git a/meta/conf/machine/qemuppc.conf b/meta/conf/machine/qemuppc.conf
index 537b2f6..743d261 100644
--- a/meta/conf/machine/qemuppc.conf
+++ b/meta/conf/machine/qemuppc.conf
@@ -16,6 +16,7 @@ QB_SYSTEM_NAME = "qemu-system-ppc"
 QB_MACHINE = "-machine mac99"
 QB_CPU = "-cpu G4"
 QB_KERNEL_CMDLINE_APPEND = "console=tty console=ttyS0"
+QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
-QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
-- 
2.8.1



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

* Re: [PATCH V2] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-10-30  2:22   ` [PATCH V2] " Hongxu Jia
@ 2018-10-30  6:59     ` Hongxu Jia
  2018-11-07  1:45     ` Hongxu Jia
  1 sibling, 0 replies; 7+ messages in thread
From: Hongxu Jia @ 2018-10-30  6:59 UTC (permalink / raw)
  To: openembedded-core, richard.purdie

Previously I do the test on qemumips, qemuarm, qemuarm64
and missed qemux86/qemux86-64 which caused the defect.

After applied the V2 fix, I do  runqemu boot test each 4 times on the 
following qemu

The qemux86
[    2.536936] random: crng init done
[    2.795946] random: crng init done
[    3.020137] random: crng init done
[    2.505998] random: crng init done

The qemux86-64
[    5.883281] random: crng init done
[    2.913999] random: crng init done
[    3.745269] random: crng init done
[    2.577969] random: crng init done

The qemuppc:
[    2.153825] random: crng init done
[    1.486999] random: crng init done
[    1.759905] random: crng init done
[    1.638786] random: crng init done

The qemumips64
[    3.460441] random: crng init done
[    4.837740] random: crng init done
[    4.870131] random: crng init done
[    3.990618] random: crng init done

//Hongxu

On 2018/10/30 上午10:22, Hongxu Jia wrote:
> Just adding `-device virtio-rng-pci' to the QEMU invocation will
> add the device with a default host backend. As of QEMU 1.3+,
> the default backend is to use the host's /dev/random as a
> source of entropy. [1]
>
> When the entropy pool is empty, reads from /dev/random will
> block until additional environmental noise is gathered. [2]
>
> For Yocto, if call runqemu frequently, it will consume lots
> of host's /dev/random, and kernel finish crng init in guest get
> more and more slowly.
>
> Here are 4 times runqemu boot test:
>
> [    3.464432] random: crng init done
> [   20.874030] random: crng init done
> [   23.583589] random: crng init done
> [   23.858945] random: crng init done
>
> Modify entropy source to /dev/urandom device on the host which
> returns random bytes using a pseudorandom number generator seeded
> from the entropy pool. Reads from this device do not block and
> kernel finish crng init in guest will not delay.
>
> Of course, the side effect is obviously, we lost the quality of
> randomness, but the modification is only on runqemu script
> rather than real embedded device, and it benefits oeqa efficiency
> in which many cases call runqemu especially multiple oeqa builds
> on one host.
>
> After apply the fix:
>
> [    3.364670] random: crng init done
> [    4.619061] random: crng init done
> [    3.403897] random: crng init done
> [    3.450717] random: crng init done
>
> [1] https://wiki.qemu.org/Features/VirtIORNG
> [2] http://man7.org/linux/man-pages/man4/random.4.html
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>   meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
>   meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
>   meta/conf/machine/qemuarm.conf              | 3 ++-
>   meta/conf/machine/qemuarm64.conf            | 4 +++-
>   meta/conf/machine/qemuppc.conf              | 3 ++-
>   5 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/meta/conf/machine/include/qemuboot-mips.inc b/meta/conf/machine/include/qemuboot-mips.inc
> index 7d9fa52..75bb988 100644
> --- a/meta/conf/machine/include/qemuboot-mips.inc
> +++ b/meta/conf/machine/include/qemuboot-mips.inc
> @@ -3,6 +3,7 @@ IMAGE_CLASSES += "qemuboot"
>   QB_MEM = "-m 256"
>   QB_MACHINE = "-machine malta"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
> +QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
> diff --git a/meta/conf/machine/include/qemuboot-x86.inc b/meta/conf/machine/include/qemuboot-x86.inc
> index 1456bf7..5fdbe4d 100644
> --- a/meta/conf/machine/include/qemuboot-x86.inc
> +++ b/meta/conf/machine/include/qemuboot-x86.inc
> @@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
>   QB_AUDIO_DRV = "alsa"
>   QB_AUDIO_OPT = "-soundhw ac97,es1370"
>   QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
> +QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   
>   UVESA_MODE ?= "640x480-32"
> diff --git a/meta/conf/machine/qemuarm.conf b/meta/conf/machine/qemuarm.conf
> index d2f2c85..a544312 100644
> --- a/meta/conf/machine/qemuarm.conf
> +++ b/meta/conf/machine/qemuarm.conf
> @@ -14,7 +14,8 @@ SERIAL_CONSOLES ?= "115200;ttyAMA0 115200;ttyAMA1"
>   QB_SYSTEM_NAME = "qemu-system-arm"
>   QB_MACHINE = "-machine versatilepb"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,115200 console=tty"
> +QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   PREFERRED_VERSION_linux-yocto ??= "4.18%"
>   QB_DTB = "${@oe.utils.version_less_or_equal('PREFERRED_VERSION_linux-yocto', '4.7', '', 'zImage-versatile-pb.dtb', d)}"
> diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
> index 242889a..34fcd2a 100644
> --- a/meta/conf/machine/qemuarm64.conf
> +++ b/meta/conf/machine/qemuarm64.conf
> @@ -16,7 +16,9 @@ QB_MACHINE = "-machine virt"
>   QB_CPU = "-cpu cortex-a57"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,38400"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -device virtio-rng-pci -monitor null"
> +QB_OPT_APPEND = "-show-cursor -monitor null"
> +# Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
>   QB_NETWORK_DEVICE = "-device virtio-net-device,netdev=net0,mac=@MAC@"
>   QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
> diff --git a/meta/conf/machine/qemuppc.conf b/meta/conf/machine/qemuppc.conf
> index 537b2f6..743d261 100644
> --- a/meta/conf/machine/qemuppc.conf
> +++ b/meta/conf/machine/qemuppc.conf
> @@ -16,6 +16,7 @@ QB_SYSTEM_NAME = "qemu-system-ppc"
>   QB_MACHINE = "-machine mac99"
>   QB_CPU = "-cpu G4"
>   QB_KERNEL_CMDLINE_APPEND = "console=tty console=ttyS0"
> +QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"




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

* Re: [PATCH V2] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-10-30  2:22   ` [PATCH V2] " Hongxu Jia
  2018-10-30  6:59     ` Hongxu Jia
@ 2018-11-07  1:45     ` Hongxu Jia
  2018-11-07  9:25       ` richard.purdie
  1 sibling, 1 reply; 7+ messages in thread
From: Hongxu Jia @ 2018-11-07  1:45 UTC (permalink / raw)
  To: openembedded-core, richard.purdie, Burton, Ross

On 2018/10/30 上午10:22, Hongxu Jia wrote:
> Just adding `-device virtio-rng-pci' to the QEMU invocation will
> add the device with a default host backend. As of QEMU 1.3+,
> the default backend is to use the host's /dev/random as a
> source of entropy. [1]
>
> When the entropy pool is empty, reads from /dev/random will
> block until additional environmental noise is gathered. [2]
>
> For Yocto, if call runqemu frequently, it will consume lots
> of host's /dev/random, and kernel finish crng init in guest get
> more and more slowly.
>
> Here are 4 times runqemu boot test:
>
> [    3.464432] random: crng init done
> [   20.874030] random: crng init done
> [   23.583589] random: crng init done
> [   23.858945] random: crng init done
>
> Modify entropy source to /dev/urandom device on the host which
> returns random bytes using a pseudorandom number generator seeded
> from the entropy pool. Reads from this device do not block and
> kernel finish crng init in guest will not delay.
>
> Of course, the side effect is obviously, we lost the quality of
> randomness, but the modification is only on runqemu script
> rather than real embedded device, and it benefits oeqa efficiency
> in which many cases call runqemu especially multiple oeqa builds
> on one host.
>
> After apply the fix:
>
> [    3.364670] random: crng init done
> [    4.619061] random: crng init done
> [    3.403897] random: crng init done
> [    3.450717] random: crng init done
>
> [1] https://wiki.qemu.org/Features/VirtIORNG
> [2] http://man7.org/linux/man-pages/man4/random.4.html
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>   meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
>   meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
>   meta/conf/machine/qemuarm.conf              | 3 ++-
>   meta/conf/machine/qemuarm64.conf            | 4 +++-
>   meta/conf/machine/qemuppc.conf              | 3 ++-
>   5 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/meta/conf/machine/include/qemuboot-mips.inc b/meta/conf/machine/include/qemuboot-mips.inc
> index 7d9fa52..75bb988 100644
> --- a/meta/conf/machine/include/qemuboot-mips.inc
> +++ b/meta/conf/machine/include/qemuboot-mips.inc
> @@ -3,6 +3,7 @@ IMAGE_CLASSES += "qemuboot"
>   QB_MEM = "-m 256"
>   QB_MACHINE = "-machine malta"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
> +QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
> diff --git a/meta/conf/machine/include/qemuboot-x86.inc b/meta/conf/machine/include/qemuboot-x86.inc
> index 1456bf7..5fdbe4d 100644
> --- a/meta/conf/machine/include/qemuboot-x86.inc
> +++ b/meta/conf/machine/include/qemuboot-x86.inc
> @@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
>   QB_AUDIO_DRV = "alsa"
>   QB_AUDIO_OPT = "-soundhw ac97,es1370"
>   QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1 uvesafb.task_timeout=-1"
> +QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet"

Hi Ross,

I am afraid the patch you merged to master-next is V1 which caused runqemu

failure on qemux86/qemux86-64, we should use V2

[v1 snip]

--- a/meta/conf/machine/include/qemuboot-x86.inc
+++ b/meta/conf/machine/include/qemuboot-x86.inc
@@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
+QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device"
  # Add the 'virtio-rng-pci' device otherwise the guest may run out of 
entropy
-QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet 
-device virtio-rng-pci"
+QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 
-device virtio-rng-pci,rng=rng0

[v1 snip]

//Hongxu


>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   
>   UVESA_MODE ?= "640x480-32"
> diff --git a/meta/conf/machine/qemuarm.conf b/meta/conf/machine/qemuarm.conf
> index d2f2c85..a544312 100644
> --- a/meta/conf/machine/qemuarm.conf
> +++ b/meta/conf/machine/qemuarm.conf
> @@ -14,7 +14,8 @@ SERIAL_CONSOLES ?= "115200;ttyAMA0 115200;ttyAMA1"
>   QB_SYSTEM_NAME = "qemu-system-arm"
>   QB_MACHINE = "-machine versatilepb"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,115200 console=tty"
> +QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   PREFERRED_VERSION_linux-yocto ??= "4.18%"
>   QB_DTB = "${@oe.utils.version_less_or_equal('PREFERRED_VERSION_linux-yocto', '4.7', '', 'zImage-versatile-pb.dtb', d)}"
> diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
> index 242889a..34fcd2a 100644
> --- a/meta/conf/machine/qemuarm64.conf
> +++ b/meta/conf/machine/qemuarm64.conf
> @@ -16,7 +16,9 @@ QB_MACHINE = "-machine virt"
>   QB_CPU = "-cpu cortex-a57"
>   QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,38400"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -device virtio-rng-pci -monitor null"
> +QB_OPT_APPEND = "-show-cursor -monitor null"
> +# Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"
>   QB_NETWORK_DEVICE = "-device virtio-net-device,netdev=net0,mac=@MAC@"
>   QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0"
> diff --git a/meta/conf/machine/qemuppc.conf b/meta/conf/machine/qemuppc.conf
> index 537b2f6..743d261 100644
> --- a/meta/conf/machine/qemuppc.conf
> +++ b/meta/conf/machine/qemuppc.conf
> @@ -16,6 +16,7 @@ QB_SYSTEM_NAME = "qemu-system-ppc"
>   QB_MACHINE = "-machine mac99"
>   QB_CPU = "-cpu G4"
>   QB_KERNEL_CMDLINE_APPEND = "console=tty console=ttyS0"
> +QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet"
>   # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
> -QB_OPT_APPEND = "-show-cursor -usb -device usb-tablet -device virtio-rng-pci"
> +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0"
>   QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"




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

* Re: [PATCH V2] machine/qemu*: fix kernel finish crng init more and more slowly
  2018-11-07  1:45     ` Hongxu Jia
@ 2018-11-07  9:25       ` richard.purdie
  0 siblings, 0 replies; 7+ messages in thread
From: richard.purdie @ 2018-11-07  9:25 UTC (permalink / raw)
  To: Hongxu Jia, openembedded-core, Burton, Ross

On Wed, 2018-11-07 at 09:45 +0800, Hongxu Jia wrote:
> On 2018/10/30 上午10:22, Hongxu Jia wrote:
> > Just adding `-device virtio-rng-pci' to the QEMU invocation will
> > add the device with a default host backend. As of QEMU 1.3+,
> > the default backend is to use the host's /dev/random as a
> > source of entropy. [1]
> > 
> > When the entropy pool is empty, reads from /dev/random will
> > block until additional environmental noise is gathered. [2]
> > 
> > For Yocto, if call runqemu frequently, it will consume lots
> > of host's /dev/random, and kernel finish crng init in guest get
> > more and more slowly.
> > 
> > Here are 4 times runqemu boot test:
> > 
> > [    3.464432] random: crng init done
> > [   20.874030] random: crng init done
> > [   23.583589] random: crng init done
> > [   23.858945] random: crng init done
> > 
> > Modify entropy source to /dev/urandom device on the host which
> > returns random bytes using a pseudorandom number generator seeded
> > from the entropy pool. Reads from this device do not block and
> > kernel finish crng init in guest will not delay.
> > 
> > Of course, the side effect is obviously, we lost the quality of
> > randomness, but the modification is only on runqemu script
> > rather than real embedded device, and it benefits oeqa efficiency
> > in which many cases call runqemu especially multiple oeqa builds
> > on one host.
> > 
> > After apply the fix:
> > 
> > [    3.364670] random: crng init done
> > [    4.619061] random: crng init done
> > [    3.403897] random: crng init done
> > [    3.450717] random: crng init done
> > 
> > [1] https://wiki.qemu.org/Features/VirtIORNG
> > [2] http://man7.org/linux/man-pages/man4/random.4.html
> > 
> > Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> > ---
> >   meta/conf/machine/include/qemuboot-mips.inc | 3 ++-
> >   meta/conf/machine/include/qemuboot-x86.inc  | 3 ++-
> >   meta/conf/machine/qemuarm.conf              | 3 ++-
> >   meta/conf/machine/qemuarm64.conf            | 4 +++-
> >   meta/conf/machine/qemuppc.conf              | 3 ++-
> >   5 files changed, 11 insertions(+), 5 deletions(-)
> > 
> > diff --git a/meta/conf/machine/include/qemuboot-mips.inc
> > b/meta/conf/machine/include/qemuboot-mips.inc
> > index 7d9fa52..75bb988 100644
> > --- a/meta/conf/machine/include/qemuboot-mips.inc
> > +++ b/meta/conf/machine/include/qemuboot-mips.inc
> > @@ -3,6 +3,7 @@ IMAGE_CLASSES += "qemuboot"
> >   QB_MEM = "-m 256"
> >   QB_MACHINE = "-machine malta"
> >   QB_KERNEL_CMDLINE_APPEND = "console=ttyS0 console=tty"
> > +QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet"
> >   # Add the 'virtio-rng-pci' device otherwise the guest may run out
> > of entropy
> > -QB_OPT_APPEND = "-vga cirrus -show-cursor -usb -device usb-tablet
> > -device virtio-rng-pci"
> > +QB_OPT_APPEND += "-object rng-random,filename=/dev/urandom,id=rng0 
> > -device virtio-rng-pci,rng=rng0"
> >   QB_SYSTEM_NAME = "qemu-system-${TUNE_ARCH}"
> > diff --git a/meta/conf/machine/include/qemuboot-x86.inc
> > b/meta/conf/machine/include/qemuboot-x86.inc
> > index 1456bf7..5fdbe4d 100644
> > --- a/meta/conf/machine/include/qemuboot-x86.inc
> > +++ b/meta/conf/machine/include/qemuboot-x86.inc
> > @@ -11,7 +11,8 @@ QB_CPU_KVM_x86-64 = "-cpu core2duo"
> >   QB_AUDIO_DRV = "alsa"
> >   QB_AUDIO_OPT = "-soundhw ac97,es1370"
> >   QB_KERNEL_CMDLINE_APPEND = "vga=0
> > uvesafb.mode_option=${UVESA_MODE} oprofile.timer=1
> > uvesafb.task_timeout=-1"
> > +QB_OPT_APPEND = "-vga vmware -show-cursor -usb -device usb-tablet"
> 
> Hi Ross,
> 
> I am afraid the patch you merged to master-next is V1 which caused
> runqemu
> 
> failure on qemux86/qemux86-64, we should use V2
> 
> [v1 snip]

Thanks, I picked this up out of mut thinking it was the V2 and meant to
check but forgot. I've the right version in -next now, thanks!

Cheers,

Richard



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

end of thread, other threads:[~2018-11-07  9:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26 13:59 [PATCH] machine/qemu*: fix kernel finish crng init more and more slowly Hongxu Jia
2018-10-29 15:07 ` richard.purdie
2018-10-30  2:22   ` [PATCH V2] " Hongxu Jia
2018-10-30  6:59     ` Hongxu Jia
2018-11-07  1:45     ` Hongxu Jia
2018-11-07  9:25       ` richard.purdie
2018-10-30  2:00 ` [PATCH] " Hongxu Jia

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.