From nobody Sat Nov 15 06:34:11 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=1754015359; cv=none; d=zohomail.com; s=zohoarc; b=ldcRR5GXOAx7eXjKPtC/CTMUTbnqlz3vGcJIZV4PHVktg1eTDPE005Ol25lNjj3UoWGeH8n5oaDlEMnh3Qzn2eqKiTsKO/SMQsdojtcSltZbLEcE9l8ChJSo+ej4YO5lWddC+cjvq29Mmbt2Jmonlxw06gi9MsNXblzYyUzG67s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754015359; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L/oY8waTEJlbC6nj/AyHq5iRJskruPCVNEp91mIGxwc=; b=Q368Nz4dRGTKKSr+Egr7PqFQD99gw7bLrzJdrIokHJ5ETEVc5hV5q7AF8iPQ9wDDpUQnuSoQ6raRULbR0yCOq9rP/weRTVcxBHobaXRDZcdamVAWwbepZijVqxa9vLQKmZOResnqGlxt1T2ib+SOLAzrt0+DX377K1CSE6tShMc= 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 1754015359091387.04549614397126; Thu, 31 Jul 2025 19:29:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uhfVK-0006uE-9g; Thu, 31 Jul 2025 22:28: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 1uhfV8-0006s6-5y for qemu-devel@nongnu.org; Thu, 31 Jul 2025 22:28:06 -0400 Received: from mgamail.intel.com ([198.175.65.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uhfV0-0003ar-3w for qemu-devel@nongnu.org; Thu, 31 Jul 2025 22:28:01 -0400 Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2025 19:27:50 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2025 19:27:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1754015278; x=1785551278; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/XifMCmwp6uRTNmX31C1T0NZmjpQHm31KL08Qui61HU=; b=lRq9c4pQKO8+DxNkpY3dbNWlNshZ+BKO13jaGvOHetjhAZ11xNhJJ0I8 q0a3nr8VvQsA/S2myVPG2f/eCpmIqH05vfX3nwPnxZR0FIuq8uE/XcwvV q6GaF6HQneBr3krjNi+kP4Zr6W4G77/aKppgjS+EPzrTHGhud51etGMaM wBnx1ywo2w0XGrFJ1imCQL9IrYNIdqfvvbfLYHBWwZMBeK3sfMMV0/XEO 8f5CDKBmkMywA9GB/jJcUeGUdz15RYv86ju9tJ/N9zwt433uSFyPN/Fpq 6CqDX72CeHxQo73nsGGAM6HnkX8b4mKvfi8neFZrzuiZV7+Ie+MJ2x+bB Q==; X-CSE-ConnectionGUID: XSRpF3MdTFeZJCLMxqzyBw== X-CSE-MsgGUID: sRgG7UiDQsKqCPdotVCp6A== X-IronPort-AV: E=McAfee;i="6800,10657,11508"; a="56243144" X-IronPort-AV: E=Sophos;i="6.17,255,1747724400"; d="scan'208";a="56243144" X-CSE-ConnectionGUID: kWMdjM+OSYKEJKXzRJsUZg== X-CSE-MsgGUID: 9a7G0WD0TKWTxhg69aDgfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,255,1747724400"; d="scan'208";a="167905623" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2] vfio: Introduce helper vfio_pci_from_vfio_device() Date: Thu, 31 Jul 2025 22:27:32 -0400 Message-ID: <20250801022732.1457628-1-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=198.175.65.21; 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_CERTIFIED_BLOCKED=0.001, 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 @intel.com) X-ZM-MESSAGEID: 1754015361202116600 Introduce helper vfio_pci_from_vfio_device() to transform from VFIODevice to VFIOPCIDevice, also to hide low level VFIO_DEVICE_TYPE_PCI type check. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- v2: move helper to hw/vfio/pci.[hc] rename with vfio_pci_ prefix hw/vfio/pci.h | 1 + hw/vfio/container.c | 4 ++-- hw/vfio/device.c | 2 +- hw/vfio/iommufd.c | 4 ++-- hw/vfio/listener.c | 4 ++-- hw/vfio/pci.c | 8 ++++++++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 81465a8214..53842cb149 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -219,6 +219,7 @@ void vfio_pci_write_config(PCIDevice *pdev, uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size); void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned siz= e); =20 +VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev); void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev); bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev); bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 3e13feaa74..134ddccc52 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1087,7 +1087,7 @@ static int vfio_legacy_pci_hot_reset(VFIODevice *vbas= edev, bool single) /* Prep dependent devices for reset and clear our marker. */ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (!vbasedev_iter->dev->realized || - vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + !vfio_pci_from_vfio_device(vbasedev_iter)) { continue; } tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); @@ -1172,7 +1172,7 @@ out: =20 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (!vbasedev_iter->dev->realized || - vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + !vfio_pci_from_vfio_device(vbasedev_iter)) { continue; } tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 52a1996dc4..08f12ac31f 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -129,7 +129,7 @@ static inline const char *action_to_str(int action) =20 static const char *index_to_str(VFIODevice *vbasedev, int index) { - if (vbasedev->type !=3D VFIO_DEVICE_TYPE_PCI) { + if (!vfio_pci_from_vfio_device(vbasedev)) { return NULL; } =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 48c590b6a9..8c27222f75 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -737,8 +737,8 @@ iommufd_cdev_dep_get_realized_vpdev(struct vfio_pci_dep= endent_device *dep_dev, } =20 vbasedev_tmp =3D iommufd_cdev_pci_find_by_devid(dep_dev->devid); - if (!vbasedev_tmp || !vbasedev_tmp->dev->realized || - vbasedev_tmp->type !=3D VFIO_DEVICE_TYPE_PCI) { + if (!vfio_pci_from_vfio_device(vbasedev_tmp) || + !vbasedev_tmp->dev->realized) { return NULL; } =20 diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index f498e23a93..903dfd8bf2 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -450,7 +450,7 @@ static void vfio_device_error_append(VFIODevice *vbased= ev, Error **errp) * MMIO region mapping failures are not fatal but in this case PCI * peer-to-peer transactions are broken. */ - if (vbasedev && vbasedev->type =3D=3D VFIO_DEVICE_TYPE_PCI) { + if (vfio_pci_from_vfio_device(vbasedev)) { error_append_hint(errp, "%s: PCI peer-to-peer transactions " "on BARs are not supported.\n", vbasedev->name); } @@ -751,7 +751,7 @@ static bool vfio_section_is_vfio_pci(MemoryRegionSectio= n *section, owner =3D memory_region_owner(section->mr); =20 QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { - if (vbasedev->type !=3D VFIO_DEVICE_TYPE_PCI) { + if (!vfio_pci_from_vfio_device(vbasedev)) { continue; } pcidev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4fa692c1a3..fb339512ba 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2824,6 +2824,14 @@ static int vfio_pci_load_config(VFIODevice *vbasedev= , QEMUFile *f) return ret; } =20 +VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *vbasedev) +{ + if (vbasedev && vbasedev->type =3D=3D VFIO_DEVICE_TYPE_PCI) { + return container_of(vbasedev, VFIOPCIDevice, vbasedev); + } + return NULL; +} + void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev) { PCIDevice *pdev =3D &vdev->pdev; --=20 2.47.1