From patchwork Sun Jul 16 08:15:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=e0dVpmB8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dP22r18z20FB for ; Sun, 16 Jul 2023 18:17:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwvN-0007mB-P0; Sun, 16 Jul 2023 04:16:13 -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 1qKwvK-0007lo-JJ for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:11 -0400 Received: from mail-sn1nam02on20608.outbound.protection.outlook.com ([2a01:111:f400:7ea9::608] helo=NAM02-SN1-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 1qKwvH-0000pn-AY for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nU4N7CzLhr2ymdUON9gOVII2QW9bgYGVZoN8WYV5DHInxEvfXztflSBQgcjqNzwXLgNT0frI89XYvD3jIc2B3fMn/cxtWdIRrO2VZV80W+JujhcbPeX9LzIdrg8EUptT/0mwJ/S+lwjM+kP3Eg9NSu0Y12KWhqZzYqyPMY181w55rv2XVabR/hxub8fzkpr6wLTLQjdkfIvpTqOiXQX7PfrN94QFuFfgQ1nPZkUFF4GnsPRIVJ8UM817h3a+Up5/PAdhjTh1BaHPF07T5UuxoSNhWSpz3uOr2/aBtDVxgtjFJO+40x3ByRZHee/PHGYHAtxbWyeb71JFaxTD0ouxbg== 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=8JJJi1BljvRnqc53fMAMnBZ/7qU6EKYrUo6YPtPQy70=; b=hkGkE+h1zeM6IY4XLNSDfosrHewab9lqEmJvBrjBybqOKjhXaY5trvUfmnJ5Pe/z2ky3C/9RJ+Grg1G61TE2Jy3wMrVn0k+Oo287KBrUFHfQlTNF8L+qHKJ3HoDQeTafJ0sFXXURvWDs6r6AgH6+O/wJM6s+jZp3GakwqCyLWfwf96FJsEq1PbA9qDG5yFIOqCxvpmKEht6d7s9321dJaTKtrtqQT5Rjd0dvc2CFdNHpn+PDKlV24BMu9xmfu9nySrhKZHHZqJeoWdP2HkNNlMm5vsznGcjK75mchRyQwG274p4/H53sas+E3lJvqk0Jy7gZq++1eoiuBz06cvtEtQ== 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 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=8JJJi1BljvRnqc53fMAMnBZ/7qU6EKYrUo6YPtPQy70=; b=e0dVpmB8ZrPp1Y4SY/d0mfy3Cs+daX2KUCo+8f6SOAJh6+6em2qInZzX549lEwZfvdgmi6mtIWnBr+kP/pSk7rHz3tbR5SlE8JiXHFhKd04ZnzLm/eEwK56AVOWvNhQxo2i0uSsXaK2JXibhkcNN3z8vWpWWpecUaZWWJcoSwE8l04ozl6GvSF9GlaNkyKJ0A3NtYw8M9/vD1LzPYCpeEPypt9VdG1Kh/NKsU76GC83RCKFpYFgA8xAMBukTDHvSqnidb/EC4yIWO3daABIkatZvwwNukoeXxEWYDMUj19TdbLOsWguWj4WD99JfpIvIr0ignJKMSm4cL9VrUvvp4Q== Received: from MW4PR03CA0224.namprd03.prod.outlook.com (2603:10b6:303:b9::19) by BL1PR12MB5032.namprd12.prod.outlook.com (2603:10b6:208:30a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Sun, 16 Jul 2023 08:16:03 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::d) by MW4PR03CA0224.outlook.office365.com (2603:10b6:303:b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:02 +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 CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:01 +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.986.5; Sun, 16 Jul 2023 01:15:48 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.986.37; Sun, 16 Jul 2023 01:15:48 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:15:45 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 1/6] vfio/migration: Move from STOP_COPY to STOP in vfio_save_cleanup() Date: Sun, 16 Jul 2023 11:15:36 +0300 Message-ID: <20230716081541.27900-2-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT058:EE_|BL1PR12MB5032:EE_ X-MS-Office365-Filtering-Correlation-Id: 81f87a5b-e1ef-46aa-6e9e-08db85d4e471 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +OLoX4zNU4sItlCjvQg3Umgi8Weq/Vq6qVjBDDK4u+mvtDn6XXBsGW3zdXvegl2jWMr6CMWTq7QUlrrg2Z9YSUtDKyhaPgiBv/ToMWqzSQSeFgSSNCq3r/7QeeYkfdaBVXdenmyHp+f5IHt6AXgvXb1UvUrCtygl848dUYn1bjuQVrmubWN8PZHWyWwsseyGlxZdWEAWvEyMwkZopDjclyyRJJESyMxQ3f/eSFl+Z5AOmlWDo4qktuNKF3XdO4aS5PjgtfjsrtdfxVo4091P0bJi6qsjcHcNPTI5VMWyNEjrqrjv4J5IsoUqww3k2opnDLSO0Zzy81rnSs1eldHaHenyZWTLAC3TOzBn9t3XM/iciwTWXXppe8O5/b1x9wppkzwcWFnqRQILGl7Atl1UfvuBap/nUw/zEBRnjmzyY0Y+4/hhXT17TvRbekHgAt9mZvCpGhEvqN5tyR/PMgfh9rflpo2jJFC9SJMOp5j12XrHFlrhlsOlpto5RIBtM/L0T7phKZFTncLeYXAs9tqZmL6LWnHL39MhoaxtOspbswASJyNkNTklWK9R7vgxeoLLtfVMAr+V6TjFP7OoSbcyUNcB/DIRZYUr7DL81SHYdv4n89pvRN4hagoSQwCntMl+WUCvy3bqoEM92geVIlACD/DR5rWQDCXStzOInQa9KgAApdCLcST7pbpzxSMMqtqq0Y8K+okR3GSS6Z+upk3/a8rKZc+GupdndbchcD90UpALpEF7RTXg4DSg3/d6ZF53 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:(13230028)(4636009)(346002)(39860400002)(376002)(396003)(136003)(451199021)(82310400008)(46966006)(40470700004)(36840700001)(54906003)(40460700003)(478600001)(26005)(186003)(1076003)(336012)(107886003)(36860700001)(7696005)(6666004)(40480700001)(83380400001)(47076005)(426003)(2616005)(86362001)(5660300002)(8676002)(82740400003)(8936002)(41300700001)(316002)(4326008)(6916009)(2906002)(36756003)(356005)(7636003)(70586007)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:01.3851 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81f87a5b-e1ef-46aa-6e9e-08db85d4e471 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5032 Received-SPF: softfail client-ip=2a01:111:f400:7ea9::608; envelope-from=avihaih@nvidia.com; helo=NAM02-SN1-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Changing the device state from STOP_COPY to STOP can take time as the device may need to free resources and do other operations as part of the transition. Currently, this is done in vfio_save_complete_precopy() and therefore it is counted in the migration downtime. To avoid this, change the device state from STOP_COPY to STOP in vfio_save_cleanup(), which is called after migration has completed and thus is not part of migration downtime. Signed-off-by: Avihai Horon --- hw/vfio/migration.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 2674f4bc47..8acd182a8b 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -383,6 +383,19 @@ static void vfio_save_cleanup(void *opaque) VFIODevice *vbasedev = opaque; VFIOMigration *migration = vbasedev->migration; + /* + * Changing device state from STOP_COPY to STOP can take time. Do it here, + * after migration has completed, so it won't increase downtime. + */ + if (migration->device_state == VFIO_DEVICE_STATE_STOP_COPY) { + /* + * If setting the device in STOP state fails, the device should be + * reset. To do so, use ERROR state as a recover state. + */ + vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP, + VFIO_DEVICE_STATE_ERROR); + } + g_free(migration->data_buffer); migration->data_buffer = NULL; migration->precopy_init_size = 0; @@ -508,12 +521,6 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) return ret; } - /* - * If setting the device in STOP state fails, the device should be reset. - * To do so, use ERROR state as a recover state. - */ - ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP, - VFIO_DEVICE_STATE_ERROR); trace_vfio_save_complete_precopy(vbasedev->name, ret); return ret; From patchwork Sun Jul 16 08:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=hBH/qMUo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dPk0TnMz20Cs for ; Sun, 16 Jul 2023 18:18:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwvO-0007mT-9B; Sun, 16 Jul 2023 04:16:14 -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 1qKwvN-0007m3-6b for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:13 -0400 Received: from mail-bn8nam12on20621.outbound.protection.outlook.com ([2a01:111:f400:fe5b::621] helo=NAM12-BN8-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 1qKwvK-0000pz-HE for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hbwW3h1Fbu4hfXyh7R+WQjODyJh9GGoELl+xLuhp9HaeWcIdQp7qiMkZcN162M94fYlvsUrkzGJZPVr02GhmTmxQWOvvXtcPLNx1qZcsUu3BzPAbydtUY4yFTUx9JXJo3PcpuM8AfKagWCA+FXjNcQdMUfTOmJRhkG+xTei+uIkHw4nmLec5hvYaHVgJCoNeYaafeK1F2yTkOiHktw1CEedFnELdYMH1oA1Cqn7JHHM1x6cJZbEQRiB575Y8Ai0iSUfvC2WPX3Pd5ddQm/zc/PJNnMrMyMcEVTcK8CuuZ6p5LkXKugo+P9obdmjNlkeeaZl9LykXKuP/4HDqyxK0Wg== 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=N+V0SKQ8fVDS0yFd8IkXWJp2BKGL9A+zyu5Gf2BFCNw=; b=QE4cyIVkYwcNeeLB3laTyHacJpW1hfAjCHegzV6kZ4v6XsUuzF0NVB/ZeGNJ4VINxm3lgUyoXT1vnKBHJGDlmqosOVCZiOi0e/rCxojVEcKhAwH7LchKqHqTL7fYSe8JBIfdMaXFucO1FaNkGSPflHARiBk8seYsaSYb2zd2d9kXUq+dJ42nb5PpHztAzUdDM20fw3e6EupNs8j+uaUgnDCRuYd8IHDR5u40/GEr4Sot3nebwsflrIOACR+0Y1movT+fvf0kVohVMvTQGyGZG6KGfuErrJDQTFw/TeEueSifXUKaKJOGJp0wmQvSvtzubw6Zh+47xl6ikMSdFAZXmQ== 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 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=N+V0SKQ8fVDS0yFd8IkXWJp2BKGL9A+zyu5Gf2BFCNw=; b=hBH/qMUouTZd5T6oiWn0St7RDMrF5RdMRHjdMVmsZvot0P80waV8rs42ZnzQLa5gHGeiN1FwExMiiqzhfAEPw43KTG8RZ4QJ+hflILXobhuruWSBpk7Ts5PUv+LLpuJBEjR2wK5jTrLQyoYcA+TsAB6sA59hg1qgwAy4XPjjFxUpa/YzGb60iQWNumXIUQf9uCazWedg2LUDMBr9EVCuFeYfCqGAwLmAvisxJkpIU5geBIqSuCGnw4PhHI+0TwEfvFXqLGvCs+Ud1V8NLqVhWjXfwuRVJAAfubQe3/NlZg8T3SP4MnO8Mgp+Px1gVZqg6b/TdHEwjdzXF6CVCBeEGA== Received: from SJ0PR05CA0034.namprd05.prod.outlook.com (2603:10b6:a03:33f::9) by CY8PR12MB8065.namprd12.prod.outlook.com (2603:10b6:930:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Sun, 16 Jul 2023 08:16:06 +0000 Received: from DM6NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:33f:cafe::d2) by SJ0PR05CA0034.outlook.office365.com (2603:10b6:a03:33f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.17 via Frontend Transport; Sun, 16 Jul 2023 08:16:05 +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 DM6NAM11FT081.mail.protection.outlook.com (10.13.172.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:05 +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.986.5; Sun, 16 Jul 2023 01:15:52 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.986.37; Sun, 16 Jul 2023 01:15:51 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:15:48 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 2/6] sysemu: Add pre VM state change callback Date: Sun, 16 Jul 2023 11:15:37 +0300 Message-ID: <20230716081541.27900-3-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT081:EE_|CY8PR12MB8065:EE_ X-MS-Office365-Filtering-Correlation-Id: 25adde31-60dc-48de-2fef-08db85d4e6e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TXH0hPaeLmVtp2ICh+SY0ee37Ncwbf8tcJaXglumuPDAR1MSZdd+Dkgzas6PZNxNiA/1wwDGmu/DVmmsYlZdiLv2AB5RbyZQDHUue7jgoK18cxVFGBert7yixvxLTC1STD4Ty6/ATb4w44BmZyjoMTz+oZZIMA0vCF1GdwHhRUxDSs6p0M0zwhvb//QgQINBzrk0Za0vdjV2KO1Cj7wDakaDYq/r6J26tSgvWjt+F4PBjuugXfU1JXZr04/nBAWIrXmnIj+Z7JjU/GHWHQPoQniVbr9damlIDuqaShFjwjTNbtHXOs2xj5zglyRGGuC2Pq6mWKKqb95ZA+ganMUup8XpBdVVybs4bGtVlbfP8sxHi3gGjTs69BNiznS/QdZGVKdkH4BgQgX+Bx4R8uX7N6gXGDJF2zhCGrbnazovZUfhOKKr8WurqIYJq1P8sf8xBtFz23pDBigXp133bcObBFkobXVIBorIfVVSo56oFpCllztPgXCvhZDNqF8vbYZD+OuFYSanZPvmQ0RImkcC+SOlbO0rPGUDZbgc1t+ilL+vOomY7i9avotC61jk2VGAh13m/Ell7ifwdFAEWCX+a1/Xgh9hl6Q5MtD+LFaP2CMYyXDxACfczJiHiGakVFkuntvv5cHHsfhU2XsSV4A41DyD8BmFCxQO8FjNEWf4/7BSXVZ8p6q0CSA8swLRs9XsIWxfiFeNUgiKPomDUDMozpGiZUOyKSoAF5hB8g8TqmsYdeeWSwgiLVtjAGcxrh8v 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:(13230028)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199021)(82310400008)(40470700004)(46966006)(36840700001)(2906002)(7636003)(356005)(82740400003)(426003)(47076005)(336012)(83380400001)(2616005)(186003)(107886003)(26005)(1076003)(40480700001)(36860700001)(86362001)(40460700003)(5660300002)(8936002)(36756003)(8676002)(478600001)(7696005)(54906003)(6666004)(316002)(41300700001)(4326008)(70206006)(6916009)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:05.4769 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25adde31-60dc-48de-2fef-08db85d4e6e4 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: DM6NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8065 Received-SPF: softfail client-ip=2a01:111:f400:fe5b::621; envelope-from=avihaih@nvidia.com; helo=NAM12-BN8-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add pre VM state change callback to struct VMChangeStateEntry. The pre VM state change callback is optional and can be set by the new function qemu_add_vm_change_state_handler_prio_full() that allows setting this callback in addition to the main callback. The pre VM state change callbacks and main callbacks are called in two separate phases: First all pre VM state change callbacks are called and only then all main callbacks are called. The purpose of the new pre VM state change callback is to allow all devices to run a preliminary task before calling the devices' main callbacks. This will facilitate adding P2P support for VFIO migration where all VFIO devices need to be put in an intermediate P2P quiescent state before being stopped or started by the main VM state change callback. Signed-off-by: Avihai Horon --- include/sysemu/runstate.h | 4 ++++ softmmu/runstate.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 7beb29c2e2..bb38a4b4bd 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -16,6 +16,10 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, void *opaque); VMChangeStateEntry *qemu_add_vm_change_state_handler_prio( VMChangeStateHandler *cb, void *opaque, int priority); +VMChangeStateEntry * +qemu_add_vm_change_state_handler_prio_full(VMChangeStateHandler *cb, + VMChangeStateHandler *pre_change_cb, + void *opaque, int priority); VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, VMChangeStateHandler *cb, void *opaque); diff --git a/softmmu/runstate.c b/softmmu/runstate.c index f3bd862818..a1f0653899 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -271,6 +271,7 @@ void qemu_system_vmstop_request(RunState state) } struct VMChangeStateEntry { VMChangeStateHandler *cb; + VMChangeStateHandler *pre_change_cb; void *opaque; QTAILQ_ENTRY(VMChangeStateEntry) entries; int priority; @@ -293,12 +294,38 @@ static QTAILQ_HEAD(, VMChangeStateEntry) vm_change_state_head = */ VMChangeStateEntry *qemu_add_vm_change_state_handler_prio( VMChangeStateHandler *cb, void *opaque, int priority) +{ + return qemu_add_vm_change_state_handler_prio_full(cb, NULL, opaque, + priority); +} + +/** + * qemu_add_vm_change_state_handler_prio_full: + * @cb: the main callback to invoke + * @pre_change_cb: a callback to invoke before the main callback + * @opaque: user data passed to the callbacks + * @priority: low priorities execute first when the vm runs and the reverse is + * true when the vm stops + * + * Register a main callback function and an optional pre VM state change + * callback function that are invoked when the vm starts or stops running. The + * main callback and the pre VM state change callback are called in two + * separate phases: First all pre VM state change callbacks are called and only + * then all main callbacks are called. + * + * Returns: an entry to be freed using qemu_del_vm_change_state_handler() + */ +VMChangeStateEntry * +qemu_add_vm_change_state_handler_prio_full(VMChangeStateHandler *cb, + VMChangeStateHandler *pre_change_cb, + void *opaque, int priority) { VMChangeStateEntry *e; VMChangeStateEntry *other; e = g_malloc0(sizeof(*e)); e->cb = cb; + e->pre_change_cb = pre_change_cb; e->opaque = opaque; e->priority = priority; @@ -333,10 +360,22 @@ void vm_state_notify(bool running, RunState state) trace_vm_state_notify(running, state, RunState_str(state)); if (running) { + QTAILQ_FOREACH_SAFE(e, &vm_change_state_head, entries, next) { + if (e->pre_change_cb) { + e->pre_change_cb(e->opaque, running, state); + } + } + QTAILQ_FOREACH_SAFE(e, &vm_change_state_head, entries, next) { e->cb(e->opaque, running, state); } } else { + QTAILQ_FOREACH_REVERSE_SAFE(e, &vm_change_state_head, entries, next) { + if (e->pre_change_cb) { + e->pre_change_cb(e->opaque, running, state); + } + } + QTAILQ_FOREACH_REVERSE_SAFE(e, &vm_change_state_head, entries, next) { e->cb(e->opaque, running, state); } From patchwork Sun Jul 16 08:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=oODUkQia; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dP20SXlz20Ct for ; Sun, 16 Jul 2023 18:17:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwvP-0007o7-PT; Sun, 16 Jul 2023 04:16:15 -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 1qKwvO-0007mR-5X for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:14 -0400 Received: from mail-bn7nam10on20615.outbound.protection.outlook.com ([2a01:111:f400:7e8a::615] 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 1qKwvM-0000qU-FA for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pj8yLN9jqDQPdM5VWrtX/b16HQ/2kFck3OvSeeNlzlUdXUQgX+gAoqE2HMczDGInTGRXKtoBWQG6HmZlfg2IqKXVF/w2VRMEGoWHygCW5nQcE9GHhAF6rkTz9HLnx8tMsYldRh7h1voqGPqKdoTHLE45nyzWtTGLwELDCnqev0EQFBwmliHtqN3e5mpSeWZg1t382phECvFjb75YQKFMtVM5bT7+ifIs1qNnJBi4xgyBVa6XVuwZAozm7Lc22tnqpty5XPhYsPEknwYdWAGE3pZPpVFFIYKIUgOBStPk5L7+mQjLMN8PoqQbQ8iHtjyij9u9e5NksByGALb32EutOQ== 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=yQ4xoMPymvJ2qudooBrQWQY1m2eDedjxURwAZ7xsNwc=; b=MulA6NjU2s15HW023gXH7DK+xSLMbrHCdFf3WKSqRouGmyUOnOJ/m9xdmThaBNcFbAKqDPfYM0DRw/VsGhK+M6L9qI0vd5N1GG70CGaDLUscgv5hGTsbGEEP8AvYp182+5wmJeQpgdusbDp/YcrXogPwgrrVx83/vSg/H/AxapBGn8IrvmiD40/SivpQHVu0LqLTm5LfE7nT4a6oDXIMOqV3o455L0DltzjLggif4RtNX3StC41p5q1zWMVvjQOABdMEbE5YyQyXz2qEv8EVnwO2MRJkiMn0hnWAs2VuELE7NULGTIH6BkrQ+6CRuW3dX5kJv0VquE6fUhSRA6h2Ew== 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 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=yQ4xoMPymvJ2qudooBrQWQY1m2eDedjxURwAZ7xsNwc=; b=oODUkQiaDW0nM2yeUvPHCMvpDNYkBHtVa/pPhFbsQ3iEgd33tTZ1m+qdz9hjE9jO3rMpZG/nnS0gJph18Lf7QsE5lLnlIwfZt2EI1KD4lDR7jDjjyc2l5bR3g+7fG+STq4nwPFZLlggmoSaahAggDvrM2lNAUPuNENmmfakjORSY7cDp7a9Io/VK0NOYbmjTmvhZ1yD6nj2jeiq8GlR2DMYVe6ljOyIQQtClYgykgsbJPRoJGBC4dnrm8hPgmhaoLLLVgIC4VhL7V33mFZiKY5oPZjQlBhfWeS5a7ww61ZRRYxxJp5bROPO4eLANvrFT8SFOgVXoJyyi3dGK9aZhug== Received: from SJ0PR05CA0047.namprd05.prod.outlook.com (2603:10b6:a03:33f::22) by DM6PR12MB4340.namprd12.prod.outlook.com (2603:10b6:5:2a8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Sun, 16 Jul 2023 08:16:08 +0000 Received: from DM6NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:33f:cafe::f6) by SJ0PR05CA0047.outlook.office365.com (2603:10b6:a03:33f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.14 via Frontend Transport; Sun, 16 Jul 2023 08:16:08 +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 DM6NAM11FT081.mail.protection.outlook.com (10.13.172.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:07 +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.986.5; Sun, 16 Jul 2023 01:15:55 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.986.37; Sun, 16 Jul 2023 01:15:55 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:15:52 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 3/6] qdev: Add qdev_add_vm_change_state_handler_full() Date: Sun, 16 Jul 2023 11:15:38 +0300 Message-ID: <20230716081541.27900-4-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT081:EE_|DM6PR12MB4340:EE_ X-MS-Office365-Filtering-Correlation-Id: 87377c0d-ec34-40f6-69b8-08db85d4e828 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qkBmE7W2lQ9YpCd2WGQl9+mZWd28rsI9KelvOP8d1nk5H2zKvdHLor+BVSmnSjvdwyawcz5BkTpbXFBBamRcTgiwlT8ZnUZYBdoCPz9jsvSD7wtWQZIAighdUl6/Lau273zOCyizM2VB9FwpI23DDCm83113EKfHi3iUpIl5e6cgtlwnJe26yRwUOWoVqQCmgGK7dlOIoFTuIE/FuRRMH0Y4zVFC77Rh69F2X4YpUcKEPYszGk4yb9g+sGOsMKC294aWPw5PBZ/f08UQClU7jzsUHO6XNRKRqhM5tt9wEL9Sa+KdbmRrOAQ+/B4L7z+4G8BxXY0rbfNxGX/pomRapKvlN1UH8TAtyWtaG6CJrqf2kGtt6LTP56/sTE5sKH8a5ZV3IoimWkKcuu35wUMO5Tgu/MxuNg/WLN1o/t9CRvW+zNVEbYskADrWQZHbN3xIZI5zjiu4gQgxbIXFrWgKKHy/PxEDk1ru2aaK983w3/9eE9ERj9jOECMQKDDfrzXnK0T5dSzpYu+BhA/0PCWe2cOcUbRHUj9/ySM5+7jyfiipcWI2Ze6wytWGbUuRJai/B7XUBlvN5OzTHFutNSkmOIB8Z7wxsVbyKoVuvZ+H5b/B5PpW8OOZbx+iSA5ryLA2XdWoT+EhuxSnEI036ou5dhyWV1A7JvWF5LLobvOoSw6+PniD0jVtJ5GlbKuxqBpAbGRgF3a+KBgzRhomvwOZnNezga31X/ut6+0o7NFt34Xb6ibVeedndi5IwFFcFmpH 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:(13230028)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199021)(82310400008)(40470700004)(46966006)(36840700001)(2906002)(7636003)(356005)(82740400003)(426003)(47076005)(336012)(83380400001)(2616005)(186003)(107886003)(26005)(1076003)(40480700001)(36860700001)(86362001)(40460700003)(5660300002)(8936002)(36756003)(8676002)(478600001)(7696005)(54906003)(6666004)(316002)(41300700001)(4326008)(70206006)(6916009)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:07.6018 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87377c0d-ec34-40f6-69b8-08db85d4e828 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: DM6NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4340 Received-SPF: softfail client-ip=2a01:111:f400:7e8a::615; envelope-from=avihaih@nvidia.com; helo=NAM10-BN7-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add qdev_add_vm_change_state_handler_full() variant that allows setting a pre VM state change callback in addition to the main callback. This will facilitate adding P2P support for VFIO migration in the following patches. Signed-off-by: Avihai Horon Signed-off-by: Joao Martins --- include/sysemu/runstate.h | 3 +++ hw/core/vm-change-state-handler.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index bb38a4b4bd..ca97b9dfa7 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -23,6 +23,9 @@ qemu_add_vm_change_state_handler_prio_full(VMChangeStateHandler *cb, VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, VMChangeStateHandler *cb, void *opaque); +VMChangeStateEntry *qdev_add_vm_change_state_handler_full( + DeviceState *dev, VMChangeStateHandler *cb, + VMChangeStateHandler *pre_change_cb, void *opaque); void qemu_del_vm_change_state_handler(VMChangeStateEntry *e); /** * vm_state_notify: Notify the state of the VM diff --git a/hw/core/vm-change-state-handler.c b/hw/core/vm-change-state-handler.c index 1f3630986d..24f155fb62 100644 --- a/hw/core/vm-change-state-handler.c +++ b/hw/core/vm-change-state-handler.c @@ -55,8 +55,20 @@ static int qdev_get_dev_tree_depth(DeviceState *dev) VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, VMChangeStateHandler *cb, void *opaque) +{ + return qdev_add_vm_change_state_handler_full(dev, cb, NULL, opaque); +} + +/* + * Exactly like qdev_add_vm_change_state_handler() but passes a pre_change_cb + * argument too. + */ +VMChangeStateEntry *qdev_add_vm_change_state_handler_full( + DeviceState *dev, VMChangeStateHandler *cb, + VMChangeStateHandler *pre_change_cb, void *opaque) { int depth = qdev_get_dev_tree_depth(dev); - return qemu_add_vm_change_state_handler_prio(cb, opaque, depth); + return qemu_add_vm_change_state_handler_prio_full(cb, pre_change_cb, opaque, + depth); } From patchwork Sun Jul 16 08:15:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=gYRIkk/5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dPL6cgvz20Cs for ; Sun, 16 Jul 2023 18:17:42 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwvT-0007p6-Hc; Sun, 16 Jul 2023 04:16:21 -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 1qKwvS-0007ol-EB for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:18 -0400 Received: from mail-bn8nam11on20601.outbound.protection.outlook.com ([2a01:111:f400:7eae::601] helo=NAM11-BN8-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 1qKwvQ-0000r9-H6 for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LbG1fc3sEnoi2IUcSeez9npbGVNcnvQZ1YFMzDiJP+zbtC3TUiXV8rCPgdDbsoRPH1hW89gbYwsctomCsYDxiBYunDv0VHbsy9vK3VLOl4hK4ZpgzLe0ieXEkP5rzW00NPIlOQvhoLFLZZpyObD8f6LXPyAzJ6PgesYWKgLXQiqR97hVHOEZYRIAm6D9m+NCnhgkoEObM6+tvKwq1aEo7vf+sYuHmOD5nQUzqrWLez7CCA75A9EFWz0Vm2BYuR4jqF0zqrWCgD+NZu7k517o36lgx/LnvvH2NZ6ZVLd3u3ATlAbl2YEJxZgVTrSYzjyDJ6pcDAqqNwJ5WQLsPIkf3Q== 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=1aFLT3zsTS4PFGtbASiYCiJoaiMXApHKu5zZo2p1a7Y=; b=IPNkWl8LHtTBTVoxKclSCjirJpmV6MOHSvB82jKMMtVMOv3VT4YAB+q8h9bzPDCq5KwJSRQw7VpnYw7J09QdjOWzE+6UJgRGSm3JCuQ9mULiP4I7ujtsnqryWmgDZlxLuVewoDC/xkBUDAN4jMVbdYtZQW1t+oiAxOKm9AkkNmQR8VBjqesVq2r1uhHQw/ri2oK6XxR7ZTem4xpF8TVelEOO5VO7bX06lTSeyg/cmJrD3dak07E4XN/r0XG5BzZxYpXM/hWX2AC+9jhPVUpNb32Vusob7qeJUPqKP23L3PREsfnBncDdd2GO1TD4MhjYUQiUJtthJ7ZjFqAliXq3Jw== 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 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=1aFLT3zsTS4PFGtbASiYCiJoaiMXApHKu5zZo2p1a7Y=; b=gYRIkk/595KPfg/S2qq0S2rE0dvObWhSapc4lwkQQOnMrWpKluP3TJXMARk4JtSYoLRAwL1y/ciiP+c7b20PTd0EVmzsgW3ldx3+Fjv7BusMh12+HUCb/CQXpjHmUc5jZEl7IxBV8DIbCO3SYC2vnfneLUntl/svrpr2O7fK0jad7lYNmzewIen+IVmpuxCX215NpbBTtm93S1TP9yNAqkWaQPpvJ9g/xu1a8lYckKcIeaUM02El4pG+7HBFUcaW/4ZN89tHYg0zIB0u03tU2tXbDVopJyvDHng3wfBdWC6oVtrQxaQSErDys1Yprd4YRRN/0J+YM+K9+OXHFwMBqA== Received: from SJ0PR05CA0054.namprd05.prod.outlook.com (2603:10b6:a03:33f::29) by MN2PR12MB4240.namprd12.prod.outlook.com (2603:10b6:208:1d3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.26; Sun, 16 Jul 2023 08:16:10 +0000 Received: from DM6NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:33f:cafe::3c) by SJ0PR05CA0054.outlook.office365.com (2603:10b6:a03:33f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.14 via Frontend Transport; Sun, 16 Jul 2023 08:16:10 +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 DM6NAM11FT081.mail.protection.outlook.com (10.13.172.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:09 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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.986.5; Sun, 16 Jul 2023 01:15:58 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 16 Jul 2023 01:15:58 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:15:55 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 4/6] vfio/migration: Refactor PRE_COPY and RUNNING state checks Date: Sun, 16 Jul 2023 11:15:39 +0300 Message-ID: <20230716081541.27900-5-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT081:EE_|MN2PR12MB4240:EE_ X-MS-Office365-Filtering-Correlation-Id: 1251883b-e41c-426e-6613-08db85d4e990 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +X9KHdbATr0VGEPDd8uHh6Zu7Or/1CKyWt9Aa/TTvaO05cfkXXurSI/pv1GuAt4VLwIa66ulDzVTm0Bi21HNUkQgKaShgz6SMblVRSq/iqADcAy3RVbncKbb7RNAC0ADzLQwTvQubF+AYWy3jwNIpCCbazvUHiweDh6MSQT7/0qd3ZHOgutQqZgh3jrqTrdx2jA73+DY6ENvZo27oS6DcVBfbmAETEv2I+ZgZcEBKN8cil0vgKbs+hWnIH85lAZk+VSI8j2FxTjKrmyvzAF+PUvZxrS814QCfNMw3O9c/MJReDD2t/y6QFOInACXrifJ7S4c8HBFL/BT/AasM1J24/t8diCTxywrZXWsmOV1S9kwTte6eDazBBqgfZDw5x+gFOICg1FErwxwiF0PgvvcCMlEnZwApfw1an7ZrlNBwbjEPJl8GoejgVq9f4j7JXXbe14ilyAoHAkWeUwSqpoJmTCxQEXYLbaRDUA1njz9j58xq68NCSC2f0wXjUcPf18CsF5mILx+mOYXtnkttErUYYvkQ+bVUJzwTTWNiMVTSdF+qZ0f+sZAGgPCGaeP48ZzBdY/VeSsHRYSFEIHfGvjSmZicSGiQl14w/qUuOkp0Ub2jdTCqb6Vgme5+bjVzdL4uDU1cUZjhZPzfH89wR95IxU9CQe8q3d743+LTY2JsKaJAWGgLzQWXU8wVzRTxTIGjRK0ItmD8uuMIx17FA9KNIuP/zrvJCm/t7k+V004GwqXV8ObvXgjEa50/QHI37I8 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:(13230028)(4636009)(346002)(39860400002)(136003)(396003)(376002)(451199021)(82310400008)(46966006)(40470700004)(36840700001)(36860700001)(40460700003)(70586007)(4326008)(70206006)(6916009)(7636003)(356005)(2616005)(86362001)(83380400001)(107886003)(26005)(47076005)(1076003)(426003)(478600001)(36756003)(82740400003)(186003)(336012)(6666004)(7696005)(40480700001)(54906003)(41300700001)(316002)(5660300002)(8936002)(8676002)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:09.9766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1251883b-e41c-426e-6613-08db85d4e990 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: DM6NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4240 Received-SPF: softfail client-ip=2a01:111:f400:7eae::601; envelope-from=avihaih@nvidia.com; helo=NAM11-BN8-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Joao Martins Move the PRE_COPY and RUNNING state checks to helper functions. This is in preparation for adding P2P VFIO migration support, where these helpers will also test for PRE_COPY_P2P and RUNNING_P2P states. Signed-off-by: Joao Martins Signed-off-by: Avihai Horon Reviewed-by: Cédric Le Goater --- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/common.c | 22 ++++++++++++++++++---- hw/vfio/migration.c | 10 ++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index da43d27352..e9b8954595 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -230,6 +230,8 @@ void vfio_unblock_multiple_devices_migration(void); bool vfio_viommu_preset(VFIODevice *vbasedev); int64_t vfio_mig_bytes_transferred(void); void vfio_reset_bytes_transferred(void); +bool vfio_device_state_is_running(VFIODevice *vbasedev); +bool vfio_device_state_is_precopy(VFIODevice *vbasedev); #ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index, diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9aac21abb7..16cf79a76c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -437,6 +437,20 @@ static void vfio_set_migration_error(int err) } } +bool vfio_device_state_is_running(VFIODevice *vbasedev) +{ + VFIOMigration *migration = vbasedev->migration; + + return migration->device_state == VFIO_DEVICE_STATE_RUNNING; +} + +bool vfio_device_state_is_precopy(VFIODevice *vbasedev) +{ + VFIOMigration *migration = vbasedev->migration; + + return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY; +} + static bool vfio_devices_all_dirty_tracking(VFIOContainer *container) { VFIOGroup *group; @@ -457,8 +471,8 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container) } if (vbasedev->pre_copy_dirty_page_tracking == ON_OFF_AUTO_OFF && - (migration->device_state == VFIO_DEVICE_STATE_RUNNING || - migration->device_state == VFIO_DEVICE_STATE_PRE_COPY)) { + (vfio_device_state_is_running(vbasedev) || + vfio_device_state_is_precopy(vbasedev))) { return false; } } @@ -503,8 +517,8 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container) return false; } - if (migration->device_state == VFIO_DEVICE_STATE_RUNNING || - migration->device_state == VFIO_DEVICE_STATE_PRE_COPY) { + if (vfio_device_state_is_running(vbasedev) || + vfio_device_state_is_precopy(vbasedev)) { continue; } else { return false; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 8acd182a8b..48f9c23cbe 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -411,7 +411,7 @@ static void vfio_state_pending_estimate(void *opaque, uint64_t *must_precopy, VFIODevice *vbasedev = opaque; VFIOMigration *migration = vbasedev->migration; - if (migration->device_state != VFIO_DEVICE_STATE_PRE_COPY) { + if (!vfio_device_state_is_precopy(vbasedev)) { return; } @@ -444,7 +444,7 @@ static void vfio_state_pending_exact(void *opaque, uint64_t *must_precopy, vfio_query_stop_copy_size(vbasedev, &stop_copy_size); *must_precopy += stop_copy_size; - if (migration->device_state == VFIO_DEVICE_STATE_PRE_COPY) { + if (vfio_device_state_is_precopy(vbasedev)) { vfio_query_precopy_size(migration); *must_precopy += @@ -459,9 +459,8 @@ static void vfio_state_pending_exact(void *opaque, uint64_t *must_precopy, static bool vfio_is_active_iterate(void *opaque) { VFIODevice *vbasedev = opaque; - VFIOMigration *migration = vbasedev->migration; - return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY; + return vfio_device_state_is_precopy(vbasedev); } static int vfio_save_iterate(QEMUFile *f, void *opaque) @@ -656,7 +655,6 @@ static const SaveVMHandlers savevm_vfio_handlers = { static void vfio_vmstate_change(void *opaque, bool running, RunState state) { VFIODevice *vbasedev = opaque; - VFIOMigration *migration = vbasedev->migration; enum vfio_device_mig_state new_state; int ret; @@ -664,7 +662,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) new_state = VFIO_DEVICE_STATE_RUNNING; } else { new_state = - (migration->device_state == VFIO_DEVICE_STATE_PRE_COPY && + (vfio_device_state_is_precopy(vbasedev) && (state == RUN_STATE_FINISH_MIGRATE || state == RUN_STATE_PAUSED)) ? VFIO_DEVICE_STATE_STOP_COPY : VFIO_DEVICE_STATE_STOP; From patchwork Sun Jul 16 08:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=nvdS+1AG; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dP22R6Sz20Dw for ; Sun, 16 Jul 2023 18:17:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwvT-0007p2-AZ; Sun, 16 Jul 2023 04:16:19 -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 1qKwvS-0007ok-DZ for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:18 -0400 Received: from mail-dm6nam04on20614.outbound.protection.outlook.com ([2a01:111:f400:7e8b::614] 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 1qKwvP-0000r2-TN for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnxpqOg6k/O3EpQFCe9y5L2fe46OvbJm0XmidwH6/zIxuirwRLkxhJawCvziY4jMUC1HSoidWidVcJ3X0zpoo1axiqySOJWXzf0x/pyba/luJI3XMdCKN4L98/qMgEQsO9Gz5C/Xb9QsBSdvJYb1Lq4kFJ1CheadD39Uigy2ab4ZlDN89vw8ZI4ERmaNdjB+qe/bBVpeaQklbKtPjUcgGVUWQ3maElcJLXfQ6tNPrV2w1vjC+aSkD11R197AKtLvK3/IbSqanVATm7higpUuwQKVhsFXWg24YeOKOt4ORtpAx+EzrYUAF+S6NqnJKMfS+zZzOGN2rlvMzbGCK/e4Cw== 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=II9vSQqvsxX2Oi4hRpElLXN6ilXWgk+/XEEI6yfyTVM=; b=drSyIGncpHZC261RmnZimeziFzE4W9pcO/ISpOFr3tVJD8blDHcu+692urNBKP6EFhPow1Q28R+RxST/jIdPEAzWHc3ypU7IJ907JSmOh9RFacLwS+XbzSmKew23PFAZg/YooIrheG5LgDYmzI2MmJGT+AjCeW0Oji3s7A7/mg849RvxfulbB0afgF+C6eegPyNJNbBBSKTSlgmGMrmaYFkr6F4dnrNBCLoSU29N4c5/DfcQ2By/J2DhgDNXrJbvb8jw6idIr0yByiUYtoAeY2Dk1WkcRU+agyrJx+Yv4tbzjw+ZcChqXrzyHBtISMp/4AqRclZmyLDG6DskstQHLA== 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 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=II9vSQqvsxX2Oi4hRpElLXN6ilXWgk+/XEEI6yfyTVM=; b=nvdS+1AGGaEU8c14zgZiExYjVG0iY5Fr+fGsNr5MYf3ZQUxfPvzY5WDYE6jcj/HcIgOQO9CjPnej/oPcNEZKthKGh4NSnZwWn3R4U5r+QL001A0RSYQBxvqlMzqnz8gSrVnNYAKfEKWk7qP14nbKe8t6A5d7QFgPTQGVgkqzUI187fgJvn0DbBbt2EvYcgO9vbenmb5meWax69SnmvU156j7P2yr7Wo50MYWG9euICHQu4IuvHTRDrljGPL6SQOnO+8Fcu8+k74Z55LTFq4agTG6JjiWGHoiRYI73B3x/xlJU1dFjobSG+tz2KJ2zOWUwJZkkgFzzHhaLazWnQfC1A== Received: from MW4PR03CA0224.namprd03.prod.outlook.com (2603:10b6:303:b9::19) by PH8PR12MB6699.namprd12.prod.outlook.com (2603:10b6:510:1ce::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Sun, 16 Jul 2023 08:16:11 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::d) by MW4PR03CA0224.outlook.office365.com (2603:10b6:303:b9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:11 +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 CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31 via Frontend Transport; Sun, 16 Jul 2023 08:16:11 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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.986.5; Sun, 16 Jul 2023 01:16:02 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 16 Jul 2023 01:16:01 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:15:58 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 5/6] vfio/migration: Add P2P support for VFIO migration Date: Sun, 16 Jul 2023 11:15:40 +0300 Message-ID: <20230716081541.27900-6-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT058:EE_|PH8PR12MB6699:EE_ X-MS-Office365-Filtering-Correlation-Id: c04d89ce-00d2-484e-1d9a-08db85d4ea73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4dYYBr4B+sft3mlK4ybMB3wqy12q0pgP4GXPABSCCOX+QaHYwIQQns6QTOLLFW78tEtSm5Ll1irIXhbWld2BJKrgQllYzhli5G5dR+3VwboxBIVhqBjAMOaQEx/Mexg5lfryzohaawdbHO//+fXdZ9idt8YVRtW666+PR1KOAgwncK6DrVbUd0HGnmkWdOaelUoBvErb1+0tCSon5/D79h2YPvLYAXrXzmKRog8LlQvYmAO+CRHfM4HGF9FF4rkVVus7/D3YwYgGkdOmr/SDQsbx1JiKiN8/sAbA2WRTtEk2bhotidJn9gRsl6dRCzmPyJbVXlePNeVFtWJoN7Ehx5cfN892l1i0LpSF6/v1QFLWhkdmzZgGNLn8Y3RvNeL7KfsoRWhbnxZdoQ5FLK6XCO1y4RD21mF9xmPOl6FR0RH9zJjINku4l9GWhsLu7LcQ6Stc+gI3mbp66epaKmI3qnX3kQThwlHzPwbe1lq+o9hplxx0sid6Nl4mxNnL++kuIWHmOyLL/YTuEtcjGxNTkdHxTOVg00Ln49ozL1OTbCATWoDF3w7asQ3svfdy0ft5tFk2D1x55SS9kV6yU9PWpPGDunHT50wIltGSlkcQKmvJRoxOvjOzskMdPIpTlPMst6QMtpRkGAgLDg6EXPd2szNUeyf1nv/lh6jIz7rWlXBGEKFQtYPWz3It7RwoUwUirQw55R5F2TaVxTbCL2r8eJ+e9BfSzVM5g0fmZWUnBPRaR4wbriXnNJz3RGMidfDI 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:(13230028)(4636009)(376002)(39860400002)(136003)(396003)(346002)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(36756003)(26005)(186003)(2906002)(40460700003)(30864003)(40480700001)(2616005)(5660300002)(1076003)(107886003)(478600001)(426003)(83380400001)(47076005)(336012)(316002)(6666004)(8676002)(41300700001)(54906003)(8936002)(4326008)(70586007)(70206006)(6916009)(36860700001)(7696005)(86362001)(82740400003)(7636003)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:11.4468 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c04d89ce-00d2-484e-1d9a-08db85d4ea73 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6699 Received-SPF: softfail client-ip=2a01:111:f400:7e8b::614; envelope-from=avihaih@nvidia.com; helo=NAM04-DM6-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org VFIO migration uAPI defines an optional intermediate P2P quiescent state. While in the P2P quiescent state, P2P DMA transactions cannot be initiated by the device, but the device can respond to incoming ones. Additionally, all outstanding P2P transactions are guaranteed to have been completed by the time the device enters this state. The purpose of this state is to support migration of multiple devices that are doing P2P transactions between themselves. Add support for P2P migration by transitioning all the devices to the P2P quiescent state before stopping or starting the devices. Use the new VMChangeStateHandler pre_change_cb to achieve that behavior. This will allow migration of multiple VFIO devices if all of them support P2P migration. Signed-off-by: Avihai Horon --- docs/devel/vfio-migration.rst | 93 +++++++++++++++++++++-------------- hw/vfio/common.c | 6 ++- hw/vfio/migration.c | 58 +++++++++++++++++----- hw/vfio/trace-events | 2 +- 4 files changed, 107 insertions(+), 52 deletions(-) diff --git a/docs/devel/vfio-migration.rst b/docs/devel/vfio-migration.rst index b433cb5bb2..b9c57ba651 100644 --- a/docs/devel/vfio-migration.rst +++ b/docs/devel/vfio-migration.rst @@ -23,9 +23,21 @@ and recommends that the initial bytes are sent and loaded in the destination before stopping the source VM. Enabling this migration capability will guarantee that and thus, can potentially reduce downtime even further. -Note that currently VFIO migration is supported only for a single device. This -is due to VFIO migration's lack of P2P support. However, P2P support is planned -to be added later on. +To support migration of multiple devices that are doing P2P transactions +between themselves, VFIO migration uAPI defines an intermediate P2P quiescent +state. While in the P2P quiescent state, P2P DMA transactions cannot be +initiated by the device, but the device can respond to incoming ones. +Additionally, all outstanding P2P transactions are guaranteed to have been +completed by the time the device enters this state. + +All the devices that support P2P migration are first transitioned to the P2P +quiescent state and only then are they stopped or started. This makes migration +safe P2P-wise, since starting and stopping the devices is not done atomically +for all the devices together. + +Thus, multiple VFIO devices migration is allowed only if all the devices +support P2P migration. Single VFIO device migration is allowed regardless of +P2P migration support. A detailed description of the UAPI for VFIO device migration can be found in the comment for the ``vfio_device_mig_state`` structure in the header file @@ -132,54 +144,63 @@ will be blocked. Flow of state changes during Live migration =========================================== -Below is the flow of state change during live migration. +Below is the state change flow during live migration for a VFIO device that +supports both precopy and P2P migration. The flow for devices that don't +support it is similar, except that the relevant states for precopy and P2P are +skipped. The values in the parentheses represent the VM state, the migration state, and the VFIO device state, respectively. -The text in the square brackets represents the flow if the VFIO device supports -pre-copy. Live migration save path ------------------------ :: - QEMU normal running state - (RUNNING, _NONE, _RUNNING) - | + QEMU normal running state + (RUNNING, _NONE, _RUNNING) + | migrate_init spawns migration_thread - Migration thread then calls each device's .save_setup() - (RUNNING, _SETUP, _RUNNING [_PRE_COPY]) - | - (RUNNING, _ACTIVE, _RUNNING [_PRE_COPY]) - If device is active, get pending_bytes by .state_pending_{estimate,exact}() - If total pending_bytes >= threshold_size, call .save_live_iterate() - [Data of VFIO device for pre-copy phase is copied] - Iterate till total pending bytes converge and are less than threshold - | - On migration completion, vCPU stops and calls .save_live_complete_precopy for - each active device. The VFIO device is then transitioned into _STOP_COPY state - (FINISH_MIGRATE, _DEVICE, _STOP_COPY) - | - For the VFIO device, iterate in .save_live_complete_precopy until - pending data is 0 - (FINISH_MIGRATE, _DEVICE, _STOP) - | - (FINISH_MIGRATE, _COMPLETED, _STOP) - Migraton thread schedules cleanup bottom half and exits + Migration thread then calls each device's .save_setup() + (RUNNING, _SETUP, _PRE_COPY) + | + (RUNNING, _ACTIVE, _PRE_COPY) + If device is active, get pending_bytes by .state_pending_{estimate,exact}() + If total pending_bytes >= threshold_size, call .save_live_iterate() + Data of VFIO device for pre-copy phase is copied + Iterate till total pending bytes converge and are less than threshold + | + On migration completion, the vCPUs and the VFIO device are stopped + The VFIO device is first put in P2P quiescent state + (FINISH_MIGRATE, _ACTIVE, _PRE_COPY_P2P) + | + Then the VFIO device is put in _STOP_COPY state + (FINISH_MIGRATE, _ACTIVE, _STOP_COPY) + .save_live_complete_precopy() is called for each active device + For the VFIO device, iterate in .save_live_complete_precopy() until + pending data is 0 + | + (POSTMIGRATE, _COMPLETED, _STOP_COPY) + Migraton thread schedules cleanup bottom half and exits + | + .save_cleanup() is called + (POSTMIGRATE, _COMPLETED, _STOP) Live migration resume path -------------------------- :: - Incoming migration calls .load_setup for each device - (RESTORE_VM, _ACTIVE, _STOP) - | - For each device, .load_state is called for that device section data - (RESTORE_VM, _ACTIVE, _RESUMING) - | - At the end, .load_cleanup is called for each device and vCPUs are started - (RUNNING, _NONE, _RUNNING) + Incoming migration calls .load_setup() for each device + (RESTORE_VM, _ACTIVE, _STOP) + | + For each device, .load_state() is called for that device section data + (RESTORE_VM, _ACTIVE, _RESUMING) + | + At the end, .load_cleanup() is called for each device and vCPUs are started + The VFIO device is first put in P2P quiescent state + (RUNNING, _ACTIVE, _RUNNING_P2P) + | + (RUNNING, _NONE, _RUNNING) Postcopy ======== diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 16cf79a76c..7c3d636025 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -441,14 +441,16 @@ bool vfio_device_state_is_running(VFIODevice *vbasedev) { VFIOMigration *migration = vbasedev->migration; - return migration->device_state == VFIO_DEVICE_STATE_RUNNING; + return migration->device_state == VFIO_DEVICE_STATE_RUNNING || + migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P; } bool vfio_device_state_is_precopy(VFIODevice *vbasedev) { VFIOMigration *migration = vbasedev->migration; - return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY; + return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY || + migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P; } static bool vfio_devices_all_dirty_tracking(VFIOContainer *container) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 48f9c23cbe..02ee99c938 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -71,8 +71,13 @@ static const char *mig_state_to_str(enum vfio_device_mig_state state) return "STOP_COPY"; case VFIO_DEVICE_STATE_RESUMING: return "RESUMING"; + case VFIO_DEVICE_STATE_RUNNING_P2P: + return "RUNNING_P2P"; case VFIO_DEVICE_STATE_PRE_COPY: return "PRE_COPY"; + case VFIO_DEVICE_STATE_PRE_COPY_P2P: + return "PRE_COPY_P2P"; + default: return "UNKNOWN STATE"; } @@ -652,20 +657,31 @@ static const SaveVMHandlers savevm_vfio_handlers = { /* ---------------------------------------------------------------------- */ -static void vfio_vmstate_change(void *opaque, bool running, RunState state) +static void vfio_vmstate_change(VFIODevice *vbasedev, bool running, + RunState state, bool pre_state_change) { - VFIODevice *vbasedev = opaque; + VFIOMigration *migration = vbasedev->migration; enum vfio_device_mig_state new_state; int ret; - if (running) { - new_state = VFIO_DEVICE_STATE_RUNNING; + if (pre_state_change && !(migration->mig_flags & VFIO_MIGRATION_P2P)) { + return; + } + + if (pre_state_change) { + new_state = migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ? + VFIO_DEVICE_STATE_PRE_COPY_P2P : + VFIO_DEVICE_STATE_RUNNING_P2P; } else { - new_state = - (vfio_device_state_is_precopy(vbasedev) && - (state == RUN_STATE_FINISH_MIGRATE || state == RUN_STATE_PAUSED)) ? - VFIO_DEVICE_STATE_STOP_COPY : - VFIO_DEVICE_STATE_STOP; + if (running) { + new_state = VFIO_DEVICE_STATE_RUNNING; + } else { + new_state = (vfio_device_state_is_precopy(vbasedev) && + (state == RUN_STATE_FINISH_MIGRATE || + state == RUN_STATE_PAUSED)) ? + VFIO_DEVICE_STATE_STOP_COPY : + VFIO_DEVICE_STATE_STOP; + } } /* @@ -685,7 +701,23 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state), - mig_state_to_str(new_state)); + pre_state_change, mig_state_to_str(new_state)); +} + +static void vfio_vmstate_pre_change_handler(void *opaque, bool running, + RunState state) +{ + VFIODevice *vbasedev = opaque; + + vfio_vmstate_change(vbasedev, running, state, true); +} + +static void vfio_vmstate_change_handler(void *opaque, bool running, + RunState state) +{ + VFIODevice *vbasedev = opaque; + + vfio_vmstate_change(vbasedev, running, state, false); } static void vfio_migration_state_notifier(Notifier *notifier, void *data) @@ -798,9 +830,9 @@ static int vfio_migration_init(VFIODevice *vbasedev) register_savevm_live(id, VMSTATE_INSTANCE_ID_ANY, 1, &savevm_vfio_handlers, vbasedev); - migration->vm_state = qdev_add_vm_change_state_handler(vbasedev->dev, - vfio_vmstate_change, - vbasedev); + migration->vm_state = qdev_add_vm_change_state_handler_full( + vbasedev->dev, vfio_vmstate_change_handler, + vfio_vmstate_pre_change_handler, vbasedev); migration->migration_state.notify = vfio_migration_state_notifier; add_migration_state_change_notifier(&migration->migration_state); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index ee7509e68e..efafe613f2 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -166,4 +166,4 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 vfio_state_pending_estimate(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 -vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" +vfio_vmstate_change(const char *name, int running, const char *reason, bool pre_state_change, const char *dev_state) " (%s) running %d reason %s pre state change %d device state %s" From patchwork Sun Jul 16 08:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 1808408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=BlZtD8DV; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R3dP20GzHz20Cs for ; Sun, 16 Jul 2023 18:17:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKwve-0007qK-Sw; Sun, 16 Jul 2023 04:16:30 -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 1qKwvc-0007qB-PR for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:28 -0400 Received: from mail-dm6nam11on20601.outbound.protection.outlook.com ([2a01:111:f400:7eaa::601] helo=NAM11-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 1qKwva-0000sL-Te for qemu-devel@nongnu.org; Sun, 16 Jul 2023 04:16:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BedhcfP7vnQ+4mWJAsVEiEutSFGLQuhbswxJ2QdM+bsjBGtM1cujtg06kkx6lDttHac8+adp18aGYy3Jvg72og3Zb1zrJrZ4UqSupzUNDykTjaUdC/ujEmsZym+SWw5D+er3Fb4YjP7fEPrUhFejvWlbGTxzCNem4/nqpkoMoauxsd2Oyj83MHXBvgBF75DjDhxOtJKQo6ohBWHDQYyBdH366dRGwGUEOW1cZbFLBYLg0QZpnOYZLZPL6zSnUC8z7UQpp75jPdJStG+kfT7Fp4X6ohv35TGt1qopYYnOqRF8NDDm/zNhhm/64jWajI1nXAbeG1aBZiOt5eOeNf6ZEA== 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=h5MEdRwV72R6OIjCi9arCh3dkqRH9me6j9H6FsOjMuA=; b=TG59wPLOLx9VDhnbTBiFj15pYlG/aTq7JaSdR7CjiiHKugn0PDE5HHqiowZZ6EaqhwIW1CM3KNQgeax4ZoqnLzR+fdpbr4N3ksJXMAp+Eay4RQFyUsumfpyXznAYiH47FQy88UAgOKsD0ISz1EdzhQv1fpCz3MAEK+UrnrYzo/1F2MDU7k/YM1V2+SEOaQeaSZBkXbrOhQbZn9LIARAm9QdiLc5shrwvwW8eqZlyuhIcJb5MSSUPjZuRo+0PtLLORm7qpfx0nWvguswo8HRFWoFBLv4+YncZzsVrRKjRMdNqFZumqGd5Cf1lch1y0EzBQjkuD6nkyiNTRpDkjfrfLg== 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 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=h5MEdRwV72R6OIjCi9arCh3dkqRH9me6j9H6FsOjMuA=; b=BlZtD8DVzyd5Wk7ozrMgFSNzmQAkUeayio/LkjID1haZaGVK04MKxAvPtACqPenis3cntLnl/lj6LJ3ppbpjhlLXP0zmRk1pJ+YF2kOJfg4S2DSy14amWtTFq0weEp2oRBmOsFuXDip/j577qCgx9tRHLk//SfQovhpH/rSj6hwqWUs8g7ozVJoO1tRKdtvlLJHQ/8tsZJjPv8vH0C6GcTbomkUklAp/VWxhW4BWxrhK8wv7yvxJXkVC7MwwQ8fGa9cV8eWVLknJEmox4tECy+lVEJdGP5zD7h3YGiiJqcZD282A115Oocj1RxHJy+WXYxEuexx55xeKQ9QncywdIQ== Received: from MW4PR03CA0127.namprd03.prod.outlook.com (2603:10b6:303:8c::12) by DS7PR12MB5767.namprd12.prod.outlook.com (2603:10b6:8:76::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Sun, 16 Jul 2023 08:16:18 +0000 Received: from CO1NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::55) by MW4PR03CA0127.outlook.office365.com (2603:10b6:303:8c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32 via Frontend Transport; Sun, 16 Jul 2023 08:16:18 +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 CO1NAM11FT065.mail.protection.outlook.com (10.13.174.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.28 via Frontend Transport; Sun, 16 Jul 2023 08:16:17 +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.986.5; Sun, 16 Jul 2023 01:16:05 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.986.37; Sun, 16 Jul 2023 01:16:04 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 16 Jul 2023 01:16:02 -0700 From: Avihai Horon To: CC: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , Paolo Bonzini , Joao Martins , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon Subject: [PATCH for-8.2 6/6] vfio/migration: Allow migration of multiple P2P supporting devices Date: Sun, 16 Jul 2023 11:15:41 +0300 Message-ID: <20230716081541.27900-7-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230716081541.27900-1-avihaih@nvidia.com> References: <20230716081541.27900-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT065:EE_|DS7PR12MB5767:EE_ X-MS-Office365-Filtering-Correlation-Id: b55c7435-7103-4d5f-3d72-08db85d4ee58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7TaTl/99q9M0XPec72DUjAsvq+R3LIPA2QAN7cZX7tnpf7hARy3WkxBkmnRnyJqPnrIXKzLcA0b0pHZ9CNfkg/uehQjvLNN7YayavhBmuWQ6ByXVGzz68vmbmqCIQJJRCQiiEECPF2vYN7hAg1xMG1mzaoN6gaGP3ECJUFxIcKcO5xfKfgmu9o8tmwQyS1BYok/qfjHaMmKWmnF2HwA1vrsYUhqJuUe1Jq3G6o9ln9uUIQxHGFHbp9s1ye/fswOdVfiM9mvNWHsFXR2M+ye8n+MPCdqu07sGrv36CuU5R4ZazEmq/car6vieg0ixwW25u87+6aMKRY/YbBjRRZeENvhEBbmRdecHIh1jtHrH3NvbTl4/hXeG8LmN7zBVOsTj+xXh+Agh+9vq6Ab1ntg3KxiFY855X5aJfIX1c6Q/A75tMr0jdhaUpwp22LQePJdgre9VwcwHsEx+mCpc3pX4MLduK4+ibDRtglYibts5bAUHZOqs8wNOa3F2J7ygba1VRFEWFSpYGv1iLIiUVgth/OohDBq7EXzek+Z4Nrwa1xHQ773cabZUd2yhGmkYlXcPjgcyuNYdTc7oOHqn/q0X3ZrTT79s2F3nCXLhj+REccTjlbDlzaUe/SXYGwSEs8LbCEwWRRI/6pxHMc0pZUVo7DEyCtwZw2PU7gSyKjE4wOOOuLPveJvBTZH2qeuqXiMOqRxWIdRAa7PEQpHoSbFKVpa38UjCm468PfUacHqdRBo= 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:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(136003)(451199021)(82310400008)(46966006)(36840700001)(40470700004)(40480700001)(40460700003)(6666004)(7696005)(107886003)(4326008)(70586007)(6916009)(70206006)(478600001)(82740400003)(356005)(7636003)(54906003)(83380400001)(47076005)(426003)(336012)(186003)(1076003)(26005)(36860700001)(2616005)(86362001)(36756003)(2906002)(5660300002)(8676002)(8936002)(41300700001)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2023 08:16:17.9816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b55c7435-7103-4d5f-3d72-08db85d4ee58 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: CO1NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5767 Received-SPF: softfail client-ip=2a01:111:f400:7eaa::601; envelope-from=avihaih@nvidia.com; helo=NAM11-DM6-obe.outbound.protection.outlook.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now that P2P support has been added to VFIO migration, allow migration of multiple devices if all of them support P2P migration. Single device migration is allowed regardless of P2P migration support. Signed-off-by: Avihai Horon Signed-off-by: Joao Martins --- hw/vfio/common.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7c3d636025..753b320739 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -363,21 +363,31 @@ bool vfio_mig_active(void) static Error *multiple_devices_migration_blocker; -static unsigned int vfio_migratable_device_num(void) +/* + * Multiple devices migration is allowed only if all devices support P2P + * migration. Single device migration is allowed regardless of P2P migration + * support. + */ +static bool vfio_should_block_multiple_devices_migration(void) { VFIOGroup *group; VFIODevice *vbasedev; unsigned int device_num = 0; + bool all_support_p2p = true; QLIST_FOREACH(group, &vfio_group_list, next) { QLIST_FOREACH(vbasedev, &group->device_list, next) { if (vbasedev->migration) { device_num++; + + if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) { + all_support_p2p = false; + } } } } - return device_num; + return !all_support_p2p && device_num > 1; } int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp) @@ -385,19 +395,19 @@ int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp) int ret; if (multiple_devices_migration_blocker || - vfio_migratable_device_num() <= 1) { + !vfio_should_block_multiple_devices_migration()) { return 0; } if (vbasedev->enable_migration == ON_OFF_AUTO_ON) { - error_setg(errp, "Migration is currently not supported with multiple " - "VFIO devices"); + error_setg(errp, "Multiple VFIO devices migration is supported only if " + "all of them support P2P migration"); return -EINVAL; } error_setg(&multiple_devices_migration_blocker, - "Migration is currently not supported with multiple " - "VFIO devices"); + "Multiple VFIO devices migration is supported only if all of " + "them support P2P migration"); ret = migrate_add_blocker(multiple_devices_migration_blocker, errp); if (ret < 0) { error_free(multiple_devices_migration_blocker); @@ -410,7 +420,7 @@ int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp) void vfio_unblock_multiple_devices_migration(void) { if (!multiple_devices_migration_blocker || - vfio_migratable_device_num() > 1) { + vfio_should_block_multiple_devices_migration()) { return; }