From 983768431676f9ab8599a0b4813e1ca17af70838 Mon Sep 17 00:00:00 2001 From: Haozhong Zhang Date: Mon, 11 Dec 2017 15:28:04 +0800 Subject: hostmem-file: add "align" option When mmap(2) the backend files, QEMU uses the host page size (getpagesize(2)) by default as the alignment of mapping address. However, some backends may require alignments different than the page size. For example, mmap a device DAX (e.g., /dev/dax0.0) on Linux kernel 4.13 to an address, which is 4K-aligned but not 2M-aligned, fails with a kernel message like [617494.969768] dax dax0.0: qemu-system-x86: dax_mmap: fail, unaligned vma (0x7fa37c579000 - 0x7fa43c579000, 0x1fffff) Because there is no common approach to get such alignment requirement, we add the 'align' option to 'memory-backend-file', so that users or management utils, which have enough knowledge about the backend, can specify a proper alignment via this option. Signed-off-by: Haozhong Zhang Message-Id: <20171211072806.2812-2-haozhong.zhang@intel.com> Reviewed-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi [ehabkost: fixed typo, fixed error_setg() format string] Signed-off-by: Eduardo Habkost --- exec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index d28fc0cd3d..629a508385 100644 --- a/exec.c +++ b/exec.c @@ -1612,7 +1612,13 @@ static void *file_ram_alloc(RAMBlock *block, void *area; block->page_size = qemu_fd_getpagesize(fd); - block->mr->align = block->page_size; + if (block->mr->align % block->page_size) { + error_setg(errp, "alignment 0x%" PRIx64 + " must be multiples of page size 0x%zx", + block->mr->align, block->page_size); + return NULL; + } + block->mr->align = MAX(block->page_size, block->mr->align); #if defined(__s390x__) if (kvm_enabled()) { block->mr->align = MAX(block->mr->align, QEMU_VMALLOC_ALIGN); -- cgit v1.2.1