From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618766; cv=none; d=zohomail.com; s=zohoarc; b=lnoHvaHNnb+iS+3mThBFpoBHM7lwwTwGicGkd48hH6jETEHhzCWLljWLqBv97IrIUi+cnlbtg/UIxG6+KXiZmL9T9Xk05i7UyOu4JRdZvg3Bf8AVv7DQsXKqQ5E3xeAeLD1NirrqjgmdNn3KuBXBRcFNopzo8lGp/WVPvHzmfl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618766; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=utna8TUZqlkP0I+rP/itsdNPDMa+AnrDKQbi4gVo8Qw=; b=WdN1njwlDMKA4Ft/ZR5mmpvLG8/Ktp+UTyLCQ8Tzlwl8o61loNoiyvtzuXwaiGL2vFUGZWES+Hq5dNMde6CqqG2gozXBRZJdzimT7n2wpm3Dbtb5oex4lgmUtrNfWlza4nCg+FGKLRq4eUSv8ve2Y2KCCVCEyj/4OkMmH5Us+/s= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618766190688.8416739032021; Fri, 4 Jul 2025 01:46:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3J-0007ew-Lu; Fri, 04 Jul 2025 04:45:49 -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 1uXc3D-0007cE-Va for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3A-0008G3-W1 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:42 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-SL_6ggJiOfCfYYNA_4861w-1; Fri, 04 Jul 2025 04:45:36 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B36F819373D8; Fri, 4 Jul 2025 08:45:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 95C6719560A7; Fri, 4 Jul 2025 08:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=utna8TUZqlkP0I+rP/itsdNPDMa+AnrDKQbi4gVo8Qw=; b=CDAfe/82chmEyKZf5MiIPHPKTN7ju1rIAqp+7/UVwZZfFjCSp7RFZPFLseSZC1BRuJq9y7 i4bRsflx23Ec5rXitD9bNwf6Mr1DJzj11kq2r2NSM4/0iUy02FCMFm7bNytqYNWthVt2lb rGT7ZTHTtGQrgNQ6Iq3EwAVSO8zlCqA= X-MC-Unique: SL_6ggJiOfCfYYNA_4861w-1 X-Mimecast-MFC-AGG-ID: SL_6ggJiOfCfYYNA_4861w_1751618735 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Steven Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 01/27] vfio/container: Fix potential SIGSEGV when recover from unmap-all-vaddr failure Date: Fri, 4 Jul 2025 10:45:02 +0200 Message-ID: <20250704084528.1412959-2-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751618767563116600 From: Zhenzhong Duan CPR overrides then restores dma_map in both outgoing and incoming QEMU, for different reasons. But it only sets saved_dma_map in the target. Fix it by always setting saved_dma_map. Fixes: eba1f657cbb1 ("vfio/container: recover from unmap-all-vaddr failure") Suggested-by: Steven Sistare Signed-off-by: Zhenzhong Duan Reviewed-by: Steve Sistare Link: https://lore.kernel.org/qemu-devel/20250627063332.5173-2-zhenzhong.du= an@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/cpr-legacy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index a84c3247b7172a1f084659f2418d0c1e1394becf..0a5d1bd480ee510f4ab5fc95217= 0fba80a5f41c8 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -180,9 +180,9 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *= container, Error **errp) vmstate_register(NULL, -1, &vfio_container_vmstate, container); =20 /* During incoming CPR, divert calls to dma_map. */ + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + container->cpr.saved_dma_map =3D vioc->dma_map; if (cpr_is_incoming()) { - VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); - container->cpr.saved_dma_map =3D vioc->dma_map; vioc->dma_map =3D vfio_legacy_cpr_dma_map; } =20 --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618808; cv=none; d=zohomail.com; s=zohoarc; b=Ha45QUSiE/UBWIXuyS4IJDdPj5U6R3i66Dwj32gEZyLogXDs/a4+3wH9bqFVVcOLVFAgjjINnwLsy8wzf6kL5n1jeGnEp2ono9CD25zr0VaGwMZ73rUkgK9C80bQkcIWIG1gtWJOrGtPDvNYsjxvkt50zlqkKAr5YjOiUwhCBhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618808; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wE+XJ85jNc+dBoCJkszkYSjGdKErWQ60+oYEQW5oaSk=; b=JsCTNpS01QXHNb0XLtI8r0yYBtl/qB+2e03jydUG58jYWc1dDwvPzF89RuCCEImQ0xT4/IlAo14RAk9QFgfjVAMGowSWvlBzZDiNEAXROEGmex7Dhm2C1ZhiW3j1zE2FJ+dyX2z5x5I68sMKfmOt98JdOGFykCUSQhSR7LewcVc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618807949759.2116515366334; Fri, 4 Jul 2025 01:46:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3O-0007fl-NV; Fri, 04 Jul 2025 04:45:54 -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 1uXc3E-0007df-Eg for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3B-0008Ji-ND for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:43 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-jVGuzoVyPwiAoYYKfDnaAQ-1; Fri, 04 Jul 2025 04:45:39 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6C5E9180029E; Fri, 4 Jul 2025 08:45:38 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3F5BE19560A7; Fri, 4 Jul 2025 08:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wE+XJ85jNc+dBoCJkszkYSjGdKErWQ60+oYEQW5oaSk=; b=dR9X+QAJ1WzeF9ABK1rGhbdpmJ0J9n8m2/eaKJgDZsz0acnqgOHfudTb8HW/9CuNbfx0kM gCpLtBTkjVgtQaQkfRmT03uc5rAZn9AieoDG4DAeFzmOfGrlOVUGV8Zy2YXIpQtqbQZOFO yZLhKwq6sHfSlEQJm/P3iMo57a/qxxo= X-MC-Unique: jVGuzoVyPwiAoYYKfDnaAQ-1 X-Mimecast-MFC-AGG-ID: jVGuzoVyPwiAoYYKfDnaAQ_1751618738 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 02/27] vfio/container: Fix vfio_container_post_load() Date: Fri, 4 Jul 2025 10:45:03 +0200 Message-ID: <20250704084528.1412959-3-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618810772116600 From: Zhenzhong Duan When there are multiple VFIO containers, vioc->dma_map is restored multiple times, this made only first container work and remaining containers using vioc->dma_map restored by first container. Fix it by save and restore vioc->dma_map locally. saved_dma_map in VFIOContainerCPR becomes useless and is removed. Fixes: 7e9f21411302 ("vfio/container: restore DMA vaddr") Signed-off-by: Zhenzhong Duan Reviewed-by: Steve Sistare Link: https://lore.kernel.org/qemu-devel/20250627063332.5173-3-zhenzhong.du= an@intel.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 7 ++++--- hw/vfio/cpr-legacy.c | 23 +++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 8bf85b9f4ec2cd712ef835dc5d720fe03d767d03..dbb2a16b7a8174c15412a9297e0= beb3d274ab520 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -16,14 +16,15 @@ struct VFIOContainer; struct VFIOContainerBase; struct VFIOGroup; =20 +typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, void *vaddr, + bool readonly, MemoryRegion *mr); + typedef struct VFIOContainerCPR { Error *blocker; bool vaddr_unmapped; NotifierWithReturn transfer_notifier; MemoryListener remap_listener; - int (*saved_dma_map)(const struct VFIOContainerBase *bcontainer, - hwaddr iova, ram_addr_t size, - void *vaddr, bool readonly, MemoryRegion *mr); } VFIOContainerCPR; =20 typedef struct VFIODeviceCPR { diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index 0a5d1bd480ee510f4ab5fc952170fba80a5f41c8..1216717546ca13d6f33e802777a= a69ab4d59ecba 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -99,20 +99,21 @@ static int vfio_container_post_load(void *opaque, int v= ersion_id) { VFIOContainer *container =3D opaque; VFIOContainerBase *bcontainer =3D &container->bcontainer; - VFIOGroup *group; + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + dma_map_fn saved_dma_map =3D vioc->dma_map; Error *local_err =3D NULL; =20 + /* During incoming CPR, divert calls to dma_map. */ + vioc->dma_map =3D vfio_legacy_cpr_dma_map; + if (!vfio_listener_register(bcontainer, &local_err)) { error_report_err(local_err); return -1; } =20 - QLIST_FOREACH(group, &container->group_list, container_next) { - VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + /* Restore original dma_map function */ + vioc->dma_map =3D saved_dma_map; =20 - /* Restore original dma_map function */ - vioc->dma_map =3D container->cpr.saved_dma_map; - } return 0; } =20 @@ -148,6 +149,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *n= otifier, */ =20 VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + dma_map_fn saved_dma_map =3D vioc->dma_map; vioc->dma_map =3D vfio_legacy_cpr_dma_map; =20 container->cpr.remap_listener =3D (MemoryListener) { @@ -158,7 +160,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *n= otifier, bcontainer->space->as); memory_listener_unregister(&container->cpr.remap_listener); container->cpr.vaddr_unmapped =3D false; - vioc->dma_map =3D container->cpr.saved_dma_map; + vioc->dma_map =3D saved_dma_map; } return 0; } @@ -179,13 +181,6 @@ bool vfio_legacy_cpr_register_container(VFIOContainer = *container, Error **errp) =20 vmstate_register(NULL, -1, &vfio_container_vmstate, container); =20 - /* During incoming CPR, divert calls to dma_map. */ - VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); - container->cpr.saved_dma_map =3D vioc->dma_map; - if (cpr_is_incoming()) { - vioc->dma_map =3D vfio_legacy_cpr_dma_map; - } - migration_add_notifier_mode(&container->cpr.transfer_notifier, vfio_cpr_fail_notifier, MIG_MODE_CPR_TRANSFER); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619168; cv=none; d=zohomail.com; s=zohoarc; b=UwuX2UkfhGMAU5QX2K1JWPTGAIkZ/uMxZrqNeAAuIQVTcz5kKl2EqAkQLaUww78xufsVvNFsjn6zKPzRfLCkeV3wNw8WcVGufF0N3Dn0sgzP9rqtUCcBmuEb7PsoTpTdl5697qJgxywgzBf+Fa9ftTi2FyAX3ub70f3DqZE+q/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619168; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sHbHQj6VRcttbej+ZZ4LEoCSLkr2QRA4FGJU96qKoVM=; b=b/61rWr3xH+PMTcNh+tv0HRWA+EXvIaUXNsLzk7A4zOS5c40/VjlZ4gdSUw9KkYWYZylTRci9pgrx6FLvKnWo+dl5Y9lPBxf85BaZjo+uSvwyQyUbVTKwTpFGOwyZ8jYbgkDiGtmktE7du4SLE9S5q18hr7iDtNmFJJcBzrVbEA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619168568562.0621474926671; Fri, 4 Jul 2025 01:52:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3M-0007fB-Dx; Fri, 04 Jul 2025 04:45:52 -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 1uXc3H-0007eO-Da for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3E-0008Lj-JP for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:47 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-106-mJxEhRAkMzSoFOuPjCh-BA-1; Fri, 04 Jul 2025 04:45:41 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9DF611944A8D; Fri, 4 Jul 2025 08:45:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EAC0719560A7; Fri, 4 Jul 2025 08:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sHbHQj6VRcttbej+ZZ4LEoCSLkr2QRA4FGJU96qKoVM=; b=HqPjCFh10uY5be/RxjBlwk8JI8WTYV+7+WaAO5VL3xzAov5hKBBg831BJO466Y0awaUlIq BN6K4f8gKlTTKSc0XreOZbhxVnyduTyw+Afoj14Oo9Rjkhxs8QOUSEE2pCxM3hPNMNzuT8 kgEeqg80gRv2pyL7aGy0FQWH9d8PwGc= X-MC-Unique: mJxEhRAkMzSoFOuPjCh-BA-1 X-Mimecast-MFC-AGG-ID: mJxEhRAkMzSoFOuPjCh-BA_1751618740 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Mark Cave-Ayland , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 03/27] vfio-user: do not register vfio-user container with cpr Date: Fri, 4 Jul 2025 10:45:04 +0200 Message-ID: <20250704084528.1412959-4-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751619171098116600 From: Mark Cave-Ayland As the full cpr implementation is yet to be merged upstream, do not register the vfio-user container with cpr. Full vfio-user support for cpr can be merged later as a follow-up series. Signed-off-by: Mark Cave-Ayland Reviewed-by: C=C3=A9dric Le Goater Message-ID: <20250702120043.267634-1-mark.caveayland@nutanix.com> [ clg: Removed now useless "hw/vfio/vfio-cpr.h" include ] Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio-user/container.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c index 3133fef17738e14fc512ad5272bc349d928c980a..d318e6a3395e8d48e3a6da69ed4= bef454e70ba82 100644 --- a/hw/vfio-user/container.c +++ b/hw/vfio-user/container.c @@ -13,7 +13,6 @@ #include "hw/vfio-user/container.h" #include "hw/vfio-user/device.h" #include "hw/vfio-user/trace.h" -#include "hw/vfio/vfio-cpr.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-listener.h" #include "qapi/error.h" @@ -225,14 +224,10 @@ vfio_user_container_connect(AddressSpace *as, VFIODev= ice *vbasedev, =20 bcontainer =3D &container->bcontainer; =20 - if (!vfio_cpr_register_container(bcontainer, errp)) { - goto free_container_exit; - } - ret =3D ram_block_uncoordinated_discard_disable(true); if (ret) { error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken"= ); - goto unregister_container_exit; + goto free_container_exit; } =20 vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); @@ -261,9 +256,6 @@ listener_release_exit: enable_discards_exit: ram_block_uncoordinated_discard_disable(false); =20 -unregister_container_exit: - vfio_cpr_unregister_container(bcontainer); - free_container_exit: object_unref(container); =20 @@ -286,7 +278,6 @@ static void vfio_user_container_disconnect(VFIOUserCont= ainer *container) vioc->release(bcontainer); } =20 - vfio_cpr_unregister_container(bcontainer); object_unref(container); =20 vfio_address_space_put(space); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619080; cv=none; d=zohomail.com; s=zohoarc; b=fWBt6MICQqu3a4C8Fmq1z5LQLYWFBkGMLKx6CZ0QElQajbiT/Nq5BTFbUyH/UUyMWtlkW4FZ4EWi/BJW3rRNd6KkdWQUwuhbmveI1lL4oECk+CcPVFMQcsZ0tooTlRfeWou9dyEIrs4pLYX+YjXXu+svW1Eme8odLHpc5r3IR9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619080; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4GZAali6jdpwdwPi2/Qouns2mwgNx4BybaUJktpftio=; b=PmXVn2VTRzniEEukEYkKcIdM5+/4Q4BAlk8rhnayT5FYfOAzxnyKxaH5CGaWnWqX+8RSEDqIBS78+MyPA+Wapr20jlrxl4NfJ2MVSabrsSUF6NSBQOXD5S+2GJQtAd8+mEWSvNA5bSNK+6fd3vK9BOG/0ed31BNprobs1S5sKOA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619080291982.5256754318427; Fri, 4 Jul 2025 01:51:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3c-0007kz-8C; Fri, 04 Jul 2025 04:46:08 -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 1uXc3L-0007fA-E6 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3J-0008UM-GY for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:50 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-AOnfORCmPaSc8iFDVZafrg-1; Fri, 04 Jul 2025 04:45:45 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85F4E1956096; Fri, 4 Jul 2025 08:45:44 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 26A76195E74A; Fri, 4 Jul 2025 08:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4GZAali6jdpwdwPi2/Qouns2mwgNx4BybaUJktpftio=; b=IHvlnXm5PplczwXvGw9X4mwmVEs7gd8ybQ9TfSXRjeLKJaYfKY+so5CVN4YIQB77jkurKx KmaFnfr+E+ZbSJgmaONy+6seF3+Cl10sQXgWUDWCQI0oQIeFtf77LHHGWqlBO5bTkS8kac 1ZUKsnS5lOQgC97NVQBJBbVr4nahqUI= X-MC-Unique: AOnfORCmPaSc8iFDVZafrg-1 X-Mimecast-MFC-AGG-ID: AOnfORCmPaSc8iFDVZafrg_1751618744 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Xiaoyao Li , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhao Liu Subject: [PULL 04/27] i386/tdx: Build TDX only for 64-bit target Date: Fri, 4 Jul 2025 10:45:05 +0200 Message-ID: <20250704084528.1412959-5-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751619082293116600 From: Xiaoyao Li Build errors related to TDX were reported when QEMU built on 32-bit host[1][2]. Since TDX cannot work on 32-bit host and it's also not worth supporting TDX with 32-bit QEMU, limit TDX to 64-bit target only. [1] https://lore.kernel.org/qemu-devel/20250602173101.1052983-1-clg@redhat.= com/ [2] https://lore.kernel.org/qemu-devel/b8171c39-6a92-4078-a59a-a63d7452e1e9= @kaod.org/ Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Xiaoyao Li Reviewed-by: Zhao Liu Tested-by: C=C3=A9dric Le Goater Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250625073310.2796298-1-xiaoyao.l= i@intel.com Signed-off-by: C=C3=A9dric Le Goater --- hw/i386/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index eb65bda6e071f907722143847804c4149cd9613d..14d23e27b580b2d5ea3aa4c07ba= 066f21a62e348 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -13,7 +13,7 @@ config SGX config TDX bool select X86_FW_OVMF - depends on KVM + depends on KVM && X86_64 =20 config PC bool --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618881; cv=none; d=zohomail.com; s=zohoarc; b=e6B+c78viuOXqrpI2zWndDXBoFp9k7yekoydO7vUCemld4u0+M7l5qFAqK71pAf11/AwqHIhFnrHhA+VnLCcPANFlWniClNnm8XL6yDW0VRx4C3rmG625cQmo9x5Af3lXUB6f5xftYmgPLsgp7To9bmsYYOoHwrDUiBoT8TAPU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618881; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HJupBfJ20LYtHzmzBW/M1PjMcCcMFvlC5aq9CPTQ+jg=; b=REhQXuRY1hIZyKW8usuLdcphZc5LB+3mCA+gmipt8tTae+NlAsgymz8yvObGs6UuRzh1WwBmSg+0BLFbEujQ3RDMH/wC1c9Q6xGupEUZl5CNexIO7CqISf6Shdwa8DXcmiXOc3+IFMe7uL2QwvO2PMprheeuD2oioVj868D9Jp4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618881528629.4961093191606; Fri, 4 Jul 2025 01:48:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3X-0007h7-6f; Fri, 04 Jul 2025 04:46:03 -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 1uXc3N-0007fm-KU for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3M-00007o-01 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:53 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-zEDr_iL1MVGti1rQGhDUhg-1; Fri, 04 Jul 2025 04:45:48 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E3BE180034E; Fri, 4 Jul 2025 08:45:47 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F0A419560A7; Fri, 4 Jul 2025 08:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HJupBfJ20LYtHzmzBW/M1PjMcCcMFvlC5aq9CPTQ+jg=; b=PNbdYyd6CQhcXnv0PbY+cE4Yx03u0SBZYs2l8Qno2VSCc+5/bBN43lEYGJfYq4T6uwwX9B FrXFBJftSt9q5L2ES3jp79cstGCKxyCvHRX4Syiv44iEXxFg1uwvhY4aBDERQr3lC+y+M8 ZVipcXGZTVHf5LHWVLtrAOf/n7sjQro= X-MC-Unique: zEDr_iL1MVGti1rQGhDUhg-1 X-Mimecast-MFC-AGG-ID: zEDr_iL1MVGti1rQGhDUhg_1751618747 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang Subject: [PULL 05/27] b4: Drop linktrailermask Date: Fri, 4 Jul 2025 10:45:06 +0200 Message-ID: <20250704084528.1412959-6-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618883586116600 When grabbing a patch series, the link trailer is replaced with a Message-ID, which is not useful compared to an URL. Fix that by dropping the linktrailermask config. Cc: Philippe Mathieu-Daud=C3=A9 Cc: Jiaxun Yang Fixes: 838cf72b5d2c ("Add a b4 configuration file") Link: https://lore.kernel.org/qemu-devel/20250630172301.519848-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater --- .b4-config | 1 - 1 file changed, 1 deletion(-) diff --git a/.b4-config b/.b4-config index 4b9b2fe290f92f784cd3229616e2cbf0e8550e02..126f503ded743473a3218bcbedf= 0721942b58585 100644 --- a/.b4-config +++ b/.b4-config @@ -11,4 +11,3 @@ prep-perpatch-check-cmd =3D scripts/checkpatch.pl -q --terse --no-summ= ary --mailback - searchmask =3D https://lore.kernel.org/qemu-devel/?x=3Dm&t=3D1&q=3D%s linkmask =3D https://lore.kernel.org/qemu-devel/%s - linktrailermask =3D Message-ID: <%s> --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618808; cv=none; d=zohomail.com; s=zohoarc; b=D4Wf9S9xItIfCE6im3p1oxHVWefN5XNw4NQRh5bCFZsPG1II/9hXNTMkfiEGfcL14fPx06BNv+BavfS06k5Ykgn3pu2JfTpIDafOGwmdSy7AHE/GHI/b+sbFzKcbsvjywVnBZAX9Qy2LL9HL6HBYLwDNTXw/Up5zbBtFpR55IKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618808; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=msW017fzKYg1BzekObA96QwL6ot5xfmZJnekxiLRO+A=; b=WDpwM3Y04E/fPS0wDInm7qfpp6VIOIUMhkRncrcmqfAaZc0arfYtmRdJEqrRdzuncocEEruj1gQaV6MeDK0NaM1I2ACg3yA2NO9tX8T1PK99voXtx6OED/DX3fLSH/HWI7wTjfaYTS9V6IIDym9DPAIG1fjha/Go7L3AaczI10A= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618808049850.13360376826; Fri, 4 Jul 2025 01:46:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3X-0007hD-82; Fri, 04 Jul 2025 04:46:03 -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 1uXc3Q-0007gO-K0 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3P-0000Ay-1q for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:56 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-36-OrHf_FUPOxSG8S09UoKPdA-1; Fri, 04 Jul 2025 04:45:50 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C774D1809C81 for ; Fri, 4 Jul 2025 08:45:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB0C819560A7; Fri, 4 Jul 2025 08:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=msW017fzKYg1BzekObA96QwL6ot5xfmZJnekxiLRO+A=; b=b7OGnFqKtVsxmM79GGxR6YrB8EMgzAJyz5rtb9wJH0Bofp2PsOB0+KR4zFkxJJwika9lSA LyraxGkjZTZYptQ/jqs6taa04cWh1x3U4ArL6PQ8S0i2toab/7y1DSvZh0l8G1j385VoFn spf9cjf0BOFU8WxOu9aNR5NqQ3aqVn0= X-MC-Unique: OrHf_FUPOxSG8S09UoKPdA-1 X-Mimecast-MFC-AGG-ID: OrHf_FUPOxSG8S09UoKPdA_1751618749 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 06/27] Makefile: prune quilt source files for cscope Date: Fri, 4 Jul 2025 10:45:07 +0200 Message-ID: <20250704084528.1412959-7-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618808659116600 Both quilt, to apply patches, and cscope, to navigate in the code, are useful tools. Make sure source files that quilt saves when applying patches are not taken into account when building the cscope database. Link: https://lore.kernel.org/qemu-devel/20250630172048.519182-1-clg@redhat= .com Signed-off-by: C=C3=A9dric Le Goater --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c92a3cf7857a51dbda71bf6b4bbe35564e8fc67f..74c2da2037203d812c7a4207434= 3b043af5322e4 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ distclean: clean recurse-distclean rm -Rf .sdk qemu-bundle =20 find-src-path =3D find "$(SRC_PATH)" -path "$(SRC_PATH)/meson" -prune -o \ + -path "$(SRC_PATH)/.pc" -prune -o \ -type l -prune -o \( -name "*.[chsS]" -o -name "*.[ch].inc" \) =20 .PHONY: ctags --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619080; cv=none; d=zohomail.com; s=zohoarc; b=EsV5wyRNOwxBkavmhl8MCiBfy4YNptrpxOxeV6807IAwdalIw2VucJ2x4ScwacCYQyQCixxdbie2LfmNEfVHEOvMSXVrNOEnLDkv36HrlG5AimbugMLUsxV4Te3+KuAjfEyWTnb0whWHFBtKwVAgPFsRFllIoPRmtJ2oWZOsfzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619080; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0jmKYEXW/S0Z39ORxlWOomJ49IWOiCtqxFymROBfA0I=; b=Htxpd7qKTdO4+XySl92FqF6YXhhkQkbSbdQVOM6fL7Uv2gb4vitLiHU8fo50sp2M0yCcdEaZZID8TXJrGOB/c4PYCtEDpW4rbvS71b5XynZGP4xYzTK6KiGNIk/OvxAjwBYe3iamFGWtlxvgRKYB+5BNdoyknCL7GaSylArQQXY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619080267223.65187174122207; Fri, 4 Jul 2025 01:51:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3a-0007hl-Jg; Fri, 04 Jul 2025 04:46:06 -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 1uXc3T-0007gz-1F for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3Q-0000F7-L8 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:45:58 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-258-7PiWimIfM7e_eSs6x1QjGg-1; Fri, 04 Jul 2025 04:45:53 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2057718011FE; Fri, 4 Jul 2025 08:45:52 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5664019560A7; Fri, 4 Jul 2025 08:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0jmKYEXW/S0Z39ORxlWOomJ49IWOiCtqxFymROBfA0I=; b=dKjwPIdCRF8QSIUAB2vgrKoymfpglwGmZVMYL4hOEWo2P5Nz1j4Pon6Qyo+tBCJlyMTmR7 aFF1+EsLSfF94ODQ5F2OET9PRY9LObaukuY4WoQA3OvhBskFXUl/4x9QGfcMh1ZlT0/xVV l6CnKD+U97ZLxCKMU/Rmqmg0NakCWjw= X-MC-Unique: 7PiWimIfM7e_eSs6x1QjGg-1 X-Mimecast-MFC-AGG-ID: 7PiWimIfM7e_eSs6x1QjGg_1751618752 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 07/27] vfio-pci: preserve MSI Date: Fri, 4 Jul 2025 10:45:08 +0200 Message-ID: <20250704084528.1412959-8-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619086727116600 From: Steve Sistare Save the MSI message area as part of vfio-pci vmstate, and preserve the interrupt and notifier eventfd's. migrate_incoming loads the MSI data, then the vfio-pci post_load handler finds the eventfds in CPR state, rebuilds vector data structures, and attaches the interrupts to the new KVM instance. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1751493538-202042-2-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 2 + include/hw/vfio/vfio-cpr.h | 8 ++++ hw/vfio/cpr.c | 97 ++++++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 52 +++++++++++++++++++- 4 files changed, 157 insertions(+), 2 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 5ba7330b27e80d1a565da2704689e48fa9bece18..495fae737d3a2e455e1cc04e062= b9860196899be 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -218,6 +218,8 @@ void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFI= OMSIVector *vector, void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev); void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev); bool vfio_pci_intx_enable(VFIOPCIDevice *vdev, Error **errp); +void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev); +void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr); =20 uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); void vfio_pci_write_config(PCIDevice *pdev, diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index dbb2a16b7a8174c15412a9297e0beb3d274ab520..f21578da3cb3611e04260f458e7= 7aca6f48036fe 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -15,6 +15,7 @@ struct VFIOContainer; struct VFIOContainerBase; struct VFIOGroup; +struct VFIOPCIDevice; =20 typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, @@ -53,6 +54,13 @@ void vfio_cpr_giommu_remap(struct VFIOContainerBase *bco= ntainer, bool vfio_cpr_ram_discard_register_listener( struct VFIOContainerBase *bcontainer, MemoryRegionSection *section); =20 +void vfio_cpr_save_vector_fd(struct VFIOPCIDevice *vdev, const char *name, + int nr, int fd); +int vfio_cpr_load_vector_fd(struct VFIOPCIDevice *vdev, const char *name, + int nr); +void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *nam= e, + int nr); + extern const VMStateDescription vfio_cpr_pci_vmstate; =20 #endif /* HW_VFIO_VFIO_CPR_H */ diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index fdbb58e2039e9fc6bd91c37a0f534522c0987680..e467373e8d17abc80fb627e8bd5= 12824d7f322ab 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -9,6 +9,8 @@ #include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-cpr.h" #include "hw/vfio/pci.h" +#include "hw/pci/msix.h" +#include "hw/pci/msi.h" #include "migration/cpr.h" #include "qapi/error.h" #include "system/runstate.h" @@ -40,6 +42,69 @@ void vfio_cpr_unregister_container(VFIOContainerBase *bc= ontainer) migration_remove_notifier(&bcontainer->cpr_reboot_notifier); } =20 +#define STRDUP_VECTOR_FD_NAME(vdev, name) \ + g_strdup_printf("%s_%s", (vdev)->vbasedev.name, (name)) + +void vfio_cpr_save_vector_fd(VFIOPCIDevice *vdev, const char *name, int nr, + int fd) +{ + g_autofree char *fdname =3D STRDUP_VECTOR_FD_NAME(vdev, name); + cpr_save_fd(fdname, nr, fd); +} + +int vfio_cpr_load_vector_fd(VFIOPCIDevice *vdev, const char *name, int nr) +{ + g_autofree char *fdname =3D STRDUP_VECTOR_FD_NAME(vdev, name); + return cpr_find_fd(fdname, nr); +} + +void vfio_cpr_delete_vector_fd(VFIOPCIDevice *vdev, const char *name, int = nr) +{ + g_autofree char *fdname =3D STRDUP_VECTOR_FD_NAME(vdev, name); + cpr_delete_fd(fdname, nr); +} + +static void vfio_cpr_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors, + bool msix) +{ + int i, fd; + bool pending =3D false; + PCIDevice *pdev =3D &vdev->pdev; + + vdev->nr_vectors =3D nr_vectors; + vdev->msi_vectors =3D g_new0(VFIOMSIVector, nr_vectors); + vdev->interrupt =3D msix ? VFIO_INT_MSIX : VFIO_INT_MSI; + + vfio_pci_prepare_kvm_msi_virq_batch(vdev); + + for (i =3D 0; i < nr_vectors; i++) { + VFIOMSIVector *vector =3D &vdev->msi_vectors[i]; + + fd =3D vfio_cpr_load_vector_fd(vdev, "interrupt", i); + if (fd >=3D 0) { + vfio_pci_vector_init(vdev, i); + vfio_pci_msi_set_handler(vdev, i); + } + + if (vfio_cpr_load_vector_fd(vdev, "kvm_interrupt", i) >=3D 0) { + vfio_pci_add_kvm_msi_virq(vdev, vector, i, msix); + } else { + vdev->msi_vectors[i].virq =3D -1; + } + + if (msix && msix_is_pending(pdev, i) && msix_is_masked(pdev, i)) { + set_bit(i, vdev->msix->pending); + pending =3D true; + } + } + + vfio_pci_commit_kvm_msi_virq_batch(vdev); + + if (msix) { + memory_region_set_enabled(&pdev->msix_pba_mmio, pending); + } +} + /* * The kernel may change non-emulated config bits. Exclude them from the * changed-bits check in get_pci_config_device. @@ -58,13 +123,45 @@ static int vfio_cpr_pci_pre_load(void *opaque) return 0; } =20 +static int vfio_cpr_pci_post_load(void *opaque, int version_id) +{ + VFIOPCIDevice *vdev =3D opaque; + PCIDevice *pdev =3D &vdev->pdev; + int nr_vectors; + + if (msix_enabled(pdev)) { + vfio_pci_msix_set_notifiers(vdev); + nr_vectors =3D vdev->msix->entries; + vfio_cpr_claim_vectors(vdev, nr_vectors, true); + + } else if (msi_enabled(pdev)) { + nr_vectors =3D msi_nr_vectors_allocated(pdev); + vfio_cpr_claim_vectors(vdev, nr_vectors, false); + + } else if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) { + g_assert_not_reached(); /* completed in a subsequent patch */ + } + + return 0; +} + +static bool pci_msix_present(void *opaque, int version_id) +{ + PCIDevice *pdev =3D opaque; + + return msix_present(pdev); +} + const VMStateDescription vfio_cpr_pci_vmstate =3D { .name =3D "vfio-cpr-pci", .version_id =3D 0, .minimum_version_id =3D 0, .pre_load =3D vfio_cpr_pci_pre_load, + .post_load =3D vfio_cpr_pci_post_load, .needed =3D cpr_incoming_needed, .fields =3D (VMStateField[]) { + VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice), + VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, pci_msix_present), VMSTATE_END_OF_LIST() } }; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index fa25bded25c51f8efb6c5ad31bd90506cd69745c..5f9f2640e5aaeca2ef26e505666= 4a979fc5c842c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -29,6 +29,7 @@ #include "hw/pci/pci_bridge.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" +#include "hw/vfio/vfio-cpr.h" #include "migration/vmstate.h" #include "migration/cpr.h" #include "qobject/qdict.h" @@ -57,20 +58,33 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev= ); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); static void vfio_msi_disable_common(VFIOPCIDevice *vdev); =20 +/* Create new or reuse existing eventfd */ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, const char *name, int nr, Error **errp) { - int ret =3D event_notifier_init(e, 0); + int fd, ret; =20 + fd =3D vfio_cpr_load_vector_fd(vdev, name, nr); + if (fd >=3D 0) { + event_notifier_init_fd(e, fd); + return true; + } + + ret =3D event_notifier_init(e, 0); if (ret) { error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name); + return false; } - return !ret; + + fd =3D event_notifier_get_fd(e); + vfio_cpr_save_vector_fd(vdev, name, nr, fd); + return true; } =20 static void vfio_notifier_cleanup(VFIOPCIDevice *vdev, EventNotifier *e, const char *name, int nr) { + vfio_cpr_delete_vector_fd(vdev, name, nr); event_notifier_cleanup(e); } =20 @@ -394,6 +408,14 @@ static void vfio_msi_interrupt(void *opaque) notify(&vdev->pdev, nr); } =20 +void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr) +{ + VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; + int fd =3D event_notifier_get_fd(&vector->interrupt); + + qemu_set_fd_handler(fd, vfio_msi_interrupt, NULL, vector); +} + /* * Get MSI-X enabled, but no vector enabled, by setting vector 0 with an i= nvalid * fd to kernel. @@ -656,6 +678,15 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, un= signed int nr, static int vfio_msix_vector_use(PCIDevice *pdev, unsigned int nr, MSIMessage msg) { + /* + * Ignore the callback from msix_set_vector_notifiers during resume. + * The necessary subset of these actions is called from + * vfio_cpr_claim_vectors during post load. + */ + if (cpr_is_incoming()) { + return 0; + } + return vfio_msix_vector_do_use(pdev, nr, &msg, vfio_msi_interrupt); } =20 @@ -686,6 +717,12 @@ static void vfio_msix_vector_release(PCIDevice *pdev, = unsigned int nr) } } =20 +void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev) +{ + msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, + vfio_msix_vector_release, NULL); +} + void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev) { assert(!vdev->defer_kvm_irq_routing); @@ -2965,6 +3002,11 @@ void vfio_pci_register_err_notifier(VFIOPCIDevice *v= dev) fd =3D event_notifier_get_fd(&vdev->err_notifier); qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); =20 + /* Do not alter irq_signaling during vfio_realize for cpr */ + if (cpr_is_incoming()) { + return; + } + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_I= NDEX, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); @@ -3032,6 +3074,12 @@ void vfio_pci_register_req_notifier(VFIOPCIDevice *v= dev) fd =3D event_notifier_get_fd(&vdev->req_notifier); qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); =20 + /* Do not alter irq_signaling during vfio_realize for cpr */ + if (cpr_is_incoming()) { + vdev->req_enabled =3D true; + return; + } + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_I= NDEX, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619089; cv=none; d=zohomail.com; s=zohoarc; b=CTOUvz5VxywLbCOPM6LBTvcFjHLUmPekTpIkq6ZbVA+VvDuL7d0z4TlQxam0R+im8+52Qrh3ft3HT4wt68sfoVbYlItV5skmWDKlfxjCjzR/MgWn4WaL3X8Kb145z1AYFbxAUxAly3ZszQ2gvacKrXRxFEamDSfGkndf/0PptQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619089; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4OBpe/6J4zCOQSdUBlq9XBrD/jdeXQVwxK0cWryWLSA=; b=ewcrkJKriNn6Lc4TLrfu26P0KNmWV6t0vplB2DPTNdr4f4QHuBTaWITZrFVCmv6M4kIV/rR8PoqnPfoqGOz6tOuiZLVMXLg3ONBVCKMsuHvRCzlMkSWc/1ewsZBlFb+3YbEMremUNQElMJQdJQCurk3LnxVnXK6RitzYaEZgXZY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175161908905177.91384211916022; Fri, 4 Jul 2025 01:51:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3c-0007l7-BT; Fri, 04 Jul 2025 04:46:08 -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 1uXc3W-0007hE-FV for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3T-0000Fu-H9 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:02 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-KqkNclA3NtKMjp8iG6pHrA-1; Fri, 04 Jul 2025 04:45:55 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AA9A1800268; Fri, 4 Jul 2025 08:45:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8000619560A7; Fri, 4 Jul 2025 08:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4OBpe/6J4zCOQSdUBlq9XBrD/jdeXQVwxK0cWryWLSA=; b=Lt52InNYnil1CdcH/Rf7I8ozHo4TUiv8DvgNj8u1ngua4aUqaKvL237rTe8707agJaf+HV SYs6hhyHC1dzNmE0Hc8YVAkgOfzVEPUqUm8TgfppR5Q7U8r4aAD+77BjNMoeidXmkypA7V lDLPZV3PaASOr8KDsbWfd3vHMQYAYRA= X-MC-Unique: KqkNclA3NtKMjp8iG6pHrA-1 X-Mimecast-MFC-AGG-ID: KqkNclA3NtKMjp8iG6pHrA_1751618754 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 08/27] vfio-pci: preserve INTx Date: Fri, 4 Jul 2025 10:45:09 +0200 Message-ID: <20250704084528.1412959-9-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619090394116600 From: Steve Sistare Preserve vfio INTx state across cpr-transfer. Preserve VFIOINTx fields as follows: pin : Recover this from the vfio config in kernel space interrupt : Preserve its eventfd descriptor across exec. unmask : Ditto route.irq : This could perhaps be recovered in vfio_pci_post_load by calling pci_device_route_intx_to_irq(pin), whose implementation reads config space for a bridge device such as ich9. However, there is no guarantee that the bridge vmstate is read before vfio vmstate. Rather than fiddling with MigrationPriority for vmstate handlers, explicitly save route.irq in vfio vmstate. pending : save in vfio vmstate. mmap_timeout, mmap_timer : Re-initialize bool kvm_accel : Re-initialize In vfio_realize, defer calling vfio_intx_enable until the vmstate is available, in vfio_pci_post_load. Modify vfio_intx_enable and vfio_intx_kvm_enable to skip vfio initialization, but still perform kvm initialization. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1751493538-202042-3-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/cpr.c | 27 ++++++++++++++++++++++++- hw/vfio/pci.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index e467373e8d17abc80fb627e8bd512824d7f322ab..f5555cabe72a817c000a1359bc7= fd318c6aff4c1 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -139,7 +139,11 @@ static int vfio_cpr_pci_post_load(void *opaque, int ve= rsion_id) vfio_cpr_claim_vectors(vdev, nr_vectors, false); =20 } else if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) { - g_assert_not_reached(); /* completed in a subsequent patch */ + Error *local_err =3D NULL; + if (!vfio_pci_intx_enable(vdev, &local_err)) { + error_report_err(local_err); + return -1; + } } =20 return 0; @@ -152,6 +156,26 @@ static bool pci_msix_present(void *opaque, int version= _id) return msix_present(pdev); } =20 +static const VMStateDescription vfio_intx_vmstate =3D { + .name =3D "vfio-cpr-intx", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(pending, VFIOINTx), + VMSTATE_UINT32(route.mode, VFIOINTx), + VMSTATE_INT32(route.irq, VFIOINTx), + VMSTATE_END_OF_LIST() + } +}; + +#define VMSTATE_VFIO_INTX(_field, _state) { \ + .name =3D (stringify(_field)), \ + .size =3D sizeof(VFIOINTx), \ + .vmsd =3D &vfio_intx_vmstate, \ + .flags =3D VMS_STRUCT, \ + .offset =3D vmstate_offset_value(_state, _field, VFIOINTx), \ +} + const VMStateDescription vfio_cpr_pci_vmstate =3D { .name =3D "vfio-cpr-pci", .version_id =3D 0, @@ -162,6 +186,7 @@ const VMStateDescription vfio_cpr_pci_vmstate =3D { .fields =3D (VMStateField[]) { VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice), VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, pci_msix_present), + VMSTATE_VFIO_INTX(intx, VFIOPCIDevice), VMSTATE_END_OF_LIST() } }; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5f9f2640e5aaeca2ef26e5056664a979fc5c842c..dd0b2a0b947d4f9c788c6cd8b41= e8ac916098724 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -210,6 +210,36 @@ fail: #endif } =20 +static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) +{ +#ifdef CONFIG_KVM + if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || + vdev->intx.route.mode !=3D PCI_INTX_ENABLED || + !kvm_resamplefds_enabled()) { + return true; + } + + if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, er= rp)) { + return false; + } + + if (kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, + &vdev->intx.interrupt, + &vdev->intx.unmask, + vdev->intx.route.irq)) { + error_setg_errno(errp, errno, "failed to setup resample irqfd"); + vfio_notifier_cleanup(vdev, &vdev->intx.unmask, "intx-unmask", 0); + return false; + } + + vdev->intx.kvm_accel =3D true; + trace_vfio_intx_enable_kvm(vdev->vbasedev.name); + return true; +#else + return true; +#endif +} + static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) { #ifdef CONFIG_KVM @@ -305,7 +335,13 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Erro= r **errp) return true; } =20 - vfio_disable_interrupts(vdev); + /* + * Do not alter interrupt state during vfio_realize and cpr load. + * The incoming state is cleared thereafter. + */ + if (!cpr_is_incoming()) { + vfio_disable_interrupts(vdev); + } =20 vdev->intx.pin =3D pin - 1; /* Pin A (1) -> irq[0] */ pci_config_set_interrupt_pin(vdev->pdev.config, pin); @@ -328,6 +364,14 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Erro= r **errp) fd =3D event_notifier_get_fd(&vdev->intx.interrupt); qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev); =20 + + if (cpr_is_incoming()) { + if (!vfio_cpr_intx_enable_kvm(vdev, &err)) { + warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); + } + goto skip_signaling; + } + if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_= INDEX, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vdev); @@ -339,6 +383,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 +skip_signaling: vdev->interrupt =3D VFIO_INT_INTx; =20 trace_vfio_intx_enable(vdev->vbasedev.name); @@ -3237,7 +3282,13 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, E= rror **errp) vfio_intx_routing_notifier); vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); - if (!vfio_intx_enable(vdev, errp)) { + + /* + * During CPR, do not call vfio_intx_enable at this time. Instead, + * call it from vfio_pci_post_load after the intx routing data has + * been loaded from vmstate. + */ + if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) { timer_free(vdev->intx.mmap_timer); pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notif= ier); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618838; cv=none; d=zohomail.com; s=zohoarc; b=fdflsCiV/WkjMcrB1GnumM8fTnxwIpQ0B/9lhFCA9IwEbToXHfdgiM7jhSoivxoFScTr9MQU6iRcxO+wGphlIrRDsinRJed0Ftc9y1BnQFUumR+RXsEvPJr8tqFzLQwWLZU8WF4Teg9c78pNXy8Cke9T2qM/I5jaEQIrhdApZ0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618838; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XTQINngnlTpKUr4ol5peoe6ICu1vlPCG0vUoKUmVS0g=; b=FuLUITeqNaQPhmWXvck7I9sbfkGL++Rmjf3O8R24n0hV/yHdiy0xbGYHebQJuAJqiuSiqRj/sZr6T7dlrQX2C5UcPV6iP7HBzBgkhnZ30wvUbsPKt0M8s83QHD1B0pINI28F19c8iwF0IqNIJR5evK1J9HjM2sEBOoUla9QNuUM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618838848223.33327453020115; Fri, 4 Jul 2025 01:47:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3e-0007mP-MD; Fri, 04 Jul 2025 04:46:10 -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 1uXc3X-0007hN-3o for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3V-0000GG-83 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:02 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-n6rQRszkPsy0OWhNLYBjGQ-1; Fri, 04 Jul 2025 04:45:58 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5D5F31955ECF; Fri, 4 Jul 2025 08:45:57 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D807419560A7; Fri, 4 Jul 2025 08:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XTQINngnlTpKUr4ol5peoe6ICu1vlPCG0vUoKUmVS0g=; b=EFvBquZBRCs7Hyq3o4d0unoe4KTnjKxdB8B3gUWI8b/HFp0IcAHg+4d4FfJv0QbQZGcCRK VrJt7tJbgmcSnHcBSZSgeYw49hGcZh1jlx1ri/c0zxpqyJ3kognGf2vNPRB7sJ4n3G0rS+ rYxvL7yq58RtVX3vptwQhvuduIREIlw= X-MC-Unique: n6rQRszkPsy0OWhNLYBjGQ-1 X-Mimecast-MFC-AGG-ID: n6rQRszkPsy0OWhNLYBjGQ_1751618757 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Paolo Bonzini , Fabiano Rosas , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 09/27] migration: close kvm after cpr Date: Fri, 4 Jul 2025 10:45:10 +0200 Message-ID: <20250704084528.1412959-10-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751618841223116600 From: Steve Sistare cpr-transfer breaks vfio network connectivity to and from the guest, and the host system log shows: irq bypass consumer (token 00000000a03c32e5) registration fails: -16 which is EBUSY. This occurs because KVM descriptors are still open in the old QEMU process. Close them. Cc: Paolo Bonzini Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/qemu-devel/1751493538-202042-4-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 2 ++ include/hw/vfio/vfio-device.h | 2 ++ include/system/kvm.h | 1 + accel/kvm/kvm-all.c | 32 ++++++++++++++++++++++++++++++++ hw/vfio/cpr-legacy.c | 2 ++ hw/vfio/cpr.c | 21 +++++++++++++++++++++ hw/vfio/helpers.c | 11 +++++++++++ 7 files changed, 71 insertions(+) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index f21578da3cb3611e04260f458e77aca6f48036fe..d37acc4a0a0ae1f6f38d8322fb9= 681227221fd09 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -63,4 +63,6 @@ void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev= , const char *name, =20 extern const VMStateDescription vfio_cpr_pci_vmstate; =20 +void vfio_cpr_add_kvm_notifier(void); + #endif /* HW_VFIO_VFIO_CPR_H */ diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index c616652ee72265c637cb5136fdffb4444639e0b7..f503837ccc6936b730a7752ca09= 2da5acba1806f 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -283,4 +283,6 @@ void vfio_device_set_fd(VFIODevice *vbasedev, const cha= r *str, Error **errp); void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, DeviceState *dev, bool ram_discard); int vfio_device_get_aw_bits(VFIODevice *vdev); + +void vfio_kvm_device_close(void); #endif /* HW_VFIO_VFIO_COMMON_H */ diff --git a/include/system/kvm.h b/include/system/kvm.h index 7cc60d26f24a48fc107d80683710939679e8e98b..4896a3c9c59e90bb0bea35407fa= 969884f6920ec 100644 --- a/include/system/kvm.h +++ b/include/system/kvm.h @@ -195,6 +195,7 @@ bool kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void); int kvm_max_nested_state_length(void); int kvm_has_gsi_routing(void); +void kvm_close(void); =20 /** * kvm_arm_supports_user_irq diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d095d1b98f8685f865cf7b49c6f02b80f6cb011b..81418546177c8eb99932900902c= d3890f45c02bb 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -515,16 +515,23 @@ static int do_kvm_destroy_vcpu(CPUState *cpu) goto err; } =20 + /* If I am the CPU that created coalesced_mmio_ring, then discard it */ + if (s->coalesced_mmio_ring =3D=3D (void *)cpu->kvm_run + PAGE_SIZE) { + s->coalesced_mmio_ring =3D NULL; + } + ret =3D munmap(cpu->kvm_run, mmap_size); if (ret < 0) { goto err; } + cpu->kvm_run =3D NULL; =20 if (cpu->kvm_dirty_gfns) { ret =3D munmap(cpu->kvm_dirty_gfns, s->kvm_dirty_ring_bytes); if (ret < 0) { goto err; } + cpu->kvm_dirty_gfns =3D NULL; } =20 kvm_park_vcpu(cpu); @@ -608,6 +615,31 @@ err: return ret; } =20 +void kvm_close(void) +{ + CPUState *cpu; + + if (!kvm_state || kvm_state->fd =3D=3D -1) { + return; + } + + CPU_FOREACH(cpu) { + cpu_remove_sync(cpu); + close(cpu->kvm_fd); + cpu->kvm_fd =3D -1; + close(cpu->kvm_vcpu_stats_fd); + cpu->kvm_vcpu_stats_fd =3D -1; + } + + if (kvm_state && kvm_state->fd !=3D -1) { + close(kvm_state->vmfd); + kvm_state->vmfd =3D -1; + close(kvm_state->fd); + kvm_state->fd =3D -1; + } + kvm_state =3D NULL; +} + /* * dirty pages logging control */ diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index 1216717546ca13d6f33e802777aa69ab4d59ecba..553b203e9b60b3a08159e2224a8= 87b4d76162428 100644 --- a/hw/vfio/cpr-legacy.c +++ b/hw/vfio/cpr-legacy.c @@ -179,6 +179,8 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *= container, Error **errp) MIG_MODE_CPR_TRANSFER, -1) =3D=3D= 0; } =20 + vfio_cpr_add_kvm_notifier(); + vmstate_register(NULL, -1, &vfio_container_vmstate, container); =20 migration_add_notifier_mode(&container->cpr.transfer_notifier, diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index f5555cabe72a817c000a1359bc7fd318c6aff4c1..0e903cdd2f7071a363eecd4ec87= 84b6f9c8f7e1d 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -190,3 +190,24 @@ const VMStateDescription vfio_cpr_pci_vmstate =3D { VMSTATE_END_OF_LIST() } }; + +static NotifierWithReturn kvm_close_notifier; + +static int vfio_cpr_kvm_close_notifier(NotifierWithReturn *notifier, + MigrationEvent *e, + Error **errp) +{ + if (e->type =3D=3D MIG_EVENT_PRECOPY_DONE) { + vfio_kvm_device_close(); + } + return 0; +} + +void vfio_cpr_add_kvm_notifier(void) +{ + if (!kvm_close_notifier.notify) { + migration_add_notifier_mode(&kvm_close_notifier, + vfio_cpr_kvm_close_notifier, + MIG_MODE_CPR_TRANSFER); + } +} diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index d0dbab1d17132743ea5f5ed0f25701436be11945..9a5f62154554e1df36545b8c315= b9ae25534d0fb 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -117,6 +117,17 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_i= nfo *info, int vfio_kvm_device_fd =3D -1; #endif =20 +void vfio_kvm_device_close(void) +{ +#ifdef CONFIG_KVM + kvm_close(); + if (vfio_kvm_device_fd !=3D -1) { + close(vfio_kvm_device_fd); + vfio_kvm_device_fd =3D -1; + } +#endif +} + int vfio_kvm_device_add_fd(int fd, Error **errp) { #ifdef CONFIG_KVM --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618886; cv=none; d=zohomail.com; s=zohoarc; b=MdCK1Z5tAA0sOhQWGaRawPgkpnIzxquj4tsNIPql+iqw6aQpIZXqrrwrsLnyrfBAk1YJiXNmWeoMTKFV3U3iJFTUnXVsu1c9LaaZvU8L850WMix3pS33l5C+OqZgBRR62vKzCSVl+P4Rbff9EwkLQkEXG3YNy1rulk1n2QlvQZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618886; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QCmQhzgK8imggIgqcbYivoAqw0X5+C7YbCCtSUdop2w=; b=drWm00n76IILBiNxSH7pf3m2YhxQbu7FygLkUx652yqdkn6i04oC7dua9vtVJ3/KoLu0TytVtA2EqvK+CnL6yzMxGt69xzQoIyH298l9Rax6Bu3ikFexueI5MKTzUTMivZz33QiVn4ftQSy3ZYtpOi606fVs3g9JQiTCRlMgNZI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618886591600.0328943159668; Fri, 4 Jul 2025 01:48:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3f-0007ms-Co; Fri, 04 Jul 2025 04:46:11 -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 1uXc3a-0007jl-Mv for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3Y-0000I5-VG for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:06 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-W9q-DJeUP3uIcqk2AnJuXQ-1; Fri, 04 Jul 2025 04:46:01 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0C0C01809C82; Fri, 4 Jul 2025 08:46:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E2E5A19560A7; Fri, 4 Jul 2025 08:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QCmQhzgK8imggIgqcbYivoAqw0X5+C7YbCCtSUdop2w=; b=Y4YERoVChFd7Te7jQax4U7/s2we2oYcI7lP9HtJD4hQAoC00Lcv0wGeRMP0Or0LLAxli6G 2oSL7qT2FwKcOtPOHbA3AizHmofVF3afFx7sOhOYTXocaH6BCP4ZGz/nyEx0fcZ9loUxMi Vjvn+E29J6QmJOe3pip5QvSG59lb7kc= X-MC-Unique: W9q-DJeUP3uIcqk2AnJuXQ-1 X-Mimecast-MFC-AGG-ID: W9q-DJeUP3uIcqk2AnJuXQ_1751618760 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Fabiano Rosas , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 10/27] migration: cpr_get_fd_param helper Date: Fri, 4 Jul 2025 10:45:11 +0200 Message-ID: <20250704084528.1412959-11-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618887657116600 From: Steve Sistare Add the helper function cpr_get_fd_param, to use when preserving a file descriptor that is opened externally and passed to QEMU. cpr_get_fd_param returns a descriptor number either from a QEMU command-line parameter, from a getfd command, or from CPR state. When a descriptor is passed to new QEMU via SCM_RIGHTS, its number changes. Hence, during CPR, the command-line parameter is ignored in new QEMU, and over-ridden by the value found in CPR state. Similarly, if the descriptor was originally specified by a getfd command in old QEMU, the fd number is not known outside of QEMU, and it changes when sent to new QEMU via SCM_RIGHTS. Hence the user cannot send getfd to new QEMU, but when the user sends a hotplug command that references the fd, cpr_get_fd_param finds its value in CPR state. Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/qemu-devel/1751493538-202042-5-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/migration/cpr.h | 2 ++ migration/cpr.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 07858e93fa2fbd9ca0c31af218216025c14369a6..eb27a933017a09c480029a50cd6= b1457e69cec8a 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -32,6 +32,8 @@ void cpr_state_close(void); struct QIOChannel *cpr_state_ioc(void); =20 bool cpr_incoming_needed(void *opaque); +int cpr_get_fd_param(const char *name, const char *fdname, int index, + Error **errp); =20 QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp); QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp); diff --git a/migration/cpr.c b/migration/cpr.c index a50a57edca754b50e68fa9c294b3c89791e62ba8..535d587aee16d2411d20ee549f8= e3cf5a4120a88 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -13,6 +13,7 @@ #include "migration/qemu-file.h" #include "migration/savevm.h" #include "migration/vmstate.h" +#include "monitor/monitor.h" #include "system/runstate.h" #include "trace.h" =20 @@ -264,3 +265,39 @@ bool cpr_incoming_needed(void *opaque) MigMode mode =3D migrate_mode(); return mode =3D=3D MIG_MODE_CPR_TRANSFER; } + +/* + * cpr_get_fd_param: find a descriptor and return its value. + * + * @name: CPR name for the descriptor + * @fdname: An integer-valued string, or a name passed to a getfd command + * @index: CPR index of the descriptor + * @errp: returned error message + * + * If CPR is not being performed, then use @fdname to find the fd. + * If CPR is being performed, then ignore @fdname, and look for @name + * and @index in CPR state. + * + * On success returns the fd value, else returns -1. + */ +int cpr_get_fd_param(const char *name, const char *fdname, int index, + Error **errp) +{ + ERRP_GUARD(); + int fd; + + if (cpr_is_incoming()) { + fd =3D cpr_find_fd(name, index); + if (fd < 0) { + error_setg(errp, "cannot find saved value for fd %s", fdname); + } + } else { + fd =3D monitor_fd_param(monitor_cur(), fdname, errp); + if (fd >=3D 0) { + cpr_save_fd(name, index, fd); + } else { + error_prepend(errp, "Could not parse object fd %s:", fdname); + } + } + return fd; +} --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619155; cv=none; d=zohomail.com; s=zohoarc; b=d/gKWUsNBWpipl7JBX9ZceeNziWXVbU/nApvlhqXW2pt1h604DWmBF+TVilEAEtW0s3pfrG/oOw//tQBtBLn0vWHxTcYx7TtsY+8WxaOl58EwhZNP4qGpbETjhA9amTweGCEzn2n0cu/wsO5FT+Kj6N+FGWCe7OckxGBangdg7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619155; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zx1lHk/zQUeP69xjueEudIIzPShaicyzWk4zw3oQOF8=; b=Fpv77qipOgUxvEXNRduUTlPS2zG1Ct1gBP990Zuz3OMYGqI9BElU0MKLkVpjrIc2pmzxc6Oc5yNIGe9ZEnfXogpOlEfN1vtOJ6KmrTcg3c520jQ12w1qopkJmgyZr9vA7OuLR+mzpUqNfnjfJzZv1Xev4OstfE48WgKqJd5inbM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619155468461.87053489998095; Fri, 4 Jul 2025 01:52:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3g-0007my-3y; Fri, 04 Jul 2025 04:46:12 -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 1uXc3d-0007mG-U1 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3b-0000Mp-SP for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:09 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-OpF9TVNEO3CUfUO4Jsj0qA-1; Fri, 04 Jul 2025 04:46:04 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 118BC180047F; Fri, 4 Jul 2025 08:46:03 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E19519560A7; Fri, 4 Jul 2025 08:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zx1lHk/zQUeP69xjueEudIIzPShaicyzWk4zw3oQOF8=; b=T3+jk4o8U5xXltUUoWDA12qUCr+3vl+OzsOam2dgqZL0KR8GB+UULrIiaKUHrFWo3KFG6L VeouSgYXGnRYi3dMPiCr0WDW4DHELhWqOXAuK9xQM+VM+hLOIPqvEHRuLhgJ8rllel/ZNa 5IncKq+MkB4jEqUAhrcT+4o7+lHNOgg= X-MC-Unique: OpF9TVNEO3CUfUO4Jsj0qA-1 X-Mimecast-MFC-AGG-ID: OpF9TVNEO3CUfUO4Jsj0qA_1751618763 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 11/27] backends/iommufd: iommufd_backend_map_file_dma Date: Fri, 4 Jul 2025 10:45:12 +0200 Message-ID: <20250704084528.1412959-12-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619157043116600 From: Steve Sistare Define iommufd_backend_map_file_dma to implement IOMMU_IOAS_MAP_FILE. This will be called as a substitute for iommufd_backend_map_dma, so the error conditions for BARs are copied as-is from that function. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-6-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/system/iommufd.h | 3 +++ backends/iommufd.c | 34 ++++++++++++++++++++++++++++++++++ backends/trace-events | 1 + 3 files changed, 38 insertions(+) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 283861b92432a1297e3e7465bdf86c3816393dcc..2d24d93d17e280bce53030a5258= 8bd91425e03ea 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -43,6 +43,9 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be); bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, Error **errp); void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); +int iommufd_backend_map_file_dma(IOMMUFDBackend *be, uint32_t ioas_id, + hwaddr iova, ram_addr_t size, int fd, + unsigned long start, bool readonly); int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr i= ova, ram_addr_t size, void *vaddr, bool readonly); int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, diff --git a/backends/iommufd.c b/backends/iommufd.c index c2c47abf7ed533c0512b89e58605b6b20ac103e8..3a2ecc7f5ba67699249ae1ad632= fc8a45e9b53d3 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -172,6 +172,40 @@ int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32= _t ioas_id, hwaddr iova, return ret; } =20 +int iommufd_backend_map_file_dma(IOMMUFDBackend *be, uint32_t ioas_id, + hwaddr iova, ram_addr_t size, + int mfd, unsigned long start, bool readon= ly) +{ + int ret, fd =3D be->fd; + struct iommu_ioas_map_file map =3D { + .size =3D sizeof(map), + .flags =3D IOMMU_IOAS_MAP_READABLE | + IOMMU_IOAS_MAP_FIXED_IOVA, + .ioas_id =3D ioas_id, + .fd =3D mfd, + .start =3D start, + .iova =3D iova, + .length =3D size, + }; + + if (!readonly) { + map.flags |=3D IOMMU_IOAS_MAP_WRITEABLE; + } + + ret =3D ioctl(fd, IOMMU_IOAS_MAP_FILE, &map); + trace_iommufd_backend_map_file_dma(fd, ioas_id, iova, size, mfd, start, + readonly, ret); + if (ret) { + ret =3D -errno; + + /* TODO: Not support mapping hardware PCI BAR region for now. */ + if (errno =3D=3D EFAULT) { + warn_report("IOMMU_IOAS_MAP_FILE failed: %m, PCI BAR?"); + } + } + return ret; +} + int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, ram_addr_t size) { diff --git a/backends/trace-events b/backends/trace-events index 7278214ea51144b7d7b36d64908567c9467036e8..e5f3e70cd1ba7eb532c8f763b12= 460ef8f552245 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -11,6 +11,7 @@ iommufd_backend_connect(int fd, bool owned, uint32_t user= s) "fd=3D%d owned=3D%d user iommufd_backend_disconnect(int fd, uint32_t users) "fd=3D%d users=3D%d" iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=3D%d" iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_= t size, void *vaddr, bool readonly, int ret) " iommufd=3D%d ioas=3D%d iova= =3D0x%"PRIx64" size=3D0x%"PRIx64" addr=3D%p readonly=3D%d (%d)" +iommufd_backend_map_file_dma(int iommufd, uint32_t ioas, uint64_t iova, ui= nt64_t size, int fd, unsigned long start, bool readonly, int ret) " iommufd= =3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" fd=3D%d start=3D%ld r= eadonly=3D%d (%d)" iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t i= ova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=3D%d ioas= =3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" (%d)" iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint6= 4_t size, int ret) " iommufd=3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"P= RIx64" (%d)" iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=3D%d ioas= =3D%d" --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619087; cv=none; d=zohomail.com; s=zohoarc; b=AImE9CkQrF3mcc+vUMPRlRFEyDazVvXO/doD+avdtDu6w6iZN0YioXyir7pMsX1tMKOiF9XglFlulJUOX6UTbKUMpwiOrO3ZQ3+Eu+/CkjBksUM3tYnMIwtE/pyOJBKEf/Kh8q18xGw8XRWaSs+nFcVW88WWIm4x3svRRxSPNxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619087; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=u7HynSMK05b6lBlM28Uo8t4bq96JVAh38/zQHg3D6aM=; b=CueqLCYXgTNeeHwkgDGDIL2Hb9dFHNKucq+KIiNmQ2loFXxPZM4Fqk9K00SdwBAov1UZhse3Ds3M7k3/VBzk6tmqgzjsZUFLTBqNjE02m8yVxw0qXpIpyniGk29muE0OQ110+QBAy2zobcG5DCpYXVhPCIigvGNwlsPiEWQyzU8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619087331999.961245465358; Fri, 4 Jul 2025 01:51:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3o-0007tY-3k; Fri, 04 Jul 2025 04:46:20 -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 1uXc3i-0007pU-1f for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3f-0000SX-5W for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:12 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-WjtOCcv8OyS-Jp8NqkQkQg-1; Fri, 04 Jul 2025 04:46:06 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BEA2918002EC; Fri, 4 Jul 2025 08:46:05 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 900AB195E752; Fri, 4 Jul 2025 08:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u7HynSMK05b6lBlM28Uo8t4bq96JVAh38/zQHg3D6aM=; b=cehiYIAD/u2v4Cec4A6k43hbjtGwwyR/tKvQxJzEedUMKh0ZBJ3oV9WDF042AeHuziwHy3 QGw2Bl300SF+d0gjtUu1XS3Xdtd+/KexHvGfodErVghftpW8PTT7putl5V24vpLvSkEkO+ DH6pgagjyEU58KLJPuV4TyxGMvThL90= X-MC-Unique: WjtOCcv8OyS-Jp8NqkQkQg-1 X-Mimecast-MFC-AGG-ID: WjtOCcv8OyS-Jp8NqkQkQg_1751618765 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 12/27] backends/iommufd: change process ioctl Date: Fri, 4 Jul 2025 10:45:13 +0200 Message-ID: <20250704084528.1412959-13-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619088317116600 From: Steve Sistare Define the change process ioctl Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-7-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/system/iommufd.h | 3 +++ backends/iommufd.c | 24 ++++++++++++++++++++++++ backends/trace-events | 1 + 3 files changed, 28 insertions(+) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 2d24d93d17e280bce53030a52588bd91425e03ea..db5f2c716c5be6cd1313045ab6d= d28eb1f8356f3 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -69,6 +69,9 @@ bool iommufd_backend_invalidate_cache(IOMMUFDBackend *be,= uint32_t id, uint32_t *entry_num, void *data, Error **errp); =20 +bool iommufd_change_process_capable(IOMMUFDBackend *be); +bool iommufd_change_process(IOMMUFDBackend *be, Error **errp); + #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" OBJECT_DECLARE_TYPE(HostIOMMUDeviceIOMMUFD, HostIOMMUDeviceIOMMUFDClass, HOST_IOMMU_DEVICE_IOMMUFD) diff --git a/backends/iommufd.c b/backends/iommufd.c index 3a2ecc7f5ba67699249ae1ad632fc8a45e9b53d3..87f81a05f6465cabc5673745f95= 947db2bb4a4fb 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -73,6 +73,30 @@ static void iommufd_backend_class_init(ObjectClass *oc, = const void *data) object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); } =20 +bool iommufd_change_process_capable(IOMMUFDBackend *be) +{ + struct iommu_ioas_change_process args =3D {.size =3D sizeof(args)}; + + /* + * Call IOMMU_IOAS_CHANGE_PROCESS to verify it is a recognized ioctl. + * This is a no-op if the process has not changed since DMA was mapped. + */ + return !ioctl(be->fd, IOMMU_IOAS_CHANGE_PROCESS, &args); +} + +bool iommufd_change_process(IOMMUFDBackend *be, Error **errp) +{ + struct iommu_ioas_change_process args =3D {.size =3D sizeof(args)}; + bool ret =3D !ioctl(be->fd, IOMMU_IOAS_CHANGE_PROCESS, &args); + + if (!ret) { + error_setg_errno(errp, errno, "IOMMU_IOAS_CHANGE_PROCESS fd %d fai= led", + be->fd); + } + trace_iommufd_change_process(be->fd, ret); + return ret; +} + bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) { int fd; diff --git a/backends/trace-events b/backends/trace-events index e5f3e70cd1ba7eb532c8f763b12460ef8f552245..56132d3fd22b5a217b07349c74f= 17e50d553a799 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -7,6 +7,7 @@ dbus_vmstate_loading(const char *id) "id: %s" dbus_vmstate_saving(const char *id) "id: %s" =20 # iommufd.c +iommufd_change_process(int fd, bool ret) "fd=3D%d (%d)" iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=3D%d owned= =3D%d users=3D%d" iommufd_backend_disconnect(int fd, uint32_t users) "fd=3D%d users=3D%d" iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=3D%d" --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618917; cv=none; d=zohomail.com; s=zohoarc; b=h2qzmZjVNcTKxAb9MWHR9LClayccJ3mF69pVVes2CglURx4a0kIOX4rfDaF+ozlFyUiln8gOnKIzP8i0egpmBK+XbKiboTx/fllNECPYufS6Ips18ktFoqnCHaMvGTnHjt2PP+OtP3yQqotQKbLvTbTE+I4IeDK913pBYwCbAA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618917; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ulbI3NpOKSsNZ8nhES+eA9VoPutBs8AfUXJ+hy3Y7UI=; b=Wibl/E0d5CHtQiKLNvibUF9jcS2+b/LZXPeP4v9xnkg75iNREBStETifwI5R8zcfHagCoo3YsdMWfhQYpQUqSrV+JOSrR07D5ROfnYf8HOaZbJPM2yRwyS6qoO00tnrbgEC4mVb033P2qkNOF56b1yV1Bs57KN8VxcQO3hwAdbg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618917320445.3419205329827; Fri, 4 Jul 2025 01:48:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3v-00080b-0m; Fri, 04 Jul 2025 04:46:27 -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 1uXc3n-0007xM-Eb for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3k-0000Xy-Po for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:19 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-IjwxZeOgOD-0myZ7ceWXjA-1; Fri, 04 Jul 2025 04:46:10 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7CAFD180029E; Fri, 4 Jul 2025 08:46:09 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 653FD19560A7; Fri, 4 Jul 2025 08:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ulbI3NpOKSsNZ8nhES+eA9VoPutBs8AfUXJ+hy3Y7UI=; b=YbdbMzygWmBLrPr4ZgzautntQzMMt60dcqPoCqRKjjmCvTVgREAMao9MngKvvHBS/6lmRh PoWQeKSpEfYUWdIEQOjYA63l17Lqz6kLO99pbKNr0YEwYkM/rg0hORitP1Um8TWB+yCC8n ZsOeJb5YPVume94E6iRgvhsC0QbtvRQ= X-MC-Unique: IjwxZeOgOD-0myZ7ceWXjA-1 X-Mimecast-MFC-AGG-ID: IjwxZeOgOD-0myZ7ceWXjA_1751618769 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Peter Xu , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 13/27] physmem: qemu_ram_get_fd_offset Date: Fri, 4 Jul 2025 10:45:14 +0200 Message-ID: <20250704084528.1412959-14-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618918323116600 From: Steve Sistare Define qemu_ram_get_fd_offset, so CPR can map a memory region using IOMMU_IOAS_MAP_FILE in a subsequent patch. Signed-off-by: Steve Sistare Reviewed-by: Peter Xu Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-8-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/exec/cpu-common.h | 1 + system/physmem.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index a68485547d5002e84306f5d82185fa7c6b2c2fcd..9b658a3f48f78ecd9ac49464c44= d7e3dc3e5644c 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -85,6 +85,7 @@ void qemu_ram_unset_idstr(RAMBlock *block); const char *qemu_ram_get_idstr(RAMBlock *rb); void *qemu_ram_get_host_addr(RAMBlock *rb); ram_addr_t qemu_ram_get_offset(RAMBlock *rb); +ram_addr_t qemu_ram_get_fd_offset(RAMBlock *rb); ram_addr_t qemu_ram_get_used_length(RAMBlock *rb); ram_addr_t qemu_ram_get_max_length(RAMBlock *rb); bool qemu_ram_is_shared(RAMBlock *rb); diff --git a/system/physmem.c b/system/physmem.c index ff0ca40222d3471f746632a21195dab1783e8345..130c148ffb5c1f8336bef0d346e= e1e8035771fcf 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1593,6 +1593,11 @@ ram_addr_t qemu_ram_get_offset(RAMBlock *rb) return rb->offset; } =20 +ram_addr_t qemu_ram_get_fd_offset(RAMBlock *rb) +{ + return rb->fd_offset; +} + ram_addr_t qemu_ram_get_used_length(RAMBlock *rb) { return rb->used_length; --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618855; cv=none; d=zohomail.com; s=zohoarc; b=cjjfWnjjogvcdGpj+e8apsam7dGUNKjzglBXU/6W1CDw3T3quKgX2ktRZR8G3nM6ZoDHHXQWV+srzPXsC3RZMnkMnzECH21qIOLaXpGDe1lJRCINHyCcAP/2FvBPanThuGn44gshaUbY+YPb9exx2LkFAnhQz9gi4slGgLzazT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618855; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H9ByR+nusummn7w7/LyYZYoD8r4c90VPIODzS0/Fy8g=; b=lv9f8+NaApBIVkhwxZF9jRQLZ5p4iXtgxHncKvWFMJXaVhqYUvtWstnhacH5/h8vhSA6eZF7QhttaXbYc01iZCOqds0EXHIccGKgsgWYKfyu/OMYfGOc1vaaE6CsezzhBpPsKZ7cSM3h3L93jBlYrPNbGB4wX86+WnRSgAltPOc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618855841576.4151301159651; Fri, 4 Jul 2025 01:47:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3v-000814-1M; Fri, 04 Jul 2025 04:46:27 -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 1uXc3m-0007tX-3X for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3k-0000Xe-6R for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:17 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-EVrEYhTWMQ2CbYRHnO94Zw-1; Fri, 04 Jul 2025 04:46:12 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C288418089B4; Fri, 4 Jul 2025 08:46:11 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB3A1195E74A; Fri, 4 Jul 2025 08:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H9ByR+nusummn7w7/LyYZYoD8r4c90VPIODzS0/Fy8g=; b=e42SipCYBtXIsqzTNttKMnUcK48/iCx00frT2ebc1VXzTJD4yvEKAH5wxa7v3WSo/20ggo Mp43dY43wvIpdhwLVQJD/y3h6mtoe8aI/hxur1MoYXupoaZPVU+NC07Q0WCYSCAkZhQein JFsx1Ra7qt5SZpe6p0ZkL2K3Dcmhn70= X-MC-Unique: EVrEYhTWMQ2CbYRHnO94Zw-1 X-Mimecast-MFC-AGG-ID: EVrEYhTWMQ2CbYRHnO94Zw_1751618771 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/27] vfio/iommufd: use IOMMU_IOAS_MAP_FILE Date: Fri, 4 Jul 2025 10:45:15 +0200 Message-ID: <20250704084528.1412959-15-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618857365116600 From: Steve Sistare Use IOMMU_IOAS_MAP_FILE when the mapped region is backed by a file. Such a mapping can be preserved without modification during CPR, because it depends on the file's address space, which does not change, rather than on the process's address space, which does change. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-9-git-send-email= -steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 15 +++++++++++++++ hw/vfio/container-base.c | 9 +++++++++ hw/vfio/iommufd.c | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 3cd86ec59e1a4605dea92fadeca5816145ae409b..bded6e993ffd34910f5583bf8e9= 4c81c41f4885f 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -167,6 +167,21 @@ struct VFIOIOMMUClass { int (*dma_map)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly, MemoryRegion *mr); + /** + * @dma_map_file + * + * Map a file range for the container. + * + * @bcontainer: #VFIOContainerBase to use for map + * @iova: start address to map + * @size: size of the range to map + * @fd: descriptor of the file to map + * @start: starting file offset of the range to map + * @readonly: map read only if true + */ + int (*dma_map_file)(const VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, + int fd, unsigned long start, bool readonly); /** * @dma_unmap * diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index d834bd482290a8b195f94c07832b7f8020504c3a..56304978e1e8ec456e0eb5f13e8= bddc091e76208 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -78,7 +78,16 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer, void *vaddr, bool readonly, MemoryRegion *mr) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_GET_CLASS(bcontainer); + RAMBlock *rb =3D mr->ram_block; + int mfd =3D rb ? qemu_ram_get_fd(rb) : -1; =20 + if (mfd >=3D 0 && vioc->dma_map_file) { + unsigned long start =3D vaddr - qemu_ram_get_host_addr(rb); + unsigned long offset =3D qemu_ram_get_fd_offset(rb); + + return vioc->dma_map_file(bcontainer, iova, size, mfd, start + off= set, + readonly); + } g_assert(vioc->dma_map); return vioc->dma_map(bcontainer, iova, size, vaddr, readonly, mr); } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index d3efef71afd4fd9e68455cefe7666c9f70e8c61e..962a1e2b1f28b297cc876fffa26= 77bd525479c8c 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -45,6 +45,18 @@ static int iommufd_cdev_map(const VFIOContainerBase *bco= ntainer, hwaddr iova, iova, size, vaddr, readonly); } =20 +static int iommufd_cdev_map_file(const VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, + int fd, unsigned long start, bool readonl= y) +{ + const VFIOIOMMUFDContainer *container =3D + container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); + + return iommufd_backend_map_file_dma(container->be, + container->ioas_id, + iova, size, fd, start, readonly); +} + static int iommufd_cdev_unmap(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb, bool unmap_all) @@ -807,6 +819,7 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *= klass, const void *data) VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); =20 vioc->dma_map =3D iommufd_cdev_map; + vioc->dma_map_file =3D iommufd_cdev_map_file; vioc->dma_unmap =3D iommufd_cdev_unmap; vioc->attach_device =3D iommufd_cdev_attach; vioc->detach_device =3D iommufd_cdev_detach; --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619090; cv=none; d=zohomail.com; s=zohoarc; b=S5MyNGb8Q6DYwOzAcJ50DOpZbe0w8nf12FFQ6xmdM+/an+pKgoJPyptuyKQ9ZyiB2tN+IM7woDf6OYs4VLc/pCowdTq8Udl6mIRq6+weu73X2CnaA3fwpvhoaSw+YXk34P8nTgEfbLHFkZxS3yhKLRmK8Zv51KsIGdfR3UZxnPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619090; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BM5vNjDCBW3H5iIwmayDEVixhk6Q2Pc3CcXMJe0BoB8=; b=D5MelZHJNohVswcndI2m6FS9hjoDkGy3cLE/hKnRtXpEao3sMecyO9pF+WiQN1LZnZ/nU5lJsExfj7I3+orivhw7DET7QqWxrkjK541yc0v/nFcDSglUsGX0XhHbaOAt7EKdK1r9CTDNcPsT/+8KMDafnsSPy3DrsL1eQyiPoac= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619090176948.5188489151476; Fri, 4 Jul 2025 01:51:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc3x-00084S-9v; Fri, 04 Jul 2025 04:46:29 -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 1uXc3p-0007yc-6d for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3n-0000cm-9w for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:20 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-T2ZyadhHNt23sir9LKjU9g-1; Fri, 04 Jul 2025 04:46:15 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52F2E1809C83; Fri, 4 Jul 2025 08:46:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D2BE19560A7; Fri, 4 Jul 2025 08:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618778; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BM5vNjDCBW3H5iIwmayDEVixhk6Q2Pc3CcXMJe0BoB8=; b=CvtT1z1w12UeJaDJbhK/e9F0f6Xfhdtq1TLzJ4aKZcVldjduEbV3fLRc+ovPuvU4PIdUEy V+vDfAYnXRoOnFsc9rwdANxpFV9RAld5Q4CcSI4salykX34Du2b6s31L5+SvgUzjYKf0C4 j2mf3SLAdmPNG/iTd2H2UGPyB8P8Y8g= X-MC-Unique: T2ZyadhHNt23sir9LKjU9g-1 X-Mimecast-MFC-AGG-ID: T2ZyadhHNt23sir9LKjU9g_1751618774 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 15/27] vfio/iommufd: invariant device name Date: Fri, 4 Jul 2025 10:45:16 +0200 Message-ID: <20250704084528.1412959-16-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619092331116600 From: Steve Sistare cpr-transfer will use the device name as a key to find the value of the device descriptor in new QEMU. However, if the descriptor number is specified by a command-line fd parameter, then vfio_device_get_name creates a name that includes the fd number. This causes a chicken-and-egg problem: new QEMU must know the fd number to construct a name to find the fd number. To fix, create an invariant name based on the id command-line parameter, if id is defined. The user will need to provide such an id to use CPR. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-10-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/device.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/vfio/device.c b/hw/vfio/device.c index d91c695b69b67ff8f09f590d3fcca8f30f259170..3cd365fb8b10a180c454d07efb4= b7d4e6f403046 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -316,12 +316,17 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error= **errp) error_setg(errp, "Use FD passing only with iommufd backend"); return false; } - /* - * Give a name with fd so any function printing out vbasedev->name - * will not break. - */ if (!vbasedev->name) { - vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->fd); + + if (vbasedev->dev->id) { + vbasedev->name =3D g_strdup(vbasedev->dev->id); + return true; + } else { + /* + * Assign a name so any function printing it will not brea= k. + */ + vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->= fd); + } } } =20 --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618956; cv=none; d=zohomail.com; s=zohoarc; b=Kbpk+/QogqLjpB1GLtzV8v+zKCXDabwlxP6B8OkXpeuTu0LVbRXe2Hc5TVC3sa3xsaFv+tmjMVebXFpeiv2tbAs8jTdEF0AM4rNKjrWsOQQw2gF7Nb6xvuTo3cq6QEj6KbvNmcIGJR+rI35IjYTHSi6u7U0oJVz/lLczsau2jAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618956; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FATOxFjlqOdGSfi9TLGXPwRXGcPggsJ2RP2fosVbyPQ=; b=XtXbZ6QraCsblr/lpLs3h4PI/kQQXabSApppbSmTioG5EcWgfsWfanGRk/66JIiSrm7BWPE36L4uGzjr1A/dd9iWaTqm4DkXGgHT2qqEKJbEa1WOCsCWV0SZ8WNvK0cN9bQ0MjTC1bpXZhhqPGb73eomnAHW/kft2CIxkiX+BxI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618956892144.6529482492682; Fri, 4 Jul 2025 01:49:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc41-0008Ej-6w; Fri, 04 Jul 2025 04:46:33 -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 1uXc3y-00087L-Rx for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3w-0000wN-Tc for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:30 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-eoX-xCADNA-_dIGSZ3Ff5g-1; Fri, 04 Jul 2025 04:46:20 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 26F5F1809C81; Fri, 4 Jul 2025 08:46:19 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59C8319560A7; Fri, 4 Jul 2025 08:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FATOxFjlqOdGSfi9TLGXPwRXGcPggsJ2RP2fosVbyPQ=; b=cJus7HoLYn9y4v+k87w1bIq+gQ9szLFTQFdievW9FAPolFBJsm/oIAoZNUlWKjfxzbzxzE z3He6AL+vR+G57bjibx/9m6M9YYpAYwzWM8kY7feGkD9gzb9rJkJIFFhOEZFIn885VB1ev lXteEfu1GovKi9oM6WRav0TqSRHlIc4= X-MC-Unique: eoX-xCADNA-_dIGSZ3Ff5g-1 X-Mimecast-MFC-AGG-ID: eoX-xCADNA-_dIGSZ3Ff5g_1751618779 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan Subject: [PULL 16/27] vfio/iommufd: add vfio_device_free_name Date: Fri, 4 Jul 2025 10:45:17 +0200 Message-ID: <20250704084528.1412959-17-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618958832116600 From: Steve Sistare Define vfio_device_free_name to free the name created by vfio_device_get_name. A subsequent patch will do more there. No functional change. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-11-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-device.h | 1 + hw/vfio/ap.c | 4 ++-- hw/vfio/ccw.c | 4 ++-- hw/vfio/device.c | 5 +++++ hw/vfio/pci.c | 2 +- hw/vfio/platform.c | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index f503837ccc6936b730a7752ca092da5acba1806f..1901a35aa90214c36369f8ac0b0= cfef36acbbaa8 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -279,6 +279,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int = index, =20 /* Returns 0 on success, or a negative errno. */ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp); +void vfio_device_free_name(VFIODevice *vbasedev); void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p); void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, DeviceState *dev, bool ram_discard); diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 1df4438149d2a06ef176e03e358336381bfa4caa..7719f245797ef45b6392270741c= 7dd0a36527fd2 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -265,7 +265,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) =20 error: error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name); - g_free(vbasedev->name); + vfio_device_free_name(vbasedev); } =20 static void vfio_ap_unrealize(DeviceState *dev) @@ -275,7 +275,7 @@ static void vfio_ap_unrealize(DeviceState *dev) vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX); vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_CFG_CHG_IRQ_INDEX); vfio_device_detach(&vapdev->vdev); - g_free(vapdev->vdev.name); + vfio_device_free_name(&vapdev->vdev); } =20 static const Property vfio_ap_properties[] =3D { diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index cea9d6e00562c241832184cafe862005fcdc992b..9560b8d851b6b25e647476c51ef= e845ebff10410 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -619,7 +619,7 @@ out_io_notifier_err: out_region_err: vfio_device_detach(vbasedev); out_attach_dev_err: - g_free(vbasedev->name); + vfio_device_free_name(vbasedev); out_unrealize: if (cdc->unrealize) { cdc->unrealize(cdev); @@ -637,7 +637,7 @@ static void vfio_ccw_unrealize(DeviceState *dev) vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); vfio_ccw_put_region(vcdev); vfio_device_detach(&vcdev->vdev); - g_free(vcdev->vdev.name); + vfio_device_free_name(&vcdev->vdev); =20 if (cdc->unrealize) { cdc->unrealize(cdev); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 3cd365fb8b10a180c454d07efb4b7d4e6f403046..97eddd04f5756a0e9e4763c4fef= 84c9829272053 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -333,6 +333,11 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error = **errp) return true; } =20 +void vfio_device_free_name(VFIODevice *vbasedev) +{ + g_clear_pointer(&vbasedev->name, g_free); +} + void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) { ERRP_GUARD(); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index dd0b2a0b947d4f9c788c6cd8b41e8ac916098724..1093b28df7c3f5f37e622e6d76a= 99ad8d2b7e01e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2996,7 +2996,7 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev) =20 vfio_device_detach(&vdev->vbasedev); =20 - g_free(vdev->vbasedev.name); + vfio_device_free_name(&vdev->vbasedev); g_free(vdev->msix); } =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 9a21f2e50a2945a6658b9be4fdec1bc1c98d0f20..5c1795a26fe79b98a9886e15f36= 5fa7a921409a4 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -530,7 +530,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) { /* @fd takes precedence over @sysfsdev which takes precedence over @ho= st */ if (vbasedev->fd < 0 && vbasedev->sysfsdev) { - g_free(vbasedev->name); + vfio_device_free_name(vbasedev); vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); } else if (vbasedev->fd < 0) { if (!vbasedev->name || strchr(vbasedev->name, '/')) { --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618899; cv=none; d=zohomail.com; s=zohoarc; b=d+m2jbw2wzoomDgU6yFZBBVden1eJfKTNdTfDqbaCicKZk27oWyLF6c/1SmqDJR6fUU8lU5UZDaUUaSqDWK92tYp553MRLhGXBMrXSP4+dVui4rmlxVphQH6/LQC6foyV0tM0F9wXqOcxnEF3Rtiw/A/TwwyfCxzjGeV1Wk4f+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618899; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8HqdYRY7R8+Tk3oVyA2DsfR6hwcoRL7MDY+RheEjH5I=; b=iVbi8MECl1ZLO0Ysqicn590FaFcI52gMyrhc2EDdwxr48ax3WKXzC9Uf07oeRJii1eC/xFHpAwozSIrih4AvAP5NsE7OtWvAZrgqX8kwRefXDPt2OAqyiiipQIptpCkwfUaccJtk0JW2stVbWWb6yV9naE76Czo4HRUdwbhIMAg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618899925374.92289688069934; Fri, 4 Jul 2025 01:48:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc42-0008I6-RA; Fri, 04 Jul 2025 04:46:35 -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 1uXc41-0008G6-NR for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3z-00011T-Pm for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:33 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-D6AnspH2PCSTA2u7Ll-c9A-1; Fri, 04 Jul 2025 04:46:22 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B9D811955EC7; Fri, 4 Jul 2025 08:46:21 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 85F5819560A7; Fri, 4 Jul 2025 08:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8HqdYRY7R8+Tk3oVyA2DsfR6hwcoRL7MDY+RheEjH5I=; b=bBtj/TaL7TBuQNwGYvvlCfbDW91lNWFk3JCwQaq1JC+Xhb8ARZoCoz23e7twsFobiE2tem gopJ+CqrnMq5qV+Ebs0o7gmZpaYAOvcqKbPzrCGctMZj0xF2Z5VXcUSqnEbnnpSbDl5am0 syjEDgZTMNl1QTyECjJLjvHYczNI8Dc= X-MC-Unique: D6AnspH2PCSTA2u7Ll-c9A-1 X-Mimecast-MFC-AGG-ID: D6AnspH2PCSTA2u7Ll-c9A_1751618781 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 17/27] vfio/iommufd: device name blocker Date: Fri, 4 Jul 2025 10:45:18 +0200 Message-ID: <20250704084528.1412959-18-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751618901975116600 From: Steve Sistare If an invariant device name cannot be created, block CPR. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-12-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 1 + hw/vfio/device.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index d37acc4a0a0ae1f6f38d8322fb9681227221fd09..fa7d43ddd8eccb305751f2311d4= ca8248b5052d0 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -30,6 +30,7 @@ typedef struct VFIOContainerCPR { =20 typedef struct VFIODeviceCPR { Error *mdev_blocker; + Error *id_blocker; } VFIODeviceCPR; =20 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 97eddd04f5756a0e9e4763c4fef84c9829272053..0ae3f3c6607d329e08fd435d293= 4e23affc27264 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -28,6 +28,8 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/units.h" +#include "migration/cpr.h" +#include "migration/blocker.h" #include "monitor/monitor.h" #include "vfio-helpers.h" =20 @@ -324,8 +326,16 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error = **errp) } else { /* * Assign a name so any function printing it will not brea= k. + * The fd number changes across processes, so this cannot = be + * used as an invariant name for CPR. */ vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->= fd); + error_setg(&vbasedev->cpr.id_blocker, + "vfio device with fd=3D%d needs an id property", + vbasedev->fd); + return migrate_add_blocker_modes(&vbasedev->cpr.id_blocker, + errp, MIG_MODE_CPR_TRANSF= ER, + -1) =3D=3D 0; } } } @@ -336,6 +346,7 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error *= *errp) void vfio_device_free_name(VFIODevice *vbasedev) { g_clear_pointer(&vbasedev->name, g_free); + migrate_del_blocker(&vbasedev->cpr.id_blocker); } =20 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618899; cv=none; d=zohomail.com; s=zohoarc; b=TBXIpiF48JRPa9CX4QRebrrczvqkaAgreqE0DBjLWDGxYLGIL8O/fFfFGsbidLB/IJ2KDo8IdeK39OjoTDDRaLqn7HWTH9ta4aO48ip1+86IEpuAjTfecOXFUNV4AHfnEQpEOM3EdH9xT322sd27cA8Kz+PhtCurxfMnEjeod2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618899; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sT+G8lgaF3ob5cncLc2Lzg1tNO58OGE9EL60ly192Fk=; b=FDqTK/KZWGvhWdf1dEb4G2gbymWlR/bQXV9idd3E7nwnfgzR6twRB+J2/2HRaPN3Ch0TqZoBR7lW49KF7OVtKZG+n/1/ns40T6GN9cjw1ZkVFsGKRRa4czVCH3pueLDid7YT84L8JgBOYJcEkULBZXYFccaFbbkm3VcfJA5Sq8Q= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618899017130.357028696797; Fri, 4 Jul 2025 01:48:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc42-0008I9-R6; Fri, 04 Jul 2025 04:46:35 -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 1uXc40-0008EN-Ov for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc3y-0000xY-8I for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:32 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-_G4d5APuMYi7FoOcoKgzLg-1; Fri, 04 Jul 2025 04:46:25 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4E98A180028D; Fri, 4 Jul 2025 08:46:24 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4107A19560A7; Fri, 4 Jul 2025 08:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sT+G8lgaF3ob5cncLc2Lzg1tNO58OGE9EL60ly192Fk=; b=VtEqThDrzW1xXZzL2Zibcenw2Vny0SE8HtTlGpEX7C1dgGgkqRCGemLb7ta56BUlkjZMkU OI7xLOI+l/8+r4HCZMNHD/siaS5uibOOuNxP8VcMCgV/OG+iFm62SkXsEB9tnL90PxmyQl bxTlBDKmK79aB7GdMTUvXEeMVfjqWCE= X-MC-Unique: _G4d5APuMYi7FoOcoKgzLg-1 X-Mimecast-MFC-AGG-ID: _G4d5APuMYi7FoOcoKgzLg_1751618784 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 18/27] vfio/iommufd: register container for cpr Date: Fri, 4 Jul 2025 10:45:19 +0200 Message-ID: <20250704084528.1412959-19-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618900155116600 From: Steve Sistare Register a vfio iommufd container and device for CPR, replacing the generic CPR register call with a more specific iommufd register call. Add a blocker if the kernel does not support IOMMU_IOAS_CHANGE_PROCESS. This is mostly boiler plate. The fields to to saved and restored are added in subsequent patches. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-13-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 12 ++++++ include/system/iommufd.h | 1 + backends/iommufd.c | 10 +++++ hw/vfio/cpr-iommufd.c | 86 ++++++++++++++++++++++++++++++++++++++ hw/vfio/iommufd.c | 6 ++- hw/vfio/meson.build | 1 + 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 hw/vfio/cpr-iommufd.c diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index fa7d43ddd8eccb305751f2311d4ca8248b5052d0..87b4206d8189c1cacd7fac629da= 5e3823a28c7ae 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -15,7 +15,10 @@ struct VFIOContainer; struct VFIOContainerBase; struct VFIOGroup; +struct VFIODevice; struct VFIOPCIDevice; +struct VFIOIOMMUFDContainer; +struct IOMMUFDBackend; =20 typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, @@ -44,6 +47,15 @@ bool vfio_cpr_register_container(struct VFIOContainerBas= e *bcontainer, Error **errp); void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer); =20 +bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *cont= ainer, + Error **errp); +void vfio_iommufd_cpr_unregister_container( + struct VFIOIOMMUFDContainer *container); +bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBackend *be, Error **= errp); +void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be); +void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev); +void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev); + int vfio_cpr_group_get_device_fd(int d, const char *name); =20 bool vfio_cpr_container_match(struct VFIOContainer *container, diff --git a/include/system/iommufd.h b/include/system/iommufd.h index db5f2c716c5be6cd1313045ab6dd28eb1f8356f3..c9c72ffc4509d7b5d09e8129c50= 65478aa23aec0 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -32,6 +32,7 @@ struct IOMMUFDBackend { /*< protected >*/ int fd; /* /dev/iommu file descriptor */ bool owned; /* is the /dev/iommu opened internally */ + Error *cpr_blocker;/* set if be does not support CPR */ uint32_t users; =20 /*< public >*/ diff --git a/backends/iommufd.c b/backends/iommufd.c index 87f81a05f6465cabc5673745f95947db2bb4a4fb..c554ce5385dd603ba35f97167ab= 8031750ecdc2f 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -108,6 +108,13 @@ bool iommufd_backend_connect(IOMMUFDBackend *be, Error= **errp) } be->fd =3D fd; } + if (!be->users && !vfio_iommufd_cpr_register_iommufd(be, errp)) { + if (be->owned) { + close(be->fd); + be->fd =3D -1; + } + return false; + } be->users++; =20 trace_iommufd_backend_connect(be->fd, be->owned, be->users); @@ -125,6 +132,9 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be) be->fd =3D -1; } out: + if (!be->users) { + vfio_iommufd_cpr_unregister_iommufd(be); + } trace_iommufd_backend_disconnect(be->fd, be->users); } =20 diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c new file mode 100644 index 0000000000000000000000000000000000000000..2f58b43793c048188ed61b560dc= ae1965383f061 --- /dev/null +++ b/hw/vfio/cpr-iommufd.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024-2025 Oracle and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/vfio/vfio-cpr.h" +#include "migration/blocker.h" +#include "migration/cpr.h" +#include "migration/migration.h" +#include "migration/vmstate.h" +#include "system/iommufd.h" +#include "vfio-iommufd.h" + +static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp) +{ + if (!iommufd_change_process_capable(be)) { + if (errp) { + error_setg(errp, "vfio iommufd backend does not support " + "IOMMU_IOAS_CHANGE_PROCESS"); + } + return false; + } + return true; +} + +static const VMStateDescription iommufd_cpr_vmstate =3D { + .name =3D "iommufd", + .version_id =3D 0, + .minimum_version_id =3D 0, + .needed =3D cpr_incoming_needed, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; + +bool vfio_iommufd_cpr_register_iommufd(IOMMUFDBackend *be, Error **errp) +{ + Error **cpr_blocker =3D &be->cpr_blocker; + + if (!vfio_cpr_supported(be, cpr_blocker)) { + return migrate_add_blocker_modes(cpr_blocker, errp, + MIG_MODE_CPR_TRANSFER, -1) =3D=3D= 0; + } + + vmstate_register(NULL, -1, &iommufd_cpr_vmstate, be); + + return true; +} + +void vfio_iommufd_cpr_unregister_iommufd(IOMMUFDBackend *be) +{ + vmstate_unregister(NULL, &iommufd_cpr_vmstate, be); + migrate_del_blocker(&be->cpr_blocker); +} + +bool vfio_iommufd_cpr_register_container(VFIOIOMMUFDContainer *container, + Error **errp) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + + migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier, + vfio_cpr_reboot_notifier, + MIG_MODE_CPR_REBOOT); + + vfio_cpr_add_kvm_notifier(); + + return true; +} + +void vfio_iommufd_cpr_unregister_container(VFIOIOMMUFDContainer *container) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + + migration_remove_notifier(&bcontainer->cpr_reboot_notifier); +} + +void vfio_iommufd_cpr_register_device(VFIODevice *vbasedev) +{ +} + +void vfio_iommufd_cpr_unregister_device(VFIODevice *vbasedev) +{ +} diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 962a1e2b1f28b297cc876fffa2677bd525479c8c..ff291be2356d1a2f59aa6dc7953= dc3fc00a627bd 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -446,7 +446,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDC= ontainer *container) if (!QLIST_EMPTY(&bcontainer->device_list)) { return; } - vfio_cpr_unregister_container(bcontainer); + vfio_iommufd_cpr_unregister_container(container); vfio_listener_unregister(bcontainer); iommufd_backend_free_id(container->be, container->ioas_id); object_unref(container); @@ -592,7 +592,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, goto err_listener_register; } =20 - if (!vfio_cpr_register_container(bcontainer, errp)) { + if (!vfio_iommufd_cpr_register_container(container, errp)) { goto err_listener_register; } =20 @@ -623,6 +623,7 @@ found_container: } =20 vfio_device_prepare(vbasedev, bcontainer, &dev_info); + vfio_iommufd_cpr_register_device(vbasedev); =20 trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, vbasedev->num_regions, vbasedev->flags); @@ -660,6 +661,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) iommufd_cdev_container_destroy(container); vfio_address_space_put(space); =20 + vfio_iommufd_cpr_unregister_device(vbasedev); iommufd_cdev_unbind_and_disconnect(vbasedev); close(vbasedev->fd); } diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 63ea39307601cce4b0783766f68c4cf8d9af71f9..7a881740a6d8d2d6f4f78024020= 060f2e11623eb 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -31,6 +31,7 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files( )) system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( 'iommufd.c', + 'cpr-iommufd.c', )) system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c', --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619080; cv=none; d=zohomail.com; s=zohoarc; b=Zj0XKVThhmWtRAxK7n3/l2/BCV2Klabs7ZFCCvrHqCvajE6TT822qbPJMw2DQoTl5fFRSWegzCHsY4kNd88GdPuWcIHacHAGGYjkv62Esu9/Iz1GO1SfAlnCc+rgqb0KCtjHfCb5xCiJSrU8/jH94k+lNYAkrKZUNmB/rqYV8CM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619080; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WRhhhtLxnfyFJaHIJ/rxc2exHfIyjH/GJ+Z3FynV/M4=; b=IUylGP8YTkRn08XT+ttiW2/cJ6Q8hT8pPF/GWZSYO3SkXS9wJecSX4BshoE0kD5vth66CCPbeKwbESLrRPigTxlRehvJ4Mi7nPUHfldT1HEjVlwh8VW/CVSVdnoMZ44Rs5IFi/dCLAAcpYKArdjGs6gHsZoJW8pT9zFf5ec7Tvg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619080183882.7848148502; Fri, 4 Jul 2025 01:51:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc45-0008OS-9T; Fri, 04 Jul 2025 04:46:37 -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 1uXc42-0008He-Ga for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc40-00011h-EX for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:34 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-Fw-MNyEjMH22_U5UT51sYg-1; Fri, 04 Jul 2025 04:46:28 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2522819560A2; Fri, 4 Jul 2025 08:46:27 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D691E19560A7; Fri, 4 Jul 2025 08:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WRhhhtLxnfyFJaHIJ/rxc2exHfIyjH/GJ+Z3FynV/M4=; b=CLK0SmfPRsTOrHmlv+6Uq2yvEu9B952Dqng0L/MdTul1ANPK7XAPaeldxoEMJuCxS0APjQ hK3S1vHPJGnOap5ECNLn9Vg+6kdHFbigQmSJpIp4+CJ7ubfKNpCaBVdpVlY7SDnwbEwvNM RM77zTmjzzMvUWIW7BlbqQqMeVQVHNQ= X-MC-Unique: Fw-MNyEjMH22_U5UT51sYg-1 X-Mimecast-MFC-AGG-ID: Fw-MNyEjMH22_U5UT51sYg_1751618787 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 19/27] migration: vfio cpr state hook Date: Fri, 4 Jul 2025 10:45:20 +0200 Message-ID: <20250704084528.1412959-20-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751619082479116600 From: Steve Sistare Define a list of vfio devices in CPR state, in a subsection so that older QEMU can be live updated to this version. However, new QEMU will not be live updateable to old QEMU. This is acceptable because CPR is not yet commonly used, and updates to older versions are unusual. The contents of each device object will be defined by the vfio subsystem in a subsequent patch. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-14-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 1 + include/migration/cpr.h | 12 ++++++++++++ hw/vfio/cpr-iommufd.c | 2 ++ hw/vfio/iommufd-stubs.c | 18 ++++++++++++++++++ migration/cpr.c | 15 ++++++--------- hw/vfio/meson.build | 1 + 6 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 hw/vfio/iommufd-stubs.c diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 87b4206d8189c1cacd7fac629da5e3823a28c7ae..286e3d4e9a7497b3ba279d99044= 9e71db676ec39 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -75,6 +75,7 @@ void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev= , const char *name, int nr); =20 extern const VMStateDescription vfio_cpr_pci_vmstate; +extern const VMStateDescription vmstate_cpr_vfio_devices; =20 void vfio_cpr_add_kvm_notifier(void); =20 diff --git a/include/migration/cpr.h b/include/migration/cpr.h index eb27a933017a09c480029a50cd6b1457e69cec8a..3fc19a74efdcf987f3b12f73b59= d11e8734f85b2 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -9,11 +9,23 @@ #define MIGRATION_CPR_H =20 #include "qapi/qapi-types-migration.h" +#include "qemu/queue.h" =20 #define MIG_MODE_NONE -1 =20 #define QEMU_CPR_FILE_MAGIC 0x51435052 #define QEMU_CPR_FILE_VERSION 0x00000001 +#define CPR_STATE "CprState" + +typedef QLIST_HEAD(CprFdList, CprFd) CprFdList; +typedef QLIST_HEAD(CprVFIODeviceList, CprVFIODevice) CprVFIODeviceList; + +typedef struct CprState { + CprFdList fds; + CprVFIODeviceList vfio_devices; +} CprState; + +extern CprState cpr_state; =20 void cpr_save_fd(const char *name, int id, int fd); void cpr_delete_fd(const char *name, int id); diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c index 2f58b43793c048188ed61b560dcae1965383f061..f95773b02c84f2ce8e27c49165b= 6ad68c4bc2328 100644 --- a/hw/vfio/cpr-iommufd.c +++ b/hw/vfio/cpr-iommufd.c @@ -14,6 +14,8 @@ #include "system/iommufd.h" #include "vfio-iommufd.h" =20 +const VMStateDescription vmstate_cpr_vfio_devices; /* TBD in a later patc= h */ + static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp) { if (!iommufd_change_process_capable(be)) { diff --git a/hw/vfio/iommufd-stubs.c b/hw/vfio/iommufd-stubs.c new file mode 100644 index 0000000000000000000000000000000000000000..0be5276175317327318283caaa5= 0e329c4be4946 --- /dev/null +++ b/hw/vfio/iommufd-stubs.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "migration/cpr.h" +#include "migration/vmstate.h" + +const VMStateDescription vmstate_cpr_vfio_devices =3D { + .name =3D CPR_STATE "/vfio devices", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]){ + VMSTATE_END_OF_LIST() + } +}; diff --git a/migration/cpr.c b/migration/cpr.c index 535d587aee16d2411d20ee549f8e3cf5a4120a88..42ad0b0d500e5de57faf0c6517e= 216b2d1c0cacf 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -7,6 +7,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "hw/vfio/vfio-device.h" #include "migration/cpr.h" #include "migration/misc.h" #include "migration/options.h" @@ -20,13 +21,7 @@ /*************************************************************************/ /* cpr state container for all information to be saved. */ =20 -typedef QLIST_HEAD(CprFdList, CprFd) CprFdList; - -typedef struct CprState { - CprFdList fds; -} CprState; - -static CprState cpr_state; +CprState cpr_state; =20 /*************************************************************************= ***/ =20 @@ -127,8 +122,6 @@ int cpr_open_fd(const char *path, int flags, const char= *name, int id, } =20 /*************************************************************************/ -#define CPR_STATE "CprState" - static const VMStateDescription vmstate_cpr_state =3D { .name =3D CPR_STATE, .version_id =3D 1, @@ -136,6 +129,10 @@ static const VMStateDescription vmstate_cpr_state =3D { .fields =3D (VMStateField[]) { VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next), VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_cpr_vfio_devices, + NULL } }; /*************************************************************************/ diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index 7a881740a6d8d2d6f4f78024020060f2e11623eb..bfaf6be805483d46190232bd680= 5a7a042380a0d 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -33,6 +33,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if= _true: files( 'iommufd.c', 'cpr-iommufd.c', )) +system_ss.add(when: 'CONFIG_IOMMUFD', if_false: files('iommufd-stubs.c')) system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c', )) --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618916; cv=none; d=zohomail.com; s=zohoarc; b=a8MZTbTh84Ysdk5L/pUE/m+w8o1GWdRPTTRT+i5h/5W9VF/1AAARrYaoNr6p/C2neLFKzKBdhbPo4/u7Dpqg421E2TVDCJxvsZXV5NA7OBES/zDsi/q/yZOUm/6WfUYMKpI7F/ZwpOS93hDCv+R3uv7ibLJay9yxzV/pB6er73U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618916; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g522b//I6zPH1mnEyR7Hwc51XyvTjb1tOQ42jXQ8atw=; b=F2NaKbiKQjoGaU4AHqThBht0F+34hTZdjzo32OUtFDUsUDPqOl4jfZ/HrQ1WKz6Io4CcGCLG56IXFX5r/xe8ziwaXZwBl3+tVEPXab1hNC5BOCz9e8v79dY/jZnD38y2ol+iJCI9nhn5vZtDHHJzn1bHtcKKeySDUna469bjJc4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618916359597.3996974105057; Fri, 4 Jul 2025 01:48:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc47-0008Vj-TW; Fri, 04 Jul 2025 04:46:39 -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 1uXc44-0008OB-V9 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc42-00013O-PW for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:36 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-uWz6ndk2NAScZiLsDed3_g-1; Fri, 04 Jul 2025 04:46:30 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8ED711808985; Fri, 4 Jul 2025 08:46:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A5C4A19560A7; Fri, 4 Jul 2025 08:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g522b//I6zPH1mnEyR7Hwc51XyvTjb1tOQ42jXQ8atw=; b=hIBAll5x4gR9G9YlbRqaY5jETaR3wD6G7Vxy16PTA5Ly4MZHEJ1ULCBCy8+ZN5qBsz2BfH wRJQSHc/f1dMh5xw4yL5H+lAFVLfmKoqi3IN742EBHoyaVUCJBkbNsc/0PSif3OmZIldZ1 M3MTJA1Be+D7hixpeS8BLNB0Cdf3GFs= X-MC-Unique: uWz6ndk2NAScZiLsDed3_g-1 X-Mimecast-MFC-AGG-ID: uWz6ndk2NAScZiLsDed3_g_1751618789 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 20/27] vfio/iommufd: cpr state Date: Fri, 4 Jul 2025 10:45:21 +0200 Message-ID: <20250704084528.1412959-21-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618918490116600 From: Steve Sistare VFIO iommufd devices will need access to ioas_id, devid, and hwpt_id in new QEMU at realize time, so add them to CPR state. Define CprVFIODevice as the object which holds the state and is serialized to the vmstate file. Define accessors to copy state between VFIODevice and CprVFIODevice. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-15-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 3 ++ hw/vfio/cpr-iommufd.c | 98 +++++++++++++++++++++++++++++++++++++- hw/vfio/iommufd.c | 2 + hw/vfio/trace-events | 3 ++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 286e3d4e9a7497b3ba279d990449e71db676ec39..287837249589e269f87e33ba263= 5e8682a764e82 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -34,6 +34,8 @@ typedef struct VFIOContainerCPR { typedef struct VFIODeviceCPR { Error *mdev_blocker; Error *id_blocker; + uint32_t hwpt_id; + uint32_t ioas_id; } VFIODeviceCPR; =20 bool vfio_legacy_cpr_register_container(struct VFIOContainer *container, @@ -55,6 +57,7 @@ bool vfio_iommufd_cpr_register_iommufd(struct IOMMUFDBack= end *be, Error **errp); void vfio_iommufd_cpr_unregister_iommufd(struct IOMMUFDBackend *be); void vfio_iommufd_cpr_register_device(struct VFIODevice *vbasedev); void vfio_iommufd_cpr_unregister_device(struct VFIODevice *vbasedev); +void vfio_cpr_load_device(struct VFIODevice *vbasedev); =20 int vfio_cpr_group_get_device_fd(int d, const char *name); =20 diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c index f95773b02c84f2ce8e27c49165b6ad68c4bc2328..4166201e3f70441ff97aef23c3b= 6f8bf506c76ad 100644 --- a/hw/vfio/cpr-iommufd.c +++ b/hw/vfio/cpr-iommufd.c @@ -7,14 +7,98 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/vfio/vfio-cpr.h" +#include "hw/vfio/vfio-device.h" #include "migration/blocker.h" #include "migration/cpr.h" #include "migration/migration.h" #include "migration/vmstate.h" #include "system/iommufd.h" #include "vfio-iommufd.h" +#include "trace.h" + +typedef struct CprVFIODevice { + char *name; + unsigned int namelen; + uint32_t ioas_id; + int devid; + uint32_t hwpt_id; + QLIST_ENTRY(CprVFIODevice) next; +} CprVFIODevice; + +static const VMStateDescription vmstate_cpr_vfio_device =3D { + .name =3D "cpr vfio device", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(namelen, CprVFIODevice), + VMSTATE_VBUFFER_ALLOC_UINT32(name, CprVFIODevice, 0, NULL, namelen= ), + VMSTATE_INT32(devid, CprVFIODevice), + VMSTATE_UINT32(ioas_id, CprVFIODevice), + VMSTATE_UINT32(hwpt_id, CprVFIODevice), + VMSTATE_END_OF_LIST() + } +}; + +const VMStateDescription vmstate_cpr_vfio_devices =3D { + .name =3D CPR_STATE "/vfio devices", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]){ + VMSTATE_QLIST_V(vfio_devices, CprState, 1, vmstate_cpr_vfio_device, + CprVFIODevice, next), + VMSTATE_END_OF_LIST() + } +}; + +static void vfio_cpr_save_device(VFIODevice *vbasedev) +{ + CprVFIODevice *elem =3D g_new0(CprVFIODevice, 1); + + elem->name =3D g_strdup(vbasedev->name); + elem->namelen =3D strlen(vbasedev->name) + 1; + elem->ioas_id =3D vbasedev->cpr.ioas_id; + elem->devid =3D vbasedev->devid; + elem->hwpt_id =3D vbasedev->cpr.hwpt_id; + QLIST_INSERT_HEAD(&cpr_state.vfio_devices, elem, next); +} + +static CprVFIODevice *find_device(const char *name) +{ + CprVFIODeviceList *head =3D &cpr_state.vfio_devices; + CprVFIODevice *elem; + + QLIST_FOREACH(elem, head, next) { + if (!strcmp(elem->name, name)) { + return elem; + } + } + return NULL; +} + +static void vfio_cpr_delete_device(const char *name) +{ + CprVFIODevice *elem =3D find_device(name); =20 -const VMStateDescription vmstate_cpr_vfio_devices; /* TBD in a later patc= h */ + if (elem) { + QLIST_REMOVE(elem, next); + g_free(elem->name); + g_free(elem); + } +} + +static bool vfio_cpr_find_device(VFIODevice *vbasedev) +{ + CprVFIODevice *elem =3D find_device(vbasedev->name); + + if (elem) { + vbasedev->cpr.ioas_id =3D elem->ioas_id; + vbasedev->devid =3D elem->devid; + vbasedev->cpr.hwpt_id =3D elem->hwpt_id; + trace_vfio_cpr_find_device(elem->ioas_id, elem->devid, elem->hwpt_= id); + return true; + } + return false; +} =20 static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp) { @@ -81,8 +165,20 @@ void vfio_iommufd_cpr_unregister_container(VFIOIOMMUFDC= ontainer *container) =20 void vfio_iommufd_cpr_register_device(VFIODevice *vbasedev) { + if (!cpr_is_incoming()) { + vfio_cpr_save_device(vbasedev); + } } =20 void vfio_iommufd_cpr_unregister_device(VFIODevice *vbasedev) { + vfio_cpr_delete_device(vbasedev->name); +} + +void vfio_cpr_load_device(VFIODevice *vbasedev) +{ + if (cpr_is_incoming()) { + bool ret =3D vfio_cpr_find_device(vbasedev); + g_assert(ret); + } } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index ff291be2356d1a2f59aa6dc7953dc3fc00a627bd..f0d57ea65f148063ec2022e2321= fd1d970494779 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -515,6 +515,8 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, const VFIOIOMMUClass *iommufd_vioc =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD)); =20 + vfio_cpr_load_device(vbasedev); + if (vbasedev->fd < 0) { devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); if (devfd < 0) { diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index e1728c4ef64acfc4a377dfc4711cad35c03a51b7..8ec0ad0cde064927f58fbd84594= 13b303d155979 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -197,6 +197,9 @@ iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [io= mmufd=3D%d] new IOMMUFD con iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regi= ons, int flags) " %s (%d) num_irqs=3D%d num_regions=3D%d flags=3D%d" iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int = function, int dev_id) "\t%04x:%02x:%02x.%x devid %d" =20 +# cpr-iommufd.c +vfio_cpr_find_device(uint32_t ioas_id, int devid, uint32_t hwpt_id) "ioas_= id %u, devid %d, hwpt_id %u" + # device.c vfio_device_get_region_info_type(const char *name, int index, uint32_t typ= e, uint32_t subtype) "%s index %d, %08x/%08x" vfio_device_reset_handler(void) "" --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618833; cv=none; d=zohomail.com; s=zohoarc; b=LNYsTpNieEO+J6jaoPpLmrZNYYRJGz3LEc2Tx+w7FP9vNHZ4ot36dMvb81U9nLb1jGHUeidHBc2hkv9acNlqyY0+TvN4sLCGAADomS98mPwKgUQuR8zHzBh7g9bgCJx67RPOvR6yV8QWo/EnCUOC4C7AA8ETPfj7QYDszetPQyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618833; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kaTS+0aZpyNuV/JhVP9aCHEbDpEONk4O446liL6Tlto=; b=krQak5NpK9fOFsfm09A6/+mudzFM0gcl5aLnK1jeyOQPbjOYPq9QuD6WtH74mX2FwmqFvEuYKbfCIQQSnThTjCm5yWRYtYg8Sveda/mVeFl51Ih5zXH7BQ3uwOCiWPb3tJqqbux8yV8HqtDaRLSb4ejyDRmr9ufp7C4alm/cVtc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618833617733.7352698693142; Fri, 4 Jul 2025 01:47:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4B-0000BN-7h; Fri, 04 Jul 2025 04:46:45 -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 1uXc47-0008VT-95 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc45-000186-5b for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:38 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-FetbsOEdPSe4rQE1MGYCTA-1; Fri, 04 Jul 2025 04:46:33 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00B121944A8C; Fri, 4 Jul 2025 08:46:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 186F819560A7; Fri, 4 Jul 2025 08:46:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kaTS+0aZpyNuV/JhVP9aCHEbDpEONk4O446liL6Tlto=; b=aFm7GRY1NF6wmm4kQ0fC73T3H0sL52HqFTv4SeTpIbE2Z2z8YavCvcQ8UxlfnKpsahB46M 8ath+Hh4FjGLOg/0uBA5uxsiVV29rBAwBObHZ/oO68O6yRStG2V2Tst+u4XViEU833FbVz CjXkNQpVbJMSXrL1CEZhShrktg2uvRs= X-MC-Unique: FetbsOEdPSe4rQE1MGYCTA-1 X-Mimecast-MFC-AGG-ID: FetbsOEdPSe4rQE1MGYCTA_1751618792 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 21/27] vfio/iommufd: preserve descriptors Date: Fri, 4 Jul 2025 10:45:22 +0200 Message-ID: <20250704084528.1412959-22-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751618835140116600 From: Steve Sistare Save the iommu and vfio device fd in CPR state when it is created. After CPR, the fd number is found in CPR state and reused. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-16-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- backends/iommufd.c | 35 +++++++++++++++++++++++++++++------ hw/vfio/cpr-iommufd.c | 10 ++++++++++ hw/vfio/device.c | 9 +-------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/backends/iommufd.c b/backends/iommufd.c index c554ce5385dd603ba35f97167ab8031750ecdc2f..e0917923bffbb60dc5c58235880= 335c4d5eb7df7 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -16,12 +16,18 @@ #include "qemu/module.h" #include "qom/object_interfaces.h" #include "qemu/error-report.h" +#include "migration/cpr.h" #include "monitor/monitor.h" #include "trace.h" #include "hw/vfio/vfio-device.h" #include #include =20 +static const char *iommufd_fd_name(IOMMUFDBackend *be) +{ + return object_get_canonical_path_component(OBJECT(be)); +} + static void iommufd_backend_init(Object *obj) { IOMMUFDBackend *be =3D IOMMUFD_BACKEND(obj); @@ -64,11 +70,27 @@ static bool iommufd_backend_can_be_deleted(UserCreatabl= e *uc) return !be->users; } =20 +static void iommufd_backend_complete(UserCreatable *uc, Error **errp) +{ + IOMMUFDBackend *be =3D IOMMUFD_BACKEND(uc); + const char *name =3D iommufd_fd_name(be); + + if (!be->owned) { + /* fd came from the command line. Fetch updated value from cpr sta= te. */ + if (cpr_is_incoming()) { + be->fd =3D cpr_find_fd(name, 0); + } else { + cpr_save_fd(name, 0, be->fd); + } + } +} + static void iommufd_backend_class_init(ObjectClass *oc, const void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); =20 ucc->can_be_deleted =3D iommufd_backend_can_be_deleted; + ucc->complete =3D iommufd_backend_complete; =20 object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); } @@ -102,7 +124,7 @@ bool iommufd_backend_connect(IOMMUFDBackend *be, Error = **errp) int fd; =20 if (be->owned && !be->users) { - fd =3D qemu_open("/dev/iommu", O_RDWR, errp); + fd =3D cpr_open_fd("/dev/iommu", O_RDWR, iommufd_fd_name(be), 0, e= rrp); if (fd < 0) { return false; } @@ -127,14 +149,15 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be) goto out; } be->users--; - if (!be->users && be->owned) { - close(be->fd); - be->fd =3D -1; - } -out: if (!be->users) { vfio_iommufd_cpr_unregister_iommufd(be); + if (be->owned) { + cpr_delete_fd(iommufd_fd_name(be), 0); + close(be->fd); + be->fd =3D -1; + } } +out: trace_iommufd_backend_disconnect(be->fd, be->users); } =20 diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c index 4166201e3f70441ff97aef23c3b6f8bf506c76ad..a72b68daa8e4da19b9cbf3ab506= 31211965cdf37 100644 --- a/hw/vfio/cpr-iommufd.c +++ b/hw/vfio/cpr-iommufd.c @@ -166,12 +166,18 @@ void vfio_iommufd_cpr_unregister_container(VFIOIOMMUF= DContainer *container) void vfio_iommufd_cpr_register_device(VFIODevice *vbasedev) { if (!cpr_is_incoming()) { + /* + * Beware fd may have already been saved by vfio_device_set_fd, + * so call resave to avoid a duplicate entry. + */ + cpr_resave_fd(vbasedev->name, 0, vbasedev->fd); vfio_cpr_save_device(vbasedev); } } =20 void vfio_iommufd_cpr_unregister_device(VFIODevice *vbasedev) { + cpr_delete_fd(vbasedev->name, 0); vfio_cpr_delete_device(vbasedev->name); } =20 @@ -180,5 +186,9 @@ void vfio_cpr_load_device(VFIODevice *vbasedev) if (cpr_is_incoming()) { bool ret =3D vfio_cpr_find_device(vbasedev); g_assert(ret); + + if (vbasedev->fd < 0) { + vbasedev->fd =3D cpr_find_fd(vbasedev->name, 0); + } } } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 0ae3f3c6607d329e08fd435d2934e23affc27264..96cf21462cb10f9ebaf1bda54fe= d13a95b79f223 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -351,14 +351,7 @@ void vfio_device_free_name(VFIODevice *vbasedev) =20 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) { - ERRP_GUARD(); - int fd =3D monitor_fd_param(monitor_cur(), str, errp); - - if (fd < 0) { - error_prepend(errp, "Could not parse remote object fd %s:", str); - return; - } - vbasedev->fd =3D fd; + vbasedev->fd =3D cpr_get_fd_param(vbasedev->dev->id, str, 0, errp); } =20 static VFIODeviceIOOps vfio_device_io_ops_ioctl; --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618896; cv=none; d=zohomail.com; s=zohoarc; b=fFvTyLia3PfSTQja7weLt2xB2ZuAgUw675xuy8e2JmpKIxOB9rUtj9eL3KuqAR0p4MnXJU0MdrC57Shz2vbNcziqxcFzoQHgmV3aV1pHqUiWFLwQEznVSMIWUvrs6gALGnqTiqV2LdauLfyFFUar1VlZ7n3sVVVlETPveSZ0+/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618896; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aUJFqZnM/Trg5Kkp3SSUPNBS9XlVzOxwVnQbV3UWGwM=; b=B5xCHEqAkTkKwKmk3U4MxBdMaQ5w4H94wJxlCG/UWgf2EF6GAscaOXT6SYZUdgg/ou4aS9zP4Iex28mGYbWajWugxQFhHpcvMEYmR81BucGTzx6CITJT6Zr9GqwoHlUOHDwAz0qBX1Yb8JguMtOm6JgbvbZBXHnEJS/2RE21cys= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618896004995.7904991212747; Fri, 4 Jul 2025 01:48:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4Q-0000XP-Ox; Fri, 04 Jul 2025 04:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4D-0000N5-Tj for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc47-0001DW-K7 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:45 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232-f1WbWrDLMwymBiaLX5yS_w-1; Fri, 04 Jul 2025 04:46:35 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B9F51809C83; Fri, 4 Jul 2025 08:46:34 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E3C519560A7; Fri, 4 Jul 2025 08:46:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aUJFqZnM/Trg5Kkp3SSUPNBS9XlVzOxwVnQbV3UWGwM=; b=RNdAhZQWefDxgtC/IqZicatRiHupcqbKECrZ385l2/cdzarfGcXDm/1cTwcbVmlFbZBnbG i/w2vDUY7ty4bZ5wIldL6iulVyagMLNmDd6mZ3H4OO0L2SjbrI+Y23mJAZpzB158Yw+V22 HLqoqrmhJLSlg1Lf8aA2hwocpsZozrg= X-MC-Unique: f1WbWrDLMwymBiaLX5yS_w-1 X-Mimecast-MFC-AGG-ID: f1WbWrDLMwymBiaLX5yS_w_1751618794 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 22/27] vfio/iommufd: reconstruct device Date: Fri, 4 Jul 2025 10:45:23 +0200 Message-ID: <20250704084528.1412959-23-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618897992116600 From: Steve Sistare Reconstruct userland device state after CPR. During vfio_realize, skip all ioctls that configure the device, as it was already configured in old QEMU. Skip bind, and use the devid from CPR state. Skip allocation of, and attachment to, ioas_id. Recover ioas_id from CPR state, and use it to find a matching container, if any, before creating a new one. This reconstruction is not complete. hwpt_id is handled in a subsequent patch. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-17-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f0d57ea65f148063ec2022e2321fd1d970494779..a650517a1d92ed5671757d425fe= e8709f2cd3ade 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -25,6 +25,7 @@ #include "system/reset.h" #include "qemu/cutils.h" #include "qemu/chardev_open.h" +#include "migration/cpr.h" #include "pci.h" #include "vfio-iommufd.h" #include "vfio-helpers.h" @@ -121,6 +122,10 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *= vbasedev, Error **errp) goto err_kvm_device_add; } =20 + if (cpr_is_incoming()) { + goto skip_bind; + } + /* Bind device to iommufd */ bind.iommufd =3D iommufd->fd; if (ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) { @@ -132,6 +137,8 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *v= basedev, Error **errp) vbasedev->devid =3D bind.out_devid; trace_iommufd_cdev_connect_and_bind(bind.iommufd, vbasedev->name, vbasedev->fd, vbasedev->devid); + +skip_bind: return true; err_bind: iommufd_cdev_kvm_device_del(vbasedev); @@ -421,7 +428,9 @@ static bool iommufd_cdev_attach_container(VFIODevice *v= basedev, return iommufd_cdev_autodomains_get(vbasedev, container, errp); } =20 - return !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); + /* If CPR, we are already attached to ioas_id. */ + return cpr_is_incoming() || + !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); } =20 static void iommufd_cdev_detach_container(VFIODevice *vbasedev, @@ -510,6 +519,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, VFIOAddressSpace *space; struct vfio_device_info dev_info =3D { .argsz =3D sizeof(dev_info) }; int ret, devfd; + bool res; uint32_t ioas_id; Error *err =3D NULL; const VFIOIOMMUClass *iommufd_vioc =3D @@ -540,7 +550,16 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, vbasedev->iommufd !=3D container->be) { continue; } - if (!iommufd_cdev_attach_container(vbasedev, container, &err)) { + + if (!cpr_is_incoming()) { + res =3D iommufd_cdev_attach_container(vbasedev, container, &er= r); + } else if (vbasedev->cpr.ioas_id =3D=3D container->ioas_id) { + res =3D true; + } else { + continue; + } + + if (!res) { const char *msg =3D error_get_pretty(err); =20 trace_iommufd_cdev_fail_attach_existing_container(msg); @@ -557,6 +576,11 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, } } =20 + if (cpr_is_incoming()) { + ioas_id =3D vbasedev->cpr.ioas_id; + goto skip_ioas_alloc; + } + /* Need to allocate a new dedicated container */ if (!iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp)) { goto err_alloc_ioas; @@ -564,10 +588,12 @@ static bool iommufd_cdev_attach(const char *name, VFI= ODevice *vbasedev, =20 trace_iommufd_cdev_alloc_ioas(vbasedev->iommufd->fd, ioas_id); =20 +skip_ioas_alloc: container =3D VFIO_IOMMU_IOMMUFD(object_new(TYPE_VFIO_IOMMU_IOMMUFD)); container->be =3D vbasedev->iommufd; container->ioas_id =3D ioas_id; QLIST_INIT(&container->hwpt_list); + vbasedev->cpr.ioas_id =3D ioas_id; =20 bcontainer =3D &container->bcontainer; vfio_address_space_insert(space, bcontainer); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618885; cv=none; d=zohomail.com; s=zohoarc; b=khrf2Gx9Wa4lNoCjEsru2oZNmShAySFxiPJ5G15KiS+n19T5M53+0huimJqtCwnJ4DLuYM7/6N9l4oMizfYZ8B/yBBgeymksGXxCQ04sJM0Lvn7La3NGgqkFokr7ax6hLBy++Veko0R7NAyjiTbzxlgCl/XG7k442SkSwdWXTjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618885; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xcFyxh59ass/jQSk1T1Fej2k2dH2B8zPFvS7BgC8LN0=; b=QRTNdGYy0DaW8M7lDq9jAKCmGFxxCDNSgkKJH7yP5fgF1o60NRwKzHWhfnDWbYFbhS4vDUX3WrsXwxdlpSsDGRuRS+AlCL3Nit4+W6orJ6GRUnm1BxV1bOJ6d+kggZ1dmMNdxfuqG70JOR7lRU8MVbP17tHkgxsiD5emOimkguU= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618885403593.3494752652092; Fri, 4 Jul 2025 01:48:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4S-0000dK-S9; Fri, 04 Jul 2025 04:47:00 -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 1uXc4E-0000N6-2T for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4A-0001IR-80 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:45 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-Rl3ryZ5AOPuQBcfLxzxC6w-1; Fri, 04 Jul 2025 04:46:38 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3990019560AD; Fri, 4 Jul 2025 08:46:37 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E943F19560A7; Fri, 4 Jul 2025 08:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xcFyxh59ass/jQSk1T1Fej2k2dH2B8zPFvS7BgC8LN0=; b=c+if7feg+R6x3B4Gb2GkZgXQGW7YmB8U551Q5ixXKAiYy3Bn4lbs0Lj9GIQniTGUu2i7Ne CUqiSIkGg4qMhEhR3hx6lZaheJW+vbJy4ePPmEXYUiGYtNSzZvQsXWTCebgjqeE0/IS1Pd VcBhE19QgnxGTkBL8bui4oFkC90ldm4= X-MC-Unique: Rl3ryZ5AOPuQBcfLxzxC6w-1 X-Mimecast-MFC-AGG-ID: Rl3ryZ5AOPuQBcfLxzxC6w_1751618797 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 23/27] vfio/iommufd: reconstruct hwpt Date: Fri, 4 Jul 2025 10:45:24 +0200 Message-ID: <20250704084528.1412959-24-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751618887655116600 From: Steve Sistare Skip allocation of, and attachment to, hwpt_id. Recover it from CPR state. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-18-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index a650517a1d92ed5671757d425fee8709f2cd3ade..48c590b6a9467c8139131bef8b9= 2864893a8f2e6 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -332,7 +332,14 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, =20 /* Try to find a domain */ QLIST_FOREACH(hwpt, &container->hwpt_list, next) { - ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, err= p); + if (!cpr_is_incoming()) { + ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id,= errp); + } else if (vbasedev->cpr.hwpt_id =3D=3D hwpt->hwpt_id) { + ret =3D 0; + } else { + continue; + } + if (ret) { /* -EINVAL means the domain is incompatible with the device. */ if (ret =3D=3D -EINVAL) { @@ -349,6 +356,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, return false; } else { vbasedev->hwpt =3D hwpt; + vbasedev->cpr.hwpt_id =3D hwpt->hwpt_id; QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); vbasedev->iommu_dirty_tracking =3D iommufd_hwpt_dirty_tracking= (hwpt); return true; @@ -371,6 +379,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING; } =20 + if (cpr_is_incoming()) { + hwpt_id =3D vbasedev->cpr.hwpt_id; + goto skip_alloc; + } + if (!iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid, container->ioas_id, flags, IOMMU_HWPT_DATA_NONE, 0, NULL, @@ -378,19 +391,20 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *= vbasedev, return false; } =20 + ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt_id, errp); + if (ret) { + iommufd_backend_free_id(container->be, hwpt_id); + return false; + } + +skip_alloc: hwpt =3D g_malloc0(sizeof(*hwpt)); hwpt->hwpt_id =3D hwpt_id; hwpt->hwpt_flags =3D flags; QLIST_INIT(&hwpt->device_list); =20 - ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp); - if (ret) { - iommufd_backend_free_id(container->be, hwpt->hwpt_id); - g_free(hwpt); - return false; - } - vbasedev->hwpt =3D hwpt; + vbasedev->cpr.hwpt_id =3D hwpt->hwpt_id; vbasedev->iommu_dirty_tracking =3D iommufd_hwpt_dirty_tracking(hwpt); QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next); QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next); --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619169; cv=none; d=zohomail.com; s=zohoarc; b=mp4DijB5MTTyrPNdDVeneIbXD9PmIWenQMAMTxhKVcl5QoR7f7c5cMht5SrThNVjb39T6xz8AIT066GF7/6rYr8RXUX05IfsiHMqH3RSlww5vxOZFRSh4Sdds1fresEELkdviCKYm9oXE7FiJ3CeCZSw7mWRyiInZpaFkFnieI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619169; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2/QQHxzSBwOZry8dpMse9+bQu7EIO9GAsfRgmGz5QH8=; b=MCQQGpdhHtmITzlZ8MOIoANPg7D38yk4BJug+8eMOYnq5EFvaj1iUE9fskmdZgmMc4ikfNHdD4isXVuinPw1lXkxK9GVAT2zIFjJloSY3VYQCxUSCpZe1XioDS0ejheKIpcjYfxP0jBjbcN8otaTUnp/+IoECpze8UgPQ8nJbLc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17516191699383.6019945322052536; Fri, 4 Jul 2025 01:52:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4R-0000b1-Fj; Fri, 04 Jul 2025 04:47:00 -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 1uXc4F-0000QX-OS for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4D-0001OF-QP for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:47 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-m3YTmIjENKOznhQTtCof_A-1; Fri, 04 Jul 2025 04:46:40 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8CC141944AA6; Fri, 4 Jul 2025 08:46:39 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 98F5219560A7; Fri, 4 Jul 2025 08:46:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2/QQHxzSBwOZry8dpMse9+bQu7EIO9GAsfRgmGz5QH8=; b=QskD0r/MbpGNa3/CAmVOH8Q8u1GNA+8xHuLdzEcCirBhYsRTGaaj7K0R+yg6UXKlwHvPwL OJEPNEURrtr+Tlr0VaX28GB8HpM2ls0OEVCekI66bo+CqTgTzt2baq2BkJ+gz1FZfpKkPh jOLttlTdFGZPpvMKRK3i/meuT//w+9s= X-MC-Unique: m3YTmIjENKOznhQTtCof_A-1 X-Mimecast-MFC-AGG-ID: m3YTmIjENKOznhQTtCof_A_1751618799 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 24/27] vfio/iommufd: change process Date: Fri, 4 Jul 2025 10:45:25 +0200 Message-ID: <20250704084528.1412959-25-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1751619171084116600 From: Steve Sistare Finish CPR by change the owning process of the iommufd device in post load. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-19-git-send-emai= l-steven.sistare@oracle.com [ clg: Fixed missing "qemu/error-report.h" include ] Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/cpr-iommufd.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c index a72b68daa8e4da19b9cbf3ab50631211965cdf37..148a06d552ff3d8e8420366c6b7= 1437e81a1f877 100644 --- a/hw/vfio/cpr-iommufd.c +++ b/hw/vfio/cpr-iommufd.c @@ -5,6 +5,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "qapi/error.h" #include "hw/vfio/vfio-cpr.h" #include "hw/vfio/vfio-device.h" @@ -112,10 +113,40 @@ static bool vfio_cpr_supported(IOMMUFDBackend *be, Er= ror **errp) return true; } =20 +static int iommufd_cpr_pre_save(void *opaque) +{ + IOMMUFDBackend *be =3D opaque; + + /* + * The process has not changed yet, but proactively try the ioctl, + * and it will fail if any DMA mappings are not supported. + */ + if (!iommufd_change_process_capable(be)) { + error_report("some memory regions do not support " + "IOMMU_IOAS_CHANGE_PROCESS"); + return -1; + } + return 0; +} + +static int iommufd_cpr_post_load(void *opaque, int version_id) +{ + IOMMUFDBackend *be =3D opaque; + Error *local_err =3D NULL; + + if (!iommufd_change_process(be, &local_err)) { + error_report_err(local_err); + return -1; + } + return 0; +} + static const VMStateDescription iommufd_cpr_vmstate =3D { .name =3D "iommufd", .version_id =3D 0, .minimum_version_id =3D 0, + .pre_save =3D iommufd_cpr_pre_save, + .post_load =3D iommufd_cpr_post_load, .needed =3D cpr_incoming_needed, .fields =3D (VMStateField[]) { VMSTATE_END_OF_LIST() --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751618849; cv=none; d=zohomail.com; s=zohoarc; b=jpJVsittN3uZZpa3hyJ1x/kqWLJljyIhnUACpVNMf8nDPGhGhH5zLoYRm9upZBQDltBSrOO+3jG8PIpZGD+LbDoH97Ez6xJCufssXxhaB+S4ZD18LEEZ1JMI2k2n7jmK04a3rCOPgecUhtTED9tFMjgMb6osjLpzLR2y8r+z3Yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751618849; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ua90FsLL79bWLK7qZojZP6bHT3h6nnQRWQmKZajp2ts=; b=JFQlQ9JsSZwk51HeI7LQg7UGzmmq9MWDAgdmUYQuBLlVa6pnmHz4BIlqZv2V/c4Dt5K1TjftaZfNb7a4V/bZySlNwyiBro2nfHW+bTlw/FtvQYKc4NI4JIJ+41OWATIKNcAQWQPyOtQPZhYlkDCSl7GEachFG3I2Xu1LAcQXbxE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751618849214211.70396028818573; Fri, 4 Jul 2025 01:47:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4W-0000oL-LP; Fri, 04 Jul 2025 04:47:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4F-0000QW-Hy for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4D-0001OC-Pe for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:47 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-Eant6zulMna0LShh_8_dKw-1; Fri, 04 Jul 2025 04:46:43 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62EEB1800343; Fri, 4 Jul 2025 08:46:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1608119560A7; Fri, 4 Jul 2025 08:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ua90FsLL79bWLK7qZojZP6bHT3h6nnQRWQmKZajp2ts=; b=JIoyXkrG06+/W8QN1mKSl+XUpeSy7vrs7/FpNgU6lBQJDs1ozjqxmFNZ2TwdYoGRFzRbyE C4DbHPrlsHobLV+FqJwaNwtu5P0v3DHbDFGIO1QlBje8mJmC0K3GBH8cFMTv+TfE3eL8qb +vlNbEhFVLsGFg2u0AqLVi04RJst+/U= X-MC-Unique: Eant6zulMna0LShh_8_dKw-1 X-Mimecast-MFC-AGG-ID: Eant6zulMna0LShh_8_dKw_1751618802 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 25/27] iommufd: preserve DMA mappings Date: Fri, 4 Jul 2025 10:45:26 +0200 Message-ID: <20250704084528.1412959-26-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751618851538116600 From: Steve Sistare During cpr-transfer load in new QEMU, the vfio_memory_listener causes spurious calls to map and unmap DMA regions, as devices are created and the address space is built. This memory was already already mapped by the device in old QEMU, so suppress the map and unmap callbacks during incoming CPR. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/1751493538-202042-20-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- backends/iommufd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backends/iommufd.c b/backends/iommufd.c index e0917923bffbb60dc5c58235880335c4d5eb7df7..2a33c7ab0bcdc9aabda55258741= 022debab0bdad 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -245,6 +245,10 @@ int iommufd_backend_map_file_dma(IOMMUFDBackend *be, u= int32_t ioas_id, .length =3D size, }; =20 + if (cpr_is_incoming()) { + return 0; + } + if (!readonly) { map.flags |=3D IOMMU_IOAS_MAP_WRITEABLE; } @@ -274,6 +278,10 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint= 32_t ioas_id, .length =3D size, }; =20 + if (cpr_is_incoming()) { + return 0; + } + ret =3D ioctl(fd, IOMMU_IOAS_UNMAP, &unmap); /* * IOMMUFD takes mapping as some kind of object, unmapping --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619087; cv=none; d=zohomail.com; s=zohoarc; b=De9dNk8sMINXQCWqcYIEmF+fEXDlKorgdrhNJxdIQ9Hvpm0vSARHwFVXp00/6+67GEifDkM1zdcIbeEgjyYUWWHvlH9S0jFqiAbGB7f2uFgRxYCS2PNgUqzOpmmhRYpTmhhs3jyU+MNcekQIzRPOk05zsWUkMy57tR1hzOq5IjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619087; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CCPfFcP9oUXLZaiFPDdAPRro3sCjt0xf3z+EAHTgsxo=; b=FK3WZ5waT5SNsuA1aydyg3ulZJnZM7c1KKqSGojybkr5qj2r7Chk7D1kG5dWtysfOXbDVFvy/lpULG4Fkwn4P02s0/xBwJJRpo7BUOKobY4Gn/XKlhmIfvvZH/y+8YRG8tq/Cv1Un04OfGBn+l4uScbcKLPiVA1JuH3dbE5dHNs= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619087261609.0614070732508; Fri, 4 Jul 2025 01:51:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4c-00013q-OU; Fri, 04 Jul 2025 04:47:11 -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 1uXc4I-0000Rg-JZ for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4G-0001TF-9U for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:49 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-b3e20PBPMayy0-Wff0XAYg-1; Fri, 04 Jul 2025 04:46:46 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64167180028D; Fri, 4 Jul 2025 08:46:45 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 60B0B195E74A; Fri, 4 Jul 2025 08:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CCPfFcP9oUXLZaiFPDdAPRro3sCjt0xf3z+EAHTgsxo=; b=CjROZgHxJ6pxKH+ZX4GHHeN1lNwkYS1EJktciI3ydDGSxQayJvngi1lKcZVjw7Axhm/+cv UCTYJzTuT6pMHcDORov6xR1VAP/ZfmvguznzPqs5LIbdUJVMQEn7mWRebJkzKzjxDfOC1g GZ37nKc1F+00vYBWGkP4yZeGnxdIrTQ= X-MC-Unique: b3e20PBPMayy0-Wff0XAYg-1 X-Mimecast-MFC-AGG-ID: b3e20PBPMayy0-Wff0XAYg_1751618805 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 26/27] vfio/container: delete old cpr register Date: Fri, 4 Jul 2025 10:45:27 +0200 Message-ID: <20250704084528.1412959-27-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619088214116600 From: Steve Sistare vfio_cpr_[un]register_container is no longer used since they were subsumed by container type-specific registration. Delete them. Signed-off-by: Steve Sistare Reviewed-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/1751493538-202042-21-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-cpr.h | 4 ---- hw/vfio/cpr.c | 13 ------------- 2 files changed, 17 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index 287837249589e269f87e33ba2635e8682a764e82..80ad20d2169086052b66d0df526= 406b8de7985d4 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -45,10 +45,6 @@ void vfio_legacy_cpr_unregister_container(struct VFIOCon= tainer *container); int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier, MigrationEvent = *e, Error **errp); =20 -bool vfio_cpr_register_container(struct VFIOContainerBase *bcontainer, - Error **errp); -void vfio_cpr_unregister_container(struct VFIOContainerBase *bcontainer); - bool vfio_iommufd_cpr_register_container(struct VFIOIOMMUFDContainer *cont= ainer, Error **errp); void vfio_iommufd_cpr_unregister_container( diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 0e903cdd2f7071a363eecd4ec8784b6f9c8f7e1d..af0f12a7adf5a3bc331afcedae3= a4e23309e4d2e 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -29,19 +29,6 @@ int vfio_cpr_reboot_notifier(NotifierWithReturn *notifie= r, return 0; } =20 -bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp) -{ - migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier, - vfio_cpr_reboot_notifier, - MIG_MODE_CPR_REBOOT); - return true; -} - -void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer) -{ - migration_remove_notifier(&bcontainer->cpr_reboot_notifier); -} - #define STRDUP_VECTOR_FD_NAME(vdev, name) \ g_strdup_printf("%s_%s", (vdev)->vbasedev.name, (name)) =20 --=20 2.50.0 From nobody Sat Dec 13 22:48:54 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1751619211; cv=none; d=zohomail.com; s=zohoarc; b=N3TJVF4Dkm1EYDaCEG5Kkk2U+qZyIThMHO15KSZES/7dr29J4Gev/DRnqfaB5Kk9JeQoo9arHpQB76Sf3bqZJKw82gja9YaeQJneJdRJfp6Qn1xhappvzFWY51OLkvDfRCs6TM7AHhf46nKZQPfqkB++XxQrA8TEWEEnPaKtaok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751619211; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wdgzniatKvacCN5OOUKzv155pnYD6csvOM5DcHK/tos=; b=d1tbQgy6em7m4iQrhNRVqg6OcIRLm9XnU0+cVPD4yi/i31zcBuFPdB9ldMIaSpunkXdJzoTciYTQBSs8L5zCfmMk2Oel4xs/CqL1HqbPjCI4aMM9qti1Vbkid4s16UZGZgsd9DhS96Xx0rP4k3oRnXRN+xSefwOa9o9A8v+kPkI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1751619211036982.0547598498324; Fri, 4 Jul 2025 01:53:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uXc4d-0001AQ-Lr; Fri, 04 Jul 2025 04:47:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4O-0000Yb-M6 for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uXc4M-0001ab-Bz for qemu-devel@nongnu.org; Fri, 04 Jul 2025 04:46:55 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-294-2jjezp29PP6QkWM6ABW47g-1; Fri, 04 Jul 2025 04:46:49 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CE344180028A; Fri, 4 Jul 2025 08:46:48 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E18F419560A7; Fri, 4 Jul 2025 08:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751618813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wdgzniatKvacCN5OOUKzv155pnYD6csvOM5DcHK/tos=; b=IFyPogOS3zhaZT/oXcRBcmoYiqzQBIjGSU+jSC6CpCvomeJzbiWOMZ6seHqIASZMpDVRxD L+ysGPcxqET/6Sv7kxmgMkAtCSTIMxzXzNF3i5hc6H8zj08MJCCtAf+yDTt2zIlc+K8AJC oyOtLyD/wP7mQuim7WZ/zFRX2SlUaMw= X-MC-Unique: 2jjezp29PP6QkWM6ABW47g-1 X-Mimecast-MFC-AGG-ID: 2jjezp29PP6QkWM6ABW47g_1751618808 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Steve Sistare , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Fabiano Rosas Subject: [PULL 27/27] vfio: doc changes for cpr Date: Fri, 4 Jul 2025 10:45:28 +0200 Message-ID: <20250704084528.1412959-28-clg@redhat.com> In-Reply-To: <20250704084528.1412959-1-clg@redhat.com> References: <20250704084528.1412959-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1751619211552116600 From: Steve Sistare Update documentation to say that cpr-transfer supports vfio and iommufd. Signed-off-by: Steve Sistare Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas Link: https://lore.kernel.org/qemu-devel/1751493538-202042-22-git-send-emai= l-steven.sistare@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- docs/devel/migration/CPR.rst | 5 ++--- qapi/migration.json | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/devel/migration/CPR.rst b/docs/devel/migration/CPR.rst index 7897873c86e6cfdf9760a26a3c150d05d02b7518..0a0fd4f6dc31912b6f5ad52d8bc= e7b4d36da0e9f 100644 --- a/docs/devel/migration/CPR.rst +++ b/docs/devel/migration/CPR.rst @@ -152,8 +152,7 @@ cpr-transfer mode This mode allows the user to transfer a guest to a new QEMU instance on the same host with minimal guest pause time, by preserving guest RAM in place, albeit with new virtual addresses in new QEMU. Devices -and their pinned memory pages will also be preserved in a future QEMU -release. +and their pinned memory pages are also preserved for VFIO and IOMMUFD. =20 The user starts new QEMU on the same host as old QEMU, with command- line arguments to create the same machine, plus the ``-incoming`` @@ -322,6 +321,6 @@ Futures =20 cpr-transfer mode is based on a capability to transfer open file descriptors from old to new QEMU. In the future, descriptors for -vfio, iommufd, vhost, and char devices could be transferred, +vhost, and char devices could be transferred, preserving those devices and their kernel state without interruption, even if they do not explicitly support live migration. diff --git a/qapi/migration.json b/qapi/migration.json index 4963f6ca1275b60ee6dc86948f7f6f7d6c42aeee..e8a7d3b2a95cf932d2e697756f1= 50d28e23f0439 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -620,8 +620,10 @@ # # @cpr-transfer: This mode allows the user to transfer a guest to a # new QEMU instance on the same host with minimal guest pause -# time by preserving guest RAM in place. Devices and their pinned -# pages will also be preserved in a future QEMU release. +# time by preserving guest RAM in place. +# +# Devices and their pinned pages are also preserved for VFIO and +# IOMMUFD. (since 10.1) # # The user starts new QEMU on the same host as old QEMU, with # command-line arguments to create the same machine, plus the --=20 2.50.0