From patchwork Mon Jul 31 10:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334251 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 CFFDFC001E0 for ; Mon, 31 Jul 2023 10:27:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6u-0000hY-7W; Mon, 31 Jul 2023 06:26:44 -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 1qQQ63-0000aq-UC for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:25:51 -0400 Received: from mail-co1nam11on20618.outbound.protection.outlook.com ([2a01:111:f400:7eab::618] helo=NAM11-CO1-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 1qQQ61-0006tC-Gm for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:25:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KqstIj8ok82b0LKEtgl3j+UTUcsKVseHELCXywkv2+ogNBMPua+AZgUE8472XVD2JHKxY/IvAO79ER+WmukmDGNovg54sa2DikTIS3Fo8ZhrunT670Lz0svK03txli0eUWqMBkvX3LZKIx2vuUNRl7JBwuTMOwAnfQhYZgQTGOhjqYeByB/l4CnTy9yFzZxBbhUJSEjY7nIGdQ+4HiYDuwveDrAe/eJRLdsDQjSx84DWVbgre0+kIZLtM1piYdxvceJLmG1QeieQqzzRmhZHBEXVNyNddWDlrA68/57qRreT3sYBVv+gglUhR39PAXGYNDTypCN8930agTS6yPk6WA== 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=lCBk7wxN9QtBWhcmskUDv2SwkZBNuweeovFhykgaUJ5F1n9Jnd7SecTnHpeBtfOuclXAi62DL/xt56NW9vhAQVF8tL9FV0j+8mIdq7bOj8fwv2RC3d+20oOVnah7FlzgJ27daqXVr7Mws3xOMAizdCVVU4xngRHpJcJD1wZK9IaxbvI3y/Sn0Zk8SkauWRx5b1YfgHx5M95NE4jPXwOTMydH1R+bk33Ea8xGB15nHH+6jDBAXWLnsQA661re8wYcEaKLDu5o0k5ei57P5TSf+iTfTv2b3GwkzhG2gmjQOFFpNiwTF4hkeQ1GsOjrJ1LAilEZO78+6cVh/M83omwhKA== 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=8JJJi1BljvRnqc53fMAMnBZ/7qU6EKYrUo6YPtPQy70=; b=pCckrrsZwMLp3CZYmXjATLPl8eAoijXBGPvJ9NSrLUj5TvSg1b+Z+VG/N14giVng8AAk39KL6FZM+vQkgaFz4OU39s7aK7SEeT5XDX3PuoCwHLhMquFX4mIcCElkHL9cm6Bi4D5atiqg/1mn89UIGlyPhBbPj2sQ2FKMLmdT+gjxrKRwAVFIIHjWJ5qXgrmyTBtpBqWgvHIKuJnsJpci/37wzGZ6reVpyKvX6CJHdBX1fLNNvR32sFMBwONLbls4nLErl7j85yCk/JbCguypPKxmhpetXCNus4rfpkPSfbC2nT9ZXyIbrwSQH+5kpZ1S6JJONLJwB55ae0Gxj9jkOg== Received: from BY5PR17CA0035.namprd17.prod.outlook.com (2603:10b6:a03:1b8::48) by SA1PR12MB7368.namprd12.prod.outlook.com (2603:10b6:806:2b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.42; Mon, 31 Jul 2023 10:25:45 +0000 Received: from DM6NAM11FT115.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:1b8:cafe::34) by BY5PR17CA0035.outlook.office365.com (2603:10b6:a03:1b8::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.42 via Frontend Transport; Mon, 31 Jul 2023 10:25:44 +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 DM6NAM11FT115.mail.protection.outlook.com (10.13.173.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Mon, 31 Jul 2023 10:25:44 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Mon, 31 Jul 2023 03:25:29 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:28 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:25 -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 v2 1/6] vfio/migration: Move from STOP_COPY to STOP in vfio_save_cleanup() Date: Mon, 31 Jul 2023 13:25:16 +0300 Message-ID: <20230731102521.15335-2-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT115:EE_|SA1PR12MB7368:EE_ X-MS-Office365-Filtering-Correlation-Id: bd6bb181-484a-4dcd-9cac-08db91b07fcc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZjCT+R5NcSlHE6Gg4HaLg/3QHyFqkPNYlXNgnTxMdpOgrWf+kwMOJhNWMvFCXGAu8jgEpy3xP5v8trJQpFQeHfer5CE/7tdzEpuwlZgKfImVrsJIfNrwZjjkCNlsd2soAQ2P9CLTqTHItAluUwrbMJ9qCCsYtu51FB7wKkhtuRKXUL/R3FECEkHAjREgf64TrpmKJbpPZeUQeZTsaLCT8ZGzoW7Qixw88hF+sYPbJsTVA+P9yH7HNuTTqfyLQhvywG5jf5gwv3zPBFnGscybGdXJlTYCCq8dP1a5zQvwYmOLeIe938Gau7lupjh67kuwr8OoSkt6imM/h8hEQoeH3S0Fr+fgKXCxNqdnW88ECfMYlryDpv10XjY8GkcKzVnULR9h00OMLGgzrvOJ95KR/bolV3aEvF+qjbDdly+/T/sE7F0QT+F2O1ULYE3wVRwNQiSdKe61zU2tgc4u9YUy6YsGex4OE/S0AhNUSVLBryBX7NCD8E3WLpwQ4kdk17p5dRlLVW6ZaNVpfSTFQ9pNT8c1xyO1H/6mU3ib23Ks9SAGw6GDc41slu8RnW/smnLykUvU29sFbyG3ULMTQ5znXcEXXdXPviH7Y+2LbYfEpya0ah4wQIRQOPGfsvtkWJtldUfgj55rBgEBQYBtzKC+2iXTFWuzmDRws0W83LCVhnIMCbks3ZM7uX0KLQIBjZSbQ5KT8qGnN5s5SAV7ZjHlhoCf4QiYsDQaJRvGDQu31qM4LK2a+e1GjJfUbaTxTzh+ 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)(396003)(39860400002)(346002)(376002)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(5660300002)(2616005)(426003)(1076003)(8936002)(8676002)(186003)(336012)(36860700001)(316002)(26005)(47076005)(83380400001)(478600001)(70586007)(70206006)(4326008)(6916009)(54906003)(107886003)(6666004)(7696005)(41300700001)(86362001)(40480700001)(40460700003)(36756003)(2906002)(356005)(7636003)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:25:44.6038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd6bb181-484a-4dcd-9cac-08db91b07fcc 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: DM6NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7368 Received-SPF: softfail client-ip=2a01:111:f400:7eab::618; envelope-from=avihaih@nvidia.com; helo=NAM11-CO1-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Mon Jul 31 10:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334253 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 2920DC001DE for ; Mon, 31 Jul 2023 10:28:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6t-0000gq-7O; Mon, 31 Jul 2023 06:26:43 -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 1qQQ6C-0000bp-M1 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:01 -0400 Received: from mail-co1nam11on20606.outbound.protection.outlook.com ([2a01:111:f400:7eab::606] helo=NAM11-CO1-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 1qQQ66-0006tv-Cm for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:25:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OalwJpgBKcJmwu/6crxleyysZI5wl7Fdl7XibJ59jLHURbf+1mgFpvVdHBp/+sG302xGdEbOBZ0bTng/Wede4mFyjRMTjKd7jusezfnCVG7W0votjAhHUnwGYtffSVNEqfUQUfQ2C9wlPK7v40PwfWySpqhEDqfZZLSt2psno/7ZUcJY6SJFndNFP2tIO0BfqGNI/32+0VF7L839yDCLonDM+mdJuiTh3nnI6YUpHwOYKwSwwU03fDEcaOSBrWSo7ePDwL0Gi02Hl95fi4TtuD183z8dxew6H14quNOwBTuDxlXY7yNY6+emBWzOXm75TR3HPUiRRDE/f+eImrSMBQ== 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=T8k5DOiHAirpYEv9iN5HRTeF1jcAK3qaPnpCUyNvjWI=; b=PQ0ntGRNjL53v9KftzW9aRRirpxu67mVY3FKtk5YUOwYgbXLkAGxWwEZgvBlStXTi+SmVks15qqBvwI4Sulc3fw8Z2cthMaM3yb5rb7qk0OYGDHQqsibLY4IQatl40REMVuB7TLMBjQTlh/dtyFH08Gltw85SiH7Ah/SPeCJ+roCYJtuFGAlgUu2Pwb9G+GeiyAeo5DZAjktZj2dPs2IqLKake7r4C2ufQ2KKlyMpT7qFPrzaE9o70Rj4WQauJFa9Sqzu5fHugrEBlJ+pn3JPBcGQ8llouy1gf9JJTLtXFE+v2068fszjn5uhSlpJAVw11ek1CrA10ODpY4v2JBb9w== 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=T8k5DOiHAirpYEv9iN5HRTeF1jcAK3qaPnpCUyNvjWI=; b=kkIsgSA2OJQaW1QidtA1fnyPGr4rA1/XdoY/K9BKpvMLb9tsU/iqpmpCb+G11i8RR2N1599dcMK6yaWT1AeEP56060skjhwoQDlweGX/0ibt5JAZuohpcX99QGDmx+Wznu6wYLPtU94GRu0z4zRbAayioesBXtmg+cOkbwaxNSfWe1D0vhm6vjaPhTpJCE3M1nRHhCurB46r6QG5scSC3tv+hKat/qjg3n36CYyd5PGP/xyc4LccqIfnZNIpYTnAC4s5PfVodvLuh/XJ11/TESIcjX+DgNyYgDXo2QdfYAfAvYFSJnmOMLUEsCojID3Sn6xqQBRm3hziLCLkjoii8w== Received: from BY5PR17CA0020.namprd17.prod.outlook.com (2603:10b6:a03:1b8::33) by MN0PR12MB5739.namprd12.prod.outlook.com (2603:10b6:208:372::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44; Mon, 31 Jul 2023 10:25:49 +0000 Received: from DM6NAM11FT115.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:1b8:cafe::cb) by BY5PR17CA0020.outlook.office365.com (2603:10b6:a03:1b8::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43 via Frontend Transport; Mon, 31 Jul 2023 10:25:48 +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 DM6NAM11FT115.mail.protection.outlook.com (10.13.173.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Mon, 31 Jul 2023 10:25:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Mon, 31 Jul 2023 03:25:32 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:32 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:29 -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 v2 2/6] sysemu: Add prepare callback to struct VMChangeStateEntry Date: Mon, 31 Jul 2023 13:25:17 +0300 Message-ID: <20230731102521.15335-3-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT115:EE_|MN0PR12MB5739:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dcb6c53-c782-449f-015c-08db91b08223 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9T7Ce9407xdLAtm8/Pag8rKrhZVHrhHSb1whIHUnkGnyHNMNRUfFXGdTfLIQo3JjMqUQA33Mi/i+hKcsWU15879qDnRgcXxcIqSxrwS5TJ86fYKsJ0HkJqrr2KbIaIXMJxvdV3M+U9ofatStExHmtHt60bRAHRPOa0MhbCudPbD1jIQ/XQaXNkuDjqiIGtn2BNrJVBOPZ+Cp/aOHOqFLk+1j90Z7EI3Qp38Ul9ZfdlTZn0HJhiYwk4ER/TCQApQarAagWja3ICX/fJ0xeNkn0usZdiVZ8BOHoIYG8NUpS0eifZYvgReSfit5y4r8WvqQATtfU10/9wVqz8jQZ2oYH2+lJkNVFMSyTEe2/TsQZHTl5zXsPlZl4MY+OtzWo8mV6S/ypig6jQky/bItl91QcboyDZjhaqdrk2WM12TZEREKEDJfLi4ZBUcvBt7RwibArg900/UEoh6y9Gm6R/75gd0pq/DISd6cA2im/lwc/AX8085iVZ/loN4TuElTwl0mxRRrkU2QS5AbuFH/lNu4oZH2wNRBSctFObLvEPmJjyVsyISg9oFsrNhSCdWVxth4teRFqqMxTjl/3OktQf6R2Db0Xt8H52j4fqOxAD97zV0fVqANiEJj/PW+RSLnUvH8VmA8KpQNWKom/cfIBLX2iTv/XGIUA+ygZqFoHQCEnqx16RSXDX2CMiEdrNsViU0d2kXXL3XCwoWkb6EMHqAV4RLLy54TvDZOAHMt+ItZNPhNcu2dDGqwUmw5Gxwig/XIA4M12tFU6afWzL+2g+UjdQ== 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)(396003)(376002)(136003)(39860400002)(451199021)(82310400008)(46966006)(36840700001)(40470700004)(6666004)(7696005)(26005)(1076003)(47076005)(2906002)(186003)(336012)(107886003)(54906003)(478600001)(82740400003)(2616005)(36860700001)(7636003)(356005)(426003)(83380400001)(316002)(70586007)(70206006)(4326008)(6916009)(40460700003)(41300700001)(8676002)(8936002)(5660300002)(40480700001)(36756003)(86362001)(145603002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:25:48.5254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5dcb6c53-c782-449f-015c-08db91b08223 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: DM6NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5739 Received-SPF: softfail client-ip=2a01:111:f400:7eab::606; envelope-from=avihaih@nvidia.com; helo=NAM11-CO1-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add prepare callback to struct VMChangeStateEntry. The prepare 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 prepare callbacks and main callbacks are called in two separate phases: First all prepare callbacks are called and only then all main callbacks are called. The purpose of the new prepare 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 callback. Signed-off-by: Avihai Horon Reviewed-by: Cédric Le Goater --- include/sysemu/runstate.h | 4 ++++ softmmu/runstate.c | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 7beb29c2e2..764a0fc6a4 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 *prepare_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..1652ed0439 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 *prepare_cb; void *opaque; QTAILQ_ENTRY(VMChangeStateEntry) entries; int priority; @@ -293,12 +294,39 @@ 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 + * @prepare_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 prepare callback function + * that are invoked when the vm starts or stops running. The main callback and + * the prepare callback are called in two separate phases: First all prepare + * callbacks are called and only then all main callbacks are called. As its + * name suggests, the prepare callback can be used to do some preparatory work + * before invoking the main callback. + * + * 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 *prepare_cb, + void *opaque, int priority) { VMChangeStateEntry *e; VMChangeStateEntry *other; e = g_malloc0(sizeof(*e)); e->cb = cb; + e->prepare_cb = prepare_cb; e->opaque = opaque; e->priority = priority; @@ -333,10 +361,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->prepare_cb) { + e->prepare_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->prepare_cb) { + e->prepare_cb(e->opaque, running, state); + } + } + QTAILQ_FOREACH_REVERSE_SAFE(e, &vm_change_state_head, entries, next) { e->cb(e->opaque, running, state); } From patchwork Mon Jul 31 10:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334250 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 2DEBEC001E0 for ; Mon, 31 Jul 2023 10:27:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6w-0000jl-Id; Mon, 31 Jul 2023 06:26:46 -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 1qQQ6C-0000bq-MJ for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:01 -0400 Received: from mail-bn1nam02on20619.outbound.protection.outlook.com ([2a01:111:f400:7eb2::619] helo=NAM02-BN1-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 1qQQ6A-0006vI-09 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:25:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jQCV+lmU0b/Qs45e7oi0jnQzSBPE1rBrhIo7XjT5j0zSZkMOOK7R7HSUxgfTKhrCG4baDPZOOviy+5kcSw3gxsdZtpsloYt0oLAXad+IvBcoUj9cVrzzLdEsjv5sjPur26flwWRCHxihRRmtARYxg4wbOI+A4hKfr2PunP+U4Xms5z33jZrRKV1/fBLSvtXkrAAKdYGD5lmocp3SBrjoESXv6rf0Kqz8DrWQXixC+ulQ9EweLKNy4vt0NLtV43ca8uP6al39vwQ/jwDpEx71VjDDpPLh15PQpFIie5NExJmVQdIgvodWiXEAgwfy72HfF/uu6lgMyuizKXfEpCPj0Q== 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=YT1gngx+aTS2pITpXaQrIffDHCnwVm1bxDuI3JT6Vnc=; b=FI6L/3d/bTGuxL8rMubHHW5l41S3Oq3AbJTP1uFt7f2zIQLNAM2qc2d8rN8cnHqWW1fDtQtCRd5HxM08VCDI3CTh+DKJoN14Hfr4P9Os/d96fMSN9UAzbGg78x3krPK021eWyAD/xrhrexwjY6OeHGd1Ygp/3woN/jeQeZBMs98M6AWAbdKdUMk+8XKVDjdWKaXA5DUr/VdSDdHSyg4Kw3UU9onlRgAJ35zujSifExZaUJ2EnAZfc/p5e8HDHP3ieJXXqYCAQIQL1zvJBrkn3uay8m+8aEhqbIX2dXuF0xZyM6KC5sxVx+8r8JH0W78RCk7jrvshKRj6ZEPH5C8qrg== 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=YT1gngx+aTS2pITpXaQrIffDHCnwVm1bxDuI3JT6Vnc=; b=lI/4eW/8W9z+vFlJWwKSXtqKu6RxhXIOek42Gioqd35sXPdjvBUh+lS9xLg3pRo9oQPK4KnjHBPyX5XGFUWNGTvwM7XA7A7sCvBPPbSah96xm9OmNsYx/5H/MJIUygOSCtqFfAMSAVvEPZ0cAFZsd91BAEbd3D9Cc0P8G7aes72TGGMN4NUY7T8guxIQkp1op5zCH4gEk/kuEz5GWMKdeEjhTzUPbOBthVm6xQ5QlJgnHck4c8m82wIhmA++9+gCfGwgDvaJ9h1JFnzAZbbHw6XIznuMq0up2ty4gA3Wrc3wQzFcOCgO+L3YnvjOxLoXAZrNJfEajA3/7beTokcQ0Q== Received: from MW4PR04CA0302.namprd04.prod.outlook.com (2603:10b6:303:82::7) by SA0PR12MB4559.namprd12.prod.outlook.com (2603:10b6:806:9e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 10:25:53 +0000 Received: from CO1NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:303:82:cafe::65) by MW4PR04CA0302.outlook.office365.com (2603:10b6:303:82::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43 via Frontend Transport; Mon, 31 Jul 2023 10:25:53 +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 CO1NAM11FT010.mail.protection.outlook.com (10.13.175.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43 via Frontend Transport; Mon, 31 Jul 2023 10:25:52 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Mon, 31 Jul 2023 03:25:36 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:35 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:32 -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 v2 3/6] qdev: Add qdev_add_vm_change_state_handler_full() Date: Mon, 31 Jul 2023 13:25:18 +0300 Message-ID: <20230731102521.15335-4-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT010:EE_|SA0PR12MB4559:EE_ X-MS-Office365-Filtering-Correlation-Id: 2008ea74-9a60-4223-7afd-08db91b084a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sPLrRpS+CaNyim/cPQ7Yln6wYc0JvRVTRofZS584n7tKcmG73zuXa41qaOnCgUwu37f2huHl93s3/fbeYNCUTQrbdgHflAZky6JVqkHGrCISEDbAF5TZbUiSJFPFxTuJ+xo/WOKSRo6TGugkl3AXXTH3+98XL5Dv7inJs8Wz6MdMH+gmD72EVyoSYEb5H9tPiuZ8JJmkhJzP3QcRmWtRW3GpvXBgH7W87ZR2bidDrFrND3IPApRL02oxeYLNkKJoBiST1CSI9AQ5ivdNR8pBGe9zsj40i1oS0mC/kwezpa1Sg4KeD5shcFOBnD1QFE6oAduFcKG6diHA6u4O2WtJYgdVwUQqLQGMbAygUjFNo6SJa9DJMk4FbQ/ImpZ4FwjHCbldHttiPGAHOxg6M8VKEKYcr/0EnhCRHUhwjO+3XzAp8Oz/MsFTwxDJsQFATtd9q2sND1XjHd/ZTXHoKyvtQynoAKhZO08q5Hi7WHCozsq/U38lsCyat3P36Od1XTItwKwCnLD2oRMN2loXIe1QqSZF60nZp/g8sLQtLvOByuhTa+/dkbC12BtR2kvWkXFmhyh/QJokaa55ngMML1M3g4HSn1IPfTzjnY0sIkTIAcALTPm+QuZ5TzLyBkjuY192d+pnf4AJRUDGtkUAKpjFY9jiJ+Z3ezIGEuB0VJp/FQq2srC+P4GdgMYFY46jUQ50taVzYUlhrFL/f38F99QPsNT+JAO8PuYF2Rok5mI+BrjxAUa3Q71yYFm8rl2WV9B6 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)(346002)(39860400002)(136003)(396003)(82310400008)(451199021)(36840700001)(46966006)(40470700004)(82740400003)(356005)(7636003)(40480700001)(86362001)(40460700003)(36756003)(6666004)(478600001)(7696005)(2616005)(107886003)(186003)(336012)(26005)(1076003)(8936002)(8676002)(5660300002)(70586007)(70206006)(54906003)(2906002)(41300700001)(6916009)(4326008)(316002)(36860700001)(83380400001)(426003)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:25:52.7138 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2008ea74-9a60-4223-7afd-08db91b084a4 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: CO1NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4559 Received-SPF: softfail client-ip=2a01:111:f400:7eb2::619; envelope-from=avihaih@nvidia.com; helo=NAM02-BN1-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add qdev_add_vm_change_state_handler_full() variant that allows setting a prepare 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 Reviewed-by: Cédric Le Goater --- 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 764a0fc6a4..08afb97695 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 *prepare_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..8e2639224e 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 prepare_cb + * argument too. + */ +VMChangeStateEntry *qdev_add_vm_change_state_handler_full( + DeviceState *dev, VMChangeStateHandler *cb, + VMChangeStateHandler *prepare_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, prepare_cb, opaque, + depth); } From patchwork Mon Jul 31 10:25:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334254 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 34C01C001DE for ; Mon, 31 Jul 2023 10:28:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6t-0000gm-4z; Mon, 31 Jul 2023 06:26:43 -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 1qQQ6F-0000cK-3q for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:06 -0400 Received: from mail-dm6nam11on2062a.outbound.protection.outlook.com ([2a01:111:f400:7eaa::62a] 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 1qQQ6C-0006vm-M1 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lo37PHd3DfTxku9fdPxWvyCIKMAgtl4lmR3/j67aSgC4tgRMCyUBh2t5INpdqGOUmItUedUXHI9GZ3IBoVH7kiLoW+2Z5lJgDEIhvIzpbUN2WxwH0/Ux5Z+IGzfXm3k+1uvJ6GvqlO+Blo5cbhQK2nKKlEAmmzCGKwYLK5gqGwGzwmlQWnoASso4U0JHahame4j48rKjdFVqCht5sEcHMscbuhN+tAz9xYrZKxWhIqivFXAuCmEQ2TLdHGQBtF90E8y1JcZ1I7gfgoxcovPLNhjWSqz9X08GKeCshNdPQLFklKEs5XmndHosbK2lzYv3tQaalPvdRh3UP2ECyaVS1w== 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=WKp/pmecsHMhRlRbJZqM6zbZwX079spotXBKYXQmioA=; b=Dieawux1krxDIXspbkSpAzU7JnFl3Jbf/7nUXO+mV2z4UaJds4+QMAykZVgND/fWu2yBeLdLBI4SjJ+7Zr500iKdGg9pWdU+pB+Gylv4FkdMBVVgn/OuMKPcr1Ae9ei1npZbbhw2WwHkh4rmtnwEUl/yYegkwvK2pvFNGNBH+x7Ofl6CzkoFKsvDDT52lrCMSbT7t2xiBnoqjz/UImpSFEVTTtNcvMxG1uwP4cMh0Lao+MYWeNXHB1a6Ouctj+K7Bjt0ke4GremZaRg1omXZCf911jQwkcIFJiMtDrQ71JY5J2JXS3rzOay0z3UMkhMox9EqNHUB95B38zsxuz6GEg== 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=WKp/pmecsHMhRlRbJZqM6zbZwX079spotXBKYXQmioA=; b=FTEqL6HI5VoGL5N2MT60YTjI3YFBajj+v9w9D47MJDRdPzhTpqmYGLMvLeaIhk9f2SvT3F7KdrjTPMUmsQ5M5H1Ewm4WdpBjiIJ6lLemTu13fULcyYi1/Tgpnq83ovsK+3vFtcfEB5K76O1reiM+fPvlSqXfwzW1oaZoLCJAJvV5eJ1IGZ6YofIdcsG3gz/JuaTNkmPX+d5PPktmXDwwSsqvev245lodZS1WSPiCgx6pYtTYU3NRax3r0B4KN3XCiDHdKJTUgJxzonFLAb8OrZicxWrrguc/mqVV4LjudEqwWLV47AuMXf+Dn7pOqOiNxniq8H4vIqrG1Cx9lAXHWg== Received: from MW2PR2101CA0019.namprd21.prod.outlook.com (2603:10b6:302:1::32) by SJ2PR12MB8111.namprd12.prod.outlook.com (2603:10b6:a03:4fe::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Mon, 31 Jul 2023 10:25:57 +0000 Received: from CO1NAM11FT082.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::d) by MW2PR2101CA0019.outlook.office365.com (2603:10b6:302:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.9 via Frontend Transport; Mon, 31 Jul 2023 10:25:56 +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 CO1NAM11FT082.mail.protection.outlook.com (10.13.175.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43 via Frontend Transport; Mon, 31 Jul 2023 10:25:56 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Mon, 31 Jul 2023 03:25:40 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:39 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:36 -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 v2 4/6] vfio/migration: Refactor PRE_COPY and RUNNING state checks Date: Mon, 31 Jul 2023 13:25:19 +0300 Message-ID: <20230731102521.15335-5-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT082:EE_|SJ2PR12MB8111:EE_ X-MS-Office365-Filtering-Correlation-Id: d961e595-2244-4cad-81b8-08db91b086dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0gXyZzBCsL3TA7rYUXXsMjsIapOpM9uCRt3sJZ54JyjC0/WCdmUTLqUT/UMrKDubafxxCpVNR/42MvSIWANxlqnRBhaYlgtzLCQqq9fcZFErXxI/V0lZZ++uIyxNNOCXZegKcpKXzfLbR9t+6Zap1tywfByhYRim04P1ILyYF48w+xz8bmDVuQ5tp/Vy/5yZdTvAjyMMB/14ZsYhu8QOavUb1uPg82Ww2oKyGkniHV9ypmpfZ6UX7znnXN9YuaecHMKqb466m7g4a+T7kQTePCWLqP4lZYDosg/MNz+wQvt8KUSdN7bh+gIlm426oWgSNI6o56HuMfX80qQvxU71sLDNEvsbaQUA3hiUJXMulJui9TpXkHiYGRZ8rnEsy7JRo+1WpmlIAnMCvo9oyg2kVTbLtC8dojjG3wNgGH2kvPEsTE7/3eX7/yu+b5bdO4grEO7KMM5ipS8/cn1LY6o9dog8OtJY4APcrFgaQBLnJSwieDacVWV2wqNfl3rmSzDTmS6W5jt5qIx6iqgPaaEB6liuDzO71+BzVF2FczOOBn5UW7lamApMFUjcx0tyORo+lkc/phPab7rqTfvERJsZIJAs9du/YEaQ+B0S9VgZNRaNFKo/2l7dxelrQnwWOscZWYbzOObiMVFOAEUf0nFxEAY0IEuJ8DebSBNKvN+4FkqV/x+/YXtYlcymNl/fK96SwGD6/Z4uFCkNehEpd9EX7emf8PjiqdPMI5JcWa5tgQEvWqNi70RrDqyNWRetYLQy 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)(136003)(376002)(39860400002)(396003)(346002)(82310400008)(451199021)(40470700004)(36840700001)(46966006)(66574015)(40460700003)(2616005)(1076003)(26005)(426003)(186003)(41300700001)(47076005)(70206006)(36860700001)(336012)(4326008)(70586007)(6916009)(83380400001)(8936002)(5660300002)(8676002)(316002)(7696005)(6666004)(478600001)(54906003)(2906002)(40480700001)(82740400003)(7636003)(356005)(36756003)(86362001)(107886003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:25:56.4364 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d961e595-2244-4cad-81b8-08db91b086dc 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: CO1NAM11FT082.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8111 Received-SPF: softfail client-ip=2a01:111:f400:7eaa::62a; 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Mon Jul 31 10:25:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334252 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 7B8E0C001DE for ; Mon, 31 Jul 2023 10:27:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6x-0000jp-AG; Mon, 31 Jul 2023 06:26:47 -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 1qQQ6N-0000ct-B4 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:12 -0400 Received: from mail-co1nam11on2062e.outbound.protection.outlook.com ([2a01:111:f400:7eab::62e] helo=NAM11-CO1-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 1qQQ6J-0006wY-RK for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aQXCGm9ExXIdMomRDC1cXiAMheYwL0S4qktiqapALv4Udt66yqFNjNAy3C8Z+YN44O1gpRlLkClGX0eyG4lNtTTcV27qD/eH31rEUCrvrjYzgTwkV7xnUIJWo+90VzxXWJkoZtRUTZH03329CzPva8crIdjXZxSJA7BYc8zsw9SYdlmp2De7KpFLAWuqJQUMdNQAkR/aJxia7WgUW4HipsYfTptRYQJfAwESOcHagvmLKTehKOe0QH1cOTEVz6Fyi0U6jrFN4Q3v1p3Dj3sk/tqY6pqhwndOsteA4hUqJDMGhatj3qLYcIiii1xGLIhQcTSQLM7SnLUGZlFn8Kz/uA== 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=ACd91EUR986Vkgxd/OiMGSwdK2ShSxIMetErK2wLLtg=; b=bn2tZHN/+Y4j7b5+kRSSHGXpKpTtBBzDhD72rdglC+bboYrm+fNZtNTPokvagWnHJtKdDPQ0V1K9EJ5cuq4nafWzQnBnnh5UCApwP+KkqZ03hbs6cPJOBBKbIA4DwxQPqgflIALP/rbFmZXAjSlOC7+wgI5nFOKjk68swubEwCmv/aDwAVIVLOiwZBvGkuo7cCGLoFiVcIL7rRu+sIxtqEYYj0k69tf7A0R7Rdt57KtMOJknqCsTcLfPGrC5c1Vdzfbg4IJIldMWYCrlSUi5D+mV1Ku5hfj1xkzq9z6YC5pe66q/nlHwaaOvc572dwH+2qGqp40kLRtymzpMLq0bGA== 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=ACd91EUR986Vkgxd/OiMGSwdK2ShSxIMetErK2wLLtg=; b=aEYbEvXnYquUxhqNYhL6Lr/yHR6Ivz676RjYT+DCY8V7KYus7fdW+On1fOn4CmuQl+ktH+5IhPdu8Nv2pht87pf++ekzv1GGdr8ZOJC2VsVsAXsQAxnAE/5w9EbegNxKXZiniGiA71R6Zdkelxj9jgyxMe0q3J7tOtpYgHsEj3QUkANs4yo2gF6y8mGUeWwu0K5WqnQYN8Wc087N4d+mG+ftsTysg3dd9qu6lD5iqIptRgbtvbt+EEPhuiAO8JFU4DUtV7k1xYyfs7DBuUJZCoUNSKdvuVoYiRjRsxVy6Q54UyGTmAztpXOcCK4Z8rUtwk4KYybQ7kQyJGUUQvK2aw== Received: from DS7P222CA0027.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::35) by PH0PR12MB7079.namprd12.prod.outlook.com (2603:10b6:510:21d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.42; Mon, 31 Jul 2023 10:26:01 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::4e) by DS7P222CA0027.outlook.office365.com (2603:10b6:8:2e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Mon, 31 Jul 2023 10:26:01 +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 DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43 via Frontend Transport; Mon, 31 Jul 2023 10:26:01 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Mon, 31 Jul 2023 03:25:43 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:43 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:40 -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 v2 5/6] vfio/migration: Add P2P support for VFIO migration Date: Mon, 31 Jul 2023 13:25:20 +0300 Message-ID: <20230731102521.15335-6-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT011:EE_|PH0PR12MB7079:EE_ X-MS-Office365-Filtering-Correlation-Id: 982d1cf0-a698-464c-af57-08db91b089a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PWB+sMg0aekyUHLE2BzFV3f1TmISeDo16v+dqVmVEImjJw5zT4z/OKrVPtiK2WwFprh3wAPkq76xGu4GITU3845RNjA5DG/iBnnBmP8gzjDte6sYFAGyHACcpOgeDuwVWF2VZwUD0LhSmmExPZjkhE9zDgblCzoS5VqP/k74U2++G3m8a1EgiAKxkfSh8NsnbGuslSIoHHgl14wdMDdxVGFFVObbAnpMc7Byc6KgleVthsSoBeNwWxsfS1PWch6wdJVsqER8OfL61bNNihKPQ71SkatrOrVxIyzGwjR8kc7tc+yBqklMtbWGTuOTWXy63kSCV+yQACZnb02Ws3w3YeHk9T8FxDXBaXXceV0i/3oK6AhGclG3ER2wb2bOVqQH7ZWliFNQtmFpWYk/zJfIgd1Ash08zSPvHtLGdHn5eQsECaLoFPXyC1uE2/xOgOOvOGteK+y8WGaxhEmD9XkMSr/tN93mJfDEz027AYYbVNiR+aMtiSioeb717XKn6JriwCmSaYbqPOcrXNEhNksPqF5cT/gNVYX7/wTJRJXM6p7R8uDFr8xCJDGKg9DOA6SMifoJkKIlqpkTEe8JiOwDeDiob91z/fYgrSCJefj4bCjx1Wu8N/kzuFX50m78OWpEupJZ+IDZAvfNsBgbMjFehZCIhhYz000vLm0pVWcu0UBRgYfaJWwskN++webZa+kwAXGRMDYK8nZveCKm24WeNJ9iRfLME4BFrioaSM98KVMyRb7KwEUJsmV3E71EQKW1 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)(82310400008)(451199021)(36840700001)(46966006)(40470700004)(47076005)(36860700001)(7696005)(36756003)(40460700003)(40480700001)(2616005)(1076003)(26005)(83380400001)(107886003)(336012)(186003)(426003)(70206006)(70586007)(7636003)(356005)(54906003)(82740400003)(86362001)(316002)(4326008)(5660300002)(6916009)(8676002)(8936002)(41300700001)(2906002)(6666004)(478600001)(30864003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:26:01.0997 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 982d1cf0-a698-464c-af57-08db91b089a1 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: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7079 Received-SPF: softfail client-ip=2a01:111:f400:7eab::62e; envelope-from=avihaih@nvidia.com; helo=NAM11-CO1-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 might do 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 prepare_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 | 47 ++++++++++++++++-- hw/vfio/trace-events | 1 + 4 files changed, 106 insertions(+), 41 deletions(-) diff --git a/docs/devel/vfio-migration.rst b/docs/devel/vfio-migration.rst index b433cb5bb2..605fe60e96 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 might do 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..05b1dac2ed 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -71,8 +71,12 @@ 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,6 +656,43 @@ static const SaveVMHandlers savevm_vfio_handlers = { /* ---------------------------------------------------------------------- */ +static void vfio_vmstate_change_prepare(void *opaque, bool running, + RunState state) +{ + VFIODevice *vbasedev = opaque; + VFIOMigration *migration = vbasedev->migration; + enum vfio_device_mig_state new_state; + int ret; + + if (!(migration->mig_flags & VFIO_MIGRATION_P2P)) { + return; + } + + new_state = migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ? + VFIO_DEVICE_STATE_PRE_COPY_P2P : + VFIO_DEVICE_STATE_RUNNING_P2P; + + /* + * If setting the device in new_state fails, the device should be reset. + * To do so, use ERROR state as a recover state. + */ + ret = vfio_migration_set_state(vbasedev, new_state, + VFIO_DEVICE_STATE_ERROR); + if (ret) { + /* + * Migration should be aborted in this case, but vm_state_notify() + * currently does not support reporting failures. + */ + if (migrate_get_current()->to_dst_file) { + qemu_file_set_error(migrate_get_current()->to_dst_file, ret); + } + } + + trace_vfio_vmstate_change_prepare(vbasedev->name, running, + RunState_str(state), + mig_state_to_str(new_state)); +} + static void vfio_vmstate_change(void *opaque, bool running, RunState state) { VFIODevice *vbasedev = opaque; @@ -798,9 +839,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, vfio_vmstate_change_prepare, + 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..329736a738 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -167,3 +167,4 @@ vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer 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_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" From patchwork Mon Jul 31 10:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avihai Horon X-Patchwork-Id: 13334255 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 5866BC001DF for ; Mon, 31 Jul 2023 10:28:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQQ6t-0000gl-3z; Mon, 31 Jul 2023 06:26:43 -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 1qQQ6M-0000cq-IR for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:12 -0400 Received: from mail-dm6nam10on2060a.outbound.protection.outlook.com ([2a01:111:f400:7e88::60a] helo=NAM10-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 1qQQ6K-0006wp-L4 for qemu-devel@nongnu.org; Mon, 31 Jul 2023 06:26:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NY9MwYxhW06Oqz2lKQxPmlg79Pjsrpw8fpinFQf+tmkpTAEzGaL+ak7asGx18WaijQCCWwwZvWH7q7Lb+Ognb/amzSF/jfjvfKIV5Jou8CihhmIQ7Lms5BlBTXbO+T78RtysKbxSP8h/23ZS6bsYGRPfEF3hq1X+0zzo5gwW09L1fH9uf6LpXThEmKgOrEO6svffp75+IQu5JJ4dYk3QzMXwEYtsfYpSJjwOWp1RQfS9VQ8OiyKJcFatfmCaPVuSfvThV9JVNV1xUbLFxnGT7P6+9CatxFjsfZopHAyuV3wxKxHx0RxflKS0+fQn+Qv6VcY38ulA+bHTXbxw7mz68A== 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=+2Cpf03ijBTQMum1kFbRQc13/tGU/Zo1ftvlQgxELvw=; b=WXEkeqxmwGTxDX6GfAIVad1oA0XKZCJXrLdy9h41v7wnTdR/9mDw0bjx5JBTcSPtc8klEPGlocFB3jT17hy1Ze1fLsbezujr5c984yBvbemvonCuXkC65umY5Yw8X4Kt55Cg42Ac7bL61fMeHEqoYuyq3Dg4Y00VBED63KPy1uxe1qIWp3w0z55bc+EsvySZ9ioeLv3kONvnxpUYy0OGsAonpRK2sFjjlI3aJHMe2SaX/R8cK8Atlgv+sL3AuGaJ3++D1A5WqVjYA1X6IY810ZpQ/4uYvvfXuJJK/XEptGKD1++bDnHVYDHclSvNy+2T8LqbHXKVjHD0hRFVUQ82tQ== 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=+2Cpf03ijBTQMum1kFbRQc13/tGU/Zo1ftvlQgxELvw=; b=th0FT/lBHgYGW0qtUaxQ0k80+8+FAHlMYxpkjFAxzjZ/On0RomG6Sd3CxV/HLObunOBjbYT33TBokoVvv2afbEEM3ipt2fKoROHnkWWVoqWZ3hGqcYkZIQNJufOxUWkcxtEB5ckptNuwQx0v1o8gVTCebGvjhm32GyKUvceBxOLYz3N8dnbRNcPc8AdtAvJIWcIUhMx0cOHJeibeFEJlg2mtZ6JfDRDPIL0aDLp22nXBmsqseiVof5bVbxCHTG/foJsUSdQDW2BikgAJZkAU6auWbgHN2zYVB+X0SoQiuc7oXE/KPCy4nEB44GKIh6ndbyqQGSfbXIByrp7eL21YQQ== Received: from MW4PR02CA0005.namprd02.prod.outlook.com (2603:10b6:303:16d::14) by MW3PR12MB4396.namprd12.prod.outlook.com (2603:10b6:303:59::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.42; Mon, 31 Jul 2023 10:26:04 +0000 Received: from CO1NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::a2) by MW4PR02CA0005.outlook.office365.com (2603:10b6:303:16d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Mon, 31 Jul 2023 10:26:04 +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 CO1NAM11FT023.mail.protection.outlook.com (10.13.175.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Mon, 31 Jul 2023 10:26:04 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Mon, 31 Jul 2023 03:25:46 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 31 Jul 2023 03:25:46 -0700 Received: from vdi.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 31 Jul 2023 03:25:43 -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 v2 6/6] vfio/migration: Allow migration of multiple P2P supporting devices Date: Mon, 31 Jul 2023 13:25:21 +0300 Message-ID: <20230731102521.15335-7-avihaih@nvidia.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230731102521.15335-1-avihaih@nvidia.com> References: <20230731102521.15335-1-avihaih@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT023:EE_|MW3PR12MB4396:EE_ X-MS-Office365-Filtering-Correlation-Id: 121ec098-408e-4a70-9437-08db91b08b7a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IzVBQ9yZq9BY3c6m+M/RA54E4T6l/MoiDzZDQgztYSoMfXvUAuYzpt2pdaciG/Ig/UgIlkC64Mimu81F/f7T5OvL9AtvFHLPFcBUcupOYE0eaLQ4XoHeQaL2GFD2U53kB7GO5OARzaeovSzuFfnOZ9hCViR2L+uZL2VboOmQ0D23BrbeTZ5KymTAXFFwdMP26xAEhfswCQ9LzPfCTRhXfAdMySxDyOGpct9lWVbQ6PvNWVnuxSHJ8sp/GhcySJhN7eccs0HAWnf5+CYokuVvROKiXjDK9muWU3FYXp/cP7ZQO6VBk3PCA7ThuIz62kZE0A8/bagvDPpzraa0rXZYaBgsV41L3gY86IRVunvypZcfctL68gkgUuI4Lgj6PSBosFcbwt3U6PeirutzFIcnlELA67xctolaT1HAIUDRHrHGF6S8mm1D+94cx045F1Gsqkrdo9RJkcvIqfBENDhdjlw2pkfM3/Qy0DWblXgZHr44/hgg5i1Z+x2sqgpE19CUY/xR27lHY2MKc+tNQrTU4TIhk7r/AGVus23Z5Dj5SH0OpxBGkH05A5IMzRQzdQiRvD+PE4PKlOTIS7Qw7XgWP3XgwNYYRMQTsSy2Sgco0dL0+8mbCpSEPHtqELyJJ4A2zHgLNDEdqpKT8km7TCHLlyWZKpMC8W/bw8QTWymUJf172t0hmPn18euHkIQ9vDlDgdQxnBvyNLT853NX4qgiQU17SdZmLF1KneCkew64I6g= 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)(82310400008)(451199021)(40470700004)(46966006)(36840700001)(82740400003)(356005)(7636003)(40480700001)(86362001)(36756003)(40460700003)(6666004)(478600001)(7696005)(2616005)(107886003)(186003)(336012)(26005)(1076003)(8936002)(8676002)(5660300002)(70586007)(70206006)(54906003)(2906002)(41300700001)(6916009)(4326008)(316002)(36860700001)(83380400001)(426003)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 10:26:04.1832 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 121ec098-408e-4a70-9437-08db91b08b7a 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: CO1NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4396 Received-SPF: softfail client-ip=2a01:111:f400:7e88::60a; envelope-from=avihaih@nvidia.com; helo=NAM10-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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 Reviewed-by: Cédric Le Goater --- 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..8a8d074e18 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_multiple_devices_migration_is_supported(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_multiple_devices_migration_is_supported()) { 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_multiple_devices_migration_is_supported()) { return; }