[PATCH v2] Allow slices for block backed NVRAM

John Levon posted 1 patch 1 week, 2 days ago
Failed in applying to current master (apply log)
src/qemu/qemu_validate.c                      | 32 ++++++++++----
...ual-efi-nvram-dev-slice.x86_64-latest.args | 35 ++++++++++++++++
...nual-efi-nvram-dev-slice.x86_64-latest.xml | 42 +++++++++++++++++++
.../firmware-manual-efi-nvram-dev-slice.xml   | 25 +++++++++++
tests/qemuxmlconftest.c                       |  1 +
5 files changed, 128 insertions(+), 7 deletions(-)
create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args
create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml
create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml
[PATCH v2] Allow slices for block backed NVRAM
Posted by John Levon 1 week, 2 days ago
For NVRAM storage specifically, the guest-visible size is critical to
correct handling of the OVMF address space. Allow specifying storage
slices for NVRAM storage when the underlying block may be larger
due to alignment/allocation restrictions.

As qemuPrepareNVRAMBlock() does not support it, disallow slices with
non-raw formats, and slice offsets.

Signed-off-by: John Levon <john.levon@nutanix.com>
---
 src/qemu/qemu_validate.c                      | 32 ++++++++++----
 ...ual-efi-nvram-dev-slice.x86_64-latest.args | 35 ++++++++++++++++
 ...nual-efi-nvram-dev-slice.x86_64-latest.xml | 42 +++++++++++++++++++
 .../firmware-manual-efi-nvram-dev-slice.xml   | 25 +++++++++++
 tests/qemuxmlconftest.c                       |  1 +
 5 files changed, 128 insertions(+), 7 deletions(-)
 create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args
 create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml
 create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 61f3bd3278..ae70eb89f0 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -707,8 +707,32 @@ qemuValidateDomainDefNvram(const virDomainDef *def,
 
     switch (src->type) {
     case VIR_STORAGE_TYPE_FILE:
-    case VIR_STORAGE_TYPE_BLOCK:
     case VIR_STORAGE_TYPE_NETWORK:
+        if (src->sliceStorage) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("slices are not supported with non-block NVRAM"));
+            return -1;
+        }
+        break;
+
+    case VIR_STORAGE_TYPE_BLOCK:
+        if (src->sliceStorage) {
+            if (src->sliceStorage->offset != 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("offset slices are not supported with NVRAM"));
+            }
+
+            switch (src->format) {
+            case VIR_STORAGE_FILE_RAW:
+            case VIR_STORAGE_FILE_NONE:
+                break;
+
+            default:
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("NVRAM slices are not supported with format '%1$s'"),
+                               virStorageFileFormatTypeToString(src->format));
+            }
+        }
         break;
 
     case VIR_STORAGE_TYPE_DIR:
@@ -728,12 +752,6 @@ qemuValidateDomainDefNvram(const virDomainDef *def,
         return -1;
     }
 
-    if (src->sliceStorage) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                        _("slices are not supported with NVRAM"));
-        return -1;
-    }
-
     if (src->pr) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                         _("persistent reservations are not supported with NVRAM"));
diff --git a/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args
new file mode 100644
index 0000000000..bb911d4ae1
--- /dev/null
+++ b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args
@@ -0,0 +1,35 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/var/lib/libvirt/qemu/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-guest/master-key.aes"}' \
+-blockdev '{"driver":"file","filename":"/usr/share/edk2/ovmf/OVMF_CODE.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \
+-blockdev '{"driver":"host_device","filename":"/dev/lv/guest_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"driver":"raw","file":"libvirt-pflash1-storage","offset":0,"size":540672,"node-name":"libvirt-0-slice-sto","read-only":false}' \
+-machine pc-i440fx-10.0,usb=off,dump-guest-core=off,memory-backend=pc.ram,pflash0=libvirt-pflash0-format,pflash1=libvirt-0-slice-sto,acpi=on \
+-accel tcg \
+-cpu qemu64 \
+-m size=1048576k \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=@mon-fd@,server=on,wait=off \
+-object '{"qom-type":"monitor-qmp","id":"monitor","chardev":"charmonitor"}' \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml
new file mode 100644
index 0000000000..9409c6a7a6
--- /dev/null
+++ b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml
@@ -0,0 +1,42 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <uuid>63840878-0deb-4095-97e6-fc444d9bc9fa</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os firmware='efi'>
+    <type arch='x86_64' machine='pc-i440fx-10.0'>hvm</type>
+    <firmware>
+      <feature enabled='no' name='enrolled-keys'/>
+      <feature enabled='no' name='secure-boot'/>
+    </firmware>
+    <loader readonly='yes' type='pflash' format='raw'>/usr/share/edk2/ovmf/OVMF_CODE.fd</loader>
+    <nvram template='/usr/share/edk2/ovmf/OVMF_VARS.fd' templateFormat='raw' type='block' format='raw'>
+      <source dev='/dev/lv/guest_VARS.fd'>
+        <slices>
+          <slice type='storage' offset='0' size='540672'/>
+        </slices>
+      </source>
+    </nvram>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <cpu mode='custom' match='exact' check='none'>
+    <model fallback='forbid'>qemu64</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' index='0' model='none'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <audio id='1' type='none'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml
new file mode 100644
index 0000000000..31cf086c2a
--- /dev/null
+++ b/tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <uuid>63840878-0deb-4095-97e6-fc444d9bc9fa</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc-i440fx-10.0'>hvm</type>
+    <loader readonly='yes' type='pflash'>/usr/share/edk2/ovmf/OVMF_CODE.fd</loader>
+    <nvram type='block'>
+      <source dev='/dev/lv/guest_VARS.fd'>
+        <slices>
+          <slice type="storage" offset="0" size="540672"/>
+        </slices>
+      </source>
+    </nvram>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' model='none'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c
index e0e64c6c38..3b6f97c2b0 100644
--- a/tests/qemuxmlconftest.c
+++ b/tests/qemuxmlconftest.c
@@ -1442,6 +1442,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("firmware-manual-efi-nvram-network-iscsi");
     DO_TEST_CAPS_LATEST("firmware-manual-efi-nvram-network-nbd");
     DO_TEST_CAPS_LATEST("firmware-manual-efi-nvram-file");
