From nobody Mon Nov 25 05:27:06 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=1717395348; cv=none; d=zohomail.com; s=zohoarc; b=jJ7LjsGgKyBRRqiY+LOBIW6DN58aJo1MAaazCVWKGdESLW4HZefpTc62G5p82HsxudbCJ+xhnZutRPKYfugdxOUeI4TXQkLNseuGRH1XgOT5tygyYMsw1V0WXgVBSt2PKjY0hZyuoA5FUe/GLHlgoTCuKuLMBEw1MHx477loURg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395348; 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=u6KB9v8H2XpKtgvFsY+jpv/vui3X13kZZQBp3xN4g0E=; b=T2bwjdMXt8x1etdrI3QV1RMdJJ4kfxe9TceQCqBQltCcf89ZXdtzD8DCLEOHlJyTS3i7BWNlxM6b6WxqJi2IflS7IlABO2DXjJYx2PN0dIF2zoRTpod4sL1DwAnhn+ZdIuAg2WyxEojqJGQaXRM+BF+2+by7uRNySTEP6T/oUuU= 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 1717395348650311.5418547575374; Sun, 2 Jun 2024 23:15:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wh-0004bj-HX; Mon, 03 Jun 2024 02:13:27 -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 1sE0wZ-0004Ti-79 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:21 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wX-0000sb-4X for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:18 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:16 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395197; x=1748931197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xpihEDh+JfAcyDYmhBEaenfK+XjqzDLvj6FwrKHsjxE=; b=VdB74w7MqIKVRC0nfmw31UHxUs4OAlmEykBFwmfHeDkNnpRbracTllcq 8sDM3+TTl52nTjQjwzq9t3rgZV/PfZou5L2RWwtA3dfbWJXrD7Eh9Vqdi BICFkg9Iqu+6Yu7+fZQY54A+Sbl2sg0ZA+6yHrPGc7gDPSxdcNVy0AGtE ABsF0ttMh/iNzJjBxClDI7i1QB7yUCT26aV+QYPQ8ARy2xc8Dqq6vEF81 qSq6E3nYOahRI4/fjMJMCPhvgZVVk2JkcN/Q+jNZW2+dzcDeax0ZuNZZx pSSBCWTeq1+FnsEE1kNoWSfSWWHHJDP4ib/SveELQ6odahkyIjzwdVW/B Q==; X-CSE-ConnectionGUID: rxEEBVOvTka7MJFyvlR2oA== X-CSE-MsgGUID: Gf310O7fTwytN041ku8p/Q== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277615" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277615" X-CSE-ConnectionGUID: zasHWgIvSJGNaOd6vs1xPg== X-CSE-MsgGUID: iG+g3CHPQBWEOoulQ3qv1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855819" 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 v6 01/19] backends: Introduce HostIOMMUDevice abstract Date: Mon, 3 Jun 2024 14:10:05 +0800 Message-Id: <20240603061023.269738-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395348820100017 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 448dc951c5..1cf2b25beb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2196,6 +2196,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 05:27:06 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=1717395294; cv=none; d=zohomail.com; s=zohoarc; b=V3Y8b9EkaR6oIHIbbzRMKCYqxAWyzXXJvghfkgwATpi5hDGC2ogOjsivYOIxK2JYXdQa9B8KavZJH8k8iGIF3Jde4xnPL8+EzO5Aulm/5wMWhnZvKicOkNvliGR87mHknwwbdMsuAynoMUw3vqmkF9YyKADSXk8//IKvjdAuT6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395294; 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=ajqTuj0oEv1R1fT7Q98PHZieceXOGqGkHQUEjiSiq2M=; b=l1OmNmrrLjXiieQZMotHkdk88eYsxpA97XFJ+ncajevZMa56pNZ3s/6bcnukE+5yhXK/EOjYSDg9ALn+mZXBRFqqhNPpCWOCeXNRaH/Dj0OTb/cam/am5A9KQFf47eznqXD39Tj7Ix9/OXVSmt8c/PMsKuqhFH8bP8le+ULSFIE= 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 171739529450818.361727209735136; Sun, 2 Jun 2024 23:14:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wk-0004dY-1M; Mon, 03 Jun 2024 02:13: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 1sE0wd-0004VS-A4 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:23 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wb-0000uQ-Jw for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:23 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:20 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395202; x=1748931202; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3+HbQHpf7tkUVGYjKSReUsjXGStIlnO1OjBBru6PBeU=; b=MJESlqdvZ/chBUDV5KCZt4p2dr8wiphci9853QS/acYSnbuKGUnwrdpj otOqUqgf4Q863vwxe8ngY1ViNuIC4LQdI4wHdix1bvr96XhhFbPIfi7FP EcONSMsDPIL6p78ztTwPag5X1yOk5z0aw2No6jw/mKDhA7ALIM38xLs6W DSVEmzeiB9HiJ4pCicVKRTLZYOnNeBTjnhStz48BwpjY7cekBPgotznni 1KUgdzVDlYzLzotGesglGGZDYbnYRHxUCCxwtcTNsTPE9xem6+sNVyGDn SkVn4Mf8m66/nRWxLINzNiePH8rJK+qkzkQEtjm2mRP1JKp9bsSUta1M7 A==; X-CSE-ConnectionGUID: 8/38pkW+TSyWT8vTr7Uulw== X-CSE-MsgGUID: jVNjfHmkQw+zi3vTjqqwQw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277623" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277623" X-CSE-ConnectionGUID: wvpJo2wFT4K8+98hVyvBhA== X-CSE-MsgGUID: WnfKisOBQS6JlN2YOXny/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855833" 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 v6 02/19] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device Date: Mon, 3 Jun 2024 14:10:06 +0800 Message-Id: <20240603061023.269738-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395296623100007 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 4cb1ab8645..75b167979a 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 @@ -171,6 +172,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 096cc97258..c4fca2dfca 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1141,7 +1141,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 05:27:06 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=1717395295; cv=none; d=zohomail.com; s=zohoarc; b=noxCkI3/FADqOeOR5ixVdF/EHCJF83bkiHFKUHc7yNnTVoG882kYRiCkhpWmhhE2YhRrLx7r5QD5osX249/YzBb9msHRwSetde1RUYt5jNRlm5uJ74zuOclhkySyuI2dllDbuZLGXLfJHb7dqmRcsaZVkxoqxvahszZ4nH7g+bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395295; 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=GiTa3GPLAGQX1WJ57yJKOKZAmhjkDGXRSVZQBk7X3MRt275fU4efacgJXkCtNqDf72kmIv6cLn/3HRYKxOS1M1rm2fABkbxoutpzWimW3JOZHzetDqnaaTzPykpO+523dgiWchIEMJNqwWQyf+4Tc7f8pKA26kKJNqn/b7nIU8I= 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 1717395295718704.9304832542268; Sun, 2 Jun 2024 23:14:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wl-0004fY-32; Mon, 03 Jun 2024 02:13:31 -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 1sE0wh-0004bv-Ob for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:28 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wf-0000uQ-S7 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:27 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:25 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395206; x=1748931206; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HyMVnPMTTEUPdrB/hPu5Ki1bM4XiJMJIG5t/CiWycQo=; b=V1Tzybg06gVbm4QuX1rt9bGtA6d832YlTLlCd6h6yaibcCk9FoeagbN8 fCUhmfIMqKnPu/5/a1zBdQtAa4W/BTxw/B4f1RM9RIB5q107tK8TIKcwb ELrCfhJ3nJ74sHHUn5Yfzf3zW1UFtSfb6+YfPt+crhFehWLcBo9O7yQIG Dn7XLWThl99WeUBqUhtkHzr1/UIKy3mj+L82jgI+83odn0KHW0gOvb2Vg qBg0aQwg75rIR92ZC9icszLFHLCEs5oCbL3E0uhpMnZmgXveGsaD9Crv5 3bAU2Zi1C8JcoYGroDJop3au2TZJmH9NdD9+nghfMazCD+TePIvZzBeod w==; X-CSE-ConnectionGUID: QPqwy/KbShuoxPslnFZEaw== X-CSE-MsgGUID: /z+YHt+xTOmOpXWL+BLXrA== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277630" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277630" X-CSE-ConnectionGUID: bvq2vwWNTZmxgKuVAQoDEw== X-CSE-MsgGUID: xl4gK1rjSSG/3Qi3vybbxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855843" 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 v6 03/19] backends/iommufd: Introduce abstract TYPE_HOST_IOMMU_DEVICE_IOMMUFD device Date: Mon, 3 Jun 2024 14:10:07 +0800 Message-Id: <20240603061023.269738-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395296635100009 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 05:27:06 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=1717395294; cv=none; d=zohomail.com; s=zohoarc; b=brAxrSBCyC3vUYoOHowDQ8WI8Z4juktgaVubIcbVv7DsIkF9AoKAZu8iFljjCHaHYXXBctrzIvW2/WOfB++A0BZe2wxtPCH+j2N+2i8nmkZ0FU7rEMRbiHzbAdjpZSB+pwHGuRb5ggkxhRsqhFiwkvMjyemKq1QYtFNO2nSfjiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395294; 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=KxF1b00AM15F0VhtaPHs200JNSSBum4RKl5koxAnfXg=; b=FCgJuIQdI6b9ZHm01HMf7ZpUIQwp3xp7OL+xEox3j8enMom4P4A5FoMYX7Gp1el8Pd1oE/ff2y/jInJ4ZqAc1fKA2JHCrYHOgrnGG9AUSwHke4CShkDnX/K7Cv5BLNGcutgZu+HdFWtm5nX7ldRwjgTIX3gbhhnb2IeR6AgNfgM= 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 1717395294663624.2151640952493; Sun, 2 Jun 2024 23:14:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wl-0004fy-Qn; Mon, 03 Jun 2024 02:13:31 -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 1sE0wk-0004fO-IH for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:30 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wi-0000uQ-VY for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:30 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:28 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395209; x=1748931209; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bH6SQfIKjpaHcGKH1cmtCIfWr1G+1rJOreNMbQzeZZo=; b=HEYsg6wEf0W0ljZUIj58XgwfpqKw4qtLyJdcgfCu6y94nc3Pa+JX/Q9n fiTfNMxqSJ8073yqystVOSvlefH8CzN6z4ZTjqOYY1gPQKqO63nqN85YL Ou3r83IN/cW7iaET9pVZULSUSw2StSRk27ORWpcTXKKmOJ1Gb7DQw2tRu tKHPZPfselVJwNnRcuoAy3GG9W4Xhvqqsc9SactVP2syymiZGaTs0EG0M 7aQPNQ9peOxME9gJymwtRqhXCofyQVzTNKTNUP2aO8wnwzywFFDxcx6I2 fQl3/u/3JkookHKmnwcd3CKsCbMZj5/K555rs2Lq9M7LtsMhkmG5EYvCd w==; X-CSE-ConnectionGUID: msOBqklZSNuBLPp/vj1kew== X-CSE-MsgGUID: xn9Ub902QtiWUjxK7lPXVg== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277640" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277640" X-CSE-ConnectionGUID: 3ECPSxN/Tb2dEEGN/Bd7MA== X-CSE-MsgGUID: 7WAopsgYRzSdZW/PMDL4xw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855852" 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 v6 04/19] vfio/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO device Date: Mon, 3 Jun 2024 14:10:08 +0800 Message-Id: <20240603061023.269738-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395296634100008 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 75b167979a..56d1717211 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 @@ -173,6 +174,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 05:27:06 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=1717395364; cv=none; d=zohomail.com; s=zohoarc; b=OSpEvi5DfGcTKcCz91GpY3bpy3iKCt2m8Q7+rRLobqQmuXW3YSO/1huOCy6ombSZJFLKPDhe84gCbFi7bNTeoxz17ESWZ+oDabrSPAuA9+PXoLR2evrEHbitgWO/Oy85QM6EkYHFzVCRKq8661OUcOaWm78m8cirSIQOakKjSXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395364; 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=0hoQ29TUu8lq7WLdCK+d7jw+Y8/Q+NTgIC+sQtcEmG8=; b=jq6fvrIWCYF3yPOrZt3KERSG4isKM6PHJn/NWi0Abq48yKt1oS6Rc9XE/HK24WHS3XTFsoyqkDwE8XIvR5UCtUBP7tcERc7eyK3CFlnWJiHqgo3bIvWFpw6x8RyfRbSEOuoGVKoKQxtGjzRYeyaUeIOPqfvtDHCdPfZQE6awfH8= 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 1717395364627514.1145202352677; Sun, 2 Jun 2024 23:16:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wr-0004jr-70; Mon, 03 Jun 2024 02:13:37 -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 1sE0wo-0004iY-Tf for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:35 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wn-0000uQ-4x for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:34 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:32 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395213; x=1748931213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DzFkETpqsyCUSo4mpTVuvp6zaJicWw8iv9n76ZkukHM=; b=FX5C1DAsMocLJItY9l9EyoajCghR59koUSZmwB9sPp0BCBJSrBP8r5gJ CSz54bkaV1q0HBPROs4JWwSPKXCRvSg0uVts+Gd1Dxu89oTEHRAeroYYF BhjQxg24f1RGk5xTl+udhfxk/uvKkXfd3/lx3Q2uO0fKqO0/W1JO23pia EHjPCeDu/pVMIwmvbJ+OoOvPoSvXW+Nz1zhInXcrpene60UYwrJt7vydQ +5vxmFuNZU8S9dRlj5tltnpHYZ+TIXF2jKUwRESeQPnAyzoRUjEw0XvDK DNnDpsT7+O7wVxD8Unl+F7qEJ9+4KAtFkgFZQ7g+Ats4fwHxO/njoETK2 Q==; X-CSE-ConnectionGUID: 0Hr9kC3zSnCGoRsTgB0bew== X-CSE-MsgGUID: LxZldkP5QfO5N9iJ8oOLQw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277648" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277648" X-CSE-ConnectionGUID: APkEOgYsTTe5TQ7XV1sb2w== X-CSE-MsgGUID: NBPqAnmERL+4ku9Qqeaw0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855857" 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 v6 05/19] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps Date: Mon, 3 Jun 2024 14:10:09 +0800 Message-Id: <20240603061023.269738-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395364877100001 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. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan --- include/sysemu/host_iommu_device.h | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 2b58a94d62..d47d1034b1 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,28 @@ 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 #endif --=20 2.34.1 From nobody Mon Nov 25 05:27:06 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=1717395276; cv=none; d=zohomail.com; s=zohoarc; b=HJhX+DilKQEyQNW1EAvYZAGpRXIQvea0IUfdS+cZ4zpt/FItI4tMSMr850YMQD5FAiejfkZovriJMLSR2IS/HaxXbdmAJTRuK1FmHNuaRawIsPWH77slVxRuAJPv/dqFfzv51JkEud6mtQCCVK207ewCerftRRktjO4xemvIoKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395276; 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=jGEs6Eat1IcFikZ16rpJCP6t57tAR/JELixRcKg4pDaNQwLJp/Ph2w9GGeubXvz0HT/DHUrLAEMeD0hJ0QjbBz9Wy/hyhzO/OtLwgjnTnI+Q0FnXpSR3JEV42OBq/ASMZoJ0qSznOtEfK3zBp95Z4n8y+lXI1ZGHCBO6M86goK8= 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 1717395276011372.4864349512369; Sun, 2 Jun 2024 23:14:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0wv-0004oL-EH; Mon, 03 Jun 2024 02:13:41 -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 1sE0wu-0004nA-1P for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:40 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0ws-0000uQ-Dk for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:39 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:36 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395218; x=1748931218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OP3qnqR2eeb5LkENXO26BG3fJHDhCXlpbz0ddpelol0=; b=e9CSkT46lGvO8jGMHLefMdFXj4xc9w2vPytV2zDfFzAjueCqGrd3xngr q8OLsNFMQbkrSaceiUfYEClUJkBDwnFpQSyANdwd/NIecMt5KV46inAX8 VlnmkLn5VozW8SUjzBmQYjSaUMTe6uVsobVEmKaQKT/U3IuxFdcwSFrtf OAqWZgy6yAy76OwUPgG7cg141IgajsxJ6PYhqC59sxYKAZnTNo6uEUDdQ 5Nf0uxEyYJFpxZj1+IcedGwGagqwh4/OtipCzgouCx5W1Wr52ovAzBT8Z /bMhXD/WyfkJ8xXgxj5Xe2SKYZIbxF+YokZE72NRYFTGwSTf+GU1zCzZL g==; X-CSE-ConnectionGUID: kCEAUqUES3iWE8+9j09CRA== X-CSE-MsgGUID: 9g8LJuigTjKj6zjtSzf3Pw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277658" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277658" X-CSE-ConnectionGUID: HOLPRB7jSfGAn3MhCF7sZw== X-CSE-MsgGUID: U5YmlkyvRjumko5cZI17Lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855866" 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 v6 06/19] range: Introduce range_get_last_bit() Date: Mon, 3 Jun 2024 14:10:10 +0800 Message-Id: <20240603061023.269738-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395276546100001 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 Reviewed-by: Eric Auger --- 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 05:27:06 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=1717395355; cv=none; d=zohomail.com; s=zohoarc; b=aaBzOZ4kTc7GezdCArffmhL86DO3CPYSxDvDQTMhaRsOj59kSSDIw7zs2A2ar71Elcz4h/ZyRkCMWmVYMTvZ4vj+ke79c+4OOcYr6utomAF2daenvO9pDAbv8MXTNPU+lc3QwFbtbqNqLzcP4IF7yXv/FI9ykBFUAq8lx3f8JT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395355; 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=MTTOJRs1vC0p9R+Okb9HykPy35E9Fnsw3HsL8cXsA9M=; b=J1n9U8SyNW0psoEeChOBkXmPLeXv5L6xAdkzMtdE+XkgVNmADVEJnmQ1nXmlFiFrkZWQ2Ff2MdUfYDYzk2BvrbvhvutMo5H56N/ErpUWrhM69+CLOCVLmYlAOtPhtkMMds/MsIZBZxwE1GfS1K8KQa5o20J8Ax//aWCgXjzDa/w= 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 1717395355882491.03983017954044; Sun, 2 Jun 2024 23:15:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0x1-0004rJ-6Z; Mon, 03 Jun 2024 02:13:47 -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 1sE0wy-0004q4-Mk for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:45 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0wx-0000uQ-0H for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:44 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:41 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395223; x=1748931223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AknpX//QEXoR/eoy9ob0jTnGeHApPRu1pEWY3rPhxXg=; b=FJC7bVapkashx1kBtdnYPPUHeyIV3l/g+Ests/MlEvjnRYvBEawC+nQD TNrKzoyxIY9hEmaZ7OPg/Veo1QiFdpHb3vBpx0crnfajjWAooZv3SvA03 T2hn5dEVXISI+8MX87d/jMUk9o/VdpdgYafktSx9cMjPeEHCqE94ZDG/7 kEeFQcybgx+iwevZ7IqXw9nPKb4vTilpeHY+ebnUYaJL3GkQ/apL3re5U JNhDMQ57HUg7CYnNI+LQYWYOsemFwla+DNHurYjh426SAC0yzhKX6mdoQ DQPpBkgMHstor07a+13q4efK6spvMpj5mak4HktMs3Ler0nN5gutxPvnc g==; X-CSE-ConnectionGUID: DiHgjnhWQw+Wyn32Nm5UTA== X-CSE-MsgGUID: zRaktsT7Ty+4DrQgAw8zOQ== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277667" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277667" X-CSE-ConnectionGUID: 6hqObsIVTt6gRj+TAOnVAA== X-CSE-MsgGUID: j/6bUBTMRYOvsC4dm8fB3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855876" 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 v6 07/19] vfio/container: Implement HostIOMMUDeviceClass::realize() handler Date: Mon, 3 Jun 2024 14:10:11 +0800 Message-Id: <20240603061023.269738-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395356837100005 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 c4fca2dfca..48800fe92f 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1136,6 +1136,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, @@ -1144,6 +1169,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 05:27:06 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=1717395344; cv=none; d=zohomail.com; s=zohoarc; b=oKvZJGt0ibRZ8+ucvdrYw1+fbuiuhV82Le5wEY9xktG45VJ+8q1oC8QaUp2QH0/xwp2cHw3fu9fHEkLXomoXdAc1UxulR20h8x6r50DXZqzJ2iGyXLwNHVz38IrdZb5A5s52ZzuSCK8bXbVSbY6MjFmmG7jLyhRG2b3helgDwFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395344; 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=hTCoF+bBKdtsASueLUScruLNWMbLMw+7joZnqQ6cVyT0GqwF0HmzzY1zwvpG6vsqbPZfNA00xBAtlTMKHumMB6wmz7M5DO9pqZqggYd/Gb8khVMV6DzWefBLCKDSrczBNkTtRP7+vLjAssE2tia/b7VrivN23KyvhTCgynpYzSM= 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 1717395344788477.17823564207276; Sun, 2 Jun 2024 23:15:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0x5-0004vd-NV; Mon, 03 Jun 2024 02:13:51 -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 1sE0x3-0004t8-T9 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:49 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0x1-0000uQ-1W for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:49 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:45 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395227; x=1748931227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SFnso2XJZnjcpe6vQEbV6q0DMy+GxluEI4QwMoNhpTQ=; b=QZ1TI99ICvKuZgRZPZ+Xc1moZ6pg1uWiRFNXF7o6WdVCbO2GCSMkeTae PL3D0luok9SRbHCFiME5bMObHFBtnD8BZOp91G/FiVrn7h639jtAEdcRj VQMPE6U/IuIXXXVQU3KWMBZG7P8PA1KifGcn6JrSf7NfNv/iHuHpwCJVl 05w1khvt/cBpGnR5Qu3U5UAxKZplLotEVLAhmkQ/aBQ6nu3frHuQaaTiH QzotVOCdMa0mORdzHn3+SGFcC+mm74ddezlW37oK1Y0VdrnDzOqvh1SIG 8ae9+o36mqCio/CDXVwPWM9iabAzEPeC14pELLj48SH5TD/tzpwcIDQhx A==; X-CSE-ConnectionGUID: V+2B4XHkT0KIeJbm17L3CQ== X-CSE-MsgGUID: my2/oMCWT3Wr/8WPLZBbDQ== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277676" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277676" X-CSE-ConnectionGUID: tG3gFRyFR6iJNDdg+l46kg== X-CSE-MsgGUID: mnNxojWCRwmfezZX02QXYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855889" 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 v6 08/19] backends/iommufd: Introduce helper function iommufd_backend_get_device_info() Date: Mon, 3 Jun 2024 14:10:12 +0800 Message-Id: <20240603061023.269738-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395346781100011 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 05:27:06 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=1717395276; cv=none; d=zohomail.com; s=zohoarc; b=cyxkD/+cjMDLpUfXkuedxjZjGLnrsepMVNvRQ2YS8AaT9LIjvOX1kowNWjPGiPcaqiHHeNXox0RmEbkxQ6DKxmU4m5MPPPMvjVsRFxqbwLQDazhQPLdU7pgzNcq0wRbYh0tN6qsKxeDVhIGCgUd81sWw1hApHvAQxIJBQ8JEixk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395276; 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=mUGlYnlZVFr20IJtBHLnD8xp6vjLQd3vDHTtSGRtZqbH5L0eQJrYEWR4e42YQZluGo0rV1Tf1Kwdsh1Yd6CT7d9hZYAoBIAR9KPXraiqYTANq/aYSMteq8S4EGw1hdxoXJ9Z/BgTV4GRgcE53Qem4nX3C77I3D/ikVS+knV5MSk= 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 1717395276931268.90715003473804; Sun, 2 Jun 2024 23:14:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xI-00057S-Fb; Mon, 03 Jun 2024 02:14:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xE-00053Y-SG for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:00 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0x4-0000uQ-H6 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:13:59 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:50 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395230; x=1748931230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VOrfu7fZiy+3eHvD+lVlGibrcIGk/lLlGO5XtB2n6eA=; b=lc1xNqXRSFXulhNuo78Kd4HCzjM7cCIzcEI+vkEgNGcaHYFblIF3PwfW ctXeWc2Ftd6nfSRkpLaXSXzLvTZtdqMIb6pI+SdxVzG4kqiZzZnQLnbke H9pCIXgJRuGNF9fYEIal6KSrZBMq8Xqs1bVIf43SjQ1dfhOcQ6mBTK/9k hj9SpPv2AZGuirqHRXuwRgRrdyuwvIDd9XH9n2MJj7nuHR70Ko0RsEp8K ioQ0O72BvqiaEyvnkc5UV/QpAHimxGn5frdqw6fcpgsWK04hQ9viDUwh6 SnPb2gjlgHsW9Qvlf5O4MTrtbGNIXFi8hfmNpkIsEXYEZD8XZXGCjlCB5 Q==; X-CSE-ConnectionGUID: aDArnocoT8aCmlpFt7scBA== X-CSE-MsgGUID: Avg3LwbqTaOy2Ay3ao9W7g== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277689" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277689" X-CSE-ConnectionGUID: Q3FtpXw8RnqJdW9SafrhvQ== X-CSE-MsgGUID: tDVoIarNS3WJxIFRhhyqcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855904" 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 v6 09/19] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler Date: Mon, 3 Jun 2024 14:10:13 +0800 Message-Id: <20240603061023.269738-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395278549100006 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 05:27:06 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=1717395355; cv=none; d=zohomail.com; s=zohoarc; b=XoSHe/lXymSIVn39RN09U5iWj3bFEp9ZYCTsux6DaK3warFC0awu4ONPJhYYb6A4y4917cz89g/ExVF29i+1eNlunl89RvNS/jXeU/A+ACoVAUXqtpESFDDXqlA1OIZmi3Qz7aM93EQS2pvV1yFu1JaO/ttRi7zL0ZTkCHRTDXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395355; 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=8NBYI+vLu7fTtrvcyDMRIMcGTm5JWnw+LTX8acisK1Q=; b=VoIQZ/42g7ir09NVRa35egHqmdJv+7vJbFZuNe3uzgQwlrS65f2ouZRuJIcXwsre7GPLws9ipuUoxGwI9gQ/5Vwl9E0zIGOig1Qhz518kAXsDEqEWvlok9JFjKVxeF0teXUxUUo9i9Tp+Jhh5huR8x4lxfn6ciz8+zQN0ESezM4= 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 171739535574381.74556454738547; Sun, 2 Jun 2024 23:15:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xN-0005LC-MH; Mon, 03 Jun 2024 02:14: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 1sE0xG-00055M-DZ for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:02 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xB-0000xl-2n for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:01 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:54 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395237; x=1748931237; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aGQbaAJ8Mo1eAYh7VSQnzPpxX2caqE6yUjp/Zueg3F4=; b=moH0ZAbw2jiW89ya0/7UWT2N/vhZrZfDwoYPHgwdO5653YDQQZysj4a5 yzNToJg17Vrt1OyYlAxxcNkM7KBtxwhdmmPYAnJpau9U3CmlLK1VgjhSS cOgyfsBGY/IVXCOnk7uNVytCjBCrX0gcWidS9WzJcXOTqusp13h/x+Mq1 UouX12en+VzXABFoM6MFQeIw5h7qb3UVkBE65F6RqJ8KYvpMCxCorcKe6 wby5BtKBa9f2aWDZVJTIqjgoiC4PIrjTwxHKsQUd3Y1u6BuvUpfHDyvIX HjTK15A1xRpoGuorft3OhHpFhJykKP8txzQ7rO/hB6+/MGKGamW6JJX7q w==; X-CSE-ConnectionGUID: X9wCeZ3pS4Gixc/45qP7KQ== X-CSE-MsgGUID: 6KA9cXb0S3uuyW5RV0lNcw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277699" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277699" X-CSE-ConnectionGUID: gIILgM3FTxa/FTbp/Isd2g== X-CSE-MsgGUID: gt7Hk+SvQ8KWvvImT67D3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855914" 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 v6 10/19] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler Date: Mon, 3 Jun 2024 14:10:14 +0800 Message-Id: <20240603061023.269738-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, 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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_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: 1717395356846100007 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 48800fe92f..a46c275a88 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1154,11 +1154,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 05:27:06 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=1717395281; cv=none; d=zohomail.com; s=zohoarc; b=aFRkA3p5ECfnA1bToIFxMX/k6ihtnN/OkwPjL8itJBK0nAOJvNJ8X3X6/tgW3pYvfIVzt5FABZ4KQUUGm7N5rxjv/dv9dG2If5GYjmvV9JviXiLUQYxQr8pcjyaiqW6X7saPX6NQwxgopZU3P8krBNWQiRHSYR5ZO63u85u836k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395281; 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=HbzmBwHbxQlhEQPMxsV+Gx6BdOXxlD9clf0I0UrAz0iHsmMCAdnTat7xydQusiGs4KJqbPR9yXmlOpSSk64xqviP7L0+FeahP+z4XxG73Ku7PNuAn94KL32OWTNZZRswq6kCJVMfFnwEqrImwOkeXqAtZBvK3FealYdv3prNzos= 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 1717395281223938.9574189139854; Sun, 2 Jun 2024 23:14:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xM-0005F5-Hh; Mon, 03 Jun 2024 02:14: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 1sE0xF-00053t-Fz for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:02 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xD-0000xv-Je for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:01 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:58 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395240; x=1748931240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dAKZSk5QgrnUIjill0jO2g0zyj3Uf0goHqo6GXW+pBI=; b=JNZyTkqyMZR7BFjewvP5//hYXZD9QqOhAuLQ8CT3jzwTX/VcGkryaQW1 LMnLY3yvtNHDt2/2lvUK3Wc2XFc4QUjgh8LObV+nTnfRftDbCFCEw3Y/J nIUBqrBR4y3OYUcUxbwjoaldQnGEf/ZJ1NRuzozRjBV2PRAUuf3MRz5in pReHVznRNaa9/4cOrfz7lQZzG0SdQXu5fbTzuZHB2NIK5iHq0sFCG10Gg 7PCL07UW51zr1y/BZ6sHyXc0Z6IoaJzyZD6btEwXuezzqJ/W4++XZFdgD ZllEV3sbFolHJJD3+bFRL8UtER9VOpr+DsOnRtKkoLfk9QLrpaFTRKj5S w==; X-CSE-ConnectionGUID: 1XJypS3MQyeDLhQ0ghUzHQ== X-CSE-MsgGUID: f4nTW8e9QdGQyXEaZINfFA== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277707" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277707" X-CSE-ConnectionGUID: 4+04TMNbRk2ZzHKqVINCGA== X-CSE-MsgGUID: v2BwHxoRQPW0LnWSjTnFTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855934" 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 v6 11/19] backends/iommufd: Implement HostIOMMUDeviceClass::get_cap() handler Date: Mon, 3 Jun 2024 14:10:15 +0800 Message-Id: <20240603061023.269738-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395282507100003 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 05:27:06 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=1717395344; cv=none; d=zohomail.com; s=zohoarc; b=ShUbKIZjCsYVowZ4p41MLsLW3Ri1aQqHddHxx7Wpa1XN9sOPVelNyrkezmn8OKYUa0DQqwYe7s2KAY7nHChRnasBvWP1jrWPDApUk/EHMf3FJCMB81XrRGPFc/8R3GJbsavr5L+Oj5k1BxLjIg9CdLwQySvnLAkyCWzIRKNeAZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395344; 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=jf6mfCS/2siCiulxxvF9xuai/RdIHMjVE1Zg+32+7SQ=; b=HYGVztv7jTQ3rB04REYoJXInd82L7uiE/JMlprvt28hhyK3t4ekdbkD0+n1sRZ7jnHRAZppoJ4PhFmSKTatNC9AXcsnfzBI838R25QGwRnki1KCyKlxKECiSh/dE0KWKoiqrofeuoSdKmjzoH02piVHxqN+cDAzIL+eMmX91evo= 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 1717395344761707.7576074490061; Sun, 2 Jun 2024 23:15:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xO-0005ON-MD; Mon, 03 Jun 2024 02:14:10 -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 1sE0xI-00057y-Lc for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:06 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xH-0000xl-32 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:04 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:02 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:13:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395243; x=1748931243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CLAH+tFOQ9hbvarHS3YJ8MOeGi0g8QtB+WDJmZOUxxE=; b=WaBSWUvClN1GG4UdLt3q8DSsta1+pzwTNlpu8hWjtvT2R7eciK2Wntvn ILhXN/xToaAwoIqostZEJhD+tdeXwfV5DDHC/caAvY0ydIpcSLJHcBqgn UaRg9EVrFGpWDaKz6nPj5kXFhjm8h+YBPt7mqjts80DUj6cxGXLfbII+t 5tzOCvVV2OYvfz0E23HBrQfmQF6O5gMnefLqwCqRp58snqxdErj98ZQCT M37HphEiQVzNck2Lm76v0HAJugLKYDO9N8DhRUpixTDlVKNfrx+6YA19E ivCvgKmDD6GWydRAsS6jAuJQEzzS/+uF5Xum34Zi8O1L04qjD39LJ2FG6 g==; X-CSE-ConnectionGUID: 8Gl4Ri2RRjqtzVq7VjLScA== X-CSE-MsgGUID: mYKyL8gmRmy5M3C/K62k+w== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277720" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277720" X-CSE-ConnectionGUID: gYN6JaamQp66eho1Ci24iQ== X-CSE-MsgGUID: 485Q5O9ISDOCrJweQ6AXsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855944" 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 v6 12/19] vfio: Introduce VFIOIOMMUClass::hiod_typename attribute Date: Mon, 3 Jun 2024 14:10:16 +0800 Message-Id: <20240603061023.269738-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395346778100010 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 2776481fc9..442c0dfc4c 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -109,6 +109,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 a46c275a88..a830426647 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1126,6 +1126,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 05:27:06 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=1717395276; cv=none; d=zohomail.com; s=zohoarc; b=cnos7wBDhdCF6tY88ujrz5b0ot/0UGRrz7etjbd2rJb8xJMGnDRgCKlwjK0espsvl6X5TqxRt7vLpTho8cFiTYBgVTdGitYJvpOlLi0wbrNHPWPbaHofoQs7IuK2iZ0+QaOA0htz53vs9gHMNvuD3UnPbx7fgTvBgOSXW4MQWeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395276; 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=rFUdP5qty3630v1yYkIIQ+vKud6/czN5807gkQmHBHY=; b=lwZ8kZp3YqIMGk0L/5s+XVCg9UQAcPhOW+iZCaY7OHLYW21x4/95nv6WdUBAITeaz0AgfKnAQbeRFEz+zvxRbDgU8pLxMskUIXctxJo5yK6WwugTt6Zh9VY7f/k6mV1pEvBGHLr2/9F7N6T++0O1so31BfaN8dgEd0R1O9H3Mn8= 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 17173952768921001.4630150472193; Sun, 2 Jun 2024 23:14:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xO-0005Om-QM; Mon, 03 Jun 2024 02:14:10 -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 1sE0xM-0005FI-HR for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:08 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xK-0000xl-Sx for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:08 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:06 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395247; x=1748931247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BMSIUgLa5Y1OsVlKLzI0+ljLIY7H18OPFG5Alyk5isg=; b=G4DKlBCSaxcOUo4nJtR8qrU86PbyFQ5mK0GKWzdyJ0rqwBvXugsNEyWS QDbhXzmn8lfrf78rJOqP+Xgsmtxb9N284SY6zYo2nQXvvqY5iM7lIft3T 6GwtE1eNfnxnmPgCb88wBeJF5oRAH856mvaSc6dxCQ/+BHynNUY2wsr/f TlRbMYukQIkVKrV5FRwB1gizzTiuC6820IxzUkIneLDlHGAI/IISkvsyE lziJ9MWpQEfzuGTt2BFSMrI1ts7d4cv288RCvMOKsU+CFkxlpxzwJi+Ua J7TUUTsyfQIaMfCfzjkFgHkAzCVpZnijP7oMabKqnAk8dEMDDxW9KY86/ w==; X-CSE-ConnectionGUID: d0aBiSHOQAakJIWubOyaXg== X-CSE-MsgGUID: iN0C+ZmPSeu3kax9tlszzA== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277732" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277732" X-CSE-ConnectionGUID: 2v3kfL2wQTCdIlOSECSkmQ== X-CSE-MsgGUID: Ol2gW2CsQDyDx7wd7+Xuag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855960" 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 v6 13/19] vfio: Create host IOMMU device instance Date: Mon, 3 Jun 2024 14:10:17 +0800 Message-Id: <20240603061023.269738-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395278536100004 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 56d1717211..c0851e83bb 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -127,6 +127,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 f9619a1dfb..f20a7b5bba 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1528,6 +1528,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)); @@ -1535,7 +1536,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) @@ -1543,5 +1556,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 05:27:06 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=1717395356; cv=none; d=zohomail.com; s=zohoarc; b=BmDLCQoMoH5ODisZC9A7SCx1WU8DmrFJIdfj8sJs8O6TaSp2WTboQi1Xy5XzEzId1OZZKj8YqmwKdCtKOW5UPOSeBzzSt87mGbCRcojn96FMaiOGfoKDk0GaTw3U8iKa2R8vR1p/AF6oZCsYJ7cnMLSXTNlKHcBCqv0DCK0EoFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395356; 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=L926YFgGEelz9EftINOkbnd0oYvg4Fjd+sJqxmBD3tM+JkgplaK/vvHBauHs6Y5BeWuHNH0lis3b9VLeMVvMF3Lf0swiRKBONb5x6l/E3Svg6SpIe6GfVecWEonCAmgLAUyURUZBMd5iSVci15TYC/xHTLdLFa+SX4rhYM4p8oA= 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 1717395356530215.11272046499448; Sun, 2 Jun 2024 23:15:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xT-0005UI-9D; Mon, 03 Jun 2024 02:14: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 1sE0xS-0005Tg-5v for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:14 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xQ-0000xl-FY for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:13 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:11 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395252; x=1748931252; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lOqDt9v6x0LF0QRt0dafkaMf+eapZI59zjmfrdfGr4k=; b=gZ8KofgIatSVzhGtZQMl7I1UV1b1e9rb7zcQJsoKWpjWaBVQK7ySZcK2 RW2OQ1IFPnD/Wuvf81IaDIoOXH3veLtN9uXewuCPAe+veHwjI4vzB7oqQ M81nyoDpPL5QDvQSKPSCeQA6N7IzKV20tGLyk5Im89Z4DWWO3hbkPTE8z zkLUn2fvJjKyXoYRhF7w022OySVvEKtTnzPKk9clMQZC8TZEXQ0YmITNk 3OldL+CqI6G7IDtj+r+2I730Px8GVEW0p45S3QxgAkgUbR+8HxNApQib1 TSIcuIf2S/CZunrmOIJ4uSSXUSgcpzmsA5lhJAZY4Vod18RQFlaweEiV9 Q==; X-CSE-ConnectionGUID: AYsTM9uwSi+WX5NeoAl2dw== X-CSE-MsgGUID: 5E1UBGBgSASfzgk8CCVkNg== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277743" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277743" X-CSE-ConnectionGUID: NeqPSDyVTZm/VxymN3xtnQ== X-CSE-MsgGUID: BbodyjcQSB+vr4/lP+v8YA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855967" 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 v6 14/19] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn() Date: Mon, 3 Jun 2024 14:10:18 +0800 Message-Id: <20240603061023.269738-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395356845100006 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 Reviewed-by: Eric Auger --- 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 05:27:06 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=1717395346; cv=none; d=zohomail.com; s=zohoarc; b=Al8/cHFch2IpXrUuyc9BRjN35ymJWuA3Y3FKH31xsxPMPuPFiFQ2auCu4p/OPfO/OOGQaE8BX4V+usX3jouf/oWZj77niejLjwsNcYtn8GoPnAn1HtoSrx6Zxv9HXOg1JolqA53mJSYO6pHUUqhEJ8qh0oC9XEiNmP5M+HDhLeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395346; 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=VoBFoxwExmcfJkoYrc7PLp1t+RoxL3iYfDfNlcluQSRUXt3dbV/BSPrLSWp65QaRQuGoPRyBxwPF6twTWFxbfteWtrVZ1H35k91KakaLLNvOh+dT9MB4E0D+wpPPOZrNmODdmhRuFkFfHQFxtjE8YTpMATb/ryIv+iP8BEo1rYU= 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 1717395346614754.2945502309274; Sun, 2 Jun 2024 23:15:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xY-00060U-Hv; Mon, 03 Jun 2024 02:14:21 -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 1sE0xW-0005q9-OO for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:18 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xU-0000xl-Fu for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:18 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:15 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395256; x=1748931256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IJL5PsoklMNCE7TY1tLnHp4d+Usegx9kN+idzGTHTOY=; b=dfHdOAG7QlzyUXpUSHV5+r1RMhfvxHGJ6XmN3udgBmsRI8uLtmnc89il JO3SaLd1TnOSqwKSMGITZRbq3hDGRgVS63n1NKSS3ckyx7ilXIIqlfy1S 2JqwfE/Xdl1JVmptONtI+I9NF5p8KqPKhxJj8eJI7kMlcQyxTCaqsfKog szElwqFYdEvpenpFM/MeecNG/GSwKMrlQMfTATCXAx4REyZuMKf6O8dNz bq1Y9WhyqkP8+qMEkZ6YpSOxxEZSwGb5/9c2rQqiA9hW+nc5pbueM/3Sn VoGTUGyW5JUL8Jzau2qPF4ZFm0mcJvaB2WZ+ByVMPmedXO0jmz7Wg+vZ2 w==; X-CSE-ConnectionGUID: lU7lQxsWTD+wkl9ev0BdwQ== X-CSE-MsgGUID: zXGtoTA7TkW0/URT0q2Iyw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277756" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277756" X-CSE-ConnectionGUID: IHyAdZVNTA+Mg+pfJRBwbQ== X-CSE-MsgGUID: xGgdzKSgTIWbDBsfFdedew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855973" 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 v6 15/19] hw/pci: Introduce pci_device_[set|unset]_iommu_device() Date: Mon, 3 Jun 2024 14:10:19 +0800 Message-Id: <20240603061023.269738-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395346777100009 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 Reviewed-by: Eric Auger --- 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 05:27:06 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=1717395365; cv=none; d=zohomail.com; s=zohoarc; b=i7DHZGr4CzbMoJ8MwfAyBYmEFQZsUAGBRvXrUY8teAcDYsmsOcn51Aal7V69HAIWEfP7KOlg46v4GiAXSG90s3k06FyhJ9bOpDpMImLzH0tqfDBlSrqLtFE/g3N8oF5BzXC37m4i5bgetqhVDE+jQTTehWF9bgWokTG7wL/WaTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395365; 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=rCWpCcJgvSQRNyNK2VJogfplzzY6EFku14uTIujDmZo=; b=SbREPwmNE406fQ2iJspE0DPUzUPr+/GiErCfZzmS/aM4KfT1ZEHN6vEptTuFVoK5S6wMGbtB9/Si08wQqQgfCCYJuji2JVQHF1Z9DTOrMTancZcNGtNhrVuwcidq+Z8M/oKXnYXGky1pHUznIpgACST3Nff/KOZ9OQR5ezLff9Y= 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 17173953651529.580431878885975; Sun, 2 Jun 2024 23:16:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0xi-0006Po-T6; Mon, 03 Jun 2024 02:14:31 -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 1sE0xd-00069g-AT for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:26 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xY-0000xl-Ou for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:23 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:20 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395261; x=1748931261; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nyd3SwoK+cs9yuOOZ+aoWR7QGb+/QWyokm8AotAsE9k=; b=UejF9VCkRnKnEKO7ZrSCls+WcV7d/b/pDTFSHG2qlpHJp02Z+UD0v4A1 eEJA6vlX9wetSvs1iIPBnbh/D+6xymPixRWoG05cV1uh1GgKdddIVDT81 nnrMJYdrm/Nlg0nYZBZigr4Fog7XGo7co4JUCcVagYMo+Tsnv23+JpDsN eGCDxe5/aG4s0zfnRJUvdmNmzcEFqyeB97X8EWPeMHn+V0+lOmdIXWMA+ E/gYL7JZqxgvOmZRj/giqZg0ShI2UU7Eeej3Bfjj8WiBnbV5oMlPmbzgL QoxN3mKPhRYEfwQuuoiLljXDZFst7zZMhMSTt6TwHam3V9lyx5E6HNZLf g==; X-CSE-ConnectionGUID: W1VWog/LQFCIfDPdJ398BQ== X-CSE-MsgGUID: v2Mz+jA+TciNUoEOxC6mQw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277766" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277766" X-CSE-ConnectionGUID: dnT36AlqSeO4435cS38E/w== X-CSE-MsgGUID: 7UCD2hSjR0emdJUVHLYebw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855976" 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 v6 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU Date: Mon, 3 Jun 2024 14:10:20 +0800 Message-Id: <20240603061023.269738-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395366875100009 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 Reviewed-by: Eric Auger --- 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 74a79bdf61..d8a76c1ee0 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3121,10 +3121,15 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) =20 vfio_bars_register(vdev); =20 - if (!vfio_add_capabilities(vdev, errp)) { + if (!pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) { + error_prepend(errp, "Failed to set iommu_device: "); goto out_teardown; } =20 + if (!vfio_add_capabilities(vdev, errp)) { + goto out_unset_idev; + } + if (vdev->vga) { vfio_vga_quirk_setup(vdev); } @@ -3141,7 +3146,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, @@ -3150,11 +3155,11 @@ 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 if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) { - goto out_teardown; + goto out_unset_idev; } } =20 @@ -3238,6 +3243,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); @@ -3266,6 +3273,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); @@ -3280,7 +3288,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 05:27:06 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=1717395365; cv=none; d=zohomail.com; s=zohoarc; b=TIdq1ZNPDNvX0FW9aYq3r+RgW9xaIUgwCzH84hRGh/OLjO5LstcUwRsOn3WcKvrwUFZWvQ12TvdOIXsJk4kCxiVPSY+rurDwbzcqzz6mlw9qP9JKeZMH5y2uoqn8Y7F9j3biQS9YZ9Q5URIRpJCwNftJIBskP0n5kF9spb/mM3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395365; 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=H5IVRo/1aWW3X32iG3swkaB1OSjMJinlUOS3PvBr18bma7IG9mD+FxfQWIaztUPAxEjnfKmtBLc35icFQAwNqniCwW5IFqyd7+ssDQ4hKoZ468gONJiXbt3rbhK4/FXLJmDB/HJyWh7FnwPh9a8A8hpxj7/hfOVnudvV84j+pMo= 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 17173953653391002.8768750074381; Sun, 2 Jun 2024 23:16:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0y3-0007Qe-BB; Mon, 03 Jun 2024 02:14:51 -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 1sE0xq-0006mx-FS for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:40 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xn-0000xl-Ft for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:36 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:25 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395275; x=1748931275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B7nXRh7ZojaXtdhNyRfMhv/+nlUrwKMI6CTd3vTaKw0=; b=FuxPPiTHJZb9GW5GSn/U9iDB7ebuz1FuiLuHsTPGljE3pP1Hvpu+jpOK 95BRfaNvanAdGzQwA+VWz6TWhEtjICuAYNF8ctHP5glcKZDEsvpxb69HI F9+2I2QZQeGAJ+Ln8icKXh+gdDLNMcoXpRE/+YkIcRKXwCxJsBG5d+myV RjDe0FIcuGG9JD1zUTZbMXEpGFMprQq2Hj6xVLPTEuvhoj2BcNBPjGP14 gL0wDfW8ne/mNJ/CmpsaA5QgRJhiCm6eKLQ1lcZlfHjE/+6TYchNCp9r9 vZDYfy5z02wyn+ZYDmXZ4iMYEZwsAiIRwKdXdr5OJyAoeoVs53MJQSaM+ A==; X-CSE-ConnectionGUID: ethdSeD6R5CRz2NTa7aAsA== X-CSE-MsgGUID: Ne/UShP5T9a8LlmlaF9H+Q== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277774" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277774" X-CSE-ConnectionGUID: j0zz8ApUQ46v09usbXqTkw== X-CSE-MsgGUID: Pr3AkDXvQty5PmnhUvKAJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855981" 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 v6 17/19] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap Date: Mon, 3 Jun 2024 14:10:21 +0800 Message-Id: <20240603061023.269738-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395366898100010 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 05:27:06 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=1717395372; cv=none; d=zohomail.com; s=zohoarc; b=j6hZzOOJMqbwX+ZjB+TZhTGQhTJLlBxx6HhV1pFE6D9GGWoFmm1LU3mnz4sAmEIzyA05eOvbYFp9FHAlYYIu+TP0Ur1XrZ8lJXrassVWKezEE0kFRW7XQ6zkbR+mP9+UxK8RQb43eHpoxbd0tLHEz3XmeEL+PZvLngfTiyakqVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395372; 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=c2+zwNj3bV++NIl909Fz6usRnamYxaN5qy6j5gCsHW/1kNkZTldGvyk0FT64yFtMvtSTJLWbGPJdS0vJNVZiLvzLqmAGz0/Afh+PQWzVThs3JqyE9BMpGQt6HGBPcExZWsHnXb/9BFiTiuTxwpY+AF8s76vAerNrZ26e0bHcRlI= 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 1717395372145361.26699333860915; Sun, 2 Jun 2024 23:16:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0y1-0007CX-JR; Mon, 03 Jun 2024 02:14:49 -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 1sE0xm-0006co-VF for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:38 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xk-000150-2V for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:33 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:30 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395272; x=1748931272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=10eC5ToShm95JMdUATdaaiU5CKNRnm6sQ9xfoHbMqWU=; b=GlQB81GbwW/4JoArjsAlylLkYOEOaycWBGyng417GvMSdiR79fBcufFB 71rS9msJ+gadNkOw8oRbmj94m1ubAl+cdNWpKivhDU3NV9P9ldthgPCdh c76qPwBJY8Th2ZzQDqzB4Sz1x3btpa4JKCSFHCfD3QfhzIGwRJ7YhRoml 6o5dwAAKgJI30Ospc1w6yoy99vg7QLAiW59SnK87fHyA7/z+rrhzkh6hc BmNtcGfFmPrtliPuEIQDNFmd1VmZ9X9O8sEFv3NiY/bZFmXso63N0Z4r6 Uc0YIxTLE7vM3Z2yjo2FjRRMsGIQVD6QtXReOSfLMmDkUQe3dCNAUnbaX Q==; X-CSE-ConnectionGUID: FAxfOxCoTZKUfUJxRC6c3w== X-CSE-MsgGUID: 1brdjDuMRvOGkoGQWLe75Q== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277790" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277790" X-CSE-ConnectionGUID: JhsoncaTSvyZ2K9gEHXrEw== X-CSE-MsgGUID: MD7B9udYTX+hbEBYQgKoqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855988" 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 , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PATCH v6 18/19] intel_iommu: Implement [set|unset]_iommu_device() callbacks Date: Mon, 3 Jun 2024 14:10:22 +0800 Message-Id: <20240603061023.269738-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395372922100003 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 05:27:06 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=1717395409; cv=none; d=zohomail.com; s=zohoarc; b=IU0PxNrkDPvjSoMdvFFX9iBLhZ2ccn6lxWDpjo/TenYSgiCEXR3e/+CYkv77ZOBx0WNkNeNQEC7d37X/Vdl0nBzLMcAd8Y9PrptJHy5d5M6kC8r/+nbPYdt/3lWKPSld2JSMMZECV5XUPsIobxnTQi5WYuLguudfHT5uQJYH7ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717395409; 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=hvsVKSA9kKJV6vJdIm/80hYNHcDkThq7tSfs8sPXNrw=; b=myr67c6gff6WSS7x3iDOzJj0hHmdnan03VHWVbiYaz+c9+W2k+/7syu3Lg53SMw92rnsH8Xvxdp2uikVp9q3qJsWrj2UWDwfEVu5IxR4sWNfGgl2i9c812pkJpQS4+Ls65c6vEW/ECW6yxMby0HwvH6cIXu+THCy9G3ebmmy7YE= 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 1717395409599586.4982040511125; Sun, 2 Jun 2024 23:16:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0y3-0007PG-8K; Mon, 03 Jun 2024 02:14:51 -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 1sE0y0-00077z-T2 for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:48 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0xy-000150-Rh for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:14:48 -0400 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:35 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2024 23:14:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717395287; x=1748931287; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=81lbEn62SdS0xMymXpmsvHqz2eXRuM4ot4UU5tiF2us=; b=gMDzdCZwsqI9AQecRHeDSVx1Y48HLUIsb4pYQOc99CTtro9w8Eo0bFSG LStfdaCpTzcVC0UOIYxk4muVH/nSSz1tfjkCkZb3m0QbVmAbo4THd5H8T uAfi3n0+W9jBp95okr5pHLhGadKDpj4RREo4Ge6dGOY9Ou2wwLXPM4VGf hnbbfahWEHWONvsNJz3Tg4BDAg7jlw+0YtOVxwWBObhRENoTwhRGuCHYm uKLXy3/Fedb/FP54M28JG5+FUkXeUuQsk1JpnJmH/Ry5DvxvU+Hw6sQfu uMOTpBKDlrrgFJ5n2OuBB76SaseqV4IB4bZX9bDrYF4tQ/4/C7ZEi5bgW g==; X-CSE-ConnectionGUID: kQP9QgiTQYqAMT5DxDHH2Q== X-CSE-MsgGUID: 3y0lkIKUT4WOwvC8NU5UWw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="25277806" X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="25277806" X-CSE-ConnectionGUID: 4X461FDtQ4eb5HlQBt2pMA== X-CSE-MsgGUID: eylKjKwmSOmNeSdyyssdQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,210,1712646000"; d="scan'208";a="36855993" 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 v6 19/19] intel_iommu: Check compatibility with host IOMMU capabilities Date: Mon, 3 Jun 2024 14:10:23 +0800 Message-Id: <20240603061023.269738-20-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603061023.269738-1-zhenzhong.duan@intel.com> References: <20240603061023.269738-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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1717395411081100003 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 747c988bc4..d8202a77dd 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3819,6 +3819,30 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s,= PCIBus *bus, return vtd_dev_as; } =20 +static bool vtd_check_hdev(IntelIOMMUState *s, HostIOMMUDevice *hiod, + Error **errp) +{ + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); + int ret; + + if (!hiodc->get_cap) { + error_setg(errp, ".get_cap() not implemented"); + return false; + } + + /* Common checks */ + ret =3D hiodc->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; + } + + return true; +} + static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, HostIOMMUDevice *hiod, Error **errp) { @@ -3842,6 +3866,11 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, vo= id *opaque, int devfn, return false; } =20 + if (!vtd_check_hdev(s, hiod, errp)) { + 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; --=20 2.34.1