Skip to content

Commit

Permalink
gui-vm: support system suspend on lid close
Browse files Browse the repository at this point in the history
* Addresses SP-4844 - Display turns on in sleep
  mode when the lid is closed.
* Removes lidSwitch which changes behaviour to
  default which is suspend on lid closed.
* Adds patch which is fixing qemu crash.
* Adds overlay tracker info.

Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
  • Loading branch information
vunnyso committed Aug 15, 2024
1 parent d895e7d commit a39e2dd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
4 changes: 0 additions & 4 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
hostPlatform.system = config.nixpkgs.hostPlatform.system;
};

# Suspend inside Qemu causes segfault
# See: https://gitlab.com/qemu-project/qemu/-/issues/2321
services.logind.lidSwitch = "ignore";

microvm = {
optimize.enable = false;
vcpu = 2;
Expand Down
1 change: 1 addition & 0 deletions overlays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The status of the integration in nixpkgs can be tracked using the [Pull Request

[gtklock: Fix black screen SP-4849](https://github.com/jovanlanik/gtklock/commit/e0e7f6d5ae7667fcc3479b6732046c67275b2f2f)

[qemu: virtio-pci: Fix the use of an uninitialized irqfd](https://gitlab.com/lulu6/gitlabqemutmp/-/commit/79dc606d30103cdaa0260df589319f4b59750947)

## carried in tiiuae/nixpkgs/...
[texinfo: cross compile failure](https://github.com/NixOS/nixpkgs/pull/328919)
7 changes: 6 additions & 1 deletion overlays/custom-packages/qemu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ in
patches = prev.patches ++ [./acpi-devices-passthrough-qemu-8.0.patch];
})
// (final.lib.optionalAttrs (final.lib.versionAtLeast qemu_version "8.1") {
patches = prev.patches ++ [./acpi-devices-passthrough-qemu-8.1.patch];
patches =
prev.patches
++ [
./acpi-devices-passthrough-qemu-8.1.patch
./virtio-pci-Fix-the-use-of-an-uninitialized-irqfd.patch
];
})
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From 79dc606d30103cdaa0260df589319f4b59750947 Mon Sep 17 00:00:00 2001
From: Cindy Lu <lulu@redhat.com>
Date: Sat, 15 Jun 2024 14:17:08 +0800
Subject: [PATCH] virtio-pci: Fix the use of an uninitialized irqfd.

The crash was reported in MAC OS and NixOS, here is the link for this bug
https://gitlab.com/qemu-project/qemu/-/issues/2334
https://gitlab.com/qemu-project/qemu/-/issues/2321

The root cause is the function virtio_pci_set_guest_notifiers() was not called
in the virtio_input device.So the vector_irqfd was not initialized

So the fix is to add the check for vector_irqfd.

This fix is verified in vyatta,MacOS,NixOS,fedora system.

The bt tree for this bug is:
Thread 6 "CPU 0/KVM" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7c817be006c0 (LWP 1269146)]
kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:817
817 if (irqfd->users == 0) {
(gdb) thread apply all bt
...
Thread 6 (Thread 0x7c817be006c0 (LWP 1269146) "CPU 0/KVM"):
0 kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:817
1 kvm_virtio_pci_vector_use_one () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:893
2 0x00005983657045e2 in memory_region_write_accessor () at ../qemu-9.0.0/system/memory.c:497
3 0x0000598365704ba6 in access_with_adjusted_size () at ../qemu-9.0.0/system/memory.c:573
4 0x0000598365705059 in memory_region_dispatch_write () at ../qemu-9.0.0/system/memory.c:1528
5 0x00005983659b8e1f in flatview_write_continue_step.isra.0 () at ../qemu-9.0.0/system/physmem.c:2713
6 0x000059836570ba7d in flatview_write_continue () at ../qemu-9.0.0/system/physmem.c:2743
7 flatview_write () at ../qemu-9.0.0/system/physmem.c:2774
8 0x000059836570bb76 in address_space_write () at ../qemu-9.0.0/system/physmem.c:2894
9 0x0000598365763afe in address_space_rw () at ../qemu-9.0.0/system/physmem.c:2904
10 kvm_cpu_exec () at ../qemu-9.0.0/accel/kvm/kvm-all.c:2917
11 0x000059836576656e in kvm_vcpu_thread_fn () at ../qemu-9.0.0/accel/kvm/kvm-accel-ops.c:50
12 0x0000598365926ca8 in qemu_thread_start () at ../qemu-9.0.0/util/qemu-thread-posix.c:541
13 0x00007c8185bcd1cf in ??? () at /usr/lib/libc.so.6
14 0x00007c8185c4e504 in clone () at /usr/lib/libc.so.6

Fixes: 2ce6cff94d ("virtio-pci: fix use of a released vector")
Cc: qemu-stable@nongnu.org

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
hw/virtio/virtio-pci.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index b1d02f4b3de..502aad28b24 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1442,7 +1442,9 @@ static void virtio_pci_set_vector(VirtIODevice *vdev,
* Otherwise just need to set the new vector on the device.
*/
if (kvm_irqfd && old_vector != VIRTIO_NO_VECTOR) {
- kvm_virtio_pci_vector_release_one(proxy, queue_no);
+ if (proxy->vector_irqfd) {
+ kvm_virtio_pci_vector_release_one(proxy, queue_no);
+ }
}
/* Set the new vector on the device. */
if (queue_no == VIRTIO_CONFIG_IRQ_IDX) {
@@ -1452,7 +1454,9 @@ static void virtio_pci_set_vector(VirtIODevice *vdev,
}
/* If the new vector changed need to set it up. */
if (kvm_irqfd && new_vector != VIRTIO_NO_VECTOR) {
- kvm_virtio_pci_vector_use_one(proxy, queue_no);
+ if (proxy->vector_irqfd) {
+ kvm_virtio_pci_vector_use_one(proxy, queue_no);
+ }
}
}

--
GitLab

0 comments on commit a39e2dd

Please sign in to comment.