public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support
@ 2026-09-14  9:20 Kaiyang Wu
  2026-09-14  9:20 ` [PATCH qemu-server 1/5] qemuserver: add pvpanic device Kaiyang Wu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

This patchset adds pvpanic device support to QEMU virtual machines to
provide extra virtual machine status (guest-panicked) when virtual
machines panic [0]. The HA stack now restarts a "started" VM when it
panics.

[0]: https://www.qemu.org/docs/master/specs/pvpanic.html

v1: https://lore.proxmox.com/pve-devel/20260827103529.393388-1-wukaiyang@loongfans.cn/

Changes v1 -> v2:
- Remove the pvpanic ISA device support to simplify the code
- Move the pvpanic setting from Hardware to Options
- Restart a HA-managed VM when it panics to restore the "started" state


qemu-server:

Kaiyang Wu (1):
  qemuserver: add pvpanic device

 src/PVE/API2/Qemu.pm      |  1 +
 src/PVE/QemuServer.pm     | 11 +++++++++++
 src/PVE/QemuServer/PCI.pm |  1 +
 3 files changed, 13 insertions(+)


docs:

Kaiyang Wu (1):
  qm: add document section for the pvpanic device

 qm.adoc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)


manager:

Kaiyang Wu (1):
  ui: qemu: add pvpanic device support

 www/manager6/qemu/Options.js | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)


ha-manager:

Kaiyang Wu (2):
  vm resource: return running status -1 for panicked VMs
  lrm: stop and restart panicked VMs to keep the "started" state

 src/PVE/HA/LRM.pm             | 9 ++++++++-
 src/PVE/HA/Resources/PVEVM.pm | 5 ++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

-- 
2.55.0




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH qemu-server 1/5] qemuserver: add pvpanic device
  2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
@ 2026-09-14  9:20 ` Kaiyang Wu
  2026-09-14  9:20 ` [PATCH docs 2/5] qm: add document section for the " Kaiyang Wu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

Add pvpanic PCI device to monitor guest system panics.

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
---
 src/PVE/API2/Qemu.pm      |  1 +
 src/PVE/QemuServer.pm     | 11 +++++++++++
 src/PVE/QemuServer/PCI.pm |  1 +
 3 files changed, 13 insertions(+)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 714c87a9..d60e90a8 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -818,6 +818,7 @@ my $hwtypeoptions = {
     'watchdog' => 1,
     'audio0' => 1,
     'rng0' => 1,
+    'pvpanic' => 1,
 };
 
 my $generaloptions = {
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 5849392e..facbb06a 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -740,6 +740,12 @@ EODESCR
         optional => 1,
         default => 1,
     },
+    pvpanic => {
+        optional => 1,
+        type => 'boolean',
+        description => "Configure a pvpanic device to monitor guest panics",
+        default => 0,
+    },
 };
 
 my $cicustom_fmt = {
@@ -3439,6 +3445,11 @@ sub config_to_command {
         push @$cmd, '-nographic';
     }
 
+    if (defined($conf->{pvpanic}) && $conf->{pvpanic}) {
+        my $pvpanicpciaddr = print_pci_addr("pvpanic", $arch);
+        push @$devices, '-device', "pvpanic-pci,id=pvpanic$pvpanicpciaddr";
+    }
+
     # For now, handles only specific parts, but the final goal is to cover everything.
     my $cfg2cmd_opts = { forcemachine => $forcemachine };
     my $cfg2cmd = PVE::QemuServer::Cfg2Cmd->new($conf, $defaults, $version_guard, $cfg2cmd_opts);
diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm
index 35e18ad9..faaeffca 100644
--- a/src/PVE/QemuServer/PCI.pm
+++ b/src/PVE/QemuServer/PCI.pm
@@ -220,6 +220,7 @@ sub get_pci_addr_map {
         'pci.4' => { bus => 1, addr => 28 },
         'rng0' => { bus => 1, addr => 29 },
         'pci.2-igd' => { bus => 1, addr => 30 }, # replaces pci.2 in case a legacy IGD device is passed through
+        'pvpanic' => { bus => 1, addr => 31 },
         'virtio6' => { bus => 2, addr => 1 },
         'virtio7' => { bus => 2, addr => 2 },
         'virtio8' => { bus => 2, addr => 3 },
-- 
2.55.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH docs 2/5] qm: add document section for the pvpanic device
  2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
  2026-09-14  9:20 ` [PATCH qemu-server 1/5] qemuserver: add pvpanic device Kaiyang Wu
