From c9053ea3fb270968ed31a66fad945b5c575336e1 Mon Sep 17 00:00:00 2001 From: Hui Zhu Date: Mon, 3 May 2021 21:49:11 +0800 Subject: [PATCH 1/2] qemu.go: qemu: setupVirtioMem: let sizeMB be multiple of 2Mib Got: FATA[0000] run pod sandbox: rpc error: code = Unknown desc = failed to create containerd task: Add 189759MB virtio-mem-pci fail QMP command failed: backend memory size must be multiple of 0x200000: unknown This commit let sizeMB be multiple of 2Mib to fix the issue. Fixes: #1796 Signed-off-by: Hui Zhu --- src/runtime/virtcontainers/qemu.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 9f00a12a44..5be0fe2c90 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -768,8 +768,8 @@ func (q *qemu) setupVirtioMem() error { if err != nil { return err } - // 1024 is size for nvdimm - sizeMB := int(maxMem) - int(q.config.MemorySize) + // backend memory size must be multiple of 2Mib + sizeMB := (int(maxMem) - int(q.config.MemorySize)) >> 2 << 2 share, target, memoryBack, err := q.getMemArgs() if err != nil { From 7f7c3fc8ec437fa91e74987fc3eee09f9ccae8a0 Mon Sep 17 00:00:00 2001 From: Hui Zhu Date: Thu, 6 May 2021 10:44:06 +0800 Subject: [PATCH 2/2] qemu.go: qemu: resizeMemory: Fix virtio-mem resize overflow issue This commit change sizeByte from uint32 to uint64 to fix overflow issue. Fixes: #1796 Signed-off-by: Hui Zhu --- src/runtime/virtcontainers/qemu.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 5be0fe2c90..c5b26facfc 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -2043,8 +2043,9 @@ func (q *qemu) resizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSiz var addMemDevice memoryDevice if q.config.VirtioMem && currentMemory != reqMemMB { q.Logger().WithField("hotplug", "memory").Debugf("resize memory from %dMB to %dMB", currentMemory, reqMemMB) - sizeByte := (reqMemMB - q.config.MemorySize) * 1024 * 1024 - err := q.qmpMonitorCh.qmp.ExecQomSet(q.qmpMonitorCh.ctx, "virtiomem0", "requested-size", uint64(sizeByte)) + sizeByte := uint64(reqMemMB - q.config.MemorySize) + sizeByte = sizeByte * 1024 * 1024 + err := q.qmpMonitorCh.qmp.ExecQomSet(q.qmpMonitorCh.ctx, "virtiomem0", "requested-size", sizeByte) if err != nil { return 0, memoryDevice{}, err }