From nobody Sun Dec 29 00:59:07 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=1720525938; cv=none; d=zohomail.com; s=zohoarc; b=eO0uhpQaWmTTp5+bto9Mf8FNSki0ngsTIphfbwrGdfFeLcKFgUKvEaB5w4yFp5WdW4fgn0tDXpt3phJ3dbkua42LohhdukG9h1YfmgBZTInB9+UcdHJfMcDULG7kx1+IpwoHPtB4ZoasWscyaHEtgcgTL7wo1nahUNLe8zwzQv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525938; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1yGLBk3on+szjb8yno/MlD+vnSsQAPQcY1uYtpRX0fc=; b=KSeEy1WO4DuLILwA9q9ftGOAp6vyAClACQwmf37kRyml0ULQUTUZZnJol8bBKvhDjg7TUmQ8CiNCXZeqnP64/+3t8t3NzR0dUHS3VOodN7SIyb7Tu0ZQw3VzMjRnfhQi1AzjBOuK+fC0/wN2Rn0bpJNUAIcwMITowr/8TM44Pno= 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 1720525938717105.37918917463867; Tue, 9 Jul 2024 04:52:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mu-0005I9-BP; Tue, 09 Jul 2024 07:50:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sR9Mp-0004y4-EW for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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 1sR9MZ-0006JN-TM for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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-658-rlpHMtaCNdiNhjmmZEVznA-1; Tue, 09 Jul 2024 07:50:24 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 7A18E1955F3B; Tue, 9 Jul 2024 11:50:23 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5C9763000181; Tue, 9 Jul 2024 11:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yGLBk3on+szjb8yno/MlD+vnSsQAPQcY1uYtpRX0fc=; b=AkDEwCtRt1loU3CDJtR92tAI0FvkWYTDgbHCOohdkS6k6ERCD4qMfPWJ8PPxkdepJ6Ii38 S5VgR3spzXZj/opwi5nYZS3qNfRec7U0xVX8ynQDK3cQX7GcDsOU/4WeUuRo5gaKOgERzn HFH+5WoTHQup7Qqxg3q9UJOqaPp8Zgc= X-MC-Unique: rlpHMtaCNdiNhjmmZEVznA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 1/9] virtio-iommu: Fix error handling in virtio_iommu_set_host_iova_ranges() Date: Tue, 9 Jul 2024 13:50:09 +0200 Message-ID: <20240709115017.798043-2-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1720525939736116300 From: Eric Auger 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: Zhenzhong Duan 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 7c54c6b5e260e65b555e63809ed247254c785d3f..8fe69ab094f501fced7098f1ba7= 90c26e63aa775 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -563,10 +563,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.45.2 From nobody Sun Dec 29 00:59:07 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=1720525877; cv=none; d=zohomail.com; s=zohoarc; b=hZNhNKuuEJPn72bYxV/Zlzb4/z3+CVJDly5AsDQlmB/H9vxwsRtsZb93VQvfZuZFqJDxgGmcMkmuuvFAMhNknnocekNeK0iD2mGH8oZVBnds1IvNH81LQ4j6DZVT9vG6q4Q4mfqYxVZKnrSJPo8yk/YnK4dxhtq+YWwCYbAsZwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525877; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N/psBi7hxDD95OK0J6Y6wND/KwFqqF6imNOS0uY2/EE=; b=Hr+tJDgQLvHq6+FmEf2uXKEOLI8egjrd4QlpVccw0asGUpzY40KxaXcrxVlilHDUnDsK0PoUaPgz0Q90ynGVsGpQhxD9ureRv+6jtvHdfnnnXHauGizl27dtT+kLH4USJn3LzuwcoLmSLbYMLfcaSDy/w2ImF5FfVUWaXPitkAU= 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 1720525877023751.8852120468819; Tue, 9 Jul 2024 04:51:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mt-0005As-N3; Tue, 09 Jul 2024 07:50:47 -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 1sR9Mo-0004tG-9x for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:42 -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 1sR9Md-0006Jn-Kt for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:42 -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-84-88Q40L0PMo6iu3FlQY1I9Q-1; Tue, 09 Jul 2024 07:50:27 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 9066F1955F3B; Tue, 9 Jul 2024 11:50:26 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC0033000184; Tue, 9 Jul 2024 11:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N/psBi7hxDD95OK0J6Y6wND/KwFqqF6imNOS0uY2/EE=; b=cWM+nQ/F7YJiXMOUf0vQnH8a/l8vk1HUktUwunTPDF6EqFV8aXL3Gcq9Vxdfdq7Xfqr6p+ WPH3cY9REAKPd8H+xoinjlCk9J1G5xwfzQUALwkYZBS7xZCQAIDkD3l0lsmDLUTwAUcA9W 0Eva5Khw/GJOAnd0qDJHDQFeISY4o5s= X-MC-Unique: 88Q40L0PMo6iu3FlQY1I9Q-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 2/9] vfio-container-base: Introduce vfio_container_get_iova_ranges() helper Date: Tue, 9 Jul 2024 13:50:10 +0200 Message-ID: <20240709115017.798043-3-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525877518116300 From: Eric Auger 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: Zhenzhong Duan 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 419e45ee7a5ac960dae4a993127fc9ee66d48db2..45d7c40fce8f4f3508cbc08b436= b2db1dfaa01e4 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 50b1664f89a8192cf4021498e59f2a92cd2f6e89..809b15767425a48f2404b08fc40= 9ee5684af2094 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 88ede913d6f7f8a6a6ec059fbe4b72d7cdb99e72..0804c1b8de2af203fd8f7ef91ee= 12fef105df9b5 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1168,15 +1168,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 c2f158e60386502eef267769ac9bce1effb67033..890d8d6a38e98138fc14780a76d= c8261285f90b5 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.45.2 From nobody Sun Dec 29 00:59:07 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=1720525877; cv=none; d=zohomail.com; s=zohoarc; b=IovY5IRGX88c/39jrLEkwitMAzG4xmWyDbSuuqn7sNGhaLmGe7mRHgdiHU6Ub3sDiyPUKIv9U8VHp3d4NuEjPwo7cvCD5o29nFXJ+Tja6GWGjRlnXcMMlnu8ugJc2t/Ocnt4VQdITxOHrcprSxXV17hS3ggiARCx3cl98HQv8bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525877; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ycE0kOAbk35t/G7qJITOZOUF1v6Ay4CxIjywLtMCyQM=; b=OaUqIw5qAHYukxLbWSDGS56pascoMlsEHhe7GzksdOfTkvzBX9WyiQ49iNt6FVBL+5GpxuPu0TMRxBinLSVuiwluTRyq860CA/ms9Cfj8n20SQGXKeylJqyDWPSsbL/sseZZ6Jm2l/oXdA+y776om90NvVI2PdujPXwG3Ic3NGI= 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 1720525877021524.3514659656323; Tue, 9 Jul 2024 04:51:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mv-0005Mb-F6; Tue, 09 Jul 2024 07:50:49 -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 1sR9Mo-0004tC-9g for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:42 -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 1sR9Mh-0006Jz-2P for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:42 -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-688-N-XUN6gNPSadr584DlvgoA-1; Tue, 09 Jul 2024 07:50:29 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 DF672196CE01; Tue, 9 Jul 2024 11:50:28 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CCBCF3000181; Tue, 9 Jul 2024 11:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycE0kOAbk35t/G7qJITOZOUF1v6Ay4CxIjywLtMCyQM=; b=SA9e0xM2bFOExWMSnoD06nBUdB3pr3g3DRMPVG4yggq54Mvjmlwm6R7f0TFexcvzkD3YZz krmvCiTiQyAQ0jOk0FykzOQpflsWHg/55tvA/PXEfmLVeeGanSduH/GQZElFberXpk/tOf L5vf07XUXjsAWIG2p4cDsEZqng7ywVU= X-MC-Unique: N-XUN6gNPSadr584DlvgoA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 3/9] HostIOMMUDevice : remove Error handle from get_iova_ranges callback Date: Tue, 9 Jul 2024 13:50:11 +0200 Message-ID: <20240709115017.798043-4-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525877507116300 From: Eric Auger 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: Zhenzhong Duan 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 ee6c813c8b2299ed1d1d3b34d143c20a8ec27400..05c7324a0d1ccd2e30bc42ca1f0= 353e55361500a 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 0804c1b8de2af203fd8f7ef91ee12fef105df9b5..ddd835996cfae13dcab01e53fd3= 81ace1cdae668 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1165,7 +1165,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 890d8d6a38e98138fc14780a76dc8261285f90b5..211e7223f150ee3c8447a9c454c= 5a3528860682f 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 8fe69ab094f501fced7098f1ba790c26e63aa775..f278417f2bd95bc57832e9d0367= 1e2834fca5f36 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -635,7 +635,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.45.2 From nobody Sun Dec 29 00:59:07 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=1720525959; cv=none; d=zohomail.com; s=zohoarc; b=QT7GrhdtZBB8R4mMEC4e8LMyURIGNVJ5EiHRZDIiZpf40ELS1zmdYVGXznUewNdAIBc55FBT+o6wjlgdXr4n6kezy+CSi+au4sHQ3078sYzcY/J9jTlHUVC9Z9nw8CKATnL4wqWbBUmUmYRK2npmJ4DoM9DrkGeWcThe6/r4ZtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525959; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F5RrE26PP86wAXgz2hxMg3FUebCPD4iG1R8gJZN5wNo=; b=BOd72QiYMXK9bkHMz2jo1ZpJ7ceGK96QXGLX9hHgpaNH0akdL63sYF2V1lLMVdSQYAV/DYzaANTIwIwjy+syr7Pit6xBI+cQHcqbDZ7g6HKMUWM3NoKn6xLbyr6aaL/s6mkHjFJfRR+38DUBEQ+mcSB1osAiMBaGfq1hxbr4r30= 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 1720525959277114.03039171912997; Tue, 9 Jul 2024 04:52:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mx-0005TY-4f; Tue, 09 Jul 2024 07:50:51 -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 1sR9Mr-000569-Mi for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:45 -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 1sR9Mg-0006K6-Up for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:45 -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-323-jc-1MXBlOBetayHg_5ybmg-1; Tue, 09 Jul 2024 07:50:31 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 F2E2B19560AA; Tue, 9 Jul 2024 11:50:30 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 284433000181; Tue, 9 Jul 2024 11:50:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F5RrE26PP86wAXgz2hxMg3FUebCPD4iG1R8gJZN5wNo=; b=MRch5nLBs91qpwSmnWWkL2KuPMpxfhzkFWSR59c+lGO8QcpmmmcAT7Qn6FGr/lzpkdZGn0 chDTcqzIY1xawhX3YokPKiE//NLPOEoIG4YQOPxerq7MNjLqwxdF6uXulSrp6BtP7jA1Rh 7JXe/auJ3DrBhmIJZQ5x/JAwcHVjlpw= X-MC-Unique: jc-1MXBlOBetayHg_5ybmg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S . Tsirkin" Subject: [PULL 4/9] HostIOMMUDevice: Introduce get_page_size_mask() callback Date: Tue, 9 Jul 2024 13:50:12 +0200 Message-ID: <20240709115017.798043-5-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525959542116300 From: Eric Auger 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: Zhenzhong Duan 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 45d7c40fce8f4f3508cbc08b436b2db1dfaa01e4..62a8b60d87db263225147a21eff= 2ef6e21cb22df 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 05c7324a0d1ccd2e30bc42ca1f0353e55361500a..c1bf74ae2c7a729b22d6512f3ca= 37ce65fa6bcec 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 ddd835996cfae13dcab01e53fd381ace1cdae668..425db1a14c076fd6eaca0d25e06= 237e4e21fb798 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1173,6 +1173,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); @@ -1187,6 +1196,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 211e7223f150ee3c8447a9c454c5a3528860682f..7b5f87a1488111f7b88ce7588db= 4f5e5bd976978 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.45.2 From nobody Sun Dec 29 00:59:07 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=1720525922; cv=none; d=zohomail.com; s=zohoarc; b=OEIFOlWa/whxbupczFxaLRjsjSfPjzdOYnl/ciPq7MjdzUEA6se0iReqvgr3CWXezQgoAaQ4QfbSH3Hj5HNw0L/J0srO/AXMm0uDapcJUCzqYqwvsTohefvJZ28rMMUtGiCj5WNY5AZCt4qUui01wqJ5LFSX7YTuFueVc2OZeic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525922; 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=3MthOu4YA0jbZLDxlULMG7zSMZtr9wLxweLA4487GoY=; b=AovoaJKJo4OynNL0gcDdzw+wluJZqK7JSLSACQ6+HlZo7GEdKOh53kwVvy90tZsriP9n8n0bXYpmGnCF+X+9mCP8AF0ZxlhkwdDRSNPTgQCTXQbRCxRluUM4YYQdiUDXar3MVWdpYL98oKpg+9rPBr/0san2Gya43YhRtl06ktM= 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 1720525922671438.3887116349356; Tue, 9 Jul 2024 04:52:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mv-0005MP-DZ; Tue, 09 Jul 2024 07:50:49 -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 1sR9Mp-0004zK-OT for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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 1sR9Mi-0006KJ-FP for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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-164-8MozQR2eMqa8kAAjt3NAYA-1; Tue, 09 Jul 2024 07:50:33 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 D44871955F43; Tue, 9 Jul 2024 11:50:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3C1FD3000184; Tue, 9 Jul 2024 11:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525835; 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=3MthOu4YA0jbZLDxlULMG7zSMZtr9wLxweLA4487GoY=; b=X6SDYOQ/dgpoNXemrPk4lNb5VG1kiJZMLcyshf8DYCfALq8dXpwnDRlyu7BaInAozz4aGz E2FCYDhrQ9qAgRk3/X6f70VbMNcQYtajiBu7jM9GS8Q+sJwYSWp5oE6iUNrI0WUEFBy1Cc ob51CglIfWbILHzCKOTe8CbF/Dp/dA8= X-MC-Unique: 8MozQR2eMqa8kAAjt3NAYA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 5/9] virtio-iommu : Retrieve page size mask on virtio_iommu_set_iommu_device() Date: Tue, 9 Jul 2024 13:50:13 +0200 Message-ID: <20240709115017.798043-6-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525923425116300 Content-Type: text/plain; charset="utf-8" From: Eric Auger 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: Zhenzhong Duan Reviewed-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 57 ++++++++++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index f278417f2bd95bc57832e9d03671e2834fca5f36..d6654985bd6ed56936289833983= e6c1e20a5d9e7 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -618,9 +618,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; @@ -643,8 +673,28 @@ 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); + if (!viommu->granule_frozen) { + viommu->config.page_size_mask &=3D new_mask; + } + } else { + error_prepend(errp, "%s: ", hiod->name); + goto error; } } =20 @@ -657,6 +707,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 3cf84e04a78fc6ee2f18d563dc8c8f2e31a70bc6..599d855ff6eeb1439ab51bed4d2= 47cb4fc4998ce 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.45.2 From nobody Sun Dec 29 00:59:07 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=1720525938; cv=none; d=zohomail.com; s=zohoarc; b=CyFCK7dQR1TUeGf7VVJ22UlEEOSZ0zgf0vny3rer5LK42874pEnbHh4m+hvZPDqJgiBPH6yqowv2i4sFwsELQo4PUW15GF3aVxLW7YhN3AVs2dRb3GxvAKCSDN0QQQ5RHCdxPQHh0OCfwI7vrphlXh6Xqqq8DDoNB4uabM75Jko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525938; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WKWkfLMyQ04RD2tDwr2ACGPMJyvQEaNn3WNUD/2GBjs=; b=CvttgV6VKbKHqKHgmI4BXy8kxXB/0pbvG4S5Hf41dMJhygtmq26P9PRKP+L4s83cBzFUcqK86bBYjFzx9wE8EVVblLctiTSm8dzYI8bO3OiiyGKpLKuGhndHl5t9cmd8oAsGEzTnZ9uuFVXI2+Jo+EKPPD8j6PqZkUNXUMMMbhA= 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 1720525938802448.66504328925487; Tue, 9 Jul 2024 04:52:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mu-0005Ir-NF; Tue, 09 Jul 2024 07:50:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sR9Mp-0004zp-Sj for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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 1sR9Mj-0006KR-V7 for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:43 -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-39-agQO9kqHMoqDocL0uEmT8A-1; Tue, 09 Jul 2024 07:50:35 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 06B521955F41; Tue, 9 Jul 2024 11:50:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DB0D3000184; Tue, 9 Jul 2024 11:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WKWkfLMyQ04RD2tDwr2ACGPMJyvQEaNn3WNUD/2GBjs=; b=e/uJt2JqbutG4hf7jdRCBWdYkeXv7VlELrV6qPgVaM/XJfHVaNSN8yv4W3iEeo9J+8C21w PgDrjg8fVv6yNogxm1HxgRyww9ZPiU475gA/zJCeSVjQpmgLrWjmXIZIlpNbBxzxWCY31R bzMAtmmOxqarx9GrS3H0wl/cd/1hcDk= X-MC-Unique: agQO9kqHMoqDocL0uEmT8A-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 6/9] memory: remove IOMMU MR iommu_set_page_size_mask() callback Date: Tue, 9 Jul 2024 13:50:14 +0200 Message-ID: <20240709115017.798043-7-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525939796116300 From: Eric Auger 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: Zhenzhong Duan 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 c26ede33d21e82beba7de82892b23dd96ab9ae70..02f7528ec0608218d35a2a12f32= b66da26c4765c 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 7cdb969fd396ae3815cb175ad631d93d7cca7006..6d15b36e0bbbdaeb9437725167e= 61fdf5502555a 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 d6654985bd6ed56936289833983e6c1e20a5d9e7..76f34ea6b32f06c73fda51b19db= 83122812b86dc 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1408,50 +1408,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; @@ -1776,7 +1732,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 2d6952136066da696aca911bba530ddc472e5d70..5e6eb459d5de064f8fc2f993c0a= 0c0a53f88b12c 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 599d855ff6eeb1439ab51bed4d247cb4fc4998ce..b7c04f0856b185e037ccd53726a= 2d8722b6adc84 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.45.2 From nobody Sun Dec 29 00:59:08 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=1720525976; cv=none; d=zohomail.com; s=zohoarc; b=K509lZmn2jxrEfFmbo+8nFgYPNFXSsqxRG9Xg0zQZZMv4dMBDi5wSX16xyoAk4UMzS17jgQjhdbxU1vrPBKZ5oiPRTAUn2zleRiUaYDKMlOOMX2MqJzR8zaheMt48a1HlJ4aD0P5K+bRyj5t7Rjwl7Za1YUQBCuufQrDSJx8bs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525976; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iFAEbYh2IP7uDwVAqftyEzcQGL/hKJ4hjaHbXjW+V1A=; b=n/Bh7tryHjKtpdMKfIDNvzEJ3BEJDQARAF2B1rISJvzjFj8vqdfFGiiaqxBkV12oD3eqizc7677BSdDnGNBvR8dpCrFjV79CWYYYbz5ebHfvi9z6F8pmXN142EePBg0p3aodxkYEjqx0RhO1uHu6Dv+Sl47ImmDwMlmiJagdlKw= 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 1720525976183236.81519599232945; Tue, 9 Jul 2024 04:52:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mx-0005U4-Ew; Tue, 09 Jul 2024 07:50:51 -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 1sR9Mq-00052u-Ib for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:44 -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 1sR9Mn-0006Kb-Od for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:44 -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-416--MQ_ZrhAMV-TbegH6SlVxw-1; Tue, 09 Jul 2024 07:50:38 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 6B44E1955F0D; Tue, 9 Jul 2024 11:50:37 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 355F63000181; Tue, 9 Jul 2024 11:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iFAEbYh2IP7uDwVAqftyEzcQGL/hKJ4hjaHbXjW+V1A=; b=KglW7YEXmzUiY2jZZSzimUr1BVCWNjpXB/cGywufOHX+2PRN8gsBEk3y0c5U+nb8Msk7uO lcURpe3iBjuER2Quc33/mhIFQplopXTYEYzWLDjhWEmROWM24vx4ul14Eq7h1kb/Fvb31b VYt+AD7cTKr7HI/mwg5xqoarJuAFAgQ= X-MC-Unique: -MQ_ZrhAMV-TbegH6SlVxw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , "Michael S . Tsirkin" Subject: [PULL 7/9] virtio-iommu: Revert transient enablement of IOMMU MR in bypass mode Date: Tue, 9 Jul 2024 13:50:15 +0200 Message-ID: <20240709115017.798043-8-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525977621116300 From: Eric Auger 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: Zhenzhong Duan 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 76f34ea6b32f06c73fda51b19db83122812b86dc..33ae61c4a6ae47d7799a32c9091= af3afbc0704d6 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1430,18 +1430,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.45.2 From nobody Sun Dec 29 00:59:08 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=1720525976; cv=none; d=zohomail.com; s=zohoarc; b=QnRr22UxLJzE1MhcQfNHbb4ZWUfar8Itl/s3fFdBtMdU2SaYMC2xMHhNO35H12YE/MdLP7CPEzMAD305t4sIDffgIbXztiSsmGxD7ADhoLRrsAo/0dGOLRqrU4W9PFMwAXhDN6sTecsOo+g6OlPROSnJORCIBAfpINX1+bJWQIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525976; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EQpv0egXJNndOFARBXntRY0jNYVT/w4qa2wRWii6RKA=; b=b594ETLJzehKfuYjlKDx9mS3U/xOrpNH4lPqW4DRao2azo1r3yEzupIsM5zWdFOaD0Q5sfHzgWg3v7KmAEjIfLxIJjtOat2MpcjhT58hwv3YOIu+m8uEfZOBYviocw+99t+ceW4TNqEfsBzFiHYK1jYCQFdqq2rVeiDY5W8zboM= 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 1720525976187303.6898368237638; Tue, 9 Jul 2024 04:52:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9Mx-0005Tb-4d; Tue, 09 Jul 2024 07:50:51 -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 1sR9Mq-00054T-Vz for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:45 -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 1sR9Mo-0006Kv-Lh for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:44 -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-341-MmulFxDVM2WZ2ZSt8VukCw-1; Tue, 09 Jul 2024 07:50:40 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 CBA1A19560B5; Tue, 9 Jul 2024 11:50:39 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D871C3000181; Tue, 9 Jul 2024 11:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQpv0egXJNndOFARBXntRY0jNYVT/w4qa2wRWii6RKA=; b=JiwDy9TCc3bjyIHl3G2HpxwOdpjjYXqOWipwv9h6KB3wYnmRkcj3lNnhTpdKqRBnScstfG iAwPkG7MPHmz5Uozi8eg4JYimSo5MvkP82uZS7Y5y1tBIBg9VKPTJe1lW/WIeAH4Yg+dWq oicnpySChlAgM0caCQlSvLeRxhfBjWQ= X-MC-Unique: MmulFxDVM2WZ2ZSt8VukCw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 8/9] vfio/display: Fix potential memleak of edid info Date: Tue, 9 Jul 2024 13:50:16 +0200 Message-ID: <20240709115017.798043-9-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525977617116300 From: Zhenzhong Duan EDID related device region info is leaked in vfio_display_edid_init() error path and VFIODisplay destroying path. Fixes: 08479114b0de ("vfio/display: add edid support.") Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/vfio/display.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 661e921616f4b85613d5f6053c30348a4ee6cbd2..9c57fd388886100bf9eae061def= 39688d33a8695 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -171,7 +171,9 @@ static void vfio_display_edid_init(VFIOPCIDevice *vdev) =20 err: trace_vfio_display_edid_write_error(); + g_free(dpy->edid_info); g_free(dpy->edid_regs); + dpy->edid_info =3D NULL; dpy->edid_regs =3D NULL; return; } @@ -182,6 +184,7 @@ static void vfio_display_edid_exit(VFIODisplay *dpy) return; } =20 + g_free(dpy->edid_info); g_free(dpy->edid_regs); g_free(dpy->edid_blob); timer_free(dpy->edid_link_timer); --=20 2.45.2 From nobody Sun Dec 29 00:59:08 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=1720525952; cv=none; d=zohomail.com; s=zohoarc; b=mxf47bLFswfnNHN1FOdw2mhDOfXH6G7zQPInHVyASKtB5wWvkq2M44QDIjkb1ynwwrrO+IK8XxzY2CdSzspsf1urHVGJnknADAjkrmGYbZgmjKy41a76sdTFqjM1hZ1qciJUf23aInkw9g4fk6uUoWIcLF0DqUfC/8aLINafVmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720525952; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8taY1k+UlGNUyqXc/omqsBgz7mHZ39E8IuXRU5oAeUo=; b=I3pUfIhVQbQlEN2cEX8I3WswRM67QYMUfJCaVGgKS8zNw01oX/jUk8r/ZcTfN+SebNRjircT2CUg4oCE6m54XK16GdblSDG89RlJMHmvnCl20s+GTBFH5n23Pr4yfOUOt+ICswkSg3JcmNjvz8uDbMt7OkTqLklHm4q5P5Bj4b4= 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 1720525952309574.6836281676474; Tue, 9 Jul 2024 04:52:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sR9My-0005YW-5H; Tue, 09 Jul 2024 07:50:52 -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 1sR9Ms-0005Af-Fl for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sR9Mq-0006Lb-VX for qemu-devel@nongnu.org; Tue, 09 Jul 2024 07:50:46 -0400 Received: from mx-prod-mc-04.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-433-zrNK9WcKMZ6_1QK9o4vylQ-1; Tue, 09 Jul 2024 07:50:42 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B391819560B3; Tue, 9 Jul 2024 11:50:41 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.243]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F1C633000183; Tue, 9 Jul 2024 11:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720525844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8taY1k+UlGNUyqXc/omqsBgz7mHZ39E8IuXRU5oAeUo=; b=eIP8nBnOyry+KCG1i87tS2RiCg5juORfzPOFhpRdytKos3LwEKecOWxNjrHW84Dpt7KOLu +s7XTyLF3UmsvUCnUE0b/a4Rdyf3HUG+x2GAAXVSLiEfToz0zkqVw8hSWyXEKAfQlAfJtY wvia12w5TiLHRhwjPWNkLKZhdkJKw4s= X-MC-Unique: zrNK9WcKMZ6_1QK9o4vylQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 9/9] vfio/display: Fix vfio_display_edid_init() error path Date: Tue, 9 Jul 2024 13:50:17 +0200 Message-ID: <20240709115017.798043-10-clg@redhat.com> In-Reply-To: <20240709115017.798043-1-clg@redhat.com> References: <20240709115017.798043-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=clg@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.144, 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: 1720525953527116300 From: Zhenzhong Duan vfio_display_edid_init() can fail for many reasons and return silently. It would be good to report the error. Old mdev driver may not support vfio edid region and we allow to go through in this case. vfio_display_edid_update() isn't changed because it can be called at runtime when UI changes (i.e. window resize). Fixes: 08479114b0de ("vfio/display: add edid support.") Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/vfio/display.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 9c57fd388886100bf9eae061def39688d33a8695..ea87830fe0d5fc66f3f27a16bde= 5d75b7b6280c0 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -124,7 +124,7 @@ static void vfio_display_edid_ui_info(void *opaque, uin= t32_t idx, } } =20 -static void vfio_display_edid_init(VFIOPCIDevice *vdev) +static bool vfio_display_edid_init(VFIOPCIDevice *vdev, Error **errp) { VFIODisplay *dpy =3D vdev->dpy; int fd =3D vdev->vbasedev.fd; @@ -135,7 +135,8 @@ static void vfio_display_edid_init(VFIOPCIDevice *vdev) VFIO_REGION_SUBTYPE_GFX_EDID, &dpy->edid_info); if (ret) { - return; + /* Failed to get GFX edid info, allow to go through without edid. = */ + return true; } =20 trace_vfio_display_edid_available(); @@ -167,15 +168,16 @@ static void vfio_display_edid_init(VFIOPCIDevice *vde= v) vfio_display_edid_link_up, vdev); =20 vfio_display_edid_update(vdev, true, 0, 0); - return; + return true; =20 err: + error_setg(errp, "vfio: failed to read GFX edid field"); trace_vfio_display_edid_write_error(); g_free(dpy->edid_info); g_free(dpy->edid_regs); dpy->edid_info =3D NULL; dpy->edid_regs =3D NULL; - return; + return false; } =20 static void vfio_display_edid_exit(VFIODisplay *dpy) @@ -368,8 +370,7 @@ static bool vfio_display_dmabuf_init(VFIOPCIDevice *vde= v, Error **errp) return false; } } - vfio_display_edid_init(vdev); - return true; + return vfio_display_edid_init(vdev, errp); } =20 static void vfio_display_dmabuf_exit(VFIODisplay *dpy) --=20 2.45.2