Limit the amount of ram below 4G. This helps in scenarios like
GPU passthrough when the GPA used by DMA device is conflict with
the decode window of a host bridge and the address translation
request to iommu isn't launched, which causes address overlapping.
Note that currently this can be triggered by some abnormal behavior
of hardware.
In the general case, this option needs to be configured when virtual
machines share the same host, which is why using qemu.conf to support
per-host configuration.
Signed-off-by: yezhiyong <yezhiyong(a)bytedance.com>
Signed-off-by: zhenwei pi <pizhenwei(a)bytedance.com>
Signed-off-by: zhangruien <zhangruien(a)bytedance.com>
---
src/qemu/qemu.conf | 8 ++++++++
src/qemu/qemu_command.c | 4 ++++
src/qemu/qemu_conf.c | 5 +++++
src/qemu/qemu_conf.h | 1 +
4 files changed, 18 insertions(+)
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index 8722dc169c..f09c89486e 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -898,6 +898,14 @@
# NOTE: big files will be stored here
#memory_backing_dir = "/var/lib/libvirt/qemu/ram"
+# Limit the amount of ram below 4G. This helps in scenarios like
+# GPU passthrough when the GPA used by DMA device is comflict with
+# the decode window of a host bridge and the address translation
+# request to iommu isn't launched, which causes address overlapping.
+# Note that currently this can be triggered by some abnormal behavior
+# of hardware.
+#max_ram_below_4g = "2G"
+
# Path to the SCSI persistent reservations helper. This helper is
# used whenever <reservations/> are enabled for SCSI LUN devices.
#pr_helper = "/usr/bin/qemu-pr-helper"
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2f69a79bc0..fd5e14c500 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6960,6 +6960,10 @@ qemuBuildMachineCommandLine(virCommand *cmd,
cfg->dumpGuestCore ? "on" : "off");
}
+ if (cfg->maxRamBelow4G)
+ virBufferAsprintf(&buf, ",max-ram-below-4g=%s",
+ cfg->maxRamBelow4G);
+
if (def->mem.nosharepages)
virBufferAddLit(&buf, ",mem-merge=off");
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 916a3d36ee..b718995870 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -384,6 +384,8 @@ static void virQEMUDriverConfigDispose(void *obj)
g_strfreev(cfg->capabilityfilters);
g_free(cfg->deprecationBehavior);
+
+ g_free(cfg->maxRamBelow4G);
}
@@ -1001,6 +1003,9 @@ virQEMUDriverConfigLoadMemoryEntry(virQEMUDriverConfig *cfg,
g_autofree char *dir = NULL;
int rc;
+ if (virConfGetValueString(conf, "max_ram_below_4g",
&cfg->maxRamBelow4G) < 0)
+ return -1;
+
if ((rc = virConfGetValueString(conf, "memory_backing_dir", &dir)) <
0) {
return -1;
} else if (rc > 0) {
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 2f64e39a18..ff558e2fdb 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -216,6 +216,7 @@ struct _virQEMUDriverConfig {
bool virtiofsdDebug;
char *memoryBackingDir;
+ char *maxRamBelow4G;
uid_t swtpm_user;
gid_t swtpm_group;
--
2.24.3 (Apple Git-128)