From nobody Mon Sep 21 11:45:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1785930781; cv=none; d=zohomail.com; s=zohoarc; b=jiped+6f28hO6j/TR6IubacSYyBMqg11X7C0o5JzXd73KQA2n+FTHTcPwCCMEeOSaWF0k8lMvY1bLtVY3haEi6/QEw3gt1oB6DVC2ms/xiZmZu2fZc3agyunRh+aqRyJeZPkeged2Fhp6khnElOrtM3F9lrpIHmm2THKKV/DqgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785930781; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Osfx8gZJrB7dh/sUZUFu7wXoAjXOKWpsoAdI1+KIrJ4=; b=REg+leSxS6csNpdWdmo592gCTtXGo/IgFG8jP6Hk1nszjRenFWALt6fuQXNXI6dIwat9iFSxR4GO7ubQp4ICpakgMGEUrJq4a8stWOHO0bWo4T+aq4Jq3gXTe1J+iTkPwdjd4bmMcz8QeIAfr6VUVYjOjZ6aEo2TwAcAwAIypAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1785930781117669.4817268031098; Wed, 5 Aug 2026 04:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wraAn-0005lO-BF; Wed, 05 Aug 2026 07:52:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wraAm-0005l5-0T for qemu-devel@nongnu.org; Wed, 05 Aug 2026 07:52:36 -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 1wraAk-0006uW-DJ for qemu-devel@nongnu.org; Wed, 05 Aug 2026 07:52:35 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-eHNH-eN9Pe6CPG8v2WK9tg-1; Wed, 05 Aug 2026 07:52:27 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8811A1955DBE for ; Wed, 5 Aug 2026 11:52:26 +0000 (UTC) Received: from localhost (unknown [10.44.22.2]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC5C6422; Wed, 5 Aug 2026 11:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785930753; 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=Osfx8gZJrB7dh/sUZUFu7wXoAjXOKWpsoAdI1+KIrJ4=; b=hfkQQAVe3W9SBSYKN2G8q0I7WNFS1LUIp2AmsYq4SJ+LkjGMcvEKohqw1cqE6CesdmS7Y4 DKEBY44nheQCKdsChjxpzU5RWZFOEYhT+qqbCyoYV83zI+Mh1w+GDsbtdnUHggYJLKQqgB fFR+8wW17P7v7cZanXiBu64yRqBnJfE= X-MC-Unique: eHNH-eN9Pe6CPG8v2WK9tg-1 X-Mimecast-MFC-AGG-ID: eHNH-eN9Pe6CPG8v2WK9tg_1785930746 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 05 Aug 2026 15:50:57 +0400 Subject: [PATCH 07/27] hw/usb/dev-smartcard-reader: block migration with pending queues MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260805-smartcard-fixes-v1-7-187ee9122441@redhat.com> References: <20260805-smartcard-fixes-v1-0-187ee9122441@redhat.com> In-Reply-To: <20260805-smartcard-fixes-v1-0-187ee9122441@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=2161; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=xzskyDLi6FbuDSwTo5I/zb0dvLyg/dAAIh1/km1p3Xo=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqcyOs4IDy37k+DXBdi2iKm1NJxCZ/4f38m7avz euH/rcoaVGJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCanMjrAAKCRDa6OEJdZac 5aWoD/0c75VSrVEZNCourY5CMQbXlBtUuj+nXf82Nnrj28MhNvl++st3cDZn3CG3oP80J9SQps6 M40vRmHHflhaotIb9qAAOTZV0NDqxZqOXyjtPDIrK/O39r/gGVjAGFd9Y96bjKjCGaNoITtbLoB aSBrYZatHb6TMK2eroHqi2Mpsc4I5umx0HJAbveZXNobvf7xAOP6I68J1LFP3SYgSw6QcLmpgea hsAmTPSgtXuz7G/rpmBWP3RKeBwR5WTRE728ODmVbw2wtEpKbUnMBzpQis+njTZFksKGyhZQ1bO mlkNxnhKWhwRSK0BMGO6xMORM4SrO6SEIjfTk4zuFiNCtjHnA4mEZFqba7D9XwW0KNUd8YcxHYP ZOYNkNIQ8uDkUMWe35Ws1laMO5+Nw+Kxm4W5s/6QEXo/kfYZWzcn63kb/JO8pimBlr2auq4rr0W SAJ7JAkg6kbuzt/FoFy0iHDVkA9h1K/MO0UvM9cIzmVJURzbrHt0RU30PwlFRBIYkg9uhvE7Ewp oq6BS/cb68Nq2BZvr1nPw1dnY25hYsOrkHj8SQLfDeKtDjaGrZuysiPGUhdpWRWyvIpkG+/fUP+ RuVncv6zJZ9SvGGCcRqkwC5SBKcAIxkp9W3U/qfLfzj6y0WOLsZFGydZ4QK7ykzjz6RrP1qnJXp bAqxXLRyLFkwS6g== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.852, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1785930781272158500 Several queue state fields are not included in the vmstate: bulk_in_pending_num, pending_answers_start, and pending_answers_end. Also if current_bulk_in !=3D NULL (ongoing transfer). Migrating while any of these are non-zero produces inconsistent state on the destination. Rather than extending the vmstate (which would require a version bump and migration compat machinery), block migration when the queues are non-empty. In practice this window is very short since the CMD_SLOT_BUSY enforcement limits pending_answers to at most one entry. Convert pre_save to the pre_save_errp form so it can report the error cleanly. Follow up patches will add migration blocker and new migration version. Fixes: 367071447ec5 ("usb-ccid: add CCID bus") Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/usb/dev-smartcard-reader.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index a147cd19f388..1b8f0e10e172 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -1377,13 +1377,20 @@ static int ccid_post_load(void *opaque, int version= _id) return 0; } =20 -static int ccid_pre_save(void *opaque) +static bool ccid_pre_save(void *opaque, Error **errp) { USBCCIDState *s =3D opaque; =20 + if (s->pending_answers_num || s->bulk_in_pending_num || + s->current_bulk_in) { + error_setg(errp, "usb-ccid has pending queue state which cannot be= " + "migrated safely"); + return false; + } + s->state_vmstate =3D s->dev.state; =20 - return 0; + return true; } =20 static const VMStateDescription bulk_in_vmstate =3D { @@ -1426,7 +1433,7 @@ static const VMStateDescription ccid_vmstate =3D { .version_id =3D 1, .minimum_version_id =3D 1, .post_load =3D ccid_post_load, - .pre_save =3D ccid_pre_save, + .pre_save_errp =3D ccid_pre_save, .fields =3D (const VMStateField[]) { VMSTATE_STRUCT(dev, USBCCIDState, 1, usb_device_vmstate, USBDevice= ), VMSTATE_UINT8(debug, USBCCIDState), --=20 2.55.0