Download raw body.
[PATCH 2/7] hyperv: attach drivers to channels regardless of monitor notification
[PATCH 3/7] hvs: use 10-byte commands with the Hyper-V virtual DVD drive
[PATCH 4/7] amd64: select the Hyper-V delay function before console probing
[PATCH 5/7] hidkbd: don't claim the console when another keyboard already has it
Generation 2 VMs have no i8254. cninit() probes pckbc(4), whose
delay() calls wait for the missing PIT forever, so the machine hangs
with a black screen before anything is printed. Split the
allocation-free CPUID signature scan out of pvbus_identify() and use
it to install the Hyper-V reference counter delay before cninit().
Hypervisor detection is unchanged: same signature table, same scan
and the same initialization order.
---
sys/arch/amd64/amd64/machdep.c | 8 ++++
sys/dev/pv/pvbus.c | 85 +++++++++++++++++++++++++---------
sys/dev/pv/pvvar.h | 1 +
3 files changed, 73 insertions(+), 21 deletions(-)
diff --git sys/arch/amd64/amd64/machdep.c sys/arch/amd64/amd64/machdep.c
index 54b654254f4..c409fad876c 100644
--- sys/arch/amd64/amd64/machdep.c
+++ sys/arch/amd64/amd64/machdep.c
@@ -116,6 +116,11 @@ extern int db_console;
#include "isadma.h"
#include "ksyms.h"
+#include "pvbus.h"
+#if NPVBUS > 0
+#include <dev/pv/pvvar.h>
+#endif
+
#include "acpi.h"
#if NACPI > 0
#include <dev/acpi/acpireg.h>
@@ -1570,6 +1575,9 @@ init_x86_64(paddr_t first_avail)
} else
panic("invalid /boot");
+#if NPVBUS > 0
+ pvbus_init_delay();
+#endif
cninit();
/*
diff --git sys/dev/pv/pvbus.c sys/dev/pv/pvbus.c
index fb328cf298f..ce2891eb131 100644
--- sys/dev/pv/pvbus.c
+++ sys/dev/pv/pvbus.c
@@ -49,6 +49,7 @@ int pvbus_match(struct device *, void *, void *);
void pvbus_attach(struct device *, struct device *, void *);
int pvbus_print(void *, const char *);
int pvbus_search(struct device *, void *, void *);
+void pvbus_scan(void);
void pvbus_kvm(struct pvbus_hv *);
void pvbus_hyperv(struct pvbus_hv *);
@@ -107,6 +108,63 @@ struct bus_dma_tag pvbus_dma_tag = {
struct pvbus_hv pvbus_hv[PVBUS_MAX];
struct pvbus_softc *pvbus_softc;
+/*
+ * Find the CPUID leaves of known hypervisors. This doesn't allocate
+ * memory, so it can be used before the console has been initialized.
+ */
+void
+pvbus_scan(void)
+{
+ static int scanned;
+ uint32_t reg0, ebx, ecx, edx, base;
+ union {
+ uint32_t regs[3];
+ char str[CPUID_HV_SIGNATURE_STRLEN];
+ } r;
+ int i;
+
+ if (scanned)
+ return;
+ scanned = 1;
+
+ CPUID(1, reg0, ebx, ecx, edx);
+ if ((ecx & CPUIDECX_HV) == 0)
+ return;
+
+ for (base = CPUID_HV_SIGNATURE_START;
+ base < CPUID_HV_SIGNATURE_END;
+ base += CPUID_HV_SIGNATURE_STEP) {
+ CPUID(base, reg0, r.regs[0], r.regs[1], r.regs[2]);
+ for (i = 0; i < 4; i++) {
+ /*
+ * Check if first 4 chars are printable ASCII as
+ * minimal validity check
+ */
+ if (r.str[i] < 32 || r.str[i] > 126)
+ return;
+ }
+
+ for (i = 0; i < PVBUS_MAX; i++) {
+ if (pvbus_types[i].signature == NULL ||
+ memcmp(pvbus_types[i].signature, r.str,
+ CPUID_HV_SIGNATURE_STRLEN) != 0)
+ continue;
+ pvbus_hv[i].hv_base = base;
+ }
+ }
+}
+
+/* Select a delay source before console drivers probe legacy devices. */
+void
+pvbus_init_delay(void)
+{
+#if NHYPERV > 0
+ pvbus_scan();
+ if (pvbus_hv[PVBUS_HYPERV].hv_base != 0)
+ pvbus_hyperv(&pvbus_hv[PVBUS_HYPERV]);
+#endif
+}
+
int
pvbus_probe(void)
{
@@ -151,34 +209,20 @@ void
pvbus_identify(void)
{
struct pvbus_hv *hv;
- uint32_t reg0, base;
- union {
- uint32_t regs[3];
- char str[CPUID_HV_SIGNATURE_STRLEN];
- } r;
+ uint32_t base;
int i, cnt;
const char *pv_name;
+ pvbus_scan();
+
+ /* Initialize the hypervisors in the order of their CPUID leaves. */
for (base = CPUID_HV_SIGNATURE_START, cnt = 0;
base < CPUID_HV_SIGNATURE_END;
base += CPUID_HV_SIGNATURE_STEP) {
- CPUID(base, reg0, r.regs[0], r.regs[1], r.regs[2]);
- for (i = 0; i < 4; i++) {
- /*
- * Check if first 4 chars are printable ASCII as
- * minimal validity check
- */
- if (r.str[i] < 32 || r.str[i] > 126)
- goto out;
- }
-
for (i = 0; i < PVBUS_MAX; i++) {
- if (pvbus_types[i].signature == NULL ||
- memcmp(pvbus_types[i].signature, r.str,
- CPUID_HV_SIGNATURE_STRLEN) != 0)
- continue;
hv = &pvbus_hv[i];
- hv->hv_base = base;
+ if (hv->hv_base != base)
+ continue;
if (pvbus_types[i].init != NULL)
(pvbus_types[i].init)(hv);
if (hw_vendor == NULL) {
@@ -198,7 +242,6 @@ pvbus_identify(void)
}
}
- out:
if (cnt)
has_hv_cpuid = 1;
}
diff --git sys/dev/pv/pvvar.h sys/dev/pv/pvvar.h
index d2ba273a45a..5c356a2ace8 100644
--- sys/dev/pv/pvvar.h
+++ sys/dev/pv/pvvar.h
@@ -79,6 +79,7 @@ struct pv_attach_args {
};
void pvbus_identify(void);
+void pvbus_init_delay(void);
int pvbus_probe(void);
void pvbus_init_cpu(void);
void pvbus_reboot(struct device *);
[PATCH 2/7] hyperv: attach drivers to channels regardless of monitor notification
[PATCH 3/7] hvs: use 10-byte commands with the Hyper-V virtual DVD drive
[PATCH 4/7] amd64: select the Hyper-V delay function before console probing
[PATCH 5/7] hidkbd: don't claim the console when another keyboard already has it