Skip to contentSkip to conversation

um: Rewrite host RNG driver.

PATCH In review Alexander Neville 2 participants 4 messages Aug 29, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 um: Rewrite host RNG driver.

The old driver had a bug that would cause it to outright stop working if the host's /dev/random were to block. Instead of trying to track down the cause of said bug, rewriting it from scratch turned out to be a much better option as it came with a few benefits:

- The new driver uses the hw_random framework.

- The code is simpler and therefore easier to maintain.

- It serves as a minimal example of writing a hardware RNG driver.

I also edited the Kconfig symbol to bring it up to more modern standards.

---
v2:
* fix -EAGAIN handling

---
 arch/um/drivers/Makefile       |   3 +-
 arch/um/drivers/random.c       | 199 +++++++++------------------------
 drivers/char/hw_random/Kconfig |  21 ++--
 3 files changed, 66 insertions(+), 157 deletions(-)
arch/um/drivers/Makefile +2 -1
index 693319839f69..29b0364f267d 100644
@@ -17,6 +17,7 @@ hostaudio-objs := hostaudio_kern.o
 ubd-objs := ubd_kern.o ubd_user.o
 port-objs := port_kern.o port_user.o
 harddog-objs := harddog_kern.o harddog_user.o
+uml-rng-objs := random.o
 
 LDFLAGS_pcap.o := -r $(shell $(CC) $(KBUILD_CFLAGS) -print-file-name=libpcap.a)
 
@@ -60,7 +61,7 @@ obj-$(CONFIG_TTY_CHAN) += tty.o
 obj-$(CONFIG_XTERM_CHAN) += xterm.o xterm_kern.o
 obj-$(CONFIG_UML_WATCHDOG) += harddog.o
 obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
-obj-$(CONFIG_UML_RANDOM) += random.o
+obj-$(CONFIG_UML_RANDOM) += uml-rng.o
 
 # pcap_user.o must be added explicitly.
 USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o vde_user.o vector_user.o
arch/um/drivers/random.c +53 -146

228 lines not on this page · raw message

drivers/char/hw_random/Kconfig +11 -10
index 59f25286befe..a0781f74d4e4 100644
@@ -440,22 +440,23 @@ config HW_RANDOM_OPTEE
 
 	  If unsure, say Y.
 
-endif # HW_RANDOM
-
 config UML_RANDOM
+	tristate "UML Host Random Number Generator Support"
 	depends on UML
-	tristate "Hardware random number generator"
+	default HW_RANDOM
 	help
 	  This option enables UML's "hardware" random number generator.  It
 	  attaches itself to the host's /dev/random, supplying as much entropy
 	  as the host has, rather than the small amount the UML gets from its
-	  own drivers.  It registers itself as a standard hardware random number
-	  generator, major 10, minor 183, and the canonical device name is
-	  /dev/hwrng.
-	  The way to make use of this is to install the rng-tools package
-	  (check your distro, or download from
-	  http://sourceforge.net/projects/gkernel/).  rngd periodically reads
-	  /dev/hwrng and injects the entropy into /dev/random.
+	  own drivers.
+
+	  To compile this driver as a moudle, choose M here: the module
+	  will be called uml-rng.
+
+	  If unsure, say Y.
+
+endif # HW_RANDOM
+
 
 config HW_RANDOM_KEYSTONE
 	depends on ARCH_KEYSTONE
Signature · 1 line
2.23.0
#1 lore raw

----- Ursprüngliche Mail -----

arch/um/drivers/random.c line 27

Quoted 4 lines

Von: "Dark" <[email protected]>

arch/um/drivers/random.c +3 -0
+	// Returning -EAGAIN to userspace is not nice.
+	if (err == -EAGAIN)
+		return 0;

Hmm, doesn't this result in a short read?
The current drives sets the calling task to sleep and wakes it up as soon data is available again. I'd assumes ti have the same behavior for the new driver.

Thanks,
//richard

#2 lore raw
Quoted 11 lines · Richard Weinberger

----- Ursprüngliche Mail -----

arch/um/drivers/random.c line 27

Quoted 4 lines

Von: "Dark" <[email protected]>

arch/um/drivers/random.c +3 -0
+	// Returning -EAGAIN to userspace is not nice.
+	if (err == -EAGAIN)
+		return 0;  

Hmm, doesn't this result in a short read?
The current drives sets the calling task to sleep and wakes it up as soon data is available again. I'd assumes ti have the same behavior for the new driver.

Quoted 2 lines

Thanks,
//richard

Clearly this patch needs a lot more work before I submit it. I'll take some time to polish it up and then resubmit it if that's fine.

#3 lore raw

----- Ursprüngliche Mail -----

Quoted 11 lines
Quoted 11 lines

----- Ursprüngliche Mail -----

arch/um/drivers/random.c line 27

Quoted 4 lines

Von: "Dark" <[email protected]>

arch/um/drivers/random.c +3 -0
+	// Returning -EAGAIN to userspace is not nice.
+	if (err == -EAGAIN)
+		return 0;

Hmm, doesn't this result in a short read?
The current drives sets the calling task to sleep and wakes it up as soon data is available again. I'd assumes ti have the same behavior for the new driver.

Quoted 5 lines
Quoted 2 lines

Thanks,
//richard

Clearly this patch needs a lot more work before I submit it. I'll take some time to polish it up and then resubmit it if that's fine.

No need to worry, take your time. Thanks a lot for working on this driver!

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um