yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-util-mmap-alloc-Add-a-is_pmem-parameter-to-qemu_ram_.patch

Pablo Greco e6a3ae
From 5e258b59991284cf2e6bfcac04ff2de01dc83005 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: "plai@redhat.com" <plai@redhat.com>
Pablo Greco e6a3ae
Date: Tue, 20 Aug 2019 16:12:48 +0100
Pablo Greco e6a3ae
Subject: [PATCH 01/11] util/mmap-alloc: Add a 'is_pmem' parameter to
Pablo Greco e6a3ae
 qemu_ram_mmap
Pablo Greco e6a3ae
MIME-Version: 1.0
Pablo Greco e6a3ae
Content-Type: text/plain; charset=UTF-8
Pablo Greco e6a3ae
Content-Transfer-Encoding: 8bit
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: plai@redhat.com
Pablo Greco e6a3ae
Message-id: <1566317571-5697-2-git-send-email-plai@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 90084
Pablo Greco e6a3ae
O-Subject: [RHEL8.2 qemu-kvm PATCH 1/4] util/mmap-alloc: Add a 'is_pmem' parameter to qemu_ram_mmap
Pablo Greco e6a3ae
Bugzilla: 1539282
Pablo Greco e6a3ae
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Zhang Yi <yi.z.zhang@linux.intel.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
besides the existing 'shared' flags, we are going to add
Pablo Greco e6a3ae
'is_pmem' to qemu_ram_mmap(), which indicated the memory backend
Pablo Greco e6a3ae
file is a persist memory.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Pablo Greco e6a3ae
Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
Pablo Greco e6a3ae
Reviewed-by: Pankaj Gupta <pagupta@redhat.com>
Pablo Greco e6a3ae
Message-Id: <786c46862cfeb253ee0ea2f44d62ffe76edb7fa4.1549555521.git.yi.z.zhang@linux.intel.com>
Pablo Greco e6a3ae
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Pankaj Gupta <pagupta@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 2ac0f1621c9be59eebc844fa10361a84fd726185)
Pablo Greco e6a3ae
Signed-off-by: Paul Lai <plai@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 exec.c                    |  2 +-
Pablo Greco e6a3ae
 include/qemu/mmap-alloc.h | 21 ++++++++++++++++++++-
Pablo Greco e6a3ae
 util/mmap-alloc.c         |  6 +++++-
Pablo Greco e6a3ae
 util/oslib-posix.c        |  2 +-
Pablo Greco e6a3ae
 4 files changed, 27 insertions(+), 4 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/exec.c b/exec.c
Pablo Greco e6a3ae
index 9028700..a79eaa3 100644
Pablo Greco e6a3ae
--- a/exec.c
Pablo Greco e6a3ae
+++ b/exec.c
Pablo Greco e6a3ae
@@ -1669,7 +1669,7 @@ static void *file_ram_alloc(RAMBlock *block,
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     area = qemu_ram_mmap(fd, memory, block->mr->align,
Pablo Greco e6a3ae
-                         block->flags & RAM_SHARED);
Pablo Greco e6a3ae
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
Pablo Greco e6a3ae
     if (area == MAP_FAILED) {
Pablo Greco e6a3ae
         error_setg_errno(errp, errno,
Pablo Greco e6a3ae
                          "unable to map backing store for guest RAM");
Pablo Greco e6a3ae
diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
Pablo Greco e6a3ae
index 50385e3..190688a 100644
Pablo Greco e6a3ae
--- a/include/qemu/mmap-alloc.h
Pablo Greco e6a3ae
+++ b/include/qemu/mmap-alloc.h
Pablo Greco e6a3ae
@@ -7,7 +7,26 @@ size_t qemu_fd_getpagesize(int fd);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 size_t qemu_mempath_getpagesize(const char *mem_path);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared);
Pablo Greco e6a3ae
+/**
Pablo Greco e6a3ae
+ * qemu_ram_mmap: mmap the specified file or device.
Pablo Greco e6a3ae
+ *
Pablo Greco e6a3ae
+ * Parameters:
Pablo Greco e6a3ae
+ *  @fd: the file or the device to mmap
Pablo Greco e6a3ae
+ *  @size: the number of bytes to be mmaped
Pablo Greco e6a3ae
+ *  @align: if not zero, specify the alignment of the starting mapping address;
Pablo Greco e6a3ae
+ *          otherwise, the alignment in use will be determined by QEMU.
Pablo Greco e6a3ae
+ *  @shared: map has RAM_SHARED flag.
Pablo Greco e6a3ae
+ *  @is_pmem: map has RAM_PMEM flag.
Pablo Greco e6a3ae
+ *
Pablo Greco e6a3ae
+ * Return:
Pablo Greco e6a3ae
+ *  On success, return a pointer to the mapped area.
Pablo Greco e6a3ae
+ *  On failure, return MAP_FAILED.
Pablo Greco e6a3ae
+ */
Pablo Greco e6a3ae
+void *qemu_ram_mmap(int fd,
Pablo Greco e6a3ae
+                    size_t size,
Pablo Greco e6a3ae
+                    size_t align,
Pablo Greco e6a3ae
+                    bool shared,
Pablo Greco e6a3ae
+                    bool is_pmem);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 void qemu_ram_munmap(void *ptr, size_t size);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
Pablo Greco e6a3ae
index 2fd8cbc..55d1890 100644
Pablo Greco e6a3ae
--- a/util/mmap-alloc.c
Pablo Greco e6a3ae
+++ b/util/mmap-alloc.c
Pablo Greco e6a3ae
@@ -73,7 +73,11 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
Pablo Greco e6a3ae
     return getpagesize();
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
Pablo Greco e6a3ae
+void *qemu_ram_mmap(int fd,
Pablo Greco e6a3ae
+                    size_t size,
Pablo Greco e6a3ae
+                    size_t align,
Pablo Greco e6a3ae
+                    bool shared,
Pablo Greco e6a3ae
+                    bool is_pmem)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     /*
Pablo Greco e6a3ae
      * Note: this always allocates at least one extra page of virtual address
Pablo Greco e6a3ae
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
Pablo Greco e6a3ae
index 13b6f8d..c36b2bb 100644
Pablo Greco e6a3ae
--- a/util/oslib-posix.c
Pablo Greco e6a3ae
+++ b/util/oslib-posix.c
Pablo Greco e6a3ae
@@ -130,7 +130,7 @@ void *qemu_memalign(size_t alignment, size_t size)
Pablo Greco e6a3ae
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     size_t align = QEMU_VMALLOC_ALIGN;
Pablo Greco e6a3ae
-    void *ptr = qemu_ram_mmap(-1, size, align, shared);
Pablo Greco e6a3ae
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     if (ptr == MAP_FAILED) {
Pablo Greco e6a3ae
         return NULL;
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae