From 5d2af555dae8bc0614e0b25d25b5150c8f60937f Mon Sep 17 00:00:00 2001 From: Chelsea Mafrica Date: Wed, 15 May 2024 11:22:19 -0700 Subject: [PATCH] runtime: Add missing check in ResizeMemory for CH ResizeMemory for Cloud Hypervisor is missing a check for the new requested memory being greater than the max hotplug size after alignment. Add the check, and since an earlier check for this setsrequested memory to the max hotplug size, do the same in the post-alignment check. Fixes #9640 Signed-off-by: Chelsea Mafrica --- src/runtime/virtcontainers/clh.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 1bc17fe525..8c7583d014 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -1042,12 +1042,15 @@ func (clh *cloudHypervisor) ResizeMemory(ctx context.Context, reqMemMB uint32, m newMem = alignedRequest } - // Check if memory is the same as requested, a second Check is done - // to consider the memory request now that is updated to be memory aligned + // Post-alignment checks if currentMem == newMem { clh.Logger().WithFields(log.Fields{"current-memory": currentMem, "new-memory": newMem}).Debug("VM already has requested memory(after alignment)") return uint32(currentMem.ToMiB()), MemoryDevice{}, nil } + // Check for aligned memory exceeding max hotplug size + if newMem > (utils.MemUnit(uint32(maxHotplugSize.ToMiB())) * utils.MiB) { + newMem = utils.MemUnit(uint32(maxHotplugSize.ToMiB())) * utils.MiB + } cl := clh.client() ctx, cancelResize := context.WithTimeout(ctx, clh.getClhAPITimeout()*time.Second)