From nobody Mon Nov 25 00:27:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719264487; cv=none; d=zohomail.com; s=zohoarc; b=nHJfGvwER62jHyV8/LRXRA65USsve70Hymerdsik8yPTFqN6GylvyF0qx05VAE4bDyCXkjTrO3VV6nJtk60ZrKi9H8lo2e4/ZqivzjLS0cqggLWT490HMC0DKo53Gxm+j0Vi5H86Eow00I4CT936MFrwjjWjCS/w5nvxF8PxK/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719264487; 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=uWZUFH399R3jvuU736nZsTHLsrSUdILRBi4uLzYr0eU=; b=Q6x3iuo3drEIr/r3sR22/PLxNfPtvPHGHtkxPH/65osG5i5R7tiVXYbgocGcBlqab/geNzZjMM0w2D3Qw1pAHE55hSYano2yPC3J/k5aggu0e6mf85XXlyim1ypVi3hWrp1jWftrWC3X6P5dW4zQbhjTHvse/VpmBsvgaW8bM6Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719264487110761.3537595688894; Mon, 24 Jun 2024 14:28:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLrC8-0003At-GR; Mon, 24 Jun 2024 17:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLrC6-00035h-GO for qemu-devel@nongnu.org; Mon, 24 Jun 2024 17:25:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLrC4-0006fa-Ur for qemu-devel@nongnu.org; Mon, 24 Jun 2024 17:25:46 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-487-7XyedHNbMJWCNdTHUexc1g-1; Mon, 24 Jun 2024 17:25:40 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6D35195609F; Mon, 24 Jun 2024 21:25:39 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.49]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8456D1956053; Mon, 24 Jun 2024 21:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719264344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uWZUFH399R3jvuU736nZsTHLsrSUdILRBi4uLzYr0eU=; b=ER7x1xaDAlLI+A8qg/4WEkBDaqlWm6dzV1n2CT0DxNH4yhMv0hGodyFcHgwrg8JQgx4F+b Aa4KZq6RIXucbY1XZqASMtYZT33uwAwSI9ZstzQkpiisYn83iOtQd+S+b8gWUDWMjwD5Rk 2aXt/4xkVBN9ekyrdS9hU7f4/5q6gTc= X-MC-Unique: 7XyedHNbMJWCNdTHUexc1g-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Yi Liu , Nicolin Chen , Yi Sun , Eric Auger , "Michael S . Tsirkin" Subject: [PULL 14/42] vfio/pci: Pass HostIOMMUDevice to vIOMMU Date: Mon, 24 Jun 2024 23:24:28 +0200 Message-ID: <20240624212456.350919-15-clg@redhat.com> In-Reply-To: <20240624212456.350919-1-clg@redhat.com> References: <20240624212456.350919-1-clg@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.207, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719264488349100001 Content-Type: text/plain; charset="utf-8" From: Zhenzhong Duan With HostIOMMUDevice passed, vIOMMU can check compatibility with host IOMMU, call into IOMMUFD specific methods, etc. Originally-by: Yi Liu Signed-off-by: Nicolin Chen Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Eric Auger Reviewed-by: Michael S. Tsirkin --- hw/vfio/pci.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 74a79bdf61f9aeb4860d532b6c076dd3491dd0ab..d8a76c1ee003e6f5669e8390271= 836fd9d839a8a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3121,10 +3121,15 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) =20 vfio_bars_register(vdev); =20 - if (!vfio_add_capabilities(vdev, errp)) { + if (!pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) { + error_prepend(errp, "Failed to set iommu_device: "); goto out_teardown; } =20 + if (!vfio_add_capabilities(vdev, errp)) { + goto out_unset_idev; + } + if (vdev->vga) { vfio_vga_quirk_setup(vdev); } @@ -3141,7 +3146,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) error_setg(errp, "cannot support IGD OpRegion feature on hotplugged " "device"); - goto out_teardown; + goto out_unset_idev; } =20 ret =3D vfio_get_dev_region_info(vbasedev, @@ -3150,11 +3155,11 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) if (ret) { error_setg_errno(errp, -ret, "does not support requested IGD OpRegion feat= ure"); - goto out_teardown; + goto out_unset_idev; } =20 if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) { - goto out_teardown; + goto out_unset_idev; } } =20 @@ -3238,6 +3243,8 @@ out_deregister: if (vdev->intx.mmap_timer) { timer_free(vdev->intx.mmap_timer); } +out_unset_idev: + pci_device_unset_iommu_device(pdev); out_teardown: vfio_teardown_msi(vdev); vfio_bars_exit(vdev); @@ -3266,6 +3273,7 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); + VFIODevice *vbasedev =3D &vdev->vbasedev; =20 vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); @@ -3280,7 +3288,8 @@ static void vfio_exitfn(PCIDevice *pdev) vfio_teardown_msi(vdev); vfio_pci_disable_rp_atomics(vdev); vfio_bars_exit(vdev); - vfio_migration_exit(&vdev->vbasedev); + vfio_migration_exit(vbasedev); + pci_device_unset_iommu_device(pdev); } =20 static void vfio_pci_reset(DeviceState *dev) --=20 2.45.2