From nobody Fri Sep 5 22:27:10 2025 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=1658854616; cv=none; d=zohomail.com; s=zohoarc; b=lOjzcBQrdemjIoqNfatmYdyeVIpX6wNgGhnPDxvcH1CkzCZ6AecYUUVVXuzM0kOJM31OO8nwiClTMzVhQfB7RTFYfn6++x41wfrU0JcprLN/9qkIGC25NMZ66gkqRvX5s32SAjwXot27pA2phDbXKhhR8cmyPTTf9LAREoKfXho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658854616; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=eLKl1cpF1HINsl2amArCE04tfWdJ8MGhRXFnI18REuc=; b=eCBSVriq3nuxM5yksJXoijK76AN5MAU0PLXVOAwoUnNgf75+3uShPDCkOYK6r3ArFNzLwPwYU6uaU4pjJ+XcaTS9LsePJPtPgoMR0ZPl6vVrU1UpcgawyG89CJI7b26ds5EZ4d7T4zK4pf7RyVv/8CyhFeJwYD4aHNpDdmaLLmw= 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 1658854616889909.6670397937984; Tue, 26 Jul 2022 09:56:56 -0700 (PDT) Received: from localhost ([::1]:40284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGNrX-0000kj-JV for importer@patchew.org; Tue, 26 Jul 2022 12:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGN9z-0003EW-PL for qemu-devel@nongnu.org; Tue, 26 Jul 2022 12:11:52 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:61180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGN9x-0006Fx-MP for qemu-devel@nongnu.org; Tue, 26 Jul 2022 12:11:51 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26QFniXO026856; Tue, 26 Jul 2022 16:11:37 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 3hg9anxn19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jul 2022 16:11:37 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 26QF2X5D006282; Tue, 26 Jul 2022 16:11:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3hh65bq2hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jul 2022 16:11:36 +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 26QG5uTJ023334; Tue, 26 Jul 2022 16:11:35 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 3hh65bq0y5-36; Tue, 26 Jul 2022 16:11:35 +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-2022-7-12; bh=eLKl1cpF1HINsl2amArCE04tfWdJ8MGhRXFnI18REuc=; b=C/QXjZeljkE/jwPlpaENjZPaaq5cLCWy7+kOK1B6+BVbAnAW6sqnROQVWePmBgK5kzoL 5oEKxay8e93u2diSIu84iOHv7Qe9UeMSERlJhHxBNPDneIq6iizcBv6jdx3cm09V11zz qVb62wdaNsdeiLibq+XMUcV30zU1BkzkRimktsblGwfR/OQ/l6nTxiPgRkYVe2/la4Lv Evr75rDLB3raZ7rQSu8On1r0zOHnCLPTBiCNUVyIUNHXy1pJ0FWrmAObQsIkIHETMpDv rvk0Ku6GlrKiX5+HbcjU3Fo9LsJJTCJZS6dQSqgtyGt56+qYRpEZI8eKs0TGJhgvdviQ WQ== From: Steve Sistare To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Dr. David Alan Gilbert" , "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , "Daniel P. Berrange" , Juan Quintela , Markus Armbruster , Eric Blake , Jason Zeng , Zheng Chuan , Steve Sistare , Mark Kanda , Guoyi Tu , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Igor Mammedov , David Hildenbrand , John Snow , Peng Liang Subject: [PATCH V9 35/46] vhost: reset vhost devices for cpr Date: Tue, 26 Jul 2022 09:10:32 -0700 Message-Id: <1658851843-236870-36-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1658851843-236870-1-git-send-email-steven.sistare@oracle.com> References: <1658851843-236870-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207260063 X-Proofpoint-ORIG-GUID: l93yUVNPZ_MdLw2yJr2agaT1Z0htXhZa X-Proofpoint-GUID: l93yUVNPZ_MdLw2yJr2agaT1Z0htXhZa 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.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1658854618646100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A vhost device is implicitly preserved across re-exec because its fd is not closed, and the value of the fd is specified on the command line for the new qemu to find. However, new qemu issues an VHOST_RESET_OWNER ioctl, which fails because the device already has an owner. To fix, reset the owner prior to exec. Signed-off-by: Mark Kanda Signed-off-by: Steve Sistare --- hw/virtio/vhost.c | 23 +++++++++++++++++++++++ include/hw/virtio/vhost.h | 1 + 2 files changed, 24 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 8d2a136..bc8df55 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -23,6 +23,7 @@ #include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "migration/misc.h" #include "migration/blocker.h" #include "migration/qemu-file-types.h" #include "sysemu/dma.h" @@ -1347,6 +1348,25 @@ static void vhost_virtqueue_cleanup(struct vhost_vir= tqueue *vq) } } =20 +static void vhost_cpr_exec_notifier(Notifier *notifier, void *data) +{ + MigrationState *s =3D data; + struct vhost_dev *dev; + int r; + + if (migrate_mode_of(s) =3D=3D MIG_MODE_CPR_EXEC) { + dev =3D container_of(notifier, struct vhost_dev, cpr_notifier); + if (migration_has_failed(s)) { + r =3D dev->vhost_ops->vhost_set_owner(dev); + } else { + r =3D dev->vhost_ops->vhost_reset_device(dev); + } + if (r < 0) { + VHOST_OPS_DEBUG(r, "vhost_reset_device failed"); + } + } +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) @@ -1356,6 +1376,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, =20 hdev->vdev =3D NULL; hdev->migration_blocker =3D NULL; + hdev->cpr_notifier.notify =3D NULL; =20 r =3D vhost_set_backend_type(hdev, backend_type); assert(r >=3D 0); @@ -1446,6 +1467,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, hdev->log_enabled =3D false; hdev->started =3D false; memory_listener_register(&hdev->memory_listener, &address_space_memory= ); + migration_add_notifier(&hdev->cpr_notifier, vhost_cpr_exec_notifier); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev= )) { @@ -1482,6 +1504,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev) QLIST_REMOVE(hdev, entry); } migrate_del_blocker(&hdev->migration_blocker); + migration_remove_notifier(&hdev->cpr_notifier); g_free(hdev->mem); g_free(hdev->mem_sections); if (hdev->vhost_ops) { diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index a346f23..a12c4e1 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -101,6 +101,7 @@ struct vhost_dev { QLIST_ENTRY(vhost_dev) entry; QLIST_HEAD(, vhost_iommu) iommu_list; IOMMUNotifier n; + Notifier cpr_notifier; const VhostDevConfigOps *config_ops; }; =20 --=20 1.8.3.1