diff --git a/kvm-hw-i386-Fix-machine-type-compatibility.patch b/kvm-hw-i386-Fix-machine-type-compatibility.patch new file mode 100644 index 0000000..430ba65 --- /dev/null +++ b/kvm-hw-i386-Fix-machine-type-compatibility.patch @@ -0,0 +1,87 @@ +From 2bb5dff02fb393530a12f4f00219cd2f90cd442a Mon Sep 17 00:00:00 2001 +From: Sebastian Ott +Date: Thu, 15 May 2025 18:45:51 +0200 +Subject: [PATCH 3/5] hw/i386: Fix machine type compatibility + +RH-Author: Sebastian Ott +RH-MergeRequest: 364: hw/i386: Fix machine type compatibility +RH-Jira: RHEL-91307 +RH-Acked-by: Cornelia Huck +RH-Acked-by: Jon Maloy +RH-Commit: [1/1] 44ddbcb3af119c65e99018d7ed90887f3948907e (seott1/cos-qemu-kvm) + +Upstream Status: RHEL only + +Ensure compatibility of rhel specific i440fx and q35 machine types. +Pick up missing bits from pc_compat_9_0 upstream. + +Signed-off-by: Sebastian Ott +--- + hw/i386/pc.c | 8 ++++++++ + hw/i386/pc_piix.c | 2 ++ + hw/i386/pc_q35.c | 2 ++ + include/hw/i386/pc.h | 3 +++ + 4 files changed, 15 insertions(+) + +diff --git a/hw/i386/pc.c b/hw/i386/pc.c +index fa9f16cbaf..5237538640 100644 +--- a/hw/i386/pc.c ++++ b/hw/i386/pc.c +@@ -298,6 +298,14 @@ GlobalProperty pc_rhel_compat[] = { + }; + const size_t pc_rhel_compat_len = G_N_ELEMENTS(pc_rhel_compat); + ++GlobalProperty pc_rhel_9_6_compat[] = { ++ /* pc_rhel_9_6_compat from pc_compat_9_0 */ ++ { TYPE_X86_CPU, "x-amd-topoext-features-only", "false" }, ++ { TYPE_X86_CPU, "x-l1-cache-per-thread", "false" }, ++ { TYPE_X86_CPU, "legacy-multi-node", "on" }, ++}; ++const size_t pc_rhel_9_6_compat_len = G_N_ELEMENTS(pc_rhel_9_6_compat); ++ + GlobalProperty pc_rhel_9_5_compat[] = { + /* pc_rhel_9_5_compat from pc_compat_pc_9_0 (backported from 9.1) */ + { TYPE_X86_CPU, "guest-phys-bits", "0" }, +diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c +index 10764bf596..0687317db5 100644 +--- a/hw/i386/pc_piix.c ++++ b/hw/i386/pc_piix.c +@@ -885,6 +885,8 @@ static void pc_i440fx_rhel_machine_7_6_0_options(MachineClass *m) + + compat_props_add(m->compat_props, hw_compat_rhel_9_6, + hw_compat_rhel_9_6_len); ++ compat_props_add(m->compat_props, pc_rhel_9_6_compat, ++ pc_rhel_9_6_compat_len); + compat_props_add(m->compat_props, pc_rhel_9_5_compat, + pc_rhel_9_5_compat_len); + compat_props_add(m->compat_props, hw_compat_rhel_9_5, +diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c +index 5bf08be0fb..871c760aea 100644 +--- a/hw/i386/pc_q35.c ++++ b/hw/i386/pc_q35.c +@@ -704,6 +704,8 @@ static void pc_q35_rhel_machine_9_4_0_options(MachineClass *m) + + compat_props_add(m->compat_props, hw_compat_rhel_9_6, + hw_compat_rhel_9_6_len); ++ compat_props_add(m->compat_props, pc_rhel_9_6_compat, ++ pc_rhel_9_6_compat_len); + compat_props_add(m->compat_props, pc_rhel_9_5_compat, + pc_rhel_9_5_compat_len); + compat_props_add(m->compat_props, hw_compat_rhel_9_5, +diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h +index 75c9271cdd..2b7c18f2b0 100644 +--- a/include/hw/i386/pc.h ++++ b/include/hw/i386/pc.h +@@ -305,6 +305,9 @@ extern const size_t pc_compat_2_3_len; + extern GlobalProperty pc_rhel_compat[]; + extern const size_t pc_rhel_compat_len; + ++extern GlobalProperty pc_rhel_9_6_compat[]; ++extern const size_t pc_rhel_9_6_compat_len; ++ + extern GlobalProperty pc_rhel_9_5_compat[]; + extern const size_t pc_rhel_9_5_compat_len; + +-- +2.48.1 + diff --git a/kvm-meson-configure-add-valgrind-option-en-dis-able-valg.patch b/kvm-meson-configure-add-valgrind-option-en-dis-able-valg.patch new file mode 100644 index 0000000..93c87f9 --- /dev/null +++ b/kvm-meson-configure-add-valgrind-option-en-dis-able-valg.patch @@ -0,0 +1,110 @@ +From 0277328b5a2d1df5d9843423ab5f5fa9481bad79 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= +Date: Fri, 25 Apr 2025 13:17:12 +0100 +Subject: [PATCH 1/5] meson/configure: add 'valgrind' option & --{en, + dis}able-valgrind flag +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +RH-Author: Daniel P. Berrangé +RH-MergeRequest: 359: distro: add an explicit valgrind-devel build dep +RH-Jira: RHEL-88153 +RH-Acked-by: Eric Blake +RH-Acked-by: Jon Maloy +RH-Commit: [1/2] ba9bc44ef9cef6fa76e2092500608575f223f1f7 (berrange/centos-src-qemu) + +Currently valgrind debugging support for coroutine stacks is enabled +unconditionally when valgrind/valgrind.h is found. There is no way +to disable valgrind support if valgrind.h is present in the build env. + +This is bad for distros, as an dependency far down the chain may cause +valgrind.h to become installed, inadvertently enabling QEMU's valgrind +debugging support. It also means if a distro wants valgrind support +there is no way to mandate this. + +The solution is to add a 'valgrind' build feature to meson and thus +configure script. + +Signed-off-by: Daniel P. Berrangé +Reviewed-by: Thomas Huth +Message-ID: <20250425121713.1913424-1-berrange@redhat.com> +Signed-off-by: Thomas Huth +(cherry picked from commit 6b1c744ec0d66d6d568f9a156282153fc11a21cf) + +Conflicts: + meson.build - context from upstream is not present in older tree +--- + meson.build | 13 ++++++++++++- + meson_options.txt | 2 ++ + scripts/meson-buildoptions.sh | 3 +++ + 3 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/meson.build b/meson.build +index 1dd97c6f49..5bb2b757c3 100644 +--- a/meson.build ++++ b/meson.build +@@ -2463,7 +2463,17 @@ config_host_data.set('CONFIG_FSTRIM', qga_fstrim) + # has_header + config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) + config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +-config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) ++valgrind = false ++if get_option('valgrind').allowed() ++ if cc.has_header('valgrind/valgrind.h') ++ valgrind = true ++ else ++ if get_option('valgrind').enabled() ++ error('valgrind requested but valgrind.h not found') ++ endif ++ endif ++endif ++config_host_data.set('CONFIG_VALGRIND_H', valgrind) + config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) + config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h')) + config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h')) +@@ -4549,6 +4559,7 @@ summary_info += {'libdw': libdw} + if host_os == 'freebsd' + summary_info += {'libinotify-kqueue': inotify} + endif ++summary_info += {'valgrind': valgrind} + summary(summary_info, bool_yn: true, section: 'Dependencies') + + if host_arch == 'unknown' +diff --git a/meson_options.txt b/meson_options.txt +index aa2ba0baef..da06441fdf 100644 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -113,6 +113,8 @@ option('dbus_display', type: 'feature', value: 'auto', + description: '-display dbus support') + option('tpm', type : 'feature', value : 'auto', + description: 'TPM support') ++option('valgrind', type : 'feature', value: 'auto', ++ description: 'valgrind debug support for coroutine stacks') + + # Do not enable it by default even for Mingw32, because it doesn't + # work on Wine. +diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh +index 5f0cbfc725..251470ea6d 100644 +--- a/scripts/meson-buildoptions.sh ++++ b/scripts/meson-buildoptions.sh +@@ -191,6 +191,7 @@ meson_options_help() { + printf "%s\n" ' u2f U2F emulation support' + printf "%s\n" ' uadk UADK Library support' + printf "%s\n" ' usb-redir libusbredir support' ++ printf "%s\n" ' valgrind valgrind debug support for coroutine stacks' + printf "%s\n" ' vde vde network backend support' + printf "%s\n" ' vdi vdi image format support' + printf "%s\n" ' vduse-blk-export' +@@ -509,6 +510,8 @@ _meson_option_parse() { + --disable-uadk) printf "%s" -Duadk=disabled ;; + --enable-usb-redir) printf "%s" -Dusb_redir=enabled ;; + --disable-usb-redir) printf "%s" -Dusb_redir=disabled ;; ++ --enable-valgrind) printf "%s" -Dvalgrind=enabled ;; ++ --disable-valgrind) printf "%s" -Dvalgrind=disabled ;; + --enable-vde) printf "%s" -Dvde=enabled ;; + --disable-vde) printf "%s" -Dvde=disabled ;; + --enable-vdi) printf "%s" -Dvdi=enabled ;; +-- +2.48.1 + diff --git a/kvm-vfio-helpers-Align-mmaps.patch b/kvm-vfio-helpers-Align-mmaps.patch new file mode 100644 index 0000000..784e024 --- /dev/null +++ b/kvm-vfio-helpers-Align-mmaps.patch @@ -0,0 +1,100 @@ +From 0e733c43122688a40b0bad9cf9af43ac3655fa30 Mon Sep 17 00:00:00 2001 +From: Alex Williamson +Date: Tue, 22 Oct 2024 14:08:29 -0600 +Subject: [PATCH 5/5] vfio/helpers: Align mmaps +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +RH-Author: Donald Dutile +RH-MergeRequest: 366: Improve VFIO mmapping performance with huge pfnmaps +RH-Jira: RHEL-88533 +RH-Acked-by: Cédric Le Goater +RH-Acked-by: Alex Williamson +RH-Commit: [2/2] f0e99cf993f82796352376bc7280342729ea5624 (ddutile/qemu-kvm) + +Thanks to work by Peter Xu, support is introduced in Linux v6.12 to +allow pfnmap insertions at PMD and PUD levels of the page table. This +means that provided a properly aligned mmap, the vfio driver is able +to map MMIO at significantly larger intervals than PAGE_SIZE. For +example on x86_64 (the only architecture currently supporting huge +pfnmaps for PUD), rather than 4KiB mappings, we can map device MMIO +using 2MiB and even 1GiB page table entries. + +Typically mmap will already provide PMD aligned mappings, so devices +with moderately sized MMIO ranges, even GPUs with standard 256MiB BARs, +will already take advantage of this support. However in order to better +support devices exposing multi-GiB MMIO, such as 3D accelerators or GPUs +with resizable BARs enabled, we need to manually align the mmap. + +There doesn't seem to be a way for userspace to easily learn about PMD +and PUD mapping level sizes, therefore this takes the simple approach +to align the mapping to the power-of-two size of the region, up to 1GiB, +which is currently the maximum alignment we care about. + +Cc: Peter Xu +Signed-off-by: Alex Williamson +Reviewed-by: Peter Xu +Reviewed-by: Cédric Le Goater +(cherry picked from commit 00b519c0bca0e933ed22e2e6f8bca6b23f41f950) + +Jira: https://issues.redhat.com/browse/RHEL-88533 + +Signed-off-by: Donald Dutile +--- + hw/vfio/helpers.c | 32 ++++++++++++++++++++++++++++++-- + 1 file changed, 30 insertions(+), 2 deletions(-) + +diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c +index b9e606e364..913796f437 100644 +--- a/hw/vfio/helpers.c ++++ b/hw/vfio/helpers.c +@@ -27,6 +27,7 @@ + #include "trace.h" + #include "qapi/error.h" + #include "qemu/error-report.h" ++#include "qemu/units.h" + #include "monitor/monitor.h" + + /* +@@ -406,8 +407,35 @@ int vfio_region_mmap(VFIORegion *region) + prot |= region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0; + + for (i = 0; i < region->nr_mmaps; i++) { +- region->mmaps[i].mmap = mmap(NULL, region->mmaps[i].size, prot, +- MAP_SHARED, region->vbasedev->fd, ++ size_t align = MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB); ++ void *map_base, *map_align; ++ ++ /* ++ * Align the mmap for more efficient mapping in the kernel. Ideally ++ * we'd know the PMD and PUD mapping sizes to use as discrete alignment ++ * intervals, but we don't. As of Linux v6.12, the largest PUD size ++ * supporting huge pfnmap is 1GiB (ARCH_SUPPORTS_PUD_PFNMAP is only set ++ * on x86_64). Align by power-of-two size, capped at 1GiB. ++ * ++ * NB. qemu_memalign() and friends actually allocate memory, whereas ++ * the region size here can exceed host memory, therefore we manually ++ * create an oversized anonymous mapping and clean it up for alignment. ++ */ ++ map_base = mmap(0, region->mmaps[i].size + align, PROT_NONE, ++ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ++ if (map_base == MAP_FAILED) { ++ ret = -errno; ++ goto no_mmap; ++ } ++ ++ map_align = (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)align); ++ munmap(map_base, map_align - map_base); ++ munmap(map_align + region->mmaps[i].size, ++ align - (map_align - map_base)); ++ ++ region->mmaps[i].mmap = mmap(map_align, region->mmaps[i].size, prot, ++ MAP_SHARED | MAP_FIXED, ++ region->vbasedev->fd, + region->fd_offset + + region->mmaps[i].offset); + if (region->mmaps[i].mmap == MAP_FAILED) { +-- +2.48.1 + diff --git a/kvm-vfio-helpers-Refactor-vfio_region_mmap-error-handlin.patch b/kvm-vfio-helpers-Refactor-vfio_region_mmap-error-handlin.patch new file mode 100644 index 0000000..6b06e31 --- /dev/null +++ b/kvm-vfio-helpers-Refactor-vfio_region_mmap-error-handlin.patch @@ -0,0 +1,93 @@ +From f3af9e4476546c0bc814f78d5dd1047ec60768e8 Mon Sep 17 00:00:00 2001 +From: Alex Williamson +Date: Tue, 22 Oct 2024 14:08:28 -0600 +Subject: [PATCH 4/5] vfio/helpers: Refactor vfio_region_mmap() error handling +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +RH-Author: Donald Dutile +RH-MergeRequest: 366: Improve VFIO mmapping performance with huge pfnmaps +RH-Jira: RHEL-88533 +RH-Acked-by: Cédric Le Goater +RH-Acked-by: Alex Williamson +RH-Commit: [1/2] b83c7dbc6a6037b465a141961ae810e5551fad30 (ddutile/qemu-kvm) + +Move error handling code to the end of the function so that it can more +easily be shared by new mmap failure conditions. No functional change +intended. + +Signed-off-by: Alex Williamson +Reviewed-by: Peter Xu +Reviewed-by: Cédric Le Goater +(cherry picked from commit 49915c0d2c9868e6f25e52e4d839943611b69e98) + +Jira: https://issues.redhat.com/browse/RHEL-88533 + +Signed-off-by: Donald Dutile +--- + hw/vfio/helpers.c | 34 +++++++++++++++++----------------- + 1 file changed, 17 insertions(+), 17 deletions(-) + +diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c +index ea15c79db0..b9e606e364 100644 +--- a/hw/vfio/helpers.c ++++ b/hw/vfio/helpers.c +@@ -395,7 +395,7 @@ static void vfio_subregion_unmap(VFIORegion *region, int index) + + int vfio_region_mmap(VFIORegion *region) + { +- int i, prot = 0; ++ int i, ret, prot = 0; + char *name; + + if (!region->mem) { +@@ -411,22 +411,8 @@ int vfio_region_mmap(VFIORegion *region) + region->fd_offset + + region->mmaps[i].offset); + if (region->mmaps[i].mmap == MAP_FAILED) { +- int ret = -errno; +- +- trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, +- region->fd_offset + +- region->mmaps[i].offset, +- region->fd_offset + +- region->mmaps[i].offset + +- region->mmaps[i].size - 1, ret); +- +- region->mmaps[i].mmap = NULL; +- +- for (i--; i >= 0; i--) { +- vfio_subregion_unmap(region, i); +- } +- +- return ret; ++ ret = -errno; ++ goto no_mmap; + } + + name = g_strdup_printf("%s mmaps[%d]", +@@ -446,6 +432,20 @@ int vfio_region_mmap(VFIORegion *region) + } + + return 0; ++ ++no_mmap: ++ trace_vfio_region_mmap_fault(memory_region_name(region->mem), i, ++ region->fd_offset + region->mmaps[i].offset, ++ region->fd_offset + region->mmaps[i].offset + ++ region->mmaps[i].size - 1, ret); ++ ++ region->mmaps[i].mmap = NULL; ++ ++ for (i--; i >= 0; i--) { ++ vfio_subregion_unmap(region, i); ++ } ++ ++ return ret; + } + + void vfio_region_unmap(VFIORegion *region) +-- +2.48.1 + diff --git a/qemu-kvm.spec b/qemu-kvm.spec index 9d1ee13..92cbffc 100644 --- a/qemu-kvm.spec +++ b/qemu-kvm.spec @@ -149,7 +149,7 @@ Obsoletes: %{name}-block-ssh <= %{epoch}:%{version} \ Summary: QEMU is a machine emulator and virtualizer Name: qemu-kvm Version: 9.1.0 -Release: 20%{?rcrel}%{?dist}%{?cc_suffix} +Release: 21%{?rcrel}%{?dist}%{?cc_suffix} # Epoch because we pushed a qemu-1.0 package. AIUI this can't ever be dropped # Epoch 15 used for RHEL 8 # Epoch 17 used for RHEL 9 (due to release versioning offset in RHEL 8.5) @@ -559,6 +559,14 @@ Patch193: kvm-file-posix-probe-discard-alignment-on-Linux-block-de.patch Patch194: kvm-block-io-skip-head-tail-requests-on-EINVAL.patch # For RHEL-86032 - QEMU sends unaligned discards on 4K devices [RHEL-9.7] Patch195: kvm-file-posix-Fix-crash-on-discard_granularity-0.patch +# For RHEL-88153 - [s390x] valgrind not working with qemu-kvm for non-x86 builds +Patch196: kvm-meson-configure-add-valgrind-option-en-dis-able-valg.patch +# For RHEL-88153 - [s390x] valgrind not working with qemu-kvm for non-x86 builds +Patch197: kvm-hw-i386-Fix-machine-type-compatibility.patch +# For RHEL-88533 - Improve VFIO mmapping performance with huge pfnmaps +Patch198: kvm-vfio-helpers-Refactor-vfio_region_mmap-error-handlin.patch +# For RHEL-88533 - Improve VFIO mmapping performance with huge pfnmaps +Patch199: kvm-vfio-helpers-Align-mmaps.patch %if %{have_clang} BuildRequires: clang @@ -636,6 +644,9 @@ BuildRequires: pulseaudio-libs-devel BuildRequires: spice-protocol BuildRequires: capstone-devel BuildRequires: python3-tomli +%ifarch %{valgrind_arches} +BuildRequires: valgrind-devel +%endif # Requires for qemu-kvm package Requires: %{name}-core = %{epoch}:%{version}-%{release} @@ -1012,6 +1023,7 @@ ulimit -n 10240 --disable-u2f \\\ --disable-usb-redir \\\ --disable-user \\\ + --disable-valgrind \\\ --disable-vde \\\ --disable-vdi \\\ --disable-vduse-blk-export \\\ @@ -1134,6 +1146,9 @@ run_configure \ --enable-tpm \ %if %{have_usbredir} --enable-usb-redir \ +%endif +%ifarch %{valgrind_arches} + --enable-valgrind \ %endif --enable-vdi \ --enable-vhost-kernel \ @@ -1627,6 +1642,19 @@ useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin \ %endif %changelog +* Mon May 26 2025 Jon Maloy - 9.1.0-21 +- kvm-meson-configure-add-valgrind-option-en-dis-able-valg.patch [RHEL-88153] +- kvm-distro-add-an-explicit-valgrind-devel-build-dep.patch [RHEL-88153] +- kvm-hw-i386-Fix-machine-type-compatibility.patch [RHEL-91307] +- kvm-vfio-helpers-Refactor-vfio_region_mmap-error-handlin.patch [RHEL-88533] +- kvm-vfio-helpers-Align-mmaps.patch [RHEL-88533] +- Resolves: RHEL-88153 + ([s390x] valgrind not working with qemu-kvm for non-x86 builds) +- Resolves: RHEL-91307 + (Fix x86 M-type compats) +- Resolves: RHEL-88533 + (Improve VFIO mmapping performance with huge pfnmaps) + * Tue May 13 2025 Jon Maloy - 9.1.0-20 - kvm-virtio-net-disable-USO-for-virt-rhel9.6.patch [RHEL-80313] - kvm-arm-Use-arm_virt_compat_set-to-apply-the-compat.patch [RHEL-80313]