qemu-kvm/kvm-mmap-alloc-unfold-qemu_ram_mmap.patch
Danilo C. L. de Paula b705db35b7 * Mon Feb 11 2019 Danilo Cesar Lemes de Paula <ddepaula@redhat.com> - 3.1.0-13.el8
- kvm-Acceptance-tests-add-Linux-initrd-checking-test.patch [bz#1669922]
- kvm-mmap-alloc-unfold-qemu_ram_mmap.patch [bz#1671519]
- kvm-mmap-alloc-fix-hugetlbfs-misaligned-length-in-ppc64.patch [bz#1671519]
- kvm-BZ1653590-Require-at-least-64kiB-pages-for-downstrea.patch [bz#1653590]
- kvm-block-Fix-invalidate_cache-error-path-for-parent-act.patch [bz#1673014]
- kvm-virtio-scsi-Move-BlockBackend-back-to-the-main-AioCo.patch [bz#1656276 bz#1662508]
- kvm-scsi-disk-Acquire-the-AioContext-in-scsi_-_realize.patch [bz#1656276 bz#1662508]
- kvm-virtio-scsi-Forbid-devices-with-different-iothreads-.patch [bz#1656276 bz#1662508]
- Resolves: bz#1653590
  ([Fast train]had better stop qemu immediately while guest was making use of an improper page size)
- Resolves: bz#1656276
  (qemu-kvm core dumped after hotplug the deleted disk with iothread parameter)
- Resolves: bz#1662508
  (Qemu core dump when start guest with two disks using same drive)
- Resolves: bz#1669922
  (Backport avocado-qemu tests for QEMU 3.1)
- Resolves: bz#1671519
  (RHEL8.0 Snapshot3 - qemu doesn't free up hugepage memory when hotplug/hotunplug using memory-backend-file (qemu-kvm))
- Resolves: bz#1673014
  (Local VM and migrated VM on the same host can run with same RAW file as visual disk source while without shareable configured or lock manager enabled)
2019-02-11 14:09:54 -02:00

139 lines
4.6 KiB
Diff

From 2215d38d1231284cced64d94b4430e92c9e2c017 Mon Sep 17 00:00:00 2001
From: David Gibson <dgibson@redhat.com>
Date: Tue, 5 Feb 2019 04:47:56 +0000
Subject: [PATCH 2/8] mmap-alloc: unfold qemu_ram_mmap()
RH-Author: David Gibson <dgibson@redhat.com>
Message-id: <20190205044757.13591-2-dgibson@redhat.com>
Patchwork-id: 84234
O-Subject: [RHELAV-8.0 qemu-kvm PATCH 1/2] mmap-alloc: unfold qemu_ram_mmap()
Bugzilla: 1671519
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
RH-Acked-by: Serhii Popovych <spopovyc@redhat.com>
From: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Unfold parts of qemu_ram_mmap() for the sake of understanding, moving
declarations to the top, and keeping architecture-specifics in the
ifdef-else blocks. No changes in the function behaviour.
Give ptr and ptr1 meaningful names:
ptr -> guardptr : pointer to the PROT_NONE guard region
ptr1 -> ptr : pointer to the mapped memory returned to caller
Signed-off-by: Murilo Opsfelder Araujo <muriloo@linux.ibm.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
(cherry picked from commit 2044c3e7116eeac0449dcb4a4130cc8f8b9310da)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1671519
Signed-off-by: David Gibson <dgibson@redhat.com>
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
---
util/mmap-alloc.c | 53 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index fd329ec..f71ea03 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -77,11 +77,19 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
{
+ int flags;
+ int guardfd;
+ size_t offset;
+ size_t total;
+ void *guardptr;
+ void *ptr;
+
/*
* Note: this always allocates at least one extra page of virtual address
* space, even if size is already aligned.
*/
- size_t total = size + align;
+ total = size + align;
+
#if defined(__powerpc64__) && defined(__linux__)
/* On ppc64 mappings in the same segment (aka slice) must share the same
* page size. Since we will be re-allocating part of this segment
@@ -91,16 +99,22 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
* We do this unless we are using the system page size, in which case
* anonymous memory is OK.
*/
- int anonfd = fd == -1 || qemu_fd_getpagesize(fd) == getpagesize() ? -1 : fd;
- int flags = anonfd == -1 ? MAP_ANONYMOUS : MAP_NORESERVE;
- void *ptr = mmap(0, total, PROT_NONE, flags | MAP_PRIVATE, anonfd, 0);
+ flags = MAP_PRIVATE;
+ if (fd == -1 || qemu_fd_getpagesize(fd) == getpagesize()) {
+ guardfd = -1;
+ flags |= MAP_ANONYMOUS;
+ } else {
+ guardfd = fd;
+ flags |= MAP_NORESERVE;
+ }
#else
- void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ guardfd = -1;
+ flags = MAP_PRIVATE | MAP_ANONYMOUS;
#endif
- size_t offset;
- void *ptr1;
- if (ptr == MAP_FAILED) {
+ guardptr = mmap(0, total, PROT_NONE, flags, guardfd, 0);
+
+ if (guardptr == MAP_FAILED) {
return MAP_FAILED;
}
@@ -108,19 +122,20 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
/* Always align to host page size */
assert(align >= getpagesize());
- offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
- ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
- MAP_FIXED |
- (fd == -1 ? MAP_ANONYMOUS : 0) |
- (shared ? MAP_SHARED : MAP_PRIVATE),
- fd, 0);
- if (ptr1 == MAP_FAILED) {
- munmap(ptr, total);
+ flags = MAP_FIXED;
+ flags |= fd == -1 ? MAP_ANONYMOUS : 0;
+ flags |= shared ? MAP_SHARED : MAP_PRIVATE;
+ offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
+
+ ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, flags, fd, 0);
+
+ if (ptr == MAP_FAILED) {
+ munmap(guardptr, total);
return MAP_FAILED;
}
if (offset > 0) {
- munmap(ptr, offset);
+ munmap(guardptr, offset);
}
/*
@@ -129,10 +144,10 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
*/
total -= offset;
if (total > size + getpagesize()) {
- munmap(ptr1 + size + getpagesize(), total - size - getpagesize());
+ munmap(ptr + size + getpagesize(), total - size - getpagesize());
}
- return ptr1;
+ return ptr;
}
void qemu_ram_munmap(void *ptr, size_t size)
--
1.8.3.1