Skip to content

Commit 0fdf920

Browse files
authored
Fix guest-agent not starting with HyperV Enlightenments enabled (#3592)
Guest agent doesn't start because if HyperV Enlightenments are enabled, the virtualization gets detected incorrectly. Backport Systemd patch that fixes the detection, allowing the guest-agent service to meet its dependencies. This patch should be no longer needed after update of Systemd to v256, or in case the patch gets eventually backported to the v254 stable branch. Fixes #3565
1 parent f27c429 commit 0fdf920

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From f42a5b49e95a8deed0b8e6f1bea6679af7e908e4 Mon Sep 17 00:00:00 2001
2+
From: Lennart Poettering <[email protected]>
3+
Date: Fri, 19 Apr 2024 13:25:55 +0200
4+
Subject: [PATCH] detect-virt: detect hyperv-enlightened qemu as qemu, not as
5+
hyperv
6+
7+
CPUID reporting hyperv should be taken with a grain of salt, and we
8+
should prefer other mechanisms then.
9+
10+
Fixes: #28001
11+
---
12+
src/basic/virt.c | 20 ++++++++++++++++----
13+
1 file changed, 16 insertions(+), 4 deletions(-)
14+
15+
diff --git a/src/basic/virt.c b/src/basic/virt.c
16+
index 88357a9..89abb53 100644
17+
--- a/src/basic/virt.c
18+
+++ b/src/basic/virt.c
19+
@@ -446,7 +446,7 @@ static Virtualization detect_vm_zvm(void) {
20+
/* Returns a short identifier for the various VM implementations */
21+
Virtualization detect_vm(void) {
22+
static thread_local Virtualization cached_found = _VIRTUALIZATION_INVALID;
23+
- bool other = false;
24+
+ bool other = false, hyperv = false;
25+
int xen_dom0 = 0;
26+
Virtualization v, dmi;
27+
28+
@@ -503,7 +503,12 @@ Virtualization detect_vm(void) {
29+
v = detect_vm_cpuid();
30+
if (v < 0)
31+
return v;
32+
- if (v == VIRTUALIZATION_VM_OTHER)
33+
+ if (v == VIRTUALIZATION_MICROSOFT)
34+
+ /* QEMU sets the CPUID string to hyperv's, in case it provides hyperv enlightenments. Let's
35+
+ * hence not return Microsoft here but just use the other mechanisms first to make a better
36+
+ * decision. */
37+
+ hyperv = true;
38+
+ else if (v == VIRTUALIZATION_VM_OTHER)
39+
other = true;
40+
else if (v != VIRTUALIZATION_NONE)
41+
goto finish;
42+
@@ -544,8 +549,15 @@ Virtualization detect_vm(void) {
43+
return v;
44+
45+
finish:
46+
- if (v == VIRTUALIZATION_NONE && other)
47+
- v = VIRTUALIZATION_VM_OTHER;
48+
+ /* None of the checks above gave us a clear answer, hence let's now use fallback logic: if hyperv
49+
+ * enlightenments are available but the VMM wasn't recognized as anything yet, it's probably
50+
+ * Microsoft. */
51+
+ if (v == VIRTUALIZATION_NONE) {
52+
+ if (hyperv)
53+
+ v = VIRTUALIZATION_MICROSOFT;
54+
+ else if (other)
55+
+ v = VIRTUALIZATION_VM_OTHER;
56+
+ }
57+
58+
cached_found = v;
59+
log_debug("Found VM virtualization %s", virtualization_to_string(v));

0 commit comments

Comments
 (0)