From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id D41751FF09C for ; Mon, 19 Oct 2026 11:54:02 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E887021694; Mon, 19 Oct 2026 11:53:52 +0200 (CEST) From: Thomas Ellmenreich To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 1/5] drive: improve and extend TPM drive size helpers Date: Mon, 19 Oct 2026 11:53:42 +0200 Message-ID: <20261019095346.175659-2-t.ellmenreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261019095346.175659-1-t.ellmenreich@proxmox.com> References: <20261019095346.175659-1-t.ellmenreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792403627495 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.438 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: AZRUNNYC6MKKMFZ2CZW5CXIXOAC7SBIB X-Message-ID-Hash: AZRUNNYC6MKKMFZ2CZW5CXIXOAC7SBIB X-MailFrom: t.ellmenreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Thomas Ellmenreich X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The size of a created TPM drive is always based on a constant of 4 MiB, but if the backing storage has a larger granularity than this, the TPM silently ignores it. Account for this properly. Adjust the 'update_tpmstate_size' subroutine so that it checks for the actual TPM drive size, but falls back on the constant to ensure a minimum size of 4MiB. Introduce a new 'get_tpmstate_size' subroutine that only determines the current best size and returns it as bytes. Suggested-by: Fiona Ebner Signed-off-by: Thomas Ellmenreich --- src/PVE/QemuMigrate.pm | 7 ++++--- src/PVE/QemuServer.pm | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm index 6605f5d8..3845fb41 100644 --- a/src/PVE/QemuMigrate.pm +++ b/src/PVE/QemuMigrate.pm @@ -685,10 +685,11 @@ sub config_update_local_disksizes { PVE::QemuServer::update_efidisk_size($conf); } - # TPM state might have an irregular filesize, to avoid problems on transfer - # we always assume the static size of 4M to allocate on the target + # TPM state might have an irregular file size, or have increased + # significantly due to differences in granularity. To avoid problems on + # transfer, update the TPM disk size. if (defined($conf->{tpmstate0})) { - PVE::QemuServer::update_tpmstate_size($conf); + PVE::QemuServer::update_tpmstate_size($conf, $self->{storecfg}); } } diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 135c993f..89192e9f 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -7972,14 +7972,35 @@ sub update_efidisk_size { return; } +# Takes a VM config and the storage configuration. Parses the configuration, +# checks the drive size and updates it to a more up to date value and finally +# writes the new size back into the provided config. sub update_tpmstate_size { - my ($conf) = @_; + my ($conf, $storecfg) = @_; + return if !defined($conf) || !defined($storecfg) || !defined($conf->{tpmstate0}); my $disk = PVE::QemuServer::parse_drive('tpmstate0', $conf->{tpmstate0}); - $disk->{size} = PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE; + + $disk->{size} = get_tpmstate_size($disk->{file}, $storecfg); $conf->{tpmstate0} = print_drive($disk); } +# Takes in a volume id and the storage configuration. Will then try to find +# the actual storage size of the TPM drive. +sub get_tpmstate_size { + my ($volid, $storecfg) = @_; + + return if !defined($volid) || !defined($storecfg); + + my $size = eval { PVE::Storage::volume_size_info($storecfg, $volid, 10) }; + + if (!$size || $size < PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE) { + $size = PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE; + } + + return $size; +} + sub vm_iothreads_list { my ($vmid) = @_; -- 2.47.3