From nobody Sat Sep 21 08:36:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1705071970; cv=none; d=zohomail.com; s=zohoarc; b=ClZdYNMygvOPWyJo2wjMv3Q9n+IcABggiozF6ezRNQopAFjZOB9hcj63tGQiwZSkQprvneJSLXfL/T0GWXMZfJ2XIFx6J6yQiaJKxcAHb3ysF/1rswIecfu3NIUu7LQdc4wk7nDS1iwMKBG5Jp9S5g+5d/4p/hK05cOGK4NSEuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705071970; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JrO5zkLOQduwIGEc35Uyhjw3dMfBotlqWvhxmQIuC0g=; b=bCOAsQiq3q+HSS1AHq2MqULgjO6fbalXoEtCcaKvfdGhcDlRdYYJQrrwC3ITPcMXlkbr+1fCgSgmWy5NPpjlxiQNXgMLFmIYSccQBX1W7bm1KMmdq3nN0v7u0ztKaik6xx/OqOQSQBUJY5MpVw05DQxHKJkkaEp477UoDGI0wxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705071970514941.5081949047955; Fri, 12 Jan 2024 07:06:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOJ6g-0001YM-02; Fri, 12 Jan 2024 10:06:02 -0500 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 1rOJ6B-00011D-Vc for qemu-devel@nongnu.org; Fri, 12 Jan 2024 10:05:32 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOJ65-0003cX-U4 for qemu-devel@nongnu.org; Fri, 12 Jan 2024 10:05:29 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40CEXrha024852; Fri, 12 Jan 2024 15:05:22 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vk68306fw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jan 2024 15:05:21 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40CDqvaP013971; Fri, 12 Jan 2024 15:05:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfurgd8ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Jan 2024 15:05:20 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40CF5BoS017833; Fri, 12 Jan 2024 15:05:19 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfurgd8k6-12; Fri, 12 Jan 2024 15:05:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=JrO5zkLOQduwIGEc35Uyhjw3dMfBotlqWvhxmQIuC0g=; b=m/ygl4ft2qwlwBfdTsT+DpD7+xnFF/xS3As+8bOioMm0fODW4Nu3yQpiTDfIOKtAlpxn 3ihpSu2Iuwqjq0lHx2FzHQYp37SFaLRXi/HfIu+VSdftBaPOGIY+D63o0rvzUvzqVfSh wFp8xMBFMoLJgkp+dBhrFWL3iI8QdDZJJHDBjI03faWlzbDIo4HA4iiiXq4CzPuF98R+ kuOA1n0Nu1iK9tQbKbxN0jVgx+UyeHD0MKXxCgMEIO5jEj4qMKV3asnyrLUeoDlHxtVM D4qynVaZG0iGt9/xN2b9DzbMPEQ8f7HWf9UQ4QL4/Oqb1TigtGhIU4WthDeeWv5yRJUG tg== From: Steve Sistare To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , "Michael S. Tsirkin" , Jason Wang , Alex Williamson , Cedric Le Goater , Gerd Hoffmann , Marc-Andre Lureau , David Hildenbrand , Steve Sistare Subject: [PATCH V2 11/11] vfio: allow cpr-reboot migration if suspended Date: Fri, 12 Jan 2024 07:05:10 -0800 Message-Id: <1705071910-174321-12-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1705071910-174321-1-git-send-email-steven.sistare@oracle.com> References: <1705071910-174321-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-12_06,2024-01-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401120117 X-Proofpoint-GUID: 2Mqs_0vYqCf0b63VTBRAg1ji1r6xIooT X-Proofpoint-ORIG-GUID: 2Mqs_0vYqCf0b63VTBRAg1ji1r6xIooT Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.177.32; envelope-from=steven.sistare@oracle.com; helo=mx0b-00069f02.pphosted.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_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1705071971228100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allow cpr-reboot for vfio if the guest is in the suspended runstate. The guest drivers' suspend methods flush outstanding requests and re-initialize the devices, and thus there is no device state to save and restore. The user is responsible for suspending the guest before initiating cpr, such as by issuing guest-suspend-ram to the qemu guest agent. Relax the vfio blocker so it does not apply to cpr, and add a notifier that verifies the guest is suspended. Skip dirty page tracking, which is N/A for cpr, to avoid ioctl errors. Signed-off-by: Steve Sistare --- hw/vfio/common.c | 2 +- hw/vfio/cpr.c | 20 ++++++++++++++++++++ hw/vfio/migration.c | 2 +- include/hw/vfio/vfio-common.h | 1 + migration/ram.c | 9 +++++---- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3352f..09af934 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -128,7 +128,7 @@ int vfio_block_multiple_devices_migration(VFIODevice *v= basedev, Error **errp) error_setg(&multiple_devices_migration_blocker, "Multiple VFIO devices migration is supported only if all o= f " "them support P2P migration"); - ret =3D migrate_add_blocker(&multiple_devices_migration_blocker, errp); + ret =3D migrate_add_blocker_normal(&multiple_devices_migration_blocker= , errp); =20 return ret; } diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index bbd1c7a..9f4b1fe 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -7,13 +7,33 @@ =20 #include "qemu/osdep.h" #include "hw/vfio/vfio-common.h" +#include "migration/misc.h" #include "qapi/error.h" +#include "sysemu/runstate.h" + +static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, + MigrationEvent *e, Error **errp) +{ + if (e->state =3D=3D MIGRATION_STATUS_SETUP && + !runstate_check(RUN_STATE_SUSPENDED)) { + + error_setg(errp, + "VFIO device only supports cpr-reboot for runstate suspended"); + + return -1; + } + return 0; +} =20 int vfio_cpr_register_container(VFIOContainer *container, Error **errp) { + migration_add_notifier_mode(&container->cpr_reboot_notifier, + vfio_cpr_reboot_notifier, + MIG_MODE_CPR_REBOOT); return 0; } =20 void vfio_cpr_unregister_container(VFIOContainer *container) { + migration_remove_notifier(&container->cpr_reboot_notifier); } diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 534fddf..488905d 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -895,7 +895,7 @@ static int vfio_block_migration(VFIODevice *vbasedev, E= rror *err, Error **errp) vbasedev->migration_blocker =3D error_copy(err); error_free(err); =20 - return migrate_add_blocker(&vbasedev->migration_blocker, errp); + return migrate_add_blocker_normal(&vbasedev->migration_blocker, errp); } =20 /* ---------------------------------------------------------------------- = */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 1add5b7..7a46e24 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -78,6 +78,7 @@ struct VFIOGroup; typedef struct VFIOContainer { VFIOContainerBase bcontainer; int fd; /* /dev/vfio/vfio, empowered by the attached groups */ + NotifierWithReturn cpr_reboot_notifier; unsigned iommu_type; QLIST_HEAD(, VFIOGroup) group_list; } VFIOContainer; diff --git a/migration/ram.c b/migration/ram.c index 1923366..44ad324 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2392,8 +2392,8 @@ static void ram_save_cleanup(void *opaque) RAMState **rsp =3D opaque; RAMBlock *block; =20 - /* We don't use dirty log with background snapshots */ - if (!migrate_background_snapshot()) { + /* We don't use dirty log with background snapshots or cpr */ + if (!migrate_background_snapshot() && migrate_mode() =3D=3D MIG_MODE_N= ORMAL) { /* caller have hold BQL or is in a bh, so there is * no writing race against the migration bitmap */ @@ -2804,8 +2804,9 @@ static void ram_init_bitmaps(RAMState *rs) =20 WITH_RCU_READ_LOCK_GUARD() { ram_list_init_bitmaps(); - /* We don't use dirty log with background snapshots */ - if (!migrate_background_snapshot()) { + /* We don't use dirty log with background snapshots or cpr */ + if (!migrate_background_snapshot() && + migrate_mode() =3D=3D MIG_MODE_NORMAL) { memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); migration_bitmap_sync_precopy(rs, false); } --=20 1.8.3.1