From nobody Mon Nov 25 12:35:52 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=1715159317; cv=none; d=zohomail.com; s=zohoarc; b=ALzxt3c8v5Bz6cpYcihevoGGXqBA74iwl22CJUBf3f97p7YALYT2zuzxCNE2qhFHpXPUsMxKpdDchIICguwFBBFPB+RenYQOohmWgmGq5hKwoWmBAqHgqP4n7DDmwsCyUaaJ9CP+jj8OykQRTcmlifnehHuUA7uvGPu4+BDuytM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159317; 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=Pm/cszAu0KrDT7EVfv+jjySKkwriS/toJItOYRKd0Vk=; b=ccWiWL7LKEdmZbokSobc/B2CH6M/UmtT9pcrgBS/JV0H1pw2Rz4AThJj4k9RUU9pnVjZGr4j73g0PugK6pxjMvBfIyKf8w+yqeTDOTxW1DkWOkurvMxdTqXqPew8anQYJbLDEcc5r4z+FqoBr6mhPZujVWJDs+nVxBllNwfBi0k= 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 1715159317359894.6577428548258; Wed, 8 May 2024 02:08:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dGZ-0008Ug-De; Wed, 08 May 2024 05:07:11 -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 1s4dGW-0008UI-IS for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:08 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGS-0005QH-TF for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:08 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:04 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:06:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159225; x=1746695225; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jn1r/x0KrmfDsO1CfAxa4HhCkuJ3CaPD/BeliOP8JC0=; b=RMeel0Cjk9JzdrPqxjAfwYulHsd4CH3M+Q3CvpkyO68UPerI2x6RaXmG GGeQIlYzxSNGse8k+Thw61P3cO2gKPcfkgtnJVJvO/E8Ku87hOcfB4Bp6 UD9nnb5p0BeToSD6rIbLtRFakvzPRKzA+T+a7TXdKIa57GEsbIIs1626U gzTcG1efDuXirLLjbtmQHONLhlaI0NkLpmJYc3DoB3yZpmfRKpXyWGeuH bMrI/oHkPq2M8GAUqzN3cs50m+CWebvyil1uf6MAqrKnZlG12BSJfBg+9 0fUdcDWoIq/htSiBnKzBwZZ8d9c6qL8AiDR9C6VIWt20tpZhkwo1aqlmK w==; X-CSE-ConnectionGUID: 4AprWPKvTMW0dv7KMTT85g== X-CSE-MsgGUID: TGNElTWMQdibedLVlV41Vg== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160863" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160863" X-CSE-ConnectionGUID: c1Gu0JvcT7u58z7ICP28iA== X-CSE-MsgGUID: NyPxPZkHQ2ml94ohQQ+7ug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226451" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Paolo Bonzini Subject: [PATCH v5 01/19] backends: Introduce HostIOMMUDevice abstract Date: Wed, 8 May 2024 17:03:36 +0800 Message-Id: <20240508090354.1815561-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318334100024 Introduce HostIOMMUDevice as an abstraction of host IOMMU device. Introduce .realize() to initialize HostIOMMUDevice further after instance init. 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 | 51 ++++++++++++++++++++++++++++++ backends/host_iommu_device.c | 30 ++++++++++++++++++ backends/Kconfig | 5 +++ backends/meson.build | 1 + 5 files changed, 89 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 84391777db..5dab60bd04 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2191,6 +2191,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..2b58a94d62 --- /dev/null +++ b/include/sysemu/host_iommu_device.h @@ -0,0 +1,51 @@ +/* + * Host IOMMU device abstract declaration + * + * Copyright (C) 2024 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef HOST_IOMMU_DEVICE_H +#define HOST_IOMMU_DEVICE_H + +#include "qom/object.h" +#include "qapi/error.h" + +#define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" +OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVI= CE) + +struct HostIOMMUDevice { + Object parent_obj; +}; + +/** + * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices. + * + * Different type of host devices (e.g., VFIO or VDPA device) or devices + * with different backend (e.g., VFIO legacy container or IOMMUFD backend) + * can have different sub-classes. + */ +struct HostIOMMUDeviceClass { + ObjectClass parent_class; + + /** + * @realize: initialize host IOMMU device instance further. + * + * Mandatory callback. + * + * @hiod: pointer to a host IOMMU device instance. + * + * @opaque: pointer to agent device of this host IOMMU device, + * i.e., for VFIO, pointer to VFIODevice + * + * @errp: pass an Error out when realize fails. + * + * Returns: true on success, false on failure. + */ + bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); +}; +#endif diff --git a/backends/host_iommu_device.c b/backends/host_iommu_device.c new file mode 100644 index 0000000000..41f2fdce20 --- /dev/null +++ b/backends/host_iommu_device.c @@ -0,0 +1,30 @@ +/* + * Host IOMMU device abstract + * + * Copyright (C) 2024 Intel Corporation. + * + * Authors: Zhenzhong Duan + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#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 Mon Nov 25 12:35:52 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=1715159316; cv=none; d=zohomail.com; s=zohoarc; b=acUnL5d0F2zITXi917pBRHF4NrjqmmK6VvL/Ui7LPR/hi1HVg0mm5mxkOztL9h4dusimjnMoH8W4L6CoYLvGgwQrDK7UUwvC8T8MsDoo/rkIpiKKT/J5pHVuCg4NVacJVvg9ettA9OhHBtYjCKNiHNhnwtp/KhlK4SwbAkYdQmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159316; 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=LOeMkEdX9RuQZa4McVXyn+01HykpPqgeJUmcAP/jrWA=; b=a1oBBMd91+Mo9GqZLIA46OUCfrhRwBbAm2DIRZieHrVVByskdk3KKnyhl3JVbKYKvKht8R3gWH+C2j7pM46UWDSbecauQZCh8BUcLJsxxRbzYCv4M3jPTwyu5N18gt8WQ9i/wF/0QtjipmIL7jIsInjIW+l1AMVhNZSyymmSvY4= 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 1715159316909990.4131451152105; Wed, 8 May 2024 02:08:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dGc-0008Vk-4s; Wed, 08 May 2024 05:07: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 1s4dGY-0008Ud-Fs for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:11 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGW-0005QH-SL for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:10 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:08 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159229; x=1746695229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p7P8aFLeoc4zseIGlhl+TlPbNc3qYP0grqWyfXSUiLo=; b=BavdJXULHaVFunCCi5d6gzpay1jcf+67PBborRmGwhNx3l7S845ebJg5 q298eO6j3uqSpXyZIu1/eE7cWaw8qkEYsroqatZMObPls++296E/n0XiV le5CIE/39WNF7t7rzDT+tryZQKSXRUjXoHSj+6V82aW3z+5PPwyCivnsn pZ4nI6CDgodRIi2LfeU4eqsJPuXnpEmac5nM8veK4pJRivRkPQRMeqAG6 tKto56BzWqA3vtRrrOkvqCS7M8SwMvMl5kh4k7tGduHgYZLSIZzhwh1gG 3LgNSMnixoPVFG3yTSgCR17S74i1p6Kbfl/bbmYavyBabFvl+bKwVV0F4 g==; X-CSE-ConnectionGUID: jPZqHAmXTICY08JxHntfSg== X-CSE-MsgGUID: xqpMtRcrRl20IqPPHuqoSQ== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160880" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160880" X-CSE-ConnectionGUID: RSq4WfkyTkORrXUGLzPYbA== X-CSE-MsgGUID: zLEC3WQjTCCCe7xLrD7z4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226462" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 02/19] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device Date: Wed, 8 May 2024 17:03:37 +0800 Message-Id: <20240508090354.1815561-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318313100010 TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO represents a host IOMMU device under VFIO legacy container backend. It will have its own realize implementation. Suggested-by: Eric Auger Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 3 +++ hw/vfio/container.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index e4c60374fa..05a199ce65 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,8 @@ typedef struct VFIOGroup { bool ram_block_discard_allowed; } VFIOGroup; =20 +#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" + 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 86266f3b83..1b4fc2f3e8 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1139,7 +1139,10 @@ 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_HOST_IOMMU_DEVICE_LEGACY_VFIO, + .parent =3D TYPE_HOST_IOMMU_DEVICE, + } }; =20 DEFINE_TYPES(types) --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159316; cv=none; d=zohomail.com; s=zohoarc; b=HjKogjxckIX1STfaU3xi2VapMp76MSweNr67BIVNo5NrRbSNRGA2BICkj6K7IhGLlbh4rWqJZ8y4lArxbzP8KrxRWG7XjEjR0l1MUzab2qqYh/KdVE7hbyxwu+daNCCjiFuO95unv16j8VtjshXHWWQ8HgCIb4lC1OU3klLl2zA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159316; 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=mH/JiIgferU6oCao2p7Tapqo214TASKKBg6z8QAVs5M=; b=gSH0gJullph2APcH8akHLYgLPWNHYoGufDRrmnPNbXI/BLpeeKkL6ycSUQNOLW7DQtAeYQiXwsBA3kiXrIk+ARLTuH+JkpygfY1KaHecIhIFnStltAJaMOyst+r1/ae5GHUxl1empYo7l6J0Abthy9s+1x14s4LarvF2BqDhkL4= 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 1715159316897548.1677910640351; Wed, 8 May 2024 02:08:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dGd-0008WQ-Kt; Wed, 08 May 2024 05:07: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 1s4dGc-0008Vm-3r for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:14 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGa-0005QH-Fy for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:13 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:12 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159233; x=1746695233; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HyMVnPMTTEUPdrB/hPu5Ki1bM4XiJMJIG5t/CiWycQo=; b=kJV1zgAgt7HLPnL/ZMdDNDMTSqFxpmbWNdRq8tItSdycQJvIshDhsK2C gG9kjCpF9EW7n475BxZZNrCGtSz56Gs9G6+KYceD/iD3mPZvag9DGChFT pFdOsQHYTmlcmsmXXE9ZXZk2fyr6Cd4mWjEYmpR8moJs58bdoz4nIPvN2 fB72MeyO1TrYaV+T/GKmuN8lVC4qwt16Ob5p8OVZzHdNJETakB4Z1o6xd j30jOgTgny29Hx7kemf+EEe8bE66Y12I2/7FK+MrLOMueH0H5/X5ULkLV Z4KR2ZZHSinWl1IPNyJ1Ki9R6yX2UFj3HxVWYhV1x8VVg2ppuhJKqUC4P g==; X-CSE-ConnectionGUID: 9LHjoxf7SyWpSFUyFjRSDg== X-CSE-MsgGUID: b/v4zAISQledxCht8oEwfA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160901" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160901" X-CSE-ConnectionGUID: xod3nQX3TCiW3gk/VjB9OA== X-CSE-MsgGUID: EYQvQbAAT2aB/Jp+NKN8mQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226468" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 03/19] backends/iommufd: Introduce abstract TYPE_HOST_IOMMU_DEVICE_IOMMUFD device Date: Wed, 8 May 2024 17:03:38 +0800 Message-Id: <20240508090354.1815561-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318323100013 TYPE_HOST_IOMMU_DEVICE_IOMMUFD represents a host IOMMU device under iommufd backend. It will have its own .get_cap() implementation. Opportunistically, add missed header to include/sysemu/iommufd.h. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 16 ++++++++++++++++ backends/iommufd.c | 35 ++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 293bfbe967..f6e6d6e1f9 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -1,9 +1,23 @@ +/* + * iommufd container backend declaration + * + * Copyright (C) 2024 Intel Corporation. + * Copyright Red Hat, Inc. 2024 + * + * Authors: Yi Liu + * Eric Auger + * Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + #ifndef SYSEMU_IOMMUFD_H #define SYSEMU_IOMMUFD_H =20 #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 +47,6 @@ 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_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index c506afbdac..012f18d8d8 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -208,23 +208,24 @@ 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 }, - { } +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_HOST_IOMMU_DEVICE_IOMMUFD, + .parent =3D TYPE_HOST_IOMMU_DEVICE, + .abstract =3D true, } }; =20 -static void register_types(void) -{ - type_register_static(&iommufd_backend_info); -} - -type_init(register_types); +DEFINE_TYPES(types) --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159318; cv=none; d=zohomail.com; s=zohoarc; b=aSGp3HFvdPQQOAijdq+Egt2Xl28/RYw34lCOksT49O5RGALkUyx4VR3rFSLNrzhZsjJputY/SrLuW4YGXCv6cxRuswzJTaB38ON8Pm5PN+ydzS1P9BCJ1d+gIdc1a+hYqmlbGpsOs097VwgClESk1HbVb0x9X03DNF/LQKIVR/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159318; 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=IHyTlAscgiqJhu5p7X7CAKFd614XCF+NgZJn1ogLN0A=; b=lEVI1t4egu98ZBMIPEFWXqcspGKJl96o/m4nbV3nJVgx9WsqQTcW7rgQ0VFMyzD2GNPn8alAfQwmhrwllxDu0rSFVgUaF9DzVeLeJ4seb1BY/43UXjoU4u+44gvu3MkRrFQSdVn7VZxYqD43dzvN0O4JokxUA+7lXcXJsF4+UYY= 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 1715159318097809.4932173105008; Wed, 8 May 2024 02:08:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dGx-00007S-E3; Wed, 08 May 2024 05:07:35 -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 1s4dGp-00006v-Uk for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:27 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGe-0005QH-JJ for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:20 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:16 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159237; x=1746695237; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zEb4sLTc/j+SaohFZy7OiH9RZU/pHjGFuDFgJP18iPQ=; b=c+s/ps6SqU7GHbOTlbIA/kiURHEM6h2Irc1B2JYhWnOfCE0rDfYI45vZ ilWsggoiemeiQOnLZ7p96K1RxpCx5P3hNBlhtLH+sM/gpesqW+qecA8Hu 0EBn8jVYRQp+ebZtDM42wwzP7wB/jly7AYWuenyXVpt1H6W0WmeIRFx+S 7SN53zar1u8jSiu0bWnAzU6v0aIjzWjuc7Ih67zHn2aOCQHcuJgSXoRZs +lPDoijISTIDPs2F+GM6i8F93XMWiof36h89L2kplbdu4On9ukoHAPBN2 D3/Rhn84x9rnPEikYkeVuJ6MSjJ//Koaq3b1qy77oksB7wME9bO2q+XoJ Q==; X-CSE-ConnectionGUID: YzR8c7RwRVGhiqO8ZiJIBg== X-CSE-MsgGUID: K6aixxLNT46IBRqUMoQ9mg== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160926" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160926" X-CSE-ConnectionGUID: X/5fb+a+QzWF6sWRYSn7/g== X-CSE-MsgGUID: /uzBjO1kQsCBx5b1IA/KFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226472" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 04/19] vfio/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO device Date: Wed, 8 May 2024 17:03:39 +0800 Message-Id: <20240508090354.1815561-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159320240100032 TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO represents a host IOMMU device under VFIO iommufd backend. It will be created during VFIO device attaching and passed to vIOMMU. It will have its own .realize() implementation. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 3 +++ hw/vfio/iommufd.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 05a199ce65..affb73f209 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 @@ -149,6 +150,8 @@ typedef struct VFIOGroup { } VFIOGroup; =20 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy= -vfio" +#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \ + TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio" =20 typedef struct VFIODMABuf { QemuDmaBuf buf; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 554f9a6292..e4a507d55c 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -624,7 +624,10 @@ 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_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, + .parent =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD, + } }; =20 DEFINE_TYPES(types) --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159317; cv=none; d=zohomail.com; s=zohoarc; b=WC9v/6ETe1vfg//yQdayaSLG/WuWVj9G84lS2hwhSbmVzpRizCpQDgIf48JqKcRVEsH4W/YsVN7vQKOv9Muc9F7HvLC7bjzk7eJTC0wwa2aSDS70q6cR3U2++2nMNEqe4X/j+ZfTJNJTJy3H97M0IPugDG1Ltrei9ov361FiFAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159317; 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=/5hjjRjxaficEo4hLIjC2I3Q+aYqD4q/gS0HMKcYqO0=; b=cIhBPFL2GnwqiecoAMEAVF1b4TzGSbw37xBQ7N5gTfPvU8/eR9vv1tCBqP6M/63v7ubsujC1VXBUU3E8cNRkaHqcu4P42WmW0WkVWNB1f6208HHpyUUpl0afYiDDp2kUnbDUA8wiI1kyWjF1gA3zK5JH78YgDzr3K/UOw2IapP0= 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 1715159317331528.9245406392736; Wed, 8 May 2024 02:08:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dH9-0000B4-0H; Wed, 08 May 2024 05:07:48 -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 1s4dGr-00007O-An for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:30 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGn-0005S1-GA for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:29 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:21 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159246; x=1746695246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=15cgjyTdq3RQ+ajo/M6kOTL4pynkB+V+xA7Xu9sIZ9U=; b=R6VUGTGhDVndBHzYi5ume9wH6kR224O1ORGOjF20W4Ek9TzD3aboqfl1 MCdB7U+P5dyM2vq/ihu0PeLVzv6Ck1LxqwnWpkCsfDtLfjFbNP0Kwd+jr tRdr6ld/bbqjqHEOitHgvFqLqXAYuJzGur8q3I2dlwdAn3gTXpK33ma7o 8KurqgBVoigA+xqBDaNQCBFVxFm4Y+1kwORjUFYuM1ROPNv2FaJyVzjUp iBQ+1E+5hrHeLat6xhZ9mTu1bTrzHOLb92Ne6thx4n0ntgFtnVxZFnUDe Xugct58lc8WuEisEqrOKnYSOthLiSRDjNIj2HGpJ0gZ7qWmQJVOES+s7W A==; X-CSE-ConnectionGUID: /U1O6P4PSpShqlo8lJyeFA== X-CSE-MsgGUID: DFNRx/OcSmqcFdrdaN9dYw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160947" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160947" X-CSE-ConnectionGUID: JGXo3fisRwynItDYLpvNFw== X-CSE-MsgGUID: O4KNJgGBQCSNgm8wuvihUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226479" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 05/19] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps Date: Wed, 8 May 2024 17:03:40 +0800 Message-Id: <20240508090354.1815561-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318313100011 HostIOMMUDeviceCaps's elements map to the host IOMMU's capabilities. Different platform IOMMU can support different elements. Currently only two elements, type and aw_bits, type hints the host platform IOMMU type, i.e., INTEL vtd, ARM smmu, etc; aw_bits hints host IOMMU address width. Introduce .get_cap() handler to check if HOST_IOMMU_DEVICE_CAP_XXX is supported. Introduce a HostIOMMUDevice API host_iommu_device_get_cap() which is a wrapper of .get_cap(). Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/sysemu/host_iommu_device.h | 40 ++++++++++++++++++++++++++++++ backends/host_iommu_device.c | 12 +++++++++ 2 files changed, 52 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 2b58a94d62..ed4cbc967a 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -15,11 +15,25 @@ #include "qom/object.h" #include "qapi/error.h" =20 +/** + * struct HostIOMMUDeviceCaps - Define host IOMMU device capabilities. + * + * @type: host platform IOMMU type. + * + * @aw_bits: host IOMMU address width. 0xff if no limitation. + */ +typedef struct HostIOMMUDeviceCaps { + uint32_t type; + uint8_t aw_bits; +} HostIOMMUDeviceCaps; + #define TYPE_HOST_IOMMU_DEVICE "host-iommu-device" OBJECT_DECLARE_TYPE(HostIOMMUDevice, HostIOMMUDeviceClass, HOST_IOMMU_DEVI= CE) =20 struct HostIOMMUDevice { Object parent_obj; + + HostIOMMUDeviceCaps caps; }; =20 /** @@ -47,5 +61,31 @@ struct HostIOMMUDeviceClass { * Returns: true on success, false on failure. */ bool (*realize)(HostIOMMUDevice *hiod, void *opaque, Error **errp); + /** + * @get_cap: check if a host IOMMU device capability is supported. + * + * Optional callback, if not implemented, hint not supporting query + * of @cap. + * + * @hiod: pointer to a host IOMMU device instance. + * + * @cap: capability to check. + * + * @errp: pass an Error out when fails to query capability. + * + * Returns: <0 on failure, 0 if a @cap is unsupported, or else + * 1 or some positive value for some special @cap, + * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. + */ + int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); }; + +/* + * Host IOMMU device capability list. + */ +#define HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE 0 +#define HOST_IOMMU_DEVICE_CAP_AW_BITS 1 + + +int host_iommu_device_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp= ); #endif diff --git a/backends/host_iommu_device.c b/backends/host_iommu_device.c index 41f2fdce20..0fcc201af3 100644 --- a/backends/host_iommu_device.c +++ b/backends/host_iommu_device.c @@ -28,3 +28,15 @@ static void host_iommu_device_init(Object *obj) static void host_iommu_device_finalize(Object *obj) { } + +/* Wrapper of HostIOMMUDeviceClass:get_cap */ +int host_iommu_device_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp) +{ + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); + if (!hiodc->get_cap) { + error_setg(errp, ".get_cap() not implemented"); + return -EINVAL; + } + + return hiodc->get_cap(hiod, cap, errp); +} --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159512; cv=none; d=zohomail.com; s=zohoarc; b=GyYHPSUxwps83DomL3/mMjHoTLiF1TC29Rodq9nFC+OTnOf2VQjMvLOvCFiqFr1i/2z0zHghgC+gg5yaAbR4UJu2+TI7RLGi60uhDws5vS2itfHnSO6xTQ+7M8cKUcRmL7bQuLDIygrwPAmz8n5C5uMfVizkGrajLSBG3RvlQ6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159512; 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=SSSKaAZjNhlbCc86YSc4mQuDqDKk5uZtheoGzQHjd00=; b=KFovHjtROhj1yJ6Gv5zwaX4GXZBUTDMHvn3WFaB0gZLfYsuP4vKq23/q6eQFKbBDKEPF3s4L9WYzU/DgYNNqwrN8Enx2ZHzhRa70m1CY3Mp4xvoD7i+KhKu+VGK81r/Bno3BG2NXnKi2M64AIkxkfT3ozSFCU/PEOlPOdIWJPmA= 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 1715159512703644.2879044001131; Wed, 8 May 2024 02:11:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHR-0000Xd-AY; Wed, 08 May 2024 05:08:05 -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 1s4dGx-0000A5-Ko for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:35 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGp-0005SD-PM for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:33 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:25 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159248; x=1746695248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OP3qnqR2eeb5LkENXO26BG3fJHDhCXlpbz0ddpelol0=; b=MFp+IWyzNzQ3Vh5jWsYMSoc4bdDarLw1N1NkfjM2uPaNPFfkTffCPejx Yh79i5SjhQEkms3HJCRIQc0mJqk/doXffxRdN5Zk7q1+ZHce6Gktw+byd 6HsxoFMbvVYUcaEukcZlvDOmsLtgqNCdJjmxQL3nOnee76la+xGea59lE TA0JYzSumfe0y619U5tezw67rzzaeDoGVZJNPKSw9FHeqFrgFzzvA7++k FYs4w2PmZOh0JGfNSpzZ3KLv2GGWzmFrfc1lG54UVg1CK/jRkRgc4rhqk YZINtGHIXM89oBVoRQ3zAm2BO4qz81A3LDh5spO9iaSt+sLxPjx4ByRsZ w==; X-CSE-ConnectionGUID: rLT+Sb47RGOg7GRJJqAWBQ== X-CSE-MsgGUID: 7S1s+s0/Sh2NCSsfFDe4EA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160964" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160964" X-CSE-ConnectionGUID: 463RM6bBQKKyvy2tanse4w== X-CSE-MsgGUID: eHMRwniHQoS2xaEIY2xjHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226484" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 06/19] range: Introduce range_get_last_bit() Date: Wed, 8 May 2024 17:03:41 +0800 Message-Id: <20240508090354.1815561-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159513159100007 This helper get the highest 1 bit position of the upper bound. If the range is empty or upper bound is zero, -1 is returned. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/qemu/range.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/qemu/range.h b/include/qemu/range.h index 205e1da76d..4ce694a398 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -20,6 +20,8 @@ #ifndef QEMU_RANGE_H #define QEMU_RANGE_H =20 +#include "qemu/bitops.h" + /* * Operations on 64 bit address ranges. * Notes: @@ -217,6 +219,15 @@ static inline int ranges_overlap(uint64_t first1, uint= 64_t len1, return !(last2 < first1 || last1 < first2); } =20 +/* Get highest non-zero bit position of a range */ +static inline int range_get_last_bit(Range *range) +{ + if (range_is_empty(range)) { + return -1; + } + return 63 - clz64(range->upb); +} + /* * Return -1 if @a < @b, 1 @a > @b, and 0 if they touch or overlap. * Both @a and @b must not be empty. --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159317; cv=none; d=zohomail.com; s=zohoarc; b=hPoQnUMuWWQ4I1WM3VtW5b4BboyaQAk1aN6UJUig7TgBVPfcNCV3JhIIUtQmUMI98qOMsh6CNWE8+gSQWUoR/G246JDnCjMDH27fflDcUzfUMP9V9dnZjjQ8MjJhlsHNjk7sHRiXTlkmSCnq1My4AnajFbnzxPJxZvv5PWC4omk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159317; 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=znnEs4LSqjSW91U20gJpL0DcTCMISCCjkW8uzHweod0=; b=lki7OHhXE+zZzCR0eHU+SGdpVRg0PW9kankTPvnZ//1VaC+N6KRl06EBK9MqX/KehKP5KeEn+8bTkIlSCMuwJkvJtfT282h+8cTf54B9EkV4MyyDX4PpQTZgpm7zgc3e991kfRARSoYhPXbDsDo1rOzdIL2D4aYu2NGgJLG2r7E= 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 1715159317170112.41334354040214; Wed, 8 May 2024 02:08:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHR-0000ZV-O0; Wed, 08 May 2024 05:08:05 -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 1s4dGx-0000A6-LZ for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:35 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGq-0005QH-SV for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:30 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:29 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159249; x=1746695249; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MjIaxja7ZxYGI0e28fQ6Z2a0sW+X9+K6isij7W/S8uA=; b=RMTZmIrnTfg8lX5KUMY6SD6WphGcbH2VwsPO64syApXFgglo1+cbY6od 6rarS6faGHNQzFLpmRNHX+EfqZmfZtOfi5Pywi+lAysTqX00QEaicSGIf i94hZKIislZ6RzHAwXLqvtf4d45h+3R3BROh2vD2QY7mNdc6zm/RXPiwI J82s4GhlDddBMRn+518UcsB2aCTEVxg9VVxpAAJd+rcogJhfuu7xr0+CO r+WatI0HjJZiM+kvRCxNMh6irG6cP60G5zc9eRBEgBhLYkCElNilYjZs6 scOkjSEswjLVRECQRG3BqGOtHmvjg8qkOtRU/vF+5Sm/E9ELMXcXOUdIt g==; X-CSE-ConnectionGUID: hKBHO9etQAaR5yqWnV3P4Q== X-CSE-MsgGUID: BuCXyB+iQua0X+Fm1z8JlA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160980" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160980" X-CSE-ConnectionGUID: P4IpsjssSUCBd+EsUibvDw== X-CSE-MsgGUID: QgjF/ZowQcuE8RKxw9INGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226493" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 07/19] vfio/container: Implement HostIOMMUDeviceClass::realize() handler Date: Wed, 8 May 2024 17:03:42 +0800 Message-Id: <20240508090354.1815561-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318299100004 Content-Type: text/plain; charset="utf-8" Utilize range_get_last_bit() to get host IOMMU address width and package it in HostIOMMUDeviceCaps for query with .get_cap(). Signed-off-by: Zhenzhong Duan --- hw/vfio/container.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 1b4fc2f3e8..b872f6f201 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1134,6 +1134,31 @@ static void vfio_iommu_legacy_class_init(ObjectClass= *klass, void *data) vioc->pci_hot_reset =3D vfio_legacy_pci_hot_reset; }; =20 +static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, + Error **errp) +{ + VFIODevice *vdev =3D opaque; + /* iova_ranges is a sorted list */ + GList *l =3D g_list_last(vdev->bcontainer->iova_ranges); + + /* Only support query HOST_IOMMU_DEVICE_CAP_AW_BITS with legacy backen= d */ + if (l) { + Range *range =3D l->data; + hiod->caps.aw_bits =3D range_get_last_bit(range) + 1; + } else { + hiod->caps.aw_bits =3D 0xff; + } + + return true; +} + +static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) +{ + HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); + + hioc->realize =3D hiod_legacy_vfio_realize; +}; + static const TypeInfo types[] =3D { { .name =3D TYPE_VFIO_IOMMU_LEGACY, @@ -1142,6 +1167,7 @@ static const TypeInfo types[] =3D { }, { .name =3D TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO, .parent =3D TYPE_HOST_IOMMU_DEVICE, + .class_init =3D hiod_legacy_vfio_class_init, } }; =20 --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159511; cv=none; d=zohomail.com; s=zohoarc; b=GyoMeV+P7hUGSIxhLZmacBREGWCVfMLfklAVhCXWbO3kxlAPzEN3jEmydiTXcfNnArgel8kcja4XQjhNlBNBpab1PruDzl/7I3NBJ6nn0NOhumwczNpMQ13guRbu+0woMet48bjXrTZuaMBzhphC5iMd6lcSsLo+pGLd/CplFb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159511; 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=tpjH0bZTJ1a3nZKBzu/Ew8LT2WXeafN/TYbkS/UR5Nk=; b=dHS49Prl3Vg8NOKf0zr5BQlZ31TE8D/p/2kmXzMXD6uv6p2ufUfklU45vdW/9de1wEF2WfsPZ+UXyqNRoWUZ7vAUJKfdayNYS1+OeKTBZ3kfJQlKWZ7YXVJMa+k5+JYB6lyAaCRZlgR2IZoQAPsFVhq8IBie/fq+O6E6rn0Atk4= 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 17151595113099.08463316798725; Wed, 8 May 2024 02:11:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHR-0000HW-1V; Wed, 08 May 2024 05:08:05 -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 1s4dGz-0000An-3F for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:39 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGx-0005S1-HG for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:36 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:33 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159256; x=1746695256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SFnso2XJZnjcpe6vQEbV6q0DMy+GxluEI4QwMoNhpTQ=; b=IZsTp8sgX/BIMlUn64Cp5OMruTnxTxud/0TCkAe+UwFUYxNao6OfeqLG YBvxmizA7sRjgaS63HL4gZ3cfVgCvsAzIuFVaqHHddpg3+4kl4TNAUAH5 AwS+PTbo3c5GD2Ylv4FsxmZRwfdb+0m3FBaSkhxONG5LgjaSi2P4viQqZ zsjZol1xNo0SY1Im7m29al/mrgpYdag/oQ9PACiihZJP8e+XJ3/9fTv7l XwxvdGfLZtN26wjbfBmif+bWLiEjsN9hSefzuMM4leB0QKPmJmSQC06QN XJXaKSY750tIIlptYhvp5UMwl2EbGErlnIL0v8+ItLblnwKDYbaejnF1v g==; X-CSE-ConnectionGUID: 2tQwEplhQt68MwlgOu1Eew== X-CSE-MsgGUID: P7uH08dJRcqbQnKeKkI6gA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11160987" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11160987" X-CSE-ConnectionGUID: Y6wEunqPR629wRriQzOtGg== X-CSE-MsgGUID: /wpUKT9ZR525r6xNLULxFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226507" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v5 08/19] backends/iommufd: Introduce helper function iommufd_backend_get_device_info() Date: Wed, 8 May 2024 17:03:43 +0800 Message-Id: <20240508090354.1815561-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159513162100008 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 | 3 +++ backends/iommufd.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index f6e6d6e1f9..9edfec6045 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -47,6 +47,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); +bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, + uint32_t *type, void *data, uint32_t = len, + Error **errp); =20 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 012f18d8d8..c7e969d6f7 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -208,6 +208,28 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint= 32_t ioas_id, return ret; } =20 +bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, + uint32_t *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, + }; + + if (ioctl(be->fd, IOMMU_GET_HW_INFO, &info)) { + error_setg_errno(errp, errno, "Failed to get hardware info"); + return false; + } + + g_assert(type); + *type =3D info.out_data_type; + + return true; +} + static const TypeInfo types[] =3D { { .name =3D TYPE_IOMMUFD_BACKEND, --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159451; cv=none; d=zohomail.com; s=zohoarc; b=bUdWbpbG9P/qcthhdBoJJj5NQpTKIPq0sxT5gQxm4ZGisIZIF2KBIchbBku42SN7NOT6bshQrXSdmH3cB6iU5Jg74eZ7yuT0t9YLGEEwsmh9qg9n8UcmTuTBp5YslB7LZJyq+nTYNyFA0+Esuanw7ZnqfutxJ+BwheN84Wr8yUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159451; 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=cJ4oXg5jALSaqMzSqvz6Fwk2QJwyzPKU/hxs+80LlQ0=; b=T6t+xSustkSsYumDEMh4Feontx1sfJgBHFtN+n5A6SXqclYRSKaTfi0YYkMUF+5EmvJn3YHAVY9FMi69DnR3e0ElRqyHfJE/4QMN9lfoBDPvuR65Af4tyrhd9Nog1CDslh0wIthcKJa+4qx6lwZZXCbQzCauSgIlmpnsVJ0WgqQ= 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 1715159451293364.3542229980545; Wed, 8 May 2024 02:10:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHU-0000ro-01; Wed, 08 May 2024 05:08:08 -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 1s4dH9-0000CE-3D for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:48 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dGz-0005S1-F9 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:38 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:37 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159258; x=1746695258; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VOrfu7fZiy+3eHvD+lVlGibrcIGk/lLlGO5XtB2n6eA=; b=FZtH8yaLHUqpg2Ks1DsExECktl+LGvW7aF+ATqRIeo2lL9cKLRiBN5es M/p3eziFEuBKv954dz3C1chyeFA3d2rLKVL6L9Tewqbf44ZVZrXm7kClG x1wnjfk7N9UeFNxWxNkSTzcttxi7IH0uvQjVtUjokqS9Aqqw95V291ggy sm6c2pq5EclxxNcdCLm5BmCBg+bZ/JcwndQ2REjasyT+kSnqMzz3tN4BZ HNBGS9VtZdr5O+l2XSDh75jELhfPqPnKzWznnHkRDqeK7XCVHDTLOIGyE CYA0j3AyMgwmwWgzjN8BNwV1Dz1vSX51Zn25sIdoj7DFnpfr2IhDRwXyQ Q==; X-CSE-ConnectionGUID: UmMDms4GSkemDUJoMnQPGQ== X-CSE-MsgGUID: ZIPIwg3qQaeIzzQxWeM7pw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161002" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161002" X-CSE-ConnectionGUID: jtMM3IBdTey840bjDO+a4w== X-CSE-MsgGUID: sohtGYNETSKo/YNsx5rwlA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226526" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Marcel Apfelbaum Subject: [PATCH v5 09/19] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler Date: Wed, 8 May 2024 17:03:44 +0800 Message-Id: <20240508090354.1815561-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159453028100003 Content-Type: text/plain; charset="utf-8" It calls iommufd_backend_get_device_info() to get host IOMMU related information and translate it into HostIOMMUDeviceCaps for query with .get_cap(). Introduce macro VTD_MGAW_FROM_CAP to get MGAW which equals to (aw_bits - 1). Signed-off-by: Zhenzhong Duan --- include/hw/i386/intel_iommu.h | 1 + hw/vfio/iommufd.c | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 7fa0a695c8..7d694b0813 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -47,6 +47,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(IntelIOMMUState, INTEL_IOMMU_D= EVICE) #define VTD_HOST_AW_48BIT 48 #define VTD_HOST_ADDRESS_WIDTH VTD_HOST_AW_39BIT #define VTD_HAW_MASK(aw) ((1ULL << (aw)) - 1) +#define VTD_MGAW_FROM_CAP(cap) ((cap >> 16) & 0x3fULL) =20 #define DMAR_REPORT_F_INTR (1) =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index e4a507d55c..9d2e95e20e 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -25,6 +25,7 @@ #include "qemu/cutils.h" #include "qemu/chardev_open.h" #include "pci.h" +#include "hw/i386/intel_iommu_internal.h" =20 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr io= va, ram_addr_t size, void *vaddr, bool readonly) @@ -619,6 +620,41 @@ static void vfio_iommu_iommufd_class_init(ObjectClass = *klass, void *data) vioc->pci_hot_reset =3D iommufd_cdev_pci_hot_reset; }; =20 +static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, + Error **errp) +{ + VFIODevice *vdev =3D opaque; + HostIOMMUDeviceCaps *caps =3D &hiod->caps; + enum iommu_hw_info_type type; + union { + struct iommu_hw_info_vtd vtd; + } data; + + if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, + &type, &data, sizeof(data), errp)= ) { + return false; + } + + caps->type =3D type; + + switch (type) { + case IOMMU_HW_INFO_TYPE_INTEL_VTD: + caps->aw_bits =3D VTD_MGAW_FROM_CAP(data.vtd.cap_reg) + 1; + break; + case IOMMU_HW_INFO_TYPE_NONE: + break; + } + + return true; +} + +static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) +{ + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); + + hiodc->realize =3D hiod_iommufd_vfio_realize; +}; + static const TypeInfo types[] =3D { { .name =3D TYPE_VFIO_IOMMU_IOMMUFD, @@ -627,6 +663,7 @@ static const TypeInfo types[] =3D { }, { .name =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, .parent =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD, + .class_init =3D hiod_iommufd_vfio_class_init, } }; =20 --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159353; cv=none; d=zohomail.com; s=zohoarc; b=VEoFejhIhIgAbRrXwDCwoUohIUNk1weArlO4u+VaFH8/kM8YgCSbF1+6vTjifEKijj1viza/COh7Kc0JdIBaYEZg3zs/FOoxHMWup9tUQ2H2Vh+tkNMc5mg6aREXBxwUuDUcMSLzuN/rv3sqR+svbx5BKnqnsn69QaHgfQ90z3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159353; 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=uMtEQc3oyvxOy81HbT/bmJkJ2LXjmYcEaZyGE7kpizQ=; b=mhH6+fIBiHGIAKgsmKgLO9qLf0w2o5ax/q1gtlYSrtLtDsV5wDN+ioq9/YMi6K3l+pgIjKvkGv2I2slROgxA9qRvRWzFRogBFz/3X3PbbndZx+Z3QqOYM6IxrkJYcBSmA/wpvOpoMMSgQBSf11/55kll96mu8ChS/ty42owXxJ4= 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 1715159353619616.3263819210041; Wed, 8 May 2024 02:09:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHV-00015S-Q3; Wed, 08 May 2024 05:08:09 -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 1s4dHG-0000E4-AO for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:55 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dH9-0005UG-0E for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:53 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:41 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159267; x=1746695267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r2PRuTeAulGK2h55QuvDIkzfGoc3c4Qtcfz0sVeJKh4=; b=AZkQb6VIkbbH9UD0vS/pOo1Iw43u+r4EFDk5P8U3rJO9TUDmGidKFhnT GoWRkmH+Eon335ABHeDwk+XdpIr91VJiK43dlYfu972ZLr3eIMlUCdkGn uUPQaBZjyIa9LM4cAZNQ2+Wesy7P98ErIaKqp0sKkEB/9ugWOCoHS5LEY bh14EOUPe+0YjyY4SnelecbsDVcXPBbXI6nALIDcNTDOly1WZz2yBSd9G 2kGvZRVzRYq0cotXECB1azs4YtB3NtuqXJdJJ64zJXDpRYOm2uplaATNi 9Y84DGHawY37Oim78nAk8gmQ0Q9uWJC1gzKuhGbIZZL6G5EDaoDhCXn/3 Q==; X-CSE-ConnectionGUID: 44I1UvvKQcCUKFBqy0mlVA== X-CSE-MsgGUID: +w7OUugQR7KSowsLeuiEbA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161013" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161013" X-CSE-ConnectionGUID: fhqq7hh7R12gTwX2q3wFYQ== X-CSE-MsgGUID: uo8h+1FkRLKEJw/D8GobHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226545" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 10/19] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler Date: Wed, 8 May 2024 17:03:45 +0800 Message-Id: <20240508090354.1815561-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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_PASS=-0.001, T_SPF_HELO_TEMPERROR=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: 1715159354385100005 Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- hw/vfio/container.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index b872f6f201..c9c5347da9 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1152,11 +1152,26 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevic= e *hiod, void *opaque, return true; } =20 +static int hiod_legacy_vfio_get_cap(HostIOMMUDevice *hiod, int cap, + Error **errp) +{ + HostIOMMUDeviceCaps *caps =3D &hiod->caps; + + switch (cap) { + case HOST_IOMMU_DEVICE_CAP_AW_BITS: + return caps->aw_bits; + default: + error_setg(errp, "Not support get cap %x", cap); + return -EINVAL; + } +} + static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 hioc->realize =3D hiod_legacy_vfio_realize; + hioc->get_cap =3D hiod_legacy_vfio_get_cap; }; =20 static const TypeInfo types[] =3D { --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159353; cv=none; d=zohomail.com; s=zohoarc; b=JCruqcGtTLsPLSpMAoG4l7uET2/NQHGYODcKD2wSMTH2BRNoDiwYcWXH6ahiVIQnEclDnM2/HBRn9aQOd6MukrvX01b0MeyIkHgI1936RfFvw/uZRbNssYbaeOC5cX8mqmasETIeohqtWkTIwg9QWMpCeNyYxR4N/PcoLgNKAQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159353; 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=Jol/cpHdulgPb0BC8TLP3qlAHHHaX1zckgsUtYxAJME=; b=Q9CtimlLvCrlvf8jHguCLm0ZbsnBDptCwbXaMLzlUkxceMlMocoDDjmF+XRaoYZ++FIpPv0lFBmZUHnjjcQFRO6AtQBYLsjeuldZXFrFJ5YwGD5kxmZi9sSo2CNCS9aDPV5KJi7HsB+HoV/w0fyJP4krVhsmqaiMnE0MOpuXzRg= 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 1715159353612405.6791349660157; Wed, 8 May 2024 02:09:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHS-0000jT-Th; Wed, 08 May 2024 05:08:06 -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 1s4dHP-0000X4-9A for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:05 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dH9-0005UP-4z for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:00 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:46 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159268; x=1746695268; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dAKZSk5QgrnUIjill0jO2g0zyj3Uf0goHqo6GXW+pBI=; b=gvNxcUkrweDSh3yCwfNMvgMnQogGJxbPpL2M9UeSiR+j3gFO5TMD4bIf 96stns1CgwgFSEDP9dsGqax7wqHu+xEQK4tDpl/HI0CWTLRd54A85KK+3 8vxadvA7vCCS7rcUz4V0U0aKu/p4mxn06noDkZ8EvaiMSuxyH1raRTnRw +o19Gz816PmZTDTiisvLE1tkGuEdrOcKWkMFl5SruY9l7X6GUH2w7my2C m9li2xpK5clac2gYLao55PhSyb0KtlOkFCvFtPbcyrwBrInKM7d+7yTpZ P5btvHjktE2ebb9Yq2vDuT8EitUuya4rYgB1FjweQEQTS64qA+etMZhUO g==; X-CSE-ConnectionGUID: /hPFKoxNS1KQH18FVxnivg== X-CSE-MsgGUID: laYfzgsWR8+xloaagABSlw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161023" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161023" X-CSE-ConnectionGUID: br2Og0hBTeee6N5fA17YOA== X-CSE-MsgGUID: Dt+wchmnRTuT/vLe6eUdrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226590" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 11/19] backends/iommufd: Implement HostIOMMUDeviceClass::get_cap() handler Date: Wed, 8 May 2024 17:03:46 +0800 Message-Id: <20240508090354.1815561-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1715159354391100006 Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- backends/iommufd.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backends/iommufd.c b/backends/iommufd.c index c7e969d6f7..f2f7a762a0 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -230,6 +230,28 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *b= e, uint32_t devid, return true; } =20 +static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **er= rp) +{ + HostIOMMUDeviceCaps *caps =3D &hiod->caps; + + switch (cap) { + case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE: + return caps->type; + case HOST_IOMMU_DEVICE_CAP_AW_BITS: + return caps->aw_bits; + default: + error_setg(errp, "Not support get cap %x", cap); + return -EINVAL; + } +} + +static void hiod_iommufd_class_init(ObjectClass *oc, void *data) +{ + HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); + + hioc->get_cap =3D hiod_iommufd_get_cap; +}; + static const TypeInfo types[] =3D { { .name =3D TYPE_IOMMUFD_BACKEND, @@ -246,6 +268,7 @@ static const TypeInfo types[] =3D { }, { .name =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD, .parent =3D TYPE_HOST_IOMMU_DEVICE, + .class_init =3D hiod_iommufd_class_init, .abstract =3D true, } }; --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159317; cv=none; d=zohomail.com; s=zohoarc; b=HdGKkzs5eAIPTN4YnIrlxwi47yXxuHaLdFVCLSd5zBA2qca5QoOsg3eklYQ1EdBOBpO3+hOEIohq2mFKyQgzP9fO+LXM0dJ4srLwfjdfQrwmDJSzqGemjrdg+iuDbkGh+6hvJeRTUfKZzZp98oGDoymyqXiJ1JrjCEbFSjZe6l4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159317; 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=pF097Nu4LYa6NqlBuXaxwKh4bim0On9ZY8BKxxgwAMA=; b=iNQ+Sli2AZi8ajfi3TcHYSBnwDJKsFB6wvCOndan3+ZHimGM7kJ5N4EjLc/li7BwT2vBkXp7fCNI8yS+1hKwhyr5MmzFwhvEkU+NB5u3iG3jJpIS4B6kU2ri782v29otAZlMFDhudMeZknlFTqlbdqMUnJyyDSUyraYRv6v/h9c= 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 1715159317051755.0679294917128; Wed, 8 May 2024 02:08:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHS-0000g9-Es; Wed, 08 May 2024 05:08:06 -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 1s4dHG-0000E6-B3 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:55 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHD-0005S1-PA for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:53 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:50 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159272; x=1746695272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5t166Nmcv4MTvQcqwSqlR73fJYwil6Adj9OK9wDutUg=; b=BkchdB1WC/8AZ2P7R3EfRjn9Gr1Jn6GLL7PRqZFePCWObpQsb5WyxBuK A+5ON1wjxKq7pLxdu6/Z1t6leOoJ6J9it3RZ2cR3pKbvR3ZOxH/E0hdk7 u6gTpSTa+pw7y9SY+Qu3HiJO7eDceCjtsTpcyZHf9/pLgtrkB5r3iATx7 kBHqSPHK9JTxzo02tE6BLyWqSsze21APcCr73gOiMAl0AYUMXnLKCbh+c cKcOE8oRwZEPwLdTglPtax2go+sLgonVckJZ/aGKN/6eE7Ux+3UiHLwAK NUoqHdQFg1tT7QRcqrW/L8zl1cFWnyb4aZgwn9WC8M99UO+qIkOc5FOSK Q==; X-CSE-ConnectionGUID: xMLAuDR/S9ewf9KA9eI3ng== X-CSE-MsgGUID: GQEnOpOdTn6vBbipiLSSyw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161029" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161029" X-CSE-ConnectionGUID: HPLKAHefQVWLkMUg49d5tw== X-CSE-MsgGUID: 9YB35r0bR6Oran/Tovec6w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226613" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 12/19] vfio: Introduce VFIOIOMMUClass::hiod_typename attribute Date: Wed, 8 May 2024 17:03:47 +0800 Message-Id: <20240508090354.1815561-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318300100005 Initialize attribute VFIOIOMMUClass::hiod_typename based on VFIO backend type. This attribute will facilitate HostIOMMUDevice creation in vfio_attach_device(). Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-container-base.h | 3 +++ hw/vfio/container.c | 2 ++ hw/vfio/iommufd.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index e96cda78c8..da00d6497f 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -110,6 +110,9 @@ DECLARE_CLASS_CHECKERS(VFIOIOMMUClass, VFIO_IOMMU, TYPE= _VFIO_IOMMU) struct VFIOIOMMUClass { InterfaceClass parent_class; =20 + /* Properties */ + const char *hiod_typename; + /* basic feature */ bool (*setup)(VFIOContainerBase *bcontainer, Error **errp); int (*dma_map)(const VFIOContainerBase *bcontainer, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index c9c5347da9..f9708f94da 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1124,6 +1124,8 @@ static void vfio_iommu_legacy_class_init(ObjectClass = *klass, void *data) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); =20 + vioc->hiod_typename =3D TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO; + vioc->setup =3D vfio_legacy_setup; vioc->dma_map =3D vfio_legacy_dma_map; vioc->dma_unmap =3D vfio_legacy_dma_unmap; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 9d2e95e20e..8fd8d52bc2 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -613,6 +613,8 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *= klass, void *data) { VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); =20 + vioc->hiod_typename =3D TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO; + vioc->dma_map =3D iommufd_cdev_map; vioc->dma_unmap =3D iommufd_cdev_unmap; vioc->attach_device =3D iommufd_cdev_attach; --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159316; cv=none; d=zohomail.com; s=zohoarc; b=iTLbKtplrSkFb7naV3+jLO6hXEJ/3B86uB2Y2RcXhPSlPZlxGnJTU1QGiktiSPOyeHhPbmthWuA03U+JlRFIkE1Bnhccq72OY6Tpxth8oulwuEEEiGUl0kUwdoj+9bL+ltGxP0mR3anjyacSNXWuEUtyfUMQ0XR3y1BwyiG9jOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159316; 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=t0PVllTd8HTOuJhBKaSYq/7VFjg+n+2oBe+6EXSqwmk=; b=nD2QdJDEoSyStLMDGZiXFJ0cZmiNG4OxGeZzA2BXPJX+8RzopILdtcgNuyTwiIhlDnu86Nx8bFIg044Ycopq4DWXZfcQaLgsLHHdzJgLNRZjb2Lyv1dwg+81e9WBYyzu8gPW6sG2negTBxTE5InDGloXnM1oFv0TJngG5JOAP/s= 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 1715159316964605.519371042539; Wed, 8 May 2024 02:08:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHX-0001Dx-DS; Wed, 08 May 2024 05:08:11 -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 1s4dHJ-0000Hp-0O for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:59 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHG-0005S1-Kv for qemu-devel@nongnu.org; Wed, 08 May 2024 05:07:56 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:54 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159275; x=1746695275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3evy5Fn1NeUvF8A+wdco68VIVay91RZK5fR/tL35KqQ=; b=Up5EM6RshJkQreGIsOa3bEiQSuc6uKH6JRoKcGDPzkyZg7oRBDiIfH6c 8ECe+0b3Yt+kbE8HSfNx4IzubiwErKFwABC7l9JX4Dm1O7kH3K9UU9mMf ixcnbAwxxtElW+qk5UB8STHYUqcmzrCh/uIE4LyYaujDSecECmo7Ln0ml JwpF+AjOIY+/yx3aLM37+HSRWxfk0d0uCCk8cZYE2/n6ZqDzpcBA1xcdr R6ykzXyq1jdJn5ZKDPcjzdanQpJJKx5n1Zu8g7xStbJpVT6y3n3DfT9DV cUrG9hHk4GhbtwzJmw4zqwiVpcv4HFiqpB7uLZ9pEPUprvFPhCtyV1wQV g==; X-CSE-ConnectionGUID: /PbniVtQRy2zXZbP1QbjxA== X-CSE-MsgGUID: huqD/+RZSFCjZReahWiRJA== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161043" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161043" X-CSE-ConnectionGUID: ISsGmb5SQRKQrUIr8V/pzg== X-CSE-MsgGUID: Rywo4QF+TPuWPx/ENFZlQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226650" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v5 13/19] vfio: Create host IOMMU device instance Date: Wed, 8 May 2024 17:03:48 +0800 Message-Id: <20240508090354.1815561-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-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=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159318317100012 Create host IOMMU device instance in vfio_attach_device() and call .realize() to initialize it further. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/common.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index affb73f209..94428abcf4 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/common.c b/hw/vfio/common.c index 9f1f2e19f7..970c9e3a5f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1497,6 +1497,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbase= dev, { const VFIOIOMMUClass *ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); + HostIOMMUDevice *hiod; =20 if (vbasedev->iommufd) { ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); @@ -1504,7 +1505,19 @@ bool vfio_attach_device(char *name, VFIODevice *vbas= edev, =20 assert(ops); =20 - return ops->attach_device(name, vbasedev, as, errp); + if (!ops->attach_device(name, vbasedev, as, errp)) { + return false; + } + + hiod =3D HOST_IOMMU_DEVICE(object_new(ops->hiod_typename)); + if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp))= { + object_unref(hiod); + ops->detach_device(vbasedev); + return false; + } + vbasedev->hiod =3D hiod; + + return true; } =20 void vfio_detach_device(VFIODevice *vbasedev) @@ -1512,5 +1525,6 @@ void vfio_detach_device(VFIODevice *vbasedev) if (!vbasedev->bcontainer) { return; } + object_unref(vbasedev->hiod); vbasedev->bcontainer->ops->detach_device(vbasedev); } --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159318; cv=none; d=zohomail.com; s=zohoarc; b=he8kxwhm00bhv4l6mAutcb0XIH0iqtup3u1pirVg6zXqg+cjlhkQrT/VSC6XjIEEf8KmBJBPO91qe0AO26KZHTg2zX9lHG9QFUlYIGXbT+/ABZRngL6lm8Ck4B9UrjC6AoqVKKmqEnmFT0EvMF1Wkv0/DUGWVK6UvyDpmuf+H/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159318; 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=4rI/W8kEHJPBEashf53i49Vw85zcrh/7wn5NRA076ws=; b=PGnwvsxyU0XD4jd0QHYU5XSzO+4EiDQN7eW9W707yyThJu1u8Fxyu3e415D8tmg9wdskxPP1e2fH91bK018OUQuhoOgXacnf463WyqqdMv0SOhvNgvyWU0DjtK9yzINyJUK3i+PgZc6jQrxlyT4Qhb5KJpCzMGm75kTen5yDliw= 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 1715159318447893.5830949489565; Wed, 8 May 2024 02:08:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHT-0000pN-Gu; Wed, 08 May 2024 05:08:07 -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 1s4dHQ-0000XA-Au for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:05 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHL-0005a5-Cz for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:04 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:59 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159280; x=1746695280; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lOqDt9v6x0LF0QRt0dafkaMf+eapZI59zjmfrdfGr4k=; b=Ow5Ra+z7yThyC5C492VouZ6EzEbI3Bl12NsWhlomXiN6RBMfCq9qLr8b L7kBGrif+AFJ7cn6zZcguAe2rg9DDxl0e4MGg/dbQPWqNHgoJKH5TqCZr zzHV6rqyQwnMqz6aK0b4pUf/ic0nHB8QkhONeti+DAi0ZlInmA4TBbmtx 1T69Vi2neRGGi58Z5m4tJ8N/2RX0ivuZVtTj4+9fD3d/tVJPNnffQfLyy K+bO5ZEJx0O6RqR2uafGhzuXTvJqhWPvFsHntUd2Tqk/eKKqiS0OVoRc2 9xoTV6xD1/OpfMxJu18UGkHr0JXa/Cm+a3l7F3ijUKgrAvBv/IRbk02lu w==; X-CSE-ConnectionGUID: /fYhiqrBSou1dNYruwN0Sg== X-CSE-MsgGUID: niEZBNjyRqeO3MSNzI5f1w== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161058" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161058" X-CSE-ConnectionGUID: PYk5jH0mShSIYsvrnGCpfg== X-CSE-MsgGUID: Ks5Dv94HSNecPkJwevpJkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226685" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun , Marcel Apfelbaum Subject: [PATCH v5 14/19] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn() Date: Wed, 8 May 2024 17:03:49 +0800 Message-Id: <20240508090354.1815561-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159320250100033 Content-Type: text/plain; charset="utf-8" Extract out pci_device_get_iommu_bus_devfn() from pci_device_iommu_address_space() to facilitate implementation of pci_device_[set|unset]_iommu_device() in following patch. No functional change intended. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Nicolin Chen Signed-off-by: Zhenzhong Duan --- hw/pci/pci.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 324c1302d2..02a4bb2af6 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,7 +2709,33 @@ AddressSpace *pci_device_iommu_address_space(PCIDevi= ce *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); } --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159447; cv=none; d=zohomail.com; s=zohoarc; b=SE7eFJXTjoHYHpYROv88nuk1eodtKlJaUeDHiEyyU5DA133UuvoyxqXt2i98yKrb/NGlEOnOAC46Zioca4exgMvFpdOM2B5NUlVfCL9oaaPrXp/cto5dgnCQuFeBPirsV4jcaJ/b2TYL/Wk5CowuIWkxaXibZyZRBwxdrs+uLU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159447; 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=J3GSGvZXQFMULPKezGdBTEc4HlcSC1vsprkYeTQVP1o=; b=jtzBGlozm6YoetGP2IATs/Krng9CPaKeZdungMYiKhKrEMNfZ7ve9mUKZ0rByoBx/bvws58zjhERU6jy0Fm5w9fd7lly9lzS8nVE2nfa4hiXFm/jpr/+yyoGHrqrm6fJ5w0sNrfop69f8eL0Gh+jBpGDLiV708i0W30P5u84n5Y= 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 1715159447377414.28482457987684; Wed, 8 May 2024 02:10:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHY-0001Mb-F7; Wed, 08 May 2024 05:08:12 -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 1s4dHR-0000Zt-Gg for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:05 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHP-0005UP-JX for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:05 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:03 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:07:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159284; x=1746695284; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IJL5PsoklMNCE7TY1tLnHp4d+Usegx9kN+idzGTHTOY=; b=fJdNNaz4AkVkKjhLP8/lz+j3B5+GRtXvEyQ5ZIPLBXCYkHPwF7w19Ail RWlm9C+zxwxFIp5wabEAtdwZTdM9HYsZHzccc/QfXd9pYrpGRalk/PzMg MUH3ktaxgiFtciL4Indq5LWbSFIIt39L2JnVe6Ijh1avZ7S8R78o1WGGu KGq33bcx5qELU8ZrBEVCqdnD9Fz6U9uB7NPuRft7jp6xpfkJ5+yPlAJ6v P82r2iueKHhmNYwpPjFFGPqSEab6RIHiPYDyUOq+fo1+pJFwnqGYVIvfv I3+AGYhXYBdl+zKzeexTpzAq8mjlr9u6b8lBCH/cZCSa2Xhw5RVoXRYbg w==; X-CSE-ConnectionGUID: gtIbM7H+SBuohkPUCJwS/Q== X-CSE-MsgGUID: u2dO/tvvReuvhvH8/ZPXzg== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161074" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161074" X-CSE-ConnectionGUID: uG8Z0a8MS4a7k4z4Q7vHaQ== X-CSE-MsgGUID: 6OLHwotgQFO7d4igwusq+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226695" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum Subject: [PATCH v5 15/19] hw/pci: Introduce pci_device_[set|unset]_iommu_device() Date: Wed, 8 May 2024 17:03:50 +0800 Message-Id: <20240508090354.1815561-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159449018100003 Content-Type: text/plain; charset="utf-8" From: Yi Liu pci_device_[set|unset]_iommu_device() call pci_device_get_iommu_bus_devfn() to get iommu_bus->iommu_ops and call [set|unset]_iommu_device callback to set/unset HostIOMMUDevice for a given PCI 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 | 38 +++++++++++++++++++++++++++++++++++++- hw/pci/pci.c | 27 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index eaa3fc99d8..c84cc9b99a 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,45 @@ 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. + * + * @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 + * + * Returns: true if HostIOMMUDevice is attached or else false with err= p set. + */ + bool (*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); +bool 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 02a4bb2af6..c8a8aab306 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2742,6 +2742,33 @@ AddressSpace *pci_device_iommu_address_space(PCIDevi= ce *dev) return &address_space_memory; } =20 +bool 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 true; +} + +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 Mon Nov 25 12:35:52 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=1715159400; cv=none; d=zohomail.com; s=zohoarc; b=lw3hCEJ+HwLaWpPnkhhPcnFoB2O1aVtxtuh6HQ1r7l3H0liXom0kdgd5EH0H76sAu+jtRpwXF9Fst9w3ZXYvMN9n5Jg47aEdpeq7KLZNEWBFdIm7yKpgo3c55evqCIOmT3dX/1aPKeF1QGJWz8T/q9GVQexOM07TEkehiPRgHSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159400; 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=fkCNvpav8natD/QuD9Asl+2RVv6TNaxwPUUqtApoAf4=; b=cq+rBHPLwRsg5fXWXw3WX4kU5ZTOeHfpJQN3N0UWVK1JJfo8nCk/I4CBjFJnU44q1fc/siNQf8gFOpEkCY0EqUNOf35SPDWSfej+bvavHxR5dhitr4juRGAsQsfAmRYu3K+A+5GHc6nAgSIG7+Os5936CggduZkW3JwJ8JCaDM4= 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 1715159400125611.1799185071986; Wed, 8 May 2024 02:10:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHY-0001Qd-WC; Wed, 08 May 2024 05:08:13 -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 1s4dHW-000179-61 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:10 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHU-0005k5-8K for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:09 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:07 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159289; x=1746695289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=18k6nX8RYXDryuQzqVzfMOPDDLkMyXMbOqZziraopNQ=; b=BCtRkZrDTqV68bqOCbtfBtglW1LSBv7UmA1PqXveQKsbWtfVtQ3PqYV3 +h85kda1u6TKsFUW34riyur4D6QmgHmEWFNpSmWOBnMg/NY9G4oCBvrCv B6gejMi5ErPzHrND3X5V0FshlyYVIPZEyF8AzS6V1f2cPopGtg69UWMsY K2yYtGILVJIkImrClF2tFNptQApfRNsfa9wu0p8jGNBMH9fvQJjsvLECw sK+ptGAe2xgnfk5FvzBQNgHJimEpa59G76VBomwIlCFv5PgCvSeffb0qR Nax3yI8rsivG9yIQ8XlWBzKJyAtSO/tlla9g67+0O0tI8lQasEIltrxla g==; X-CSE-ConnectionGUID: StfrwCfYSxKNbymy0B3GSQ== X-CSE-MsgGUID: NBbRaMLyTHaVeWay97jdEw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161085" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161085" X-CSE-ConnectionGUID: HF51NBo4Q0u1jcjep99Ddw== X-CSE-MsgGUID: 98kbx5F1QTqZn3K6Vyiy5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226713" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v5 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU Date: Wed, 8 May 2024 17:03:51 +0800 Message-Id: <20240508090354.1815561-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159400691100003 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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d3beb15514..7205702f7f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3109,9 +3109,14 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) =20 vfio_bars_register(vdev); =20 + if (!pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) { + error_prepend(errp, "Failed to set iommu_device: "); + goto out_teardown; + } + ret =3D vfio_add_capabilities(vdev, errp); if (ret) { - goto out_teardown; + goto out_unset_idev; } =20 if (vdev->vga) { @@ -3130,7 +3135,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, @@ -3139,13 +3144,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 @@ -3231,6 +3236,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); @@ -3259,6 +3266,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); @@ -3273,7 +3281,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 From nobody Mon Nov 25 12:35:52 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=1715159453; cv=none; d=zohomail.com; s=zohoarc; b=EprPO5WitZzsu+COeHvIhdm7nDHne2Sg4s+p1wQdXz7fVt5nn58WOPdqqwj7b9TVl2Xg+bEzJLgrz8XQEhqDFnE8VJ8gHZ0UkeLKw/swBJjY9XQgRujOy4MdJqtfUAKwXthr+Cs0CY68L1Bs3ReZzgLKaTpcfwMI/xqYxquo5pQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159453; 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=WgOmfib2QyJNQEA3gjPHIZxg/+5VXAGpv277yP3L/HY=; b=jxwxVarcf45uXq68/iRsyeNUv9QDuVL8RUdgG+JnVEjGw3v2HCZqwB3s7bBqCDR8bqUamUOcQnWoUB2f3VOjkvebZoZDjbrE6+7lIM7FNCWR0zG0aYhyjK+r5Cqwrb5dupD1IaHY19GJO6NCdbDGKpeCpLLJ3TSkDSKgezpodUc= 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 1715159453195635.6206984693256; Wed, 8 May 2024 02:10:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHq-00031f-IM; Wed, 08 May 2024 05:08: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 1s4dHo-0002xt-Ub for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:28 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHi-0005k5-K1 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:28 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:12 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159303; x=1746695303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B7nXRh7ZojaXtdhNyRfMhv/+nlUrwKMI6CTd3vTaKw0=; b=k7wGCKE/r7l4QlnjV5/wEfJzIneI/eGMr2P6qoNkpT8MayLy5nGwj5S0 VmZ2F+VVYX09tjle1qZE/gEPS54tBQf7NXac9n/GYZTq0iY8knaYUK7AA wa5AKd/sRcGajKxYzo2ieO1H1CRmXpw7van5iKbWF6cYgvZzTxdCrJOf2 9BtPM/MeJB+oTWrjePXp9kSB5jlgQ85l03BwoHyK/B3YwIZAOr7wQ9l83 eygc8fvsU/ISERpAqKEIJzKCpE/OXJHz6rLYLdc9srhw0Iuk1C0cQw+VL OrF0svSXuh2Y233ACMtcug+j9IW0UFTkwAGtXBGCT+0vWCvCOCzmbCHEF w==; X-CSE-ConnectionGUID: rPoh+UNzRLaaREJ0l/0WUg== X-CSE-MsgGUID: U/KHEFP1SDC0dfkU4N9v0Q== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161097" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161097" X-CSE-ConnectionGUID: VzZ5Y5iZRseupblQulWLww== X-CSE-MsgGUID: jqj7ltoOTVquF5Qiz9VrWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226722" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v5 17/19] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap Date: Wed, 8 May 2024 17:03:52 +0800 Message-Id: <20240508090354.1815561-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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_PASS=-0.001, T_SPF_HELO_TEMPERROR=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: 1715159455002100007 Content-Type: text/plain; charset="utf-8" Extract cap/ecap initialization in vtd_cap_init() to make code cleaner. No functional change intended. Reviewed-by: Eric Auger Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu.c | 93 ++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index cc8e59674e..519063c8f8 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3934,30 +3934,10 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iom= mu_mr, IOMMUNotifier *n) return; } =20 -/* Do the initialization. It will also be called when reset, so pay - * attention when adding new initialization stuff. - */ -static void vtd_init(IntelIOMMUState *s) +static void vtd_cap_init(IntelIOMMUState *s) { X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); =20 - memset(s->csr, 0, DMAR_REG_SIZE); - memset(s->wmask, 0, DMAR_REG_SIZE); - memset(s->w1cmask, 0, DMAR_REG_SIZE); - memset(s->womask, 0, DMAR_REG_SIZE); - - s->root =3D 0; - s->root_scalable =3D false; - s->dmar_enabled =3D false; - s->intr_enabled =3D false; - s->iq_head =3D 0; - s->iq_tail =3D 0; - s->iq =3D 0; - s->iq_size =3D 0; - s->qi_enabled =3D false; - s->iq_last_desc_type =3D VTD_INV_DESC_NONE; - s->iq_dw =3D false; - s->next_frcd_reg =3D 0; s->cap =3D VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS | VTD_CAP_MGAW(s->aw_bits); @@ -3974,27 +3954,6 @@ static void vtd_init(IntelIOMMUState *s) } s->ecap =3D VTD_ECAP_QI | VTD_ECAP_IRO; =20 - /* - * Rsvd field masks for spte - */ - vtd_spte_rsvd[0] =3D ~0ULL; - vtd_spte_rsvd[1] =3D VTD_SPTE_PAGE_L1_RSVD_MASK(s->aw_bits, - x86_iommu->dt_supported); - vtd_spte_rsvd[2] =3D VTD_SPTE_PAGE_L2_RSVD_MASK(s->aw_bits); - vtd_spte_rsvd[3] =3D VTD_SPTE_PAGE_L3_RSVD_MASK(s->aw_bits); - vtd_spte_rsvd[4] =3D VTD_SPTE_PAGE_L4_RSVD_MASK(s->aw_bits); - - vtd_spte_rsvd_large[2] =3D VTD_SPTE_LPAGE_L2_RSVD_MASK(s->aw_bits, - x86_iommu->dt_sup= ported); - vtd_spte_rsvd_large[3] =3D VTD_SPTE_LPAGE_L3_RSVD_MASK(s->aw_bits, - x86_iommu->dt_sup= ported); - - if (s->scalable_mode || s->snoop_control) { - vtd_spte_rsvd[1] &=3D ~VTD_SPTE_SNP; - vtd_spte_rsvd_large[2] &=3D ~VTD_SPTE_SNP; - vtd_spte_rsvd_large[3] &=3D ~VTD_SPTE_SNP; - } - if (x86_iommu_ir_supported(x86_iommu)) { s->ecap |=3D VTD_ECAP_IR | VTD_ECAP_MHMV; if (s->intr_eim =3D=3D ON_OFF_AUTO_ON) { @@ -4027,6 +3986,56 @@ static void vtd_init(IntelIOMMUState *s) if (s->pasid) { s->ecap |=3D VTD_ECAP_PASID; } +} + +/* + * Do the initialization. It will also be called when reset, so pay + * attention when adding new initialization stuff. + */ +static void vtd_init(IntelIOMMUState *s) +{ + X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); + + memset(s->csr, 0, DMAR_REG_SIZE); + memset(s->wmask, 0, DMAR_REG_SIZE); + memset(s->w1cmask, 0, DMAR_REG_SIZE); + memset(s->womask, 0, DMAR_REG_SIZE); + + s->root =3D 0; + s->root_scalable =3D false; + s->dmar_enabled =3D false; + s->intr_enabled =3D false; + s->iq_head =3D 0; + s->iq_tail =3D 0; + s->iq =3D 0; + s->iq_size =3D 0; + s->qi_enabled =3D false; + s->iq_last_desc_type =3D VTD_INV_DESC_NONE; + s->iq_dw =3D false; + s->next_frcd_reg =3D 0; + + vtd_cap_init(s); + + /* + * Rsvd field masks for spte + */ + vtd_spte_rsvd[0] =3D ~0ULL; + vtd_spte_rsvd[1] =3D VTD_SPTE_PAGE_L1_RSVD_MASK(s->aw_bits, + x86_iommu->dt_supported); + vtd_spte_rsvd[2] =3D VTD_SPTE_PAGE_L2_RSVD_MASK(s->aw_bits); + vtd_spte_rsvd[3] =3D VTD_SPTE_PAGE_L3_RSVD_MASK(s->aw_bits); + vtd_spte_rsvd[4] =3D VTD_SPTE_PAGE_L4_RSVD_MASK(s->aw_bits); + + vtd_spte_rsvd_large[2] =3D VTD_SPTE_LPAGE_L2_RSVD_MASK(s->aw_bits, + x86_iommu->dt_supporte= d); + vtd_spte_rsvd_large[3] =3D VTD_SPTE_LPAGE_L3_RSVD_MASK(s->aw_bits, + x86_iommu->dt_supporte= d); + + if (s->scalable_mode || s->snoop_control) { + vtd_spte_rsvd[1] &=3D ~VTD_SPTE_SNP; + vtd_spte_rsvd_large[2] &=3D ~VTD_SPTE_SNP; + vtd_spte_rsvd_large[3] &=3D ~VTD_SPTE_SNP; + } =20 vtd_reset_caches(s); =20 --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159359; cv=none; d=zohomail.com; s=zohoarc; b=Un3hYxYYUijt0bZ5eoltXscbQlf8ZHgtPUvLLX74MyR/KqC87Kw+UBtB3DsXk8VCBCQfsjugEBnk3dLY6B9DF5+HroOnEYYV9WmmJA8gBU6kf1n21378iPW0k5nm82v/GKD11SXV1RB4ramKS37ZOT2QAVX0pWfc9ImiZM1VXaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159359; 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=V3y2U9TseaM7CPGFv+a9IVgh+gNVToUG6ZMi5JTCvm0=; b=Z/knmlDeP7DI3H5/B1NhOHmRJabFzIy1xwB5E9R4EVZnAtsr+N0xlBOAeKfzaFMAdGvVmPHn25ccWtNn8lrV+9rtilMOJedsvkLnQpekrhBOrge5jVtkhyVmj7c1CfITHiPb7C4iWtW7idCbD4Qyhx4N76RLa9bhRo5y16zdASY= 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 171515935913751.44532376584243; Wed, 8 May 2024 02:09:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dHt-0003IG-N3; Wed, 08 May 2024 05:08:33 -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 1s4dHr-00039e-Np for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:31 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHp-00065P-Lt for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:31 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:18 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159310; x=1746695310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=10eC5ToShm95JMdUATdaaiU5CKNRnm6sQ9xfoHbMqWU=; b=E+B6vE91eZC93AsDoFeb80l/0Sn4eOi6SQ95uIpjQY3ktM+uyd3QADkW u2KZ7PO1tgTduzUknKqXQdVORnpXLzX7T6mC0KcMilxTU6GUbx7RxVacU leS9my7quXQSMucVGgH6xSgeZywkFq71yETxzc84+WVYfdlqSe6KKA0WZ bsoKBU2S5lhzf1rtTG9wOfVlPP8/TXzvYVZjisShPj+0DfqlDOt6ZeFeE TDgyqfa/WJV6p/AJ7H6WrAQUYc0+T8SiP3rKmvJVwc2qRtGixQZNaOeth Xp1TGKDKXr/iNq17L/oIJy3ts1z+s1G/5ME/37DSzX58XrKANBJ0CWM5A w==; X-CSE-ConnectionGUID: 0+azxWITSymNcRVO1d2RFg== X-CSE-MsgGUID: ASeavdlWSYW/im5Ed83MiQ== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161123" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161123" X-CSE-ConnectionGUID: wMHBomcgSzGLmFyBDkHghg== X-CSE-MsgGUID: fwxyo6sxQSGRonVOW++RHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226726" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v5 18/19] intel_iommu: Implement [set|unset]_iommu_device() callbacks Date: Wed, 8 May 2024 17:03:53 +0800 Message-Id: <20240508090354.1815561-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159360426100001 Content-Type: text/plain; charset="utf-8" From: Yi Liu Implement [set|unset]_iommu_device() callbacks in Intel vIOMMU. In set call, a new structure VTDHostIOMMUDevice which holds a reference to HostIOMMUDevice is stored in hash table indexed by PCI BDF. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 9 ++++ include/hw/i386/intel_iommu.h | 2 + hw/i386/intel_iommu.c | 76 ++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index f8cf99bddf..b800d62ca0 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -28,6 +28,7 @@ #ifndef HW_I386_INTEL_IOMMU_INTERNAL_H #define HW_I386_INTEL_IOMMU_INTERNAL_H #include "hw/i386/intel_iommu.h" +#include "sysemu/host_iommu_device.h" =20 /* * Intel IOMMU register specification @@ -537,4 +538,12 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_SL_IGN_COM 0xbff0000000000000ULL #define VTD_SL_TM (1ULL << 62) =20 + +typedef struct VTDHostIOMMUDevice { + IntelIOMMUState *iommu_state; + PCIBus *bus; + uint8_t devfn; + HostIOMMUDevice *dev; + QLIST_ENTRY(VTDHostIOMMUDevice) next; +} VTDHostIOMMUDevice; #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 7d694b0813..2bbde41e45 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -293,6 +293,8 @@ struct IntelIOMMUState { /* list of registered notifiers */ QLIST_HEAD(, VTDAddressSpace) vtd_as_with_notifiers; =20 + GHashTable *vtd_host_iommu_dev; /* VTDHostIOMMUDevice */ + /* interrupt remapping */ bool intr_enabled; /* Whether guest enabled IR */ dma_addr_t intr_root; /* Interrupt remapping table pointer */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 519063c8f8..747c988bc4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -237,6 +237,13 @@ static gboolean vtd_as_equal(gconstpointer v1, gconstp= ointer v2) (key1->pasid =3D=3D key2->pasid); } =20 +static gboolean vtd_as_idev_equal(gconstpointer v1, gconstpointer v2) +{ + const struct vtd_as_key *key1 =3D v1; + const struct vtd_as_key *key2 =3D v2; + + return (key1->bus =3D=3D key2->bus) && (key1->devfn =3D=3D key2->devfn= ); +} /* * Note that we use pointer to PCIBus as the key, so hashing/shifting * based on the pointer value is intended. Note that we deal with @@ -3812,6 +3819,70 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 +static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, + HostIOMMUDevice *hiod, Error **errp) +{ + IntelIOMMUState *s =3D opaque; + VTDHostIOMMUDevice *vtd_hdev; + struct vtd_as_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + }; + struct vtd_as_key *new_key; + + assert(hiod); + + vtd_iommu_lock(s); + + vtd_hdev =3D g_hash_table_lookup(s->vtd_host_iommu_dev, &key); + + if (vtd_hdev) { + error_setg(errp, "IOMMUFD device already exist"); + vtd_iommu_unlock(s); + return false; + } + + vtd_hdev =3D g_malloc0(sizeof(VTDHostIOMMUDevice)); + vtd_hdev->bus =3D bus; + vtd_hdev->devfn =3D (uint8_t)devfn; + vtd_hdev->iommu_state =3D s; + vtd_hdev->dev =3D hiod; + + new_key =3D g_malloc(sizeof(*new_key)); + new_key->bus =3D bus; + new_key->devfn =3D devfn; + + object_ref(hiod); + g_hash_table_insert(s->vtd_host_iommu_dev, new_key, vtd_hdev); + + vtd_iommu_unlock(s); + + return true; +} + +static void vtd_dev_unset_iommu_device(PCIBus *bus, void *opaque, int devf= n) +{ + IntelIOMMUState *s =3D opaque; + VTDHostIOMMUDevice *vtd_hdev; + struct vtd_as_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + }; + + vtd_iommu_lock(s); + + vtd_hdev =3D g_hash_table_lookup(s->vtd_host_iommu_dev, &key); + if (!vtd_hdev) { + vtd_iommu_unlock(s); + return; + } + + g_hash_table_remove(s->vtd_host_iommu_dev, &key); + object_unref(vtd_hdev->dev); + + vtd_iommu_unlock(s); +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -4116,6 +4187,8 @@ static AddressSpace *vtd_host_dma_iommu(PCIBus *bus, = void *opaque, int devfn) =20 static PCIIOMMUOps vtd_iommu_ops =3D { .get_address_space =3D vtd_host_dma_iommu, + .set_iommu_device =3D vtd_dev_set_iommu_device, + .unset_iommu_device =3D vtd_dev_unset_iommu_device, }; =20 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) @@ -4235,6 +4308,9 @@ static void vtd_realize(DeviceState *dev, Error **err= p) g_free, g_free); s->vtd_address_spaces =3D g_hash_table_new_full(vtd_as_hash, vtd_as_eq= ual, g_free, g_free); + s->vtd_host_iommu_dev =3D g_hash_table_new_full(vtd_as_hash, + vtd_as_idev_equal, + g_free, g_free); vtd_init(s); pci_setup_iommu(bus, &vtd_iommu_ops, dev); /* Pseudo address space under root PCI bus. */ --=20 2.34.1 From nobody Mon Nov 25 12:35:52 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=1715159370; cv=none; d=zohomail.com; s=zohoarc; b=NzZWl5xopRmu/2BFv5vsdzK8eyUPKSSx6WJno+xD4tFa31HFnhSBGWYT9zUP4cyHTJK9657q9IT7HshptVk+XfYKCFOo6A5QBEBayM+97leInV5MfJORiyOAUr5D3yZ7qgI7kbtXiONMCL4uKGKu00JoBPvbpRGytY8Na/krmcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715159370; 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=d8MVvTwn7xi/24rrwYuiBeZrD02+TmCzwLxTuSUbhAs=; b=Ck2nalyKVwH9DOmrS08b/HdV0qn8jtgdZ+zi7AOqpZxR0wC8YRKn+4qyzenB90PrhTnj7TW4vkZlgqbdfh/5DwzpFltedccB8JFNJh7Fo1E9X0tyzAyQdxHvf+rcd0Rz8OX1IhUgewwvoQFtPG6FdbEYoKq5OZva9VpbK4zP4GA= 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 1715159370097561.632483790938; Wed, 8 May 2024 02:09:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4dID-0003yH-K4; Wed, 08 May 2024 05:08:53 -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 1s4dHy-0003gk-54 for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:40 -0400 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4dHu-0006As-HI for qemu-devel@nongnu.org; Wed, 08 May 2024 05:08:36 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:22 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 02:08:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715159315; x=1746695315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hekfpiha/Rj7V7KVBExc5NCKEYWksRlYB1K0ySsENCU=; b=QEcuNHq+z5QbbzQjUxm5VNcq1Hh82VJ5ixnuq4XEpylX/R6LYFf+2ZXj oSax6IFsO2R/pD6PHRk7I3OfhIb1CujCpyXNMUacZQ1d57VFtVK+6/JLX YSFWwn6dQrC+1YwgJo9UFyE0NQJGFaubCsuGp+wVBY9VP80EVI+7I8duw lU+qFrmdO4JuOaFeTtuMUE4PekpYpLSauNEkC5WaMGLq1yGTahxxNF300 poufUvUM9J9Asb6mHWFMi2DYWcnqkFk4qwY/l9kfFKhkgq5x5ILExtNI2 1Ytet1f+I05YMGEOR71/2h3gobamR6+/lDwQbEaWhSVCXYmWrte5mWH6j A==; X-CSE-ConnectionGUID: 0GscNwmAQyWnEQ7L/e14dA== X-CSE-MsgGUID: oinWrxCASx+Jze2vPrTsmw== X-IronPort-AV: E=McAfee;i="6600,9927,11066"; a="11161138" X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="11161138" X-CSE-ConnectionGUID: pVLPV03DT3ObTmfDQA6aUw== X-CSE-MsgGUID: Dhg9q+PtRSuMz670DFobpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,144,1712646000"; d="scan'208";a="29226732" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v5 19/19] intel_iommu: Check compatibility with host IOMMU capabilities Date: Wed, 8 May 2024 17:03:54 +0800 Message-Id: <20240508090354.1815561-20-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240508090354.1815561-1-zhenzhong.duan@intel.com> References: <20240508090354.1815561-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, 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 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: 1715159370618100001 Content-Type: text/plain; charset="utf-8" If check fails, host device (either VFIO or VDPA device) is not compatible with current vIOMMU config and should not be passed to guest. Only aw_bits is checked for now, we don't care other capabilities before scalable modern mode is introduced. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 747c988bc4..07bfd4f99e 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -20,6 +20,7 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_HOST_IOMMU_DEVICE */ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qapi/error.h" @@ -3819,6 +3820,26 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 +static bool vtd_check_hdev(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hde= v, + Error **errp) +{ +#ifdef CONFIG_HOST_IOMMU_DEVICE + HostIOMMUDevice *hiod =3D vtd_hdev->dev; + int ret; + + /* Common checks */ + ret =3D host_iommu_device_get_cap(hiod, HOST_IOMMU_DEVICE_CAP_AW_BITS,= errp); + if (ret < 0) { + return false; + } + if (s->aw_bits > ret) { + error_setg(errp, "aw-bits %d > host aw-bits %d", s->aw_bits, ret); + return false; + } +#endif + return true; +} + static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, HostIOMMUDevice *hiod, Error **errp) { @@ -3848,6 +3869,12 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, vo= id *opaque, int devfn, vtd_hdev->iommu_state =3D s; vtd_hdev->dev =3D hiod; =20 + if (!vtd_check_hdev(s, vtd_hdev, errp)) { + g_free(vtd_hdev); + vtd_iommu_unlock(s); + return false; + } + new_key =3D g_malloc(sizeof(*new_key)); new_key->bus =3D bus; new_key->devfn =3D devfn; --=20 2.34.1