From d90e785901d29e98914e2711fe66ccd2496ec649 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Thu, 18 Sep 2025 12:27:36 +0200 Subject: [PATCH] runtime: Set maxmem to initialmem on s390x when memory hotplug is disabled On s390x, QEMU fails if maxmem is set to 0: ``` invalid value of maxmem: maximum memory size (0x0) must be at least the initial memory size ``` This commit sets maxmem to the initial memory size for s390x when hotplug is disabled, resolving the error while still ensuring that memory hotplug remains off. Signed-off-by: Hyounggyu Choi --- src/runtime/virtcontainers/qemu_s390x.go | 18 ++++++++++++++++++ src/runtime/virtcontainers/qemu_s390x_test.go | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/runtime/virtcontainers/qemu_s390x.go b/src/runtime/virtcontainers/qemu_s390x.go index 9a10510d13..459d1c1bc7 100644 --- a/src/runtime/virtcontainers/qemu_s390x.go +++ b/src/runtime/virtcontainers/qemu_s390x.go @@ -424,3 +424,21 @@ func (q *qemuS390x) qomGetPciPath(qemuID string, qmpCh *qmpChannel) (types.PciPa hvLogger.Warnf("qomGetPciPath not implemented for s390x") return types.PciPath{}, nil } + +func (q *qemuS390x) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory { + // For no hotplug memory, set hostMemoryMb to memoryMb, otherwise will cause + // `invalid value of maxmem: maximum memory size (0x0) must be at least the initial memory size` + if hostMemoryMb == 0 { + hostMemoryMb = memoryMb + } + + memMax := fmt.Sprintf("%dM", hostMemoryMb) + mem := fmt.Sprintf("%dM", memoryMb) + memory := govmmQemu.Memory{ + Size: mem, + Slots: slots, + MaxMem: memMax, + } + + return memory +} diff --git a/src/runtime/virtcontainers/qemu_s390x_test.go b/src/runtime/virtcontainers/qemu_s390x_test.go index f04c8cbf40..b8fa723715 100644 --- a/src/runtime/virtcontainers/qemu_s390x_test.go +++ b/src/runtime/virtcontainers/qemu_s390x_test.go @@ -56,6 +56,12 @@ func TestQemuS390xMemoryTopology(t *testing.T) { m := s390x.memoryTopology(mem, hostMem, slots) assert.Equal(expectedMemory, m) + + // test when hostMem is set to 0 (no hotplug memory) + hostMem = 0 + expectedMemory.MaxMem = fmt.Sprintf("%dM", mem) + m = s390x.memoryTopology(mem, hostMem, slots) + assert.Equal(expectedMemory, m) } func TestQemuS390xAppendVhostUserDevice(t *testing.T) {