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 520F6C83F1B for ; Wed, 16 Jul 2025 10:52:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubzi3-0002la-Jx; Wed, 16 Jul 2025 06:50:03 -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 1ubzeo-0001NC-VJ for qemu-devel@nongnu.org; Wed, 16 Jul 2025 06:46:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubzem-0000sn-EF for qemu-devel@nongnu.org; Wed, 16 Jul 2025 06:46:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752662795; 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=VB7ywUEVqmA3oghObQBPFE3seKY/3Bw1DaxOoNhDBBY=; b=CyU7tYKI4t7PE02+Bwk0DQRmX3VF3gw8vALIhAcy820rNe8LZUAgEFRCMAJ64xvlPhJbfM WNKAwtsMVT5yC8sCzaDxvLVVF7B+zj+1xZHUSdGGzrTdLeYZlP/OWU+Aa+9KVJsgxdHZWp Wppr/LwSYFRLquK+KdLEL6A9PlqJ9N0= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-TgeZmAZfPmSvKT9iKcdRiA-1; Wed, 16 Jul 2025 06:46:34 -0400 X-MC-Unique: TgeZmAZfPmSvKT9iKcdRiA-1 X-Mimecast-MFC-AGG-ID: TgeZmAZfPmSvKT9iKcdRiA_1752662793 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-313c3915345so9298245a91.3 for ; Wed, 16 Jul 2025 03:46:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752662793; x=1753267593; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VB7ywUEVqmA3oghObQBPFE3seKY/3Bw1DaxOoNhDBBY=; b=gauyGRaZE33cBafRLpNNT2SgGCmxYwFtnKf+b+qW10AI0yPOp6cgkbZQ5stPQ77dsJ +WM+y9QDJ3tEUML8q1lrtLHzYpcoFjKGQkvHkMO/DwNlu6mx9eGY+4aJ8Pe5rQF9OB94 wy+BjZkT864klRoSXBjFeQEhIrv5aKiLw9snZwoz9huv+TMoopQe5Ylnm9NheY8E/eHy 7BPj1Z908KXfM42BDbEThMvbgleGbTJ43/BYbRl92xx8MmveebsU8jkmV4mUX9YU1W/8 h/Pivubs1o30ONt/gK0M+O3LEgi4T1g7WXpYrJZykjRnmLwb3llbOuQbaXisVoK444qe UO4w== X-Gm-Message-State: AOJu0YwfGrl9hXCaGtRpKvnAKckSfCo2jXRlmpxIYZFQJzb3JJAwcFjR cvUeXmkDAXKJWRrJ6z4P/LV1sKW4FLbmGX6Lv3+st3TsLpObC4nKvkgUKLCOtPtiuYEti3ACQKT IeIEbkbNpdFVIB3IYrCk8qhz8frR7rS1Xh3lEF2oDH7+yWzlSjTGAQcur X-Gm-Gg: ASbGnctmmrW5Nq08SwnDWKEOUTYSP2QiWFmfYmRuAYDy4jADM1C5hvBzuLY2j6zISJK 7C0ZoVKODbXFNyvcSnxCHPS0wY1wja42wsYcQpr4NJjpuwfVm+XzQA4ZH1mN9Lcaj0lPYXcpxAI 6iT9LuH2yN7mcDYe9SnFiSzWbWsX9ZCOoUMkvZCQUnxeS/ayisjf+Bz+RMWvupPAfrK8QTE/Dm8 M8Lc7ODuaycmC7KEV6OBLbovNIuAxxUCZ+RMB3DJPXAUH5nwV3jiHPZgxbGE7OBCijQHuC419tH rEKN1H5q1nXgms3v9SuMP9OTzbOnBfAdRYWxCDdmiY6tJ+Uk0w== X-Received: by 2002:a17:90b:2707:b0:31c:15d9:8a5 with SMTP id 98e67ed59e1d1-31c9e76aa99mr3565476a91.19.1752662793338; Wed, 16 Jul 2025 03:46:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeWRxHIik1dK5kGqGPffuearQ/eEZrGtR6LPebeMcXg8zlsBfzfTrVidIomQs6pd3wSkpAtw== X-Received: by 2002:a17:90b:2707:b0:31c:15d9:8a5 with SMTP id 98e67ed59e1d1-31c9e76aa99mr3565439a91.19.1752662792805; Wed, 16 Jul 2025 03:46:32 -0700 (PDT) Received: from armenon-kvm.bengluru.csb ([49.36.97.1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de435baccsm123363265ad.227.2025.07.16.03.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 03:46:32 -0700 (PDT) From: Arun Menon Date: Wed, 16 Jul 2025 16:13:13 +0530 Subject: [PATCH v4 23/23] backends/tpm: Propagate vTPM error on migration failure MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250716-propagate_tpm_error-v4-23-7141902077c0@redhat.com> References: <20250716-propagate_tpm_error-v4-0-7141902077c0@redhat.com> In-Reply-To: <20250716-propagate_tpm_error-v4-0-7141902077c0@redhat.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , Cornelia Huck , Halil Pasic , Eric Farman , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Thomas Huth , Christian Borntraeger , Paolo Bonzini , Fam Zheng , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Xu , Fabiano Rosas , Hailiang Zhang , Steve Sistare , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Stefan Berger , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Matthew Rosato , Arun Menon , Stefan Berger X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6614; i=armenon@redhat.com; h=from:subject:message-id; bh=lhIHMpU0qkadz4azlKtjxrgPGcXYLFkklrIa1moEZ6E=; b=owGbwMvMwCWWVaVqcZPfqI/xtFoSQ0Z5k4P1WyddPseslZdZnNMXvI9a+avmwKsV0/SmTTN/2 i80IUG+o5SFQYyLQVZMkaXha4BsU0BhRKTty+swc1iZQIYwcHEKwETmyTEyzHm5Z+L9v7+XLeg6 NsGyYdHvEzlukil1Gaz+30ocxbbP3czIsOe3bMc+sYCtu1LakzsYsz9y616vXFBlyWD5rdf21SM uNgA= X-Developer-Key: i=armenon@redhat.com; a=openpgp; fpr=80F5501D82507158593DE9D76A7A2538D90F328E Received-SPF: pass client-ip=170.10.133.124; envelope-from=armenon@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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 - 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 Signed-off-by: Arun Menon --- backends/tpm/tpm_emulator.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index 4a234ab2c0b19b2604bf0dd8cb5f4540c72a9438..9bf5927e8e1542cf2e4f2275783d32853d5f1473 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,17 @@ 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(errp, "tpm-emulator: could not set state blob type %d : %s", + type, strerror(errno)); 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 +857,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 +881,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 +895,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 +949,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 +970,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.0