Hi Peter,

 

Sorry for the incomplete description of the issue, we are working on a virtualization use case and trying to automate the VM creation and management using libvirt-python.

Since Libvirt is basically XML oriented, we wanted to convert the existing tested QEMU commands into Libvirt XML for VM management.

 

Below is the QEMU command – its SRIOV based GPU pass-thru in our system with KVM hypervisor

qemu-system-x86_64 \

-m 4096 \

-enable-kvm \

-cpu host \

-smp cores=6 \

-drive file=/usr/share/qemu/OVMF.fd,format=raw,if=pflash \

-drive id=ubuntu_drive,if=virtio,file=/home/ubuntu/ubuntu_1.qcow2,format=qcow2,cache=none \

-usb \

-device usb-tablet \

-device virtio-vga,max_outputs=1,blob=true \

-display gtk,gl=on \

-object memory-backend-memfd,id=mem1,size=4096M \

-machine memory-backend=mem1 \

-device vfio-pci,host=0000:00:02.2

 

Libvirt XML (Memory backing added)

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

  <name>ubuntu-vm-test</name>

  <memory unit="KiB">4194304</memory>

  <currentMemory unit="KiB">4194304</currentMemory>

   <memoryBacking>

    <source type='memfd'/>

  </memoryBacking>

  

  <vcpu>6</vcpu>

  <os>

    <loader>/usr/share/qemu/OVMF.fd</loader>

    <type arch="x86_64" machine="pc">hvm</type>

    <boot dev="hd" />

    <boot dev="cdrom" />

  </os>

  <features>

    <acpi />

    <apic />

  </features>

  <cpu mode='host-passthrough'>

  </cpu>

  <clock offset="utc">

  </clock>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>destroy</on_crash>

  <devices>

    <emulator>/usr/bin/qemu-system-x86_64</emulator>

    <disk type="file" device="disk">

       <driver name="qemu" type="qcow2" />

       <source file="=/home/ubuntu/ubuntu_1.qcow2" />

       <target dev="vda" bus="virtio" />

  </disk>

    <serial type="pty">

      <target port="0" />

      <target type="serial" port="0">

        </target>

      <alias name="serial0" />

    </serial>

    <console type="pty">

      <target type="serial" port="0" />

      <alias name="serial0" />

    </console>

    <hostdev mode="subsystem" type="pci" managed="yes">

    <driver name='vfio'/>

      <source>

              <address domain="0x0000" bus="0x00" slot="0x02" function="0x03" />

      </source>

        </hostdev>

     <video>

    <model type='virtio' virgl='off'/>

     <driver name='qemu'/>

     </video>

</devices>

<qemu:commandline>

    <qemu:arg value='-set'/>

    <qemu:arg value='device.video0.blob=false'/>

</qemu:commandline>

<qemu:commandline>

    <qemu:arg value='-display'/>

    <qemu:arg value='gtk,gl=on'/>

  </qemu:commandline>

</domain>

 

When we check the Libvirt logs, we noticed that converted XML to QEMU args are almost similar to the original

LC_ALL=C \

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin \

HOME=/var/lib/libvirt/qemu/domain-7-ubuntu-vm-test \

XDG_DATA_HOME=/var/lib/libvirt/qemu/domain-7-ubuntu-vm-test/.local/share \

XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain-7-ubuntu-vm-test/.cache \

XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain-7-ubuntu-vm-test/.config \

DISPLAY=:1.0 \

MESA_LOADER_DRIVER_OVERRIDE=i965 \

/usr/bin/qemu-system-x86_64 \

-name guest=ubuntu-vm-test,debug-threads=on \

-S \

-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain-7-ubuntu-vm-test/master-key.aes"}' \

-machine pc-i440fx-6.0,usb=off,dump-guest-core=off,memory-backend=pc.ram \

-accel kvm \

-cpu host,migratable=on \

-bios /usr/share/qemu/OVMF.fd \

-m 4096 \

-object '{"qom-type":"memory-backend-memfd","id":"pc.ram","x-use-canonical-path-for-ramblock-id":false,"size":4294967296}' \

-overcommit mem-lock=off \

-smp 6,sockets=6,cores=1,threads=1 \

-uuid 25e70b21-5dc9-44ff-9e7a-026ba637f521 \

-display none \

-no-user-config \

-nodefaults \

-chardev socket,id=charmonitor,fd=32,server=on,wait=off \

-mon chardev=charmonitor,id=monitor,mode=control \

-rtc base=utc \

-no-shutdown \

-boot strict=on \

-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \

-blockdev '{"driver":"file","filename":"/home/ubuntu/ubuntu_1.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \

-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2","file":"libvirt-1-storage","backing":null}' \

-device virtio-blk-pci,bus=pci.0,addr=0x3,drive=libvirt-1-format,id=virtio-disk0,bootindex=1 \

-chardev pty,id=charserial0 \

-device isa-serial,chardev=charserial0,id=serial0 \

-audiodev '{"id":"audio1","driver":"none"}' \

-device virtio-vga,id=video0,max_outputs=1,bus=pci.0,addr=0x2 \

-device vfio-pci,host=0000:00:02.3,id=hostdev0,bus=pci.0,addr=0x4 \

-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 \

-set device.video0.blob=false \

-display gtk,gl=on \

-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \

-msg timestamp=on

Our goal is to have GTK window enabled using libvirt-Python API, and we are seeing below issues with the lIbvirt but same commands working thgrough QEMU args.

2022-01-22T10:49:08.685664Z qemu-system-x86_64: egl: eglGetDisplay failed

2022-01-22T10:49:08.685792Z qemu-system-x86_64: OpenGL is not supported by the display

2022-01-22 10:49:08.688+0000: shutting down, reason=failed

 

I assume there must be some security policies set at the Libvirt side to access the OpenGL , please help us to resolve it .

 

Thanks,

Shiv

 

 

-----Original Message-----
From: Peter Krempa <pkrempa@redhat.com>
Sent: Thursday, January 27, 2022 3:37 PM
To: M, Shivakumar <shivakumar.m@intel.com>
Cc: libvirt-users@redhat.com; libvir-list@redhat.com
Subject: Re: Backend memory object creation - query

 

On Thu, Jan 27, 2022 at 04:05:19 +0000, M, Shivakumar wrote:

> Hello,

 

Hi,

 

note that there's no need to CC both libvir-list and libvirt-users maling lists.

 

>

>

> For our use-case with Libvirt we want to create the Memory backend

> object ,

>

> Expected QEMU args would be

> -object memory-backend-memfd,id=mem1,size=4096M

 

Your description is a bit vague. Do you want to use it to back the guest memory?

 

As by itself a memory object itself is useless without being attached somewhere

 

In case you want to configure qemu to back the default memory of the VM by a memfd:

 

Per https://www.libvirt.org/formatdomain.html#memory-backing

 

<domain type='kvm'>

...

 

<memoryBacking>

   <source type='memfd'/>

</memoryBacking>

...

</domain>

 

Results into invoking qemu with:

 

-machine pc-i440fx-2.9,usb=off,vmport=off,dump-guest-core=off,memory-backend=pc.ram \ ...

-object '{"qom-type":"memory-backend-memfd","id":"pc.ram","x-use-canonical-path-for-ramblock-id":false,"size":1048576000,"host-nodes":[0],"policy":"bind"}' \

 

 

>

> Request you to please help us to specify this arg in the libvirt XML.

>

> Thanks,

> Shiv