@ 2026-09-14  9:20 ` Kaiyang Wu
  2026-09-14  9:20 ` [PATCH manager 3/5] ui: qemu: add pvpanic device support Kaiyang Wu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

Document the pvpanic device and corresponding driver requirements on
different VMs.

Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
---
 qm.adoc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/qm.adoc b/qm.adoc
index 18a4fbe..49376ec 100644
--- a/qm.adoc
+++ b/qm.adoc
@@ -1476,6 +1476,28 @@ tag (name used to mount the device on the guest).
 For more information on available virtiofsd parameters, see the
 https://gitlab.com/virtio-fs/virtiofsd[GitLab virtiofsd project page].
 
+[[qm_pvpanic]]
+Pvpanic
+~~~~~~~
+
+Pvpanic is a device to send system panic events to QEMU. It allows to
+provide extra VM status when the VM system crashes.
+
+To add a pvpanic PCI device run the following command:
+
+----
+qm set <vmid> -pvpanic 1
+----
+
+Linux VMs with kernel >=5.2 support pvpanic PCI device by default
+(https://www.kernelconfig.io/CONFIG_PVPANIC_PCI[pvpanic PCI driver]).
+
+Windows VMs require
+https://github.com/virtio-win/kvm-guest-drivers-windows/[kvm-guest-drivers-windows]
+to use pvpanic.
+
+FreeBSD VMs do not support pvpanic.
+
 [[qm_bootorder]]
 Device Boot Order
 ~~~~~~~~~~~~~~~~~
-- 
2.55.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH manager 3/5] ui: qemu: add pvpanic device support
  2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
  2026-09-14  9:20 ` [PATCH qemu-server 1/5] qemuserver: add pvpanic device Kaiyang Wu
  2026-09-14  9:20 ` [PATCH docs 2/5] qm: add document section for the " Kaiyang Wu
