From nobody Tue Nov 26 20:12:03 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=1705313879; cv=none; d=zohomail.com; s=zohoarc; b=Wxquax7CQhQg+DJqjOhNWwsIvtRfeOGiqteVaAkMLTa9LF186mHvO1omqSAAJVW9NQfpthgwPG6kNk81Q8cEcxSOF8lJYuc/+hdn5aNc0RHloXg8ffYJnFOytMqp6iKlsHbIanFrorS9vNQ96EaliD/grGm5IqrKF3oSDhu0pGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705313879; 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=sl7+W6DObwpwUA4KvHbcUVHsXq6O5jhbpIncYqD5IMs=; b=kxmSMpgWV8mBmGzT+qMRSE2JuClo3AuswiiyTjPVkVdPiPJ+IH8PIb5HnunsDk2R+/JO8/eLrj8voFsLK5ZlAdgcXebKZ/v2QiWrwsGggQZGLyYgIy8OkOVtyfIVaOdnhMil7CMddadQaGtr9Was+Q6oTvwdiIPrcpk32eSfumU= 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 1705313879588594.2509437857786; Mon, 15 Jan 2024 02:17:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rPK1D-0007fe-2E; Mon, 15 Jan 2024 05:16:35 -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 1rPK1B-0007f9-0O for qemu-devel@nongnu.org; Mon, 15 Jan 2024 05:16:33 -0500 Received: from mgamail.intel.com ([134.134.136.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rPK18-0007OP-UM for qemu-devel@nongnu.org; Mon, 15 Jan 2024 05:16:32 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2024 02:16:28 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2024 02:16:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705313790; x=1736849790; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=17c0COtBuoW99QpVJLPDdLL1AX5u6nkzdn4+JzBln0w=; b=BpX91YLxIHofBHvyETRkLSSLTGYYX0RcZi6ppiHpQLT9KODBG+n/Y6Pi efos8Y3Y1IHBXWAA3A/AgmvDdcgUnvVXL7j8CP5mJOS9LqM1JKsuAuQfl mcxT3hnHjRZzSP3+ZSIcKVW9zGvSB+gk2kAc3WfTV3okZHNi/1PPpD2rJ /9zgRBApsZcGzZaiC6HmRi0PMRUtiSFoiJ3HU1uHDcT4XP8msGHlDGAeD T4UDIeU12IFR0w6CeXDG4l7GKLut/dowJkHS4gUe+/guXd6MCYDjvzfr6 YP/PqJ3sOYHDq6+VTx/lgLaF2eviB+nBCmj2ZBrKbymf8D3TUNsHEZJDX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="390032452" X-IronPort-AV: E=Sophos;i="6.04,196,1695711600"; d="scan'208";a="390032452" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="1030599485" X-IronPort-AV: E=Sophos;i="6.04,196,1695711600"; d="scan'208";a="1030599485" 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 rfcv1 1/6] backends/iommufd_device: introduce IOMMUFDDevice Date: Mon, 15 Jan 2024 18:13:08 +0800 Message-Id: <20240115101313.131139-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240115101313.131139-1-zhenzhong.duan@intel.com> References: <20240115101313.131139-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=134.134.136.20; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -71 X-Spam_score: -7.2 X-Spam_bar: ------- X-Spam_report: (-7.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.758, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1705313881260100007 Content-Type: text/plain; charset="utf-8" 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 iommufd handler and device id information which could be used by vIOMMU to get hw IOMMU information. In future nested translation support, vIOMMU is going to have more iommufd related operations like allocate hwpt for a device, attach/detach hwpt, etc. So IOMMUFDDevice will be further expanded. 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 --- MAINTAINERS | 4 +-- include/sysemu/iommufd_device.h | 31 ++++++++++++++++++++ backends/iommufd_device.c | 50 +++++++++++++++++++++++++++++++++ backends/meson.build | 2 +- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 include/sysemu/iommufd_device.h create mode 100644 backends/iommufd_device.c diff --git a/MAINTAINERS b/MAINTAINERS index 00ec1f7eca..606dfeb2b1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2171,8 +2171,8 @@ M: Yi Liu M: Eric Auger M: Zhenzhong Duan S: Supported -F: backends/iommufd.c -F: include/sysemu/iommufd.h +F: backends/iommufd*.c +F: include/sysemu/iommufd*.h F: include/qemu/chardev_open.h F: util/chardev_open.c F: docs/devel/vfio-iommufd.rst diff --git a/include/sysemu/iommufd_device.h b/include/sysemu/iommufd_devic= e.h new file mode 100644 index 0000000000..795630324b --- /dev/null +++ b/include/sysemu/iommufd_device.h @@ -0,0 +1,31 @@ +/* + * IOMMUFD Device + * + * Copyright (C) 2024 Intel Corporation. + * + * Authors: Yi Liu + * Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SYSEMU_IOMMUFD_DEVICE_H +#define SYSEMU_IOMMUFD_DEVICE_H + +#include +#include "sysemu/iommufd.h" + +typedef struct IOMMUFDDevice IOMMUFDDevice; + +/* This is an abstraction of host IOMMUFD device */ +struct IOMMUFDDevice { + IOMMUFDBackend *iommufd; + uint32_t dev_id; +}; + +int iommufd_device_get_info(IOMMUFDDevice *idev, + enum iommu_hw_info_type *type, + uint32_t len, void *data); +void iommufd_device_init(void *_idev, size_t instance_size, + IOMMUFDBackend *iommufd, uint32_t dev_id); +#endif diff --git a/backends/iommufd_device.c b/backends/iommufd_device.c new file mode 100644 index 0000000000..f6e7ca1dbf --- /dev/null +++ b/backends/iommufd_device.c @@ -0,0 +1,50 @@ +/* + * QEMU abstract of Host IOMMU + * + * Copyright (C) 2024 Intel Corporation. + * + * Authors: Yi Liu + * Zhenzhong Duan + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "sysemu/iommufd_device.h" + +int iommufd_device_get_info(IOMMUFDDevice *idev, + enum iommu_hw_info_type *type, + uint32_t len, void *data) +{ + struct iommu_hw_info info =3D { + .size =3D sizeof(info), + .flags =3D 0, + .dev_id =3D idev->dev_id, + .data_len =3D len, + .__reserved =3D 0, + .data_uptr =3D (uintptr_t)data, + }; + int ret; + + ret =3D ioctl(idev->iommufd->fd, IOMMU_GET_HW_INFO, &info); + if (ret) { + error_report("Failed to get info %m"); + } else { + *type =3D info.out_data_type; + } + + return ret; +} + +void iommufd_device_init(void *_idev, size_t instance_size, + IOMMUFDBackend *iommufd, uint32_t dev_id) +{ + IOMMUFDDevice *idev =3D (IOMMUFDDevice *)_idev; + + g_assert(sizeof(IOMMUFDDevice) <=3D instance_size); + + idev->iommufd =3D iommufd; + idev->dev_id =3D dev_id; +} diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..c437cdb363 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -24,7 +24,7 @@ if have_vhost_user system_ss.add(when: 'CONFIG_VIRTIO', if_true: files('vhost-user.c')) 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_IOMMUFD', if_true: files('iommufd.c', 'iommufd= _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