[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 authored and Geoffrey McRae committed 2021-08-13 20:24:15 +10:00
1 parent a76b274e1a
commit 717b90366b
1 file changed
+7 -1
+7 -1
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 =
{