As noticed by Peter[1], the memory locking limit for the QEMU process is increased before assigning a VFIO device to a guest, but it might not be decreased when returning said device to the host. This series fixes this inconsistent behaviour and cleans up the code a little bit along the way. The idea is to introduce a new, smarter function called qemuDomainAdjustMaxMemLock() that does The Right Thing™ and increases the limit when required, while at the same time storing the original value. This way, when memory locking is no longer needed, it can restore it. I've tested this both on x86 and ppc64, both by removing devices that were assigned in the domain XML and devices that I had hotplugged. Patches 1-2 lay some groundwork by allowing retrieval of the memory locking limit for a process. Patches 3-4 add qemuDomainAdjustMaxMemLock() and use it where appropriate in the existing code. Patch 5 adds one more use of the function, after a PCI hostdev has been detached from the guest. Patch 6 replaces the use of Mlock with MemLock. Suggestions on how to further improve the names of those functions is very welcome, this is just a first step in the right direction. Cheers. [1] https://www.redhat.com/archives/libvir-list/2015-November/msg00642.html Andrea Bolognani (6): process: Allow virProcessPrLimit() to get current limit process: Add virProcessGetMaxMemLock() qemu: Add qemuDomainAdjustMaxMemLock() qemu: Use qemuDomainAdjustMaxMemLock() qemu: Reduce memlock limit after detaching hostdev qemu: Replace Mlock with MemLock in function names configure.ac | 2 +- src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain.c | 56 +++++++++++++++++++++++++++++++++++++++++++--- src/qemu/qemu_domain.h | 5 +++-- src/qemu/qemu_hotplug.c | 46 ++++++++++++++++---------------------- src/util/virprocess.c | 58 +++++++++++++++++++++++++++++++++++++++++++----- src/util/virprocess.h | 2 ++ 9 files changed, 136 insertions(+), 41 deletions(-) -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list