From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390528; cv=none; d=zohomail.com; s=zohoarc; b=l0Wn2IUfVGTgKKtwDbkiH+xa+vDeGUQTRkss0Ljq5NKvXeZ+i1Mjn4nzvtHm4lXBx7j+sd1w0Jcnz9xDZ2mHEJyBhKeRbkbqUi3kxqBchkQJhvSLJXHN6lotfuMJiF8NnXVa1QYvOh/LWvp5EzMjHAvBJyX9GAU/nfrF11PIX3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390528; h=Content-Transfer-Encoding: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:Cc; bh=IIj8ad/t6QF6I2S65p7DeU6tGtDq1WeGUySH+lTT+ZI=; b=mYXdlG8Ai4xhjzrZOPFNCRt0OlOFp75yBjWmfxt7JwMFa5kOvzGGFrQciPiAjhyj/zx5sIqDHfXAhwMKMMTYUlfLtiTb2uJ8viUf3Ry2JjeNTsrhFbaEgRDDWD9UfCmt3MJ26dIDlOaShFSEgnXEaxl6FJUsq2zwpRegNEXQdkw= 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+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 1719390528228491.48779176029973; Wed, 26 Jun 2024 01:28:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0M-0006u0-Kw; Wed, 26 Jun 2024 04:27:50 -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 1sMO0L-0006sy-5B for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:27:49 -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 1sMO0J-00077l-Me for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:27:48 -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-355-eqvEHFaBPu6SvVecpm19uQ-1; Wed, 26 Jun 2024 04:27:43 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 185CD1956089; Wed, 26 Jun 2024 08:27:42 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7240E1955E82; Wed, 26 Jun 2024 08:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IIj8ad/t6QF6I2S65p7DeU6tGtDq1WeGUySH+lTT+ZI=; b=bJWehBZbLT919MMnMT7nG6h9D2pBO4EFjlbqj/uY4kHA4w1g5oEQz/PmSTwSd5HlT25nYj vdnYlK233eummjXPfDUrfv96RkSU0DG/Cu6Q+JG/jwb9+BQyG35Hyz4jt5vGjfygyhNrJ/ wHowy7QTgUTFaY611H3Zsl7kpBexCtw= X-MC-Unique: eqvEHFaBPu6SvVecpm19uQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 1/7] virtio-iommu: Fix error handling in virtio_iommu_set_host_iova_ranges() Date: Wed, 26 Jun 2024 10:26:46 +0200 Message-ID: <20240626082727.1278530-2-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390529635100001 Content-Type: text/plain; charset="utf-8" In case no IOMMUPciBus/IOMMUDevice are found we need to properly set the error handle and return. Fixes : Coverity CID 1549006 Signed-off-by: Eric Auger Fixes: cf2647a76e ("virtio-iommu: Compute host reserved regions") Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index b9a7ddcd14..b708fb96fd 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -543,10 +543,15 @@ static int virtio_iommu_set_host_iova_ranges(VirtIOIO= MMU *s, PCIBus *bus, int ret =3D -EINVAL; =20 if (!sbus) { - error_report("%s no sbus", __func__); + error_setg(errp, "%s: no IOMMUPciBus found!", __func__); + return ret; } =20 sdev =3D sbus->pbdev[devfn]; + if (!sdev) { + error_setg(errp, "%s: no IOMMUDevice found!", __func__); + return ret; + } =20 current_ranges =3D sdev->host_resv_ranges; =20 --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390530; cv=none; d=zohomail.com; s=zohoarc; b=VzRCkgt3J20Vih4QsdaPqAzvuv+Qf/nHUcANlrvKMe6LmrrZLhM6NIi/Ywr6EbbZ7J7DACZ+RXcL0cqg0RCPQngwbgaR5A+inl/4Ck0sak8KTuEkLE5JHEZZME02EyJH4HWB+94De38vFzhwxji3SWKaksYPH38MmHyCpEkGN30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390530; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=tJ6Al0ZQnV18rO+0upSDA/VdXWm+39WAGj4ddyLFL9M=; b=BaQIHHUR4rtiHa/YYouJnfZ09HZjIQ2klzUGe0F6MTu2edU36fNai7g4lUgR1K3sLAZa5Yf53q1um5meAdaQkb2dDfe6DTuhzPyfMb7QCrEfFSZnNOPm/eeDHx6NsV/QY+uQSD5JXhDI9GVwUbVFnAK779Fg9HAHyM0UOYwttA8= 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+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 1719390530151646.1411454284005; Wed, 26 Jun 2024 01:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0S-0006y3-TX; Wed, 26 Jun 2024 04:27:56 -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 1sMO0Q-0006vv-Lm for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:27:54 -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 1sMO0P-00078c-3K for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:27:54 -0400 Received: from mx-prod-mc-03.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-393-owTbmDJ5Ob-D4nckyWdMsg-1; Wed, 26 Jun 2024 04:27:50 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93AA319560AB; Wed, 26 Jun 2024 08:27:49 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 84B371956087; Wed, 26 Jun 2024 08:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tJ6Al0ZQnV18rO+0upSDA/VdXWm+39WAGj4ddyLFL9M=; b=UYLKF+5h0mqBHlY/dK0+mSVh2wLFb5ILY2+ML/bCSW03NFPnV6jAESxarL+bo/Hjbtol5S CPL1qNbfcL7R8fE87Fdx9rjq3V9I4E7wROxF9VhAlej8wIjRjB2Nq0Doug3qjCidaBLvoW nPwlTwZOVczuasehFcvCa8x9n4NeUMA= X-MC-Unique: owTbmDJ5Ob-D4nckyWdMsg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 2/7] vfio-container-base: Introduce vfio_container_get_iova_ranges() helper Date: Wed, 26 Jun 2024 10:26:47 +0200 Message-ID: <20240626082727.1278530-3-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390531140100006 Introduce vfio_container_get_iova_ranges() to retrieve the usable IOVA regions of the base container and use it in the Host IOMMU device implementations of get_iova_ranges() callback. We also fix a UAF bug as the list was shallow copied while g_list_free_full() was used both on the single call site, in virtio_iommu_set_iommu_device() but also in vfio_container_instance_finalize(). Instead use g_list_copy_deep. Fixes: cf2647a76e ("virtio-iommu: Compute host reserved regions") Signed-off-by: Eric Auger Suggested-by: C=C3=A9dric Le Goater Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- include/hw/vfio/vfio-container-base.h | 2 ++ hw/vfio/container-base.c | 15 +++++++++++++++ hw/vfio/container.c | 8 +------- hw/vfio/iommufd.c | 8 +------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 419e45ee7a..45d7c40fce 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -86,6 +86,8 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerB= ase *bcontainer, int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp); =20 +GList *vfio_container_get_iova_ranges(const VFIOContainerBase *bcontainer); + #define TYPE_VFIO_IOMMU "vfio-iommu" #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy" #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr" diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 50b1664f89..809b157674 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -83,6 +83,21 @@ int vfio_container_query_dirty_bitmap(const VFIOContaine= rBase *bcontainer, errp); } =20 +static gpointer copy_iova_range(gconstpointer src, gpointer data) +{ + Range *source =3D (Range *)src; + Range *dest =3D g_new(Range, 1); + + range_set_bounds(dest, range_lob(source), range_upb(source)); + return dest; +} + +GList *vfio_container_get_iova_ranges(const VFIOContainerBase *bcontainer) +{ + assert(bcontainer); + return g_list_copy_deep(bcontainer->iova_ranges, copy_iova_range, NULL= ); +} + static void vfio_container_instance_finalize(Object *obj) { VFIOContainerBase *bcontainer =3D VFIO_IOMMU(obj); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 2e7ecdf10e..2ad57cd845 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1169,15 +1169,9 @@ static GList * hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) { VFIODevice *vdev =3D hiod->agent; - GList *l =3D NULL; =20 g_assert(vdev); - - if (vdev->bcontainer) { - l =3D g_list_copy(vdev->bcontainer->iova_ranges); - } - - return l; + return vfio_container_get_iova_ranges(vdev->bcontainer); } =20 static void vfio_iommu_legacy_instance_init(Object *obj) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index c2f158e603..890d8d6a38 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -647,15 +647,9 @@ static GList * hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) { VFIODevice *vdev =3D hiod->agent; - GList *l =3D NULL; =20 g_assert(vdev); - - if (vdev->bcontainer) { - l =3D g_list_copy(vdev->bcontainer->iova_ranges); - } - - return l; + return vfio_container_get_iova_ranges(vdev->bcontainer); } =20 static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390547; cv=none; d=zohomail.com; s=zohoarc; b=DJehlbcCqFWCmgkXdtBlb7c3N/EaeJ8AunXEdD+FtmwW3wszhMtmYk0DQld7YJzMCcaAu2wC4nZk8ZyUkJJqY9BGmyRdzg6o/h612jFQjTaDaBzes2aJvIUolBwHNWaDx1ynGVXVrrRFOb/Hk4i2zWo4xr1oPvjaNA0nXrB5ues= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390547; h=Content-Transfer-Encoding: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:Cc; bh=NDTYo/p7rWWGol+dOUs5Dsf60vz8nXghSY68K5KXSmM=; b=hXsblR1DwEv6JPpWWYsZHpj+sQxYmSWTw2Jpz/qXoW1jeGBdEYXhi5naBGrslPujLfrL/IP9sf91Ko6OWdkdTf1VjsdwXAbSzbhuBkHnYGKmaHLL3zYAKKxqLRpb/175HNB6ql6RQTAqQ2y76dMz8NJ3IC/wW2/Rrh5Iky+5uro= 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+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 1719390547139851.9539060479665; Wed, 26 Jun 2024 01:29:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0Y-00072Q-2e; Wed, 26 Jun 2024 04:28:02 -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 1sMO0V-0006ys-SQ for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:00 -0400 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 1sMO0U-0007AG-BI for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:27:59 -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-18-eSr8stjDNsyyrCgcsYHaoQ-1; Wed, 26 Jun 2024 04:27:55 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 6C683195609F; Wed, 26 Jun 2024 08:27:54 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0B5651956087; Wed, 26 Jun 2024 08:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NDTYo/p7rWWGol+dOUs5Dsf60vz8nXghSY68K5KXSmM=; b=SKiLUZ1Ibzmk0KWbL9G7ow3sR/Au3itrhulLmZ5b0BW7E0YcLoGRFjGRLRPVYiezxuBhfD rtq969YvDmoy3oT/jm0uFsgqp4YR9iLlxXb/hHAFD2SrNUibrCT73zjYI6onFLUrrL0csI bg7Gym56o+NzIgkrFcBmWM8ljxlHc/w= X-MC-Unique: eSr8stjDNsyyrCgcsYHaoQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 3/7] HostIOMMUDevice : remove Error handle from get_iova_ranges callback Date: Wed, 26 Jun 2024 10:26:48 +0200 Message-ID: <20240626082727.1278530-4-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390549180100011 Content-Type: text/plain; charset="utf-8" The error handle argument is not used anywhere. let's remove it. Signed-off-by: Eric Auger Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- include/sysemu/host_iommu_device.h | 3 +-- hw/vfio/container.c | 2 +- hw/vfio/iommufd.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index ee6c813c8b..05c7324a0d 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -87,9 +87,8 @@ struct HostIOMMUDeviceClass { * @hiod Host IOMMU device * * @hiod: handle to the host IOMMU device - * @errp: error handle */ - GList* (*get_iova_ranges)(HostIOMMUDevice *hiod, Error **errp); + GList* (*get_iova_ranges)(HostIOMMUDevice *hiod); }; =20 /* diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 2ad57cd845..adeab1ac89 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1166,7 +1166,7 @@ static int hiod_legacy_vfio_get_cap(HostIOMMUDevice *= hiod, int cap, } =20 static GList * -hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hiod) { VFIODevice *vdev =3D hiod->agent; =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 890d8d6a38..211e7223f1 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -644,7 +644,7 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, } =20 static GList * -hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod) { VFIODevice *vdev =3D hiod->agent; =20 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index b708fb96fd..b8f75d2b1a 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -615,7 +615,7 @@ static bool virtio_iommu_set_iommu_device(PCIBus *bus, = void *opaque, int devfn, =20 if (hiodc->get_iova_ranges) { int ret; - host_iova_ranges =3D hiodc->get_iova_ranges(hiod, errp); + host_iova_ranges =3D hiodc->get_iova_ranges(hiod); if (!host_iova_ranges) { return true; /* some old kernels may not support that capabili= ty */ } --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390544; cv=none; d=zohomail.com; s=zohoarc; b=NyMd85Q3zGwIHTKF/Xiw5PMqlJ1SR/dWClI/TazDQCvk7voPltMjMrWk4fieeoPxWwRP3kSqsLiMbV2EQFpoWOEjjy6d4PREo5TLRDwUtQKMgg/tTnf1dz8ysjBK0X8RBLTSuZkMK0IyYOfO3Y9Rq5xxT3oVSXIFFbP85Kp7S/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390544; h=Content-Transfer-Encoding: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:Cc; bh=bZve/t/4IEVVs0YkFY83LrcVufG1gG2T8mz5Ir3gtRw=; b=fg1pBdtzKm+wK3KAgcvCpEzKDpJUPmngyY/1WMy+ERasRxSlGXaJXzsVmF/yffFUVbohTG8PnSBaxO84QhVOO5gTscbyo0WvniKwpTpyAOuQHJJtn0OBymkpECGHmzTZyqE67bSkn8YOJi3j+iJ1DR/pq3ApUKvvHnrKrs64jsM= 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+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 1719390543460459.32489430693545; Wed, 26 Jun 2024 01:29:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0n-0007Q0-37; Wed, 26 Jun 2024 04:28:17 -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 1sMO0h-0007LK-Sw for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:12 -0400 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 1sMO0Z-0007Aq-Nc for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:11 -0400 Received: from mx-prod-mc-05.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-520-Dg7AECljMLuwnfeKL0Nlmg-1; Wed, 26 Jun 2024 04:28:00 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 46CA919560AB; Wed, 26 Jun 2024 08:27:59 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 554E61955E82; Wed, 26 Jun 2024 08:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bZve/t/4IEVVs0YkFY83LrcVufG1gG2T8mz5Ir3gtRw=; b=HhFfKqonwjCUoE1JOeUcFxLW2WVLuZfg6F5+YYk9qAjRAR5hc5+4h2m90JuuwWI/b4dHoi 3kcOtw3elfgUVXB5G4/4jtkjP7gec47dxjQKY1RzuyTJ9kN1C08TjXlWjJnmybSA8W45pX NIqyWYaFOtl78k7dYpmAhLF7mtd66Ps= X-MC-Unique: Dg7AECljMLuwnfeKL0Nlmg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 4/7] HostIOMMUDevice: Introduce get_page_size_mask() callback Date: Wed, 26 Jun 2024 10:26:49 +0200 Message-ID: <20240626082727.1278530-5-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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 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 @redhat.com) X-ZM-MESSAGEID: 1719390545176100001 Content-Type: text/plain; charset="utf-8" This callback will be used to retrieve the page size mask supported along a given Host IOMMU device. Signed-off-by: Eric Auger Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- include/hw/vfio/vfio-container-base.h | 7 +++++++ include/sysemu/host_iommu_device.h | 8 ++++++++ hw/vfio/container.c | 10 ++++++++++ hw/vfio/iommufd.c | 11 +++++++++++ 4 files changed, 36 insertions(+) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 45d7c40fce..62a8b60d87 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -88,6 +88,13 @@ int vfio_container_query_dirty_bitmap(const VFIOContaine= rBase *bcontainer, =20 GList *vfio_container_get_iova_ranges(const VFIOContainerBase *bcontainer); =20 +static inline uint64_t +vfio_container_get_page_size_mask(const VFIOContainerBase *bcontainer) +{ + assert(bcontainer); + return bcontainer->pgsizes; +} + #define TYPE_VFIO_IOMMU "vfio-iommu" #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy" #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr" diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 05c7324a0d..c1bf74ae2c 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -89,6 +89,14 @@ struct HostIOMMUDeviceClass { * @hiod: handle to the host IOMMU device */ GList* (*get_iova_ranges)(HostIOMMUDevice *hiod); + /** + * + * @get_page_size_mask: Return the page size mask supported along this + * @hiod Host IOMMU device + * + * @hiod: handle to the host IOMMU device + */ + uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod); }; =20 /* diff --git a/hw/vfio/container.c b/hw/vfio/container.c index adeab1ac89..b5ce559a0d 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1174,6 +1174,15 @@ hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hi= od) return vfio_container_get_iova_ranges(vdev->bcontainer); } =20 +static uint64_t +hiod_legacy_vfio_get_page_size_mask(HostIOMMUDevice *hiod) +{ + VFIODevice *vdev =3D hiod->agent; + + g_assert(vdev); + return vfio_container_get_page_size_mask(vdev->bcontainer); +} + static void vfio_iommu_legacy_instance_init(Object *obj) { VFIOContainer *container =3D VFIO_IOMMU_LEGACY(obj); @@ -1188,6 +1197,7 @@ static void hiod_legacy_vfio_class_init(ObjectClass *= oc, void *data) hioc->realize =3D hiod_legacy_vfio_realize; hioc->get_cap =3D hiod_legacy_vfio_get_cap; hioc->get_iova_ranges =3D hiod_legacy_vfio_get_iova_ranges; + hioc->get_page_size_mask =3D hiod_legacy_vfio_get_page_size_mask; }; =20 static const TypeInfo types[] =3D { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 211e7223f1..7b5f87a148 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -652,12 +652,23 @@ hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hi= od) return vfio_container_get_iova_ranges(vdev->bcontainer); } =20 +static uint64_t +hiod_iommufd_vfio_get_page_size_mask(HostIOMMUDevice *hiod) +{ + VFIODevice *vdev =3D hiod->agent; + + g_assert(vdev); + return vfio_container_get_page_size_mask(vdev->bcontainer); +} + + static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 hiodc->realize =3D hiod_iommufd_vfio_realize; hiodc->get_iova_ranges =3D hiod_iommufd_vfio_get_iova_ranges; + hiodc->get_page_size_mask =3D hiod_iommufd_vfio_get_page_size_mask; }; =20 static const TypeInfo types[] =3D { --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390545; cv=none; d=zohomail.com; s=zohoarc; b=F/X7f8/2n7DVbE4qPc1hT2XxgFtGCqOtzjr/kwAtUKv+OrvMBaZE2fBODeAjexmPVx1QhXJ1zL8Zm+qO6ihfpJKFpYBBgNHqxx3ThxadDznzChK5GHuHJZh0+Ku9W4UvBn5icYjjuGNBfQ8atVLwFWuKfEad/yQScpdlD5h3b2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390545; h=Content-Transfer-Encoding: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:Cc; bh=I0KLPOuTDMTxkK4QreGWaRVWTuh4m0WBW5E4iSJbcTU=; b=Xz5m38y+BhXmMV9HOipcX6OI8jtTFcqeVX8eYzI5Tqkv7gtJMRpfmbY+kFjLyeO8r91dGd2TGpC0MFHNfmIHpeGXZIFPE0eKN3NpjKYrs6lH+96GaBwht2KsG0t0LkTw0iZehUvQ1SAuGS6CxtxGsirYfDgz2B9zhyJXsT8scPI= 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+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 1719390545810298.4816039898101; Wed, 26 Jun 2024 01:29:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0r-0007Vj-8D; Wed, 26 Jun 2024 04:28:21 -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 1sMO0k-0007Oj-Ag for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:14 -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 1sMO0h-0007Co-Cc for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:14 -0400 Received: from mx-prod-mc-02.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-339-pU6ox6fWPqeSXoePb38__w-1; Wed, 26 Jun 2024 04:28:06 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2481919560AD; Wed, 26 Jun 2024 08:28:03 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B47441956087; Wed, 26 Jun 2024 08:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I0KLPOuTDMTxkK4QreGWaRVWTuh4m0WBW5E4iSJbcTU=; b=H4u080XJrxqkrUcwNJbzv2yIjj5bQ9LcrnIxpeqgpU03zIVzydLYOQcBmMf8RtY4opj/Te 8xbjMpWpEW+MvacM0S7S0nwPczrJOSUQTHqBQqLoOdXyFlKXmO31C/hpP2+rS4lhDtFhv5 J/14kc20+pHTJVj9biXK3/H2vKTs5ww= X-MC-Unique: pU6ox6fWPqeSXoePb38__w-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 5/7] virtio-iommu : Retrieve page size mask on virtio_iommu_set_iommu_device() Date: Wed, 26 Jun 2024 10:26:50 +0200 Message-ID: <20240626082727.1278530-6-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390547183100007 Content-Type: text/plain; charset="utf-8" Retrieve the Host IOMMU Device page size mask when this latter is set. This allows to get the information much sooner than when relying on IOMMU MR set_page_size_mask() call, whcih happens when the IOMMU MR gets enabled. We introduce check_page_size_mask() helper whose code is inherited from current virtio_iommu_set_page_size_mask() implementation. This callback will be removed in a subsequent patch. Signed-off-by: Eric Auger Reviewed-by: Michael S. Tsirkin Reviewed-by: Zhenzhong Duan --- hw/virtio/virtio-iommu.c | 55 ++++++++++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index b8f75d2b1a..631589735a 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -598,9 +598,39 @@ out: return ret; } =20 +static bool check_page_size_mask(VirtIOIOMMU *viommu, uint64_t new_mask, + Error **errp) +{ + uint64_t cur_mask =3D viommu->config.page_size_mask; + + if ((cur_mask & new_mask) =3D=3D 0) { + error_setg(errp, "virtio-iommu reports a page size mask 0x%"PRIx64 + " incompatible with currently supported mask 0x%"PRIx64, + new_mask, cur_mask); + return false; + } + /* + * Once the granule is frozen we can't change the mask anymore. If by + * chance the hotplugged device supports the same granule, we can still + * accept it. + */ + if (viommu->granule_frozen) { + int cur_granule =3D ctz64(cur_mask); + + if (!(BIT_ULL(cur_granule) & new_mask)) { + error_setg(errp, + "virtio-iommu does not support frozen granule 0x%ll= x", + BIT_ULL(cur_granule)); + return false; + } + } + return true; +} + static bool virtio_iommu_set_iommu_device(PCIBus *bus, void *opaque, int d= evfn, HostIOMMUDevice *hiod, Error **e= rrp) { + ERRP_GUARD(); VirtIOIOMMU *viommu =3D opaque; HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); struct hiod_key *new_key; @@ -623,8 +653,26 @@ static bool virtio_iommu_set_iommu_device(PCIBus *bus,= void *opaque, int devfn, hiod->aliased_devfn, host_iova_ranges, errp); if (ret) { - g_list_free_full(host_iova_ranges, g_free); - return false; + goto error; + } + } + if (hiodc->get_page_size_mask) { + uint64_t new_mask =3D hiodc->get_page_size_mask(hiod); + + if (check_page_size_mask(viommu, new_mask, errp)) { + /* + * The default mask depends on the "granule" property. For exa= mple, + * with 4k granule, it is -(4 * KiB). When an assigned device = has + * page size restrictions due to the hardware IOMMU configurat= ion, + * apply this restriction to the mask. + */ + trace_virtio_iommu_update_page_size_mask(hiod->name, + viommu->config.page_s= ize_mask, + new_mask); + viommu->config.page_size_mask &=3D new_mask; + } else { + error_prepend(errp, "%s: ", hiod->name); + goto error; } } =20 @@ -637,6 +685,9 @@ static bool virtio_iommu_set_iommu_device(PCIBus *bus, = void *opaque, int devfn, g_list_free_full(host_iova_ranges, g_free); =20 return true; +error: + g_list_free_full(host_iova_ranges, g_free); + return false; } =20 static void diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 3cf84e04a7..599d855ff6 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -132,6 +132,7 @@ virtio_iommu_notify_map(const char *name, uint64_t virt= _start, uint64_t virt_end virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_en= d, uint64_t phys_start) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PR= Ix64" phys_start=3D0x%"PRIx64 virtio_iommu_set_page_size_mask(const char *name, uint64_t old, uint64_t n= ew) "mr=3D%s old_mask=3D0x%"PRIx64" new_mask=3D0x%"PRIx64 +virtio_iommu_update_page_size_mask(const char *name, uint64_t old, uint64_= t new) "host iommu device=3D%s old_mask=3D0x%"PRIx64" new_mask=3D0x%"PRIx64 virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" virtio_iommu_switch_address_space(uint8_t bus, uint8_t slot, uint8_t fn, b= ool on) "Device %02x:%02x.%x switching address space (iommu enabled=3D%d)" --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390558; cv=none; d=zohomail.com; s=zohoarc; b=nSxI8LU6lA4nwcU5Xz4a4FCjOnvnjnyj/Eh6UVo3QXDzsjbDTgMYCob6IVrd/ieuhfD9rqry6PL0NP2HLQTj0FVIROjth6MNKYXWLhNiiKk66r7tPsq7Mk0FWhBwDmVv4sjr4LCkrkqG5+euEgUxrOK9/9bC2u4iyTi1OnnGeDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390558; h=Content-Transfer-Encoding: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:Cc; bh=V8+yh9BO2co7/n68WttUqz+fb/n9Db2ubdRGfHNjNH8=; b=AVuMcVcIB1tcSyVtjI/JDWj+mZG1uAlb+iaNrDPO+pG4XmX1MlrKEGFu398fgkridJZfFgLCjdG+YdIF0nXCDwMmoPVbgZBIvCK+zQOdTrldlLj3gd6VMr412IJEdnlx0OorYDUAW9cu8R7seHUslCKERKqjLAy2f4OYqdwx4Gs= 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+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 1719390558629320.50460654235985; Wed, 26 Jun 2024 01:29:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0s-0007al-Bu; Wed, 26 Jun 2024 04:28:22 -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 1sMO0l-0007PL-Nx for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:16 -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 1sMO0j-0007DD-U4 for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:15 -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-279-HcmZaVBSNwysIrtAk5dOvw-1; Wed, 26 Jun 2024 04:28:08 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 1E83F195608B; Wed, 26 Jun 2024 08:28:07 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 909281956087; Wed, 26 Jun 2024 08:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V8+yh9BO2co7/n68WttUqz+fb/n9Db2ubdRGfHNjNH8=; b=SXtra9jZjCtrl9dncteEn4Kzd4Gb7lB5iq3dSQ85Z0DcOXWZYs+mrEsQzdBax/oz5AHJmX etztfUyI7Q4+z8QjYt4eehETiZThUfJljiBnLoY/KInQ2ISS42JZcRrsWG5iEBJcmDzLQ4 Ejm35vrbGap4hVgeEbDegKlEldxqgTU= X-MC-Unique: HcmZaVBSNwysIrtAk5dOvw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 6/7] memory: remove IOMMU MR iommu_set_page_size_mask() callback Date: Wed, 26 Jun 2024 10:26:51 +0200 Message-ID: <20240626082727.1278530-7-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.129.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390559237100001 Content-Type: text/plain; charset="utf-8" Everything is now in place to use the Host IOMMU Device callbacks to retrieve the page size mask usable with a given assigned device. This new method brings the advantage to pass the info much earlier to the virtual IOMMU and before the IOMMU MR gets enabled. So let's remove the call to memory_region_iommu_set_page_size_mask in vfio common.c and remove the single implementation of the IOMMU MR callback in the virtio-iommu.c Signed-off-by: Eric Auger Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- include/exec/memory.h | 38 --------------------------------- hw/vfio/common.c | 8 ------- hw/virtio/virtio-iommu.c | 45 ---------------------------------------- system/memory.c | 13 ------------ hw/virtio/trace-events | 1 - 5 files changed, 105 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 0903513d13..6f9c78cc14 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -504,32 +504,6 @@ struct IOMMUMemoryRegionClass { * @iommu: the IOMMUMemoryRegion */ int (*num_indexes)(IOMMUMemoryRegion *iommu); - - /** - * @iommu_set_page_size_mask: - * - * Restrict the page size mask that can be supported with a given IOMMU - * memory region. Used for example to propagate host physical IOMMU pa= ge - * size mask limitations to the virtual IOMMU. - * - * Optional method: if this method is not provided, then the default g= lobal - * page mask is used. - * - * @iommu: the IOMMUMemoryRegion - * - * @page_size_mask: a bitmask of supported page sizes. At least one bi= t, - * representing the smallest page size, must be set. Additional set bi= ts - * represent supported block sizes. For example a host physical IOMMU = that - * uses page tables with a page size of 4kB, and supports 2MB and 4GB - * blocks, will set mask 0x40201000. A granule of 4kB with indiscrimin= ate - * block sizes is specified with mask 0xfffffffffffff000. - * - * Returns 0 on success, or a negative error. In case of failure, the = error - * object must be created. - */ - int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, - uint64_t page_size_mask, - Error **errp); }; =20 typedef struct RamDiscardListener RamDiscardListener; @@ -1919,18 +1893,6 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRe= gion *iommu_mr, */ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); =20 -/** - * memory_region_iommu_set_page_size_mask: set the supported page - * sizes for a given IOMMU memory region - * - * @iommu_mr: IOMMU memory region - * @page_size_mask: supported page size mask - * @errp: pointer to Error*, to store an error if it happens. - */ -int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, - uint64_t page_size_mask, - Error **errp); - /** * memory_region_name: get a memory region's name * diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7cdb969fd3..6d15b36e0b 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -622,14 +622,6 @@ static void vfio_listener_region_add(MemoryListener *l= istener, int128_get64(llend), iommu_idx); =20 - ret =3D memory_region_iommu_set_page_size_mask(giommu->iommu_mr, - bcontainer->pgsizes, - &err); - if (ret) { - g_free(giommu); - goto fail; - } - ret =3D memory_region_register_iommu_notifier(section->mr, &giommu= ->n, &err); if (ret) { diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 631589735a..b24e10de81 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1363,50 +1363,6 @@ static int virtio_iommu_notify_flag_changed(IOMMUMem= oryRegion *iommu_mr, return 0; } =20 -/* - * The default mask depends on the "granule" property. For example, with - * 4k granule, it is -(4 * KiB). When an assigned device has page size - * restrictions due to the hardware IOMMU configuration, apply this restri= ction - * to the mask. - */ -static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, - uint64_t new_mask, - Error **errp) -{ - IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); - VirtIOIOMMU *s =3D sdev->viommu; - uint64_t cur_mask =3D s->config.page_size_mask; - - trace_virtio_iommu_set_page_size_mask(mr->parent_obj.name, cur_mask, - new_mask); - - if ((cur_mask & new_mask) =3D=3D 0) { - error_setg(errp, "virtio-iommu %s reports a page size mask 0x%"PRI= x64 - " incompatible with currently supported mask 0x%"PRIx64, - mr->parent_obj.name, new_mask, cur_mask); - return -1; - } - - /* - * Once the granule is frozen we can't change the mask anymore. If by - * chance the hotplugged device supports the same granule, we can still - * accept it. - */ - if (s->granule_frozen) { - int cur_granule =3D ctz64(cur_mask); - - if (!(BIT_ULL(cur_granule) & new_mask)) { - error_setg(errp, "virtio-iommu %s does not support frozen gran= ule 0x%llx", - mr->parent_obj.name, BIT_ULL(cur_granule)); - return -1; - } - return 0; - } - - s->config.page_size_mask &=3D new_mask; - return 0; -} - static void virtio_iommu_system_reset(void *opaque) { VirtIOIOMMU *s =3D opaque; @@ -1731,7 +1687,6 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, imrc->translate =3D virtio_iommu_translate; 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; } =20 static const TypeInfo virtio_iommu_info =3D { diff --git a/system/memory.c b/system/memory.c index 2d69521360..5e6eb459d5 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1901,19 +1901,6 @@ static int memory_region_update_iommu_notify_flags(I= OMMUMemoryRegion *iommu_mr, return ret; } =20 -int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, - uint64_t page_size_mask, - Error **errp) -{ - IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); - int ret =3D 0; - - if (imrc->iommu_set_page_size_mask) { - ret =3D imrc->iommu_set_page_size_mask(iommu_mr, page_size_mask, e= rrp); - } - return ret; -} - int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 599d855ff6..b7c04f0856 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -131,7 +131,6 @@ virtio_iommu_fill_resv_property(uint32_t devid, uint8_t= subtype, uint64_t start, virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t vi= rt_end, uint64_t phys_start, uint32_t flags) "mr=3D%s virt_start=3D0x%"PRIx= 64" virt_end=3D0x%"PRIx64" phys_start=3D0x%"PRIx64" flags=3D%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_en= d, uint64_t phys_start) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PR= Ix64" phys_start=3D0x%"PRIx64 -virtio_iommu_set_page_size_mask(const char *name, uint64_t old, uint64_t n= ew) "mr=3D%s old_mask=3D0x%"PRIx64" new_mask=3D0x%"PRIx64 virtio_iommu_update_page_size_mask(const char *name, uint64_t old, uint64_= t new) "host iommu device=3D%s old_mask=3D0x%"PRIx64" new_mask=3D0x%"PRIx64 virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" --=20 2.41.0 From nobody Mon Sep 16 19:23:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719390538; cv=none; d=zohomail.com; s=zohoarc; b=P1PBUgjts5g4naZmN1qXwFiqL6H6gaR5dRsbnDsOGUYcWbCHiJefnCDpmnINbhMADZpMg6V7690CxVDKmdAYeCEBlfSARhMxdol1+ZOkiyXal/GaINvGipwrHD/69Sf17dbHQKcajgLNwFOJKPtPPhE9ogW+O8N90aJ6EmNPp/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719390538; h=Content-Transfer-Encoding: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:Cc; bh=p+DGD3fPGv2kOWXJer3oVP7HLhSLO1OZboYmYmKyNY0=; b=Xrny8yUcUtYimMFAZ+H78t1gC9z5TKr6x5JBZ4xUslYMNymS3Sua9CsNwEEOcWF6uUspM6d6AWQggDZ+pVsu8cLdYopgBzCVFQKxYtvJVX/Wr7/Y6BeRFnm8RSgLJA58k98eLoKtIRum0R5AkaTylqRqU4HTeNTI6ey0VAdKgpk= 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+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 1719390538572683.650775686007; Wed, 26 Jun 2024 01:28:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMO0t-0007cT-Do; Wed, 26 Jun 2024 04:28:23 -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 1sMO0o-0007Rg-W0 for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:20 -0400 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 1sMO0n-0007Dd-Bo for qemu-devel@nongnu.org; Wed, 26 Jun 2024 04:28:18 -0400 Received: from mx-prod-mc-03.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-464-I5ffquUuNPG9d9BrVpB2_g-1; Wed, 26 Jun 2024 04:28:14 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 27E7A19560AF; Wed, 26 Jun 2024 08:28:12 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8CFC21956087; Wed, 26 Jun 2024 08:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719390496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p+DGD3fPGv2kOWXJer3oVP7HLhSLO1OZboYmYmKyNY0=; b=AiQsN3ztP4+1XaWFDY/P0c5MXkP2dEd4vXyfPJA6C+5PijIWkbjTRmF6jIfgK7KhMQZVsW 9V43UgUX953HwqAhqkAd1hVqNsuHCcaYvZmiLqs0aPoKaUHJoa38YeE0SbdkgGqcC26tvp +AXdsEq7bBcfsjU2hW7n4mDzzCYspLk= X-MC-Unique: I5ffquUuNPG9d9BrVpB2_g-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com, alex.williamson@redhat.com Subject: [PATCH 7/7] virtio-iommu: Revert transient enablement of IOMMU MR in bypass mode Date: Wed, 26 Jun 2024 10:26:52 +0200 Message-ID: <20240626082727.1278530-8-eric.auger@redhat.com> In-Reply-To: <20240626082727.1278530-1-eric.auger@redhat.com> References: <20240626082727.1278530-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719390539141100001 Content-Type: text/plain; charset="utf-8" In 94df5b2180d6 ("virtio-iommu: Fix 64kB host page size VFIO device assignment"), in case of bypass mode, we transiently enabled the IOMMU MR to allow the set_page_size_mask() to be called and pass information about the page size mask constraint of cold plugged VFIO devices. Now we do not use the IOMMU MR callback anymore, we can just get rid of this hack. Signed-off-by: Eric Auger Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index b24e10de81..f87359b3e7 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1385,18 +1385,6 @@ static void virtio_iommu_freeze_granule(Notifier *no= tifier, void *data) VirtIOIOMMU *s =3D container_of(notifier, VirtIOIOMMU, machine_done); int granule; =20 - if (likely(s->config.bypass)) { - /* - * Transient IOMMU MR enable to collect page_size_mask requirements - * through memory_region_iommu_set_page_size_mask() called by - * VFIO region_add() callback - */ - s->config.bypass =3D false; - virtio_iommu_switch_address_space_all(s); - /* restore default */ - s->config.bypass =3D true; - virtio_iommu_switch_address_space_all(s); - } s->granule_frozen =3D true; granule =3D ctz64(s->config.page_size_mask); trace_virtio_iommu_freeze_granule(BIT_ULL(granule)); --=20 2.41.0