From 06b8b1c34c9092e8d81b619c4c1dd402042a77c2 Mon Sep 17 00:00:00 2001 From: Hao_Wang Date: Tue, 22 Sep 2020 14:35:57 +0800 Subject: [PATCH] backport upstream patches --- ...or-OOM-after-calling-xmlBufferCreate.patch | 98 ++++++++++++++++ libvirt-leaseshelper-Report-more-errors.patch | 64 +++++++++++ ...easeshelper-Wait-to-acquire-PID-file.patch | 43 +++++++ ...ramfb-attribute-for-mediated-devices.patch | 105 ++++++++++++++++++ ...ackendProps-Use-boolean-type-for-pme.patch | 55 +++++++++ ...rl-Do-not-open-directory-for-writing.patch | 38 +++++++ libvirt.spec | 6 + 7 files changed, 409 insertions(+) create mode 100644 libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch create mode 100644 libvirt-leaseshelper-Report-more-errors.patch create mode 100644 libvirt-leaseshelper-Wait-to-acquire-PID-file.patch create mode 100644 libvirt-qemu-format-ramfb-attribute-for-mediated-devices.patch create mode 100644 libvirt-qemuBuildMemoryBackendProps-Use-boolean-type-for-pme.patch create mode 100644 libvirt-resctrl-Do-not-open-directory-for-writing.patch diff --git a/libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch b/libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch new file mode 100644 index 0000000..779c554 --- /dev/null +++ b/libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch @@ -0,0 +1,98 @@ +From 657c7f5d79fe43823ffb4d46e244bea15a65baf6 Mon Sep 17 00:00:00 2001 +From: Laine Stump +Date: Thu, 18 Jun 2020 12:49:09 -0400 +Subject: [PATCH 1/6] conf, vmx: check for OOM after calling xmlBufferCreate() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Although libvirt itself uses g_malloc0() and friends, which exit when +there isn't enouogh memory, libxml2 uses standard malloc(), which just +returns NULL on OOM - this means we must check for NULL on return from +any libxml2 functions that allocate memory. + +xmlBufferCreate(), for example, might return NULL, and we don't always +check for it. This patch adds checks where it isn't already done. + +(NB: Although libxml2 has a provision for changing behavior on OOM (by +calling xmlMemSetup() to change what functions are used to +allocating/freeing memory), we can't use that, since parts of libvirt +code end up in libvirt.so, which is linked and called directly by +applications that may themselves use libxml2 (and may have already set +their own alternate malloc()), e.g. drivers like esx which live totally +in the library rather than a separate process.) + +Signed-off-by: Laine Stump +Reviewed-by: Ján Tomko +--- + src/conf/domain_conf.c | 6 +++++- + src/conf/network_conf.c | 6 +++++- + src/vmx/vmx.c | 11 +++++++---- + 3 files changed, 17 insertions(+), 6 deletions(-) + +diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c +index 914e03c..37c785a 100644 +--- a/src/conf/domain_conf.c ++++ b/src/conf/domain_conf.c +@@ -29022,7 +29022,11 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, + * Thankfully, libxml maps what looks like globals into + * thread-local uses, so we are thread-safe. */ + xmlIndentTreeOutput = 1; +- xmlbuf = xmlBufferCreate(); ++ if (!(xmlbuf = xmlBufferCreate())) { ++ virReportOOMError(); ++ goto error; ++ } ++ + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, + virBufferGetIndent(buf) / 2, 1) < 0) { + xmlBufferFree(xmlbuf); +diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c +index 819b645..c379042 100644 +--- a/src/conf/network_conf.c ++++ b/src/conf/network_conf.c +@@ -2478,7 +2478,11 @@ virNetworkDefFormatBuf(virBufferPtr buf, + * Thankfully, libxml maps what looks like globals into + * thread-local uses, so we are thread-safe. */ + xmlIndentTreeOutput = 1; +- xmlbuf = xmlBufferCreate(); ++ if (!(xmlbuf = xmlBufferCreate())) { ++ virReportOOMError(); ++ return -1; ++ } ++ + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, + virBufferGetIndent(buf) / 2, 1) < 0) { + xmlBufferFree(xmlbuf); +diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c +index b1fd118..fbc8366 100644 +--- a/src/vmx/vmx.c ++++ b/src/vmx/vmx.c +@@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string) + { + char *result = NULL; + xmlCharEncodingHandlerPtr handler; +- xmlBufferPtr input; +- xmlBufferPtr utf8; ++ xmlBufferPtr input = NULL; ++ xmlBufferPtr utf8 = NULL; + + handler = xmlFindCharEncodingHandler(encoding); + +@@ -708,8 +708,11 @@ virVMXConvertToUTF8(const char *encoding, const char *string) + return NULL; + } + +- input = xmlBufferCreateStatic((char *)string, strlen(string)); +- utf8 = xmlBufferCreate(); ++ if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) || ++ !(utf8 = xmlBufferCreate())) { ++ virReportOOMError(); ++ goto cleanup; ++ } + + if (xmlCharEncInFunc(handler, utf8, input) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, +-- +1.8.3.1 + diff --git a/libvirt-leaseshelper-Report-more-errors.patch b/libvirt-leaseshelper-Report-more-errors.patch new file mode 100644 index 0000000..1ce6ef8 --- /dev/null +++ b/libvirt-leaseshelper-Report-more-errors.patch @@ -0,0 +1,64 @@ +From cc842aa3030697b1a454e15ccfb2a201e57d5602 Mon Sep 17 00:00:00 2001 +From: Michal Privoznik +Date: Mon, 15 Jun 2020 12:53:48 +0200 +Subject: [PATCH 3/6] leaseshelper: Report more errors +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some functions or code paths that may fail don't report error +(e.g. when acquiring PID file fails) leading to a silent quit +of the leaseshelper. This makes it super hard for us and users +to debug what is happening. Fortunately, dnsmasq captures both +stdout and stderr so we can write an error message there. + +Signed-off-by: Michal Privoznik +Reviewed-by: Daniel P. Berrangé +--- + src/network/leaseshelper.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c +index 86c847d..2b5fc0f 100644 +--- a/src/network/leaseshelper.c ++++ b/src/network/leaseshelper.c +@@ -131,8 +131,10 @@ main(int argc, char **argv) + * events for expired leases. So, libvirtd sets another env var for this + * purpose */ + if (!interface && +- !(interface = getenv("VIR_BRIDGE_NAME"))) +- goto cleanup; ++ !(interface = getenv("VIR_BRIDGE_NAME"))) { ++ fprintf(stderr, _("interface not set\n")); ++ exit(EXIT_FAILURE); ++ } + + ip = argv[3]; + mac = argv[2]; +@@ -160,13 +162,21 @@ main(int argc, char **argv) + pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid"); + + /* Try to claim the pidfile, exiting if we can't */ +- if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0) ++ if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0) { ++ fprintf(stderr, ++ _("Unable to acquire PID file: %s\n errno=%d"), ++ pid_file, errno); + goto cleanup; ++ } + + /* Since interfaces can be hot plugged, we need to make sure that the + * corresponding custom lease file exists. If not, 'touch' it */ +- if (virFileTouch(custom_lease_file, 0644) < 0) ++ if (virFileTouch(custom_lease_file, 0644) < 0) { ++ fprintf(stderr, ++ _("Unable to create: %s\n errno=%d"), ++ custom_lease_file, errno); + goto cleanup; ++ } + + switch ((enum virLeaseActionFlags) action) { + case VIR_LEASE_ACTION_ADD: +-- +1.8.3.1 + diff --git a/libvirt-leaseshelper-Wait-to-acquire-PID-file.patch b/libvirt-leaseshelper-Wait-to-acquire-PID-file.patch new file mode 100644 index 0000000..353538e --- /dev/null +++ b/libvirt-leaseshelper-Wait-to-acquire-PID-file.patch @@ -0,0 +1,43 @@ +From 173b80e8f8103f26438d344e9b97335d4e5036b4 Mon Sep 17 00:00:00 2001 +From: Michal Privoznik +Date: Thu, 11 Jun 2020 16:43:22 +0200 +Subject: [PATCH 2/6] leaseshelper: Wait to acquire PID file +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +On a DHCP transaction, dnsmasq runs our leases helper which +updates corresponding JSON files. While one dnsmasq won't run the +leaseshelper in parallel, two dnsmasqs (from two distinct +networks) might. To avoid corrupting JSON file, the leaseshelper +acquires PID file first. Well, the way it's acquiring it is not +ideal - it calls virPidFileAcquirePath(wait = false); which +means, that either it acquires the PID file instantly or returns +an error and does not touch the JSON at all. This in turn means +that there might be a leases record missing. With wait = true, +this won't happen. + +Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1840307 + +Signed-off-by: Michal Privoznik +Reviewed-by: Daniel P. Berrangé +--- + src/network/leaseshelper.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c +index a1780ca..86c847d 100644 +--- a/src/network/leaseshelper.c ++++ b/src/network/leaseshelper.c +@@ -160,7 +160,7 @@ main(int argc, char **argv) + pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid"); + + /* Try to claim the pidfile, exiting if we can't */ +- if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0) ++ if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0) + goto cleanup; + + /* Since interfaces can be hot plugged, we need to make sure that the +-- +1.8.3.1 + diff --git a/libvirt-qemu-format-ramfb-attribute-for-mediated-devices.patch b/libvirt-qemu-format-ramfb-attribute-for-mediated-devices.patch new file mode 100644 index 0000000..cae85d2 --- /dev/null +++ b/libvirt-qemu-format-ramfb-attribute-for-mediated-devices.patch @@ -0,0 +1,105 @@ +From e017f95c7d833c0e9a463a1613d01fe93020606b Mon Sep 17 00:00:00 2001 +From: Jonathon Jongsma +Date: Tue, 23 Jun 2020 13:29:56 -0500 +Subject: [PATCH 5/6] qemu: format 'ramfb' attribute for mediated devices +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's possible to use ramfb as the boot display of an assigned vgpu +device. This was introduced in 4b95738c, but unfortunately the attribute +was not formatted into the xml output for such a device. This patch +fixes that oversight and adds a xml2xml test to verify proper behavior. + +https://bugzilla.redhat.com/show_bug.cgi?id=1847791 + +Signed-off-by: Jonathon Jongsma +Reviewed-by: Daniel Henrique Barboza +Signed-off-by: Ján Tomko +Reviewed-by: Ján Tomko +--- + src/conf/domain_conf.c | 3 ++ + .../hostdev-mdev-display-ramfb.x86_64-latest.xml | 44 ++++++++++++++++++++++ + tests/qemuxml2xmltest.c | 1 + + 3 files changed, 48 insertions(+) + create mode 100644 tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml + +diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c +index 37c785a..93e78a0 100644 +--- a/src/conf/domain_conf.c ++++ b/src/conf/domain_conf.c +@@ -27849,6 +27849,9 @@ virDomainHostdevDefFormat(virBufferPtr buf, + if (mdevsrc->display != VIR_TRISTATE_SWITCH_ABSENT) + virBufferAsprintf(buf, " display='%s'", + virTristateSwitchTypeToString(mdevsrc->display)); ++ if (mdevsrc->ramfb != VIR_TRISTATE_SWITCH_ABSENT) ++ virBufferAsprintf(buf, " ramfb='%s'", ++ virTristateSwitchTypeToString(mdevsrc->ramfb)); + } + + } +diff --git a/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml b/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml +new file mode 100644 +index 0000000..c134400 +--- /dev/null ++++ b/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml +@@ -0,0 +1,44 @@ ++ ++ QEMUGuest2 ++ c7a5fdbd-edaf-9455-926a-d65c16db1809 ++ 219136 ++ 219136 ++ 1 ++ ++ hvm ++ ++ ++ ++ qemu64 ++ ++ ++ destroy ++ restart ++ destroy ++ ++ /usr/bin/qemu-system-i386 ++ ++
++ ++ ++ ++
++ ++ ++ ++ ++ ++ ++