From 717b90366b40051e8314b1d6af2d30e11a7b1811 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 13 Aug 2021 05:14:11 -0400 Subject: [PATCH] [common] ivshmem: use correct page alignment logic Before, if the size is exactly the multiple of the page size, an extra padding page is added for no reason. This commit fixes the logic and also uses the page size obtained dynamically. --- common/src/platform/linux/ivshmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/src/platform/linux/ivshmem.c b/common/src/platform/linux/ivshmem.c index eb8e35d0..bc1364cb 100644 --- a/common/src/platform/linux/ivshmem.c +++ b/common/src/platform/linux/ivshmem.c @@ -33,6 +33,7 @@ #include "common/debug.h" #include "common/option.h" +#include "common/sysinfo.h" #include "common/stringutils.h" #include "module/kvmfr.h" @@ -222,11 +223,16 @@ int ivshmemGetDMABuf(struct IVSHMEM * dev, uint64_t offset, uint64_t size) assert(dev && dev->opaque); assert(offset + size <= dev->size); + static long pageSize = 0; + + if (!pageSize) + pageSize = sysinfo_getPageSize(); + struct IVSHMEMInfo * info = (struct IVSHMEMInfo *)dev->opaque; // align to the page size - size = (size & ~(0x1000-1)) + 0x1000; + size = (size + pageSize - 1) & -pageSize; const struct kvmfr_dmabuf_create create = {