From nobody Wed Nov 27 09:51:55 2024 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=1699957705; cv=none; d=zohomail.com; s=zohoarc; b=Ds1RIsIjpbCpZwEK/EvLqIFt5A9aTt24L0MmcZRbHAxt18qTpf2MDYtKyESR0Lg5YB3ic/PVtjt3bIkHAZMSZyq0+6/yFuGQx08uuHjBH98ZZCGhQ+dG3RlxIcg91GzKD56ZRGsPHyBSCi+E+tqSEk8BREKNYWbGV9TNmnJVOg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699957705; 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=Uf0olqPl5uIiIrqpVgcUhflp73BaUfQ8uWsZsDd+wmM=; b=aGXqJDvginEJAqNlOKP0pFqtq31pUQxZwPFofxfuEF0Noi8Yg7ArAn0NR9XNljY5AfopWS+k4CgniCzSeRsLSMiBNtatMPGVZP/6e0hjx84gmplSRi3/0ROYqu1XMphJyG/6hDlrQ/LP0XSjzqT7MlOQOWV9i62lRCz3kP1ovro= 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 1699957705613282.1571064531944; Tue, 14 Nov 2023 02:28:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2qcP-0003At-Fk; Tue, 14 Nov 2023 05:26:05 -0500 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 1r2qcK-00036z-3H for qemu-devel@nongnu.org; Tue, 14 Nov 2023 05:26:00 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2qcI-0007i0-99 for qemu-devel@nongnu.org; Tue, 14 Nov 2023 05:25:59 -0500 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 02:25:56 -0800 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.147]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 02:25:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699957558; x=1731493558; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LQv/3rZNZ3in5A5oE3V6Vys9V8Colat4lrcDJfGO1Jw=; b=bZ8jegEpACH4UFR8fZAYY3JhKwKSKEJ/0il2GZsRepv6RewemBJmG9rC XEwPulEwagODy7u4Xi+BNPtyPqsHPwi8MaDVkposVyWFOyQn+u1OmyrS3 ve5DDz3YQutcSscgY2w2dwilXzZ6l4j45z1+EwgbFc9dlISjthYReXayG 5iGTkbbNpe6u6ceCbS3Fq3SxcSRN/6gvPhRYp1U3DW5725REVR+x8RSt9 f2UHSLOsiLQ5MTvTt86cot3qjnIqWjv/8P6fDXVXXSqEsVLmzODCi7ku3 2ej+sUVXP0GqzgQT5kARJ+4ychQClcD6k6HCp6xZfDK1uYlFOauWY0IpO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10893"; a="394543470" X-IronPort-AV: E=Sophos;i="6.03,301,1694761200"; d="scan'208";a="394543470" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10893"; a="888212919" X-IronPort-AV: E=Sophos;i="6.03,301,1694761200"; d="scan'208";a="888212919" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v6 07/21] vfio/pci: Extract out a helper vfio_pci_get_pci_hot_reset_info Date: Tue, 14 Nov 2023 18:09:41 +0800 Message-Id: <20231114100955.1961974-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231114100955.1961974-1-zhenzhong.duan@intel.com> References: <20231114100955.1961974-1-zhenzhong.duan@intel.com> 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=134.134.136.65; 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, 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: 1699957705978100001 This helper will be used by both legacy and iommufd backends. No functional changes intended. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- hw/vfio/pci.h | 3 +++ hw/vfio/pci.c | 54 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index fba8737ab2..1006061afb 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -218,6 +218,9 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 +int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **info_= p); + int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c62c02f7b6..eb55e8ae88 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2445,22 +2445,13 @@ static bool vfio_pci_host_match(PCIHostDeviceAddres= s *addr, const char *name) return (strcmp(tmp, name) =3D=3D 0); } =20 -static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) +int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **info_= p) { - VFIOGroup *group; struct vfio_pci_hot_reset_info *info; - struct vfio_pci_dependent_device *devices; - struct vfio_pci_hot_reset *reset; - int32_t *fds; - int ret, i, count; - bool multi =3D false; + int ret, count; =20 - trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); - - if (!single) { - vfio_pci_pre_reset(vdev); - } - vdev->vbasedev.needs_reset =3D false; + assert(info_p && !*info_p); =20 info =3D g_malloc0(sizeof(*info)); info->argsz =3D sizeof(*info); @@ -2468,24 +2459,53 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, = bool single) ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, i= nfo); if (ret && errno !=3D ENOSPC) { ret =3D -errno; + g_free(info); if (!vdev->has_pm_reset) { error_report("vfio: Cannot reset device %s, " "no available reset mechanism.", vdev->vbasedev.n= ame); } - goto out_single; + return ret; } =20 count =3D info->count; - info =3D g_realloc(info, sizeof(*info) + (count * sizeof(*devices))); - info->argsz =3D sizeof(*info) + (count * sizeof(*devices)); - devices =3D &info->devices[0]; + info =3D g_realloc(info, sizeof(*info) + (count * sizeof(info->devices= [0]))); + info->argsz =3D sizeof(*info) + (count * sizeof(info->devices[0])); =20 ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, i= nfo); if (ret) { ret =3D -errno; + g_free(info); error_report("vfio: hot reset info failed: %m"); + return ret; + } + + *info_p =3D info; + return 0; +} + +static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) +{ + VFIOGroup *group; + struct vfio_pci_hot_reset_info *info =3D NULL; + struct vfio_pci_dependent_device *devices; + struct vfio_pci_hot_reset *reset; + int32_t *fds; + int ret, i, count; + bool multi =3D false; + + trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); + + if (!single) { + vfio_pci_pre_reset(vdev); + } + vdev->vbasedev.needs_reset =3D false; + + ret =3D vfio_pci_get_pci_hot_reset_info(vdev, &info); + + if (ret) { goto out_single; } + devices =3D &info->devices[0]; =20 trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); =20 --=20 2.34.1