+    DO_TEST_CAPS_LATEST("firmware-manual-efi-nvram-dev-slice");
     DO_TEST_CAPS_LATEST_PARSE_ERROR("firmware-manual-efi-nvram-stateless");
 
     DO_TEST_CAPS_ARCH_LATEST_FULL("firmware-manual-efi-sev-snp", "x86_64",
-- 
2.43.0
Re: [PATCH v2] Allow slices for block backed NVRAM
Posted by Peter Krempa via Devel 3 days, 17 hours ago
On Fri, Aug 14, 2026 at 09:19:29 +0100, John Levon wrote:
> For NVRAM storage specifically, the guest-visible size is critical to
> correct handling of the OVMF address space. Allow specifying storage
> slices for NVRAM storage when the underlying block may be larger
> due to alignment/allocation restrictions.
> 
> As qemuPrepareNVRAMBlock() does not support it, disallow slices with
> non-raw formats, and slice offsets.
> 
> Signed-off-by: John Levon <john.levon@nutanix.com>
> ---
>  src/qemu/qemu_validate.c                      | 32 ++++++++++----
>  ...ual-efi-nvram-dev-slice.x86_64-latest.args | 35 ++++++++++++++++
>  ...nual-efi-nvram-dev-slice.x86_64-latest.xml | 42 +++++++++++++++++++
>  .../firmware-manual-efi-nvram-dev-slice.xml   | 25 +++++++++++
>  tests/qemuxmlconftest.c                       |  1 +
>  5 files changed, 128 insertions(+), 7 deletions(-)
>  create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.args
>  create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.x86_64-latest.xml
>  create mode 100644 tests/qemuxmlconfdata/firmware-manual-efi-nvram-dev-slice.xml
> 
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index 61f3bd3278..ae70eb89f0 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -707,8 +707,32 @@ qemuValidateDomainDefNvram(const virDomainDef *def,
>  
>      switch (src->type) {
>      case VIR_STORAGE_TYPE_FILE:
> -    case VIR_STORAGE_TYPE_BLOCK:
>      case VIR_STORAGE_TYPE_NETWORK:
> +        if (src->sliceStorage) {
> +            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +                           _("slices are not supported with non-block NVRAM"));
> +            return -1;
> +        }
> +        break;
> +
> +    case VIR_STORAGE_TYPE_BLOCK:
> +        if (src->sliceStorage) {
> +            if (src->sliceStorage->offset != 0) {
> +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +                               _("offset slices are not supported with NVRAM"));

Missing 'return -1;'


> +            }
> +
> +            switch (src->format) {
> +            case VIR_STORAGE_FILE_RAW:
> +            case VIR_STORAGE_FILE_NONE:
> +                break;
> +
> +            default:
> +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                               _("NVRAM slices are not supported with format '%1$s'"),
> +                               virStorageFileFormatTypeToString(src->format));

Missing 'return -1'. Also we normally prefer enum statements with a
proper type which are then forced by the compiler to cover all cases.

Since 'src->format' wasn't converted to proper type yet I think we can
leave it as-is.


> +            }
> +        }
>          break;
>  
>      case VIR_STORAGE_TYPE_DIR:
> @@ -728,12 +752,6 @@ qemuValidateDomainDefNvram(const virDomainDef *def,
>          return -1;
>      }
>  
> -    if (src->sliceStorage) {
> -        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> -                        _("slices are not supported with NVRAM"));
> -        return -1;
> -    }
> -
>      if (src->pr) {
>          virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>                          _("persistent reservations are not supported with NVRAM"));

I'll add the missing code and:

Reviewed-by: Peter Krempa <pkrempa@redhat.com>

and push this soon
Re: [PATCH v2] Allow slices for block backed NVRAM
Posted by John Levon 3 days, 17 hours ago
On Thu, Aug 20, 2026 at 04:27:30PM +0200, Peter Krempa wrote:

> > +    case VIR_STORAGE_TYPE_BLOCK:
> > +        if (src->sliceStorage) {
> > +            if (src->sliceStorage->offset != 0) {
> > +                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> > +                               _("offset slices are not supported with NVRAM"));
> 
> Missing 'return -1;'

Oops, apologies, thanks for review + fixing.

regards
john