From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556480; cv=none; d=zohomail.com; s=zohoarc; b=dsP5TnlGwi4QpySwjKu3llAx+ivZ5OPp6wVL9Eoprfyd5A5AUeFigOLGX9k2CjIeR04Z+4TLJYPcTxyNHqqpHMKdqg8BD/OpeuSoKxHOh5+/3u9loca9HISyj1s9wJLeDKtBd+C6ZX+s2SME1lw63+wFloY8lKzXUp6pI44x1nI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556480; 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=vF+BG4uReMCvtZiHNDHGPuyNbzosknO7XM2v4CZUT2A=; b=hweoMvocTiGe9+V9Is8v//cOkTImhZxjDV8H5+zICa0tL3MLtL64jUz5LjZArmbvntp6v94iqid9pdFfnRGkoOG8g92HHsCAfBcwxnXhqnw+sSiUbgVkwT2TW0UBADFEcIUi4mQVp4ON/jFVyputKqPFh4hp1t81+4Z8e3uDOBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556480852464.0907709465084; Tue, 21 Nov 2023 00:48:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MOx-00062l-Rt; Tue, 21 Nov 2023 03:46: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 1r5MOp-00061s-Ld for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:30 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MOl-0001Oi-UL for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:26 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:22 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556383; x=1732092383; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WewTeaI8tc/Rg5FnOaTStpww5oM27/sYccRNsLxM7OM=; b=e3u9HLr4MOsOmNLps0PI+5VU8nx/JiOcDzcI+1A/v3ejFy4Lsiy2ntZM 1cZQGGFGIiI7JDfyfb7GM0ha7xj/Mexi9aep8Wxu0q+C+9I4F25H8IkV9 De8KUiJ9Ebl4i5fNWQssos9RQTaRNSsfQfuCgOGqscI+7zeU9WrJdqLnH tF/mQshAydN28zOaiNXKjmlQnx5Efhbb8qVY6upykh7CW1RfQQi2aBRIU uExNODjHAVPZ+G4DDGQrnaKExBdy3x7qfixgc89qLUgE4rBXZUx3QN4Rs P3PjXEMTbb5V06HgFiadtuMurZ3Iq5MK8tkNLELAYdBe5jvaakRdDFyzL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395721957" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395721957" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124823" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124823" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 01/27] backends/iommufd: Introduce the iommufd object Date: Tue, 21 Nov 2023 16:44:00 +0800 Message-Id: <20231121084426.1286987-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556482867100006 From: Eric Auger Introduce an iommufd object which allows the interaction with the host /dev/iommu device. The /dev/iommu can have been already pre-opened outside of qemu, in which case the fd can be passed directly along with the iommufd object: This allows the iommufd object to be shared accross several subsystems (VFIO, VDPA, ...). For example, libvirt would open the /dev/iommu once. If no fd is passed along with the iommufd object, the /dev/iommu is opened by the qemu code. Suggested-by: Alex Williamson Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Tested-by: Eric Auger Tested-by: Nicolin Chen --- MAINTAINERS | 8 ++ qapi/qom.json | 19 +++ include/sysemu/iommufd.h | 38 ++++++ backends/iommufd.c | 245 +++++++++++++++++++++++++++++++++++++++ backends/Kconfig | 4 + backends/meson.build | 1 + backends/trace-events | 10 ++ qemu-options.hx | 12 ++ 8 files changed, 337 insertions(+) create mode 100644 include/sysemu/iommufd.h create mode 100644 backends/iommufd.c diff --git a/MAINTAINERS b/MAINTAINERS index 695e0bd34f..a5a446914a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2167,6 +2167,14 @@ F: hw/vfio/ap.c F: docs/system/s390x/vfio-ap.rst L: qemu-s390x@nongnu.org =20 +iommufd +M: Yi Liu +M: Eric Auger +M: Zhenzhong Duan +S: Supported +F: backends/iommufd.c +F: include/sysemu/iommufd.h + vhost M: Michael S. Tsirkin S: Supported diff --git a/qapi/qom.json b/qapi/qom.json index c53ef978ff..95516ba325 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -794,6 +794,23 @@ { 'struct': 'VfioUserServerProperties', 'data': { 'socket': 'SocketAddress', 'device': 'str' } } =20 +## +# @IOMMUFDProperties: +# +# Properties for iommufd objects. +# +# @fd: file descriptor name previously passed via 'getfd' command, +# which represents a pre-opened /dev/iommu. This allows the +# iommufd object to be shared accross several subsystems +# (VFIO, VDPA, ...), and the file descriptor to be shared +# with other process, e.g. DPDK. (default: QEMU opens +# /dev/iommu by itself) +# +# Since: 9.0 +## +{ 'struct': 'IOMMUFDProperties', + 'data': { '*fd': 'str' } } + ## # @RngProperties: # @@ -934,6 +951,7 @@ 'input-barrier', { 'name': 'input-linux', 'if': 'CONFIG_LINUX' }, + 'iommufd', 'iothread', 'main-loop', { 'name': 'memory-backend-epc', @@ -1003,6 +1021,7 @@ 'input-barrier': 'InputBarrierProperties', 'input-linux': { 'type': 'InputLinuxProperties', 'if': 'CONFIG_LINUX' }, + 'iommufd': 'IOMMUFDProperties', 'iothread': 'IothreadProperties', 'main-loop': 'MainLoopProperties', 'memory-backend-epc': { 'type': 'MemoryBackendEpcProperties', diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h new file mode 100644 index 0000000000..9c5524b0ed --- /dev/null +++ b/include/sysemu/iommufd.h @@ -0,0 +1,38 @@ +#ifndef SYSEMU_IOMMUFD_H +#define SYSEMU_IOMMUFD_H + +#include "qom/object.h" +#include "qemu/thread.h" +#include "exec/hwaddr.h" +#include "exec/cpu-common.h" + +#define TYPE_IOMMUFD_BACKEND "iommufd" +OBJECT_DECLARE_TYPE(IOMMUFDBackend, IOMMUFDBackendClass, IOMMUFD_BACKEND) + +struct IOMMUFDBackendClass { + ObjectClass parent_class; +}; + +struct IOMMUFDBackend { + Object parent; + + /*< protected >*/ + int fd; /* /dev/iommu file descriptor */ + bool owned; /* is the /dev/iommu opened internally */ + QemuMutex lock; + uint32_t users; + + /*< public >*/ +}; + +int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); +void iommufd_backend_disconnect(IOMMUFDBackend *be); + +int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp); +void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); +int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr i= ova, + 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); +#endif diff --git a/backends/iommufd.c b/backends/iommufd.c new file mode 100644 index 0000000000..ba58a0eb0d --- /dev/null +++ b/backends/iommufd.c @@ -0,0 +1,245 @@ +/* + * iommufd container backend + * + * Copyright (C) 2023 Intel Corporation. + * Copyright Red Hat, Inc. 2023 + * + * Authors: Yi Liu + * Eric Auger + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "sysemu/iommufd.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" +#include "qemu/module.h" +#include "qom/object_interfaces.h" +#include "qemu/error-report.h" +#include "monitor/monitor.h" +#include "trace.h" +#include +#include + +static void iommufd_backend_init(Object *obj) +{ + IOMMUFDBackend *be =3D IOMMUFD_BACKEND(obj); + + be->fd =3D -1; + be->users =3D 0; + be->owned =3D true; + qemu_mutex_init(&be->lock); +} + +static void iommufd_backend_finalize(Object *obj) +{ + IOMMUFDBackend *be =3D IOMMUFD_BACKEND(obj); + + if (be->owned) { + close(be->fd); + be->fd =3D -1; + } +} + +static void iommufd_backend_set_fd(Object *obj, const char *str, Error **e= rrp) +{ + IOMMUFDBackend *be =3D IOMMUFD_BACKEND(obj); + int fd =3D -1; + + fd =3D monitor_fd_param(monitor_cur(), str, errp); + if (fd =3D=3D -1) { + error_prepend(errp, "Could not parse remote object fd %s:", str); + return; + } + qemu_mutex_lock(&be->lock); + be->fd =3D fd; + be->owned =3D false; + qemu_mutex_unlock(&be->lock); + trace_iommu_backend_set_fd(be->fd); +} + +static bool iommufd_backend_can_be_deleted(UserCreatable *uc) +{ + IOMMUFDBackend *be =3D IOMMUFD_BACKEND(uc); + + return !be->users; +} + +static void iommufd_backend_class_init(ObjectClass *oc, void *data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + + ucc->can_be_deleted =3D iommufd_backend_can_be_deleted; + + object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); +} + +int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) +{ + int fd, ret =3D 0; + + qemu_mutex_lock(&be->lock); + if (be->users =3D=3D UINT32_MAX) { + error_setg(errp, "too many connections"); + ret =3D -E2BIG; + goto out; + } + if (be->owned && !be->users) { + fd =3D qemu_open_old("/dev/iommu", O_RDWR); + if (fd < 0) { + error_setg_errno(errp, errno, "/dev/iommu opening failed"); + ret =3D fd; + goto out; + } + be->fd =3D fd; + } + be->users++; +out: + trace_iommufd_backend_connect(be->fd, be->owned, + be->users, ret); + qemu_mutex_unlock(&be->lock); + return ret; +} + +void iommufd_backend_disconnect(IOMMUFDBackend *be) +{ + qemu_mutex_lock(&be->lock); + if (!be->users) { + goto out; + } + be->users--; + if (!be->users && be->owned) { + close(be->fd); + be->fd =3D -1; + } +out: + trace_iommufd_backend_disconnect(be->fd, be->users); + qemu_mutex_unlock(&be->lock); +} + +int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp) +{ + int ret, fd =3D be->fd; + struct iommu_ioas_alloc alloc_data =3D { + .size =3D sizeof(alloc_data), + .flags =3D 0, + }; + + ret =3D ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data); + if (ret) { + error_setg_errno(errp, errno, "Failed to allocate ioas"); + return ret; + } + + *ioas_id =3D alloc_data.out_ioas_id; + trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret); + + return ret; +} + +void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id) +{ + int ret, fd =3D be->fd; + struct iommu_destroy des =3D { + .size =3D sizeof(des), + .id =3D id, + }; + + ret =3D ioctl(fd, IOMMU_DESTROY, &des); + trace_iommufd_backend_free_id(fd, id, ret); + if (ret) { + error_report("Failed to free id: %u %m", id); + } +} + +int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr i= ova, + ram_addr_t size, void *vaddr, bool readonly) +{ + int ret, fd =3D be->fd; + struct iommu_ioas_map map =3D { + .size =3D sizeof(map), + .flags =3D IOMMU_IOAS_MAP_READABLE | + IOMMU_IOAS_MAP_FIXED_IOVA, + .ioas_id =3D ioas_id, + .__reserved =3D 0, + .user_va =3D (uintptr_t)vaddr, + .iova =3D iova, + .length =3D size, + }; + + if (!readonly) { + map.flags |=3D IOMMU_IOAS_MAP_WRITEABLE; + } + + ret =3D ioctl(fd, IOMMU_IOAS_MAP, &map); + trace_iommufd_backend_map_dma(fd, ioas_id, iova, size, + vaddr, readonly, ret); + if (ret) { + ret =3D -errno; + + /* TODO: Not support mapping hardware PCI BAR region for now. */ + if (errno =3D=3D EFAULT) { + warn_report("IOMMU_IOAS_MAP failed: %m, PCI BAR?"); + } else { + error_report("IOMMU_IOAS_MAP failed: %m"); + } + } + return ret; +} + +int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, + hwaddr iova, ram_addr_t size) +{ + int ret, fd =3D be->fd; + struct iommu_ioas_unmap unmap =3D { + .size =3D sizeof(unmap), + .ioas_id =3D ioas_id, + .iova =3D iova, + .length =3D size, + }; + + ret =3D ioctl(fd, IOMMU_IOAS_UNMAP, &unmap); + /* + * IOMMUFD takes mapping as some kind of object, unmapping + * nonexistent mapping is treated as deleting a nonexistent + * object and return ENOENT. This is different from legacy + * backend which allows it. vIOMMU may trigger a lot of + * redundant unmapping, to avoid flush the log, treat them + * as succeess for IOMMUFD just like legacy backend. + */ + if (ret && errno =3D=3D ENOENT) { + trace_iommufd_backend_unmap_dma_non_exist(fd, ioas_id, iova, size,= ret); + ret =3D 0; + } else { + trace_iommufd_backend_unmap_dma(fd, ioas_id, iova, size, ret); + } + + if (ret) { + ret =3D -errno; + error_report("IOMMU_IOAS_UNMAP failed: %m"); + } + return ret; +} + +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 void register_types(void) +{ + type_register_static(&iommufd_backend_info); +} + +type_init(register_types); diff --git a/backends/Kconfig b/backends/Kconfig index f35abc1609..2cb23f62fa 100644 --- a/backends/Kconfig +++ b/backends/Kconfig @@ -1 +1,5 @@ source tpm/Kconfig + +config IOMMUFD + bool + depends on VFIO diff --git a/backends/meson.build b/backends/meson.build index 914c7c4afb..9a5cea480d 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -20,6 +20,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')) if have_vhost_user_crypto system_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('cryptodev-vh= ost-user.c')) endif diff --git a/backends/trace-events b/backends/trace-events index 652eb76a57..d45c6e31a6 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -5,3 +5,13 @@ dbus_vmstate_pre_save(void) dbus_vmstate_post_load(int version_id) "version_id: %d" dbus_vmstate_loading(const char *id) "id: %s" dbus_vmstate_saving(const char *id) "id: %s" + +# iommufd.c +iommufd_backend_connect(int fd, bool owned, uint32_t users, int ret) "fd= =3D%d owned=3D%d users=3D%d (%d)" +iommufd_backend_disconnect(int fd, uint32_t users) "fd=3D%d users=3D%d" +iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=3D%d" +iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_= t size, void *vaddr, bool readonly, int ret) " iommufd=3D%d ioas=3D%d iova= =3D0x%"PRIx64" size=3D0x%"PRIx64" addr=3D%p readonly=3D%d (%d)" +iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t i= ova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=3D%d ioas= =3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" (%d)" +iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint6= 4_t size, int ret) " iommufd=3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"P= RIx64" (%d)" +iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd= =3D%d ioas=3D%d (%d)" +iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" diff --git a/qemu-options.hx b/qemu-options.hx index 42fd09e4de..5fe8ea57d2 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5224,6 +5224,18 @@ SRST =20 The ``share`` boolean option is on by default with memfd. =20 + ``-object iommufd,id=3Did[,fd=3Dfd]`` + Creates an iommufd backend which allows control of DMA mapping + through the ``/dev/iommu`` device. + + The ``id`` parameter is a unique ID which frontends (such as + vfio-pci of vdpa) will use to connect with the iommufd backend. + + The ``fd`` parameter is an optional pre-opened file descriptor + resulting from ``/dev/iommu`` opening. Usually the iommufd is shar= ed + across all subsystems, bringing the benefit of centralized + reference counting. + ``-object rng-builtin,id=3Did`` Creates a random number generator backend which obtains entropy from QEMU builtin functions. The ``id`` parameter is a unique ID --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556446; cv=none; d=zohomail.com; s=zohoarc; b=C2v5jiO7745U0Xu/2Lu2YK90VRkxYevMKe9p0TaYUey4ffIRY6gRCIzjtPmzibx+Q3ytW41s1+w58+TLdsdLPxwBXty0zuYprOb16XtQxVw7wx0fuWlGQ38e1JxsG6uFDWO2pAlWPDtlyyazQ5ihbI5bjpsBJIcbq0XtSHYRR+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556446; 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=3UHPgKC+SMV4LJPG7b1NHUoM/gET5mUpZg09lQ9FQus=; b=C4uFrPP4TwbczZ5ibumjPgtjbH9Iom2gtEzGYwR7Hif2JJ/DLP3Z1NZxK42ZDby+/LX0VwugjaWVKp1b86NQ2jxjyyYzgBFkh5lByg/JcfS9L8qPfSCIP60VmW6Zq7C+pDQiam3yYhOvkA6ye1y5g23Yuvvlu9EHchAh53Y0x9k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556446651222.1366604667487; Tue, 21 Nov 2023 00:47:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MOx-00062u-SR; Tue, 21 Nov 2023 03:46: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 1r5MOr-00062C-MV for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:31 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MOo-0001Nv-Ic for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:29 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:25 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556386; x=1732092386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RIcSBZ7hnZdrg2FUYgRh4KwEi6LTS+5UThVVGneHQWA=; b=mMONYOvyLATasMSlupPBCOilc4EhFZGzDw4fs1ZTORGGPO57CLKGnDLG LOgFgejl2rK0ngnNQjaBw2UI8c+hUJPaglPQlpL4/om17P7iWCEFMxGzE kFIA89sz3M3FGeHvZOuzAdECuXdDWb65rnmF27hgYUcwPPoIkfpZ8+q2z dfzibueUn5H2sx7n9+QsEDepIIaZzgyBEHfqwKix10APPTfab7vhhYzNs B8wf3sOdmXdQar8Cg2fDnzpwRs5RjyKyCDYjZUm3ZSbYCTrC/SiR4rgi4 OWP7pYcACiLQKUn3Y/0TR58Z3cglsc03G/bMxM8V0OXN4a8+fFNXj3jSO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395721970" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395721970" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124836" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124836" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 02/27] util/char_dev: Add open_cdev() Date: Tue, 21 Nov 2023 16:44:01 +0800 Message-Id: <20231121084426.1286987-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556448207100007 From: Yi Liu /dev/vfio/devices/vfioX may not exist. In that case it is still possible to open /dev/char/$major:$minor instead. Add helper function to abstract the cdev open. Suggested-by: Jason Gunthorpe Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- MAINTAINERS | 2 + include/qemu/chardev_open.h | 16 ++++++++ util/chardev_open.c | 81 +++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 4 files changed, 100 insertions(+) create mode 100644 include/qemu/chardev_open.h create mode 100644 util/chardev_open.c diff --git a/MAINTAINERS b/MAINTAINERS index a5a446914a..ca70bb4e64 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2174,6 +2174,8 @@ M: Zhenzhong Duan S: Supported F: backends/iommufd.c F: include/sysemu/iommufd.h +F: include/qemu/chardev_open.h +F: util/chardev_open.c =20 vhost M: Michael S. Tsirkin diff --git a/include/qemu/chardev_open.h b/include/qemu/chardev_open.h new file mode 100644 index 0000000000..64e8fcfdcb --- /dev/null +++ b/include/qemu/chardev_open.h @@ -0,0 +1,16 @@ +/* + * QEMU Chardev Helper + * + * Copyright (C) 2023 Intel Corporation. + * + * Authors: Yi Liu + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef QEMU_CHARDEV_OPEN_H +#define QEMU_CHARDEV_OPEN_H + +int open_cdev(const char *devpath, dev_t cdev); +#endif diff --git a/util/chardev_open.c b/util/chardev_open.c new file mode 100644 index 0000000000..f776429788 --- /dev/null +++ b/util/chardev_open.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019, Mellanox Technologies. All rights reserved. + * Copyright (C) 2023 Intel Corporation. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: Yi Liu + * + * Copied from + * https://github.com/linux-rdma/rdma-core/blob/master/util/open_cdev.c + * + */ + +#include "qemu/osdep.h" +#include "qemu/chardev_open.h" + +static int open_cdev_internal(const char *path, dev_t cdev) +{ + struct stat st; + int fd; + + fd =3D qemu_open_old(path, O_RDWR); + if (fd =3D=3D -1) { + return -1; + } + if (fstat(fd, &st) || !S_ISCHR(st.st_mode) || + (cdev !=3D 0 && st.st_rdev !=3D cdev)) { + close(fd); + return -1; + } + return fd; +} + +static int open_cdev_robust(dev_t cdev) +{ + g_autofree char *devpath =3D NULL; + + /* + * This assumes that udev is being used and is creating the /dev/char/ + * symlinks. + */ + devpath =3D g_strdup_printf("/dev/char/%u:%u", major(cdev), minor(cdev= )); + return open_cdev_internal(devpath, cdev); +} + +int open_cdev(const char *devpath, dev_t cdev) +{ + int fd; + + fd =3D open_cdev_internal(devpath, cdev); + if (fd =3D=3D -1 && cdev !=3D 0) { + return open_cdev_robust(cdev); + } + return fd; +} diff --git a/util/meson.build b/util/meson.build index c2322ef6e7..174c133368 100644 --- a/util/meson.build +++ b/util/meson.build @@ -108,6 +108,7 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif util_ss.add(when: 'CONFIG_LINUX', if_true: files('vfio-helpers.c')) + util_ss.add(when: 'CONFIG_LINUX', if_true: files('chardev_open.c')) endif =20 if cpu =3D=3D 'aarch64' --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556492; cv=none; d=zohomail.com; s=zohoarc; b=gZ28ULTVSSe9m+sS5Ca/I43tx/KburTwrYiH+6odvX1HqWAm3mJSspNNk3+ygY95LAOrNcU6lbx+Kl4NKEbDh3S4DDBllNhDevH7tQJiVKa2Wol7NxlME2wXJ6cj3o1Idn0oPXjgJE/Iw8rIby4kzMtl5aUTyuNsqGNSjrC9vS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556492; 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=SsVydQUoKe2dxWBEqxzpHOMdNAbbjA+tSVL5MoOSGU4=; b=j3/AbUxJS7XJQdd72FgpivMuoHARTTEu+QVMbeoyWtQ8ozFXMeJkM19zyXmzct4W3RP0eLfHnh4n7eTf2iek3QQm4sJ3GZ4slvABSuKQLxEd8sGJuefvMa1wjMyNhJNNPVZ9yerxFEmQ8/o4PfaAGcwfn05jaKyuvzAjEmDYEGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17005564922091005.1202223227361; Tue, 21 Nov 2023 00:48:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MOz-00063M-Bx; Tue, 21 Nov 2023 03:46:37 -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 1r5MOv-00062b-BF for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:33 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MOt-0001Qo-0I for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:32 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:29 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:25 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556391; x=1732092391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z+wJpLKhgIS1v006pPPmVkqIUKj3EnkrkRZBjwby9FQ=; b=afFwo/m1Z8c0T6JW5+ZS8l0wD+9JbwVjwLxzbe+GH7AiarROx0ijqpPF pWFJI4dua6uIHbaEO4m/7sKk4/P8NcOAQ2CXC2sKwPYT7S1GeyJHr4u3d zzGQTjonmm7aWdlcU1YbNEymzz6St+xhWr8yL+oVWrg1dkhzHEKzxg1/4 +h748+CkpxsvhUIg3e1yPFVkdTAOTUkf8FcskGfuOT+Xe9UO3o8qUUGDM RGIGu5Ak1R/0YyFaGRhMzvtF8rEzdHjgLioS71oX6EtrLU+cnaAtjoBRK tG2m0mzKVqnwuIP5Li0zrIKtkWVxxIG905fb/wlB+Z2w3suuaPK6vaXQG g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395721990" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395721990" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124850" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124850" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 03/27] vfio/common: return early if space isn't empty Date: Tue, 21 Nov 2023 16:44:02 +0800 Message-Id: <20231121084426.1286987-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556493032100001 This is a trivial optimization. If there is active container in space, vfio_reset_handler will never be unregistered. So revert the check of space->containers and return early. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 572ae7c934..934f4f5446 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1462,10 +1462,13 @@ VFIOAddressSpace *vfio_get_address_space(AddressSpa= ce *as) =20 void vfio_put_address_space(VFIOAddressSpace *space) { - if (QLIST_EMPTY(&space->containers)) { - QLIST_REMOVE(space, list); - g_free(space); + if (!QLIST_EMPTY(&space->containers)) { + return; } + + QLIST_REMOVE(space, list); + g_free(space); + if (QLIST_EMPTY(&vfio_address_spaces)) { qemu_unregister_reset(vfio_reset_handler, NULL); } --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556562; cv=none; d=zohomail.com; s=zohoarc; b=VkT0P1HaaWgG1+5YWjcorxCdM2OBh35A/lvt7NoVGFsr7gaC8CZ8PGfOEa0DT7rnXLd41SVUfdVLOWKaltRw67GNx/fPBCyS1s3iAyiBT6CLqeVxxGyXLcvf643TwpcIeKIyT13U2j0axpSQ4fm5HalVgP5Taqf4x4bO2KOkp3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556562; 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=OmHleGdgF7avDeJ5XX8WWqx8gtq14B+1DpPkAG2P8/E=; b=bCRHqk7k595myLziuIvts2upAM0ZkAlcWJoJlYE3bveyzR+S8Q0C64+uZ01/8BlplLuiLLdpsawFKvC6fZxgbWzzuJl89pneUiSCAQ5tZVT25yk7uuXy7LfJItuHDkUzUGS/QKsnRUdAfxjyyhqduxwK+C4ruovbatiqjplbYwI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556562464836.8462462911158; Tue, 21 Nov 2023 00:49:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MP0-00063u-Fj; Tue, 21 Nov 2023 03:46: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 1r5MOy-000635-V6 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:36 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MOw-0001Qo-7o for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:36 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:33 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556394; x=1732092394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p+4Q0nAodIbFpCQ+8iGAWaRObnrunuoy8gK94tDCrw0=; b=DyfM8Ww5ifMNM3zpqpM+J5PvVJyj+NBZLVcUprt86K2CSNpEzk+i0lQc U+O0Zocj645dBZGFqOl0Ohf0jjsKQZqfV+oH0cNE7fE2CkRZO/0+0JJ3N RklqVvD99bHOUVASyk9Z74/GoT9zkU81AAhEN9Dkw0ts/K3vbJuwveXp3 duB5hIHyPIt12uxalBabFKezYC8Ca+gD9gr+jX4WFfTS91lafq3yoocCW HLYXFyg+kHvuPMNHTl25m9VVKZDU/Xn2JboJ6p+3dtE0ahBDUk8DDnfFc 409utj0kRRMrSpxmskf9mMxULHykZaA5F48crW6rNmlJ8ZsS1wvULE5dO Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722008" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722008" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124865" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124865" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 04/27] vfio/iommufd: Implement the iommufd backend Date: Tue, 21 Nov 2023 16:44:03 +0800 Message-Id: <20231121084426.1286987-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556562995100003 From: Yi Liu The iommufd backend is implemented based on the new /dev/iommu user API. This backend obviously depends on CONFIG_IOMMUFD. So far, the iommufd backend doesn't support dirty page sync yet. Co-authored-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Tested-by: Eric Auger Tested-by: Nicolin Chen --- include/hw/vfio/vfio-common.h | 11 + hw/vfio/common.c | 6 + hw/vfio/iommufd.c | 422 ++++++++++++++++++++++++++++++++++ hw/vfio/meson.build | 3 + hw/vfio/trace-events | 10 + 5 files changed, 452 insertions(+) create mode 100644 hw/vfio/iommufd.c diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 24ecc0e7ee..3dac5c167e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -89,6 +89,14 @@ typedef struct VFIOHostDMAWindow { QLIST_ENTRY(VFIOHostDMAWindow) hostwin_next; } VFIOHostDMAWindow; =20 +typedef struct IOMMUFDBackend IOMMUFDBackend; + +typedef struct VFIOIOMMUFDContainer { + VFIOContainerBase bcontainer; + IOMMUFDBackend *be; + uint32_t ioas_id; +} VFIOIOMMUFDContainer; + typedef struct VFIODeviceOps VFIODeviceOps; =20 typedef struct VFIODevice { @@ -116,6 +124,8 @@ typedef struct VFIODevice { OnOffAuto pre_copy_dirty_page_tracking; bool dirty_pages_supported; bool dirty_tracking; + int devid; + IOMMUFDBackend *iommufd; } VFIODevice; =20 struct VFIODeviceOps { @@ -201,6 +211,7 @@ typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODevi= ceList; extern VFIOGroupList vfio_group_list; extern VFIODeviceList vfio_device_list; extern const VFIOIOMMUOps vfio_legacy_ops; +extern const VFIOIOMMUOps vfio_iommufd_ops; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 934f4f5446..6569732b7a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #ifdef CONFIG_KVM #include @@ -1503,6 +1504,11 @@ int vfio_attach_device(char *name, VFIODevice *vbase= dev, { const VFIOIOMMUOps *ops =3D &vfio_legacy_ops; =20 +#ifdef CONFIG_IOMMUFD + if (vbasedev->iommufd) { + ops =3D &vfio_iommufd_ops; + } +#endif return ops->attach_device(name, vbasedev, as, errp); } =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c new file mode 100644 index 0000000000..6d31aeac7b --- /dev/null +++ b/hw/vfio/iommufd.c @@ -0,0 +1,422 @@ +/* + * iommufd container backend + * + * Copyright (C) 2023 Intel Corporation. + * Copyright Red Hat, Inc. 2023 + * + * Authors: Yi Liu + * Eric Auger + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include +#include +#include + +#include "hw/vfio/vfio-common.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "qapi/error.h" +#include "sysemu/iommufd.h" +#include "hw/qdev-core.h" +#include "sysemu/reset.h" +#include "qemu/cutils.h" +#include "qemu/chardev_open.h" + +static int iommufd_cdev_map(VFIOContainerBase *bcontainer, hwaddr iova, + ram_addr_t size, void *vaddr, bool readonly) +{ + VFIOIOMMUFDContainer *container =3D + container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); + + return iommufd_backend_map_dma(container->be, + container->ioas_id, + iova, size, vaddr, readonly); +} + +static int iommufd_cdev_unmap(VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) +{ + VFIOIOMMUFDContainer *container =3D + container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); + + /* TODO: Handle dma_unmap_bitmap with iotlb args (migration) */ + return iommufd_backend_unmap_dma(container->be, + container->ioas_id, iova, size); +} + +static int iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) +{ + return vfio_kvm_device_add_fd(vbasedev->fd, errp); +} + +static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev) +{ + Error *err =3D NULL; + + if (vfio_kvm_device_del_fd(vbasedev->fd, &err)) { + error_report_err(err); + } +} + +static int iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **err= p) +{ + IOMMUFDBackend *iommufd =3D vbasedev->iommufd; + struct vfio_device_bind_iommufd bind =3D { + .argsz =3D sizeof(bind), + .flags =3D 0, + }; + int ret; + + ret =3D iommufd_backend_connect(iommufd, errp); + if (ret) { + return ret; + } + + /* + * Add device to kvm-vfio to be prepared for the tracking + * in KVM. Especially for some emulated devices, it requires + * to have kvm information in the device open. + */ + ret =3D iommufd_cdev_kvm_device_add(vbasedev, errp); + if (ret) { + goto err_kvm_device_add; + } + + /* Bind device to iommufd */ + bind.iommufd =3D iommufd->fd; + ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind); + if (ret) { + error_setg_errno(errp, errno, "error bind device fd=3D%d to iommuf= d=3D%d", + vbasedev->fd, bind.iommufd); + goto err_bind; + } + + vbasedev->devid =3D bind.out_devid; + trace_iommufd_cdev_connect_and_bind(bind.iommufd, vbasedev->name, + vbasedev->fd, vbasedev->devid); + return ret; +err_bind: + iommufd_cdev_kvm_device_del(vbasedev); +err_kvm_device_add: + iommufd_backend_disconnect(iommufd); + return ret; +} + +static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev) +{ + /* Unbind is automatically conducted when device fd is closed */ + iommufd_cdev_kvm_device_del(vbasedev); + iommufd_backend_disconnect(vbasedev->iommufd); +} + +static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) +{ + long int ret =3D -ENOTTY; + char *path, *vfio_dev_path =3D NULL, *vfio_path =3D NULL; + DIR *dir =3D NULL; + struct dirent *dent; + gchar *contents; + struct stat st; + gsize length; + int major, minor; + dev_t vfio_devt; + + path =3D g_strdup_printf("%s/vfio-dev", sysfs_path); + if (stat(path, &st) < 0) { + error_setg_errno(errp, errno, "no such host device"); + goto out_free_path; + } + + dir =3D opendir(path); + if (!dir) { + error_setg_errno(errp, errno, "couldn't open directory %s", path); + goto out_free_path; + } + + while ((dent =3D readdir(dir))) { + if (!strncmp(dent->d_name, "vfio", 4)) { + vfio_dev_path =3D g_strdup_printf("%s/%s/dev", path, dent->d_n= ame); + break; + } + } + + if (!vfio_dev_path) { + error_setg(errp, "failed to find vfio-dev/vfioX/dev"); + goto out_close_dir; + } + + if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) { + error_setg(errp, "failed to load \"%s\"", vfio_dev_path); + goto out_free_dev_path; + } + + if (sscanf(contents, "%d:%d", &major, &minor) !=3D 2) { + error_setg(errp, "failed to get major:minor for \"%s\"", vfio_dev_= path); + goto out_free_dev_path; + } + g_free(contents); + vfio_devt =3D makedev(major, minor); + + vfio_path =3D g_strdup_printf("/dev/vfio/devices/%s", dent->d_name); + ret =3D open_cdev(vfio_path, vfio_devt); + if (ret < 0) { + error_setg(errp, "Failed to open %s", vfio_path); + } + + trace_iommufd_cdev_getfd(vfio_path, ret); + g_free(vfio_path); + +out_free_dev_path: + g_free(vfio_dev_path); +out_close_dir: + closedir(dir); +out_free_path: + if (*errp) { + error_prepend(errp, VFIO_MSG_PREFIX, path); + } + g_free(path); + + return ret; +} + +static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t id, + Error **errp) +{ + int ret, iommufd =3D vbasedev->iommufd->fd; + struct vfio_device_attach_iommufd_pt attach_data =3D { + .argsz =3D sizeof(attach_data), + .flags =3D 0, + .pt_id =3D id, + }; + + /* Attach device to an IOAS or hwpt within iommufd */ + ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_dat= a); + if (ret) { + error_setg_errno(errp, errno, + "[iommufd=3D%d] error attach %s (%d) to id=3D%d", + iommufd, vbasedev->name, vbasedev->fd, id); + } else { + trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, + vbasedev->fd, id); + } + return ret; +} + +static int iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **err= p) +{ + int ret, iommufd =3D vbasedev->iommufd->fd; + struct vfio_device_detach_iommufd_pt detach_data =3D { + .argsz =3D sizeof(detach_data), + .flags =3D 0, + }; + + ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_dat= a); + if (ret) { + error_setg_errno(errp, errno, "detach %s failed", vbasedev->name); + } else { + trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + } + return ret; +} + +static int iommufd_cdev_attach_container(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container, + Error **errp) +{ + return iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, err= p); +} + +static void iommufd_cdev_detach_container(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container) +{ + Error *err =3D NULL; + + if (iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { + error_report_err(err); + } +} + +static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + + if (!QLIST_EMPTY(&bcontainer->device_list)) { + return; + } + memory_listener_unregister(&bcontainer->listener); + vfio_container_destroy(bcontainer); + iommufd_backend_free_id(container->be, container->ioas_id); + g_free(container); +} + +static int iommufd_cdev_ram_block_discard_disable(bool state) +{ + /* + * We support coordinated discarding of RAM via the RamDiscardManager. + */ + return ram_block_uncoordinated_discard_disable(state); +} + +static int iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) +{ + VFIOContainerBase *bcontainer; + VFIOIOMMUFDContainer *container; + VFIOAddressSpace *space; + struct vfio_device_info dev_info =3D { .argsz =3D sizeof(dev_info) }; + int ret, devfd; + uint32_t ioas_id; + Error *err =3D NULL; + + devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); + if (devfd < 0) { + return devfd; + } + vbasedev->fd =3D devfd; + + ret =3D iommufd_cdev_connect_and_bind(vbasedev, errp); + if (ret) { + goto err_connect_bind; + } + + space =3D vfio_get_address_space(as); + + /* try to attach to an existing container in this space */ + QLIST_FOREACH(bcontainer, &space->containers, next) { + container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcont= ainer); + if (bcontainer->ops !=3D &vfio_iommufd_ops || + vbasedev->iommufd !=3D container->be) { + continue; + } + if (iommufd_cdev_attach_container(vbasedev, container, &err)) { + const char *msg =3D error_get_pretty(err); + + trace_iommufd_cdev_fail_attach_existing_container(msg); + error_free(err); + err =3D NULL; + } else { + ret =3D iommufd_cdev_ram_block_discard_disable(true); + if (ret) { + error_setg(errp, + "Cannot set discarding of RAM broken (%d)", = ret); + goto err_discard_disable; + } + goto found_container; + } + } + + /* Need to allocate a new dedicated container */ + ret =3D iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp); + if (ret < 0) { + goto err_alloc_ioas; + } + + trace_iommufd_cdev_alloc_ioas(vbasedev->iommufd->fd, ioas_id); + + container =3D g_malloc0(sizeof(*container)); + container->be =3D vbasedev->iommufd; + container->ioas_id =3D ioas_id; + + bcontainer =3D &container->bcontainer; + vfio_container_init(bcontainer, space, &vfio_iommufd_ops); + QLIST_INSERT_HEAD(&space->containers, bcontainer, next); + + ret =3D iommufd_cdev_attach_container(vbasedev, container, errp); + if (ret) { + goto err_attach_container; + } + + ret =3D iommufd_cdev_ram_block_discard_disable(true); + if (ret) { + goto err_discard_disable; + } + + bcontainer->pgsizes =3D qemu_real_host_page_size(); + + bcontainer->listener =3D vfio_memory_listener; + memory_listener_register(&bcontainer->listener, bcontainer->space->as); + + if (bcontainer->error) { + ret =3D -1; + error_propagate_prepend(errp, bcontainer->error, + "memory listener initialization failed: "); + goto err_listener_register; + } + + bcontainer->initialized =3D true; + +found_container: + ret =3D ioctl(devfd, VFIO_DEVICE_GET_INFO, &dev_info); + if (ret) { + error_setg_errno(errp, errno, "error getting device info"); + goto err_listener_register; + } + + /* + * TODO: examine RAM_BLOCK_DISCARD stuff, should we do group level + * for discarding incompatibility check as well? + */ + if (vbasedev->ram_block_discard_allowed) { + iommufd_cdev_ram_block_discard_disable(false); + } + + vbasedev->group =3D 0; + vbasedev->num_irqs =3D dev_info.num_irqs; + vbasedev->num_regions =3D dev_info.num_regions; + vbasedev->flags =3D dev_info.flags; + vbasedev->reset_works =3D !!(dev_info.flags & VFIO_DEVICE_FLAGS_RESET); + vbasedev->bcontainer =3D bcontainer; + QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); + QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); + + trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, + vbasedev->num_regions, vbasedev->flags); + return 0; + +err_listener_register: + iommufd_cdev_ram_block_discard_disable(false); +err_discard_disable: + iommufd_cdev_detach_container(vbasedev, container); +err_attach_container: + iommufd_cdev_container_destroy(container); +err_alloc_ioas: + vfio_put_address_space(space); + iommufd_cdev_unbind_and_disconnect(vbasedev); +err_connect_bind: + close(vbasedev->fd); + return ret; +} + +static void iommufd_cdev_detach(VFIODevice *vbasedev) +{ + VFIOContainerBase *bcontainer =3D vbasedev->bcontainer; + VFIOAddressSpace *space =3D bcontainer->space; + VFIOIOMMUFDContainer *container =3D container_of(bcontainer, + VFIOIOMMUFDContainer, + bcontainer); + QLIST_REMOVE(vbasedev, global_next); + QLIST_REMOVE(vbasedev, container_next); + vbasedev->bcontainer =3D NULL; + + if (!vbasedev->ram_block_discard_allowed) { + iommufd_cdev_ram_block_discard_disable(false); + } + + iommufd_cdev_detach_container(vbasedev, container); + iommufd_cdev_container_destroy(container); + vfio_put_address_space(space); + + iommufd_cdev_unbind_and_disconnect(vbasedev); + close(vbasedev->fd); +} + +const VFIOIOMMUOps vfio_iommufd_ops =3D { + .dma_map =3D iommufd_cdev_map, + .dma_unmap =3D iommufd_cdev_unmap, + .attach_device =3D iommufd_cdev_attach, + .detach_device =3D iommufd_cdev_detach, +}; diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build index eb6ce6229d..e5d98b6adc 100644 --- a/hw/vfio/meson.build +++ b/hw/vfio/meson.build @@ -7,6 +7,9 @@ vfio_ss.add(files( 'spapr.c', 'migration.c', )) +vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files( + 'iommufd.c', +)) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c', 'pci-quirks.c', diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 08a1f9dfa4..3340c93af0 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -164,3 +164,13 @@ vfio_state_pending_estimate(const char *name, uint64_t= precopy, uint64_t postcop vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t post= copy, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_= dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0= x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 vfio_vmstate_change(const char *name, int running, const char *reason, con= st char *dev_state) " (%s) running %d reason %s device state %s" vfio_vmstate_change_prepare(const char *name, int running, const char *rea= son, const char *dev_state) " (%s) running %d reason %s device state %s" + +#iommufd.c + +iommufd_cdev_connect_and_bind(int iommufd, const char *name, int devfd, in= t devid) " [iommufd=3D%d] Successfully bound device %s (fd=3D%d): output de= vid=3D%d" +iommufd_cdev_getfd(const char *dev, int devfd) " %s (fd=3D%d)" +iommufd_cdev_attach_ioas_hwpt(int iommufd, const char *name, int devfd, in= t id) " [iommufd=3D%d] Successfully attached device %s (%d) to id=3D%d" +iommufd_cdev_detach_ioas_hwpt(int iommufd, const char *name) " [iommufd=3D= %d] Successfully detached %s" +iommufd_cdev_fail_attach_existing_container(const char *msg) " %s" +iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=3D%d] new IOM= MUFD container with ioasid=3D%d" +iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regi= ons, int flags) " %s (%d) num_irqs=3D%d num_regions=3D%d flags=3D%d" --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556567; cv=none; d=zohomail.com; s=zohoarc; b=QQfiKUWQGsOhQ3sUCyQHGB4yWdAHDkXbWXUWBybiBIKNhAUolvEM6AeRi4vD6CCgc/d7pS3mzMrC7oO53LKuz0NSlewlCqc0oGk2z871qgtvtZA6ajwUIhe348YVdR/V8mBjfihEwDrRs0L5TrImIVNouC9PyDTTQhuKTpocDQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556567; 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=fqHKk0b4ZWTthufLu56IIEIH7rbI++2UpDb9I3XyMM0=; b=Hj0CKepNm2yjc0VIOqwE4dLoqLeFX0hQZFjh58Se5wVpP4FTERmtRsp1xmRY5666vfCH/0D+NYWQXAX3MB2DJ+0u4eT0nNCYHDoEy/6tB3nMTe/2PDHgyPY8NAzSLilB3u3RchhGaMBmF0d4U9aza8UG+pKvFgQPelv2iXky+Og= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556567896165.2266121346812; Tue, 21 Nov 2023 00:49:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MP3-00064q-1b; Tue, 21 Nov 2023 03:46:41 -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 1r5MP2-00064f-08 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:40 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MP0-0001Qo-Cu for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:39 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:37 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556398; x=1732092398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GB2wT+bF18h6O66WxNQkH6AVmyasMVqzPc1b9COIOfU=; b=jj33+jjr1l3TFZRpOEs6iKzPK2zVBcMzJs4146n5zeMn4Ukev4aU649M ond5vp+bXCpwjyjA5eSP2SliPVR/2hdWcwgxDeCGty3ZEK+n98NUGdOAY u/kE8E0FVSppCDcLypm0VjCpTmULoq7bn7Kuu4wW3ciA2E6N7xZV75Kod QtWP8nau8ItJj1NwfazycEz1ehrV+seOIwjcGbaAM3ChxMkrKuhuRVpI2 1A5OsDodmyF/qcuYVfwOHoPWS3rZ4B/YitqvweDKYT1UruwlJl2797yJ2 NbQFekasi9sXzBky6Wg85wJSh3R4M2wYUJUPRo8snaa8FOSaNvm0vJuz5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722026" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722026" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124874" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124874" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 05/27] vfio/iommufd: Relax assert check for iommufd backend Date: Tue, 21 Nov 2023 16:44:04 +0800 Message-Id: <20231121084426.1286987-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556569098100005 Currently iommufd doesn't support dirty page sync yet, but it will not block us doing live migration if VFIO migration is force enabled. So in this case we allow set_dirty_page_tracking to be NULL. Note we don't need same change for query_dirty_bitmap because when dirty page sync isn't supported, query_dirty_bitmap will never be called. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/container-base.c | 4 ++++ hw/vfio/container.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 71f7274973..eee2dcfe76 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -55,6 +55,10 @@ void vfio_container_del_section_window(VFIOContainerBase= *bcontainer, int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start) { + if (!bcontainer->dirty_pages_supported) { + return 0; + } + g_assert(bcontainer->ops->set_dirty_page_tracking); return bcontainer->ops->set_dirty_page_tracking(bcontainer, start); } diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 6bacf38222..ed2d721b2b 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -216,10 +216,6 @@ static int vfio_legacy_set_dirty_page_tracking(VFIOCon= tainerBase *bcontainer, .argsz =3D sizeof(dirty), }; =20 - if (!bcontainer->dirty_pages_supported) { - return 0; - } - if (start) { dirty.flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_START; } else { --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556480; cv=none; d=zohomail.com; s=zohoarc; b=LJdc2M4f0G7E5tobrRqimA+JwqgLeuawXKFa24VB3jjkErV/5fsvgL3zOPkvidEYnRbBXGSLF/yMW5qy9YGC+M4CgjlxwXZnDRPNy11Ojg0RpoKr3UYWkSNAIZhjkRoPElJaVWNqdQgrHf+sj1N2Ca5fv2OZweIBItbxLmBlCQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556480; 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=ER+FJsK8GZnRjAqDyvRKIiV5uzGCyajZdhiQPQGbQ64=; b=PtQU0bH6zoX/S+mju5un9QCqgvszfaGEeI6GlGL4gV4FII3kP4ozlfYfbRDZriCAslgUUjLSEZyUYhz3h2cEY1x/M3trprJrpwqSaCjW6hoS+GEpkN6wdiQisyWJ29izK2mNnCCaF6nv+rrUnPwKjHmFO7TRsyl6QRKHccznlQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556480733317.9599000174553; Tue, 21 Nov 2023 00:48:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MP7-00065X-RG; Tue, 21 Nov 2023 03:46:45 -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 1r5MP5-00065F-Kc for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:43 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MP3-0001Qo-TI for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:43 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:41 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556401; x=1732092401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uw7DnlmdMZPLbQL7qWgqiELopkS8trDa/dLDZoi3etc=; b=OrbcSvY3b9LK4Gl0H0hiSqnbLJyqsmupwfs3GlDR/KJ3XP622gaGiW8q 6aoBWdM7K8g5yho6gCUfngED/jXgntjTaomDL0kQKmf3LJXpeM3kUaftP 29cDEz+y/NRKqO7LkMvgFl4jXe8DLmoYPYpmY8ItqBHv+NHZpAfSOJPYf zT4NLM2CSZ7R3w62Btq/3b5ZgGHLuofg5HgnHAxpxAKIpQYzBOO9Oo+Mx wh34RCyU4ASrmj88mXcRTnir0X5OmjuVk3VYCkgFhvEzgMVGteLF37dJ/ o9KvWeNKx5viH8rh2qgAkg/ZvEuF4qYZciA28QnFy7jHXPW7BOsSBUhWC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722046" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722046" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124886" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124886" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 06/27] vfio/iommufd: Add support for iova_ranges and pgsizes Date: Tue, 21 Nov 2023 16:44:05 +0800 Message-Id: <20231121084426.1286987-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556482838100005 Some vIOMMU such as virtio-iommu use IOVA ranges from host side to setup reserved ranges for passthrough device, so that guest will not use an IOVA range beyond host support. Use an uAPI of IOMMUFD to get IOVA ranges of host side and pass to vIOMMU just like the legacy backend, if this fails, fallback to 64bit IOVA range. Also use out_iova_alignment returned from uAPI as pgsizes instead of qemu_real_host_page_size() as a fallback. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/iommufd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 6d31aeac7b..01b448e840 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -261,6 +261,53 @@ static int iommufd_cdev_ram_block_discard_disable(bool= state) return ram_block_uncoordinated_discard_disable(state); } =20 +static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *containe= r, + uint32_t ioas_id, Error **errp) +{ + VFIOContainerBase *bcontainer =3D &container->bcontainer; + struct iommu_ioas_iova_ranges *info; + struct iommu_iova_range *iova_ranges; + int ret, sz, fd =3D container->be->fd; + + info =3D g_malloc0(sizeof(*info)); + info->size =3D sizeof(*info); + info->ioas_id =3D ioas_id; + + ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); + if (ret && errno !=3D EMSGSIZE) { + goto error; + } + + sz =3D info->num_iovas * sizeof(struct iommu_iova_range); + info =3D g_realloc(info, sizeof(*info) + sz); + info->allowed_iovas =3D (uintptr_t)(info + 1); + + ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); + if (ret) { + goto error; + } + + iova_ranges =3D (struct iommu_iova_range *)(uintptr_t)info->allowed_io= vas; + + for (int i =3D 0; i < info->num_iovas; i++) { + Range *range =3D g_new(Range, 1); + + range_set_bounds(range, iova_ranges[i].start, iova_ranges[i].last); + bcontainer->iova_ranges =3D + range_list_insert(bcontainer->iova_ranges, range); + } + bcontainer->pgsizes =3D info->out_iova_alignment; + + g_free(info); + return 0; + +error: + ret =3D -errno; + g_free(info); + error_setg_errno(errp, errno, "Cannot get IOVA ranges"); + return ret; +} + static int iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp) { @@ -335,7 +382,14 @@ static int iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, goto err_discard_disable; } =20 - bcontainer->pgsizes =3D qemu_real_host_page_size(); + ret =3D iommufd_cdev_get_info_iova_range(container, ioas_id, &err); + if (ret) { + error_append_hint(&err, + "Fallback to default 64bit IOVA range and 4K page size\= n"); + warn_report_err(err); + err =3D NULL; + bcontainer->pgsizes =3D qemu_real_host_page_size(); + } =20 bcontainer->listener =3D vfio_memory_listener; memory_listener_register(&bcontainer->listener, bcontainer->space->as); --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556502; cv=none; d=zohomail.com; s=zohoarc; b=HGHjntFW2oBC5P7DJ63eTSgVg1pzSKXtJ/oIzeUwRscOH7k4YsuOCNMU3lySjm5hqCZKY1vreqI9tSARP+XciJxNc6nu5Q0M/lrxACqrhfHpmKMtYOIhG0w3Z36Z0hGq1SFetM8BGupWwewbKXHJfhO7xcWu+Oj4GATVhEmt5fk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556502; 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=bBEoElvuYnH6q0PjqKN39vFl0/H0FBlLWmpFhakXqT8=; b=llt/X2cyfdaVupgKbX2ohOPxYWdySQ25rn0U1FGDorTmH3NAoSdE6+X3Oy1zbSv7dR9/32/nFrHjacI/y2nGJiMfnEb/iSojsjNa0zQ9wzN+EFKq6+P+Um7MfYImmxIkP7iHTVGw3arYSs3cGsR4PmTL7u/bWDw719wrronwo+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556502845556.0523390554091; Tue, 21 Nov 2023 00:48:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPC-000669-4h; Tue, 21 Nov 2023 03:46:50 -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 1r5MPA-00065s-4w for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:48 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MP8-0001Qo-BG for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:47 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:44 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556406; x=1732092406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1iSGJzqaij9umCCLXF5dT+WsPF2Bb5NP0jCh7b7Rxsk=; b=eJor/d07cpSk27yghIEjMP0/rX/l42fhdxLkRPNGViU7IoL1OTmYhuiO nKyZiUR9PPxV1VZGn10uR2BzTfsZUw4lZA5W55UGY+1FR3oAw4TinuXl2 T8TH3vF+AOxLm5CYfPrGonE1rd/CGGfP7cq/HJ6EO9FVNeLVS/GAXUl2k RCDU2Mja/UvpITcYXPQGr1huySCbD4wLF9POHYaHCOMH23tGLjwGymlKm MTljz8DwGL9b0M4Hu0DHaHvHWj30CIM72zMr+I6GqzHnI/9UyoS0dSTv1 3vAXFFGSyLqsQTa4ooRxoawwluDDT6LLnTRh/qn1+NyYAiHe/htImtIK7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722065" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722065" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124897" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124897" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 07/27] vfio/pci: Extract out a helper vfio_pci_get_pci_hot_reset_info Date: Tue, 21 Nov 2023 16:44:06 +0800 Message-Id: <20231121084426.1286987-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556503432100001 This helper will be used by both legacy and iommufd backends. No functional changes intended. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/pci.h | 3 +++ hw/vfio/pci.c | 54 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index fba8737ab2..1006061afb 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -218,6 +218,9 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 +int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **info_= p); + int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c62c02f7b6..eb55e8ae88 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2445,22 +2445,13 @@ static bool vfio_pci_host_match(PCIHostDeviceAddres= s *addr, const char *name) return (strcmp(tmp, name) =3D=3D 0); } =20 -static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) +int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, + struct vfio_pci_hot_reset_info **info_= p) { - VFIOGroup *group; struct vfio_pci_hot_reset_info *info; - struct vfio_pci_dependent_device *devices; - struct vfio_pci_hot_reset *reset; - int32_t *fds; - int ret, i, count; - bool multi =3D false; + int ret, count; =20 - trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); - - if (!single) { - vfio_pci_pre_reset(vdev); - } - vdev->vbasedev.needs_reset =3D false; + assert(info_p && !*info_p); =20 info =3D g_malloc0(sizeof(*info)); info->argsz =3D sizeof(*info); @@ -2468,24 +2459,53 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, = bool single) ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, i= nfo); if (ret && errno !=3D ENOSPC) { ret =3D -errno; + g_free(info); if (!vdev->has_pm_reset) { error_report("vfio: Cannot reset device %s, " "no available reset mechanism.", vdev->vbasedev.n= ame); } - goto out_single; + return ret; } =20 count =3D info->count; - info =3D g_realloc(info, sizeof(*info) + (count * sizeof(*devices))); - info->argsz =3D sizeof(*info) + (count * sizeof(*devices)); - devices =3D &info->devices[0]; + info =3D g_realloc(info, sizeof(*info) + (count * sizeof(info->devices= [0]))); + info->argsz =3D sizeof(*info) + (count * sizeof(info->devices[0])); =20 ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, i= nfo); if (ret) { ret =3D -errno; + g_free(info); error_report("vfio: hot reset info failed: %m"); + return ret; + } + + *info_p =3D info; + return 0; +} + +static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) +{ + VFIOGroup *group; + struct vfio_pci_hot_reset_info *info =3D NULL; + struct vfio_pci_dependent_device *devices; + struct vfio_pci_hot_reset *reset; + int32_t *fds; + int ret, i, count; + bool multi =3D false; + + trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); + + if (!single) { + vfio_pci_pre_reset(vdev); + } + vdev->vbasedev.needs_reset =3D false; + + ret =3D vfio_pci_get_pci_hot_reset_info(vdev, &info); + + if (ret) { goto out_single; } + devices =3D &info->devices[0]; =20 trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556446; cv=none; d=zohomail.com; s=zohoarc; b=GSos27oYqffHBTiDhCzIEyDf3A4GKEc7YQAndapo+oidNJu1lTpSQuDKX6gGYA4euayEN0vdPFK+T5n+ADGDF4/EPVeEAuK2lVJC8wtxsDSo5OBMqEST5IpTWKUqr3ifv8ZffvVKp07t8oCm5gvXCOSGdixmshhr17hPv8IVau8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556446; 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=xMn3vg2sG7uQMJaHHvnTsV8oZKQJsZyV6ygJeZJSr2M=; b=Zo+JQ3zHij2qaOd8ohorW1qXpYJuHikimCPFA67Zs+FxXwW0cHR2rGvBGuFB51ekSCFTWN2dfe8xSjDsUrfo5hjV0S0CetCRjYMVqY+X9+4Rer+kw5zg/CRoiEk6+GjgPIdphfrio2EjFHRz9QJyQtGbbEmUfcnuNUCgEio2nsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556446714241.51891377732557; Tue, 21 Nov 2023 00:47:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPF-00066d-H1; Tue, 21 Nov 2023 03:46:53 -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 1r5MPE-00066S-74 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:52 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPB-0001Qo-LA for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:51 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:48 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:45 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556409; x=1732092409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UNas8XAavess8nltGjqiy+ekcAqAWzf1KSGBBlwm46k=; b=X/b/3d+tSRpD/xFY2saIxr4tp7wbQpViz+G1TfsujqC56UqJlOSsfrSq 47norjBaKpz05CiEyfgJu0/bpglDrVZFjTEDPVYzJO9GPBGEjvPWFAzjy JB6N22XLIx8SK2PeCIw4JXCh/fbpx1aPBNo+Aelo5PKRyC2iYhMMqrR/y DAlNw/1Ov0bXhGLXPIpHozllDa/jE/qXbap8OeBTr6jYRlmkxt6gAUgvt TbgL6YMBtOIl/HUm8drmMT9JJoEYlnj3w/v7tGxNqw80uzf/i6zDDApye 0jqfwoZXvZ19g+giM1Wdg3FDY/OnXwcAk+0avFXJLM6ZdzAMg1l2R38JB g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722084" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722084" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124907" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124907" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 08/27] vfio/pci: Introduce a vfio pci hot reset interface Date: Tue, 21 Nov 2023 16:44:07 +0800 Message-Id: <20231121084426.1286987-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556448238100009 Legacy vfio pci and iommufd cdev have different process to hot reset vfio device, expand current code to abstract out pci_hot_reset callback for legacy vfio, this same interface will also be used by iommufd cdev vfio device. Rename vfio_pci_hot_reset to vfio_legacy_pci_hot_reset and move it into container.c. vfio_pci_[pre/post]_reset and vfio_pci_host_match are exported so they could be called in legacy and iommufd pci_hot_reset callback. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/pci.h | 3 + include/hw/vfio/vfio-container-base.h | 3 + hw/vfio/container.c | 170 ++++++++++++++++++++++++++ hw/vfio/pci.c | 168 +------------------------ 4 files changed, 182 insertions(+), 162 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 1006061afb..6e64a2654e 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -218,6 +218,9 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr); =20 extern const PropertyInfo qdev_prop_nv_gpudirect_clique; =20 +void vfio_pci_pre_reset(VFIOPCIDevice *vdev); +void vfio_pci_post_reset(VFIOPCIDevice *vdev); +bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name); int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, struct vfio_pci_hot_reset_info **info_= p); =20 diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 4b6f017c6f..45bb19c767 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -106,6 +106,9 @@ struct VFIOIOMMUOps { int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool sta= rt); int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *v= bmap, hwaddr iova, hwaddr size); + /* PCI specific */ + int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); + /* SPAPR specific */ int (*add_window)(VFIOContainerBase *bcontainer, MemoryRegionSection *section, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index ed2d721b2b..1dbf9b9a17 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -33,6 +33,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/migration.h" +#include "pci.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -922,6 +923,174 @@ static void vfio_legacy_detach_device(VFIODevice *vba= sedev) vfio_put_group(group); } =20 +static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + VFIOGroup *group; + struct vfio_pci_hot_reset_info *info =3D NULL; + struct vfio_pci_dependent_device *devices; + struct vfio_pci_hot_reset *reset; + int32_t *fds; + int ret, i, count; + bool multi =3D false; + + trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); + + if (!single) { + vfio_pci_pre_reset(vdev); + } + vdev->vbasedev.needs_reset =3D false; + + ret =3D vfio_pci_get_pci_hot_reset_info(vdev, &info); + + if (ret) { + goto out_single; + } + devices =3D &info->devices[0]; + + trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); + + /* Verify that we have all the groups required */ + for (i =3D 0; i < info->count; i++) { + PCIHostDeviceAddress host; + VFIOPCIDevice *tmp; + VFIODevice *vbasedev_iter; + + host.domain =3D devices[i].segment; + host.bus =3D devices[i].bus; + host.slot =3D PCI_SLOT(devices[i].devfn); + host.function =3D PCI_FUNC(devices[i].devfn); + + trace_vfio_pci_hot_reset_dep_devices(host.domain, + host.bus, host.slot, host.function, devices[i].group_id); + + if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { + continue; + } + + QLIST_FOREACH(group, &vfio_group_list, next) { + if (group->groupid =3D=3D devices[i].group_id) { + break; + } + } + + if (!group) { + if (!vdev->has_pm_reset) { + error_report("vfio: Cannot reset device %s, " + "depends on group %d which is not owned.", + vdev->vbasedev.name, devices[i].group_id); + } + ret =3D -EPERM; + goto out; + } + + /* Prep dependent devices for reset and clear our marker. */ + QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { + if (!vbasedev_iter->dev->realized || + vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + continue; + } + tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); + if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { + if (single) { + ret =3D -EINVAL; + goto out_single; + } + vfio_pci_pre_reset(tmp); + tmp->vbasedev.needs_reset =3D false; + multi =3D true; + break; + } + } + } + + if (!single && !multi) { + ret =3D -EINVAL; + goto out_single; + } + + /* Determine how many group fds need to be passed */ + count =3D 0; + QLIST_FOREACH(group, &vfio_group_list, next) { + for (i =3D 0; i < info->count; i++) { + if (group->groupid =3D=3D devices[i].group_id) { + count++; + break; + } + } + } + + reset =3D g_malloc0(sizeof(*reset) + (count * sizeof(*fds))); + reset->argsz =3D sizeof(*reset) + (count * sizeof(*fds)); + fds =3D &reset->group_fds[0]; + + /* Fill in group fds */ + QLIST_FOREACH(group, &vfio_group_list, next) { + for (i =3D 0; i < info->count; i++) { + if (group->groupid =3D=3D devices[i].group_id) { + fds[reset->count++] =3D group->fd; + break; + } + } + } + + /* Bus reset! */ + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_PCI_HOT_RESET, reset); + g_free(reset); + if (ret) { + ret =3D -errno; + } + + trace_vfio_pci_hot_reset_result(vdev->vbasedev.name, + ret ? strerror(errno) : "Success"); + +out: + /* Re-enable INTx on affected devices */ + for (i =3D 0; i < info->count; i++) { + PCIHostDeviceAddress host; + VFIOPCIDevice *tmp; + VFIODevice *vbasedev_iter; + + host.domain =3D devices[i].segment; + host.bus =3D devices[i].bus; + host.slot =3D PCI_SLOT(devices[i].devfn); + host.function =3D PCI_FUNC(devices[i].devfn); + + if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { + continue; + } + + QLIST_FOREACH(group, &vfio_group_list, next) { + if (group->groupid =3D=3D devices[i].group_id) { + break; + } + } + + if (!group) { + break; + } + + QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { + if (!vbasedev_iter->dev->realized || + vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { + continue; + } + tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); + if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { + vfio_pci_post_reset(tmp); + break; + } + } + } +out_single: + if (!single) { + vfio_pci_post_reset(vdev); + } + g_free(info); + + return ret; +} + const VFIOIOMMUOps vfio_legacy_ops =3D { .dma_map =3D vfio_legacy_dma_map, .dma_unmap =3D vfio_legacy_dma_unmap, @@ -929,4 +1098,5 @@ const VFIOIOMMUOps vfio_legacy_ops =3D { .detach_device =3D vfio_legacy_detach_device, .set_dirty_page_tracking =3D vfio_legacy_set_dirty_page_tracking, .query_dirty_bitmap =3D vfio_legacy_query_dirty_bitmap, + .pci_hot_reset =3D vfio_legacy_pci_hot_reset, }; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index eb55e8ae88..d00c3472c7 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2374,7 +2374,7 @@ static int vfio_add_capabilities(VFIOPCIDevice *vdev,= Error **errp) return 0; } =20 -static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) +void vfio_pci_pre_reset(VFIOPCIDevice *vdev) { PCIDevice *pdev =3D &vdev->pdev; uint16_t cmd; @@ -2411,7 +2411,7 @@ static void vfio_pci_pre_reset(VFIOPCIDevice *vdev) vfio_pci_write_config(pdev, PCI_COMMAND, cmd, 2); } =20 -static void vfio_pci_post_reset(VFIOPCIDevice *vdev) +void vfio_pci_post_reset(VFIOPCIDevice *vdev) { Error *err =3D NULL; int nr; @@ -2435,7 +2435,7 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev) vfio_quirk_reset(vdev); } =20 -static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *na= me) +bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name) { char tmp[13]; =20 @@ -2485,166 +2485,10 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice = *vdev, =20 static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) { - VFIOGroup *group; - struct vfio_pci_hot_reset_info *info =3D NULL; - struct vfio_pci_dependent_device *devices; - struct vfio_pci_hot_reset *reset; - int32_t *fds; - int ret, i, count; - bool multi =3D false; - - trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); - - if (!single) { - vfio_pci_pre_reset(vdev); - } - vdev->vbasedev.needs_reset =3D false; - - ret =3D vfio_pci_get_pci_hot_reset_info(vdev, &info); - - if (ret) { - goto out_single; - } - devices =3D &info->devices[0]; - - trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); - - /* Verify that we have all the groups required */ - for (i =3D 0; i < info->count; i++) { - PCIHostDeviceAddress host; - VFIOPCIDevice *tmp; - VFIODevice *vbasedev_iter; - - host.domain =3D devices[i].segment; - host.bus =3D devices[i].bus; - host.slot =3D PCI_SLOT(devices[i].devfn); - host.function =3D PCI_FUNC(devices[i].devfn); - - trace_vfio_pci_hot_reset_dep_devices(host.domain, - host.bus, host.slot, host.function, devices[i].group_id); - - if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { - continue; - } - - QLIST_FOREACH(group, &vfio_group_list, next) { - if (group->groupid =3D=3D devices[i].group_id) { - break; - } - } - - if (!group) { - if (!vdev->has_pm_reset) { - error_report("vfio: Cannot reset device %s, " - "depends on group %d which is not owned.", - vdev->vbasedev.name, devices[i].group_id); - } - ret =3D -EPERM; - goto out; - } - - /* Prep dependent devices for reset and clear our marker. */ - QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { - if (!vbasedev_iter->dev->realized || - vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { - continue; - } - tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); - if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { - if (single) { - ret =3D -EINVAL; - goto out_single; - } - vfio_pci_pre_reset(tmp); - tmp->vbasedev.needs_reset =3D false; - multi =3D true; - break; - } - } - } - - if (!single && !multi) { - ret =3D -EINVAL; - goto out_single; - } - - /* Determine how many group fds need to be passed */ - count =3D 0; - QLIST_FOREACH(group, &vfio_group_list, next) { - for (i =3D 0; i < info->count; i++) { - if (group->groupid =3D=3D devices[i].group_id) { - count++; - break; - } - } - } - - reset =3D g_malloc0(sizeof(*reset) + (count * sizeof(*fds))); - reset->argsz =3D sizeof(*reset) + (count * sizeof(*fds)); - fds =3D &reset->group_fds[0]; - - /* Fill in group fds */ - QLIST_FOREACH(group, &vfio_group_list, next) { - for (i =3D 0; i < info->count; i++) { - if (group->groupid =3D=3D devices[i].group_id) { - fds[reset->count++] =3D group->fd; - break; - } - } - } - - /* Bus reset! */ - ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_PCI_HOT_RESET, reset); - g_free(reset); - - trace_vfio_pci_hot_reset_result(vdev->vbasedev.name, - ret ? strerror(errno) : "Success"); - -out: - /* Re-enable INTx on affected devices */ - for (i =3D 0; i < info->count; i++) { - PCIHostDeviceAddress host; - VFIOPCIDevice *tmp; - VFIODevice *vbasedev_iter; - - host.domain =3D devices[i].segment; - host.bus =3D devices[i].bus; - host.slot =3D PCI_SLOT(devices[i].devfn); - host.function =3D PCI_FUNC(devices[i].devfn); - - if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { - continue; - } - - QLIST_FOREACH(group, &vfio_group_list, next) { - if (group->groupid =3D=3D devices[i].group_id) { - break; - } - } - - if (!group) { - break; - } - - QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { - if (!vbasedev_iter->dev->realized || - vbasedev_iter->type !=3D VFIO_DEVICE_TYPE_PCI) { - continue; - } - tmp =3D container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); - if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { - vfio_pci_post_reset(tmp); - break; - } - } - } -out_single: - if (!single) { - vfio_pci_post_reset(vdev); - } - g_free(info); + VFIODevice *vbasedev =3D &vdev->vbasedev; + const VFIOIOMMUOps *ops =3D vbasedev->bcontainer->ops; =20 - return ret; + return ops->pci_hot_reset(vbasedev, single); } =20 /* --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556469; cv=none; d=zohomail.com; s=zohoarc; b=VS9FZHWH18Pm8d7uqozQQJMNCXwqou3nxI6uFNPxdZ797rnZK0dq6gCC2o7QNWFRk4L6oJErx7Ady05SsuLbhfE8v0btHrYdjVBcYJyoHV0BLsf+aRi1ihMJWX8MzuLcmVtVxpiJExTZT7En8VmHknZvOYEd7KXC9ub1q9e1Wu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556469; 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=2meceRQG4Ddeg5I0W9DMV+7Up/m2w3+q7tcnBv9GGh0=; b=JXCE53fRY+VJYfKRCbBYWjQPPxT8wHQ8yeF38UYY03OfpD1HPJXD1sryAdC6dPx6BYp/2ZJrR5QxyBjXYwBrB+5JidvXyM0d/xDhzBh7CVBEIaItBuSEIuZadtGdB8kk4NbD7qlwqaNNMlP5q49UxTX42SFWf2G6BqX5ef3qVwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170055646899446.97849561087355; Tue, 21 Nov 2023 00:47:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPJ-000677-5r; Tue, 21 Nov 2023 03:46:57 -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 1r5MPI-00066y-CP for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:56 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPF-0001Qo-BV for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:46:56 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:52 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556413; x=1732092413; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SJ7Va2T7ak5UciNAvMEEVNZXzKuRGCGY5c4uhn0XlMA=; b=Oo+4IaHhJIcnU11KMpQBfgWZ9y7vhQBkp7PxWcU0KZZQ+lH7hDiT9PrU IZah7Fs7y5BqLQp+JvsxeTJk/9/GYUNZCvtOhwfZLccxJLVcjyi5TPAzz ltDbN0McQM5v6DEw+sccQrwx/SCdy8hL8zK2J7EoZ7A42iBMLLr63H0Nw VcOKju9xxOQzVFW4gbIhj1xuvxUmoHlxlEYacxjaMlqRu0+n20jZ57Q97 QCpGRZIIRoEeC3DSK5HoIhoH2ty+u1Eh8ZX4ZtLbfvTdzpAoZUyCnjoO9 IwAt9sbVr+gwhgtPAcfrXaZKeijWQIDqijjYKiWF1LjrzOECMXO1l+Qx+ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722095" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722095" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124918" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124918" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 09/27] vfio/iommufd: Enable pci hot reset through iommufd cdev interface Date: Tue, 21 Nov 2023 16:44:08 +0800 Message-Id: <20231121084426.1286987-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556470591100003 Content-Type: text/plain; charset="utf-8" Implement the newly introduced pci_hot_reset callback named iommufd_cdev_pci_hot_reset to do iommufd specific check and reset operation. Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/iommufd.c | 150 +++++++++++++++++++++++++++++++++++++++++++ hw/vfio/trace-events | 1 + 2 files changed, 151 insertions(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 01b448e840..6e53e013ef 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -24,6 +24,7 @@ #include "sysemu/reset.h" #include "qemu/cutils.h" #include "qemu/chardev_open.h" +#include "pci.h" =20 static int iommufd_cdev_map(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly) @@ -468,9 +469,158 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) close(vbasedev->fd); } =20 +static VFIODevice *iommufd_cdev_pci_find_by_devid(__u32 devid) +{ + VFIODevice *vbasedev_iter; + + QLIST_FOREACH(vbasedev_iter, &vfio_device_list, global_next) { + if (vbasedev_iter->bcontainer->ops !=3D &vfio_iommufd_ops) { + continue; + } + if (devid =3D=3D vbasedev_iter->devid) { + return vbasedev_iter; + } + } + return NULL; +} + +static VFIOPCIDevice * +iommufd_cdev_dep_get_realized_vpdev(struct vfio_pci_dependent_device *dep_= dev, + VFIODevice *reset_dev) +{ + VFIODevice *vbasedev_tmp; + + if (dep_dev->devid =3D=3D reset_dev->devid || + dep_dev->devid =3D=3D VFIO_PCI_DEVID_OWNED) { + return NULL; + } + + vbasedev_tmp =3D iommufd_cdev_pci_find_by_devid(dep_dev->devid); + if (!vbasedev_tmp || !vbasedev_tmp->dev->realized || + vbasedev_tmp->type !=3D VFIO_DEVICE_TYPE_PCI) { + return NULL; + } + + return container_of(vbasedev_tmp, VFIOPCIDevice, vbasedev); +} + +static int iommufd_cdev_pci_hot_reset(VFIODevice *vbasedev, bool single) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + struct vfio_pci_hot_reset_info *info =3D NULL; + struct vfio_pci_dependent_device *devices; + struct vfio_pci_hot_reset *reset; + int ret, i; + bool multi =3D false; + + trace_vfio_pci_hot_reset(vdev->vbasedev.name, single ? "one" : "multi"= ); + + if (!single) { + vfio_pci_pre_reset(vdev); + } + vdev->vbasedev.needs_reset =3D false; + + ret =3D vfio_pci_get_pci_hot_reset_info(vdev, &info); + + if (ret) { + goto out_single; + } + + assert(info->flags & VFIO_PCI_HOT_RESET_FLAG_DEV_ID); + + devices =3D &info->devices[0]; + + if (!(info->flags & VFIO_PCI_HOT_RESET_FLAG_DEV_ID_OWNED)) { + if (!vdev->has_pm_reset) { + for (i =3D 0; i < info->count; i++) { + if (devices[i].devid =3D=3D VFIO_PCI_DEVID_NOT_OWNED) { + error_report("vfio: Cannot reset device %s, " + "depends on device %04x:%02x:%02x.%x " + "which is not owned.", + vdev->vbasedev.name, devices[i].segment, + devices[i].bus, PCI_SLOT(devices[i].devfn= ), + PCI_FUNC(devices[i].devfn)); + } + } + } + ret =3D -EPERM; + goto out_single; + } + + trace_vfio_pci_hot_reset_has_dep_devices(vdev->vbasedev.name); + + for (i =3D 0; i < info->count; i++) { + VFIOPCIDevice *tmp; + + trace_iommufd_cdev_pci_hot_reset_dep_devices(devices[i].segment, + devices[i].bus, + PCI_SLOT(devices[i].d= evfn), + PCI_FUNC(devices[i].d= evfn), + devices[i].devid); + + /* + * If a VFIO cdev device is resettable, all the dependent devices + * are either bound to same iommufd or within same iommu_groups as + * one of the iommufd bound devices. + */ + assert(devices[i].devid !=3D VFIO_PCI_DEVID_NOT_OWNED); + + tmp =3D iommufd_cdev_dep_get_realized_vpdev(&devices[i], &vdev->vb= asedev); + if (!tmp) { + continue; + } + + if (single) { + ret =3D -EINVAL; + goto out_single; + } + vfio_pci_pre_reset(tmp); + tmp->vbasedev.needs_reset =3D false; + multi =3D true; + } + + if (!single && !multi) { + ret =3D -EINVAL; + goto out_single; + } + + /* Use zero length array for hot reset with iommufd backend */ + reset =3D g_malloc0(sizeof(*reset)); + reset->argsz =3D sizeof(*reset); + + /* Bus reset! */ + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_PCI_HOT_RESET, reset); + g_free(reset); + if (ret) { + ret =3D -errno; + } + + trace_vfio_pci_hot_reset_result(vdev->vbasedev.name, + ret ? strerror(errno) : "Success"); + + /* Re-enable INTx on affected devices */ + for (i =3D 0; i < info->count; i++) { + VFIOPCIDevice *tmp; + + tmp =3D iommufd_cdev_dep_get_realized_vpdev(&devices[i], &vdev->vb= asedev); + if (!tmp) { + continue; + } + vfio_pci_post_reset(tmp); + } +out_single: + if (!single) { + vfio_pci_post_reset(vdev); + } + g_free(info); + + return ret; +} + const VFIOIOMMUOps vfio_iommufd_ops =3D { .dma_map =3D iommufd_cdev_map, .dma_unmap =3D iommufd_cdev_unmap, .attach_device =3D iommufd_cdev_attach, .detach_device =3D iommufd_cdev_detach, + .pci_hot_reset =3D iommufd_cdev_pci_hot_reset, }; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 3340c93af0..8fdde54456 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -174,3 +174,4 @@ iommufd_cdev_detach_ioas_hwpt(int iommufd, const char *= name) " [iommufd=3D%d] Succ iommufd_cdev_fail_attach_existing_container(const char *msg) " %s" iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=3D%d] new IOM= MUFD container with ioasid=3D%d" iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regi= ons, int flags) " %s (%d) num_irqs=3D%d num_regions=3D%d flags=3D%d" +iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int = function, int dev_id) "\t%04x:%02x:%02x.%x devid %d" --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556531; cv=none; d=zohomail.com; s=zohoarc; b=fE7ugmXtevzey7yIhblbh6SJfHLEq9pej1z90XaH8k6ALNKl0zHyR3n3YMQFDH5Onsjhk1SngmuFlhPjwqh5/J9LKXQK00ZQ92ZdFpL8PUFMgCh6SaC8ZCHqpf5fpZ/gfuM2HiliKz+GX5gxZWhrDXpTqFox/DgwGA23JOneHY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556531; 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=a6nj+DSVVyhfKVmBVsx0mlrj9PO5aBnxgD3hHdahxhE=; b=MDR3kMdlBLttA/YM5hu5qHPDMisZpJ6PknJ1PfQdWK426gzv/6Nvo4+8h2vTOBORgAh8+OG1ONblPWNmQSQ5L8GmuQbXJeyvMckY4WRbD4grJD9glMfnsEzqMs5AO41Ad7cj5nnrJ38ljnnWcP9FSQiV8FOhDZ1Uk41kFk7ekAg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556531818579.639620528086; Tue, 21 Nov 2023 00:48:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPd-0006S1-TO; Tue, 21 Nov 2023 03:47:17 -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 1r5MPX-0006RV-Dy for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:11 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPS-0001cK-G6 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:11 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:03 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:46:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556426; x=1732092426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QE9y/ZL0Q6TcsW6wcCz4QOTYfnkF+XmxMxjbI4QMbHw=; b=WMHebBqldiMRR44hkg6lvqT0VWCYl7lRxey+a4fjV2a0yWMwJreZ18Dm O3en278OoQJaj3JCTyb8kf1CeWzoxKwCmhJIfvNItQ/wOQp+AeSz3i4Pc 9wa1RlLymvyM9lGhFludgFGQjMpT7h0gvPL+N+xJZfLZ/qN1XwlnNByYM qXhViaIEQYyQsku0tctNGVB5djLZd2WSfDhdudqZe0oQOkzlHlOe0OomY eJgyxWZq3qp5WYvrEJ+L2OYz/v303y27svGnZVjAxlDFU7HT9vZmJwMSc LriX40ZMEjtsURxd3a+LigbpIdHpAT22PLUpE7ya6OcKaNE3rXY0po0ZF Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722126" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722126" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124939" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124939" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 10/27] vfio/pci: Allow the selection of a given iommu backend Date: Tue, 21 Nov 2023 16:44:09 +0800 Message-Id: <20231121084426.1286987-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556532195100003 From: Eric Auger Now we support two types of iommu backends, let's add the capability to select one of them. This depends on whether an iommufd object has been linked with the vfio-pci device: If the user wants to use the legacy backend, it shall not link the vfio-pci device with any iommufd object: -device vfio-pci,host=3D0000:02:00.0 This is called the legacy mode/backend. If the user wants to use the iommufd backend (/dev/iommu) it shall pass an iommufd object id in the vfio-pci device options: -object iommufd,id=3Diommufd0 -device vfio-pci,host=3D0000:02:00.0,iommufd=3Diommufd0 Suggested-by: Alex Williamson Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d00c3472c7..c5984b0598 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include =20 @@ -42,6 +43,7 @@ #include "qapi/error.h" #include "migration/blocker.h" #include "migration/qemu-file.h" +#include "sysemu/iommufd.h" =20 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug" =20 @@ -3386,6 +3388,10 @@ static Property vfio_pci_dev_properties[] =3D { * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name), * DEFINE_PROP_STRING("vfiogroupfd, VFIOPCIDevice, vfiogroupfd_name), */ +#ifdef CONFIG_IOMMUFD + DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd, + TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), +#endif DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556503; cv=none; d=zohomail.com; s=zohoarc; b=oJQ5mXCTM4mvO0H1oNj56EqBkJ6eISuP31MhGoWhUa93z+XDIvFYiodUkV3xNNUf/qznibYymCBJDnO/kf0dIiEaO8rqjy4riY4gFwUjVZepsIRZ4P9opZlBkddvNn53Z4wQd7wgDlOibE3mmYN3ExsSVHZPwo8XekrViaMgl8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556503; 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=pBvsK95/z6unImS7zwGsLgj8SHkkIaDb/Y5CGYBvFgk=; b=DhIpogUY3QDtXlc2eMMeqNyGkTS+wT3VxZVb1o5I11T4VxT0MT4+eB9LoJ1cnncMS7lgdb/E3cWHr1be6oCMONu7G/UXlDXmkwhLQ2jn/2ebydp/A431ShLFVkX5XEllTYlMALSSVXrTkYJa6wrtjf+tP2DxBHOglu27zue+0Ts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556503908920.3899397331714; Tue, 21 Nov 2023 00:48:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPf-0006Sz-Hp; Tue, 21 Nov 2023 03:47:19 -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 1r5MPe-0006Sj-Hj for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:18 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPb-0001cm-FH for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:18 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:06 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:02 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556435; x=1732092435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EAe7XZq9QM0SYPbyPTESyBLfOXRjEFRfeioVOqIGqq4=; b=aA1DFMDtWAfuS7pDQYusIAQWANALclQ+ofpybLbblKn4IVkiXJ0thhQX SGMOoKYgA1jPunQsC1uY+yh6EH1BEdAvN9aSF3t/m28mFb2ecHFC5HpHt Yvc5sp9SJhy7NjUJP0HbAZsTDwqA01ppaH4AqC74bIv3GppcYJjqGEirB hIoweB2788KqpG5bSPAzJ0lhOAK655LZQlZpM7Ca9mD8QuPowerebXVkH KvAjq/3itXnERV5pVu57A/err1geG0bwKnO+1V9E6Q4IyCehUeODllusW 5+qIqtcR1EKFCj7FWQBOpFGKE6pr3dFEZnnGufXwpTNhUALNmS4GC4Ihr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722134" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722134" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124951" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124951" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 11/27] vfio/pci: Make vfio cdev pre-openable by passing a file handle Date: Tue, 21 Nov 2023 16:44:10 +0800 Message-Id: <20231121084426.1286987-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556505521100007 This gives management tools like libvirt a chance to open the vfio cdev with privilege and pass FD to qemu. This way qemu never needs to have privilege to open a VFIO or iommu cdev node. Together with the earlier support of pre-opening /dev/iommu device, now we have full support of passing a vfio device to unprivileged qemu by management tool. This mode is no more considered for the legacy backend. So let's remove the "TODO" comment. Add helper functions vfio_device_set_fd() and vfio_device_get_name() to set fd and get device name, they will also be used by other vfio devices. There is no easy way to check if a device is mdev with FD passing, so fail the x-balloon-allowed check unconditionally in this case. There is also no easy way to get BDF as name with FD passing, so we fake a name by VFIO_FD[fd]. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Tested-by: Eric Auger Tested-by: Nicolin Chen --- include/hw/vfio/vfio-common.h | 4 ++++ hw/vfio/helpers.c | 43 +++++++++++++++++++++++++++++++++++ hw/vfio/iommufd.c | 12 ++++++---- hw/vfio/pci.c | 28 +++++++++++++---------- 4 files changed, 71 insertions(+), 16 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 3dac5c167e..697bf24a35 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -251,4 +251,8 @@ int vfio_devices_query_dirty_bitmap(VFIOContainerBase *= bcontainer, hwaddr size); int vfio_get_dirty_bitmap(VFIOContainerBase *bcontainer, uint64_t iova, uint64_t size, ram_addr_t ram_addr); + +/* Returns 0 on success, or a negative errno. */ +int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); +void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p); #endif /* HW_VFIO_VFIO_COMMON_H */ diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 168847e7c5..3592c3d54e 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -27,6 +27,7 @@ #include "trace.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "monitor/monitor.h" =20 /* * Common VFIO interrupt disable @@ -609,3 +610,45 @@ bool vfio_has_region_cap(VFIODevice *vbasedev, int reg= ion, uint16_t cap_type) =20 return ret; } + +int vfio_device_get_name(VFIODevice *vbasedev, Error **errp) +{ + struct stat st; + + if (vbasedev->fd < 0) { + if (stat(vbasedev->sysfsdev, &st) < 0) { + error_setg_errno(errp, errno, "no such host device"); + error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); + return -errno; + } + /* User may specify a name, e.g: VFIO platform device */ + if (!vbasedev->name) { + vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); + } + } else { + if (!vbasedev->iommufd) { + error_setg(errp, "Use FD passing only with iommufd backend"); + return -EINVAL; + } + /* + * Give a name with fd so any function printing out vbasedev->name + * will not break. + */ + if (!vbasedev->name) { + vbasedev->name =3D g_strdup_printf("VFIO_FD%d", vbasedev->fd); + } + } + + return 0; +} + +void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) +{ + int fd =3D monitor_fd_param(monitor_cur(), str, errp); + + if (fd < 0) { + error_prepend(errp, "Could not parse remote object fd %s:", str); + return; + } + vbasedev->fd =3D fd; +} diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 6e53e013ef..5accd26484 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -320,11 +320,15 @@ static int iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, uint32_t ioas_id; Error *err =3D NULL; =20 - devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); - if (devfd < 0) { - return devfd; + if (vbasedev->fd < 0) { + devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); + if (devfd < 0) { + return devfd; + } + vbasedev->fd =3D devfd; + } else { + devfd =3D vbasedev->fd; } - vbasedev->fd =3D devfd; =20 ret =3D iommufd_cdev_connect_and_bind(vbasedev, errp); if (ret) { diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c5984b0598..445d58c8e5 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2944,17 +2944,19 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) VFIODevice *vbasedev =3D &vdev->vbasedev; char *tmp, *subsys; Error *err =3D NULL; - struct stat st; int i, ret; bool is_mdev; char uuid[UUID_STR_LEN]; char *name; =20 - if (!vbasedev->sysfsdev) { + if (vbasedev->fd < 0 && !vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || ~vdev->host.slot || ~vdev->host.function)) { error_setg(errp, "No provided host device"); error_append_hint(errp, "Use -device vfio-pci,host=3DDDDD:BB:D= D.F " +#ifdef CONFIG_IOMMUFD + "or -device vfio-pci,fd=3DDEVICE_FD " +#endif "or -device vfio-pci,sysfsdev=3DPATH_TO_DEVI= CE\n"); return; } @@ -2964,13 +2966,9 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vdev->host.slot, vdev->host.function); } =20 - if (stat(vbasedev->sysfsdev, &st) < 0) { - error_setg_errno(errp, errno, "no such host device"); - error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); + if (vfio_device_get_name(vbasedev, errp) < 0) { return; } - - vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); vbasedev->ops =3D &vfio_pci_ops; vbasedev->type =3D VFIO_DEVICE_TYPE_PCI; vbasedev->dev =3D DEVICE(vdev); @@ -3330,6 +3328,7 @@ static void vfio_instance_init(Object *obj) vdev->host.bus =3D ~0U; vdev->host.slot =3D ~0U; vdev->host.function =3D ~0U; + vdev->vbasedev.fd =3D -1; =20 vdev->nv_gpudirect_clique =3D 0xFF; =20 @@ -3383,11 +3382,6 @@ static Property vfio_pci_dev_properties[] =3D { qdev_prop_nv_gpudirect_clique, uint8_t), DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_r= elo, OFF_AUTOPCIBAR_OFF), - /* - * TODO - support passed fds... is this necessary? - * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name), - * DEFINE_PROP_STRING("vfiogroupfd, VFIOPCIDevice, vfiogroupfd_name), - */ #ifdef CONFIG_IOMMUFD DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd, TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), @@ -3395,6 +3389,13 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +#ifdef CONFIG_IOMMUFD +static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp) +{ + vfio_device_set_fd(&VFIO_PCI(obj)->vbasedev, str, errp); +} +#endif + static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -3402,6 +3403,9 @@ static void vfio_pci_dev_class_init(ObjectClass *klas= s, void *data) =20 dc->reset =3D vfio_pci_reset; device_class_set_props(dc, vfio_pci_dev_properties); +#ifdef CONFIG_IOMMUFD + object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd); +#endif dc->desc =3D "VFIO-based PCI device assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); pdc->realize =3D vfio_realize; --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556510; cv=none; d=zohomail.com; s=zohoarc; b=hROKKWE4Drt0rItB2IhwD9DXfKHhKvSOaHxvF8MYs2fXoWAd0PpCHADWLFks5cfXmMHjSU8FNjttXs0PuCopoq9DnR0y4yfy6E5WJfMLuHzWYXF7bk/8fb9iqJAvWEEIVWiwUTqptIBHLQyrgDiF/UxgqqVKEnQfMspDkjy1bO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556510; 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=tymdpJx5wlm5P9R/GB+uvC7QPDjKB1wEIpZfQlbiOgQ=; b=jJsyZ07v9iAkX93X1jzun4gU7P5gZEU4Ut6t3+2qWyGn9HXhX453u22Gm9SWYY/jsw6b65MY1SWP7EZO3NOXxhbHqU3eMKgrTpFVG7Yw2nTvDrQ89+jAAVz/edfRL/5auLgRKx9gWqLPnhMtMeepRd5+xIQwSBjdn9McYF0NIPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556510166694.8289414118947; Tue, 21 Nov 2023 00:48:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPq-0006nh-CS; Tue, 21 Nov 2023 03:47:30 -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 1r5MPn-0006ez-MF for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:27 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPd-0001cK-Am for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:27 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:15 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556437; x=1732092437; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XRYtppU1OqVAAa4Mhe2SkKZSp77WBiRqxEHT0WeSqMM=; b=EtKq8UxWlSCudV9ePYE11wBaBnsfWiWW+h+wl64Mpx4jWkv4COgOZ7bd FfBw9wjK9nx33irXwCSNCLaF5FQJ1z2B8GsR8Un7fI/payL5eQw5ADGya JtHuxWcXlW6vkGJr4ikMJjx3pNZ7mte+RJqhKL63hn85MPgW0O84j31n4 NMWAxgRzdOEOksbAeFpOO6naFJ/baRKWpbDOew4dqQuhhOALvHSwyjzXO AxeAfphSakG5rtyFint1lzJMUN3jdQhMU/0EweTLpKFwG9ApHVs9epact Tka65xbdkt84y2wq76yH9oj3r3e+kSnQhaed7wIiVNQ5nwFgMXk/A8rap A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722144" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722144" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124959" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124959" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 12/27] vfio/platform: Allow the selection of a given iommu backend Date: Tue, 21 Nov 2023 16:44:11 +0800 Message-Id: <20231121084426.1286987-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556511658100007 Now we support two types of iommu backends, let's add the capability to select one of them. This depends on whether an iommufd object has been linked with the vfio-platform device: If the user wants to use the legacy backend, it shall not link the vfio-platform device with any iommufd object: -device vfio-platform,host=3DXXX This is called the legacy mode/backend. If the user wants to use the iommufd backend (/dev/iommu) it shall pass an iommufd object id in the vfio-platform device options: -object iommufd,id=3Diommufd0 -device vfio-platform,host=3DXXX,iommufd=3Diommufd0 Suggested-by: Alex Williamson Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Nicolin Chen --- hw/vfio/platform.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 8e3d4ac458..98ae4bc655 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -15,11 +15,13 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include "qapi/error.h" #include #include =20 #include "hw/vfio/vfio-platform.h" +#include "sysemu/iommufd.h" #include "migration/vmstate.h" #include "qemu/error-report.h" #include "qemu/lockable.h" @@ -649,6 +651,10 @@ static Property vfio_platform_dev_properties[] =3D { DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice, mmap_timeout, 1100), DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true), +#ifdef CONFIG_IOMMUFD + DEFINE_PROP_LINK("iommufd", VFIOPlatformDevice, vbasedev.iommufd, + TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), +#endif DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556461; cv=none; d=zohomail.com; s=zohoarc; b=A2fFj+mO0sGnkSEynmW6FwdZvNogh0CYUIQuD5xkWFWkdGWacmm3C30dFVNfb/3oKoMuB+n7Aj8bbg8Xoh2NmF/UhKfnu1fkuPOci25BfPhcMaSgRTw/UU93BvxImRre7hxmXSQnz/dKX5zfyo358FYszFf04DdKrSwyJA5QsWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556461; 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=CuTi7GfdR2Zcold1ILdKDt4i7EMsTzcG9OT0Um8pS6s=; b=dl6+lq/9F6OW03VL72zeicnI0fnKYY72yc/GzZuaoCppTwiQ5+RvYTcqOJP63X02W8dfnn2Q0hRbeSkxf7o3im1pC1KA99trFrCwEkpFvOdgiQgMMhPgF3UYwggoXkN8VvtzSAjkSkwuvip4QObPikOEJv+3+8DGQyEPQW3enug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170055646100693.65987758316442; Tue, 21 Nov 2023 00:47:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPj-0006U6-J4; Tue, 21 Nov 2023 03:47:23 -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 1r5MPi-0006T6-61 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:22 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPg-0001e9-FP for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:21 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:15 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556440; x=1732092440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dd2xEWWk0YPsEf75LQpuy0bDEAZE9RO0Ebhfbs3ZVWA=; b=f1zA5sUTr7BTW4At485dAoIHIfRrasPSgqfho98zwR/ln7Mr+cLZRueD D/Wfn7PMCMENm8nrPDlE6+2PmWOaMYVmeJV2nLCXwv36ir2QqZ4nM2imo 9ZHznmavnwM67OoGyrEiRaAe4oIXhg/vToB3uFp++wqlLtumxjTFdV8JG 6gxpZo4SwSBV3w1dDHIauGKavMAB3bD/4zTjaR6UtR2lW+5s+YvAd+Bv+ 7dbEgU60Fum51fIKAKEO4fvYpdrBA0mhJVzSo6KNCa35uHnicL2FxEdLI KqwZ64HZrNaGLcK7HdEwH2ehfTFnnGjrIjUrr8TyZH5WPHfCrhnm5Y485 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722157" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722157" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124976" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124976" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 13/27] vfio/platform: Make vfio cdev pre-openable by passing a file handle Date: Tue, 21 Nov 2023 16:44:12 +0800 Message-Id: <20231121084426.1286987-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556462663100002 This gives management tools like libvirt a chance to open the vfio cdev with privilege and pass FD to qemu. This way qemu never needs to have privilege to open a VFIO or iommu cdev node. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Tested-by: Nicolin Chen --- hw/vfio/platform.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 98ae4bc655..a97d9c6234 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -531,14 +531,13 @@ static VFIODeviceOps vfio_platform_ops =3D { */ static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp) { - struct stat st; int ret; =20 - /* @sysfsdev takes precedence over @host */ - if (vbasedev->sysfsdev) { + /* @fd takes precedence over @sysfsdev which takes precedence over @ho= st */ + if (vbasedev->fd < 0 && vbasedev->sysfsdev) { g_free(vbasedev->name); vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); - } else { + } else if (vbasedev->fd < 0) { if (!vbasedev->name || strchr(vbasedev->name, '/')) { error_setg(errp, "wrong host device name"); return -EINVAL; @@ -548,10 +547,9 @@ static int vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) vbasedev->name); } =20 - if (stat(vbasedev->sysfsdev, &st) < 0) { - error_setg_errno(errp, errno, - "failed to get the sysfs host device file status"= ); - return -errno; + ret =3D vfio_device_get_name(vbasedev, errp); + if (ret) { + return ret; } =20 ret =3D vfio_attach_device(vbasedev->name, vbasedev, @@ -658,6 +656,20 @@ static Property vfio_platform_dev_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static void vfio_platform_instance_init(Object *obj) +{ + VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(obj); + + vdev->vbasedev.fd =3D -1; +} + +#ifdef CONFIG_IOMMUFD +static void vfio_platform_set_fd(Object *obj, const char *str, Error **err= p) +{ + vfio_device_set_fd(&VFIO_PLATFORM_DEVICE(obj)->vbasedev, str, errp); +} +#endif + static void vfio_platform_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -665,6 +677,9 @@ static void vfio_platform_class_init(ObjectClass *klass= , void *data) =20 dc->realize =3D vfio_platform_realize; device_class_set_props(dc, vfio_platform_dev_properties); +#ifdef CONFIG_IOMMUFD + object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd); +#endif dc->vmsd =3D &vfio_platform_vmstate; dc->desc =3D "VFIO-based platform device assignment"; sbc->connect_irq_notifier =3D vfio_start_irqfd_injection; @@ -677,6 +692,7 @@ static const TypeInfo vfio_platform_dev_info =3D { .name =3D TYPE_VFIO_PLATFORM, .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(VFIOPlatformDevice), + .instance_init =3D vfio_platform_instance_init, .class_init =3D vfio_platform_class_init, .class_size =3D sizeof(VFIOPlatformDeviceClass), }; --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556465; cv=none; d=zohomail.com; s=zohoarc; b=e1lnewSZvoJb9Xtw5As24uVNKYaMb7f2I/xBjB8PUaIvGuRtyZn2F41h7e/GoOkrrX/1gv1IV7NATrJ33WGmUTCu/MHTvZ5rdEZpbhyzPaDttfckn4FCSxxooc/HgtUns7+or+wi80KIqvCQ1Ij3tD25gbNC5t4J9Fyz3r6dvcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556465; 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=YRIyNAUYfxkn65tm/iCWHuuGAtcZ3QNKHRbxYZkkPd8=; b=HjbNT/Es3IOZmZsK3/OKqmDl8OY/RJqk2paqxPfK6MT9mTOxrNSe5WI5VolxsmYYcL75LShrkddvP8jEpSszNKw2JK9N1/6KE6fZEJHrD6zVATbxZNdAVhWL6xwG0lbFMoyqgC88/0/TEMVv6G9T8JFxNAwVSb9AYO/ovL9ZujA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556465269849.5396813646743; Tue, 21 Nov 2023 00:47:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPk-0006UJ-On; Tue, 21 Nov 2023 03:47:24 -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 1r5MPi-0006Ts-Qw for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:22 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPh-0001cm-93 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:22 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:19 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556441; x=1732092441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JfdZ3bx5X+vXP8ujM+7gwBwdhnrjh2mzHpDVpuno9Lw=; b=lCkjP7tRpEjpaIKiUWOc5wHgdlzmUGfAE53NwE7M1ALIlzwJV8lMtePf F4AJcfVmRrpwKyEc6KGHIGaXrWvpkTus2i5YQuU4Yq77zxHdRRVRP/eFR A7hrZefKFBtUXiwC/T0in3+H1mbB59RhircDZaLv2beneaEt6ER4ujqPo xWIiZIMA0DlqvaxBkDr4P0y1uaheEnNFvzGjXgNczFBxXSiQT7/o2PDVF U59di3Mu11WGEEa5czyxPXBvuqT/id+ttmLCCzLtEATz99t6A/Bq+9Ijn rkvhXgBlw2EISUXSdYUnk3V7s/1ux76wupaKTJprSyqzZ0etyrZIjaRDv w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722176" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722176" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884124988" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884124988" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 14/27] vfio/ap: Allow the selection of a given iommu backend Date: Tue, 21 Nov 2023 16:44:13 +0800 Message-Id: <20231121084426.1286987-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556466510100011 Now we support two types of iommu backends, let's add the capability to select one of them. This depends on whether an iommufd object has been linked with the vfio-ap device: if the user wants to use the legacy backend, it shall not link the vfio-ap device with any iommufd object: -device vfio-ap,sysfsdev=3D/sys/bus/mdev/devices/XXX This is called the legacy mode/backend. If the user wants to use the iommufd backend (/dev/iommu) it shall pass an iommufd object id in the vfio-ap device options: -object iommufd,id=3Diommufd0 -device vfio-ap,sysfsdev=3D/sys/bus/mdev/devices/XXX,iommufd=3Diommufd0 Suggested-by: Alex Williamson Signed-off-by: Zhenzhong Duan Reviewed-by: Matthew Rosato Reviewed-by: C=C3=A9dric Le Goater Tested-by: Nicolin Chen --- hw/vfio/ap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index bbf69ff55a..80629609ae 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -11,10 +11,12 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include #include "qapi/error.h" #include "hw/vfio/vfio-common.h" +#include "sysemu/iommufd.h" #include "hw/s390x/ap-device.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h" @@ -204,6 +206,10 @@ static void vfio_ap_unrealize(DeviceState *dev) =20 static Property vfio_ap_properties[] =3D { DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev), +#ifdef CONFIG_IOMMUFD + DEFINE_PROP_LINK("iommufd", VFIOAPDevice, vdev.iommufd, + TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), +#endif DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556462; cv=none; d=zohomail.com; s=zohoarc; b=VawtSEoI7mbD79ElnD86inqf+4MUw/0Wtc3UiQ68EbfhgnFd4J1HPvHxcnRY6ZiReFAbFplUHIpd7bEx7c3NMtGA0lfsMoeCMEWoAqlJ25ZiIXPlWIXx1Z71A9Khu6Rtvwq0ZQjXe3Sy/NTdCRHoBm0N6nhai5q0bBZm3Fru9bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556462; 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=+rsDQbWtBELg2+rd7bFruubaktP7CfhRG0KUEmF87ck=; b=mUsLDObI6u0O7G6BzL0CUj5xcjpyeFtr5e1sWGLe037Km50nPTMyxFPcE03+q3OmbncRbdSdlJDqSMW5/FfM0VlIPRNNZlaZKjbMkgjTsJh8jo/e76b6oDoGQ3iXAUOjCrM5ADgROiIrI51+8ZfAHAJgeNWBqgGo0RuuJIl6gfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556462900117.61610616272856; Tue, 21 Nov 2023 00:47:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MPp-0006n3-BQ; Tue, 21 Nov 2023 03:47:29 -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 1r5MPn-0006dM-Aw for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:27 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MPl-0001gM-CP for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:27 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:22 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556445; x=1732092445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UPAOUojblgTst9HnU7B0CVXxHRF8+Gvxw59jZTn4acM=; b=OkCk3Y2ntQ9K0KYhLL8UD0j7VXf6tn6w/8t1nKNE8AXQm1dTBJx2bjmX geweHB2rscPZwmWbPRTvnd/htKzukr04bHXdgiid1914OSof4sSv0OpkM qL0EtJZPPU9/nWcZET96D3o2FxDmYAl1mR/sRpNNWcrmVWiueOTEZApII kjGNRCQUlmSenxOKgY7DSH4AkdCoAp2GmxiCwZ+5dEGqcuvcpiKxYOL/O pW39e2JiVTzMOJPeY1uLcCgkYX3Pq6ozgmZIDKg/yHbXVQwxii68UZvH6 TPqi81u2HiJMNAjB5t+bZQFK4gBThSiaEVrpS644/lpgMKpL0f/5Q5WcL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722188" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722188" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125001" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125001" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 15/27] vfio/ap: Make vfio cdev pre-openable by passing a file handle Date: Tue, 21 Nov 2023 16:44:14 +0800 Message-Id: <20231121084426.1286987-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556464443100006 This gives management tools like libvirt a chance to open the vfio cdev with privilege and pass FD to qemu. This way qemu never needs to have privilege to open a VFIO or iommu cdev node. Signed-off-by: Zhenzhong Duan Reviewed-by: Matthew Rosato Reviewed-by: C=C3=A9dric Le Goater Tested-by: Nicolin Chen --- hw/vfio/ap.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 80629609ae..f180e4a32a 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -160,7 +160,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **= errp) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); VFIODevice *vbasedev =3D &vapdev->vdev; =20 - vbasedev->name =3D g_path_get_basename(vbasedev->sysfsdev); + if (vfio_device_get_name(vbasedev, errp) < 0) { + return; + } + vbasedev->ops =3D &vfio_ap_ops; vbasedev->type =3D VFIO_DEVICE_TYPE_AP; vbasedev->dev =3D dev; @@ -230,11 +233,28 @@ static const VMStateDescription vfio_ap_vmstate =3D { .unmigratable =3D 1, }; =20 +static void vfio_ap_instance_init(Object *obj) +{ + VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(obj); + + vapdev->vdev.fd =3D -1; +} + +#ifdef CONFIG_IOMMUFD +static void vfio_ap_set_fd(Object *obj, const char *str, Error **errp) +{ + vfio_device_set_fd(&VFIO_AP_DEVICE(obj)->vdev, str, errp); +} +#endif + static void vfio_ap_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 device_class_set_props(dc, vfio_ap_properties); +#ifdef CONFIG_IOMMUFD + object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd); +#endif dc->vmsd =3D &vfio_ap_vmstate; dc->desc =3D "VFIO-based AP device assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); @@ -249,6 +269,7 @@ static const TypeInfo vfio_ap_info =3D { .name =3D TYPE_VFIO_AP_DEVICE, .parent =3D TYPE_AP_DEVICE, .instance_size =3D sizeof(VFIOAPDevice), + .instance_init =3D vfio_ap_instance_init, .class_init =3D vfio_ap_class_init, }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556508; cv=none; d=zohomail.com; s=zohoarc; b=WkZTdeohAW4RcmFMlkY4HTCzgY0d5FWbDZhE9CiYgmgu7CCIxksY3dmhH1B2KviHY/P1qJDEuO2EmJJOxPTFC1esCVPum/EI+84Nc5Xq1elx4nVl6CBHliE3Wh2ICk+tIpozu4iLSmiDLdsct0EFojSQdVKEc6G3pwiSiVma8Ao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556508; 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=KRMo2e9olub7KDR+mprQ+wG+zzUuF7uk+8NbyTLZBYo=; b=feCL/eoVit0lpcVkc9RjmsbuyC/cQsrWyQ+Cwyw7KeaamuW4C1QEZXW73MVmXD0p68QPT1N9OxbhL7ilYH8orDjplKd0T0X7y0xgGwuspkJv1VYSKiUG4vkX+dCsd1TLzdur5O9Wuz0i0JEllDScq9gKlDPwSLgkn6KGiI5ysdA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556508507363.10034784178185; Tue, 21 Nov 2023 00:48:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQN-0000f9-Ub; Tue, 21 Nov 2023 03:48:04 -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 1r5MQL-0000W4-0p for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:01 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQI-0002Dg-BK for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:47:59 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:26 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556478; x=1732092478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DDboMTfLcnf4ZakXgLoI1otweQs8iHjAcpmVNegNIik=; b=D7TTTOG0Ne/lbSlC9gen8ylOxi0mYHh7OsOgwwdUpRuO3CzHBd15JDAX 1FatqFq8lzkLxanoP1uAiE+kw9m8rZxkXaseoeEZqpWl2la5aZlz00NOT bcHZRs1YwVqUqvMef+2ANl6+9QSoC1enT0te3UyN0TseG0gL/N40dnG1t Uejnd8Cu7HJI+OkVI9HW6rka0Bx75GL1sQrUDZOBHYtpVOOZpNvSYtLhp UtmwK821neZeDRCtyMS6UC6yISfrSu1scOWnnWnP92j94EowqO5F7DRMx fE9lUcTbvlxZm3Q258ED1W8QD8RlbZ0y5exPuLfqLCqeVT5bURELjpVrM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722217" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722217" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125023" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125023" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 16/27] vfio/ccw: Allow the selection of a given iommu backend Date: Tue, 21 Nov 2023 16:44:15 +0800 Message-Id: <20231121084426.1286987-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556509615100001 Now we support two types of iommu backends, let's add the capability to select one of them. This depends on whether an iommufd object has been linked with the vfio-ccw device: If the user wants to use the legacy backend, it shall not link the vfio-ccw device with any iommufd object: -device vfio-ccw,sysfsdev=3D/sys/bus/mdev/devices/XXX This is called the legacy mode/backend. If the user wants to use the iommufd backend (/dev/iommu) it shall pass an iommufd object id in the vfio-ccw device options: -object iommufd,id=3Diommufd0 -device vfio-ccw,sysfsdev=3D/sys/bus/mdev/devices/XXX,iommufd=3Diommufd0 Suggested-by: Alex Williamson Signed-off-by: Zhenzhong Duan Reviewed-by: Matthew Rosato Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Farman Tested-by: Nicolin Chen --- hw/vfio/ccw.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index d857bb8d0f..d2d58bb677 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -15,12 +15,14 @@ */ =20 #include "qemu/osdep.h" +#include CONFIG_DEVICES /* CONFIG_IOMMUFD */ #include #include #include =20 #include "qapi/error.h" #include "hw/vfio/vfio-common.h" +#include "sysemu/iommufd.h" #include "hw/s390x/s390-ccw.h" #include "hw/s390x/vfio-ccw.h" #include "hw/qdev-properties.h" @@ -677,6 +679,10 @@ static void vfio_ccw_unrealize(DeviceState *dev) static Property vfio_ccw_properties[] =3D { DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev), DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, fals= e), +#ifdef CONFIG_IOMMUFD + DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd, + TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), +#endif DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556549; cv=none; d=zohomail.com; s=zohoarc; b=YKmhqKZvu6KHSSEUsWAGmgQzUQuFXr+JbxeDV0rduODukdrt9o1WSKXGLVjp1sOGSV8sMfWNyjPhpiD1wmTEBpk1lC2dDnJW3iDJ9cwOEP7H49Ha7U81IWsuhzTdf57T9SgxRfwC8Y7mj216AQN+ae40vzlysFY0rixjJmOv3ds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556549; 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=mVBVim6/QpaY41JZuSqJJxg5FenZ005N7/WgHyu6y7Q=; b=Lx9gF36/tv+sIjPhyotgdu9edCBC5+6+JXfaEtwSBexqJmMd3UFOUU6DH+sNe8OjoEJnh4O5JZ47WVkotnMqq+oZjvPmJKMTMeyXpicWOigXYxO5WHhVkkzE7TGT/11P1B+AgkLfxUKwrdARYhdOqdApQE0asn72nuMYN7FgOQQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556549657628.2100006214711; Tue, 21 Nov 2023 00:49:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQf-0001Jp-NP; Tue, 21 Nov 2023 03:48:21 -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 1r5MQO-0000mL-3Q for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:05 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQK-0002Dl-MH for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:02 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:30 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556480; x=1732092480; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EMLoOfNancx8vwEhcxw9v1vGtVT7TNhE86U5UKPlPfE=; b=FOT7thwZHNn0BD/qmFHjpLC/DtHhxHuIZBa2BKNwUxmtWyUBnUCtP0os Plp8CI2ek2RPP9USai6syggRTvJ4jzhSGCKMG2Uqjt0SHnLDtuHfA6IIH ZcUVxLxF8dNJEcamnrkjxokjOTMayjDEnwfQQR/BEta91q4oxBgtBZGCs tUFlFwyAKxr7nPggwIduE6d4xt3ME29q+noYx+d7MLGLIV5D6HCjaOpTj XOKVlCPcjmjIq9HJhl+mSOA3QG+q//YeXT+AaFntNFq9WS89HxaWvr/oc 8VcXIR7n+bXpg2dpCc7UzQ8FQTFc0HkrbS7rGtQ2tYpAkTzZ3iBvaNqON g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722235" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722235" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125045" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125045" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 17/27] vfio/ccw: Make vfio cdev pre-openable by passing a file handle Date: Tue, 21 Nov 2023 16:44:16 +0800 Message-Id: <20231121084426.1286987-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556550693100017 This gives management tools like libvirt a chance to open the vfio cdev with privilege and pass FD to qemu. This way qemu never needs to have privilege to open a VFIO or iommu cdev node. Signed-off-by: Zhenzhong Duan Reviewed-by: Matthew Rosato Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Farman Tested-by: Nicolin Chen --- hw/vfio/ccw.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index d2d58bb677..2afdf17dbe 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -590,11 +590,12 @@ static void vfio_ccw_realize(DeviceState *dev, Error = **errp) } } =20 + if (vfio_device_get_name(vbasedev, errp) < 0) { + return; + } + vbasedev->ops =3D &vfio_ccw_ops; vbasedev->type =3D VFIO_DEVICE_TYPE_CCW; - vbasedev->name =3D g_strdup_printf("%x.%x.%04x", vcdev->cdev.hostid.cs= sid, - vcdev->cdev.hostid.ssid, - vcdev->cdev.hostid.devid); vbasedev->dev =3D dev; =20 /* @@ -691,12 +692,29 @@ static const VMStateDescription vfio_ccw_vmstate =3D { .unmigratable =3D 1, }; =20 +static void vfio_ccw_instance_init(Object *obj) +{ + VFIOCCWDevice *vcdev =3D VFIO_CCW(obj); + + vcdev->vdev.fd =3D -1; +} + +#ifdef CONFIG_IOMMUFD +static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp) +{ + vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp); +} +#endif + static void vfio_ccw_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_CLASS(klass); =20 device_class_set_props(dc, vfio_ccw_properties); +#ifdef CONFIG_IOMMUFD + object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd); +#endif dc->vmsd =3D &vfio_ccw_vmstate; dc->desc =3D "VFIO-based subchannel assignment"; set_bit(DEVICE_CATEGORY_MISC, dc->categories); @@ -714,6 +732,7 @@ static const TypeInfo vfio_ccw_info =3D { .name =3D TYPE_VFIO_CCW, .parent =3D TYPE_S390_CCW, .instance_size =3D sizeof(VFIOCCWDevice), + .instance_init =3D vfio_ccw_instance_init, .class_init =3D vfio_ccw_class_init, }; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556530; cv=none; d=zohomail.com; s=zohoarc; b=i63M/hXisKBkDtJHJEMQk3+mEQDKmUjd6PkhNLm3wurC20uYjN7OcdExMhoViPJEw+hPNNDvoskTvjoFokT0y/3BwjyhOJkrOJtc/BOjumOY7B8TywyvYKDBV9pgcdjQrAmMtT5yiaePNkti1vczXt8KBoHNzBsAWEZA9S1BpIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556530; 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=jVc7gVIvNwNL/JFSTie1JNYb4WR0EzVkU93jyHRV+dQ=; b=SsYJ9Dy75IOYKIVXB327PoouDu4eLVc71M3ca1ufmjsSihVpJpBFQ6QeHcXaVcIvZI5xRzyMBjYpjjIypqFXjS8+i85JfKWxXolXHkHx+7YlSelOu+GOUky6xps7DYgyPMrTPHqoITgbh7PxiRNPwNvIPn+3mFt7ZWWhb6YlZSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556530290422.56819883724745; Tue, 21 Nov 2023 00:48:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQi-0001bj-MN; Tue, 21 Nov 2023 03:48:24 -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 1r5MQO-0000mo-4i for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:06 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQK-0002Ds-Pu for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:03 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:34 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556480; x=1732092480; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RnghmGBf/mYl+pI66swTZ+ihPYKZf4ZOeE9KfWJxz6w=; b=K4Va8WMSZbR8PB5zsC1mY4o62uPKNNXLtripVQeVmHTrE2LquFqCIaoy LXTc0eQjpKmEguUWmE2Dh6T4I2KraSwmJHno5eG9gondcqwMLRtrQeS51 Yt/mcRU/hR9gO7uxiB43nfxZmNjcuyCCtpYgoNfjYoT7NSw2JgAIHfNDJ SoOdk4z33Op+/wAdQUP/yrjoFE7/BuTHiHvKL6Ll6tWI1mAJlrKrhTJNa aPenHB9WeKhMaUm79j2n5JVuyCEG9YkU9cCPHD+MAncGm1kNoJ9/K+VQD 6XXJcf1dNqnvYuo6scgzHxFOx3lFtOwJqEnUCmIwobJLCpg9plddjjvGV g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722253" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722253" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125065" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125065" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 18/27] vfio: Make VFIOContainerBase poiner parameter const in VFIOIOMMUOps callbacks Date: Tue, 21 Nov 2023 16:44:17 +0800 Message-Id: <20231121084426.1286987-19-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556532248100006 Some of the callbacks in VFIOIOMMUOps pass VFIOContainerBase poiner, those callbacks only need read access to the sub object of VFIOContainerBas= e. So make VFIOContainerBase, VFIOContainer and VFIOIOMMUFDContainer as const in these callbacks. Local functions called by those callbacks also need same changes to avoid build error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- include/hw/vfio/vfio-common.h | 12 ++++++---- include/hw/vfio/vfio-container-base.h | 12 ++++++---- hw/vfio/common.c | 9 +++---- hw/vfio/container-base.c | 2 +- hw/vfio/container.c | 34 ++++++++++++++------------- hw/vfio/iommufd.c | 8 +++---- 6 files changed, 42 insertions(+), 35 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 697bf24a35..efcba19f66 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -244,13 +244,15 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Err= or **errp); void vfio_migration_exit(VFIODevice *vbasedev); =20 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); -bool vfio_devices_all_running_and_mig_active(VFIOContainerBase *bcontainer= ); -bool vfio_devices_all_device_dirty_tracking(VFIOContainerBase *bcontainer); -int vfio_devices_query_dirty_bitmap(VFIOContainerBase *bcontainer, +bool +vfio_devices_all_running_and_mig_active(const VFIOContainerBase *bcontaine= r); +bool +vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer= ); +int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); -int vfio_get_dirty_bitmap(VFIOContainerBase *bcontainer, uint64_t iova, - uint64_t size, ram_addr_t ram_addr); +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, + uint64_t size, ram_addr_t ram_addr); =20 /* Returns 0 on success, or a negative errno. */ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 45bb19c767..2ae297ccda 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -82,7 +82,7 @@ void vfio_container_del_section_window(VFIOContainerBase = *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start); -int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer, +int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); =20 @@ -93,18 +93,20 @@ void vfio_container_destroy(VFIOContainerBase *bcontain= er); =20 struct VFIOIOMMUOps { /* basic feature */ - int (*dma_map)(VFIOContainerBase *bcontainer, + int (*dma_map)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); - int (*dma_unmap)(VFIOContainerBase *bcontainer, + int (*dma_unmap)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); int (*attach_device)(const char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); /* migration feature */ - int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool sta= rt); - int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *v= bmap, + int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, + bool start); + int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, + VFIOBitmap *vbmap, hwaddr iova, hwaddr size); /* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 6569732b7a..08a3e57672 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -204,7 +204,7 @@ static bool vfio_devices_all_dirty_tracking(VFIOContain= erBase *bcontainer) return true; } =20 -bool vfio_devices_all_device_dirty_tracking(VFIOContainerBase *bcontainer) +bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcont= ainer) { VFIODevice *vbasedev; =20 @@ -221,7 +221,8 @@ bool vfio_devices_all_device_dirty_tracking(VFIOContain= erBase *bcontainer) * Check if all VFIO devices are running and migration is active, which is * essentially equivalent to the migration being in pre-copy phase. */ -bool vfio_devices_all_running_and_mig_active(VFIOContainerBase *bcontainer) +bool +vfio_devices_all_running_and_mig_active(const VFIOContainerBase *bcontaine= r) { VFIODevice *vbasedev; =20 @@ -1139,7 +1140,7 @@ static int vfio_device_dma_logging_report(VFIODevice = *vbasedev, hwaddr iova, return 0; } =20 -int vfio_devices_query_dirty_bitmap(VFIOContainerBase *bcontainer, +int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size) { @@ -1162,7 +1163,7 @@ int vfio_devices_query_dirty_bitmap(VFIOContainerBase= *bcontainer, return 0; } =20 -int vfio_get_dirty_bitmap(VFIOContainerBase *bcontainer, uint64_t iova, +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, uint64_t size, ram_addr_t ram_addr) { bool all_device_dirty_tracking =3D diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index eee2dcfe76..1ffd25bbfa 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -63,7 +63,7 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerB= ase *bcontainer, return bcontainer->ops->set_dirty_page_tracking(bcontainer, start); } =20 -int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer, +int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size) { diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 1dbf9b9a17..b22feb8ded 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -61,11 +61,11 @@ static int vfio_ram_block_discard_disable(VFIOContainer= *container, bool state) } } =20 -static int vfio_dma_unmap_bitmap(VFIOContainer *container, +static int vfio_dma_unmap_bitmap(const VFIOContainer *container, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb) { - VFIOContainerBase *bcontainer =3D &container->bcontainer; + const VFIOContainerBase *bcontainer =3D &container->bcontainer; struct vfio_iommu_type1_dma_unmap *unmap; struct vfio_bitmap *bitmap; VFIOBitmap vbmap; @@ -117,11 +117,12 @@ unmap_exit: /* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ -static int vfio_legacy_dma_unmap(VFIOContainerBase *bcontainer, hwaddr iov= a, - ram_addr_t size, IOMMUTLBEntry *iotlb) +static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) { - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); + const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, + bcontainer); struct vfio_iommu_type1_dma_unmap unmap =3D { .argsz =3D sizeof(unmap), .flags =3D 0, @@ -174,11 +175,11 @@ static int vfio_legacy_dma_unmap(VFIOContainerBase *b= container, hwaddr iova, return 0; } =20 -static int vfio_legacy_dma_map(VFIOContainerBase *bcontainer, hwaddr iova, +static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr= iova, ram_addr_t size, void *vaddr, bool readonly) { - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); + const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, + bcontainer); struct vfio_iommu_type1_dma_map map =3D { .argsz =3D sizeof(map), .flags =3D VFIO_DMA_MAP_FLAG_READ, @@ -207,11 +208,12 @@ static int vfio_legacy_dma_map(VFIOContainerBase *bco= ntainer, hwaddr iova, return -errno; } =20 -static int vfio_legacy_set_dirty_page_tracking(VFIOContainerBase *bcontain= er, - bool start) +static int +vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, + bool start) { - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); + const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, + bcontainer); int ret; struct vfio_iommu_type1_dirty_bitmap dirty =3D { .argsz =3D sizeof(dirty), @@ -233,12 +235,12 @@ static int vfio_legacy_set_dirty_page_tracking(VFIOCo= ntainerBase *bcontainer, return ret; } =20 -static int vfio_legacy_query_dirty_bitmap(VFIOContainerBase *bcontainer, +static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontai= ner, VFIOBitmap *vbmap, hwaddr iova, hwaddr size) { - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); + const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, + bcontainer); struct vfio_iommu_type1_dirty_bitmap *dbitmap; struct vfio_iommu_type1_dirty_bitmap_get *range; int ret; diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 5accd26484..87a561c545 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -26,10 +26,10 @@ #include "qemu/chardev_open.h" #include "pci.h" =20 -static int iommufd_cdev_map(VFIOContainerBase *bcontainer, hwaddr iova, +static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr io= va, ram_addr_t size, void *vaddr, bool readonly) { - VFIOIOMMUFDContainer *container =3D + const VFIOIOMMUFDContainer *container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); =20 return iommufd_backend_map_dma(container->be, @@ -37,11 +37,11 @@ static int iommufd_cdev_map(VFIOContainerBase *bcontain= er, hwaddr iova, iova, size, vaddr, readonly); } =20 -static int iommufd_cdev_unmap(VFIOContainerBase *bcontainer, +static int iommufd_cdev_unmap(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb) { - VFIOIOMMUFDContainer *container =3D + const VFIOIOMMUFDContainer *container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer); =20 /* TODO: Handle dma_unmap_bitmap with iotlb args (migration) */ --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556577; cv=none; d=zohomail.com; s=zohoarc; b=KcClUpHpUGm45ZkN16ZxjjiIdPKOk3inpZ/7TJ/TmkC5/DIOmW3iXNukJufPjoVjhD2Aj185Tw2kNUrYzEGbEaDYsVQDqOHzk3/jC64q5fOy6/eweNnZ4c98gh61AvJdok885JosM5DOqUPs8eTOCnFG5ZTDQy6wppsFrETYKK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556577; 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=dPDJFdqR3Ya/3co0yMSVQ0gcSWC/z6/rRGj5fNgy0W0=; b=ZBo8NSVPz9WHCrF28WUVegeehDfVqP+066F86ckpu6MrEio/FuElw+OJCFoTdH2eIY7jRWxwme9nYWJMhQZWYmYHS5gih74GVLxWWWPb27FeCosEUv4YkqTu1wfZRlkR1V73iO+0pmnLwKeducrYua2aHeEmFClwzlltgELA3fg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556577256221.73002655373534; Tue, 21 Nov 2023 00:49:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQe-00015k-Ls; Tue, 21 Nov 2023 03:48: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 1r5MQO-0000nB-7e for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:06 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQL-0002Dg-FI for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:03 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:38 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556481; x=1732092481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GSHO0Us1hcaj4OATadcehVg7sx7bO0NWj/yAniD9gPg=; b=DS+EhkOgcNzhwtbiEi1xU+JC30061nvfzEH9Qm4WTjEAduY5cetESp6V SRuXd9Gk/gd4PYoxXZhkOYlEui0fwV7cCdwC8Gpp8Ta4ggdkAqSfQUAbo l3WOTP5CVRphVYbCeqNIVsy9IWff0etZmopulI2O2B4BeopwKlslCTldv ZiF9Jc8Yx5F1biQqOvYHIdIbMNnFidOyjYUPmeK2kpBd5f7pVRk2VWA7i DynbWTIf8FGojGdtk4WLLlRArJZhYzxZSGmRk7hCG8fmgUXoJqxVJWFap Litg7IAx9+ZOMEDWcTW0kEIA90NvbtDus88fRHKqHFxI4uL9wnWRUK6KP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722261" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722261" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125089" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125089" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 19/27] hw/arm: Activate IOMMUFD for virt machines Date: Tue, 21 Nov 2023 16:44:18 +0800 Message-Id: <20231121084426.1286987-20-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556579328100003 From: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Tested-by: Eric Auger Tested-by: Nicolin Chen --- hw/arm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 3ada335a24..660f49db49 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -8,6 +8,7 @@ config ARM_VIRT imply TPM_TIS_SYSBUS imply TPM_TIS_I2C imply NVDIMM + imply IOMMUFD select ARM_GIC select ACPI select ARM_SMMUV3 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556547; cv=none; d=zohomail.com; s=zohoarc; b=evR1O3Wckuc0aja307AQ/6GhZX5G9ekXcAYU1+lDZnv4R+izSlOqtypiK5XUQHBntyMGtkVCfeeVLeluk/9V0WLiEjiKHbveRiP6L3Y9+VIP6zDROHjkEh5AmSpwltjZe2f15Lr7Xfb1JZKQ273ormhP7oeYKkMqSnVP1Rpj2eA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556547; 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=opYwYh6o6xC0CBrpnuwNx5OjOf9BzEnRAl546p6jiVw=; b=kwAbaSgrxdnDx1EkvjNsooN7GT8sdt3gWmizgHj49jIhP+xrHeyPKewaAQ+RO3zMBRzODQ9qX08++lpLGmwXMpdsl52KpNKv7V2RhROLl2NZHq28lQ0nUGAjs4hemlducEqVbM8CngJWzGhskC3IY/4RNZ+F6ZOocqJH1OWcEDI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556547144298.06102598817233; Tue, 21 Nov 2023 00:49:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQk-0001yX-2g; Tue, 21 Nov 2023 03:48:26 -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 1r5MQX-0000xr-El for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:17 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQR-0002Ds-M6 for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:12 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:42 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556487; x=1732092487; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3VgUu1aR166z5MaIUW2c52jqW4WEIS7JPL5AeKsrx2c=; b=gcGZvR3dVup/GlBZ3uZFO187XIhcTlzXADH/84zCurauocKKipPA9aK9 Ogiyxzu3aiDlm2wRBYB8C113kmZTuj24hKz5LVp11V5slt2hq6AVetPGc bz+kqfNW5GxoJKuGs1y9bGDicRWoIGwUoWO2rcPBEa1pFbBpxMv36+aFj meXLEAAswsdcGT+UKKRPxAmyXwsuJCY48tGW8ZGcvX5HI5y0Ho6X9pA+V JdjQ5TkmCEhyzgpvTGF5V900/0wzM2InbGCgEGSo7lytWcG1adVKeK4Qc +ZiQGFxCveld0CqYryIrBWt0/pPegkm/yqWrn7jtNpUgVUpx1wa6p0igl A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722280" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722280" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125118" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125118" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 20/27] kconfig: Activate IOMMUFD for s390x machines Date: Tue, 21 Nov 2023 16:44:19 +0800 Message-Id: <20231121084426.1286987-21-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556548693100007 From: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Matthew Rosato Reviewed-by: Eric Farman Tested-by: Nicolin Chen --- hw/s390x/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 4c068d7960..26ad104485 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -6,6 +6,7 @@ config S390_CCW_VIRTIO imply VFIO_CCW imply WDT_DIAG288 imply PCIE_DEVICES + imply IOMMUFD select PCI_EXPRESS select S390_FLIC select S390_FLIC_KVM if KVM --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556651; cv=none; d=zohomail.com; s=zohoarc; b=A0iQ5FMT2Gc4lPzOGfYgt1aRzDYBqqSIIZ+l9MwQ1O/eF3HGK5SBNjc6zNwxc9gRf9twU/9NN7I14bBf9mu1LDv+Xlw0iAVSTCUd6xcD7AUtA86tUo1XSE9bTKigWitfBvjLTEIytyOMGb7XqEl52bKmpe925fX1+oG4TbVSE04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556651; 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=MS8IGTer9HohM4ZQ7xBEM78IYiceRBIJeVfkQARZwno=; b=ZyjT8MK/a+W+dVqc35w7wk+HXnt5RxwTSmvDYJzKP6WljC9ra2QUstpXq67TFG34RrcmOba7G8saoKyDzAvhNJ3LpLQQUm2ugi8SYXVycCrYLphOTlBg/tynnRWXa93BBIcYIFI0TdaRSw+nWXKdLaGsn3+4BGPL1VhVDZ5iadk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556651878238.48348512933865; Tue, 21 Nov 2023 00:50:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MR8-0004dk-77; Tue, 21 Nov 2023 03:48:50 -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 1r5MR6-0004T7-GE for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:48 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MR3-0002Dg-8N for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:48 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:46 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556525; x=1732092525; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CodAN8dAh5o4VK2f3gSAAb1kS5E0dAh3CSKbhh8sQBU=; b=m6vg02HejfWwRNsN/ZHV8p+xFG+Ihppm1rEBz9vm9VdHm1xgzSQ9Y7Dz yNRbfyfU7VKljafYzbd0zcT2zrX01cCw0DcfRGZmyJAN/UMiINPzU/Weu 9HD3oZAOvqHm8oq0PiwrfeJS3Ia9DL0Fl7vSRa7L0rCHbkBSK4q7cNb4y saW6LDjOV4vIM1cWAKdWLetoqh9OBSxLL5XVr1yqRs8YSG7i7q7XmRvnf RaoFUSo4HfKB4AWRqt8O3MxtexndLsJTz/Ujt7GGZUTfpJ6EZs9bTfBXl U7QYLm4J4mH5L6N6cDCGWpfkoVYtbfUJRyhKdihNpBIZfkY4u36+1iNpU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722289" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722289" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125140" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125140" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 21/27] hw/i386: Activate IOMMUFD for q35 machines Date: Tue, 21 Nov 2023 16:44:20 +0800 Message-Id: <20231121084426.1286987-22-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556652959100001 From: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Tested-by: Nicolin Chen --- hw/i386/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 55850791df..a1846be6f7 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -95,6 +95,7 @@ config Q35 imply E1000E_PCI_EXPRESS imply VMPORT imply VMMOUSE + imply IOMMUFD select PC_PCI select PC_ACPI select PCI_EXPRESS_Q35 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556548; cv=none; d=zohomail.com; s=zohoarc; b=g+HWuI3yJ0VTiwAkbZd0DE5TuZKQQH5vhsuiDswaYgtzTOEIWYuHiUvTij3Fp2qVhilvcVyuH+DLj7TJyh2OOL6kCQOCroHy6Eg5lUksFqGH4b9yBxn2vfBScM/J6hLhfGa3yqj06tmIqmFMZ8BmDZ5R1Y0gic5mmXJl0KvNays= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556548; 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=EHVl/CPEx1tfKp5nXiog8wCt+WlGuLoOzA8CwAA+pF0=; b=hSptAd7x+5Ck2L+FgxiaqRop9NP7fqZkzglYnclFKznIUDUwWX7e3PXSNPMOniTgvEAdJMIulHNVGZQgk4N4YYJ6uo6+sAIsRWYAAYbIXZ6Nce+3fo6OnYuxpYu7+vTjPlikYhISVFu51YxgX58geRmQZggvcT9l7ZpGqacz72w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556548077397.3126744480285; Tue, 21 Nov 2023 00:49:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQh-0001a1-Ga; Tue, 21 Nov 2023 03:48:24 -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 1r5MQd-0000zb-Cr for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:19 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQZ-0002Dl-SC for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:17 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:49 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:46 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556495; x=1732092495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sAeaLlOpv+KZAzUVgMMu6EKWOeoJE+9x1mOXczPlT4c=; b=ba/aWyKdWjOunImT6o5QlR/xuEsInx1QOXSADVdEb3ueyo4avISIUOoY d4m29bYTY+mLql23jH6PmbNQTXUnHeo8y/BkhQY98A5WOkS/xHXVTRkm/ /QhYeyEJQgjonWDQKIDRzOyesTQ6SrUG5OgSlsY8mhuic3UxArsRN8iS/ qETwPkkAe1qzZbV8xk5AWhxIiHwUs2oTiVOOUbD3CYAUnQ5Tq9SYUyJih nPvNABC/ZU409sWRVzfQfjTLtdVwnRvl351miZOc67MOagFQoediHz72C 6/JUYEH38NLqkgWA7HKSnLuKtCApb5gMaiS09LY9SczznGQuG8Elzl/c8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722304" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722304" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125170" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125170" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 22/27] vfio/pci: Move VFIODevice initializations in vfio_instance_init Date: Tue, 21 Nov 2023 16:44:21 +0800 Message-Id: <20231121084426.1286987-23-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556548697100008 Some of the VFIODevice initializations is in vfio_realize, move all of them in vfio_instance_init. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Nicolin Chen --- hw/vfio/pci.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 445d58c8e5..87405584d7 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2969,9 +2969,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) if (vfio_device_get_name(vbasedev, errp) < 0) { return; } - vbasedev->ops =3D &vfio_pci_ops; - vbasedev->type =3D VFIO_DEVICE_TYPE_PCI; - vbasedev->dev =3D DEVICE(vdev); =20 /* * Mediated devices *might* operate compatibly with discarding of RAM,= but @@ -3320,6 +3317,7 @@ static void vfio_instance_init(Object *obj) { PCIDevice *pci_dev =3D PCI_DEVICE(obj); VFIOPCIDevice *vdev =3D VFIO_PCI(obj); + VFIODevice *vbasedev =3D &vdev->vbasedev; =20 device_add_bootindex_property(obj, &vdev->bootindex, "bootindex", NULL, @@ -3328,7 +3326,11 @@ static void vfio_instance_init(Object *obj) vdev->host.bus =3D ~0U; vdev->host.slot =3D ~0U; vdev->host.function =3D ~0U; - vdev->vbasedev.fd =3D -1; + + vbasedev->type =3D VFIO_DEVICE_TYPE_PCI; + vbasedev->ops =3D &vfio_pci_ops; + vbasedev->dev =3D DEVICE(vdev); + vbasedev->fd =3D -1; =20 vdev->nv_gpudirect_clique =3D 0xFF; =20 --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556569; cv=none; d=zohomail.com; s=zohoarc; b=kgGx2hab45LQ4+KTq/MhVaZbvzuXTEA5pUWpnHf9TiBJxupIquUjx/O1AoxRiq7fIaF1Vaa2U8d+hk82RIMzWPZhkEoDZ0yNVPOLmbYa3M5GBvv2OxMw9+qDBr3WYu54Lw7jUhsoA13Qu5IuoG+HWmBuJZFNFPrPZzlxF9OlcMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556569; 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=fqKPGfZbMk/COBj4eOjHc4qOUUlmSbxVwDUFO+D3EPQ=; b=I3r+hLGOBzZI+ne8m2S3Vh/9WENbUrJIYCYriyR0WHhCyeKd5kbggtAMioycqByHaENX1hJXRPk8x082W0f7dgi8lM3+woCXcTCx15tulUTUEACA1VFqWYhOkDFUjhPJ/3beek469bWiryUrhkyzCI2QGUD1Lwd46uKotaImhy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556569635960.3783621529665; Tue, 21 Nov 2023 00:49:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQi-0001d8-Ty; Tue, 21 Nov 2023 03:48:24 -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 1r5MQd-0000zk-DM for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:19 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQZ-0002Dg-SI for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:17 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:58 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556495; x=1732092495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vBzP3WlnfEWRiydsgFq9tEsSz3B2gVoYx0Pa8U2lpLY=; b=U4k8NwIsN+QVaJyRkwZYbNkN0u1xkhoz3yI7HPmsRK2Unvt2FHmIIrrK yLDvecsvDnxSSV9sGHRoFKA0OkqMlJjjEUP3Q0W9TuyhYYZYMI08lEL7n j8a5KxtTJGD5UtQcTa16GWhCFqgU9rdZdwQ1ORk0mCFvj4ZGzap/GNw2v pJ/Gzgcy+VGmnNGHtssHgwtDRn21RucVU0lLh0xPfNAUpfQT+1/H6ype3 E6+TqTZ/PinL9ZvF6uy3MZa/mobMrPfyXAUbtQduSDUph17Rohrg48GRE gbxM0lyU810KMO3MxsH3N3FWGHLAuQHdUBq4ryJrrJ9bpfRxWkk872MNM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722314" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722314" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125200" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125200" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 23/27] vfio/platform: Move VFIODevice initializations in vfio_platform_instance_init Date: Tue, 21 Nov 2023 16:44:22 +0800 Message-Id: <20231121084426.1286987-24-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556571129100009 Some of the VFIODevice initializations is in vfio_platform_realize, move all of them in vfio_platform_instance_init. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Nicolin Chen --- hw/vfio/platform.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index a97d9c6234..506eb8193f 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -581,10 +581,6 @@ static void vfio_platform_realize(DeviceState *dev, Er= ror **errp) VFIODevice *vbasedev =3D &vdev->vbasedev; int i, ret; =20 - vbasedev->type =3D VFIO_DEVICE_TYPE_PLATFORM; - vbasedev->dev =3D dev; - vbasedev->ops =3D &vfio_platform_ops; - qemu_mutex_init(&vdev->intp_mutex); =20 trace_vfio_platform_realize(vbasedev->sysfsdev ? @@ -659,8 +655,12 @@ static Property vfio_platform_dev_properties[] =3D { static void vfio_platform_instance_init(Object *obj) { VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(obj); + VFIODevice *vbasedev =3D &vdev->vbasedev; =20 - vdev->vbasedev.fd =3D -1; + vbasedev->type =3D VFIO_DEVICE_TYPE_PLATFORM; + vbasedev->ops =3D &vfio_platform_ops; + vbasedev->dev =3D DEVICE(vdev); + vbasedev->fd =3D -1; } =20 #ifdef CONFIG_IOMMUFD --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556553; cv=none; d=zohomail.com; s=zohoarc; b=UTA3qBrB3uepacRr3CFQ56QzCgimSvYqUqV4oi0OD9ZJaTFG5DusdhJFQu0Qtsux+tDrhxP84hfVoHKdgjK/WyIDzPi7A7kcqe/p3KGgzA6eNP8zDlpzQlXJz2Ys6us39I0fhWXt64j3wyOvq200iMT7PRb7pLVmIl0mZDR+uT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556553; 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=ezNSIv9TAaywURG/H3zZfQYAh4vldiNjQzmdPi94HBc=; b=gYYPyqK2wqn/DhHkC4dThw0ZWkdBUBwx2Jj9GC6BguAv2Ep0bCx+9Inkfxy3tjXcVS/BuBU40G05Wy0+t6HaJbmC8EOVkTWyQFt21p81Fluwj081AU305XsYLdog2rjUaYZRTt+TykMXql3E9pHIUexOUAxnN4AQ5hB3ZvoHVn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556553015539.635474241365; Tue, 21 Nov 2023 00:49:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MQl-0002AW-4b; Tue, 21 Nov 2023 03:48:27 -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 1r5MQj-0001yw-Uo for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:25 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MQi-0002Ds-5W for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:25 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:01 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:47:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556504; x=1732092504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=perSvVuLH99R5mxqXjaeWDoIbXt+QU64r+kPU7JyJSo=; b=B8w9XYwcCKIA/7hVexVarxvKWb4azAmlqdE75TMDhfEcK5VTi89VQlKI gRwCNLfk6kwgLKPJqaf5H7K3cApkcfeK6OKe+2SJkLRkpdAb+N5VttpLi aqcP775OYuXfKm3Ii/hjuMd9g6jhUGDZPsxsA7+btwyiJ591ZsNkWz+BU rEDky2U//5A9EKTeGKyCL1chHKfv5Q7IzQxuYxiglvupoMh/kckUfLVWL brlSHZFSF3+Vb7x9G6WGS6CwDsZQbc5ri6emtid6rp+FadXkz+CSUHISm NId/O3S3pXk7Lpha9KHk7L5C4+k/KPnE3gGFk8ip2G/FNlrwKl5L8nDdR g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722329" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722329" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125223" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125223" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 24/27] vfio/ap: Move VFIODevice initializations in vfio_ap_instance_init Date: Tue, 21 Nov 2023 16:44:23 +0800 Message-Id: <20231121084426.1286987-25-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556554771100003 Some of the VFIODevice initializations is in vfio_ap_realize, move all of them in vfio_ap_instance_init. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Farman Tested-by: Nicolin Chen --- hw/vfio/ap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index f180e4a32a..95fe7cd98b 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -164,18 +164,6 @@ static void vfio_ap_realize(DeviceState *dev, Error **= errp) return; } =20 - vbasedev->ops =3D &vfio_ap_ops; - vbasedev->type =3D VFIO_DEVICE_TYPE_AP; - vbasedev->dev =3D dev; - - /* - * vfio-ap devices operate in a way compatible with discarding of - * memory in RAM blocks, as no pages are pinned in the host. - * This needs to be set before vfio_get_device() for vfio common to - * handle ram_block_discard_disable(). - */ - vapdev->vdev.ram_block_discard_allowed =3D true; - ret =3D vfio_attach_device(vbasedev->name, vbasedev, &address_space_memory, errp); if (ret) { @@ -236,8 +224,20 @@ static const VMStateDescription vfio_ap_vmstate =3D { static void vfio_ap_instance_init(Object *obj) { VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(obj); + VFIODevice *vbasedev =3D &vapdev->vdev; =20 - vapdev->vdev.fd =3D -1; + vbasedev->type =3D VFIO_DEVICE_TYPE_AP; + vbasedev->ops =3D &vfio_ap_ops; + vbasedev->dev =3D DEVICE(vapdev); + vbasedev->fd =3D -1; + + /* + * vfio-ap devices operate in a way compatible with discarding of + * memory in RAM blocks, as no pages are pinned in the host. + * This needs to be set before vfio_get_device() for vfio common to + * handle ram_block_discard_disable(). + */ + vbasedev->ram_block_discard_allowed =3D true; } =20 #ifdef CONFIG_IOMMUFD --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556606; cv=none; d=zohomail.com; s=zohoarc; b=mexKcPihP7cOdZCE4tVkSlLMelHGYflyybPJbjx1twKpi92SZhzyw2PNA2vPlzDriPqzJ+oFNs3WEzjt4ylED7C02tViISFEXIDlQWHyxSyEDra7CFxLjb4T00EwJUIFY3W1e+790zWtL9jHS2LO2byrUUjXSOc7ltiKML6CKvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556606; 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=Nm9GfJ3fTyPm/DIISSugO3M4JTe0P/nGZL88XmdEp3Y=; b=XRnzPojU0gtJsgh0Afb/RpCsuIjVfRvrmTQT1/HEcRJwkRqU0Zf9qdvo2e29CzEF6NDCvUWvuul41qgzhTL0bCgKKc2+wBJoPjJBupnNEwa+XnbQboEhRFlxW09VxeG2OZjiUefsWipmFeSLdgAwiuts+dx28pAqF55iVHrGmmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556606187904.8473264586579; Tue, 21 Nov 2023 00:50:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MR6-0004W6-Ty; Tue, 21 Nov 2023 03:48:48 -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 1r5MR5-0004LM-Im for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:47 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MR3-0002Dl-8M for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:47 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:03 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556525; x=1732092525; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HOrhtKWR9cVgHhnV/ZX7kzUMPFVOZ7WTSbkhyX3ZwQ0=; b=Z/BZvSZdnbnz1VMI2fBABylpi94+BPRN2goQg0hxrK8tt3+eHReNU40s mbTFem50cuQZ7mOSd5KzaAgGViobyNzPzMNpCeiuKWK4NsbD0slpp8fDT GEQuVfAcXq62FzsPeMXOZHwFhAKjnuI/v1a+4TRIfVyDmSutStpQ/EVb4 Zv5NI4crw3DDSBKnm/HU66+/zE5Q4yWNf/86rLf0g/k61n+FVMzD1/hVd t4XkRCZZ61XjmMSgVdAeiTtiyBGouFe8YirYa7E5MZIb/x5hw5kjo2Fzi CqgfRPsJWbLZNoS7GxqQJUdVSWfmqeH2QCpwAp/K3HxlmXqU3+Apqq2oM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722338" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722338" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125246" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125246" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 25/27] vfio/ccw: Move VFIODevice initializations in vfio_ccw_instance_init Date: Tue, 21 Nov 2023 16:44:24 +0800 Message-Id: <20231121084426.1286987-26-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556607890100003 Some of the VFIODevice initializations is in vfio_ccw_realize, move all of them in vfio_ccw_instance_init. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Farman Tested-by: Nicolin Chen --- hw/vfio/ccw.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 2afdf17dbe..6305a4c1b8 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -594,20 +594,6 @@ static void vfio_ccw_realize(DeviceState *dev, Error *= *errp) return; } =20 - vbasedev->ops =3D &vfio_ccw_ops; - vbasedev->type =3D VFIO_DEVICE_TYPE_CCW; - vbasedev->dev =3D dev; - - /* - * All vfio-ccw devices are believed to operate in a way compatible wi= th - * discarding of memory in RAM blocks, ie. pages pinned in the host are - * in the current working set of the guest driver and therefore never - * overlap e.g., with pages available to the guest balloon driver. Th= is - * needs to be set before vfio_get_device() for vfio common to handle - * ram_block_discard_disable(). - */ - vbasedev->ram_block_discard_allowed =3D true; - ret =3D vfio_attach_device(cdev->mdevid, vbasedev, &address_space_memory, errp); if (ret) { @@ -695,8 +681,22 @@ static const VMStateDescription vfio_ccw_vmstate =3D { static void vfio_ccw_instance_init(Object *obj) { VFIOCCWDevice *vcdev =3D VFIO_CCW(obj); + VFIODevice *vbasedev =3D &vcdev->vdev; + + vbasedev->type =3D VFIO_DEVICE_TYPE_CCW; + vbasedev->ops =3D &vfio_ccw_ops; + vbasedev->dev =3D DEVICE(vcdev); + vbasedev->fd =3D -1; =20 - vcdev->vdev.fd =3D -1; + /* + * All vfio-ccw devices are believed to operate in a way compatible wi= th + * discarding of memory in RAM blocks, ie. pages pinned in the host are + * in the current working set of the guest driver and therefore never + * overlap e.g., with pages available to the guest balloon driver. Th= is + * needs to be set before vfio_get_device() for vfio common to handle + * ram_block_discard_disable(). + */ + vbasedev->ram_block_discard_allowed =3D true; } =20 #ifdef CONFIG_IOMMUFD --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556564; cv=none; d=zohomail.com; s=zohoarc; b=ic+Be5qH5qbAUnCNRwUbamHCoH4z2BPtscXcUFVLMbdL+n3BZit/yHx4dkWSRuLJutWpMvzLr8flDwqTDm1o3EPP1q7ezHadGmxL0t06GxHsk1bCyvPVuReSN+WvOyShDOanqa/u9fLNIUspxgxsYk5MtEXB/mzH6iaodwyGeQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556564; 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=7q2YeujZprEx/DdzDCVBGVZQnPaDWCe5awrtv0Twjxg=; b=WEAEqqsBB9ohUBr2luYqJa3fdTfFQk84aQq9OIYC29T4Iuvlg7tbKVK5X+Dbv9fCxNEA7FmSLs2UeffGy6urQR3SFqhOa1izvsCvkATaA26pKri8wWYCINtCGJF0Ht0BZgvY9ctdb10M1zWoOPU/2wlDtM11v1YmNpz/CajN1WE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556564914213.35172642777547; Tue, 21 Nov 2023 00:49:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MRA-000568-TI; Tue, 21 Nov 2023 03:48:52 -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 1r5MR9-0004rd-MK for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:51 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MR4-0002Ds-GR for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:51 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:08 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:03 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556526; x=1732092526; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oKZBGGkUtxu2p8MQLrsT6cVzGhVGmAT6MNDAIu8FKOk=; b=fFTk6ItfxCY8fJpr99vOwUhbR85TIzHjykdbUc2qI2/y+4apIP97PW/F QpqC6vPAK6YVT6n4sGeeZbh8pBFxO6APDTK2eFDzeVCElf1pZEu4iGm9G 0h2LQz/q8i2A+A1lYEKlQSdozlDkIuWyMuaUEnuYPQK0/tNzPLPLWO5kq xNp5bzWzn5iQ5cXxQCp/k/uhqX1G0A1GJudPsU+9ewZRyG2S69zketcTX saq/GN3/glcX/tsXGYdV/LSX70N1qaOH0ADekpmb75BLA0+tp18jTg7D/ yo2Zf7sGmSS9v5DKHqhxwGr2+s+mHm9nC64JJNekVULbLv/22Y3217l7U g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722359" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722359" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125266" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125266" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 26/27] vfio: Introduce a helper function to initialize VFIODevice Date: Tue, 21 Nov 2023 16:44:25 +0800 Message-Id: <20231121084426.1286987-27-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556567019100001 Introduce a helper function to replace the common code to initialize VFIODevice in pci, platform, ap and ccw VFIO device. No functional change intended. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Tested-by: Nicolin Chen --- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/ap.c | 8 ++------ hw/vfio/ccw.c | 8 ++------ hw/vfio/helpers.c | 11 +++++++++++ hw/vfio/pci.c | 6 ++---- hw/vfio/platform.c | 6 ++---- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index efcba19f66..b8aa8a5495 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -257,4 +257,6 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, /* Returns 0 on success, or a negative errno. */ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p); +void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, + DeviceState *dev, bool ram_discard); #endif /* HW_VFIO_VFIO_COMMON_H */ diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 95fe7cd98b..e157aa1ff7 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -226,18 +226,14 @@ static void vfio_ap_instance_init(Object *obj) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(obj); VFIODevice *vbasedev =3D &vapdev->vdev; =20 - vbasedev->type =3D VFIO_DEVICE_TYPE_AP; - vbasedev->ops =3D &vfio_ap_ops; - vbasedev->dev =3D DEVICE(vapdev); - vbasedev->fd =3D -1; - /* * vfio-ap devices operate in a way compatible with discarding of * memory in RAM blocks, as no pages are pinned in the host. * This needs to be set before vfio_get_device() for vfio common to * handle ram_block_discard_disable(). */ - vbasedev->ram_block_discard_allowed =3D true; + vfio_device_init(vbasedev, VFIO_DEVICE_TYPE_AP, &vfio_ap_ops, + DEVICE(vapdev), true); } =20 #ifdef CONFIG_IOMMUFD diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 6305a4c1b8..90e4a53437 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -683,11 +683,6 @@ static void vfio_ccw_instance_init(Object *obj) VFIOCCWDevice *vcdev =3D VFIO_CCW(obj); VFIODevice *vbasedev =3D &vcdev->vdev; =20 - vbasedev->type =3D VFIO_DEVICE_TYPE_CCW; - vbasedev->ops =3D &vfio_ccw_ops; - vbasedev->dev =3D DEVICE(vcdev); - vbasedev->fd =3D -1; - /* * All vfio-ccw devices are believed to operate in a way compatible wi= th * discarding of memory in RAM blocks, ie. pages pinned in the host are @@ -696,7 +691,8 @@ static void vfio_ccw_instance_init(Object *obj) * needs to be set before vfio_get_device() for vfio common to handle * ram_block_discard_disable(). */ - vbasedev->ram_block_discard_allowed =3D true; + vfio_device_init(vbasedev, VFIO_DEVICE_TYPE_CCW, &vfio_ccw_ops, + DEVICE(vcdev), true); } =20 #ifdef CONFIG_IOMMUFD diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 3592c3d54e..6789870802 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -652,3 +652,14 @@ void vfio_device_set_fd(VFIODevice *vbasedev, const ch= ar *str, Error **errp) } vbasedev->fd =3D fd; } + +void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, + DeviceState *dev, bool ram_discard) +{ + vbasedev->type =3D type; + vbasedev->ops =3D ops; + vbasedev->dev =3D dev; + vbasedev->fd =3D -1; + + vbasedev->ram_block_discard_allowed =3D ram_discard; +} diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 87405584d7..1874ec1aba 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3327,10 +3327,8 @@ static void vfio_instance_init(Object *obj) vdev->host.slot =3D ~0U; vdev->host.function =3D ~0U; =20 - vbasedev->type =3D VFIO_DEVICE_TYPE_PCI; - vbasedev->ops =3D &vfio_pci_ops; - vbasedev->dev =3D DEVICE(vdev); - vbasedev->fd =3D -1; + vfio_device_init(vbasedev, VFIO_DEVICE_TYPE_PCI, &vfio_pci_ops, + DEVICE(vdev), false); =20 vdev->nv_gpudirect_clique =3D 0xFF; =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 506eb8193f..a8d9b7da63 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -657,10 +657,8 @@ static void vfio_platform_instance_init(Object *obj) VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(obj); VFIODevice *vbasedev =3D &vdev->vbasedev; =20 - vbasedev->type =3D VFIO_DEVICE_TYPE_PLATFORM; - vbasedev->ops =3D &vfio_platform_ops; - vbasedev->dev =3D DEVICE(vdev); - vbasedev->fd =3D -1; + vfio_device_init(vbasedev, VFIO_DEVICE_TYPE_PLATFORM, &vfio_platform_o= ps, + DEVICE(vdev), false); } =20 #ifdef CONFIG_IOMMUFD --=20 2.34.1 From nobody Fri May 17 13:05:20 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700556550; cv=none; d=zohomail.com; s=zohoarc; b=iF18E7s+KM0FP/jgfU6bm/w/bY9awORunqh5SWMCYIZqBzce2E7qQad83OaarFyKd/E/kt9stxrpd//tHKgOIJXwR4rpcFzC3+D3otrgKZmImZt0glZSU0Gt0RDkS0RPe8axPLu7Z6SOeinRRTmc3EE8sb2z0DvY+dV28LN60bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700556550; 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=7gKVXg/tRXfCjI+CEebgPhIhJJwHhHKiogZ73Ao3l/E=; b=MT0nPyI8t/5lXiU1kKn7VLA6LaC1E6SaKC86bc1Mn73yrEVlI2bpQGT1N+JpSrHZDLV8YD1L39sBl8TMztErJpLkfUa5EM01pt9wqW0IauKRC0wQtv2C1OBPK5ijq/9JQGqfHYvXELGzGaxVzaYmGc0keb8VuHy7Mg2wrmgZScY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700556550317762.1256881319098; Tue, 21 Nov 2023 00:49:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5MR9-0004oO-BR; Tue, 21 Nov 2023 03:48:51 -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 1r5MR8-0004fM-9m for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:50 -0500 Received: from mgamail.intel.com ([134.134.136.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5MR6-0002Dl-0v for qemu-devel@nongnu.org; Tue, 21 Nov 2023 03:48:49 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:15 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.124]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2023 00:48:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700556528; x=1732092528; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kQ9IDrP9QE9vNS1P0Ei1YI0Qvu8bWOKghkTr3//VaAQ=; b=K3i+22e/4Fo0378hAmF1z72GDxHaqM5nvqC462304ajBQYEXtHze03AQ yEa0v0b+TRjftHKX31KuutQfTc/9Z91b+GSsFBK4kTmwNRHLdWMm1b2Lb FaBYK/CYW6VhXYi+gYCAFxtmjrUgnxrNGe6sbm4WPyS3dSiPV62W3kb/X xybdGDnyzoEBjwupMwecLcEBv5zVJYSafoE3kiRwKaF7V1nwmqHM4NoLI jzM0i8vp16IcAbD9nL14fXUZe6uku5Ck2m1XfM8HmZa110ujXOMJLZVNk RaVXEKAiDQh/hfwV7bX/aYdAIQLjkcPR8eNd9v821yIa5djjy6Z/gVBVx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395722394" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395722394" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884125290" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884125290" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com Subject: [PATCH v7 27/27] docs/devel: Add VFIO iommufd backend documentation Date: Tue, 21 Nov 2023 16:44:26 +0800 Message-Id: <20231121084426.1286987-28-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121084426.1286987-1-zhenzhong.duan@intel.com> References: <20231121084426.1286987-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.65; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700556550753100018 Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Nicolin Chen --- MAINTAINERS | 1 + docs/devel/index-internals.rst | 1 + docs/devel/vfio-iommufd.rst | 166 +++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 docs/devel/vfio-iommufd.rst diff --git a/MAINTAINERS b/MAINTAINERS index ca70bb4e64..0ddb20a35f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2176,6 +2176,7 @@ 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 =20 vhost M: Michael S. Tsirkin diff --git a/docs/devel/index-internals.rst b/docs/devel/index-internals.rst index 6f81df92bc..3def4a138b 100644 --- a/docs/devel/index-internals.rst +++ b/docs/devel/index-internals.rst @@ -18,5 +18,6 @@ Details about QEMU's various subsystems including how to = add features to them. s390-dasd-ipl tracing vfio-migration + vfio-iommufd writing-monitor-commands virtio-backends diff --git a/docs/devel/vfio-iommufd.rst b/docs/devel/vfio-iommufd.rst new file mode 100644 index 0000000000..3d1c11f175 --- /dev/null +++ b/docs/devel/vfio-iommufd.rst @@ -0,0 +1,166 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D +IOMMUFD BACKEND usage with VFIO +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +(Same meaning for backend/container/BE) + +With the introduction of iommufd, the Linux kernel provides a generic +interface for user space drivers to propagate their DMA mappings to kernel +for assigned devices. While the legacy kernel interface is group-centric, +the new iommufd interface is device-centric, relying on device fd and iomm= ufd. + +To support both interfaces in the QEMU VFIO device, introduce a base conta= iner +to abstract the common part of VFIO legacy and iommufd container. So that = the +generic VFIO code can use either container. + +The base container implements generic functions such as memory_listener and +address space management whereas the derived container implements callbacks +specific to either legacy or iommufd. Each container has its own way to se= tup +secure context and dma management interface. The below diagram shows how it +looks like with both containers. + +:: + + VFIO AddressSpace/Memory + +-------+ +----------+ +-----+ +-----+ + | pci | | platform | | ap | | ccw | + +---+---+ +----+-----+ +--+--+ +--+--+ +---------------------= -+ + | | | | | AddressSpace = | + | | | | +------------+--------= -+ + +---V-----------V-----------V--------V----+ / + | VFIOAddressSpace | <------------+ + | | | MemoryListener + | VFIOContainerBase list | + +-------+----------------------------+----+ + | | + | | + +-------V------+ +--------V----------+ + | iommufd | | vfio legacy | + | container | | container | + +-------+------+ +--------+----------+ + | | + | /dev/iommu | /dev/vfio/vfio + | /dev/vfio/devices/vfioX | /dev/vfio/$group_id + Userspace | | + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + Kernel | device fd | + +---------------+ | group/container fd + | (BIND_IOMMUFD | | (SET_CONTAINER/SET_IOMMU) + | ATTACH_IOAS) | | device fd + | | | + | +-------V------------V-----------------+ + iommufd | | vfio | + (map/unmap | +---------+--------------------+-------+ + ioas_copy) | | | map/unmap + | | | + +------V------+ +-----V------+ +------V--------+ + | iommfd core | | device | | vfio iommu | + +-------------+ +------------+ +---------------+ + +* Secure Context setup + + - iommufd BE: uses device fd and iommufd to setup secure context + (bind_iommufd, attach_ioas) + - vfio legacy BE: uses group fd and container fd to setup secure context + (set_container, set_iommu) + +* Device access + + - iommufd BE: device fd is opened through ``/dev/vfio/devices/vfioX`` + - vfio legacy BE: device fd is retrieved from group fd ioctl + +* DMA Mapping flow + + 1. VFIOAddressSpace receives MemoryRegion add/del via MemoryListener + 2. VFIO populates DMA map/unmap via the container BEs + * iommufd BE: uses iommufd + * vfio legacy BE: uses container fd + +Example configuration +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Step 1: configure the host device +--------------------------------- + +It's exactly same as the VFIO device with legacy VFIO container. + +Step 2: configure QEMU +---------------------- + +Interactions with the ``/dev/iommu`` are abstracted by a new iommufd +object (compiled in with the ``CONFIG_IOMMUFD`` option). + +Any QEMU device (e.g. VFIO device) wishing to use ``/dev/iommu`` must +be linked with an iommufd object. It gets a new optional property +named iommufd which allows to pass an iommufd object. Take ``vfio-pci`` +device for example: + +.. code-block:: bash + + -object iommufd,id=3Diommufd0 + -device vfio-pci,host=3D0000:02:00.0,iommufd=3Diommufd0 + +Note the ``/dev/iommu`` and VFIO cdev can be externally opened by a +management layer. In such a case the fd is passed, the fd supports a +string naming the fd or a number, for example: + +.. code-block:: bash + + -object iommufd,id=3Diommufd0,fd=3D22 + -device vfio-pci,iommufd=3Diommufd0,fd=3D23 + +If the ``fd`` property is not passed, the fd is opened by QEMU. + +If no ``iommufd`` object is passed to the ``vfio-pci`` device, iommufd +is not used and the user gets the behavior based on the legacy VFIO +container: + +.. code-block:: bash + + -device vfio-pci,host=3D0000:02:00.0 + +Supported platform +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Supports x86, ARM and s390x currently. + +Caveats +=3D=3D=3D=3D=3D=3D=3D + +Dirty page sync +--------------- + +Dirty page sync with iommufd backend is unsupported yet, live migration is +disabled by default. But it can be force enabled like below, low efficient +though. + +.. code-block:: bash + + -object iommufd,id=3Diommufd0 + -device vfio-pci,host=3D0000:02:00.0,iommufd=3Diommufd0,enable-migrati= on=3Don + +P2P DMA +------- + +PCI p2p DMA is unsupported as IOMMUFD doesn't support mapping hardware PCI +BAR region yet. Below warning shows for assigned PCI device, it's not a bu= g. + +.. code-block:: none + + qemu-system-x86_64: warning: IOMMU_IOAS_MAP failed: Bad address, PCI B= AR? + qemu-system-x86_64: vfio_container_dma_map(0x560cb6cb1620, 0xe00000002= 1000, 0x3000, 0x7f32ed55c000) =3D -14 (Bad address) + +FD passing with mdev +-------------------- + +``vfio-pci`` device checks sysfsdev property to decide if backend is a mde= v. +If FD passing is used, there is no way to know that and the mdev is treated +like a real PCI device. There is an error as below if user wants to enable +RAM discarding for mdev. + +.. code-block:: none + + qemu-system-x86_64: -device vfio-pci,iommufd=3Diommufd0,x-balloon-allo= wed=3Don,fd=3D9: vfio VFIO_FD9: x-balloon-allowed only potentially compatib= le with mdev devices + +``vfio-ap`` and ``vfio-ccw`` devices don't have same issue as their backend +devices are always mdev and RAM discarding is force enabled. --=20 2.34.1