From nobody Sat Nov 15 16:34:21 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1750674436; cv=none; d=zohomail.com; s=zohoarc; b=KNZ2jVhCno9JZcnN3yDqyMY8anezu7PkjuT26/ljGKFPyhByIAPsHI+APIEEvZFPqU6OYEhHCvtlwqKwBMuf+KbiD2PAtH5nDD2giZ0audxUaQUirf7V/jjGxSfRMDjOVMZLnD/wj5uiUdGS3vWsf/qHt8THfdDxt9uXUa8zdJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1750674436; h=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=zBJdGVosk9ryW62O9dmfPOosoxhyE7eUyarH1NmgZjI=; b=H+DCHGVGqidTrxBdjqeqo6nMmyJhhgWnSrGh7qeKmmg+9lbsnpOTvVX0QaT8alhZEUEgy3VW9Ty/jd8QK1RsavfPvpsGAvUV2ikvWGTHYGIezHf5OI9uhIANpFTad66pUW+IOrEOG+j99v6p5pvFaud7tgfnHqSCpGNPrfPVo9U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1750674436104717.087156150818; Mon, 23 Jun 2025 03:27:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uTeNv-00061x-Ul; Mon, 23 Jun 2025 06:26:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uTeNu-0005yO-J4 for qemu-devel@nongnu.org; Mon, 23 Jun 2025 06:26:42 -0400 Received: from mgamail.intel.com ([192.198.163.9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uTeNr-0000l4-Lj for qemu-devel@nongnu.org; Mon, 23 Jun 2025 06:26:41 -0400 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2025 03:26:37 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2025 03:26:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750674399; x=1782210399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JV8/tKIjtQekCcqphu512/XnCCpL9Gbwuue5YmsnoZE=; b=H3fzKKp7uBV73YoWDHwWqX4TQVEDX157B1vm6CGa8PDIZbftgJI2UfZ+ UO+wxrcdjVLQzbK+b6FxV9f8jINgHP0P6kpuf56DDW6RLmV2oqxrRXfpq qye1TtBIWm6ur4etUqYQb/xY7DpveN0aINPQfuQbzM3QCKQvOW3ISqTvv IsiwQmX8V/SMYjM60+Sn197YQ9GwLTzH5re3e4UCcqVqMKqYOl+JDie/5 EQqV+ZLOzq3GhLMNOyPTazgX1NMUeoxlD4m8dJKhORycgOsJ6iDwQc6oK iQFdiKu9E0YOhmiFSouMISD7/yNek99XQ34bIG/9sdNMwsT9ys2QYoIvH A==; X-CSE-ConnectionGUID: SDhFbfwURb2DwhYmdVunmA== X-CSE-MsgGUID: 9koHa9vRRYyQLYdkURqGXw== X-IronPort-AV: E=McAfee;i="6800,10657,11472"; a="63565469" X-IronPort-AV: E=Sophos;i="6.16,258,1744095600"; d="scan'208";a="63565469" X-CSE-ConnectionGUID: cUj+0b/yS2uJRtiaPt8Leg== X-CSE-MsgGUID: AB91I+O7Rs6X46vTeja4RQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,258,1744095600"; d="scan'208";a="182427963" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, steven.sistare@oracle.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH 4/4] vfio/container: Fix vfio_container_post_load() Date: Mon, 23 Jun 2025 18:22:35 +0800 Message-Id: <20250623102235.94877-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250623102235.94877-1-zhenzhong.duan@intel.com> References: <20250623102235.94877-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.198.163.9; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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 @intel.com) X-ZM-MESSAGEID: 1750674437174116600 Content-Type: text/plain; charset="utf-8" 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 --- include/hw/vfio/vfio-cpr.h | 1 - hw/vfio/cpr-legacy.c | 20 +++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h index aef542e93c..71a1c1a70c 100644 --- a/include/hw/vfio/vfio-cpr.h +++ b/include/hw/vfio/vfio-cpr.h @@ -25,7 +25,6 @@ typedef struct VFIOContainerCPR { bool vaddr_unmapped; NotifierWithReturn transfer_notifier; MemoryListener remap_listener; - DMA_MAP_FUNC saved_dma_map; } VFIOContainerCPR; =20 typedef struct VFIODeviceCPR { diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c index 100a8db74d..ff45a5128f 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_FUNC 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 @@ -180,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. */ - 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; - } - migration_add_notifier_mode(&container->cpr.transfer_notifier, vfio_cpr_fail_notifier, MIG_MODE_CPR_TRANSFER); --=20 2.34.1