From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <root@kvmformation3.odiso.net>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 5794593391
 for <pve-devel@lists.proxmox.com>; Wed,  4 Jan 2023 07:43:42 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 37E5C1B6B8
 for <pve-devel@lists.proxmox.com>; Wed,  4 Jan 2023 07:43:12 +0100 (CET)
Received: from bastionodiso.odiso.net (bastionodiso.odiso.net
 [IPv6:2a0a:1580:2000::2d])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Wed,  4 Jan 2023 07:43:11 +0100 (CET)
Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12])
 by bastionodiso.odiso.net (Postfix) with ESMTP id B49E57BB9;
 Wed,  4 Jan 2023 07:43:04 +0100 (CET)
Received: by kvmformation3.odiso.net (Postfix, from userid 0)
 id B16EF2249A8; Wed,  4 Jan 2023 07:43:04 +0100 (CET)
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Date: Wed,  4 Jan 2023 07:42:58 +0100
Message-Id: <20230104064303.2898194-5-aderumier@odiso.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20230104064303.2898194-1-aderumier@odiso.com>
References: <20230104064303.2898194-1-aderumier@odiso.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.031 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 HEADER_FROM_DIFFERENT_DOMAINS 0.249 From and EnvelopeFrom 2nd level mail
 domains are different
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery
 methods
 NO_DNS_FOR_FROM         0.001 Envelope sender has no MX or A DNS records
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_NONE                0.001 SPF: sender does not publish an SPF Record
Subject: [pve-devel] [PATCH v2 qemu-server 4/9] config: memory: add 'max'
 option
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 04 Jan 2023 06:43:42 -0000

max can be multiple of 64GB only,
The dimm size is compute from the max memory

we can have 64 slots:

64GB = 64 slots x 1GB
128GB = 64 slots x 2GB
..
4TB = 64 slots x 64GB

Also, with numa, we need to share slot between (up to 8) sockets.

64 is a multiple of 8,

64GB = 8 sockets * 8 slots * 1GB
128GB = 8 sockets * 8 slots * 2GB
...

and with virtio-mem,
we can have 32000 blocks of 2M minimum

64GB = 32000 * 2MB

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 PVE/QemuServer/Memory.pm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
index e9c0115..1c4f356 100644
--- a/PVE/QemuServer/Memory.pm
+++ b/PVE/QemuServer/Memory.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use PVE::Tools qw(run_command lock_file lock_file_full file_read_firstline dir_glob_foreach);
 use PVE::Exception qw(raise raise_param_exc);
+use PVE::GuestHelpers qw(safe_string_ne safe_num_ne safe_boolean_ne);
 
 use PVE::QemuServer;
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -25,7 +26,14 @@ my $memory_fmt = {
 	optional => 1,
 	minimum => 16,
 	default => 512,
-    }
+    },
+    max => {
+	type => 'integer',
+	optional => 1,
+	type => 'integer',
+	minimum => 65536,
+	maximum => 4194304
+    },
 };
 
 sub print_memory {
@@ -43,6 +51,9 @@ sub parse_memory {
 
     $res = eval { PVE::JSONSchema::parse_property_string($memory_fmt, $value) };
     die $@ if $@;
+
+    die "max memory need to be a multiple of 64GB" if $res->{max} && $res->{max} % 65536 != 0;
+
     return $res;
 }
 
@@ -223,6 +234,11 @@ sub qemu_memory_hotplug {
     my $oldmem = parse_memory($conf->{memory});
     my $newmem = parse_memory($value);
 
+    # skip non hotpluggable value
+    if (safe_num_ne($newmem->{max}, $oldmem->{max})) {
+	die "skip\n";
+    }
+
     my $memory = $oldmem->{current};
     $value = $newmem->{current};
 
-- 
2.30.2