[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.
This commit is contained in:
Quantum 2021-08-13 05:14:11 -04:00 committed by Geoffrey McRae
parent a76b274e1a
commit 717b90366b

View File

@ -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 =
{