Bug 2216212

Summary: [RHEL9] Libvirt still requires a (DIMM) slot for virtio-mem devices
Product: Red Hat Enterprise Linux 9 Reporter: David Hildenbrand <dhildenb>
Component: libvirtAssignee: Peter Krempa <pkrempa>
libvirt sub component: General QA Contact: liang cong <lcong>
Status: VERIFIED --- Docs Contact:
Severity: unspecified    
Priority: unspecified CC: jdenemar, jsuchane, lmen, mprivozn, pkrempa, virt-maint
Version: 9.2Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-9.5.0-0rc1.1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version: 9.5.0
Embargoed:

Description David Hildenbrand 2023-06-20 14:08:57 UTC
Ever since QEMU commit 951f2269af2d ("vl: allow 'maxmem' without 'slot'") in 2018, QEMU has supported setting the "maxmem" option without the "slots" option.

That was a preparation for virtio-pmem and virtio-mem devices, that do not consume DIMM/NVDIMM slots.

Currently, in Libvirt, it's still required to reserve one slot for each virtio-mem and virtio-pmem device.


For example, specifying two virtio-mem devices with only 1 slot:

  <maxMemory slots='1' unit='KiB'>16777216</maxMemory>

results in

"error: unsupported configuration: memory device count '2' exceeds slots 
count '1'"


Specifying maxMemory without "slots" makes Libvirt angry:

  <maxMemory unit='KiB'>16777216</maxMemory>

"
error: XML document failed to validate against schema: Unable to 
validate doc against /usr/share/libvirt/schemas/domain.rng
Extra element maxMemory in interleave
Invalid sequence in interleave
Element domain failed to validate content
"

virtio-mem (and virtio-pmem) devices don't require a DIMM slot. To increase usability, virtio-based memory devices should not require/consume a slot in Libvirt, and it should be possible to define a domain using the maxMemory option and no slots. Old QEMU versions will report an error like "invalid value of -m option: maxmem was specified, but no hotplug slots were specified".

Comment 1 Peter Krempa 2023-06-28 14:53:00 UTC
Fixed upstream:

commit 91856be29bb38e218c9bfe29ca08a9fef57dc64f
Author: Peter Krempa <pkrempa>
Date:   Thu Jun 22 13:56:06 2023 +0200

    qemuxml2(argv|xml)test: Add case for validating proper DIMM slot validation
    
    Add a config where both DIMM and non-DIMM <memory> devices are used so
    that it validates that only DIMMs require memory slots.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit e4b4765f4f2b24035402510263021bcf55bbea38
Author: Peter Krempa <pkrempa>
Date:   Wed Jun 21 16:01:26 2023 +0200

    conf: Allow omitting 'slots' attribute of <maxMemory>
    
    Memory slots are required only for DIMM-like devices, but the maximum
    memory address space is relevant also for other non-DIMM memory devices
    such as virtio-mem. Allow configurations where no slots are added.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit e3ce39195c82c4e8f54ddad73e192d9317c9bb39
Author: Peter Krempa <pkrempa>
Date:   Wed Jun 21 15:31:24 2023 +0200

    qemu_domain: Properly validate count of memory slots
    
    Memory slots are required only for DIMM-like devices, while other
    devices defined via <memory> such as virtio-mem may use the PCI bus and
    thus do not require/consume a memory slot.
    
    Fix the validation code to calculate the required count of memory
    devices only for DIMMs and NVDIMMs.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit a52c68443d12e0c9be98137150b7e9314d87dac6
Author: Peter Krempa <pkrempa>
Date:   Wed Jun 21 16:31:46 2023 +0200

    qemu_command: Always use modern syntax of '-m'
    
    Specify the memory size by using '-m size=2048k' instead of just '-m 2'.
    
    The new syntax is used when memory hotplug is enabled. To preserve
    memory sizing, if memory hotplug is disabled the size is rounded down to
    the nearest mebibyte.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

v9.4.0-71-g91856be29b

Comment 2 liang cong 2023-07-05 06:58:18 UTC
Pre-verify on upstream build libvirt v9.5.0-10-gcd4bdcb8cf 

Test scenarios:
1.Virtio-mem cold plug with no slot
1.1 Define and start a guest with below config:
<maxMemory unit='KiB'>15242880</maxMemory>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
...
<numa>
    <cell id='0' cpus='0' memory='1048576' unit='KiB' />
    <cell id='1' cpus='1' memory='1048576' unit='KiB' />
</numa>
...
<memory model='virtio-mem'>
     <target>
       <size unit='KiB'>2097152</size>
       <node>0</node>
       <block unit='KiB'>2048</block>
       <requested unit='KiB'>1048576</requested>
     </target>
</memory>

# virsh define vm1.xml
Domain 'vm1' defined from vm1.xml

# virsh start vm1
Domain 'vm1' started


1.2 Check the virsh dumpxml
# virsh dumpxml vm1 | xmllint --xpath '//devices/memory' -
<memory model="virtio-mem">
      <target>
        <size unit="KiB">2097152</size>
        <node>0</node>
        <block unit="KiB">2048</block>
        <requested unit="KiB">1048576</requested>
        <current unit="KiB">1048576</current>
        <address base="0x100000000"/>
      </target>
      <alias name="virtiomem0"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </memory>

1.3 Attach a dimm memory device
# virsh attach-device vm1 dimm.xml 
error: Failed to attach device from dimm.xml
error: unsupported configuration: count of memory devices requiring memory slots '1' exceeds slots count '0'

