From patchwork Tue Apr 30 05:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13648267 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 A8966C4345F for ; Tue, 30 Apr 2024 05:17:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1frO-0000jH-2C; Tue, 30 Apr 2024 01:16:58 -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 1s1frJ-0000iv-Nt for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:16:53 -0400 Received: from mail-bn7nam10on20601.outbound.protection.outlook.com ([2a01:111:f403:2009::601] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1frG-0006Zo-Cz for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:16:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OkEOumpr85qT6dMuTO4PsYiRbNKDrh8U0lyETBhHSpCekpIQMCWlvwqF0x/CD1HR3FxIeMeDAeyFM9p4Wlk/jfWkXSDCFLJAREyoue+5UlUJwtgS8tSoZLCKPVlusE3ECUtg0KR/JFC3PdWpVEiwgA99+d4dgHSccPzBPOmHnJZiqHOiiLCU/BGwy9QNlCHMRNDW9hIl8thalnq6wp3+u6oF6hbQKdMx/XUFdpzofbeS/pfBuwtoYFfswo6Th6a7YmMe5qw0QoMpFShXIvG8XWnF5gqgeebWTwMin7LVhTxwkjGeAzYesi0QqO+5fHyRRmB/czTMs2SMvqNor/h6HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PSglfxLsM4KMhQ6WV6via/0uDKuW4tyx8UYxK35Oux4=; b=mD80QyditjtIAIHB1bxVV3fMS5eWEhpmSEkLs+lBNO9T4CrEtfdA4JcmcL+yxh8RwJxbJDN2aepeD6k6iN0+i5UxHQewh+K5vxMER+lPrvPsjq9JV073Y2pCeesAurY5NM80GVVmIOmawh92fTYuEex2+6grCtK0CMMtWUd0T5A5bvAJHmu1iNfITjoUEWI7iMBmEvBNv3Pny4SKiXHG2lOTMXOlqxGmBxK7ALIdHCqUpdIkMdVvVnc0+EKwr3QQ9ZXToHjfjkISQW3uowAWI9IrOxohoeIRsAqcMiobeu6FuP4kFowJQ7CVIfWynCTs4AGFNwGsDV8qsDcf4b+N7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=nongnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PSglfxLsM4KMhQ6WV6via/0uDKuW4tyx8UYxK35Oux4=; b=Wbe7UvjAYWsmMeklOrGCUNhIDNaBn3bSn4rE+lyUJR5a+T80i2Y9BcFZtEbnHCJ9SDcJb6FqbF49+0G96BgyUZ/AzV6L6Qx1WHN22/AiGIOBSJ7e+N0L7r1dbso4mycqqbI9jlbnrCb8iXVMCqlo73F3gFbZcSIsOIwCkL34A2XBkJ+RbNmQDjhLgIjLNj2/Glohc0YyPvTjr3qdoxgafS1lVNfMt4hIpObe7G2UKC5VpSIhcZiNlz10GVyJZwFDCWQ7FplhcWLdW8FLKx522tCOSnX8Ggz4byWZZ50/KfyVEHleXOgey+sQlktTVx8deXB3sDIYiVmAugTs8udHVA== Received: from BN9PR03CA0194.namprd03.prod.outlook.com (2603:10b6:408:f9::19) by PH7PR12MB9068.namprd12.prod.outlook.com (2603:10b6:510:1f4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 05:16:45 +0000 Received: from BN1PEPF0000468E.namprd05.prod.outlook.com (2603:10b6:408:f9:cafe::64) by BN9PR03CA0194.outlook.office365.com (2603:10b6:408:f9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.32 via Frontend Transport; Tue, 30 Apr 2024 05:16:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN1PEPF0000468E.mail.protection.outlook.com (10.167.243.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 05:16:44 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:28 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:28 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 29 Apr 2024 22:16:25 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Markus Armbruster , Michael Roth , Eric Blake , Peter Xu , Fabiano Rosas , Joao Martins , Maor Gottlieb , Avihai Horon Subject: [PATCH 1/3] qapi/vfio: Add VFIO device migration state change QAPI event Date: Tue, 30 Apr 2024 08:16:19 +0300 Message-ID: <20240430051621.19597-2-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20240430051621.19597-1-avihaih@nvidia.com> References: <20240430051621.19597-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468E:EE_|PH7PR12MB9068:EE_ X-MS-Office365-Filtering-Correlation-Id: 13c9ef40-dbfa-4d32-1a5d-08dc68d4ba4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|82310400014|376005|36860700004; X-Microsoft-Antispam-Message-Info: 4ZiPFJCiezK9FUYbNYysToliB/eNsBeUzi+k7Axr7gF2vRo/UWyOtlCQyexNiowAjZdhgJopqFZGkgaon+OqEH4OV4Sx/xnCUMdOxzLhwGar5DHlRn9Or4UwMvD4A3F7uXJrY22Nne1XqVQGaPF9olgphWzWLDZVOkcxAy1aN0kMoH9z3XpEhaK637q6XpgGXEtF6wQPjOTXaEMyz7AQM65g85PDs4OsLBVI+1gARm/q/j3Z7L+K1nEpf5qQQ05ICtJ7Tv3+CR1p/EmEbv1hL3top/kVDSzr2xsbQaksmZfoG5zYFom2epuykQ7lYmGa6znFz3z/wdWhAuVPW9E1LsnPhPaJp2sHylBdezfZ2Sq924vOZUwpy/luiqvoSR0m+jvQo4kMmKDf7JI+nIHLNG+JPSmW8DaeP8Cj7YRWgaeHJlT3Ti/RCEUKbRKSaUn9zl5eHbj49OnX5/w7yhm8uhBppOeSkXZ9VHm9IMtlFCa5Un6cvlEhtCfNokU4Aj+kdF6RCb2+dNfg1ZpkSl2STT0bLL0uSz7XzygU+k0c4pndAsCZqqeWkHKsnFPHG6E0sJgyYsnUv0rR4f/yxns+LEikUJ2O8KtJGv/MS3HGWB87u2fhWJQdY+TRzUdLSdlObdkgWDPyzZuxeeN+B0nMlymx5jov2WakioqYGnqVLE+D6XgIp4/8xcx6S8/6cvHRcN9hczxprbLk/pwsechLeVRAKWVRRf+HV36Y00/wbkF+OrrPCxQxx8e4uiE2/xHASSQLpLT0fYprCsNeu/eUz18L6qv6j5D5skncv98etoSybPgN3S4kKklF2+l7yHCdDy+nnkjojRKO834UWYhmkamHe52hbTteHOwzJfsFb7v+g+pT/38ayAZy31lwLhAji0DQlOrT/8Llqktc9Mj+r9kiEXJ1/mRFMUDOORmlhetDUbGdD5WT+98C4WJ7hsGk34pehb2bEMhP/wpnidqKTxxSaHWWKQ/qYDIeboLHW1+L2s6gl05ajK8l4HMk9naE1UL3R8AGS9Eynh9V74K0RIR3t6FNZ5dwCK+BC3waImLVrdbT1ElR7KmhBv9mI6sVpz41CM454kbuQGpgXnqhU4NkLsvud1I1cu6Co802QKkLJoQd/Otrzcbq6AyZMw3zHQkzPadeF73d8GEC80IwTbhU6Odu+a3DfMTD9sMZdKg5XhemdA+TeGqp0h7TovDh6jFYhU1riNhtkZ8i1hS39Awno2tTus8vMeIn4oHkEGuWyEdToQ6oBPQFvZVcRDxvkcSzajjlwpc7wkPRMbh9XZ/+9tdppjQCtBlwcoQmdvHzshu+KigkXAOOe9U3yDIqpO8BQ6Igwepyb5eheT/SgSChxY+mO1zuNMoFKPKd02RufIxQhvkNf43BPuXSbnkW X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(1800799015)(82310400014)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 05:16:44.5641 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13c9ef40-dbfa-4d32-1a5d-08dc68d4ba4c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9068 Received-SPF: softfail client-ip=2a01:111:f403:2009::601; envelope-from=avihaih@nvidia.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.987, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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 Add a new QAPI event for VFIO device migration state change. This event will be emitted when a VFIO device changes its migration state, for example, during migration or when stopping/starting the guest. This event can be used by management applications to get updates on the current state of the VFIO device for their own purposes. Signed-off-by: Avihai Horon --- MAINTAINERS | 1 + qapi/qapi-schema.json | 1 + qapi/vfio.json | 61 +++++++++++++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + 4 files changed, 64 insertions(+) create mode 100644 qapi/vfio.json diff --git a/MAINTAINERS b/MAINTAINERS index 302b6fd00c..ef58a39d36 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2159,6 +2159,7 @@ F: hw/vfio/* F: include/hw/vfio/ F: docs/igd-assign.txt F: docs/devel/migration/vfio.rst +F: qapi/vfio.json vfio-ccw M: Eric Farman diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 5e33da7228..b1581988e4 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -78,5 +78,6 @@ { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' } +{ 'include': 'vfio.json' } { 'include': 'cryptodev.json' } { 'include': 'cxl.json' } diff --git a/qapi/vfio.json b/qapi/vfio.json new file mode 100644 index 0000000000..a38f26bccd --- /dev/null +++ b/qapi/vfio.json @@ -0,0 +1,61 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# + +## +# = VFIO devices +## + +## +# @VFIODeviceMigState: +# +# An enumeration of the VFIO device migration states. +# +# @stop: The device is stopped. +# +# @running: The device is running. +# +# @stop-copy: The device is stopped and its internal state is available +# for reading. +# +# @resuming: The device is stopped and its internal state is available +# for writing. +# +# @running-p2p: The device is running in the P2P quiescent state. +# +# @pre-copy: The device is running, tracking its internal state and its +# internal state is available for reading. +# +# @pre-copy-p2p: The device is running in the P2P quiescent state, +# tracking its internal state and its internal state is available +# for reading. +# +# Since: 9.1 +## +{ 'enum': 'VFIODeviceMigState', + 'data': [ 'stop', 'running', 'stop-copy', 'resuming', 'running-p2p', + 'pre-copy', 'pre-copy-p2p' ], + 'prefix': 'QAPI_VFIO_DEVICE_MIG_STATE' } + +## +# @VFIO_DEVICE_MIG_STATE_CHANGED: +# +# This event is emitted when a VFIO device migration state is changed. +# +# @device-id: The id of the VFIO device (final component of QOM path). +# +# @device-state: The new changed device migration state. +# +# Since: 9.1 +# +# Example: +# +# <- {"timestamp": {"seconds": 1713771323, "microseconds": 212268}, +# "event": "VFIO_DEVICE_MIG_STATE_CHANGED", +# "data": {"device-id": "vfio_dev1", "device-state": "stop"} } +## +{ 'event': 'VFIO_DEVICE_MIG_STATE_CHANGED', + 'data': { + 'device-id': 'str', + 'device-state': 'VFIODeviceMigState' + } } diff --git a/qapi/meson.build b/qapi/meson.build index c92af6e063..e7bc54e5d0 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -52,6 +52,7 @@ qapi_all_modules = [ 'stats', 'trace', 'transaction', + 'vfio', 'virtio', 'yank', ] From patchwork Tue Apr 30 05:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13648268 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 EFCECC25B10 for ; Tue, 30 Apr 2024 05:17:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1frU-0000jx-AJ; Tue, 30 Apr 2024 01:17:04 -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 1s1frJ-0000iw-UT for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:16:54 -0400 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1frG-0006Zr-I2 for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:16:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=brGOo5CViVz3hLu+qAaUgcr3Sr0IPrx1KP3wQz/Nx+yhpPTsHqwUqe3T8JegPQrjnnEboXTJyYLu679IPYQUzeTIxK43iWi5CoykI1+mw1DuBontWgr7cYslhA69bgwXnSEg8o2WphtWgx7ZGwzxgCrp265oMIl82kjUXvipZ6FACVpy2CxCLPNjnGIt/eHe35n8OGAMPhIT8eHjceH/M8qXCAaIxkvD8GM+RRQT4HDeiVdwYbUIG3FkI6wBwCBNs0a9Jiw8LmipMkmUnvtpSn0oGktjFkwAZvmSWCYd53zcUWfFcqad+HnhluDDXJe2rekHGKT/QApz+6hWqSyq4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=trL3uBjO5cicwCkNsL9K2hS9t77/0ZNOOJldkgzrGNU=; b=YJxUF7Lly2dZ8pno1Xf/N2hrichUZut6NNP1jTfwEbb/ExqgxZSgTBobJZCjIJ+GV+nvlESb/lRdmm+gFO643ytb6EBV/qE2L7FgQLh9v63HrmwHio/uHriF34PQP72IdqDrTqPqMaHdZ5YjfZ/9R7aNbDa2NL3bci0RCJ2Xqk3kjVLjsvF2RJtlVr+g19Lre7Zmgnx3FNtgF0JS+9017motYpL9iT2M1mTCaT5nDIieCklkX7qZHZrPW+i2oNqE4kO9KEZHxvFxAEPTqlXtpsHfIW2iQfibLhN9q9chKHw9pAMgIvJUN93z7mwTl+BZZokjRHpvDUSj1x1L+Pz8Ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=nongnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=trL3uBjO5cicwCkNsL9K2hS9t77/0ZNOOJldkgzrGNU=; b=EICAoWGqhu+iUCis2bGv8IPUBI6kh8ashzrH0GoCWBtURgnx1so1WbKOV+7uZoxagCqomK2vrl+puA0uTMJ2CbebzdOgwL5vwMuelSbSLlzLp3itz6YFflxQaMjxlpg0MvhnkZ9Axz8RQT/3pAv1G/7btLun06oyuecNRrMi6hkmWliVW8t8/tLe+lDh9rfRlGP1tErA4fi1i+Bm7dyuwqDOYBw5mrdj8qK6tOznBlwzrLvgrAgWzO2HiXNPdttc6VhOmwDoaDfyU/BPqjEKWXcb0+9m2AxUtY+lPyPjaU31bEHbJqK6qO9fHNZIQj0ONrA8bjaGJyHCjs1DHfWMmg== Received: from SJ0PR13CA0016.namprd13.prod.outlook.com (2603:10b6:a03:2c0::21) by IA1PR12MB8310.namprd12.prod.outlook.com (2603:10b6:208:3ff::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.36; Tue, 30 Apr 2024 05:16:45 +0000 Received: from CO1PEPF000066EA.namprd05.prod.outlook.com (2603:10b6:a03:2c0:cafe::4e) by SJ0PR13CA0016.outlook.office365.com (2603:10b6:a03:2c0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.21 via Frontend Transport; Tue, 30 Apr 2024 05:16:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1PEPF000066EA.mail.protection.outlook.com (10.167.249.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 05:16:44 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:32 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:31 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 29 Apr 2024 22:16:28 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Markus Armbruster , Michael Roth , Eric Blake , Peter Xu , Fabiano Rosas , Joao Martins , Maor Gottlieb , Avihai Horon Subject: [PATCH 2/3] vfio/migration: Emit VFIO device migration state change QAPI event Date: Tue, 30 Apr 2024 08:16:20 +0300 Message-ID: <20240430051621.19597-3-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20240430051621.19597-1-avihaih@nvidia.com> References: <20240430051621.19597-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EA:EE_|IA1PR12MB8310:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d1da453-4018-47ab-8810-08dc68d4ba5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|82310400014|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: 8BAfbuCoq4M/wbboqbgfOt4uVA7Hs84zNxvV9xuvSGqskZqaLpinIHlN5g3IbXvcdpQb3F7YPJhJYO+ignqjlGcb74z4WEONc83MYw2tKvbGjNgo+I5JIrFOsqZmycoPluhRlEnZjggQ788rZy28xiylD2kkFg5fnLBwrdYY7muqJg1L6u+TXM40sKTx4qc812K3YuK2m17UEYIsjQGti5kxNCMoeAddrjp7x26FAkE+VeEDctEv7CAsXW6nqvU3ubOgybPba2Ek5K4sbs1NkgRzxyC9nNnTR+7v/i/ww+dzgnJu7SvDFuVjIgNkhDpOpcZVaIU2jH5Qdj0CkEDQ+qFcijhCecuC+izoE/g0MucJSbnBHdDJk/56zE6SBTPnv8PT3BqbTQDK/3WgdxkHui+GKpIjQnJu/3bfKGf1vDGWhOdk8ergzfhSrqbnG9VKeHq30al1iBtm1I+j3MxFsJqELjRRK61xFp1NyKaRQC9xbPoXPcTiMLaVtsrlkZED5kslt0kncGIOU9cMxPNb8us31gLKFo2jcXk12MlZyaTn7B+gimm3BYSzyTSviY2B5a6WMFBYkQa4H+AJtua/KwSOAPzEakx9K9lgbfpwncCz+cuSnPD5wvNbEHyLtaS0S55cnq7rkl26so3JN8uiDFsCEBp05LTvl1UZ8u8Fu7js1TB1/mVpHVpmOAvvKw+bkGbvaGKrsfOJCVyA10LKm4xa3m8t0++w9MS8T1cuVvqF3JWShJLOMBdFXTq/Z97d63go0JS5j4EHxJQHzqvFMdb59e3HLjPR/pxZ/Dbwmc/F/XW7YJlSZjMuPXsifAuqtOlkvB5BvEM+83/supz372yKzXP4DhZSkR2dG2i7/ItO5KX3rUzj8PtivvOcgISu6OA7KO2yNsFwfNZ98Si4p2AR5/jT7c4cWcJS1Dw2co4p6gCFg5zB8csOWSXVvPU0GE1T2gh8bOAslQAgiOD+6L/bDwBXgH7/PMfdcbBQ3yIjkiALvxjnn60xYw0dtkSbjsUQtExpOqVHUwvrU0BxOVU+Lqu6IwattIRRR6BXFYsI3v5qBuVix3KDYO0hXT2kM8LRb9B3a2Aevk0q9A3Pv8IssAdb4ICe4tuhexSgmuL2VUqEzmto6xqobFPyAd4JfmcILyhkCOb7a3TpmkYY4ZpI/0YYbxWpSAFA9Zs26PY9247+GKtyd36PKEw2404mYAoUGQ0BVap2YUMKRQ6Qqo0kSr17xnS1eiMX8ajTATqNRfBfG0EcG1jwaimoNvRb4G6AsDsd1wj0snVYGuoMV5A0jEEOd/GSn+SeMdifbCh54vA18YtCQdv+/wCDoSd0+0jRlZ5KrDEhaGD/ol1PUTBmDepNFBX44Nu8/rRiBu7PwC1w9rTkrtkEiiekGksh X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(82310400014)(1800799015)(36860700004)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 05:16:44.7877 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d1da453-4018-47ab-8810-08dc68d4ba5d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000066EA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8310 Received-SPF: softfail client-ip=2a01:111:f403:2409::600; envelope-from=avihaih@nvidia.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.987, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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 Emit VFIO device migration state change QAPI event when a VFIO device changes its migration state. This can be used by management applications to get updates on the current state of the VFIO device for their own purposes. A new per VFIO device capability, "migration-events", is added so events can be enabled only for the required devices. It is disabled by default. Signed-off-by: Avihai Horon --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/migration.c | 44 +++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 2 ++ 3 files changed, 47 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b9da6c08ef..3ec5f2425e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -115,6 +115,7 @@ typedef struct VFIODevice { bool no_mmap; bool ram_block_discard_allowed; OnOffAuto enable_migration; + bool migration_events; VFIODeviceOps *ops; unsigned int num_irqs; unsigned int num_regions; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 06ae40969b..6bbccf6545 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -24,6 +24,7 @@ #include "migration/register.h" #include "migration/blocker.h" #include "qapi/error.h" +#include "qapi/qapi-events-vfio.h" #include "exec/ramlist.h" #include "exec/ram_addr.h" #include "pci.h" @@ -80,6 +81,46 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state) } } +static VFIODeviceMigState +mig_state_to_qapi_state(enum vfio_device_mig_state state) +{ + switch (state) { + case VFIO_DEVICE_STATE_STOP: + return QAPI_VFIO_DEVICE_MIG_STATE_STOP; + case VFIO_DEVICE_STATE_RUNNING: + return QAPI_VFIO_DEVICE_MIG_STATE_RUNNING; + case VFIO_DEVICE_STATE_STOP_COPY: + return QAPI_VFIO_DEVICE_MIG_STATE_STOP_COPY; + case VFIO_DEVICE_STATE_RESUMING: + return QAPI_VFIO_DEVICE_MIG_STATE_RESUMING; + case VFIO_DEVICE_STATE_RUNNING_P2P: + return QAPI_VFIO_DEVICE_MIG_STATE_RUNNING_P2P; + case VFIO_DEVICE_STATE_PRE_COPY: + return QAPI_VFIO_DEVICE_MIG_STATE_PRE_COPY; + case VFIO_DEVICE_STATE_PRE_COPY_P2P: + return QAPI_VFIO_DEVICE_MIG_STATE_PRE_COPY_P2P; + default: + g_assert_not_reached(); + } +} + +static void vfio_migration_send_state_change_event(VFIODevice *vbasedev) +{ + VFIOMigration *migration = vbasedev->migration; + const char *id; + Object *obj; + + if (!vbasedev->migration_events) { + return; + } + + obj = vbasedev->ops->vfio_get_object(vbasedev); + id = object_get_canonical_path_component(obj); + + qapi_event_send_vfio_device_mig_state_changed( + id, mig_state_to_qapi_state(migration->device_state)); +} + static int vfio_migration_set_state(VFIODevice *vbasedev, enum vfio_device_mig_state new_state, enum vfio_device_mig_state recover_state) @@ -126,11 +167,13 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, } migration->device_state = recover_state; + vfio_migration_send_state_change_event(vbasedev); return ret; } migration->device_state = new_state; + vfio_migration_send_state_change_event(vbasedev); if (mig_state->data_fd != -1) { if (migration->data_fd != -1) { /* @@ -157,6 +200,7 @@ reset_device: } migration->device_state = VFIO_DEVICE_STATE_RUNNING; + vfio_migration_send_state_change_event(vbasedev); return ret; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 64780d1b79..8840602c50 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3362,6 +3362,8 @@ static Property vfio_pci_dev_properties[] = { VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, vbasedev.enable_migration, ON_OFF_AUTO_AUTO), + DEFINE_PROP_BOOL("migration-events", VFIOPCIDevice, + vbasedev.migration_events, false), DEFINE_PROP_BOOL("x-no-mmap", VFIOPCIDevice, vbasedev.no_mmap, false), DEFINE_PROP_BOOL("x-balloon-allowed", VFIOPCIDevice, vbasedev.ram_block_discard_allowed, false), From patchwork Tue Apr 30 05:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13648269 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 341DBC4345F for ; Tue, 30 Apr 2024 05:17:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1frV-0000kF-3t; Tue, 30 Apr 2024 01:17:05 -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 1s1frS-0000jj-SY for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:17:03 -0400 Received: from mail-mw2nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:200a::600] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1frN-0006af-Ok for qemu-devel@nongnu.org; Tue, 30 Apr 2024 01:17:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m5T3DOYCZsDjIKdB1xpvNbj85ruUzwQQDJh7ACkQDU4FoedYO0BaK/7QfdGFNJhoONSCMZ7aQa8YCUbXZ74pugo+jr4kh4ZRTCkqxl9QYDqyv02IrXmvTiC+qzQOfVgPuxr8EfMdxdTnZ8/HDxMg8QZ0a1IBIzfEY6uYElNvknsj/FvfckyJ9jDCP1Cz1570sTzGlRwVMqEAUeLk5bDKVj27NjSZfiB8ozn5qDgEPVqqUtM3o8EOPfTn2z+YKSXzEX691QwtWohVj6IF7KCyk2YLUWhH5a24vOR5Fp+OdSVER0wGqjpwCw5JF7ZpIHokz2bZKmDx9G4UXYXTp++o5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uZ6EB4ySYq+wDgPEQhcBbWuo6kce+vcwHrrkjaessfg=; b=LqUlaR1/B5ZmKUd6pqroeUSaCIGm9r/3hJF3rN0rI8Wr8v+hcR7GlIstA+Xk4E02LOfE7hRIO3714fUBPE9DyHTgbtDWFsmUDG8AgGsRQtFOvkUrGHOX5QwCfKJZTREC2Tj4R5zzwA+dfFDZsCrHJRmy/4O6HX/U//fbJtnQrpBg5adOJ4xl5+7bYd6wq8dg6P+O3XfyWK1yhSZ8dTGFzKioQQuKC7wuYifMyFK5n87TrrJYB4u9z2zF6jEIeB34OBSTGOTtqjl9BAwwJpNU1wM42dPePn/w+ktqApQeoCBwUoQrMBX033zL03jBdSZjZ4xthNxE9mQvnqm5dlP/WA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=nongnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uZ6EB4ySYq+wDgPEQhcBbWuo6kce+vcwHrrkjaessfg=; b=Rpox3utOfQn3ma5Q5cHp0uaqmjo5NtM3R5Jjsu9WNWg71WGIqRC84qP0Kf+wxf0+oS/vesAFeDq0ADZubc38mNNKMdoDXfh/hXCX1syLz6kQS4u81YiIKDH0Q3SzhoQSJ8vpkyFj9ugU/M6TtBOWRBPUQhzEwZ097myVu5Cp96AFUYcBHj0Mq3X9TNAjr05jYTb3pOYRRZZ9fP8aeKmOIGcCQ25XcbmO3sCQYMkw7k1/boIHnW9NssiU5F6jrDbZuhjKAjOGXdXRM+GTsfK3XuDp1xp4gn/n6voyRYZK+jcoZ+wH1nNWd49O5x5jLPYriAEyqluvKaS8yD1nI3JBiw== Received: from BN8PR15CA0043.namprd15.prod.outlook.com (2603:10b6:408:80::20) by PH7PR12MB6395.namprd12.prod.outlook.com (2603:10b6:510:1fd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 05:16:52 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:80:cafe::3d) by BN8PR15CA0043.outlook.office365.com (2603:10b6:408:80::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35 via Frontend Transport; Tue, 30 Apr 2024 05:16:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.18 via Frontend Transport; Tue, 30 Apr 2024 05:16:51 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:35 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 29 Apr 2024 22:16:34 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 29 Apr 2024 22:16:32 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Markus Armbruster , Michael Roth , Eric Blake , Peter Xu , Fabiano Rosas , Joao Martins , Maor Gottlieb , Avihai Horon Subject: [PATCH 3/3] vfio/migration: Don't emit STOP_COPY state change event twice Date: Tue, 30 Apr 2024 08:16:21 +0300 Message-ID: <20240430051621.19597-4-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20240430051621.19597-1-avihaih@nvidia.com> References: <20240430051621.19597-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468C:EE_|PH7PR12MB6395:EE_ X-MS-Office365-Filtering-Correlation-Id: 38644ec4-279c-4b83-ef9d-08dc68d4be65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|36860700004|82310400014|1800799015; X-Microsoft-Antispam-Message-Info: 2XsrvNY/p+IBqqOMu9BuBqIyBQVz6e4gdhMo/OGgm5n2LWkfuCUTlJnrP51rCsdyUQrAf6FdoZ4dbdX+GjVZhjsgdGutAch3EO60OTYvgXeRznyOgHZN39LyztbFOjw6fyoAbyyD2Jm+YwOItbcCrUwpZgQ1VwWJCS4DeupCd6qXXf+YkdjiBAJfrtVYouawehlbYs/a8c5loSRqOS+gav+lZiSoSwHgiY55F8OcGoVILEK11lYOtsJavPYrYKpzH0r8BFEjoYyElQbgtjGcoObjxLVZzsB7QHcNebAMiJ+G2dqvs0TilUlDC0HY2IUIyATSBuSiSTvcO0OGkme6WHy0wtBD2i8vnIQZiF+goEC7O4nMvsAg8Ijf7/gOT2GTvbjsScXFy3HSqUSBx294sa2x226TCraNtwZMvvkrA7jQ+khgLYECOPFxcYOJ4Cyos36J0LVXZVhn1wE24ARE8lexvjyYFLmfX8OH0oqfnw6TTihQ6poOXAIPj0hjcOpgr9ZtvJ9epsnImLgUyloghrfCiX0pn+KaI9vUiCcVwvzpVrVWNlI2QDuCU140C/1WkSZFQiEsMNJllqa5nhOlYSBjaCfvfOhw3B2qx+o72K4yTroyViXAREO0M/BcGegh9qvF2ftf5wDSM/PejRnLi3vc4ETEVB7usUCOmjqm4gpTTLqvzv9LWQZwP+oBJnHzLHAPcPauRVknL/4Zk3fvRag3Al3n+qzUYxueRIF0Hre2DX2YGL7I7i1g1Rn/qAGqxivjQPjPPYcrCOczCrznUqgv6Ap4iWxikHrBnPeXCNoqR89EjFpYXJpuG1+3nWV34E2k+6EOQmJwOrjazhVoNFjYzkhFqB0nIOr32wTw7r+EBP9efh7qU8F1PakE05VqdcTRtu7nS+DhSEKTH86qNazhfC4RRi4CKlnIcqfHFQa4XHJpKGFbbqw/3H696TiDzJk/ouVbMNLMQezMZDf7qKt9MpPoZQH455jshcLgiMOOOUS1AkWrrG2BLDHeVX4YfKq5agSUmHjVZlg1TkQYSSfITqi7AM0smlh8EYocwfQYt89BpeMJSb+WzOyRYRJ4HbRrQ1C6CyXZ5js9+OXRfjp/38fUTX2qE5HCTaDlMWC/8om5g5vCtmNo10l3gnyHoIcUmVjcU6AWzC9YNaZpAILhjr5ivp6avV621SQRQF2nFsCuL3cXGqcpx0Dox7r6SLLgUViqklyTFo2DG9/4fOjmLl1cIsYNxkNU+ahQ4shsYZI5fpGb+UFEw+n8dS52ADtRhR+SlveMjmrwMH65zNtNq6e6j+poExIWOEfvrJKk0DVf4fWox792S+QwteRj7hZA05poK1V7bHwfEhQj+OX/6hI3BSzYl9ybFdeIZ5y/u3Q0WTMjOtUq4Cztwfhy X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(376005)(36860700004)(82310400014)(1800799015); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 05:16:51.4287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38644ec4-279c-4b83-ef9d-08dc68d4be65 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6395 Received-SPF: softfail client-ip=2a01:111:f403:200a::600; envelope-from=avihaih@nvidia.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.987, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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 When migrating a VFIO device that supports pre-copy, it is transitioned to STOP_COPY twice: once in vfio_vmstate_change() and second time in vfio_save_complete_precopy(). The second transition is harmless, as it's a STOP_COPY->STOP_COPY no-op transition. However, with the newly added migration state change QAPI event, the STOP_COPY state change event is undesirably emitted twice. Prevent this by conditionally transitioning to STOP_COPY state in vfio_save_complete_precopy(). Note that the STOP_COPY transition in vfio_save_complete_precopy() is essential for VFIO devices that don't support pre-copy, for migrating an already stopped guest and for snapshots. Signed-off-by: Avihai Horon --- hw/vfio/migration.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 6bbccf6545..30a2b2ea74 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -591,14 +591,17 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) { VFIODevice *vbasedev = opaque; + VFIOMigration *migration = vbasedev->migration; ssize_t data_size; int ret; /* We reach here with device state STOP or STOP_COPY only */ - ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, - VFIO_DEVICE_STATE_STOP); - if (ret) { - return ret; + if (migration->device_state == VFIO_DEVICE_STATE_STOP) { + ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, + VFIO_DEVICE_STATE_STOP); + if (ret) { + return ret; + } } do {