Works for me on qemu-5.2.0-0.7.rc2.fc34.x86_64, libvirt v6.10.0-61-gd8c9cc3bd0 with this series patched:
guest kernel: kernel-5.10.0-0.rc5.20201125git127c501a03d5.85.fc33.x86_64 recompiled with VIRTIO_PMEM
Steps:
1. Start VM with <maxMemory> and <numa>:
Domain xml:
<domain type='kvm' id='5'>
<name>pc</name>
<uuid>bb508b28-d57b-44bd-9e9c-a134cef24b60</uuid>
<maxMemory slots='16' unit='KiB'>20972544</maxMemory>
<memory unit='KiB'>1048576</memory>
<cpu mode='custom' match='exact' check='full'>
<numa>
<cell id='0' cpus='0-3' memory='1048576' unit='KiB'/>
</numa>
</cpu>
...
</domain>
2. Attach the virtio memory device:
➜ ~ cat /tmp/virtio-mem.xml
<memory model='virtio'>
<target>
<size unit='KiB'>4194304</size>
<node>0</node>
<block unit='KiB'>2048</block>
<requested unit='KiB'>524288</requested>
</target>
</memory>
➜ ~ virsh attach-device pc /tmp/virtio-mem.xml
Device attached successfully
Before memory attached, the VM memory is:
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 879 124 601 2 152 615
Swap: 0 0 0
After:
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 1391 132 1106 2 153 1074
Swap: 0 0 0
3. Attach the virtio pmem device:
➜ ~ cat /tmp/virtio-pmem.xml
<memory model='virtio' access='shared'>
<source>
<path>/tmp/virtio_pmem</path>
<pmem/>
</source>
<target>
<size unit='KiB'>524288</size>
</target>
</memory>
➜ ~ virsh attach-device pc /tmp/virtio-pmem.xml
Device attached successfully
Check it in VM:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 10G 0 disk
└─vda1 252:1 0 10G 0 part /
pmem0 259:0 0 512M 0 disk
3. Try to detach them:
➜ ~ virsh detach-device pc /tmp/virtio-mem.xml
error: Failed to detach device from /tmp/virtio-mem.xml
error: internal error: unable to execute QEMU command 'device_del': virtio based memory devices cannot be unplugged.
➜ ~ virsh detach-device pc /tmp/virtio-pmem.xml
error: Failed to detach device from /tmp/virtio-pmem.xml
error: internal error: unable to execute QEMU command 'device_del': virtio based memory devices cannot be unplugged.