From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAC23CCA471 for ; Fri, 3 Oct 2025 15:56:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v4huu-0005Qu-IU; Fri, 03 Oct 2025 11:41:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v4huF-0004wf-SO for qemu-devel@nongnu.org; Fri, 03 Oct 2025 11:41:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v4htf-0007h9-3S for qemu-devel@nongnu.org; Fri, 03 Oct 2025 11:41:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759506033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KfG73FUocIV7TIWN4Dkf/geLVmg1Zdm6vjeMUbHZ264=; b=jTcrpCOG7VXDIfgPP1G3fRr2qdvLMwSpRh5ymMPG1EDewzKfFluinWMQaSFcZXJ1+334rQ 8yn9NHh5+/zMAXp9+d4H0cFk4W5vHjdjbxtlpBfalAsQW1mlI1Y/JK0GGMkLujEWL82Seb EUXICw8d10r8XWI9nsniYiNG8xOk2S4= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-aG_2T5QYObezjKalLGYozA-1; Fri, 03 Oct 2025 11:40:31 -0400 X-MC-Unique: aG_2T5QYObezjKalLGYozA-1 X-Mimecast-MFC-AGG-ID: aG_2T5QYObezjKalLGYozA_1759506031 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-81a8065daf4so29083066d6.0 for ; Fri, 03 Oct 2025 08:40:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759506031; x=1760110831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KfG73FUocIV7TIWN4Dkf/geLVmg1Zdm6vjeMUbHZ264=; b=RPCwTH96kuJrcPsguNuCqf3i+6/7Z/lf9CwX82gccuLCJXEhLoxxsU3N1c8clMRuJs fkMivaQa82kwRkhpi8Q0+mMt4Cd4cRQkk7HgE0UJaSgd1LJ0l6IR7C+5+atNA+xLYvR9 clUos3EYxHfwsRQDARlmIw7rye+EEFSFp6AfkcVnjQGvWKkJZZ/i4ggY8alL0zXXHr0M 0+CE1oLONqHFSMobbVcD9bWmMJCsBbBWKzfTSFkRZncovsNQ1TnK3RMzNi4pr6Pqw2CT A/kPlZMMyPPMgLyFJ4McKz2QxLJcQy7ShFQSSyTk+nMA2b/47b4TWIMp57MNtvDkODKR nenA== X-Forwarded-Encrypted: i=1; AJvYcCW+KJpvqi9//8eTDEGS9e2E2iX6sOOaYo4N6D6jUL/5nhKwiq647CZIOGkfTBW257n8F5VU1dw8HpS+@nongnu.org X-Gm-Message-State: AOJu0Yxx2jNJTs8DfOG+D15BZ8D0uJj4w1LrucoYqqH8FnllXtWrMKBR S4GQ0wdu46byHFeNPMrlmf3sFilj472xGGoMrMGvIu7ax0YnLcDsTyDgDZ/8VIU9eg8gI73LiFR k28WtFGOjpeM0bfshwJtMEa3vu0sTkbPAAU8b0kNdonVgMR/8cY3SKLBQ X-Gm-Gg: ASbGncsRg9QNJYkObDDzo1KHfrkt7hBvSo8MziZx88vTHffBMo1ZYSCz+hV4bm8nANf GFlVDq83KqIYiF44WDaOij7OBJ1pZi8YEqLqVP8GN+jeNVvchHEclKtz7Mrg/Dno5TV+bS1z2R4 9s4US2q0aKl747I6GRlmqLSsPZZqY/Upt7+SImKkV5fqT5benIxpqOWEd+J1/FLI7sYuWqbtu9l cZrNG07ritft8oRU5XbeExW0OD8msk9URTmSYsTYXXYaC3/Csj0reA9gZKK6sFcsHhj+4KA/hQS mk2RWh/mZNpUJSSwhjL3njT2aEINxOnaax48Kw== X-Received: by 2002:a05:6214:212d:b0:775:1d3:d07f with SMTP id 6a1803df08f44-879dc7b4d50mr41489996d6.11.1759506030364; Fri, 03 Oct 2025 08:40:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHq0L3J6/65QcdI01Dk/0ylNPI7IzRNFvuM0fXNmCZ3GDg631zPIB9/UVBD6aw/Jv7zX6YPkw== X-Received: by 2002:a05:6214:212d:b0:775:1d3:d07f with SMTP id 6a1803df08f44-879dc7b4d50mr41489526d6.11.1759506029735; Fri, 03 Oct 2025 08:40:29 -0700 (PDT) Received: from x1.local ([142.188.210.50]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-878bb53d91fsm40656746d6.23.2025.10.03.08.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Oct 2025 08:40:29 -0700 (PDT) From: Peter Xu To: Peter Maydell , qemu-devel@nongnu.org Cc: Fabiano Rosas , peterx@redhat.com, David Hildenbrand , Paolo Bonzini , Arun Menon , Stefan Berger , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Akihiko Odaki Subject: [PULL 26/45] backends/tpm: Propagate vTPM error on migration failure Date: Fri, 3 Oct 2025 11:39:29 -0400 Message-ID: <20251003153948.1304776-27-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251003153948.1304776-1-peterx@redhat.com> References: <20251003153948.1304776-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.467, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Arun Menon - When migration of a VM with encrypted vTPM fails on the destination host, (e.g., due to a mismatch in secret values), the error message displayed on the source host is generic and unhelpful. - For example, a typical error looks like this: "operation failed: job 'migration out' failed: Sibling indicated error 1. operation failed: job 'migration in' failed: load of migration failed: Input/output error" - Such generic errors are logged using error_report(), which prints to the console/monitor but does not make the detailed error accessible via the QMP query-migrate command. - This change, along with the set of changes of passing errp Error object to the VM state loading functions, help in addressing the issue. We use the post_load_errp hook of VMStateDescription to propagate errors by setting Error **errp objects in case of failure in the TPM backend. - It can then be retrieved using QMP command: {"execute" : "query-migrate"} Buglink: https://issues.redhat.com/browse/RHEL-82826 Reviewed-by: Stefan Berger Reviewed-by: Daniel P. Berrangé Reviewed-by: Fabiano Rosas Signed-off-by: Arun Menon Tested-by: Fabiano Rosas Reviewed-by: Akihiko Odaki Link: https://lore.kernel.org/r/20250918-propagate_tpm_error-v14-27-36f11a6fb9d3@redhat.com Signed-off-by: Peter Xu --- backends/tpm/tpm_emulator.c | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index 4a234ab2c0..dacfca5ab7 100644 --- a/backends/tpm/tpm_emulator.c +++ b/backends/tpm/tpm_emulator.c @@ -819,7 +819,8 @@ static int tpm_emulator_get_state_blobs(TPMEmulator *tpm_emu) static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, uint32_t type, TPMSizedBuffer *tsb, - uint32_t flags) + uint32_t flags, + Error **errp) { ssize_t n; ptm_setstate pss; @@ -838,17 +839,18 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, /* write the header only */ if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_STATEBLOB, &pss, offsetof(ptm_setstate, u.req.data), 0, 0) < 0) { - error_report("tpm-emulator: could not set state blob type %d : %s", - type, strerror(errno)); + error_setg_errno(errp, errno, + "tpm-emulator: could not set state blob type %d", + type); return -1; } /* now the body */ n = qemu_chr_fe_write_all(&tpm_emu->ctrl_chr, tsb->buffer, tsb->size); if (n != tsb->size) { - error_report("tpm-emulator: Writing the stateblob (type %d) " - "failed; could not write %u bytes, but only %zd", - type, tsb->size, n); + error_setg(errp, "tpm-emulator: Writing the stateblob (type %d) " + "failed; could not write %u bytes, but only %zd", + type, tsb->size, n); return -1; } @@ -856,17 +858,17 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, n = qemu_chr_fe_read_all(&tpm_emu->ctrl_chr, (uint8_t *)&pss, sizeof(pss.u.resp)); if (n != sizeof(pss.u.resp)) { - error_report("tpm-emulator: Reading response from writing stateblob " - "(type %d) failed; expected %zu bytes, got %zd", type, - sizeof(pss.u.resp), n); + error_setg(errp, "tpm-emulator: Reading response from writing " + "stateblob (type %d) failed; expected %zu bytes, " + "got %zd", type, sizeof(pss.u.resp), n); return -1; } tpm_result = be32_to_cpu(pss.u.resp.tpm_result); if (tpm_result != 0) { - error_report("tpm-emulator: Setting the stateblob (type %d) failed " - "with a TPM error 0x%x %s", type, tpm_result, - tpm_emulator_strerror(tpm_result)); + error_setg(errp, "tpm-emulator: Setting the stateblob (type %d) " + "failed with a TPM error 0x%x %s", type, tpm_result, + tpm_emulator_strerror(tpm_result)); return -1; } @@ -880,7 +882,7 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, * * Returns a negative errno code in case of error. */ -static int tpm_emulator_set_state_blobs(TPMBackend *tb) +static int tpm_emulator_set_state_blobs(TPMBackend *tb, Error **errp) { TPMEmulator *tpm_emu = TPM_EMULATOR(tb); TPMBlobBuffers *state_blobs = &tpm_emu->state_blobs; @@ -894,13 +896,13 @@ static int tpm_emulator_set_state_blobs(TPMBackend *tb) if (tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_PERMANENT, &state_blobs->permanent, - state_blobs->permanent_flags) < 0 || + state_blobs->permanent_flags, errp) < 0 || tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_VOLATILE, &state_blobs->volatil, - state_blobs->volatil_flags) < 0 || + state_blobs->volatil_flags, errp) < 0 || tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_SAVESTATE, &state_blobs->savestate, - state_blobs->savestate_flags) < 0) { + state_blobs->savestate_flags, errp) < 0) { return -EIO; } @@ -948,12 +950,12 @@ static void tpm_emulator_vm_state_change(void *opaque, bool running, * * Returns negative errno codes in case of error. */ -static int tpm_emulator_post_load(void *opaque, int version_id) +static int tpm_emulator_post_load(void *opaque, int version_id, Error **errp) { TPMBackend *tb = opaque; int ret; - ret = tpm_emulator_set_state_blobs(tb); + ret = tpm_emulator_set_state_blobs(tb, errp); if (ret < 0) { return ret; } @@ -969,7 +971,7 @@ static const VMStateDescription vmstate_tpm_emulator = { .name = "tpm-emulator", .version_id = 0, .pre_save = tpm_emulator_pre_save, - .post_load = tpm_emulator_post_load, + .post_load_errp = tpm_emulator_post_load, .fields = (const VMStateField[]) { VMSTATE_UINT32(state_blobs.permanent_flags, TPMEmulator), VMSTATE_UINT32(state_blobs.permanent.size, TPMEmulator), -- 2.50.1