/**
* getPPC64MemLockLimitBytes:
* @def: domain definition
+ * @forceVFIO: force VFIO usage
*
* A PPC64 helper that calculates the memory locking limit in order for
* the guest to operate properly.
*/
static unsigned long long
-getPPC64MemLockLimitBytes(virDomainDefPtr def)
+getPPC64MemLockLimitBytes(virDomainDefPtr def,
+ bool forceVFIO)
{
unsigned long long memKB = 0;
unsigned long long baseLimit = 0;
passthroughLimit = maxMemory +
128 * (1ULL<<30) / 512 * nPCIHostBridges +
8192;
- } else if (usesVFIO) {
+ } else if (usesVFIO || forceVFIO) {
/* For regular (non-NVLink2 present) VFIO passthrough, the value
* of passthroughLimit is:
*
/**
* qemuDomainGetMemLockLimitBytes:
* @def: domain definition
+ * @forceVFIO: force VFIO calculation
*
* Calculate the memory locking limit that needs to be set in order for
* the guest to operate properly. The limit depends on a number of factors,
* including certain configuration options and less immediately apparent ones
* such as the guest architecture or the use of certain devices.
+ * The @forceVFIO argument can be used to tell this function will use VFIO even
+ * though @def doesn't indicates so right now.
*
* Returns: the memory locking limit, or 0 if setting the limit is not needed
*/
unsigned long long
-qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
+qemuDomainGetMemLockLimitBytes(virDomainDefPtr def,
+ bool forceVFIO)
{
unsigned long long memKB = 0;
bool usesVFIO = false;
return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
if (ARCH_IS_PPC64(def->os.arch) && def->virtType == VIR_DOMAIN_VIRT_KVM)
- return getPPC64MemLockLimitBytes(def);
+ return getPPC64MemLockLimitBytes(def, forceVFIO);
/* For device passthrough using VFIO the guest memory and MMIO memory
* regions need to be locked persistent in order to allow DMA.
*
* Note that this may not be valid for all platforms.
*/
- for (i = 0; i < def->nhostdevs; i++) {
- if (virHostdevIsVFIODevice(def->hostdevs[i]) ||
- virHostdevIsMdevDevice(def->hostdevs[i])) {
- usesVFIO = true;
- break;
+ if (!forceVFIO) {
+ for (i = 0; i < def->nhostdevs; i++) {
+ if (virHostdevIsVFIODevice(def->hostdevs[i]) ||
+ virHostdevIsMdevDevice(def->hostdevs[i])) {
+ usesVFIO = true;
+ break;
+ }
}
- }
- if (virDomainDefHasNVMeDisk(def))
- usesVFIO = true;
+ if (virDomainDefHasNVMeDisk(def))
+ usesVFIO = true;
+ }
- if (usesVFIO)
+ if (usesVFIO || forceVFIO)
memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
done:
/**
* qemuDomainAdjustMaxMemLock:
* @vm: domain
+ * @forceVFIO: apply VFIO requirements even if vm's def doesn't require it
*
* Adjust the memory locking limit for the QEMU process associated to @vm, in
- * order to comply with VFIO or architecture requirements.
+ * order to comply with VFIO or architecture requirements. If @forceVFIO is
+ * true then the limit is changed even if nothing in @vm's definition indicates
+ * so.
*
* The limit will not be changed unless doing so is needed; the first time
* the limit is changed, the original (default) limit is stored in @vm and
* Returns: 0 on success, <0 on failure
*/
int
-qemuDomainAdjustMaxMemLock(virDomainObjPtr vm)
+qemuDomainAdjustMaxMemLock(virDomainObjPtr vm,
+ bool forceVFIO)
{
unsigned long long bytes = 0;
int ret = -1;
- bytes = qemuDomainGetMemLockLimitBytes(vm->def);
+ bytes = qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO);
if (bytes) {
/* If this is the first time adjusting the limit, save the current
int ret = 0;
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
- if (qemuDomainAdjustMaxMemLock(vm) < 0)
+ if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
ret = -1;
vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
if (teardowndevice &&
qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0)
VIR_WARN("Unable to remove host device from /dev");
- if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0)
+ if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0)
VIR_WARN("Unable to reset maximum locked memory on hotplug fail");
if (releaseaddr)
if (virDomainMemoryInsert(vm->def, mem) < 0)
goto cleanup;
- if (qemuDomainAdjustMaxMemLock(vm) < 0)
+ if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
goto removedef;
qemuDomainObjEnterMonitor(driver, vm);
/* reset the mlock limit */
virErrorPreserveLast(&orig_err);
- ignore_value(qemuDomainAdjustMaxMemLock(vm));
+ ignore_value(qemuDomainAdjustMaxMemLock(vm, false));
virErrorRestore(&orig_err);
goto audit;
ret = 0;
cleanup:
if (ret < 0) {
- if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0)
+ if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0)
VIR_WARN("Unable to reset maximum locked memory on hotplug fail");
if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB_NONE));
/* decrease the mlock limit after memory unplug if necessary */
- ignore_value(qemuDomainAdjustMaxMemLock(vm));
+ ignore_value(qemuDomainAdjustMaxMemLock(vm, false));
return 0;
}
qemuDomainRemovePCIHostDevice(driver, vm, hostdev);
/* QEMU might no longer need to lock as much memory, eg. we just
* detached the last VFIO device, so adjust the limit here */
- if (qemuDomainAdjustMaxMemLock(vm) < 0)
+ if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
VIR_WARN("Failed to adjust locked memory limit");
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: