diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2021-02-03 09:54:21 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2021-02-03 09:54:21 +0000 |
commit | 8360ebeb4f4a707984cafd1a22c049ec82ddcb4c (patch) | |
tree | 9363af79103b6ffcdc40322efa0963770810d9c4 /util | |
parent | 77f3804ab7ed94b471a14acb260e5aeacf26193f (diff) | |
parent | dbd730e8598701e11b2fb7aee1704f4ec1787e86 (diff) | |
download | qemu-8360ebeb4f4a707984cafd1a22c049ec82ddcb4c.zip qemu-8360ebeb4f4a707984cafd1a22c049ec82ddcb4c.tar.gz qemu-8360ebeb4f4a707984cafd1a22c049ec82ddcb4c.tar.bz2 |
Merge remote-tracking branch 'remotes/ehabkost-gl/tags/machine-next-pull-request' into staging
Machine queue, 2021-02-02
Feature:
* nvdimm: read-only file support (Stefan Hajnoczi)
# gpg: Signature made Tue 02 Feb 2021 19:27:21 GMT
# gpg: using RSA key 5A322FD5ABC4D3DBACCFD1AA2807936F984DC5A6
# gpg: issuer "ehabkost@redhat.com"
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" [full]
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6
* remotes/ehabkost-gl/tags/machine-next-pull-request:
nvdimm: check -object memory-backend-file, readonly=on option
hostmem-file: add readonly=on|off option
memory: add readonly support to memory_region_init_ram_from_file()
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/mmap-alloc.c | 10 | ||||
-rw-r--r-- | util/oslib-posix.c | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 27dcccd..890fda6 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -85,9 +85,11 @@ size_t qemu_mempath_getpagesize(const char *mem_path) void *qemu_ram_mmap(int fd, size_t size, size_t align, + bool readonly, bool shared, bool is_pmem) { + int prot; int flags; int map_sync_flags = 0; int guardfd; @@ -146,8 +148,9 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; - ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags | map_sync_flags, fd, 0); + prot = PROT_READ | (readonly ? 0 : PROT_WRITE); + + ptr = mmap(guardptr + offset, size, prot, flags | map_sync_flags, fd, 0); if (ptr == MAP_FAILED && map_sync_flags) { if (errno == ENOTSUP) { @@ -171,8 +174,7 @@ void *qemu_ram_mmap(int fd, * if map failed with MAP_SHARED_VALIDATE | MAP_SYNC, * we will remove these flags to handle compatibility. */ - ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags, fd, 0); + ptr = mmap(guardptr + offset, size, prot, flags, fd, 0); } if (ptr == MAP_FAILED) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 359c52d..bf57d3b 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -230,7 +230,7 @@ void *qemu_memalign(size_t alignment, size_t size) void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); + void *ptr = qemu_ram_mmap(-1, size, align, false, shared, false); if (ptr == MAP_FAILED) { return NULL; |