Port-xen archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: XenServer and viridian



On Wed, 26 Mar 2025, Manuel Bouyer wrote:
On Wed, Mar 26, 2025 at 05:24:39PM +0000, Stephen Borrill wrote:
On XenServer/XCP-ng VMs can have 'Viridian enlightenments' enabled. This is
used by Windows VMs to get some features that would otherwise require
Hyper-V, for instance, VM generation counter as used by Active Directory to
spot it if is has been rolled back.

These shouldn't affect any non-Windows VMs, but NetBSD mistakenly thinks it
is running on Hyper-V rather than Xen, so the PVH code is not enabled.

I tried the following naive patch:

--- sys/arch/x86/x86/identcpu.c 2 Feb 2025 14:51:59 -0000       1.123.4.2
+++ sys/arch/x86/x86/identcpu.c 26 Mar 2025 17:20:44 -0000
@@ -1132,8 +1132,22 @@
                                vm_guest = VM_GUEST_VMWARE;
                        else if (memcmp(hv_vendor, "Microsoft Hv", 12) == 0) {
                                vm_guest = VM_GUEST_HV;
+                               p = pmf_get_platform("system-vendor");
+                               if (p != NULL) {
+                                       if (strncmp(p, "Xen", 3) == 0) {
+                                               /*
+                                                * XenServer VMs may have
+                                                * Viridian enlightenments
+                                                * enabled which may make
+                                                * Hyper-V be falsely matched
+                                                */
+                                               vm_guest = VM_GUEST_XENHVM;
+                                       }
+                               }
 #if NHYPERV > 0
-                               hyperv_early_init();
+                               if (vm_guest == VM_GUEST_HV) {
+                                       hyperv_early_init();
+                               }
 #endif
                        } else if (memcmp(hv_vendor, "KVMKVMKVM\0\0\0", 12) == 0)
                                vm_guest = VM_GUEST_KVM;


It correctly "Identified Guest XEN in HVM mode" instead of Hyper-C, but
immediately panicked in xen_hvm_init().

Is there a less naive patch I could try? :-)

Can you give more details about the panic ?

[   1.0000000] NetBSD 10.1_STABLE (GENERIC) #6: Wed Mar 26 17:13:37 GMT 2025
[   1.0000000]  root@builder10:/usr/work/obj/10/amd64/sys/arch/amd64/compile/GENERIC
[   1.0000000] total memory = 1019 MB
[   1.0000000] avail memory = 957 MB
[   1.0000040] efi: systbl at pa 3f5ee018
[   1.0000040] mainbus0 (root)
[   1.0000040] Identified Guest XEN in HVM mode.
[   1.0000040] fatal protection fault in supervisor mode
[   1.0000040] trap type 4 code 0 rip 0xffffffff802499cd cs 0x8 rflags 0x246 cr2 0 ilevel 0x8 rsp 0xffffffff81d40cf0
[   1.0000040] curlwp 0xffffffff8188b000 pid 0.0 lowest kstack 0xffffffff81d3b2c0
kernel: protection fault trap, code=0
Stopped in pid 0.0 (system) at  netbsd:xen_hvm_init+0xad:       wrmsr
xen_hvm_init() at netbsd:xen_hvm_init+0xad
mainbus_attach() at netbsd:mainbus_attach+0x38
config_attach_internal() at netbsd:config_attach_internal+0x214
config_rootfound() at netbsd:config_rootfound+0x6e
cpu_configure() at netbsd:cpu_configure+0x38
main() at netbsd:main+0x2f1
ds          8
es          cb0
fs          cf0
gs          8
rdi         8
rsi         3f8
rbp         ffffffff81d40d40
rbx         60000
rdx         0
rcx         60000
rax         20f000
r8          0
r9          7
r10         ffffd91b555ced58
r11         fffffff8
r12         0
r13         fc
r14         0
r15         ffffffff818a7f60    cfdata+0x6de0
rip         ffffffff802499cd    xen_hvm_init+0xad
cs          8
rflags      246
rsp         ffffff81d3fcf0
ss          10
netbsd@xen_hvm_init+0xad:       wrmsr

For record, I got this by running the following in the dom0 to output the serial console to a file:

xenstore-write /local/logconsole/@ /tmp/console.%d.log

Because of the --db_more-- prompt and the console being output-only, I had to hand-copy from r12 onwards from a second boot with the VGA ocnsole. With the serial console, I tried to send input into its console tty, but it didn't help:

# xenstore-read /local/domain/60/console/tty
/dev/pts/25
# echo " " >> /dev/pts/25


--
Stephen



Home | Main Index | Thread Index | Old Index