Hyper-V hosts make 64 bytes of entropy available to guests in the form
of a OEM0 acpi table.  Feed that into the entropy pool.

This is less interesting for machines with rdrand, but there are still
pre ivy bridge machines running Hyper-V (including parts of Azure).

Index: sys/dev/acpi/files.acpi
===================================================================
RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.35
diff -u -p -r1.35 files.acpi
--- sys/dev/acpi/files.acpi     3 Aug 2016 17:23:38 -0000       1.35
+++ sys/dev/acpi/files.acpi     9 Jan 2017 12:47:20 -0000
@@ -145,3 +145,8 @@ file        dev/acpi/acpials.c              acpials
 device tpm
 attach tpm at acpi
 file   dev/acpi/tpm.c                  tpm
+
+# Hyper-V Entropy
+device acpihve
+attach acpihve at acpi
+file   dev/acpi/acpihve.c              acpihve
Index: sys/arch/amd64/conf/GENERIC
===================================================================
RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.437
diff -u -p -r1.437 GENERIC
--- sys/arch/amd64/conf/GENERIC 13 Dec 2016 19:47:32 -0000      1.437
+++ sys/arch/amd64/conf/GENERIC 9 Jan 2017 12:48:09 -0000
@@ -67,6 +67,7 @@ sdhc*         at acpi?
 acpicbkbd*     at acpi?
 acpials*       at acpi?
 tpm*           at acpi?
+acpihve*       at acpi?
 
 mpbios0                at bios0
 
--- /dev/null   Tue Jan 10 13:56:15 2017
+++ sys/dev/acpi/acpihve.c      Tue Jan 10 13:55:28 2017
@@ -0,0 +1,89 @@
+/*     $OpenBSD$       */
+
+/*
+ * Copyright (c) 2017 Jonathan Gray <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/rndvar.h>
+
+int     acpihve_match(struct device *, void *, void *);
+void    acpihve_attach(struct device *, struct device *, void *);
+
+struct acpi_oem0 {
+       struct acpi_table_header        hdr;
+       uint32_t                        entropy[16];
+} __packed;
+
+struct acpihve_softc {
+       struct device                   sc_dev;
+};
+
+struct cfattach acpihve_ca = {
+       sizeof(struct acpihve_softc), acpihve_match, acpihve_attach
+};
+
+struct cfdriver acpihve_cd = {
+       NULL, "acpihve", DV_DULL
+};
+
+int     acpihve_attached;
+
+int
+acpihve_match(struct device *parent, void *match, void *aux)
+{
+       struct acpi_attach_args *aaa = aux;
+       struct acpi_table_header *hdr;
+
+       /*
+        * If we do not have a table, it is not us; attach only once
+        */
+       if (acpihve_attached || aaa->aaa_table == NULL)
+               return (0);
+
+       hdr = (struct acpi_table_header *)aaa->aaa_table;
+       if (memcmp(hdr->signature, "OEM0", 4) != 0 ||
+           memcmp(hdr->oemid, "VRTUAL", 6) != 0 ||
+           memcmp(hdr->oemtableid, "MICROSFT", 8) != 0)
+               return (0);
+
+       return (1);
+}
+
+void
+acpihve_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct acpi_attach_args *aaa = aux;
+       struct acpi_oem0 *oem0 = (struct acpi_oem0 *)aaa->aaa_table;
+       int i;
+
+       acpihve_attached++;
+
+       /* should be 64 bytes of entropy */
+       if (oem0->hdr.length != sizeof(*oem0)) {
+               printf(": unexpected table length %u\n", oem0->hdr.length);
+               return;
+       }
+
+       for (i = 0; i < nitems(oem0->entropy); i++)
+               add_true_randomness(oem0->entropy[i]);
+
+       printf(": added %lu bytes of entropy\n", sizeof(oem0->entropy));
+}
--- /dev/null   Tue Jan 10 13:56:29 2017
+++ share/man/man4/acpihve.4    Tue Jan 10 13:49:52 2017
@@ -0,0 +1,38 @@
+.\"    $OpenBSD$
+.\"
+.\" Copyright (c) 2017 Jonathan Gray <[email protected]>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate$
+.Dt ACPIHVE 4
+.Os
+.Sh NAME
+.Nm acpihve
+.Nd Hyper-V entropy
+.Sh SYNOPSIS
+.Cd "acpihve* at acpi?"
+.Sh DESCRIPTION
+Hyper-V and Azure hosts make entropy available to guests in a OEM0 acpi
+table.
+The
+.Nm
+driver feeds the entropy into the kernel's entropy pool.
+.Sh SEE ALSO
+.Xr acpi 4 ,
+.Xr add_true_randomness 9
+.Sh HISTORY
+The
+.Nm
+device driver first appeared in
+.Ox 6.1 .
Index: share/man/man4/Makefile
===================================================================
RCS file: /cvs/src/share/man/man4/Makefile,v
retrieving revision 1.648
diff -u -p -r1.648 Makefile
--- share/man/man4/Makefile     3 Jan 2017 20:35:46 -0000       1.648
+++ share/man/man4/Makefile     10 Jan 2017 02:51:28 -0000
@@ -2,7 +2,7 @@
 
 MAN=   aac.4 ac97.4 acphy.4 \
        acpi.4 acpiac.4 acpials.4 acpiasus.4 acpibat.4 \
-       acpibtn.4 acpicbkbd.4 acpicpu.4 acpidock.4 \
+       acpibtn.4 acpicbkbd.4 acpicpu.4 acpidock.4 acpihve.4 \
        acpiec.4 acpihpet.4 acpimadt.4 acpimcfg.4 acpiprt.4 acpipwrres.4 \
        acpisony.4 acpithinkpad.4 acpitoshiba.4 acpitimer.4 acpivideo.4 \
        acpivout.4 acpitz.4 \
Index: share/man/man4/acpi.4
===================================================================
RCS file: /cvs/src/share/man/man4/acpi.4,v
retrieving revision 1.51
diff -u -p -r1.51 acpi.4
--- share/man/man4/acpi.4       23 Aug 2016 18:58:53 -0000      1.51
+++ share/man/man4/acpi.4       10 Jan 2017 03:14:53 -0000
@@ -58,6 +58,8 @@ ACPI docking station
 ACPI embedded controller
 .It Xr acpihpet 4
 ACPI high precision event timer
+.It Xr acpihve 4
+Hyper-V entropy
 .It Xr acpimadt 4
 ACPI APIC configuration
 .It Xr acpimcfg 4

Reply via email to