@ 2026-09-14  9:20 ` Kaiyang Wu
  2026-09-14  9:20 ` [PATCH ha-manager 4/5] vm resource: return running status -1 for panicked VMs Kaiyang Wu
  2026-09-14  9:20 ` [PATCH ha-manager 5/5] lrm: stop and restart panicked VMs to keep the "started" state Kaiyang Wu
  4 siblings, 0 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

Add basic structure for adding a pvpanic device, allowing to monitor
guest system panics through the pvpanic device.

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
---
 www/manager6/qemu/Options.js | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/www/manager6/qemu/Options.js b/www/manager6/qemu/Options.js
index 73e27500..157ab7b6 100644
--- a/www/manager6/qemu/Options.js
+++ b/www/manager6/qemu/Options.js
@@ -313,6 +313,26 @@ Ext.define('PVE.qemu.Options', {
                       }
                     : undefined,
             },
+            pvpanic: {
+                header: gettext('Panic Monitor'),
+                defaultValue: false,
+                renderer: Proxmox.Utils.format_boolean,
+                editor: caps.vms['VM.Config.HWType']
+                    ? {
+                          xtype: 'proxmoxWindowEdit',
+                          subject: gettext('Panic Monitor'),
+                          onlineHelp: 'qm_pvpanic',
+                          items: {
+                              xtype: 'proxmoxcheckbox',
+                              name: 'pvpanic',
+                              uncheckedValue: 0,
+                              defaultValue: 0,
+                              deleteDefaultValue: true,
+                              fieldLabel: gettext('Panic Monitor'),
+                          },
+                      }
+                    : undefined,
+            },
             protection: {
                 header: gettext('Protection'),
                 defaultValue: false,
-- 
2.55.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH ha-manager 4/5] vm resource: return running status -1 for panicked VMs
  2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
                   ` (2 preceding siblings ...)
  2026-09-14  9:20 ` [PATCH manager 3/5] ui: qemu: add pvpanic device support Kaiyang Wu
@ 2026-09-14  9:20 ` Kaiyang Wu
  2026-09-14  9:20 ` [PATCH ha-manager 5/5] lrm: stop and restart panicked VMs to keep the "started" state Kaiyang Wu
  4 siblings, 0 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

Indicate the panicked status used to stop the VM before restarting it to
keep the 'started' state. Keep the return value truthy to shutdown the
VM when needed (e.g. 'stopped' state).

Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
---
 src/PVE/HA/Resources/PVEVM.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index 8753271..51c7bac 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -143,10 +143,13 @@ sub check_running {
     my $nodename = $haenv->nodename();
 
     if (PVE::QemuServer::check_running($vmid, 1, $nodename)) {
+        # return -1 to indicate the panicked status while keeping it truthy
+        my $qmpstatus = eval { PVE::QemuServer::Monitor::mon_cmd($vmid, 'query-status') };
+        return -1 if defined($qmpstatus) && $qmpstatus->{status} eq 'guest-panicked';
+
         # do not count VMs which are suspended for a backup job as running
         my $conf = PVE::QemuConfig->load_config($vmid, $nodename);
         if (defined($conf->{lock}) && $conf->{lock} eq 'backup') {
-            my $qmpstatus = eval { PVE::QemuServer::Monitor::mon_cmd($vmid, 'query-status') };
             $haenv->log('warning', "$@") if $@;
 
             return 0 if defined($qmpstatus) && $qmpstatus->{status} eq 'prelaunch';
-- 
2.55.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH ha-manager 5/5] lrm: stop and restart panicked VMs to keep the "started" state
  2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
                   ` (3 preceding siblings ...)
  2026-09-14  9:20 ` [PATCH ha-manager 4/5] vm resource: return running status -1 for panicked VMs Kaiyang Wu
@ 2026-09-14  9:20 ` Kaiyang Wu
  4 siblings, 0 replies; 6+ messages in thread
From: Kaiyang Wu @ 2026-09-14  9:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Kaiyang Wu

When a VM panics, 'check_running()' returns -1 to indicate the panicked
state. Stop the service first since panicked VMs are still running, then
restart the service to keep the "started" state.

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
---
 src/PVE/HA/LRM.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 72e37e6..8fa1ff6 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -982,7 +982,14 @@ sub exec_resource_agent {
 
     if ($cmd eq 'started') {
 
-        return SUCCESS if $running;
+        return SUCCESS if $running == 1; # running normally
+
+        # stop the panicked service before restarting it
+        if ($running == -1) {
+            $haenv->log("info", "stopping panicked service $sid");
+
+            $plugin->shutdown($haenv, $id, 0);
+        }
 
         $haenv->log("info", "starting service $sid");
 
-- 
2.55.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-14  9:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14  9:20 [PATCH qemu-server/docs/manager/ha-manager 0/5] add pvpanic device support Kaiyang Wu
2026-09-14  9:20 ` [PATCH qemu-server 1/5] qemuserver: add pvpanic device Kaiyang Wu
2026-09-14  9:20 ` [PATCH docs 2/5] qm: add document section for the " Kaiyang Wu
2026-09-14  9:20 ` [PATCH manager 3/5] ui: qemu: add pvpanic device support Kaiyang Wu
2026-09-14  9:20 ` [PATCH ha-manager 4/5] vm resource: return running status -1 for panicked VMs Kaiyang Wu
2026-09-14  9:20 ` [PATCH ha-manager 5/5] lrm: stop and restart panicked VMs to keep the "started" state Kaiyang Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal