2016-06-29 13:47:03 +02:00
|
|
|
#ifndef QEMU_MMAP_ALLOC_H
|
|
|
|
#define QEMU_MMAP_ALLOC_H
|
2015-09-24 13:41:17 +02:00
|
|
|
|
2023-04-19 18:17:36 +02:00
|
|
|
typedef enum {
|
|
|
|
QEMU_FS_TYPE_UNKNOWN = 0,
|
|
|
|
QEMU_FS_TYPE_TMPFS,
|
|
|
|
QEMU_FS_TYPE_HUGETLBFS,
|
|
|
|
QEMU_FS_TYPE_NUM,
|
|
|
|
} QemuFsType;
|
2015-09-24 13:41:17 +02:00
|
|
|
|
util/mmap-alloc: fix hugetlb support on ppc64
Since commit 8561c9244ddf1122d "exec: allocate PROT_NONE pages on top of
RAM", it is no longer possible to back guest RAM with hugepages on ppc64
hosts:
mmap(NULL, 285212672, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x3fff57000000
mmap(0x3fff57000000, 268435456, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 19, 0) = -1 EBUSY (Device or resource busy)
This is because on ppc64, Linux fixes a page size for a virtual address
at mmap time, so we can't switch a range of memory from anonymous
small pages to hugetlbs with MAP_FIXED.
See commit d0f13e3c20b6fb73ccb467bdca97fa7cf5a574cd
("[POWERPC] Introduce address space "slices"") in Linux
history for the details.
Detect this and create the PROT_NONE mapping using the same fd.
Naturally, this makes the guard page bigger with hugetlbfs.
Based on patch by Greg Kurz.
Acked-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-12-02 20:14:12 +01:00
|
|
|
size_t qemu_fd_getpagesize(int fd);
|
2023-04-19 18:17:36 +02:00
|
|
|
QemuFsType qemu_fd_getfs(int fd);
|
util/mmap-alloc: fix hugetlb support on ppc64
Since commit 8561c9244ddf1122d "exec: allocate PROT_NONE pages on top of
RAM", it is no longer possible to back guest RAM with hugepages on ppc64
hosts:
mmap(NULL, 285212672, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x3fff57000000
mmap(0x3fff57000000, 268435456, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 19, 0) = -1 EBUSY (Device or resource busy)
This is because on ppc64, Linux fixes a page size for a virtual address
at mmap time, so we can't switch a range of memory from anonymous
small pages to hugetlbs with MAP_FIXED.
See commit d0f13e3c20b6fb73ccb467bdca97fa7cf5a574cd
("[POWERPC] Introduce address space "slices"") in Linux
history for the details.
Detect this and create the PROT_NONE mapping using the same fd.
Naturally, this makes the guard page bigger with hugetlbfs.
Based on patch by Greg Kurz.
Acked-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-12-02 20:14:12 +01:00
|
|
|
|
2019-02-08 11:10:37 +01:00
|
|
|
/**
|
2021-05-10 13:43:20 +02:00
|
|
|
* qemu_ram_mmap: mmap anonymous memory, the specified file or device.
|
|
|
|
*
|
|
|
|
* mmap() abstraction to map guest RAM, simplifying flag handling, taking
|
|
|
|
* care of alignment requirements and installing guard pages.
|
2019-02-08 11:10:37 +01:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* @fd: the file or the device to mmap
|
|
|
|
* @size: the number of bytes to be mmaped
|
|
|
|
* @align: if not zero, specify the alignment of the starting mapping address;
|
|
|
|
* otherwise, the alignment in use will be determined by QEMU.
|
2021-05-10 13:43:20 +02:00
|
|
|
* @qemu_map_flags: QEMU_MAP_* flags
|
2021-01-29 17:46:04 +01:00
|
|
|
* @map_offset: map starts at offset of map_offset from the start of fd
|
2019-02-08 11:10:37 +01:00
|
|
|
*
|
2021-05-10 13:43:20 +02:00
|
|
|
* Internally, MAP_PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set
|
|
|
|
* implicitly based on other parameters.
|
|
|
|
*
|
2019-02-08 11:10:37 +01:00
|
|
|
* Return:
|
|
|
|
* On success, return a pointer to the mapped area.
|
|
|
|
* On failure, return MAP_FAILED.
|
|
|
|
*/
|
|
|
|
void *qemu_ram_mmap(int fd,
|
|
|
|
size_t size,
|
|
|
|
size_t align,
|
2021-05-10 13:43:20 +02:00
|
|
|
uint32_t qemu_map_flags,
|
2021-01-29 17:46:04 +01:00
|
|
|
off_t map_offset);
|
2015-09-24 13:41:17 +02:00
|
|
|
|
2019-01-31 00:36:05 +01:00
|
|
|
void qemu_ram_munmap(int fd, void *ptr, size_t size);
|
2015-09-24 13:41:17 +02:00
|
|
|
|
2022-02-08 21:08:54 +01:00
|
|
|
/*
|
|
|
|
* Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example,
|
|
|
|
* consumed by qemu_ram_mmap().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Map PROT_READ instead of PROT_READ | PROT_WRITE. */
|
|
|
|
#define QEMU_MAP_READONLY (1 << 0)
|
|
|
|
|
|
|
|
/* Use MAP_SHARED instead of MAP_PRIVATE. */
|
|
|
|
#define QEMU_MAP_SHARED (1 << 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use MAP_SYNC | MAP_SHARED_VALIDATE if supported. Ignored without
|
|
|
|
* QEMU_MAP_SHARED. If mapping fails, warn and fallback to !QEMU_MAP_SYNC.
|
|
|
|
*/
|
|
|
|
#define QEMU_MAP_SYNC (1 << 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use MAP_NORESERVE to skip reservation of swap space (or huge pages if
|
|
|
|
* applicable). Bail out if not supported/effective.
|
|
|
|
*/
|
|
|
|
#define QEMU_MAP_NORESERVE (1 << 3)
|
|
|
|
|
2015-09-24 13:41:17 +02:00
|
|
|
#endif
|