From patchwork Wed Feb 28 03:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26482C47DD9 for ; Wed, 28 Feb 2024 04:03:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8A-0005Rh-Tf; Tue, 27 Feb 2024 23:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB89-0005R5-B6 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:17 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB83-000087-7d for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092871; x=1740628871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lhqz2iRToADp66tcHjAaagZoKGFICWwlIhQ9qtn5y64=; b=jE/Eu+gTfx0+ECeIy1/m3i2CAj+3U/O2OSnA3cKM23vx/Wxp3WhOCHWX sGmE3UpVfqpIQqYPTq3wD0U8qmxOU2YBnwBMoCxjC70f5DI4aSr8EAexI JvVRMRoNHu9vnyOakUJwbmeNCny1KvjcqC67wd2PLskbDUebDzjP+HZTz 3iPXxxd6Cd31yjCPVLMDjTeBUyUmIVPLlA3z3yt3qbnd9Lqhfo6z8mgNC TlXcB3RyqzM5Ew70Ni2rzmbSHTiGFyRzRrrfHGqD0qD0Kx5nsOUGdpHz0 qJnWE+5RNpyCY9JkJZni8o9BBUXRT82mUP3a9RMMzhlqXz/1NBh0TZE5t w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342422" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342422" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917075" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:05 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 01/11] Introduce a common abstract struct HostIOMMUDevice Date: Wed, 28 Feb 2024 11:58:50 +0800 Message-Id: <20240228035900.1085727-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org HostIOMMUDevice will be inherited by two sub classes, legacy and iommufd currently. Introduce a helper function host_iommu_base_device_init to initialize it. Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan --- include/sysemu/host_iommu_device.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 include/sysemu/host_iommu_device.h diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu_device.h new file mode 100644 index 0000000000..fe80ab25fb --- /dev/null +++ b/include/sysemu/host_iommu_device.h @@ -0,0 +1,22 @@ +#ifndef HOST_IOMMU_DEVICE_H +#define HOST_IOMMU_DEVICE_H + +typedef enum HostIOMMUDevice_Type { + HID_LEGACY, + HID_IOMMUFD, + HID_MAX, +} HostIOMMUDevice_Type; + +typedef struct HostIOMMUDevice { + HostIOMMUDevice_Type type; + size_t size; +} HostIOMMUDevice; + +static inline void host_iommu_base_device_init(HostIOMMUDevice *dev, + HostIOMMUDevice_Type type, + size_t size) +{ + dev->type = type; + dev->size = size; +} +#endif From patchwork Wed Feb 28 03:58:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19452C47DD9 for ; Wed, 28 Feb 2024 04:03:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8A-0005RO-TA; Tue, 27 Feb 2024 23:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB89-0005R6-CM for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:17 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB87-0000Ae-LQ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092876; x=1740628876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kd69TG3kOXlDt16q01lfY4mg94D34FMScX/P6hYvxjc=; b=Z/uaxbyH3/OWgFVKqTuZSbq6NPR++xYF9nGTBMpTCt7S14KhUmwT6PH+ eb3zN1ygREUus81oOLs8H+Wft/8vOMAKp3q9+u9Q7+zqbF4oMGnPWcPuJ yCf0NM6180MV1mijM2yM7buX2Z+KJZSTCJbvwxcKXGOwjQDzDjDWqrNEi 77KgEjxbpzs2tv4bORTLUnq+8x6QaT7+ZnDnFCtjOWmgCXTFgeM7fSTH5 8LRpixq65VNHsz4Qkc5mUTWXvTXSFcTcDhTEEFQNxtliCALCv3lZ6CxPW twcM7Y9AkyEFC3Gj+YK71lhuyC0OlSx698byZiBNN3xTDAeRI0ogjHYee A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342432" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342432" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917115" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:10 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v1 02/11] backends/iommufd: Introduce IOMMUFDDevice Date: Wed, 28 Feb 2024 11:58:51 +0800 Message-Id: <20240228035900.1085727-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org IOMMUFDDevice represents a device in iommufd and can be used as a communication interface between devices (i.e., VFIO, VDPA) and vIOMMU. Currently it includes only public iommufd handle and device id which could be used by vIOMMU to get hw IOMMU information. There will also be some elements in private field in future, i.e., capability bits for dirty tracking; when nested translation is supported in future, vIOMMU is going to have more iommufd related operations like allocate hwpt for a device, attach/detach hwpt, etc. So IOMMUFDDevice will be further extended with those needs. IOMMUFDDevice is willingly not a QOM object because we don't want it to be visible from the user interface. Introduce a helper iommufd_device_init to initialize IOMMUFDDevice. Originally-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 15 +++++++++++++++ backends/iommufd.c | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 9af27ebd6c..d509ff88ef 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -4,6 +4,7 @@ #include "qom/object.h" #include "exec/hwaddr.h" #include "exec/cpu-common.h" +#include "sysemu/host_iommu_device.h" #define TYPE_IOMMUFD_BACKEND "iommufd" OBJECT_DECLARE_TYPE(IOMMUFDBackend, IOMMUFDBackendClass, IOMMUFD_BACKEND) @@ -33,4 +34,18 @@ 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); + + +/* Abstraction of host IOMMUFD device */ +typedef struct IOMMUFDDevice { + /* private: */ + HostIOMMUDevice base; + + /* public: */ + IOMMUFDBackend *iommufd; + uint32_t devid; +} IOMMUFDDevice; + +void iommufd_device_init(IOMMUFDDevice *idev, + IOMMUFDBackend *iommufd, int devid); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 1ef683c7b0..6d280e4aea 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -231,3 +231,12 @@ static void register_types(void) } type_init(register_types); + +void iommufd_device_init(IOMMUFDDevice *idev, + IOMMUFDBackend *iommufd, int devid) +{ + host_iommu_base_device_init(&idev->base, HID_IOMMUFD, + sizeof(IOMMUFDDevice)); + idev->iommufd = iommufd; + idev->devid = devid; +} From patchwork Wed Feb 28 03:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB4A7C54E55 for ; Wed, 28 Feb 2024 04:02:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8U-0005WS-JR; Tue, 27 Feb 2024 23:01:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8R-0005W0-KC for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:37 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8M-0000kD-OL for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092891; x=1740628891; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N3xsv2GtRVX6aSgVHRkuCisTKekGHMSdCU/SFK0nNzk=; b=HOhbg2tZk8JeUZVNJjQIvz+bCngn9TD87FvcKSuMx34ufz165OxQVz5e UO5vNl6eRcC25nNjin3lSfNwShtqrzxHeBMsH8dELd0FfxfK5Sg7qcT63 JIDP0y6DR/lM6FYPrWpAZ/IJiOV71QCcMid2S70WFHYWOumnGG/ENCqqF vpPrzXdmEXnFmfSWWTSXWi3Ado3aFLOgzB94nvtJBOC9oYJqT2pBZncGN as2oA5kv3nc0GGGft9h2BwjWbRhO+ClNPw2xq6RG5gKNvaVGYBhW2EoT6 U9y+OG4o78eAgDVZ95gxIUoaSoXRSWKpWP/ZvdnM3o8gHqxOSJCbW+LlO A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342451" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342451" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917189" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:14 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 03/11] vfio: Introduce IOMMULegacyDevice Date: Wed, 28 Feb 2024 11:58:52 +0800 Message-Id: <20240228035900.1085727-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Similar as IOMMUFDDevice, IOMMULegacyDevice represents a device in legacy mode and can be used as a communication interface between devices (i.e., VFIO, VDPA) and vIOMMU. Currently it includes nothing legacy specific, but could be extended with any wanted info of legacy mode when necessary. IOMMULegacyDevice is willingly not a QOM object because we don't want it to be visible from the user interface. Suggested-by: Eric Auger Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9b7ef7d02b..8bfb9cbe94 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" #define VFIO_MSG_PREFIX "vfio %s: " @@ -97,6 +98,11 @@ typedef struct VFIOIOMMUFDContainer { uint32_t ioas_id; } VFIOIOMMUFDContainer; +/* Abstraction of host IOMMU legacy device */ +typedef struct IOMMULegacyDevice { + HostIOMMUDevice base; +} IOMMULegacyDevice; + typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIODevice { From patchwork Wed Feb 28 03:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8143C47DD9 for ; Wed, 28 Feb 2024 04:03:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8Z-0005Xc-TW; Tue, 27 Feb 2024 23:01:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8W-0005Wu-IH for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:41 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8R-0000uR-LS for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092896; x=1740628896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=InINaFpruLMkFpCTED2dU+8i3KHEDP/YmQBNqrbqvAo=; b=LfS3/Agd5V9j3E2yha7wL9MzV+wLNfcsn6m1kQm1e2BIGHlPRR2w8Ap9 Fh2vZpwhm8JhNTVnm7cRyNc/dCwUZEdv0Md3df3+kTO7TdRhmLNvnBElp piLMjmUqkUzVgJWo+dj9Qm+MK7aQoTAKLiu19A6kw8GErJ+selmzQ3xsS 34SQ/MTsmCc8psSUlsO+d6dFftg/+wuA6IB9Wua8hbUHcH4s/Ayp/Ueun Lquat+6hUNoemZrdc3DygJizsoXY6hDoP+qjNcK762XdTl9T2vJ7KfjAS l+Rjb0iDbCv50IFMXlQsdXH1cIILAHYv4WhMp61cAc2+sEU7sy4Tun5Uz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342455" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342455" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917202" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:21 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 04/11] vfio: Add HostIOMMUDevice handle into VFIODevice Date: Wed, 28 Feb 2024 11:58:53 +0800 Message-Id: <20240228035900.1085727-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This handle points to either IOMMULegacyDevice or IOMMUFDDevice variant, neither both. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8bfb9cbe94..b6676c9f79 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -130,6 +130,7 @@ typedef struct VFIODevice { OnOffAuto pre_copy_dirty_page_tracking; bool dirty_pages_supported; bool dirty_tracking; + HostIOMMUDevice *base_hdev; int devid; IOMMUFDBackend *iommufd; } VFIODevice; From patchwork Wed Feb 28 03:58:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE99BC5478C for ; Wed, 28 Feb 2024 04:03:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8o-0005hp-5G; Tue, 27 Feb 2024 23:01:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8j-0005Zq-I9 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:53 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8T-0000kD-8m for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092897; x=1740628897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kK5GveDjiGIDtpRZDuuTtvD+hLljT6hrvvuILu4Z11U=; b=Fb5N9IqW9nccqbL9IU5LpZSmvhi8+rQbfnt4PD1xTTlQUBEcM6ShWkNQ rg6s1FsWBN7+d8PBfrUtUnDL1Rxyz5X9m32VtNXz+dA3bypL6BOmsJ9oy uygNzCcOKWCalAQqwJyMlpV9CFBm/xN8m/eUl07UcYXwCXlLJYXxhlQqI Pa/+Pam4IZke4lBYr7RqDym3Y0GoaJykDMXJ/YbFgMrOGwxjZuFHS4xfr c/vM+/+MdK3e8+vCgNWEaA4rz8lF8w7wNWNcCuibql7rdlYob9GYaCEhn 9xA6Sw9hzqzDMrRcd7ayPHNYwmC95AU0m51A7/1K5LrWjkPxahBaUq1WV Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342461" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342461" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917209" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:25 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 05/11] vfio: Introduce host_iommu_device_create callback Date: Wed, 28 Feb 2024 11:58:54 +0800 Message-Id: <20240228035900.1085727-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce host_iommu_device_create callback and a wrapper for it. This callback is used to allocate a host iommu device instance and initialize it based on type. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 1 + include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/common.c | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b6676c9f79..9fefea4b89 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -208,6 +208,7 @@ struct vfio_device_info *vfio_get_device_info(int fd); int vfio_attach_device(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void vfio_detach_device(VFIODevice *vbasedev); +void host_iommu_device_create(VFIODevice *vbasedev); int vfio_kvm_device_add_fd(int fd, Error **errp); int vfio_kvm_device_del_fd(int fd, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h index b2813b0c11..dc003f6eb2 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -120,6 +120,7 @@ struct VFIOIOMMUClass { int (*attach_device)(const char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); + void (*host_iommu_device_create)(VFIODevice *vbasedev); /* migration feature */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, bool start); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 059bfdc07a..41e9031c59 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1521,3 +1521,11 @@ void vfio_detach_device(VFIODevice *vbasedev) } vbasedev->bcontainer->ops->detach_device(vbasedev); } + +void host_iommu_device_create(VFIODevice *vbasedev) +{ + const VFIOIOMMUClass *ops = vbasedev->bcontainer->ops; + + assert(ops->host_iommu_device_create); + ops->host_iommu_device_create(vbasedev); +} From patchwork Wed Feb 28 03:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574834 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8C11C5478C for ; Wed, 28 Feb 2024 04:02:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8l-0005dv-Fu; Tue, 27 Feb 2024 23:01:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8j-0005Zr-I9 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:53 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8T-0000ub-Du for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092897; x=1740628897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=icy4H9M8PojAQrFizVqgsDbF6SyIjp2lAf7GphYLMq4=; b=fj4T5nydECroKgy7S2NRgRcFenwAp/AmD+QehXyeILPhiVWNNHCOJe+3 BZNvlSF9hwu9pRtVmL6XMnVAuVFxwJBNAk6VSI0uFzKf95hiCZqeYkhdH Sf9SiyajaQ5dMPunEVDDTbAGRhSChs6epXsUsvSBrRIFGWzg5OOR7ckAd W1tlWxhOtmtPO5uFMBF57F+AaBTAInyCWn+19XAf7C762QXaeb0I9h8Sj OPUFN5B6mJVBBTpPMeSuRKCH0z71Gay1pLKH+BC+daqMlUL2XFmT44ZpZ RfFbyvbjlVrUKubAuyPVpHMiepwyK+RdLt5m4XpZUbiGm1/lEcar5Jand w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342465" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342465" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917245" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:29 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 06/11] vfio/container: Implement host_iommu_device_create callback in legacy mode Date: Wed, 28 Feb 2024 11:58:55 +0800 Message-Id: <20240228035900.1085727-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This callback will be used to initialize base and public elements in IOMMULegacyDevice. Signed-off-by: Zhenzhong Duan --- hw/vfio/container.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index bd25b9fbad..2e8ff32284 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1120,6 +1120,14 @@ out_single: return ret; } +static void vfio_legacy_host_iommu_device_create(VFIODevice *vbasedev) +{ + vbasedev->base_hdev = g_malloc0(sizeof(IOMMULegacyDevice)); + + host_iommu_base_device_init(vbasedev->base_hdev, HID_LEGACY, + sizeof(IOMMULegacyDevice)); +} + static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data) { VFIOIOMMUClass *vioc = VFIO_IOMMU_CLASS(klass); @@ -1132,6 +1140,7 @@ static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data) vioc->set_dirty_page_tracking = vfio_legacy_set_dirty_page_tracking; vioc->query_dirty_bitmap = vfio_legacy_query_dirty_bitmap; vioc->pci_hot_reset = vfio_legacy_pci_hot_reset; + vioc->host_iommu_device_create = vfio_legacy_host_iommu_device_create; }; static const TypeInfo types[] = { From patchwork Wed Feb 28 03:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D3DBC47DD9 for ; Wed, 28 Feb 2024 04:02:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8c-0005YS-TS; Tue, 27 Feb 2024 23:01:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8c-0005YB-4F for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:46 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8W-0000uR-Rb for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092901; x=1740628901; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gw0hrQHuPDQ6mwD5brO8Q/qloWIq/kzw0hTCfTFA7Sk=; b=ell1CEno9laGypKzhEqnzStITvr1gxaB9ZNfRwLTQMvQp5YTj9YMvKrc OyG7nuOuyagjsheitckU3DUCBRevZ+oi+NLPuDiHcr+Hs/s5KwVH8TTvc hCvVu9oz16uhYLbvUGqXzWufSgE3F3Eu5I2UQAgRmDhX2rpH7DdOSaFbs Pq1ODAlNtGT7lfHwEQA7QqcWlr1x09hJaO1m6uOvsU4ZxpVj+9qr6RNoR 2bRsw/Q3A0gP0p9M8vYI8SHlgLUqnzpNMx4vdS/SbJQ/8CBic8J4p9Kcl zWfswn+KGDw6k464DsdhOpCJZ2p90+IkMkRzYoyqJ2JA3Z2bl/yd+DjD/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342473" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342473" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917267" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:33 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 07/11] vfio/iommufd: Implement host_iommu_device_create callback in iommufd mode Date: Wed, 28 Feb 2024 11:58:56 +0800 Message-Id: <20240228035900.1085727-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This callback will be used to initialize base and public elements in IOMMUFDDevice. Signed-off-by: Zhenzhong Duan --- hw/vfio/iommufd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 9bfddc1360..1c2f5da0d0 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -619,6 +619,15 @@ out_single: return ret; } +static void vfio_cdev_host_iommu_device_create(VFIODevice *vbasedev) +{ + IOMMUFDDevice *idev = g_malloc0(sizeof(IOMMUFDDevice)); + + vbasedev->base_hdev = &idev->base; + + iommufd_device_init(idev, vbasedev->iommufd, vbasedev->devid); +} + static void vfio_iommu_iommufd_class_init(ObjectClass *klass, void *data) { VFIOIOMMUClass *vioc = VFIO_IOMMU_CLASS(klass); @@ -628,6 +637,7 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *klass, void *data) vioc->attach_device = iommufd_cdev_attach; vioc->detach_device = iommufd_cdev_detach; vioc->pci_hot_reset = iommufd_cdev_pci_hot_reset; + vioc->host_iommu_device_create = vfio_cdev_host_iommu_device_create; }; static const TypeInfo types[] = { From patchwork Wed Feb 28 03:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2B36C47DD9 for ; Wed, 28 Feb 2024 04:02:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB8f-0005Z2-Jf; Tue, 27 Feb 2024 23:01:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8d-0005Yb-RF for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:47 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB8c-0000uR-En for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:01:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092907; x=1740628907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q7ZLZEg0dJgeXq8Fhcp4By04/sUyu5XmxNwoPYw8P94=; b=BdvHVTWjQHeWG0GVX1mD7lrQDbY8FOuw41Zk4CnuVlINE7yeOYrUkg8D dXTq0+bYBVNfO+3u9O6bjIRbACvl7DdtKJc51jXbI78ihlMi6lMc2fGZL vQvObzuOliLrkOh0um+9el2WsriZNKfc+A/4mH41HTjpW7DKYWaWE22nY FNQ/zC2BlwsNjrtPl+ICbwF/EHc/usM/RTIjrJVoJzMzaf8SDVEVmNmnb OFL3/MwmLuSHjUVK4K7uHCCyRmc2MclHrOFgPqnw4zSVtnO5h6MZWzAKU SFDamWtpy/QL3gqd5GTMc9qr/ev0vbAiO8uYEuR9aqu1ad6n1WasmNQcm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342478" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342478" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917296" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:38 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v1 08/11] vfio/pci: Allocate and initialize HostIOMMUDevice after attachment Date: Wed, 28 Feb 2024 11:58:57 +0800 Message-Id: <20240228035900.1085727-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Zhenzhong Duan --- hw/vfio/pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4fa387f043..6cc7de5d10 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3006,6 +3006,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) goto error; } + /* Allocate and initialize HostIOMMUDevice after attachment succeed */ + host_iommu_device_create(vbasedev); + vfio_populate_device(vdev, &err); if (err) { error_propagate(errp, err); @@ -3244,6 +3247,7 @@ static void vfio_instance_finalize(Object *obj) vfio_display_finalize(vdev); vfio_bars_finalize(vdev); + g_free(vdev->vbasedev.base_hdev); g_free(vdev->emulated_config_bits); g_free(vdev->rom); /* From patchwork Wed Feb 28 03:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEBACC54E51 for ; Wed, 28 Feb 2024 04:02:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB95-0006hd-F1; Tue, 27 Feb 2024 23:02:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB93-0006Ub-Ex for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:13 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB91-00010z-In for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092932; x=1740628932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/FZkjh4wFP1pCHMF/7JUAaS1bTgJi59ZJsmhOQ2lNpo=; b=RcTmPsew3xQ23WKvbGhutBx6LiOchN+nhYLSHCaF364MMcNST8A3unLD lOqsKej3zjqsBQzTLKh0Jkq59iNGvAmuFe3iVhFrL/Bxs6ltlq5pIrRc4 bnU7YPJ2qgZfQhCGNompt7getuvP7AnvJ0rVwH4xJNYBghcOoQnEl/cmv btT7y31Je01U8g6ZwFNviOsF1246us54mrnHTVkiggD12Q7acQwPWv801 qUbRj+/VxE6JuSxVxtWefcOm/VPLKvcgbBeE55P6AvtfiiaC4jKHMaz/H 0MxqFmKLS7xQaec7PkIZKds8cnPd/1SWNTP4AtHyJRnneaUXy2SLZK/2U g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342503" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342503" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917333" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:42 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum Subject: [PATCH v1 09/11] hw/pci: Introduce pci_device_set/unset_iommu_device() Date: Wed, 28 Feb 2024 11:58:58 +0800 Message-Id: <20240228035900.1085727-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Yi Liu This adds pci_device_set/unset_iommu_device() to set/unset HostIOMMUDevice for a given PCIe device. Caller of set should fail if set operation fails. Extract out pci_device_get_iommu_bus_devfn() to facilitate implementation of pci_device_set/unset_iommu_device(). Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Nicolin Chen Signed-off-by: Zhenzhong Duan --- include/hw/pci/pci.h | 38 ++++++++++++++++++++++++++- hw/pci/pci.c | 62 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index fa6313aabc..8fe6f746d7 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -3,6 +3,7 @@ #include "exec/memory.h" #include "sysemu/dma.h" +#include "sysemu/host_iommu_device.h" /* PCI includes legacy ISA access. */ #include "hw/isa/isa.h" @@ -384,10 +385,45 @@ typedef struct PCIIOMMUOps { * * @devfn: device and function number */ - AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int devfn); + AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int devfn); + /** + * @set_iommu_device: attach a HostIOMMUDevice to a vIOMMU + * + * Optional callback, if not implemented in vIOMMU, then vIOMMU can't + * retrieve host information from the associated HostIOMMUDevice. + * + * Return true if HostIOMMUDevice is attached, or else return false + * with errp set. + * + * @bus: the #PCIBus of the PCI device. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number of the PCI device. + * + * @dev: the data structure representing host IOMMU device. + * + */ + int (*set_iommu_device)(PCIBus *bus, void *opaque, int devfn, + HostIOMMUDevice *dev, Error **errp); + /** + * @unset_iommu_device: detach a HostIOMMUDevice from a vIOMMU + * + * Optional callback. + * + * @bus: the #PCIBus of the PCI device. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number of the PCI device. + */ + void (*unset_iommu_device)(PCIBus *bus, void *opaque, int devfn); } PCIIOMMUOps; AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); +int pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *base_dev, + Error **errp); +void pci_device_unset_iommu_device(PCIDevice *dev); /** * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 76080af580..8078307963 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2672,11 +2672,14 @@ static void pci_device_class_base_init(ObjectClass *klass, void *data) } } -AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) +static void pci_device_get_iommu_bus_devfn(PCIDevice *dev, + PCIBus **aliased_bus, + PCIBus **piommu_bus, + int *aliased_devfn) { PCIBus *bus = pci_get_bus(dev); PCIBus *iommu_bus = bus; - uint8_t devfn = dev->devfn; + int devfn = dev->devfn; while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) { PCIBus *parent_bus = pci_get_bus(iommu_bus->parent_dev); @@ -2717,13 +2720,66 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) iommu_bus = parent_bus; } - if (!pci_bus_bypass_iommu(bus) && iommu_bus->iommu_ops) { + + assert(0 <= devfn && devfn < PCI_DEVFN_MAX); + assert(iommu_bus); + + if (pci_bus_bypass_iommu(bus) || !iommu_bus->iommu_ops) { + iommu_bus = NULL; + } + + *piommu_bus = iommu_bus; + + if (aliased_bus) { + *aliased_bus = bus; + } + + if (aliased_devfn) { + *aliased_devfn = devfn; + } +} + +AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) +{ + PCIBus *bus; + PCIBus *iommu_bus; + int devfn; + + pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus, &devfn); + if (iommu_bus) { return iommu_bus->iommu_ops->get_address_space(bus, iommu_bus->iommu_opaque, devfn); } return &address_space_memory; } +int pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *base_dev, + Error **errp) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, NULL, &iommu_bus, 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_opaque, + dev->devfn, base_dev, + errp); + } + return 0; +} + +void pci_device_unset_iommu_device(PCIDevice *dev) +{ + PCIBus *iommu_bus; + + pci_device_get_iommu_bus_devfn(dev, NULL, &iommu_bus, 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_opaque, + dev->devfn); + } +} + void pci_setup_iommu(PCIBus *bus, const PCIIOMMUOps *ops, void *opaque) { /* From patchwork Wed Feb 28 03:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94A00C47DD9 for ; Wed, 28 Feb 2024 04:03:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB98-00078q-Rh; Tue, 27 Feb 2024 23:02:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB97-0006uh-0s for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:17 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB95-00010z-7X for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092935; x=1740628935; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G5emsBpzDoR9ENpp9MsafbIOfAuXfNSRmkIdZdtH4dw=; b=M37t1odFgGFfNZq6l44aFfwSgG7WH7Vv0Tyc370pU9rsPog2kIaoDi6C FeVuNq8RbNYhsXFy5c7jxFCcH5ZhbecgrZXG+M5Vf0vZwjYCDocx270lf cYPQwAsPuL9cD0t76T2zf2tUG9D40IlTHdjIDqEhs/b9Yh/CQxW7SqQKl VHuRSfAqEB94cFGOvA2K0UpGoKXnEJpgjlPz3wHehsjsY9J4+W+gRVAZe +lTVzLT+vowwDgdjahoS5tzimvpTsVHMAMMpkRSx/AVWdIa0SFIj/VoaS w6UywNeGM8vu9ES+24YGXVqhMeWboCIIVHFn0w2fAhtBGAFgminiXPOTB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342521" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342521" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917371" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:46 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v1 10/11] vfio: Pass HostIOMMUDevice to vIOMMU Date: Wed, 28 Feb 2024 11:58:59 +0800 Message-Id: <20240228035900.1085727-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Support both iommufd and legacy backend. Originally-by: Yi Liu Signed-off-by: Nicolin Chen Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/vfio/pci.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6cc7de5d10..ed9f386fde 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3112,11 +3112,17 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) vfio_bars_register(vdev); - ret = vfio_add_capabilities(vdev, errp); + ret = pci_device_set_iommu_device(pdev, vbasedev->base_hdev, errp); if (ret) { + error_prepend(errp, "Failed to set iommu_device: "); goto out_teardown; } + ret = vfio_add_capabilities(vdev, errp); + if (ret) { + goto out_unset_idev; + } + if (vdev->vga) { vfio_vga_quirk_setup(vdev); } @@ -3133,7 +3139,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) error_setg(errp, "cannot support IGD OpRegion feature on hotplugged " "device"); - goto out_teardown; + goto out_unset_idev; } ret = vfio_get_dev_region_info(vbasedev, @@ -3142,13 +3148,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) if (ret) { error_setg_errno(errp, -ret, "does not support requested IGD OpRegion feature"); - goto out_teardown; + goto out_unset_idev; } ret = vfio_pci_igd_opregion_init(vdev, opregion, errp); g_free(opregion); if (ret) { - goto out_teardown; + goto out_unset_idev; } } @@ -3234,6 +3240,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); @@ -3263,6 +3271,7 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev = VFIO_PCI(pdev); + VFIODevice *vbasedev = &vdev->vbasedev; vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); @@ -3277,7 +3286,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); } static void vfio_pci_reset(DeviceState *dev) From patchwork Wed Feb 28 03:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Duan, Zhenzhong" X-Patchwork-Id: 13574842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADF67C47DD9 for ; Wed, 28 Feb 2024 04:03:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfB9A-0007VV-JV; Tue, 27 Feb 2024 23:02:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB99-0007Gs-CQ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:19 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfB95-000117-Lc for qemu-devel@nongnu.org; Tue, 27 Feb 2024 23:02:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709092936; x=1740628936; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tgFCwv/7Yk27/h7/Nc9J58CONVxBSdPJewlTX/Yvjno=; b=VNRsSnZJnEEzgqF7iSobDmL4Adz6OTMh5yeKXV5qgD2VpAmepb06LRyH Q+HJtUmeBLjGvZfnHmG8xQy6q3O5Slqj2sn62G2LnCg/n9bo9m1puBGsg WvYdd3F1eZuAzdHoY31lNvml+R81K7ArUNxkz6c92lCREHJB/tEM607Ja Ua72hJSnbocniuwec/OCzN+tXCwwW5vHFps2ckv0Z9R19TMUAivBEnqOm gStRntY2ulKjfqwwkXEy3eQ4m8iWiDpGUo2PuBo8wUBaPaxbWtizZBQuP AwljU4WEK2wowMrebsahmhPIMg+VAobvyr+Cx5jU35K0NEMr8pTXU3Von Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3342531" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="3342531" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="11917386" Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 20:01:51 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, mst@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Sun Subject: [PATCH v1 11/11] backends/iommufd: Introduce helper function iommufd_device_get_info() Date: Wed, 28 Feb 2024 11:59:00 +0800 Message-Id: <20240228035900.1085727-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228035900.1085727-1-zhenzhong.duan@intel.com> References: <20240228035900.1085727-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.198.163.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce a helper function iommufd_device_get_info() to get host IOMMU related information through iommufd uAPI. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- include/sysemu/iommufd.h | 4 ++++ backends/iommufd.c | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index d509ff88ef..518b97bfed 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -4,6 +4,7 @@ #include "qom/object.h" #include "exec/hwaddr.h" #include "exec/cpu-common.h" +#include #include "sysemu/host_iommu_device.h" #define TYPE_IOMMUFD_BACKEND "iommufd" @@ -48,4 +49,7 @@ typedef struct IOMMUFDDevice { void iommufd_device_init(IOMMUFDDevice *idev, IOMMUFDBackend *iommufd, int devid); +int iommufd_device_get_info(IOMMUFDDevice *idev, + enum iommu_hw_info_type *type, + uint32_t len, void *data, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 6d280e4aea..69f3f75ea5 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -20,7 +20,6 @@ #include "monitor/monitor.h" #include "trace.h" #include -#include static void iommufd_backend_init(Object *obj) { @@ -240,3 +239,25 @@ void iommufd_device_init(IOMMUFDDevice *idev, idev->iommufd = iommufd; idev->devid = devid; } + +int iommufd_device_get_info(IOMMUFDDevice *idev, + enum iommu_hw_info_type *type, + uint32_t len, void *data, Error **errp) +{ + struct iommu_hw_info info = { + .size = sizeof(info), + .dev_id = idev->devid, + .data_len = len, + .data_uptr = (uintptr_t)data, + }; + int ret; + + ret = ioctl(idev->iommufd->fd, IOMMU_GET_HW_INFO, &info); + if (ret) { + error_setg_errno(errp, errno, "Failed to get hardware info"); + } else { + *type = info.out_data_type; + } + + return ret; +}