From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564184; cv=none; d=zohomail.com; s=zohoarc; b=T2hzG1MQGFaoixuvhAK9ShpqQzv35gsf2HhhnDwPMFVrOnaj932HXuxy/qOMWSMTR11UHLI+X1jTnoAIZUCseX3qEzU85V7fbt7F2nR4JHHq6753FNIoiarImf7rbDVtO7oe92TWr1Kc7N4ZD8yG97ua2cXGB4vLvK8+bBuSZd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564184; 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=7a5OZPwEYdi8B8ZrYujAzNcgcXtrf+BtstuvH6UevYI=; b=hnCkDnI2AUCTGHszmfMwt+TRu6s89kPjQLSej1j3vG33a1h/jWKAUZ2sJJfT+Xa1ozbAjfFNvdKPCw5MIXxRG6rdDhkJPXanS0GwqEVQcjlvzBR98kPtdU1YJWBQCtPhqN5XjlabeoZjJAj+u7dcrlYxrvae8itQ7J7H0hjGUwQ= 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+importer2=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 1712564184523655.5511364953059; Mon, 8 Apr 2024 01:16:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtk9q-0002qD-9I; Mon, 08 Apr 2024 04:15:14 -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 1rtk9o-0002mX-6b for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:12 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtk9l-00088l-93 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:11 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:07 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564109; x=1744100109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wykm8CTdvs/a63yu30J9vOfyYa6zOvbij1LOSE5uNY0=; b=Frg0stdvjDGrSjSlNM/DjUiPTbe0+grjfNEdqUwfHFj+XDxlYWPLRkt9 UhgWhuJnN4Lo9Ad8d2w0bE8uVg+kWEHx4qswROjG0tqInhRr8KJQz//4R BChNXaWEUxQVDwcPHpQp6qp9cgs6q19TRj/xArkzZsqPK5BMxaP+MFrFR bMJYUslih+3sldKcBevb2DXYRSV7otBDzRsx7p1q87OdddjewqR3suon/ oWaF3DlWe+uXq7JrrbgakGFdh46rDs5qi4KBXxuV3u13mjvBbuOtW5LYT BBPBhN2h/0+s6tLoD+kIfidM4jno9xsD+MxoL+l0awqT9e3okjzbCu+CI w==; X-CSE-ConnectionGUID: DEm5sQyBS/27OiXiUhI7Ug== X-CSE-MsgGUID: wnNE+OFRQVq7Cnl3nXR2Eg== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199660" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199660" X-CSE-ConnectionGUID: uA+19ALmRUi0BuSiAzEreQ== X-CSE-MsgGUID: nyHeRnZ9QP+qXdTzXmjSJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845170" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Paolo Bonzini Subject: [PATCH v2 01/10] backends: Introduce abstract HostIOMMUDevice Date: Mon, 8 Apr 2024 16:12:21 +0800 Message-Id: <20240408081230.1030078-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564186532100007 Introduce HostIOMMUDevice as an abstraction of host IOMMU device. get_host_iommu_info() is used to get host IOMMU info, different backends can have different implementations and result format. Introduce a macro CONFIG_HOST_IOMMU_DEVICE to define the usage for VFIO, and VDPA in the future. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- MAINTAINERS | 2 ++ include/sysemu/host_iommu_device.h | 19 +++++++++++++++++++ backends/host_iommu_device.c | 19 +++++++++++++++++++ backends/Kconfig | 5 +++++ backends/meson.build | 1 + 5 files changed, 46 insertions(+) create mode 100644 include/sysemu/host_iommu_device.h create mode 100644 backends/host_iommu_device.c diff --git a/MAINTAINERS b/MAINTAINERS index e71183eef9..22f71cbe02 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2202,6 +2202,8 @@ M: Zhenzhong Duan S: Supported F: backends/iommufd.c F: include/sysemu/iommufd.h +F: backends/host_iommu_device.c +F: include/sysemu/host_iommu_device.h F: include/qemu/chardev_open.h F: util/chardev_open.c F: docs/devel/vfio-iommufd.rst diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h new file mode 100644 index 0000000000..22ccbe3a5d --- /dev/null +++ b/include/sysemu/host_iommu_device.h @@ -0,0 +1,19 @@ +#ifndef HOST_IOMMU_DEVICE_H +#define HOST_IOMMU_DEVICE_H + +#include "qom/object.h" + +#define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" +OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVI= CE) + +struct HostIOMMUDevice { + Object parent; +}; + +struct HostIOMMUDeviceClass { + ObjectClass parent_class; + + int (*get_host_iommu_info)(HostIOMMUDevice *hiod, void *data, uint32_t= len, + Error **errp); +}; +#endif diff --git a/backends/host_iommu_device.c b/backends/host_iommu_device.c new file mode 100644 index 0000000000..6cb6007d8c --- /dev/null +++ b/backends/host_iommu_device.c @@ -0,0 +1,19 @@ +#include "qemu/osdep.h" +#include "sysemu/host_iommu_device.h" + +OBJECT_DEFINE_ABSTRACT_TYPE(HostIOMMUDevice, + host_iommu_device, + HOST_IOMMU_DEVICE, + OBJECT) + +static void host_iommu_device_class_init(ObjectClass *oc, void *data) +{ +} + +static void host_iommu_device_init(Object *obj) +{ +} + +static void host_iommu_device_finalize(Object *obj) +{ +} diff --git a/backends/Kconfig b/backends/Kconfig index 2cb23f62fa..34ab29e994 100644 --- a/backends/Kconfig +++ b/backends/Kconfig @@ -3,3 +3,8 @@ source tpm/Kconfig config IOMMUFD bool depends on VFIO + +config HOST_IOMMU_DEVICE + bool + default y + depends on VFIO diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..2e975d641e 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -25,6 +25,7 @@ if have_vhost_user endif system_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('cryptodev-vhos= t.c')) system_ss.add(when: 'CONFIG_IOMMUFD', if_true: files('iommufd.c')) +system_ss.add(when: 'CONFIG_HOST_IOMMU_DEVICE', if_true: files('host_iommu= _device.c')) if have_vhost_user_crypto system_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('cryptodev-vh= ost-user.c')) endif --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564146; cv=none; d=zohomail.com; s=zohoarc; b=cvaNkGeWY33BArAVKel2umWkxFdxHEY3SeOmlivw4+LcMdrh5m+qufhqsNx7bU8ESzfS6puGtpu1+ctnVLiHEvY5V70p2T6V15dVWNL5quUmPFd94dQmlBJtzpj+JvH5t7sZw6GN6sxG+8hyfdPaKZyuoG01cQrMiswApfW9mdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564146; 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=vE23wqO4vJHfY2qGud+RM8SfHDPJTgaWEGdDVDHKx5I=; b=N3h2l5MBlzeIchrh5GFNerEvls92QcDy6Nin+efyAdz8BQTUQ2+2fpxJkyZp1v2xTBmHhg2nsLPwJNw5npf7leuKa0c+zuJ8N++JsXIJT4kS77xSySZ3OBIM9n1MPuWb6mpBJdp00v8xpw8QbFL1+Ai4KOwUa1EU4miiOTefgjc= 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+importer2=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 1712564146315134.64785707094086; Mon, 8 Apr 2024 01:15:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtk9r-0002rL-1u; Mon, 08 Apr 2024 04:15:15 -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 1rtk9p-0002p5-MT for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:13 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtk9n-00081z-9C for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:13 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:11 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564111; x=1744100111; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nvxHeLmjV4rkU7CI9wa3Pysp6fP4cvCvnf1CbZdvW5U=; b=Z1bImBPqbQ7LVibhmVH0M2CEkC0wVWb1es9+zjthD2pgnQXPSCbdgjk9 XhJz3HG7ZPKGug19wPROsS74JEcgmLBn9PPE/mXAriUa/10j2t0sTSIKh rvpvIHCH/sRzc5k8ncBQSEaJhvYiZgUpPuPECA3b/n9wqj376i17lKYp4 7xw1jxbtS8CbqmsGVkBqRsP1P3Fs25shCqCplf7w8MvuOnAsnz4yp3dk5 /A89vLIM4ZKzG0+uHpBMVp1NHzNRPhclH/0mQ3ysUT9RXOVnkBuMLfzap CUwqVNZiDdx+XcyxbZq0dNisx1D5u3AoksHgBCn5GHTSIeVQJMD+lMjjc g==; X-CSE-ConnectionGUID: Dts6YZpmSyyEtXe7VvJDng== X-CSE-MsgGUID: ZchQYIrfSLGoVmQKrvO50Q== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199666" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199666" X-CSE-ConnectionGUID: GAlrNFepRhe8+MfiBHG8dw== X-CSE-MsgGUID: TwAZU6QrSj+g917OTWRCiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845177" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 02/10] vfio: Introduce HIODLegacyVFIO device Date: Mon, 8 Apr 2024 16:12:22 +0800 Message-Id: <20240408081230.1030078-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564148393100003 HIODLegacyVFIO represents a host IOMMU device under VFIO legacy container backend. It includes a link to VFIODevice. Suggested-by: Eric Auger Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 11 +++++++++++ hw/vfio/container.c | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b9da6c08ef..f30772f534 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -31,6 +31,7 @@ #endif #include "sysemu/sysemu.h" #include "hw/vfio/vfio-container-base.h" +#include "sysemu/host_iommu_device.h" =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 @@ -147,6 +148,16 @@ typedef struct VFIOGroup { bool ram_block_discard_allowed; } VFIOGroup; =20 +#define TYPE_HIOD_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio" +OBJECT_DECLARE_SIMPLE_TYPE(HIODLegacyVFIO, HIOD_LEGACY_VFIO) + +/* Abstraction of VFIO legacy host IOMMU device */ +struct HIODLegacyVFIO { + /*< private >*/ + HostIOMMUDevice parent; + VFIODevice *vdev; +}; + typedef struct VFIODMABuf { QemuDmaBuf buf; uint32_t pos_x, pos_y, pos_updates; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 77bdec276e..44018ef085 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1143,12 +1143,21 @@ static void vfio_iommu_legacy_class_init(ObjectClas= s *klass, void *data) vioc->pci_hot_reset =3D vfio_legacy_pci_hot_reset; }; =20 +static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) +{ +}; + static const TypeInfo types[] =3D { { .name =3D TYPE_VFIO_IOMMU_LEGACY, .parent =3D TYPE_VFIO_IOMMU, .class_init =3D vfio_iommu_legacy_class_init, - }, + }, { + .name =3D TYPE_HIOD_LEGACY_VFIO, + .parent =3D TYPE_HOST_IOMMU_DEVICE, + .instance_size =3D sizeof(HIODLegacyVFIO), + .class_init =3D hiod_legacy_vfio_class_init, + } }; =20 DEFINE_TYPES(types) --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564182; cv=none; d=zohomail.com; s=zohoarc; b=aRSVPWrlcIRRV1xxbL6tOW6oracH+LrMlyguI5osGA7fZHbLFVT6RZvrLn0Qf5sB+V2OPgcFBf2LzTYg56paa3AXSwBV3h0a9T3+Yik3jUvoaZ1FpwXkuNejWMc0vYvO5DE7iJBJZaUPE1zH4xj/lnx+8UVbAnMDP/RMQr/5T/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564182; 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=As3ZllD6lfanyTK+Q75Kc0WMHUKylXFUfZOnDbE7Z9g=; b=R5XVTIfWZbCZWKZYdhXzb1ni8UIDfaPQnUHq6GUqdbbfWmnv5cbE90gme8FJe9JrWKoZIn7DRodStnJSwoIDknNgOqBVOh1Ifp/H6IKxBh3ywMjyb2a6tchwihvXF7/bVzqG8jqntzgGQH/GNDgh4ahEQD6PywrByHb5tdM1+cg= 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+importer2=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 1712564182538802.3790174918922; Mon, 8 Apr 2024 01:16:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtk9v-00030i-3H; Mon, 08 Apr 2024 04:15:19 -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 1rtk9t-0002y7-Ha for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:17 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtk9r-00089q-Nz for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:17 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:14 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564116; x=1744100116; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mThwLA2cpqB/Ub1Co78HjfLcWVvgAn50zoxRT0ghxDo=; b=ebPNTtPakWIp6QOjpZHjEnsXFiUQmHnOSqEBlON5mEEO3t4o+aF+1m2O 7idCUguaw4n6xEGZzBKunvfJZZt4T3lxmSKZTqYAzvY6LwHQNDcCf3666 PVRRBKk2agzauEZokAVBbQA8KAWAOiuVDsinpP4G+izrGWudq/EOEoTl4 f5mGbMNIHz5uW10P3eolqWSQewYDkcD1NbQtfXJ5OgoKU9FyS8Atdesc9 5tRJ577rNvrHRA6wahcPjaUE4InY2lW2aiu/+lWkTAsYyq77Y0uNK3vnG o1rfVmWTtH3H3ogfiKKvXuOdjb0WCZrkQbFylYSMJN6CEiFysiOmJm5/G Q==; X-CSE-ConnectionGUID: WMmEY20hTrykIicrsAK46Q== X-CSE-MsgGUID: jpPJ00l+T6W/0vnbSeXCVw== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199680" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199680" X-CSE-ConnectionGUID: 8Mh8REmGQ/KKVYHWXwmyqw== X-CSE-MsgGUID: DogWqoJiTUyyZOH1poh80Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845186" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v2 03/10] backends/iommufd: Introduce abstract HIODIOMMUFD device Date: Mon, 8 Apr 2024 16:12:23 +0800 Message-Id: <20240408081230.1030078-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564184577100003 HIODIOMMUFD represents a host IOMMU device under iommufd backend. Currently it includes only public iommufd handle and device id. which could be used to get hw IOMMU information. When nested translation is supported in future, vIOMMU is going to have iommufd related operations like attaching/detaching hwpt, So IOMMUFDDevice interface will be further extended at that time. VFIO and VDPA device have different way of attaching/detaching hwpt. So HIODIOMMUFD is still an abstract class which will be inherited by VFIO and VDPA device. Introduce a helper hiod_iommufd_init() to initialize HIODIOMMUFD device. Suggested-by: C=C3=A9dric Le Goater Originally-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 22 +++++++++++++++++++ backends/iommufd.c | 47 ++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 9af27ebd6c..71c53cbb45 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -4,6 +4,7 @@ #include "qom/object.h" #include "exec/hwaddr.h" #include "exec/cpu-common.h" +#include "sysemu/host_iommu_device.h" =20 #define TYPE_IOMMUFD_BACKEND "iommufd" OBJECT_DECLARE_TYPE(IOMMUFDBackend, IOMMUFDBackendClass, IOMMUFD_BACKEND) @@ -33,4 +34,25 @@ int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t= ioas_id, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, ram_addr_t size); + +#define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" +OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass, HIOD_IOMMUFD) + +struct HIODIOMMUFD { + /*< private >*/ + HostIOMMUDevice parent; + void *opaque; + + /*< public >*/ + IOMMUFDBackend *iommufd; + uint32_t devid; +}; + +struct HIODIOMMUFDClass { + /*< private >*/ + HostIOMMUDeviceClass parent_class; +}; + +void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBackend *iommufd, + uint32_t devid); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 62a79fa6b0..ef8b3a808b 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -212,23 +212,38 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uin= t32_t ioas_id, return ret; } =20 -static const TypeInfo iommufd_backend_info =3D { - .name =3D TYPE_IOMMUFD_BACKEND, - .parent =3D TYPE_OBJECT, - .instance_size =3D sizeof(IOMMUFDBackend), - .instance_init =3D iommufd_backend_init, - .instance_finalize =3D iommufd_backend_finalize, - .class_size =3D sizeof(IOMMUFDBackendClass), - .class_init =3D iommufd_backend_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; +void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBackend *iommufd, + uint32_t devid) +{ + idev->iommufd =3D iommufd; + idev->devid =3D devid; +} =20 -static void register_types(void) +static void hiod_iommufd_class_init(ObjectClass *oc, void *data) { - type_register_static(&iommufd_backend_info); } =20 -type_init(register_types); +static const TypeInfo types[] =3D { + { + .name =3D TYPE_IOMMUFD_BACKEND, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(IOMMUFDBackend), + .instance_init =3D iommufd_backend_init, + .instance_finalize =3D iommufd_backend_finalize, + .class_size =3D sizeof(IOMMUFDBackendClass), + .class_init =3D iommufd_backend_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } + }, { + .name =3D TYPE_HIOD_IOMMUFD, + .parent =3D TYPE_HOST_IOMMU_DEVICE, + .instance_size =3D sizeof(HIODIOMMUFD), + .class_size =3D sizeof(HIODIOMMUFDClass), + .class_init =3D hiod_iommufd_class_init, + .abstract =3D true, + } +}; + +DEFINE_TYPES(types) --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564134; cv=none; d=zohomail.com; s=zohoarc; b=J9qhDTqi2GrOUEQhla3DrUex6AaFvXdd7IW6cc0lUMcs/dqQlM9ugJyXj5V6SHf9LD6EZVn61jKCyKWM7GXPC74LzIG+wMN2nkED2on+O//vnxEYBhi65AMk2h987H+hDWn2tg4D5aulDM4RhpxN62YDxGt5vJo/k9Pykn2hwlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564134; 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=gl7NIM2lF2bdwbNU8kNMyiM/SWIN3DqZ2MOI3uyQmQY=; b=d5dtd/Itb0zo2U4zX8yRwYXK3zsjeEjc3WbJYwtCS4bggD43a79ua4p/p5E599DgyXVdyi6vlwxgCKAp5hKi26hZ120a8ZHIt9MH/zc1QFJ4WvsrSbTFwf7JHjk1DVopG/yDwr9A5vHbCjOOvucwAndtRwAdSOze1nbd5x/YneA= 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+importer2=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 1712564134032728.9898876834598; Mon, 8 Apr 2024 01:15:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtk9z-0003AI-PX; Mon, 08 Apr 2024 04:15:23 -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 1rtk9x-00039u-Q7 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:21 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtk9v-00089q-Vi for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:21 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:18 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564120; x=1744100120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bvbdJgRIGiY6OBmpA+3MhD5hfFd6dTo8QUt8PrlDTNk=; b=g/LSajqI7ZP0rk5rChsq3f/StY+wBYeCY8BCR5QvQgIL7Ued9PiicDr7 jbbXczSb3p0w0DJ3+FjPayp5/dISCgQdqFUt+9pmjWngS39TXpYRgagtM izO6iTjBURVtWwifFuiufdCsNzeL2ADkcofCexYUd4wu9hTOQ1gv0XF1e ZHA3TbY4zrNM4GdFVBzo8hdKeGHNEVtgrZGw4iRWHa6W+WYupEfCEZ9bt IYLbpNvLxUZsycIUnQ2LotkwnauXudSDub3MwwzWfO7bqSbXP7YTGc/s/ qHyYoiNDYWy+zMRP98k7kGqPdVjuR01i08tb0dZqJDLlBILG0ew3ZiRpa Q==; X-CSE-ConnectionGUID: h/gQGqHNR6yfTBzVxD5oiA== X-CSE-MsgGUID: mkg0Ugg+Q32PAUu9lItMgw== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199701" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199701" X-CSE-ConnectionGUID: aNHqgbzrS4K5rg6x79zEfw== X-CSE-MsgGUID: jvOGt1H/RoqGyMJE75LTKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845198" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 04/10] vfio/iommufd: Introduce HIODIOMMUFDVFIO device Date: Mon, 8 Apr 2024 16:12:24 +0800 Message-Id: <20240408081230.1030078-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564134541100003 Content-Type: text/plain; charset="utf-8" HIODIOMMUFDVFIO represents a host IOMMU device under VFIO iommufd backend. It will be created during VFIO device attaching and passed to vIOMMU. It includes a link to VFIODevice so that we can do VFIO device specific hwpt attaching/detaching. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 11 +++++++++++ hw/vfio/iommufd.c | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f30772f534..d382b12ec1 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -32,6 +32,7 @@ #include "sysemu/sysemu.h" #include "hw/vfio/vfio-container-base.h" #include "sysemu/host_iommu_device.h" +#include "sysemu/iommufd.h" =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 @@ -158,6 +159,16 @@ struct HIODLegacyVFIO { VFIODevice *vdev; }; =20 +#define TYPE_HIOD_IOMMUFD_VFIO TYPE_HIOD_IOMMUFD "-vfio" +OBJECT_DECLARE_SIMPLE_TYPE(HIODIOMMUFDVFIO, HIOD_IOMMUFD_VFIO) + +/* Abstraction of VFIO IOMMUFD host IOMMU device */ +struct HIODIOMMUFDVFIO { + /*< private >*/ + HIODIOMMUFD parent; + VFIODevice *vdev; +}; + typedef struct VFIODMABuf { QemuDmaBuf buf; uint32_t pos_x, pos_y, pos_updates; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 8827ffe636..115b9f8e7f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -634,12 +634,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass= *klass, void *data) vioc->pci_hot_reset =3D iommufd_cdev_pci_hot_reset; }; =20 +static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) +{ +}; + static const TypeInfo types[] =3D { { .name =3D TYPE_VFIO_IOMMU_IOMMUFD, .parent =3D TYPE_VFIO_IOMMU, .class_init =3D vfio_iommu_iommufd_class_init, - }, + }, { + .name =3D TYPE_HIOD_IOMMUFD_VFIO, + .parent =3D TYPE_HIOD_IOMMUFD, + .instance_size =3D sizeof(HIODIOMMUFDVFIO), + .class_init =3D hiod_iommufd_vfio_class_init, + } }; =20 DEFINE_TYPES(types) --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564223; cv=none; d=zohomail.com; s=zohoarc; b=PluZxWmlx/R+C4oSiBtGPgFfgGQHqi+6Kx0NaPAjbBO4Qermw7XzTVvyOv6C99l3h84+rW2jw4l2T4Vw9ntCvtZX7+5f5E0NquiMpknnC5UHlpgbXq6jTj8TH5ny0n1b+hw9uiK2wXW8ld3mdzqmW98+5XKD8W7Jozhd0poybfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564223; 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=exGtTevUdsZyzegHfzRR+x+naIbpjinh2/Cr3MQpFD4=; b=iVT/TbPX7SNWsRpPykyBxHlau10wldNK0CVHHjdeGnZvMxWktl9UDuBhfGT2LfQPY9gNHsOaSGCd0CRDPiDaMVr+kOJf23O7vwIRCHY4r6Dh7GNLXfEZKC6tkocV5LCMajLHU9n5m/PnVfmntxVjw30rreoOgq01rgS1yR04JWc= 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+importer2=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 1712564223871385.0178359955429; Mon, 8 Apr 2024 01:17:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkA2-0003B0-B0; Mon, 08 Apr 2024 04:15:26 -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 1rtkA0-0003AR-4y for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:24 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtk9y-00089q-FC for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:23 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:22 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564122; x=1744100122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C4MsvBvx9B64HLRW4B7bTMYTxjVlbMxQElKE/nS9Vhc=; b=mzP+eHlcZpmLyNUd3jJHzPOQ1AX+zLpt9kLawSFPa7kJwNEaPpxkgqv0 hpWPdtuFYJ5+xni+DDLcz16NS8YfEjTUHpIYzrx1n/ejDl1ZBwkNDqyUK dOF+ExfFT0MawfKiT3sA0k8tuAG4gGe4wsKwi70s+HdVlROOjjxt0CG6V 85VPtSeUCNgljIQCHLcpqtnd+2cm9xAhcO7iokORdWp2pC4EG9QViVboq Ugulyv+hJdV1DCipeyw6GdkDdBzby4IDfnG9p8LCIktCjptEqL4bZS+0s 6Us5OjtBaxNf2FY+MFH4pbV2zw637plh8kRliZKypmrPTDdqGXCBp5dNU A==; X-CSE-ConnectionGUID: 3ge72sZrQ6i70Ao7v1HpPg== X-CSE-MsgGUID: dbqPhMitSJuAbFdDQwh0OQ== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199712" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199712" X-CSE-ConnectionGUID: CjhSjub6RROLMU6Ty4M7XQ== X-CSE-MsgGUID: wSi5G0lYQ7a3sz9JvvB0qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845206" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 05/10] vfio: Implement get_host_iommu_info() callback Date: Mon, 8 Apr 2024 16:12:25 +0800 Message-Id: <20240408081230.1030078-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564224722100003 Content-Type: text/plain; charset="utf-8" Utilize iova_ranges to calculate host IOMMU address width and package it in HIOD_LEGACY_INFO for vIOMMU usage. HIOD_LEGACY_INFO will be used by both VFIO and VDPA so declare it in host_iommu_device.h. Signed-off-by: Zhenzhong Duan --- include/sysemu/host_iommu_device.h | 10 ++++++++++ hw/vfio/container.c | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 22ccbe3a5d..beb8be8231 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -16,4 +16,14 @@ struct HostIOMMUDeviceClass { int (*get_host_iommu_info)(HostIOMMUDevice *hiod, void *data, uint32_t= len, Error **errp); }; + +/* + * Define the format of host IOMMU related info that current VFIO + * or VDPA can privode to vIOMMU. + * + * @aw_bits: Host IOMMU address width. 0xff if no limitation. + */ +typedef struct HIOD_LEGACY_INFO { + uint8_t aw_bits; +} HIOD_LEGACY_INFO; #endif diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 44018ef085..ba0ad4a41b 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1143,8 +1143,32 @@ static void vfio_iommu_legacy_class_init(ObjectClass= *klass, void *data) vioc->pci_hot_reset =3D vfio_legacy_pci_hot_reset; }; =20 +static int hiod_legacy_vfio_get_host_iommu_info(HostIOMMUDevice *hiod, + void *data, uint32_t len, + Error **errp) +{ + VFIODevice *vbasedev =3D HIOD_LEGACY_VFIO(hiod)->vdev; + /* iova_ranges is a sorted list */ + GList *l =3D g_list_last(vbasedev->bcontainer->iova_ranges); + HIOD_LEGACY_INFO *info =3D data; + + assert(sizeof(HIOD_LEGACY_INFO) <=3D len); + + if (l) { + Range *range =3D l->data; + info->aw_bits =3D find_last_bit(&range->upb, BITS_PER_LONG) + 1; + } else { + info->aw_bits =3D 0xff; + } + + return 0; +} + static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) { + HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); + + hioc->get_host_iommu_info =3D hiod_legacy_vfio_get_host_iommu_info; }; =20 static const TypeInfo types[] =3D { --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564211; cv=none; d=zohomail.com; s=zohoarc; b=IcDtxnh7H5IRU4t4QvSfykmyMypx7vGS3f6OHZFAJILxkz6WGa15naIRVqC1DIqPM1LUwTSk7cV5dVjOAEEjJFGZPrFqhRvOMTjAu0iKOicIXEyP912OuFYy5XANNGA2XF2PAQMqroDt//IsnFnok2i5DMl/2v9vhK5D+mrJZpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564211; 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=4sU5v7M7a/2z8ghhXi3IJneyHSJCjSkUtt8gfIdcdLY=; b=NQbdG759f8OnDbsQun1USG6iUjqyL7Rt82rA9d/gB1VZsMUWyv//Pn4iP8HJhhuofcGb4SzYb0s49qg/NIl34VOVHDSbgcUZq6A0MjbwxUHuIQwQEYHU974JUgsQ20wfUyX8LBuCk9vzHE7AstAYQXNVKr7uQF1XDZ+TEqaPgsA= 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+importer2=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 1712564211476892.2869239071812; Mon, 8 Apr 2024 01:16:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkA6-0003EL-IL; Mon, 08 Apr 2024 04:15:30 -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 1rtkA5-0003Bg-1D for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:29 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtkA2-00089q-Bm for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:28 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:26 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564126; x=1744100126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OEWdQXklwv4XAzXDZ24doa8pgMnpGHHQ2cUDfFr+BSg=; b=EscL1OsXRbd9lMpiKkbtrEyckacGYt2YgudMJ/h44iljKb4U2E9eGO5t iQIdVmpzmBvXuDXqKNHaJDFaPbXqYWPE2HfOe/yP0EfbBBQ7/g2s+p81Q bZOIDJmOMTSmY4llx6BAR9dOSLw5o0xJJiX0RE68iox7nRscW4RfdQbAA CaVWBwfCBlpLo5ShY6GbBZJaLb/bI5CKIrW04JnqnqEej6NXWNuqkdLFg 9T0WqEw4HSLQdw6nd4wn5kPZkdyz/Gevyp3pCOg7G7lreie/Pan/prPti auuge6vjd7K25EGDJIlknJa+cLSB75MVerLVQoYuDtWHF3JJu9Je7BPQe Q==; X-CSE-ConnectionGUID: 7/LfREySRqKgr6C9mo1fWw== X-CSE-MsgGUID: ccJNiClERRWSVYXvrqAduQ== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199722" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199722" X-CSE-ConnectionGUID: j4JXK4wBQImrPHCXFQIKeQ== X-CSE-MsgGUID: XnhhlLBaQBKl+om8ORecHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845210" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v2 06/10] backends/iommufd: Introduce helper function iommufd_backend_get_device_info() Date: Mon, 8 Apr 2024 16:12:26 +0800 Message-Id: <20240408081230.1030078-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564212637100003 Content-Type: text/plain; charset="utf-8" Introduce a helper function iommufd_backend_get_device_info() to get host IOMMU related information through iommufd uAPI. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 4 ++++ backends/iommufd.c | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 71c53cbb45..fa1a866237 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -4,6 +4,7 @@ #include "qom/object.h" #include "exec/hwaddr.h" #include "exec/cpu-common.h" +#include #include "sysemu/host_iommu_device.h" =20 #define TYPE_IOMMUFD_BACKEND "iommufd" @@ -34,6 +35,9 @@ int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t = ioas_id, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, ram_addr_t size); +int iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, + enum iommu_hw_info_type *type, + void *data, uint32_t len, Error **errp= ); =20 #define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass, HIOD_IOMMUFD) diff --git a/backends/iommufd.c b/backends/iommufd.c index ef8b3a808b..559affa9ec 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -20,7 +20,6 @@ #include "monitor/monitor.h" #include "trace.h" #include -#include =20 static void iommufd_backend_init(Object *obj) { @@ -212,6 +211,28 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint= 32_t ioas_id, return ret; } =20 +int iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, + enum iommu_hw_info_type *type, + void *data, uint32_t len, Error **errp) +{ + struct iommu_hw_info info =3D { + .size =3D sizeof(info), + .dev_id =3D devid, + .data_len =3D len, + .data_uptr =3D (uintptr_t)data, + }; + int ret; + + ret =3D ioctl(be->fd, IOMMU_GET_HW_INFO, &info); + if (ret) { + error_setg_errno(errp, errno, "Failed to get hardware info"); + } else { + *type =3D info.out_data_type; + } + + return ret; +} + void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBackend *iommufd, uint32_t devid) { --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564190; cv=none; d=zohomail.com; s=zohoarc; b=b+Ge0hEjKfTcYqqXkrLUbPaX7gyh02JKZOLZ0yqGZtcYYlxgSY4Je4Fvtncgzj8F1Dua+UMyeIpRM9prFS9LFU7byu12MJsi8FofERIYv9v9iDa0uPNSPPt0UNIyLOZg4mLK7yZmf5S92kgcV9Hb2CYzwuBnIKq+QH6NA/rFWKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564190; 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=LlZ2gENbxLlsJ5L39xj7fgS5KI8LvMK24S+HXcy1/8k=; b=ijZQDt3Zkdp8ZIGbagLtr5Kw/e625Ym/MUFi7L2cg9MjC9QYZgrI2Ddm7S2AC3RG6MyjuwPPZJsZ4UbLg28nR2bY0+CPTaiBqlhARFbnAOyip5NfS6S5RSbUC+KrIsB9oU/iDdMv+FGiVU/UIhn+rnDrFB3kWJGLb0g7cQ1wgNw= 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+importer2=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 1712564190222214.9853812926916; Mon, 8 Apr 2024 01:16:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkAY-0003Nh-RB; Mon, 08 Apr 2024 04:16: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 1rtkA7-0003Gz-Ku for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:31 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtkA5-00089q-SB for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:31 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:29 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564130; x=1744100130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RajnNcVKs+6ypzH6WcL3+uFvOHZi+tCP/jt2sxffnkU=; b=Cc8/KOWif++x1+v7k0r0xmFmvWabN3dCPADo09HvqeWoaw0nnkx8wFnB FfdiW7LI4i2cW+0nx1YT12xImMlD4jO1vdPxraPGsWXnspLxetjUiwSKB MVcUUIypcCP+SQfhR4tXS5VaMBsd/zCW3IS8P0+GOnbF25ZIKFW1yU3Mb eSOG+wdZX/vtG67QvBaeKD7ZrMMUH419PVnNleMq+iHyhlMwVlsEkyVxx heJ8HD8cY1uofZqCTI4rmeTp/Lx707kjxPkgqbisry8Rhkvaliwiyu6nh j5r1UANhCgLE3eSQGcfD9nNsIuO/I7t285HsgJw9w8/jhyUEqbY0ppMa0 w==; X-CSE-ConnectionGUID: hqIRHT3DT32Sx+7Ct/CIKw== X-CSE-MsgGUID: ahDLwpJITZ2afy+t+nQ4qA== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199736" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199736" X-CSE-ConnectionGUID: 13QfKuu2QaiwI0B/e4f+Jg== X-CSE-MsgGUID: Mr0nPNFWTk2LC9ThWK5AZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845213" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 07/10] backends/iommufd: Implement get_host_iommu_info() callback Date: Mon, 8 Apr 2024 16:12:27 +0800 Message-Id: <20240408081230.1030078-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564192593100003 Content-Type: text/plain; charset="utf-8" It calls iommufd_backend_get_device_info() to get host IOMMU related information. Define a common structure HIOD_IOMMUFD_INFO to describe the info returned from kernel. Currently only vtd, but easy to add arm smmu when kernel supports. Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 7 +++++++ backends/iommufd.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index fa1a866237..44ec1335b2 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -39,6 +39,13 @@ int iommufd_backend_get_device_info(IOMMUFDBackend *be, = uint32_t devid, enum iommu_hw_info_type *type, void *data, uint32_t len, Error **errp= ); =20 +typedef struct HIOD_IOMMUFD_INFO { + enum iommu_hw_info_type type; + union { + struct iommu_hw_info_vtd vtd; + } data; +} HIOD_IOMMUFD_INFO; + #define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass, HIOD_IOMMUFD) =20 diff --git a/backends/iommufd.c b/backends/iommufd.c index 559affa9ec..1e9c469e65 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -240,8 +240,25 @@ void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBacke= nd *iommufd, idev->devid =3D devid; } =20 +static int hiod_iommufd_get_host_iommu_info(HostIOMMUDevice *hiod, + void *data, uint32_t len, + Error **errp) +{ + HIODIOMMUFD *idev =3D HIOD_IOMMUFD(hiod); + HIOD_IOMMUFD_INFO *info =3D data; + + assert(sizeof(HIOD_IOMMUFD_INFO) <=3D len); + + return iommufd_backend_get_device_info(idev->iommufd, idev->devid, + &info->type, &info->data, + sizeof(info->data), errp); +} + static void hiod_iommufd_class_init(ObjectClass *oc, void *data) { + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); + + hiodc->get_host_iommu_info =3D hiod_iommufd_get_host_iommu_info; } =20 static const TypeInfo types[] =3D { --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564224; cv=none; d=zohomail.com; s=zohoarc; b=mChD02Twu4G0ZVrg37aHiL0Ii7wQ8vgYGGtNhsT1jFBtqASSd9nSP1LudNrlgoOyqSJ4cWvRVJye47QYOViCrg3/sexD5BQa6Q96IHumxYvKMRrldX6Xuo9uCwYD4D78tDSq9+KqdKpVaQtoYtYvcWOMGObXiciUlfYgl48XIyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564224; 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=GoQuwMQ3mm9mlBir7yWg3Nzw0aVoZpfflDapvGIY7wM=; b=BqYq723esFHMNx1I1QzXgk80vEaw6vkaVs0jtYXdaSEXuyk8MTBhZjq0NaZizhdJBX8Sw5clZghPa7x4ERetj2xE3ZmZQ90RKmxLKI5RnQ7k8y+gLcCBJwq0R6SaOn9wiENtnLZBSsKcPINXBar9jR7l0valQkIH9v+nUjdZDZ4= 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+importer2=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 1712564224821909.3724887440633; Mon, 8 Apr 2024 01:17:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkAv-0003jy-3f; Mon, 08 Apr 2024 04:16:23 -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 1rtkAC-0003N9-CJ for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:42 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtkA9-00089q-JL for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:36 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:33 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564134; x=1744100134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DVXEQ9yLYmU2ztZd49QkuJi4eo9VDVlNfFqfrJ3+k7g=; b=GSTDpJDXkwkBRm5ZgtjybBWLh1js5xg1Oc6IudeCVkv6qRfQq4FD1Kqo ckoYCi+vK+wepGEbLS+RY4ON/GIvF1g8rd+NDZKNexAnfv/3Wxlxa6TzS Ot7EGTZ1IdZLB4TtWuGbh9okGF8kwN2a5c5+6cJ78dw8SSXmRCgwDU5Vs qLSXdHXSF1qADDz7T0g3QPA/hbdLrhAJeWkKopZuUy/B7NG5c9OkdOedE LpsHHZu1YSfo82kABpxXB13GeoPplw+o3DeP8djfF9sniFGL6Y2LHzJ1p gGjhfiAfj99UK6dsxs2Zqnakb69uXA+YcVJpGqbfy1A5rndTGR0m0xhIt g==; X-CSE-ConnectionGUID: UgUpGAStRW2WiKo/+U31FQ== X-CSE-MsgGUID: fjvCROubSta6N+jMskoFhw== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199743" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199743" X-CSE-ConnectionGUID: nRXBpU6nSUqBwRBd1UeG5Q== X-CSE-MsgGUID: RcHR3eY3ThaPjkYeyG39Qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845216" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 08/10] vfio: Create host IOMMU device instance Date: Mon, 8 Apr 2024 16:12:28 +0800 Message-Id: <20240408081230.1030078-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564226735100010 Content-Type: text/plain; charset="utf-8" Create host IOMMU device instance and initialize it based on backend. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/container.c | 5 +++++ hw/vfio/iommufd.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d382b12ec1..4fbba85018 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -126,6 +126,7 @@ typedef struct VFIODevice { OnOffAuto pre_copy_dirty_page_tracking; bool dirty_pages_supported; bool dirty_tracking; + HostIOMMUDevice *hiod; int devid; IOMMUFDBackend *iommufd; } VFIODevice; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index ba0ad4a41b..fc0c027501 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -915,6 +915,7 @@ static int vfio_legacy_attach_device(const char *name, = VFIODevice *vbasedev, VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; + HIODLegacyVFIO *hiod_vfio; int ret; =20 if (groupid < 0) { @@ -945,6 +946,9 @@ static int vfio_legacy_attach_device(const char *name, = VFIODevice *vbasedev, vbasedev->bcontainer =3D bcontainer; QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); + hiod_vfio =3D HIOD_LEGACY_VFIO(object_new(TYPE_HIOD_LEGACY_VFIO)); + hiod_vfio->vdev =3D vbasedev; + vbasedev->hiod =3D HOST_IOMMU_DEVICE(hiod_vfio); =20 return ret; } @@ -959,6 +963,7 @@ static void vfio_legacy_detach_device(VFIODevice *vbase= dev) trace_vfio_detach_device(vbasedev->name, group->groupid); vfio_put_base_device(vbasedev); vfio_put_group(group); + object_unref(vbasedev->hiod); } =20 static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 115b9f8e7f..b6d058339b 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -308,6 +308,7 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, VFIOIOMMUFDContainer *container; VFIOAddressSpace *space; struct vfio_device_info dev_info =3D { .argsz =3D sizeof(dev_info) }; + HIODIOMMUFDVFIO *hiod_vfio; int ret, devfd; uint32_t ioas_id; Error *err =3D NULL; @@ -431,6 +432,12 @@ found_container: QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); =20 + hiod_vfio =3D HIOD_IOMMUFD_VFIO(object_new(TYPE_HIOD_IOMMUFD_VFIO)); + hiod_iommufd_init(HIOD_IOMMUFD(hiod_vfio), vbasedev->iommufd, + vbasedev->devid); + hiod_vfio->vdev =3D vbasedev; + vbasedev->hiod =3D HOST_IOMMU_DEVICE(hiod_vfio); + trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, vbasedev->num_regions, vbasedev->flags); return 0; @@ -468,6 +475,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) iommufd_cdev_detach_container(vbasedev, container); iommufd_cdev_container_destroy(container); vfio_put_address_space(space); + object_unref(vbasedev->hiod); =20 iommufd_cdev_unbind_and_disconnect(vbasedev); close(vbasedev->fd); --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564200; cv=none; d=zohomail.com; s=zohoarc; b=C+iMG3+t8GyeHHOJ2SzkF8hl3Y6762N2JSFvxkC/QhzC0L8C3Ur2jD6Bufc/1JzWKL8G7H9n1PMgMiYOjJLsT9SwRT9I5dinm7UoTBxlXuDMu2JgEAMahFK6Z8uezZQw+quC9yrq+cY+V0SEx+Q+SLWv7QpCK+sV6DT/qgNjS4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564200; 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=8PNnmbh+DKE8etqTzdpPxkYllG6DbwoGtmxzwz4z2Xk=; b=V5/FVj9wSK60ZHPF80ycekRWZhX9Nz4oTp7fWvDXZqNBa2xLTXFHEyaSPG7SGh2eCyJM17yv1GVO4INp8tlBH1ld8Vg2B7GHu/79cPYZkd1ecSFEnrSPRpC41HXRycHwv0dVfuNz4W3hzdG2g36IreS9QfQaw3mf674SeQdIzKA= 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+importer2=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 1712564200511946.9167881655114; Mon, 8 Apr 2024 01:16:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkB3-00043k-2k; Mon, 08 Apr 2024 04:16:30 -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 1rtkAG-0003Ni-2q for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:43 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtkAE-00089q-39 for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:39 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:37 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564138; x=1744100138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rhf6gqcQqWTnIyTi86DlfojgFggLJA6Lto3EZkYbwsw=; b=MF661VO811RfbsjdfJqoLWt9MgBFywXdwUpGaRrYcOILQwwJDjPI2oXh tdiWeo3pP1EYZInNtc65FEInPeXkFMGtI+nrwpqUuT9dnCULwcB8Ak1sF AIe6+VC9htCZyX9qcI0IimvqXZEYlPrXz/EdFqkoLiQmldtRU5PDfRWuH JCVHkxdmW6IfDhbLFltgFf1JILozMIxfdODBc64imniwydy6RkNmD8tqZ xJonDBaQQmXS0zzygbW+X+RxcufOHGHi6pcfiJGuNJkwxwDnm7gcGlSjt 7Y0syI9mw63UrBupUfuSrtkYHvHXMOeEH5nKCD6Me40KblvjcGlDmzUYC A==; X-CSE-ConnectionGUID: 5mIXzPOOQUS/+ETMasnY2A== X-CSE-MsgGUID: 3giUB8t3RZ6acv4z7ZCjYQ== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199758" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199758" X-CSE-ConnectionGUID: hw28PJNJRH+f1N9Hd+KGVQ== X-CSE-MsgGUID: cDtIRS4qTTymxwX9aruT/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845220" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum Subject: [PATCH v2 09/10] hw/pci: Introduce pci_device_set/unset_iommu_device() Date: Mon, 8 Apr 2024 16:12:29 +0800 Message-Id: <20240408081230.1030078-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564202594100003 Content-Type: text/plain; charset="utf-8" From: Yi Liu This adds pci_device_set/unset_iommu_device() to set/unset HostIOMMUDevice for a given PCI device. Caller of set should fail if set operation fails. Extract out pci_device_get_iommu_bus_devfn() to facilitate implementation of pci_device_set/unset_iommu_device(). Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Nicolin Chen Signed-off-by: Zhenzhong Duan --- include/hw/pci/pci.h | 40 ++++++++++++++++++++++- hw/pci/pci.c | 75 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index eaa3fc99d8..4ae7fe6f3f 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -3,6 +3,7 @@ =20 #include "exec/memory.h" #include "sysemu/dma.h" +#include "sysemu/host_iommu_device.h" =20 /* PCI includes legacy ISA access. */ #include "hw/isa/isa.h" @@ -383,10 +384,47 @@ typedef struct PCIIOMMUOps { * * @devfn: device and function number */ - AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int devf= n); + AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int dev= fn); + /** + * @set_iommu_device: attach a HostIOMMUDevice to a vIOMMU + * + * Optional callback, if not implemented in vIOMMU, then vIOMMU can't + * retrieve host information from the associated HostIOMMUDevice. + * + * Return true if HostIOMMUDevice is attached, or else return false + * with errp set. + * + * @bus: the #PCIBus of the PCI device. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number of the PCI device. + * + * @dev: the data structure representing host IOMMU device. + * + * @errp: pass an Error out only when return false + * + */ + int (*set_iommu_device)(PCIBus *bus, void *opaque, int devfn, + HostIOMMUDevice *dev, Error **errp); + /** + * @unset_iommu_device: detach a HostIOMMUDevice from a vIOMMU + * + * Optional callback. + * + * @bus: the #PCIBus of the PCI device. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number of the PCI device. + */ + void (*unset_iommu_device)(PCIBus *bus, void *opaque, int devfn); } PCIIOMMUOps; =20 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); +int pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, + Error **errp); +void pci_device_unset_iommu_device(PCIDevice *dev); =20 /** * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e7a39cb203..8ece617673 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2648,11 +2648,27 @@ static void pci_device_class_base_init(ObjectClass = *klass, void *data) } } =20 -AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) +/* + * Get IOMMU root bus, aliased bus and devfn of a PCI device + * + * IOMMU root bus is needed by all call sites to call into iommu_ops. + * For call sites which don't need aliased BDF, passing NULL to + * aliased_[bus/devfn] is allowed. + * + * @piommu_bus: return root #PCIBus backed by an IOMMU for the PCI device. + * + * @aliased_bus: return aliased #PCIBus of the PCI device, optional. + * + * @aliased_devfn: return aliased devfn of the PCI device, optional. + */ +static void pci_device_get_iommu_bus_devfn(PCIDevice *dev, + PCIBus **piommu_bus, + PCIBus **aliased_bus, + int *aliased_devfn) { PCIBus *bus =3D pci_get_bus(dev); PCIBus *iommu_bus =3D bus; - uint8_t devfn =3D dev->devfn; + int devfn =3D dev->devfn; =20 while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) { PCIBus *parent_bus =3D pci_get_bus(iommu_bus->parent_dev); @@ -2693,13 +2709,66 @@ AddressSpace *pci_device_iommu_address_space(PCIDev= ice *dev) =20 iommu_bus =3D parent_bus; } - if (!pci_bus_bypass_iommu(bus) && iommu_bus->iommu_ops) { + + assert(0 <=3D devfn && devfn < PCI_DEVFN_MAX); + assert(iommu_bus); + + if (pci_bus_bypass_iommu(bus) || !iommu_bus->iommu_ops) { + iommu_bus =3D NULL; + } + + *piommu_bus =3D iommu_bus; + + if (aliased_bus) { + *aliased_bus =3D bus; + } + + if (aliased_devfn) { + *aliased_devfn =3D devfn; + } +} + +AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) +{ + PCIBus *bus; + PCIBus *iommu_bus; + int devfn; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, &bus, &devfn); + if (iommu_bus) { return iommu_bus->iommu_ops->get_address_space(bus, iommu_bus->iommu_opaque, devfn); } return &address_space_memory; } =20 +int pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, + Error **errp) +{ + PCIBus *iommu_bus; + + /* set_iommu_device requires device's direct BDF instead of aliased BD= F */ + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->set_iommu_device) { + return iommu_bus->iommu_ops->set_iommu_device(pci_get_bus(dev), + iommu_bus->iommu_opa= que, + dev->devfn, hiod, er= rp); + } + return 0; +} + +void pci_device_unset_iommu_device(PCIDevice *dev) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, &iommu_bus, NULL, NULL); + if (iommu_bus && iommu_bus->iommu_ops->unset_iommu_device) { + return iommu_bus->iommu_ops->unset_iommu_device(pci_get_bus(dev), + iommu_bus->iommu_o= paque, + dev->devfn); + } +} + void pci_setup_iommu(PCIBus *bus, const PCIIOMMUOps *ops, void *opaque) { /* --=20 2.34.1 From nobody Sun May 19 08:24:53 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1712564225; cv=none; d=zohomail.com; s=zohoarc; b=oIu8Xr1pZ0VDQBpjZktvJdzYefZ7GAzHDBGHFNRfRtY8bozLmR+GYU7ghQPZJM6A+WaSg07rc9RO1f57M6t6uGDQOV9N0qgiRsEMu0gnhh45U1Z1uZApCeCOST/Fb3m+ffgMszLO0BAv8OWr5OH+NyxDg3yGwR76yknFIiPHGWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712564225; 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=kHqykyC8b+BJYy4FxOgjTdOQ3JFGJ7/NgoSk8DOSj1M=; b=VbIRV5SrZ0aMOkCXqxnhDFJz8nNLPQIKdgpXb4uTuob3AaYUKztWlTw/RNAGBF5VwC3tAtpByuEibvIJlTeBkl+aiRCLT2cjyM2NcY+21DLAOr+eA4AI6GuEQmAAWx8oAzTm1GPHQWrqG3JM4OVWAiRou085H1h9kqOvJVbpe9k= 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+importer2=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 1712564225235833.1560344449114; Mon, 8 Apr 2024 01:17:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtkB8-0004E4-DE; Mon, 08 Apr 2024 04:16:34 -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 1rtkAK-0003UB-GV for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:57 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtkAI-00089q-9b for qemu-devel@nongnu.org; Mon, 08 Apr 2024 04:15:43 -0400 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:41 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 01:15:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712564142; x=1744100142; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=brdfmfoa2727Rep2O7aimUC9ZxCZnVThwz+OaTXE4tU=; b=AS4GVMAii4zrtKfKNxW680ydF2A5wAapkGeAlyS5dakgLveKhqQ+eVAj 3AwCLDEWYkuftGWWIevbdjeLxUQte/rCo7IiyLegE72PHRi5mjNa7mg+b uzfJtM2HUc8Gdd7/aN5YNQgkQoQhD8YYYBsIhY4LGwMUdRZIn2RoJN2Oy xUpGaCo/2CbbYpUB/WIQpNVuaM8PQVu9gAwq7fSo2S43eB6NccO+zLD7r +W5oN7tQpiXElHN8q05AHSEdRG1RiudmbapYR3ozzkCW2XYUiU5bJapRW W8k0RB6WKiUn1l0naLdb0HyOv853FihwilqfiMSd2aMOal+kgGqytb85Y Q==; X-CSE-ConnectionGUID: MGDtHaW3TAauZV5e3M2WUw== X-CSE-MsgGUID: BYzlxdZFSxqkR1gQiD0pZw== X-IronPort-AV: E=McAfee;i="6600,9927,11037"; a="19199771" X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19199771" X-CSE-ConnectionGUID: NsZ77xSCTZupDm0SFEWB4w== X-CSE-MsgGUID: 9+J4+smwSGO54IRKr9Cg9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,186,1708416000"; d="scan'208";a="19845225" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v2 10/10] vfio: Pass HostIOMMUDevice to vIOMMU Date: Mon, 8 Apr 2024 16:12:30 +0800 Message-Id: <20240408081230.1030078-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408081230.1030078-1-zhenzhong.duan@intel.com> References: <20240408081230.1030078-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -51 X-Spam_score: -5.2 X-Spam_bar: ----- X-Spam_report: (-5.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.355, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1712564226709100009 Content-Type: text/plain; charset="utf-8" With HostIOMMUDevice passed, vIOMMU can check compatibility with host IOMMU, call into IOMMUFD specific methods, etc. Originally-by: Yi Liu Signed-off-by: Nicolin Chen Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/vfio/pci.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 64780d1b79..224501a86e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3111,11 +3111,17 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) =20 vfio_bars_register(vdev); =20 - ret =3D vfio_add_capabilities(vdev, errp); + ret =3D pci_device_set_iommu_device(pdev, vbasedev->hiod, errp); if (ret) { + error_prepend(errp, "Failed to set iommu_device: "); goto out_teardown; } =20 + ret =3D vfio_add_capabilities(vdev, errp); + if (ret) { + goto out_unset_idev; + } + if (vdev->vga) { vfio_vga_quirk_setup(vdev); } @@ -3132,7 +3138,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) error_setg(errp, "cannot support IGD OpRegion feature on hotplugged " "device"); - goto out_teardown; + goto out_unset_idev; } =20 ret =3D vfio_get_dev_region_info(vbasedev, @@ -3141,13 +3147,13 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) if (ret) { error_setg_errno(errp, -ret, "does not support requested IGD OpRegion feat= ure"); - goto out_teardown; + goto out_unset_idev; } =20 ret =3D vfio_pci_igd_opregion_init(vdev, opregion, errp); g_free(opregion); if (ret) { - goto out_teardown; + goto out_unset_idev; } } =20 @@ -3233,6 +3239,8 @@ out_deregister: if (vdev->intx.mmap_timer) { timer_free(vdev->intx.mmap_timer); } +out_unset_idev: + pci_device_unset_iommu_device(pdev); out_teardown: vfio_teardown_msi(vdev); vfio_bars_exit(vdev); @@ -3261,6 +3269,7 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); + VFIODevice *vbasedev =3D &vdev->vbasedev; =20 vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); @@ -3275,7 +3284,8 @@ static void vfio_exitfn(PCIDevice *pdev) vfio_teardown_msi(vdev); vfio_pci_disable_rp_atomics(vdev); vfio_bars_exit(vdev); - vfio_migration_exit(&vdev->vbasedev); + vfio_migration_exit(vbasedev); + pci_device_unset_iommu_device(pdev); } =20 static void vfio_pci_reset(DeviceState *dev) --=20 2.34.1