From nobody Tue Nov 26 18:48:27 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=1705478736; cv=none; d=zohomail.com; s=zohoarc; b=RP0pRl/eKId0O0duSQi/IeiS/4jdMn9nx5Fg4wPiH/dfYVZzZtfBlpBNF2r+jbFT4ve6isJQEo/m5k9XHeXFxa8tP8yqGb7Hk5RlgRpvFgjLFYjWFWw2Y7bbqLsLvy7RJWMmFDwbpKozUyWJNJ19dRnqHpCv+ON60BfsdVHYGOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478736; 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=w3CdxFmDkghBhZU+EeJss4FDl+MilK9UCJU2qsqidD0=; b=M9fObHb5Ut3ETDWl468CkdQXIiBC829mlJ1i95RIaGe3TUqVjGOIXcNJ5S9npkYc+d4EcnGp4CB6OGW9OLTzYxmQ+GgpERwZtfPDEITbY0GsMkvdcSHo36HF7+oWU3n0DmAFlJvD5mfdEZogTNgQZ81PZ08HhHLYVJScPfFLCMU= 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 1705478736737103.54609390186295; Wed, 17 Jan 2024 00:05:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0ui-0002EE-3q; Wed, 17 Jan 2024 03:04:44 -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 1rQ0ud-000295-Vi for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:40 -0500 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 1rQ0ua-00033B-4h for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:39 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-kKPI23l6N-aYcSqG6ds7qQ-1; Wed, 17 Jan 2024 03:04:27 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 379383815F8D; Wed, 17 Jan 2024 08:04:27 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id C666BFFF3; Wed, 17 Jan 2024 08:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478670; 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=w3CdxFmDkghBhZU+EeJss4FDl+MilK9UCJU2qsqidD0=; b=GpMn11dGBCGUSSfyNwgozyLcno+gmbZkBNF82LdcLwB750dxfFt8Ud4Fjmi8z1CVrpLWCG Im0+bDfu/KhooDSKLG31gKP+zHs9160euMOfE7rejnwmLYCLwZRTKXuBSZIoSHanbI0NnE itiyb3My8ji8qxYSkPKQPhXn5OtrMTI= X-MC-Unique: kKPI23l6N-aYcSqG6ds7qQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 1/7] hw/pci: Introduce PCIIOMMUOps::set_host_iova_regions Date: Wed, 17 Jan 2024 09:02:05 +0100 Message-ID: <20240117080414.316890-2-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705478738662100003 Content-Type: text/plain; charset="utf-8" This new callback will be used to convey usable IOVA regions from VFIO-PCI devices to vIOMMUS (esp. virtio-iommu). The advantage is that this callback can be called very early, once the device has is known to be protected by a vIOMMU, after the get_address_space() has been called by the parent device. Current solution to convey IOVA regions relies on IOMMU MR callbacks but this requires an IOMMU MR to be connected with the VFIO-PCI device which generally comes with the enablement of the IOMMU MR (vIOMMU protection activated). The downside is that is comes pretty late and in case of virtio-iommu, after the probe. Signed-off-by: Eric Auger --- include/hw/pci/pci.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index fa6313aabc..63c018b35a 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -385,6 +385,21 @@ typedef struct PCIIOMMUOps { * @devfn: device and function number */ AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int devf= n); + + /** + * @set_host_iova_ranges: convey the usable iova ranges for a given de= vice + * + * Optional callback which returns 0 on success or an error value if a= ny + * should be called after @get_address_space() + * + * @bus: the #PCIBus being accessed. + * @opaque: the data passed to pci_setup_iommu(). + * @devfn: device and function number + * @iova_ranges: list of IOVA ranges usable by the device + * @errp: error handle + */ + int (*set_host_iova_ranges)(PCIBus *bus, void *opaque, int devfn, + GList *iova_ranges, Error **errp); } PCIIOMMUOps; =20 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478776; cv=none; d=zohomail.com; s=zohoarc; b=kcqUK8huEjj3myndNoOdaXeqEWK1wtVk9GC2X2ZvEzpRWVkE+khE8YhXCMCerHBt9ys1NFn9R/guJKNpdjnfKIiVKGq9VJSJT7fx49NN0ZOWVkNKmoleOakl6bcpaNN0tnMy8Pil5aji6ztLegG8DHkaWQGYfyClKvTUu1DbEGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478776; 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=XLDP4eW2xkgtMCC/IcVRlbka3/PL5Xups7xg3OV5U4E=; b=YrvyOMTHDMk8fjxgacYpCU5M93CATlMk4mPUUXL+IQ830upGlQim4TBO7ifbLNxepXITPgfKYSjiotKHKQ2znSPbz+Eel5COjA/yC3p+kY6SmI4AMd4TKnQXm1h12GGOp2vNlTMkrIMPOE3i+jpbBXPSKVtJudHEs1iOkFq0asI= 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 1705478776884749.9722347128153; Wed, 17 Jan 2024 00:06:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0uj-0002GF-7Z; Wed, 17 Jan 2024 03:04: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 1rQ0uf-0002AD-LZ for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:41 -0500 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 1rQ0ub-00033T-Uw for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:40 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-3QDMzPqQNkGZ5z8l9WGP9Q-1; Wed, 17 Jan 2024 03:04:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 073481064D7F; Wed, 17 Jan 2024 08:04:30 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B8301BDB0; Wed, 17 Jan 2024 08:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478677; 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=XLDP4eW2xkgtMCC/IcVRlbka3/PL5Xups7xg3OV5U4E=; b=ZFLJxHYoujTFPdvzOhX65o2Qvtc67UGkXnZ/89BnoVClJPUImwUG6IrSFkLmJKnP+sRoJe OW396MKMxLBJ3KIyMrK8/LRwsHcylYtnrYZ/Z9P5GOLr08HFMUUvlgxPIAF0hT2CMyPH1X xsdKzSdR/zP2CrcbKuIB1PYbhiDFF3Q= X-MC-Unique: 3QDMzPqQNkGZ5z8l9WGP9Q-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 2/7] hw/pci: Introduce pci_device_iommu_bus Date: Wed, 17 Jan 2024 09:02:06 +0100 Message-ID: <20240117080414.316890-3-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: 1705478778788100007 Content-Type: text/plain; charset="utf-8" This helper will allow subsequent patches to retrieve the IOMMU bus and call its associated PCIIOMMUOps callbacks. Signed-off-by: Eric Auger --- include/hw/pci/pci.h | 1 + hw/pci/pci.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 63c018b35a..649b327f9f 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -403,6 +403,7 @@ typedef struct PCIIOMMUOps { } PCIIOMMUOps; =20 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); +PCIBus *pci_device_iommu_bus(PCIDevice *dev); =20 /** * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 76080af580..5bf07662fe 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2672,6 +2672,22 @@ static void pci_device_class_base_init(ObjectClass *= klass, void *data) } } =20 +PCIBus *pci_device_iommu_bus(PCIDevice *dev) +{ + PCIBus *bus =3D pci_get_bus(dev); + PCIBus *iommu_bus =3D bus; + + while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) { + PCIBus *parent_bus =3D pci_get_bus(iommu_bus->parent_dev); + + iommu_bus =3D parent_bus; + } + if (pci_bus_bypass_iommu(bus)) { + return NULL; + } + return iommu_bus; +} + AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) { PCIBus *bus =3D pci_get_bus(dev); --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478776; cv=none; d=zohomail.com; s=zohoarc; b=OwO7PktNSj79d4YlSGAr5YVu/dHAHfCm1gZZ0Zhh1iEKTolBz0UI7o5iyhEEejg7bTOp6lYTJow7pnctQTImg6BUnDu3mbK/5PoYGYRly0Y2svJquqxHDNuiQIfAYzuSg7u//Kv3wvwoLhGhCO/1lUuvLWNgYrGLgoyPhs2BSq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478776; 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=5nsKjRxVEJHSXPoYhVMa5N+yiqed+CHT2lIF6QJc32s=; b=nMW/ONCGMe1Sg3YV8+iPHHEeE/1jGKcBvG4g7YF5KKzvLUNLAgO4OXgzTylMOvCN1MYA0xgA56xbr0ptrMbFr/UH4T233qEeA6cGPiZkV5+q5nFK7yn/964vV6X2pZlPrv27jlwBXJ5Bj0GLeXlZhJnN1gUQIlrlICbPdaaM01I= 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 1705478776730399.73672204288584; Wed, 17 Jan 2024 00:06:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0um-0002JV-Hm; Wed, 17 Jan 2024 03:04: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 1rQ0uf-0002AF-Me for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:41 -0500 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 1rQ0ub-00033P-OL for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:40 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-FwoKoz-XMmSqSuKgv5P43A-1; Wed, 17 Jan 2024 03:04:33 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id A716F811E86; Wed, 17 Jan 2024 08:04:32 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B18E1BDB0; Wed, 17 Jan 2024 08:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478677; 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=5nsKjRxVEJHSXPoYhVMa5N+yiqed+CHT2lIF6QJc32s=; b=TX4xkcktQNTk91ePCxkNqtJD5vzJ5kQgtAg24vmbPakGlTdm5FAqDiBLdPN+0bss9tFJy9 BVxUn4QiYrgP7N2WsQKUeqsOcck0DJ/G65pOecE7IlVAXh6TzFKMeJi1O/A+L9rXku1In5 3f8Jt42owUhZOGd8H+PbUgq6eMeFE/Y= X-MC-Unique: FwoKoz-XMmSqSuKgv5P43A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 3/7] vfio/pci: Pass the usable IOVA ranges through PCIIOMMUOps Date: Wed, 17 Jan 2024 09:02:07 +0100 Message-ID: <20240117080414.316890-4-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705478778790100008 Content-Type: text/plain; charset="utf-8" Pass the collected usable IOVA regions using the PCIIOMMUOps set_host_iova_ranges() callback, if implemented. Signed-off-by: Eric Auger --- hw/vfio/pci.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d7fe06715c..63937952bb 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2485,6 +2485,28 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *v= dev, return 0; } =20 +static int vfio_pci_set_iova_ranges(VFIOPCIDevice *vdev, Error **errp) +{ + VFIODevice *vbasedev =3D &vdev->vbasedev; + PCIDevice *pdev =3D &vdev->pdev; + VFIOContainerBase *bcontainer =3D vbasedev->bcontainer; + PCIBus *bus, *iommu_bus; + + if (!bcontainer->iova_ranges) { + return 0; + } + + bus =3D pci_get_bus(pdev); + iommu_bus =3D pci_device_iommu_bus(pdev); + if (iommu_bus && iommu_bus->iommu_ops && + iommu_bus->iommu_ops->set_host_iova_ranges) { + return iommu_bus->iommu_ops->set_host_iova_ranges( + bus, iommu_bus->iommu_opaque, + pdev->devfn, bcontainer->iova_ranges, errp); + } + return 0; +} + static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) { VFIODevice *vbasedev =3D &vdev->vbasedev; @@ -3004,6 +3026,11 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) goto error; } =20 + ret =3D vfio_pci_set_iova_ranges(vdev, errp); + if (ret) { + goto error; + } + vfio_populate_device(vdev, &err); if (err) { error_propagate(errp, err); --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478808; cv=none; d=zohomail.com; s=zohoarc; b=FyP6YTwHVeGqEHzdHFe+y4r6AlcuPRo88n2u1Im7wacRjmSbGXISQvsJGl6LxHWDTV31EWoZLU92iZttjULEgZ34UddpFrKzQYQ8/Xm+n2Gded7UAcXXYGUCAe0Wxd5hn1D7ok7nezvmzFiPueLG1jpiN8lGmBoaTizDrN5/sfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478808; 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=uU99jB0p1RkrN4YqJZlTMLWPHdwQmT3jWpzsIJLgPa0=; b=bR5DU3C2DXb0XNR/341Cagyel+pEk/JzTXyWzCAXHSv/HPFbsZVkt3lR29b9WS9BQlN2L4JDLXC0UGaAq0GwgEDoDKhKwX5in3o6bZxx6PQjMEUHjGJt3lcoL1Df7CT4uN5DEtkpd5fkT/2dyc5OU0m+V/3TVDpgPT4BKynwKcM= 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 1705478808487717.3436982832825; Wed, 17 Jan 2024 00:06:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0un-0002LD-E3; Wed, 17 Jan 2024 03:04:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQ0uh-0002CO-7J for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:43 -0500 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 1rQ0uf-00035I-AT for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:42 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-bRc9LiKvNZaU3LEMEaDfWA-1; Wed, 17 Jan 2024 03:04:35 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5803A185A781; Wed, 17 Jan 2024 08:04:35 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECDBD1BDB0; Wed, 17 Jan 2024 08:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478680; 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=uU99jB0p1RkrN4YqJZlTMLWPHdwQmT3jWpzsIJLgPa0=; b=UYTttuqRN/+Prj3HyaW4xc41BvDT+NPLzcB0jLDxC59TDHVdjep7We6kq5o/3WpB2/aKg1 u4lnezRqb4Db6oRsmR5AhGMgnNb56cc1I/Po8WxpvmEb2gGTP7CPzQCmJ3RYFxYdPMFWxZ bQXB1QY1PLUn8vac7pdQOwKLJQZOwkM= X-MC-Unique: bRc9LiKvNZaU3LEMEaDfWA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 4/7] virtio-iommu: Implement PCIIOMMUOps set_host_resv_regions Date: Wed, 17 Jan 2024 09:02:08 +0100 Message-ID: <20240117080414.316890-5-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: 1705478808920100001 Content-Type: text/plain; charset="utf-8" Reuse the implementation of virtio_iommu_set_iova_ranges() which will be removed in subsequent patches. Signed-off-by: Eric Auger --- hw/virtio/virtio-iommu.c | 134 +++++++++++++++++++++++++++++---------- 1 file changed, 101 insertions(+), 33 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 8a4bd933c6..716a3fcfbf 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -461,8 +461,109 @@ static AddressSpace *virtio_iommu_find_add_as(PCIBus = *bus, void *opaque, return &sdev->as; } =20 +/** + * rebuild_resv_regions: rebuild resv regions with both the + * info of host resv ranges and property set resv ranges + */ +static int rebuild_resv_regions(IOMMUDevice *sdev) +{ + GList *l; + int i =3D 0; + + /* free the existing list and rebuild it from scratch */ + g_list_free_full(sdev->resv_regions, g_free); + sdev->resv_regions =3D NULL; + + /* First add host reserved regions if any, all tagged as RESERVED */ + for (l =3D sdev->host_resv_ranges; l; l =3D l->next) { + ReservedRegion *reg =3D g_new0(ReservedRegion, 1); + Range *r =3D (Range *)l->data; + + reg->type =3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED; + range_set_bounds(®->range, range_lob(r), range_upb(r)); + sdev->resv_regions =3D resv_region_list_insert(sdev->resv_regions,= reg); + trace_virtio_iommu_host_resv_regions(sdev->iommu_mr.parent_obj.nam= e, i, + range_lob(®->range), + range_upb(®->range)); + i++; + } + /* + * then add higher priority reserved regions set by the machine + * through properties + */ + add_prop_resv_regions(sdev); + return 0; +} + +static int virtio_iommu_set_host_iova_ranges(PCIBus *bus, void *opaque, + int devfn, GList *iova_ranges, + Error **errp) +{ + VirtIOIOMMU *s =3D opaque; + IOMMUPciBus *sbus =3D g_hash_table_lookup(s->as_by_busptr, bus); + IOMMUDevice *sdev; + GList *current_ranges; + GList *l, *tmp, *new_ranges =3D NULL; + int ret =3D -EINVAL; + + if (!sbus) { + error_report("%s no sbus", __func__); + } + + sdev =3D sbus->pbdev[devfn]; + + current_ranges =3D sdev->host_resv_ranges; + + warn_report("%s: host_resv_regions=3D%d", __func__, !!sdev->host_resv_= ranges); + /* check that each new resv region is included in an existing one */ + if (sdev->host_resv_ranges) { + range_inverse_array(iova_ranges, + &new_ranges, + 0, UINT64_MAX); + + for (tmp =3D new_ranges; tmp; tmp =3D tmp->next) { + Range *newr =3D (Range *)tmp->data; + bool included =3D false; + + for (l =3D current_ranges; l; l =3D l->next) { + Range * r =3D (Range *)l->data; + + if (range_contains_range(r, newr)) { + included =3D true; + break; + } + } + if (!included) { + goto error; + } + } + /* all new reserved ranges are included in existing ones */ + ret =3D 0; + goto out; + } + + if (sdev->probe_done) { + warn_report("%s: Notified about new host reserved regions after pr= obe", + __func__); + } + + range_inverse_array(iova_ranges, + &sdev->host_resv_ranges, + 0, UINT64_MAX); + rebuild_resv_regions(sdev); + + return 0; +error: + error_setg(errp, "%s Conflicting host reserved ranges set!", + __func__); +out: + g_list_free_full(new_ranges, g_free); + return ret; +} + static const PCIIOMMUOps virtio_iommu_ops =3D { .get_address_space =3D virtio_iommu_find_add_as, + .set_host_iova_ranges =3D virtio_iommu_set_host_iova_ranges, }; =20 static int virtio_iommu_attach(VirtIOIOMMU *s, @@ -1158,39 +1259,6 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemo= ryRegion *mr, return 0; } =20 -/** - * rebuild_resv_regions: rebuild resv regions with both the - * info of host resv ranges and property set resv ranges - */ -static int rebuild_resv_regions(IOMMUDevice *sdev) -{ - GList *l; - int i =3D 0; - - /* free the existing list and rebuild it from scratch */ - g_list_free_full(sdev->resv_regions, g_free); - sdev->resv_regions =3D NULL; - - /* First add host reserved regions if any, all tagged as RESERVED */ - for (l =3D sdev->host_resv_ranges; l; l =3D l->next) { - ReservedRegion *reg =3D g_new0(ReservedRegion, 1); - Range *r =3D (Range *)l->data; - - reg->type =3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED; - range_set_bounds(®->range, range_lob(r), range_upb(r)); - sdev->resv_regions =3D resv_region_list_insert(sdev->resv_regions,= reg); - trace_virtio_iommu_host_resv_regions(sdev->iommu_mr.parent_obj.nam= e, i, - range_lob(®->range), - range_upb(®->range)); - i++; - } - /* - * then add higher priority reserved regions set by the machine - * through properties - */ - add_prop_resv_regions(sdev); - return 0; -} =20 /** * virtio_iommu_set_iova_ranges: Conveys the usable IOVA ranges --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478796; cv=none; d=zohomail.com; s=zohoarc; b=L66X2Xi3spj+LmAoE63D3Y6iakn/z/+W8vGz7fXbgNSNiUTmUAlUg2m1TFQ8veSnRKSMXZGzKmgOnTCcc++8bNi/sC4a87+1kMfF2T2jShEqNpSOhtTA1TOXsVheZ+DKvirFheYcAo6ESLhesoyd5SxuZMj0Rh/+3NgkiveTL+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478796; 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=dmZJv/kbQ1MJHJydCzRe7SLGQcxXzFSj2i/ycuIN4lw=; b=RSIIRcehEQeUSQbNKigrILtqhkoNhClrcCnEV2t/NwWqkuweZpF14kcGNdwsDFH6cuDIACdD7aGd/qjDS2n7m+M9jyz+YxMp07uR2wr1z8VLDky23HFWOJqouYKQ7D3hQmXti8/bXCH0VDK04Xq5lp1GG8fVCrSMbWAeW9m/MS0= 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 1705478796719243.98231979586365; Wed, 17 Jan 2024 00:06:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0um-0002K1-P6; Wed, 17 Jan 2024 03:04: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 1rQ0ui-0002GC-HM for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQ0ug-00037I-TF for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:44 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-6-11Q8hggUMl60zHM85BdQMA-1; Wed, 17 Jan 2024 03:04:38 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B94528AC1E9; Wed, 17 Jan 2024 08:04:38 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E19C1BDB1; Wed, 17 Jan 2024 08:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478682; 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=dmZJv/kbQ1MJHJydCzRe7SLGQcxXzFSj2i/ycuIN4lw=; b=A9CwIE4C9zAuEPCkX593gIIF5TNRSLk1mhCsWVg3hysmhuSEVzUsNe1iDZP48fZbgYNZtU 6SdmFGsJk+OD4Xel7C2UIW6+n5KG+XLRJdGjsw1jQ3UWJH4qv7R3uTN7K1fr6LbIoKXb8Y +eKYo2b4lmAfbLid/zOOMXZxP8miTWU= X-MC-Unique: 11Q8hggUMl60zHM85BdQMA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 5/7] virtio-iommu: Remove the implementation of iommu_set_iova_ranges Date: Wed, 17 Jan 2024 09:02:09 +0100 Message-ID: <20240117080414.316890-6-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705478798866100003 Content-Type: text/plain; charset="utf-8" Now that we use PCIIOMMUOps to convey information about usable IOVA ranges we do not to implement the iommu_set_iova_ranges IOMMU MR callback. Signed-off-by: Eric Auger --- hw/virtio/virtio-iommu.c | 67 ---------------------------------------- 1 file changed, 67 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 716a3fcfbf..1e2fc86f2f 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1260,72 +1260,6 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemo= ryRegion *mr, } =20 =20 -/** - * virtio_iommu_set_iova_ranges: Conveys the usable IOVA ranges - * - * The function turns those into reserved ranges. Once some - * reserved ranges have been set, new reserved regions cannot be - * added outside of the original ones. - * - * @mr: IOMMU MR - * @iova_ranges: list of usable IOVA ranges - * @errp: error handle - */ -static int virtio_iommu_set_iova_ranges(IOMMUMemoryRegion *mr, - GList *iova_ranges, - Error **errp) -{ - IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); - GList *current_ranges =3D sdev->host_resv_ranges; - GList *l, *tmp, *new_ranges =3D NULL; - int ret =3D -EINVAL; - - /* check that each new resv region is included in an existing one */ - if (sdev->host_resv_ranges) { - range_inverse_array(iova_ranges, - &new_ranges, - 0, UINT64_MAX); - - for (tmp =3D new_ranges; tmp; tmp =3D tmp->next) { - Range *newr =3D (Range *)tmp->data; - bool included =3D false; - - for (l =3D current_ranges; l; l =3D l->next) { - Range * r =3D (Range *)l->data; - - if (range_contains_range(r, newr)) { - included =3D true; - break; - } - } - if (!included) { - goto error; - } - } - /* all new reserved ranges are included in existing ones */ - ret =3D 0; - goto out; - } - - if (sdev->probe_done) { - warn_report("%s: Notified about new host reserved regions after pr= obe", - mr->parent_obj.name); - } - - range_inverse_array(iova_ranges, - &sdev->host_resv_ranges, - 0, UINT64_MAX); - rebuild_resv_regions(sdev); - - return 0; -error: - error_setg(errp, "IOMMU mr=3D%s Conflicting host reserved ranges set!", - mr->parent_obj.name); -out: - g_list_free_full(new_ranges, g_free); - return ret; -} - static void virtio_iommu_system_reset(void *opaque) { VirtIOIOMMU *s =3D opaque; @@ -1621,7 +1555,6 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, imrc->replay =3D virtio_iommu_replay; imrc->notify_flag_changed =3D virtio_iommu_notify_flag_changed; imrc->iommu_set_page_size_mask =3D virtio_iommu_set_page_size_mask; - imrc->iommu_set_iova_ranges =3D virtio_iommu_set_iova_ranges; } =20 static const TypeInfo virtio_iommu_info =3D { --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478776; cv=none; d=zohomail.com; s=zohoarc; b=AWoAkORPspXxIyxHV8Ss8OsZkO94U0Td6EWjHVXpKR+2xmFTs8r7aRbMgVOjsT2A0Bsj3G1ZvMZsp5fM0SSr4eaS9+1g7VNuchW0mQlglLw3ax/8WkwqH4OqVlwzzyJjNqWTsoO4ynyCD0MZPMbVmBhBDOyZPjctumF2gVcaboY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478776; 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=v3geESpC2ThPvLVZQCG2RlkrSjDSoLwWpI8cdplUGWA=; b=GJASRR2ILYDTkunMs8mT7mkkYYVKxh7AnVTNr7bFoxHpdHWgQ/iOtCBjLgwIsKEwzuUYQULCqNvZDSyx0WAvf1R6kqnHVGWn0y8f2H8KCO1B5DxkvhgjlOr/FFvk0O73HZ2THRi8wSPv/TSpjkZqwnZXrBeQHXINg3fqJz1ChMY= 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 170547877682036.05866895799443; Wed, 17 Jan 2024 00:06:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0up-0002Mw-7Q; Wed, 17 Jan 2024 03:04: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 1rQ0um-0002KN-WC for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:49 -0500 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 1rQ0ul-00039T-Ky for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:48 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-gexDKdI-M7S6uHLMl43Z8A-1; Wed, 17 Jan 2024 03:04:41 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1833F86EB21; Wed, 17 Jan 2024 08:04:41 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1A6F1BDB0; Wed, 17 Jan 2024 08:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478687; 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=v3geESpC2ThPvLVZQCG2RlkrSjDSoLwWpI8cdplUGWA=; b=NV6RuAPawyPI1JEJVw8U4zQzB3GP+3tl5xVcXSCBXqlENhBIdoCnf5PawLd2eLWc5hpXZr zZ7EMveXEoyGAt/eYDEdBW52rA7QWIIYmw667GiUjw4tAh3yeBmP2Mpk6Eld+7xOiykabc zPsDFlVuPFgC4HSIAc/otgXTrF2knr8= X-MC-Unique: gexDKdI-M7S6uHLMl43Z8A-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 6/7] hw/vfio: Remove memory_region_iommu_set_iova_ranges() call Date: Wed, 17 Jan 2024 09:02:10 +0100 Message-ID: <20240117080414.316890-7-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: 1705478778798100009 Content-Type: text/plain; charset="utf-8" As we have just removed the only implementation of iommu_set_iova_ranges IOMMU MR callback in the virtio-iommu, let's remove the call to the memory wrapper. Usable IOVA ranges are now conveyed through the PCIIOMMUOps in VFIO-PCI. Signed-off-by: Eric Auger --- hw/vfio/common.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3352f2a9..d88602e050 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -636,16 +636,6 @@ static void vfio_listener_region_add(MemoryListener *l= istener, goto fail; } =20 - if (bcontainer->iova_ranges) { - ret =3D memory_region_iommu_set_iova_ranges(giommu->iommu_mr, - bcontainer->iova_ran= ges, - &err); - if (ret) { - g_free(giommu); - goto fail; - } - } - ret =3D memory_region_register_iommu_notifier(section->mr, &giommu= ->n, &err); if (ret) { --=20 2.41.0 From nobody Tue Nov 26 18:48:27 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=1705478755; cv=none; d=zohomail.com; s=zohoarc; b=YVRqQXHCoOFw03BycOP1TpnaQol2Hpn21F+9r9m4QJ3MUbJbF0HOEAO8RW7XNEChotz29odMYlyMOpOxLtowsfiIm99DiBxN5gyJ+XgL7JA837KTQoDuQ/V5Yr0rk6KE+SumcojJYpHVztUm3XvAIb6AGywlEMSOf/KAoauAq20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705478755; 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=xqIsR4i4BO9OGZmzS8WyxkJHNJeLczlReQB/Vcukk1A=; b=BmUQYOc2QjPBKoYdukbwdm87nGPPeYnhmmJ+2vxTMtK24cYcWZGTaxx3X3wigdES+tYE2cTl1TdCBWhY8M+4BORNSJMjlDvieC8iMoeLna/U5YUrxbFyarB/Jw++u9Get2mYytlFkeNLlAeTontnMaGJdElu8kEnFcIzBoUAowM= 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 1705478755572481.3782511285789; Wed, 17 Jan 2024 00:05:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQ0up-0002NJ-Oh; Wed, 17 Jan 2024 03:04: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 1rQ0uo-0002MG-BU for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQ0um-00039X-7k for qemu-devel@nongnu.org; Wed, 17 Jan 2024 03:04:49 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-264-8kzxvro_NzG6YgVOEPRBzw-1; Wed, 17 Jan 2024 03:04:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C104E85A58B; Wed, 17 Jan 2024 08:04:43 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D1A810721; Wed, 17 Jan 2024 08:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705478687; 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=xqIsR4i4BO9OGZmzS8WyxkJHNJeLczlReQB/Vcukk1A=; b=W3GBuVaYBI6/f9cKIutduWwzRqPgLwbPWJVlqjfnpPt+d7XIWZDTmqLv8nYjBmCplrLill LdrM/TlPni8o/aif6+AfkhI+JRXCcN2WWhhkIueONMJicNdEfUWZnSI8z1EdyOZEX2m53J He+JkRH0hqr+K7KTg7neLv9NHF2gCF4= X-MC-Unique: 8kzxvro_NzG6YgVOEPRBzw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, jean-philippe@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, zhenzhong.duan@intel.com, peterx@redhat.com, yanghliu@redhat.com, pbonzini@redhat.com Cc: mst@redhat.com, clg@redhat.com Subject: [RFC 7/7] memory: Remove IOMMU MR iommu_set_iova_range API Date: Wed, 17 Jan 2024 09:02:11 +0100 Message-ID: <20240117080414.316890-8-eric.auger@redhat.com> In-Reply-To: <20240117080414.316890-1-eric.auger@redhat.com> References: <20240117080414.316890-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: 1705478756746100003 Content-Type: text/plain; charset="utf-8" Since the host IOVA ranges are now passed through the PCIIOMMUOps set_host_resv_regions and we have removed the only implementation of iommu_set_iova_range() in the virtio-iommu and the only call site in vfio/common, let's retire the IOMMU MR API and its memory wrapper. Signed-off-by: Eric Auger --- include/exec/memory.h | 32 -------------------------------- system/memory.c | 13 ------------- 2 files changed, 45 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 177be23db7..7677b572c5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -527,26 +527,6 @@ struct IOMMUMemoryRegionClass { int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, uint64_t page_size_mask, Error **errp); - /** - * @iommu_set_iova_ranges: - * - * Propagate information about the usable IOVA ranges for a given IOMMU - * memory region. Used for example to propagate host physical device - * reserved memory region constraints to the virtual IOMMU. - * - * Optional method: if this method is not provided, then the default I= OVA - * aperture is used. - * - * @iommu: the IOMMUMemoryRegion - * - * @iova_ranges: list of ordered IOVA ranges (at least one range) - * - * Returns 0 on success, or a negative error. In case of failure, the = error - * object must be created. - */ - int (*iommu_set_iova_ranges)(IOMMUMemoryRegion *iommu, - GList *iova_ranges, - Error **errp); }; =20 typedef struct RamDiscardListener RamDiscardListener; @@ -1896,18 +1876,6 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemo= ryRegion *iommu_mr, uint64_t page_size_mask, Error **errp); =20 -/** - * memory_region_iommu_set_iova_ranges - Set the usable IOVA ranges - * for a given IOMMU MR region - * - * @iommu: IOMMU memory region - * @iova_ranges: list of ordered IOVA ranges (at least one range) - * @errp: pointer to Error*, to store an error if it happens. - */ -int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu, - GList *iova_ranges, - Error **errp); - /** * memory_region_name: get a memory region's name * diff --git a/system/memory.c b/system/memory.c index a229a79988..b2fb12f87f 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1909,19 +1909,6 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemo= ryRegion *iommu_mr, return ret; } =20 -int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu_mr, - GList *iova_ranges, - Error **errp) -{ - IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); - int ret =3D 0; - - if (imrc->iommu_set_iova_ranges) { - ret =3D imrc->iommu_set_iova_ranges(iommu_mr, iova_ranges, errp); - } - return ret; -} - int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { --=20 2.41.0