1.4 Attach another virtio-mem device
# virsh attach-device vm1 virtio.xml 
Device attached successfully


2 Virtio-mem cold plug with 1 slot
2.1 Define and start a guest with below config:
<maxMemory unit='KiB' slots='1'>15242880</maxMemory>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
...
<numa>
    <cell id='0' cpus='0' memory='1048576' unit='KiB' />
    <cell id='1' cpus='1' memory='1048576' unit='KiB' />
</numa>
...
<memory model='virtio-mem'>
     <target>
       <size unit='KiB'>2097152</size>
       <node>0</node>
       <block unit='KiB'>2048</block>
       <requested unit='KiB'>1048576</requested>
     </target>
</memory>

# virsh define vm1.xml
Domain 'vm1' defined from vm1.xml

# virsh start vm1
Domain 'vm1' started

2.2 Check the virsh dumpxml
# virsh dumpxml vm1 | xmllint --xpath '//devices/memory' -
<memory model="virtio-mem">
      <target>
        <size unit="KiB">2097152</size>
        <node>0</node>
        <block unit="KiB">2048</block>
        <requested unit="KiB">1048576</requested>
        <current unit="KiB">1048576</current>
        <address base="0x100000000"/>
      </target>
      <alias name="virtiomem0"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </memory>

2.3 Attach a dimm memory device
# virsh attach-device vm1 dimm.xml 
Device attached successfully

2.4 Attach a nvdimm memory device
# virsh attach-device vm1 nvdimm.xml 
error: Failed to attach device from nvdimm.xml
error: unsupported configuration: count of memory devices requiring memory slots '2' exceeds slots count '1'

2.5 Attach another virtio-mem device
# virsh attach-device vm1 virtio.xml 
Device attached successfully


Also test other scenarios, such as: dimm|nvdimm device with no|scarcy slot

Comment 3 liang cong 2023-07-25 09:45:25 UTC
Verified on build:
# rpm -q libvirt qemu-kvm
libvirt-9.5.0-3.el9.x86_64
qemu-kvm-8.0.0-9.el9.x86_64

Test scenarios:
1.Virtio-mem cold plug with no slot
1.1 Define and start a guest with below config:
<maxMemory unit='KiB'>15242880</maxMemory>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
...
<numa>
    <cell id='0' cpus='0' memory='1048576' unit='KiB' />
    <cell id='1' cpus='1' memory='1048576' unit='KiB' />
</numa>
...
<memory model='virtio-mem'>
     <target>
       <size unit='KiB'>2097152</size>
       <node>0</node>
       <block unit='KiB'>2048</block>
       <requested unit='KiB'>1048576</requested>
     </target>
</memory>

# virsh define vm1.xml
Domain 'vm1' defined from vm1.xml

# virsh start vm1
Domain 'vm1' started


1.2 Check the virsh dumpxml
# virsh dumpxml vm1 | xmllint --xpath '//devices/memory' -
<memory model="virtio-mem">
      <target>
        <size unit="KiB">2097152</size>
        <node>0</node>
        <block unit="KiB">2048</block>
        <requested unit="KiB">1048576</requested>
        <current unit="KiB">1048576</current>
        <address base="0x100000000"/>
      </target>
      <alias name="virtiomem0"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </memory>


1.3 Attach a dimm memory device
# virsh attach-device vm1 mem.xml 
error: Failed to attach device from mem.xml
error: unsupported configuration: count of memory devices requiring memory slots '1' exceeds slots count '0'

1.4 Attach another virtio-mem device
# virsh attach-device vm1 virtio-mem.xml 
Device attached successfully


2 Virtio-mem cold plug with 1 slot
2.1 Define and start a guest with below config:
<maxMemory unit='KiB' slots='1'>15242880</maxMemory>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
...
<numa>
    <cell id='0' cpus='0' memory='1048576' unit='KiB' />
    <cell id='1' cpus='1' memory='1048576' unit='KiB' />
</numa>
...
<memory model='virtio-mem'>
     <target>
       <size unit='KiB'>2097152</size>
       <node>0</node>
       <block unit='KiB'>2048</block>
       <requested unit='KiB'>1048576</requested>
     </target>
</memory>

# virsh define vm1.xml
Domain 'vm1' defined from vm1.xml

# virsh start vm1
Domain 'vm1' started

2.2 Check the virsh dumpxml
# virsh dumpxml vm1 | xmllint --xpath '//devices/memory' -
<memory model="virtio-mem">
      <target>
        <size unit="KiB">2097152</size>
        <node>0</node>
        <block unit="KiB">2048</block>
        <requested unit="KiB">1048576</requested>
        <current unit="KiB">1048576</current>
        <address base="0x100000000"/>
      </target>
      <alias name="virtiomem0"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </memory>

2.3 Attach a dimm and a virtio-mem memory device
# virsh attach-device vm1 virtio-mem.xml 
Device attached successfully

# virsh attach-device vm1 mem.xml 
Device attached successfully

2.4 Attach a nvdimm memory device
# virsh attach-device vm1 nvdimm.xml 
error: Failed to attach device from nvdimm.xml
error: unsupported configuration: count of memory devices requiring memory slots '2' exceeds slots count '1'


2.5 Attach another virtio-mem device
# virsh attach-device vm1 virtio-mem.xml 
Device attached successfully


Also test other scenarios, such as: dimm|nvdimm device with no|scarcy slot

Comment 6 liang cong 2023-08-07 03:25:47 UTC
mark it verified per comment 3