From nobody Fri Dec 19 13:24:55 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=1689147807; cv=none; d=zohomail.com; s=zohoarc; b=bEnoW6ZRO8fJFzIo2bR8Y+co67/9SS+cwfPcgZKlv//0vykmcXbtigDc/FWJGUYIzBL15t2GbDwWe5brzotPiNxr1qNEscD85aLuL+LFVFQ0SokFW0XXmG4aAWMJI+41htQHvrQledpbulY4ECx/HynornmFyOJXBDbAquj6iWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689147807; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cn1sSDfamkk9cPXI+BQEgvlMCYoO64fJ+UCPniaNJBs=; b=T7tjxMJMG+mkYTTW6jR3IqJiStY9Pp6KX2U4jXG4FiidsZ38B0P4ciUazaAViHhOmKfZx6YFq7xQB12sY7eFYPxPf+zrhI4I87EdiCssJDxThdc+bChEnS2vyj34R1ciuupjT7bjCArPwnn/VUHQ8QShgcxsYtvM9teTarkrLrI= 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 1689147807272547.1311498836657; Wed, 12 Jul 2023 00:43:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJUTA-00072f-3a; Wed, 12 Jul 2023 03:41:04 -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 1qJUSq-0006eW-NR for qemu-devel@nongnu.org; Wed, 12 Jul 2023 03:40:48 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJUSm-0006qy-Hm for qemu-devel@nongnu.org; Wed, 12 Jul 2023 03:40:44 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:40:15 -0700 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.147]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:40:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689147640; x=1720683640; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KHXRXNWf+zNNMgCNyiIVRGRuGjopqW7tqQLMHau6IdM=; b=K1fNh/8dGDFb+vGuImyHLi/lSDbjl8ZhuamKo//TIa/Gw99KUz0RiCkW u7utXhT5um53jlgM6ETxcKevBd2r83plQyJQJdQV2YSjsFouT6lG/mEVi JbFJ6T3ENtyqTz5A606fZHc2mIENz5Hll9lRWMC98Rkb5JIGKOg3ig0/b tAth0qLaG6WyjtlBVtgRAVkMjK+qwK5t2ei1U+gYABAUSPAy/sC7LDOmi e9CnxoTOET0JT+qDW2mVFp1uGq95gthO2IiD+TgYidZLRo6m56+JuMKTr 7DiSko8t7kjKJLWUXQ6DEUOtMXHeFo0JeYS9qhV0NeFHGKsIDW0r6dXDd A==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="430953858" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="430953858" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="835024140" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="835024140" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, eric.auger@redhat.com, peterx@redhat.com, jasonwang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [RFC PATCH v4 21/24] vfio/as: Add vfio device iterator callback for iommufd Date: Wed, 12 Jul 2023 15:25:25 +0800 Message-Id: <20230712072528.275577-22-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230712072528.275577-1-zhenzhong.duan@intel.com> References: <20230712072528.275577-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=134.134.136.100; envelope-from=zhenzhong.duan@intel.com; helo=mga07.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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1689147808585100005 Content-Type: text/plain; charset="utf-8" The way to get vfio device pointer is different between legacy container and iommufd container, with iommufd backend support added, it's time to add the iterator support for iommufd. In order to implement it, a pointer to hwpt is added in vbasedev. Signed-off-by: Zhenzhong Duan --- hw/vfio/iommufd.c | 31 +++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 32 insertions(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 286ad0b766..e532eed2ac 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -36,6 +36,34 @@ #include "qemu/cutils.h" #include "qemu/char_dev.h" =20 +static VFIODevice *iommufd_dev_iter_next(VFIOContainer *bcontainer, + VFIODevice *curr) +{ + + VFIOIOASHwpt *hwpt; + + assert(object_class_dynamic_cast(OBJECT_CLASS(bcontainer->ops), + TYPE_VFIO_IOMMU_BACKEND_IOMMUFD_OPS)); + + VFIOIOMMUFDContainer *container =3D container_of(bcontainer, + VFIOIOMMUFDContainer, + bcontainer); + + if (!curr) { + hwpt =3D QLIST_FIRST(&container->hwpt_list); + } else { + if (curr->next.le_next) { + return curr->next.le_next; + } + hwpt =3D curr->hwpt->next.le_next; + } + + if (!hwpt) { + return NULL; + } + return QLIST_FIRST(&hwpt->device_list); +} + static int iommufd_map(VFIOContainer *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly) { @@ -218,6 +246,7 @@ static void vfio_device_detach_container(VFIODevice *vb= asedev, hwpt =3D vfio_find_hwpt_for_dev(container, vbasedev); if (hwpt) { QLIST_REMOVE(vbasedev, next); + vbasedev->hwpt =3D NULL; if (QLIST_EMPTY(&hwpt->device_list)) { vfio_container_put_hwpt(hwpt); } @@ -281,6 +310,7 @@ static int vfio_device_attach_container(VFIODevice *vba= sedev, hwpt =3D vfio_container_get_hwpt(container, attach_data.pt_id); =20 QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, next); + vbasedev->hwpt =3D hwpt; return 0; } =20 @@ -490,6 +520,7 @@ static void vfio_iommu_backend_iommufd_ops_class_init(O= bjectClass *oc, void *data) { VFIOIOMMUBackendOpsClass *ops =3D VFIO_IOMMU_BACKEND_OPS_CLASS(oc); =20 + ops->dev_iter_next =3D iommufd_dev_iter_next; ops->dma_map =3D iommufd_map; ops->dma_unmap =3D iommufd_unmap; ops->attach_device =3D iommufd_attach_device; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 6434a442fd..d596e802b0 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -133,6 +133,7 @@ typedef struct VFIODevice { #ifdef CONFIG_IOMMUFD int devid; IOMMUFDBackend *iommufd; + VFIOIOASHwpt *hwpt; #endif } VFIODevice; =20 --=20 2.34.1